qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
97,370
|
<p>I have a macro which refreshes all fields in a document (the equivalent of doing an <kbd>F9</kbd> on the fields). I'd like to fire this macro automatically when the user saves the document.</p>
<p>Under options I can select "update fields when document is printed", but that's not what I want. In the VBA editor I only seem to find events for the <code>Document_Open()</code> event, not the <code>Document_Save()</code> event.</p>
<p>Is it possible to get the macro to fire when the user saves the document?</p>
<p>Please note:</p>
<ol>
<li>This is Word 97. I know it is
possible in later versions of Word</li>
<li>I don't want to replace the standard
Save button on the toolbar with a
button to run my custom macro.
Replacing the button on the toolbar
applies to all documents and I only
want it to affect this one document.</li>
</ol>
<p>To understand why I need this, the document contains a "SaveDate" field and I'd like this field to update on the screen when the user clicks Save. So if you can suggest another way to achieve this, then that would be just as good.</p>
|
[
{
"answer_id": 97486,
"author": "Gregg",
"author_id": 18266,
"author_profile": "https://Stackoverflow.com/users/18266",
"pm_score": 1,
"selected": false,
"text": "<Import Project=\"$(MSBuildProjectDirectory)\\my.team.build.targets.proj\" />\n <Import Project=\"$(SolutionRoot)/libs/my.team.build/my.team.build.targets\" Condition=\"Exists('$(SolutionRoot)/libs/my.team.build/my.team.build.targets')\" />\n"
},
{
"answer_id": 99893,
"author": "Mr. Kraus",
"author_id": 5132,
"author_profile": "https://Stackoverflow.com/users/5132",
"pm_score": 0,
"selected": false,
"text": "<Import Project=\"$(MSBuildProjectDirectory)\\TeamBuildOverrides.targets\" />\n"
},
{
"answer_id": 100493,
"author": "Martin Woodward",
"author_id": 6438,
"author_profile": "https://Stackoverflow.com/users/6438",
"pm_score": 5,
"selected": true,
"text": "<Import Project=\"myTeamBuild.targets\"/>\n $/TeamProject/main/MySolution/TeamBuild\n <add key=\"ConfigurationFolderRecursionType\" value=\"Full\" />\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97370",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9625/"
] |
97,371
|
<p>I need to copy the newest file in a directory to a new location. So far I've found resources on the <a href="http://www.ss64.com/nt/forfiles.html" rel="noreferrer">forfiles</a> command, a <a href="https://stackoverflow.com/q/51837">date-related question</a> here, and another <a href="https://stackoverflow.com/q/50902">related question</a>. I'm just having a bit of trouble putting the pieces together! How do I copy the newest file in that directory to a new place?</p>
|
[
{
"answer_id": 97414,
"author": "Robert Swisher",
"author_id": 1852,
"author_profile": "https://Stackoverflow.com/users/1852",
"pm_score": 2,
"selected": false,
"text": "cp `ls -t1 | head -1` /somedir/\n"
},
{
"answer_id": 97427,
"author": "moswald",
"author_id": 8368,
"author_profile": "https://Stackoverflow.com/users/8368",
"pm_score": 2,
"selected": false,
"text": "@echo off\nfor /F %%i in ('dir /B /O:-D *.txt') do (\n call :open \"%%i\"\n exit /B 0\n)\n:open\n start \"window title\" \"cmd /K copy %~1 new_file_loc\"\nexit /B 0\n"
},
{
"answer_id": 97438,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": -1,
"selected": false,
"text": " find -type f -printf \"%T@ %p \\n\" \\\n | sort \\\n | tail -n 1 \\\n | sed -r \"s/^\\S+\\s//;s/\\s*$//\" \\\n | xargs -iSTR cp STR newestfile\n"
},
{
"answer_id": 97782,
"author": "PabloG",
"author_id": 394,
"author_profile": "https://Stackoverflow.com/users/394",
"pm_score": 7,
"selected": true,
"text": "FOR /F \"delims=\" %%I IN ('DIR *.* /A-D /B /O:-D') DO COPY \"%%I\" <<NewDir>> & EXIT\n"
},
{
"answer_id": 978259,
"author": "Chris Magnuson",
"author_id": 101679,
"author_profile": "https://Stackoverflow.com/users/101679",
"pm_score": 7,
"selected": false,
"text": "FOR /F \"delims=\" %%I IN ('DIR \"*.*\" /A-D /B /O:D') DO SET \"NewestFile=%%I\"\n %NewestFile% :Variables\nSET DatabaseBackupPath=\\\\virtualserver1\\Database Backups\n\necho.\necho Restore WebServer Database\nFOR /F \"delims=|\" %%I IN ('DIR \"%DatabaseBackupPath%\\WebServer\\*.bak\" /B /O:D') DO SET NewestFile=%%I\ncopy \"%DatabaseBackupPath%\\WebServer\\%NewestFile%\" \"D:\\\"\n\nsqlcmd -U <username> -P <password> -d master -Q ^\n\"RESTORE DATABASE [ExampleDatabaseName] ^\nFROM DISK = N'D:\\%NewestFile%' ^\nWITH FILE = 1, ^\nMOVE N'Example_CS' TO N'C:\\Program Files\\Microsoft SQL Server\\MSSQL.1\\MSSQL\\Example.mdf', ^\nMOVE N'Example_CS_log' TO N'C:\\Program Files\\Microsoft SQL Server\\MSSQL.1\\MSSQL\\Example_1.LDF', ^\nNOUNLOAD, STATS = 10\"\n"
},
{
"answer_id": 5082562,
"author": "TimH - Codidact",
"author_id": 382254,
"author_profile": "https://Stackoverflow.com/users/382254",
"pm_score": 4,
"selected": false,
"text": "FOR /F \"delims=\" %%I IN ('DIR . /B /O:-D') DO COPY \"%%I\" <<NewDir>> & GOTO :END\n:END\n"
},
{
"answer_id": 6524910,
"author": "Richard",
"author_id": 821597,
"author_profile": "https://Stackoverflow.com/users/821597",
"pm_score": 2,
"selected": false,
"text": "FOR /F %%I IN ('DIR \"*.*\" /B /O:D') DO (SET NewestFile=%%I)"
},
{
"answer_id": 27028828,
"author": "DoTheEvo",
"author_id": 1383369,
"author_profile": "https://Stackoverflow.com/users/1383369",
"pm_score": 3,
"selected": false,
"text": "@echo off\nset source=\"C:\\test case\"\nset target=\"C:\\Users\\Alexander\\Desktop\\random folder\"\n\nFOR /F \"delims=\" %%I IN ('DIR %source%\\*.* /A:-D /O:-D /B') DO COPY %source%\\\"%%I\" %target% & echo %%I & GOTO :END\n:END\nTIMEOUT 4\n *.* *.zip"
},
{
"answer_id": 68243394,
"author": "Bharathiraja",
"author_id": 2648257,
"author_profile": "https://Stackoverflow.com/users/2648257",
"pm_score": 0,
"selected": false,
"text": "date echo off\nrem copying latest file with current date from one folder to another folder\ncls\necho Copying files. Please wait...\n:: echo Would you like to do a copy?\nrem pause\nfor /f \"tokens=1-4 delims=/ \" %%i in (\"%date%\") do (\n set dow=%%i\n set month=%%j\n set day=%%k\n set year=%%l\n)\n:: Pad digits with leading zeros e.g Sample_01-01-21.csv\n set yy=%year:~-2%\n:: Alternate way - set datestr=%date:~0,2%-%date:~3,2%-%date:~6,2%\nset datestr=%day%-%month%-%yy%\n:: echo \"\\\\networkdrive\\Test\\Sample_%datestr%.csv\"\nrem copy files from src to dest e.g copy <src path> <dest path>\ncopy \"D:\\Source\\Sample_%datestr%.csv\" D:\\Destination\necho Completed\nrem pause\n Save .bat batch"
},
{
"answer_id": 72858926,
"author": "YazanGhafir",
"author_id": 11886045,
"author_profile": "https://Stackoverflow.com/users/11886045",
"pm_score": 1,
"selected": false,
"text": "set origFolderPath=..\\Source\\Customization.Solution\nset distFolderPath=.\\PublishCustomization.Solution\n\nFOR /F \"tokens=*\" %%I IN ('DIR \"%origFolderPath%\\*.zip\" /T:C /B /O:D') DO SET \"NewestFile=%%I\"\ncopy %origFolderPath%\\%NewestFile% %distFolderPath%\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97371",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5269/"
] |
97,381
|
<p>C# has the keyword called <a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0(VS.80).aspx" rel="noreferrer">yield</a>. VB.NET lacks this keyword. How have the Visual Basic programmers gotten around the lack of this keyword? Do they implement they own iterator class? Or do they try and code to avoid the need of an iterator?</p>
<p>The <a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0(VS.80).aspx" rel="noreferrer">yield</a> keyword does force the compiler to do some coding behind the scenes. <em><a href="http://blogs.msdn.com/oldnewthing/archive/2008/08/12/8849519.aspx" rel="noreferrer">The implementation of iterators in C# and its consequences (part 1)</a></em> has a good example of that. </p>
|
[
{
"answer_id": 97398,
"author": "MagicKat",
"author_id": 8505,
"author_profile": "https://Stackoverflow.com/users/8505",
"pm_score": 1,
"selected": false,
"text": "IEnumerator(Of T) IEnumerable(Of T) List(Of T) .AddRange"
},
{
"answer_id": 382189,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 6,
"selected": false,
"text": "static Shared Static Static Static Iterator<T> Iterator(Of T) Yield() Break() yield"
},
{
"answer_id": 1480667,
"author": "MarkJ",
"author_id": 15639,
"author_profile": "https://Stackoverflow.com/users/15639",
"pm_score": 4,
"selected": false,
"text": "yield"
},
{
"answer_id": 5855766,
"author": "meenakshisundaram muthukrishna",
"author_id": 734254,
"author_profile": "https://Stackoverflow.com/users/734254",
"pm_score": -1,
"selected": false,
"text": "Public Shared Function setofNumbers() As Integer()\n Dim counter As Integer = 0\n Dim results As New List(Of Integer)\n Dim result As Integer = 1\n While counter < 5\n result = result * 2\n results.Add(result)\n counter += 1\n End While\n Return results.ToArray()\nEnd Function\n\nPrivate Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load\n For Each i As Integer In setofNumbers()\n MessageBox.Show(i)\n Next\nEnd Sub\n private void Form1_Load(object sender, EventArgs e)\n{\n foreach (int i in setofNumbers())\n {\n MessageBox.Show(i.ToString());\n }\n}\n\npublic static IEnumerable<int> setofNumbers()\n{\n int counter=0;\n int result=1;\n while (counter < 5)\n {\n result = result * 2;\n counter += 1;\n yield return result;\n }\n}\n"
},
{
"answer_id": 5899580,
"author": "CoderDennis",
"author_id": 69527,
"author_profile": "https://Stackoverflow.com/users/69527",
"pm_score": 4,
"selected": false,
"text": "Yield"
},
{
"answer_id": 44701114,
"author": "Luke T O'Brien",
"author_id": 2137483,
"author_profile": "https://Stackoverflow.com/users/2137483",
"pm_score": 1,
"selected": false,
"text": "Iterator"
},
{
"answer_id": 48730455,
"author": "Jonathan Applebaum",
"author_id": 5718868,
"author_profile": "https://Stackoverflow.com/users/5718868",
"pm_score": 2,
"selected": false,
"text": "Yield System.Collections.Generic.IEnumerable(T) Public Class Status\n Implements IStatus\n\n Private _statusChangeDate As DateTime\n Public Property statusChangeDate As DateTime Implements IStatus.statusChangeDate\n Get\n Return _statusChangeDate\n End Get\n Set(value As Date)\n _statusChangeDate = value\n End Set\n End Property\n\n Private _statusId As Integer\n Public Property statusId As Integer Implements IStatus.statusId\n Get\n Return _statusId\n End Get\n Set(value As Integer)\n _statusId = value\n End Set\n End Property\n\n Private _statusName As String\n Public Property statusName As String Implements IStatus.statusName\n Get\n Return _statusName\n End Get\n Set(value As String)\n _statusName = value\n End Set\n End Property\n\n Public Iterator Function GetEnumerator() As IEnumerable(Of Object) Implements IStatus.GetEnumerator\n Yield Convert.ToDateTime(statusChangeDate)\n Yield Convert.ToInt32(statusId)\n Yield statusName.ToString()\n End Function\n\nEnd Class\n\nPublic Interface IStatus\n Property statusChangeDate As DateTime\n Property statusId As Integer\n Property statusName As String\n Function GetEnumerator() As System.Collections.Generic.IEnumerable(Of Object)\nEnd Interface\n For Each itm As SLA.IStatus In outputlist\n For Each it As Object In itm.GetEnumerator()\n Debug.Write(it & \" \")\n Next\n Debug.WriteLine(\"\")\nNext\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97381",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8505/"
] |
97,391
|
<p>I have the following enum declared:</p>
<pre><code> public enum TransactionTypeCode { Shipment = 'S', Receipt = 'R' }
</code></pre>
<p>How do I get the value 'S' from a TransactionTypeCode.Shipment or 'R' from TransactionTypeCode.Receipt ?</p>
<p>Simply doing TransactionTypeCode.ToString() gives a string of the Enum name "Shipment" or "Receipt" so it doesn't cut the mustard.</p>
|
[
{
"answer_id": 97397,
"author": "J D OConal",
"author_id": 17023,
"author_profile": "https://Stackoverflow.com/users/17023",
"pm_score": -1,
"selected": true,
"text": "string value = (string)TransactionTypeCode.Shipment;\n"
},
{
"answer_id": 123545,
"author": "IaCoder",
"author_id": 17337,
"author_profile": "https://Stackoverflow.com/users/17337",
"pm_score": -1,
"selected": false,
"text": "public enum TransactionTypeCode {\n\n Shipment(\"S\"),Receipt (\"R\");\n\n private final String val;\n\n TransactionTypeCode(String val){\n this.val = val;\n }\n\n public String getTypeCode(){\n return val;\n }\n}\n\nSystem.out.println(TransactionTypeCode.Shipment.getTypeCode());\n"
},
{
"answer_id": 703937,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "int value = Convert.ToInt32(TransactionTypeCode.Shipment);\n"
},
{
"answer_id": 2292564,
"author": "Andre",
"author_id": 276515,
"author_profile": "https://Stackoverflow.com/users/276515",
"pm_score": 5,
"selected": false,
"text": "public enum SuperTasks : int\n {\n Sleep = 5,\n Walk = 7,\n Run = 9\n }\n\n private void btnTestEnumWithReflection_Click(object sender, EventArgs e)\n {\n SuperTasks task = SuperTasks.Walk;\n Type underlyingType = Enum.GetUnderlyingType(task.GetType());\n object value = Convert.ChangeType(task, underlyingType); // x will be int\n } \n"
},
{
"answer_id": 20312247,
"author": "nawfal",
"author_id": 661933,
"author_profile": "https://Stackoverflow.com/users/661933",
"pm_score": 1,
"selected": false,
"text": "char int TransactionTypeCode { Shipment = 83, Receipt = 82, }\n enum char TransactionTypeCode : char { Shipment = 'S', Receipt = 'R', }\n char var value = (char)TransactionTypeCode.Shipment;\n\n// or to make it more explicit:\nvar value = Convert.ToChar(TransactionTypeCode.Shipment);\n var value = Convert.ToChar((int)TransactionTypeCode.Shipment);\n"
},
{
"answer_id": 31048652,
"author": "Tonio",
"author_id": 5048578,
"author_profile": "https://Stackoverflow.com/users/5048578",
"pm_score": 0,
"selected": false,
"text": "enum myEnum : byte {Some = 1, SomeMore, Alot, TooMuch};\nmyEnum HowMuch = myEnum.Alot;\nConsole.Writeline(\"How much: {0}\", (byte)HowMuch);\n enum myFlags:int {None='N',Alittle='A',Some='S',Somemore='M',Alot='L'};\nmyFlags howMuch = myFlags.Some;\nConsole.WriteLine(\"How much: {0}\", (char)howMuch);\n//If you cast as int you get the ASCII value not the character.\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97391",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5056/"
] |
97,392
|
<p>How do I get the physical addresses of my machine in <strong>Java</strong>?</p>
|
[
{
"answer_id": 97411,
"author": "Joe Dean",
"author_id": 5917,
"author_profile": "https://Stackoverflow.com/users/5917",
"pm_score": 0,
"selected": false,
"text": "try {\n InetAddress addr = InetAddress.getLocalHost();\n\n // Get IP Address\n byte[] ipAddr = addr.getAddress();\n\n // Get hostname\n String hostname = addr.getHostName();\n} catch (UnknownHostException e) {\n}\n"
},
{
"answer_id": 97415,
"author": "zxcv",
"author_id": 9628,
"author_profile": "https://Stackoverflow.com/users/9628",
"pm_score": 0,
"selected": false,
"text": "getLocalHost() \n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97392",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16949/"
] |
97,421
|
<p>Will IE6 negotiate a 256 bit AES SSL connection if the server is capable?</p>
|
[
{
"answer_id": 31424019,
"author": "hairysocks",
"author_id": 1782344,
"author_profile": "https://Stackoverflow.com/users/1782344",
"pm_score": 0,
"selected": false,
"text": "SSLCipherSuite ALL:!ADH:RC4+RSA:+HIGH:!MEDIUM:!LOW:!SSLv2:!EXP:!NULL\n <Connector port=\"8443\" protocol=\"HTTP/1.1\" SSLEnabled=\"true\"\n maxThreads=\"150\" minSpareThreads=\"25\" scheme=\"https\" secure=\"true\" \n keystorePass=\"xxxxxxxx\"\n clientAuth=\"false\" sslProtocol=\"TLSv1.2\" \n SSLCipherSuite=\"ALL:!ADH+DH:!RC4:+HIGH:!MEDIUM:!LOW:!SSLv2:!EXPORT\"\n enableLookups=\"false\" redirectPort=\"8443\" acceptCount=\"100\"\n connectionTimeout=\"20000\" disableUploadTimeout=\"true\"\n allowTrace=\"false\" />\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97421",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17583/"
] |
97,435
|
<p>Suppose you have the following string:</p>
<pre><code>white sand, tall waves, warm sun
</code></pre>
<p>It's easy to write a regular expression that will match the delimiters, which the Java String.split() method can use to give you an array containing the tokens "white sand", "tall waves" and "warm sun":</p>
<pre><code>\s*,\s*
</code></pre>
<p>Now say you have this string:</p>
<pre><code>white sand and tall waves and warm sun
</code></pre>
<p>Again, the regex to split the tokens is easy (ensuring you don't get the "and" inside the word "sand"):</p>
<pre><code>\s+and\s+
</code></pre>
<p>Now, consider this string:</p>
<pre><code>white sand, tall waves and warm sun
</code></pre>
<p>Can a regex be written that will match the delimiters correctly, allowing you to split the string into the same tokens as in the previous two cases? Alternatively, can a regex be written that will match the tokens themselves and omit the delimiters? (Any amount of white space on either side of a comma or the word "and" should be considered part of the delimiter.)</p>
<p>Edit: As has been pointed out in the comments, the correct answer should robustly handle delimiters at the beginning or end of the input string. The <em>ideal</em> answer should be able to take a string like ",white sand, tall waves and warm sun and " and provide these exact three tokens:</p>
<pre><code>[ "white sand", "tall waves", "warm sun" ]
</code></pre>
<p>...without <del>extra empty tokens or</del> extra white space at the start or end of any token.</p>
<p>Edit: It's been pointed out that extra empty tokens are unavoidable with String.split(), so that's been removed as a criterion for the "perfect" regex.</p>
<hr>
<p>Thanks everyone for your responses! I've tried to make sure I upvoted everyone who contributed a workable regex that wasn't essentially a duplicate. Dan's answer was the most robust (it even handles ",white sand, tall waves,and warm sun and " reasonably, with that odd comma placement after the word "waves"), so I've marked his as the accepted answer. The regex provided by nsayer was a close second.</p>
|
[
{
"answer_id": 97457,
"author": "UnkwnTech",
"author_id": 115,
"author_profile": "https://Stackoverflow.com/users/115",
"pm_score": 2,
"selected": false,
"text": "(?:\\sand|,)\\s\n"
},
{
"answer_id": 97458,
"author": "e-satis",
"author_id": 9951,
"author_profile": "https://Stackoverflow.com/users/9951",
"pm_score": 1,
"selected": false,
"text": "\\s*(?:and|,)\\s*\n \\s*(?:[^s]and|,)\\s*\n"
},
{
"answer_id": 97470,
"author": "nsayer",
"author_id": 13757,
"author_profile": "https://Stackoverflow.com/users/13757",
"pm_score": 2,
"selected": false,
"text": "\\s*(,|(and))\\s*\n \\s+(,|(and))\\s+\n (\\s*,\\s*)|(\\s+and\\s+)\n"
},
{
"answer_id": 97482,
"author": "Shinhan",
"author_id": 18219,
"author_profile": "https://Stackoverflow.com/users/18219",
"pm_score": 2,
"selected": false,
"text": "\\s*(,|\\s+and)\\s+\n"
},
{
"answer_id": 97494,
"author": "Quintin Robinson",
"author_id": 12707,
"author_profile": "https://Stackoverflow.com/users/12707",
"pm_score": 0,
"selected": false,
"text": "(?:(?<!s)and\\s+|\\,\\s+)\n"
},
{
"answer_id": 97632,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 4,
"selected": true,
"text": "\\s*(?:\\band\\b|,)\\s*\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97435",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4287/"
] |
97,447
|
<p>If I am writing a library and I have a function that needs to return a sequence of values, I could do something like:</p>
<pre><code>std::vector<int> get_sequence();
</code></pre>
<p>However, this requires the library user to use the std::vector<> container rather than allowing them to use whatever container they want to use. In addition, it can add an extra copy of the returned array (depending on whether the compiler could optimize this or not) that might have a negative impact on performance.</p>
<p>You could theoretically enable the use of arbitrary containers (and avoid the unnecessary extra copying) by making a templated function that takes a start and an end iter:</p>
<pre><code>template<class T_iter> void get_sequence(T_iter begin, T_iter end);
</code></pre>
<p>The function would then store the sequence values in the range given by the iterators. But the problem with this is that it requires you to know the size of the sequence so you have enough elements between <code>begin</code> and <code>end</code> to store all of the values in the sequence.</p>
<p>I thought about an interface such as:</p>
<pre><code>template<T_insertIter> get_sequence(T_insertIter inserter);
</code></pre>
<p>which requires that the T_insertIter be an insert iterator (e.g. created with <code>std::back_inserter(my_vector)</code>), but this seems way too easy to misuse since the compiler would happily accept a non-insert iterator but would behave incorrectly at run-time.</p>
<p>So is there a best practice for designing generic interfaces that return sequences of arbitrary length?</p>
|
[
{
"answer_id": 97519,
"author": "Matt Cruikshank",
"author_id": 8643,
"author_profile": "https://Stackoverflow.com/users/8643",
"pm_score": 0,
"selected": false,
"text": "std::list<int> std void get_sequence(std::tr1::function<void(int)> f);\n std::tr1::bind get_sequence f"
},
{
"answer_id": 97541,
"author": "moswald",
"author_id": 8368,
"author_profile": "https://Stackoverflow.com/users/8368",
"pm_score": 0,
"selected": false,
"text": "template<typename container>\ncontainer get_sequence();\n"
},
{
"answer_id": 97551,
"author": "user17481",
"author_id": 17481,
"author_profile": "https://Stackoverflow.com/users/17481",
"pm_score": 2,
"selected": false,
"text": "\ntemplate void get_sequence(T_Container & container)\n{\n //...\n container.assign(iter1, iter2);\n //...\n}\n \ntemplate void get_sequence(T_Container & container)\n{\n //...\n container.resize(size);\n //use push_back or whatever\n //...\n}\n \nclass AssignStrategy // for stl\n{\npublic:\n template\n void fill(T_Container & container, T_Container::iterator it1, T_Container::iterator it2){\n container.assign(it1, it2);\n }\n};\n\nclass ReserveStrategy // for vectors and stuff\n{\npublic:\n template\n void fill(T_Container & container, T_Container::iterator it1, T_Container::iterator it2){\n container.reserve(it2 - it1);\n while(it1 != it2)\n container.push_back(*it1++);\n }\n};\n\n\ntemplate \nvoid get_sequence(T_Container & container)\n{\n //...\n T_FillStrategy::fill(container, iter1, iter2);\n //...\n}\n"
},
{
"answer_id": 97597,
"author": "David Pierre",
"author_id": 18296,
"author_profile": "https://Stackoverflow.com/users/18296",
"pm_score": 0,
"selected": false,
"text": "template<T_insertIter> get_sequence(T_insertIter inserter)\n{\n return get_sequence(inserter, typename iterator_traits<Iterator>::iterator_category());\n}\n\ntemplate<T_insertIter> get_sequence(T_insertIter inserter, input_iterator_tag);\n"
},
{
"answer_id": 97623,
"author": "cjm",
"author_id": 8355,
"author_profile": "https://Stackoverflow.com/users/8355",
"pm_score": 3,
"selected": false,
"text": "forward_iterator bidirectional_iterator static const my_itr& end() { static const my_itr e(...); return e; };\n ... for (my_itr i = get_sequence(); i != my_itr::end(); ++i) { ... }\n #include <iterator>\n\nclass integer_sequence_itr\n : public std::iterator<std::forward_iterator_tag, int>\n{\n private:\n int i;\n\n public:\n explicit integer_sequence_itr(int start) : i(start) {};\n\n const int& operator*() const { return i; };\n const int* operator->() const { return &i; };\n\n integer_sequence_itr& operator++() { ++i; return *this; };\n integer_sequence_itr operator++(int)\n { integer_sequence_itr copy(*this); ++i; return copy; };\n\n inline bool operator==(const integer_sequence_itr& rhs) const\n { return i == rhs.i; };\n\n inline bool operator!=(const integer_sequence_itr& rhs) const\n { return i != rhs.i; };\n}; // end integer_sequence_itr\n\n//Example: Print the integers from 1 to 10.\n#include <iostream>\n\nint main()\n{\n const integer_sequence_itr stop(11);\n\n for (integer_sequence_itr i(1); i != stop; ++i)\n std::cout << *i << std::endl;\n\n return 0;\n} // end main\n"
},
{
"answer_id": 97628,
"author": "Johann Gerell",
"author_id": 6345,
"author_profile": "https://Stackoverflow.com/users/6345",
"pm_score": 2,
"selected": false,
"text": "std::vector<>"
},
{
"answer_id": 97712,
"author": "paercebal",
"author_id": 14089,
"author_profile": "https://Stackoverflow.com/users/14089",
"pm_score": 2,
"selected": false,
"text": "void get_sequence(std::vector<int> & p_aInt);\n template <typename T>\nvoid get_sequence(T & p_aInt)\n{\n p_aInt.push_back(25) ; // Or whatever you need to add\n}\n template <typename T>\nvoid get_sequence(T & p_aInt)\n{\n p_aInt.insert(p_aInt.end(), 25) ; // Or whatever you need to add\n}\n"
},
{
"answer_id": 3736379,
"author": "Alexandre C.",
"author_id": 373025,
"author_profile": "https://Stackoverflow.com/users/373025",
"pm_score": 0,
"selected": false,
"text": "template <typename OutputIter>\nvoid generate_sequence(OutputIter out)\n{\n //...\n while (...) { *out = ...; ++out; }\n}\n struct sequence_generator\n{\n bool has_next() { ... }\n your_type next() { mutate_state(); return next_value; }\n\nprivate:\n // some state\n};\n boost::iterator_facade copy transform boost::transform_iterator"
},
{
"answer_id": 3736499,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 0,
"selected": false,
"text": "struct vector_adder {\n vector_adder(std::vector<int>& v) : v(v) {}\n void operator()(int n) { v.push_back(n); }\n std::vector<int>& v;\n};\n\nvoid gen_sequence(boost::function< void(int) > f) {\n ...\n f(n);\n ...\n}\n\nmain() {\n std::vector<int> vi;\n gen_sequence(vector_adder(vi));\n}\n main() {\n std::vector<int> ui;\n gen_sequence([&](int n)->void{ui.push_back(n);});\n}\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97447",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/78437/"
] |
97,459
|
<p>When a C# WinForms textbox receives focus, I want it to behave like your browser's address bar.</p>
<p>To see what I mean, click in your web browser's address bar. You'll notice the following behavior: </p>
<ol>
<li>Clicking in the textbox should select all the text if the textbox wasn't previously focused.</li>
<li>Mouse down and drag in the textbox should select only the text I've highlighted with the mouse.</li>
<li>If the textbox is already focused, clicking does not select all text.</li>
<li>Focusing the textbox programmatically or via keyboard tabbing should select all text.</li>
</ol>
<p>I want to do exactly this in WinForms.</p>
<p><strong>FASTEST GUN ALERT: please read the following before answering!</strong> Thanks guys. :-)</p>
<blockquote>
<p><strong>Calling .SelectAll() during
the .Enter or .GotFocus events won't
work</strong> because if the user clicked the
textbox, the caret will be placed
where he clicked, thus deselecting all
text.</p>
<p><strong>Calling .SelectAll() during the .Click event won't work</strong> because the user won't be able to select any text with the mouse; the .SelectAll() call will keep overwriting the user's text selection.</p>
<p><strong>Calling BeginInvoke((Action)textbox.SelectAll) on focus/enter event enter doesn't work</strong> because it breaks rule #2 above, it will keep overriding the user's selection on focus.</p>
</blockquote>
|
[
{
"answer_id": 97499,
"author": "Jakub Kotrla",
"author_id": 16943,
"author_profile": "https://Stackoverflow.com/users/16943",
"pm_score": 2,
"selected": false,
"text": "private bool f = false;\n\nprivate void textBox_MouseClick(object sender, MouseEventArgs e)\n{ \n if (this.f) { this.textBox.SelectAll(); }\n this.f = false;\n}\n\nprivate void textBox_Enter(object sender, EventArgs e)\n{\n this.f = true;\n this.textBox.SelectAll();\n}\nprivate void textBox_MouseMove(object sender, MouseEventArgs e) // idea from the other answer\n{\n this.f = false; \n}\n"
},
{
"answer_id": 97509,
"author": "Todd Benning",
"author_id": 18298,
"author_profile": "https://Stackoverflow.com/users/18298",
"pm_score": 3,
"selected": false,
"text": "SendKeys.Send( \"{HOME}+{END}\" );"
},
{
"answer_id": 97515,
"author": "MagicKat",
"author_id": 8505,
"author_profile": "https://Stackoverflow.com/users/8505",
"pm_score": 2,
"selected": false,
"text": "'Inside the Enter event\nTextBox1.SelectAll();\n bool entered = false;\n private void textBox1_Enter(object sender, EventArgs e)\n {\n entered = true;\n textBox1.SelectAll(); //From Jakub's answer.\n }\n\n private void textBox1_Click(object sender, EventArgs e)\n {\n if (entered) textBox1.SelectAll();\n entered = false;\n }\n\n private void textBox1_MouseMove(object sender, MouseEventArgs e)\n {\n if (entered) entered = false;\n }\n"
},
{
"answer_id": 97664,
"author": "Nescio",
"author_id": 14484,
"author_profile": "https://Stackoverflow.com/users/14484",
"pm_score": 0,
"selected": false,
"text": "private bool _isSelected = false;\nprivate void textBox_Validated(object sender, EventArgs e)\n{\n _isSelected = false;\n}\n\nprivate void textBox_MouseClick(object sender, MouseEventArgs e)\n{\n SelectAllText(textBox);\n}\n\nprivate void textBox_Enter(object sender, EventArgs e)\n{\n SelectAllText(textBox);\n}\n\nprivate void SelectAllText(TextBox text)\n{\n if (!_isSelected)\n {\n _isSelected = true;\n textBox.SelectAll();\n }\n}\n"
},
{
"answer_id": 97735,
"author": "benPearce",
"author_id": 4490,
"author_profile": "https://Stackoverflow.com/users/4490",
"pm_score": -1,
"selected": false,
"text": " private ########### void textBox1_Enter(object sender, EventArgs e)\n {\n textBox1.SelectAll();\n }\n\n private void textBox1_MouseDown(object sender, MouseEventArgs e)\n {\n if (textBox1.Focused)\n textBox1.SelectAll();\n }\n"
},
{
"answer_id": 100362,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "public partial class Form1 : Form\n{\n public Form1()\n {\n InitializeComponent();\n this.textBox1.GotFocus += new EventHandler(textBox1_GotFocus);\n }\n\n private delegate void SelectAllDelegate(); \n private IAsyncResult _selectAllar = null; //So we can clean up afterwards.\n\n //Catch the input focus event\n void textBox1_GotFocus(object sender, EventArgs e)\n {\n //We could have gotten here many ways (including mouse click)\n //so there could be other messages queued up already that might change the selection.\n //Don't call SelectAll here, since it might get undone by things such as positioning the cursor.\n //Instead use BeginInvoke on the form to queue up a message\n //to select all the text after everything caused by the current event is processed.\n this._selectAllar = this.BeginInvoke(new SelectAllDelegate(this._SelectAll));\n }\n\n private void _SelectAll()\n {\n //Clean-up the BeginInvoke\n if (this._selectAllar != null)\n {\n this.EndInvoke(this._selectAllar);\n }\n //Now select everything.\n this.textBox1.SelectAll();\n }\n}\n"
},
{
"answer_id": 102095,
"author": "Judah Gabriel Himango",
"author_id": 536,
"author_profile": "https://Stackoverflow.com/users/536",
"pm_score": 8,
"selected": true,
"text": "bool alreadyFocused;\n\n...\n\ntextBox1.GotFocus += textBox1_GotFocus;\ntextBox1.MouseUp += textBox1_MouseUp;\ntextBox1.Leave += textBox1_Leave;\n\n...\n\nvoid textBox1_Leave(object sender, EventArgs e)\n{\n alreadyFocused = false;\n}\n\n\nvoid textBox1_GotFocus(object sender, EventArgs e)\n{\n // Select all text only if the mouse isn't down.\n // This makes tabbing to the textbox give focus.\n if (MouseButtons == MouseButtons.None)\n {\n this.textBox1.SelectAll();\n alreadyFocused = true;\n }\n}\n\nvoid textBox1_MouseUp(object sender, MouseEventArgs e)\n{\n // Web browsers like Google Chrome select the text on mouse up.\n // They only do it if the textbox isn't already focused,\n // and if the user hasn't selected all text.\n if (!alreadyFocused && this.textBox1.SelectionLength == 0)\n {\n alreadyFocused = true;\n this.textBox1.SelectAll();\n }\n}\n"
},
{
"answer_id": 277254,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "private void textbox_MouseDown(object sender, MouseEventArgs e) {\n if (textbox != null && !string.IsNullOrEmpty(textbox.Text))\n {\n textbox.SelectAll();\n } }\n"
},
{
"answer_id": 1625439,
"author": "Sreejith K.",
"author_id": 196700,
"author_profile": "https://Stackoverflow.com/users/196700",
"pm_score": 0,
"selected": false,
"text": " private bool _tailTextBoxFirstClick = false;\n\n private void textBox1_MouseUp(object sender, MouseEventArgs e)\n {\n if(_textBoxFirstClick) \n textBox1.SelectAll();\n\n _textBoxFirstClick = false;\n } \n\n private void textBox1_Leave(object sender, EventArgs e)\n {\n _textBoxFirstClick = true;\n textBox1.Select(0, 0);\n }\n"
},
{
"answer_id": 2011104,
"author": "Mohammad Mahdipour",
"author_id": 244468,
"author_profile": "https://Stackoverflow.com/users/244468",
"pm_score": 0,
"selected": false,
"text": "public class SMaskedTextBox : MaskedTextBox\n{\n protected override void OnGotFocus(EventArgs e)\n {\n base.OnGotFocus(e);\n this.SelectAll();\n }\n}\n"
},
{
"answer_id": 2647823,
"author": "BSalita",
"author_id": 317797,
"author_profile": "https://Stackoverflow.com/users/317797",
"pm_score": -1,
"selected": false,
"text": "Class MainWindow \n\n Sub New()\n\n ' This call is required by the designer.\n InitializeComponent()\n\n ' Add any initialization after the InitializeComponent() call.\n AddHandler PreviewMouseLeftButtonDown, New MouseButtonEventHandler(AddressOf SelectivelyIgnoreMouseButton)\n AddHandler GotKeyboardFocus, New KeyboardFocusChangedEventHandler(AddressOf SelectAllText)\n AddHandler MouseDoubleClick, New MouseButtonEventHandler(AddressOf SelectAllText)\n End Sub\n\n Private Shared Sub SelectivelyIgnoreMouseButton(ByVal sender As Object, ByVal e As MouseButtonEventArgs)\n ' Find the TextBox\n Dim parent As DependencyObject = TryCast(e.OriginalSource, UIElement)\n While parent IsNot Nothing AndAlso Not (TypeOf parent Is TextBox)\n parent = VisualTreeHelper.GetParent(parent)\n End While\n\n If parent IsNot Nothing Then\n Dim textBox As Object = DirectCast(parent, TextBox)\n If Not textBox.IsKeyboardFocusWithin Then\n ' If the text box is not yet focussed, give it the focus and\n ' stop further processing of this click event.\n textBox.Focus()\n e.Handled = True\n End If\n End If\n End Sub\n\n Private Shared Sub SelectAllText(ByVal sender As Object, ByVal e As RoutedEventArgs)\n Dim textBox As Object = TryCast(e.OriginalSource, TextBox)\n If textBox IsNot Nothing Then\n textBox.SelectAll()\n End If\n End Sub\n\nEnd Class\n"
},
{
"answer_id": 3678888,
"author": "nzhenry",
"author_id": 443649,
"author_profile": "https://Stackoverflow.com/users/443649",
"pm_score": 5,
"selected": false,
"text": "public class MyTextBox : System.Windows.Forms.TextBox\n{\n private bool _focused;\n\n protected override void OnEnter(EventArgs e)\n {\n base.OnEnter(e);\n if (MouseButtons == MouseButtons.None)\n {\n SelectAll();\n _focused = true;\n }\n }\n\n protected override void OnLeave(EventArgs e)\n {\n base.OnLeave(e);\n _focused = false;\n }\n\n protected override void OnMouseUp(MouseEventArgs mevent)\n {\n base.OnMouseUp(mevent);\n if (!_focused)\n {\n if (SelectionLength == 0)\n SelectAll();\n _focused = true;\n }\n }\n}\n"
},
{
"answer_id": 6101372,
"author": "Yfiua",
"author_id": 766508,
"author_profile": "https://Stackoverflow.com/users/766508",
"pm_score": 0,
"selected": false,
"text": "private System.Windows.Forms.TextBox lastFocus; \n\nprivate void textBox_GotFocus(object sender, System.Windows.Forms.MouseEventArgs e) \n{\n TextBox senderTextBox = sender as TextBox;\n if (lastFocus!=senderTextBox){\n senderTextBox.SelectAll();\n }\n lastFocus = senderTextBox; \n}\n"
},
{
"answer_id": 6857301,
"author": "Duncan Smart",
"author_id": 1278,
"author_profile": "https://Stackoverflow.com/users/1278",
"pm_score": 6,
"selected": false,
"text": "Control.BeginInvoke private void MyTextBox_Enter(object sender, EventArgs e)\n{\n // Kick off SelectAll asynchronously so that it occurs after Click\n BeginInvoke((Action)delegate\n {\n MyTextBox.SelectAll();\n });\n}\n Private Sub MyTextBox_Enter(sender As Object, e As EventArgs) Handles MyTextBox.Enter \n BeginInvoke(DirectCast(Sub() MyTextBox.SelectAll(), Action)) \nEnd Sub\n"
},
{
"answer_id": 6970941,
"author": "Ross K.",
"author_id": 882448,
"author_profile": "https://Stackoverflow.com/users/882448",
"pm_score": 2,
"selected": false,
"text": " public static void WireSelectAllOnFocus( TextBox aTextBox )\n {\n bool lActive = false;\n aTextBox.GotFocus += new EventHandler( ( sender, e ) =>\n {\n if ( System.Windows.Forms.Control.MouseButtons == MouseButtons.None )\n {\n aTextBox.SelectAll();\n lActive = true;\n }\n } );\n\n aTextBox.Leave += new EventHandler( (sender, e ) => {\n lActive = false;\n } );\n\n aTextBox.MouseUp += new MouseEventHandler( (sender, e ) => {\n if ( !lActive )\n {\n lActive = true;\n if ( aTextBox.SelectionLength == 0 ) aTextBox.SelectAll();\n } \n });\n }\n"
},
{
"answer_id": 8853861,
"author": "Eluem",
"author_id": 1148085,
"author_profile": "https://Stackoverflow.com/users/1148085",
"pm_score": 0,
"selected": false,
"text": "if(textBox.SelectionLength = 0)\n{\n textBox.SelectAll();\n}\n"
},
{
"answer_id": 10416412,
"author": "Chris",
"author_id": 1370369,
"author_profile": "https://Stackoverflow.com/users/1370369",
"pm_score": 2,
"selected": false,
"text": "Private LastFocused As Control = Nothing\n\nPrivate Sub TextBox1_Enter(sender As Object, e As System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter\n If MouseButtons = Windows.Forms.MouseButtons.None Then LastFocused = sender\nEnd Sub\n\nPrivate Sub TextBox1_Leave(sender As Object, e As System.EventArgs) Handles TextBox1.Leave, TextBox2.Leave, TextBox3.Leave\n LastFocused = Nothing\nEnd Sub\n\nPrivate Sub TextBox1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseUp, TextBox2.MouseUp, TextBox3.MouseUp\n With CType(sender, TextBox)\n If LastFocused IsNot sender AndAlso .SelectionLength = 0 Then .SelectAll()\n End With\n LastFocused = sender\nEnd Sub\n"
},
{
"answer_id": 10420952,
"author": "Adam Bruss",
"author_id": 638740,
"author_profile": "https://Stackoverflow.com/users/638740",
"pm_score": 1,
"selected": false,
"text": "ActiveControl = textBox1;\ntextBox1->SelectionStart = 0;\ntextBox1->SelectionLength = textBox1->Text->Length;\n"
},
{
"answer_id": 12212017,
"author": "abrfra",
"author_id": 978489,
"author_profile": "https://Stackoverflow.com/users/978489",
"pm_score": 0,
"selected": false,
"text": "OnKeyDown OnKeyUp public class NumericTextBox : TextBox\n{\n private bool _focused;\n protected override void OnGotFocus(EventArgs e)\n {\n base.OnGotFocus(e);\n if (MouseButtons == MouseButtons.None)\n {\n this.SelectAll();\n _focused = true;\n }\n }\n protected override void OnEnter(EventArgs e)\n {\n base.OnEnter(e);\n if (MouseButtons == MouseButtons.None)\n {\n SelectAll();\n _focused = true;\n }\n }\n\n protected override void OnLeave(EventArgs e)\n {\n base.OnLeave(e);\n _focused = false;\n }\n\n protected override void OnMouseUp(MouseEventArgs mevent)\n {\n base.OnMouseUp(mevent);\n if (!_focused)\n {\n if (SelectionLength == 0)\n SelectAll();\n _focused = true;\n }\n }\n\n protected override void OnKeyUp(KeyEventArgs e)\n {\n base.OnKeyUp(e);\n\n if (SelectionLength == 0)\n SelectAll();\n _focused = true;\n }\n protected override void OnKeyDown(KeyEventArgs e)\n {\n base.OnKeyDown(e);\n if (SelectionLength == 0)\n SelectAll();\n _focused = true;\n }\n}\n"
},
{
"answer_id": 15284242,
"author": "slobs",
"author_id": 2146540,
"author_profile": "https://Stackoverflow.com/users/2146540",
"pm_score": 2,
"selected": false,
"text": " private bool initialEntry = true;\n private void TextBox_SelectionChanged(object sender, RoutedEventArgs e)\n {\n if (initialEntry)\n {\n e.Handled = true;\n initialEntry = false;\n TextBox.SelectAll();\n }\n }\n private void TextBox_GotFocus(object sender, RoutedEventArgs e)\n {\n TextBox.SelectAll();\n initialEntry = true; \n }\n"
},
{
"answer_id": 17221130,
"author": "Joel",
"author_id": 2506459,
"author_profile": "https://Stackoverflow.com/users/2506459",
"pm_score": 0,
"selected": false,
"text": "private void maskedTextBox1_Leave(object sender, CancelEventArgs e)\n {\n maskedTextBox1.SelectAll();\n }\n"
},
{
"answer_id": 22812804,
"author": "MDB",
"author_id": 3489564,
"author_profile": "https://Stackoverflow.com/users/3489564",
"pm_score": -1,
"selected": false,
"text": "public void YourTextBox_MouseEnter(object sender, MouseEventArgs e)\n {\n YourTextBox.Focus();\n YourTextBox.SelectAll();\n }\n"
},
{
"answer_id": 25998482,
"author": "Mauro Sampietro",
"author_id": 711061,
"author_profile": "https://Stackoverflow.com/users/711061",
"pm_score": 0,
"selected": false,
"text": " private bool _focusing = false;\n\n protected override void OnEnter( EventArgs e )\n {\n _focusing = true;\n base.OnEnter( e );\n }\n\n protected override void OnMouseUp( MouseEventArgs mevent )\n {\n base.OnMouseUp( mevent );\n\n if( _focusing )\n {\n this.SelectAll();\n _focusing = false;\n }\n }\n protected override void WndProc( ref Message m )\n {\n if( m.Msg == 32 ) //WM_SETCURSOR=0x20\n {\n this.SelectAll(); // or your custom logic here \n }\n\n base.WndProc( ref m );\n }\n"
},
{
"answer_id": 27229467,
"author": "Pieter Heemeryck",
"author_id": 2568944,
"author_profile": "https://Stackoverflow.com/users/2568944",
"pm_score": 1,
"selected": false,
"text": "private void textBox1_Click(object sender, EventArgs e){\n textBox1_Enter(sender, e);\n }\n\nprivate void textBox1_Enter(object sender, EventArgs e){\n TextBox tb = ((TextBox)sender);\n tb.SelectAll();\n }\n"
},
{
"answer_id": 29624996,
"author": "EKanadily",
"author_id": 365867,
"author_profile": "https://Stackoverflow.com/users/365867",
"pm_score": -1,
"selected": false,
"text": "private void textBox1_Enter(object sender, EventArgs e)\n {\n\n textBox1.SelectAll();\n }\n private void textBox1_Click(object sender, EventArgs e)\n {\n textBox1.SelectAll();\n }\n"
},
{
"answer_id": 30487179,
"author": "Hawston",
"author_id": 3729779,
"author_profile": "https://Stackoverflow.com/users/3729779",
"pm_score": 0,
"selected": false,
"text": " private bool SearchBoxInFocusAlready = false;\n private void SearchBox_LostFocus(object sender, RoutedEventArgs e)\n {\n SearchBoxInFocusAlready = false;\n }\n\n private void SearchBox_PreviewMouseUp(object sender, MouseButtonEventArgs e)\n {\n if (e.ButtonState == MouseButtonState.Released && e.ChangedButton == MouseButton.Left &&\n SearchBox.SelectionLength == 0 && SearchBoxInFocusAlready == false)\n {\n SearchBox.SelectAll();\n }\n\n SearchBoxInFocusAlready = true;\n }\n"
},
{
"answer_id": 31502179,
"author": "BlueWizard",
"author_id": 4773888,
"author_profile": "https://Stackoverflow.com/users/4773888",
"pm_score": 0,
"selected": false,
"text": "private async void TextBox_GotFocus(object sender, RoutedEventArgs e)\n{\n if (sender is TextBox)\n {\n await Task.Delay(100);\n (sender as TextBox).SelectAll();\n }\n}\n"
},
{
"answer_id": 34028458,
"author": "Cody",
"author_id": 5627196,
"author_profile": "https://Stackoverflow.com/users/5627196",
"pm_score": -1,
"selected": false,
"text": " ' * if the mouse button is down, do not run the select all.\n If MouseButtons = Windows.Forms.MouseButtons.Left Then\n Exit Sub\n End If\n\n ' * OTHERWISE INVOKE THE SELECT ALL AS DISCUSSED.\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97459",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/536/"
] |
97,465
|
<p>Has anyone figured out how to use Crystal Reports with Linq to SQL?</p>
|
[
{
"answer_id": 7691717,
"author": "Mohammad Sepahvand",
"author_id": 189756,
"author_profile": "https://Stackoverflow.com/users/189756",
"pm_score": 3,
"selected": true,
"text": "List DataSet SetDataSource IEnumerable List IEnumerable .ToList() CrystalReport1 cr1 = new CrystalReport1();\n\n var results = (from obj in context.tSamples\n where obj.ID == 112\n select new { obj.Name, obj.Model, obj.Producer }).ToList();\n\n cr1.SetDataSource(results);\n crystalReportsViewer1.ReportSource = cr1;\n"
},
{
"answer_id": 23882327,
"author": "user3243012",
"author_id": 3243012,
"author_profile": "https://Stackoverflow.com/users/3243012",
"pm_score": 0,
"selected": false,
"text": " public class CollectionHelper\n {\n public CollectionHelper()\n {\n }\n\n // this is the method I have been using\n public DataTable ConvertTo<T>(IList<T> list)\n {\n DataTable table = CreateTable<T>();\n Type entityType = typeof(T);\n PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(entityType);\n\n foreach (T item in list)\n {\n DataRow row = table.NewRow();\n\n foreach (PropertyDescriptor prop in properties)\n {\n row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;\n }\n\n table.Rows.Add(row);\n }\n\n return table;\n }\n\n public static DataTable CreateTable<T>()\n {\n Type entityType = typeof(T);\n DataTable table = new DataTable(entityType.Name);\n PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(entityType);\n\n foreach (PropertyDescriptor prop in properties)\n {\n // HERE IS WHERE THE ERROR IS THROWN FOR NULLABLE TYPES\n table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(\n prop.PropertyType) ?? prop.PropertyType);\n }\n\n return table;\n }\n }\n CrystalReport1 cr1 = new CrystalReport1();\n\n var results = (from obj in context.tSamples\n where obj.ID == 112\n select new { obj.Name, obj.Model, obj.Producer }).ToList();\n CollectionHelper ch = new CollectionHelper();\n DataTable dt = ch.ConvertTo(results);\n cr1.SetDataSource(dt);\n crystalReportsViewer1.ReportSource = cr1;\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97465",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11063/"
] |
97,468
|
<p><a href="http://github.com/rails/ssl_requirement/tree/master/lib/ssl_requirement.rb" rel="nofollow noreferrer">Take a look at the ssl_requirement plugin.</a></p>
<p>Shouldn't it check to see if you're in production mode? We're seeing a redirect to https in development mode, which seems odd. Or is that the normal behavior for the plugin? I thought it behaved differently in the past.</p>
|
[
{
"answer_id": 98697,
"author": "Nathan de Vries",
"author_id": 11109,
"author_profile": "https://Stackoverflow.com/users/11109",
"pm_score": 4,
"selected": true,
"text": "class YourController < ApplicationController\n ssl_required :update unless Rails.env.development?\nend\n"
},
{
"answer_id": 2152995,
"author": "tfentonz",
"author_id": 254356,
"author_profile": "https://Stackoverflow.com/users/254356",
"pm_score": 0,
"selected": false,
"text": "require 'controllers/application_controller'\n\nclass ApplicationController < ActionController::Base\n def ssl_required?\n false\n end\nend\n"
},
{
"answer_id": 2482569,
"author": "Anatoly",
"author_id": 290338,
"author_profile": "https://Stackoverflow.com/users/290338",
"pm_score": 2,
"selected": false,
"text": " def ssl_required?\n return false if local_request? || RAILS_ENV == 'test' || RAILS_ENV == 'development'\n super\n end\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97468",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17076/"
] |
97,474
|
<p>I need to get the value of the 'test' attribute in the xsl:when tag, and the 'name' attribute in the xsl:call-template tag. This xpath gets me pretty close: </p>
<pre><code>..../xsl:template/xsl:choose/xsl:when
</code></pre>
<p>But that just returns the 'when' elements, not the exact attribute values I need.</p>
<p>Here is a snippet of my XML:</p>
<pre><code><xsl:template match="field">
<xsl:choose>
<xsl:when test="@name='First Name'">
<xsl:call-template name="handleColumn_1" />
</xsl:when>
</xsl:choose>
</code></pre>
|
[
{
"answer_id": 97500,
"author": "Steve Cooper",
"author_id": 6722,
"author_profile": "https://Stackoverflow.com/users/6722",
"pm_score": 2,
"selected": false,
"text": ".../xsl:template/xsl:choose/xsl:when/@test"
},
{
"answer_id": 97738,
"author": "Mike Tunnicliffe",
"author_id": 13956,
"author_profile": "https://Stackoverflow.com/users/13956",
"pm_score": 2,
"selected": true,
"text": ".../xsl:template/xsl:choose/xsl:when[@test=\"@name='First Name'\"]/xsl:call-template/@name\n .../xsl:template/xsl:choose/xsl:when/xsl:call-template/@name\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97474",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10876/"
] |
97,480
|
<p>I have a Progress database that I'm performing an ETL from. One of the tables that I'm reading from does not have a unique key on it, so I need to access the ROWID to be able to uniquely identify the row. What is the syntax for accessing the ROWID in Progress?</p>
<p>I understand there are problems with using ROWID for row identification, but it's all I have right now.</p>
|
[
{
"answer_id": 100430,
"author": "David Webb",
"author_id": 3171,
"author_profile": "https://Stackoverflow.com/users/3171",
"pm_score": 4,
"selected": true,
"text": "ROWID RECID ROWID FIND customer WHERE cust-num = 123.\ncrowid = ROWID(customer).\n FIND customer WHERE ROWID(customer) = crowid EXCLUSIVE-LOCK.\n ROWID SELECT ROWID, FirstName, LastName FROM customer WHERE cust-num = 123\n"
},
{
"answer_id": 102910,
"author": "Stefan Moser",
"author_id": 8739,
"author_profile": "https://Stackoverflow.com/users/8739",
"pm_score": 2,
"selected": false,
"text": "SELECT ROWID, * FROM customer WHERE cust-num = 123\n SELECT ROWID, FirstName, LastName FROM customer WHERE cust-num = 123\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8739/"
] |
97,505
|
<p>Working on a somewhat complex page for configuring customers at work. The setup is that there's a main page, which contains various "panels" for various groups of settings. </p>
<p>In one case, there's an email address field on the main table and an "export" configuration that controls how emails are sent out. I created a main panel that selects the company, and binds to a FormView. The FormView contains a Web User Control that handles the display/configuration of the export details.</p>
<p>The Web User Control Contains a property to define which Config it should be handling, and it gets the value from the FormView using Bind().</p>
<p>Basically the control is used like this:</p>
<pre><code><syn:ExportInfo ID="eiConfigDetails" ExportInfoID='<%# Bind("ExportInfoID" ) %>' runat="server" />
</code></pre>
<p>The property being bound is declared like this in CodeBehind:</p>
<pre><code>public int ExportInfoID
{
get
{
return Convert.ToInt32(hfID.Value);
}
set
{
try
{
hfID.Value = value.ToString();
}
catch(Exception)
{
hfID.Value="-1";
}
}
}
</code></pre>
<p>Whenever the <code>ExportInfoID</code> is null I get a null reference exception, but the kicker is that it happens BEFORE it actually tries to set the property (or it would be caught in this version.)</p>
<p>Anyone know what's going on or, more importantly, how to fix it...?</p>
|
[
{
"answer_id": 100430,
"author": "David Webb",
"author_id": 3171,
"author_profile": "https://Stackoverflow.com/users/3171",
"pm_score": 4,
"selected": true,
"text": "ROWID RECID ROWID FIND customer WHERE cust-num = 123.\ncrowid = ROWID(customer).\n FIND customer WHERE ROWID(customer) = crowid EXCLUSIVE-LOCK.\n ROWID SELECT ROWID, FirstName, LastName FROM customer WHERE cust-num = 123\n"
},
{
"answer_id": 102910,
"author": "Stefan Moser",
"author_id": 8739,
"author_profile": "https://Stackoverflow.com/users/8739",
"pm_score": 2,
"selected": false,
"text": "SELECT ROWID, * FROM customer WHERE cust-num = 123\n SELECT ROWID, FirstName, LastName FROM customer WHERE cust-num = 123\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17145/"
] |
97,506
|
<p><strong>This isn't a holy war, this isn't a question of "which is better".</strong></p>
<p>What are the pros of using the following format for single statement if blocks.</p>
<pre><code>if (x) print "x is true";
if(x)
print "x is true";
</code></pre>
<p>As opposed to</p>
<pre><code>if (x) { print "x is true"; }
if(x) {
print "x is true";
}
</code></pre>
<p><strong>If you format your single statement ifs without brackets</strong> or know a programmer that does, what led you/them to adopt this style in the first place? I'm specifically interested in what benefits this has brought you.</p>
<p><strong>Update</strong>: As the most popular answer ignores the actual question (even if it presents the most sane advice), here's a roundup of the bracket-less pros.</p>
<ol>
<li>Compactness</li>
<li>More readable to some</li>
<li>Brackets invoke scope, which has a theoretical overhead in some cases</li>
</ol>
|
[
{
"answer_id": 97525,
"author": "MagicKat",
"author_id": 8505,
"author_profile": "https://Stackoverflow.com/users/8505",
"pm_score": 2,
"selected": false,
"text": "if (foo)\n{\n Console.WriteLine(\"Foobar\");\n}\n"
},
{
"answer_id": 97526,
"author": "Matt Dillard",
"author_id": 863,
"author_profile": "https://Stackoverflow.com/users/863",
"pm_score": 7,
"selected": true,
"text": "if( true ) {\n DoSomething();\n} else {\n DoSomethingElse();\n}\n if( true )\n DoSomething();\nelse\n DoSomethingElse();\n"
},
{
"answer_id": 97529,
"author": "user18301",
"author_id": 18301,
"author_profile": "https://Stackoverflow.com/users/18301",
"pm_score": 4,
"selected": false,
"text": "if(x) \n{\n print \"x is true\"; \n}\n"
},
{
"answer_id": 97531,
"author": "Darren Kopp",
"author_id": 77,
"author_profile": "https://Stackoverflow.com/users/77",
"pm_score": 3,
"selected": false,
"text": "if\n{\n// code\n}\nelse \n{\n// else code\n}\n"
},
{
"answer_id": 97549,
"author": "Chris Pietschmann",
"author_id": 7831,
"author_profile": "https://Stackoverflow.com/users/7831",
"pm_score": 0,
"selected": false,
"text": "// Do this if you only have one line of code\n// executing within the if statement\nif (x)\n print \"x is true\";\n\n// Do this when you have multiple lines of code\n// getting executed within the if statement \nif (x)\n{\n print \"x is true\";\n}\n"
},
{
"answer_id": 97552,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 3,
"selected": false,
"text": "if(x) \n print \"x is true\";\n if(x) \n print \"x is true\";\n print \"x is still true\";\n if(x) { \n print \"x is true\";\n print \"x is still true\";\n}\n"
},
{
"answer_id": 97562,
"author": "Lucas Oman",
"author_id": 6726,
"author_profile": "https://Stackoverflow.com/users/6726",
"pm_score": 2,
"selected": false,
"text": "if (cond) {\n ...\n} else {\n ...\n}\n"
},
{
"answer_id": 97564,
"author": "moonshadow",
"author_id": 11834,
"author_profile": "https://Stackoverflow.com/users/11834",
"pm_score": 2,
"selected": false,
"text": "if (x)\n{\n print \"x is true\";\n}\n"
},
{
"answer_id": 97583,
"author": "Matthew Jaskula",
"author_id": 4356,
"author_profile": "https://Stackoverflow.com/users/4356",
"pm_score": 3,
"selected": false,
"text": "if(x) \n print \"x is true\";\n print \"something else\";\n"
},
{
"answer_id": 97596,
"author": "user17000",
"author_id": 17000,
"author_profile": "https://Stackoverflow.com/users/17000",
"pm_score": 1,
"selected": false,
"text": "If(x)\n{\n print \"Hello World !!\"\n}\nElse\n{\n print \"Good bye!!\"\n}\n"
},
{
"answer_id": 97680,
"author": "Zack Peterson",
"author_id": 83,
"author_profile": "https://Stackoverflow.com/users/83",
"pm_score": 2,
"selected": false,
"text": "if (i != 0) \n foo(i);\n if (i != 0)\n bar(i);\n foo(i);\n"
},
{
"answer_id": 97791,
"author": "mike511",
"author_id": 9593,
"author_profile": "https://Stackoverflow.com/users/9593",
"pm_score": 1,
"selected": false,
"text": "if(x)\n{\n somecode;\n}\nelse\n{\n morecode;\n}\n"
},
{
"answer_id": 97917,
"author": "Jeff",
"author_id": 16639,
"author_profile": "https://Stackoverflow.com/users/16639",
"pm_score": 2,
"selected": false,
"text": "if (a)\n foo();\n bar();\n"
},
{
"answer_id": 97918,
"author": "johnc",
"author_id": 5302,
"author_profile": "https://Stackoverflow.com/users/5302",
"pm_score": 3,
"selected": false,
"text": "public void MyFunction(object param)\n{\n if (param == null) return;\n\n ...\n}\n"
},
{
"answer_id": 97919,
"author": "Jason Hanford-Smith",
"author_id": 18345,
"author_profile": "https://Stackoverflow.com/users/18345",
"pm_score": 3,
"selected": false,
"text": "if (x)\n{\n ...statement1\n ...statement2\n}\n if (x)\n ...statement\nelse\n ...statement\n"
},
{
"answer_id": 97921,
"author": "Doron Yaacoby",
"author_id": 3389,
"author_profile": "https://Stackoverflow.com/users/3389",
"pm_score": 2,
"selected": false,
"text": "if (x)\n print \"x is true\"\nfor (int i=0; i<10; i++)\n print \"y is true\"\n"
},
{
"answer_id": 98086,
"author": "easeout",
"author_id": 10906,
"author_profile": "https://Stackoverflow.com/users/10906",
"pm_score": 2,
"selected": false,
"text": "if (x) {\n print \"x is true\"; \n}\nelse {\n do something else;\n}\n"
},
{
"answer_id": 98569,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 5,
"selected": false,
"text": "if (condition)\n do_something();\nelse\n do_something_else();\n if (condition)\n if (condition2)\n do_something();\nelse\n do_something_else();\n if (condition)\n if (condition2)\n do_something();\n else\n do_something_else();\n"
},
{
"answer_id": 98646,
"author": "spoulson",
"author_id": 3347,
"author_profile": "https://Stackoverflow.com/users/3347",
"pm_score": 0,
"selected": false,
"text": "if (expr) {\n funcA();\n}\nelse {\n funcB();\n}\n if (expr) funcA();\nelse funcB();\n if (expr)\n funcA();\nelse\n funcB();\n if else if else"
},
{
"answer_id": 99615,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "/* I type one liners with brackets like this */\nif(0){return(0);}\n/* If else blocks like this */\nif(0){\n return(0);\n}else{\n return(-1);\n}\n"
},
{
"answer_id": 99898,
"author": "Robert Paulson",
"author_id": 14033,
"author_profile": "https://Stackoverflow.com/users/14033",
"pm_score": 2,
"selected": false,
"text": "public int IndexOf(string haystack, string needle)\n{\n // check parameters.\n if (haystack == null)\n throw new ArgumentNullException(\"haystack\");\n if (string.IsNullOrEmpty(needle))\n return -1;\n\n // rest of method here ...\n"
},
{
"answer_id": 103168,
"author": "Dave Sherohman",
"author_id": 18914,
"author_profile": "https://Stackoverflow.com/users/18914",
"pm_score": 0,
"selected": false,
"text": "if (x) {\n print \"x is true\"; \n}\n print \"x is true\" if x;\n"
},
{
"answer_id": 109750,
"author": "quinmars",
"author_id": 18687,
"author_profile": "https://Stackoverflow.com/users/18687",
"pm_score": 0,
"selected": false,
"text": "\nif (x)\n x = x + 1;\n printf(\"%d\\n\", x);\n \n#define FREE(ptr) {free(ptr); ptr = NULL;}\n\nif (x)\n FREE(x);\nelse\n ...\n"
},
{
"answer_id": 118679,
"author": "Dan Adams",
"author_id": 1628,
"author_profile": "https://Stackoverflow.com/users/1628",
"pm_score": 0,
"selected": false,
"text": "if(x)\n{\n code;\n}\nelse\n{\n other code;\n}\n"
},
{
"answer_id": 154813,
"author": "Lucas Gabriel Sánchez",
"author_id": 20601,
"author_profile": "https://Stackoverflow.com/users/20601",
"pm_score": 1,
"selected": false,
"text": "if (x) doSomething();\n\nif (x) {\n doSomthing();\n doOtherthing();\n}\n"
},
{
"answer_id": 1107746,
"author": "TSomKes",
"author_id": 18347,
"author_profile": "https://Stackoverflow.com/users/18347",
"pm_score": 0,
"selected": false,
"text": "if (x)\n{ foo(); }\n if (x)\n{ foo(); }\nelse\n{\n bar();\n baz();\n}\n"
},
{
"answer_id": 1107839,
"author": "Newtopian",
"author_id": 25812,
"author_profile": "https://Stackoverflow.com/users/25812",
"pm_score": 0,
"selected": false,
"text": "if (param == null || parameterDoesNotValidateForMethod) throw new InvalidArgumentExeption(\"Parameter null or invalid\");\n if (something)\n{\n for(blablabla)\n {\n }\n}else if\n{\n //one liner or bunch of other code all get the braces\n}else\n{\n //... well you get the point\n}\n if(someCondition) { doSimpleStuff; }\n if(somethingElse){\n //then do something\n}\n if(someStuff)\n {\n //do something\n }\n"
},
{
"answer_id": 28863415,
"author": "RicardoVallejo",
"author_id": 3429457,
"author_profile": "https://Stackoverflow.com/users/3429457",
"pm_score": 2,
"selected": false,
"text": "(a==b) ? printf(\"yup true\") : printf(\"nop false\");\n int x = (a==b) ? printf(\"yup true\") : printf(\"nop false\");\n"
},
{
"answer_id": 37676645,
"author": "user160917",
"author_id": 160917,
"author_profile": "https://Stackoverflow.com/users/160917",
"pm_score": 2,
"selected": false,
"text": "if(x > y) { xIsGreaterThanY(); }\nelse if(y > x) { yIsGreaterThanX; }\nelse { xEqualsY(); }\n if( x > y ){\n xIsGreaterThanY(); \n}else if( x < y){\n yIsGreaterThanX();\n}else{\n xEqualsY();\n}\n"
},
{
"answer_id": 45828183,
"author": "Scott - Слава Україні",
"author_id": 1672723,
"author_profile": "https://Stackoverflow.com/users/1672723",
"pm_score": 0,
"selected": false,
"text": "if (x)\n DoSomething();\n DoSomething"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97506",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4668/"
] |
97,520
|
<p>How is possible to set some special column values when update/insert entities via NHibernate without extending domain classes with special properties?</p>
<p>E.g. every table contains audit columns like CreatedBy, CreatedDate, UpdatedBy, UpdatedDate. But I dont want to add these poperties to the domain classes. I want to keep domain modedl Percistence Ignorance factor as high as possible.</p>
|
[
{
"answer_id": 101037,
"author": "noetic",
"author_id": 9198,
"author_profile": "https://Stackoverflow.com/users/9198",
"pm_score": 1,
"selected": false,
"text": "private IDictionary _infrastructureProperties = new Dictionary<object, object>();\n <dynamic-component name='_infrastructureProperties' access='field'>\n <property name='CreateBy' column='CreatedBy' />\n <property name='CreateDate' column='CreatedDate' />\n</dynamic-component>\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97520",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9198/"
] |
97,522
|
<p>What are all the valid self-closing elements (e.g. <br/>) in XHTML (as implemented by the major browsers)?</p>
<p>I know that XHTML technically allows any element to be self-closed, but I'm looking for a list of those elements supported by all major browsers. See <a href="http://dusan.fora.si/blog/self-closing-tags" rel="noreferrer">http://dusan.fora.si/blog/self-closing-tags</a> for examples of some problems caused by self-closing elements such as <div />.</p>
|
[
{
"answer_id": 97575,
"author": "e-satis",
"author_id": 9951,
"author_profile": "https://Stackoverflow.com/users/9951",
"pm_score": 3,
"selected": false,
"text": "<br />\n<hr />\n<img />\n<input />\n"
},
{
"answer_id": 97585,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 5,
"selected": false,
"text": "<area />\n<base />\n<basefont />\n<br />\n<hr />\n<input />\n<img />\n<link />\n<meta />\n"
},
{
"answer_id": 142447,
"author": "AmbroseChapel",
"author_id": 242241,
"author_profile": "https://Stackoverflow.com/users/242241",
"pm_score": 3,
"selected": false,
"text": "<meta> <link> <br> <img>"
},
{
"answer_id": 142457,
"author": "Erik van Brakel",
"author_id": 909,
"author_profile": "https://Stackoverflow.com/users/909",
"pm_score": 5,
"selected": false,
"text": "<script <!-- this will not consistently work in all browsers! -->\n<script type=\"text/javascript\" src=\"external.js\" />\n"
},
{
"answer_id": 196249,
"author": "Kevin Hakanson",
"author_id": 22514,
"author_profile": "https://Stackoverflow.com/users/22514",
"pm_score": 2,
"selected": false,
"text": "<title/>\n"
},
{
"answer_id": 206409,
"author": "Kornel",
"author_id": 27009,
"author_profile": "https://Stackoverflow.com/users/27009",
"pm_score": 9,
"selected": true,
"text": "<div/> <script/> <br></br> text/html <span style=\"color:green\"><span style=\"color:red\"/> \n If it's red, it's HTML. Green is XHTML.\n</span>\n DOCTYPE Content-Type /> <br/> <hr></hr>"
},
{
"answer_id": 1735748,
"author": "Jeff",
"author_id": 142233,
"author_profile": "https://Stackoverflow.com/users/142233",
"pm_score": 4,
"selected": false,
"text": "<base />\n<basefont />\n<frame />\n<link />\n<meta />\n\n<area />\n<br />\n<col />\n<hr />\n<img />\n<input />\n<param />\n"
},
{
"answer_id": 3581293,
"author": "Nathan Sokalski",
"author_id": 432546,
"author_profile": "https://Stackoverflow.com/users/432546",
"pm_score": 2,
"selected": false,
"text": "<title/> <head></head> <script/> <script/> <form> <script/> <script></script>"
},
{
"answer_id": 8853550,
"author": "Dmitry Osinovskiy",
"author_id": 194020,
"author_profile": "https://Stackoverflow.com/users/194020",
"pm_score": 5,
"selected": false,
"text": "area, base, br, col, embed, hr, img, input, keygen, link, menuitem, meta, param, source, track, wbr command basefont, bgsound, frame, isindex"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97522",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1335/"
] |
97,565
|
<p>C# question (.net 3.5). I have a class, ImageData, that has a field ushort[,] pixels. I am dealing with proprietary image formats. The ImageData class takes a file location in the constructor, then switches on file extension to determine how to decode. In several of the image files, there is a "bit depth" field in the header. After I decode the header I read the pixel values into the "pixels" array. So far I have not had more than 16bpp, so I'm okay. But what if I have 32bpp?</p>
<p>What I want to do is have the type of pixels be determined at runtime. I want to do this after I read the bit depth out of the header and before I copy the pixel data into memory. Any ideas?</p>
|
[
{
"answer_id": 97788,
"author": "Wedge",
"author_id": 332,
"author_profile": "https://Stackoverflow.com/users/332",
"pm_score": 3,
"selected": true,
"text": "public static ImageData Create(string imageFilename)\n{\n // ...\n ImageDataHeader imageHeader = ParseHeader(imageFilename);\n ImageData newImageData;\n if (imageHeader.bpp == 32)\n {\n newImageData = new ImageData32(imageFilename, imageHeader);\n }\n else\n {\n newImageData = new ImageData16(imageFilename, imageHeader);\n }\n // ...\n return newImageData;\n}\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97565",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1812999/"
] |
97,578
|
<p>Maybe I'm just thinking about this too hard, but I'm having a problem figuring out what escaping to use on a string in some JavaScript code inside a link's onClick handler. Example:</p>
<pre><code><a href="#" onclick="SelectSurveyItem('<%itemid%>', '<%itemname%>'); return false;">Select</a>
</code></pre>
<p>The <code><%itemid%></code> and <code><%itemname%></code> are where template substitution occurs. My problem is that the item name can contain any character, including single and double quotes. Currently, if it contains single quotes it breaks the JavaScript code.</p>
<p>My first thought was to use the template language's function to JavaScript-escape the item name, which just escapes the quotes. That will not fix the case of the string containing double quotes which breaks the HTML of the link. How is this problem normally addressed? Do I need to HTML-escape the entire onClick handler?</p>
<p>If so, that would look really strange since the template language's escape function for that would also HTMLify the parentheses, quotes, and semicolons...</p>
<p>This link is being generated for every result in a search results page, so creating a separate method inside a JavaScript tag is not possible, because I'd need to generate one per result.</p>
<p>Also, I'm using a templating engine that was home-grown at the company I work for, so toolkit-specific solutions will be of no use to me.</p>
|
[
{
"answer_id": 97613,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 3,
"selected": false,
"text": "> > < < \" ""
},
{
"answer_id": 97670,
"author": "Alexandre Victoor",
"author_id": 11897,
"author_profile": "https://Stackoverflow.com/users/11897",
"pm_score": 1,
"selected": false,
"text": "<a id=\"someLinkId\"href=\"#\">Select</a>\n<script type=\"text/javascript\">\n document.getElementById(\"someLinkId\").onClick = \n function() {\n SelectSurveyItem('<%itemid%>', '<%itemname%>'); return false;\n };\n\n</script>\n \" \\\""
},
{
"answer_id": 97687,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 3,
"selected": false,
"text": "<a id=\"tehbutton\" href=\"somewhereToGoWithoutWorkingJavascript.com\">Select</a>\n <script type=\"text/javascript\">//<!-- <![CDATA[\njQuery(function($){\n $(\"#tehbutton\").click(function(){\n SelectSurveyItem('<%itemid%>', '<%itemname%>');\n return false;\n });\n});\n//]]>--></script>\n <a id=\"link_1\" href=\"foo\">Bar</a>\n<a id=\"link_2\" href=\"foo2\">Baz</a>\n\n<script type=\"text/javascript\">\n jQuery(function($){\n var l = [[1,'Bar'],[2,'Baz']];\n $(l).each(function(k,v){\n $(\"#link_\" + v[0] ).click(function(){\n SelectSurveyItem(v[0],v[1]);\n return false;\n });\n });\n });\n </script>\n"
},
{
"answer_id": 97724,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 2,
"selected": false,
"text": "<a href=\"#\" itemid=\"<%itemid%>\" itemname=\"<%itemname%>\" onclick=\"SelectSurveyItem(this.itemid, this.itemname); return false;\">Select</a>\n"
},
{
"answer_id": 97804,
"author": "Duncan Smart",
"author_id": 1278,
"author_profile": "https://Stackoverflow.com/users/1278",
"pm_score": 7,
"selected": true,
"text": "<a href=\"#\" onclick=\"SelectSurveyItem('<% JSEncode(itemid) %>', '<% JSEncode(itemname) %>'); return false;\">Select</a>\n"
},
{
"answer_id": 506347,
"author": "Shyam Kumar Sundarakumar",
"author_id": 35392,
"author_profile": "https://Stackoverflow.com/users/35392",
"pm_score": 4,
"selected": false,
"text": "<%itemid%> <%itemname%> <%itemid%> <span id='itemid' style='display:none'><%itemid%></span> SelectSurveyItem innerHTML"
},
{
"answer_id": 5273245,
"author": "AhmedGamal",
"author_id": 655389,
"author_profile": "https://Stackoverflow.com/users/655389",
"pm_score": 0,
"selected": false,
"text": "onclick=\"myfun(1)\"\nonclick=\"myfun(2)\"\nonclick=\"myfun(3)\"\n\nfunction myfun(var)\n{\n if (var ==1)\n alert(v1);\n\n if (var ==2)\n alert(v2);\n\n if (var ==3)\n alert(v3);\n}\n"
},
{
"answer_id": 8611916,
"author": "Vitalii Fedorenko",
"author_id": 288671,
"author_profile": "https://Stackoverflow.com/users/288671",
"pm_score": 5,
"selected": false,
"text": "string result = System.Web.HttpUtility.JavaScriptStringEncode(\"jsString\")\n import org.apache.commons.lang.StringEscapeUtils;\n...\n\nString result = StringEscapeUtils.escapeJavaScript(jsString);\n import json\nresult = json.dumps(jsString)\n $result = strtr($jsString, array('\\\\' => '\\\\\\\\', \"'\" => \"\\\\'\", '\"' => '\\\\\"', \n \"\\r\" => '\\\\r', \"\\n\" => '\\\\n' ));\n <%= escape_javascript(jsString) %>\n"
},
{
"answer_id": 9303208,
"author": "Starbuck Johnson",
"author_id": 1212632,
"author_profile": "https://Stackoverflow.com/users/1212632",
"pm_score": 1,
"selected": false,
"text": "function noQuote(text)\n{\n var newtext = \"\";\n for (var i = 0; i < text.length; i++) {\n if (text[i] == \"'\") {\n newtext += \"\\\"\";\n }\n else {\n newtext += text[i];\n }\n }\n return newtext;\n}\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97578",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10861/"
] |
97,586
|
<p>My boss loves VB (we work in a Java shop) because he thinks it's easy to learn and maintain. We want to replace some of the VB with java equivalents using the Eclipse SWT editor, because we think it is almost as easy to maintain. To sell this, we'd like to use an aerith style L&F.</p>
<p>Can anyone provide an example of an SWT application still being able to edit the GUI in eclipse, but having the Aerith L&F?</p>
|
[
{
"answer_id": 97613,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 3,
"selected": false,
"text": "> > < < \" ""
},
{
"answer_id": 97670,
"author": "Alexandre Victoor",
"author_id": 11897,
"author_profile": "https://Stackoverflow.com/users/11897",
"pm_score": 1,
"selected": false,
"text": "<a id=\"someLinkId\"href=\"#\">Select</a>\n<script type=\"text/javascript\">\n document.getElementById(\"someLinkId\").onClick = \n function() {\n SelectSurveyItem('<%itemid%>', '<%itemname%>'); return false;\n };\n\n</script>\n \" \\\""
},
{
"answer_id": 97687,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 3,
"selected": false,
"text": "<a id=\"tehbutton\" href=\"somewhereToGoWithoutWorkingJavascript.com\">Select</a>\n <script type=\"text/javascript\">//<!-- <![CDATA[\njQuery(function($){\n $(\"#tehbutton\").click(function(){\n SelectSurveyItem('<%itemid%>', '<%itemname%>');\n return false;\n });\n});\n//]]>--></script>\n <a id=\"link_1\" href=\"foo\">Bar</a>\n<a id=\"link_2\" href=\"foo2\">Baz</a>\n\n<script type=\"text/javascript\">\n jQuery(function($){\n var l = [[1,'Bar'],[2,'Baz']];\n $(l).each(function(k,v){\n $(\"#link_\" + v[0] ).click(function(){\n SelectSurveyItem(v[0],v[1]);\n return false;\n });\n });\n });\n </script>\n"
},
{
"answer_id": 97724,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 2,
"selected": false,
"text": "<a href=\"#\" itemid=\"<%itemid%>\" itemname=\"<%itemname%>\" onclick=\"SelectSurveyItem(this.itemid, this.itemname); return false;\">Select</a>\n"
},
{
"answer_id": 97804,
"author": "Duncan Smart",
"author_id": 1278,
"author_profile": "https://Stackoverflow.com/users/1278",
"pm_score": 7,
"selected": true,
"text": "<a href=\"#\" onclick=\"SelectSurveyItem('<% JSEncode(itemid) %>', '<% JSEncode(itemname) %>'); return false;\">Select</a>\n"
},
{
"answer_id": 506347,
"author": "Shyam Kumar Sundarakumar",
"author_id": 35392,
"author_profile": "https://Stackoverflow.com/users/35392",
"pm_score": 4,
"selected": false,
"text": "<%itemid%> <%itemname%> <%itemid%> <span id='itemid' style='display:none'><%itemid%></span> SelectSurveyItem innerHTML"
},
{
"answer_id": 5273245,
"author": "AhmedGamal",
"author_id": 655389,
"author_profile": "https://Stackoverflow.com/users/655389",
"pm_score": 0,
"selected": false,
"text": "onclick=\"myfun(1)\"\nonclick=\"myfun(2)\"\nonclick=\"myfun(3)\"\n\nfunction myfun(var)\n{\n if (var ==1)\n alert(v1);\n\n if (var ==2)\n alert(v2);\n\n if (var ==3)\n alert(v3);\n}\n"
},
{
"answer_id": 8611916,
"author": "Vitalii Fedorenko",
"author_id": 288671,
"author_profile": "https://Stackoverflow.com/users/288671",
"pm_score": 5,
"selected": false,
"text": "string result = System.Web.HttpUtility.JavaScriptStringEncode(\"jsString\")\n import org.apache.commons.lang.StringEscapeUtils;\n...\n\nString result = StringEscapeUtils.escapeJavaScript(jsString);\n import json\nresult = json.dumps(jsString)\n $result = strtr($jsString, array('\\\\' => '\\\\\\\\', \"'\" => \"\\\\'\", '\"' => '\\\\\"', \n \"\\r\" => '\\\\r', \"\\n\" => '\\\\n' ));\n <%= escape_javascript(jsString) %>\n"
},
{
"answer_id": 9303208,
"author": "Starbuck Johnson",
"author_id": 1212632,
"author_profile": "https://Stackoverflow.com/users/1212632",
"pm_score": 1,
"selected": false,
"text": "function noQuote(text)\n{\n var newtext = \"\";\n for (var i = 0; i < text.length; i++) {\n if (text[i] == \"'\") {\n newtext += \"\\\"\";\n }\n else {\n newtext += text[i];\n }\n }\n return newtext;\n}\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15441/"
] |
97,637
|
<p>Anyone got a good explanation of "combinators" (Y-combinators etc. and <strong>NOT</strong> <a href="https://en.wikipedia.org/wiki/Y_Combinator_(company)" rel="noreferrer">the company</a>)?</p>
<p>I'm looking for one for the practical programmer who understands recursion and higher-order functions, but doesn't have a strong theory or math background.</p>
<p>(Note: that I'm talking about <a href="https://en.wikipedia.org/wiki/Fixed-point_combinator#Fixed_point_combinators_in_lambda_calculus" rel="noreferrer">these things</a>)</p>
|
[
{
"answer_id": 101932,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": "> def fun():\n> print \"bla\"\n> fun()\n\n> fun()\nbla\nbla\nbla\n...\n fun fun fun fun > def fun():\n> print \"bla\"\n> # what to do here? (cannot call fun!)\n fun fun > def fun(arg): # fun receives itself as argument\n> print \"bla\"\n> arg(arg) # to recur, fun calls itself, and passes itself along\n > def Y(f):\n> f(f)\n\n> Y(fun)\nbla\nbla\nbla\n...\n"
},
{
"answer_id": 286014,
"author": "mbac32768",
"author_id": 18446,
"author_profile": "https://Stackoverflow.com/users/18446",
"pm_score": 1,
"selected": false,
"text": "tru = lambda x,y: x\nfls = lambda x,y: y \n\ntest = lambda l,m,n: l(m,n)\n >>> test(tru,\"goto loop\",\"break\")\n'goto loop'\n>>> test(fls,\"goto loop\",\"break\")\n'break'\n >>> x = tru\n>>> test(x,\"goto loop\",\"break\")\n'goto loop'\n"
},
{
"answer_id": 2215223,
"author": "Thomas Eding",
"author_id": 239916,
"author_profile": "https://Stackoverflow.com/users/239916",
"pm_score": 4,
"selected": false,
"text": "(f o g)(x) = f(g(x)) o f g f g f o g NumberUndefined NumberUndefined Num x Undefined x Number Number Undefined Undefined 0 Undefined Undefined +' num = Undefined\nnum +' Undefined = Undefined\n(Num x) +' (Num y) = Num (x + y)\n\nUndefined -' num = Undefined\nnum -' Undefined = Undefined\n(Num x) -' (Num y) = Num (x - y)\n\nUndefined *' num = Undefined\nnum *' Undefined = Undefined\n(Num x) *' (Num y) = Num (x * y)\n\nUndefined /' num = Undefined\nnum /' Undefined = Undefined\n(Num x) /' (Num y) = if y == 0 then Undefined else Num (x / y)\n Undefined comb (~) Undefined num = Undefined\ncomb (~) num Undefined = Undefined\ncomb (~) (Num x) (Num y) = Num (x ~ y)\n\nx +' y = comb (+) x y\nx -' y = comb (-) x y\nx *' y = comb (*) x y\nx /' y = if y == Num 0 then Undefined else comb (/) x y\n Maybe"
},
{
"answer_id": 2215293,
"author": "Igor Zevaka",
"author_id": 129404,
"author_profile": "https://Stackoverflow.com/users/129404",
"pm_score": 3,
"selected": false,
"text": "let sum a b = a + b;; //sum function (lambda)\n a b let sum3 a b c = sum((sum a b) c);;\n sum let sum3 a b c sumFunc = sumFunc((sumFunc a b) c);;\n sumFunc explicit"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97637",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8482/"
] |
97,640
|
<p>How do I get my project's runtime dependencies copied into the <code>target/lib</code> folder? </p>
<p>As it is right now, after <code>mvn clean install</code> the <code>target</code> folder contains only my project's jar, but none of the runtime dependencies.</p>
|
[
{
"answer_id": 996915,
"author": "Georgy Bolyuba",
"author_id": 4052,
"author_profile": "https://Stackoverflow.com/users/4052",
"pm_score": 8,
"selected": false,
"text": "<project>\n ...\n <profiles>\n <profile>\n <id>qa</id>\n <build>\n <plugins>\n <plugin>\n <artifactId>maven-dependency-plugin</artifactId>\n <executions>\n <execution>\n <phase>install</phase>\n <goals>\n <goal>copy-dependencies</goal>\n </goals>\n <configuration>\n <outputDirectory>${project.build.directory}/lib</outputDirectory>\n </configuration>\n </execution>\n </executions>\n </plugin>\n </plugins>\n </build>\n </profile>\n </profiles>\n</project>\n"
},
{
"answer_id": 1449651,
"author": "Rich Seller",
"author_id": 123582,
"author_profile": "https://Stackoverflow.com/users/123582",
"pm_score": 3,
"selected": false,
"text": " <plugin>\n <groupId>org.codehaus.mojo</groupId>\n <artifactId>appassembler-maven-plugin</artifactId>\n <version>1.0</version>\n <executions>\n <execution>\n <id>generate-jsw-scripts</id>\n <phase>package</phase>\n <goals>\n <goal>generate-daemons</goal>\n </goals>\n <configuration>\n <!--declare the JSW config -->\n <daemons>\n <daemon>\n <id>myApp</id>\n <mainClass>name.seller.rich.MyMainClass</mainClass>\n <commandLineArguments>\n <commandLineArgument>start</commandLineArgument>\n </commandLineArguments>\n <platforms>\n <platform>jsw</platform>\n </platforms> \n </daemon>\n </daemons>\n <target>${project.build.directory}/appassembler</target>\n </configuration>\n </execution>\n <execution>\n <id>assemble-standalone</id>\n <phase>integration-test</phase>\n <goals>\n <goal>assemble</goal>\n </goals>\n <configuration>\n <programs>\n <program>\n <mainClass>name.seller.rich.MyMainClass</mainClass>\n <!-- the name of the bat/sh files to be generated -->\n <name>mymain</name>\n </program>\n </programs>\n <platforms>\n <platform>windows</platform>\n <platform>unix</platform>\n </platforms>\n <repositoryLayout>flat</repositoryLayout>\n <repositoryName>lib</repositoryName>\n </configuration>\n </execution>\n </executions>\n </plugin>\n <plugin>\n <artifactId>maven-assembly-plugin</artifactId>\n <version>2.2-beta-4</version>\n <executions>\n <execution>\n <phase>integration-test</phase>\n <goals>\n <goal>single</goal>\n </goals>\n <configuration>\n <descriptors>\n <descriptor>src/main/assembly/archive.xml</descriptor>\n </descriptors>\n </configuration>\n </execution>\n </executions>\n </plugin> \n <assembly>\n <id>archive</id>\n <formats>\n <format>zip</format>\n </formats>\n <fileSets>\n <fileSet>\n <directory>${project.build.directory}/appassembler</directory>\n <outputDirectory>/</outputDirectory>\n </fileSet>\n </fileSets>\n</assembly>\n"
},
{
"answer_id": 3769147,
"author": "OleVV",
"author_id": 455012,
"author_profile": "https://Stackoverflow.com/users/455012",
"pm_score": 1,
"selected": false,
"text": "<plugin>\n <artifactId>maven-assembly-plugin</artifactId>\n <version>2.2-beta-5</version>\n <configuration>\n <archive>\n <manifest>\n <mainClass>dk.certifikat.oces2.some.package.MyMainClass</mainClass>\n </manifest>\n </archive>\n <descriptorRefs>\n <descriptorRef>jar-with-dependencies</descriptorRef>\n </descriptorRefs>\n </configuration>\n</plugin>\n"
},
{
"answer_id": 6536190,
"author": "ruhsuzbaykus",
"author_id": 453708,
"author_profile": "https://Stackoverflow.com/users/453708",
"pm_score": 5,
"selected": false,
"text": "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">\n\n <modelVersion>4.0.0</modelVersion>\n <groupId>groupId</groupId>\n <artifactId>artifactId</artifactId>\n <version>1.0</version>\n\n <dependencies>\n <dependency>\n <groupId>org.mybatis</groupId>\n <artifactId>mybatis-spring</artifactId>\n <version>1.1.1</version>\n </dependency>\n </dependencies>\n\n <build>\n <plugins>\n <plugin>\n <artifactId>maven-dependency-plugin</artifactId>\n <executions>\n <execution>\n <phase>process-sources</phase>\n\n <goals>\n <goal>copy-dependencies</goal>\n </goals>\n\n <configuration>\n <outputDirectory>${targetdirectory}</outputDirectory>\n </configuration>\n </execution>\n </executions>\n </plugin>\n </plugins>\n </build>\n</project>\n mvn process-sources /target/dependency"
},
{
"answer_id": 9087972,
"author": "RubyTuesdayDONO",
"author_id": 155090,
"author_profile": "https://Stackoverflow.com/users/155090",
"pm_score": 2,
"selected": false,
"text": "<project>\n <build>\n <plugins>\n <plugin>\n <artifactId>maven-assembly-plugin</artifactId>\n <version>2.2.2</version>\n <configuration>\n <descriptorRefs>\n <descriptorRef>jar-with-dependencies</descriptorRef>\n </descriptorRefs>\n </configuration>\n </plugin>\n </plugins>\n </build>\n</project>\n"
},
{
"answer_id": 10395558,
"author": "adjablon",
"author_id": 1075955,
"author_profile": "https://Stackoverflow.com/users/1075955",
"pm_score": 5,
"selected": false,
"text": "<plugin>\n<groupId>org.apache.maven.plugins</groupId>\n<artifactId>maven-jar-plugin</artifactId>\n<version>2.4</version>\n<configuration>\n <archive>\n <manifest> \n <addClasspath>true</addClasspath>\n <classpathPrefix>lib/</classpathPrefix>\n <mainClass>MainClass</mainClass>\n </manifest>\n </archive>\n </configuration>\n</plugin>\n<plugin>\n <groupId>org.apache.maven.plugins</groupId>\n <artifactId>maven-dependency-plugin</artifactId>\n <version>2.4</version>\n <executions>\n <execution>\n <id>copy</id>\n <phase>install</phase>\n <goals>\n <goal>copy-dependencies</goal>\n </goals>\n <configuration>\n <outputDirectory>\n ${project.build.directory}/lib\n </outputDirectory>\n </configuration>\n </execution>\n </executions>\n</plugin>\n"
},
{
"answer_id": 21641165,
"author": "user3286149",
"author_id": 3286149,
"author_profile": "https://Stackoverflow.com/users/3286149",
"pm_score": 7,
"selected": false,
"text": "mvn install dependency:copy-dependencies \n"
},
{
"answer_id": 25441276,
"author": "Duncan Jones",
"author_id": 474189,
"author_profile": "https://Stackoverflow.com/users/474189",
"pm_score": 5,
"selected": false,
"text": "target/dependencies"
},
{
"answer_id": 47963667,
"author": "isapir",
"author_id": 968244,
"author_profile": "https://Stackoverflow.com/users/968244",
"pm_score": 5,
"selected": false,
"text": "build/plugins <plugin>\n <artifactId>maven-dependency-plugin</artifactId>\n <executions>\n <execution>\n <phase>prepare-package</phase>\n <goals>\n <goal>copy-dependencies</goal>\n </goals>\n <configuration>\n <outputDirectory>${project.build.directory}/lib</outputDirectory>\n </configuration>\n </execution>\n </executions>\n</plugin>\n package mvn clean package\n lib mvn clean package dependency:copy-dependencies\n ${project.build.directory}/dependencies outputDirectory -DoutputDirectory=${project.build.directory}/lib\n"
},
{
"answer_id": 70747872,
"author": "Times",
"author_id": 5151202,
"author_profile": "https://Stackoverflow.com/users/5151202",
"pm_score": 0,
"selected": false,
"text": "settings.xml <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<settings xmlns=\"http://maven.apache.org/SETTINGS/1.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd\">\n <localRepository>.m2/repository</localRepository>\n <interactiveMode/>\n <offline/>\n <pluginGroups/>\n <servers/>\n <mirrors/>\n <proxies/>\n <profiles/>\n <activeProfiles/>\n</settings>\n mvn -s settings.xml clean install\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97640",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18320/"
] |
97,646
|
<p>Given a source color of any hue by the system or user, I'd like a simple algorithm I can use to work out a lighter or darker variants of the selected color. Similar to effects used on Windows Live Messenger for styling the user interface.</p>
<p>Language is C# with .net 3.5.</p>
<p><strong>Responding to comment:</strong> Color format is (Alpha)RGB. With values as bytes or floats.</p>
<p><strong>Marking answer:</strong> For the context of my use (a few simple UI effects), the answer I'm marking as accepted is actually the most simple for this context. However, I've given up votes to the more complex and accurate answers too. Anyone doing more advanced color operations and finding this thread in future should definitely check those out. Thanks SO. :)</p>
|
[
{
"answer_id": 97697,
"author": "KPexEA",
"author_id": 13676,
"author_profile": "https://Stackoverflow.com/users/13676",
"pm_score": 4,
"selected": false,
"text": "void RGBToHSV(unsigned char cr, unsigned char cg, unsigned char cb,double *ph,double *ps,double *pv)\n{\ndouble r,g,b;\ndouble max, min, delta;\n\n/* convert RGB to [0,1] */\n\nr = (double)cr/255.0f;\ng = (double)cg/255.0f;\nb = (double)cb/255.0f;\n\nmax = MAXx(r,(MAXx(g,b)));\nmin = MINx(r,(MINx(g,b)));\n\npv[0] = max;\n\n/* Calculate saturation */\n\nif (max != 0.0)\n ps[0] = (max-min)/max;\nelse\n ps[0] = 0.0; \n\nif (ps[0] == 0.0)\n{\n ph[0] = 0.0f; //UNDEFINED;\n return;\n}\n/* chromatic case: Saturation is not 0, so determine hue */\ndelta = max-min;\n\nif (r==max)\n{\n ph[0] = (g-b)/delta;\n}\nelse if (g==max)\n{\n ph[0] = 2.0 + (b-r)/delta;\n}\nelse if (b==max)\n{\n ph[0] = 4.0 + (r-g)/delta;\n}\nph[0] = ph[0] * 60.0;\nif (ph[0] < 0.0)\n ph[0] += 360.0;\n}\n\nvoid HSVToRGB(double h,double s,double v,unsigned char *pr,unsigned char *pg,unsigned char *pb)\n{\nint i;\ndouble f, p, q, t;\ndouble r,g,b;\n\nif( s == 0 )\n{\n // achromatic (grey)\n r = g = b = v;\n}\nelse\n{\n h /= 60; // sector 0 to 5\n i = (int)floor( h );\n f = h - i; // factorial part of h\n p = v * ( 1 - s );\n q = v * ( 1 - s * f );\n t = v * ( 1 - s * ( 1 - f ) );\n switch( i )\n {\n case 0:\n r = v;\n g = t;\n b = p;\n break;\n case 1:\n r = q;\n g = v;\n b = p;\n break;\n case 2:\n r = p;\n g = v;\n b = t;\n break;\n case 3:\n r = p;\n g = q;\n b = v;\n break;\n case 4:\n r = t;\n g = p;\n b = v;\n break;\n default: // case 5:\n r = v;\n g = p;\n b = q;\n break;\n }\n}\nr*=255;\ng*=255;\nb*=255;\n\npr[0]=(unsigned char)r;\npg[0]=(unsigned char)g;\npb[0]=(unsigned char)b;\n}\n"
},
{
"answer_id": 97796,
"author": "DarenW",
"author_id": 10468,
"author_profile": "https://Stackoverflow.com/users/10468",
"pm_score": 3,
"selected": false,
"text": "f Rnew = (1-f)*R + f*255\nGnew = (1-f)*G + f*255\nBnew = (1-f)*B + f*255\n"
},
{
"answer_id": 214350,
"author": "GregUzelac",
"author_id": 27068,
"author_profile": "https://Stackoverflow.com/users/27068",
"pm_score": 3,
"selected": false,
"text": "ControlPaint.Dark() .Light() System.Windows.Forms"
},
{
"answer_id": 2690026,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 6,
"selected": false,
"text": "Color.Lerp Lerp float public static float Lerp( this float start, float end, float amount)\n{\n float difference = end - start;\n float adjusted = difference * amount;\n return start + adjusted;\n}\n public static Color Lerp(this Color colour, Color to, float amount)\n{\n // start colours as lerp-able floats\n float sr = colour.R, sg = colour.G, sb = colour.B;\n\n // end colours as lerp-able floats\n float er = to.R, eg = to.G, eb = to.B;\n\n // lerp the colours to get the difference\n byte r = (byte) sr.Lerp(er, amount),\n g = (byte) sg.Lerp(eg, amount),\n b = (byte) sb.Lerp(eb, amount);\n\n // return the new colour\n return Color.FromArgb(r, g, b);\n}\n // make red 50% lighter:\nColor.Red.Lerp( Color.White, 0.5f );\n\n// make red 75% darker:\nColor.Red.Lerp( Color.Black, 0.75f );\n\n// make white 10% bluer:\nColor.White.Lerp( Color.Blue, 0.1f );\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97646",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/483/"
] |
97,663
|
<p>Programming PHP in Eclipse PDT is predominately a joy: code completion, templates, method jumping, etc.</p>
<p>However, one thing that drives me crazy is that I can't get my lines in PHP files to word wrap so on long lines I'm typing out indefinitely to the right.</p>
<p>I click on Windows|Preferences and type in "wrap" and get:</p>
<pre><code>- Java | Code Style | Formatter
- Java | Editor | Typing
- Web and XML | CSS Files | Source
</code></pre>
<p>I've tried changing the "wrap automatically" that I found there and the "Line width" to 72 but they had no effect.</p>
<p>How can I get word wrap to work in Eclipse PDT for PHP files?</p>
|
[
{
"answer_id": 15783091,
"author": "Fedir RYKHTIK",
"author_id": 634275,
"author_profile": "https://Stackoverflow.com/users/634275",
"pm_score": 4,
"selected": false,
"text": "-clean"
},
{
"answer_id": 37103016,
"author": "KrisWebDev",
"author_id": 2227298,
"author_profile": "https://Stackoverflow.com/users/2227298",
"pm_score": 3,
"selected": false,
"text": "ADVANCED MODE Eclipse IDE for PHP Developers Latest Window Preferences General Editors Text Editors Enable Wordwrap org.eclipse.ui.editors.prefs find ~ -name org.eclipse.ui.editors.prefs -printf \"%p %TY-%Tm-%Td %TH:%TM:%TS\\n\" .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.editors.prefs wordwrap.enabled=true"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4639/"
] |
97,683
|
<p>Here is a snippet of CSS that I need explained:</p>
<pre class="lang-css prettyprint-override"><code>#section {
width: 860px;
background: url(/blah.png);
position: absolute;
top: 0;
left: 50%;
margin-left: -445px;
}
</code></pre>
<p>Ok so it's absolute positioning of an image, obviously.</p>
<ol>
<li>top is like padding from the top, right?</li>
<li>what does left 50% do?</li>
<li>why is the left margin at -445px? </li>
</ol>
<p><b>Update:</b>
width is 860px.
The actual image is 100x100 if that makes a difference??</p>
|
[
{
"answer_id": 97747,
"author": "pilsetnieks",
"author_id": 6615,
"author_profile": "https://Stackoverflow.com/users/6615",
"pm_score": 3,
"selected": true,
"text": "top: 50%\nmargin-top: -(height/2)px;\n"
},
{
"answer_id": 97761,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 2,
"selected": false,
"text": "position:absolute left:50% position:relative width"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97683",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1368/"
] |
97,694
|
<p>I've been somewhat spoiled using Eclipse and java. I started using vim to do C coding in a linux environment, is there a way to have vim automatically do the proper spacing for blocks? </p>
<p>So after typing a { the next line will have 2 spaces indented in, and a return on that line will keep it at the same indentation, and a } will shift back 2 spaces?</p>
|
[
{
"answer_id": 97723,
"author": "davr",
"author_id": 14569,
"author_profile": "https://Stackoverflow.com/users/14569",
"pm_score": 8,
"selected": true,
"text": ":set autoindent\n:set cindent\n"
},
{
"answer_id": 97775,
"author": "Commodore Jaeger",
"author_id": 4659,
"author_profile": "https://Stackoverflow.com/users/4659",
"pm_score": 6,
"selected": false,
"text": ":set cindent\n :set shiftwidth=2\n :set expandtab\n"
},
{
"answer_id": 98367,
"author": "rampion",
"author_id": 9859,
"author_profile": "https://Stackoverflow.com/users/9859",
"pm_score": 3,
"selected": false,
"text": "autoindent cindent ~/.vimrc $VIMRUNTIME/vimrc_example.vim :source $VIMRUNTIME/vimrc_example.vim\n ~/.vimrc :e $VIMRUNTIME/vimrc_example.vim\n:w! ~/.vimrc\n ~/.vimrc :help vimrc-intro"
},
{
"answer_id": 2657596,
"author": "JamesM-SiteGen",
"author_id": 407348,
"author_profile": "https://Stackoverflow.com/users/407348",
"pm_score": 3,
"selected": false,
"text": "user@host:~ $ echo set autoindent >> .vimrc\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97694",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9628/"
] |
97,732
|
<p>I have a certain page (we'll call it MyPage) that can be accessed from three different pages. In the Web.sitemap file, I tried to stuff the XML for this page under the three separate nodes like this:</p>
<p>< Page 1 ><br>
< MyPage / ><br>
...<br>
< /Page 1 ><br><br>
< Page 2 ><br>
< MyPage / ><br>
...<br>
< /Page 2 ><br><br>
< Page 3 ><br>
< MyPage / ><br>
...<br>
< /Page 3 ><br></p>
<p>In doing so I received the following error:</p>
<p>Multiple nodes with the same URL 'Default.aspx' were found.
XmlSiteMapProvider requires that sitemap nodes have unique URLs.</p>
<p>I read online that the SiteMapNodes are stored as a dictionary internally which explains why I can't use the same URL. In any case, I'm just looking for alternate ways to go about solving this problem. Any suggestions would be greatly appreciated.</p>
|
[
{
"answer_id": 202251,
"author": "Beaker",
"author_id": 8673,
"author_profile": "https://Stackoverflow.com/users/8673",
"pm_score": 0,
"selected": false,
"text": "<siteMapNode url=\"ListAll.aspx\">\n <siteMapNode url =\"Detail.aspx?node=all\" />\n</siteMapNode>\n<siteMapNode url=\"ListMine.aspx\">\n <siteMapNode url =\"Detail.aspx?node=mine\" />\n</siteMapNode>\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16830/"
] |
97,762
|
<p>I have a collection of non-overlapping rectangles that cover an enclosing rectangle. What is the best way to find the containing rectangle for a mouse click?</p>
<p>The obvious answer is to have an array of rectangles and to search them in sequence, making the search O(n). Is there some way to order them by position so that the algorithm is less than O(n), say, O(log n) or O(sqrt(n))?</p>
|
[
{
"answer_id": 97806,
"author": "Nils Pipenbrinck",
"author_id": 15955,
"author_profile": "https://Stackoverflow.com/users/15955",
"pm_score": 4,
"selected": true,
"text": " int id = bitmap_getpixel (mouse.x, mouse.y)\n if (id != -1)\n {\n hit_rectange (id);\n }\n else\n {\n no_hit();\n }\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97762",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10293/"
] |
97,781
|
<p>Part of a new product I have been assigned to work on involves server-side conversion of the 'common' video formats to something that Flash can play.</p>
<p>As far as I know, my only option is to convert to FLV. I have been giving ffmpeg a go around, but I'm finding a few WMV files that come out with garbled sound (I've tried playing with the audio rates).</p>
<p>Are there any other 'good' CLI converters for Linux? Or are there other video formats that Flash can play?</p>
|
[
{
"answer_id": 97799,
"author": "Dark Shikari",
"author_id": 11206,
"author_profile": "https://Stackoverflow.com/users/11206",
"pm_score": 5,
"selected": true,
"text": "FLV with AAC or MP3 audio, and FLV1 (Sorenson Spark H.263), VP6, or H.264 video.\nMP4 with AAC or MP3 audio, and H.264 video (mp4s must be hinted with qt-faststart or mp4box).\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97781",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2192/"
] |
97,816
|
<p>I want to know if people here typically disable SELinux on installations where it is on by default? If so can you explain why, what kind of system it was, etc?</p>
<p>I'd like to get as many opinions on this as possible.</p>
|
[
{
"answer_id": 97881,
"author": "hoyhoy",
"author_id": 3499,
"author_profile": "https://Stackoverflow.com/users/3499",
"pm_score": 2,
"selected": false,
"text": "chcon -R -h -t httpd_sys_content_t /var/www/html \n"
},
{
"answer_id": 98219,
"author": "mike511",
"author_id": 9593,
"author_profile": "https://Stackoverflow.com/users/9593",
"pm_score": 1,
"selected": false,
"text": "/dev/sda* /var/log/messages"
},
{
"answer_id": 98238,
"author": "jtimberman",
"author_id": 7672,
"author_profile": "https://Stackoverflow.com/users/7672",
"pm_score": 3,
"selected": false,
"text": "sudo audit2allow -m \"${name}\" -i /var/log/audit/audit.log > ${name}.te\n /etc/selinux/local/${name}-setup.sh SOURCE=/etc/selinux/local\nBUILD=/etc/selinux/local\n\n/usr/bin/checkmodule -M -m -o ${BUILD}/${name}.mod ${SOURCE}/${name}.te\n/usr/bin/semodule_package -o ${BUILD}/${name}.pp -m ${BUILD}/${name}.mod\n/usr/sbin/semodule -i ${BUILD}/${name}.pp\n\n/bin/rm ${BUILD}/${name}.mod ${BUILD}/${name}.pp\n"
},
{
"answer_id": 102091,
"author": "Scott",
"author_id": 7399,
"author_profile": "https://Stackoverflow.com/users/7399",
"pm_score": -1,
"selected": false,
"text": "/etc/sysconfig/selinux SELINIX=disabled selinux=0 noselinux"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12098/"
] |
97,850
|
<p>For my school work, I do a lot of switching computers (from labs to my laptop to the library). I'd kind of like to put this code under some kind of version control. Of course the problem is that I can't always install additional software on the computers I use. Is there any kind of version control system that I can keep on a thumb drive? I have a 2GB drive to put this on, but I can get a bigger one if necessary.</p>
<p>The projects I'm doing aren't especially big FYI.</p>
<p><strong>EDIT:</strong> This needs to work under windows.</p>
<p><strong>EDIT II:</strong> Bazaar ended up being what I chose. It's even better if you go with TortoiseBzr.</p>
|
[
{
"answer_id": 97922,
"author": "Milan Babuškov",
"author_id": 14690,
"author_profile": "https://Stackoverflow.com/users/14690",
"pm_score": 4,
"selected": false,
"text": "git-init\ngit add .\ngit commit -m \"Done\"\n git-clone --bare /path/to/my/dir\n git-clone /path/to/stick/repos\n"
},
{
"answer_id": 97955,
"author": "Jonny Buchanan",
"author_id": 6760,
"author_profile": "https://Stackoverflow.com/users/6760",
"pm_score": 4,
"selected": false,
"text": "darcs init\ndarcs add -r *\ndarcs record -am \"Initial commit\"\n darcs get E:\\path\\to\\repos\n darcs whatsnew # Show all changed hunks of code\ndarcs whatsnew -ls # List all modified & new files\n darcs record\n darcs push\n darcs get http://example.com/repos/forum/\n# Make changes and record patches\ndarcs send -o C:\\changes.patch\n"
},
{
"answer_id": 98143,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 2,
"selected": false,
"text": "RCS ci -u $FILE rcs -i -kb $FILE RCS ,v"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97850",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] |
97,875
|
<p>I need a way to recursively delete a folder and its children.</p>
<p>Is there a prebuilt tool for this, or do I need to write one?</p>
<p><code>DEL /S</code> doesn't delete directories.</p>
<p><code>DELTREE</code> was removed from Windows 2000+</p>
|
[
{
"answer_id": 97895,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 3,
"selected": false,
"text": "del /s foldername\n"
},
{
"answer_id": 97896,
"author": "Duncan Smart",
"author_id": 1278,
"author_profile": "https://Stackoverflow.com/users/1278",
"pm_score": 11,
"selected": true,
"text": "rd /s /q \"path\"\n Remove-Item del erase rd ri rm rmdir -Recurse -r rd -r \"path\"\n"
},
{
"answer_id": 97900,
"author": "Branan",
"author_id": 13894,
"author_profile": "https://Stackoverflow.com/users/13894",
"pm_score": 3,
"selected": false,
"text": "rmdir /S /Q %DIRNAME%"
},
{
"answer_id": 97911,
"author": "Jim McKeeth",
"author_id": 255,
"author_profile": "https://Stackoverflow.com/users/255",
"pm_score": 7,
"selected": false,
"text": "RMDIR [/S] [/Q] [drive:]path RD [/S] [/Q] [drive:]path /S /Q /S"
},
{
"answer_id": 97924,
"author": "user17481",
"author_id": 17481,
"author_profile": "https://Stackoverflow.com/users/17481",
"pm_score": 4,
"selected": false,
"text": "rm ls"
},
{
"answer_id": 98069,
"author": "wbkang",
"author_id": 2710,
"author_profile": "https://Stackoverflow.com/users/2710",
"pm_score": 7,
"selected": false,
"text": "takeown /r /f folder\ncacls folder /c /G \"ADMINNAME\":F /T\nrmdir /s folder\n mkdir \\empty\nrobocopy /mir \\empty folder\n"
},
{
"answer_id": 12255881,
"author": "Louis",
"author_id": 1644882,
"author_profile": "https://Stackoverflow.com/users/1644882",
"pm_score": 2,
"selected": false,
"text": "RMDIR /S %1 Remove.bat C:\\windows HKEY_CLASSES_ROOT\\Directory\\shell\\Remove Directory (RMDIR) regedit HKEY_CLASSES_ROOT\\Directory\\shell\\Remove Directory (RMDIR)\\default \"c:\\windows\\REMOVE.bat\" \"%1\""
},
{
"answer_id": 29779439,
"author": "binki",
"author_id": 429091,
"author_profile": "https://Stackoverflow.com/users/429091",
"pm_score": 2,
"selected": false,
"text": "rm -rf C:\\Users\\ohnob\\things>touch stuff.txt\n\nC:\\Users\\ohnob\\things>rm -rf stuff.txt\n\nC:\\Users\\ohnob\\things>mkdir stuff.txt\n\nC:\\Users\\ohnob\\things>rm -rf stuff.txt\n\nC:\\Users\\ohnob\\things>ls -l\ntotal 0\n\nC:\\Users\\ohnob\\things>rm -rf stuff.txt\n rm -rf 0 ERRORLEVEL IF EXIST ERRORLEVEL ERRORLEVEL rm -rf RD IF EXIST RD rm -f SET DELPATH=%1 ECHO %1 .cmd IF ERRORLEVEL 1 : # Determine whether we need to invoke DEL or RD or do nothing.\nSET DELPATH_DELMETHOD=RD\nPUSHD %DELPATH% 2>NUL\nIF ERRORLEVEL 1 (SET DELPATH_DELMETHOD=DEL) ELSE (POPD)\nIF NOT EXIST %DELPATH% SET DELPATH_DELMETHOD=NOOP\n: # Reset ERRORLEVEL so that the last command which\n: # otherwise set it does not cause us to falsely detect\n: # failure.\nCMD /C EXIT 0\nIF %DELPATH_DELMETHOD%==DEL DEL /Q %DELPATH%\nIF %DELPATH_DELMETHOD%==RD RD /S /Q %DELPATH%\n"
},
{
"answer_id": 35731786,
"author": "Sireesh Yarlagadda",
"author_id": 2057902,
"author_profile": "https://Stackoverflow.com/users/2057902",
"pm_score": 5,
"selected": false,
"text": "rd /s /q \"FOLDER_NAME\"\n"
},
{
"answer_id": 37577718,
"author": "Clay",
"author_id": 444917,
"author_profile": "https://Stackoverflow.com/users/444917",
"pm_score": 4,
"selected": false,
"text": "if exist myfolder ( rmdir /s/q myfolder )\n"
},
{
"answer_id": 52144579,
"author": "gdenuf",
"author_id": 582398,
"author_profile": "https://Stackoverflow.com/users/582398",
"pm_score": 2,
"selected": false,
"text": " get-childitem *logs* -path .\\ -directory -recurse | remove-item -confirm:$false -recurse -force\n"
},
{
"answer_id": 53859156,
"author": "cilerler",
"author_id": 439130,
"author_profile": "https://Stackoverflow.com/users/439130",
"pm_score": 3,
"selected": false,
"text": " Remove-Item -Recurse -Force \"TestDirectory\"\n"
},
{
"answer_id": 54947647,
"author": "Artif3x",
"author_id": 2487033,
"author_profile": "https://Stackoverflow.com/users/2487033",
"pm_score": 4,
"selected": false,
"text": "yarn global add rimraf\n rimraf .\\**\\node_modules\n npx rimraf .\\**\\node_modules\n"
},
{
"answer_id": 56571474,
"author": "Roel Van de Paar",
"author_id": 1208218,
"author_profile": "https://Stackoverflow.com/users/1208218",
"pm_score": 2,
"selected": false,
"text": "rd -r -include *.* -force somedir\n somedir"
},
{
"answer_id": 61047316,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "rm -rf... npm config set script-shell \"C:\\Program Files\\Git\\bin\\bash.exe\" rm -rf rm styled-components rm rm"
},
{
"answer_id": 63745519,
"author": "stackprotector",
"author_id": 11942268,
"author_profile": "https://Stackoverflow.com/users/11942268",
"pm_score": 4,
"selected": false,
"text": "rm -r -fo <path>\n Remove-Item -Recurse -Force -Path <path>\n"
},
{
"answer_id": 68315523,
"author": "faester",
"author_id": 540968,
"author_profile": "https://Stackoverflow.com/users/540968",
"pm_score": 2,
"selected": false,
"text": "rm -recurse -force"
},
{
"answer_id": 68369398,
"author": "BananaAcid",
"author_id": 1644202,
"author_profile": "https://Stackoverflow.com/users/1644202",
"pm_score": 2,
"selected": false,
"text": "$ rm -rf ./path PS> rm -r -fo ./path Remove-Item ALIASE\n ri\n rm\n rmdir\n del\n erase\n rd\n"
},
{
"answer_id": 69406402,
"author": "jianyongli",
"author_id": 4046647,
"author_profile": "https://Stackoverflow.com/users/4046647",
"pm_score": 2,
"selected": false,
"text": "Remove-Item rm -R -Fo the_file\n Remove-Item -R -Fo the_file\n rm rm choco choco install GnuWin\n rm.exe -rf the_file\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97875",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1965/"
] |
97,913
|
<p>What are your best usability testing tips?
I need quick & cheap. </p>
|
[
{
"answer_id": 98664,
"author": "therealhoff",
"author_id": 18175,
"author_profile": "https://Stackoverflow.com/users/18175",
"pm_score": 3,
"selected": false,
"text": "The archetypal non-technical user, one's elderly and scatterbrained maiden aunt. Invoked in discussions of usability for people who are not hackers and geeks; one sees references to the “Aunt Tillie test”. Aunt Tilly Test"
},
{
"answer_id": 105815,
"author": "pcorcoran",
"author_id": 15992,
"author_profile": "https://Stackoverflow.com/users/15992",
"pm_score": 1,
"selected": false,
"text": "\"John spent 15 seconds looking at the screen before acting. He moused over the top nav to see if it contained popup menus. He first clicked \"About Us\" even though it wasn't central to his task.\""
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97913",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17398/"
] |
97,948
|
<p>What is <code>std::pair</code> for, why would I use it, and what benefits does <code>boost::compressed_pair</code> bring?</p>
|
[
{
"answer_id": 97968,
"author": "John Mulder",
"author_id": 2242,
"author_profile": "https://Stackoverflow.com/users/2242",
"pm_score": 2,
"selected": false,
"text": "std::map<>\nstd::multimap<> \n"
},
{
"answer_id": 97973,
"author": "user17481",
"author_id": 17481,
"author_profile": "https://Stackoverflow.com/users/17481",
"pm_score": 2,
"selected": false,
"text": "std::map::insert boost::compressed_pair"
},
{
"answer_id": 98022,
"author": "jwfearn",
"author_id": 10559,
"author_profile": "https://Stackoverflow.com/users/10559",
"pm_score": 6,
"selected": true,
"text": "std::pair std::map pair tuple pair tuple"
},
{
"answer_id": 573457,
"author": "Logan Capaldo",
"author_id": 61289,
"author_profile": "https://Stackoverflow.com/users/61289",
"pm_score": 6,
"selected": false,
"text": "compressed_pair struct A { };\n A A a1;\nA a2;\n&a1 == &a2;\n struct A { };\nstruct B { int x; };\nstruct C : public A { int x; };\n B C sizeof(A) boost::compressed_pair std::pair template<typename FirstType, typename SecondType>\nstruct pair {\n FirstType first;\n SecondType second;\n};\n FirstType SecondType A pair<A, int> sizeof(int) compressed_pair struct compressed_pair<A,int> : private A {\n int second_;\n A first() { return *this; }\n int second() { return second_; }\n };\n compressed_pair<A,int>"
},
{
"answer_id": 573582,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 4,
"selected": false,
"text": "boost::function<void(int)> f(boost::bind(&f, _1));\n _1 std::pair sizeof(&f) + sizeof(_1) boost::function boost::function compressed_pair"
},
{
"answer_id": 2124394,
"author": "mloskot",
"author_id": 151641,
"author_profile": "https://Stackoverflow.com/users/151641",
"pm_score": 2,
"selected": false,
"text": "std::pair std::pair<iterator, iterator>"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97948",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18352/"
] |
97,962
|
<p>A poorly-written back-end system we interface with is having trouble with handling the load we're producing. While they fix their load problems, we're trying to reduce any additional load we're generating, one of which is that the back-end system continues to try and service a form submission even if another submission has come from the same user.</p>
<p>One thing we've noticed is users double-clicking the form submission button. I need to de-bounce these clicks, and prevent a second form submission.<br>
My approach (using Prototype) places an <code>onSubmit</code> on the form that calls the following function which hides the form submission button and displays a "loading..." <code>div</code>.</p>
<pre><code>function disableSubmit(id1, id2) {
$(id1).style.display = 'none';
$(id2).style.display = 'inline';
}
</code></pre>
<p>The problem I've found with this approach is that if I use an animated gif in the "loading..." <code>div</code>, it loads fine but doesn't animate while the form is submitting.</p>
<p>Is there a better way to do this de-bouncing and continue to show animation on the page while waiting for the form result to (finally) load?
</p>
|
[
{
"answer_id": 99366,
"author": "matt lohkamp",
"author_id": 14026,
"author_profile": "https://Stackoverflow.com/users/14026",
"pm_score": 3,
"selected": true,
"text": "$('input[type=\"submit\"]').click(function(event){\n event.preventDefault();\n this.click(null);\n});\n"
},
{
"answer_id": 142983,
"author": "Fczbkk",
"author_id": 22920,
"author_profile": "https://Stackoverflow.com/users/22920",
"pm_score": 3,
"selected": false,
"text": "document.observe( 'dom:loaded', function() { // when document is loaded\n $$( 'form' ).each( function( form ) { // find all FORM elements in the document\n form.observe( 'submit', function() { // when any form is submitted\n $$( 'input[type=\"submit\"]' ).invoke( 'disable' ); // disable all submit buttons\n } );\n } );\n} );\n document.observe( 'dom:loaded', function() {\n $$( 'form' ).each( function( form ) {\n form.observe( 'submit', function() {\n $$( 'input[type=\"submit\"]' ).invoke( 'disable' );\n $$( 'form' ).observe( 'submit', function( evt ) { // once any form is submitted\n evt.stop(); // prevent any other form submission\n } );\n } );\n } );\n} );\n"
},
{
"answer_id": 667104,
"author": "unscriptable",
"author_id": 80593,
"author_profile": "https://Stackoverflow.com/users/80593",
"pm_score": 2,
"selected": false,
"text": "var debounce = function (func, threshold, execAsap) {\n\n var timeout;\n\n return function debounced () {\n var obj = this, args = arguments;\n function delayed () {\n if (!execAsap)\n func.apply(obj, args);\n timeout = null; \n };\n\n if (timeout)\n clearTimeout(timeout);\n else if (execAsap)\n func.apply(obj, args);\n\n timeout = setTimeout(delayed, threshold || 100); \n };\n\n}\n"
},
{
"answer_id": 73077049,
"author": "Bhola Kr. Khawas",
"author_id": 9985883,
"author_profile": "https://Stackoverflow.com/users/9985883",
"pm_score": 0,
"selected": false,
"text": "<i class=\"spinner hidden fa fa-spinner fa-spin\" style=\"margin-right: 2px\"></i>\n $('.prevent-mult-submit-form').on('submit', function(){\n $('.disable-mult-click').attr('disabled', true)\n $('.spinner').removeClass('hidden')\n })\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97962",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10788/"
] |
97,971
|
<p>Having programmed through emacs and vi for years and years at this point, I have heard that using an IDE is a very good way of becoming more efficient.</p>
<p>To that end, I have decided to try using Eclipse for a lot of coding and seeing how I get on.</p>
<p>Are there any suggestions for easing the transition over to an IDE. Obviously, some will think none of this is worth the bother, but I think with Eclipse allowing emacs-style key bindings and having code completion and in-built debugging, I reckon it is well worth trying to move over to a more feature-rich environment for the bulk of my development worth.</p>
<p>So what suggestions do you have for easing the transition?</p>
|
[
{
"answer_id": 98151,
"author": "Desty",
"author_id": 2161072,
"author_profile": "https://Stackoverflow.com/users/2161072",
"pm_score": 3,
"selected": true,
"text": "String messageXml = in.read();\nMessage response = messageParser.parse(messageXml);\nreturn response; return messageParser.parse(in.read());\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97971",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/277/"
] |
97,976
|
<p>I have a datagridview that accepts a list(of myObject) as a datasource. I want to add a new row to the datagrid to add to the database. I get this done by getting the list... adding a blank myObject to the list and then reseting the datasource. I now want to set the focus to the second cell in the new row.</p>
<p>To CLARIFY i am trying to set the focus</p>
|
[
{
"answer_id": 97986,
"author": "ine",
"author_id": 4965,
"author_profile": "https://Stackoverflow.com/users/4965",
"pm_score": 0,
"selected": false,
"text": "Me.dataEvidence.SelectedRows\n"
},
{
"answer_id": 1213548,
"author": "Michael Todd",
"author_id": 16623,
"author_profile": "https://Stackoverflow.com/users/16623",
"pm_score": 3,
"selected": true,
"text": "dataGridView.Rows[rowNumber].Cells[columnNumber].Selected = true;\n"
},
{
"answer_id": 18220884,
"author": "Elias",
"author_id": 2414458,
"author_profile": "https://Stackoverflow.com/users/2414458",
"pm_score": 0,
"selected": false,
"text": "Sub Whatever()\n\n ' all above code\n\n DataGridView1.Focus()\n DataGridView1.CurrentCell = DataGridView1.Rows(x).Cells(y) 'x is your desired row number, y is your desired column number\n\n ' all below code\n\nEnd Sub\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97976",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16820/"
] |
97,982
|
<p>A Google search for "site:example.com" will tell you the number of pages of example.com that are currently in Google's index. Is it possible to find out how this number has changed over time?</p>
|
[
{
"answer_id": 172539,
"author": "Peter Boughton",
"author_id": 9360,
"author_profile": "https://Stackoverflow.com/users/9360",
"pm_score": 0,
"selected": false,
"text": "\\d+(?=</b> from <b>domain\\.net</b>)\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18333/"
] |
97,984
|
<p>When a PHP application makes a database connection it of course generally needs to pass a login and password. If I'm using a single, minimum-permission login for my application, then the PHP needs to know that login and password somewhere. What is the best way to secure that password? It seems like just writing it in the PHP code isn't a good idea.</p>
|
[
{
"answer_id": 98120,
"author": "Jim",
"author_id": 8427,
"author_profile": "https://Stackoverflow.com/users/8427",
"pm_score": 3,
"selected": false,
"text": "~/.pgpass"
},
{
"answer_id": 101696,
"author": "e-satis",
"author_id": 9951,
"author_profile": "https://Stackoverflow.com/users/9951",
"pm_score": 2,
"selected": false,
"text": "<?php exit() ?>\n\n[...]\n\nPlain text data including password\n"
},
{
"answer_id": 104790,
"author": "Bob Fanger",
"author_id": 19165,
"author_profile": "https://Stackoverflow.com/users/19165",
"pm_score": 4,
"selected": false,
"text": "mysql_connect(\"localhost\", \"me\", \"mypass\");\n include(\"/outside-webroot/db_settings.php\"); \nmysql_connect(\"localhost\", $db_user, $db_pass); \nunset ($db_user, $db_pass); \n"
},
{
"answer_id": 1223883,
"author": "kellen",
"author_id": 94671,
"author_profile": "https://Stackoverflow.com/users/94671",
"pm_score": 7,
"selected": false,
"text": "<files mypasswdfile>\norder allow,deny\ndeny from all\n</files>\n"
},
{
"answer_id": 10176831,
"author": "Lars Nyström",
"author_id": 1227116,
"author_profile": "https://Stackoverflow.com/users/1227116",
"pm_score": 6,
"selected": false,
"text": "php_value mysql.default.user myusername\nphp_value mysql.default.password mypassword\nphp_value mysql.default.host server\n <?php\n$db = mysqli_connect();\n <?php\n$db = mysqli_connect(ini_get(\"mysql.default.user\"),\n ini_get(\"mysql.default.password\"),\n ini_get(\"mysql.default.host\"));\n"
},
{
"answer_id": 42239784,
"author": "Courtney Miles",
"author_id": 2045006,
"author_profile": "https://Stackoverflow.com/users/2045006",
"pm_score": 3,
"selected": false,
"text": "phpinfo()"
},
{
"answer_id": 65475916,
"author": "Bruno Guignard",
"author_id": 10313805,
"author_profile": "https://Stackoverflow.com/users/10313805",
"pm_score": 0,
"selected": false,
"text": "$_ENV['MYVAR'] = $myvar echo $_ENV[\"MYVAR\"] putenv(\"MYVAR=$myvar\"); getenv('MYVAR'); php envvars.php symfony var:set FOO=bar --env-level"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97984",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18359/"
] |
97,987
|
<p>What's the best practice for using a <code>switch</code> statement vs using an <code>if</code> statement for 30 <code>unsigned</code> enumerations where about 10 have an expected action (that presently is the same action). Performance and space need to be considered but are not critical. I've abstracted the snippet so don't hate me for the naming conventions.</p>
<p><code>switch</code> statement:</p>
<pre><code>// numError is an error enumeration type, with 0 being the non-error case
// fire_special_event() is a stub method for the shared processing
switch (numError)
{
case ERROR_01 : // intentional fall-through
case ERROR_07 : // intentional fall-through
case ERROR_0A : // intentional fall-through
case ERROR_10 : // intentional fall-through
case ERROR_15 : // intentional fall-through
case ERROR_16 : // intentional fall-through
case ERROR_20 :
{
fire_special_event();
}
break;
default:
{
// error codes that require no additional action
}
break;
}
</code></pre>
<p><code>if</code> statement:</p>
<pre><code>if ((ERROR_01 == numError) ||
(ERROR_07 == numError) ||
(ERROR_0A == numError) ||
(ERROR_10 == numError) ||
(ERROR_15 == numError) ||
(ERROR_16 == numError) ||
(ERROR_20 == numError))
{
fire_special_event();
}
</code></pre>
|
[
{
"answer_id": 98011,
"author": "William Keller",
"author_id": 17095,
"author_profile": "https://Stackoverflow.com/users/17095",
"pm_score": 0,
"selected": false,
"text": "if"
},
{
"answer_id": 98036,
"author": "Jay Bazuzi",
"author_id": 5314,
"author_profile": "https://Stackoverflow.com/users/5314",
"pm_score": 1,
"selected": false,
"text": "if == !="
},
{
"answer_id": 98052,
"author": "lewis",
"author_id": 14442,
"author_profile": "https://Stackoverflow.com/users/14442",
"pm_score": 0,
"selected": false,
"text": "switch(numerror){\n ERROR_20 : { fire_special_event(); } break;\n default : { null; } break;\n}\n"
},
{
"answer_id": 103332,
"author": "paercebal",
"author_id": 14089,
"author_profile": "https://Stackoverflow.com/users/14089",
"pm_score": 5,
"selected": false,
"text": "// WON'T COMPILE\nextern const int MY_VALUE ;\n\nvoid doSomething(const int p_iValue)\n{\n switch(p_iValue)\n {\n case MY_VALUE : /* do something */ ; break ;\n default : /* do something else */ ; break ;\n }\n}\n // WILL COMPILE\nconst int MY_VALUE = 25 ;\n\nvoid doSomething(const int p_iValue)\n{\n switch(p_iValue)\n {\n case MY_VALUE : /* do something */ ; break ;\n default : /* do something else */ ; break ;\n }\n}\n"
},
{
"answer_id": 129515,
"author": "Mark Ransom",
"author_id": 5987,
"author_profile": "https://Stackoverflow.com/users/5987",
"pm_score": 6,
"selected": false,
"text": "if (RequiresSpecialEvent(numError))\n fire_special_event();\n bool RequiresSpecialEvent(int numError)\n{\n return specialSet.find(numError) != specialSet.end();\n}\n"
},
{
"answer_id": 129860,
"author": "mbac32768",
"author_id": 18446,
"author_profile": "https://Stackoverflow.com/users/18446",
"pm_score": 1,
"selected": false,
"text": "unsigned int special_events[] = {\n ERROR_01,\n ERROR_07,\n ERROR_0A,\n ERROR_10,\n ERROR_15,\n ERROR_16,\n ERROR_20\n };\n int special_events_length = sizeof (special_events) / sizeof (unsigned int);\n\n void process_event(unsigned int numError) {\n for (int i = 0; i < special_events_length; i++) {\n if (numError == special_events[i]) {\n fire_special_event();\n break;\n }\n }\n }\n special_events = [\n ERROR_01,\n ERROR_07,\n ERROR_0A,\n ERROR_10,\n ERROR_15,\n ERROR_16,\n ERROR_20,\n ]\ndef process_event(numError):\n if numError in special_events:\n fire_special_event()\n"
},
{
"answer_id": 1783241,
"author": "McAnix",
"author_id": 190401,
"author_profile": "https://Stackoverflow.com/users/190401",
"pm_score": 0,
"selected": false,
"text": "public class SwitchTest {\nstatic final int max = 100000;\n\npublic static void main(String[] args) {\n\nint counter1 = 0;\nlong start1 = 0l;\nlong total1 = 0l;\n\nint counter2 = 0;\nlong start2 = 0l;\nlong total2 = 0l;\nboolean loop = true;\n\nstart1 = System.currentTimeMillis();\nwhile (true) {\n if (counter1 == max) {\n break;\n } else {\n counter1++;\n }\n}\ntotal1 = System.currentTimeMillis() - start1;\n\nstart2 = System.currentTimeMillis();\nwhile (loop) {\n switch (counter2) {\n case max:\n loop = false;\n break;\n default:\n counter2++;\n }\n}\ntotal2 = System.currentTimeMillis() - start2;\n\nSystem.out.println(\"While if/else: \" + total1 + \"ms\");\nSystem.out.println(\"Switch: \" + total2 + \"ms\");\nSystem.out.println(\"Max Loops: \" + max);\n\nSystem.exit(0);\n}\n}\n"
},
{
"answer_id": 3834930,
"author": "MarioFrost",
"author_id": 463312,
"author_profile": "https://Stackoverflow.com/users/463312",
"pm_score": 1,
"selected": false,
"text": "while (true) != while (loop)\n"
},
{
"answer_id": 32356125,
"author": "Peter Cordes",
"author_id": 224132,
"author_profile": "https://Stackoverflow.com/users/224132",
"pm_score": 3,
"selected": false,
"text": "switch if case switch if errhandler_switch(errtype): # gcc 5.2 -O3\n cmpl $32, %edi\n ja .L5\n movabsq $4301325442, %rax # highest set bit is bit 32 (the 33rd bit)\n btq %rdi, %rax\n jc .L10\n.L5:\n rep ret\n.L10:\n jmp fire_special_event()\n switch 1U<<errNumber if errhandler_switch(errtype): # gcc 4.9.2 -O3\n leal -1(%rdi), %ecx\n cmpl $31, %ecx # cmpl $32, %edi wouldn't have to wait an extra cycle for lea's output.\n # However, register read ports are limited on pre-SnB Intel\n ja .L5\n movl $1, %eax\n salq %cl, %rax # with -march=haswell, it will use BMI's shlx to avoid moving the shift count into ecx\n testl $2150662721, %eax\n jne .L10\n.L5:\n rep ret\n.L10:\n jmp fire_special_event()\n errNumber lea movabsq cmpl $32, %edi\n ja .L5\n mov $2150662721, %eax\n dec %edi # movabsq and btq is fewer instructions / fewer Intel uops, but this saves several bytes\n bt %edi, %eax\n jc fire_special_event\n.L5:\n ret\n jc fire_special_event rep ret bt errNumber test bt"
},
{
"answer_id": 42406571,
"author": "Jordan Effinger",
"author_id": 7455487,
"author_profile": "https://Stackoverflow.com/users/7455487",
"pm_score": 0,
"selected": false,
"text": "`int a;\n cout<<\"enter value:\\n\";\n cin>>a;\n\n if( a > 0 && a < 5)\n {\n cout<<\"a is between 0, 5\\n\";\n\n }else if(a > 5 && a < 10)\n\n cout<<\"a is between 5,10\\n\";\n\n }else{\n\n \"a is not an integer, or is not in range 0,10\\n\";\n `int a;\n cout<<\"enter value:\\n\";\n cin>>a;\n\n switch(a)\n {\n case 0:\n case 1:\n case 2: \n case 3:\n case 4:\n case 5:\n cout<<\"a is between 0,5 and equals: \"<<a<<\"\\n\";\n break;\n //other case statements\n default:\n cout<<\"a is not between the range or is not a good value\\n\"\n break;\n"
},
{
"answer_id": 66429462,
"author": "Kai Petzke",
"author_id": 2528436,
"author_profile": "https://Stackoverflow.com/users/2528436",
"pm_score": 3,
"selected": false,
"text": "switch if switch (numError) { case ERROR_A: case ERROR_B: ... }\n if(numError == ERROR_A || numError == ERROR_B || ...) { ... }\n template<typename C, typename EL>\nbool has(const C& cont, const EL& el) {\n return std::find(cont.begin(), cont.end(), el) != cont.end();\n}\n\nconstexpr std::array errList = { ERROR_A, ERROR_B, ... };\nif(has(errList, rnd)) { ... }\n has() clang++ -O3 -std=c++1z g++ -O3 -std=c++1z functionA() if functionB() switch clang functionC() switch clang functionC() functionA() functionB() functionH() clang clang functionH() functionA() functionB() functionA() functionB() adc functionH() g++ clang functionA() functionC() functionC() g++ clang functionH() g++ clang g++ clang:\nfunctionA: 109877 3627\nfunctionB: 109877 3626\nfunctionC: 109877 4192\nfunctionH: 109877 524\n\ng++:\nfunctionA: 109877 3337\nfunctionB: 109877 4668\nfunctionC: 109877 2890\nfunctionH: 109877 982\n 32 63 clang:\nfunctionA: 106943 1435\nfunctionB: 106943 1436\nfunctionC: 106943 4191\nfunctionH: 106943 524\n\ng++:\nfunctionA: 106943 1265\nfunctionB: 106943 4481\nfunctionC: 106943 2804\nfunctionH: 106943 1038\n rnd functionA() if() g++ functionH() switch if clang array g++ #include <iostream>\n#include <chrono>\n#include <limits>\n#include <array>\n#include <algorithm>\n\nunsigned long long functionA() {\n unsigned long long cnt = 0;\n\n for(unsigned long long i = 0; i < 1000000; i++) {\n unsigned char rnd = (((i * (i >> 3)) >> 8) ^ i) & 63;\n if(rnd == 1 || rnd == 7 || rnd == 10 || rnd == 16 ||\n rnd == 21 || rnd == 22 || rnd == 63)\n {\n cnt += 1;\n }\n }\n\n return cnt;\n}\n\nunsigned long long functionB() {\n unsigned long long cnt = 0;\n\n for(unsigned long long i = 0; i < 1000000; i++) {\n unsigned char rnd = (((i * (i >> 3)) >> 8) ^ i) & 63;\n switch(rnd) {\n case 1:\n case 7:\n case 10:\n case 16:\n case 21:\n case 22:\n case 63:\n cnt++;\n break;\n }\n }\n\n return cnt;\n}\n\ntemplate<typename C, typename EL>\nbool has(const C& cont, const EL& el) {\n return std::find(cont.begin(), cont.end(), el) != cont.end();\n}\n\nunsigned long long functionC() {\n unsigned long long cnt = 0;\n constexpr std::array errList { 1, 7, 10, 16, 21, 22, 63 };\n\n for(unsigned long long i = 0; i < 1000000; i++) {\n unsigned char rnd = (((i * (i >> 3)) >> 8) ^ i) & 63;\n cnt += has(errList, rnd);\n }\n\n return cnt;\n}\n\n// Hand optimized version (manually created bitfield):\nunsigned long long functionH() {\n unsigned long long cnt = 0;\n\n const unsigned long long bitfield =\n (1ULL << 1) +\n (1ULL << 7) +\n (1ULL << 10) +\n (1ULL << 16) +\n (1ULL << 21) +\n (1ULL << 22) +\n (1ULL << 63);\n\n for(unsigned long long i = 0; i < 1000000; i++) {\n unsigned char rnd = (((i * (i >> 3)) >> 8) ^ i) & 63;\n if(bitfield & (1ULL << rnd)) {\n cnt += 1;\n }\n }\n\n return cnt;\n}\n\nvoid timeit(unsigned long long (*function)(), const char* message)\n{\n unsigned long long mintime = std::numeric_limits<unsigned long long>::max();\n unsigned long long fres = 0;\n\n for(int i = 0; i < 100; i++) {\n auto t1 = std::chrono::high_resolution_clock::now();\n fres = function();\n auto t2 = std::chrono::high_resolution_clock::now();\n\n auto duration = std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();\n if(duration < mintime) {\n mintime = duration;\n }\n }\n\n std::cout << message << fres << \" \" << mintime << std::endl;\n}\n\n\nint main(int argc, char* argv[]) {\n timeit(functionA, \"functionA: \");\n timeit(functionB, \"functionB: \");\n timeit(functionC, \"functionC: \");\n timeit(functionH, \"functionH: \");\n timeit(functionA, \"functionA: \");\n timeit(functionB, \"functionB: \");\n timeit(functionC, \"functionC: \");\n timeit(functionH, \"functionH: \");\n timeit(functionA, \"functionA: \");\n timeit(functionB, \"functionB: \");\n timeit(functionC, \"functionC: \");\n timeit(functionH, \"functionH: \");\n\n return 0;\n}\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/97987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8883/"
] |
98,033
|
<p>Several Linq.Enumerable functions take an <code>IEqualityComparer<T></code>. Is there a convenient wrapper class that adapts a <code>delegate(T,T)=>bool</code> to implement <code>IEqualityComparer<T></code>? It's easy enough to write one (if your ignore problems with defining a correct hashcode), but I'd like to know if there is an out-of-the-box solution.</p>
<p>Specifically, I want to do set operations on <code>Dictionary</code>s, using only the Keys to define membership (while retaining the values according to different rules).</p>
|
[
{
"answer_id": 98119,
"author": "aku",
"author_id": 1196,
"author_profile": "https://Stackoverflow.com/users/1196",
"pm_score": 6,
"selected": false,
"text": "class Comparer<T>: IEqualityComparer<T>\n{\n private readonly Func<T, T, bool> _comparer;\n\n public Comparer(Func<T, T, bool> comparer)\n {\n if (comparer == null)\n throw new ArgumentNullException(\"comparer\");\n\n _comparer = comparer;\n }\n\n public bool Equals(T x, T y)\n {\n return _comparer(x, y);\n }\n\n public int GetHashCode(T obj)\n {\n return obj.ToString().ToLower().GetHashCode();\n }\n}\n\n...\n\nFunc<int, int, bool> f = (x, y) => x == y;\nvar comparer = new Comparer<int>(f);\nConsole.WriteLine(comparer.Equals(1, 1));\nConsole.WriteLine(comparer.Equals(1, 2));\n"
},
{
"answer_id": 98138,
"author": "Gregg",
"author_id": 18266,
"author_profile": "https://Stackoverflow.com/users/18266",
"pm_score": -1,
"selected": false,
"text": "public class MyComparer<T> : IEqualityComparer<T>\n{\n private Func<T, T, bool> _compare;\n MyComparer(Func<T, T, bool> compare)\n {\n _compare = compare;\n }\n\n public bool Equals(T x, Ty)\n {\n return _compare(x, y);\n }\n\n public int GetHashCode(T obj)\n {\n return obj.GetHashCode();\n }\n}\n"
},
{
"answer_id": 270203,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "public class FuncEqualityComparer<T> : IEqualityComparer<T>\n{\n readonly Func<T, T, bool> _comparer;\n readonly Func<T, int> _hash;\n\n public FuncEqualityComparer( Func<T, T, bool> comparer )\n : this( comparer, t => t.GetHashCode())\n {\n }\n\n public FuncEqualityComparer( Func<T, T, bool> comparer, Func<T, int> hash )\n {\n _comparer = comparer;\n _hash = hash;\n }\n\n public bool Equals( T x, T y )\n {\n return _comparer( x, y );\n }\n\n public int GetHashCode( T obj )\n {\n return _hash( obj );\n }\n}\n public static class SequenceExtensions\n{\n public static bool SequenceEqual<T>( this IEnumerable<T> first, IEnumerable<T> second, Func<T, T, bool> comparer )\n {\n return first.SequenceEqual( second, new FuncEqualityComparer<T>( comparer ) );\n }\n\n public static bool SequenceEqual<T>( this IEnumerable<T> first, IEnumerable<T> second, Func<T, T, bool> comparer, Func<T, int> hash )\n {\n return first.SequenceEqual( second, new FuncEqualityComparer<T>( comparer, hash ) );\n }\n}\n"
},
{
"answer_id": 1239337,
"author": "orip",
"author_id": 37020,
"author_profile": "https://Stackoverflow.com/users/37020",
"pm_score": 7,
"selected": false,
"text": "var foo = new List<string> { \"abc\", \"de\", \"DE\" };\n\n// case-insensitive distinct\nvar distinct = foo.Distinct(new KeyEqualityComparer<string>( x => x.ToLower() ) );\n KeyEqualityComparer public class KeyEqualityComparer<T> : IEqualityComparer<T>\n{\n private readonly Func<T, object> keyExtractor;\n\n public KeyEqualityComparer(Func<T,object> keyExtractor)\n {\n this.keyExtractor = keyExtractor;\n }\n\n public bool Equals(T x, T y)\n {\n return this.keyExtractor(x).Equals(this.keyExtractor(y));\n }\n\n public int GetHashCode(T obj)\n {\n return this.keyExtractor(obj).GetHashCode();\n }\n}\n"
},
{
"answer_id": 3142096,
"author": "Sushil",
"author_id": 379132,
"author_profile": "https://Stackoverflow.com/users/379132",
"pm_score": 1,
"selected": false,
"text": "public class MyComparer<T> : IEqualityComparer<T> \n{ \n public bool Equals(T x, T y) \n { \n return EqualityComparer<T>.Default.Equals(x, y); \n } \n\n public int GetHashCode(T obj) \n { \n return obj.GetHashCode(); \n } \n} \n"
},
{
"answer_id": 3719617,
"author": "Ruben Bartelink",
"author_id": 11635,
"author_profile": "https://Stackoverflow.com/users/11635",
"pm_score": 7,
"selected": true,
"text": "class FuncEqualityComparer<T> : IEqualityComparer<T>\n{\n readonly Func<T, T, bool> _comparer;\n readonly Func<T, int> _hash;\n\n public FuncEqualityComparer( Func<T, T, bool> comparer )\n : this( comparer, t => 0 ) // NB Cannot assume anything about how e.g., t.GetHashCode() interacts with the comparer's behavior\n {\n }\n\n public FuncEqualityComparer( Func<T, T, bool> comparer, Func<T, int> hash )\n {\n _comparer = comparer;\n _hash = hash;\n }\n\n public bool Equals( T x, T y )\n {\n return _comparer( x, y );\n }\n\n public int GetHashCode( T obj )\n {\n return _hash( obj );\n }\n}\n"
},
{
"answer_id": 3719802,
"author": "Dan Tao",
"author_id": 105570,
"author_profile": "https://Stackoverflow.com/users/105570",
"pm_score": 7,
"selected": false,
"text": "GetHashCode IEqualityComparer<T> GetHashCode Distinct Equals Equals Distinct Distinct Equals GetHashCode IEqualityComparer<T> GetHashCode class Value\n{\n public string Name { get; private set; }\n public int Number { get; private set; }\n\n public Value(string name, int number)\n {\n Name = name;\n Number = number;\n }\n\n public override string ToString()\n {\n return string.Format(\"{0}: {1}\", Name, Number);\n }\n}\n List<Value> Distinct Comparer<T> var comparer = new Comparer<Value>((x, y) => x.Name == y.Name);\n Value Name Distinct var values = new List<Value>();\n\nvar random = new Random();\nfor (int i = 0; i < 10; ++i)\n{\n values.Add(\"x\", random.Next());\n}\n\nvar distinct = values.Distinct(comparer);\n\nforeach (Value x in distinct)\n{\n Console.WriteLine(x);\n}\n GroupBy var grouped = values.GroupBy(x => x, comparer);\n\nforeach (IGrouping<Value> g in grouped)\n{\n Console.WriteLine(\"[KEY: '{0}']\", g);\n foreach (Value x in g)\n {\n Console.WriteLine(x);\n }\n}\n Distinct HashSet<T> GroupBy Dictionary<TKey, List<T>> var uniqueValues = new HashSet<Value>(values, comparer);\n\nforeach (Value x in uniqueValues)\n{\n Console.WriteLine(x);\n}\n GetHashCode IEqualityComparer<T> Func<T, TKey> Func<T, object> keyExtractor where TKey : IEquatable<TKey> Equals object.Equals object IEquatable<TKey> TKey public class KeyEqualityComparer<T, TKey> : IEqualityComparer<T>\n{\n protected readonly Func<T, TKey> keyExtractor;\n\n public KeyEqualityComparer(Func<T, TKey> keyExtractor)\n {\n this.keyExtractor = keyExtractor;\n }\n\n public virtual bool Equals(T x, T y)\n {\n return this.keyExtractor(x).Equals(this.keyExtractor(y));\n }\n\n public int GetHashCode(T obj)\n {\n return this.keyExtractor(obj).GetHashCode();\n }\n}\n\npublic class StrictKeyEqualityComparer<T, TKey> : KeyEqualityComparer<T, TKey>\n where TKey : IEquatable<TKey>\n{\n public StrictKeyEqualityComparer(Func<T, TKey> keyExtractor)\n : base(keyExtractor)\n { }\n\n public override bool Equals(T x, T y)\n {\n // This will use the overload that accepts a TKey parameter\n // instead of an object parameter.\n return this.keyExtractor(x).Equals(this.keyExtractor(y));\n }\n}\n"
},
{
"answer_id": 6150492,
"author": "Bruno",
"author_id": 168043,
"author_profile": "https://Stackoverflow.com/users/168043",
"pm_score": 3,
"selected": false,
"text": "public static IEnumerable<T> Distinct<T>(this IEnumerable<T> list, Func<T, object> keyExtractor)\n{\n return list.Distinct(new KeyEqualityComparer<T>(keyExtractor));\n}\nvar distinct = foo.Distinct(x => x.ToLower())\n"
},
{
"answer_id": 6176711,
"author": "Max",
"author_id": 260093,
"author_profile": "https://Stackoverflow.com/users/260093",
"pm_score": 0,
"selected": false,
"text": "public static Dictionary<TKey, TValue> Distinct<TKey, TValue>(this IEnumerable<TValue> items, Func<TValue, TKey> selector)\n {\n Dictionary<TKey, TValue> result = null;\n ICollection collection = items as ICollection;\n if (collection != null)\n result = new Dictionary<TKey, TValue>(collection.Count);\n else\n result = new Dictionary<TKey, TValue>();\n foreach (TValue item in items)\n result[selector(item)] = item;\n return result;\n }\n .Select(y => y.Article).Distinct(x => x.ArticleID);"
},
{
"answer_id": 6913646,
"author": "ldp615",
"author_id": 285996,
"author_profile": "https://Stackoverflow.com/users/285996",
"pm_score": 5,
"selected": false,
"text": "EqualityComparer<>.Default struct IEquatable<> EqualityComparer<>.Default null.Equals(something) IEqualityComparer<> Equality<Person>.CreateComparer(p => p.ID);\n new EqualityComparer<Person, int>(p => p.ID);\n IEqualityComparer<> public static class Equality<T>\n{\n public static IEqualityComparer<T> CreateComparer<V>(Func<T, V> keySelector)\n {\n return CreateComparer(keySelector, null);\n }\n\n public static IEqualityComparer<T> CreateComparer<V>(Func<T, V> keySelector, \n IEqualityComparer<V> comparer)\n {\n return new KeyEqualityComparer<V>(keySelector, comparer);\n }\n\n class KeyEqualityComparer<V> : IEqualityComparer<T>\n {\n readonly Func<T, V> keySelector;\n readonly IEqualityComparer<V> comparer;\n\n public KeyEqualityComparer(Func<T, V> keySelector, \n IEqualityComparer<V> comparer)\n {\n if (keySelector == null)\n throw new ArgumentNullException(nameof(keySelector));\n\n this.keySelector = keySelector;\n this.comparer = comparer ?? EqualityComparer<V>.Default;\n }\n\n public bool Equals(T x, T y)\n {\n return comparer.Equals(keySelector(x), keySelector(y));\n }\n\n public int GetHashCode(T obj)\n {\n return comparer.GetHashCode(keySelector(obj));\n }\n }\n}\n var comparer1 = Equality<Person>.CreateComparer(p => p.ID);\nvar comparer2 = Equality<Person>.CreateComparer(p => p.Name);\nvar comparer3 = Equality<Person>.CreateComparer(p => p.Birthday.Year);\nvar comparer4 = Equality<Person>.CreateComparer(p => p.Name, StringComparer.CurrentCultureIgnoreCase);\n class Person\n{\n public int ID { get; set; }\n public string Name { get; set; }\n public DateTime Birthday { get; set; }\n}\n"
},
{
"answer_id": 10040172,
"author": "matrix",
"author_id": 1295274,
"author_profile": "https://Stackoverflow.com/users/1295274",
"pm_score": 1,
"selected": false,
"text": " public static class Comparer \n {\n public static IEqualityComparer<T> CreateComparerForElements<T>(this IEnumerable<T> enumerable, Func<T, object> keyExtractor)\n {\n return new KeyEqualityComparer<T>(keyExtractor);\n }\n }\n var n = ItemList.Select(s => new { s.Vchr, s.Id, s.Ctr, s.Vendor, s.Description, s.Invoice }).ToList();\nn.AddRange(OtherList.Select(s => new { s.Vchr, s.Id, s.Ctr, s.Vendor, s.Description, s.Invoice }).ToList(););\nn = n.Distinct(x=>new{Vchr=x.Vchr,Id=x.Id}).ToList();\n"
},
{
"answer_id": 17379690,
"author": "Fried",
"author_id": 2534462,
"author_profile": "https://Stackoverflow.com/users/2534462",
"pm_score": 2,
"selected": false,
"text": "persons1.Union(persons2, person => person.LastName)\n public class LambdaEqualityComparer<TSource, TComparable> : IEqualityComparer<TSource>\n{\n Func<TSource, TComparable> _keyGetter;\n \n public LambdaEqualityComparer(Func<TSource, TComparable> keyGetter)\n {\n _keyGetter = keyGetter;\n }\n \n public bool Equals(TSource x, TSource y)\n {\n if (x == null || y == null) return (x == null && y == null);\n return object.Equals(_keyGetter(x), _keyGetter(y));\n }\n \n public int GetHashCode(TSource obj)\n {\n if (obj == null) return int.MinValue;\n var k = _keyGetter(obj);\n if (k == null) return int.MaxValue;\n return k.GetHashCode();\n }\n}\n public static class LambdaEqualityComparer\n{\n // source1.Union(source2, lambda)\n public static IEnumerable<TSource> Union<TSource, TComparable>(\n this IEnumerable<TSource> source1, \n IEnumerable<TSource> source2, \n Func<TSource, TComparable> keySelector)\n {\n return source1.Union(source2, \n new LambdaEqualityComparer<TSource, TComparable>(keySelector));\n }\n }\n"
},
{
"answer_id": 73979911,
"author": "Tomas C",
"author_id": 7226886,
"author_profile": "https://Stackoverflow.com/users/7226886",
"pm_score": 0,
"selected": false,
"text": "public class DelegateEqualityComparer<T>: IEqualityComparer<T>\n{\n private readonly Func<T, T, bool> _equalsDelegate;\n private readonly Func<T, int> _getHashCodeDelegate;\n\n public DelegateEqualityComparer(Func<T, T, bool> equalsDelegate, Func<T, int> getHashCodeDelegate)\n {\n _equalsDelegate = equalsDelegate ?? ((tx, ty) => object.Equals(tx, ty));\n _getHashCodeDelegate = getHashCodeDelegate ?? (t => t.GetSafeHashCode());\n }\n\n public bool Equals(T x, T y) => _equalsDelegate(x, y);\n\n public int GetHashCode(T obj) => _getHashCodeDelegate(obj);\n}\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/98033",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9990/"
] |
98,096
|
<p>I've seen some people use <code>EXISTS (SELECT 1 FROM ...)</code> rather than <code>EXISTS (SELECT id FROM ...)</code> as an optimization--rather than looking up and returning a value, SQL Server can simply return the literal it was given.</p>
<p>Is <code>SELECT(1)</code> always faster? Would Selecting a value from the table require work that Selecting a literal would avoid?</p>
|
[
{
"answer_id": 99340,
"author": "jalbert",
"author_id": 1360388,
"author_profile": "https://Stackoverflow.com/users/1360388",
"pm_score": 3,
"selected": false,
"text": "SELECT 1 SELECT * EXISTS WHERE SET STATISTICS IO ON SELECT * EXISTS"
},
{
"answer_id": 115881,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "SELECT null ..."
},
{
"answer_id": 1602714,
"author": "Matt Rogish",
"author_id": 2590,
"author_profile": "https://Stackoverflow.com/users/2590",
"pm_score": 4,
"selected": true,
"text": "SELECT whatever\n FROM yourtable\n WHERE EXISTS( SELECT 1/0\n FROM someothertable \n WHERE a_valid_clause )\n 3) Case:\n\n a) If the <select list> \"*\" is simply contained in a <subquery> that is immediately contained in an <exists predicate>, then the <select list> is equivalent to a <value expression> that is an arbitrary <literal>.\n"
},
{
"answer_id": 4348102,
"author": "Martin Smith",
"author_id": 73226,
"author_profile": "https://Stackoverflow.com/users/73226",
"pm_score": 1,
"selected": false,
"text": "select COUNT(1) from master..spt_values\n Scalar Operator(Count(*))\n 1 * *"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/98096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18347/"
] |
98,098
|
<p>Is the a VS2005 C++ compiler flag like the Xmx???M java flag so I can limit the heap size of my application running on Windows. </p>
<p>I need to limit the heap size so I can fill the memory to find out the current free memory. (The code also runs on an embedded system where this is the best method to get the memory usage)</p>
|
[
{
"answer_id": 98217,
"author": "jfs",
"author_id": 6223,
"author_profile": "https://Stackoverflow.com/users/6223",
"pm_score": 0,
"selected": false,
"text": "malloc() new"
},
{
"answer_id": 641887,
"author": "Ashwin Nanjappa",
"author_id": 1630,
"author_profile": "https://Stackoverflow.com/users/1630",
"pm_score": 1,
"selected": false,
"text": "Linker -> System -> Heap Reserve Size /HEAP:reserve"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/98098",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2731698/"
] |
98,124
|
<p>Why does this javascript return 108 instead of 2008? it gets the day and month correct but not the year?</p>
<pre><code>myDate = new Date();
year = myDate.getYear();
</code></pre>
<p>year = 108?</p>
|
[
{
"answer_id": 98136,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 2,
"selected": false,
"text": "date.getFullYear() 98 getYear() 00 100 getFullYear"
},
{
"answer_id": 98162,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 8,
"selected": true,
"text": "getYear() getFullYear() * The year according to getYear(): 108\n* The year according to getFullYear(): 2008\n getYear() getFullYear()"
},
{
"answer_id": 98237,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 5,
"selected": false,
"text": "Date.prototype.getRealYear = function() \n{ \n if(this.getFullYear)\n return this.getFullYear();\n else\n return this.getYear() + 1900; \n};\n var myDate = new Date();\nmyDate.getRealYear();\n// Outputs 2008\n"
},
{
"answer_id": 100802,
"author": "Arve",
"author_id": 9595,
"author_profile": "https://Stackoverflow.com/users/9595",
"pm_score": 2,
"selected": false,
"text": "getYear() getFullYear() GetYear() getFullYear() getYear() getYear() getFullYear() javascript:alert(new Date(917823600000).getYear());\n javascript:alert(new Date().getYear());\n"
},
{
"answer_id": 3447564,
"author": "D3vito",
"author_id": 415976,
"author_profile": "https://Stackoverflow.com/users/415976",
"pm_score": 1,
"selected": false,
"text": "date.getUTCFullYear()"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/98124",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6161/"
] |
98,134
|
<p>I'm using a build script that calls Wise to create some install files. The problem is that the Wise license only allows it to be run under one particular user account, which is not the same account that my build script will run under. I know Windows has the <strong>runas</strong> command but this won't work for an automated script as there is no way to enter the password via the command line.</p>
|
[
{
"answer_id": 98323,
"author": "Jeffrey Vanneste",
"author_id": 5497,
"author_profile": "https://Stackoverflow.com/users/5497",
"pm_score": 2,
"selected": false,
"text": "CPAU -u user [-p password] -ex \"WhatToRun\" [switches]\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/98134",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/327/"
] |
98,135
|
<p>I want to use the Django template engine in my (Python) code, but I'm not building a Django-based web site. How do I use it without having a settings.py file (and others) and having to set the DJANGO_SETTINGS_MODULE environment variable?</p>
<p>If I run the following code:</p>
<pre><code>>>> import django.template
>>> from django.template import Template, Context
>>> t = Template('My name is {{ my_name }}.')
</code></pre>
<p>I get:</p>
<pre><code>ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
</code></pre>
|
[
{
"answer_id": 98146,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 3,
"selected": false,
"text": "settings.py DJANGO_SETTINGS_MODULE from django.conf import settings\nsettings.configure (FOO='bar') # Your settings go here\n"
},
{
"answer_id": 98150,
"author": "William Keller",
"author_id": 17095,
"author_profile": "https://Stackoverflow.com/users/17095",
"pm_score": 0,
"selected": false,
"text": "AppEngine"
},
{
"answer_id": 98178,
"author": "Daryl Spitzer",
"author_id": 4766,
"author_profile": "https://Stackoverflow.com/users/4766",
"pm_score": 8,
"selected": true,
"text": ">>> from django.template import Template, Context\n>>> from django.conf import settings\n>>> settings.configure()\n>>> t = Template('My name is {{ my_name }}.')\n>>> c = Context({'my_name': 'Daryl Spitzer'})\n>>> t.render(c)\nu'My name is Daryl Spitzer.'\n"
},
{
"answer_id": 98214,
"author": "nosklo",
"author_id": 17160,
"author_profile": "https://Stackoverflow.com/users/17160",
"pm_score": 6,
"selected": false,
"text": ">>> import jinja2\n>>> print jinja2.Environment().compile('{% for row in data %}{{ row.name | upper }}{% endfor %}', raw=True) \nfrom __future__ import division\nfrom jinja2.runtime import LoopContext, Context, TemplateReference, Macro, Markup, TemplateRuntimeError, missing, concat, escape, markup_join, unicode_join\nname = None\n\ndef root(context, environment=environment):\n l_data = context.resolve('data')\n t_1 = environment.filters['upper']\n if 0: yield None\n for l_row in l_data:\n if 0: yield None\n yield unicode(t_1(environment.getattr(l_row, 'name')))\n\nblocks = {}\ndebug_info = '1=9'\n"
},
{
"answer_id": 109380,
"author": "olt",
"author_id": 19759,
"author_profile": "https://Stackoverflow.com/users/19759",
"pm_score": 3,
"selected": false,
"text": "django jinja2"
},
{
"answer_id": 345360,
"author": "muhuk",
"author_id": 42188,
"author_profile": "https://Stackoverflow.com/users/42188",
"pm_score": 2,
"selected": false,
"text": "manage.py generatereports --format=html\n"
},
{
"answer_id": 11519049,
"author": "hupantingxue",
"author_id": 1318785,
"author_profile": "https://Stackoverflow.com/users/1318785",
"pm_score": 0,
"selected": false,
"text": "manage.py >>> from django import template \n>>> t = template.Template('My name is {{ me }}.') \n>>> c = template.Context({'me': 'ShuJi'}) \n>>> t.render(c)\n"
},
{
"answer_id": 20480267,
"author": "Gourneau",
"author_id": 56069,
"author_profile": "https://Stackoverflow.com/users/56069",
"pm_score": 2,
"selected": false,
"text": "from django import template\n\nregister = template.Library()\n\n@register.filter(name='bracewrap')\ndef bracewrap(value):\n return \"{\" + value + \"}\"\n {{var|bracewrap}}\n import django\nfrom django.conf import settings\nfrom django.template import Template, Context\nimport os\n\n#load your tags\nfrom django.template.loader import get_template\ndjango.template.base.add_to_builtins(\"read\")\n\n# You need to configure Django a bit\nsettings.configure(\n TEMPLATE_DIRS=(os.path.dirname(os.path.realpath(__file__)), ),\n)\n\n#or it could be in python\n#t = Template('My name is {{ my_name }}.')\nc = Context({'var': 'stackoverflow.com rox'})\n\ntemplate = get_template(\"temp.html\")\n# Prepare context ....\nprint template.render(c)\n {stackoverflow.com rox}\n"
},
{
"answer_id": 34494931,
"author": "Pramod",
"author_id": 817277,
"author_profile": "https://Stackoverflow.com/users/817277",
"pm_score": 3,
"selected": false,
"text": "settings.DEBUG from django.template import Template, Context\nfrom django.template.engine import Engine\n\nfrom django.conf import settings\nsettings.configure(DEBUG=False)\n\ntemplate_string = \"Hello {{ name }}\"\ntemplate = Template(template_string, engine=Engine())\ncontext = Context({\"name\": \"world\"})\noutput = template.render(context) #\"hello world\"\n"
},
{
"answer_id": 47465370,
"author": "Robert Vanden Eynde",
"author_id": 1980630,
"author_profile": "https://Stackoverflow.com/users/1980630",
"pm_score": 3,
"selected": false,
"text": "from django.conf import settings\n\nsettings.configure(TEMPLATES=[\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': ['.'], # if you want the templates from a file\n 'APP_DIRS': False, # we have no apps\n },\n])\n\nimport django\ndjango.setup()\n from django import template \nt = template.Template('My name is {{ name }}.') \nc = template.Context({'name': 'Rob'}) \nt.render(c)\n from django.template.loader import get_template\nt = get_template('a.html')\nt.render({'name': 5})\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/98135",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4766/"
] |
98,153
|
<p>I've found the standard hashing function on VS2005 is painfully slow when trying to achieve high performance look ups. What are some good examples of fast and efficient hashing algorithms that should void most collisions?</p>
|
[
{
"answer_id": 98179,
"author": "Dark Shikari",
"author_id": 11206,
"author_profile": "https://Stackoverflow.com/users/11206",
"pm_score": 4,
"selected": false,
"text": "/* magic numbers from http://www.isthe.com/chongo/tech/comp/fnv/ */\nstatic const size_t InitialFNV = 2166136261U;\nstatic const size_t FNVMultiple = 16777619;\n\n/* Fowler / Noll / Vo (FNV) Hash */\nsize_t myhash(const string &s)\n{\n size_t hash = InitialFNV;\n for(size_t i = 0; i < s.length(); i++)\n {\n hash = hash ^ (s[i]); /* xor the low 8 bits */\n hash = hash * FNVMultiple; /* multiply by the magic number */\n }\n return hash;\n}\n"
},
{
"answer_id": 98280,
"author": "Brian",
"author_id": 8959,
"author_profile": "https://Stackoverflow.com/users/8959",
"pm_score": 2,
"selected": false,
"text": " template <> struct myhash{};\n\n template <> struct myhash<string>\n {\n size_t operator()(string &to_hash) const\n {\n const char * in = to_hash.c_str();\n size_t out=0;\n while(NULL != *in)\n {\n out*= 53; //just a prime number\n out+= *in;\n ++in;\n }\n return out;\n }\n };\n\n hash_map<string, int, myhash<string> > my_hash_map;\n"
},
{
"answer_id": 99214,
"author": "bk1e",
"author_id": 8090,
"author_profile": "https://Stackoverflow.com/users/8090",
"pm_score": 3,
"selected": false,
"text": "hash_map vector"
},
{
"answer_id": 107657,
"author": "George V. Reilly",
"author_id": 6364,
"author_profile": "https://Stackoverflow.com/users/6364",
"pm_score": 6,
"selected": false,
"text": "unsigned int\nhash(\n const char* s,\n unsigned int seed = 0)\n{\n unsigned int hash = seed;\n while (*s)\n {\n hash = hash * 101 + *s++;\n }\n return hash;\n}\n"
},
{
"answer_id": 41314400,
"author": "philix",
"author_id": 707094,
"author_profile": "https://Stackoverflow.com/users/707094",
"pm_score": 1,
"selected": false,
"text": "unsigned long\nhash(unsigned char *str)\n{\n unsigned long hash = 5381;\n int c;\n\n while (c = *str++)\n hash = ((hash << 5) + hash) + c; /* hash * 33 + c */\n\n return hash;\n}\n hash = FNV_offset_basis\nfor each byte_of_data to be hashed\n hash = hash × FNV_prime\n hash = hash XOR byte_of_data\nreturn hash\n hash = FNV_offset_basis\nfor each byte_of_data to be hashed\n hash = hash XOR byte_of_data\n hash = hash × FNV_prime\nreturn hash\n"
}
] |
2008/09/18
|
[
"https://Stackoverflow.com/questions/98153",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13646/"
] |
98,205
|
<p>I'm gearing up to do some Ajax style client-side JavaScript code in the near future, and I've heard rave reviews of jQuery when it comes to this realm. What I'm wondering is:</p>
<ul>
<li><strong>What are all the cross-browser JavaScript libraries out there?</strong></li>
</ul>
<p>What is the experience using them?</p>
|
[
{
"answer_id": 11110702,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "Element::classList"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98205",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/145/"
] |
98,212
|
<p>I am wondering what methods people are using for validating check boxes in ASP.NET MVC (both client and server side).</p>
<p>I am using JQuery currently for client side validation but I am curious what methods people are using, ideally with the least amount of fuss (I am looking for a new solution).</p>
<p>I should mention that I am currently using MVC Preview 4, and while I could upgrade to MVC Preview 5 if there is no elegant solution in MVC Preview 4, I would prefer not to at this stage just for compatibility purposes with other developers and existing solutions.</p>
<p>Note, I have seen these related posts:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/10300/validating-posted-form-data-in-the-aspnet-mvc-framework">Validating posted form data in the
ASP.NET MVC framework</a></li>
<li><a href="https://stackoverflow.com/questions/16747/whats-the-best-way-to-implement-field-validation-using-aspnet-mvc">What’s the best way to implement field validation using ASP.NET MVC?</a></li>
<li><a href="https://stackoverflow.com/questions/61456/mvcnet-jquery-validation">MVC.net JQuery Validation</a></li>
</ul>
|
[
{
"answer_id": 98227,
"author": "Thomas R",
"author_id": 2192,
"author_profile": "https://Stackoverflow.com/users/2192",
"pm_score": 0,
"selected": false,
"text": "<?php echo isset($_POST['checkbox_name']) ? 'checked' : 'not checked'; ?>\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98212",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/364/"
] |
98,224
|
<p>After downloading files from a remote UNIX FTP server, you want to verify that you have downloaded all the files correctly. Minimal you will get information similar to "dir /s" command in Windows command prompt. The FTP client runs on Windows.</p>
|
[
{
"answer_id": 4414456,
"author": "jamesmar",
"author_id": 538522,
"author_profile": "https://Stackoverflow.com/users/538522",
"pm_score": 3,
"selected": false,
"text": "ls -lR\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98224",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13584/"
] |
98,225
|
<p>Any other tweaks for making emacs as vim-like as possible would be appreciated as well.</p>
<p>Addendum: The main reason I don't just use vim is that I love how emacs lets you open a file in two different frames [ADDED: sorry, this was confusing: I mean separate <em>windows</em>, which emacs calls "frames"]. It's like making a vertical split but I don't have to have one enormous window.</p>
|
[
{
"answer_id": 482859,
"author": "Sébastien RoccaSerra",
"author_id": 2797,
"author_profile": "https://Stackoverflow.com/users/2797",
"pm_score": 2,
"selected": false,
"text": "(define-key viper-vi-global-user-map [(delete)] 'delete-char)\n(define-key viper-vi-global-user-map \"/\" 'isearch-forward-regexp)\n(define-key viper-vi-global-user-map \"?\" 'isearch-backward-regexp)\n(define-key viper-vi-global-user-map \"\\C-wh\" 'windmove-left)\n(define-key viper-vi-global-user-map \"\\C-wj\" 'windmove-down)\n(define-key viper-vi-global-user-map \"\\C-wk\" 'windmove-up)\n(define-key viper-vi-global-user-map \"\\C-wl\" 'windmove-right)\n(define-key viper-vi-global-user-map \"\\C-wv\" '(lambda () (interactive)\n (split-window-horizontally)\n (other-window 1)\n (switch-to-buffer (other-buffer))))\n\n(define-key viper-visual-mode-map \"F\" 'viper-find-char-backward)\n(define-key viper-visual-mode-map \"t\" 'viper-goto-char-forward)\n(define-key viper-visual-mode-map \"T\" 'viper-goto-char-backward)\n(define-key viper-visual-mode-map \"e\" '(lambda ()\n (interactive)\n (viper-end-of-word 1)\n (viper-forward-char 1)))\n\n(push '(\"only\" (delete-other-windows)) ex-token-alist)\n(push '(\"close\" (delete-window)) ex-token-alist)\n C-M-x"
},
{
"answer_id": 488044,
"author": "MCS",
"author_id": 1094969,
"author_profile": "https://Stackoverflow.com/users/1094969",
"pm_score": 1,
"selected": false,
"text": ":split :vsplit CTRL-w-w :resize +n :resize -n"
},
{
"answer_id": 6079323,
"author": "tbear",
"author_id": 238973,
"author_profile": "https://Stackoverflow.com/users/238973",
"pm_score": 1,
"selected": false,
"text": " ; I use C-d to quit emacs and vim\n (vimpulse-global-set-key 'vi-state (kbd \"C-d\") 'save-buffers-kill-terminal)\n ; use ; instead of :\n (vimpulse-global-set-key 'vi-state (kbd \";\") 'viper-ex)\n ; use C-e instead of $. This works for all motion command too! (e.g. d C-e is easier to type than d$)\n (vimpulse-global-set-key 'vi-state (kbd \"C-e\") 'viper-goto-eol)\n (defun t_save() (interactive)(save-buffer)(viper-change-state-to-vi)) \n (global-set-key (kbd \"\\C-s\") 't_save) ; save using C-s instead of :w<CR> or C-x-s\n\n (defun command-line-diff (switch)\n (let ((file1 (pop command-line-args-left))\n (file2 (pop command-line-args-left)))\n (ediff file1 file2)))\n\n ;; Usage: emacs -diff file1 file2 (much better then vimdiff)\n (add-to-list 'command-switch-alist '(\"-diff\" . command-line-diff))\n (setq viper-inhibit-startup-message 't)\n (setq viper-expert-level '3)\n (setq viper-ESC-key \"\\C-c\") ; use C-c instead of ESC. unlike vim, C-c works perfectly with vimpulse.\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4234/"
] |
98,242
|
<blockquote>
<p><strong>Possible Duplicate:</strong><br />
<a href="https://stackoverflow.com/questions/6457130/pre-post-increment-operator-behavior-in-c-c-java-c-sharp">Pre & post increment operator behavior in C, C++, Java, & C#</a></p>
</blockquote>
<p>Here is a test case:</p>
<pre><code>
void foo(int i, int j)
{
printf("%d %d", i, j);
}
...
test = 0;
foo(test++, test);
</code></pre>
<p>I would expect to get a "0 1" output, but I get "0 0"
What gives??</p>
|
[
{
"answer_id": 98263,
"author": "Mike Thompson",
"author_id": 2754,
"author_profile": "https://Stackoverflow.com/users/2754",
"pm_score": 4,
"selected": false,
"text": "mov ecx, DWORD PTR _i$[ebp]\npush ecx\nmov edx, DWORD PTR tv66[ebp]\npush edx\ncall _foo\nadd esp, 8\nmov eax, DWORD PTR _i$[ebp]\nadd eax, 1\nmov DWORD PTR _i$[ebp], eax\n"
},
{
"answer_id": 99363,
"author": "Benjamin Autin",
"author_id": 1440933,
"author_profile": "https://Stackoverflow.com/users/1440933",
"pm_score": 3,
"selected": false,
"text": "int printf(const char *format, ...);\n"
},
{
"answer_id": 100634,
"author": "Anthony Williams",
"author_id": 5597,
"author_profile": "https://Stackoverflow.com/users/5597",
"pm_score": 5,
"selected": false,
"text": "f(test,test++) test int preincrement(int* p)\n{\n return ++(*p);\n}\n\nint test;\nprintf(\"%d %d\\n\",preincrement(&test),test);\n preincrement int dummy;\ndummy=test++,test;\n dummy"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10703/"
] |
98,274
|
<p>Is it possible to integrate SSRS reports to the webforms..an example will be enough to keep me moving. </p>
|
[
{
"answer_id": 98344,
"author": "John Christensen",
"author_id": 1194,
"author_profile": "https://Stackoverflow.com/users/1194",
"pm_score": 3,
"selected": false,
"text": "public void ProcessRequest(HttpContext context)\n{\n string report = null;\n int managerId = -1;\n int planId = -1;\n GetParametersFromSession(context.Session, out report, out managerId, out planId);\n if (report == null || managerId == -1 || planId == -1)\n {\n return;\n }\n\n CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;\n\n List<ReportParameter> parameters = new List<ReportParameter>();\n parameters.Add(new ReportParameter(\"Prefix\", report));\n parameters.Add(new ReportParameter(\"ManagerId\", managerId.ToString()));\n parameters.Add(new ReportParameter(\"ActionPlanId\", planId.ToString()));\n string language = Thread.CurrentThread.CurrentCulture.Name;\n language = String.Format(\"{0}_{1}\", language.Substring(0, 2), language.Substring(3, 2).ToLower());\n parameters.Add(new ReportParameter(\"Lang\", language));\n\n ReportViewer rv = new ReportViewer();\n rv.ProcessingMode = ProcessingMode.Remote;\n rv.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings[\"ReportServer\"]);\n if (ConfigurationManager.AppSettings[\"DbYear\"] == \"2007\")\n {\n rv.ServerReport.ReportPath = \"/ActionPlanning/Plan\";\n }\n else\n {\n rv.ServerReport.ReportPath = String.Format(\"/ActionPlanning{0}/Plan\", ConfigurationManager.AppSettings[\"DbYear\"]);\n }\n rv.ServerReport.SetParameters(parameters);\n\n string mimeType = null;\n string encoding = null;\n string extension = null;\n string[] streamIds = null;\n Warning[] warnings = null;\n byte[] output = rv.ServerReport.Render(\"pdf\", null, out mimeType, out encoding, out extension, out streamIds, out warnings);\n\n context.Response.ContentType = mimeType;\n context.Response.BinaryWrite(output);\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14752/"
] |
98,310
|
<p>(I don't want to hear about how crazy I am to want that! :)</p>
<p>Focus-follows-mouse is also known as point-to-focus, pointer focus, and (in some implementations) sloppy focus. [Add other terms that will make this more searchable!] X-mouse</p>
|
[
{
"answer_id": 98331,
"author": "Clint Ecker",
"author_id": 13668,
"author_profile": "https://Stackoverflow.com/users/13668",
"pm_score": 6,
"selected": false,
"text": "defaults write com.apple.Terminal FocusFollowsMouse -bool true\n defaults write com.apple.x11 wm_ffm -bool true\n defaults write org.x.X11 wm_ffm -bool true\n"
},
{
"answer_id": 98357,
"author": "dreeves",
"author_id": 4234,
"author_profile": "https://Stackoverflow.com/users/4234",
"pm_score": 3,
"selected": false,
"text": "defaults write com.apple.Terminal FocusFollowsMouse -string YES\n defaults write org.x.X11 wm_ffm -bool true \n defaults write com.apple.x11 wm_ffm true\n"
},
{
"answer_id": 29159270,
"author": "wprl",
"author_id": 17847,
"author_profile": "https://Stackoverflow.com/users/17847",
"pm_score": 4,
"selected": false,
"text": "brew install amethyst ~/.amethyst {\n \"LAYOUTS\": \"----------------------\",\n \"layouts\": [\n ],\n\n \"MODIFIERS\": \"----------------------\",\n \"Valid modifiers are\": [\n \"option\",\n \"shift\",\n \"control\",\n \"command\"\n ],\n\n \"mod1\": [\n ],\n \"mod2\": [\n ],\n\n \"COMMANDS\": \"----------------------\",\n \"Commands are\": {\n \"cycle-layout\": \"Cycle layout to the next layout\",\n \"cycle-layout-backward\": \"Cycle layout to the previous layout\",\n \"focus-screen-1\": \"Focus the main window on the first screen\",\n \"focus-screen-2\": \"Focus the main window on the second screen\",\n \"focus-screen-3\": \"Focus the main window on the third screen\",\n \"focus-screen-2\": \"Focus the main window on the second screen\",\n \"focus-screen-3\": \"Focus the main window on the third screen\",\n \"focus-screen-4\": \"Focus the main window on the fourth screen\",\n \"throw-screen-1\": \"Throw the focused window to the first screen\",\n \"throw-screen-2\": \"Throw the focused window to the second screen\",\n \"throw-screen-3\": \"Throw the focused window to the third screen\",\n \"throw-screen-4\": \"Throw the focused window to the fourth screen\",\n \"shrink-main\": \"Shrink the main pane of the current layout\",\n \"expand-main\": \"Expand the main pane of the current layout\",\n \"increase-main\": \"Increase the number of windows in the main pane\",\n \"decrease-main\": \"Decrease the number of windows in the main pane\",\n \"focus-ccw\": \"Move window focus counter-clockwise on the current screen\",\n \"focus-cw\": \"Move window focus clockwise on the current screen\",\n \"swap-ccw\": \"Swap focused window with the next window going counter-clockwi$\n \"swap-cw\": \"Swap focused window with the next window going clockwise\",\n \"swap-main\": \"Swap focused window with the main window of its screen\",\n \"throw-space-1\": \"Throw the focused window to the first space\",\n \"throw-space-2\": \"Throw the focused window to the second space\",\n \"throw-space-3\": \"Throw the focused window to the third space\",\n \"throw-space-4\": \"Throw the focused window to the fourth space\",\n \"throw-space-5\": \"Throw the focused window to the fifth space\",\n \"throw-space-6\": \"Throw the focused window to the sixth space\",\n \"throw-space-7\": \"Throw the focused window to the seventh space\",\n \"throw-space-8\": \"Throw the focused window to the eighth space\",\n \"throw-space-9\": \"Throw the focused window to the ninth space\",\n \"throw-space-8\": \"Throw the focused window to the eighth space\",\n \"throw-space-9\": \"Throw the focused window to the ninth space\",\n \"toggle-float\": \"Toggle the focused window between being floating and tiled\"\n },\n\n \"screens\": \"3\",\n\n \"cycle-layout\": {\n \"mod\": \"mod1\",\n },\n \"cycle-layout-backward\": {\n \"mod\": \"mod2\",\n },\n \"select-tall-layout\": {\n \"mod\": \"mod1\"\n },\n \"select-wide-layout\": {\n \"mod\": \"mod1\"\n },\n \"select-fullscreen-layout\": {\n \"mod\": \"mod1\"\n },\n \"select-column-layout\": {\n \"mod\": \"mod1\"\n },\n \"mod\": \"mod1\"\n },\n \"focus-screen-1\": {\n \"mod\": \"mod1\"\n },\n \"focus-screen-2\": {\n \"mod\": \"mod1\"\n },\n \"focus-screen-3\": {\n \"mod\": \"mod1\"\n },\n \"focus-screen-4\": {\n \"mod\": \"mod1\"\n },\n \"throw-screen-1\": {\n \"mod\": \"mod2\"\n },\n \"throw-screen-2\": {\n \"mod\": \"mod2\"\n },\n \"throw-screen-3\": {\n \"mod\": \"mod2\"\n },\n \"throw-screen-4\": {\n \"mod\": \"mod2\"\n \"throw-screen-4\": {\n \"mod\": \"mod2\"\n },\n \"shrink-main\": {\n \"mod\": \"mod1\"\n },\n \"expand-main\": {\n \"mod\": \"mod1\"\n },\n \"increase-main\": {\n \"mod\": \"mod1\"\n },\n \"decrease-main\": {\n \"mod\": \"mod1\"\n },\n \"focus-ccw\": {\n \"mod\": \"mod1\"\n },\n \"focus-cw\": {\n \"mod\": \"mod1\"\n },\n \"swap-screen-ccw\": {\n \"mod\": \"mod2\"\n },\n \"swap-screen-cw\": {\n },\n \"swap-screen-cw\": {\n \"mod\": \"mod2\"\n },\n \"swap-ccw\": {\n \"mod\": \"mod2\"\n },\n \"swap-cw\": {\n \"mod\": \"mod2\"\n },\n \"swap-main\": {\n \"mod\": \"mod1\"\n },\n \"throw-space-1\": {\n \"mod\": \"mod2\"\n },\n \"throw-space-2\": {\n \"mod\": \"mod2\"\n },\n \"throw-space-3\": {\n \"mod\": \"mod2\"\n },\n \"throw-space-4\": {\n \"mod\": \"mod2\"\n },\n\n \"mod\": \"mod2\"\n },\n \"throw-space-5\": {\n \"mod\": \"mod2\"\n },\n \"throw-space-6\": {\n \"mod\": \"mod2\"\n },\n \"throw-space-7\": {\n \"mod\": \"mod2\"\n },\n \"throw-space-8\": {\n \"mod\": \"mod2\"\n },\n \"throw-space-9\": {\n \"mod\": \"mod2\"\n },\n \"toggle-float\": {\n \"mod\": \"mod1\"\n },\n \"toggle-tiling\": {\n \"mod\": \"mod2\"\n },\n \"display-current-layout\": {\n \"mod\": \"mod1\"\n \"display-current-layout\": {\n \"mod\": \"mod1\"\n },\n\n \"MISC\": \"----------------------\",\n \"floating\": [],\n \"float-small-windows\": false,\n \"mouse-follows-focus\": false,\n \"focus-follows-mouse\": true,\n \"enables-layout-hud\": false,\n \"enables-layout-hud-on-space-change\": false\n}\n"
},
{
"answer_id": 35073462,
"author": "sbmpost",
"author_id": 5394382,
"author_profile": "https://Stackoverflow.com/users/5394382",
"pm_score": 5,
"selected": false,
"text": "on run {input, parameters}\n tell application \"Finder\"\n if exists of application process \"AutoRaise\" then\n quit application \"/Applications/AutoRaise\"\n display notification \"AutoRaise Stopped\"\n else\n launch application \"/Applications/AutoRaise\"\n display notification \"AutoRaise Started\"\n end if\n end tell\n return input\nend run\n"
},
{
"answer_id": 55970830,
"author": "Les Grieve",
"author_id": 4637974,
"author_profile": "https://Stackoverflow.com/users/4637974",
"pm_score": 4,
"selected": false,
"text": "chunkc set ffm_disable_autoraise 0\n ~/.chunkwmrc brew tap koekeishiya/formulae\nbrew install yabai\nmkdir -p ~/.config/yabai/\nprintf 'yabai -m config focus_follows_mouse autoraise' >> ~/.config/yabai/yabairc\nbrew services start yabai\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98310",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4234/"
] |
98,320
|
<p>My model layer is being used by a handful of different projects and I'd like to use a single XML Spring Configuration file for the model regardless of which project is using it.</p>
<p>My question is: Since not all beans are used in all projects am I wasting resources to any significant amount if there not being instantiated? I'm not too sure how lazy Spring is about loading them since it's never been an issue until now.</p>
<p>Any ideas?</p>
|
[
{
"answer_id": 98544,
"author": "MetroidFan2002",
"author_id": 8026,
"author_profile": "https://Stackoverflow.com/users/8026",
"pm_score": 4,
"selected": true,
"text": "<bean id=\"lazy\" class=\"com.foo.ExpensiveToCreateBean\" lazy-init=\"true\"/>\n"
},
{
"answer_id": 150210,
"author": "Tom De Leu",
"author_id": 22263,
"author_profile": "https://Stackoverflow.com/users/22263",
"pm_score": 3,
"selected": false,
"text": "<beans/> <beans default-lazy-init=\"true\">\n <!-- no beans will be pre-instantiated... -->\n</beans>\n lazy-init"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98320",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2443/"
] |
98,340
|
<p>An example of unspecified behavior in the C language is the order of evaluation of arguments to a function. It might be left to right or right to left, you just don't know. This would affect how <code>foo(c++, c)</code> or <code>foo(++c, c)</code> gets evaluated.</p>
<p>What other unspecified behavior is there that can surprise the unaware programmer?</p>
|
[
{
"answer_id": 98356,
"author": "Nils Pipenbrinck",
"author_id": 15955,
"author_profile": "https://Stackoverflow.com/users/15955",
"pm_score": 7,
"selected": true,
"text": "float funky_float_abs (float a)\n{\n unsigned int temp = *(unsigned int *)&a;\n temp &= 0x7fffffff;\n return *(float *)&temp;\n}\n float funky_float_abs (float a)\n{\n float temp_float = a;\n // valid, because it's a char pointer. These are special.\n unsigned char * temp = (unsigned char *)&temp_float;\n temp[3] &= 0x7f;\n return temp_float;\n}\n float funky_float_abs (float a)\n{\n int i;\n float result;\n memcpy (&i, &a, sizeof (int));\n i &= 0x7fffffff;\n memcpy (&result, &i, sizeof (int));\n return result;\n}\n float funky_float_abs (float a)\n{\n union \n {\n unsigned int i;\n float f;\n } cast_helper;\n\n cast_helper.f = a;\n cast_helper.i &= 0x7fffffff;\n return cast_helper.f;\n}\n"
},
{
"answer_id": 98358,
"author": "1800 INFORMATION",
"author_id": 3146,
"author_profile": "https://Stackoverflow.com/users/3146",
"pm_score": 4,
"selected": false,
"text": "// what does this do?\nx = x++;\n x = 1 x++ x ="
},
{
"answer_id": 98414,
"author": "Adam Pierce",
"author_id": 5324,
"author_profile": "https://Stackoverflow.com/users/5324",
"pm_score": 4,
"selected": false,
"text": "result = x/*y;\n"
},
{
"answer_id": 98589,
"author": "Steve Jessop",
"author_id": 13005,
"author_profile": "https://Stackoverflow.com/users/13005",
"pm_score": 5,
"selected": false,
"text": "if (x+1 < x) x -fstrict-overflow"
},
{
"answer_id": 18260275,
"author": "Jens",
"author_id": 648658,
"author_profile": "https://Stackoverflow.com/users/648658",
"pm_score": 4,
"selected": false,
"text": "int long %x unsigned int unsigned int %d int size_t %u %d %zu %d %x %p void *"
},
{
"answer_id": 18261067,
"author": "Keith Thompson",
"author_id": 827263,
"author_profile": "https://Stackoverflow.com/users/827263",
"pm_score": 3,
"selected": false,
"text": "\"x\"\n char[2] char* 'x'\n int 'xy'\n int"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98340",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10703/"
] |
98,359
|
<p>How do you implement the fastest possible <a href="http://en.wikipedia.org/wiki/Gaussian_blur" rel="noreferrer">Gaussian blur</a> algorithm?</p>
<p>I am going to implement it in Java, so <a href="http://en.wikipedia.org/wiki/Graphics_processing_unit" rel="noreferrer">GPU</a> solutions are ruled out. My application, <a href="http://planetGenesis.sourceforge.net" rel="noreferrer">planetGenesis</a>, is cross platform, so I don't want <a href="http://en.wikipedia.org/wiki/Java_Native_Interface" rel="noreferrer">JNI</a>.</p>
|
[
{
"answer_id": 1377012,
"author": "Paul Harrison",
"author_id": 102709,
"author_profile": "https://Stackoverflow.com/users/102709",
"pm_score": 2,
"selected": false,
"text": "y(i) = y(i-1) + x(i)\n blurred(i) = y(i+radius) - y(i-radius)\n"
},
{
"answer_id": 3712073,
"author": "Ben McIntosh",
"author_id": 50859,
"author_profile": "https://Stackoverflow.com/users/50859",
"pm_score": 2,
"selected": false,
"text": "Gaussian coefficient input pixel value"
},
{
"answer_id": 38285167,
"author": "Ali Akdurak",
"author_id": 306711,
"author_profile": "https://Stackoverflow.com/users/306711",
"pm_score": 2,
"selected": false,
"text": "@Override\npublic BufferedImage ProcessImage(BufferedImage image) {\n int width = image.getWidth();\n int height = image.getHeight();\n\n int[] pixels = image.getRGB(0, 0, width, height, null, 0, width);\n int[] changedPixels = new int[pixels.length];\n\n FastGaussianBlur(pixels, changedPixels, width, height, 12);\n\n BufferedImage newImage = new BufferedImage(width, height, image.getType());\n newImage.setRGB(0, 0, width, height, changedPixels, 0, width);\n\n return newImage;\n}\n\nprivate void FastGaussianBlur(int[] source, int[] output, int width, int height, int radius) {\n ArrayList<Integer> gaussianBoxes = CreateGausianBoxes(radius, 3);\n BoxBlur(source, output, width, height, (gaussianBoxes.get(0) - 1) / 2);\n BoxBlur(output, source, width, height, (gaussianBoxes.get(1) - 1) / 2);\n BoxBlur(source, output, width, height, (gaussianBoxes.get(2) - 1) / 2);\n}\n\nprivate ArrayList<Integer> CreateGausianBoxes(double sigma, int n) {\n double idealFilterWidth = Math.sqrt((12 * sigma * sigma / n) + 1);\n\n int filterWidth = (int) Math.floor(idealFilterWidth);\n\n if (filterWidth % 2 == 0) {\n filterWidth--;\n }\n\n int filterWidthU = filterWidth + 2;\n\n double mIdeal = (12 * sigma * sigma - n * filterWidth * filterWidth - 4 * n * filterWidth - 3 * n) / (-4 * filterWidth - 4);\n double m = Math.round(mIdeal);\n\n ArrayList<Integer> result = new ArrayList<>();\n\n for (int i = 0; i < n; i++) {\n result.add(i < m ? filterWidth : filterWidthU);\n }\n\n return result;\n}\n\nprivate void BoxBlur(int[] source, int[] output, int width, int height, int radius) {\n System.arraycopy(source, 0, output, 0, source.length);\n BoxBlurHorizantal(output, source, width, height, radius);\n BoxBlurVertical(source, output, width, height, radius);\n}\n\nprivate void BoxBlurHorizontal(int[] sourcePixels, int[] outputPixels, int width, int height, int radius) {\n int resultingColorPixel;\n float iarr = 1f / (radius + radius);\n for (int i = 0; i < height; i++) {\n int outputIndex = i * width;\n int li = outputIndex;\n int sourceIndex = outputIndex + radius;\n\n int fv = Byte.toUnsignedInt((byte) sourcePixels[outputIndex]);\n int lv = Byte.toUnsignedInt((byte) sourcePixels[outputIndex + width - 1]);\n float val = (radius) * fv;\n\n for (int j = 0; j < radius; j++) {\n val += Byte.toUnsignedInt((byte) (sourcePixels[outputIndex + j]));\n }\n\n for (int j = 0; j < radius; j++) {\n val += Byte.toUnsignedInt((byte) sourcePixels[sourceIndex++]) - fv;\n resultingColorPixel = Byte.toUnsignedInt(((Integer) Math.round(val * iarr)).byteValue());\n outputPixels[outputIndex++] = (0xFF << 24) | (resultingColorPixel << 16) | (resultingColorPixel << 8) | (resultingColorPixel);\n }\n\n for (int j = (radius + 1); j < (width - radius); j++) {\n val += Byte.toUnsignedInt((byte) sourcePixels[sourceIndex++]) - Byte.toUnsignedInt((byte) sourcePixels[li++]);\n resultingColorPixel = Byte.toUnsignedInt(((Integer) Math.round(val * iarr)).byteValue());\n outputPixels[outputIndex++] = (0xFF << 24) | (resultingColorPixel << 16) | (resultingColorPixel << 8) | (resultingColorPixel);\n }\n\n for (int j = (width - radius); j < width; j++) {\n val += lv - Byte.toUnsignedInt((byte) sourcePixels[li++]);\n resultingColorPixel = Byte.toUnsignedInt(((Integer) Math.round(val * iarr)).byteValue());\n outputPixels[outputIndex++] = (0xFF << 24) | (resultingColorPixel << 16) | (resultingColorPixel << 8) | (resultingColorPixel);\n }\n }\n}\n\nprivate void BoxBlurVertical(int[] sourcePixels, int[] outputPixels, int width, int height, int radius) {\n int resultingColorPixel;\n float iarr = 1f / (radius + radius + 1);\n for (int i = 0; i < width; i++) {\n int outputIndex = i;\n int li = outputIndex;\n int sourceIndex = outputIndex + radius * width;\n\n int fv = Byte.toUnsignedInt((byte) sourcePixels[outputIndex]);\n int lv = Byte.toUnsignedInt((byte) sourcePixels[outputIndex + width * (height - 1)]);\n float val = (radius + 1) * fv;\n\n for (int j = 0; j < radius; j++) {\n val += Byte.toUnsignedInt((byte) sourcePixels[outputIndex + j * width]);\n }\n for (int j = 0; j <= radius; j++) {\n val += Byte.toUnsignedInt((byte) sourcePixels[sourceIndex]) - fv;\n resultingColorPixel = Byte.toUnsignedInt(((Integer) Math.round(val * iarr)).byteValue());\n outputPixels[outputIndex] = (0xFF << 24) | (resultingColorPixel << 16) | (resultingColorPixel << 8) | (resultingColorPixel);\n sourceIndex += width;\n outputIndex += width;\n }\n for (int j = radius + 1; j < (height - radius); j++) {\n val += Byte.toUnsignedInt((byte) sourcePixels[sourceIndex]) - Byte.toUnsignedInt((byte) sourcePixels[li]);\n resultingColorPixel = Byte.toUnsignedInt(((Integer) Math.round(val * iarr)).byteValue());\n outputPixels[outputIndex] = (0xFF << 24) | (resultingColorPixel << 16) | (resultingColorPixel << 8) | (resultingColorPixel);\n li += width;\n sourceIndex += width;\n outputIndex += width;\n }\n for (int j = (height - radius); j < height; j++) {\n val += lv - Byte.toUnsignedInt((byte) sourcePixels[li]);\n resultingColorPixel = Byte.toUnsignedInt(((Integer) Math.round(val * iarr)).byteValue());\n outputPixels[outputIndex] = (0xFF << 24) | (resultingColorPixel << 16) | (resultingColorPixel << 8) | (resultingColorPixel);\n li += width;\n outputIndex += width;\n }\n }\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98359",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18390/"
] |
98,376
|
<p>I need to store some simple properties in a file and access them from Ruby.</p>
<p>I absolutely love the .properties file format that is the standard for such things in Java (using the java.util.Properties class)... it is simple, easy to use and easy to read.</p>
<p>So, is there a Ruby class somewhere that will let me load up some key value pairs from a file like that without a lot of effort?</p>
<p>I don't want to use XML, so please don't suggest REXML (my purpose does not warrant the "angle bracket tax").</p>
<p>I have considered rolling my own solution... it would probably be about 5-10 lines of code tops, but I would still rather use an existing library (if it is essentially a hash built from a file)... as that would bring it down to 1 line....</p>
<hr>
<p>UPDATE: It's actually a straight Ruby app, not rails, but I think YAML will do nicely (it was in the back of my mind, but I had forgotten about it... have seen but never used as of yet), thanks everyone!</p>
|
[
{
"answer_id": 98415,
"author": "Ryan Bigg",
"author_id": 15245,
"author_profile": "https://Stackoverflow.com/users/15245",
"pm_score": 6,
"selected": true,
"text": "YAML::Load(File.open(\"file\")) File.open(\"file\") { |yf| YAML::load(yf) }\n YAML.load_file(\"file\")\n"
},
{
"answer_id": 99032,
"author": "Dan Harper",
"author_id": 14530,
"author_profile": "https://Stackoverflow.com/users/14530",
"pm_score": 3,
"selected": false,
"text": "migration:\n customer: Example Customer\n test: false\nsources:\n- name: Use the Source\n engine: Foo\n- name: Sourcey\n engine: Bar\n config = YAML.load_file(File.join(File.dirname(__FILE__), ARGV[0]))\nputs config['migration']['customer']\n\nconfig['sources'].each do |source|\n puts source['name']\nend\n"
},
{
"answer_id": 99695,
"author": "Aaron Hinni",
"author_id": 12086,
"author_profile": "https://Stackoverflow.com/users/12086",
"pm_score": 3,
"selected": false,
"text": "{\n :blah => 'blee',\n :foo => 'bar',\n :items => ['item1', 'item2'],\n :stuff => true\n}\n ops = eval(File.open('options') {|f| f.read })\nputs ops[:foo]\n"
},
{
"answer_id": 15607254,
"author": "Ross Attrill",
"author_id": 556644,
"author_profile": "https://Stackoverflow.com/users/556644",
"pm_score": 3,
"selected": false,
"text": "[SECTION]\nkey=value\n .properties .ini"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98376",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/122/"
] |
98,394
|
<p>I looked for the name of a procedure, which applies a tree structure of procedures to a tree structure of data, yielding a tree structure of results - all three trees having the same structure. </p>
<p>Such a procedure might have the signature: </p>
<pre>(map-tree data functree)</pre>
<p>Its return value would be the result of elementwise application of functree's elements on the corresponding data elements. </p>
<p>Examples (assuming that the procedure is called map-tree): </p>
<p>Example 1: </p>
<pre>(define *2 (lambda (x) (* 2 x)))
; and similar definitions for *3 and *5
(map-tree '(100 (10 1)) '(*2 (*3 *5)))</pre>
<p>would yield the result <pre>(200 (30 5))</pre></p>
<p>Example 2: </p>
<pre>(map-tree '(((aa . ab) (bb . bc)) (cc . (cd . ce)))
'((car cdr) cadr))</pre>
<p>yields the result <pre>((aa bc) cd)</pre></p>
<p>However I did not find such a function in the SLIB documentation, which I consulted. </p>
<p>Does such a procedure already exist?<br>
If not, what would be a suitable name for the procedure, and how would you order its arguments?</p>
|
[
{
"answer_id": 98520,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 3,
"selected": true,
"text": "map-traversing map (define (map-traversing func data)\n (if (list? func)\n (map map-traversing func data)\n (func data)))\n (map-traversing `((,car ,cdr) ,cadr) '(((aa . ab) (bb . bc)) (cc cd . ce)))\n (cut * 2 <>) (lambda (x) (* 2 x)) (map-traversing `(,(cut * 2 <>) (,(cut * 3 <>) ,(cut * 5 <>))) '(100 (10 1)))\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98394",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11886/"
] |
98,400
|
<p>I've got a git-svn clone of an svn repo, and I want to encourage my colleagues to look at git as an option. The problem is that cloning the repo out of svn takes 3 days, but cloning from my git instance takes 10 minutes.</p>
<p>I've got a script that will allow people to clone my git repo and re-point it at the original SVN, but it requires knowing how I set some of my config values. I'd prefer the script be able to pull those values over the wire.</p>
|
[
{
"answer_id": 107740,
"author": "Pat Notz",
"author_id": 825,
"author_profile": "https://Stackoverflow.com/users/825",
"pm_score": 2,
"selected": false,
"text": "\ngit config -f/path/to/your/repo/.git/config --get ...\n scp rcp ftp \nscp curries_box:/home/currie/repo/.git/config /tmp/currie_config\ngit config -f/tmp/currie_config --get ...\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98400",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9700/"
] |
98,426
|
<p>I am working on an application that is about 250,000 lines of code. I'm currently the only developer working on this application that was originally built in .NET 1.1. Pervasive throughout is a class that inherits from CollectionBase. All database collections inherit from this class. I am considering refactoring to inherit from the generic collection List instead. Needless to say, Martin Fowler's Refactoring book has no suggestions. Should I attempt this refactor? If so, what is the best way to tackle this refactor?</p>
<p>And yes, there are unit tests throughout, but no QA team.</p>
|
[
{
"answer_id": 99555,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 2,
"selected": false,
"text": "Collection<T> List<T> Add()"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18372/"
] |
98,449
|
<p>How would I go about converting an address or city to a latitude/longitude? Are there commercial outfits I can "rent" this service from? This would be used in a commercial desktop application on a Windows PC with fulltime internet access.</p>
|
[
{
"answer_id": 25066314,
"author": "MilanNz",
"author_id": 2922851,
"author_profile": "https://Stackoverflow.com/users/2922851",
"pm_score": 2,
"selected": false,
"text": " public static String GET(String url) throws Exception {//GET Method\n String result = null;\n InputStream inputStream = null;\n try {\n HttpClient httpclient = new DefaultHttpClient();\n HttpGet httpGet = new HttpGet(url);\n\n Log.v(\"ExecuteGET: \", httpGet.getRequestLine().toString());\n\n HttpResponse httpResponse = httpclient.execute(httpGet);\n inputStream = httpResponse.getEntity().getContent();\n if (inputStream != null) {\n result = convertInputStreamToString(inputStream);\n Log.v(\"Result: \", \"result\\n\" + result);\n } \n } catch (Exception e) {\n e.printStackTrace();\n }\n return result;\n}\n @SuppressWarnings(\"deprecation\")\n public static String getLatLng(String accessToken) throws Exception{\n String query=StaticString.gLobalGoogleUrl+\"json?address=\"+URLEncoder.encode(accessToken)+\"&sensor=false\";\n Log.v(\"GETGoogleGeocoder\", query+\"\");\n return GET(query);\n }\n String result=getLatLng(\"W Main St, Bergenfield, NJ 07621\");\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17259/"
] |
98,454
|
<p>There are a number of other questions related to this topic:</p>
<ol>
<li><s><a href="https://stackoverflow.com/questions/5214/whats-a-good-standard-code-layout-for-a-php-application">Whats a good standard code layout for a php application</a></s> (deleted)</li>
<li><a href="https://stackoverflow.com/questions/7596/how-to-structure-a-java-application-in-other-words-where-do-i-put-my-classes">How to structure a java application, in other words: where do I put my classes?</a></li>
<li><a href="https://stackoverflow.com/questions/41513/recommended-source-control-directory-structure">Recommended Source Control Directory Structure?</a> </li>
<li><a href="https://stackoverflow.com/questions/16829/structure-of-projects-in-version-control">Structure of Projects in Version Control</a></li>
</ol>
<p>I could not find any specific to VSTF, which has some capabilities like Team Build, integrated Unit Testing, etc. I'm wondering if these capabilities lead to a slightly different source layout recommendation.</p>
<p>Please post example of high level directory structures that you have had good luck with an explain why you like them. I'll let people vote on a "best" approach and I'll award the answer in a few days.</p>
|
[
{
"answer_id": 25066314,
"author": "MilanNz",
"author_id": 2922851,
"author_profile": "https://Stackoverflow.com/users/2922851",
"pm_score": 2,
"selected": false,
"text": " public static String GET(String url) throws Exception {//GET Method\n String result = null;\n InputStream inputStream = null;\n try {\n HttpClient httpclient = new DefaultHttpClient();\n HttpGet httpGet = new HttpGet(url);\n\n Log.v(\"ExecuteGET: \", httpGet.getRequestLine().toString());\n\n HttpResponse httpResponse = httpclient.execute(httpGet);\n inputStream = httpResponse.getEntity().getContent();\n if (inputStream != null) {\n result = convertInputStreamToString(inputStream);\n Log.v(\"Result: \", \"result\\n\" + result);\n } \n } catch (Exception e) {\n e.printStackTrace();\n }\n return result;\n}\n @SuppressWarnings(\"deprecation\")\n public static String getLatLng(String accessToken) throws Exception{\n String query=StaticString.gLobalGoogleUrl+\"json?address=\"+URLEncoder.encode(accessToken)+\"&sensor=false\";\n Log.v(\"GETGoogleGeocoder\", query+\"\");\n return GET(query);\n }\n String result=getLatLng(\"W Main St, Bergenfield, NJ 07621\");\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] |
98,479
|
<p>What is the maximum value of an int in ChucK? Is there a symbolic constant for it?</p>
|
[
{
"answer_id": 98500,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 1,
"selected": false,
"text": "int MAXINT"
},
{
"answer_id": 98865,
"author": "Paul Reiners",
"author_id": 7648,
"author_profile": "https://Stackoverflow.com/users/7648",
"pm_score": 4,
"selected": true,
"text": "<<<Math.INT_MAX>>>;\n long 0x7FFFFFFF 2147483647 0x7FFFFFFFFFFFFFFFFF 9223372036854775807"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98479",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7648/"
] |
98,484
|
<p>I have a huge file, where I have to insert certain characters at a specific location. What is the easiest way to do that in C# without rewriting the whole file again.</p>
|
[
{
"answer_id": 469174,
"author": "Scott Marlowe",
"author_id": 1683,
"author_profile": "https://Stackoverflow.com/users/1683",
"pm_score": 1,
"selected": false,
"text": "using (BinaryWriter bw = new BinaryWriter (File.Open (strFile, FileMode.Open)))\n{\n string strNewData = \"this is some new data\";\n byte[] byteNewData = new byte[strNewData.Length];\n\n // copy contents of string to byte array\n for (var i = 0; i < strNewData.Length; i++)\n {\n byteNewData[i] = Convert.ToByte (strNewData[i]);\n }\n\n // write new data to file\n bw.Seek (15, SeekOrigin.Begin); // seek to position 15\n bw.Write (byteNewData, 0, byteNewData.Length);\n}\n"
},
{
"answer_id": 8437274,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "var sw = new Stopwatch();\nvar ab = \"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ \";\n\n// create\nvar fs = new FileStream(@\"d:\\test.txt\", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, 262144, FileOptions.None);\nsw.Restart();\nfs.Seek(0, SeekOrigin.Begin);\nfor (var i = 0; i < 40000000; i++) fs.Write(ASCIIEncoding.ASCII.GetBytes(ab), 0, ab.Length);\nsw.Stop();\nConsole.WriteLine(\"{0} ms\", sw.Elapsed.TotalMilliseconds);\nfs.Dispose();\n\n// insert\nfs = new FileStream(@\"d:\\test.txt\", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, 262144, FileOptions.None);\nsw.Restart();\nbyte[] b = new byte[262144];\nlong target = 10, offset = fs.Length - b.Length;\nwhile (offset != 0)\n{\n if (offset < 0)\n {\n offset = b.Length - target;\n b = new byte[offset];\n }\n fs.Position = offset; fs.Read(b, 0, b.Length);\n fs.Position = offset + target; fs.Write(b, 0, b.Length);\n offset -= b.Length;\n}\nfs.Position = target; fs.Write(ASCIIEncoding.ASCII.GetBytes(ab), 0, ab.Length);\nsw.Stop();\nConsole.WriteLine(\"{0} ms\", sw.Elapsed.TotalMilliseconds);\n"
},
{
"answer_id": 36748251,
"author": "Fabrizio Stellato",
"author_id": 3042207,
"author_profile": "https://Stackoverflow.com/users/3042207",
"pm_score": 1,
"selected": false,
"text": "// this.Stream is the stream in which you insert data\n\n{\n\nlong position = this.Stream.Position;\n\nlong length = this.Stream.Length;\n\nMemoryStream ms = new MemoryStream();\n\nthis.Stream.Position = 0;\n\nDIUtils.CopyStream(this.Stream, ms, position, progressCallback);\n\nms.Write(data, 0, data.Length);\n\nthis.Stream.Position = position;\n\nDIUtils.CopyStream(this.Stream, ms, this.Stream.Length - position, progressCallback);\n\nthis.Stream = ms;\n\n}\n\n#region Delegates\n\npublic delegate void ProgressCallback(long position, long total);\n\n#endregion\n public static void CopyStream(Stream input, Stream output, long length, DataInspector.ProgressCallback callback)\n{\n long totalsize = input.Length;\n long byteswritten = 0;\n const int size = 32768;\n byte[] buffer = new byte[size];\n int read;\n int readlen = length < size ? (int)length : size;\n while (length > 0 && (read = input.Read(buffer, 0, readlen)) > 0)\n {\n output.Write(buffer, 0, read);\n byteswritten += read;\n length -= read;\n readlen = length < size ? (int)length : size;\n if (callback != null)\n callback(byteswritten, totalsize);\n }\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4337/"
] |
98,497
|
<p>Hi i need to generate 9 digit unique account numbers. Here is my pseudocode:</p>
<pre><code>function generateAccNo()
generate an account number between 100,000,000 and 999,999,999
if the account number already exists in the DB
call generateAccNo() /* recursive call */
else
return new accout number
end if
end function
</code></pre>
<p>The function seems to be working well, however I am a bit worried about the recursive call. </p>
<p>Will this cause any memory leaks (PHP 5 under apache)?</p>
<p>Is this an acceptable way to tackle this problem?</p>
<p>Thanks for your input.</p>
|
[
{
"answer_id": 98513,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 0,
"selected": false,
"text": "function generateAccNo()\n\n while (true) { \n\n generate an account number between 100,000,000 and 999,999,999\n\n if the account number already exists in the DB \n /* do nothing */\n else\n return new accout number\n end if\n }\n\nend function\n"
},
{
"answer_id": 98522,
"author": "Josh Millard",
"author_id": 13600,
"author_profile": "https://Stackoverflow.com/users/13600",
"pm_score": 2,
"selected": false,
"text": "function generateAccNo()\n\n generate an account number between 100,000,000 and 999,999,999\n\n while ( the account number already exists in the DB ) {\n generate new account number;\n }\n return new account number\n\nend function\n"
},
{
"answer_id": 98529,
"author": "Wesley Tarle",
"author_id": 17057,
"author_profile": "https://Stackoverflow.com/users/17057",
"pm_score": 0,
"selected": false,
"text": "lock_db\ndo\n account_num <= generate number\nwhile account_num in db\n\nput row with account_num in db\n\nunlock_db\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
98,559
|
<pre><code>uint color;
bool parsedhex = uint.TryParse(TextBox1.Text, out color);
//where Text is of the form 0xFF0000
if(parsedhex)
//...
</code></pre>
<p>doesn't work. What am i doing wrong?</p>
|
[
{
"answer_id": 98572,
"author": "Nescio",
"author_id": 14484,
"author_profile": "https://Stackoverflow.com/users/14484",
"pm_score": 8,
"selected": true,
"text": "Convert.ToUInt32(hex, 16) //Using ToUInt32 not ToUInt64, as per OP comment\n"
},
{
"answer_id": 98588,
"author": "Corey Ross",
"author_id": 5927,
"author_profile": "https://Stackoverflow.com/users/5927",
"pm_score": 4,
"selected": false,
"text": "string hexNum = \"0xFFFF\";\nstring hexNumWithoutPrefix = hexNum.Substring(2);\n\nuint i;\nbool success = uint.TryParse(hexNumWithoutPrefix, System.Globalization.NumberStyles.HexNumber, null, out i);\n"
},
{
"answer_id": 98592,
"author": "Jeremy Wiebe",
"author_id": 11807,
"author_profile": "https://Stackoverflow.com/users/11807",
"pm_score": 6,
"selected": false,
"text": "TryParse() TryParse NumberStyles.HexNumber NumberStyles.HexNumber 0x &H # uint color;\nvar hex = TextBox1.Text;\n\nif (hex.StartsWith(\"0x\", StringComparison.CurrentCultureIgnoreCase) ||\n hex.StartsWith(\"&H\", StringComparison.CurrentCultureIgnoreCase)) \n{\n hex = hex.Substring(2);\n}\n\nbool parsedSuccessfully = uint.TryParse(hex, \n NumberStyles.HexNumber, \n CultureInfo.CurrentCulture, \n out color);\n"
},
{
"answer_id": 19301980,
"author": "Curtis Yallop",
"author_id": 854342,
"author_profile": "https://Stackoverflow.com/users/854342",
"pm_score": 3,
"selected": false,
"text": " private static bool TryParseHex(string hex, out UInt32 result)\n {\n result = 0;\n\n if (hex == null)\n {\n return false;\n }\n\n try\n {\n result = Convert.ToUInt32(hex, 16);\n\n return true;\n }\n catch (Exception exception)\n {\n return false;\n }\n }\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98559",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1748529/"
] |
98,586
|
<p>I'm looking for an extremely fast atof() implementation on IA32 optimized for US-en locale, ASCII, and non-scientific notation. The windows multithreaded CRT falls down miserably here as it checks for locale changes on every call to isdigit(). Our current best is derived from the best of perl + tcl's atof implementation, and outperforms msvcrt.dll's atof by an order of magnitude. I want to do better, but am out of ideas. The BCD related x86 instructions seemed promising, but I couldn't get it to outperform the perl/tcl C code. Can any SO'ers dig up a link to the best out there? Non x86 assembly based solutions are also welcome.</p>
<p>Clarifications based upon initial answers:</p>
<p>Inaccuracies of ~2 ulp are fine for this application.<br>
The numbers to be converted will arrive in ascii messages over the network in small batches and our application needs to convert them in the lowest latency possible.</p>
|
[
{
"answer_id": 1638340,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "__forceinline __forceinline bool float_scan(const wchar_t* wcs, float* val)\n{\nint hdr=0;\nwhile (wcs[hdr]==L' ')\n hdr++;\n\nint cur=hdr;\n\nbool negative=false;\nbool has_sign=false;\n\nif (wcs[cur]==L'+' || wcs[cur]==L'-')\n{\n if (wcs[cur]==L'-')\n negative=true;\n has_sign=true;\n cur++;\n}\nelse\n has_sign=false;\n\nint quot_digs=0;\nint frac_digs=0;\n\nbool full=false;\n\nwchar_t period=0;\nint binexp=0;\nint decexp=0;\nunsigned long value=0;\n\nwhile (wcs[cur]>=L'0' && wcs[cur]<=L'9')\n{\n if (!full)\n {\n if (value>=0x19999999 && wcs[cur]-L'0'>5 || value>0x19999999)\n {\n full=true;\n decexp++;\n }\n else\n value=value*10+wcs[cur]-L'0';\n }\n else\n decexp++;\n\n quot_digs++;\n cur++;\n}\n\nif (wcs[cur]==L'.' || wcs[cur]==L',')\n{\n period=wcs[cur];\n cur++;\n\n while (wcs[cur]>=L'0' && wcs[cur]<=L'9')\n {\n if (!full)\n {\n if (value>=0x19999999 && wcs[cur]-L'0'>5 || value>0x19999999)\n full=true;\n else\n {\n decexp--;\n value=value*10+wcs[cur]-L'0';\n }\n }\n\n frac_digs++;\n cur++;\n }\n}\n\nif (!quot_digs && !frac_digs)\n return false;\n\nwchar_t exp_char=0;\n\nint decexp2=0; // explicit exponent\nbool exp_negative=false;\nbool has_expsign=false;\nint exp_digs=0;\n\n// even if value is 0, we still need to eat exponent chars\nif (wcs[cur]==L'e' || wcs[cur]==L'E')\n{\n exp_char=wcs[cur];\n cur++;\n\n if (wcs[cur]==L'+' || wcs[cur]==L'-')\n {\n has_expsign=true;\n if (wcs[cur]=='-')\n exp_negative=true;\n cur++;\n }\n\n while (wcs[cur]>=L'0' && wcs[cur]<=L'9')\n {\n if (decexp2>=0x19999999)\n return false;\n decexp2=10*decexp2+wcs[cur]-L'0';\n exp_digs++;\n cur++;\n }\n\n if (exp_negative)\n decexp-=decexp2;\n else\n decexp+=decexp2;\n}\n\n// end of wcs scan, cur contains value's tail\n\nif (value)\n{\n while (value<=0x19999999)\n {\n decexp--;\n value=value*10;\n }\n\n if (decexp)\n {\n // ensure 1bit space for mul by something lower than 2.0\n if (value&0x80000000)\n {\n value>>=1;\n binexp++;\n }\n\n if (decexp>308 || decexp<-307)\n return false;\n\n // convert exp from 10 to 2 (using FPU)\n int E;\n double v=pow(10.0,decexp);\n double m=frexp(v,&E);\n m=2.0*m;\n E--;\n value=(unsigned long)floor(value*m);\n\n binexp+=E;\n }\n\n binexp+=23; // rebase exponent to 23bits of mantisa\n\n\n // so the value is: +/- VALUE * pow(2,BINEXP);\n // (normalize manthisa to 24bits, update exponent)\n while (value&0xFE000000)\n {\n value>>=1;\n binexp++;\n }\n if (value&0x01000000)\n {\n if (value&1)\n value++;\n value>>=1;\n binexp++;\n if (value&0x01000000)\n {\n value>>=1;\n binexp++;\n }\n }\n\n while (!(value&0x00800000))\n {\n value<<=1;\n binexp--;\n }\n\n if (binexp<-127)\n {\n // underflow\n value=0;\n binexp=-127;\n }\n else\n if (binexp>128)\n return false;\n\n //exclude \"implicit 1\"\n value&=0x007FFFFF;\n\n // encode exponent\n unsigned long exponent=(binexp+127)<<23;\n value |= exponent;\n}\n\n// encode sign\nunsigned long sign=negative<<31;\nvalue |= sign;\n\nif (val)\n{\n *(unsigned long*)val=value;\n}\n\nreturn true;\n}\n"
},
{
"answer_id": 10425062,
"author": "Ira Baxter",
"author_id": 120163,
"author_profile": "https://Stackoverflow.com/users/120163",
"pm_score": 2,
"selected": false,
"text": "getchar ptr++ *(start+k)"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6996/"
] |
98,597
|
<p>I use AutoHotKey for Windows macros. Most commonly I use it to define hotkeys that start/focus particular apps, and one to send an instant email message into my ToDo list. I also have an emergency one that kills all of my big memory-hogging apps (Outlook, Firefox, etc).</p>
<p>So, does anyone have any good AHK macros to share?</p>
|
[
{
"answer_id": 100648,
"author": "Eli Bendersky",
"author_id": 8206,
"author_profile": "https://Stackoverflow.com/users/8206",
"pm_score": 4,
"selected": false,
"text": "SetTitleMatchMode RegEx ;\n; Stuff to do when Windows Explorer is open\n;\n#IfWinActive ahk_class ExploreWClass|CabinetWClass\n ; create new folder\n ;\n ^!n::Send !fwf\n\n ; create new text file\n ;\n ^!t::Send !fwt\n\n ; open 'cmd' in the current directory\n ;\n ^!c::\n OpenCmdInCurrent()\n return\n#IfWinActive\n\n; Opens the command shell 'cmd' in the directory browsed in Explorer.\n; Note: expecting to be run when the active window is Explorer.\n;\nOpenCmdInCurrent()\n{\n WinGetText, full_path, A ; This is required to get the full path of the file from the address bar\n\n ; Split on newline (`n)\n StringSplit, word_array, full_path, `n\n full_path = %word_array1% ; Take the first element from the array\n\n ; Just in case - remove all carriage returns (`r)\n StringReplace, full_path, full_path, `r, , all \n full_path := RegExReplace(full_path, \"^Address: \", \"\") ;\n\n IfInString full_path, \\\n {\n Run, cmd /K cd /D \"%full_path%\"\n }\n else\n {\n Run, cmd /K cd /D \"C:\\ \"\n }\n}\n"
},
{
"answer_id": 780626,
"author": "Bård",
"author_id": 89349,
"author_profile": "https://Stackoverflow.com/users/89349",
"pm_score": 3,
"selected": false,
"text": "sleep, 5000\nSoundSet, 1.5 ; really low volume\n"
},
{
"answer_id": 2331289,
"author": "Peter Gfader",
"author_id": 35693,
"author_profile": "https://Stackoverflow.com/users/35693",
"pm_score": 2,
"selected": false,
"text": "#+m:: Run \"mailto:\"\n #^M:: Run \"%ProgramFiles%\\Microsoft Office\\Office12\\OUTLOOK.EXE\" /recycle\n #+A:: Run \"%ProgramFiles%\\Microsoft Office\\Office12\\OUTLOOK.EXE\"/c ipm.appointment\n #+T:: Run \"%ProgramFiles%\\Microsoft Office\\Office12\\OUTLOOK.EXE\"/c ipm.task\n#+K:: Run \"%ProgramFiles%\\Microsoft Office\\Office12\\OUTLOOK.EXE\"/c ipm.task\n"
},
{
"answer_id": 2331297,
"author": "Peter Gfader",
"author_id": 35693,
"author_profile": "https://Stackoverflow.com/users/35693",
"pm_score": 3,
"selected": false,
"text": "; Win + X\n#x:: ; Attention: Strips formatting from the clipboard too!\nSend ^c\nclipboard = \"%clipboard%\"\n; Remove space introduced by WORD\nStringReplace, clipboard, clipboard,%A_SPACE%\",\", All\nSend ^v\nreturn\n"
},
{
"answer_id": 5336476,
"author": "rkagerer",
"author_id": 589059,
"author_profile": "https://Stackoverflow.com/users/589059",
"pm_score": 2,
"selected": false,
"text": "#IfWinActive ;Close active window when mouse button 5 is pressed\n XButton2::\n SendInput {Alt Down}{F4}{Alt Up}\n Return\n#IfWinActive \n ;-----------------------------------------------------------------------------\n; Bind Mouse Button 5 to Close Tab / Close Window command\n;-----------------------------------------------------------------------------\n\n; Create a group to hold windows which will use Ctrl+F4 instead of Alt+F4\nGroupAdd, CtrlCloseGroup, ahk_class IEFrame ; Internet Explorer\nGroupAdd, CtrlCloseGroup, ahk_class Chrome_WidgetWin_0 ; Google Chrome\n; (Add more programs that use tabbed documents here)\nReturn\n\n; For windows in above group, bind mouse button to Ctrl+F4\n#IfWinActive, ahk_group CtrlCloseGroup\n XButton2::\n SendInput {Ctrl Down}{F4}{Ctrl Up}\n Return\n#IfWinActive \n\n; For everything else, bind mouse button to Alt+F4\n#IfWinActive\n XButton2::\n SendInput {Alt Down}{F4}{Alt Up}\n Return\n#IfWinActive \n\n; In FireFox, bind to Ctrl+W instead, so that the close command also works\n; on the Downloads window.\n#IfWinActive, ahk_class MozillaUIWindowClass\n XButton2::\n SendInput {Ctrl Down}w{Ctrl Up}\n Return\n#IfWinActive\n CtrlCloseGroup SetTitleMatchMode, 2 ; Move this line to the top of your script\n\n;-----------------------------------------------------------------------------\n; Visual Studio 2010\n;-----------------------------------------------------------------------------\n\n#IfWinActive, Microsoft Visual Studio\n\n ; Make the middle mouse button jump to the definition of any token\n MButton::\n Click Left ; put the cursor where you clicked\n Send {Shift Down}{F2}{Shift Up}\n Return\n\n ; Make the Back button on the mouse jump you back to the previous area\n ; of code you were working on.\n XButton1::\n Send {Ctrl Down}{Shift Down}{F2}{Shift Up}{Ctrl Up}\n Return\n\n ; Bind the Forward button to close the current tab\n XButton2::\n SendInput {Ctrl Down}{F4}{Ctrl Up}\n Return\n\n#IfWinActive\n"
},
{
"answer_id": 9555021,
"author": "EvanBlack",
"author_id": 394622,
"author_profile": "https://Stackoverflow.com/users/394622",
"pm_score": 4,
"selected": false,
"text": "^SPACE:: Winset, Alwaysontop, , A\n"
},
{
"answer_id": 14455149,
"author": "Johann",
"author_id": 638040,
"author_profile": "https://Stackoverflow.com/users/638040",
"pm_score": 2,
"selected": false,
"text": "SetTimer, FocusOnWindow, 500\nreturn\n\nFocusOnWindow:\nIfWinExist, Confirm File Replace\n WinActivate\nreturn\n Capslock::\nreturn\n ^+c::\nMouseGetPos,x,y\nPixelGetColor,rgb,x,y,RGB\nStringTrimLeft,rgb,rgb,2\nClipboard=%rgb%\nReturn\n #m::\nSend, my@email.com{LWINUP}\nSleep, 100\nSend, {TAB}\nreturn\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98597",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10934/"
] |
98,606
|
<p>What is your favorite Visual Studio keyboard shortcut? I'm always up for leaving my hands on the keyboard and away from the mouse! <br /></p>
<p><strong>One</strong> per answer please.</p>
|
[
{
"answer_id": 98629,
"author": "Eric Schoonover",
"author_id": 3957,
"author_profile": "https://Stackoverflow.com/users/3957",
"pm_score": 5,
"selected": false,
"text": "Collection<string>"
},
{
"answer_id": 98779,
"author": "rbrayb",
"author_id": 9922,
"author_profile": "https://Stackoverflow.com/users/9922",
"pm_score": 6,
"selected": false,
"text": "try try \n{ \n\n}\ncatch (Exception)\n{\n\n throw;\n}\n"
},
{
"answer_id": 162470,
"author": "Herb Caudill",
"author_id": 239663,
"author_profile": "https://Stackoverflow.com/users/239663",
"pm_score": 0,
"selected": false,
"text": "<table> <asp:gridview>"
},
{
"answer_id": 277004,
"author": "Keith Elder",
"author_id": 10624,
"author_profile": "https://Stackoverflow.com/users/10624",
"pm_score": 5,
"selected": false,
"text": "**int** x = 1;\n**int** y = 2;\n**int** z = 3;\n"
},
{
"answer_id": 917439,
"author": "callisto",
"author_id": 67249,
"author_profile": "https://Stackoverflow.com/users/67249",
"pm_score": 1,
"selected": false,
"text": "try..catch #region"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98606",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13791/"
] |
98,610
|
<p>By default, Eclipse won't show my .htaccess file that I maintain in my project. It just shows an empty folder in the Package Viewer tree. How can I get it to show up? No obvious preferences.</p>
|
[
{
"answer_id": 98634,
"author": "scubabbl",
"author_id": 9450,
"author_profile": "https://Stackoverflow.com/users/9450",
"pm_score": 11,
"selected": true,
"text": "Package Explorer -> View Menu -> Filters -> uncheck .* resources Package Explorer -> Customize View -> Filters -> uncheck .* resources\n"
},
{
"answer_id": 26042251,
"author": "kakhkAtion",
"author_id": 3434053,
"author_profile": "https://Stackoverflow.com/users/3434053",
"pm_score": 2,
"selected": false,
"text": "Preferences -> Remote Systems -> Files -> Show hidden files"
},
{
"answer_id": 51046273,
"author": "Saikat",
"author_id": 1594823,
"author_profile": "https://Stackoverflow.com/users/1594823",
"pm_score": 4,
"selected": false,
"text": "Package Explorer Filters... .* resources"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98610",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4223/"
] |
98,622
|
<p>In VisualStudio (Pro 2008), I have just noticed some inconsistent behaviour and wondered if there was any logical reasoning behind it</p>
<p>In a WinForms project, if I use the line</p>
<pre><code>if(myComboBox.Items[i] == myObject)
</code></pre>
<p>I get a compiler warning that I might get 'Possible unintended references' as I am comparing type object to type MyObject. Fair enough.</p>
<p>However, if I instead use an interface to compare against:</p>
<pre><code>if(myComboBox.Items[i] == iMyInterface)
</code></pre>
<p>the compile warning goes away.</p>
<p>Can anyone think if there is any logical reason why this should happen, or just an artifact of the compiler not to check interfaces for comparison warnings. Any thoughts?</p>
<p><strong>EDIT</strong> In my example, the combobox was bound to a List, but that list was generated using <code>list<IMyInterface>.Cast<MyObject>().ToList<MyObject>()</code></p>
<p>Its as if the compiler is only taking still assuming I am binding to the List of IMyInterface.</p>
<p>(Object and Interface methods have been changed to protect the innocent)</p>
|
[
{
"answer_id": 98708,
"author": "Jason Stevenson",
"author_id": 13368,
"author_profile": "https://Stackoverflow.com/users/13368",
"pm_score": 0,
"selected": false,
"text": "myComboBox.DataSource = Collection<Car>;\n if((car)myComboBox.Items[i] == thisCar)\n using(myComboBox.Items[i] as car){\n if(myComboBox.Items[i] == thisCar)\n}\n"
},
{
"answer_id": 171045,
"author": "Danny Tuppeny",
"author_id": 25124,
"author_profile": "https://Stackoverflow.com/users/25124",
"pm_score": 2,
"selected": true,
"text": "class Program\n{\n static void Main(string[] args)\n {\n object t1 = new MyTest() { Key = 1 };\n MyTest t2 = new MyTest() { Key = 1 };\n\n Console.WriteLine((MyTest)t1 == t2); // Uses overriden == operator, returns true\n Console.WriteLine(t1 == t2); // Reference comparison, returns false\n }\n}\n\npublic class MyTest\n{\n public int Key { get; set; }\n\n public override bool Equals(object obj)\n {\n return this.Key == (obj as MyTest).Key;\n }\n\n public override int GetHashCode()\n {\n return this.Key.GetHashCode();\n }\n\n public static bool operator ==(MyTest t1, MyTest t2)\n {\n return t1.Equals(t2);\n }\n\n public static bool operator !=(MyTest t1, MyTest t2)\n {\n return !t1.Equals(t2);\n }\n\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98622",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5302/"
] |
98,650
|
<p>When asking about <a href="https://stackoverflow.com/questions/98340/what-are-the-common-undefinedunspecified-behavior-for-c-that-you-run-into">common undefined behavior in C</a>, people sometimes refer to the strict aliasing rule.<br>
What are they talking about?</p>
|
[
{
"answer_id": 98702,
"author": "Niall",
"author_id": 6049,
"author_profile": "https://Stackoverflow.com/users/6049",
"pm_score": 8,
"selected": false,
"text": "int* int float* float char*"
},
{
"answer_id": 99010,
"author": "Doug T.",
"author_id": 8123,
"author_profile": "https://Stackoverflow.com/users/8123",
"pm_score": 10,
"selected": true,
"text": "uint32_t uint16_t typedef struct Msg\n{\n unsigned int a;\n unsigned int b;\n} Msg;\n\nvoid SendWord(uint32_t);\n\nint main(void)\n{\n // Get a 32-bit buffer from the system\n uint32_t* buff = malloc(sizeof(Msg));\n \n // Alias that buffer through message\n Msg* msg = (Msg*)(buff);\n \n // Send a bunch of messages \n for (int i = 0; i < 10; ++i)\n {\n msg->a = i;\n msg->b = i+1;\n SendWord(buff[0]);\n SendWord(buff[1]); \n }\n}\n buff buff[0] buff[1] buff void SendMessage(uint32_t* buff, size_t size32)\n{\n for (int i = 0; i < size32; ++i) \n {\n SendWord(buff[i]);\n }\n}\n for (int i = 0; i < 10; ++i)\n{\n msg->a = i;\n msg->b = i+1;\n SendMessage(buff, 2);\n}\n SendMessage union {\n Msg msg;\n unsigned int asBuffer[sizeof(Msg)/sizeof(unsigned int)];\n };\n char* char* signed char unsigned char char*"
},
{
"answer_id": 7005988,
"author": "Ben Voigt",
"author_id": 103167,
"author_profile": "https://Stackoverflow.com/users/103167",
"pm_score": 7,
"selected": false,
"text": "char unsigned char char unsigned char"
},
{
"answer_id": 16534243,
"author": "Ingo Blackman",
"author_id": 1917520,
"author_profile": "https://Stackoverflow.com/users/1917520",
"pm_score": 5,
"selected": false,
"text": "#include <stdio.h>\n\nvoid check(short *h,long *k)\n{\n *h=5;\n *k=6;\n if (*h == 5)\n printf(\"strict aliasing problem\\n\");\n}\n\nint main(void)\n{\n long k[1];\n check((short *)k,k);\n return 0;\n}\n gcc -O2 -o check check.c if (*h == 5) movw $5, (%rdi)\nmovq $6, (%rsi)\nmovl $.LC0, %edi\njmp puts\n"
},
{
"answer_id": 43645721,
"author": "supercat",
"author_id": 363751,
"author_profile": "https://Stackoverflow.com/users/363751",
"pm_score": 5,
"selected": false,
"text": "int x;\nint test(double *p)\n{\n x=5;\n *p = 1.0;\n return x;\n}\n x p x *p x void test(void)\n{\n struct S {int x;} s;\n s.x = 1;\n}\n int struct S int struct S int test(int *ip, double *dp)\n{\n *ip = 1;\n *dp = 1.23;\n return *ip;\n}\nint test2(void)\n{\n union U { int i; double d; } u;\n return test(&u.i, &u.d);\n}\n void inc_int(int *p) { *p = 3; }\n int test(void)\n {\n int *p;\n struct S { int x; } s;\n s.x = 1;\n p = &s.x;\n inc_int(p);\n return s.x;\n }\n inc_int *p int test p struct S s p void inc_int(int *p) { *p = 3; }\n int test(void)\n {\n int *p;\n struct S { int x; } s;\n p = &s.x;\n s.x = 1; // !!*!!\n *p += 1;\n return s.x;\n }\n p s.x"
},
{
"answer_id": 47960435,
"author": "Myst",
"author_id": 4025095,
"author_profile": "https://Stackoverflow.com/users/4025095",
"pm_score": 4,
"selected": false,
"text": "restrict int * float * void merge_two_ints(int *a, int *b) {\n *b += *a;\n *a += *b;\n}\n a == b a b a b b a b a a a b void merge_two_numbers(int *a, long *b) {...}\n restrict void merge_two_ints(int * restrict a, int * restrict b) {...}\n restrict a b a b a b a b"
},
{
"answer_id": 51228315,
"author": "Shafik Yaghmour",
"author_id": 1708801,
"author_profile": "https://Stackoverflow.com/users/1708801",
"pm_score": 7,
"selected": false,
"text": "int x = 10;\nint *ip = &x;\n\nstd::cout << *ip << \"\\n\";\n*ip = 12;\nstd::cout << x << \"\\n\";\n int foo( float *f, int *i ) { \n *i = 1;\n *f = 0.f;\n \n return *i;\n}\n\nint main() {\n int x = 0;\n \n std::cout << x << \"\\n\"; // Expect 0\n x = foo(reinterpret_cast<float*>(&x), &x);\n std::cout << x << \"\\n\"; // Expect 0?\n}\n 0\n1\n foo(float*, int*): # @foo(float*, int*)\nmov dword ptr [rsi], 1\nmov dword ptr [rdi], 0\nmov eax, 1\nret\n int x = 1;\nint *p = &x;\nprintf(\"%d\\n\", *p); // *p gives us an lvalue expression of type int which is compatible with int\n int x = 1;\nconst int *p = &x;\nprintf(\"%d\\n\", *p); // *p gives us an lvalue expression of type const int which is compatible with int\n int x = 1;\nunsigned int *p = (unsigned int*)&x;\nprintf(\"%u\\n\", *p ); // *p gives us an lvalue expression of type unsigned int which corresponds to \n // the effective type of the object\n int x = 1;\nconst unsigned int *p = (const unsigned int*)&x;\nprintf(\"%u\\n\", *p ); // *p gives us an lvalue expression of type const unsigned int which is a unsigned type \n // that corresponds with to a qualified version of the effective type of the object\n struct foo {\n int x;\n};\n \nvoid foobar( struct foo *fp, int *ip ); // struct foo is an aggregate that includes int among its members so it\n // can alias with *ip\n\nfoo f;\nfoobar( &f, &f.x );\n int x = 65;\nchar *p = (char *)&x;\nprintf(\"%c\\n\", *p ); // *p gives us an lvalue expression of type char which is a character type.\n // The results are not portable due to endianness issues.\n void *p = malloc( sizeof(int) ); // We have allocated storage but not started the lifetime of an object\nint *ip = new (p) int{0}; // Placement new changes the dynamic type of the object to int\nstd::cout << *ip << \"\\n\"; // *ip gives us a glvalue expression of type int which matches the dynamic type \n // of the allocated object\n int x = 1;\nconst int *cip = &x;\nstd::cout << *cip << \"\\n\"; // *cip gives us a glvalue expression of type const int which is a cv-qualified \n // version of the dynamic type of x\n // Both si and ui are signed or unsigned types corresponding to each others dynamic types\n// We can see from this godbolt(https://godbolt.org/g/KowGXB) the optimizer assumes aliasing.\nsigned int foo( signed int &si, unsigned int &ui ) {\n si = 1;\n ui = 2;\n\n return si;\n}\n signed int foo( const signed int &si1, int &si2); // Hard to show this one assumes aliasing\n struct foo {\n int x;\n};\n\n// Compiler Explorer example(https://godbolt.org/g/z2wJTC) shows aliasing assumption\nint foobar( foo &fp, int &ip ) {\n fp.x = 1;\n ip = 2;\n\n return fp.x;\n}\n\nfoo f;\nfoobar( f, f.x );\n struct foo { int x; };\n\nstruct bar : public foo {};\n\nint foobar( foo &f, bar &b ) {\n f.x = 1;\n b.x = 2;\n\n return f.x;\n}\n int foo( std::byte &b, uint32_t &ui ) {\n b = static_cast<std::byte>('a');\n ui = 0xFFFFFFFF;\n \n return std::to_integer<int>( b ); // b gives us a glvalue expression of type std::byte which can alias\n // an object of type uint32_t\n}\n int x = 1;\n\n// In C\nfloat *fp = (float*)&x; // Not a valid aliasing\n\n// In C++\nfloat *fp = reinterpret_cast<float*>(&x); // Not a valid aliasing\n\nprintf( \"%f\\n\", *fp );\n union u1\n{\n int n;\n float f;\n};\n\nunion u1 u;\nu.f = 1.0f;\n\nprintf( \"%d\\n\", u.n ); // UB in C++ n is not the active member\n static_assert( sizeof( double ) == sizeof( int64_t ) ); // C++17 does not require a message\n void func1( double d ) {\n std::int64_t n;\n std::memcpy(&n, &d, sizeof d);\n //...\n std::cout << bit_cast<float>(0x447a0000) << \"\\n\"; //assuming sizeof(float) == sizeof(unsigned int)\n struct uint_chars {\n unsigned char arr[sizeof( unsigned int )] = {}; // Assume sizeof( unsigned int ) == 4\n};\n\n// Assume len is a multiple of 4 \nint bar( unsigned char *p, size_t len ) {\n int result = 0;\n\n for( size_t index = 0; index < len; index += sizeof(unsigned int) ) {\n uint_chars f;\n std::memcpy( f.arr, &p[index], sizeof(unsigned int));\n unsigned int result = bit_cast<unsigned int>(f);\n\n result += foo( result );\n }\n\n return result;\n}\n int a = 1;\nshort j;\nfloat f = 1.f; // Originally not initialized but tis-kernel caught \n // it was being accessed w/ an indeterminate value below\n\nprintf(\"%i\\n\", j = *(reinterpret_cast<short*>(&a)));\nprintf(\"%i\\n\", j = *(reinterpret_cast<int*>(&f)));\n int *p;\n\np = &a;\nprintf(\"%i\\n\", j = *(reinterpret_cast<short*>(p)));\n int *x = new int[2]; // 8 bytes: [0,7].\nint *u = (int*)((char*)x + 6); // regardless of alignment of x this will not be an aligned address\n*u = 1; // Access to range [6-9]\nprintf( \"%d\\n\", *u ); // Access to range [6-9]\n int a = 1;\nshort j;\nfloat f = 1.0;\n\nprintf(\"%i\\n\", j = *((short*)&a));\nprintf(\"%i\\n\", j = *((int*)&f));\n \nint *p;\n\np = &a;\nprintf(\"%i\\n\", j = *((short*)p));\n ./bin/tis-kernel -sa example1.c \n...\nexample1.c:9:[sa] warning: The pointer (short *)(& a) has type short *. It violates strict aliasing\n rules by accessing a cell with effective type int.\n...\n\nexample1.c:10:[sa] warning: The pointer (int *)(& f) has type int *. It violates strict aliasing rules by\n accessing a cell with effective type float.\n Callstack: main\n...\n\nexample1.c:15:[sa] warning: The pointer (short *)p has type short *. It violates strict aliasing rules by\n accessing a cell with effective type int.\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10703/"
] |
98,687
|
<p>I have developed some custom DAO-like classes to meet some very specialized requirements for my project that is a server-side process that does not run inside any kind of framework. </p>
<p>The solution works great except that every time a new request is made, I open a new connection via MySQLdb.connect. </p>
<p>What is the best "drop in" solution to switch this over to using connection pooling in python? I am imagining something like the commons DBCP solution for Java. </p>
<p>The process is long running and has many threads that need to make requests, but not all at the same time... specifically they do quite a lot of work before brief bursts of writing out a chunk of their results.</p>
<p>Edited to add:
After some more searching I found <a href="http://furius.ca/antiorm/" rel="noreferrer">anitpool.py</a> which looks decent, but as I'm relatively new to python I guess I just want to make sure I'm not missing a more obvious/more idiomatic/better solution. </p>
|
[
{
"answer_id": 98703,
"author": "Chris",
"author_id": 15578,
"author_profile": "https://Stackoverflow.com/users/15578",
"pm_score": 4,
"selected": false,
"text": "import sqlalchemy.pool as pool\nimport MySQLdb as mysql\nmysql = pool.manage(mysql)\n"
},
{
"answer_id": 24741694,
"author": "metaperture",
"author_id": 955854,
"author_profile": "https://Stackoverflow.com/users/955854",
"pm_score": 3,
"selected": false,
"text": "def pool(ctor, limit=None):\n local_pool = multiprocessing.Queue()\n n = multiprocesing.Value('i', 0)\n @contextlib.contextmanager\n def pooled(ctor=ctor, lpool=local_pool, n=n):\n # block iff at limit\n try: i = lpool.get(limit and n.value >= limit)\n except multiprocessing.queues.Empty:\n n.value += 1\n i = ctor()\n yield i\n lpool.put(i)\n return pooled\n # in main:\nmy_pool = pool(lambda: do_something())\n# in thread:\nwith my_pool() as my_obj:\n my_obj.do_something()\n"
},
{
"answer_id": 44476153,
"author": "kilokahn",
"author_id": 8129808,
"author_profile": "https://Stackoverflow.com/users/8129808",
"pm_score": 2,
"selected": false,
"text": "dbconfig = { \"database\": \"test\", \"user\":\"joe\" }\ncnxpool = mysql.connector.pooling.MySQLConnectionPool(pool_name = \"mypool\",pool_size = 3, **dbconfig)\n cnx1 = cnxpool.get_connection()\ncnx2 = cnxpool.get_connection()\n"
},
{
"answer_id": 53246568,
"author": "ospider",
"author_id": 1061155,
"author_profile": "https://Stackoverflow.com/users/1061155",
"pm_score": 1,
"selected": false,
"text": "DBUtils pip install DBUtils\n"
},
{
"answer_id": 72698613,
"author": "mahesh langote",
"author_id": 9153368,
"author_profile": "https://Stackoverflow.com/users/9153368",
"pm_score": 0,
"selected": false,
"text": " from opensearchpy import OpenSearch\n\n def get_connection():\n connection = None\n try:\n connection = OpenSearch(\n hosts=[{'host': settings.OPEN_SEARCH_HOST, 'port': settings.OPEN_SEARCH_PORT}],\n http_compress=True,\n http_auth=(settings.OPEN_SEARCH_USER, settings.OPEN_SEARCH_PASSWORD),\n use_ssl=True,\n verify_certs=True,\n ssl_assert_hostname=False,\n ssl_show_warn=False,\n )\n except Exception as error:\n print(\"Error: Connection not established {}\".format(error))\n else:\n print(\"Connection established\")\n return connection\n\n class OpenSearchClient(object):\n connection_pool = []\n connection_in_use = []\n\n def __init__(self):\n if OpenSearchClient.connection_pool:\n pass\n else:\n\n OpenSearchClient.connection_pool = [get_connection() for i in range(0, settings.CONNECTION_POOL_SIZE)]\n\n def search_data(self, query=\"\", index_name=settings.OPEN_SEARCH_INDEX):\n available_cursor = OpenSearchClient.connection_pool.pop(0)\n OpenSearchClient.connection_in_use.append(available_cursor)\n response = available_cursor.search(body=query, index=index_name)\n available_cursor.close()\n OpenSearchClient.connection_pool.append(available_cursor)\n OpenSearchClient.connection_in_use.pop(-1)\n return response\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98687",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2168/"
] |
98,693
|
<p>First of all, I don't need a textual comparison so Beyond Compare doesn't do what I need.</p>
<p>I'm looking for a util that can report on the differences between two files, at the byte level. Bare minimum is the need to see the percentage change in the file, or a report on affected bytes/sectors. </p>
<p>Is there anything available to save me the trouble of doing this myself?</p>
|
[
{
"answer_id": 98723,
"author": "Steve Moyer",
"author_id": 17008,
"author_profile": "https://Stackoverflow.com/users/17008",
"pm_score": 2,
"selected": false,
"text": "hexdump file1 > file1.tmp\nhexdump file2 > file2.tmp\ndiff file1.tmp file2.tmp\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98693",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13132/"
] |
98,705
|
<p>I understand that the function is not allowed to change the state of the object, but I thought I read somewhere that the compiler was allowed to assume that if the function was called with the same arguments, it would return the same value and thus could reuse a cached value if it was available. e.g.</p>
<pre><code>class object
{
int get_value(int n) const
{
...
}
...
object x;
int a = x.get_value(1);
...
int b = x.get_value(1);
</code></pre>
<p>then the compiler could optimize the second call away and either use the value in a register or simply do <code>b = a;</code></p>
<p>Is this true?</p>
|
[
{
"answer_id": 98762,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 2,
"selected": false,
"text": "const this const this const pure __attribute__((pure))"
},
{
"answer_id": 98787,
"author": "blackwing",
"author_id": 9107,
"author_profile": "https://Stackoverflow.com/users/9107",
"pm_score": 2,
"selected": false,
"text": "const"
},
{
"answer_id": 98804,
"author": "Statement",
"author_id": 2166173,
"author_profile": "https://Stackoverflow.com/users/2166173",
"pm_score": 2,
"selected": false,
"text": "int something() const { return m_pSomeObject->NextValue(); }\n"
},
{
"answer_id": 100593,
"author": "Anthony Williams",
"author_id": 5597,
"author_profile": "https://Stackoverflow.com/users/5597",
"pm_score": 6,
"selected": true,
"text": "const const const const X this X const * X const mutable const const mutable const const class X\n{\n int data;\n mutable boost::mutex m;\npublic:\n void set_data(int i)\n {\n boost::lock_guard<boost::mutex> lk(m);\n data=i;\n }\n int get_data() const // we want to be able to get the data on a const object\n {\n boost::lock_guard<boost::mutex> lk(m); // this requires m to be non-const\n return data;\n }\n};\n std::auto_ptr boost::shared_ptr const const constexpr constexpr"
},
{
"answer_id": 106578,
"author": "nobody",
"author_id": 19405,
"author_profile": "https://Stackoverflow.com/users/19405",
"pm_score": 0,
"selected": false,
"text": "class Foo\n{\npublic:\n int bar() const\n {\n static int x = 0;\n return x++;\n }\n};\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98705",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4086/"
] |
98,739
|
<p>Should entities have behavior? or not?</p>
<p>Why or why not?</p>
<p>If not, does that violate Encapsulation?</p>
|
[
{
"answer_id": 5527174,
"author": "Eduard",
"author_id": 689450,
"author_profile": "https://Stackoverflow.com/users/689450",
"pm_score": 3,
"selected": false,
"text": "book.Write(); \nbook.Print(); \nbook.Publish(); \nbook.Buy(); \nbook.Open(); \nbook.Read(); \nbook.Highlight(); \nbook.Bookmark(); \nbook.GetRelatedBooks(); \n Book book = author.WriteBook(); \nprinter.Print(book); \npublisher.Publish(book); \ncustomer.Buy(book); \n \nreader = new BookReader(); \n \nreader.Open(Book); \n \nreader.Read(); \nreader.Highlight(); \nreader.Bookmark(); \n \nlibrarian.GetRelatedBooks(book); \n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18175/"
] |
98,768
|
<p>I can understand that imposing a minimum length on passwords makes a lot of sense (to save users from themselves), but my <strong>bank</strong> has a requirement that passwords are between 6 and 8 characters long, and I started wondering...</p>
<ul>
<li>Wouldn't this just make it easier for brute force attacks? (Bad)</li>
<li>Does this imply that my password is being stored unencrypted? (Bad)</li>
</ul>
<p>If someone with (hopefully) some good IT security professionals working for them are imposing a max password length, should I think about doing similar? What are the pros/cons of this?</p>
|
[
{
"answer_id": 72495962,
"author": "dewd",
"author_id": 2298108,
"author_profile": "https://Stackoverflow.com/users/2298108",
"pm_score": 0,
"selected": false,
"text": "password_hash() password_verify()"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98768",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9021/"
] |
98,774
|
<p>I am creating a downloading application and I wish to preallocate room on the harddrive for the files before they are actually downloaded as they could potentially be rather large, and noone likes to see "This drive is full, please delete some files and try again." So, in that light, I wrote this.</p>
<pre><code>// Quick, and very dirty
System.IO.File.WriteAllBytes(filename, new byte[f.Length]);
</code></pre>
<p>It works, atleast until you download a file that is several hundred MB's, or potentially even GB's and you throw Windows into a thrashing frenzy if not totally wipe out the pagefile and kill your systems memory altogether. Oops.</p>
<p>So, with a little more enlightenment, I set out with the following algorithm.</p>
<pre><code>using (FileStream outFile = System.IO.File.Create(filename))
{
// 4194304 = 4MB; loops from 1 block in so that we leave the loop one
// block short
byte[] buff = new byte[4194304];
for (int i = buff.Length; i < f.Length; i += buff.Length)
{
outFile.Write(buff, 0, buff.Length);
}
outFile.Write(buff, 0, f.Length % buff.Length);
}
</code></pre>
<p>This works, well even, and doesn't suffer the crippling memory problem of the last solution. It's still slow though, especially on older hardware since it writes out (potentially GB's worth of) data out to the disk.</p>
<p>The question is this: Is there a better way of accomplishing the same thing? Is there a way of telling Windows to create a file of x size and simply allocate the space on the filesystem rather than actually write out a tonne of data. I don't care about initialising the data in the file at all (the protocol I'm using - bittorrent - provides hashes for the files it sends, hence worst case for random uninitialised data is I get a lucky coincidence and part of the file is correct).</p>
|
[
{
"answer_id": 98822,
"author": "Mark",
"author_id": 4405,
"author_profile": "https://Stackoverflow.com/users/4405",
"pm_score": 3,
"selected": false,
"text": "using (FileStream outFile = System.IO.File.Create(filename))\n{\n outFile.Seek(<length_to_write>-1, SeekOrigin.Begin);\n OutFile.WriteByte(0);\n}\n"
},
{
"answer_id": 98838,
"author": "Doug McClean",
"author_id": 11173,
"author_profile": "https://Stackoverflow.com/users/11173",
"pm_score": 6,
"selected": true,
"text": "public override void SetLength(\n long value\n)\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98774",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15537/"
] |
98,778
|
<p>I need to execute a batch file as part of the un-install process in a Windows installer project (standard OOTB VS 2008 installer project-vdproj). One cannot execute a bat file directly from the Custom Actions in the installer project, so I wrote a quick vbs script to call the required bat file.<br>
vbs code: </p>
<pre><code>Set WshShell = WScript.CreateObject( "WScript.Shell" )
command = "uninstall-windows-serivce.bat"
msgbox command
WshShell.Run ("cmd /C " & """" & command & """")
Set WshShell = Nothing
</code></pre>
<p>When this script is run independent of the uninstall, it works perfectly. However, when run as part of the uninstall, it does not execute the bat file (but the message box is shown, so I know the vbs file is called). No errors reported (at least that I can tell). Why doesn't this script work as part of the "Uninstall Custom Action"</p>
|
[
{
"answer_id": 98839,
"author": "Mike L",
"author_id": 12085,
"author_profile": "https://Stackoverflow.com/users/12085",
"pm_score": 0,
"selected": false,
"text": " Public Overrides Sub Uninstall(ByVal savedState As System.Collections.IDictionary)\n MyBase.Uninstall(savedState)\n 'Shell to batch file here\n End Sub\n"
},
{
"answer_id": 123766,
"author": "JustinD",
"author_id": 12063,
"author_profile": "https://Stackoverflow.com/users/12063",
"pm_score": 3,
"selected": false,
"text": "Set WshShell = CreateObject( \"WScript.Shell\" )\ncommand = \"uninstall-windows-serivce.bat\"\nmsgbox command\nWshShell.Run (\"cmd /C \" & \"\"\"\" & command & \"\"\"\")\nSet WshShell = Nothing\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98778",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18449/"
] |
98,827
|
<p>I'm looking for a method to assign variables with patterns in regular expressions with C++ .NET
something like </p>
<pre><code>String^ speed;
String^ size;
</code></pre>
<p>"command SPEED=[speed] SIZE=[size]"</p>
<p>Right now I'm using IndexOf() and Substring() but it is quite ugly</p>
|
[
{
"answer_id": 98946,
"author": "user10392",
"author_id": 10392,
"author_profile": "https://Stackoverflow.com/users/10392",
"pm_score": 0,
"selected": false,
"text": "foreach (FieldInfo f in typeof(InputArgs).GetFields()) {\n string = Regex.replace(\"\\\\[\" + f.Name + \"\\\\]\",\n f.GetValue(InputArgs).ToString());\n}\n"
},
{
"answer_id": 99048,
"author": "Sparr",
"author_id": 13675,
"author_profile": "https://Stackoverflow.com/users/13675",
"pm_score": 3,
"selected": true,
"text": "String^ speed; String^ size;\nMatch m;\nRegex theregex = new Regex (\n \"SPEED=(?<speed>(.*?)) SIZE=(?<size>(.*?)) \",\n RegexOptions::ExplicitCapture);\nm = theregex.Match (yourinputstring);\nif (m.Success)\n{\n if (m.Groups[\"speed\"].Success)\n speed = m.Groups[\"speed\"].Value;\n if (m.Groups[\"size\"].Success)\n size = m.Groups[\"size\"].Value;\n}\nelse\n throw new FormatException (\"Input options not recognized\");\n"
},
{
"answer_id": 99114,
"author": "jon",
"author_id": 12215,
"author_profile": "https://Stackoverflow.com/users/12215",
"pm_score": 2,
"selected": false,
"text": "Pattern pattern = Pattern.compile(\"command SPEED=(\\d+) SIZE=(\\d+)\");\nMatcher matcher = pattern.matcher(inputStr);\nif (matcher.find()) {\n speed = matcher.group(1);\n size = matcher.group(2);\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98827",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6367/"
] |
98,859
|
<p>Does Information Hiding mean I should minimize the number of properties my classes have? Is that right? Do you tend to make your classes private fields with methods?</p>
|
[
{
"answer_id": 98939,
"author": "Benjamin Autin",
"author_id": 1440933,
"author_profile": "https://Stackoverflow.com/users/1440933",
"pm_score": 0,
"selected": false,
"text": "private int _myInt;\npublic int MyInt\n{\n get { return _myInt; }\n set { _myInt = value; }\n}\n public int MyInt { get; set; }\n public int MyInt\n{\n get { return _myInt; }\n set\n {\n _myInt = (value % 2 == 0) ? value : _myInt;\n }\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98859",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18175/"
] |
98,867
|
<p>In c#, we have interfaces. Where did these come from? They didn't exist in c++.</p>
|
[
{
"answer_id": 98881,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 2,
"selected": false,
"text": "public class Dog : Animal, IMammal\n public class Dog extends Animal implements IMammal\n"
},
{
"answer_id": 98891,
"author": "Statement",
"author_id": 2166173,
"author_profile": "https://Stackoverflow.com/users/2166173",
"pm_score": 0,
"selected": false,
"text": "class IFoo\n{\npublic:\n void Bar() =0;\n void Bar2() =0;\n};\n\nclass Concrete : public IFoo\n{\npublic:\n void Bar() { ... }\n void Bar2() { ... }\n}\n"
},
{
"answer_id": 100150,
"author": "Max Galkin",
"author_id": 2351099,
"author_profile": "https://Stackoverflow.com/users/2351099",
"pm_score": 0,
"selected": false,
"text": "class IExecutable\n{\npublic:\n virtual void Execute() = 0;\n};\n\nclass MyClass : public IExecutable\n{\npublic:\n void Execute() { return; };\n};\n public interface IPurring\n{\n void Purr();\n}\n\npublic class Cat : Animal, IPurring\n{\n public Cat(bool _isAlive)\n {\n isAlive = _isAlive;\n }\n\n #region IPurring Members\n\n public void Purr()\n {\n //implement purring\n }\n\n #endregion\n}\n"
},
{
"answer_id": 478903,
"author": "BBetances",
"author_id": 53599,
"author_profile": "https://Stackoverflow.com/users/53599",
"pm_score": 1,
"selected": false,
"text": "static string Method(int i)\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98867",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18175/"
] |
98,878
|
<p>I've always been wondering how people use CRC (class responsiblity collaboration) cards. I've read about them in books, found vague information on the internet, but never grasped it really. I think someone ought to make a youtube video showing a session with CRC cards, since one of my books described it as being very hard to formulate in text, that it should be "taught by someone who already masters it". Sadly, I know noone around here who uses CRC cards and I'd like to learn more.</p>
<h2>UPDATE</h2>
<p>Any links to videos showing people elaborating with this technique would be appreciated.</p>
|
[
{
"answer_id": 99384,
"author": "Robert Gould",
"author_id": 15124,
"author_profile": "https://Stackoverflow.com/users/15124",
"pm_score": 3,
"selected": false,
"text": "///////////////////////\n//* CRC CARD\n//* Class: UISliderEvent\n//* Responsability: Event that holds the value and id of a Slider's movement\n//* Collaborators: UISlider, UIEvent\n//////////////////////\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98878",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2166173/"
] |
98,895
|
<p>I'm having problems refreshing .Net 2.0 with IIS 6.</p>
<p>I have been able to successfully execute "aspnet_regiis.exe -i", but when I try to register the aspnet_isapi.dll:</p>
<pre><code>regsvr32 “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"
</code></pre>
<p>I get the error</p>
<blockquote>
<p>C:\Windows..\aspnet_isapi.dll was loaded, but the DllRegisterServer entry point was not found.</p>
<p>The file cannot be registered.</p>
</blockquote>
<p>Does anyone know how to resolve this? Google hasn't been very helpful.</p>
<p><strong>Edit:</strong> My problem is actually that IIS isn't serving my webpages properly - that is, it's returning 404s when I try to request .aspx files that I know exist.</p>
<p>I can access .gif and .js files OK, but I can't access .aspx or other .Net files. I know this is related to .Net being properly configured with IIS, and the above commands are supposed to be the solution, but the second command doesn't work.</p>
<p><strong>@aaronjensen</strong>: Your command to register scripts worked successfully, and investigating the logs I find that I'm getting an entry for my failed request with status 404, substatus 2.</p>
<p>Microsoft tells me this because "<a href="http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/0f4ac79a-dc2b-4a5f-89c1-d57266aa6ffe.mspx?mfr=true" rel="nofollow noreferrer">Lockdown Policy Prevents This Request</a>".</p>
<blockquote>
<p>If a request is denied because the
associated ISAPI or CGI has not been
unlocked, a 404.2 error is returned.</p>
</blockquote>
<p>Which I assume is due to the isapi DLL in my original query being denied?</p>
|
[
{
"answer_id": 1052042,
"author": "Dexter",
"author_id": 10717,
"author_profile": "https://Stackoverflow.com/users/10717",
"pm_score": 3,
"selected": true,
"text": "C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\aspnet_regiis -s /w3svc/1/root"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10717/"
] |
98,901
|
<p>In any language really, im looking for a simple (very simple) way to control the position of a shortcut on the users desktop. I already make the assumption that Auto Arrange and Align to Grid are unchecked.</p>
<p>Ex: The program creates the shortcut to the desktop than places it at position (450,302) on the desktop. </p>
<p>I know how to create shortcuts, but i dont know how to control their placement on the desktop.</p>
|
[
{
"answer_id": 1052042,
"author": "Dexter",
"author_id": 10717,
"author_profile": "https://Stackoverflow.com/users/10717",
"pm_score": 3,
"selected": true,
"text": "C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\aspnet_regiis -s /w3svc/1/root"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98901",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18431/"
] |
98,915
|
<p>I realize that this question has been <a href="https://stackoverflow.com/questions/10293/has-anyone-used-jaxer-in-production">asked before</a>, but it has been a month with no decent responses... I'm looking at <a href="http://web.archive.org/web/20090803092709/http://www.aptana.com:80/Jaxer" rel="nofollow noreferrer">Aptana's Jaxer</a> and I find the concept to be very exciting.</p>
<p>Here is a quick overview for those who are not familiar with it:</p>
<p>Jaxer is, in their words, "the world's first true AJAX server". It is based on the Mozilla engine so scripts are written with javascript and you have complete access to the DOM on the server-side. </p>
<p>Scripts are placed on your pages with <code><script></code> tags and you can specify a <code>runat</code> attribute (ala ASP.NET) to mark scripts for execution on the client, server, both, or as a "server-proxy" which makes the functions available on the client, but they execute on the server via AJAX. This also means that you can use your favorite client-side libraries (jQuery, Prototype) on the server as well as the client.</p>
<p>It also can be used to process documents that are generated in another language (e.g. php, ruby) which I imagine is not practical except to help in transitioning existing applications to use Jaxer.</p>
<ul>
<li>What are the pros and cons?</li>
<li>How mature/stable is it the API?</li>
<li>How good is performance compared to
other server-side html
preprocessors?</li>
<li>Has anyone used Jaxer with another
technology (php, pearl, ruby, etc.)
and what were your experiences?</li>
</ul>
<p>EDIT: I've posted another question regarding a drawback I discovered while playing with Jaxer: <a href="https://stackoverflow.com/questions/109762/defining-objects-when-using-jaxer">Defining objects when using Jaxer</a></p>
|
[
{
"answer_id": 105555,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<jaxer:include"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98915",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5628/"
] |
98,916
|
<p>How do you programmatically find the number of hosts that a netmask supports.</p>
<p>Eg, If you have a /30 , how do you find how many IP's are in it without using a lookup table?</p>
<p>Preferably would be able to work with the "/" notation, rather than 255.xxx.xxx.xxx notation.</p>
|
[
{
"answer_id": 98935,
"author": "Aaron Maenpaa",
"author_id": 2603,
"author_profile": "https://Stackoverflow.com/users/2603",
"pm_score": 2,
"selected": false,
"text": ">>> def number_of_hosts(n):\n... return 2 ** (32 - n)\n... \n>>> number_of_hosts(32)\n1\n>>> number_of_hosts(30)\n4\n"
},
{
"answer_id": 9394944,
"author": "SHEEN",
"author_id": 1225814,
"author_profile": "https://Stackoverflow.com/users/1225814",
"pm_score": 2,
"selected": false,
"text": " package com.test;\n\nimport java.net.InetAddress;\nimport java.net.NetworkInterface;\nimport java.net.SocketException;\nimport java.net.UnknownHostException;\nimport java.util.Enumeration;\n\npublic class EasyNet {\n\n /**\n * @param args\n */\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n\n try {\n InetAddress localhost = InetAddress.getLocalHost();\n System.out.println(\" IP Addr: \" + localhost.getHostAddress());\n // Just in case this host has multiple IP addresses....\n InetAddress[] allMyIps = InetAddress.getAllByName(localhost.getCanonicalHostName());\n if (allMyIps != null && allMyIps.length > 1) {\n System.out.println(\" Full list of IP addresses:\");\n for (int i = 0; i < allMyIps.length; i++) {\n System.out.println(\" \" + allMyIps[i]);\n }\n }\n } catch (UnknownHostException e) {\n System.out.println(\" (error retrieving server host name)\");\n }\n\n try {\n System.out.println(\"Full list of Network Interfaces:\");\n for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {\n NetworkInterface intf = en.nextElement();\n System.out.println(\" \" + intf.getName() + \" \" + intf.getDisplayName());\n for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) \n {\n System.out.println(\" \" + enumIpAddr.nextElement().toString());\n }\n }\n } catch (SocketException e) {\n System.out.println(\" (error retrieving network interface list)\");\n }\n }\n\n}\n package com.test;\n\nimport java.net.*;\nimport java.util.*;\n\npublic class GetIp {\n\n public static void main(String args[]) throws Exception {\n\n Enumeration<NetworkInterface> nets = \n NetworkInterface.getNetworkInterfaces();\n\n for (NetworkInterface netint : Collections.list(nets)) {\n System.out.println(\"\\nDisplay name : \" + netint.getDisplayName());\n\n Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();\n\n for (InetAddress inetAddress : Collections.list(inetAddresses)) {\n\n System.out.println(\"InetAddress : \" + inetAddress);\n }\n }\n }\n}\n package com.test;\n\nimport java.io.IOException;\nimport java.net.InetAddress;\n\npublic class Nethosts {\n\n /**\n * @param args\n */\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n try{\n InetAddress localhost = InetAddress.getLocalHost();\n // this code assumes IPv4 is used\n byte[] ip = localhost.getAddress();\n checkHosts(ip.toString());\n }\n catch(Exception e){\n e.printStackTrace();\n }\n\n\n }\n public static void checkHosts(String subnet){\n int timeout=1000;\n for (int i=1;i<254;i++){\n try{\n String host=subnet + \".\" + i;\n if (InetAddress.getByName(host).isReachable(timeout)){\n System.out.println(host + \" is reachable\");\n }\n }\n catch(IOException e){e.printStackTrace();}\n }\n }\n}\n package com.test;\n\nimport java.awt.List;\nimport java.net.InetAddress;\nimport java.net.InterfaceAddress;\nimport java.net.NetworkInterface;\nimport java.net.SocketException;\nimport java.net.UnknownHostException;\nimport java.util.ArrayList;\nimport java.util.Enumeration;\n\npublic class Netintr {\n\n /**\n * @param args\n */\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n try\n {\n System.out.println(\"Output of Network Interrogation:\");\n System.out.println(\"********************************\\n\");\n\n InetAddress theLocalhost = InetAddress.getLocalHost();\n System.out.println(\" LOCALHOST INFO\");\n if(theLocalhost != null)\n {\n System.out.println(\" host: \" + theLocalhost.getHostName());\n System.out.println(\" class: \" + theLocalhost.getClass().getSimpleName());\n System.out.println(\" ip: \" + theLocalhost.getHostAddress());\n System.out.println(\" chost: \" + theLocalhost.getCanonicalHostName());\n System.out.println(\" byteaddr: \" + toMACAddrString(theLocalhost.getAddress()));\n System.out.println(\" sitelocal?: \" + theLocalhost.isSiteLocalAddress());\n System.out.println(\"\");\n }\n else\n {\n System.out.println(\" localhost was null\");\n }\n\n Enumeration<NetworkInterface> theIntfList = NetworkInterface.getNetworkInterfaces();\n ArrayList<InterfaceAddress> theAddrList = null;\n NetworkInterface theIntf = null;\n InetAddress theAddr = null;\n\n while(theIntfList.hasMoreElements())\n {\n theIntf = theIntfList.nextElement();\n\n System.out.println(\"--------------------\");\n System.out.println(\" \" + theIntf.getDisplayName());\n System.out.println(\" name: \" + theIntf.getName());\n System.out.println(\" mac: \" + toMACAddrString(theIntf.getHardwareAddress()));\n System.out.println(\" mtu: \" + theIntf.getMTU());\n System.out.println(\" mcast?: \" + theIntf.supportsMulticast());\n System.out.println(\" loopback?: \" + theIntf.isLoopback());\n System.out.println(\" ptp?: \" + theIntf.isPointToPoint());\n System.out.println(\" virtual?: \" + theIntf.isVirtual());\n System.out.println(\" up?: \" + theIntf.isUp());\n\n theAddrList = (ArrayList<InterfaceAddress>) theIntf.getInterfaceAddresses();\n System.out.println(\" int addrs: \" + theAddrList.size() + \" total.\");\n int addrindex = 0;\n for(InterfaceAddress intAddr : theAddrList)\n {\n addrindex++;\n theAddr = intAddr.getAddress();\n System.out.println(\" \" + addrindex + \").\");\n System.out.println(\" host: \" + theAddr.getHostName());\n System.out.println(\" class: \" + theAddr.getClass().getSimpleName());\n System.out.println(\" ip: \" + theAddr.getHostAddress() + \"/\" + intAddr.getNetworkPrefixLength());\n System.out.println(\" bcast: \" + intAddr.getBroadcast().getHostAddress());\n int maskInt = Integer.MIN_VALUE >> (intAddr.getNetworkPrefixLength()-1);\n System.out.println(\" mask: \" + toIPAddrString(maskInt));\n System.out.println(\" chost: \" + theAddr.getCanonicalHostName());\n System.out.println(\" byteaddr: \" + toMACAddrString(theAddr.getAddress()));\n System.out.println(\" sitelocal?: \" + theAddr.isSiteLocalAddress());\n System.out.println(\"\");\n }\n }\n }\n catch (SocketException e)\n {\n e.printStackTrace();\n }\n catch (UnknownHostException e)\n {\n e.printStackTrace();\n }\n\n }\n\n\n public static String toMACAddrString(byte[] a) { if (a == null) { return \"null\"; } int iMax = a.length - 1;\n\n if (iMax == -1)\n {\n return \"[]\";\n }\n\n StringBuilder b = new StringBuilder();\n b.append('[');\n for (int i = 0;; i++)\n {\n b.append(String.format(\"%1$02x\", a[i]));\n\n if (i == iMax)\n {\n return b.append(']').toString();\n }\n b.append(\":\");\n }\n }\n\n public static String toIPAddrString(int ipa)\n {\n StringBuilder b = new StringBuilder();\n b.append(Integer.toString(0x000000ff & (ipa >> 24)));\n b.append(\".\");\n b.append(Integer.toString(0x000000ff & (ipa >> 16)));\n b.append(\".\");\n b.append(Integer.toString(0x000000ff & (ipa >> 8)));\n b.append(\".\");\n b.append(Integer.toString(0x000000ff & (ipa)));\n return b.toString();\n }\n\n}\n package com.test;\n\nimport java.io.IOException;\nimport java.net.InetAddress;\n\npublic class NetworkPing {\n\n /**\n * JavaProgrammingForums.com\n */\n public static void main(String[] args) throws IOException {\n\n InetAddress localhost = InetAddress.getLocalHost();\n // this code assumes IPv4 is used\n byte[] ip = localhost.getAddress();\n\n for (int i = 1; i <= 254; i++)\n {\n ip[3] = (byte)i;\n InetAddress address = InetAddress.getByAddress(ip);\n if (address.isReachable(1000))\n {\n System.out.println(address + \" machine is turned on and can be pinged\");\n }\n else if (!address.getHostAddress().equals(address.getHostName()))\n {\n //hostName is the Machine name and hostaddress is the ip addr\n System.out.println(address + \" machine is known in a DNS lookup\");\n }\n else\n {\n System.out.println(address + \" the host address and host name are equal, meaning the host name could not be resolved\");\n }\n }\n\n }\n}\n package com.test;\n\nimport java.net.*;\nimport java.util.*;\n\npublic class NIC {\n\npublic static void main(String args[]) throws Exception {\n\n List<InetAddress> addrList = new ArrayList<InetAddress>();\n Enumeration<NetworkInterface> interfaces = null;\n try {\n interfaces = NetworkInterface.getNetworkInterfaces();\n } catch (SocketException e) {\n e.printStackTrace();\n }\n\n InetAddress localhost = null;\n\n try {\n localhost = InetAddress.getByName(\"127.0.0.1\");\n } catch (UnknownHostException e) {\n e.printStackTrace();\n }\n\n while (interfaces.hasMoreElements()) {\n NetworkInterface ifc = interfaces.nextElement();\n Enumeration<InetAddress> addressesOfAnInterface = ifc.getInetAddresses();\n\n while (addressesOfAnInterface.hasMoreElements()) {\n InetAddress address = addressesOfAnInterface.nextElement();\n\n if (!address.equals(localhost) && !address.toString().contains(\":\")) {\n addrList.add(address);\n System.out.println(\"FOUND ADDRESS ON NIC: \" + address.getHostAddress());\n }\n }\n }\n\n}\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98916",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3839/"
] |
98,930
|
<p>In an environment with multiple windows servers what is the best way to ensure patch compliance accross all systems? </p>
<p>Is there a simple tool (some sort of client/server app?) that allows reports to be generated showing the status of all the systems so any that aren't automatically patching themselves can be fixed without having to manually check each systemevery time an audit is needed?</p>
|
[
{
"answer_id": 98935,
"author": "Aaron Maenpaa",
"author_id": 2603,
"author_profile": "https://Stackoverflow.com/users/2603",
"pm_score": 2,
"selected": false,
"text": ">>> def number_of_hosts(n):\n... return 2 ** (32 - n)\n... \n>>> number_of_hosts(32)\n1\n>>> number_of_hosts(30)\n4\n"
},
{
"answer_id": 9394944,
"author": "SHEEN",
"author_id": 1225814,
"author_profile": "https://Stackoverflow.com/users/1225814",
"pm_score": 2,
"selected": false,
"text": " package com.test;\n\nimport java.net.InetAddress;\nimport java.net.NetworkInterface;\nimport java.net.SocketException;\nimport java.net.UnknownHostException;\nimport java.util.Enumeration;\n\npublic class EasyNet {\n\n /**\n * @param args\n */\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n\n try {\n InetAddress localhost = InetAddress.getLocalHost();\n System.out.println(\" IP Addr: \" + localhost.getHostAddress());\n // Just in case this host has multiple IP addresses....\n InetAddress[] allMyIps = InetAddress.getAllByName(localhost.getCanonicalHostName());\n if (allMyIps != null && allMyIps.length > 1) {\n System.out.println(\" Full list of IP addresses:\");\n for (int i = 0; i < allMyIps.length; i++) {\n System.out.println(\" \" + allMyIps[i]);\n }\n }\n } catch (UnknownHostException e) {\n System.out.println(\" (error retrieving server host name)\");\n }\n\n try {\n System.out.println(\"Full list of Network Interfaces:\");\n for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {\n NetworkInterface intf = en.nextElement();\n System.out.println(\" \" + intf.getName() + \" \" + intf.getDisplayName());\n for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) \n {\n System.out.println(\" \" + enumIpAddr.nextElement().toString());\n }\n }\n } catch (SocketException e) {\n System.out.println(\" (error retrieving network interface list)\");\n }\n }\n\n}\n package com.test;\n\nimport java.net.*;\nimport java.util.*;\n\npublic class GetIp {\n\n public static void main(String args[]) throws Exception {\n\n Enumeration<NetworkInterface> nets = \n NetworkInterface.getNetworkInterfaces();\n\n for (NetworkInterface netint : Collections.list(nets)) {\n System.out.println(\"\\nDisplay name : \" + netint.getDisplayName());\n\n Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();\n\n for (InetAddress inetAddress : Collections.list(inetAddresses)) {\n\n System.out.println(\"InetAddress : \" + inetAddress);\n }\n }\n }\n}\n package com.test;\n\nimport java.io.IOException;\nimport java.net.InetAddress;\n\npublic class Nethosts {\n\n /**\n * @param args\n */\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n try{\n InetAddress localhost = InetAddress.getLocalHost();\n // this code assumes IPv4 is used\n byte[] ip = localhost.getAddress();\n checkHosts(ip.toString());\n }\n catch(Exception e){\n e.printStackTrace();\n }\n\n\n }\n public static void checkHosts(String subnet){\n int timeout=1000;\n for (int i=1;i<254;i++){\n try{\n String host=subnet + \".\" + i;\n if (InetAddress.getByName(host).isReachable(timeout)){\n System.out.println(host + \" is reachable\");\n }\n }\n catch(IOException e){e.printStackTrace();}\n }\n }\n}\n package com.test;\n\nimport java.awt.List;\nimport java.net.InetAddress;\nimport java.net.InterfaceAddress;\nimport java.net.NetworkInterface;\nimport java.net.SocketException;\nimport java.net.UnknownHostException;\nimport java.util.ArrayList;\nimport java.util.Enumeration;\n\npublic class Netintr {\n\n /**\n * @param args\n */\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n try\n {\n System.out.println(\"Output of Network Interrogation:\");\n System.out.println(\"********************************\\n\");\n\n InetAddress theLocalhost = InetAddress.getLocalHost();\n System.out.println(\" LOCALHOST INFO\");\n if(theLocalhost != null)\n {\n System.out.println(\" host: \" + theLocalhost.getHostName());\n System.out.println(\" class: \" + theLocalhost.getClass().getSimpleName());\n System.out.println(\" ip: \" + theLocalhost.getHostAddress());\n System.out.println(\" chost: \" + theLocalhost.getCanonicalHostName());\n System.out.println(\" byteaddr: \" + toMACAddrString(theLocalhost.getAddress()));\n System.out.println(\" sitelocal?: \" + theLocalhost.isSiteLocalAddress());\n System.out.println(\"\");\n }\n else\n {\n System.out.println(\" localhost was null\");\n }\n\n Enumeration<NetworkInterface> theIntfList = NetworkInterface.getNetworkInterfaces();\n ArrayList<InterfaceAddress> theAddrList = null;\n NetworkInterface theIntf = null;\n InetAddress theAddr = null;\n\n while(theIntfList.hasMoreElements())\n {\n theIntf = theIntfList.nextElement();\n\n System.out.println(\"--------------------\");\n System.out.println(\" \" + theIntf.getDisplayName());\n System.out.println(\" name: \" + theIntf.getName());\n System.out.println(\" mac: \" + toMACAddrString(theIntf.getHardwareAddress()));\n System.out.println(\" mtu: \" + theIntf.getMTU());\n System.out.println(\" mcast?: \" + theIntf.supportsMulticast());\n System.out.println(\" loopback?: \" + theIntf.isLoopback());\n System.out.println(\" ptp?: \" + theIntf.isPointToPoint());\n System.out.println(\" virtual?: \" + theIntf.isVirtual());\n System.out.println(\" up?: \" + theIntf.isUp());\n\n theAddrList = (ArrayList<InterfaceAddress>) theIntf.getInterfaceAddresses();\n System.out.println(\" int addrs: \" + theAddrList.size() + \" total.\");\n int addrindex = 0;\n for(InterfaceAddress intAddr : theAddrList)\n {\n addrindex++;\n theAddr = intAddr.getAddress();\n System.out.println(\" \" + addrindex + \").\");\n System.out.println(\" host: \" + theAddr.getHostName());\n System.out.println(\" class: \" + theAddr.getClass().getSimpleName());\n System.out.println(\" ip: \" + theAddr.getHostAddress() + \"/\" + intAddr.getNetworkPrefixLength());\n System.out.println(\" bcast: \" + intAddr.getBroadcast().getHostAddress());\n int maskInt = Integer.MIN_VALUE >> (intAddr.getNetworkPrefixLength()-1);\n System.out.println(\" mask: \" + toIPAddrString(maskInt));\n System.out.println(\" chost: \" + theAddr.getCanonicalHostName());\n System.out.println(\" byteaddr: \" + toMACAddrString(theAddr.getAddress()));\n System.out.println(\" sitelocal?: \" + theAddr.isSiteLocalAddress());\n System.out.println(\"\");\n }\n }\n }\n catch (SocketException e)\n {\n e.printStackTrace();\n }\n catch (UnknownHostException e)\n {\n e.printStackTrace();\n }\n\n }\n\n\n public static String toMACAddrString(byte[] a) { if (a == null) { return \"null\"; } int iMax = a.length - 1;\n\n if (iMax == -1)\n {\n return \"[]\";\n }\n\n StringBuilder b = new StringBuilder();\n b.append('[');\n for (int i = 0;; i++)\n {\n b.append(String.format(\"%1$02x\", a[i]));\n\n if (i == iMax)\n {\n return b.append(']').toString();\n }\n b.append(\":\");\n }\n }\n\n public static String toIPAddrString(int ipa)\n {\n StringBuilder b = new StringBuilder();\n b.append(Integer.toString(0x000000ff & (ipa >> 24)));\n b.append(\".\");\n b.append(Integer.toString(0x000000ff & (ipa >> 16)));\n b.append(\".\");\n b.append(Integer.toString(0x000000ff & (ipa >> 8)));\n b.append(\".\");\n b.append(Integer.toString(0x000000ff & (ipa)));\n return b.toString();\n }\n\n}\n package com.test;\n\nimport java.io.IOException;\nimport java.net.InetAddress;\n\npublic class NetworkPing {\n\n /**\n * JavaProgrammingForums.com\n */\n public static void main(String[] args) throws IOException {\n\n InetAddress localhost = InetAddress.getLocalHost();\n // this code assumes IPv4 is used\n byte[] ip = localhost.getAddress();\n\n for (int i = 1; i <= 254; i++)\n {\n ip[3] = (byte)i;\n InetAddress address = InetAddress.getByAddress(ip);\n if (address.isReachable(1000))\n {\n System.out.println(address + \" machine is turned on and can be pinged\");\n }\n else if (!address.getHostAddress().equals(address.getHostName()))\n {\n //hostName is the Machine name and hostaddress is the ip addr\n System.out.println(address + \" machine is known in a DNS lookup\");\n }\n else\n {\n System.out.println(address + \" the host address and host name are equal, meaning the host name could not be resolved\");\n }\n }\n\n }\n}\n package com.test;\n\nimport java.net.*;\nimport java.util.*;\n\npublic class NIC {\n\npublic static void main(String args[]) throws Exception {\n\n List<InetAddress> addrList = new ArrayList<InetAddress>();\n Enumeration<NetworkInterface> interfaces = null;\n try {\n interfaces = NetworkInterface.getNetworkInterfaces();\n } catch (SocketException e) {\n e.printStackTrace();\n }\n\n InetAddress localhost = null;\n\n try {\n localhost = InetAddress.getByName(\"127.0.0.1\");\n } catch (UnknownHostException e) {\n e.printStackTrace();\n }\n\n while (interfaces.hasMoreElements()) {\n NetworkInterface ifc = interfaces.nextElement();\n Enumeration<InetAddress> addressesOfAnInterface = ifc.getInetAddresses();\n\n while (addressesOfAnInterface.hasMoreElements()) {\n InetAddress address = addressesOfAnInterface.nextElement();\n\n if (!address.equals(localhost) && !address.toString().contains(\":\")) {\n addrList.add(address);\n System.out.println(\"FOUND ADDRESS ON NIC: \" + address.getHostAddress());\n }\n }\n }\n\n}\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98930",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17007/"
] |
98,944
|
<p>How do I write a cpp macro which expands to include newlines?</p>
|
[
{
"answer_id": 98956,
"author": "Branan",
"author_id": 13894,
"author_profile": "https://Stackoverflow.com/users/13894",
"pm_score": -1,
"selected": false,
"text": "\\ #define my_multiline_macro(a, b, c) \\\nif (a) { \\\n b += c; \\\n}\n"
},
{
"answer_id": 98972,
"author": "PiNoYBoY82",
"author_id": 13646,
"author_profile": "https://Stackoverflow.com/users/13646",
"pm_score": -1,
"selected": false,
"text": "#define NEWLINE_MACRO(x) line1 \\\nline2 \\\nline3\n #define NEWLINE_MACRO(x) ##x\n NEWLINE_MACRO( line1 ) // is replaced with line1\n #define NEWLINE_MACRO(x) #x // stringify x\n"
},
{
"answer_id": 98973,
"author": "David L Morris",
"author_id": 3137,
"author_profile": "https://Stackoverflow.com/users/3137",
"pm_score": 3,
"selected": false,
"text": "#define SOME_STRING \"Some string\\n with a new line.\"\n"
},
{
"answer_id": 99017,
"author": "Charles Graham",
"author_id": 7705,
"author_profile": "https://Stackoverflow.com/users/7705",
"pm_score": -1,
"selected": false,
"text": "#define foo() do \\\n{\n //code goes here \\\n \\\n \\\n}while(0);\n #define foo(x) a+b\n//should be\n#define foo(x) (a+b)\n"
},
{
"answer_id": 36384452,
"author": "Florian Fleissner",
"author_id": 6151578,
"author_profile": "https://Stackoverflow.com/users/6151578",
"pm_score": 4,
"selected": false,
"text": "// Content of MyMacro.hpp\n\n#include \"MultilineMacroDebugging.hpp\"\n\n#define PRINT_VARIABLE(S) \\\n__NL__ std::cout << #S << \": \" << S << std::endl; \\\n__NL__ /* more lines if necessary */ \\\n__NL__ /* even more lines */\n // Content of MultilineMacroDebugging.hpp\n\n#ifndef HAVE_MULTILINE_DEBUGGING\n#define __NL__\n#endif\n __NL__ __NL__ // Content of MyImplementation.cpp\n\n// Uncomment the following line to enable macro debugging\n//#define HAVE_MULTILINE_DEBUGGING\n\n#include \"MyMacro.hpp\"\n\nint a = 10;\nPRINT_VARIABLE(a)\n PRINT_VARIABLE HAVE_MULTILINE_DEBUGGING __NL__ __NL__"
},
{
"answer_id": 74238404,
"author": "Björn Grieger",
"author_id": 20360122,
"author_profile": "https://Stackoverflow.com/users/20360122",
"pm_score": 0,
"selected": false,
"text": "sed s/'\\\\ '/'\\n'/g\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/98944",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18458/"
] |
99,013
|
<p>Is it possible to use stored procedures for designing Reports in Report builder?</p>
|
[
{
"answer_id": 123573,
"author": "jimmyorr",
"author_id": 19239,
"author_profile": "https://Stackoverflow.com/users/19239",
"pm_score": 0,
"selected": false,
"text": "select * from table (f_foo(:p_bar))\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/99013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14752/"
] |
99,020
|
<p>I have a java app (not running in any application container) which listens on a ServerSocket for connections. I would like it to only accept connections which come from localhost. Currently, after a connection is accepted, it checks the peer IP and rejects it if it is not the loopback address, but I know that peer IP addresses can be spoofed. So, if possible, I'd prefer to bind to a socket that only listens on the loopback interface; is this possible?</p>
<p>I've tried a few different things (such as specifying "127.0.0.1" as the local address when calling bind()) with no luck.</p>
<hr />
<p><strong>Update:</strong></p>
<p>I'm embarrassed to admit that this was all my mistake. Our application listens on two different ports, and I was binding one to the loopback interface but testing against the other. When I actually try to telnet to the correct port, everything works fine (i.e., binding to "127.0.0.1" does exactly what it's supposed to).</p>
<p>As for spoofing the loopback address, you guys are right. I shouldn't have made it sound like the primary concern. Really, the desired behavior is to only take local connections, and binding to only the local interface is a more direct way of achieving that than accepting all connections and then closing non-local ones.</p>
|
[
{
"answer_id": 99430,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 2,
"selected": false,
"text": "127.0.0.1"
},
{
"answer_id": 9271782,
"author": "Selfmade Javaman",
"author_id": 1208324,
"author_profile": "https://Stackoverflow.com/users/1208324",
"pm_score": 2,
"selected": false,
"text": "if (socket.getInetAddress().isLoopbackAddress()){\n //Your code goes here\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/99020",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
99,045
|
<p>We are running Selenium regression tests against our existing code base, and certain screens in our web app use pop-ups for intermediate steps.</p>
<p>Currently we use the commands in the test:</p>
<pre><code>// force new window to open at this point - so we can select it later
selenium().getEval("this.browserbot.getCurrentWindow().open('', 'enquiryPopup')");
selenium().click("//input[@value='Submit']");
selenium().waitForPopUp("enquiryPopup", getWaitTime());
selenium().selectWindow("enquiryPopup");
</code></pre>
<p>...which works <em>most of the time</em>. Occasionally the test will fail on the <code>waitForPopUp()</code> line with </p>
<pre><code>com.thoughtworks.selenium.SeleniumException: Permission denied
</code></pre>
<p>Can anyone suggest a better, more <em>reliable</em> method?</p>
<p>Also, we primarily run these tests on IE6 and 7.</p>
|
[
{
"answer_id": 99372,
"author": "brasskazoo",
"author_id": 6340,
"author_profile": "https://Stackoverflow.com/users/6340",
"pm_score": 0,
"selected": false,
"text": "windowFocus() // force new window to open at this point - so we can select it later\nselenium().getEval(\"this.browserbot.getCurrentWindow().open('', 'enquiryPopup')\");\nselenium().click(\"//input[@value='Submit']\");\nselenium().windowFocus(\"enquiryPopup\");\nselenium().waitForPopUp(\"enquiryPopup\", getWaitTime());\nselenium().selectWindow(\"enquiryPopup\");\n"
},
{
"answer_id": 429196,
"author": "branchgabriel",
"author_id": 30807,
"author_profile": "https://Stackoverflow.com/users/30807",
"pm_score": 3,
"selected": true,
"text": "<tr>\n <td>getEval</td>\n <td>selenium.browserbot.getCurrentWindow().open('', 'windowName');</td>\n <td></td>\n</tr>\n<tr>\n <td>click</td>\n <td>buttonName</td>\n <td></td>\n</tr>\n<tr>\n <td>windowFocus</td>\n <td>windowName</td>\n <td></td>\n</tr>\n<tr>\n <td>waitForPopUp</td>\n <td>windowName</td>\n <td>3000</td>\n</tr>\n<tr>\n <td>selectWindow</td>\n <td>windowName</td>\n <td></td>\n</tr>\n"
},
{
"answer_id": 1941915,
"author": "nicholasklick",
"author_id": 236260,
"author_profile": "https://Stackoverflow.com/users/236260",
"pm_score": 0,
"selected": false,
"text": "<tr>\n <td>click</td>\n <td>//a[@class='item_add']</td>\n <td></td>\n</tr>\n<tr>\n <td>windowFocus</td>\n <td>account_frame</td>\n <td></td>\n</tr>\n<tr>\n <td>waitForPopUp</td>\n <td>account_frame</td>\n <td>10000</td>\n</tr>\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/99045",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6340/"
] |
99,056
|
<p>If given the choice, which path would you take?</p>
<blockquote>
<p>ASP.NET Webforms + ASP.NET AJAX</p>
</blockquote>
<p><strong>or</strong></p>
<blockquote>
<p>ASP.NET MVC + JavaScript Framework of your Choice</p>
</blockquote>
<p>Are there any limitations that ASP.NET Webforms / ASP.NET AJAX has vis-a-vis MVC? </p>
|
[
{
"answer_id": 1651600,
"author": "Mike",
"author_id": 199673,
"author_profile": "https://Stackoverflow.com/users/199673",
"pm_score": 4,
"selected": false,
"text": "public partial class SamplePage : System.Web.Mvc.ViewPage\n{\n protected void Page_Load(object sender, EventArgs e)\n {\n }\n}\n protected void Page_Load(object sender, EventArgs e)\n {\n IObjectDefinition instance = (IObjectDefinition)ViewData[\"definition\"];\n _objectName.Text = instance.DisplayName;//textbox or label\n\n DataTable itemVals = new DataTable();\n itemVals .Columns.Add(\"itemName\");\n itemVals .Columns.Add(\"itemValue\"); \n\n\n IDictionary<string, string> items = (IDictionary<string, string>)ViewData[\"items\"];\n foreach (KeyValuePair<string, string> datum in items)\n {\n conditions.Rows.Add(new object[] { datum.Key, datum.Value});\n }\n\n _itemList.DataSource = itemVals;//repeater\n _itemList.DataBind();\n }\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/99056",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1368/"
] |
99,074
|
<p>Would it be useful to be able to provide method return value for null objects?</p>
<p>For a List the null return values might be:</p>
<pre><code>get(int) : null
size() : 0
iterator() : empty iterator
</code></pre>
<p>That would allow the following code that has less null checks.</p>
<pre><code>List items = null;
if(something) {
items = ...
}
for(int index = 0; index < items.size(); index++) {
Object obj = items.get(index);
}
</code></pre>
<p>This would only be used if the class or interface defined it and a null check would still work. Sometimes you don't want to do null checks so it seems like it could be beneficial to have this as an option.</p>
<p>From: <a href="http://jamesjava.blogspot.com/2007/05/method-return-values-for-null-objects.html" rel="nofollow noreferrer">http://jamesjava.blogspot.com/2007/05/method-return-values-for-null-objects.html</a></p>
|
[
{
"answer_id": 99332,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 0,
"selected": false,
"text": "Foo x = null;\nif (x.Bar() == 0)\n{\n Console.WriteLine(\"I win\");\n}\n public static int Bar (this Foo theFoo)\n{\n return theFoo == null ? 0 : 1;\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/99074",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6770/"
] |
99,098
|
<p>What is the best way to generate a current datestamp in Java? </p>
<p>YYYY-MM-DD:hh-mm-ss</p>
|
[
{
"answer_id": 99105,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 3,
"selected": false,
"text": "Date d = new Date();\nString formatted = new SimpleDateFormat (\"yyyy-MM-dd:HH-mm-ss\").format (d);\nSystem.out.println (formatted);\n"
},
{
"answer_id": 99133,
"author": "sblundy",
"author_id": 4893,
"author_profile": "https://Stackoverflow.com/users/4893",
"pm_score": 1,
"selected": false,
"text": "long timestamp = System.currentTimeMillis() \n new Date()"
},
{
"answer_id": 99152,
"author": "Walter Rumsby",
"author_id": 1654,
"author_profile": "https://Stackoverflow.com/users/1654",
"pm_score": 0,
"selected": false,
"text": "final DateFormat formatter = new SimpleDateFormat(\"yyyy-MM-dd:hh-mm-ss\");\n\nformatter.format(new Date());\n"
},
{
"answer_id": 99175,
"author": "jt.",
"author_id": 4362,
"author_profile": "https://Stackoverflow.com/users/4362",
"pm_score": 6,
"selected": true,
"text": "Date myDate = new Date();\nSimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd:HH-mm-ss\");\nString myDateString = sdf.format(myDate);\n Date myDate = new Date();\nFastDateFormat fdf = FastDateFormat.getInstance(\"yyyy-MM-dd:HH-mm-ss\");\nString myDateString = fdf.format(myDate);\n SimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd:HH-mm-ss\");\nDate yourDate = sdf.parse(\"2008-09-18:22-03-15\");\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/99098",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3020/"
] |
99,118
|
<p>Is there any downside or problem potential to change the Java compiler to automatically cast? In the example below the result of list.get(0) would automatically be casted to the type of the variable hi.</p>
<pre><code>List list = new ArrayList();
list.add("hi");
String hi = list.get(0);
</code></pre>
<p>I know that generics allow you to reduce casting but they do so at the expense of making declaration more difficult. To me, the benefit of generics is that they allow you to have the complier enforce more rules -- not they they reduce casting (but I haven't used them much so I am somewhat uninformed). This proposal would only reduce the amount of code to type, not move it to another place.
Also there are instances where generics can't be used because a collection can have different objectis.
If that "looks too surprising" based on current usage maybe there could be a syntax tweak to use it.</p>
<p>From: <a href="http://jamesjava.blogspot.com/2007/01/automatic-casting.html" rel="nofollow noreferrer">http://jamesjava.blogspot.com/2007/01/automatic-casting.html</a></p>
|
[
{
"answer_id": 99216,
"author": "jon",
"author_id": 12215,
"author_profile": "https://Stackoverflow.com/users/12215",
"pm_score": 2,
"selected": false,
"text": "List list = new ArrayList();\nlist.add(new Integer(42));\nString hi = (String) list.get(0); // run time error\n\nList<String> list = new ArrayList<String>();\nlist.add(new Integer(42)); // compile time error\nString hi = list.get(0);\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/99118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6770/"
] |
99,132
|
<p>I need to generate a directory in my makefile and I would like to not get the "directory already exists error" over and over even though I can easily ignore it.</p>
<p>I mainly use mingw/msys but would like something that works across other shells/systems too.</p>
<p>I tried this but it didn't work, any ideas?</p>
<pre><code>ifeq (,$(findstring $(OBJDIR),$(wildcard $(OBJDIR) )))
-mkdir $(OBJDIR)
endif
</code></pre>
|
[
{
"answer_id": 99156,
"author": "andrewdotnich",
"author_id": 10569,
"author_profile": "https://Stackoverflow.com/users/10569",
"pm_score": 4,
"selected": false,
"text": "-mkdir $(OBJDIR) 2>/dev/null\n"
},
{
"answer_id": 99174,
"author": "tchen",
"author_id": 18417,
"author_profile": "https://Stackoverflow.com/users/18417",
"pm_score": 8,
"selected": true,
"text": "mkdir -p $(OBJDIR)\n"
},
{
"answer_id": 99176,
"author": "Lee H",
"author_id": 18201,
"author_profile": "https://Stackoverflow.com/users/18201",
"pm_score": 4,
"selected": false,
"text": "target:\n if test -d dir; then echo \"hello world!\"; else mkdir dir; fi\n"
},
{
"answer_id": 99188,
"author": "skymt",
"author_id": 18370,
"author_profile": "https://Stackoverflow.com/users/18370",
"pm_score": 6,
"selected": false,
"text": "test -d $(OBJDIR) || mkdir $(OBJDIR)\n"
},
{
"answer_id": 175750,
"author": "Michael McCarty",
"author_id": 25007,
"author_profile": "https://Stackoverflow.com/users/25007",
"pm_score": 3,
"selected": false,
"text": "ifeq \"$(wildcard $(MY_DIRNAME) )\" \"\"\n -mkdir $(MY_DIRNAME)\nendif\n"
},
{
"answer_id": 511665,
"author": "Martin Fido",
"author_id": 62457,
"author_profile": "https://Stackoverflow.com/users/62457",
"pm_score": 3,
"selected": false,
"text": "$(OBJDIR):\n mkdir $@\n OBJDIRS := $(sort $(dir $(OBJECTS)))\n\n$(OBJDIRS):\n mkdir $@\n $(OBJDIR)"
},
{
"answer_id": 3300436,
"author": "wmad",
"author_id": 398088,
"author_profile": "https://Stackoverflow.com/users/398088",
"pm_score": 3,
"selected": false,
"text": "if not exist \"$(OBJDIR)\" mkdir $(OBJDIR)\n if [ ! -d \"$(OBJDIR)\" ]; then mkdir $(OBJDIR); fi\n"
},
{
"answer_id": 3739843,
"author": "Northern Stream",
"author_id": 1167733,
"author_profile": "https://Stackoverflow.com/users/1167733",
"pm_score": 4,
"selected": false,
"text": " %/.d:\n mkdir -p $(@D)\n touch $@\n obj/%.o: %.c obj/.d\n $(CC) $(CFLAGS) -c -o $@ $<\n .PRECIOUS: %/.d\n"
},
{
"answer_id": 6170280,
"author": "ofavre",
"author_id": 508831,
"author_profile": "https://Stackoverflow.com/users/508831",
"pm_score": 7,
"selected": false,
"text": "OBJDIR := objdir\nOBJS := $(addprefix $(OBJDIR)/,foo.o bar.o baz.o)\n\n$(OBJDIR)/%.o : %.c\n $(COMPILE.c) $(OUTPUT_OPTION) $<\n\nall: $(OBJS)\n\n$(OBJS): | $(OBJDIR)\n\n$(OBJDIR):\n mkdir -p $(OBJDIR)\n $(OBJDIR) mkdir -p -p"
},
{
"answer_id": 10100865,
"author": "lygstate",
"author_id": 321938,
"author_profile": "https://Stackoverflow.com/users/321938",
"pm_score": 2,
"selected": false,
"text": "ifeq \"$(wildcard .dep)\" \"\"\n-include $(shell mkdir .dep) $(wildcard .dep/*)\nendif\n"
},
{
"answer_id": 17385817,
"author": "Mischa",
"author_id": 205874,
"author_profile": "https://Stackoverflow.com/users/205874",
"pm_score": 0,
"selected": false,
"text": "something_needs_directory_xxx : xxx/..\n %/.. : ;@mkdir -p $(@D)\n"
},
{
"answer_id": 32495400,
"author": "Andrew",
"author_id": 383188,
"author_profile": "https://Stackoverflow.com/users/383188",
"pm_score": 0,
"selected": false,
"text": "mkdir 2>/dev/null || true\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/99132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13676/"
] |
99,161
|
<p>I search for "nurple" in a file. I found it, great. But now, every occurrence of "nurple" is rendered in sick black on yellow. Forever.</p>
<p>Forever, that is, until I search for something I know won't be found, such as "asdhfalsdflajdflakjdf" simply so it clears the previous search highlighting.</p>
<p>Can't I just hit a magic key to kill the highlights when I'm done searching?</p>
|
[
{
"answer_id": 99182,
"author": "Lee H",
"author_id": 18201,
"author_profile": "https://Stackoverflow.com/users/18201",
"pm_score": 9,
"selected": false,
"text": ":noh nohighlight"
},
{
"answer_id": 99186,
"author": "Lucas S.",
"author_id": 7363,
"author_profile": "https://Stackoverflow.com/users/7363",
"pm_score": 9,
"selected": true,
"text": "\" <Ctrl-l> redraws the screen and removes any search highlighting.\nnnoremap <silent> <C-l> :nohl<CR><C-l>\n"
},
{
"answer_id": 99196,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 3,
"selected": false,
"text": ":help #"
},
{
"answer_id": 99207,
"author": "Daniel Bruce",
"author_id": 6456,
"author_profile": "https://Stackoverflow.com/users/6456",
"pm_score": 4,
"selected": false,
"text": ".vimrc set nohlsearch\n"
},
{
"answer_id": 99208,
"author": "Jeffrey Vanneste",
"author_id": 5497,
"author_profile": "https://Stackoverflow.com/users/5497",
"pm_score": 2,
"selected": false,
"text": "hlsearch nohlsearch :help hlsearch map <F12> :nohlsearch<CR>\nimap <F12> <ESC>:nohlsearch<CR>i\nvmap <F12> <ESC>:nohlsearch<CR>gv\n"
},
{
"answer_id": 99226,
"author": "jon",
"author_id": 12215,
"author_profile": "https://Stackoverflow.com/users/12215",
"pm_score": 7,
"selected": false,
"text": "/lkjasdf :noh"
},
{
"answer_id": 99982,
"author": "Zsolt Botykai",
"author_id": 11621,
"author_profile": "https://Stackoverflow.com/users/11621",
"pm_score": 4,
"selected": false,
"text": "map <F12> :set hls!<CR>\nimap <F12> <ESC>:set hls!<CR>a\nvmap <F12> <ESC>:set hls!<CR>gv\n"
},
{
"answer_id": 100141,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "nnoremap <silent> _ :nohl<CR>\n"
},
{
"answer_id": 101756,
"author": "Max Cantor",
"author_id": 16034,
"author_profile": "https://Stackoverflow.com/users/16034",
"pm_score": 2,
"selected": false,
"text": "nnoremap ; :set invhlsearch<CR>\n"
},
{
"answer_id": 19865983,
"author": "Daniel Miessler",
"author_id": 500958,
"author_profile": "https://Stackoverflow.com/users/500958",
"pm_score": 2,
"selected": false,
"text": "<leader>c :nohl<CR>\n"
},
{
"answer_id": 19877212,
"author": "Andy Lester",
"author_id": 8454,
"author_profile": "https://Stackoverflow.com/users/8454",
"pm_score": 5,
"selected": false,
"text": "\" Make double-<Esc> clear search highlights\nnnoremap <silent> <Esc><Esc> <Esc>:nohlsearch<CR><Esc>\n"
},
{
"answer_id": 22807541,
"author": "nocache",
"author_id": 778675,
"author_profile": "https://Stackoverflow.com/users/778675",
"pm_score": 2,
"selected": false,
"text": ":let @/ = \"\"\n"
},
{
"answer_id": 23416923,
"author": "Aman Jain",
"author_id": 29405,
"author_profile": "https://Stackoverflow.com/users/29405",
"pm_score": -1,
"selected": false,
"text": "map e/ /sdfdskfxxxxy\n e/"
},
{
"answer_id": 24951879,
"author": "Guillaume",
"author_id": 857728,
"author_profile": "https://Stackoverflow.com/users/857728",
"pm_score": 0,
"selected": false,
"text": "nmap <F12> :set hls!<CR>\nnnoremap / :set hls<CR>/\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/99161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18446/"
] |
99,164
|
<p>I often see code like:</p>
<pre><code>Iterator i = list.iterator();
while(i.hasNext()) {
...
}
</code></pre>
<p>but I write that (when Java 1.5 isn't available or for each can't be used) as:</p>
<pre><code>for(Iterator i = list.iterator(); i.hasNext(); ) {
...
}
</code></pre>
<p>because</p>
<ul>
<li>It is shorter</li>
<li>It keeps <code>i</code> in a smaller scope</li>
<li>It reduces the chance of confusion. (Is <code>i</code> used outside the
while? Where is <code>i</code> declared?)</li>
</ul>
<p>I think code should be as simple to understand as possible so that I only have to make complex code to do complex things. What do you think? Which is better?</p>
<p>From: <a href="http://jamesjava.blogspot.com/2006/04/iterating.html" rel="noreferrer">http://jamesjava.blogspot.com/2006/04/iterating.html</a></p>
|
[
{
"answer_id": 99189,
"author": "Giorgio Galante",
"author_id": 18269,
"author_profile": "https://Stackoverflow.com/users/18269",
"pm_score": 3,
"selected": false,
"text": "List<String> names = new ArrayList<String>();\nnames.add(\"a\");\nnames.add(\"b\");\nnames.add(\"c\");\n\nfor (String name : names)\n System.out.println(name.charAt(0));\n"
},
{
"answer_id": 99246,
"author": "Jon Limjap",
"author_id": 372,
"author_profile": "https://Stackoverflow.com/users/372",
"pm_score": 4,
"selected": false,
"text": "while for foreach foreach"
},
{
"answer_id": 8435741,
"author": "Igor Vaschuk",
"author_id": 154664,
"author_profile": "https://Stackoverflow.com/users/154664",
"pm_score": 2,
"selected": false,
"text": "for (; (currUserObjectIndex < _domainObjectReferences.Length) && (_domainObjectReferences[currUserObjectIndex].VisualIndex == index); ++currUserObjectIndex)\n ++currNumUserObjects;\n while (currUserObjectIndex < _domainObjectReferences.Length && _domainObjectReferences[currUserObjectIndex].VisualIndex == index)\n{\n ++currNumUserObjects;\n ++currUserObjectIndex;\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/99164",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6770/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.