qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
306,602 | <p>I am porting an existing application to C# and want to improve performance wherever possible. Many existing loop counters and array references are defined as System.UInt32, instead of the Int32 I would have used.</p>
<p>Is there any significant performance difference for using UInt32 vs Int32?</p>
| [
{
"answer_id": 306670,
"author": "Rohan West",
"author_id": 38686,
"author_profile": "https://Stackoverflow.com/users/38686",
"pm_score": 0,
"selected": false,
"text": " Console.WriteLine(Int32.MaxValue); // Max interation 2147483647\n Console.WriteLine(UInt32.MaxValue); // Max interation 4294967295\n"
},
{
"answer_id": 35142888,
"author": "Robear",
"author_id": 1269672,
"author_profile": "https://Stackoverflow.com/users/1269672",
"pm_score": 5,
"selected": false,
"text": "class Program\n{\n static void Main(string[] args)\n {\n const int iterations = 100;\n Console.WriteLine($\"Signed: {Iterate(TestSigned, iterations)}\");\n Console.WriteLine($\"Unsigned: {Iterate(TestUnsigned, iterations)}\");\n Console.Read();\n }\n\n private static void TestUnsigned()\n {\n uint accumulator = 0;\n var max = (uint)Int32.MaxValue;\n for (uint i = 0; i < max; i++) ++accumulator;\n }\n\n static void TestSigned()\n {\n int accumulator = 0;\n var max = Int32.MaxValue;\n for (int i = 0; i < max; i++) ++accumulator;\n }\n\n static TimeSpan Iterate(Action action, int count)\n {\n var elapsed = TimeSpan.Zero;\n for (int i = 0; i < count; i++)\n elapsed += Time(action);\n return new TimeSpan(elapsed.Ticks / count);\n }\n\n static TimeSpan Time(Action action)\n {\n var sw = new Stopwatch();\n sw.Start();\n action();\n sw.Stop();\n return sw.Elapsed;\n }\n}\n"
},
{
"answer_id": 62581564,
"author": "Paul Klee",
"author_id": 13814346,
"author_profile": "https://Stackoverflow.com/users/13814346",
"pm_score": 0,
"selected": false,
"text": "int"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12113/"
] |
306,626 | <p>I'm completely stumped on this one. I have three different lists that need to be displayed on the screen. It's completely possible that the lists will extend past the bottom edge of the screen, so I would need scrolling.</p>
<p>I've tried using a <code>ScrollView</code> with a <code>LinearLayout</code> child, and putting my <code>ListViews</code> in the <code>LinearView</code>, but all of the <code>ListViews</code> lock to a fixed height with scroll bars. Using other kinds of Layouts means no scrolling.</p>
<p>Does anyone have any suggestions, or will I need to programmatically add the list items to some layout and hope for the best?</p>
| [
{
"answer_id": 5127111,
"author": "hgllnt",
"author_id": 593529,
"author_profile": "https://Stackoverflow.com/users/593529",
"pm_score": 3,
"selected": false,
"text": "ListAdapter listAdapter = listView.getAdapter();\n \nint rows = listAdapter.getCount() / columns;\nint height = 60 * rows; // Insert the general cell height plus the dividers.\n\nViewGroup.LayoutParams params = listView.getLayoutParams();\nparams.height = height;\nlistView.setLayoutParams(params);\nlistView.requestLayout();\n"
},
{
"answer_id": 6522685,
"author": "Richard",
"author_id": 488991,
"author_profile": "https://Stackoverflow.com/users/488991",
"pm_score": 4,
"selected": false,
"text": "touched"
},
{
"answer_id": 12357744,
"author": "Kevin Parker",
"author_id": 568508,
"author_profile": "https://Stackoverflow.com/users/568508",
"pm_score": 2,
"selected": false,
"text": "public class MainActivity extends Activity implements OnTouchListener {\n\n private ScrollView scrollViewLeft;\n private ScrollView scrollViewRight;\n private static String LOG_TAG = MainActivity.class.getName();\n private boolean requestedFocus = false;\n\n @Override\n public void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_main);\n\n scrollViewLeft = (ScrollView) findViewById(R.id.scrollview_left);\n scrollViewRight = (ScrollView) findViewById(R.id.scrollview_right);\n\n scrollViewLeft.setOnTouchListener(this);\n scrollViewRight.setOnTouchListener(this);\n \n scrollViewLeft.setFocusableInTouchMode(true);\n scrollViewRight.setFocusableInTouchMode(true);\n }\n\n @Override\n public boolean onCreateOptionsMenu(Menu menu) {\n getMenuInflater().inflate(R.menu.activity_main, menu);\n return true;\n }\n\n @Override\n public boolean onTouch(View view, MotionEvent motionEvent) {\n Log.d(LOG_TAG, \"--> View, event: \" + view.getId() + \", \" + motionEvent.getAction() + \", \" + view.isFocused());\n Log.d(LOG_TAG, \"--> \" + scrollViewLeft.isFocused() + \", \" + scrollViewRight.isFocused());\n \n if (motionEvent.getAction() == MotionEvent.ACTION_DOWN && requestedFocus == false) {\n view.requestFocus();\n requestedFocus = true;\n } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {\n requestedFocus = false;\n }\n \n if (view.getId() == R.id.scrollview_left && view.isFocused()) {\n scrollViewRight.dispatchTouchEvent(motionEvent);\n } else if (view.getId() == R.id.scrollview_right && view.isFocused()) {\n scrollViewLeft.dispatchTouchEvent(motionEvent);\n }\n \n return super.onTouchEvent(motionEvent);\n }\n}\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306626",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12096/"
] |
306,641 | <p>I am implementing a validation class in classic ASP. How should the validation class interface with my other classes? </p>
<p>My current setup:
The User class's set methods call the appropriate validation method in the validation class. Any errors that occur are stored in User.mError. For example, here's my set method for the Email member variable in ASP Classic:</p>
<pre><code>Class User
Property Let Email(EmailInput)
If (myValidation.isEmail(EmailInput)) then
mEmail = EmailInput
Else
mError = "Invalid Email Address format."
End If
</code></pre>
<p>I don't like how I'm going to need an error member variable for every object that calls my validation class. Suggestions on a better setup?</p>
<p>Any suggestions for a validation architecture I should review as a benchmark?</p>
| [
{
"answer_id": 306823,
"author": "shahkalpesh",
"author_id": 23574,
"author_profile": "https://Stackoverflow.com/users/23574",
"pm_score": 0,
"selected": false,
"text": "\nPsuedo Code.\n\nclass EmailValidator\n...\nfunction Validate(byval EmailAddress as string, optional byval Result as string) as boolean)\n..\nif (condition success)\nresult = success\nelseif (emailafddress doesnt have @)\nresult = \"invalid email address. missing @\"\nendif\nend function\nend class\n"
},
{
"answer_id": 306873,
"author": "localshred",
"author_id": 29690,
"author_profile": "https://Stackoverflow.com/users/29690",
"pm_score": 0,
"selected": false,
"text": "class Validation\n{\n\n // define the properties for dealing with different type validations\n public static $firstNamePattern = '/[-a-zA-Z0-9._ ]{2,}/';\n public static $lastNamePattern = '/[-a-zA-Z0-9._ ]{2,}/';\n // ... more fields\n\n\n public static function validateText($type, $text, $fieldName)\n {\n $pattern = $type.\"Pattern\";\n if ($this->$pattern != '')\n {\n // perfom the validation\n // ...\n return true; // or false\n }\n }\n\n // other validation methods below\n // ...\n\n}\n"
},
{
"answer_id": 307747,
"author": "Michal",
"author_id": 21672,
"author_profile": "https://Stackoverflow.com/users/21672",
"pm_score": 2,
"selected": false,
"text": "class User\n public firstname\n public lastname\n\n 'validates the user instance\n '- call before save()\n public function isValid(byRef v)\n isValid = true\n if len(firstname) < 5 then\n v.add \"firstname\", \"Firstname must be at least 5 chars long.\"\n isValid = false\n end if\n if len(lastname) < 5 then\n v.add \"lastname\", \"Lastname must be at least 5 chars long.\"\n isValid = false\n end if\n end function\n\n public sub save()\n 'do some DB stuff\n end sub\nend class\n\n'usage scenario 1 (simple - we just know if valid or not)\nset u = new User\nif u.isValid(new Validator) then\n u.save()\nelse\n response.write(\"User is invalid. some error happend\")\nend if\n\n'usage scenario 2 (detailed - we have an error summary)\nset u = new User\nu.firstname = \"Michal\"\nset v = new Validator\nif u.isValid(v) then\n u.save()\nelse\n 'the validator offers a helper to create a validation summary\n response.write(v.getErrorSummary(\"<div><ul>\", \"<ul/></div>\", \"<li>\", \"</li>\"))\nend if\n\n'usage scenario 3 (we can even validator more users in one go)\nset u1 = new User\nset u2 = new User\nset v = new Validator\nu1.isValid(v)\nu2.isValid(v)\n\nif v then\n u1.save()\n u2.save()\nelse\n response.write(\"something is invalid\")\nend if\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306641",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26180/"
] |
306,642 | <p>How can I retrieve raw time-series data from a Proficy Historian/iHistorian?</p>
<p>Ideally, I would ask for data for a particular tag between two dates.</p>
| [
{
"answer_id": 306646,
"author": "Michael Haren",
"author_id": 29,
"author_profile": "https://Stackoverflow.com/users/29",
"pm_score": 2,
"selected": false,
"text": "<add name=\"HistorianConnectionString\" \n providerName=\"ihOLEDB.iHistorian.1\" \n connectionString=\"\n Provider=ihOLEDB.iHistorian;\n User Id=;\n Password=;\n Data Source=localhost;\"\n/>\n"
},
{
"answer_id": 3320405,
"author": "Brian Gideon",
"author_id": 158779,
"author_profile": "https://Stackoverflow.com/users/158779",
"pm_score": 5,
"selected": true,
"text": "C:\\Program Files\\GE Fanuc\\Proficy Historian\\Docs\\iHistorian.chm"
},
{
"answer_id": 38559214,
"author": "rollsch",
"author_id": 434537,
"author_profile": "https://Stackoverflow.com/users/434537",
"pm_score": 0,
"selected": false,
"text": "[DllImport(\"IHUAPI.dll\", CallingConvention = CallingConvention.StdCall, EntryPoint = \"ihuReadRawDataByTime@24\")]\npublic static extern int ihuReadRawDataByTime(int serverhandle, string tagname, ref IHU_TIMESTAMP startTime, ref IHU_TIMESTAMP endTime, ref int noOfSamples, ref IHU_DATA_SAMPLE* dataValues);\n...\nprivate int _handle;\n\npublic HistorianTypes.ErrorCode ReadRawByTime(string tagName, DateTime startTime, DateTime endTime,\n out double[] timeStamps, out double[] values, out IhuComment [] comments)\n{\n var startTimeStruct = new IhuApi.IHU_TIMESTAMP(); //Custom datetime to epoch extension method\n var endTimeStruct = new IhuApi.IHU_TIMESTAMP();\n\n int lRet = 0;\n int noOfSamples = 0;\n startTimeStruct = DateTimeToTimeStruct(dstZone.ToUniversalTime(startTime));\n endTimeStruct = DateTimeToTimeStruct(dstZone.ToUniversalTime(endTime));\n IhuApi.IHU_DATA_SAMPLE* dataSample = (IhuApi.IHU_DATA_SAMPLE*)new IntPtr(0);\n\n try {\n lRet = IhuApi.ihuReadRawDataByTime\n (\n _handle, // the handle returned from the connect\n tagName, // the single tagname to retrieve\n ref startTimeStruct, // start time for query\n ref endTimeStruct, // end time for query\n ref noOfSamples, // will be set by API\n ref dataSample // will be allocated and populated in the user API\n );\n ....\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306642",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29/"
] |
306,668 | <p>I've been preaching both to my colleagues and here on SO about the goodness of using parameters in SQL queries, especially in .NET applications. I've even gone so far as to promise them as giving immunity against SQL injection attacks.</p>
<p>But I'm starting to wonder if this really is true. Are there any known SQL injection attacks that will be successfull against a parameterized query? Can you for example send a string that causes a buffer overflow on the server?</p>
<p>There are of course other considerations to make to ensure that a web application is safe (like sanitizing user input and all that stuff) but now I am thinking of SQL injections. I'm especially interested in attacks against MsSQL 2005 and 2008 since they are my primary databases, but all databases are interesting. </p>
<p>Edit: To clarify what I mean by parameters and parameterized queries. By using parameters I mean using "variables" instead of building the sql query in a string.<br>
So instead of doing this: </p>
<pre><code>SELECT * FROM Table WHERE Name = 'a name'
</code></pre>
<p>We do this:</p>
<pre><code>SELECT * FROM Table WHERE Name = @Name
</code></pre>
<p>and then set the value of the @Name parameter on the query / command object.</p>
| [
{
"answer_id": 306675,
"author": "Adam Bellaire",
"author_id": 21632,
"author_profile": "https://Stackoverflow.com/users/21632",
"pm_score": 7,
"selected": true,
"text": "security_level"
},
{
"answer_id": 306676,
"author": "Steven A. Lowe",
"author_id": 9345,
"author_profile": "https://Stackoverflow.com/users/9345",
"pm_score": 3,
"selected": false,
"text": "create procedure dbo.uspBeAfraidBeVeryAfraid ( @p1 varchar(64) ) \nAS\n SET NOCOUNT ON\n declare @sql varchar(512)\n set @sql = 'select * from ' + @p1\n exec(@sql)\nGO\n"
},
{
"answer_id": 306818,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 4,
"selected": false,
"text": "'SELECT * FROM mytable WHERE colname = ?'\n"
},
{
"answer_id": 306981,
"author": "HTTP 410",
"author_id": 13118,
"author_profile": "https://Stackoverflow.com/users/13118",
"pm_score": 4,
"selected": false,
"text": "exec dbo.MyStoredProc 'DodgyText'\n"
},
{
"answer_id": 5637172,
"author": "Mohamed Abbas",
"author_id": 365716,
"author_profile": "https://Stackoverflow.com/users/365716",
"pm_score": 1,
"selected": false,
"text": "DECLARE @SQL NVARCHAR(4000);\nDECLARE @ParameterDefinition NVARCHAR(4000);\n\nSELECT @ParameterDefinition = '@date varchar(10)'\n\nSET @SQL='Select CAST(@date AS DATETIME) Date'\n\nEXEC sp_executeSQL @SQL,@ParameterDefinition,@date='04/15/2011'\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306668",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30366/"
] |
306,679 | <p>If a line of text is wrapped to an additional line, how do I determine programmatically the point in the string where it was broken.</p>
<p>Example: Input string = "This is a test of a wrapped line of text".</p>
<pre><code> Based on the width of the richTextBox it could display:
This is a test of a wrapped line of
text.
</code></pre>
<p>What I need to determine is offset in the line of the word(s) that got wrapped. In the above case the word "text".</p>
<p>When I extract the Xaml from the richTextBox, I get the original text unwrapped.</p>
<p>Thanks,</p>
<p>Bob Kerlinger</p>
| [
{
"answer_id": 313168,
"author": "Mike Two",
"author_id": 23659,
"author_profile": "https://Stackoverflow.com/users/23659",
"pm_score": 2,
"selected": false,
"text": "public partial class Window1 : Window\n{\n public Window1()\n {\n InitializeComponent();\n }\n\n private void inspect(object sender, RoutedEventArgs e)\n {\n TextPointer pointer = FindRun(inBox.Document);\n\n string textAfterBreak = FindBreak(pointer);\n\n outBox.Text = textAfterBreak;\n }\n\n private string FindBreak(TextPointer pointer)\n {\n Rect rectAtStart = pointer.GetCharacterRect(LogicalDirection.Forward);\n\n pointer = pointer.GetNextInsertionPosition(LogicalDirection.Forward);\n Rect currentRect = pointer.GetCharacterRect(LogicalDirection.Forward);\n\n while (currentRect.Bottom == rectAtStart.Bottom)\n {\n pointer = pointer.GetNextInsertionPosition(LogicalDirection.Forward);\n currentRect = pointer.GetCharacterRect(LogicalDirection.Forward);\n }\n\n string textBeforeBreak = pointer.GetTextInRun(LogicalDirection.Backward);\n string textAfterBreak = pointer.GetTextInRun(LogicalDirection.Forward);\n\n return textAfterBreak;\n }\n\n private TextPointer FindRun(FlowDocument document)\n {\n TextPointer position = document.ContentStart;\n\n while (position != null)\n {\n if (position.Parent is Run)\n break;\n\n position = position.GetNextContextPosition(LogicalDirection.Forward);\n }\n\n return position;\n }\n}\n\n<Window x:Class=\"LineBreaker.Window1\"\n xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n Title=\"Window1\" Height=\"300\" Width=\"300\">\n <Grid>\n <Grid.RowDefinitions>\n <RowDefinition></RowDefinition>\n <RowDefinition></RowDefinition>\n <RowDefinition></RowDefinition>\n </Grid.RowDefinitions>\n <RichTextBox Grid.Row=\"0\" Name=\"inBox\">\n </RichTextBox>\n <Button Grid.Row=\"1\" Click=\"inspect\">Find Break</Button>\n <TextBox Name=\"outBox\" Grid.Row=\"2\"/>\n </Grid>\n</Window>\n"
},
{
"answer_id": 313308,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "TextPointer startOfFirstLine = richTextBox.Document.ContentStart;\nTextPointer startOfNextLine = startOfFirstLine.GetLineStartPosition(1);\nif(startOfNextLine != null)\n{\n // At this point what you do with the TextPointer depends on what you define as the position of text.\n // If you want to find out how many characters are on the first line ...\n int firstLineCharacterCount = new TextRange(startOfFirstLine, startOfNextLine).Text.Length;\n}\n"
},
{
"answer_id": 454700,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "startOfFirstLine.GetLineStartPosition(1)"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306679",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37918/"
] |
306,684 | <p>I've encountered a weird situation:</p>
<p>Messages are sent from ServerA to ServerB. It goes into ServerA outgoing queue and then sent to ServerB's queue.</p>
<p>ServerB crashed. We had to reformat. When we brought it up, we forgot to install the MSMQ Service.</p>
<p>Messages begin pilling up in ServerA's outgoing queue until the program that sends messages throws an insufficient resources exception.</p>
<p>We notice the the error and installed the MSMQ Service onto ServerB. ServerA begins to immediately emptying its outgoing queue.</p>
<p>When we started the program to process messages on ServerB, it couldn't connect. We learned that we forgot to create the queue on ServerB. However, by this time, it was too late. All 900K messages that sat in ServerA's queue has been sent to ServerB. From what I can tell, ServerB threw them away because it was not configured with the destination queue. I already know that the correct solution is to STOP the queue on ServerA until after we've completely setup ServerB.</p>
<p>The question is: Is this really the true behavior that we should expect from MSMQ? I would've thought that a more defensive design approach would've been for ServerB to reject the messages instead of taking it and throwing them away.</p>
| [
{
"answer_id": 546587,
"author": "Carlos A. Ibarra",
"author_id": 37835,
"author_profile": "https://Stackoverflow.com/users/37835",
"pm_score": 3,
"selected": true,
"text": "MQ_SEND_ACCESS"
},
{
"answer_id": 18854569,
"author": "barrypicker",
"author_id": 415559,
"author_profile": "https://Stackoverflow.com/users/415559",
"pm_score": 0,
"selected": false,
"text": "var message = new System.Messaging.Message();\nmessage.UseDeadLetterQueue = true;\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306684",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13484/"
] |
306,709 | <p>I've been using SVN a lot as a single user on a single computer</p>
<p>Now I'd like to share my stuff across multiple computers</p>
<p>So far I've been checking out from <code>file://c:/myproject</code></p>
<p>I'd like to checkout from <code>svn://mycomputer/myproject</code></p>
<p>How can I map the first into the second?</p>
| [
{
"answer_id": 306834,
"author": "localshred",
"author_id": 29690,
"author_profile": "https://Stackoverflow.com/users/29690",
"pm_score": 2,
"selected": false,
"text": "svnserve -d -r /path/to/repos/\n"
},
{
"answer_id": 451002,
"author": "Christian Studer",
"author_id": 6260,
"author_profile": "https://Stackoverflow.com/users/6260",
"pm_score": 1,
"selected": false,
"text": "scn checkout svn+ssh://USERNAME@mycomputer/ABSOLUTE/PATH/TO/REPOSITORY\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306709",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6367/"
] |
306,713 | <p>I'm having some trouble navigating Java's rule for inferring generic type parameters. Consider the following class, which has an optional list parameter:</p>
<pre><code>import java.util.Collections;
import java.util.List;
public class Person {
private String name;
private List<String> nicknames;
public Person(String name) {
this(name, Collections.emptyList());
}
public Person(String name, List<String> nicknames) {
this.name = name;
this.nicknames = nicknames;
}
}
</code></pre>
<p>My Java compiler gives the following error:</p>
<pre><code>Person.java:9: The constructor Person(String, List<Object>) is undefined
</code></pre>
<p>But <code>Collections.emptyList()</code> returns type <code><T> List<T></code>, not <code>List<Object></code>. Adding a cast doesn't help</p>
<pre><code>public Person(String name) {
this(name,(List<String>)Collections.emptyList());
}
</code></pre>
<p>yields</p>
<pre><code>Person.java:9: inconvertible types
</code></pre>
<p>Using <code>EMPTY_LIST</code> instead of <code>emptyList()</code></p>
<pre><code>public Person(String name) {
this(name, Collections.EMPTY_LIST);
}
</code></pre>
<p>yields</p>
<pre><code>Person.java:9: warning: [unchecked] unchecked conversion
</code></pre>
<p>Whereas the following change makes the error go away:</p>
<pre><code>public Person(String name) {
this.name = name;
this.nicknames = Collections.emptyList();
}
</code></pre>
<p>Can anyone explain what type-checking rule I'm running up against here, and the best way to work around it? In this example, the final code example is satisfactory, but with larger classes, I'd like to be able to write methods following this "optional parameter" pattern without duplicating code.</p>
<p>For extra credit: when is it appropriate to use <code>EMPTY_LIST</code> as opposed to <code>emptyList()</code>?</p>
| [
{
"answer_id": 306748,
"author": "carson",
"author_id": 25343,
"author_profile": "https://Stackoverflow.com/users/25343",
"pm_score": 7,
"selected": false,
"text": "Collections.<String>emptyList();\n"
},
{
"answer_id": 306750,
"author": "Dan Vinton",
"author_id": 21849,
"author_profile": "https://Stackoverflow.com/users/21849",
"pm_score": 5,
"selected": false,
"text": "public static final <T> List<T> emptyList()\n"
},
{
"answer_id": 306773,
"author": "InverseFalcon",
"author_id": 39455,
"author_profile": "https://Stackoverflow.com/users/39455",
"pm_score": 10,
"selected": true,
"text": "emptyList()"
},
{
"answer_id": 64264059,
"author": "Lii",
"author_id": 452775,
"author_profile": "https://Stackoverflow.com/users/452775",
"pm_score": 1,
"selected": false,
"text": "public Person(String name) {\n this(name, Collections.emptyList()); // Inferred to List<String> in Java 8\n}\n\npublic Person(String name, List<String> nicknames) {\n this.name = name;\n this.nicknames = nicknames;\n}\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1412/"
] |
306,722 | <p>I have a table in my MYSQL database which does not have a primary key, but has a unique key on two columns. When using MyEclipse's Hibernate reverse engineer tool to create a mapping for that table, it generates two classes, one for named after the table itself, and one with an "Id" suffix. It seems most of the useful methods ended up in the Id class, so it seems that is the one you would instantiate and save to persist data. I can appreciate the fact that the Id class is created in order to represent a unique row in the table / mapped object, but what is the use of splitting out this into two classes, and what, then is the use of the non-Id-suffixed class?</p>
<p>My colleague argues you can accomplish the same with just one class and scoffs at using the reverse engineering for these tables which don't have a primary key. I, on the other hand, assume MyEclipse developers are much smarter than me and that there is a really good reason to do it this way. Is there?</p>
| [
{
"answer_id": 306748,
"author": "carson",
"author_id": 25343,
"author_profile": "https://Stackoverflow.com/users/25343",
"pm_score": 7,
"selected": false,
"text": "Collections.<String>emptyList();\n"
},
{
"answer_id": 306750,
"author": "Dan Vinton",
"author_id": 21849,
"author_profile": "https://Stackoverflow.com/users/21849",
"pm_score": 5,
"selected": false,
"text": "public static final <T> List<T> emptyList()\n"
},
{
"answer_id": 306773,
"author": "InverseFalcon",
"author_id": 39455,
"author_profile": "https://Stackoverflow.com/users/39455",
"pm_score": 10,
"selected": true,
"text": "emptyList()"
},
{
"answer_id": 64264059,
"author": "Lii",
"author_id": 452775,
"author_profile": "https://Stackoverflow.com/users/452775",
"pm_score": 1,
"selected": false,
"text": "public Person(String name) {\n this(name, Collections.emptyList()); // Inferred to List<String> in Java 8\n}\n\npublic Person(String name, List<String> nicknames) {\n this.name = name;\n this.nicknames = nicknames;\n}\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306722",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
306,732 | <p>I have a Freemarker template which contains a bunch of placeholders for which values are supplied when the template is processed. I want to conditionally include part of the template if the userName variable is supplied, something like:</p>
<pre><code>[#if_exists userName]
Hi ${userName}, How are you?
[/#if_exists]
</code></pre>
<p>However, the FreeMarker manual seems to indicate that if_exists is deprecated, but I can't find another way to achieve this. Of course, I could simple providing an additional boolean variable isUserName and use that like this:</p>
<pre><code>[#if isUserName]
Hi ${userName}, How are you?
[/#if]
</code></pre>
<p>But if there's a way of checking whether userName exists then I can avoid adding this extra variable.</p>
| [
{
"answer_id": 306749,
"author": "Ulf Lindback",
"author_id": 30354,
"author_profile": "https://Stackoverflow.com/users/30354",
"pm_score": 9,
"selected": true,
"text": "[#if userName??]\n Hi ${userName}, How are you?\n[/#if]\n"
},
{
"answer_id": 306766,
"author": "Ulf Lindback",
"author_id": 30354,
"author_profile": "https://Stackoverflow.com/users/30354",
"pm_score": 6,
"selected": false,
"text": "Hi ${userName?if_exists}, How are you?\n"
},
{
"answer_id": 11614342,
"author": "user1546081",
"author_id": 1546081,
"author_profile": "https://Stackoverflow.com/users/1546081",
"pm_score": 7,
"selected": false,
"text": "<#if userName?has_content>\n... do something\n</#if>\n"
},
{
"answer_id": 23616781,
"author": "Jake Toronto",
"author_id": 1930619,
"author_profile": "https://Stackoverflow.com/users/1930619",
"pm_score": 3,
"selected": false,
"text": "<#if p?? && p?has_content>1</#if>\n"
},
{
"answer_id": 49691421,
"author": "Petter Friberg",
"author_id": 5292302,
"author_profile": "https://Stackoverflow.com/users/5292302",
"pm_score": 2,
"selected": false,
"text": "??"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2648/"
] |
306,743 | <p>What is the most efficient way to detect duplicates in a 10 column / 50K row table? I'm using MSSQL 8.0</p>
| [
{
"answer_id": 306756,
"author": "Guge",
"author_id": 37771,
"author_profile": "https://Stackoverflow.com/users/37771",
"pm_score": 4,
"selected": false,
"text": "group by"
},
{
"answer_id": 306789,
"author": "Aaron Palmer",
"author_id": 24908,
"author_profile": "https://Stackoverflow.com/users/24908",
"pm_score": 2,
"selected": false,
"text": "select fieldA, fieldB, count(*) from table\ngroup by fieldA, fieldB\nhaving count(*) > 1\n"
},
{
"answer_id": 306798,
"author": "Charles Bretana",
"author_id": 32632,
"author_profile": "https://Stackoverflow.com/users/32632",
"pm_score": 3,
"selected": false,
"text": "Select * From Table\nGroup By [List all fields in the Table here]\nHaving Count(*) > 1\n"
},
{
"answer_id": 306803,
"author": "knightpfhor",
"author_id": 17089,
"author_profile": "https://Stackoverflow.com/users/17089",
"pm_score": 7,
"selected": true,
"text": "SELECT\n Col1, -- All of the columns you want to dedupe on\n Col2, -- which is not neccesarily all of the columns\n Col3, -- in the table\n Col4,\n Col5,\n Col6,\n Col7,\n Col8,\n Col9,\n Col10\nFROM\n MyTable\nGROUP BY\n Col1,\n Col2,\n Col3,\n Col4,\n Col5,\n Col6,\n Col7,\n Col8,\n Col9,\n Col10\nHAVING\n COUNT(*) > 1\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306743",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39426/"
] |
306,757 | <p><strong>Given:</strong> Constructing an ADO Connection object from one thread and giving it to another thread is <strong><em>forbidden</em></strong>. The two threads are different apartments, and even though the first thread will <strong>never</strong> touch it again (not even maintain a reference to it!), it doesn't matter. </p>
<p>That ADO Connection object was created by ThreadA, ThreadA is the only thread, ever, under any circumstances, at all, ever, that is allowed to use that Connection object, ever.</p>
<p>Now replace "ADO Connection" with "ADO.NET Connection". Does the same rule apply?</p>
<hr>
<p>i know that most objects in the .NET framework are not thread-safe. For example, the <a href="http://msdn.microsoft.com/en-us/library/system.collections.dictionaryentry.aspx" rel="nofollow noreferrer">DictionaryEntry</a> structure in the SDK says: </p>
<blockquote>
<p><strong>Thread Safety</strong><br>
Any public <strong>static</strong> members of
this type are thread safe. Any
instance members are not guaranteed to
be thread safe.</p>
</blockquote>
<p>i understand that <strong>not thread-safe</strong> means that i have to synchronize access to the object if i am going to access it from different threads. That's all well and good, and i could ensure only one thread access the object at a time:</p>
<pre><code>lock (myObject)
{
...
}
</code></pre>
<p>But there's something more than not being thread-safe. </p>
<p>In COM, (some) objects are bound to the "<em>apartment</em>" that created it. Once the object has been constructed on one apartment, you are <strong><em>forbidden</em></strong> from accessing it from another apartment - no matter how much you protect that object from multiple simultaneous thread access.</p>
<p>Does a similar concept exist in .NET? </p>
<hr>
<h2>More Information</h2>
<p>i know you are forbidden from accessing Controls from threads other than the one that created it - even if you use it in a thread-safe manner. This is not documented on MSDN:</p>
<blockquote>
<p><strong>Thread Safety</strong></p>
<p>Only the following members are thread
safe: BeginInvoke, EndInvoke, Invoke,
InvokeRequired, and CreateGraphics if
the handle for the control has already
been created. Calling CreateGraphics
before the control's handle has been
created on a background thread can
cause illegal cross thread calls.</p>
</blockquote>
<p>There is no mention of Controls throwing exceptions when you create and use them from a single thread - when that thread is not the first thread that was created when the application started.</p>
<p>But what about arbitrary objects? What about:</p>
<pre><code>public class MyClass
{
int _number;
public int Number { get { return _number; } set { _number = value; } }
}
MyClass myObject = new MyClass();
</code></pre>
<p>As long as i synchronize access to myObject two threads are allowed to talk to it?</p>
<hr>
<p>The same goes for:</p>
<pre><code>List<Object> sharedList = new List<Object>();
</code></pre>
<p>Two threads can talk to the list, as long as they don't do it simultaneously, usually with:</p>
<pre><code>lock (sharedList)
{
sharedList.Add(data);
}
</code></pre>
<p>are two threads allowed to touch the same object?</p>
<hr>
<p>The same goes for:</p>
<pre><code>IAsyncResult ar = BeginSetLabelToTheValueINeed(label1);
...
EndSetLabelToTheValueINeed(ar);
</code></pre>
<hr>
<p>The same goes for:</p>
<pre><code>//Fetch image on connection that is an existing DB transaction
public static Bitmap GetImageThumbnail(DbConnection conn, int imageID)
{
}
</code></pre>
<p>being converted into the asynchronous delegate pattern:</p>
<pre><code>//Begin fetching an image on connection that is an existing DB transaction
IAsyncResult ar = BeginGetImageThumbnuts(conn, imageID, callback, stateOjbect);
...
//Finish fetching an image on connection that is an existing DB transaction
Bitmap thumb = EndGetImageNumbthail(ar);
</code></pre>
<hr>
<p>Rather than answering the question, people went off on a discussion about design patterns in ADO.NET. Please answer the question. Ignore the examples if they confuse and distract your squirrel brains.</p>
| [
{
"answer_id": 483780,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 1,
"selected": false,
"text": "public class MyClass\n{\n int _number;\n\n public int Number { get { return _number; } set { _number = value; } }\n}\n\nMyClass myObject = new MyClass();\n"
},
{
"answer_id": 484140,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": true,
"text": "SqlConnection sc = new SqlConnection();\nvar data = AppDomain.CurrentDomain.GetAssemblies()\n .Where(x => x.FullName.StartsWith(\"System.Data,\")).First();\nvar dtypes = data.GetTypes();\nvar results = new List<string>();\nforeach (var type in dtypes)\n foreach (var method in type.GetMethods())\n foreach (var attr in \n method.GetCustomAttributes(true).OfType<System.Attribute>())\n {\n results.Add(string.Format(\"{0} {1} {2}\", \n type.Name, method.Name, attr.GetType().Name));\n if (attr.GetType() == typeof(STAThreadAttribute)) \n throw new Exception(\"SHIII\");\n }\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12597/"
] |
306,779 | <p>I have a PPPOE connection on a computer. That computer has two LAN cards and I activated ICS on it. The problem is, the connection kinda degrades over time (don't know why), and a redial would be nice, hourly maybe. I was thinking of writing an AutoIT script that would do this, if, for example I'm sending some data to a port the gateway pc is listening on. The only trouble is, I don't know what's the name of the executable I would have to run.</p>
<p>EDIT: I'm interested in the one with the GUI.</p>
<p>EDIT 2: I am interested in automating this process, and wouldn't like to have to write the thing in AutoIT (this a last resort option).</p>
| [
{
"answer_id": 484495,
"author": "sven",
"author_id": 46,
"author_profile": "https://Stackoverflow.com/users/46",
"pm_score": 3,
"selected": true,
"text": "rasdial connectionname\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31610/"
] |
306,788 | <p>How do I check if the timestamp date of a record is before midnight today?</p>
<p>datediff is driving me nuts...</p>
| [
{
"answer_id": 306794,
"author": "Cade Roux",
"author_id": 18255,
"author_profile": "https://Stackoverflow.com/users/18255",
"pm_score": 3,
"selected": false,
"text": "WHERE dtColumn < DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))\n"
},
{
"answer_id": 306802,
"author": "StingyJack",
"author_id": 16391,
"author_profile": "https://Stackoverflow.com/users/16391",
"pm_score": 2,
"selected": true,
"text": "SELECT (CAST(FLOOR(CAST(GETDATE() as FLOAT)) AS DateTime))\n"
},
{
"answer_id": 306814,
"author": "John MacIntyre",
"author_id": 29043,
"author_profile": "https://Stackoverflow.com/users/29043",
"pm_score": 0,
"selected": false,
"text": "where myColumn < cast( (cast(getdate() - 0.5 as int)) as datetime)\n"
},
{
"answer_id": 307221,
"author": "Charles Bretana",
"author_id": 32632,
"author_profile": "https://Stackoverflow.com/users/32632",
"pm_score": 0,
"selected": false,
"text": "Select Case DateDiff(day, columnName, getDate()) \n When 0 Then 'Today' Else 'Earlier' End\nFrom TableName\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306788",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/750/"
] |
306,806 | <p>I have the following entity class (in Groovy):</p>
<pre><code>import javax.persistence.Entity
import javax.persistence.Id
import javax.persistence.GeneratedValue
import javax.persistence.GenerationType
@Entity
public class ServerNode {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id
String firstName
String lastName
}
</code></pre>
<p>and my persistence.xml:</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="NewPersistenceUnit">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/Icarus"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hbm2ddl.auto" value="create"/>
</properties>
<class>net.interaxia.icarus.data.models.ServerNode</class>
</persistence-unit>
</persistence>
</code></pre>
<p>and the script:</p>
<pre><code>import javax.persistence.EntityManager
import javax.persistence.EntityManagerFactory
import javax.persistence.Persistence
import net.interaxia.icarus.data.models.ServerNode
def factory = Persistence.createEntityManagerFactory("NewPersistenceUnit")
def manager = factory.createEntityManager()
manager.getTransaction().begin()
manager.persist new ServerNode(firstName: "Test", lastName: "Server")
manager.getTransaction().commit()
</code></pre>
<p>the database <em>Icarus</em> exists, but currently has no tables. I would like Hibernate to automatically create and/or update the tables based on the entity classes. How would I accomplish this?</p>
| [
{
"answer_id": 306825,
"author": "billjamesdev",
"author_id": 13824,
"author_profile": "https://Stackoverflow.com/users/13824",
"pm_score": 6,
"selected": false,
"text": "<property name=\"hbm2ddl.auto\" value=\"create\"/>\n"
},
{
"answer_id": 306875,
"author": "toolkit",
"author_id": 3295,
"author_profile": "https://Stackoverflow.com/users/3295",
"pm_score": 8,
"selected": true,
"text": "hibernate"
},
{
"answer_id": 16825571,
"author": "Harbir",
"author_id": 802740,
"author_profile": "https://Stackoverflow.com/users/802740",
"pm_score": 3,
"selected": false,
"text": "<property name=\"hibernate.hbm2ddl.auto\" value=\"create\"/>\n"
},
{
"answer_id": 37325142,
"author": "thorinkor",
"author_id": 1207102,
"author_profile": "https://Stackoverflow.com/users/1207102",
"pm_score": 2,
"selected": false,
"text": "hibernate.hbm2ddl.auto"
},
{
"answer_id": 43422897,
"author": "Yusuf Aksun",
"author_id": 6226786,
"author_profile": "https://Stackoverflow.com/users/6226786",
"pm_score": 0,
"selected": false,
"text": "<bean id=\"entityManagerFactoryBean\" class=\"org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean\">\n <property name=\"dataSource\" ref=\"dataSource\" />\n <!-- This makes /META-INF/persistence.xml is no longer necessary -->\n <property name=\"packagesToScan\" value=\"com.howtodoinjava.demo.model\" />\n <!-- JpaVendorAdapter implementation for Hibernate EntityManager.\n Exposes Hibernate's persistence provider and EntityManager extension interface -->\n <property name=\"jpaVendorAdapter\">\n <bean class=\"org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter\" />\n </property>\n <property name=\"jpaProperties\">\n <props>\n <prop key=\"hibernate.hbm2ddl.auto\">update</prop>\n <prop key=\"hibernate.dialect\">org.hibernate.dialect.MySQL5Dialect</prop>\n </props>\n </property>\n </bean>\n"
},
{
"answer_id": 47741227,
"author": "DevDio",
"author_id": 5294016,
"author_profile": "https://Stackoverflow.com/users/5294016",
"pm_score": 3,
"selected": false,
"text": "<properties>\n <property name=\"hibernate.archive.autodetection\" value=\"class\"/>\n <property name=\"hibernate.show_sql\" value=\"true\"/>\n <property name=\"hibernate.format_sql\" value=\"true\"/>\n <property name=\"hbm2ddl.auto\" value=\"create-drop\"/>\n <!-- without below table was not created -->\n <property name=\"javax.persistence.schema-generation.database.action\" value=\"drop-and-create\" />\n</properties>\n"
},
{
"answer_id": 69098659,
"author": "Rizwan Ali",
"author_id": 11517372,
"author_profile": "https://Stackoverflow.com/users/11517372",
"pm_score": 1,
"selected": false,
"text": " <property name=\"hbm2ddl.auto\">update</property> \n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306806",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18811/"
] |
306,839 | <p>Is there a way to reuse a 3rd party control reference?</p>
<p>For example, I have this referenced in my App.xaml</p>
<pre><code>xmlns:cust="clr-namespace:ThirdParty.Controls;assembly=ThirdParty.Controls"
</code></pre>
<p>I don't want to repeat this 3rd party control xml namespace on each page/control that needs a control from the library. </p>
<p>Is there anyway to centralize these references and use the prefix defined here? The possibility of each control having a different prefix is also worrisome. In asp.net you would put a reference in the web.config and it was available globally, I'm just looking to see if there is a similar method in WPF.</p>
| [
{
"answer_id": 306990,
"author": "Jobi Joy",
"author_id": 8091,
"author_profile": "https://Stackoverflow.com/users/8091",
"pm_score": 3,
"selected": true,
"text": "<ContentControl Template=\"{DynamicResource thirdPartyControlTemplate}\" />\n"
},
{
"answer_id": 307032,
"author": "Bryan Anderson",
"author_id": 21186,
"author_profile": "https://Stackoverflow.com/users/21186",
"pm_score": 0,
"selected": false,
"text": "<ControlTemplate TargetType=\"Label\" \n xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" \n xmlns:s=\"clr-namespace:System;assembly=mscorlib\" \n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306839",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29676/"
] |
306,840 | <p>I have a working makefile that builds with mingw32. Now i renamed that makefile to Makefile.w32 (source -> <a href="http://pastie.org/319964" rel="nofollow noreferrer">http://pastie.org/319964</a>)</p>
<p>Now i have a Makefile with the following. The problem is, it does not build my source</p>
<pre><code>all:
make mingw32
clean:
@echo "causes an infinite loop -> make mingw32 clean"
mingw32:
@echo "yeahhhhhhhhh"
make Makefile.w32
mingw32-clean:
@echo "mingw clean"
make Makefile.w32 clean
</code></pre>
<p>result:</p>
<pre><code>> "make"
make mingw32
make[1]: Entering directory `/c/nightly/test'
yeahhhhhhhhh
make Makefile.w32
make[2]: Entering directory `/c/nightly/test'
make[2]: Nothing to be done for `Makefile.w32'.
make[2]: Leaving directory `/c/nightly/test'
make[1]: Leaving directory `/c/nightly/test'
</code></pre>
<p>It seems to me it doesn't like Makefile.w32 extension. I dont understand why it isn't building. It;s obviously getting to my "make Makefile.w32" line.</p>
| [
{
"answer_id": 306854,
"author": "Sherm Pendley",
"author_id": 27631,
"author_profile": "https://Stackoverflow.com/users/27631",
"pm_score": 3,
"selected": true,
"text": "make -f Makefile.w32\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306840",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
306,852 | <p>I have a C# application that is a client to a web service. One of my requirements is to allow capturing the SOAP that I send, so that if there is a problem, I can either fix the bug, or demonstrate that the problem is in the service I am calling.</p>
<p>My WebReference proxy service class derives from <code>System.Web.Services.Protocols.SoapHttpClientProtocol</code> as usual. If I had a magic wand, I would make this base class implement an event <code>OnPost</code> that I could handle to write the SOAP into my logs and continue.</p>
<p>Short of running a packet sniffer like WireShark, is there an easy way to get this level of logging?</p>
| [
{
"answer_id": 21592590,
"author": "bnieland",
"author_id": 279393,
"author_profile": "https://Stackoverflow.com/users/279393",
"pm_score": 2,
"selected": false,
"text": "mySoapHttpClientProtocol.Url = mySoapHttpClientProtocol.Url.Replace(\"localhost\", \"localhost.fiddler\");\n"
},
{
"answer_id": 22837772,
"author": "uzay95",
"author_id": 104085,
"author_profile": "https://Stackoverflow.com/users/104085",
"pm_score": 0,
"selected": false,
"text": " <endpoint address=\"http://localhost.:8868/FEInvoice.asmx\" binding=\"basicHttpBinding\"\n bindingConfiguration=\"FEInvoice_Test\" contract=\"EInvoiceIntegration.FEInvoiceSoap\"\n name=\"FEInvoice_Test\" />\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306852",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7475/"
] |
306,859 | <p>I have a ContextMenuStrip that contains a submenu of dynamically generated ToolStripMenuItems. There are up to 80 sub menu items. Pressing the first letter of a desired menu item selects it correctly, but if the item happens to be out of the visible range (in a range handled by the scroll arrows), it isn't displayed - the user has to press the up arrow and then the down arrow for the desired option to be displayed & focussed on the screen.</p>
<p>As an example, I have 6 items starting with "m" but only 3.5 are visible. I hit m one and the first item is highlighted, I hit m 3 more times and I can see half a selected row (it's at the bottom of the visible area), hit m two more times, and I can't see the select row, then m one more time and the first m entry is visible and selected again.</p>
<p>By default ToolStripMenuItems (TSMI) don't have key listeners available, however if I subclass the TSMI I can catch ProcessDialogKey and ProcessCmdKey and manually select the right option, but I am unable to scroll the toolstrip sub menu down to ensure my option is visible.</p>
<p>Any tips on how to either:</p>
<p><strong>a)</strong> scroll a tool strip's sub menu </p>
<p>or</p>
<p><strong>b)</strong> allow the sub menu to use multiple columns (and hope the user doesn't have a ridiculously low resolution).</p>
| [
{
"answer_id": 21592590,
"author": "bnieland",
"author_id": 279393,
"author_profile": "https://Stackoverflow.com/users/279393",
"pm_score": 2,
"selected": false,
"text": "mySoapHttpClientProtocol.Url = mySoapHttpClientProtocol.Url.Replace(\"localhost\", \"localhost.fiddler\");\n"
},
{
"answer_id": 22837772,
"author": "uzay95",
"author_id": 104085,
"author_profile": "https://Stackoverflow.com/users/104085",
"pm_score": 0,
"selected": false,
"text": " <endpoint address=\"http://localhost.:8868/FEInvoice.asmx\" binding=\"basicHttpBinding\"\n bindingConfiguration=\"FEInvoice_Test\" contract=\"EInvoiceIntegration.FEInvoiceSoap\"\n name=\"FEInvoice_Test\" />\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306859",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1484/"
] |
306,862 | <p>Today my colleagues and me have a discussion about the usage of the <code>final</code> keyword in Java to improve the garbage collection.</p>
<p>For example, if you write a method like:</p>
<pre><code>public Double doCalc(final Double value)
{
final Double maxWeight = 1000.0;
final Double totalWeight = maxWeight * value;
return totalWeight;
}
</code></pre>
<p>Declaring the variables in the method <code>final</code> would help the garbage collection to clean up the memory from the unused variables in the method after the method exits.</p>
<p>Is this true? </p>
| [
{
"answer_id": 306893,
"author": "SCdF",
"author_id": 1666,
"author_profile": "https://Stackoverflow.com/users/1666",
"pm_score": 5,
"selected": false,
"text": "final"
},
{
"answer_id": 306900,
"author": "Aaron",
"author_id": 19130,
"author_profile": "https://Stackoverflow.com/users/19130",
"pm_score": 5,
"selected": false,
"text": "final"
},
{
"answer_id": 306966,
"author": "benjismith",
"author_id": 22979,
"author_profile": "https://Stackoverflow.com/users/22979",
"pm_score": 8,
"selected": true,
"text": "public class MyClass {\n\n public final MyOtherObject obj;\n\n}\n"
},
{
"answer_id": 318357,
"author": "Tom Hawtin - tackline",
"author_id": 4725,
"author_profile": "https://Stackoverflow.com/users/4725",
"pm_score": 2,
"selected": false,
"text": "final"
},
{
"answer_id": 1353417,
"author": "Thorbjørn Ravn Andersen",
"author_id": 53897,
"author_profile": "https://Stackoverflow.com/users/53897",
"pm_score": 3,
"selected": false,
"text": "final boolean debug = false;\n\n......\n\nif (debug) {\n System.out.println(\"DEBUG INFO!\");\n}\n"
},
{
"answer_id": 9183984,
"author": "Debasish Pakhira",
"author_id": 1195742,
"author_profile": "https://Stackoverflow.com/users/1195742",
"pm_score": 1,
"selected": false,
"text": "final int a=10;"
},
{
"answer_id": 59392595,
"author": "Eugene",
"author_id": 1059372,
"author_profile": "https://Stackoverflow.com/users/1059372",
"pm_score": 1,
"selected": false,
"text": "final"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306862",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34856/"
] |
306,863 | <p>I know this isn't really what XPath is for but if I have a HashMap of XPath expressions to values how would I go about building an XML document. I've found dom-4j's
DocumentHelper.makeElement(branch, xpath) except it is incapable of creating attributes or indexing. Surely a library exists that can do this?</p>
<pre><code>Map xMap = new HashMap();
xMap.put("root/entity/@att", "fooattrib");
xMap.put("root/array[0]/ele/@att", "barattrib");
xMap.put("root/array[0]/ele", "barelement");
xMap.put("root/array[1]/ele", "zoobelement");
</code></pre>
<p>would result in:</p>
<pre><code><root>
<entity att="fooattrib"/>
<array><ele att="barattrib">barelement</ele></array>
<array><ele>zoobelement</ele></array>
</root>
</code></pre>
| [
{
"answer_id": 306893,
"author": "SCdF",
"author_id": 1666,
"author_profile": "https://Stackoverflow.com/users/1666",
"pm_score": 5,
"selected": false,
"text": "final"
},
{
"answer_id": 306900,
"author": "Aaron",
"author_id": 19130,
"author_profile": "https://Stackoverflow.com/users/19130",
"pm_score": 5,
"selected": false,
"text": "final"
},
{
"answer_id": 306966,
"author": "benjismith",
"author_id": 22979,
"author_profile": "https://Stackoverflow.com/users/22979",
"pm_score": 8,
"selected": true,
"text": "public class MyClass {\n\n public final MyOtherObject obj;\n\n}\n"
},
{
"answer_id": 318357,
"author": "Tom Hawtin - tackline",
"author_id": 4725,
"author_profile": "https://Stackoverflow.com/users/4725",
"pm_score": 2,
"selected": false,
"text": "final"
},
{
"answer_id": 1353417,
"author": "Thorbjørn Ravn Andersen",
"author_id": 53897,
"author_profile": "https://Stackoverflow.com/users/53897",
"pm_score": 3,
"selected": false,
"text": "final boolean debug = false;\n\n......\n\nif (debug) {\n System.out.println(\"DEBUG INFO!\");\n}\n"
},
{
"answer_id": 9183984,
"author": "Debasish Pakhira",
"author_id": 1195742,
"author_profile": "https://Stackoverflow.com/users/1195742",
"pm_score": 1,
"selected": false,
"text": "final int a=10;"
},
{
"answer_id": 59392595,
"author": "Eugene",
"author_id": 1059372,
"author_profile": "https://Stackoverflow.com/users/1059372",
"pm_score": 1,
"selected": false,
"text": "final"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306863",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
306,867 | <p>I have a problem where I cannot identify visitors to my intranet page because their browser is configured to use a proxy, even for the local intranet. I always see the proxy IP and no other details about the client. The SOE that my company uses has the proxy set up already for Firefox and Internet Explorer, and I cannot ask them to reconfigure their browser because that is fairly complicated. I have tried using the PHP <code>$_SERVER['REMOTE_ADDR']</code> and also one called <code>$HTTP_SERVER_VARS['HTTP_X_FORWARD_FOR']</code>. In fact, I wrote a page that lists both the <code>$_SERVER</code> and <code>$HTTP_SERVER_VARS</code> arrays and there was nothing informative of the actual client connecting. This is why I think it needs to be done on the client's side.</p>
<p>I'm not looking for a secure solution because it is only a simple page, so I was hoping that I could use Javascript or something similar to find something revealing about the client and send it to my intranet page as a <code>GET</code> variable. It's basically for collating statistics. It is no use telling me most of the visitors are a proxy! :)</p>
<p>I also want to avoid having users log in if possible.</p>
| [
{
"answer_id": 306882,
"author": "Sijin",
"author_id": 8884,
"author_profile": "https://Stackoverflow.com/users/8884",
"pm_score": 1,
"selected": false,
"text": "HTTP-X-FORWARD-FOR"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306867",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10320/"
] |
306,871 | <p>A table exists that someone else loaded. I need to query against the table, but the lack of indexes makes the query plan abysmal. What I would like to do is detect if there is an index for a particular column, so that I can created it if it does not exist, and not create it if it is already there.</p>
<p>Thanks.</p>
<p>Evil</p>
| [
{
"answer_id": 306881,
"author": "BQ.",
"author_id": 4632,
"author_profile": "https://Stackoverflow.com/users/4632",
"pm_score": 2,
"selected": false,
"text": "Select * from sys.all_ind_columns where table_name=:TabName and table_owner=:TabOwner;\n"
},
{
"answer_id": 306895,
"author": "Justin Cave",
"author_id": 10397,
"author_profile": "https://Stackoverflow.com/users/10397",
"pm_score": 4,
"selected": true,
"text": "DBA_/ALL_/USER_IND_COLUMNS"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7734/"
] |
306,877 | <p>I wanted to deserialize an XML message containing an element that can be marked <code>nil="true"</code> into a class with a property of type <code>int?</code>. The only way I could get it to work was to write my own <code>NullableInt</code> type which implements <code>IXmlSerializable</code>. Is there a better way to do it?</p>
<p>I wrote up the full problem and the way I solved it <a href="http://alexscordellis.blogspot.com/2008/11/using-xmlserializer-to-deserialize-into.html" rel="nofollow noreferrer">on my blog</a>.</p>
| [
{
"answer_id": 306980,
"author": "Phil Jenkins",
"author_id": 35496,
"author_profile": "https://Stackoverflow.com/users/35496",
"pm_score": 4,
"selected": true,
"text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<entities xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"array\">\n <entity>\n <id xsi:type=\"integer\">1</id>\n <name>Foo</name>\n <parent-id xsi:type=\"integer\" xsi:nil=\"true\"/>\n"
},
{
"answer_id": 1580488,
"author": "Tom Mayfield",
"author_id": 2314,
"author_profile": "https://Stackoverflow.com/users/2314",
"pm_score": 2,
"selected": false,
"text": "public static void FixNilAttributeName(this XmlNode @this)\n{\n XmlAttribute nilAttribute = @this.Attributes[\"nil\"];\n if (nilAttribute == null)\n {\n return;\n }\n\n XmlAttribute newNil = @this.OwnerDocument.CreateAttribute(\"xsi\", \"nil\", \"http://www.w3.org/2001/XMLSchema-instance\");\n newNil.Value = nilAttribute.Value;\n @this.Attributes.Remove(nilAttribute);\n @this.Attributes.Append(newNil);\n}\n"
},
{
"answer_id": 4836235,
"author": "sipsorcery",
"author_id": 75658,
"author_profile": "https://Stackoverflow.com/users/75658",
"pm_score": 0,
"selected": false,
"text": "xmlStr = Regex.Replace(xmlStr, \"nil=\\\"true\\\"\", \"xmlns:xsi=\\\"http://www.w3.org/2001/XMLSchema-instance\\\" xsi:nil=\\\"true\\\"\");\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306877",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12006/"
] |
306,880 | <pre><code>ArrayList <String> list = new ArrayList();
list.add("behold");
list.add("bend");
list.add("bet");
list.add("bear");
list.add("beat");
list.add("become");
list.add("begin");
</code></pre>
<p>There is a way to search for the regexp bea.* and get the indexes like in ArrayList.indexOf ?</p>
<p>EDIT: returning the items is fine but I need something with more performance than a Linear search</p>
| [
{
"answer_id": 306954,
"author": "Herms",
"author_id": 1409,
"author_profile": "https://Stackoverflow.com/users/1409",
"pm_score": 3,
"selected": false,
"text": "import java.util.regex.Pattern;\nimport java.util.ListIterator;\nimport java.util.ArrayList;\n\n/**\n * Finds the index of all entries in the list that matches the regex\n * @param list The list of strings to check\n * @param regex The regular expression to use\n * @return list containing the indexes of all matching entries\n */\nList<Integer> getMatchingIndexes(List<String> list, String regex) {\n ListIterator<String> li = list.listIterator();\n\n List<Integer> indexes = new ArrayList<Integer>();\n\n while(li.hasNext()) {\n int i = li.nextIndex();\n String next = li.next();\n if(Pattern.matches(regex, next)) {\n indexes.add(i);\n }\n }\n\n return indexes;\n}\n"
},
{
"answer_id": 306999,
"author": "DJClayworth",
"author_id": 19276,
"author_profile": "https://Stackoverflow.com/users/19276",
"pm_score": 4,
"selected": false,
"text": "import java.util.regex.Pattern;\nimport java.util.ListIterator;\nimport java.util.ArrayList;\n\n/**\n * Finds the index of all entries in the list that matches the regex\n * @param list The list of strings to check\n * @param regex The regular expression to use\n * @return list containing the indexes of all matching entries\n */\nList<String> getMatchingStrings(List<String> list, String regex) {\n\n ArrayList<String> matches = new ArrayList<String>();\n\n Pattern p = Pattern.compile(regex);\n\n for (String s:list) {\n if (p.matcher(s).matches()) {\n matches.add(s);\n }\n }\n\n return matches\n}\n"
},
{
"answer_id": 24487142,
"author": "grinch",
"author_id": 1476154,
"author_profile": "https://Stackoverflow.com/users/1476154",
"pm_score": 2,
"selected": false,
"text": "final Iterable<String> matches = Iterables.filter(myStrings, Predicates.contains(Pattern.compile(\"myPattern\")));\n\nfor (final String matched : matches) {\n ...\n}\n"
},
{
"answer_id": 58273362,
"author": "Anton Krug",
"author_id": 4535300,
"author_profile": "https://Stackoverflow.com/users/4535300",
"pm_score": 0,
"selected": false,
"text": " import java.util.regex.Pattern;\n import java.util.stream.Collectors;\n import java.util.List;\n\n ...\n\n var pattern = Pattern.compile(define); // var is Java 10 feature\n\n List<String> list = originalList\n .stream()\n .filter(e -> pattern.matcher(e).matches())\n .collect(Collectors.toList());\n"
},
{
"answer_id": 65918848,
"author": "Misha Betekhtin",
"author_id": 9984243,
"author_profile": "https://Stackoverflow.com/users/9984243",
"pm_score": 0,
"selected": false,
"text": "@Test\npublic void testRegexPerformance()\n{\n List<String> list = new ArrayList<>();\n list.add(\"behold\");\n list.add(\"bend\");\n list.add(\"bet\");\n list.add(\"bear\");\n list.add(\"beat\");\n list.add(\"become\");\n list.add(\"begin\");\n for (int i = 0; i < 20; i++)\n {\n list.addAll(list);\n }\n System.out.println(\"Original list size: \" + list.size());\n Instant startTime = Instant.now();\n List<String> results = testLoopApproach(list, \"bea.*\");\n Instant current = Instant.now();\n System.out.println(\"Found List size: \" + results.size());\n System.out.println(\"Elapsed millis: \" + (current.toEpochMilli() - startTime.toEpochMilli()));\n startTime = Instant.now();\n results = testStreamApproach(list, \"bea.*\");\n current = Instant.now();\n System.out.println(\"Found List size: \" + results.size());\n System.out.println(\"Elapsed millis: \" + (current.toEpochMilli() - startTime.toEpochMilli()));\n}\n\nprivate List<String> testStreamApproach(List<String> list, String regex)\n{\n Predicate<String> pred = Pattern.compile(regex).asPredicate();\n return list.parallelStream().filter(pred).collect(Collectors.toList());\n}\n\nprivate List<String> testLoopApproach(List<String> list, String regex)\n{\n Pattern p = Pattern.compile(regex);\n List<String> resulsts = new ArrayList<>();\n for (String string : list)\n {\n if (p.matcher(string).find())\n {\n resulsts.add(string);\n }\n }\n return resulsts;\n}\n\nand the results are:\nOriginal list size: 7340032\nFound List size: 2097152\nElapsed millis: 1785\nFound List size: 2097152\nElapsed millis: 260\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306880",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14015/"
] |
306,894 | <p>As a beginning programmer, I'm trying to settle on a standard naming convention for myself. I realize that it's personal preference, but I was trying to get some ideas from some of you (well a LOT of you) who are much smarter than myself.</p>
<p>I'm not talking about camel notation but rather how do you name your variables, etc. IMHO, var_Quantity is much more descriptive than Q or varQ. However, how do you keep the variable from becoming too long. I've tried to be more descriptive with naming my controls, but I've ended up with some like "rtxtboxAddrLine1" for a RadTextBox that holds address line 1. Too me,that is unmanageable, although it's pretty clear what that control is.</p>
<p>I'm just curious if you have some guides that you follow or am I left up to my own devices?</p>
| [
{
"answer_id": 306923,
"author": "Greg Beech",
"author_id": 13552,
"author_profile": "https://Stackoverflow.com/users/13552",
"pm_score": 5,
"selected": true,
"text": "quantity"
},
{
"answer_id": 307003,
"author": "Ryan Lundy",
"author_id": 5486,
"author_profile": "https://Stackoverflow.com/users/5486",
"pm_score": 3,
"selected": false,
"text": "strFirstName"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306894",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38317/"
] |
306,896 | <p>Is it possible to use EventListener to Listen to a variable and detect when the value of that variable changes? Thanks.</p>
| [
{
"answer_id": 318639,
"author": "Brian Hodge",
"author_id": 20628,
"author_profile": "https://Stackoverflow.com/users/20628",
"pm_score": 5,
"selected": true,
"text": "someVar = 5"
},
{
"answer_id": 787834,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "dispatchEvent"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306896",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34797/"
] |
306,901 | <p>When I run a wxPython application, it prints the string “Redirecting output to win32trace remote collector”and I must open PythonWin's trace collector tool to view that trace output.</p>
<p>Since I'm not interested in collecting this output, how should I disable this feature?</p>
| [
{
"answer_id": 306925,
"author": "joeforker",
"author_id": 36330,
"author_profile": "https://Stackoverflow.com/users/36330",
"pm_score": 1,
"selected": false,
"text": "class MyApp(wx.App):\n def __init__(self):\n # Prevent wxPython from redirecting stdout/stderr:\n super(MyApp, self).__init__(redirect=0)\n"
},
{
"answer_id": 306936,
"author": "DrBloodmoney",
"author_id": 35681,
"author_profile": "https://Stackoverflow.com/users/35681",
"pm_score": 3,
"selected": true,
"text": "if __name__ == \"__main__\":\n app = wx.App(redirect=False) #or 0\n app.MainLoop()\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306901",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36330/"
] |
306,906 | <p>I would like to find all the rows in a table and match on an exact case sensitive string. Unfortunately, my table has the case insensitive collation. </p>
<p>What is the most efficient way to perform this.</p>
<p>Eg.</p>
<p>I would like the following to return no rows:</p>
<pre><code>select * from sysobject where name = 'Sysbinobjs'
</code></pre>
<p>For the answer assume @match is in a variable: </p>
<pre><code>declare @match varchar(4000)
set @match = 'sysbinobjs'
</code></pre>
<p><strong>EDIT</strong> </p>
<p>Clarification, make sure trailing spaces are treated properly, I want an exact match that takes account of trailing spaces so 'Hello' will only be matched with 'Hello' and not with 'Hello ' </p>
| [
{
"answer_id": 306918,
"author": "Sam Saffron",
"author_id": 17174,
"author_profile": "https://Stackoverflow.com/users/17174",
"pm_score": 4,
"selected": true,
"text": "declare @match nvarchar(4000) \nset @match = 'sysbinobjs'\n\n\nselect * from sysobjects\nwhere name = @match and\ncast(name as varbinary(4000)) = cast(@match as varbinary(4000))\n"
},
{
"answer_id": 308516,
"author": "devzero",
"author_id": 37083,
"author_profile": "https://Stackoverflow.com/users/37083",
"pm_score": 2,
"selected": false,
"text": "select * from sysobjects\nWHERE name = @match and --Get all relevant hits from the index before doing the final case sensitive test\nname COLLATE Latin1_General_CS_AS = @match COLLATE Latin1_General_CS_AS\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17174/"
] |
306,924 | <p>Is it possible to set the size of a checkbox using CSS or HTML across browsers? </p>
<p><code>width</code> and <code>size</code> work in IE6+, but not with Firefox, where the checkbox stays 16x16 even if I set a smaller size.</p>
| [
{
"answer_id": 3132509,
"author": "Avi Flax",
"author_id": 7012,
"author_profile": "https://Stackoverflow.com/users/7012",
"pm_score": 3,
"selected": false,
"text": "-webkit-transform: scale(1.3, 1.3);"
},
{
"answer_id": 10415275,
"author": "jdw",
"author_id": 1370191,
"author_profile": "https://Stackoverflow.com/users/1370191",
"pm_score": 9,
"selected": false,
"text": "input[type=checkbox]\n{\n /* Double-sized Checkboxes */\n -ms-transform: scale(2); /* IE */\n -moz-transform: scale(2); /* FF */\n -webkit-transform: scale(2); /* Safari and Chrome */\n -o-transform: scale(2); /* Opera */\n transform: scale(2);\n padding: 10px;\n}\n\n/* Might want to wrap a span around your checkbox text */\n.checkboxtext\n{\n /* Checkbox text */\n font-size: 110%;\n display: inline;\n}"
},
{
"answer_id": 13210588,
"author": "UniMe",
"author_id": 1540801,
"author_profile": "https://Stackoverflow.com/users/1540801",
"pm_score": 5,
"selected": false,
"text": "*,*:after,*:before {\n -webkit-box-sizing: border-box;\n -moz-box-sizing: border-box;\n box-sizing: border-box;\n padding: 0;\n margin: 0;\n}\n\n.switch {\n margin: 50px auto;\n position: relative;\n}\n\n.switch label {\n width: 100%;\n height: 100%;\n position: relative;\n display: block;\n}\n\n.switch input {\n top: 0; \n right: 0; \n bottom: 0; \n left: 0;\n opacity: 0;\n z-index: 100;\n position: absolute;\n width: 100%;\n height: 100%;\n cursor: pointer;\n}\n\n/* DEMO 3 */\n\n.switch.demo3 {\n width: 180px;\n height: 50px;\n}\n\n.switch.demo3 label {\n display: block;\n width: 100%;\n height: 100%;\n background: #a5a39d;\n border-radius: 40px;\n box-shadow:\n inset 0 3px 8px 1px rgba(0,0,0,0.2),\n 0 1px 0 rgba(255,255,255,0.5);\n}\n\n.switch.demo3 label:after {\n content: \"\";\n position: absolute;\n z-index: -1;\n top: -8px; right: -8px; bottom: -8px; left: -8px;\n border-radius: inherit;\n background: #ababab;\n background: -moz-linear-gradient(#f2f2f2, #ababab);\n background: -ms-linear-gradient(#f2f2f2, #ababab);\n background: -o-linear-gradient(#f2f2f2, #ababab);\n background: -webkit-gradient(linear, 0 0, 0 100%, from(#f2f2f2), to(#ababab));\n background: -webkit-linear-gradient(#f2f2f2, #ababab);\n background: linear-gradient(#f2f2f2, #ababab);\n box-shadow: 0 0 10px rgba(0,0,0,0.3),\n 0 1px 1px rgba(0,0,0,0.25);\n}\n\n.switch.demo3 label:before {\n content: \"\";\n position: absolute;\n z-index: -1;\n top: -18px; right: -18px; bottom: -18px; left: -18px;\n border-radius: inherit;\n background: #eee;\n background: -moz-linear-gradient(#e5e7e6, #eee);\n background: -ms-linear-gradient(#e5e7e6, #eee);\n background: -o-linear-gradient(#e5e7e6, #eee);\n background: -webkit-gradient(linear, 0 0, 0 100%, from(#e5e7e6), to(#eee));\n background: -webkit-linear-gradient(#e5e7e6, #eee);\n background: linear-gradient(#e5e7e6, #eee);\n box-shadow:\n 0 1px 0 rgba(255,255,255,0.5);\n -webkit-filter: blur(1px);\n -moz-filter: blur(1px);\n -ms-filter: blur(1px);\n -o-filter: blur(1px);\n filter: blur(1px);\n}\n\n.switch.demo3 label i {\n display: block;\n height: 100%;\n width: 60%;\n border-radius: inherit;\n background: silver;\n position: absolute;\n z-index: 2;\n right: 40%;\n top: 0;\n background: #b2ac9e;\n background: -moz-linear-gradient(#f7f2f6, #b2ac9e);\n background: -ms-linear-gradient(#f7f2f6, #b2ac9e);\n background: -o-linear-gradient(#f7f2f6, #b2ac9e);\n background: -webkit-gradient(linear, 0 0, 0 100%, from(#f7f2f6), to(#b2ac9e));\n background: -webkit-linear-gradient(#f7f2f6, #b2ac9e);\n background: linear-gradient(#f7f2f6, #b2ac9e);\n box-shadow:\n inset 0 1px 0 white,\n 0 0 8px rgba(0,0,0,0.3),\n 0 5px 5px rgba(0,0,0,0.2);\n}\n\n.switch.demo3 label i:after {\n content: \"\";\n position: absolute;\n left: 15%;\n top: 25%;\n width: 70%;\n height: 50%;\n background: #d2cbc3;\n background: -moz-linear-gradient(#cbc7bc, #d2cbc3);\n background: -ms-linear-gradient(#cbc7bc, #d2cbc3);\n background: -o-linear-gradient(#cbc7bc, #d2cbc3);\n background: -webkit-gradient(linear, 0 0, 0 100%, from(#cbc7bc), to(#d2cbc3));\n background: -webkit-linear-gradient(#cbc7bc, #d2cbc3);\n background: linear-gradient(#cbc7bc, #d2cbc3);\n border-radius: inherit;\n}\n\n.switch.demo3 label i:before {\n content: \"off\";\n text-transform: uppercase;\n font-style: normal;\n font-weight: bold;\n color: rgba(0,0,0,0.4);\n text-shadow: 0 1px 0 #bcb8ae, 0 -1px 0 #97958e;\n font-family: Helvetica, Arial, sans-serif;\n font-size: 24px;\n position: absolute;\n top: 50%;\n margin-top: -12px;\n right: -50%;\n}\n\n.switch.demo3 input:checked ~ label {\n background: #9abb82;\n}\n\n.switch.demo3 input:checked ~ label i {\n right: -1%;\n}\n\n.switch.demo3 input:checked ~ label i:before {\n content: \"on\";\n right: 115%;\n color: #82a06a;\n text-shadow: \n 0 1px 0 #afcb9b,\n 0 -1px 0 #6b8659;\n}"
},
{
"answer_id": 21114938,
"author": "Luiz",
"author_id": 3194201,
"author_profile": "https://Stackoverflow.com/users/3194201",
"pm_score": 6,
"selected": false,
"text": "zoom"
},
{
"answer_id": 21387229,
"author": "Justin",
"author_id": 642128,
"author_profile": "https://Stackoverflow.com/users/642128",
"pm_score": 3,
"selected": false,
"text": "font-size: x-large;\n"
},
{
"answer_id": 24688640,
"author": "Fellow Stranger",
"author_id": 1417223,
"author_profile": "https://Stackoverflow.com/users/1417223",
"pm_score": 9,
"selected": false,
"text": "input[type=checkbox] {\n transform: scale(1.5);\n}"
},
{
"answer_id": 40379743,
"author": "hcarreras",
"author_id": 1611802,
"author_profile": "https://Stackoverflow.com/users/1611802",
"pm_score": 2,
"selected": false,
"text": ".checkbox-list__item {\n position: relative;\n padding: 10px 0;\n display: block;\n cursor: pointer;\n margin: 0 0 0 34px;\n border-bottom: 1px solid #b4bcc2;\n}\n.checkbox-list__item:last-of-type {\n border-bottom: 0;\n}\n\n.checkbox-list__check {\n width: 18px;\n height: 18px;\n border: 3px solid #b4bcc2;\n position: absolute;\n left: -34px;\n top: 50%;\n margin-top: -12px;\n transition: border .3s ease;\n border-radius: 5px;\n}\n.checkbox-list__check:before {\n position: absolute;\n display: block;\n width: 18px;\n height: 22px;\n top: -2px;\n left: 0px;\n padding-left: 2px;\n background-color: transparent;\n transition: background-color .3s ease;\n content: '\\2713';\n font-family: initial;\n font-size: 19px;\n color: white;\n}\n\ninput[type=\"checkbox\"]:checked ~ .checkbox-list__check {\n border-color: #5bc0de;\n}\ninput[type=\"checkbox\"]:checked ~ .checkbox-list__check:before {\n background-color: #5bc0de;\n}"
},
{
"answer_id": 43647055,
"author": "Worthy7",
"author_id": 1079267,
"author_profile": "https://Stackoverflow.com/users/1079267",
"pm_score": 2,
"selected": false,
"text": "input[type=checkbox] {\n width: 25px;\n height: 25px;\n -moz-appearance: none;\n}"
},
{
"answer_id": 44626004,
"author": "ViliusL",
"author_id": 2676137,
"author_profile": "https://Stackoverflow.com/users/2676137",
"pm_score": 6,
"selected": false,
"text": "body{\n padding:0 20px;\n}\n.big{\n font-size: 50px;\n}\n\n/* CSS below will force radio/checkbox size be same as font size */\nlabel{\n position: relative;\n line-height: 1.4;\n}\n/* radio */\ninput[type=radio]{\n width: 1em;\n font-size: inherit;\n margin: 0;\n transform: translateX(-9999px);\n}\ninput[type=radio] + label:before{\n position: absolute;\n content: '';\n left: -1.3em;\n top: 0;\n width: 1em;\n height: 1em;\n margin: 0;\n border:none;\n border-radius: 50%;\n background-color: #bbbbbb;\n}\ninput[type=radio] + label:after{\n position: absolute;\n content: '';\n left: -1.3em;\n top: 0;\n width: 1em;\n height: 1em;\n margin: 0;\n border: none;\n background-color: white;\n border-radius: 50%;\n transform: scale(0.8);\n}\n/*checked*/\ninput[type=radio]:checked + label:before{\n position:absolute;\n content:'';\n left: -1.3em;\n top: 0;\n width: 1em;\n height: 1em;\n margin: 0;\n border: none;\n background-color: #3b88fd;\n}\ninput[type=radio]:checked + label:after{\n position: absolute;\n content: '';\n left: -1.3em;\n top: 0;\n width: 1em;\n height: 1em;\n margin: 0;\n border: none;\n background-color: white;\n border-radius: 50%;\n transform: scale(0.3);\n}\n/*focused*/\ninput[type=radio]:focus + label:before{\n border: 0.2em solid #8eb9fb;\n margin-top: -0.2em;\n margin-left: -0.2em;\n box-shadow: 0 0 0.3em #3b88fd;\n}\n\n\n/*checkbox/*/\ninput[type=checkbox]{\n width: 1em;\n font-size: inherit;\n margin: 0;\n transform: translateX(-9999px);\n}\ninput[type=checkbox] + label:before{\n position: absolute;\n content: '';\n left: -1.3em;\n top: 0;\n width: 1em;\n height: 1em;\n margin: 0;\n border:none;\n border-radius: 10%;\n background-color: #bbbbbb;\n}\ninput[type=checkbox] + label:after{\n position: absolute;\n content: '';\n left: -1.3em;\n top: 0;\n width: 1em;\n height: 1em;\n margin: 0;\n border: none;\n background-color: white;\n border-radius: 10%;\n transform: scale(0.8);\n}\n/*checked*/\ninput[type=checkbox]:checked + label:before{\n position:absolute;\n content:'';\n left: -1.3em;\n top: 0;\n width: 1em;\n height: 1em;\n margin: 0;\n border: none;\n background-color: #3b88fd;\n}\ninput[type=checkbox]:checked + label:after{\n position: absolute;\n content: \"\\2713\";\n left: -1.3em;\n top: 0;\n width: 1em;\n height: 1em;\n margin: 0;\n border: none;\n background-color: #3b88fd;\n border-radius: 10%;\n color: white;\n text-align: center;\n line-height: 1;\n}\n/*focused*/\ninput[type=checkbox]:focus + label:before{\n border: 0.1em solid #8eb9fb;\n margin-top: -0.1em;\n margin-left: -0.1em;\n box-shadow: 0 0 0.2em #3b88fd;\n}"
},
{
"answer_id": 46911415,
"author": "Sharcoux",
"author_id": 1967800,
"author_profile": "https://Stackoverflow.com/users/1967800",
"pm_score": 5,
"selected": false,
"text": "input[type=\"checkbox\"] {display:none;}\ninput[type=\"checkbox\"] + label:before {content:\"☐\";}\ninput:checked + label:before {content:\"☑\";}\nlabel:hover {color:blue;}"
},
{
"answer_id": 48038954,
"author": "squarecandy",
"author_id": 947370,
"author_profile": "https://Stackoverflow.com/users/947370",
"pm_score": 2,
"selected": false,
"text": "input:checked~div label"
},
{
"answer_id": 53589180,
"author": "ruchika vasu",
"author_id": 10389389,
"author_profile": "https://Stackoverflow.com/users/10389389",
"pm_score": 0,
"selected": false,
"text": ".checkmark {\n position: absolute;\n top: 0;\n left: 0;\n height: 20px;\n width: 20px;\n border-radius:5px;\n border:1px solid #ff7e02;\n}"
},
{
"answer_id": 54804563,
"author": "Jack Miller",
"author_id": 2484903,
"author_profile": "https://Stackoverflow.com/users/2484903",
"pm_score": 4,
"selected": false,
"text": "appearance"
},
{
"answer_id": 57024223,
"author": "JCdotNET",
"author_id": 6463338,
"author_profile": "https://Stackoverflow.com/users/6463338",
"pm_score": 3,
"selected": false,
"text": "input[type=checkbox] {\n -webkit-appearance: none;\n -moz-appearance: none;\n vertical-align: middle;\n width: 14px; \n height: 14px;\n font-size: 14px;\n background-color: #eee;\n}\n\ninput[type=checkbox]:checked:after {\n position: relative;\n bottom: 3px;\n left: 1px;\n color: blue;\n content: \"\\2713\"; /* check mark */\n}\n"
},
{
"answer_id": 65959703,
"author": "RKaneKnight",
"author_id": 2059632,
"author_profile": "https://Stackoverflow.com/users/2059632",
"pm_score": 3,
"selected": false,
"text": " input[type=checkbox] {\n width: 17px;\n -webkit-appearance: none;\n -moz-appearance: none;\n height: 17px;\n border: 1px solid black;\n }\n\n input[type=checkbox]:checked {\n background-color: #F58027;\n }\n\n input[type=checkbox]:checked:after {\n margin-left: 4px;\n margin-top: -1px;\n width: 4px;\n height: 12px;\n border: solid white;\n border-width: 0 2px 2px 0;\n -webkit-transform: rotate(45deg);\n -moz-transform: rotate(45deg);\n -ms-transform: rotate(45deg);\n transform: rotate(45deg);\n content: \"\";\n display: inline-block;\n }\n input[type=checkbox]:after {\n margin-left: 4px;\n margin-top: -1px;\n width: 4px;\n height: 12px;\n border: solid white;\n border-width: 0;\n -webkit-transform: rotate(45deg);\n -moz-transform: rotate(45deg);\n -ms-transform: rotate(45deg);\n transform: rotate(45deg);\n content: \"\";\n display: inline-block;\n }"
},
{
"answer_id": 68009548,
"author": "Waad Mawlood",
"author_id": 15186994,
"author_profile": "https://Stackoverflow.com/users/15186994",
"pm_score": 2,
"selected": false,
"text": "input[type=checkbox]\n{\n /* Double-sized Checkboxes */\n -ms-transform: scale(1.5); /* IE */\n -moz-transform: scale(1.5); /* FF */\n -webkit-transform: scale(1.5); /* Safari and Chrome */\n -o-transform: scale(1.5); /* Opera */\n transform: scale(1.5);\n padding: 10px;\n}\n"
},
{
"answer_id": 68332668,
"author": "Manu Järvinen",
"author_id": 4383420,
"author_profile": "https://Stackoverflow.com/users/4383420",
"pm_score": 3,
"selected": false,
"text": "input {\n width: 25px;\n height: 25px;\n}\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39474/"
] |
306,937 | <p>What is the cast expression equivalent of VB.NET's CType in Visual Basic 6?</p>
| [
{
"answer_id": 306944,
"author": "JohnFx",
"author_id": 30018,
"author_profile": "https://Stackoverflow.com/users/30018",
"pm_score": 5,
"selected": true,
"text": "cint() Cast to integer\ncstr() cast to string\nclng() cast to long\ncdbl() cast to double\ncdate() cast to date\n"
},
{
"answer_id": 307130,
"author": "Ryan",
"author_id": 29762,
"author_profile": "https://Stackoverflow.com/users/29762",
"pm_score": 2,
"selected": false,
"text": "If IsObject(Value) Then\n Set myObject = Value ' VB6 does not have CType(Value, MyObjectType)\nElse\n myObject = Value ' VB6 does not have CType(Value, MyObjectType)\nEnd If\n"
},
{
"answer_id": 308645,
"author": "Ant",
"author_id": 11529,
"author_profile": "https://Stackoverflow.com/users/11529",
"pm_score": 3,
"selected": false,
"text": "Dim base As BaseClass\nSet base = child\n"
},
{
"answer_id": 310913,
"author": "Mike Spross",
"author_id": 17862,
"author_profile": "https://Stackoverflow.com/users/17862",
"pm_score": 4,
"selected": false,
"text": "CType"
},
{
"answer_id": 460255,
"author": "Bob",
"author_id": 24007,
"author_profile": "https://Stackoverflow.com/users/24007",
"pm_score": 0,
"selected": false,
"text": "MsgBox CLng(CBool(3&))\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306937",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35286/"
] |
306,938 | <p>We currently have an appserver setup where EVERYTHING is off of one big context root, and we copy class files and restart app servers to deploy. Not ideal.
I'm trying to set up an ant script to do the build and deploy using wdeploy, and everything works, except I need my servlet to forward to jsps outside of the context root of my war file deploy. So I figure if I can put a symlink in my war file, it can point to somewhere outside of my context root space.</p>
<p>This is the goal I'm trying to achieve, perhaps the symlink isn't the best idea.
I just need a way to forward outside of my context root from a servlet.</p>
| [
{
"answer_id": 306944,
"author": "JohnFx",
"author_id": 30018,
"author_profile": "https://Stackoverflow.com/users/30018",
"pm_score": 5,
"selected": true,
"text": "cint() Cast to integer\ncstr() cast to string\nclng() cast to long\ncdbl() cast to double\ncdate() cast to date\n"
},
{
"answer_id": 307130,
"author": "Ryan",
"author_id": 29762,
"author_profile": "https://Stackoverflow.com/users/29762",
"pm_score": 2,
"selected": false,
"text": "If IsObject(Value) Then\n Set myObject = Value ' VB6 does not have CType(Value, MyObjectType)\nElse\n myObject = Value ' VB6 does not have CType(Value, MyObjectType)\nEnd If\n"
},
{
"answer_id": 308645,
"author": "Ant",
"author_id": 11529,
"author_profile": "https://Stackoverflow.com/users/11529",
"pm_score": 3,
"selected": false,
"text": "Dim base As BaseClass\nSet base = child\n"
},
{
"answer_id": 310913,
"author": "Mike Spross",
"author_id": 17862,
"author_profile": "https://Stackoverflow.com/users/17862",
"pm_score": 4,
"selected": false,
"text": "CType"
},
{
"answer_id": 460255,
"author": "Bob",
"author_id": 24007,
"author_profile": "https://Stackoverflow.com/users/24007",
"pm_score": 0,
"selected": false,
"text": "MsgBox CLng(CBool(3&))\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306938",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12386/"
] |
306,945 | <p>I have a very long-running stored procedure in SQL Server 2005 that I'm trying to debug, and I'm using the 'print' command to do it. The problem is, I'm only getting the messages back from SQL Server at the very end of my sproc - I'd like to be able to flush the message buffer and see these messages immediately during the sproc's runtime, rather than at the very end.</p>
| [
{
"answer_id": 307005,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 9,
"selected": true,
"text": "RAISERROR"
},
{
"answer_id": 4068129,
"author": "tcbrazil",
"author_id": 391029,
"author_profile": "https://Stackoverflow.com/users/391029",
"pm_score": 4,
"selected": false,
"text": "-- Replace PRINT function\nDECLARE @strMsg NVARCHAR(100)\nSELECT @strMsg = 'Here''s your message...'\nRAISERROR (@strMsg, 0, 1) WITH NOWAIT\n"
},
{
"answer_id": 30415596,
"author": "Robert Lujo",
"author_id": 565525,
"author_profile": "https://Stackoverflow.com/users/565525",
"pm_score": 3,
"selected": false,
"text": "print 'test'\nprint 'test'\ngo\n"
},
{
"answer_id": 46146880,
"author": "Mike",
"author_id": 914490,
"author_profile": "https://Stackoverflow.com/users/914490",
"pm_score": 6,
"selected": false,
"text": "PRINT 'MyVariableName: ' + @MyVariableName\nRAISERROR(N'', 0, 1) WITH NOWAIT\n"
},
{
"answer_id": 67584337,
"author": "sisisisi",
"author_id": 4255824,
"author_profile": "https://Stackoverflow.com/users/4255824",
"pm_score": 1,
"selected": false,
"text": "READ UNCOMMITTED"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306945",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16942/"
] |
306,946 | <p>need ask you about some help.</p>
<p>I have web app running in Net 2.0.<br>
I wanna ask what storage (cache, session, file) I should use for my objects as they have different scope of using. Can be divide into several groups:<br>
1) objects related directly to visitor (e.g. details about visitor that are received after authentication)<br>
2) objects that are used for every visitor, so its scope of application (some init data, common data) </p>
<p>Most of these objects get data from web service, which is expensive.</p>
<p>So what's my best choices considering speed, memory, accessibility and what else I should look out.</p>
<p>Any help most welcome. Thanks, X.</p>
| [
{
"answer_id": 306978,
"author": "cfeduke",
"author_id": 5645,
"author_profile": "https://Stackoverflow.com/users/5645",
"pm_score": 3,
"selected": true,
"text": "Session"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306946",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24507/"
] |
306,968 | <p>I have a linux box with a bank of modems and need to create demand-dial (outbound) PPP connections to a very large set of remote machines. Since I have far more remotes than local modems, I'd like to launch one or more instances of <code>pppd</code> in <code>demand</code> mode, but not allocate a particular modem until a connection is requested. When the connection becomes idle, I'd like <code>pppd</code> to release the modem so it can be used for a connection to a different remote.</p>
<p>I've been through the <code>pppd man</code> pages and understand the concepts of the <code>call</code> and <code>connect</code> options, as well as the <code>options.DEVICE</code> files and the <code>/etc/ppp/peers</code> directory. Lock files will tell me which modems are in use or available. And I'm able to connect to multiple remote peers as long as I hard-code the modem assignments. But I haven't found a way to assign them dynamically, say by calling a <code>get_available_modem</code> script when <code>pppd</code> needs to dial. Google doesn't seem to know, either.</p>
<p>A work-around might be to detect the need to demand-dial with an external mechanism, and then launch <code>pppd</code> to service it, but it seems cleaner to leverage the facility within <code>pppd</code> itself.</p>
<p>Any pointers or ideas are appreciated. Thanks for your thoughts!</p>
| [
{
"answer_id": 361114,
"author": "Adam Liss",
"author_id": 29157,
"author_profile": "https://Stackoverflow.com/users/29157",
"pm_score": 2,
"selected": true,
"text": "/dev/modem0"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306968",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29157/"
] |
306,992 | <p>I have found an example for encrypting a web.config during installation <a href="http://madtechnology.wordpress.com/2007/05/04/using-wix-to-secure-a-connection-string/" rel="nofollow noreferrer">here</a>, but my app is a windows service. The <code>aspnetreg_iis</code> method works only for web.config files.</p>
<p>I know how to programatically encrypt the config file, but I don't think I can do that using WiX. Am I wrong? Any ideas?</p>
| [
{
"answer_id": 307080,
"author": "AJ.",
"author_id": 27457,
"author_profile": "https://Stackoverflow.com/users/27457",
"pm_score": 2,
"selected": false,
"text": "//class global\nstatic System.Reflection.Assembly DefiningAssembly;\n\nAppDomain currentDomain = AppDomain.CurrentDomain;\ncurrentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);\n\nstatic System.Reflection.Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)\n{\n return DefiningAssembly;\n}\n"
},
{
"answer_id": 316403,
"author": "JasonS",
"author_id": 1865,
"author_profile": "https://Stackoverflow.com/users/1865",
"pm_score": 2,
"selected": false,
"text": " public static void EncryptConfig(Session session)\n {\n\n var configPath = session[\"APPCONFIGPATH\"];\n var sectionToEncrypt = session[\"SECTIONTOENCRYPT\"];\n\n var fileMap = new ExeConfigurationFileMap();\n fileMap.ExeConfigFilename = configPath;\n var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);\n ConfigurationSection section = configuration.GetSection(sectionToEncrypt);\n \n if (!section.SectionInformation.IsProtected)\n {\n section.SectionInformation.ProtectSection(\"DataProtectionConfigurationProvider\");\n section.SectionInformation.ForceSave = true;\n configuration.Save(ConfigurationSaveMode.Modified);\n\n }\n }\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/306992",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1865/"
] |
307,004 | <p>On several of my usercontrols, I change the cursor by using</p>
<pre><code>this.Cursor = Cursors.Wait;
</code></pre>
<p>when I click on something.</p>
<p>Now I want to do the same thing on a WPF page on a button click. When I hover over my button, the cursor changes to a hand, but when I click it, it doesn't change to the wait cursor. I wonder if this has something to do with the fact that it's a button, or because this is a page and not a usercontrol? This seems like weird behavior.</p>
| [
{
"answer_id": 307020,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 9,
"selected": true,
"text": "Mouse.OverrideCursor = Cursors.Wait;\ntry\n{\n // do stuff\n}\nfinally\n{\n Mouse.OverrideCursor = null;\n}\n"
},
{
"answer_id": 675686,
"author": "Dennis",
"author_id": 73025,
"author_profile": "https://Stackoverflow.com/users/73025",
"pm_score": 6,
"selected": false,
"text": "using(){}"
},
{
"answer_id": 2858068,
"author": "Zamboni",
"author_id": 174682,
"author_profile": "https://Stackoverflow.com/users/174682",
"pm_score": 5,
"selected": false,
"text": "<Button x:Name=\"NextButton\"\n Content=\"Go\"\n Command=\"{Binding GoCommand }\">\n <Button.Style>\n <Style TargetType=\"{x:Type Button}\">\n <Setter Property=\"Cursor\" Value=\"Arrow\"/>\n <Style.Triggers>\n <DataTrigger Binding=\"{Binding Path=IsWorking}\" Value=\"True\">\n <Setter Property=\"Cursor\" Value=\"Wait\"/>\n </DataTrigger>\n </Style.Triggers>\n </Style>\n </Button.Style>\n</Button>\n"
},
{
"answer_id": 17528840,
"author": "Valeriu Caraulean",
"author_id": 473440,
"author_profile": "https://Stackoverflow.com/users/473440",
"pm_score": 3,
"selected": false,
"text": "Application.Current.Dispatcher.Invoke(() =>\n{\n // The check is required to prevent cursor flickering\n if (Mouse.OverrideCursor != cursor)\n Mouse.OverrideCursor = cursor;\n});\n"
},
{
"answer_id": 60749671,
"author": "Mike Lowery",
"author_id": 298511,
"author_profile": "https://Stackoverflow.com/users/298511",
"pm_score": 0,
"selected": false,
"text": "ForceCursor = true;\nCursor = Cursors.Wait;\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307004",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047/"
] |
307,006 | <p>I'm working on an application controller for a program that is spitting text directly to /dev/tty.</p>
<p>This is a production application controller that must be able to catch all text going to the terminal. Generally, this isn't a problem. We simply redirect stdout and stderr. This particular application is making direct calls to echo and redirecting the result to /dev/tty (<code>echo "some text" > /dev/tty</code>). Redirects via my application controller are failing to catch the text.</p>
<p>I do have the source for this application, but am not in a position to modify it, nor is it being maintained anymore. Any ideas on how to catch and/or throw away the output? </p>
| [
{
"answer_id": 307328,
"author": "flolo",
"author_id": 36472,
"author_profile": "https://Stackoverflow.com/users/36472",
"pm_score": 2,
"selected": false,
"text": " screen -D -m yourEvilProgram\n"
},
{
"answer_id": 307505,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 3,
"selected": true,
"text": "screen"
},
{
"answer_id": 4073248,
"author": "Davide",
"author_id": 25891,
"author_profile": "https://Stackoverflow.com/users/25891",
"pm_score": 2,
"selected": false,
"text": "import pty, os\n\npid, fd = pty.fork()\nif pid == 0: # In the child process execute another command\n os.execv('./my-progr', [''])\n print \"Execv never returns :-)\"\nelse:\n while True:\n try:\n print os.read(fd,65536),\n except OSError:\n break\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307006",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19741/"
] |
307,013 | <p>This is for .NET. IgnoreCase is set and MultiLine is NOT set.</p>
<p>Usually I'm decent at regex, maybe I'm running low on caffeine...</p>
<p>Users are allowed to enter HTML-encoded entities (<lt;, <amp;, etc.), and to use the following HTML tags:</p>
<pre><code>u, i, b, h3, h4, br, a, img
</code></pre>
<p>Self-closing <br/> and <img/> are allowed, with or without the extra space, but are not required.</p>
<p>I want to:</p>
<ol>
<li>Strip all starting and ending HTML tags other than those listed above. </li>
<li>Remove attributes from the remaining tags, <em>except</em> anchors can have an href.</li>
</ol>
<p>My search pattern (replaced with an empty string) so far:</p>
<pre><code><(?!i|b|h3|h4|a|img|/i|/b|/h3|/h4|/a|/img)[^>]+>
</code></pre>
<p>This <em>seems</em> to be stripping all but the start and end tags I want, but there are three problems:</p>
<ol>
<li>Having to include the end tag version of each allowed tag is ugly.</li>
<li>The attributes survive. Can this happen in a single replacement?</li>
<li>Tags <em>starting with</em> the allowed tag names slip through. E.g., "<abbrev>" and "<iframe>".</li>
</ol>
<p>The following suggested pattern does not strip out tags that have no attributes.</p>
<pre><code></?(?!i|b|h3|h4|a|img)\b[^>]*>
</code></pre>
<p>As mentioned below, ">" is legal in an attribute value, but it's safe to say I won't support that. Also, there will be no CDATA blocks, etc. to worry about. Just a little HTML.</p>
<p>Loophole's answer is the best one so far, thanks! Here's his pattern (hoping the PRE works better for me):</p>
<pre><code>static string SanitizeHtml(string html)
{
string acceptable = "script|link|title";
string stringPattern = @"</?(?(?=" + acceptable + @")notag|[a-zA-Z0-9]+)(?:\s[a-zA-Z0-9\-]+=?(?:([""']?).*?\1?)?)*\s*/?>";
return Regex.Replace(html, stringPattern, "sausage");
}
</code></pre>
<p>Some small tweaks I think could still be made to this answer:</p>
<ol>
<li><p>I think this could be modified to capture simple HTML comments (those that do not themselves contain tags) by adding "!--" to the "acceptable" variable and making a small change to the end of the expression to allow for an optional trailing "\s--".</p></li>
<li><p>I think this would break if there are multiple whitespace characters between attributes (example: heavily-formatted HTML with line breaks and tabs between attributes).</p></li>
</ol>
<p><strong>Edit 2009-07-23:</strong> Here's the final solution I went with (in VB.NET):</p>
<pre><code> Dim AcceptableTags As String = "i|b|u|sup|sub|ol|ul|li|br|h2|h3|h4|h5|span|div|p|a|img|blockquote"
Dim WhiteListPattern As String = "</?(?(?=" & AcceptableTags & _
")notag|[a-zA-Z0-9]+)(?:\s[a-zA-Z0-9\-]+=?(?:([""']?).*?\1?)?)*\s*/?>"
html = Regex.Replace(html, WhiteListPattern, "", RegExOptions.Compiled)
</code></pre>
<p>The caveat is that the HREF attribute of A tags still gets scrubbed, which is not ideal.</p>
| [
{
"answer_id": 308367,
"author": "Jan Goyvaerts",
"author_id": 33358,
"author_profile": "https://Stackoverflow.com/users/33358",
"pm_score": 1,
"selected": false,
"text": "<(?!/?(i|b|h3|h4|a|img)\\b)[^>]+>\n"
},
{
"answer_id": 315823,
"author": "Jason Kelley",
"author_id": 36790,
"author_profile": "https://Stackoverflow.com/users/36790",
"pm_score": 0,
"selected": false,
"text": "?"
},
{
"answer_id": 315851,
"author": "Jason Kelley",
"author_id": 36790,
"author_profile": "https://Stackoverflow.com/users/36790",
"pm_score": 6,
"selected": true,
"text": "static string SanitizeHtml(string html)\n{\n string acceptable = \"script|link|title\";\n string stringPattern = @\"</?(?(?=\" + acceptable + @\")notag|[a-zA-Z0-9]+)(?:\\s[a-zA-Z0-9\\-]+=?(?:([\"\",']?).*?\\1?)?)*\\s*/?>\";\n return Regex.Replace(html, stringPattern, \"sausage\");\n}\n"
},
{
"answer_id": 13230174,
"author": "Chirag",
"author_id": 1799843,
"author_profile": "https://Stackoverflow.com/users/1799843",
"pm_score": 0,
"selected": false,
"text": " /// <summary>\n /// Trims the ignoring spacified tags\n /// </summary>\n /// <param name=\"text\">the text from which html is to be removed</param>\n /// <param name=\"isRemoveScript\">specify if you want to remove scripts</param>\n /// <param name=\"ignorableTags\">specify the tags that are to be ignored while stripping</param>\n /// <returns>Stripped Text</returns>\n public static string StripHtml(string text, bool isRemoveScript, params string[] ignorableTags)\n {\n if (!string.IsNullOrEmpty(text))\n {\n text = text.Replace(\"<\", \"<\");\n text = text.Replace(\">\", \">\");\n string ignorePattern = null;\n\n if (isRemoveScript)\n {\n text = Regex.Replace(text, \"<script[^<]*</script>\", string.Empty, RegexOptions.IgnoreCase);\n }\n if (!ignorableTags.Contains(\"style\"))\n {\n text = Regex.Replace(text, \"<style[^<]*</style>\", string.Empty, RegexOptions.IgnoreCase);\n }\n foreach (string tag in ignorableTags)\n {\n //the character b spoils the regex so replace it with strong\n if (tag.Equals(\"b\"))\n {\n text = text.Replace(\"<b>\", \"<strong>\");\n text = text.Replace(\"</b>\", \"</strong>\");\n if (ignorableTags.Contains(\"strong\"))\n {\n ignorePattern = string.Format(\"{0}(?!strong)(?!/strong)\", ignorePattern);\n }\n }\n else\n {\n //Create ignore pattern fo the tags to ignore\n ignorePattern = string.Format(\"{0}(?!{1})(?!/{1})\", ignorePattern, tag);\n }\n\n }\n //finally add the ignore pattern into regex <[^<]*> which is used to match all html tags\n ignorePattern = string.Format(@\"<{0}[^<]*>\", ignorePattern);\n text = Regex.Replace(text, ignorePattern, \"\", RegexOptions.IgnoreCase);\n }\n\n return text;\n }\n"
},
{
"answer_id": 62921504,
"author": "Jared Beach",
"author_id": 1834329,
"author_profile": "https://Stackoverflow.com/users/1834329",
"pm_score": 2,
"selected": false,
"text": "HtmlSanitizer.SimpleHtml5Sanitizer()"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16306/"
] |
307,014 | <p>A client of mine has told me the program I made for them won't connect to a SQL server named instance, I have a standard SQL server with no named instance so I'm wondering how I can test this. A named instance connection string look like the one below, could the backslash be were my code fails?</p>
<p>Driver={SQL Native Client};Server=myServerName\theInstanceName;Database=myDataBase; </p>
<p>My code is as follows:</p>
<pre><code>sqlServer=s.Substring(keyword.Length,s.Length-keyword.Length);
FormODBC formODBC=new FormODBC(this);
formODBC.SetSqlServer(sqlServer,dbUsername,dbPassword,database,table);
formODBC.ReadData();
</code></pre>
<p>How should I handle the backslash as I suspect this may be the problem?</p>
<p>Thanks</p>
| [
{
"answer_id": 309877,
"author": "D'Arcy Rittich",
"author_id": 39430,
"author_profile": "https://Stackoverflow.com/users/39430",
"pm_score": 2,
"selected": false,
"text": "string server = \"myServer\\\\myInstance\";\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307014",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,015 | <p>This isn't working. Can this be done in find? Or do I need to xargs?</p>
<pre><code>find -name 'file_*' -follow -type f -exec zcat {} \| agrep -dEOE 'grep' \;
</code></pre>
| [
{
"answer_id": 307023,
"author": "Paul Tomblin",
"author_id": 3333,
"author_profile": "https://Stackoverflow.com/users/3333",
"pm_score": 4,
"selected": false,
"text": "find . -name \"file_*\" -follow -type f -print0 | xargs -0 zcat | agrep -dEOE 'grep'\n"
},
{
"answer_id": 307154,
"author": "flolo",
"author_id": 36472,
"author_profile": "https://Stackoverflow.com/users/36472",
"pm_score": 8,
"selected": false,
"text": "... -exec sh -c \"zcat {} | agrep -dEOE 'grep' \" \\;\n"
},
{
"answer_id": 307167,
"author": "Rolf W. Rasmussen",
"author_id": 39469,
"author_profile": "https://Stackoverflow.com/users/39469",
"pm_score": 8,
"selected": true,
"text": "find -name 'file_*' -follow -type f -exec zcat {} \\; | agrep -dEOE 'grep'\n"
},
{
"answer_id": 3741624,
"author": "simbo1905",
"author_id": 329496,
"author_profile": "https://Stackoverflow.com/users/329496",
"pm_score": 4,
"selected": false,
"text": "while"
},
{
"answer_id": 58412010,
"author": "Louis Gagnon",
"author_id": 4148979,
"author_profile": "https://Stackoverflow.com/users/4148979",
"pm_score": 2,
"selected": false,
"text": "for i in $(find -name 'file_*' -follow -type f); do\n zcat $i | agrep -dEOE 'grep'\ndone\n"
},
{
"answer_id": 59082869,
"author": "Andrew Khoury",
"author_id": 480880,
"author_profile": "https://Stackoverflow.com/users/480880",
"pm_score": 3,
"selected": false,
"text": "find -name 'file_*' -follow -type f -exec bash -c \"zcat \\\"{}\\\" | agrep -dEOE 'grep'\" \\;\n"
},
{
"answer_id": 72036209,
"author": "Daniel Kaplan",
"author_id": 61624,
"author_profile": "https://Stackoverflow.com/users/61624",
"pm_score": 0,
"selected": false,
"text": "find -name 'file_*' -follow -type f -exec sh -c 'zcat \"$1\" | agrep -dEOE \"grep\"' sh {} \\;\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34594/"
] |
307,019 | <p>The following query returns strange results for me:</p>
<pre><code>SELECT
`Statistics`.`StatisticID`,
COUNT(`Votes`.`StatisticID`) AS `Score`,
COUNT(`Views`.`StatisticID`) AS `Views`,
COUNT(`Comments`.`StatisticID`) AS `Comments`
FROM `Statistics`
LEFT JOIN `Votes` ON `Votes`.`StatisticID` = `Statistics`.`StatisticID`
LEFT JOIN `Views` ON `Views`.`StatisticID` = `Statistics`.`StatisticID`
LEFT JOIN `Comments` ON `Comments`.`StatisticID` = `Statistics`.`StatisticID`
GROUP BY `Statistics`.`StatisticID`
LIMIT 0, 10
</code></pre>
<p>I'm querying this on a table structure like the following:</p>
<p>(only data relevant to <code>Statistics.StatisticID = 8</code>)</p>
<h3>Votes</h3>
<pre><code>StatisticID
8
</code></pre>
<h3>Views</h3>
<pre><code>StatisticID
8
8
</code></pre>
<h3>Comments</h3>
<pre><code>StatisticID
8
8
8
8
8
</code></pre>
<p>Now if I run this query I get the following result set:</p>
<pre><code>StatisticID Score Views Comments
8 5 5 5
</code></pre>
<p>I knwo where the 5 comes from - the number of Comments - and this works if I take the comments statement out. Can anyone debug this as this is out of my reach (I'm relatively new with SQL).</p>
<p>Thanks,
Ross</p>
| [
{
"answer_id": 307303,
"author": "benlumley",
"author_id": 39161,
"author_profile": "https://Stackoverflow.com/users/39161",
"pm_score": 3,
"selected": true,
"text": "SELECT\n `Statistics`.`StatisticID`,\n COUNT(DISTINCT `Votes`.`VoteID`) AS `Score`,\n COUNT(DISTINCT `Views`.`ViewID`) AS `Views`,\n COUNT(DISTINCT `Comments`.`CommentID`) AS `Comments`\nFROM `Statistics`\nLEFT JOIN `Votes` ON `Votes`.`StatisticID` = `Statistics`.`StatisticID`\nLEFT JOIN `Views` ON `Views`.`StatisticID` = `Statistics`.`StatisticID`\nLEFT JOIN `Comments` ON `Comments`.`StatisticID` = `Statistics`.`StatisticID`\nGROUP BY `Statistics`.`StatisticID`\nLIMIT 0, 10\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307019",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2025/"
] |
307,024 | <p>A link that stands out is <a href="http://www.devdaily.com/blog/post/jfc-swing/handling-main-mac-menu-in-swing-application/" rel="noreferrer">http://www.devdaily.com/blog/post/jfc-swing/handling-main-mac-menu-in-swing-application/</a> however the menu bar under Mac OS X displays as the package name as opposed to the application name. I'm using the code in the above link without any luck, so I'm unsure if anything's changed in recent Mac OS versions.</p>
<p>Here's an extract:</p>
<blockquote>
<pre><code>public RootGUI() {
super("Hello");
JMenuBar menuBar = new JMenuBar();
JMenu file = new JMenu("File");
JMenuItem item = new JMenuItem("Woah");
file.add(item);
menuBar.add(file);
setJMenuBar(menuBar);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(100, 100);
pack();
setVisible(true);
}
</code></pre>
</blockquote>
<pre><code>public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Test");
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
new RootGUI();
}
catch(ClassNotFoundException e) {
System.out.println("ClassNotFoundException: " + e.getMessage());
}
catch(InstantiationException e) {
System.out.println("InstantiationException: " + e.getMessage());
}
catch(IllegalAccessException e) {
System.out.println("IllegalAccessException: " + e.getMessage());
}
catch(UnsupportedLookAndFeelException e) {
System.out.println("UnsupportedLookAndFeelException: " + e.getMessage());
}
}
});
}
</code></pre>
<p>The first menu item on the menu bar should display as "test", unfortunately this isn't the case. The file menu works fine, on the other hand. Any ideas?</p>
| [
{
"answer_id": 307996,
"author": "Daniel Hiller",
"author_id": 16193,
"author_profile": "https://Stackoverflow.com/users/16193",
"pm_score": 2,
"selected": false,
"text": "-Xdock:name=\"YourNameHere\"\n"
},
{
"answer_id": 310575,
"author": "Matt Solnit",
"author_id": 6198,
"author_profile": "https://Stackoverflow.com/users/6198",
"pm_score": 6,
"selected": true,
"text": "public class RootGUILauncher {\n public static void main(String[] args) {\n try {\n System.setProperty(\"apple.laf.useScreenMenuBar\", \"true\");\n System.setProperty(\"com.apple.mrj.application.apple.menu.about.name\", \"Test\");\n UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\n }\n catch(ClassNotFoundException e) {\n System.out.println(\"ClassNotFoundException: \" + e.getMessage());\n }\n catch(InstantiationException e) {\n System.out.println(\"InstantiationException: \" + e.getMessage());\n }\n catch(IllegalAccessException e) {\n System.out.println(\"IllegalAccessException: \" + e.getMessage());\n }\n catch(UnsupportedLookAndFeelException e) {\n System.out.println(\"UnsupportedLookAndFeelException: \" + e.getMessage());\n }\n javax.swing.SwingUtilities.invokeLater(new Runnable() {\n public void run() {\n new RootGUI();\n }\n });\n}\n"
},
{
"answer_id": 67237918,
"author": "Will Iverson",
"author_id": 311440,
"author_profile": "https://Stackoverflow.com/users/311440",
"pm_score": 0,
"selected": false,
"text": "System.setProperty(\"apple.laf.useScreenMenuBar\", \"true\");"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307024",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39693/"
] |
307,027 | <p>I'm wondering if this is a good design. I have a number of tables that require address information (e.g. street, post code/zip, country, fax, email). Sometimes the same address will be repeated multiple times. For example, an address may be stored against a supplier, and then on each purchase order sent to them. The supplier may then change their address and any subsequent purchase orders should have the new address. It's more complicated than this, but that's an example requirement.</p>
<p>Option 1
Put all the address columns as attributes on the various tables. Copy the details down from the supplier to the PO as it is created. Potentially store multiple copies of the </p>
<p>Option 2
Create a separate address table. Have a foreign key from the supplier and purchase order tables to the address table. Only allow insert and delete on the address table as updates could change more than you intend. Then I would have some scheduled task that deletes any rows from the address table that are no longer referenced by anything so unused rows were not left about. Perhaps also have a unique constraint on all the non-pk columns in the address table to stop duplicates as well.</p>
<p>I'm leaning towards option 2. Is there a better way?</p>
<p>EDIT: I must keep the address on the purchase order as it was when sent. Also, it's a bit more complicated that I suggested as there may be a delivery address and a billing address (there's also a bunch of other tables that have address information).</p>
<p>After a while, I will delete old purchase orders en-masse based on their date. It is after this that I was intending on garbage collecting any address records that are not referenced anymore by anything (otherwise it feels like I'm creating a leak).</p>
| [
{
"answer_id": 307111,
"author": "Eric Z Beard",
"author_id": 1219,
"author_profile": "https://Stackoverflow.com/users/1219",
"pm_score": 6,
"selected": true,
"text": "Addresses\n---------\nAddressId (PK)\nStreet1\n... (etc)\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307027",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14663/"
] |
307,030 | <p>I have a working make, I have platform code and like several makes for each os in the folder. Right now I have one makefile which works. I renamed it to Makefile.ws and wrote this in Makefile</p>
<pre><code>all:
make -f Makefile.w32
clean:
make -f Makefile.w32 clean
</code></pre>
<p>I ran it and got this error</p>
<pre><code>> "make"
make -f Makefile.w32
make[1]: Entering directory `/c/nightly/test'
make -f Makefile.w32
make[3]: Makefile.w32: No such file or directory
make[3]: *** No rule to make target `Makefile.w32'. Stop.
make[2]: *** [all] Error 2
make[1]: *** [build] Error 2
make[1]: Leaving directory `/c/nightly/test'
"make": *** [all] Error 2
</code></pre>
<p>Oddly enough the clean works perfectly. Then I decided to write "make -f Makefile.w32 mingw32" and that did not work correctly. In fact it made a folder called mingw32 which I thought was very strange.</p>
<p>As for the mingw32 rule I just copy build which I suspect is the main/normal rule that is used to build</p>
<pre><code>$(BUILD):
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
mingw32:
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
</code></pre>
<p>full .w32 source is here <a href="http://pastie.org/320035" rel="nofollow noreferrer">http://pastie.org/320035</a></p>
| [
{
"answer_id": 307062,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 0,
"selected": false,
"text": "$(MAKE) -f ..."
},
{
"answer_id": 307067,
"author": "JesperE",
"author_id": 13051,
"author_profile": "https://Stackoverflow.com/users/13051",
"pm_score": 1,
"selected": false,
"text": "make -f Makefile.w32\nmake[1]: Entering directory `/c/nightly/test'\nmake -f Makefile.w32 \nmake[3]: Makefile.w32: No such file or directory\n"
},
{
"answer_id": 307086,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 0,
"selected": false,
"text": "mingw32:\n @[ -d $@ ] || mkdir -p $@\n @make --no-print-directory -C mingw32 -f $(CURDIR)/Makefile"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307030",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,041 | <p>The rails books and web pages I've been following have all stuck to very simple projects for the sake of providing complete examples. I'm moving away from the small project app and into a realm of non-browser clients and need to decide where to put code that is shared by all involved parties.</p>
<p>The non-browser client is a script that runs on any machine which can connect to the database. Browser clients write commands into the database, which the script examines and decides what to do. Upon completion, the script then writes its result back. The script is not started by the RoR server, but has access to its directory structure.</p>
<p>Where would be the best place for shared code to live, and how would the RoR loader handle it? The code in question doesn't really belong in a model, otherwise I'd drop it in there and be done with it.</p>
| [
{
"answer_id": 307061,
"author": "John Topley",
"author_id": 1450,
"author_profile": "https://Stackoverflow.com/users/1450",
"pm_score": 4,
"selected": true,
"text": "/lib"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307041",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30997/"
] |
307,048 | <p>Suddenly my Flex Apps can no longer connect to salesforce.com via its API, I am getting a security sandbox violation. Login credentials are correct, I have tried them via a different means, and I have obfuscated them below.</p>
<p>This was working fine earlier today and I have not been coding since then.</p>
<p>Anyone else come across this or know what's going on?</p>
<p>Here is the exception returned to my app</p>
<pre><code>Method name is: login
'A997F86A-36E9-DDDC-EC6B-BBEE23101466' producer connected.
'A997F86A-36E9-DDDC-EC6B-BBEE23101466' producer sending message 'B89E5879-D7F7-E91E-2082-BBEE231054DD'
'direct_http_channel' channel sending message:
(mx.messaging.messages::HTTPRequestMessage)#0
body = "<se:Envelope xmlns:se="http://schemas.xmlsoap.org/soap/envelope/"><se:Header xmlns:sfns="urn:partner.soap.sforce.com"/><se:Body><login xmlns="urn:partner.soap.sforce.com" xmlns:ns1="sobject.partner.soap.sforce.com"><username>simon.palmer@***.com</username><password>***</password></login></se:Body></se:Envelope>"
clientId = (null)
contentType = "text/xml; charset=UTF-8"
destination = "DefaultHTTPS"
headers = (Object)#1
httpHeaders = (Object)#2
Accept = "text/xml"
SOAPAction = """"
X-Salesforce-No-500-SC = "true"
messageId = "B89E5879-D7F7-E91E-2082-BBEE231054DD"
method = "POST"
recordHeaders = false
timestamp = 0
timeToLive = 0
url = "https://www.salesforce.com/services/Soap/u/11.0"
Method name is: login
*** Security Sandbox Violation ***
Connection to https://www.salesforce.com/services/Soap/u/11.0 halted - not permitted from https://localhost/pm_server/pm/pm-debug.swf
'A997F86A-36E9-DDDC-EC6B-BBEE23101466' producer acknowledge of 'B89E5879-D7F7-E91E-2082-BBEE231054DD'.
'A997F86A-36E9-DDDC-EC6B-BBEE23101466' producer fault for 'B89E5879-D7F7-E91E-2082-BBEE231054DD'.
Comunication Error : Channel.Security.Error : Security error accessing url : Destination: DefaultHTTPS
Error: Request for resource at https://www.salesforce.com/services/Soap/u/11.0 by requestor from https://localhost/pm_server/pm/pm-debug.swf is denied due to lack of policy file permissions.
</code></pre>
| [
{
"answer_id": 339479,
"author": "Simon",
"author_id": 24039,
"author_profile": "https://Stackoverflow.com/users/24039",
"pm_score": 1,
"selected": false,
"text": "apex = new Connection(); \napex.serverUrl = \"https://na3.salesforce.com/services/Soap/u/14.0\";\napex.protocol = \"https\";\n"
},
{
"answer_id": 805274,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "Error:[FaultEvent fault=[RPC Fault faultString=\"Security error accessing url\"\nfaultCode=\"Channel.Security.Error\" faultDetail=\"Destination: DefaultHTTPS\"] \nmessageId=\"1F812836-1318-B845-AC01-F51AB1D11518\" type=\"fault\" bubbles=false \ncancelable=true eventPhase=2]\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307048",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24039/"
] |
307,056 | <p>What rules apply to the name that ends up in the exports section of an PE (Portable Executable)?
Roughly, I see names starting with an '_' underscore, a '?' question mark or an '@' at-sign. What do those mean, and what about the rest of the name?</p>
<p>Also - How can I reverse the naming convention into something more usable?</p>
| [
{
"answer_id": 307076,
"author": "Eric",
"author_id": 6367,
"author_profile": "https://Stackoverflow.com/users/6367",
"pm_score": 3,
"selected": true,
"text": "LIBRARY \"MyDll\"\n\nEXPORTS\n exportFunction1\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307056",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12170/"
] |
307,060 | <p>The function <a href="http://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx" rel="noreferrer">CreateFileMapping</a> can be used to allocate space in the pagefile (if the first argument is <code>INVALID_HANDLE_VALUE</code>). The allocated space can later be memory mapped into the process virtual address space.</p>
<p>Why would I want to do this instead of using just <a href="http://msdn.microsoft.com/en-us/library/aa366887(VS.85).aspx" rel="noreferrer">VirtualAlloc</a>?</p>
<p>It seems that both functions do almost the same thing. Memory allocated by VirtualAlloc may at some point be pushed out to the pagefile. Why should I need an API that specifically requests that my pages be allocated there in the first instance? Why should I care where my private pages live?</p>
<p>Is it just a hint to the OS about my expected memory usage patterns? (Ie, the former is a hint to swap out those pages more aggressively.)</p>
<p>Or is it simply a convenience method when working with very large datasets on 32-bit processes? (Ie, I can use CreateFileMapping to make >4Gb allocations, then memory map smaller chunks of the space as needed. Using the pagefile saves me the work of manually managing my own set of files to "swap" to.)</p>
<p>PS. This question is sparked by an article I read recently: <a href="http://blogs.technet.com/markrussinovich/archive/2008/11/17/3155406.aspx" rel="noreferrer">http://blogs.technet.com/markrussinovich/archive/2008/11/17/3155406.aspx</a></p>
| [
{
"answer_id": 307106,
"author": "Kieveli",
"author_id": 15852,
"author_profile": "https://Stackoverflow.com/users/15852",
"pm_score": 3,
"selected": true,
"text": "A single file mapping object can be shared by multiple processes.\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307060",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/755/"
] |
307,070 | <p>I want to offload a block of code in my main process to child process to make it run concurrently. I also want to have the PID of the spawned child process so I can monitor and kill it if necessary.</p>
| [
{
"answer_id": 307088,
"author": "Chris Lloyd",
"author_id": 42413,
"author_profile": "https://Stackoverflow.com/users/42413",
"pm_score": 6,
"selected": true,
"text": "fork"
},
{
"answer_id": 307127,
"author": "Martin Carpenter",
"author_id": 39443,
"author_profile": "https://Stackoverflow.com/users/39443",
"pm_score": 6,
"selected": false,
"text": "Process.wait"
},
{
"answer_id": 308330,
"author": "Brent.Longborough",
"author_id": 9634,
"author_profile": "https://Stackoverflow.com/users/9634",
"pm_score": 2,
"selected": false,
"text": "def doit(x)\n sleep(rand(10))\n puts \"Done... #{x}\"\nend\n\nthingstodo = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\"]\ntasklist = []\n\n# Set the threads going\n\nthingstodo.each { |thing|\n task = Thread.new(thing) { |this| doit(this) } \n tasklist << task\n} \n\n# Wait for the threads to finish\n\ntasklist.each { |task|\n task.join\n}\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307070",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42413/"
] |
307,073 | <p>Consider the "double-check idiom for lazy initialization of instance fields":</p>
<blockquote><pre>// Item 71 in Effective Java copied from <a href="http://java.sun.com/developer/technicalArticles/Interviews/bloch_effective_08_qa.html" rel="nofollow noreferrer">this interview with Bloch</a>.
private volatile FieldType field;
FieldType getField() {
FieldType result = field;
if (result == null) { // First check (no locking)
synchronized(this) {
result = field;
if (result == null) // Second check (with locking)
field = result = computeFieldValue();
}
}
return result;
}</pre></blockquote>
<p><p>I want to be able to reset the field in a safe way (force it to load again from the database, in my case). I assume that we could do this by having a reset method:</p>
<blockquote><pre>
void reset() {
field = null;
}</pre></blockquote>
<p><p>Is this the standard way of doing resetting the field? Is it safe? Any pitfalls? I'm asking because Bloch gave the following warning about double-checked lazy-loading: "The idiom is very fast but also complicated and delicate, so don't be tempted to modify it in any way. Just copy and paste -- normally not a good idea, but appropriate here."</p>
<p>Thanks in advance,
Playa from the Himalayas.</p>
| [
{
"answer_id": 307206,
"author": "jacobko",
"author_id": 1318,
"author_profile": "https://Stackoverflow.com/users/1318",
"pm_score": 0,
"selected": false,
"text": "reset()"
},
{
"answer_id": 307225,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 3,
"selected": true,
"text": "computeFieldValue()"
},
{
"answer_id": 14477684,
"author": "Ivan",
"author_id": 2003552,
"author_profile": "https://Stackoverflow.com/users/2003552",
"pm_score": 0,
"selected": false,
"text": "FieldType result = field;if (result == null) { // First check (no locking)"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307073",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39489/"
] |
307,082 | <p>What is the shortest chunk of C++ you can come up with to safely clean up a <code>std::vector</code> or <code>std::list</code> of pointers? (assuming you have to call delete on the pointers?)</p>
<pre><code>list<Foo*> foo_list;
</code></pre>
<p>I'd rather not use Boost or wrap my pointers with smart pointers.</p>
| [
{
"answer_id": 307090,
"author": "John Dibling",
"author_id": 241536,
"author_profile": "https://Stackoverflow.com/users/241536",
"pm_score": 3,
"selected": false,
"text": "template< typename T >\nstruct delete_ptr : public std::unary_function<T,bool>\n{\n bool operator()(T*pT) const { delete pT; return true; }\n};\n\nstd::for_each(foo_list.begin(), foo_list.end(), delete_ptr<Foo>());\n"
},
{
"answer_id": 307121,
"author": "Douglas Leeder",
"author_id": 3978,
"author_profile": "https://Stackoverflow.com/users/3978",
"pm_score": 5,
"selected": false,
"text": "for(list<Foo*>::const_iterator it = foo_list.begin(); it != foo_list.end(); ++it)\n{\n delete *it;\n} \nfoo_list.clear();\n"
},
{
"answer_id": 307124,
"author": "CB Bailey",
"author_id": 19563,
"author_profile": "https://Stackoverflow.com/users/19563",
"pm_score": 3,
"selected": false,
"text": "for( list<Foo*>::iterator i = foo_list.begin(); i != foo_list.end(); ++i )\n delete *i;\n"
},
{
"answer_id": 307125,
"author": "Assaf Lavie",
"author_id": 11208,
"author_profile": "https://Stackoverflow.com/users/11208",
"pm_score": 0,
"selected": false,
"text": "for (list<Foo*>::const_iterator i = foo_list.begin(), e = foo_list.end(); i != e; ++i)\n delete *i;\nfoo_list.clear();\n"
},
{
"answer_id": 307190,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 6,
"selected": false,
"text": "std::list<T*>"
},
{
"answer_id": 307269,
"author": "Greg Rogers",
"author_id": 5963,
"author_profile": "https://Stackoverflow.com/users/5963",
"pm_score": 2,
"selected": false,
"text": "for (list<Foo*>::iterator i = foo_list.begin(), e = foo_list.end(); i != e; )\n{\n list<Foo*>::iterator tmp(i++);\n delete *tmp;\n foo_list.erase(tmp);\n}\n"
},
{
"answer_id": 307360,
"author": "Mr.Ree",
"author_id": 37946,
"author_profile": "https://Stackoverflow.com/users/37946",
"pm_score": 7,
"selected": true,
"text": "static bool deleteAll( Foo * theElement ) { delete theElement; return true; }\n\nfoo_list . remove_if ( deleteAll );\n"
},
{
"answer_id": 10383000,
"author": "Linoliumz",
"author_id": 363778,
"author_profile": "https://Stackoverflow.com/users/363778",
"pm_score": 3,
"selected": false,
"text": "template <typename T>\nclass Deleter {\npublic:\n Deleter(T* pointer) : pointer_(pointer) { }\n Deleter(const Deleter& deleter) {\n Deleter* d = const_cast<Deleter*>(&deleter);\n pointer_ = d->pointer_;\n d->pointer_ = 0;\n }\n ~Deleter() { delete pointer_; }\n T* pointer_;\n};\n"
},
{
"answer_id": 20404762,
"author": "kendotwill",
"author_id": 1713375,
"author_profile": "https://Stackoverflow.com/users/1713375",
"pm_score": 1,
"selected": false,
"text": "void remove(Foo* foo) { delete foo; }\n....\nfor_each( foo_list.begin(), foo_list.end(), remove );\n"
},
{
"answer_id": 21740770,
"author": "Adisak",
"author_id": 14904,
"author_profile": "https://Stackoverflow.com/users/14904",
"pm_score": 4,
"selected": false,
"text": "for(auto &it:foo_list) delete it; foo_list.clear();\n"
},
{
"answer_id": 22980249,
"author": "Heero",
"author_id": 3517920,
"author_profile": "https://Stackoverflow.com/users/3517920",
"pm_score": 2,
"selected": false,
"text": "for(list<Foo*>::const_iterator it = foo_list.begin(); it != foo_list.end(); it++)\n{\n delete *it;\n} \nfoo_list.clear();\n"
},
{
"answer_id": 25867610,
"author": "ostappus",
"author_id": 2324228,
"author_profile": "https://Stackoverflow.com/users/2324228",
"pm_score": 2,
"selected": false,
"text": "std::vector<Type*> v;\n...\nstd::for_each(v.begin(), v.end(), std::default_delete<Type>());\n"
},
{
"answer_id": 51142181,
"author": "CompEng88",
"author_id": 916046,
"author_profile": "https://Stackoverflow.com/users/916046",
"pm_score": 0,
"selected": false,
"text": "for (Object *i : container) delete i; \ncontainer.clear();\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307082",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23524/"
] |
307,084 | <p>The .net framework 3.5 (or vista) provides me with an English voice (David I think) to use with the Speech.Synthesis api. I need a french voice to use with a french dictation practice app I am building for my kids to use to improve their french spelling. The api allows me to change culture when creating a voice, but the default English voice cannot pronounce the french words correctly.</p>
<p>I have been unable to find any way to download a french voice from Microsoft. Is this possible? I did download a Demo commercial voice from Cepstral, but it is crippled in a way that makes it unusable (even for testing). I did not want to buy anything as this exercise is just for fun.</p>
<p>I had hoped alternative language voices might be easily had without resort to the commercial professional voices. Any free alternatives?</p>
| [
{
"answer_id": 307090,
"author": "John Dibling",
"author_id": 241536,
"author_profile": "https://Stackoverflow.com/users/241536",
"pm_score": 3,
"selected": false,
"text": "template< typename T >\nstruct delete_ptr : public std::unary_function<T,bool>\n{\n bool operator()(T*pT) const { delete pT; return true; }\n};\n\nstd::for_each(foo_list.begin(), foo_list.end(), delete_ptr<Foo>());\n"
},
{
"answer_id": 307121,
"author": "Douglas Leeder",
"author_id": 3978,
"author_profile": "https://Stackoverflow.com/users/3978",
"pm_score": 5,
"selected": false,
"text": "for(list<Foo*>::const_iterator it = foo_list.begin(); it != foo_list.end(); ++it)\n{\n delete *it;\n} \nfoo_list.clear();\n"
},
{
"answer_id": 307124,
"author": "CB Bailey",
"author_id": 19563,
"author_profile": "https://Stackoverflow.com/users/19563",
"pm_score": 3,
"selected": false,
"text": "for( list<Foo*>::iterator i = foo_list.begin(); i != foo_list.end(); ++i )\n delete *i;\n"
},
{
"answer_id": 307125,
"author": "Assaf Lavie",
"author_id": 11208,
"author_profile": "https://Stackoverflow.com/users/11208",
"pm_score": 0,
"selected": false,
"text": "for (list<Foo*>::const_iterator i = foo_list.begin(), e = foo_list.end(); i != e; ++i)\n delete *i;\nfoo_list.clear();\n"
},
{
"answer_id": 307190,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 6,
"selected": false,
"text": "std::list<T*>"
},
{
"answer_id": 307269,
"author": "Greg Rogers",
"author_id": 5963,
"author_profile": "https://Stackoverflow.com/users/5963",
"pm_score": 2,
"selected": false,
"text": "for (list<Foo*>::iterator i = foo_list.begin(), e = foo_list.end(); i != e; )\n{\n list<Foo*>::iterator tmp(i++);\n delete *tmp;\n foo_list.erase(tmp);\n}\n"
},
{
"answer_id": 307360,
"author": "Mr.Ree",
"author_id": 37946,
"author_profile": "https://Stackoverflow.com/users/37946",
"pm_score": 7,
"selected": true,
"text": "static bool deleteAll( Foo * theElement ) { delete theElement; return true; }\n\nfoo_list . remove_if ( deleteAll );\n"
},
{
"answer_id": 10383000,
"author": "Linoliumz",
"author_id": 363778,
"author_profile": "https://Stackoverflow.com/users/363778",
"pm_score": 3,
"selected": false,
"text": "template <typename T>\nclass Deleter {\npublic:\n Deleter(T* pointer) : pointer_(pointer) { }\n Deleter(const Deleter& deleter) {\n Deleter* d = const_cast<Deleter*>(&deleter);\n pointer_ = d->pointer_;\n d->pointer_ = 0;\n }\n ~Deleter() { delete pointer_; }\n T* pointer_;\n};\n"
},
{
"answer_id": 20404762,
"author": "kendotwill",
"author_id": 1713375,
"author_profile": "https://Stackoverflow.com/users/1713375",
"pm_score": 1,
"selected": false,
"text": "void remove(Foo* foo) { delete foo; }\n....\nfor_each( foo_list.begin(), foo_list.end(), remove );\n"
},
{
"answer_id": 21740770,
"author": "Adisak",
"author_id": 14904,
"author_profile": "https://Stackoverflow.com/users/14904",
"pm_score": 4,
"selected": false,
"text": "for(auto &it:foo_list) delete it; foo_list.clear();\n"
},
{
"answer_id": 22980249,
"author": "Heero",
"author_id": 3517920,
"author_profile": "https://Stackoverflow.com/users/3517920",
"pm_score": 2,
"selected": false,
"text": "for(list<Foo*>::const_iterator it = foo_list.begin(); it != foo_list.end(); it++)\n{\n delete *it;\n} \nfoo_list.clear();\n"
},
{
"answer_id": 25867610,
"author": "ostappus",
"author_id": 2324228,
"author_profile": "https://Stackoverflow.com/users/2324228",
"pm_score": 2,
"selected": false,
"text": "std::vector<Type*> v;\n...\nstd::for_each(v.begin(), v.end(), std::default_delete<Type>());\n"
},
{
"answer_id": 51142181,
"author": "CompEng88",
"author_id": 916046,
"author_profile": "https://Stackoverflow.com/users/916046",
"pm_score": 0,
"selected": false,
"text": "for (Object *i : container) delete i; \ncontainer.clear();\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307084",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1400/"
] |
307,089 | <p>I've been looking for some guidelines on how to layout PHP code. I've found some good references, such as the following:</p>
<p><a href="http://www.dagbladet.no/development/phpcodingstandard/" rel="nofollow noreferrer">http://www.dagbladet.no/development/phpcodingstandard/</a></p>
<p>and <a href="https://stackoverflow.com/questions/5214/whats-a-good-standard-code-layout-for-a-php-application">this question</a> on SO.</p>
<p>However, none of that quite gets to what I'm specifically wondering about, which is the integration of HTML and PHP. For example:</p>
<ol>
<li>Is it OK to have a PHP file that starts out with HTML tags and only has PHP inserted where needed? Or should you just have one section of PHP code that contains everything?</li>
<li>If you have a chunk of PHP code in the middle of which is a set of <code>echo</code>'s that just output a fixed bit of HTML, is it better to break out of PHP and just put in the HTML directly?</li>
<li>Should functions all be defined in dedicated PHP files, or is it OK to define a bunch of functions at the top of a file and call them later on in that same file?</li>
</ol>
<p>There are probably other questions I'd like to ask, but really I'm looking for someone to point me at some kind of resource online that offers guidance on the general idea of how HTML and PHP should be combined together.</p>
| [
{
"answer_id": 307164,
"author": "Nick Van Brunt",
"author_id": 30470,
"author_profile": "https://Stackoverflow.com/users/30470",
"pm_score": 2,
"selected": false,
"text": "index.php"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307089",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11522/"
] |
307,094 | <p>I have a couple of tables that I want to map to classes. The tables look like this:</p>
<pre><code>Asset
---------
AssetId
AssetName
Product
---------
ProductId
ProductName
AssetId
Disposal
---------
DisposalId
AssetId
DisposalDate
</code></pre>
<p>Basically what I want to do is join the Product Table to the Disposal table on AssetId so that my Product has a collection of Disposals joined by asset. I have defined the following mapping but NHibernate (1.2) seems to ignore the key column defined in the bag and chooses to join the Product table to the Disposal table by ProductId (ie Product.ProductId = Disposal.AssetId). I'm not sure if this is a bug or if I'm not defining it properly but if anyone has a way to do this I'd be most greatful.</p>
<pre><code> <class name="Product" table="Product" lazy="false">
<id name="ProductId" column="ProductId" type="int">
<generator class="native" />
</id>
<property name="ProductName" column="ProductName"/>
<bag name="Disposals" fetch="join" >
<key column="AssetId" foreign-key="AssetId/>
<many-to-many class="Disposal"/>
</bag>
</class>
</code></pre>
| [
{
"answer_id": 750741,
"author": "Stefan Steinegger",
"author_id": 2658202,
"author_profile": "https://Stackoverflow.com/users/2658202",
"pm_score": 1,
"selected": true,
"text": " <class name=\"Product\" table=\"Product\" lazy=\"false\">\n <id name=\"ProductId\" column=\"ProductId\" type=\"int\">\n <generator class=\"native\" />\n </id>\n <property name=\"ProductName\" column=\"ProductName\"/>\n <many-to-one name name=\"Asset\" class=\"Asset\" column=\"AssetId\" />\n </class>\n\n <class name=\"Asset\">\n <id name=\"AssetId\" >\n <generator class=\"native\" />\n </id>\n <property name=\"AssetName\" />\n <bag name=\"Disposals\">\n <key column=\"AssetId\" />\n <many-to-many class=\"Disposal\" />\n </bag>\n </class>\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307094",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/493/"
] |
307,096 | <p>When using tables in a CSS-based layout, I've noticed if I have a table with 4 columns (2 on the side are small for spacing, 2 in the middle are for content), when I type content in one of the two middle columns, it will stay at the top, which is perfect.</p>
<p>However, if I type content in the other middle column, and press enter, the content in the other middle content will come down.</p>
<p>This means I can never type content in the two columns while keeping the content in both columns glued to the top (roof) of the table column. I have tried everything, is there a way I can do this? If I can't do this, my content looks wonky as it's not level in the two columns, and thus unprofessional.</p>
| [
{
"answer_id": 307186,
"author": "Zack The Human",
"author_id": 18265,
"author_profile": "https://Stackoverflow.com/users/18265",
"pm_score": 1,
"selected": false,
"text": "td {\n vertical-align:top;\n}\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32484/"
] |
307,098 | <p>i get a Keyword not supported: '192.168.1.1;initial catalog'. error when trying to do this </p>
<p><code>Dim cn As New SqlConnection(str)</code> </p>
<p>where str is the connection string starts with '192.168.1.1;initial catalog' ...
I have not specified the provider in the connection string</p>
| [
{
"answer_id": 307114,
"author": "lomaxx",
"author_id": 493,
"author_profile": "https://Stackoverflow.com/users/493",
"pm_score": 5,
"selected": true,
"text": "Dim str As String\nstr = \"Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;\"\n\nDim cn As New SqlConnection(str)\n"
},
{
"answer_id": 307119,
"author": "Barry Dorman",
"author_id": 39475,
"author_profile": "https://Stackoverflow.com/users/39475",
"pm_score": 2,
"selected": false,
"text": "Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307098",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,120 | <p>I need to set a system environment variable from a Bash script that would be available outside of the current scope. So you would normally export environment variables like this:</p>
<pre><code>export MY_VAR=/opt/my_var
</code></pre>
<p>But I need the environment variable to be available at a system level though. Is this possible?</p>
| [
{
"answer_id": 307145,
"author": "Douglas Leeder",
"author_id": 3978,
"author_profile": "https://Stackoverflow.com/users/3978",
"pm_score": 4,
"selected": false,
"text": "source {script}\n"
},
{
"answer_id": 307204,
"author": "Jeremy Cantrell",
"author_id": 18866,
"author_profile": "https://Stackoverflow.com/users/18866",
"pm_score": 4,
"selected": true,
"text": "#!/bin/bash\necho MYVAR=abc123\n"
},
{
"answer_id": 68023961,
"author": "koyaanisqatsi",
"author_id": 11740758,
"author_profile": "https://Stackoverflow.com/users/11740758",
"pm_score": 1,
"selected": false,
"text": "root"
},
{
"answer_id": 73170171,
"author": "Himanshu Tanwar",
"author_id": 10075467,
"author_profile": "https://Stackoverflow.com/users/10075467",
"pm_score": 0,
"selected": false,
"text": "# Executable : exec.sh\nexport var=\"test\"\ninvar=\"inside variable\"\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307120",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18228/"
] |
307,128 | <p>I'm having trouble with this code:</p>
<pre><code>NSRect itemFrame;
id item;
// code to assign item goes here.
itemFrame.origin.y -= [item respondsToSelector:@selector(selectedHeight)] ? [item selectedHeight] : [self defaultSelectedHeight];
</code></pre>
<p>This is the problematic bit:</p>
<pre><code>[item selectedHeight]
</code></pre>
<p>The compiler is assuming that the return type is id. I though that adding a cast would fix this:</p>
<pre><code>(float)[item selectedHeight]
</code></pre>
<p>but it doesn't work. </p>
<p>What am I doing wrong? (I suspect the problem is to do with resolving pointers related to id but I can't find any relevant documentation).</p>
| [
{
"answer_id": 307146,
"author": "Marc Charbonneau",
"author_id": 35136,
"author_profile": "https://Stackoverflow.com/users/35136",
"pm_score": 1,
"selected": false,
"text": "selectedHeight"
},
{
"answer_id": 307147,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 6,
"selected": true,
"text": "[[item selectedHeight] floatValue]"
},
{
"answer_id": 307149,
"author": "Sherm Pendley",
"author_id": 27631,
"author_profile": "https://Stackoverflow.com/users/27631",
"pm_score": 1,
"selected": false,
"text": "SomeItemClass *item;\n"
},
{
"answer_id": 12976887,
"author": "csonuryilmaz",
"author_id": 1750142,
"author_profile": "https://Stackoverflow.com/users/1750142",
"pm_score": 3,
"selected": false,
"text": "id obj;\nfloat fVal;\n\nfVal = [obj floatValue];\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307128",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,141 | <p>I need to test for general URLs using any protocol (http, https, shttp, ftp, svn, mysql and things I don't know about).</p>
<p>My first pass is this:</p>
<pre><code>\w+://(\w+\.)+[\w+](/[\w]+)(\?[-A-Z0-9+&@#/%=~_|!:,.;]*)?
</code></pre>
<p>(<a href="http://perldoc.perl.org/perlre.html" rel="nofollow noreferrer">PCRE</a> and <a href="http://msdn.microsoft.com/en-us/library/hs600312.aspx" rel="nofollow noreferrer">.NET</a> so nothing to fancy)</p>
| [
{
"answer_id": 307142,
"author": "BCS",
"author_id": 1343,
"author_profile": "https://Stackoverflow.com/users/1343",
"pm_score": 2,
"selected": false,
"text": "[\\w+-]+://([a-zA-Z0-9]+\\.)+[[a-zA-Z0-9]+](/[%\\w]+)(\\?[-A-Z0-9+&@#/%=~_|!:,.;]*)?\n"
},
{
"answer_id": 307182,
"author": "Christian C. Salvadó",
"author_id": 5445,
"author_profile": "https://Stackoverflow.com/users/5445",
"pm_score": 3,
"selected": true,
"text": "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?\n"
},
{
"answer_id": 15708979,
"author": "aychedee",
"author_id": 639295,
"author_profile": "https://Stackoverflow.com/users/639295",
"pm_score": 1,
"selected": false,
"text": "something.co.uk"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] |
307,148 | <p>Vim is acting slow when I scroll. The cursor skips some lines when I'm pressing j/k continually.</p>
<p>I'm using xterm and urxvt. In both vim acts like this.</p>
<p>This happens locally, with small or big files. I do use Control + F/B they work just fine.</p>
<p>EDIT: ttyfast in small files did the trick but in bigger is the same. When running without customization it goes allright.</p>
| [
{
"answer_id": 307175,
"author": "Jeremy Cantrell",
"author_id": 18866,
"author_profile": "https://Stackoverflow.com/users/18866",
"pm_score": 7,
"selected": true,
"text": ":help 'ttyfast'\n"
},
{
"answer_id": 378967,
"author": "Cyber Oliveira",
"author_id": 9793,
"author_profile": "https://Stackoverflow.com/users/9793",
"pm_score": 6,
"selected": false,
"text": ":set lazyredraw"
},
{
"answer_id": 15955179,
"author": "jtpereyda",
"author_id": 461834,
"author_profile": "https://Stackoverflow.com/users/461834",
"pm_score": 2,
"selected": false,
"text": "$ sudo apt-get install rxvt-unicode\n$ urxvt\n"
},
{
"answer_id": 23144657,
"author": "Matthew Mitchell",
"author_id": 238411,
"author_profile": "https://Stackoverflow.com/users/238411",
"pm_score": 2,
"selected": false,
"text": "let loaded_matchparen = 1\n"
},
{
"answer_id": 34075222,
"author": "Stephen Wood",
"author_id": 896958,
"author_profile": "https://Stackoverflow.com/users/896958",
"pm_score": 4,
"selected": false,
"text": ":set cul!\n"
},
{
"answer_id": 34159294,
"author": "JoErNanO",
"author_id": 1521571,
"author_profile": "https://Stackoverflow.com/users/1521571",
"pm_score": 4,
"selected": false,
"text": "set relativenumber\nset cursorline\n"
},
{
"answer_id": 65472034,
"author": "Chaim Leib Halbert",
"author_id": 1795125,
"author_profile": "https://Stackoverflow.com/users/1795125",
"pm_score": 0,
"selected": false,
"text": "set foldmethod=syntax \"slow!\n"
},
{
"answer_id": 66495534,
"author": "craft",
"author_id": 5367106,
"author_profile": "https://Stackoverflow.com/users/5367106",
"pm_score": 1,
"selected": false,
"text": "j"
},
{
"answer_id": 67596645,
"author": "jpgeek",
"author_id": 454246,
"author_profile": "https://Stackoverflow.com/users/454246",
"pm_score": 2,
"selected": false,
"text": ":help prof\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307148",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36532/"
] |
307,152 | <p>What do I gain by adding a timestamp column called recordversion to a table in ms-sql?</p>
| [
{
"answer_id": 307261,
"author": "TravisO",
"author_id": 35116,
"author_profile": "https://Stackoverflow.com/users/35116",
"pm_score": 1,
"selected": false,
"text": "CreatedBy(varchar) | CreatedOn(date) | ModifiedBy(varchar) | ModifiedOn(date)\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307152",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1632/"
] |
307,179 | <p>Is this defined by the language? Is there a defined maximum? Is it different in different browsers?</p>
| [
{
"answer_id": 307194,
"author": "Peter Bailey",
"author_id": 8815,
"author_profile": "https://Stackoverflow.com/users/8815",
"pm_score": 9,
"selected": false,
"text": "Number.MIN_SAFE_INTEGER;\nNumber.MAX_SAFE_INTEGER;\n"
},
{
"answer_id": 307200,
"author": "Jimmy",
"author_id": 4435,
"author_profile": "https://Stackoverflow.com/users/4435",
"pm_score": 11,
"selected": true,
"text": "Number"
},
{
"answer_id": 307272,
"author": "Raynet",
"author_id": 4294,
"author_profile": "https://Stackoverflow.com/users/4294",
"pm_score": 2,
"selected": false,
"text": "javascript: alert(9e15-(9e15+1));\n"
},
{
"answer_id": 3079182,
"author": "Martin Naatz",
"author_id": 371507,
"author_profile": "https://Stackoverflow.com/users/371507",
"pm_score": 3,
"selected": false,
"text": "maxInt = -1 >>> 1\n"
},
{
"answer_id": 4375743,
"author": "Vjeux",
"author_id": 232122,
"author_profile": "https://Stackoverflow.com/users/232122",
"pm_score": 7,
"selected": false,
"text": "Number"
},
{
"answer_id": 6722456,
"author": "danorton",
"author_id": 351201,
"author_profile": "https://Stackoverflow.com/users/351201",
"pm_score": 5,
"selected": false,
"text": "0…(-1>>>0)"
},
{
"answer_id": 7179733,
"author": "coolaj86",
"author_id": 151312,
"author_profile": "https://Stackoverflow.com/users/151312",
"pm_score": 5,
"selected": false,
"text": "var MAX_INT = 4294967295;\n"
},
{
"answer_id": 8948208,
"author": "BananaNeil",
"author_id": 937841,
"author_profile": "https://Stackoverflow.com/users/937841",
"pm_score": 6,
"selected": false,
"text": "Infinity"
},
{
"answer_id": 11639621,
"author": "Briguy37",
"author_id": 508537,
"author_profile": "https://Stackoverflow.com/users/508537",
"pm_score": 5,
"selected": false,
"text": "console.log(9007199254740993);"
},
{
"answer_id": 15558879,
"author": "TinyTimZamboni",
"author_id": 375688,
"author_profile": "https://Stackoverflow.com/users/375688",
"pm_score": -1,
"selected": false,
"text": "Number.MAX_VALUE = 1.7976931348623157e+308\n"
},
{
"answer_id": 19200268,
"author": "Philippe97",
"author_id": 836862,
"author_profile": "https://Stackoverflow.com/users/836862",
"pm_score": 4,
"selected": false,
"text": "for (var x = 2; x + 1 !== x; x *= 2);\nconsole.log(x);\n"
},
{
"answer_id": 22754473,
"author": "WaiKit Kung",
"author_id": 1325563,
"author_profile": "https://Stackoverflow.com/users/1325563",
"pm_score": 5,
"selected": false,
"text": "Number.MAX_SAFE_INTEGER = Math.pow(2, 53)-1;\nNumber.MIN_SAFE_INTEGER = -Number.MAX_SAFE_INTEGER;\n"
},
{
"answer_id": 26041165,
"author": "jerome",
"author_id": 1268409,
"author_profile": "https://Stackoverflow.com/users/1268409",
"pm_score": 2,
"selected": false,
"text": "var max_int = 0x20000000000000;\nvar min_int = -0x20000000000000;\n(max_int + 1) === 0x20000000000000; //true\n(max_int - 1) < 0x20000000000000; //true\n"
},
{
"answer_id": 49218637,
"author": "Carr",
"author_id": 4365123,
"author_profile": "https://Stackoverflow.com/users/4365123",
"pm_score": 5,
"selected": false,
"text": "9007199254740992 === 9007199254740992 + 1"
},
{
"answer_id": 51398430,
"author": "simhumileco",
"author_id": 4217744,
"author_profile": "https://Stackoverflow.com/users/4217744",
"pm_score": 2,
"selected": false,
"text": "MAX_SAFE_INTEGER"
},
{
"answer_id": 53859607,
"author": "Marwen Trabelsi",
"author_id": 1154692,
"author_profile": "https://Stackoverflow.com/users/1154692",
"pm_score": 1,
"selected": false,
"text": "2^53 - 1"
},
{
"answer_id": 53957713,
"author": "trincot",
"author_id": 5459839,
"author_profile": "https://Stackoverflow.com/users/5459839",
"pm_score": 3,
"selected": false,
"text": "BigInt"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307179",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5657/"
] |
307,183 | <p>In .NET is there a function that tests if a string is syntactically a correct path? I specifically don't want it to test if the path actually exists.</p>
<p>my current take on this is a regex:</p>
<pre><code>([a-zA-Z]:|\\)?\\?([^/\\:*?"<>|]+[/\\])*[^/\\:*?"<>|]*
</code></pre>
<p>matches:</p>
<pre><code>c:\
bbbb
\\bob/john\
..\..\
</code></pre>
<p>rejects:</p>
<pre><code>xy:
c:\\bob
</code></pre>
| [
{
"answer_id": 307196,
"author": "Aaron Palmer",
"author_id": 24908,
"author_profile": "https://Stackoverflow.com/users/24908",
"pm_score": 2,
"selected": true,
"text": "RegEx=\"^([a-zA-Z]\\:|\\\\\\\\[^\\/\\\\:*?\"<>|]+\\\\[^\\/\\\\:*?\"<>|]+)(\\\\[^\\/\\\\:*?\"<>|]+)+(\\.[^\\/\\\\:*?\"<>|]+)$\"\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307183",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] |
307,198 | <p>I want to store a URL prefix in an Windows environment variable. The ampersands in the query string makes this troublesome though.</p>
<p>For example: I have a URL prefix of <code>http://example.com?foo=1&bar=</code> and want to create a full URL by providing a value for the <code>bar</code> parameter. I then want to launch that URL using the "start" command.</p>
<p>Adding quotes around the value for the SET operation is easy enough:</p>
<pre><code>set myvar="http://example.com?foo=1&bar="
</code></pre>
<p>Windows includes the quotes in the actual value though (thanks Windows!):</p>
<pre><code>echo %myvar%
"http://example.com?foo=1&bar=true"
</code></pre>
<p>I know that I can strip quotes away from batch file arguments by using tilde:</p>
<pre><code>echo %~1
</code></pre>
<p>However, I can't seem to do it to named variables:</p>
<pre><code>echo %~myvar%
%~myvar%
</code></pre>
<p>What's the syntax for accomplishing this?</p>
| [
{
"answer_id": 307218,
"author": "wimh",
"author_id": 33499,
"author_profile": "https://Stackoverflow.com/users/33499",
"pm_score": -1,
"selected": false,
"text": "for /f \"tokens=*\" %i in (%myvar%) do set %myvar%=%~i\n"
},
{
"answer_id": 307231,
"author": "zdan",
"author_id": 4304,
"author_profile": "https://Stackoverflow.com/users/4304",
"pm_score": 6,
"selected": true,
"text": "set \"myvar=http://example.com?foo=1&bar=\"\n"
},
{
"answer_id": 2802442,
"author": "Christian d'Heureuse",
"author_id": 337221,
"author_profile": "https://Stackoverflow.com/users/337221",
"pm_score": 2,
"selected": false,
"text": "@echo off\nsetlocal enabledelayedexpansion\nset myvar=\"http://example.com?foo=1&bar=\"\nset myvarWithoutQuotes=!myvar:~1,-1!\necho !myvarWithoutQuotes!\n"
},
{
"answer_id": 7575490,
"author": "CmdCrazy",
"author_id": 967896,
"author_profile": "https://Stackoverflow.com/users/967896",
"pm_score": 1,
"selected": false,
"text": "set myvar=\"http://example.com?foo=1&bar=\"\n\nset bar=true\n\nset launch=%testvar:,-1%%bar%\"\n\nstart iexplore %launch%\n"
},
{
"answer_id": 7742703,
"author": "Keith",
"author_id": 125170,
"author_profile": "https://Stackoverflow.com/users/125170",
"pm_score": 2,
"selected": false,
"text": "SET myvar=###%myvar%###\nSET myvar=%myvar:\"###=%\nSET myvar=%myvar:###\"=%\nSET myvar=%myvar:###=%\n"
},
{
"answer_id": 8641036,
"author": "Chris",
"author_id": 1117048,
"author_profile": "https://Stackoverflow.com/users/1117048",
"pm_score": 3,
"selected": false,
"text": "for %a in (%myvar%) do set myvar=%~a\n"
},
{
"answer_id": 15174893,
"author": "jimhark",
"author_id": 514485,
"author_profile": "https://Stackoverflow.com/users/514485",
"pm_score": 4,
"selected": false,
"text": ":unquote\n set %1=%~2\n goto :EOF\n"
},
{
"answer_id": 27110179,
"author": "Amr Ali",
"author_id": 4208440,
"author_profile": "https://Stackoverflow.com/users/4208440",
"pm_score": 0,
"selected": false,
"text": "@echo off\nset \"myvar=http://example.com?foo=1&bar=\"\nsetlocal EnableDelayedExpansion\necho !myvar!\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3488/"
] |
307,210 | <p>I'm doing a PHP site which displays code examples in various languages (C#, PHP, Perl, Ruby, etc.). Are there any PHP functions which add syntax coloring for these and other languages? </p>
<p>If not, I would at least like to find that one built-in PHP function which does syntax coloring for PHP code, can't find it anymore. Thanks.</p>
| [
{
"answer_id": 307228,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 1,
"selected": false,
"text": "\"<?php\\n$code\\n?>\""
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4639/"
] |
307,232 | <p>I am very curious about the possibility of providing immutability for java beans (by beans here I mean classes with an empty constructor providing getters and setters for members). Clearly these classes are not immutable and where they are used to transport values from the data layer this seems like a real problem.</p>
<p>One approach to this problem has been mentioned here in StackOverflow called "Immutable object pattern in C#" where the object is frozen once fully built. I have an alternative approach and would really like to hear people's opinions on it.</p>
<p>The pattern involves two classes Immutable and Mutable where Mutable and Immutable both implement an interface which provides non-mutating bean methods.</p>
<p>For example</p>
<pre><code>public interface DateBean {
public Date getDate();
public DateBean getImmutableInstance();
public DateBean getMutableInstance();
}
public class ImmutableDate implements DateBean {
private Date date;
ImmutableDate(Date date) {
this.date = new Date(date.getTime());
}
public Date getDate() {
return new Date(date.getTime());
}
public DateBean getImmutableInstance() {
return this;
}
public DateBean getMutableInstance() {
MutableDate dateBean = new MutableDate();
dateBean.setDate(getDate());
return dateBean;
}
}
public class MutableDate implements DateBean {
private Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public DateBean getImmutableInstance() {
return new ImmutableDate(this.date);
}
public DateBean getMutableInstance() {
MutableDate dateBean = new MutableDate();
dateBean.setDate(getDate());
return dateBean;
}
}
</code></pre>
<p>This approach allows the bean to be constructed using reflection (by the usual conventions) and also allows us to convert to an immutable variant at the nearest opportunity. Unfortunately there is clearly a large amount of boilerplate per bean.</p>
<p>I am very interested to hear other people's approach to this issue. (My apologies for not providing a good question, which can be answered rather than discussed :)</p>
| [
{
"answer_id": 307283,
"author": "Michael Rutherfurd",
"author_id": 33889,
"author_profile": "https://Stackoverflow.com/users/33889",
"pm_score": 2,
"selected": false,
"text": "public interface DateBean {\n public Date getDate();\n}\n\npublic class ImmutableDate implements DateBean {\n private final long date;\n\n ImmutableDate(long date) {\n this.date = date;\n }\n\n ImmutableDate(Date date) {\n this(date.getTime());\n }\n\n ImmutableDate(DateBean bean) {\n this(bean.getDate());\n }\n\n public Date getDate() {\n return new Date(date);\n }\n}\n\n\npublic class MutableDate implements DateBean {\n private long date;\n\n MutableDate() {}\n\n MutableDate(long date) {\n this.date = date;\n }\n\n MutableDate(Date date) {\n this(date.getTime());\n }\n\n MutableDate(DateBean bean) {\n this(bean.getDate());\n }\n\n public Date getDate() {\n return new Date(date);\n }\n\n public void setDate(Date date) {\n this.date = date.getTime();\n }\n\n}\n"
},
{
"answer_id": 307284,
"author": "yclian",
"author_id": 36397,
"author_profile": "https://Stackoverflow.com/users/36397",
"pm_score": 1,
"selected": false,
"text": "getImmutableInstance()"
},
{
"answer_id": 310264,
"author": "Chris",
"author_id": 8415,
"author_profile": "https://Stackoverflow.com/users/8415",
"pm_score": 3,
"selected": true,
"text": "public class ImmutableDate implements DateBean\n{\n private DateBean delegate;\n\n public ImmutableDate(DateBean d)\n {\n this.delegate = d;\n }\n\n public Date getDate()\n {\n return delegate.getDate();\n }\n}\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307232",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39476/"
] |
307,236 | <p>Can any one give me a scripts (HTML/CSS/Javascript) that can reproduce this error on <code>IE 7.0</code>? I am trying to fix this bug in my page where I get this warning but could not exactly found the problem. Line number does not match with the source either. </p>
<p>I thought the better approach would be to create a bug and then work on it incrementally rather than making some wild guess!</p>
| [
{
"answer_id": 307385,
"author": "Shog9",
"author_id": 811,
"author_profile": "https://Stackoverflow.com/users/811",
"pm_score": 1,
"selected": false,
"text": "var blah = {};\nblah.methodWhichDoesntExist(); // <-- error\n"
},
{
"answer_id": 307431,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 2,
"selected": false,
"text": "var myEl = document.getElementById('myElement');\nmyEl.appendChild(...)\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307236",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3627/"
] |
307,250 | <p>I have a field in my form labeled "Name" that will contain both the First & Last name.</p>
<p>Our existing dynamic server (to which the form is being POSTed to), expects two separate fields (first name, last name). </p>
<p>Can I use Javascript to split the user input into two separate variables before the form is posted to the server? How would I do this?</p>
| [
{
"answer_id": 307266,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 0,
"selected": false,
"text": "var yourForm = document.getElementById('yourFormId');\nyourform.onsubmit = new function()\n{\n var nameBox = document.getElementById('nameBox');\n var fname = document.createElement('INPUT');\n var lname = document.createElement('INPUT');\n fname.type = 'HIDDEN';\n lname.type = 'HIDDEN';\n fname.name = 'fname';\n lname.name = 'lname';\n\n var tokens = nameBox.value.split(' ');\n\n // Note there are a million ways to break this parser, demonstration only\n fname.value = tokens[0];\n lname.value = tokens[1];\n\n yourForm.appendChild(fname);\n yourForm.appendChild(lname);\n}\n"
},
{
"answer_id": 307282,
"author": "TravisO",
"author_id": 35116,
"author_profile": "https://Stackoverflow.com/users/35116",
"pm_score": 2,
"selected": false,
"text": "John Smith Jr\nDr John Smith\nJohn Smith Esq.\nJohn Smith IV\nJohn A Smith\n"
},
{
"answer_id": 307318,
"author": "localshred",
"author_id": 29690,
"author_profile": "https://Stackoverflow.com/users/29690",
"pm_score": 1,
"selected": true,
"text": "$arrNames = preg_split('/\\s+/', $_POST['name']);\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32154/"
] |
307,273 | <p>I have the whole MVC-Model set up and use HTML views as templates. But I have german strings in there that I would like to translate to other languages at some point.</p>
<p>What is the best way to do this? I know I have to use Zend_Translate, but do I have to implement a single call to a translate function for every word that I have in my view templates?</p>
| [
{
"answer_id": 308170,
"author": "Stefan Gehrig",
"author_id": 11354,
"author_profile": "https://Stackoverflow.com/users/11354",
"pm_score": 5,
"selected": true,
"text": "// setup your translation\n$translate = new Zend_Translate('csv', '/my/path/source-de.csv', 'de');\n$translate->addTranslation('/my/path/source-en.csv', 'en');\n// add the translation adapter to the registry\nZend_Registry::set('Zend_Translate', $translate);\n"
},
{
"answer_id": 308233,
"author": "smack0007",
"author_id": 26566,
"author_profile": "https://Stackoverflow.com/users/26566",
"pm_score": 1,
"selected": false,
"text": "<?=$this->translate('Add');?>\n<?=$this->translate('Delete');?>\n<?=$this->translate('Are you sure you want to delete %1$s?', $thing);?>\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9535/"
] |
307,287 | <p>I have a question about implementing caching (memoization) using arrays in Haskell. The following pattern works:</p>
<pre><code>f = (fA !)
where fA = listArray...
</code></pre>
<p>But this does not (the speed of the program suggests that the array is getting recreated each call or something):</p>
<pre><code>f n = (fA ! n)
where fA = listArray...
</code></pre>
<p>Defining fA outside of a where clause (in "global scope") also works with either pattern.</p>
<p>I was hoping that someone could point me towards a technical explanation of what the difference between the above two patterns is.</p>
<p>Note that I am using the latest GHC, and I'm not sure if this is just a compiler peculiarity or part of the language itself.</p>
<p>EDIT: ! is used for array access, so fA ! 5 means fA[5] in C++ syntax. My understanding of Haskell is that (fA !) n would be the same as (fA ! n)...also it would have been more conventional for me to have written "f n = fA ! n" (without the parentheses). Anyway, I get the same behaviour no matter how I parenthesize.</p>
| [
{
"answer_id": 307399,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https://Stackoverflow.com/users/28258",
"pm_score": 3,
"selected": false,
"text": "-v4"
},
{
"answer_id": 308567,
"author": "luqui",
"author_id": 33796,
"author_profile": "https://Stackoverflow.com/users/33796",
"pm_score": 3,
"selected": false,
"text": "f = let fA = listArray ... in \\n -> fA ! n\nf' = \\n -> let fA = listArray ... in fA ! n\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307287",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,292 | <p>I have been bitten by a poorly architected solution. It is not thread safe! </p>
<p>I have several shared classes and members in the solution, and during development all was cool...<br>
BizTalk has sunk my battle ship. </p>
<p>We are using a custom BizTalk Adapter to call my assemblies. The Adapter is calling my code and running things in parallel, so I assume it is using multiple threads all under the same AppDomain. </p>
<p>What I would like to do is make my code run under its own AppDomain so the shared problems I have will not muck with each other. </p>
<p>I have a very simple class that the BizTalk adapter is instantiating then running a Process() method. </p>
<p>I would like to create a new AppDomain inside my Process() method, so each time BizTalk spins another thread, it will have its own version of the static classes and methods. </p>
<p>BizTalkAdapter Code: </p>
<pre><code> // this is inside the BizTalkAdapter and it is calling the Loader class //
private void SendMessage(IBaseMessage message, TransactionalTransmitProperties properties)
{
Stream strm = message.BodyPart.GetOriginalDataStream();
string connectionString = properties.ConnectionString;
string msgFileName = message.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties") as string;
Loader loader = new Loader(strm, msgFileName, connectionString);
loader.Process();
EventLog.WriteEntry("Loader", "Successfully processed: " + msgFileName);
}
</code></pre>
<p>This is the class BizTalk Calls: </p>
<pre><code>public class Loader
{
private string connectionString;
private string fileName;
private Stream stream;
private DataFile dataFile;
public Loader(Stream stream, string fileName, string connectionString)
{
this.connectionString = connectionString;
this.fileName = fileName;
this.stream = stream;
}
public void Process()
{
//***** Create AppDomain HERE *****
// run following code entirely under that domain
dataFile = new DataFile(aredStream, fileName, connectionString);
dataFile.ParseFile();
dataFile.Save();
// get rid of the AppDomain here...
}
}
</code></pre>
<p>FYI: The Loader class is in a seperate DLL from the dataFile class.</p>
<p>Any help would be appreciated. I will continue to working on making the code Thread-Safe, but I feel like this could be the "simple" answer. </p>
<p>If anyone has any other thought, please throw in.</p>
<p>Thank you,<br>
Keith</p>
<blockquote>
<p>Just for completeness.</p>
<p>I did find that if I marked the send adapter as "Ordered Delivery" in
the "Transport Advanced Options" dialog I was able to avoid the
multi-thread issues I was having.</p>
<p>I figure this is another possible answer to my problem, but not
necessarily to the question.</p>
</blockquote>
| [
{
"answer_id": 307310,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 0,
"selected": false,
"text": "public class Loader\n{\n private static object SyncRoot = new object();\n private string connectionString;\n private string fileName;\n private Stream stream;\n private DataFile dataFile;\n\n public Loader(Stream stream, string fileName, string connectionString)\n {\n this.connectionString = connectionString;\n this.fileName = fileName;\n this.stream = stream;\n } \n\n public void Process()\n {\n\n lock(SyncRoot) {\n dataFile = new DataFile(aredStream, fileName, connectionString);\n dataFile.ParseFile();\n dataFile.Save();\n }\n\n }\n\n}\n"
},
{
"answer_id": 307836,
"author": "Kev",
"author_id": 419,
"author_profile": "https://Stackoverflow.com/users/419",
"pm_score": 3,
"selected": true,
"text": "public class Loader\n{\n\n private string connectionString;\n private string fileName;\n private Stream stream;\n private DataFile dataFile;\n\n public Loader(Stream stream, string fileName, string connectionString)\n {\n this.connectionString = connectionString;\n this.fileName = fileName;\n this.stream = stream;\n } \n\n public void Process()\n {\n //***** Create AppDomain HERE *****\n string threadID = Thread.CurrentThread.ManagedThreadId.ToString();\n AppDomain appDomain = AppDomain.CreateDomain(threadID);\n\n DataFile dataFile = \n (DataFile) appDomain.CreateInstanceAndUnwrap(\n \"<DataFile AssemblyName>\", \n \"DataFile\", \n true, \n BindingFlags.Default,\n null,\n new object[] \n { \n aredstream, \n filename, \n connectionString \n },\n null,\n null,\n null);\n dataFile.ParseFile();\n dataFile.Save();\n\n appDomain.Unload(threadID); \n }\n}\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1048/"
] |
307,294 | <p>SOLVED: Nevermind, the links were visited, and the border definition was missing for visited links (as someone pointed out, thanks). As for the color being first place in the border definition, the snippet comes from the IE Developper Toolbar, this is not directly my code. Anyway, thank you guys !</p>
<p>Why does the link in the following snippet does not render underlined with a dashed line, just as expected and as ff would do ?</p>
<pre><code><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML Strict//EN"><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD><STYLE>
/* Rule 1 of css/style.css */
* {
PADDING-RIGHT: 0px;
PADDING-LEFT: 0px;
PADDING-BOTTOM: 0px;
MARGIN: 0px;
PADDING-TOP: 0px;
FONT-FAMILY: "trebuchet ms", Arial, Helvetica, sans-serif
}
/* Rule 26 of css/style.css */
#main {
PADDING-RIGHT: 15px;
PADDING-LEFT: 15px;
PADDING-BOTTOM: 15px;
PADDING-TOP: 15px
}
/* Rule 12 of css/style.css */
#page {
BORDER-RIGHT: #555 1px solid;
PADDING-RIGHT: 0px;
BORDER-TOP: #555 1px solid;
PADDING-LEFT: 0px;
BACKGROUND: #fff;
PADDING-BOTTOM: 0px;
MARGIN: 50px auto;
BORDER-LEFT: #555 1px solid;
WIDTH: 752px;
PADDING-TOP: 0px;
BORDER-BOTTOM: #555 1px solid
}
/* Rule 2 of css/style.css */
BODY {
BACKGROUND: url(bg.gif) #ebeeff repeat-y center 50%
}
/* Rule 35 of css/style.css */
#main A:link {
COLOR: #437fda;
BORDER-BOTTOM: #437fda 1px dashed;
TEXT-DECORATION: none
}
</STYLE></HEAD>
<BODY><DIV id="page"><DIV id="main"><TABLE><TBODY><TR><TD>
<A href="http://www.immo-brasseurs.com/coords.php?num=37">Test link </A>
</TD></TR></TBODY></TABLE></DIV></DIV></BODY></HTML>
</code></pre>
| [
{
"answer_id": 307297,
"author": "Patrick Desjardins",
"author_id": 13913,
"author_profile": "https://Stackoverflow.com/users/13913",
"pm_score": 3,
"selected": true,
"text": "*{...}"
},
{
"answer_id": 307301,
"author": "Cristian Libardo",
"author_id": 16526,
"author_profile": "https://Stackoverflow.com/users/16526",
"pm_score": 0,
"selected": false,
"text": "#main A:link {\n ...\n display:block\n}\n"
},
{
"answer_id": 307307,
"author": "Marc Charbonneau",
"author_id": 35136,
"author_profile": "https://Stackoverflow.com/users/35136",
"pm_score": -1,
"selected": false,
"text": "#main a"
},
{
"answer_id": 307321,
"author": "Ian G",
"author_id": 31765,
"author_profile": "https://Stackoverflow.com/users/31765",
"pm_score": -1,
"selected": false,
"text": "#main a {\ncolor:#437fda; \nborder-bottom: 1px solid #437fda;\ntext-decoration:none;\n}\n\n#main a:visited {\ncolor:#437fda; \nborder-bottom: 1px solid #437fda;\ntext-decoration:none;\n}\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39474/"
] |
307,304 | <p>How do I convert an SQL Server SMALLDATETIME to Unix Timestamp? </p>
<p>date was stored as CAST(0x96040474 AS SmallDateTime) in MS Access DB. Data was dumped to SQL and I'm looking to convert those times to Unix Timestamps for MySQL.</p>
<p>Thanks
AO</p>
| [
{
"answer_id": 307625,
"author": "Ken Gentle",
"author_id": 8709,
"author_profile": "https://Stackoverflow.com/users/8709",
"pm_score": 0,
"selected": false,
"text": "smalldatetime"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,305 | <p>What's the easiest way to play a sound file (.wav) in Python? By easiest I mean both most platform independent and requiring the least dependencies. pygame is certainly an option, but it seems overkill for just sound.</p>
| [
{
"answer_id": 307316,
"author": "Rizwan Kassim",
"author_id": 35335,
"author_profile": "https://Stackoverflow.com/users/35335",
"pm_score": 3,
"selected": false,
"text": "import time, wave, pymedia.audio.sound as sound\nf= wave.open( 'YOUR FILE NAME', 'rb' )\nsampleRate= f.getframerate()\nchannels= f.getnchannels()\nformat= sound.AFMT_S16_LE\nsnd= sound.Output( sampleRate, channels, format )\ns= f.readframes( 300000 )\nsnd.play( s )\n"
},
{
"answer_id": 307501,
"author": "csexton",
"author_id": 19839,
"author_profile": "https://Stackoverflow.com/users/19839",
"pm_score": 6,
"selected": true,
"text": "s = Sound() \ns.read('sound.wav') \ns.play()\n"
},
{
"answer_id": 310393,
"author": "Peter Shinners",
"author_id": 17209,
"author_profile": "https://Stackoverflow.com/users/17209",
"pm_score": 4,
"selected": false,
"text": "import pyglet\n\nmusic = pyglet.resource.media('music.mp3')\nmusic.play()\n\npyglet.app.run()\n"
},
{
"answer_id": 311634,
"author": "orestis",
"author_id": 32617,
"author_profile": "https://Stackoverflow.com/users/32617",
"pm_score": 7,
"selected": false,
"text": "import winsound\n\nwinsound.PlaySound('sound.wav', winsound.SND_FILENAME)\n"
},
{
"answer_id": 1852132,
"author": "suki",
"author_id": 225392,
"author_profile": "https://Stackoverflow.com/users/225392",
"pm_score": 2,
"selected": false,
"text": "pygame.init()\npygame.mixer.Sound('sound.wav').play()\n"
},
{
"answer_id": 7592937,
"author": "ramkumar",
"author_id": 970446,
"author_profile": "https://Stackoverflow.com/users/970446",
"pm_score": 3,
"selected": false,
"text": "import pygame\n\nimport time\n\npygame.init()\n\npygame.mixer.music.load(\"test.wav\")\n\npygame.mixer.music.play()\n\ntime.sleep(10)\n"
},
{
"answer_id": 15323370,
"author": "Dave C",
"author_id": 1249075,
"author_profile": "https://Stackoverflow.com/users/1249075",
"pm_score": 2,
"selected": false,
"text": "from sound4python import sound\nimport random\na = []\nfor idx in xrange(1*16000):\n a.append(random.randint(-16384,16384))\nsound(a)\n"
},
{
"answer_id": 17978545,
"author": "Fillip",
"author_id": 2639370,
"author_profile": "https://Stackoverflow.com/users/2639370",
"pm_score": 5,
"selected": false,
"text": "import os\nos.system(\"start C:/thepathyouwant/file\")\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307305",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15055/"
] |
307,313 | <p>I am writing an iPhone application, and need to save the state of my application (5K or so).</p>
<p>My main worry is data persisting across upgrades. Some of the applications I use clearly got this wrong, and I would prefer not to!</p>
| [
{
"answer_id": 9675747,
"author": "Allison",
"author_id": 1166266,
"author_profile": "https://Stackoverflow.com/users/1166266",
"pm_score": 4,
"selected": false,
"text": "NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];\n[prefs setObject:@\"TextToSave\" forKey:@\"keyToFindText\"];\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307313",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27074/"
] |
307,322 | <p>Let's say I have some code like this:<br /></p>
<pre><code><html>
<head><title>Title</title></head>
<body>
<?php
if (!$someCondition){
die();
}
else{
#Do something
}
?>
</body>
<html>
</code></pre>
<p>I hope the purpose of this code is straightforward. If a certain condition is met (ie can't connect to database), then the program should die, but otherwise it should execute. My problem arises when the die() function is executed. It stops <strong>right</strong> there, and sends only the first three lines to the browser, but not the last two lines.</p>
<p>Is there a funciton that I can use instead of die() so that the php chunks will stop executing, but the static HTML text is still sent through?</p>
| [
{
"answer_id": 307325,
"author": "stalepretzel",
"author_id": 1615,
"author_profile": "https://Stackoverflow.com/users/1615",
"pm_score": 0,
"selected": false,
"text": "die()"
},
{
"answer_id": 307336,
"author": "J Cooper",
"author_id": 38803,
"author_profile": "https://Stackoverflow.com/users/38803",
"pm_score": 0,
"selected": false,
"text": "die()"
},
{
"answer_id": 307345,
"author": "Kornel",
"author_id": 27009,
"author_profile": "https://Stackoverflow.com/users/27009",
"pm_score": 3,
"selected": false,
"text": "<?php\nfunction logic() {\n if (!$someCondition) {\n return 'display_empty_page';\n } else {\n return 'display_other_stuff';\n }\n}\n\npresentation(logic());\n"
},
{
"answer_id": 307354,
"author": "localshred",
"author_id": 29690,
"author_profile": "https://Stackoverflow.com/users/29690",
"pm_score": 3,
"selected": true,
"text": "<?php\n\nprintHeader(); // outputs the html header\ntry\n{\n if (some condition)\n {\n throw new Exception(\"It Died...\");\n }\n // More processing here that should not execute if the above condition is true\n // ...\n}\ncatch (Exception e)\n{\n echo $e->getMessage();\n}\nprintFooter(); // outputs the html footer\n\n?>\n"
},
{
"answer_id": 307376,
"author": "Andrew G. Johnson",
"author_id": 428190,
"author_profile": "https://Stackoverflow.com/users/428190",
"pm_score": 2,
"selected": false,
"text": "<html>\n<head><title>Title</title></head>\n<body>\n\n<?php\nif (!$someCondition){\n die();\n}\nelse{\n #Do something\n}\n?>\n</body>\n<html>\n"
},
{
"answer_id": 307387,
"author": "TonyUser",
"author_id": 22873,
"author_profile": "https://Stackoverflow.com/users/22873",
"pm_score": 0,
"selected": false,
"text": "register_shutdown_function"
},
{
"answer_id": 307613,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 0,
"selected": false,
"text": "<html>\n<head><title>Title</title></head>\n<body>\n\n<?php\ndo {\n if (!$someCondition){\n break;\n } else {\n #Do something\n }\n} while (0);\n?>\n</body>\n<html>\n"
},
{
"answer_id": 17277179,
"author": "PHP",
"author_id": 2077779,
"author_profile": "https://Stackoverflow.com/users/2077779",
"pm_score": 0,
"selected": false,
"text": "<html>\n<head><title>Title</title></head>\n<body>\n\n<?php\nif (!$someCondition){\nheader (\"location:error_page.php?erro_message='This error occured'\");\n\n die();\n}\nelse{\n #Do something\n}\n?>\n</body>\n<html>\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1615/"
] |
307,338 | <p>how to create a good plugin engine for standalone executables created with pyInstaller, py2exe or similar tools? </p>
<p>I do not have experience with py2exe, but pyInstaller uses an import hook to import packages from it's compressed repository. Of course I am able to import dynamically another compressed repository created with pyInstaller and execute the code - this may be a simple plugin engine.</p>
<p>Problems appears when the plugin (this what is imported dynamically) uses a library that is not present in original repository (never imported). This is because import hook is for the original application and searches for packages in original repository - not the one imported later (plugin package repository). </p>
<p>Is there an easy way to solve this problem? Maybe there exist such engine?</p>
| [
{
"answer_id": 307517,
"author": "monkut",
"author_id": 24718,
"author_profile": "https://Stackoverflow.com/users/24718",
"pm_score": 3,
"selected": true,
"text": "from distutils.core import setup\nimport py2exe\n\nsetup (name = \"script2compile\",\n console=['script2compile.pyw'],\n version = \"1.4\",\n author = \"me\",\n author_email=\"somemail@me.com\",\n url=\"myurl.com\",\n windows = [{\n \"script\":\"script2compile.pyw\",\n \"icon_resources\":[(1,\"./ICONS/app.ico\")] # Icon file to use for display\n }],\n # put packages/libraries to include in the \"packages\" list\n options = {\"py2exe\":{\"packages\": [ \"pickle\",\n \"csv\",\n \"Tkconstants\",\n \"Tkinter\",\n \"tkFileDialog\",\n \"pyexpat\",\n \"xml.dom.minidom\",\n \"win32pdh\",\n \"win32pdhutil\",\n \"win32api\",\n \"win32con\",\n \"subprocess\", \n ]}} \n\n )\n\nimport win32pdh\nimport win32pdhutil\nimport win32api\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1369629/"
] |
307,343 | <p>Is it possible to forward declare an standard container in a header file? For example, take the following code:</p>
<pre><code>#include <vector>
class Foo
{
private:
std::vector<int> container_;
...
};
</code></pre>
<p>I want to be able to do something like this:</p>
<pre><code>namespace std
{
template <typename T> class vector;
}
class Foo
{
private:
std::vector<int> container_;
...
};
</code></pre>
<p>Can this be done?</p>
| [
{
"answer_id": 307349,
"author": "Evan Teran",
"author_id": 13430,
"author_profile": "https://Stackoverflow.com/users/13430",
"pm_score": 4,
"selected": false,
"text": "container_"
},
{
"answer_id": 307408,
"author": "Rob Kennedy",
"author_id": 33732,
"author_profile": "https://Stackoverflow.com/users/33732",
"pm_score": 6,
"selected": true,
"text": "vector"
},
{
"answer_id": 3922609,
"author": "Sebastian Mach",
"author_id": 76722,
"author_profile": "https://Stackoverflow.com/users/76722",
"pm_score": 4,
"selected": false,
"text": "<iosfwd>"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307343",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9236/"
] |
307,348 | <p>I need to create a custom control to display bmp images with alpha channel. The background can be painted in different colors and the images have shadows so I need to truly "paint" the alpha channel.</p>
<p>Does anybody know how to do it?</p>
<p>I also want if possible to create a mask using the alpha channel information to know whether the mouse has been click on the image or on the transparent area.</p>
<p>Any kind of help will be appreciated!</p>
<p>Thanks.</p>
<p>Edited(JDePedro): As some of you have suggested I've been trying to use alpha blend to paint the bitmap with alpha channel. This just a test I've implemented where I load a 32-bit bitmap from resources and I try to paint it using AlphaBlend function:</p>
<pre><code>void CAlphaDlg::OnPaint()
{
CClientDC dc(this);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP);
BITMAP BitMap;
bitmap.GetBitmap(&BitMap);
int nWidth = BitMap.bmWidth;
int nHeight = BitMap.bmHeight;
CBitmap *pOldBitmap = dcMem.SelectObject(&bitmap);
BLENDFUNCTION m_bf;
m_bf.BlendOp = AC_SRC_OVER;
m_bf.BlendFlags = 0;
m_bf.SourceConstantAlpha = 255;
m_bf.AlphaFormat = AC_SRC_ALPHA;
AlphaBlend(dc.GetSafeHdc(), 100, 100, nWidth, nHeight, dcMem.GetSafeHdc(), 0, 0,nWidth, nHeight,m_bf);
dcMem.SelectObject(pOldBitmap);
CDialog::OnPaint();
}
</code></pre>
<p>This is just a test so I put the code in the OnPaint of the dialog (I also tried the AlphaBlend function of the CDC object).</p>
<p>The non-transparent areas are being painted correctly but I get white where the bitmap should be transparent.</p>
<p>Any help???</p>
<p>This is a screenshot..it's not easy to see but there is a white rectangle around the blue circle:
<a href="http://img385.imageshack.us/img385/7965/alphamh8.png">alt text http://img385.imageshack.us/img385/7965/alphamh8.png</a></p>
<p>Ok. I got it! I have to pre-multiply every pixel for the alpha value. Someone can suggest the optimized way to do that?</p>
| [
{
"answer_id": 333542,
"author": "mackenir",
"author_id": 25457,
"author_profile": "https://Stackoverflow.com/users/25457",
"pm_score": 1,
"selected": false,
"text": "R = multiplicationLookup[alpha][R];\nG = multiplicationLookup[alpha][G];\nB = multiplicationLookup[alpha][B];\n"
},
{
"answer_id": 17186974,
"author": "Roel",
"author_id": 11449,
"author_profile": "https://Stackoverflow.com/users/11449",
"pm_score": 4,
"selected": false,
"text": "inline void PremultiplyBitmapAlpha(HDC hDC, HBITMAP hBmp)\n{\n BITMAP bm = { 0 };\n GetObject(hBmp, sizeof(bm), &bm);\n BITMAPINFO* bmi = (BITMAPINFO*) _alloca(sizeof(BITMAPINFOHEADER) + (256 * sizeof(RGBQUAD)));\n ::ZeroMemory(bmi, sizeof(BITMAPINFOHEADER) + (256 * sizeof(RGBQUAD)));\n bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);\n BOOL bRes = ::GetDIBits(hDC, hBmp, 0, bm.bmHeight, NULL, bmi, DIB_RGB_COLORS);\n if( !bRes || bmi->bmiHeader.biBitCount != 32 ) return;\n LPBYTE pBitData = (LPBYTE) ::LocalAlloc(LPTR, bm.bmWidth * bm.bmHeight * sizeof(DWORD));\n if( pBitData == NULL ) return;\n LPBYTE pData = pBitData;\n ::GetDIBits(hDC, hBmp, 0, bm.bmHeight, pData, bmi, DIB_RGB_COLORS);\n for( int y = 0; y < bm.bmHeight; y++ ) {\n for( int x = 0; x < bm.bmWidth; x++ ) {\n pData[0] = (BYTE)((DWORD)pData[0] * pData[3] / 255);\n pData[1] = (BYTE)((DWORD)pData[1] * pData[3] / 255);\n pData[2] = (BYTE)((DWORD)pData[2] * pData[3] / 255);\n pData += 4;\n }\n }\n ::SetDIBits(hDC, hBmp, 0, bm.bmHeight, pBitData, bmi, DIB_RGB_COLORS);\n ::LocalFree(pBitData);\n}\n"
}
] | 2008/11/20 | [
"https://Stackoverflow.com/questions/307348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14053/"
] |
307,352 | <p>I just ran across the following error (and found the solution online, but it's not present in Stack Overflow):</p>
<blockquote>
<p>(.gnu.linkonce.[stuff]): undefined
reference to [method] [object
file]:(.gnu.linkonce.[stuff]):
undefined reference to `typeinfo for
[classname]'</p>
</blockquote>
<p>Why might one get one of these "undefined reference to typeinfo" linker errors?</p>
<p>(Bonus points if you can explain what's going on behind the scenes.)</p>
| [
{
"answer_id": 307381,
"author": "cdleary",
"author_id": 3594,
"author_profile": "https://Stackoverflow.com/users/3594",
"pm_score": 6,
"selected": false,
"text": "virtual void foo();\n"
},
{
"answer_id": 307427,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 9,
"selected": true,
"text": "virtual void fn() { /* insert code here */ }\n"
},
{
"answer_id": 3114829,
"author": "human",
"author_id": 375805,
"author_profile": "https://Stackoverflow.com/users/375805",
"pm_score": 5,
"selected": false,
"text": "__attribute__ ((visibility(\"default\")))\n"
},
{
"answer_id": 4184877,
"author": "Sergiy Belozorov",
"author_id": 178315,
"author_profile": "https://Stackoverflow.com/users/178315",
"pm_score": 7,
"selected": false,
"text": "-fno-rtti"
},
{
"answer_id": 34031859,
"author": "dinkelk",
"author_id": 1743929,
"author_profile": "https://Stackoverflow.com/users/1743929",
"pm_score": 4,
"selected": false,
"text": "clang++"
},
{
"answer_id": 39155467,
"author": "Alex Paniutin",
"author_id": 6491350,
"author_profile": "https://Stackoverflow.com/users/6491350",
"pm_score": 2,
"selected": false,
"text": "class ICommProvider\n{\npublic:\n /**\n * @brief If connection is established, it sends the message into the server.\n * @param[in] msg - message to be send\n * @return 0 if success, error otherwise\n */\n virtual int vaSend(const std::string &msg) = 0;\n /**\n * @brief If connection is established, it is waiting will server response back.\n * @param[out] msg is the message received from server\n * @return 0 if success, error otherwise\n */\n virtual int vaReceive(std::string &msg) = 0;\n virtual int vaSendRaw(const char *buff, int bufflen) = 0;\n virtual int vaReceiveRaw(char *buff, int bufflen) = 0;\n /**\n * @bief Closes current connection (if needed) after serving\n * @return 0 if success, error otherwise\n */\n virtual int vaClose();\n};"
},
{
"answer_id": 52391146,
"author": "Vitaly Isaev",
"author_id": 2361497,
"author_profile": "https://Stackoverflow.com/users/2361497",
"pm_score": 1,
"selected": false,
"text": "-f-nortti"
},
{
"answer_id": 60435535,
"author": "Goosebumps",
"author_id": 1297364,
"author_profile": "https://Stackoverflow.com/users/1297364",
"pm_score": 3,
"selected": false,
"text": "class IInterface\n{\npublic:\n virtual void Foo() = 0;\n}\n"
},
{
"answer_id": 69033818,
"author": "Kai Petzke",
"author_id": 2528436,
"author_profile": "https://Stackoverflow.com/users/2528436",
"pm_score": 2,
"selected": false,
"text": "/usr/bin/ld: module.o:(.data.rel.ro+0x10): undefined reference to `typeinfo for type_xxx'\n/usr/bin/ld: module.o:(.data.rel.ro+0x28): undefined reference to `typeinfo for type_xxx'\n/usr/bin/ld: module.o:(.data.rel.ro+0x40): undefined reference to `typeinfo for type_xxx'\n/usr/bin/ld: module.o:(.data.rel.ro+0x150): undefined reference to `type_xxx::has_property(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307352",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3594/"
] |
307,362 | <p>I'm trying to get this:</p>
<pre><code>//C.h
#ifndef C_H
#define C_H
#include "c.h"
class C
{
public:
C();
int function(int, int);
};
#endif
</code></pre>
<p>which is defined in this:</p>
<pre><code>//c.cpp
#include "c.h"
C::C()
{
}
int C::function(int a, int b)
{
return a * b;
}
</code></pre>
<p>to work in this:</p>
<pre><code>//crp.cpp
#include <iostream>
#include "c.h"
void main(void)
{
C a;
std::cout << a.function(1, 2);
}
</code></pre>
<p>but I get two errors</p>
<p>Error: Unresolved external 'C::C()' referenced from C:\C++\CRP.OBJ</p>
<p>Error: Unresolved external 'C::function(int, int)' referenced from C:\C++\CRP.OBJ</p>
<p>I'm really stuck. Help v. much appreciated! </p>
<p>EDIT:</p>
<p>Thank you for your replies,</p>
<p>I'm using Borland C++ 5.5.1 for Win32, via the command line, I'm not actually sure what a linker is, this is the first time I've tried doing this.</p>
| [
{
"answer_id": 307378,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 2,
"selected": false,
"text": "bcc32 -ecrp.exe crp.cpp c.cpp\n"
},
{
"answer_id": 307383,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "C:\\c++>bcc32 crp\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307362",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,364 | <p>I have a gallery I quickly coded up for a small site, and under Firefox 3 and Safari 3 works fine. But when I test on my old best friend IE7, it seems to not fire the imageVar.onload = function() { // code here }.. which I want to use to stop the load effect and load the image. </p>
<p>Please bear in mind...</p>
<ul>
<li>I know the thumbnails are just scaled down version of the larger images. When the images are finalised by the client I am going to create proper thumbnails.</li>
<li>This is my first attempt to try and get out of procedural JavaScript for the most part.. so please go easy and kindly let me know where my code sucks!</li>
</ul>
| [
{
"answer_id": 307392,
"author": "Eran Galperin",
"author_id": 10585,
"author_profile": "https://Stackoverflow.com/users/10585",
"pm_score": 2,
"selected": false,
"text": " window.load = function(){ \n //actions to be performed on window load\n }\n\n imageViewer.image.onload = function(){ \n //actions to be performed on image load\n }\n"
},
{
"answer_id": 307403,
"author": "Vincent Ramdhanie",
"author_id": 27439,
"author_profile": "https://Stackoverflow.com/users/27439",
"pm_score": 0,
"selected": false,
"text": "$(document).ready(function(){\n //your code\n});\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307364",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31671/"
] |
307,365 | <p>I'm trying to attach a PDF attachment to an email being sent with System.Net.Mail. The attachment-adding part looks like this:</p>
<pre><code>using (MemoryStream pdfStream = new MemoryStream())
{
pdfStream.Write(pdfData, 0, pdfData.Length);
Attachment a = new Attachment(pdfStream,
string.Format("Receipt_{0}_{1}.pdf", jobId, DateTime.UtcNow.ToString("yyyyMMddHHmm")));
msg.Attachments.Add(a);
SmtpClient smtp = new SmtpClient(serverName, port);
smtp.Credentials = new NetworkCredential(fromEmailName, fromEmailPassword);
smtp.Send(msg);
}
</code></pre>
<p>The problem is that the attachment gets corrupted on the other end. I found some discussion of this problem <a href="http://www.systemwebmail.com/faq/4.4.8.aspx" rel="noreferrer">here</a>, however the solution mentioned on that page used System.Web.Mail.MailAttachment, which was made obsolete in .NET 2.0. </p>
<p>I've tried changing the TransferEncoding in the Attachment class (which replaces MailAttachment), but had no luck. Has anyone solved this on .NET 2.0?</p>
| [
{
"answer_id": 307401,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 5,
"selected": true,
"text": "pdfStream.Seek(0,SeekOrigin.Begin)"
},
{
"answer_id": 74226856,
"author": "Jacob C.",
"author_id": 14210270,
"author_profile": "https://Stackoverflow.com/users/14210270",
"pm_score": 1,
"selected": false,
"text": "using(MemoryStream memoryStream = new MemoryStream()) \n{\n byte[] contentAsBytes = File.ReadAllBytes(EnterFileLocationOnDisk);\n\n memoryStream.Write(contentAsBytes, 0, contentAsBytes.Length);\n\n // Set the position to the beginning of the stream.\n memoryStream.Seek(0, SeekOrigin.Begin);\n\n // Create attachment\n ContentType contentType = new ContentType();\n //Pick correct media type Octet/PDF/Zip etc.\n contentType.MediaType = MediaTypeNames.Application.Octet;\n contentType.Name = EnterFileName;\n Attachment attachment = new Attachment(memoryStream, contentType);\n\n // Add the attachment\n message.Attachments.Add(attachment);\n\n // Send Mail via SmtpClient\n client.Send(message);\n}\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307365",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24952/"
] |
307,367 | <p>I have a C project that is built using a makefile, Eclipse constantly warns about "Invalid project path: Duplicate path entries", but I cannot figure out what the hell it wants me to do. I would like to disable this warning and continue with my life.</p>
<p>My application compiles and runs fine, with not a single warning except this one. Being a conscientious developer I am keen to fix this problem so I have the warm fuzzies only a clean build can bring.</p>
| [
{
"answer_id": 12089022,
"author": "bouum",
"author_id": 1619349,
"author_profile": "https://Stackoverflow.com/users/1619349",
"pm_score": 0,
"selected": false,
"text": ".metadata"
},
{
"answer_id": 27936817,
"author": "jww",
"author_id": 608639,
"author_profile": "https://Stackoverflow.com/users/608639",
"pm_score": 0,
"selected": false,
"text": "infoPath"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307367",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34879/"
] |
307,370 | <p>I'm have a ADO DataSet that I'm loading from its XML file via ReadXml. The data and the schema are in separate files.</p>
<p>Right now, it takes close to 13 seconds to load this DataSet. I can cut this to 700 milliseconds if I don't read the DataSet's schema and just let ReadXml infer the schema, but then the resulting DataSet doesn't contain any constraints.</p>
<p>I've tried doing this:</p>
<pre><code>Console.WriteLine("Reading dataset with external schema.");
ds.ReadXmlSchema(xsdPath);
Console.WriteLine("Reading the schema took {0} milliseconds.", sw.ElapsedMilliseconds);
foreach (DataTable dt in ds.Tables)
{
dt.BeginLoadData();
}
ds.ReadXml(xmlPath);
Console.WriteLine("ReadXml completed after {0} milliseconds.", sw.ElapsedMilliseconds);
foreach (DataTable dt in ds.Tables)
{
dt.EndLoadData();
}
Console.WriteLine("Process complete at {0} milliseconds.", sw.ElapsedMilliseconds);
</code></pre>
<p>When I do this, reading the schema takes 27ms, and reading the DataSet takes 12000+ milliseconds. And that's the time reported <em>before</em> I call EndLoadData on all the DataTables.</p>
<p>This is not an enormous amount of data - it's about 1.5mb, there are no nested relations, and all of the tables contain two or three columns of 6-30 characters. The only thing I can figure that's different if I read the schema up front is that the schema includes all of the unique constraints. But BeginLoadData is supposed to turn constraints off (as well as change notification, etc.). So that shouldn't apply here. (And yes, I've tried just setting EnforceConstraints to false.)</p>
<p>I've read many reports of people improving the load time of DataSets by reading the schema first instead of having the object infer the schema. In my case, inferring the schema makes for a process that's about 20 times faster than having the schema provided explicitly.</p>
<p>This is making me a little crazy. This DataSet's schema is generated off of metainformation, and I'm tempted to write a method that creates it programatically and just deseralizes it with an XmlReader. But I'd much prefer not to.</p>
<p>What am I missing? What else can I do to improve the speed here?</p>
| [
{
"answer_id": 10856773,
"author": "Jon",
"author_id": 1431550,
"author_profile": "https://Stackoverflow.com/users/1431550",
"pm_score": 1,
"selected": false,
"text": "void create_files()\n {\n //create text file with data\n StreamWriter sr = new StreamWriter(\"plain_text.txt\");\n\n for(int i=0;i<1000000;i++)\n {\n sr.WriteLine(i.ToString() + \"<SEP>\" + \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbb\" + i.ToString());\n }\n\n sr.Flush();\n sr.Close();\n\n //create xml file with data\n DataSet ds = new DataSet(\"DS1\");\n\n DataTable dt = new DataTable(\"T1\");\n\n DataColumn c1 = new DataColumn(\"c1\", typeof(int));\n DataColumn c2 = new DataColumn(\"c2\", typeof(string));\n\n dt.Columns.Add(c1);\n dt.Columns.Add(c2);\n\n ds.Tables.Add(dt);\n\n DataRow dr;\n\n for(int j=0; j< 1000000; j++)\n {\n dr = dt.NewRow();\n dr[0]=j;\n dr[1] = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbb\" + j.ToString();\n dt.Rows.Add(dr);\n }\n\n ds.WriteXml(\"xml_text.xml\");\n\n }\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307370",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19403/"
] |
307,389 | <p>Is there a firefox plugin or something similar I can use to validate that my html output has properly closed tags?</p>
| [
{
"answer_id": 307412,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 1,
"selected": false,
"text": "alt"
},
{
"answer_id": 307461,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "https://addons.mozilla.org/en-US/firefox/addon/60\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307389",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7883/"
] |
307,391 | <p>I am using an ASP.NET <code>ModalPopupExtender</code> on a page and would like to prevent the dialog from hiding when the user presses the ok button in certain conditions. But I can't seem to find a way.</p>
<p>What I am looking for is something like this</p>
<pre><code>ajax:ModalPopupExtender
...
OnOkScript="return confirm('You sure?')"
...
</code></pre>
<p>if confirm is false, then the modal dialog doesn't disappear.</p>
| [
{
"answer_id": 307412,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 1,
"selected": false,
"text": "alt"
},
{
"answer_id": 307461,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "https://addons.mozilla.org/en-US/firefox/addon/60\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307391",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/698/"
] |
307,411 | <p>I'm new to jQuery, and I'm totally struggling with using jQuery UI's <code>sortable</code>.</p>
<p>I'm trying to put together a page to facilitate grouping and ordering of items.</p>
<p>My page has a list of groups, and each group contains a list of items. I want to allow users to be able to do the following: </p>
<blockquote>
<ol>
<li>Reorder the groups </li>
<li>Reorder the items within the groups </li>
<li>Move the items between the groups</li>
</ol>
</blockquote>
<p>The first two requirements are no problem. I'm able to sort them just fine. The problem comes in with the third requirement. I just can't connect those lists to each other. Some code might help. Here's the markup. </p>
<pre><code><ul id="groupsList" class="groupsList">
<li id="group1" class="group">Group 1
<ul id="groupItems1" class="itemsList">
<li id="item1-1" class="item">Item 1.1</li>
<li id="item1-2" class="item">Item 1.2</li>
</ul>
</li>
<li id="group2" class="group">Group 2
<ul id="groupItems2" class="itemsList">
<li id="item2-1" class="item">Item 2.1</li>
<li id="item2-2" class="item">Item 2.2</li>
</ul>
</li>
<li id="group3" class="group">Group 3
<ul id="groupItems3" class="itemsList">
<li id="item3-1" class="item">Item 3.1</li>
<li id="item3-2" class="item">Item 3.2</li>
</ul>
</li>
</ul>
</code></pre>
<p>I was able to sort the lists by putting <code>$('#groupsList').sortable({});</code> and <code>$('.itemsList').sortable({});</code> in the <code>document ready function</code>. I tried using the <code>connectWith</code> option for <code>sortable</code> to make it work, but I failed spectacularly. What I'd like to do is have the every <code>groupItemsX</code> list connected to every <code>groupItemsX</code> list but itself. How should I do that?</p>
<hr>
<p>I was thinking I needed to specifically not connect a list to itself less there be some sort of circular reference. Granted, I'm not working with Excel, but it seemed like that could cause some sort of never ending recursion that would cause a stack overflow or something. Hmm. Sorry for the pun. Couldn't help myself. </p>
<p>Anyway, I was trying to do something like this, and it wasn't working: </p>
<pre><code>$('.groupsList').sortable(); // worked great
$('.groupsList').each( function () {
$(this).sortable( {
connectWith: ['.groupsList':not('#'+ $(this).attr('id') )];
});
});
</code></pre>
<p>I'm sure I've completely mangled the syntax there, and I suppose that's the reason I had to ask the question in the first place. Is it even necessary or helpful performance-wise to filter the current item out of the list?</p>
<p>Both of the answers provided by Adam and JimmyP worked in IE (although they behave really oddly in FireFox, overwriting list items when you try to re-sort). I'll accept one of your answers and vote on the other, but if you have ideas/ suggestions about the filtering, I'd like to hear it.</p>
| [
{
"answer_id": 310508,
"author": "Adam Bellaire",
"author_id": 21632,
"author_profile": "https://Stackoverflow.com/users/21632",
"pm_score": 6,
"selected": true,
"text": "connectWith"
},
{
"answer_id": 311159,
"author": "James",
"author_id": 21677,
"author_profile": "https://Stackoverflow.com/users/21677",
"pm_score": 4,
"selected": false,
"text": "$('#groupsList').sortable();\n$('.itemsList').sortable({\n connectWith: $('.itemsList')\n});\n"
},
{
"answer_id": 10897124,
"author": "Mrigesh Raj Shrestha",
"author_id": 1136833,
"author_profile": "https://Stackoverflow.com/users/1136833",
"pm_score": 2,
"selected": false,
"text": " $(function() {\n $( \"#groupItems1, #groupItems2, #groupItems3\" ).sortable({\n connectWith: \".itemsList\"\n }).disableSelection();\n });\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307411",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1245/"
] |
307,423 | <p>I have the following two files and would like the second to extend the first:</p>
<ol>
<li>wwwroot\site\application.cfc</li>
<li>wwwroot\site\dir\application.cfc</li>
</ol>
<p>However, when I go to declare the component for the second file, I'm not sure what to put in the extends attribute. <strong>My problem is that several dev sites (with a shared SVN repository) are running off the same instance of ColdFusion</strong>, so I can't just create a mapping in the CF admin like so:</p>
<pre><code><cfcomponent extends="site.application">
</code></pre>
<p>However, ColdFusion doesn't like:</p>
<pre><code><cfcomponent extends="..application">
</code></pre>
<p>or any dynamic input like:</p>
<pre><code><cfcomponent extends="#expandpath('..').#application">
</code></pre>
<p>Creating a runtime mapping (<a href="https://stackoverflow.com/questions/287187/extend-a-cfc-using-a-relative-path">like here</a>) doesn't seem possible either. Creating it in the base application.cfc is useless because that code hasn't yet executed by the time the inheriting cfc is being declared; and I can't create the mapping before the inheriting component is defined because there isn't yet an application to attach it to.</p>
<p>Is there any way I can reference the parent directory to accomplish my extends?</p>
<p>Edit to clarify: The ApplicationProxy solution doesn't work because of the bolded text above. Right now, as a workaround, we're simply not checking the \dir\application.cfc into SVN so that each developer can keep a version that extends his/her own root application.cfc. Obviously, this is not ideal.</p>
| [
{
"answer_id": 307441,
"author": "Peter Boughton",
"author_id": 9360,
"author_profile": "https://Stackoverflow.com/users/9360",
"pm_score": 4,
"selected": false,
"text": "<cfcomponent>\n\n <cfset this.name = \"cf7app\" />\n <cfset this.sessionmanagement = true />\n\n</cfcomponent>\n"
},
{
"answer_id": 310303,
"author": "Lucas Moellers",
"author_id": 2232,
"author_profile": "https://Stackoverflow.com/users/2232",
"pm_score": 3,
"selected": true,
"text": "<cfcomponent output=\"false\">\n <cfset variables.higherPath = ReReplace(GetMetaData(this).name,\"\\.[^\\.]+\\.[^\\.]+$\",\"\") />\n <cfset variables.extendApp = CreateObject(\"component\", \"#variables.higherPath#.Application\") />\n\n <cfloop item=\"variables.key\" collection=\"#variables.extendApp#\">\n <cfif IsCustomFunction(variables.extendApp[variables.key])>\n <cfset super[variables.key] = variables.extendApp[variables.key]>\n <cfelse>\n <cfset this[variables.key] = variables.extendApp[variables.key] >\n </cfif>\n </cfloop>\n <cffunction name=\"onApplicationStart\" output=\"false\">\n <cfset super.onApplicationStart() />\n </cffunction>\n"
},
{
"answer_id": 2402979,
"author": "Edward M Smith",
"author_id": 267404,
"author_profile": "https://Stackoverflow.com/users/267404",
"pm_score": 2,
"selected": false,
"text": "<cfcomponent extends=\"cms.Application\" output=\"false\">\n<cfset this.mappings[\"/cms\"] = expandPath(getDirectoryFromPath(getCurrentTemplatePath()) & \"../../../../\")>\n<cflog text=\"#getMetadata(this).extends.path#\">\n</cfcomponent>\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307423",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3420/"
] |
307,433 | <p>Working to get DateTimes for any time zone.
I'm using DateTimeOffset, and a string, and an XmlElement attribute. When I do, I get the following error:</p>
<blockquote>
<p>[InvalidOperationException: 'dateTime'
is an invalid value for the
XmlElementAttribute.DataType property.
dateTime cannot be converted to
System.String.]<br>
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel
model, String ns, ImportContext
context, String dataType,
XmlAttributes a, Boolean repeats,
Boolean openModel, RecursionLimiter
limiter) +450</p>
<p>[InvalidOperationException: There was
an error reflecting type
'System.String'.]<br>
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel
model, String ns, ImportContext
context, String dataType,
XmlAttributes a, Boolean repeats,
Boolean openModel, RecursionLimiter
limiter) +1621<br>
System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(MemberMapping
accessor, FieldModel model,
XmlAttributes a, String ns, Type
choiceIdentifierType, Boolean rpc,
Boolean openModel, RecursionLimiter
limiter) +8750<br>
System.Xml.Serialization.XmlReflectionImporter.ImportFieldMapping(StructModel
parent, FieldModel model,
XmlAttributes a, String ns,
RecursionLimiter limiter) +139<br>
System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping
mapping, StructModel model, Boolean
openModel, String typeName,
RecursionLimiter limiter) +1273</p>
<p>[InvalidOperationException: There was
an error reflecting property
'creationTimeX'.] ...</p>
</blockquote>
<p>Code:</p>
<pre><code> [System.Xml.Serialization.XmlElement(ElementName = "creationTime",
DataType="dateTime")]
public string creationTimeX
{
get
{
return this.creationTimeField.ToString("yyyy-MM-ddTHH:mm:sszzz");
}
set
{
DateTimeOffset.TryParse(value, out this.creationTimeField);
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public System.DateTimeOffset creationTime
{
get {
return this.creationTimeField;
}
set {
this.creationTimeField = value;
}
}
</code></pre>
| [
{
"answer_id": 307453,
"author": "user35559",
"author_id": 35559,
"author_profile": "https://Stackoverflow.com/users/35559",
"pm_score": 0,
"selected": false,
"text": "creationTimeX"
},
{
"answer_id": 310162,
"author": "Asher",
"author_id": 38265,
"author_profile": "https://Stackoverflow.com/users/38265",
"pm_score": 1,
"selected": false,
"text": "DateTime.Ticks"
},
{
"answer_id": 9379897,
"author": "jhilden",
"author_id": 1173800,
"author_profile": "https://Stackoverflow.com/users/1173800",
"pm_score": 2,
"selected": false,
"text": "private const string DateTimeOffsetFormatString = \"yyyy-MM-ddTHH:mm:sszzz\";\nprivate DateTimeOffset eventTimeField;\n\n[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 0)]\npublic string eventTime\n{\n get { return eventTimeField.ToString(DateTimeOffsetFormatString); }\n set { eventTimeField = DateTimeOffset.Parse(value); }\n}\n"
},
{
"answer_id": 54679725,
"author": "nipunasudha",
"author_id": 4112088,
"author_profile": "https://Stackoverflow.com/users/4112088",
"pm_score": 0,
"selected": false,
"text": "UDateTime"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36627/"
] |
307,437 | <p>I have two directories in the same parent directory. Call the parent directory <strong>base</strong> and the children directories <strong>alpha</strong> and <strong>bravo</strong>. I want to replace <strong>alpha</strong> with <strong>bravo</strong>. The simplest method is:</p>
<pre><code>rm -rf alpha
mv bravo alpha
</code></pre>
<p>The mv command is atomic, but the rm -rf is not. Is there a simple way in bash to atomically replace <strong>alpha</strong> with <strong>bravo</strong>? If not, is there a complicated way?</p>
<p>ADDENDUM:</p>
<p>By the by, it's not an insurmountable problem if the directory doesn't exist for a short period. There's only one place that tries to access alpha, and it checks if alpha exists before doing anything critical. If not, it gives an error message. But it would be nice if there was a way to do this. :) Maybe there's some way to modify the inodes directly, or something...</p>
| [
{
"answer_id": 307447,
"author": "Chris Charabaruk",
"author_id": 5697,
"author_profile": "https://Stackoverflow.com/users/5697",
"pm_score": 0,
"selected": false,
"text": "mv alpha delme\nmv bravo alpha\nrm -rf delme\n"
},
{
"answer_id": 307450,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 3,
"selected": false,
"text": "mv alpha delta\nmv bravo alpha\nrm -rf delta\n"
},
{
"answer_id": 307532,
"author": "Doug Currie",
"author_id": 33252,
"author_profile": "https://Stackoverflow.com/users/33252",
"pm_score": 5,
"selected": true,
"text": "$ ls -l\nlrwxrwxrwx alpha -> alpha_1\ndrwxr-xr-x alpha_1\ndrwxr-xr-x alpha_2\n"
},
{
"answer_id": 307887,
"author": "Dan Fego",
"author_id": 34426,
"author_profile": "https://Stackoverflow.com/users/34426",
"pm_score": -1,
"selected": false,
"text": "rm -rf alpha/*\nmv bravo/* alpha/\nrm -rf bravo/\n"
},
{
"answer_id": 1742612,
"author": "Philip Reynolds",
"author_id": 1087,
"author_profile": "https://Stackoverflow.com/users/1087",
"pm_score": 0,
"selected": false,
"text": "ln -nsf <target> <link_name>\n"
},
{
"answer_id": 10886940,
"author": "David Schmitt",
"author_id": 4918,
"author_profile": "https://Stackoverflow.com/users/4918",
"pm_score": 6,
"selected": false,
"text": "mkdir alpha_real\nln -s alpha_real alpha\n\n# now use \"alpha\"\n\nmkdir beta_real\nln -s beta_real tmp \n\n# atomically rename \"tmp\" to \"alpha\"\n# use -T to actually replace \"alpha\" instead of moving *into* \"alpha\"\nmv -T tmp alpha\n"
},
{
"answer_id": 17492792,
"author": "mssaxm",
"author_id": 2430776,
"author_profile": "https://Stackoverflow.com/users/2430776",
"pm_score": 4,
"selected": false,
"text": "-T"
},
{
"answer_id": 20959923,
"author": "Peter",
"author_id": 3167004,
"author_profile": "https://Stackoverflow.com/users/3167004",
"pm_score": 2,
"selected": false,
"text": "mkdir bravo_dir alpha_dir\nln -s bravo_dir bravo\nln -s alpha_dir alpha\nmv -fT bravo alpha\n"
},
{
"answer_id": 48233341,
"author": "Tomilov Anatoliy",
"author_id": 1430927,
"author_profile": "https://Stackoverflow.com/users/1430927",
"pm_score": 0,
"selected": false,
"text": "Z"
},
{
"answer_id": 50353568,
"author": "Lucas Werkmeister",
"author_id": 1420237,
"author_profile": "https://Stackoverflow.com/users/1420237",
"pm_score": 4,
"selected": false,
"text": "renameat2"
},
{
"answer_id": 58661740,
"author": "William Hay",
"author_id": 2370452,
"author_profile": "https://Stackoverflow.com/users/2370452",
"pm_score": 0,
"selected": false,
"text": "mount --bind bravo alpha"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307437",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20903/"
] |
307,438 | <p>In the footer of my page, I would like to add something like "last updated the xx/xx/200x" with this date being the last time a certain mySQL table has been updated.</p>
<p>What is the best way to do that? Is there a function to retrieve the last updated date? Should I access to the database every time I need this value?</p>
| [
{
"answer_id": 307488,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 9,
"selected": true,
"text": "information_schema"
},
{
"answer_id": 3227579,
"author": "Radu Maris",
"author_id": 207603,
"author_profile": "https://Stackoverflow.com/users/207603",
"pm_score": 6,
"selected": false,
"text": "SHOW TABLE STATUS FROM your_database LIKE 'your_table';\n"
},
{
"answer_id": 3676354,
"author": "Andrés Chandía",
"author_id": 443381,
"author_profile": "https://Stackoverflow.com/users/443381",
"pm_score": -1,
"selected": false,
"text": "<?php\n mysql_connect(\"localhost\", \"USER\", \"PASSWORD\") or die(mysql_error());\n mysql_select_db(\"information_schema\") or die(mysql_error());\n $query1 = \"SELECT `UPDATE_TIME` FROM `TABLES` WHERE\n `TABLE_SCHEMA` LIKE 'DataBaseName' AND `TABLE_NAME` LIKE 'TableName'\";\n $result1 = mysql_query($query1) or die(mysql_error());\n while($row = mysql_fetch_array($result1)) {\n echo \"<strong>1r tr.: </strong>\".$row['UPDATE_TIME'];\n }\n?>\n"
},
{
"answer_id": 14214371,
"author": "Francois Bourgeois",
"author_id": 1703313,
"author_profile": "https://Stackoverflow.com/users/1703313",
"pm_score": 4,
"selected": false,
"text": "SELECT UPDATE_TIME, TABLE_SCHEMA, TABLE_NAME\nFROM information_schema.tables\nORDER BY UPDATE_TIME DESC, TABLE_SCHEMA, TABLE_NAME\n"
},
{
"answer_id": 14848350,
"author": "Steve Wood",
"author_id": 2067436,
"author_profile": "https://Stackoverflow.com/users/2067436",
"pm_score": 0,
"selected": false,
"text": " tbl_updated = file.update_time(\n \"C:\\ProgramData\\MySQL\\MySQL Server 5.5\\data\\mydb\\person.frm\")\n"
},
{
"answer_id": 18369829,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 6,
"selected": false,
"text": "mysql> CREATE TABLE foo (\n id INT PRIMARY KEY\n x INT,\n updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP \n ON UPDATE CURRENT_TIMESTAMP,\n KEY (updated_at)\n);\n\nmysql> INSERT INTO foo VALUES (1, NOW() - INTERVAL 3 DAY), (2, NOW());\n\nmysql> SELECT * FROM foo;\n+----+------+---------------------+\n| id | x | updated_at |\n+----+------+---------------------+\n| 1 | NULL | 2013-08-18 03:26:28 |\n| 2 | NULL | 2013-08-21 03:26:28 |\n+----+------+---------------------+\n\nmysql> UPDATE foo SET x = 1234 WHERE id = 1;\n"
},
{
"answer_id": 36634184,
"author": "user2654744",
"author_id": 2654744,
"author_profile": "https://Stackoverflow.com/users/2654744",
"pm_score": 4,
"selected": false,
"text": "cd /var/lib/mysql/<mydatabase>\nls -lhtr *.ibd\n"
},
{
"answer_id": 46323606,
"author": "John McLean",
"author_id": 7099453,
"author_profile": "https://Stackoverflow.com/users/7099453",
"pm_score": 2,
"selected": false,
"text": "grep datadir /etc/my.cnf\ndatadir=/var/lib/mysql\n"
},
{
"answer_id": 50388734,
"author": "Soul Reaver",
"author_id": 639956,
"author_profile": "https://Stackoverflow.com/users/639956",
"pm_score": 2,
"selected": false,
"text": "CREATE PROCEDURE `timestamp_update` ()\nBEGIN\n UPDATE `SCHEMA_NAME`.`TIMESTAMPS_TABLE_NAME`\n SET `timestamp_column`=DATE_FORMAT(NOW(), '%Y-%m-%d %T')\n WHERE `table_name_column`='TABLE_NAME';\nEND\n"
},
{
"answer_id": 59305498,
"author": "justnajm",
"author_id": 389616,
"author_profile": "https://Stackoverflow.com/users/389616",
"pm_score": 1,
"selected": false,
"text": "SHOW TABLE STATUS FROM db_name;\n"
},
{
"answer_id": 64380206,
"author": "TASC Solutions",
"author_id": 4904581,
"author_profile": "https://Stackoverflow.com/users/4904581",
"pm_score": 1,
"selected": false,
"text": "SELECT last_update FROM mysql.innodb_table_stats WHERE table_name = 'yourTblName';\n\n'2020-10-09 08:25:10'\n"
},
{
"answer_id": 69900227,
"author": "Manohar Reddy Poreddy",
"author_id": 984471,
"author_profile": "https://Stackoverflow.com/users/984471",
"pm_score": 0,
"selected": false,
"text": "SELECT\n UPDATE_TIME,\n TABLE_SCHEMA,\n TABLE_NAME\nFROM\n information_schema.tables\nWHERE\n 1 = 1\n AND UPDATE_TIME > '2021-11-09 00:00:00'\n AND TABLE_SCHEMA = 'db_name_here'\n AND TABLE_NAME not in ('table_name_here',)\nORDER BY\n UPDATE_TIME DESC,\n TABLE_SCHEMA,\n TABLE_NAME;\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307438",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39474/"
] |
307,445 | <p>I have a 2D image randomly and sparsely scattered with pixels.<br>
given a point on the image, I need to find the distance to the closest pixel that is not in the background color (black).<br>
What is the fastest way to do this? </p>
<p>The only method I could come up with is building a kd-tree for the pixels. but I would really want to avoid such expensive preprocessing. also, it seems that a kd-tree gives me more than I need. I only need the distance to something and I don't care about what this something is. </p>
| [
{
"answer_id": 320735,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 3,
"selected": false,
"text": "r^2 = dx^2 + dy^2\n"
},
{
"answer_id": 3381634,
"author": "XCS",
"author_id": 407650,
"author_profile": "https://Stackoverflow.com/users/407650",
"pm_score": 1,
"selected": false,
"text": "//(c++ version)\n#include<iostream>\n#include<cmath>\n#include<ctime>\nusing namespace std;\n//ITERATIVE VERSION\n\n//picture witdh&height\n#define width 800\n#define height 600\n//indexex\nint i,j;\n\n//initial point coordinates\nint x,y;\n//variables to work with the array\nint p,u;\n//minimum dist\ndouble min_dist=2000000000;\n//array for memorising the points added\nstruct point{\n int x;\n int y;\n} points[width*height];\ndouble dist;\nbool viz[width][height];\n// direction vectors, used for adding adjacent points in the \"points\" array.\nint dx[8]={1,1,0,-1,-1,-1,0,1};\nint dy[8]={0,1,1,1,0,-1,-1,-1};\nint k,nX,nY;\n//we will generate an image with white&black pixels (0&1)\nbool image[width-1][height-1];\nint main(){\n srand(time(0));\n //generate the random pic\n for(i=1;i<=width-1;i++)\n for(j=1;j<=height-1;j++)\n if(rand()%10001<=9999) //9999/10000 chances of generating a black pixel\n image[i][j]=0;\n else image[i][j]=1;\n //random coordinates for starting x&y\n x=rand()%width;\n y=rand()%height;\n p=1;u=1;\n points[1].x=x;\n points[1].y=y;\n while(p<=u){\n for(k=0;k<=7;k++){\n nX=points[p].x+dx[k];\n nY=points[p].y+dy[k];\n //nX&nY are the coordinates for the next point\n //if we haven't added the point yet\n //also check if the point is valid\n if(nX>0&&nY>0&&nX<width&&nY<height)\n if(viz[nX][nY] == 0 ){\n //mark it as added\n viz[nX][nY]=1;\n //add it in the array\n u++;\n points[u].x=nX;\n points[u].y=nY;\n //if it's not black\n if(image[nX][nY]!=0){\n //calculate the distance\n dist=(x-nX)*(x-nX) + (y-nY)*(y-nY);\n dist=sqrt(dist);\n //if the dist is shorter than the minimum, we save it\n if(dist<min_dist)\n min_dist=dist;\n //you could save the coordinates of the point that has\n //the minimum distance too, like sX=nX;, sY=nY;\n }\n }\n }\n p++;\n}\n cout<<\"Minimum dist:\"<<min_dist<<\"\\n\";\nreturn 0;\n}\n"
},
{
"answer_id": 6741559,
"author": "Adam Eberbach",
"author_id": 189804,
"author_profile": "https://Stackoverflow.com/users/189804",
"pm_score": 0,
"selected": false,
"text": "- (SomeBigObjCStruct *)nearestWalkablePoint:(SomeBigObjCStruct)point { \n\ntypedef struct _testPoint { // using the IYMapPoint object here is very slow\n int x;\n int y;\n} testPoint;\n\n// see if the point supplied is walkable\ntestPoint centre;\ncentre.x = point.x;\ncentre.y = point.y;\n\nNSMutableData *map = [self getWalkingMapDataForLevelId:point.levelId];\n\n// check point for walkable (case radius = 0)\nif(testThePoint(centre.x, centre.y, map) != 0) // bullseye\n return point;\n\n// radius is the distance from the location of point. A square is checked on each iteration, radius units from point.\n// The point with y=0 or x=0 distance is checked first, i.e. the centre of the side of the square. A cursor variable\n// is used to move along the side of the square looking for a walkable point. This proceeds until a walkable point\n// is found or the side is exhausted. Sides are checked until radius is exhausted at which point the search fails.\nint radius = 1;\n\nBOOL leftWithinMap = YES, rightWithinMap = YES, upWithinMap = YES, downWithinMap = YES;\n\ntestPoint leftCentre, upCentre, rightCentre, downCentre;\ntestPoint leftUp, leftDown, rightUp, rightDown;\ntestPoint upLeft, upRight, downLeft, downRight;\n\nleftCentre = rightCentre = upCentre = downCentre = centre;\n\nint foundX = -1;\nint foundY = -1;\n\nwhile(radius < 1000) {\n\n // radius increases. move centres outward\n if(leftWithinMap == YES) {\n\n leftCentre.x -= 1; // move left\n\n if(leftCentre.x < 0) {\n\n leftWithinMap = NO;\n }\n }\n\n if(rightWithinMap == YES) {\n\n rightCentre.x += 1; // move right\n\n if(!(rightCentre.x < kIYMapWidth)) {\n\n rightWithinMap = NO;\n }\n }\n\n if(upWithinMap == YES) {\n\n upCentre.y -= 1; // move up\n\n if(upCentre.y < 0) {\n\n upWithinMap = NO;\n }\n }\n\n if(downWithinMap == YES) {\n\n downCentre.y += 1; // move down\n\n if(!(downCentre.y < kIYMapHeight)) {\n\n downWithinMap = NO;\n }\n }\n\n // set up cursor values for checking along the sides of the square\n leftUp = leftDown = leftCentre;\n leftUp.y -= 1;\n leftDown.y += 1;\n rightUp = rightDown = rightCentre;\n rightUp.y -= 1;\n rightDown.y += 1;\n upRight = upLeft = upCentre;\n upRight.x += 1;\n upLeft.x -= 1;\n downRight = downLeft = downCentre;\n downRight.x += 1;\n downLeft.x -= 1;\n\n // check centres\n if(testThePoint(leftCentre.x, leftCentre.y, map) != 0) {\n\n foundX = leftCentre.x;\n foundY = leftCentre.y;\n break;\n }\n if(testThePoint(rightCentre.x, rightCentre.y, map) != 0) {\n\n foundX = rightCentre.x;\n foundY = rightCentre.y;\n break;\n }\n if(testThePoint(upCentre.x, upCentre.y, map) != 0) {\n\n foundX = upCentre.x;\n foundY = upCentre.y;\n break;\n }\n if(testThePoint(downCentre.x, downCentre.y, map) != 0) {\n\n foundX = downCentre.x;\n foundY = downCentre.y;\n break;\n }\n\n int i;\n\n for(i = 0; i < radius; i++) {\n\n if(leftWithinMap == YES) {\n // LEFT Side - stop short of top/bottom rows because up/down horizontal cursors check that line\n // if cursor position is within map\n if(i < radius - 1) {\n\n if(leftUp.y > 0) {\n // check it\n if(testThePoint(leftUp.x, leftUp.y, map) != 0) {\n foundX = leftUp.x;\n foundY = leftUp.y;\n break;\n }\n leftUp.y -= 1; // moving up\n }\n if(leftDown.y < kIYMapHeight) {\n // check it\n if(testThePoint(leftDown.x, leftDown.y, map) != 0) {\n foundX = leftDown.x;\n foundY = leftDown.y;\n break;\n }\n leftDown.y += 1; // moving down\n }\n }\n }\n\n if(rightWithinMap == YES) {\n // RIGHT Side\n if(i < radius - 1) {\n\n if(rightUp.y > 0) {\n\n if(testThePoint(rightUp.x, rightUp.y, map) != 0) {\n foundX = rightUp.x;\n foundY = rightUp.y;\n break;\n }\n rightUp.y -= 1; // moving up\n }\n if(rightDown.y < kIYMapHeight) {\n\n if(testThePoint(rightDown.x, rightDown.y, map) != 0) {\n foundX = rightDown.x;\n foundY = rightDown.y;\n break;\n }\n rightDown.y += 1; // moving down\n }\n }\n }\n\n if(upWithinMap == YES) {\n // UP Side\n if(upRight.x < kIYMapWidth) {\n\n if(testThePoint(upRight.x, upRight.y, map) != 0) {\n foundX = upRight.x;\n foundY = upRight.y;\n break;\n }\n upRight.x += 1; // moving right\n }\n if(upLeft.x > 0) {\n\n if(testThePoint(upLeft.x, upLeft.y, map) != 0) {\n foundX = upLeft.x;\n foundY = upLeft.y;\n break;\n }\n upLeft.y -= 1; // moving left\n }\n }\n\n if(downWithinMap == YES) {\n // DOWN Side\n if(downRight.x < kIYMapWidth) {\n\n if(testThePoint(downRight.x, downRight.y, map) != 0) {\n foundX = downRight.x;\n foundY = downRight.y;\n break;\n }\n downRight.x += 1; // moving right\n }\n if(downLeft.x > 0) {\n\n if(testThePoint(upLeft.x, upLeft.y, map) != 0) {\n foundX = downLeft.x;\n foundY = downLeft.y;\n break;\n }\n downLeft.y -= 1; // moving left\n }\n }\n }\n\n if(foundX != -1 && foundY != -1) {\n break;\n }\n\n radius++;\n}\n\n// build the return object\nif(foundX != -1 && foundY != -1) {\n\n SomeBigObjCStruct *foundPoint = [SomeBigObjCStruct mapPointWithX:foundX Y:foundY levelId:point.levelId];\n foundPoint.z = [self zWithLevelId:point.levelId];\n return foundPoint;\n}\nreturn nil;\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307445",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9611/"
] |
307,463 | <p>What's the general consensus?</p>
<p>If you need to change the database after a given action, do you use an observer pattern and let the framework / application handle the update for you? Or do you bypass the application and delegate the update to a database trigger?</p>
<p>Obviously the trigger is faster, but is it worth it?</p>
| [
{
"answer_id": 307487,
"author": "Andre Gallo",
"author_id": 14401,
"author_profile": "https://Stackoverflow.com/users/14401",
"pm_score": 2,
"selected": false,
"text": " /// <summary>\n /// Sends changes that were made to retrieved objects to the underlying database, \n /// and specifies the action to be taken if the submission fails.\n /// NOTE: Handling this event to easily perform Audit tasks whenever a table gets updated.\n /// </summary>\n /// <param name=\"failureMode\">The action to be taken if the submission fails. \n /// Valid arguments are as follows:<see cref=\"F:System.Data.Linq.ConflictMode.FailOnFirstConflict\"/>\n /// <see cref=\"F:System.Data.Linq.ConflictMode.ContinueOnConflict\"/></param>\n public override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)\n {\n //Updates\n for (int changeCounter = 0; changeCounter < this.GetChangeSet().Updates.Count; changeCounter++)\n {\n object modifiedEntity = this.GetChangeSet().Updates[changeCounter];\n SetAuditStamp(this, modifiedEntity, ChangeType.Update);\n }\n\n //Inserts\n for (int changeCounter = 0; changeCounter < this.GetChangeSet().Inserts.Count; changeCounter++)\n {\n object modifiedEntity = this.GetChangeSet().Inserts[changeCounter];\n SetAuditStamp(this, modifiedEntity, ChangeType.Insert);\n }\n base.SubmitChanges(failureMode);\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38354/"
] |
307,486 | <p>I want to create a unique id but <code>uniqid()</code> is giving something like <code>'492607b0ee414'</code>. What i would like is something similar to what tinyurl gives: <code>'64k8ra'</code>. The shorter, the better. The only requirements are that it should not have an obvious order and that it should look prettier than a seemingly random sequence of numbers. Letters are preferred over numbers and ideally it would not be mixed case. As the number of entries will not be that many (up to 10000 or so) the risk of collision isn't a huge factor.</p>
<p>Any suggestions appreciated.</p>
| [
{
"answer_id": 307617,
"author": "RJHunter",
"author_id": 39223,
"author_profile": "https://Stackoverflow.com/users/39223",
"pm_score": 2,
"selected": false,
"text": "uniqid()"
},
{
"answer_id": 307773,
"author": "lpfavreau",
"author_id": 35935,
"author_profile": "https://Stackoverflow.com/users/35935",
"pm_score": 7,
"selected": true,
"text": "<?php\nfunction generate_random_letters($length) {\n $random = '';\n for ($i = 0; $i < $length; $i++) {\n $random .= chr(rand(ord('a'), ord('z')));\n }\n return $random;\n}\n"
},
{
"answer_id": 308306,
"author": "OIS",
"author_id": 36175,
"author_profile": "https://Stackoverflow.com/users/36175",
"pm_score": 3,
"selected": false,
"text": "function toUId($baseId, $multiplier = 1) {\n return base_convert($baseId * $multiplier, 10, 36);\n}\nfunction fromUId($uid, $multiplier = 1) {\n return (int) base_convert($uid, 36, 10) / $multiplier;\n}\n\necho toUId(10000, 11111);\n1u5h0w\necho fromUId('1u5h0w', 11111);\n10000\n"
},
{
"answer_id": 368905,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "function rand_str($len = 12, $type = '111', $add = null) {\n $rand = ($type[0] == '1' ? 'abcdefghijklmnpqrstuvwxyz' : '') .\n ($type[1] == '1' ? 'ABCDEFGHIJKLMNPQRSTUVWXYZ' : '') .\n ($type[2] == '1' ? '123456789' : '') .\n (strlen($add) > 0 ? $add : '');\n\n if(empty($rand)) $rand = sha1( uniqid(mt_rand(), true) . uniqid( uniqid(mt_rand(), true), true) );\n\n return substr(str_shuffle( str_repeat($rand, 2) ), 0, $len);\n}\n"
},
{
"answer_id": 1516430,
"author": "gord",
"author_id": 182271,
"author_profile": "https://Stackoverflow.com/users/182271",
"pm_score": 4,
"selected": false,
"text": "gen_uuid()"
},
{
"answer_id": 2113462,
"author": "Adcuz",
"author_id": 256252,
"author_profile": "https://Stackoverflow.com/users/256252",
"pm_score": 4,
"selected": false,
"text": "$id = 100;\nbase_convert($id, 10, 36);\n"
},
{
"answer_id": 3537633,
"author": "Tobias Boschek",
"author_id": 216663,
"author_profile": "https://Stackoverflow.com/users/216663",
"pm_score": 5,
"selected": false,
"text": "function gen_uuid($len=8) {\n\n $hex = md5(\"yourSaltHere\" . uniqid(\"\", true));\n\n $pack = pack('H*', $hex);\n $tmp = base64_encode($pack);\n\n $uid = preg_replace(\"#(*UTF8)[^A-Za-z0-9]#\", \"\", $tmp);\n\n $len = max(4, min(128, $len));\n\n while (strlen($uid) < $len)\n $uid .= gen_uuid(22);\n\n return substr($uid, 0, $len);\n}\n"
},
{
"answer_id": 15086294,
"author": "Aldee",
"author_id": 969645,
"author_profile": "https://Stackoverflow.com/users/969645",
"pm_score": 1,
"selected": false,
"text": "public static function generateCode($length = 6)\n {\n $az = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';\n $azr = rand(0, 51);\n $azs = substr($az, $azr, 10);\n $stamp = hash('sha256', time());\n $mt = hash('sha256', mt_rand(5, 20));\n $alpha = hash('sha256', $azs);\n $hash = str_shuffle($stamp . $mt . $alpha);\n $code = ucfirst(substr($hash, $azr, $length));\n return $code;\n }\n"
},
{
"answer_id": 18987803,
"author": "nico gawenda",
"author_id": 857958,
"author_profile": "https://Stackoverflow.com/users/857958",
"pm_score": 1,
"selected": false,
"text": "mt_rand()"
},
{
"answer_id": 22408968,
"author": "Nico Schefer",
"author_id": 1705555,
"author_profile": "https://Stackoverflow.com/users/1705555",
"pm_score": 5,
"selected": false,
"text": "function gen_uid($l=10){\n return substr(str_shuffle(\"0123456789abcdefghijklmnopqrstuvwxyz\"), 0, $l);\n}\n"
},
{
"answer_id": 25126110,
"author": "John Erck",
"author_id": 394969,
"author_profile": "https://Stackoverflow.com/users/394969",
"pm_score": -1,
"selected": false,
"text": "<?php\n/*\nTHE FOLLOWING CODE WILL PRINT:\nA database_id value of 200 maps to 5K\nA database_id value of 1 maps to 1\nA database_id value of 1987645 maps to 16LOD\n*/\n$database_id = 200;\n$base36value = dec2string($database_id, 36);\necho \"A database_id value of 200 maps to $base36value\\n\";\n$database_id = 1;\n$base36value = dec2string($database_id, 36);\necho \"A database_id value of 1 maps to $base36value\\n\";\n$database_id = 1987645;\n$base36value = dec2string($database_id, 36);\necho \"A database_id value of 1987645 maps to $base36value\\n\";\n\n// HERE'S THE FUNCTION THAT DOES THE HEAVY LIFTING...\nfunction dec2string ($decimal, $base)\n// convert a decimal number into a string using $base\n{\n //DebugBreak();\n global $error;\n $string = null;\n\n $base = (int)$base;\n if ($base < 2 | $base > 36 | $base == 10) {\n echo 'BASE must be in the range 2-9 or 11-36';\n exit;\n } // if\n\n // maximum character string is 36 characters\n $charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';\n\n // strip off excess characters (anything beyond $base)\n $charset = substr($charset, 0, $base);\n\n if (!ereg('(^[0-9]{1,50}$)', trim($decimal))) {\n $error['dec_input'] = 'Value must be a positive integer with < 50 digits';\n return false;\n } // if\n\n do {\n // get remainder after dividing by BASE\n $remainder = bcmod($decimal, $base);\n\n $char = substr($charset, $remainder, 1); // get CHAR from array\n $string = \"$char$string\"; // prepend to output\n\n //$decimal = ($decimal - $remainder) / $base;\n $decimal = bcdiv(bcsub($decimal, $remainder), $base);\n\n } while ($decimal > 0);\n\n return $string;\n\n}\n\n?>\n"
},
{
"answer_id": 64594484,
"author": "oriadam",
"author_id": 3356679,
"author_profile": "https://Stackoverflow.com/users/3356679",
"pm_score": 1,
"selected": false,
"text": "substr(uniqid(),-10);\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6037/"
] |
307,494 | <p>I would like to do something like the following:</p>
<pre><code>def add(a, b):
#some code
def subtract(a, b):
#some code
operations = [add, subtract]
operations[0]( 5,3)
operations[1](5,3)
</code></pre>
<p>In python, is it possible to assign something like a function pointer?</p>
| [
{
"answer_id": 307622,
"author": "Ned Batchelder",
"author_id": 14343,
"author_profile": "https://Stackoverflow.com/users/14343",
"pm_score": 3,
"selected": false,
"text": "def the_simple_way(a, b):\n # blah blah\n\ndef the_complicated_way(a, b):\n # blah blah\n\ndef foo(way):\n if way == 'complicated':\n doit = the_complicated_way\n else:\n doit = the_simple_way\n\n doit(a, b)\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307494",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/64/"
] |
307,495 | <p>in Web 2.0 applications many users usually want to stay logged in ('remember me' flag) and on the other hand their cookie can give access to very private data. Is there a way to prevent that somebody who steals the cookie - directly from the computer or via sniffing - can use the cookie to get access to the user's data? Always HTTPS is not an option.</p>
<p>Thanks, Bernd</p>
<p>[Edit] Connect the IP address to the cookie is not an option either.</p>
| [
{
"answer_id": 309276,
"author": "mjmcinto",
"author_id": 28660,
"author_profile": "https://Stackoverflow.com/users/28660",
"pm_score": 0,
"selected": false,
"text": "Page.Request.UserHostName\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,500 | <p>I have a table structure that looks like:</p>
<pre><code><table>
<tr id="row1">
<td>
<div>row 1 content1</div>
</td>
<td>
<div>row 1 content2</div>
</td>
<td>
<div>row 1 content3</div>
</td>
</tr>
<tr id="row2">
<td>
<div>row 2 content1</div>
</td>
<td>
<div>row 2 content2</div>
</td>
<td>
<div>row 2 content3</div>
</td>
</tr>
<tr id="row3">
<td>
<div>row 3 content1</div>
</td>
<td>
<div>row 3 content2</div>
</td>
<td>
<div>row 3 content3</div>
</td>
</tr>
</table>
</code></pre>
<p>Using jQuery I am trying to select the DIV in the second cell of the third row. I tried the following (amongst other things):</p>
<pre><code>var d = $('#row3').children(':eq(1)').children(':eq(0)');
</code></pre>
<p>What I get back is an array with a single element (the DIV I'm after) and I have to then access using d[0]. Why is jQuery returning a single element array, I thought using the selector above would return the DIV element directly?</p>
<hr>
<p><strong><a href="https://stackoverflow.com/questions/307500/how-do-i-select-an-element-in-jquery#307509">@Shog9</a></strong> - Duh...Ok a light just switched on in my brain, I get it now. Cheers.</p>
| [
{
"answer_id": 307509,
"author": "Shog9",
"author_id": 811,
"author_profile": "https://Stackoverflow.com/users/811",
"pm_score": 6,
"selected": true,
"text": "$(\"selector\").each(function()\n{\n this.style.backgroundColor = \"red\";\n});\n"
},
{
"answer_id": 6269297,
"author": "CodeNinja",
"author_id": 787952,
"author_profile": "https://Stackoverflow.com/users/787952",
"pm_score": 4,
"selected": false,
"text": "$(\"selector\")[0].value \n"
},
{
"answer_id": 11345480,
"author": "vcarel",
"author_id": 1202385,
"author_profile": "https://Stackoverflow.com/users/1202385",
"pm_score": 5,
"selected": false,
"text": "$(\"selector\").first().val()\n"
},
{
"answer_id": 31743377,
"author": "pradip_PRP",
"author_id": 3164333,
"author_profile": "https://Stackoverflow.com/users/3164333",
"pm_score": -1,
"selected": false,
"text": "$divElement = $('#row3 td div');"
},
{
"answer_id": 43210705,
"author": "bnsk",
"author_id": 1666429,
"author_profile": "https://Stackoverflow.com/users/1666429",
"pm_score": 2,
"selected": false,
"text": "<div>Div 1</div>\n <div class=\"highlight\">Div 2</div>\n <div id=\"third\">Div 3</div>\n <div class=\"highlight\">Div 4</div>"
},
{
"answer_id": 57929154,
"author": "Waqu Wex",
"author_id": 12059273,
"author_profile": "https://Stackoverflow.com/users/12059273",
"pm_score": 1,
"selected": false,
"text": "$($('li')[0]).css('color', 'blue');"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307500",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/419/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.