qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
---|---|---|---|---|
9,256 |
<p>Thanks to FireFox's buggy implementation of ActiveX components (it really should take an image of them when printing) Flex components (in our case charts) don't print in FX.</p>
<p>They print fine in IE7, even IE6.</p>
<p>We need these charts to print, but they also have dynamic content. I don't really want to draw them again as images when the user prints - the Flex component should do it.</p>
<p>We've found a <a href="http://www.anychart.com/blog/2007/09/23/solving-problem-with-printing-flash-content-in-firefox-browser/" rel="nofollow noreferrer">potential workaround</a>, but unfortunately it doesn't work in FireFox3 (in FireFox2 it sort-of works, but not well enough).</p>
<p>Anyone know a workaround?</p>
|
[
{
"answer_id": 16362,
"author": "Matt MacLean",
"author_id": 22,
"author_profile": "https://Stackoverflow.com/users/22",
"pm_score": 3,
"selected": true,
"text": "private function initPrint():void {\n //if we don't have a stage, wait until the next frame and try again\n if ( stage == null ) {\n callLater(initPrint);\n return;\n }\n\n PrintManager.init(stage);\n\n var data:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);\n data.draw(myDataGrid);\n\n PrintManager.setPrintableContent(data);\n}\n"
},
{
"answer_id": 27930,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 0,
"selected": false,
"text": "callLater"
}
] |
2008/08/12
|
[
"https://Stackoverflow.com/questions/9256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/905/"
] |
9,272 |
<p>Anybody have a script or alias to find untracked (really: unadded) files in a Perforce tree?</p>
<p>EDIT: I updated the accepted answer on this one since it looks like P4V added support for this in the January 2009 release.</p>
|
[
{
"answer_id": 9280,
"author": "Mark Harrison",
"author_id": 116,
"author_profile": "https://Stackoverflow.com/users/116",
"pm_score": 6,
"selected": false,
"text": "find . -type f -print0 | xargs -0 p4 fstat >/dev/null\n find . -type f -print0 | xargs -0 p4 fstat >/dev/null 2>mylogfile\n"
},
{
"answer_id": 100126,
"author": "ahu",
"author_id": 15646,
"author_profile": "https://Stackoverflow.com/users/15646",
"pm_score": 4,
"selected": false,
"text": "find -type f ! -name '*~' -print0| xargs -0 p4 fstat 2>&1|awk '/no such file/{print $1}'\n ! -name '*~'"
},
{
"answer_id": 966386,
"author": "Ross Patterson",
"author_id": 241753,
"author_profile": "https://Stackoverflow.com/users/241753",
"pm_score": 2,
"selected": false,
"text": "dir /S /B /A-D | sed -e \"s/%/%25/g\" -e \"s/@/%40/g\" -e \"s/#/%23/g\" -e \"s/\\*/%2A/g\" | p4 -x- have 1>NUL:\n Z:\\No_Backup\\Workspaces\\full\\depot\\Projects\\Archerfish\\Portal\\Main\\admin\\html\\images\\nav\\navxx_background.gif - file(s) not on client.\n"
},
{
"answer_id": 971143,
"author": "tenpn",
"author_id": 11801,
"author_profile": "https://Stackoverflow.com/users/11801",
"pm_score": 7,
"selected": true,
"text": "p4 status"
},
{
"answer_id": 13864328,
"author": "Colonel Panic",
"author_id": 284795,
"author_profile": "https://Stackoverflow.com/users/284795",
"pm_score": 4,
"selected": false,
"text": "svn status git status p4 status p4ignore.txt"
},
{
"answer_id": 33926660,
"author": "Jac Goudsmit",
"author_id": 1365956,
"author_profile": "https://Stackoverflow.com/users/1365956",
"pm_score": 0,
"selected": false,
"text": "p4 fstat p4 have dir /S /B /A-D | sed -e \"s/%/%25/g\" -e \"s/@/%40/g\" -e \"s/#/%23/g\" -e \"s/\\*/%2A/g\" | p4 -x- fstat 2>&1 | sed -n -e \"s/ - no such file[(]s[)]\\.$//gp\"\n"
},
{
"answer_id": 38434276,
"author": "Rhubbarb",
"author_id": 202130,
"author_profile": "https://Stackoverflow.com/users/202130",
"pm_score": 1,
"selected": false,
"text": "svn status git status p4 status p4 opened p4 diff -ds"
},
{
"answer_id": 39936860,
"author": "Krazy Glew",
"author_id": 1051115,
"author_profile": "https://Stackoverflow.com/users/1051115",
"pm_score": 3,
"selected": false,
"text": "p4 reconcile -na -a -n p4 edit p4 reconcile -n p4 fstat p4 reconcile -n p4 status p4 status p4 status p4 reconcile p4 status -n p4 reconcile p4 status p4 revert p4 status p4 status p4 reconcile -n P4V p4v"
},
{
"answer_id": 46824653,
"author": "beena",
"author_id": 8769413,
"author_profile": "https://Stackoverflow.com/users/8769413",
"pm_score": 0,
"selected": false,
"text": "p4 fstat find // throw the output of p4 fstat to a 'output file'\n// find:\n// -type f :- only look at files,\n// -print0 :- terminate strings with \\0s to support filenames with spaces\n// xargs:\n// Groups its input into command lines,\n// -0 :- read input strings terminated with \\0s\n// p4:\n// fstat :- fetch workspace stat on files\n\nmy $status=system \"(find . -type f -print0 | xargs -0 p4 fstat > /dev/null) >& $outputFile\";\n\n// read output file\nopen F1, $outputFile or die \"$!\\n\";\n\n// iterate over all the lines in F1\nwhile (<F1>) {\n // remove trailing whitespace\n chomp $_;\n\n // grep lines which has 'no such file' or 'not in client'\n if($_ =~ m/no such file/ || $_ =~ m/not in client/){\n\n // Remove the content after '-'\n $_=~ s/-\\s.*//g;\n\n // below line is optional. Check ur output file for more clarity.\n $_=~ s/^.\\///g;\n\n print \"$_\\n\";\n }\n}\n\nclose F1;\n p4 reconcile -n -m ... -n"
},
{
"answer_id": 50142337,
"author": "givanse",
"author_id": 7852,
"author_profile": "https://Stackoverflow.com/users/7852",
"pm_score": 0,
"selected": false,
"text": "p4 fstat"
}
] |
2008/08/12
|
[
"https://Stackoverflow.com/questions/9272",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1146/"
] |
9,275 |
<p>I writing a report in Visual Studio that takes a user input parameter and runs against an ODBC datasource. I would like to write the query manually and have reporting services replace part of the where clause with the parameter value before sending it to the database. What seems to be happening is that the <code>@parmName</code> I am assuming will be replaced is actually being sent as part of the SQL statement. Am I missing a configuration setting somewhere or is this simply not possible?</p>
<p>I am not using the filter option in the tool because this appears to bring back the full dataset from the database and do the filtering on the SQL Server.</p>
|
[
{
"answer_id": 9325,
"author": "Jorriss",
"author_id": 621,
"author_profile": "https://Stackoverflow.com/users/621",
"pm_score": 4,
"selected": true,
"text": "=\"Select col1, col2 from table 1 Where col3 = \" & Parameters!Param1.Value \n =\"Select col1, col2 from table 1 Where col3 = '\" & Parameters!Param1.Value & \"'\"\n"
},
{
"answer_id": 19600,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 1,
"selected": false,
"text": "select col1, col2 from table1 where col3 = ?\n"
},
{
"answer_id": 28572,
"author": "stjohnroe",
"author_id": 2985,
"author_profile": "https://Stackoverflow.com/users/2985",
"pm_score": 0,
"selected": false,
"text": "*paramName* WHERE SQL"
},
{
"answer_id": 10551669,
"author": "H.G.",
"author_id": 1238246,
"author_profile": "https://Stackoverflow.com/users/1238246",
"pm_score": 1,
"selected": false,
"text": "SELECT A.1 FROM A WHERE A.1 = @parameter SELECT A.1 FROM A WHERE A.1 = ?"
}
] |
2008/08/12
|
[
"https://Stackoverflow.com/questions/9275",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1104/"
] |
9,279 |
<p>I absolutely love the <a href="http://winscp.net/eng/docs/task_keep_up_to_date" rel="noreferrer">Keep Remote Directory Up-to-date</a> feature in <a href="http://winscp.net/" rel="noreferrer">Winscp</a>. Unfortunately, I can't find anything as simple to use in OS X or Linux. I know the same thing can <em>theoretically</em> be accomplished using <a href="http://freshmeat.net/projects/changedfiles/" rel="noreferrer">changedfiles</a> or <a href="http://samba.anu.edu.au/rsync/" rel="noreferrer">rsync</a>, but I've always found the tutorials for both tools to be lacking and/or contradictory. </p>
<p>I basically just need a tool that works in OSX or Linux and keeps a remote directory in sync (mirrored) with a local directory while I make changes to the local directory.</p>
<hr>
<p><strong>Update</strong></p>
<p>Looking through the solutions, I see a couple which solve the general problem of keeping a remote directory in sync with a local directory <em>manually</em>. I know that I can set a cron task to run rsync every minute, and this should be fairly close to real time. </p>
<p>This is not the exact solution I was looking for as winscp does this and more: it detects file changes in a directory (while I work on them) and then automatically pushes the changes to the remote server. I know this is not the best solution (no code repository), but it allows me to very quickly test code on a server while I develop it. Does anyone know how to combine rsync with any other commands to get this functionality?</p>
|
[
{
"answer_id": 9287,
"author": "dwj",
"author_id": 346,
"author_profile": "https://Stackoverflow.com/users/346",
"pm_score": 5,
"selected": true,
"text": "#!/bin/sh\nrsync -avrz --progress --exclude-from .rsync_exclude_remote . remote_login@remote_computer:remote_dir \n\n# options\n# -a archive\n# -v verbose\n# -r recursive\n# -z compress \n -n (--dry-run)"
},
{
"answer_id": 9302,
"author": "Pat Notz",
"author_id": 825,
"author_profile": "https://Stackoverflow.com/users/825",
"pm_score": 2,
"selected": false,
"text": "rsync unison"
},
{
"answer_id": 289305,
"author": "KevinButler",
"author_id": 34463,
"author_profile": "https://Stackoverflow.com/users/34463",
"pm_score": 3,
"selected": false,
"text": "# sshfs username@host:path/to/directory local_dir\n # while true; do rsync -avrz localdir user@host:path; sleep 5; done\n # touch -d 01/01/1970 last; while true; do if [ \"`find localdir -newer last -print -quit`\" ]; then touch last; rsync -avrz localdir user@host:path; else echo -ne .; fi; sleep 5; done\n"
},
{
"answer_id": 4378901,
"author": "webasdf",
"author_id": 228301,
"author_profile": "https://Stackoverflow.com/users/228301",
"pm_score": 2,
"selected": false,
"text": "#!/bin/sh\n\nupload_files()\n{\n if [ \"$HOMEDIR\" = \".\" ]\n then\n HOMEDIR=`pwd`\n fi\n\n while read input\n do\n SYNCFILE=${input#$HOMEDIR}\n echo -n \"Sync File: $SYNCFILE...\"\n rsync -Cvz --temp-dir=\"$REMOTEDIR\" \"$HOMEDIR/$SYNCFILE\" \"$REMOTEDIR/$SYNCFILE\" > /dev/null\n echo \"Done.\"\n done\n}\n\n\nhelp()\n{\n echo \"Live rsync copy from one directory to another. This will overwrite the existing files on DEST.\"\n echo \"Usage: $0 SOURCE DEST\" \n}\n\n\ncase \"$1\" in\n rsyncThis)\n HOMEDIR=$2\n REMOTEDIR=$3\n echo \"HOMEDIR=$HOMEDIR\"\n echo \"REMOTEDIR=$REMOTEDIR\"\n upload_files\n ;;\n\n help)\n help\n ;;\n\n *)\n if [ -n \"$1\" ] && [ -n \"$2\" ]\n then\n fileschanged -r \"$1\" | \"$0\" rsyncThis \"$1\" \"$2\"\n else\n help\n fi\n ;;\nesac\n"
},
{
"answer_id": 14435664,
"author": "Eduardo Russo",
"author_id": 1302318,
"author_profile": "https://Stackoverflow.com/users/1302318",
"pm_score": 0,
"selected": false,
"text": "ssh [email protected]\n gem install terminal-notifier\n terminal-notifier -message \"Starting sync\"\n #!/bin/bash\nterminal-notifier -message \"Starting sync\"\nrsync -azP ~/Sites/folder/ [email protected]:site_folder/\nterminal-notifier -message \"Sync has finished\"\n sudo chmod 777 ~/Scripts/sync.sh\n brew install libyaml\n easy_install watchdog\n watchmedo shell-command\n --patterns=\"*.php;*.txt;*.js;*.css\" \\\n --recursive \\\n --command='~/Scripts/Sync.sh' \\\n .\n /Library/Python/2.7/site-packages/argh-0.22.0-py2.7.egg/argh/completion.py:84: UserWarning: Bash completion not available. Install argcomplete.\n"
},
{
"answer_id": 15283061,
"author": "juwens",
"author_id": 534812,
"author_profile": "https://Stackoverflow.com/users/534812",
"pm_score": 5,
"selected": false,
"text": "lsyncd -rsyncssh /home remotehost.org backup-home/\n"
},
{
"answer_id": 24455670,
"author": "Mike Mitterer",
"author_id": 504184,
"author_profile": "https://Stackoverflow.com/users/504184",
"pm_score": 0,
"selected": false,
"text": "#!/usr/bin/env ruby\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n# Rsyncs 2Folders\n#\n# watchAndSync by Mike Mitterer, 2014 <http://www.MikeMitterer.at>\n# with credit to Brett Terpstra <http://brettterpstra.com>\n# and Carlo Zottmann <https://github.com/carlo/haml-sass-file-watcher>\n# Found link on: http://brettterpstra.com/2011/03/07/watch-for-file-changes-and-refresh-your-browser-automatically/\n#\n\ntrap(\"SIGINT\") { exit }\n\nif ARGV.length < 2\n puts \"Usage: #{$0} watch_folder sync_folder\"\n puts \"Example: #{$0} web keepInSync\"\n exit\nend\n\ndev_extension = 'dev'\nfiletypes = ['css','html','htm','less','js', 'dart']\n\nwatch_folder = ARGV[0]\nsync_folder = ARGV[1]\n\nputs \"Watching #{watch_folder} and subfolders for changes in project files...\"\nputs \"Syncing with #{sync_folder}...\"\n\nwhile true do\n files = []\n filetypes.each {|type|\n files += Dir.glob( File.join( watch_folder, \"**\", \"*.#{type}\" ) )\n }\n new_hash = files.collect {|f| [ f, File.stat(f).mtime.to_i ] }\n hash ||= new_hash\n diff_hash = new_hash - hash\n\n unless diff_hash.empty?\n hash = new_hash\n\n diff_hash.each do |df|\n puts \"Detected change in #{df[0]}, syncing...\"\n system(\"rsync -avzh #{watch_folder} #{sync_folder}\")\n end\n end\n\n sleep 1\nend\n"
},
{
"answer_id": 56717832,
"author": "doom",
"author_id": 1619521,
"author_profile": "https://Stackoverflow.com/users/1619521",
"pm_score": 2,
"selected": false,
"text": "-delay lsyncd --nodaemon -rsyncssh local_dir remote_user@remote_host remote_dir -delay .2\n while inotifywait -r -e modify,create,delete local_dir ; do\n # if you need you can add wait here\n rsync -avz local_dir remote_user@remote_host:remote_dir\ndone\n inotify-tools ssh-keygen"
}
] |
2008/08/12
|
[
"https://Stackoverflow.com/questions/9279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/302/"
] |
9,289 |
<p>I would like to filter an array of items by using the <code>map()</code> function. Here is a code snippet:</p>
<pre><code>var filteredItems = items.map(function(item)
{
if( ...some condition... )
{
return item;
}
});
</code></pre>
<p>The problem is that filtered out items still uses space in the array and I would like to completely wipe them out.</p>
<p>Any idea?</p>
<p>EDIT: Thanks, I forgot about <code>filter()</code>, what I wanted is actually a <code>filter()</code> then a <code>map()</code>.</p>
<p>EDIT2: Thanks for pointing that <code>map()</code> and <code>filter()</code> are not implemented in all browsers, although my specific code was not intended to run in a browser.</p>
|
[
{
"answer_id": 9295,
"author": "Patrick",
"author_id": 429,
"author_profile": "https://Stackoverflow.com/users/429",
"pm_score": 4,
"selected": false,
"text": "Array.filter"
},
{
"answer_id": 9297,
"author": "olliej",
"author_id": 784,
"author_profile": "https://Stackoverflow.com/users/784",
"pm_score": 8,
"selected": true,
"text": "filter var filteredItems = items.filter(function(item)\n{\n return ...some condition...;\n});\n sourceArray.filter(...).map(...)"
},
{
"answer_id": 9329,
"author": "ggasp",
"author_id": 527,
"author_profile": "https://Stackoverflow.com/users/527",
"pm_score": 1,
"selected": false,
"text": "Array.filter //This prototype is provided by the Mozilla foundation and\n//is distributed under the MIT license.\n//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license\n\nif (!Array.prototype.filter)\n{\n Array.prototype.filter = function(fun /*, thisp*/)\n {\n var len = this.length;\n\n if (typeof fun != \"function\")\n throw new TypeError();\n\n var res = new Array();\n var thisp = arguments[1];\n\n for (var i = 0; i < len; i++)\n {\n if (i in this)\n {\n var val = this[i]; // in case fun mutates this\n\n if (fun.call(thisp, val, i, this))\n res.push(val);\n }\n }\n\n return res;\n };\n}\n"
},
{
"answer_id": 1498642,
"author": "vsync",
"author_id": 104380,
"author_profile": "https://Stackoverflow.com/users/104380",
"pm_score": 3,
"selected": false,
"text": "var arr = [1, 2, 3]\n\n// ES5 syntax\narr = arr.filter(function(item){ return item != 3 })\n\n// ES2015 syntax\narr = arr.filter(item => item != 3)\n\nconsole.log( arr )"
},
{
"answer_id": 36557522,
"author": "Kyle Baker",
"author_id": 4526479,
"author_profile": "https://Stackoverflow.com/users/4526479",
"pm_score": 6,
"selected": false,
"text": "Array.reduce() [1,2,3].filter(num => num > 2).map(num => num * 2) Array.reduce() let array = [1,2,3];\nconst initialMemo = [];\n\narray = array.reduce((memo, iteratee) => {\n // if condition is our filter\n if (iteratee > 1) {\n // what happens inside the filter is the map\n memo.push(iteratee * 2); \n }\n\n // this return value will be passed in as the 'memo' argument\n // to the next call of this function, and this function will have\n // every element passed into it at some point.\n return memo; \n}, initialMemo)\n\nconsole.log(array) // [4,6], equivalent to [(2 * 2), (3 * 2)]\n [1,2,3].reduce((memo, value) => value > 1 ? memo.concat(value * 2) : memo, [])\n [7,4,1,99,57,2,1,100].reduce((memo, val) => memo > val ? memo : val)\n// ^this would return the largest number in the list.\n test_arr = [];\n\n// we accept an anonymous function, and an optional 'initial memo' value.\ntest_arr.my_reducer = function(reduceFunc, initialMemo) {\n // if we did not pass in a second argument, then our first memo value \n // will be whatever is in index zero. (Otherwise, it will \n // be that second argument.)\n const initialMemoIsIndexZero = arguments.length < 2;\n\n // here we use that logic to set the memo value accordingly.\n let memo = initialMemoIsIndexZero ? this[0] : initialMemo;\n\n // here we use that same boolean to decide whether the first\n // value we pass in as iteratee is either the first or second\n // element\n const initialIteratee = initialMemoIsIndexZero ? 1 : 0;\n\n for (var i = initialIteratee; i < this.length; i++) {\n // memo is either the argument passed in above, or the \n // first item in the list. initialIteratee is either the\n // first item in the list, or the second item in the list.\n memo = reduceFunc(memo, this[i]);\n // or, more technically complete, give access to base array\n // and index to the reducer as well:\n // memo = reduceFunc(memo, this[i], i, this);\n }\n\n // after we've compressed the array into a single value,\n // we return it.\n return memo;\n}\n"
},
{
"answer_id": 58272005,
"author": "Nicolas",
"author_id": 6325415,
"author_profile": "https://Stackoverflow.com/users/6325415",
"pm_score": 0,
"selected": false,
"text": "var arraytoclean = [{v:65, toberemoved:\"gronf\"}, {v:12, toberemoved:null}, {v:4}];\narraytoclean.map((x,i)=>x.toberemoved=undefined);\nconsole.dir(arraytoclean);"
},
{
"answer_id": 58880113,
"author": "gkucmierz",
"author_id": 3573210,
"author_profile": "https://Stackoverflow.com/users/3573210",
"pm_score": 0,
"selected": false,
"text": "// array intersection that correctly handles also duplicates\n\nconst intersection = (a1, a2) => {\n const cnt = new Map();\n a2.map(el => cnt[el] = el in cnt ? cnt[el] + 1 : 1);\n return a1.filter(el => el in cnt && 0 < cnt[el]--);\n};\n\nconst l = console.log;\nl(intersection('1234'.split``, '3456'.split``)); // [ '3', '4' ]\nl(intersection('12344'.split``, '3456'.split``)); // [ '3', '4' ]\nl(intersection('1234'.split``, '33456'.split``)); // [ '3', '4' ]\nl(intersection('12334'.split``, '33456'.split``)); // [ '3', '3', '4' ]"
},
{
"answer_id": 61328209,
"author": "Rishab Surana",
"author_id": 6183464,
"author_profile": "https://Stackoverflow.com/users/6183464",
"pm_score": 0,
"selected": false,
"text": "state.map(item => {\n if(item.id === action.item.id){ \n return {\n id : action.item.id,\n name : item.name,\n price: item.price,\n quantity : item.quantity-1\n }\n\n }else{\n return item;\n }\n }).filter(item => {\n if(item.quantity <= 0){\n return false;\n }else{\n return true;\n }\n });\n"
},
{
"answer_id": 66282857,
"author": "Senseful",
"author_id": 35690,
"author_profile": "https://Stackoverflow.com/users/35690",
"pm_score": 1,
"selected": false,
"text": "map undefined filter flatMap compactMap compactMap computation let array = [1, 2, 3, 4, 5, 6, 7, 8];\n let mapped = array\n .filter(x => {\n let computation = x / 2 + 1;\n let isIncluded = computation % 2 === 0;\n return isIncluded;\n })\n .map(x => {\n let computation = x / 2 + 1;\n return `${x} is included because ${computation} is even`\n })\n\n // Output: [2 is included because 2 is even, 6 is included because 4 is even]\n compactMap compactMap undefined undefined let array = [1, 2, 3, 4, 5, 6, 7, 8];\n let mapped = array\n .map(x => {\n let computation = x / 2 + 1;\n let isIncluded = computation % 2 === 0;\n if (isIncluded) {\n return `${x} is included because ${computation} is even`\n } else {\n return undefined\n }\n })\n .filter(x => typeof x !== \"undefined\")\n"
}
] |
2008/08/12
|
[
"https://Stackoverflow.com/questions/9289",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/268/"
] |
9,301 |
<p>I'm having trouble with events in Internet Explorer 7.</p>
<p>When I have a form with <strong>two or more</strong> <code>input[type=text]</code> and I press enter, the events occurs in this order:</p>
<ol>
<li>submit button (<code>onClick</code>)</li>
<li>form (<code>onSubmit</code>)</li>
</ol>
<p>Sample code:</p>
<pre><code><form onSubmit="{alert('form::onSubmit'); return false;}">
<input type="text">
<input type="text">
<input type="submit" onClick="{alert('button::onClick');}">
</form>
</code></pre>
<p>If I have only <strong>one</strong> <code>input[type=text]</code> and I press enter the submit button <code>onClick</code> event doesn't fire. Sample code:</p>
<pre><code><form onSubmit="{alert('form::onSubmit'); return false;}">
<input type="text">
<input type="submit" onClick="{alert('button::onClick');}">
</form>
</code></pre>
|
[
{
"answer_id": 35775438,
"author": "Crystal Paladin",
"author_id": 5917094,
"author_profile": "https://Stackoverflow.com/users/5917094",
"pm_score": 0,
"selected": false,
"text": "<FORM onSubmit=\"{alert('form::onSubmit'); return false;}\">\n <INPUT TYPE=\"text\">\n <input type=\"hidden\" name=\"dummy\">\n <INPUT TYPE=\"submit\" onClick=\"{alert('buttom::onClick');}\">\n</FORM>\n"
}
] |
2008/08/12
|
[
"https://Stackoverflow.com/questions/9301",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1100/"
] |
9,303 |
<p>How do you retrieve selected text using Regex in C#?</p>
<p>I am looking for C# code that is equivalent to this Perl code:</p>
<pre><code>$indexVal = 0;
if($string =~ /Index: (\d*)/){$indexVal = $1;}
</code></pre>
|
[
{
"answer_id": 9306,
"author": "Patrick",
"author_id": 429,
"author_profile": "https://Stackoverflow.com/users/429",
"pm_score": 4,
"selected": true,
"text": "int indexVal = 0;\nRegex re = new Regex(@\"Index: (\\d*)\")\nMatch m = re.Match(s)\n\nif(m.Success)\n indexVal = int.TryParse(m.Groups[1].toString());\n"
},
{
"answer_id": 9307,
"author": "Dillie-O",
"author_id": 71,
"author_profile": "https://Stackoverflow.com/users/71",
"pm_score": 1,
"selected": false,
"text": "Regex MagicRegex = new Regex(RegexExpressionString);\nMatch RegexMatch;\nstring CapturedResults;\n\nRegexMatch = MagicRegex.Match(SourceDataString);\nCapturedResults = RegexMatch.Groups[1].Value;\n"
},
{
"answer_id": 9318,
"author": "Jeff Atwood",
"author_id": 1,
"author_profile": "https://Stackoverflow.com/users/1",
"pm_score": 3,
"selected": false,
"text": "Regex.Match(s, @\"Index (?<num>\\d*)\").Groups[\"num\"].Value\n"
},
{
"answer_id": 9322,
"author": "andynil",
"author_id": 446,
"author_profile": "https://Stackoverflow.com/users/446",
"pm_score": 1,
"selected": false,
"text": "int indexVal = 0;\nRegex re = new Regex(@\"Index: (\\d*)\");\nMatch m = re.Match(s);\n\nif (m.Success)\n indexVal = m.Groups[1].Index;\n int indexVal = 0;\nMatch m2 = Regex.Match(s, @\"Index: (?<myIndex>\\d*)\");\n\nif (m2.Success)\n indexVal = m2.Groups[\"myIndex\"].Index;\n"
},
{
"answer_id": 11302661,
"author": "burning_LEGION",
"author_id": 1477076,
"author_profile": "https://Stackoverflow.com/users/1477076",
"pm_score": 0,
"selected": false,
"text": "int indexVal = 0;\nRegex re = new Regex.Match(s, @\"(<?=Index: )(\\d*)\");\n\nif(re.Success)\n{\n indexVal = Convert.ToInt32(re.Value);\n}\n"
}
] |
2008/08/12
|
[
"https://Stackoverflow.com/questions/9303",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/889/"
] |
9,304 |
<p><em>Note: This was posted when I was starting out C#. With 2014 knowledge, I can truly say that auto-properties are among the best things that ever happened to the C# language.</em></p>
<p>I am used to create my properties in C# using a private and a public field:</p>
<pre><code>private string title;
public string Title
{
get { return title; }
set { title = value; }
}
</code></pre>
<p>Now, with <a href="http://en.wikipedia.org/wiki/.NET_Framework" rel="noreferrer">.NET</a> 3.0, we got auto-properties:</p>
<pre><code>public string Title { get; set; }
</code></pre>
<p>I know this is more a philosophical/subjective questions, but is there any reason to use these auto-properties except from saving five lines of code for each field? My personal gripe is that those properties are hiding stuff from me, and I am not a big fan of black magic.</p>
<p>In fact, the hidden private field does not even show up in the debugger, which is OK given the fact that the get/set functions do nothing. But when I want to actually implement some getter/setter logic, I have to use the private/public pair anyway.</p>
<p>I see the benefit that I save a lot of code (one vs six lines) without losing the ability to change the getter/setter logic later, but then again I can already do that by simply declaring a public field "Public string Title" without the need of the { get; set; } block, thus even saving more code.</p>
<p>So, what am I missing here? Why would anyone actually want to use auto-properties?</p>
|
[
{
"answer_id": 9315,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": 3,
"selected": false,
"text": "public string Name = \"DefaultName\";\n"
},
{
"answer_id": 9342,
"author": "Mike Stone",
"author_id": 122,
"author_profile": "https://Stackoverflow.com/users/122",
"pm_score": 3,
"selected": false,
"text": "attr_accessor :my_property\nattr_reader :my_getter\nattr_writer :my_setter\n"
},
{
"answer_id": 9529,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 6,
"selected": false,
"text": "public string PropertyName { get; private set; }\n readonly public string PropertyName { get; }\n\npublic MyClass() { this.PropertyName = \"whatever\"; }\n readonly string pName;\npublic string PropertyName { get { return this.pName; } }\n\npublic MyClass() { this.pName = \"whatever\"; }\n"
},
{
"answer_id": 19624,
"author": "Brian Leahy",
"author_id": 580,
"author_profile": "https://Stackoverflow.com/users/580",
"pm_score": 0,
"selected": false,
"text": " private string title;\npublic string Title\n{\n get { return title; }\n set { title = value; }\n}\n"
},
{
"answer_id": 30747,
"author": "Domenic",
"author_id": 3191,
"author_profile": "https://Stackoverflow.com/users/3191",
"pm_score": 4,
"selected": false,
"text": "private readonly string title;\npublic string Title\n{\n get { return this.title; }\n}\n get private set"
},
{
"answer_id": 35909,
"author": "Andrei Rînea",
"author_id": 1796,
"author_profile": "https://Stackoverflow.com/users/1796",
"pm_score": 0,
"selected": false,
"text": "public string Title { get; }\n public string Title { get; private set; }\n"
}
] |
2008/08/12
|
[
"https://Stackoverflow.com/questions/9304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91/"
] |
9,314 |
<p>I have a .NET 2.0 windows forms app, which makes heavy use of the <code>ListView</code> control.</p>
<p>I've subclassed the <code>ListView</code> class into a templated <code>SortableListView<T></code> class, so it can be a bit smarter about how it displays things, and sort itself.</p>
<p>Unfortunately this seems to break the Visual Studio Forms Designer, in both VS2005 and 2008.</p>
<p>The program compiles and runs fine, but when I try view the owning form in the designer, I get these Errors:</p>
<ul>
<li>Could not find type 'MyApp.Controls.SortableListView'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built.</li>
</ul>
<p>There is no stack trace or error line information available for this error </p>
<ul>
<li>The variable 'listViewImages' is either undeclared or was never assigned. </li>
</ul>
<p>At MyApp.Main.Designer.cs Line:XYZ Column:1</p>
<pre><code>Call stack:
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)
</code></pre>
<p>The line of code in question is where it is actually added to the form, and is</p>
<pre><code>this.imagesTab.Controls.Add( this.listViewImages );
</code></pre>
<p>listViewImages is declared as</p>
<pre><code>private MyApp.Controls.SortableListView<Image> listViewImages;
</code></pre>
<p>and is instantiated in the <code>InitializeComponent</code> method as follows:</p>
<pre><code>this.listViewImages = new MyApp.Controls.SortableListView<Image>();
</code></pre>
<p>As mentioned earlier, the program compiles and runs perfectly, and I've tried shifting the <code>SortableListView</code> class out to a seperate assembly so it can be compiled seperately, but this makes no difference.</p>
<p>I have no idea where to go from here. Any help would be appreciated!</p>
|
[
{
"answer_id": 9320,
"author": "lomaxx",
"author_id": 493,
"author_profile": "https://Stackoverflow.com/users/493",
"pm_score": 3,
"selected": false,
"text": "using My.Other.Namespace;\n"
},
{
"answer_id": 9387,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": 4,
"selected": true,
"text": "Main.Designer.cs System.Windows.Forms.ListView MyApp.Controls.SortableListView<Image> class ImagesListView : SortableListView<Image> { }\n Main.Designer.cs SortableListView SortableListView"
},
{
"answer_id": 1293135,
"author": "Unsliced",
"author_id": 2902,
"author_profile": "https://Stackoverflow.com/users/2902",
"pm_score": 1,
"selected": false,
"text": "if (this.DesignMode) return;\n private readonly Client _client = new Client();\n private Client _client;\n\npublic new void Load()\n{\n if(DesignMode) return;\n _client = new Client();\n}\n"
},
{
"answer_id": 11748957,
"author": "PahanCS",
"author_id": 1566944,
"author_profile": "https://Stackoverflow.com/users/1566944",
"pm_score": 2,
"selected": false,
"text": " /// <summary>\n /// Required designer variable.\n /// </summary>\n private System.ComponentModel.IContainer components = null;\n\n /// <summary>\n /// Release all resources used.\n /// </summary>\n /// <param name=\"disposing\">true if managed resources should be removed otherwise; false.</param>\n protected override void Dispose(bool disposing)\n {\n if (disposing && (components != null))\n {\n components.Dispose();\n }\n base.Dispose(disposing);\n }\n\n private void InitializeComponent()\n {\n // ...\n this.components = new System.ComponentModel.Container(); // Not necessarily, if You do not use\n // ...\n }\n"
},
{
"answer_id": 20070749,
"author": "Nila",
"author_id": 2663777,
"author_profile": "https://Stackoverflow.com/users/2663777",
"pm_score": 1,
"selected": false,
"text": "InitializeComponent InitializeComponent this->resources = (gcnew System::ComponentModel::ComponentResourceManager(XXX::typeid));\n"
}
] |
2008/08/12
|
[
"https://Stackoverflow.com/questions/9314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/234/"
] |
9,321 |
<p>How do you create a static class in C++? I should be able to do something like:</p>
<pre><code>cout << "bit 5 is " << BitParser::getBitAt(buffer, 5) << endl;
</code></pre>
<p>Assuming I created the <code>BitParser</code> class. What would the <code>BitParser</code> class definition look like?</p>
|
[
{
"answer_id": 9326,
"author": "Philip Reynolds",
"author_id": 1087,
"author_profile": "https://Stackoverflow.com/users/1087",
"pm_score": 4,
"selected": false,
"text": "class BitParser {\npublic:\n ...\n static ... getBitAt(...) {\n }\n};\n"
},
{
"answer_id": 9328,
"author": "OJ.",
"author_id": 611,
"author_profile": "https://Stackoverflow.com/users/611",
"pm_score": 9,
"selected": true,
"text": "class BitParser\n{\n public:\n static bool getBitAt(int buffer, int bitIndex);\n\n // ...lots of great stuff\n\n private:\n // Disallow creating an instance of this object\n BitParser() {}\n};\n bool BitParser::getBitAt(int buffer, int bitIndex)\n{\n bool isBitSet = false;\n // .. determine if bit is set\n return isBitSet;\n}\n"
},
{
"answer_id": 9348,
"author": "Matt Price",
"author_id": 852,
"author_profile": "https://Stackoverflow.com/users/852",
"pm_score": 6,
"selected": false,
"text": "namespace BitParser\n{\n bool getBitAt(int buffer, int bitIndex);\n}\n namespace BitParser\n{\n bool getBitAt(int buffer, int bitIndex)\n {\n //get the bit :)\n }\n}\n"
},
{
"answer_id": 112451,
"author": "paercebal",
"author_id": 14089,
"author_profile": "https://Stackoverflow.com/users/14089",
"pm_score": 8,
"selected": false,
"text": "// header\nclass MyClass\n{\n public :\n static void myMethod() ;\n} ;\n\n// source\nvoid MyClass::myMethod()\n{\n // etc.\n}\n // header\nnamespace MyNamespace\n{\n void myMethod() ;\n}\n\n// source\nnamespace MyNamespace\n{\n void myMethod()\n {\n // etc.\n }\n}\n // HPP\n\nclass Foo\n{\n public :\n void barA() ;\n private :\n void barB() ;\n static std::string myGlobal ;\n} ;\n // CPP\nstd::string Foo::myGlobal ; // You MUST declare it in a CPP\n\nvoid Foo::barA()\n{\n // I can access Foo::myGlobal\n}\n\nvoid Foo::barB()\n{\n // I can access Foo::myGlobal, too\n}\n\nvoid barC()\n{\n // I CAN'T access Foo::myGlobal !!!\n}\n private // HPP\n\nnamespace Foo\n{\n void barA() ;\n}\n // CPP\nnamespace Foo\n{\n namespace\n {\n std::string myGlobal ;\n\n void Foo::barB()\n {\n // I can access Foo::myGlobal\n }\n }\n\n void barA()\n {\n // I can access myGlobal, too\n }\n}\n\nvoid barC()\n{\n // I STILL CAN'T access myGlobal !!!\n}\n private private private namespace alpha\n{\n void foo() ;\n void bar() ;\n}\n\nstruct Beta\n{\n static void foo() ;\n static void bar() ;\n};\n\ntemplate <typename T>\nstruct Gamma\n{\n void foobar()\n {\n T::foo() ;\n T::bar() ;\n }\n};\n\nGamma<alpha> ga ; // compilation error\nGamma<Beta> gb ; // ok\ngb.foobar() ; // ok !!!\n"
},
{
"answer_id": 2715977,
"author": "John",
"author_id": 326261,
"author_profile": "https://Stackoverflow.com/users/326261",
"pm_score": 2,
"selected": false,
"text": "MyNamespace.Function(blah);\n class TheDataToBeHidden\n{\n public:\n static int _var1;\n static int _var2;\n};\n\nnamespace SharedData\n{\n void SetError(const char *Message, const char *Title);\n void DisplayError(void);\n}\n //Init the data (Link error if not done)\nint TheDataToBeHidden::_var1 = 0;\nint TheDataToBeHidden::_var2 = 0;\n\n\n//Implement the namespace\nnamespace SharedData\n{\n void SetError(const char *Message, const char *Title)\n {\n //blah using TheDataToBeHidden::_var1, etc\n }\n\n void DisplayError(void)\n {\n //blah\n }\n}\n #include \"SharedModule.h\"\n //Call the functions using the hidden variables\nSharedData::SetError(\"Hello\", \"World\");\nSharedData::DisplayError();\n"
},
{
"answer_id": 3015915,
"author": "Malc B",
"author_id": 363621,
"author_profile": "https://Stackoverflow.com/users/363621",
"pm_score": 2,
"selected": false,
"text": "public ref class BitParser abstract sealed\n{\n public:\n static bool GetBitAt(...)\n {\n ...\n }\n}\n"
},
{
"answer_id": 31201984,
"author": "Ciro Santilli OurBigBook.com",
"author_id": 895245,
"author_profile": "https://Stackoverflow.com/users/895245",
"pm_score": 4,
"selected": false,
"text": "static class static struct S { // valid C, invalid in C++\n int i;\n};\n struct class static struct"
},
{
"answer_id": 49405640,
"author": "Mikhail Vasilyev",
"author_id": 4432988,
"author_profile": "https://Stackoverflow.com/users/4432988",
"pm_score": 3,
"selected": false,
"text": "final static class class BitParser final\n{\npublic:\n BitParser() = delete;\n\n static bool GetBitAt(int buffer, int pos);\n};\n\nbool BitParser::GetBitAt(int buffer, int pos)\n{\n // your code\n}\n"
},
{
"answer_id": 50016722,
"author": "Josh Olson",
"author_id": 9209968,
"author_profile": "https://Stackoverflow.com/users/9209968",
"pm_score": 0,
"selected": false,
"text": "class Class {\n public:\n void foo() { Static::bar(*this); } \n\n private:\n int member{0};\n friend class Static;\n}; \n\nclass Static {\n public:\n template <typename T>\n static void bar(T& t) {\n t.member = 1;\n }\n};\n"
},
{
"answer_id": 61626014,
"author": "hecate",
"author_id": 6426767,
"author_profile": "https://Stackoverflow.com/users/6426767",
"pm_score": 2,
"selected": false,
"text": "private class Foo {\n public:\n static int someMethod(int someArg);\n\n private:\n virtual void __dummy() = 0;\n};\n final // C++11 ONLY\nclass Foo final {\n public:\n static int someMethod(int someArg);\n\n private:\n virtual void __dummy() = 0;\n};\n final // C++11 ONLY\nclass Foo final {\n public:\n static int someMethod(int someArg);\n\n private:\n // Other private declarations\n\n virtual void __dummy() = 0 final;\n}; // Foo now exhibits all the properties of a static class\n"
},
{
"answer_id": 66422537,
"author": "Саша Зезюлинский",
"author_id": 857684,
"author_profile": "https://Stackoverflow.com/users/857684",
"pm_score": 0,
"selected": false,
"text": "class A final {\n ~A() = delete;\n static bool your_func();\n}\n final delete static class namespace static"
}
] |
2008/08/12
|
[
"https://Stackoverflow.com/questions/9321",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/432/"
] |
9,336 |
<p>I'm trying to generate a sitemap.xml on the fly for a particular asp.net website.</p>
<p>I found a couple solutions:<br /></p>
<ol>
<li><a href="http://sitemap.chinookwebs.com/" rel="nofollow noreferrer">chinookwebs</a></li>
<li><a href="http://web.archive.org/web/20080307061444/http://www.cervoproject.info:80/sitemaps.aspx" rel="nofollow noreferrer">cervoproject</a></li>
<li><a href="http://www.codeplex.com/Sitemaps" rel="nofollow noreferrer">newtonking</a></li>
</ol>
<p>Chinookwebs is working great but seems a bit inactive right now and it's impossible to personalize the "priority" and the "changefreq" tags of each and every page, they all inherit the same value from the config file.</p>
<p>What solutions do you guys use?</p>
|
[
{
"answer_id": 9533,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": true,
"text": "void IHttpHandler.ProcessRequest(HttpContext context)\n{\n //\n // Important to return qualified XML (text/xml) for sitemaps\n //\n context.Response.ClearHeaders();\n context.Response.ClearContent();\n context.Response.ContentType = \"text/xml\";\n //\n // Create an XML writer\n //\n XmlTextWriter writer = new XmlTextWriter(context.Response.Output);\n writer.WriteStartDocument();\n writer.WriteStartElement(\"urlset\", \"http://www.sitemaps.org/schemas/sitemap/0.9\");\n //\n // Now add entries for individual pages..\n //\n writer.WriteStartElement(\"url\");\n writer.WriteElementString(\"loc\", \"http://www.codingthewheel.com\");\n // use W3 date format..\n writer.WriteElementString(\"lastmod\", postDate.ToString(\"yyyy-MM-dd\"));\n writer.WriteElementString(\"changefreq\", \"daily\");\n writer.WriteElementString(\"priority\", \"1.0\");\n writer.WriteEndElement();\n //\n // Close everything out and go home.\n //\n result.WriteEndElement();\n result.WriteEndDocument();\n writer.Flush();\n}\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9336",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/296/"
] |
9,338 |
<p>One of the articles I really enjoyed reading recently was <a href="http://blog.last.fm/2008/08/01/quality-control" rel="nofollow noreferrer">Quality Control by Last.FM</a>. In the spirit of this article, I was wondering if anyone else had favorite monitoring setups for web type applications. Or maybe if you don't believe in Log Monitoring, why?<br>
I'm looking for a mix of opinion slash experience here I guess.</p>
|
[
{
"answer_id": 9533,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": true,
"text": "void IHttpHandler.ProcessRequest(HttpContext context)\n{\n //\n // Important to return qualified XML (text/xml) for sitemaps\n //\n context.Response.ClearHeaders();\n context.Response.ClearContent();\n context.Response.ContentType = \"text/xml\";\n //\n // Create an XML writer\n //\n XmlTextWriter writer = new XmlTextWriter(context.Response.Output);\n writer.WriteStartDocument();\n writer.WriteStartElement(\"urlset\", \"http://www.sitemaps.org/schemas/sitemap/0.9\");\n //\n // Now add entries for individual pages..\n //\n writer.WriteStartElement(\"url\");\n writer.WriteElementString(\"loc\", \"http://www.codingthewheel.com\");\n // use W3 date format..\n writer.WriteElementString(\"lastmod\", postDate.ToString(\"yyyy-MM-dd\"));\n writer.WriteElementString(\"changefreq\", \"daily\");\n writer.WriteElementString(\"priority\", \"1.0\");\n writer.WriteEndElement();\n //\n // Close everything out and go home.\n //\n result.WriteEndElement();\n result.WriteEndDocument();\n writer.Flush();\n}\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1063/"
] |
9,341 |
<p>Simple ASP.NET application.</p>
<p>I have two drop-down controls. On the first-drop down I have a JavaScript <code>onChange</code> event. The JavaScript enables the second drop-down and removes a value from it (the value selected in the first drop-down). If they click the blank first value of the drop-down, then the second drop-down will be disabled (and the options reset).</p>
<p>I also have code in the <code>OnPreRender</code> method that will enable or disable the second drop-down based on the value of the first drop-down. This is so that the value of the first drop-down can be selected in code (loading user settings).</p>
<p>My problem is:</p>
<ol>
<li>The user selects something in the first drop-down. The second drop-down will become enabled through JavaScript. </li>
<li>They then change a third drop-down that initiates a post back. After the post back the drop-downs are in the correct state (first value selected, second drop-down enabled).</li>
<li>If they then click the back button, the second drop-down will no longer be enabled although it should be since there's something selected in the first drop-down.</li>
</ol>
<p>I've tried adding a startup script (that will set the correct state of the second-drop down) through <code>ClientScript.RegisterStartupScript</code>, however when this gets called the first drop-down has a <code>selectedIndex</code> of <code>0</code>, not what it actually is. My guess is that the value of the selection gets set after my start script (but still doesn't call the <code>onChange</code> script).</p>
<p>Any ideas on what to try?</p>
|
[
{
"answer_id": 9365,
"author": "Adhip Gupta",
"author_id": 384,
"author_profile": "https://Stackoverflow.com/users/384",
"pm_score": 3,
"selected": true,
"text": "<%@ Page Language=\"C#\" %>\n\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n<script runat=\"server\">\n protected void indexChanged(object sender, EventArgs e)\n {\n Label1.Text = \" I did something! \";\n }\n</script>\n\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head runat=\"server\">\n <title>Test Page</title>\n</head>\n<body>\n <script type=\"text/javascript\">\n function firstChanged() {\n if(document.getElementById(\"firstSelect\").selectedIndex != 0)\n document.getElementById(\"secondSelect\").disabled = false;\n else\n document.getElementById(\"secondSelect\").disabled = true;\n }\n </script>\n <form id=\"form1\" runat=\"server\">\n <div>\n <select id=\"firstSelect\" onchange=\"firstChanged()\">\n <option value=\"0\"></option>\n <option value=\"1\">One</option>\n <option value=\"2\">Two</option>\n <option value=\"3\">Three</option>\n </select>\n <select id=\"secondSelect\" disabled=\"disabled\">\n <option value=\"1\">One</option>\n <option value=\"2\">Two</option>\n <option value=\"3\">Three</option>\n </select>\n <asp:DropDownList ID=\"DropDownList1\" AutoPostBack=\"true\" OnSelectedIndexChanged=\"indexChanged\" runat=\"server\">\n <asp:ListItem Text=\"One\" Value=\"1\"></asp:ListItem>\n <asp:ListItem Text=\"Two\" Value=\"2\"></asp:ListItem> \n </asp:DropDownList>\n <asp:Label ID=\"Label1\" runat=\"server\"></asp:Label>\n </div>\n </form>\n <script type=\"text/javascript\">\n window.onload = function() {firstChanged();}\n </script>\n</body>\n</html>\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9341",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/233/"
] |
9,355 |
<p>I can display and select a single file in windows explorer like this:</p>
<pre><code>explorer.exe /select, "c:\path\to\file.txt"
</code></pre>
<p>However, I can't work out how to select more than one file. None of the permutations of select I've tried work.</p>
<p>Note: I looked at these pages for docs, neither helped.</p>
<p><a href="https://support.microsoft.com/kb/314853" rel="nofollow noreferrer">https://support.microsoft.com/kb/314853</a><br />
<a href="http://web.archive.org/web/20100716112458/http://www.infocellar.com:80/Win98/explorer-switches.htm" rel="nofollow noreferrer">http://web.archive.org/web/20100716112458/http://www.infocellar.com:80/Win98/explorer-switches.htm</a></p>
|
[
{
"answer_id": 9497,
"author": "bruceatk",
"author_id": 791,
"author_profile": "https://Stackoverflow.com/users/791",
"pm_score": 2,
"selected": false,
"text": "F12:: \n run explorer.exe /select`, \"c:\\path\\to\\file.txt\"\n SendInput {Shift Down}{Down}{Down}{Shift Up}\nreturn\n"
},
{
"answer_id": 233129,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 0,
"selected": false,
"text": "FindWindowEx SendMessage LVM_SETITEMSTATE LVM_FINDITEM"
},
{
"answer_id": 3011284,
"author": "flashk",
"author_id": 25149,
"author_profile": "https://Stackoverflow.com/users/25149",
"pm_score": 5,
"selected": true,
"text": "SHOpenFolderAndSelectItems //Directory to open\nITEMIDLIST *dir = ILCreateFromPath(_T(\"C:\\\\\"));\n\n//Items in directory to select\nITEMIDLIST *item1 = ILCreateFromPath(_T(\"C:\\\\Program Files\\\\\"));\nITEMIDLIST *item2 = ILCreateFromPath(_T(\"C:\\\\Windows\\\\\"));\nconst ITEMIDLIST* selection[] = {item1,item2};\nUINT count = sizeof(selection) / sizeof(ITEMIDLIST);\n\n//Perform selection\nSHOpenFolderAndSelectItems(dir, count, selection, 0);\n\n//Free resources\nILFree(dir);\nILFree(item1);\nILFree(item2);\n"
},
{
"answer_id": 3576444,
"author": "Siarhei Kuchuk",
"author_id": 212746,
"author_profile": "https://Stackoverflow.com/users/212746",
"pm_score": 3,
"selected": false,
"text": "static class NativeMethods\n{\n [DllImport(\"shell32.dll\", ExactSpelling = true)]\n public static extern int SHOpenFolderAndSelectItems(\n IntPtr pidlFolder,\n uint cidl,\n [In, MarshalAs(UnmanagedType.LPArray)] IntPtr[] apidl,\n uint dwFlags);\n\n [DllImport(\"shell32.dll\", CharSet = CharSet.Auto)]\n public static extern IntPtr ILCreateFromPath([MarshalAs(UnmanagedType.LPTStr)] string pszPath);\n\n [ComImport]\n [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]\n [Guid(\"000214F9-0000-0000-C000-000000000046\")]\n public interface IShellLinkW\n {\n [PreserveSig]\n int GetPath(StringBuilder pszFile, int cch, [In, Out] ref WIN32_FIND_DATAW pfd, uint fFlags);\n\n [PreserveSig]\n int GetIDList([Out] out IntPtr ppidl);\n\n [PreserveSig]\n int SetIDList([In] ref IntPtr pidl);\n\n [PreserveSig]\n int GetDescription(StringBuilder pszName, int cch);\n\n [PreserveSig]\n int SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);\n\n [PreserveSig]\n int GetWorkingDirectory(StringBuilder pszDir, int cch);\n\n [PreserveSig]\n int SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);\n\n [PreserveSig]\n int GetArguments(StringBuilder pszArgs, int cch);\n\n [PreserveSig]\n int SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);\n\n [PreserveSig]\n int GetHotkey([Out] out ushort pwHotkey);\n\n [PreserveSig]\n int SetHotkey(ushort wHotkey);\n\n [PreserveSig]\n int GetShowCmd([Out] out int piShowCmd);\n\n [PreserveSig]\n int SetShowCmd(int iShowCmd);\n\n [PreserveSig]\n int GetIconLocation(StringBuilder pszIconPath, int cch, [Out] out int piIcon);\n\n [PreserveSig]\n int SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);\n\n [PreserveSig]\n int SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, uint dwReserved);\n\n [PreserveSig]\n int Resolve(IntPtr hwnd, uint fFlags);\n\n [PreserveSig]\n int SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);\n }\n\n [Serializable, StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode), BestFitMapping(false)]\n public struct WIN32_FIND_DATAW\n {\n public uint dwFileAttributes;\n public FILETIME ftCreationTime;\n public FILETIME ftLastAccessTime;\n public FILETIME ftLastWriteTime;\n public uint nFileSizeHigh;\n public uint nFileSizeLow;\n public uint dwReserved0;\n public uint dwReserved1;\n\n [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]\n public string cFileName;\n\n [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]\n public string cAlternateFileName;\n }\n\n public static void OpenFolderAndSelectFiles(string folder, params string[] filesToSelect)\n {\n IntPtr dir = ILCreateFromPath(folder);\n\n var filesToSelectIntPtrs = new IntPtr[filesToSelect.Length];\n for (int i = 0; i < filesToSelect.Length; i++)\n {\n filesToSelectIntPtrs[i] = ILCreateFromPath(filesToSelect[i]);\n }\n\n SHOpenFolderAndSelectItems(dir, (uint) filesToSelect.Length, filesToSelectIntPtrs, 0);\n ReleaseComObject(dir);\n ReleaseComObject(filesToSelectIntPtrs);\n }\n\n private static void ReleaseComObject(params object[] comObjs)\n {\n foreach (object obj in comObjs)\n {\n if (obj != null && Marshal.IsComObject(obj))\n Marshal.ReleaseComObject(obj);\n }\n }\n}\n"
},
{
"answer_id": 59517153,
"author": "stax76",
"author_id": 4526366,
"author_profile": "https://Stackoverflow.com/users/4526366",
"pm_score": 2,
"selected": false,
"text": "$shell = New-Object -ComObject Shell.Application\n\nfunction SelectFiles($filesToSelect)\n{\n foreach ($fileToSelect in $filesToSelect)\n {\n foreach ($window in $shell.Windows())\n {\n foreach ($folderItem in $window.Document.Folder.Items())\n {\n if ($folderItem.Path -eq $fileToSelect)\n {\n $window.Document.SelectItem($folderItem, 1 + 8)\n }\n }\n }\n }\n}\n Option Strict Off\n\nImports Microsoft.VisualBasic\n\nPublic Class ExplorerHelp\n Shared ShellApp As Object = CreateObject(\"Shell.Application\")\n\n Shared Sub SelectFile(filepath As String)\n For Each i In ShellApp.Windows\n For Each i2 In i.Document.Folder.Items()\n If i2.Path = filepath Then\n i.Document.SelectItem(i2, 1 + 8)\n Exit Sub\n End If\n Next\n Next\n End Sub\nEnd Class\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9355",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/234/"
] |
9,376 |
<p>Do you use ILMerge? Do you use ILMerge to merge multiple assemblies to ease deployment of dll's? Have you found problems with deployment/versioning in production after ILMerging assemblies together?</p>
<p>I'm looking for some advice in regards to using ILMerge to reduce deployment friction, if that is even possible.</p>
|
[
{
"answer_id": 9784933,
"author": "Contango",
"author_id": 107409,
"author_profile": "https://Stackoverflow.com/users/107409",
"pm_score": 5,
"selected": false,
"text": ".exe + .dll files combined .exe .pdb Post Build String \"$(SolutionDir)ILMerge\\ILMerge.exe\" /out:\"$(TargetDir)$(TargetName).all.exe\" \"$(TargetDir)$(TargetName).exe\" \"$(TargetDir)*.dll\" /target:exe /targetplatform:v4,C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319 /wildcards\n AssemblyName.all.exe ILMerge\\ Output Show output from: Build .exe + .dll files combined .exe Post Build Build Events ILMerge.exe rem Create a single .exe that combines the root .exe and all subassemblies.\n\"$(SolutionDir)ILMerge\\ILMerge.exe\" /out:\"$(TargetDir)$(TargetName).all.exe\" \"$(TargetDir)$(TargetName).exe\" \"$(TargetDir)*.dll\" /target:exe /targetplatform:v4,C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319 /wildcards\nrem Remove all subassemblies.\ndel *.dll\nrem Remove all .pdb files (except the new, combined pdb we just created).\nren \"$(TargetDir)$(TargetName).all.pdb\" \"$(TargetName).all.pdb.temp\"\ndel *.pdb\nren \"$(TargetDir)$(TargetName).all.pdb.temp\" \"$(TargetName).all.pdb\"\nrem Delete the original, non-combined .exe.\ndel \"$(TargetDir)$(TargetName).exe\"\nrem Rename the combined .exe and .pdb to the original project name we started with.\nren \"$(TargetDir)$(TargetName).all.pdb\" \"$(TargetName).pdb\"\nren \"$(TargetDir)$(TargetName).all.exe\" \"$(TargetName).exe\"\nexit 0\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9376",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1083/"
] |
9,383 |
<p>How do you access a SQL Server 2005 Express Edition from a application in a network computer?</p>
<p>The access I need is both from application (Linq-to-SQL and ODBC) and from Management Studio</p>
|
[
{
"answer_id": 9896,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "telnet 192.168.10.10 1433\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9383",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1154/"
] |
9,409 |
<p>I have a datagrid getting bound to a dataset, and I want to display the average result in the footer for a column populated with integers.</p>
<p>The way I figure, there's 2 ways I can think of:</p>
<p>1."Use the <strong>Source</strong>, Luke"<br>
In the code where I'm calling DataGrid.DataBind(), use the DataTable.Compute() method (<em>or in my case DataSet.DataTable(0).Compute()</em>). For example: </p>
<pre><code>Dim strAverage = DataTable.Compute("Avg(ColumnName)", "")
</code></pre>
<p>But once I have this, how can I insert it into the footer?</p>
<p>2."<strong>Bound</strong> for Glory"<br>
Using the DataGrid.ItemDataBound event, and calculating a running total from every ListItemType.Item and ListItemType.AlternatingItem, finally displaying in ListItemType.Footer. For example: </p>
<pre><code>Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
runningTotal += CInt(e.Item.Cells(2).Text)
Case ListItemType.Footer
e.Item.Cells(2).Text = runningTotal/DataGrid.Items.Count
End Select
</code></pre>
<p>This just feels wrong, plus I would have to make sure the runningTotal is reset on every DataBind. </p>
<p>Is there a better way?</p>
|
[
{
"answer_id": 9896,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "telnet 192.168.10.10 1433\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/952/"
] |
9,410 |
<p>I want to create a function that performs a function passed by parameter on a set of data. How do you pass a function as a parameter in C?</p>
|
[
{
"answer_id": 9413,
"author": "Niyaz",
"author_id": 184,
"author_profile": "https://Stackoverflow.com/users/184",
"pm_score": 11,
"selected": true,
"text": "void func ( void (*f)(int) );\n f void int print func void print ( int x ) {\n printf(\"%d\\n\", x);\n}\n func(print);\n func func func for ( int ctr = 0 ; ctr < 5 ; ctr++ ) {\n print(ctr);\n}\n func f f *f f print *f void func ( void (*f)(int) ) {\n for ( int ctr = 0 ; ctr < 5 ; ctr++ ) {\n (*f)(ctr);\n }\n}\n"
},
{
"answer_id": 9421,
"author": "roo",
"author_id": 716,
"author_profile": "https://Stackoverflow.com/users/716",
"pm_score": 7,
"selected": false,
"text": "typedef void (*functiontype)();\n void dosomething() { }\n\nfunctiontype func = &dosomething;\nfunc();\n typedef int (*functiontype2)(char);\n int dosomethingwithchar(char a) { return 1; }\n\nfunctiontype2 func2 = &dosomethingwithchar\nint result = func2('a');\n boost::function<int (char a)> functiontype2;\n"
},
{
"answer_id": 31521586,
"author": "Richard",
"author_id": 752843,
"author_profile": "https://Stackoverflow.com/users/752843",
"pm_score": 7,
"selected": false,
"text": "std::function<bool (int)>\n bool int // g++ test.cpp --std=c++11\n#include <functional>\n\ndouble Combiner(double a, double b, std::function<double (double,double)> func){\n return func(a,b);\n}\n\ndouble Add(double a, double b){\n return a+b;\n}\n\ndouble Mult(double a, double b){\n return a*b;\n}\n\nint main(){\n Combiner(12,13,Add);\n Combiner(12,13,Mult);\n}\n // g++ test.cpp --std=c++11\n\ntemplate<class T>\ndouble Combiner(double a, double b, T func){\n return func(a,b);\n}\n\ndouble Add(double a, double b){\n return a+b;\n}\n\ndouble Mult(double a, double b){\n return a*b;\n}\n\nint main(){\n Combiner(12,13,Add);\n Combiner(12,13,Mult);\n}\n"
},
{
"answer_id": 33870738,
"author": "Yogeesh H T",
"author_id": 3725702,
"author_profile": "https://Stackoverflow.com/users/3725702",
"pm_score": 5,
"selected": false,
"text": "#include <stdio.h>\n\nvoid print();\nvoid execute(void());\n\nint main()\n{\n execute(print); // sends address of print\n return 0;\n}\n\nvoid print()\n{\n printf(\"Hello!\");\n}\n\nvoid execute(void f()) // receive address of print\n{\n f();\n}\n #include <stdio.h>\n\nvoid print();\nvoid execute(void (*f)());\n\nint main()\n{\n execute(&print); // sends address of print\n return 0;\n}\n\nvoid print()\n{\n printf(\"Hello!\");\n}\n\nvoid execute(void (*f)()) // receive address of print\n{\n f();\n}\n"
},
{
"answer_id": 53503192,
"author": "doppelheathen",
"author_id": 4206613,
"author_profile": "https://Stackoverflow.com/users/4206613",
"pm_score": 4,
"selected": false,
"text": "void foo(int bar(int, int));\n void foo(int (*bar)(int, int));\n"
},
{
"answer_id": 55174838,
"author": "Walter",
"author_id": 7270598,
"author_profile": "https://Stackoverflow.com/users/7270598",
"pm_score": -1,
"selected": false,
"text": "#include <stdio.h>\n\nint IncMultInt(int a, int b)\n{\n a++;\n return a * b;\n}\n\nint main(int argc, char *argv[])\n\n{\n int a = 5;\n int b = 7;\n\n printf(\"%d * %d = %d\\n\", a, b, IncMultInt(a, b));\n\n b = 9;\n\n // Create some local code with it's own local variable\n printf(\"%d * %d = %d\\n\", a, b, ( { int _a = a+1; _a * b; } ) );\n\n return 0;\n}\n"
},
{
"answer_id": 65977096,
"author": "Hemanth Kollipara",
"author_id": 11534375,
"author_profile": "https://Stackoverflow.com/users/11534375",
"pm_score": 2,
"selected": false,
"text": "compare sorting bool compare(int a, int b) {\n return a > b;\n}\n void bubble_sort(int arr[], int n, bool (&cmp)(int a, int b)) {\n\n for (int i = 0;i < n - 1;i++) {\n for (int j = 0;j < (n - 1 - i);j++) {\n \n if (cmp(arr[j], arr[j + 1])) {\n swap(arr[j], arr[j + 1]);\n }\n }\n }\n}\n main int main()\n{\n int i, n = 10, key = 11;\n int arr[10] = { 20, 22, 18, 8, 12, 3, 6, 12, 11, 15 };\n\n bubble_sort(arr, n, compare);\n cout<<\"Sorted Order\"<<endl;\n for (int i = 0;i < n;i++) {\n cout << arr[i] << \" \";\n }\n}\n Sorted Order\n3 6 8 11 12 12 15 18 20 22\n"
},
{
"answer_id": 69301994,
"author": "mada",
"author_id": 16972547,
"author_profile": "https://Stackoverflow.com/users/16972547",
"pm_score": -1,
"selected": false,
"text": "typedef int function();\n\nfunction *g(function *f)\n{\n f();\n return f;\n}\n\nint main(void)\n{\n function f;\n\n function *fn = g(f);\n\n fn();\n}\n\nint f() { return 0; }\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9410",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/432/"
] |
9,434 |
<p>In my ASP.NET User Control I'm adding some JavaScript to the <code>window.onload</code> event:</p>
<pre><code>if (!Page.ClientScript.IsStartupScriptRegistered(this.GetType(), onloadScriptName))
Page.ClientScript.RegisterStartupScript(this.GetType(), onloadScriptName,
"window.onload = function() {myFunction();};", true);
</code></pre>
<p>My problem is, if there is already something in the <code>onload</code> event, than this overwrites it. How would I go about allowing two user controls to each execute JavaScript in the <code>onload</code> event?</p>
<p><strong>Edit:</strong> Thanks for the info on third party libraries. I'll keep them in mind. </p>
|
[
{
"answer_id": 9447,
"author": "Chris Farmer",
"author_id": 404,
"author_profile": "https://Stackoverflow.com/users/404",
"pm_score": 2,
"selected": false,
"text": "window.attachEvent(\"onload\", myOtherFunctionToCall);\n\nfunction myOtherFunctionToCall() {\n // do something\n}\n"
},
{
"answer_id": 9451,
"author": "Derek Park",
"author_id": 872,
"author_profile": "https://Stackoverflow.com/users/872",
"pm_score": 1,
"selected": false,
"text": "Page.ClientScript.RegisterStartupScript(\n this.GetType(), key1, function1, true);\n\nPage.ClientScript.RegisterStartupScript(\n this.GetType(), key2, function2, true);\n"
},
{
"answer_id": 9470,
"author": "cole",
"author_id": 910,
"author_profile": "https://Stackoverflow.com/users/910",
"pm_score": 2,
"selected": false,
"text": "window.addEvent('domready', function(){\n alert('Just put all your code here');\n});\n"
},
{
"answer_id": 9814,
"author": "Vincent Robert",
"author_id": 268,
"author_profile": "https://Stackoverflow.com/users/268",
"pm_score": 4,
"selected": false,
"text": "addEventListener attachEvent onload function addOnLoad(fn)\n{ \n var old = window.onload;\n window.onload = function()\n {\n old();\n fn();\n };\n}\n\naddOnLoad(function()\n{\n // your code here\n});\naddOnLoad(function()\n{\n // your code here\n});\naddOnLoad(function()\n{\n // your code here\n});\n"
},
{
"answer_id": 688199,
"author": "user83421",
"author_id": 83421,
"author_profile": "https://Stackoverflow.com/users/83421",
"pm_score": 8,
"selected": true,
"text": "if (window.addEventListener) // W3C standard\n{\n window.addEventListener('load', myFunction, false); // NB **not** 'onload'\n} \nelse if (window.attachEvent) // Microsoft\n{\n window.attachEvent('onload', myFunction);\n}\n"
},
{
"answer_id": 4320764,
"author": "Fábio de Lima Souto",
"author_id": 495410,
"author_profile": "https://Stackoverflow.com/users/495410",
"pm_score": 3,
"selected": false,
"text": "index.js window.onloadFuncs = [];\n\nwindow.onload = function()\n{\n for(var i in this.onloadFuncs)\n {\n this.onloadFuncs[i]();\n }\n}\n window.onloadFuncs.push(function(){\n // code here\n});\n"
},
{
"answer_id": 12192966,
"author": "DadViegas",
"author_id": 1354106,
"author_profile": "https://Stackoverflow.com/users/1354106",
"pm_score": 1,
"selected": false,
"text": "$(window).load(function () {\n // jQuery functions to initialize after the page has loaded.\n});\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9434",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/233/"
] |
9,435 |
<p>We are in the initial planning stages of building out a mobile site for one of our clients. This mobile site will be in addition to the main site that we have already built for them. We've determined that the content is going to be a small subsection of the main site and will target the main audience that is expected to use the site.</p>
<p>While looking through some sample mobile sites we noticed that a lot of site that have WAP in the url are actually just simplified HTML files. <a href="http://wap.mlb.com" rel="nofollow noreferrer">http://wap.mlb.com</a> is not really WAP enabled but simple HTML.</p>
<p>My question is WAP a think of the past? With smartphones and the iPhone having the ability to render sites as is do we need to worry about WML and WAP or will a stripped down html version be enough? </p>
<p>Also can you recommend a blog or tutorial or answer below how best to check for mobile devices? Do we as the programmer need to know each variation of user agent in order to redirect them to our mobile site? </p>
<p>Finally, would you program a mobile site for the iPhone/Touch Safari browser or just leave the site as is?</p>
|
[
{
"answer_id": 15168,
"author": "crashmstr",
"author_id": 1441,
"author_profile": "https://Stackoverflow.com/users/1441",
"pm_score": 2,
"selected": false,
"text": "<script type=\"application/x-javascript\">\n\n if (navigator.userAgent.indexOf('iPhone') != -1) {\n addEventListener(\"load\", function() {\n setTimeout(hideURLbar, 0);\n }, false);\n }\n\n function hideURLbar() {\n window.scrollTo(0, 1);\n }\n\n</script>\n user-scalable=true <meta name=\"viewport\" content=\"width=320; user-scalable=false\" />\n"
},
{
"answer_id": 15688077,
"author": "Tom S",
"author_id": 2220801,
"author_profile": "https://Stackoverflow.com/users/2220801",
"pm_score": 0,
"selected": false,
"text": "<!DOCTYPE HTML>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">\n<title>Photography Aerial Commercial Portrait Underwater Wedding Tom Szabo</title>\n<meta name=\"description\" content=\"A Thomas Image professional photography serving Cleveland\nNortheast Ohio Chagrin Falls Chardon Kirtland Madison Mentor Painesville Perry and Willoughby\">\n<meta name=\"keywords\" content=\"A Thomas Image, professional, photography, cleveland, northeast ohio, chagrin falls, chardon, concord, kirtland, madison, mentor, painesville, perry, willoughby,commercial, marketing, advertising, executive, head shot, portrait, baby, children, family, high school senior, family reunion, underwater, scuba diving, pool party, wedding, bride, groom,\">\n<meta name=\"y_key\" content=\"7b00158550200c1c\">\n<meta name=\"y_key\" content=\"b5a3e0c1d778ff8a\">\n<meta name=\"msvalidate.01\" content=\"7C6C4CEC2EB84051B1DCFEC558B77724\" />\n<meta name=\"verify-v1\" content=\"G4nmk0aesZsCjneBo0W6kVlv5NpImVnTfsQ+fXEk1fA=\" />\n<meta name=\"viewport\" content=”width=320,user-scalable=false”>\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9435",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/648/"
] |
9,455 |
<p>Has anyone been able to get xinc to run correctly under OpenBSD's chrooted default Apache? I'd like to keep our development server running fully chrooted just like our Production server so that we make sure our code runs just fine chrooted.</p>
|
[
{
"answer_id": 24990,
"author": "Henrik Gustafsson",
"author_id": 2010,
"author_profile": "https://Stackoverflow.com/users/2010",
"pm_score": 1,
"selected": false,
"text": "systrace -A -d. <app>\nldd <app>\n"
},
{
"answer_id": 36964,
"author": "Till",
"author_id": 2859,
"author_profile": "https://Stackoverflow.com/users/2859",
"pm_score": 2,
"selected": false,
"text": "pear list-files xinc/Xinc\n pear config-get php_dir\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/204/"
] |
9,473 |
<p>I have a custom control that implements IPostBackEventHandler. Some client-side events invoke __doPostBack(controlID, eventArgs).</p>
<p>The control is implemented in two different user controls. In one control, RaisePostBackEvent is fired on the server-side when <code>__doPostBack</code> is invoked. In the other control, RaisePostBackEvent is never invoked. I checked the <code>__EVENTTARGET</code> parameter and it does match the ClientID of the control... where else might I look to troubleshoot this?</p>
|
[
{
"answer_id": 9523,
"author": "Lars Mæhlum",
"author_id": 960,
"author_profile": "https://Stackoverflow.com/users/960",
"pm_score": 0,
"selected": false,
"text": "public class MyControl : UserControl {}\n public class MyControl : WebControl, INamingContainer {}\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9473",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/67/"
] |
9,486 |
<p>I could swear I've seen people typing function headers and then hitting some key combination to auto-create function braces and insert the cursor between them like so:</p>
<pre><code>void foo()_
</code></pre>
<p>to</p>
<pre><code>void foo()
{
_
}
</code></pre>
<p>Is this a built-in feature?</p>
|
[
{
"answer_id": 9494,
"author": "Luke",
"author_id": 327,
"author_profile": "https://Stackoverflow.com/users/327",
"pm_score": 3,
"selected": false,
"text": "Sub FunctionBraces()\n DTE.ActiveDocument.Selection.NewLine\n DTE.ActiveDocument.Selection.Text = \"{}\"\n DTE.ActiveDocument.Selection.CharLeft\n DTE.ActiveDocument.Selection.NewLine(2)\n DTE.ActiveDocument.Selection.LineUp\n DTE.ActiveDocument.Selection.Indent\nEnd Sub\n"
},
{
"answer_id": 12285187,
"author": "PCPGMR",
"author_id": 323650,
"author_profile": "https://Stackoverflow.com/users/323650",
"pm_score": 0,
"selected": false,
"text": "if ()\n{\n\n}\nelse\n{\n\n}\n Sub IfStatement()\n DTE.ActiveDocument.Selection.Text = \"if ()\"\n DTE.ActiveDocument.Selection.NewLine()\n DTE.ActiveDocument.Selection.Text = \"{\"\n DTE.ActiveDocument.Selection.NewLine(2)\n DTE.ActiveDocument.Selection.Text = \"}\"\n DTE.ActiveDocument.Selection.NewLine()\n DTE.ActiveDocument.Selection.Text = \"else\"\n DTE.ActiveDocument.Selection.NewLine(2)\n DTE.ActiveDocument.Selection.Text = \"{\"\n DTE.ActiveDocument.Selection.NewLine(2)\n DTE.ActiveDocument.Selection.Text = \"}\"\n DTE.ActiveDocument.Selection.LineUp(False, 7)\n DTE.ActiveDocument.Selection.EndOfLine()\n DTE.ActiveDocument.Selection.CharLeft(3)\nEnd Sub\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/327/"
] |
9,508 |
<p>This should be fine seeing as the CLR hasn't actually changed?</p>
<p>The boxes running the C# 2.0 code <strong>have</strong> had .NET 3.5 rolled out.</p>
<p>The background is that we have a windows service (.NET 2.0 exe built with VS2005, deployed to ~150 servers) that dynamically loads assemblies (almost like plug-ins) to complete various work items asked of it. Whenever we roll out a new version of the bus logic, we just drop the assemblies on an FTP server and the windows service knows how to check for, grab and store the latest versions. New assemblies are now built using VS2008 and targetting .NET 2.0, we know that works ok. However we'd like to start taking advantage of C# 3.0 language features such as LINQ and targetting the assemblies against .NET 3.5 without having to build and deploy a new version of the windows service.</p>
|
[
{
"answer_id": 9526,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 4,
"selected": true,
"text": "yield var"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9508",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/419/"
] |
9,612 |
<p>I'm trying to set the group type for a new Active Directory Entry via VB.NET and DirectoryServices to create a distribution list.</p>
<p>How do I access the ADS_GROUP_TYPE enumerations?</p>
<p>Specifically I'm after ADS_GROUP_TYPE_GLOBAL_GROUP.</p>
|
[
{
"answer_id": 9617,
"author": "David A Gibson",
"author_id": 982,
"author_profile": "https://Stackoverflow.com/users/982",
"pm_score": 0,
"selected": false,
"text": " Const ADS_GROUP_TYPE_GLOBAL_GROUP As Object = &H2\n adNewGroup.Properties(\"groupType\").Value = ADS_GROUP_TYPE_GLOBAL_GROUP\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/982/"
] |
9,614 |
<p>Suppose we have a table A:</p>
<pre><code>itemid mark
1 5
2 3
</code></pre>
<p>and table B:</p>
<pre><code>itemid mark
1 3
3 5
</code></pre>
<p>I want to join A*B on A.itemid=B.itemid both right and left ways. i.e. result:</p>
<pre><code>itemid A.mark B.mark
1 5 3
2 3 NULL
3 NULL 5
</code></pre>
<p>Is there a way to do it in one query in MySQL?</p>
|
[
{
"answer_id": 9625,
"author": "roo",
"author_id": 716,
"author_profile": "https://Stackoverflow.com/users/716",
"pm_score": 2,
"selected": false,
"text": "select distinct T.itemid, A.mark as \"A.mark\", B.mark as \"B.mark\"\n from (select * from A union select * from B) T \n left join A on T.itemid = A.itemid \n left join B on T.itemid = B.itemid;\n"
},
{
"answer_id": 9626,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": -1,
"selected": false,
"text": "select isnull(a.id, b.id), a.mark, b.mark\nfrom a \nfull outer join b on b.id = a.id\n"
},
{
"answer_id": 9635,
"author": "Nickolay",
"author_id": 1026,
"author_profile": "https://Stackoverflow.com/users/1026",
"pm_score": 4,
"selected": true,
"text": "SELECT *\nFROM A LEFT JOIN B ON A.id = B.id\nUNION ALL\nSELECT *\nFROM A RIGHT JOIN B ON A.id = B.id\nWHERE A.id IS NULL\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/844/"
] |
9,632 |
<p>Apparantly when users right-click in our WPF application, and they use the Windows Classic theme, the default ContextMenu of the TextBox (which contains Copy, Cut and Paste) has a black background.</p>
<p>I know this works well:</p>
<pre><code><Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBox ContextMenu="{x:Null}"/>
</Page>
</code></pre>
<p>But this doesn't work:</p>
<pre><code><Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}">
<Setter Property="ContextMenu" Value="{x:Null}"/>
</Style>
</Page.Resources>
<TextBox/>
</Page>
</code></pre>
<p>Does anyone know how to style or disable the default ContextMenu for all TextBoxes in WPF?</p>
|
[
{
"answer_id": 9864,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": " <Style\n TargetType=\"{x:Type ToolTip}\">\n <Setter\n Property=\"Template\">\n <Setter.Value>\n <ControlTemplate\n TargetType=\"{x:Type ToolTip}\">\n <Grid\n Width=\"{TemplateBinding Width}\"\n Height=\"{TemplateBinding Height}\">\n <Rectangle\n RadiusX=\"9\"\n RadiusY=\"9\"\n Stroke=\"LightGray\"\n StrokeThickness=\"2\">\n <Rectangle.Fill>\n <RadialGradientBrush>\n <GradientStop />\n <GradientStop\n Color=\"FloralWhite\"\n Offset=\"0\" />\n <GradientStop\n Color=\"Cornsilk\"\n Offset=\"2\" />\n </RadialGradientBrush>\n </Rectangle.Fill>\n </Rectangle>\n <ContentPresenter\n Margin=\"6 4 6 4\" />\n </Grid>\n </ControlTemplate>\n </Setter.Value>\n </Setter>\n </Style>\n"
},
{
"answer_id": 9878,
"author": "Arcturus",
"author_id": 900,
"author_profile": "https://Stackoverflow.com/users/900",
"pm_score": 2,
"selected": false,
"text": "TargetType TargetType TextBlock x:Key x:Key {x:Type TextBlock} x:Key {x:Type TextBlock} TextBlock"
},
{
"answer_id": 9897,
"author": "Brad Leach",
"author_id": 708,
"author_profile": "https://Stackoverflow.com/users/708",
"pm_score": 5,
"selected": false,
"text": "<ContextMenu x:Key=\"TextBoxContextMenu\" Background=\"White\">\n <MenuItem Command=\"ApplicationCommands.Copy\" />\n <MenuItem Command=\"ApplicationCommands.Cut\" />\n <MenuItem Command=\"ApplicationCommands.Paste\" />\n</ContextMenu>\n <Style TargetType=\"{x:Type TextBox}\">\n <Setter Property=\"ContextMenu\" Value=\"{StaticResource TextBoxContextMenu}\" />\n</Style>\n <TextBox />\n <TextBox ContextMenu=\"{StaticResource TextBoxContextMenu}\" />\n"
},
{
"answer_id": 2523372,
"author": "Arcturus",
"author_id": 900,
"author_profile": "https://Stackoverflow.com/users/900",
"pm_score": 4,
"selected": true,
"text": "<ContextMenu x:Key=\"TextBoxContextMenu\" Width=\"0\" Height=\"0\" />\n <Style TargetType=\"{x:Type TextBox}\">\n <Setter Property=\"ContextMenu\" Value=\"{StaticResource TextBoxContextMenu}\" />\n</Style>\n"
},
{
"answer_id": 3484929,
"author": "Robin Davies",
"author_id": 415713,
"author_profile": "https://Stackoverflow.com/users/415713",
"pm_score": 5,
"selected": false,
"text": "ContextMenu=\"{x:Null}\" <TextBox.ContextMenu>\n <ContextMenu Visibility=\"Collapsed\">\n </ContextMenu>\n</TextBox.ContextMenu>\n"
},
{
"answer_id": 53862931,
"author": "MrBi",
"author_id": 10765214,
"author_profile": "https://Stackoverflow.com/users/10765214",
"pm_score": 2,
"selected": false,
"text": " <TextBox x:Name=\"MyTextbox\">\n <TextBox.ContextMenu>\n <ContextMenu Visibility=\"Hidden\"/>\n </TextBox.ContextMenu>\n </TextBox>\n MyTextbox.ContextMenu.Visibility = Visibility.Hidden;\n MyTextbox.ContextMenu.Visibility = Visibility.Visble;\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9632",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/900/"
] |
9,650 |
<p>I've been wanting to teach myself Lisp for a while. However, all the interpreters of which I've heard involve some flavor of emacs.
Are there any command line interpreters, such that I could type this into the command line:</p>
<blockquote>
<p>lispinterpret sourcefile.lisp</p>
</blockquote>
<p>just like I can run perl or python.</p>
<p>While I'd also like to become more familiar with Emacs (if only not to be frustrated when I work with somebody who uses Emacs), I'd rather decouple learning Emacs from learning Lisp.</p>
<p>Edit: I actually want to follow SICP which uses Scheme, so an answer about Scheme would be more useful. I'm just not that familiar with the differences.</p>
|
[
{
"answer_id": 14731001,
"author": "pnkfelix",
"author_id": 36585,
"author_profile": "https://Stackoverflow.com/users/36585",
"pm_score": 2,
"selected": false,
"text": "scheme petite mit-scheme scheme48 rs racket guile bigloo csi gsi gosh IronScheme.Console kawa java kawa.repl larceny scm"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1084/"
] |
9,666 |
<p>I've been raised to believe that if multiple threads can access a variable, then all reads from and writes to that variable must be protected by synchronization code, such as a "lock" statement, because the processor might switch to another thread halfway through a write.</p>
<p>However, I was looking through System.Web.Security.Membership using Reflector and found code like this:</p>
<pre><code>public static class Membership
{
private static bool s_Initialized = false;
private static object s_lock = new object();
private static MembershipProvider s_Provider;
public static MembershipProvider Provider
{
get
{
Initialize();
return s_Provider;
}
}
private static void Initialize()
{
if (s_Initialized)
return;
lock(s_lock)
{
if (s_Initialized)
return;
// Perform initialization...
s_Initialized = true;
}
}
}
</code></pre>
<p>Why is the s_Initialized field read outside of the lock? Couldn't another thread be trying to write to it at the same time? <strong>Are reads and writes of variables atomic?</strong> </p>
|
[
{
"answer_id": 9682,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 0,
"selected": false,
"text": "//Perform initialization private static void Initialize()\n{\n if (s_Initialized)\n return;\n\n lock(s_lock)\n {\n s_Provider = new MembershipProvider ( ... )\n s_Initialized = true;\n }\n}\n"
},
{
"answer_id": 9689,
"author": "John Richardson",
"author_id": 887,
"author_profile": "https://Stackoverflow.com/users/887",
"pm_score": 2,
"selected": false,
"text": "private static void Initialize()\n{\n if(s_initialized)\n return;\n\n lock(s_lock)\n {\n if(s_Initialized)\n return;\n s_Initialized = true;\n }\n}\n s_Initialized"
},
{
"answer_id": 9699,
"author": "olliej",
"author_id": 784,
"author_profile": "https://Stackoverflow.com/users/784",
"pm_score": 0,
"selected": false,
"text": "s_Initialized s_Initialized private static void Initialize()\n{\n if (s_Initialized)\n return;\n\n lock(s_lock)\n {\n if (s_Initialized)\n return;\n s_Provider = new MembershipProvider ( ... )\n s_Initialized = true;\n }\n}\n"
},
{
"answer_id": 9711,
"author": "John Richardson",
"author_id": 887,
"author_profile": "https://Stackoverflow.com/users/887",
"pm_score": 1,
"selected": false,
"text": "s_Initialized"
},
{
"answer_id": 9788,
"author": "John Richardson",
"author_id": 887,
"author_profile": "https://Stackoverflow.com/users/887",
"pm_score": 6,
"selected": true,
"text": "double long Int64 UInt64 Interlocked CompareExchange Increment"
},
{
"answer_id": 73827,
"author": "Thomas Danecker",
"author_id": 9632,
"author_profile": "https://Stackoverflow.com/users/9632",
"pm_score": 5,
"selected": false,
"text": "Thread 1 reads s_Provider (which is null) \nThread 2 initializes the data \nThread 2 sets s\\_Initialized to true \nThread 1 reads s\\_Initialized (which is true now) \nThread 1 uses the previously read Provider and gets a NullReferenceException\n"
},
{
"answer_id": 12206783,
"author": "doug65536",
"author_id": 1127972,
"author_profile": "https://Stackoverflow.com/users/1127972",
"pm_score": 0,
"selected": false,
"text": "s_Provider = new MemershipProvider;\n\n// MUST PUT BARRIER HERE to make sure the memory writes from the assignment\n// and the constructor have been wriitten to memory\n// BEFORE the write to s_Initialized!\nThread.MemoryBarrier();\n\n// Now that we've guaranteed that the writes above\n// will be globally first, set the flag\ns_Initialized = true;\n"
},
{
"answer_id": 15125936,
"author": "James Anderson",
"author_id": 38207,
"author_profile": "https://Stackoverflow.com/users/38207",
"pm_score": 1,
"selected": false,
"text": "If (itisso) {"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9666",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1016/"
] |
9,667 |
<p>Given a handle of type <code>HWND</code> is it possible to confirm that the handle represents a real window?</p>
|
[
{
"answer_id": 9670,
"author": "Serge",
"author_id": 1007,
"author_profile": "https://Stackoverflow.com/users/1007",
"pm_score": 5,
"selected": true,
"text": "IsWindow BOOL isRealHandle = IsWindow(unknwodnHandle);\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/887/"
] |
9,673 |
<p>I have been working with a <code>string[]</code> array in C# that gets returned from a function call. I could possibly cast to a <code>Generic</code> collection, but I was wondering if there was a better way to do it, possibly by using a temp array.</p>
<p><strong>What is the best way to remove duplicates from a C# array?</strong></p>
|
[
{
"answer_id": 9685,
"author": "Jeff Atwood",
"author_id": 1,
"author_profile": "https://Stackoverflow.com/users/1",
"pm_score": 10,
"selected": true,
"text": "int[] s = { 1, 2, 3, 3, 4};\nint[] q = s.Distinct().ToArray();\n"
},
{
"answer_id": 9755,
"author": "GateKiller",
"author_id": 383,
"author_profile": "https://Stackoverflow.com/users/383",
"pm_score": 4,
"selected": false,
"text": "string[] sArray = {\"a\", \"b\", \"b\", \"c\", \"c\", \"d\", \"e\", \"f\", \"f\"};\nvar sList = new ArrayList();\n\nfor (int i = 0; i < sArray.Length; i++) {\n if (sList.Contains(sArray[i]) == false) {\n sList.Add(sArray[i]);\n }\n}\n\nvar sNew = sList.ToArray();\n\nfor (int i = 0; i < sNew.Length; i++) {\n Console.Write(sNew[i]);\n}\n"
},
{
"answer_id": 9763,
"author": "rjzii",
"author_id": 1185,
"author_profile": "https://Stackoverflow.com/users/1185",
"pm_score": 3,
"selected": false,
"text": " public string[] RemoveDuplicates(string[] myList) {\n System.Collections.ArrayList newList = new System.Collections.ArrayList();\n\n foreach (string str in myList)\n if (!newList.Contains(str))\n newList.Add(str);\n return (string[])newList.ToArray(typeof(string));\n }\n"
},
{
"answer_id": 9768,
"author": "ZombieSheep",
"author_id": 377,
"author_profile": "https://Stackoverflow.com/users/377",
"pm_score": 2,
"selected": false,
"text": "string[] test(string[] myStringArray)\n{\n List<String> myStringList = new List<string>();\n foreach (string s in myStringArray)\n {\n if (!myStringList.Contains(s))\n {\n myStringList.Add(s);\n }\n }\n return myStringList.ToString();\n}\n"
},
{
"answer_id": 9833,
"author": "Arcturus",
"author_id": 900,
"author_profile": "https://Stackoverflow.com/users/900",
"pm_score": 6,
"selected": false,
"text": "public static string[] RemoveDuplicates(string[] s)\n{\n HashSet<string> set = new HashSet<string>(s);\n string[] result = new string[set.Count];\n set.CopyTo(result);\n return result;\n}\n"
},
{
"answer_id": 9873,
"author": "Will Dean",
"author_id": 987,
"author_profile": "https://Stackoverflow.com/users/987",
"pm_score": 3,
"selected": false,
"text": "List<String> myStringList = new List<string>();\nforeach (string s in myStringArray)\n{\n if (!myStringList.Contains(s))\n {\n myStringList.Add(s);\n }\n}\n"
},
{
"answer_id": 1856035,
"author": "Sesh",
"author_id": 38212,
"author_profile": "https://Stackoverflow.com/users/38212",
"pm_score": 3,
"selected": false,
"text": "void removeDuplicates(char* strIn)\n{\n int numDups = 0, prevIndex = 0;\n if(NULL != strIn && *strIn != '\\0')\n {\n int len = strlen(strIn);\n for(int i = 0; i < len; i++)\n {\n bool foundDup = false;\n for(int j = 0; j < i; j++)\n {\n if(strIn[j] == strIn[i])\n {\n foundDup = true;\n numDups++;\n break;\n }\n }\n\n if(foundDup == false)\n {\n strIn[prevIndex] = strIn[i];\n prevIndex++;\n }\n }\n\n strIn[len-numDups] = '\\0';\n }\n}\n"
},
{
"answer_id": 2644115,
"author": "Vijay Swami",
"author_id": 317324,
"author_profile": "https://Stackoverflow.com/users/317324",
"pm_score": 3,
"selected": false,
"text": "private void RemoveDuplicate() \n{\n\nArrayList dataArray = new ArrayList(5);\n\n dataArray.Add(\"1\");\n dataArray.Add(\"1\");\n dataArray.Add(\"6\");\n dataArray.Add(\"6\");\n dataArray.Add(\"6\");\n dataArray.Add(\"3\");\n dataArray.Add(\"6\");\n dataArray.Add(\"4\");\n dataArray.Add(\"5\");\n dataArray.Add(\"4\");\n dataArray.Add(\"1\");\n\n dataArray.Sort();\n\n GetDistinctArrayList(dataArray, 0);\n}\n\nprivate void GetDistinctArrayList(ArrayList arr, int idx)\n\n{\n\n int count = 0;\n\n if (idx >= arr.Count) return;\n\n string val = arr[idx].ToString();\n foreach (String s in arr)\n {\n if (s.Equals(arr[idx]))\n {\n count++;\n }\n }\n\n if (count > 1)\n {\n arr.Remove(val);\n GetDistinctArrayList(arr, idx);\n }\n else\n {\n idx += 1;\n GetDistinctArrayList(arr, idx);\n }\n }\n"
},
{
"answer_id": 9272477,
"author": "Pintu",
"author_id": 1177685,
"author_profile": "https://Stackoverflow.com/users/1177685",
"pm_score": 3,
"selected": false,
"text": "protected void Page_Load(object sender, EventArgs e)\n{\n string a = \"a;b;c;d;e;v\";\n string[] b = a.Split(';');\n string[] c = b.Distinct().ToArray();\n\n if (b.Length != c.Length)\n {\n for (int i = 0; i < b.Length; i++)\n {\n try\n {\n if (b[i].ToString() != c[i].ToString())\n {\n Response.Write(\"Found duplicate \" + b[i].ToString());\n return;\n }\n }\n catch (Exception ex)\n {\n Response.Write(\"Found duplicate \" + b[i].ToString());\n return;\n }\n } \n }\n else\n {\n Response.Write(\"No duplicate \");\n }\n}\n"
},
{
"answer_id": 13996868,
"author": "komizo",
"author_id": 1792434,
"author_profile": "https://Stackoverflow.com/users/1792434",
"pm_score": 3,
"selected": false,
"text": "static void Main()\n{\n string textWithDuplicates = \"aaabbcccggg\"; \n\n Console.WriteLine(textWithDuplicates.Count()); \n var letters = new HashSet<char>(textWithDuplicates);\n Console.WriteLine(letters.Count());\n\n foreach (char c in letters) Console.Write(c);\n Console.WriteLine(\"\");\n\n int[] array = new int[] { 12, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2 };\n\n Console.WriteLine(array.Count());\n var distinctArray = new HashSet<int>(array);\n Console.WriteLine(distinctArray.Count());\n\n foreach (int i in distinctArray) Console.Write(i + \",\");\n}\n"
},
{
"answer_id": 17121191,
"author": "AptSenSDET",
"author_id": 2488362,
"author_profile": "https://Stackoverflow.com/users/2488362",
"pm_score": 2,
"selected": false,
"text": "class RemoveDuplicatesInString\n{\n public static String RemoveDups(String origString)\n {\n String outString = null;\n int readIndex = 0;\n CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;\n\n\n if(String.IsNullOrEmpty(origString))\n {\n return outString;\n }\n\n foreach (var ch in origString)\n {\n if (readIndex == 0)\n {\n outString = String.Concat(ch);\n readIndex++;\n continue;\n }\n\n if (ci.IndexOf(origString, ch.ToString().ToLower(), 0, readIndex) == -1)\n {\n //Unique char as this char wasn't found earlier.\n outString = String.Concat(outString, ch); \n }\n\n readIndex++;\n\n }\n\n\n return outString;\n }\n\n\n static void Main(string[] args)\n {\n String inputString = \"aAbcefc\";\n String outputString;\n\n outputString = RemoveDups(inputString);\n\n Console.WriteLine(outputString);\n }\n"
},
{
"answer_id": 17442504,
"author": "Muhammad Mubashir",
"author_id": 878106,
"author_profile": "https://Stackoverflow.com/users/878106",
"pm_score": 3,
"selected": false,
"text": "static void Main(string[] args)\n{ \n int[] array = new int[] { 4, 8, 4, 1, 1, 4, 8 }; \n int numDups = 0, prevIndex = 0;\n\n for (int i = 0; i < array.Length; i++)\n {\n bool foundDup = false;\n for (int j = 0; j < i; j++)\n {\n if (array[i] == array[j])\n {\n foundDup = true;\n numDups++; // Increment means Count for Duplicate found in array.\n break;\n } \n }\n\n if (foundDup == false)\n {\n array[prevIndex] = array[i];\n prevIndex++;\n }\n }\n\n // Just Duplicate records replce by zero.\n for (int k = 1; k <= numDups; k++)\n { \n array[array.Length - k] = '\\0'; \n }\n\n\n Console.WriteLine(\"Console program for Remove duplicates from array.\");\n Console.Read();\n }\n"
},
{
"answer_id": 24587289,
"author": "Salman Ramzan",
"author_id": 3807840,
"author_profile": "https://Stackoverflow.com/users/3807840",
"pm_score": 2,
"selected": false,
"text": "for(int i=0;i<size;i++)\n{\n for(int j=i+1;j<size;j++)\n {\n if(a[i] == a[j])\n {\n for(int k=j;k<size;k++)\n {\n a[k]=a[k+1];\n }\n j--;\n size--;\n }\n }\n\n}\n"
},
{
"answer_id": 29020414,
"author": "Fábio Delboni",
"author_id": 4664826,
"author_profile": "https://Stackoverflow.com/users/4664826",
"pm_score": 3,
"selected": false,
"text": "using System.Linq;\n...\n\npublic static int[] Distinct(int[] handles)\n{\n return handles.ToList().Distinct().ToArray();\n}\n"
},
{
"answer_id": 29587789,
"author": "R.Akhlaghi",
"author_id": 2830315,
"author_profile": "https://Stackoverflow.com/users/2830315",
"pm_score": 1,
"selected": false,
"text": "ArrayList arrayList;\n//Add some Members :)\narrayList.Add(\"ali\");\narrayList.Add(\"hadi\");\narrayList.Add(\"ali\");\n\n//Remove duplicates from array\n for (int i = 0; i < arrayList.Count; i++)\n {\n for (int j = i + 1; j < arrayList.Count ; j++)\n if (arrayList[i].ToString() == arrayList[j].ToString())\n arrayList.Remove(arrayList[j]);\n"
},
{
"answer_id": 35145623,
"author": "HMartyrossian",
"author_id": 5075542,
"author_profile": "https://Stackoverflow.com/users/5075542",
"pm_score": 1,
"selected": false,
"text": "public static int RemoveDuplicates(ref int[] array)\n{\n int size = array.Length;\n\n // if 0 or 1, return 0 or 1:\n if (size < 2) {\n return size;\n }\n\n int current = 0;\n for (int candidate = 1; candidate < size; ++candidate) {\n if (array[current] != array[candidate]) {\n array[++current] = array[candidate];\n }\n }\n\n // index to count conversion:\n return ++current;\n}\n"
},
{
"answer_id": 39868699,
"author": "Papasani Mohansrinivas",
"author_id": 6504878,
"author_profile": "https://Stackoverflow.com/users/6504878",
"pm_score": 1,
"selected": false,
"text": "import java.util.*;\nclass removeDuplicate{\nint [] y ;\n\npublic removeDuplicate(int[] array){\n y=array;\n\n for(int b=0;b<y.length;b++){\n int temp = y[b];\n for(int v=0;v<y.length;v++){\n if( b!=v && temp==y[v]){\n y[v]=0;\n }\n }\n }\n}\n"
},
{
"answer_id": 47568568,
"author": "Arie Yehieli",
"author_id": 4604796,
"author_profile": "https://Stackoverflow.com/users/4604796",
"pm_score": 0,
"selected": false,
"text": " private static string[] distinct(string[] inputArray)\n {\n bool alreadyExists;\n string[] outputArray = new string[] {};\n\n for (int i = 0; i < inputArray.Length; i++)\n {\n alreadyExists = false;\n for (int j = 0; j < outputArray.Length; j++)\n {\n if (inputArray[i] == outputArray[j])\n alreadyExists = true;\n }\n if (alreadyExists==false)\n {\n Array.Resize<string>(ref outputArray, outputArray.Length + 1);\n outputArray[outputArray.Length-1] = inputArray[i];\n }\n }\n return outputArray;\n }\n"
},
{
"answer_id": 52789546,
"author": "Ali Bayat",
"author_id": 3427324,
"author_profile": "https://Stackoverflow.com/users/3427324",
"pm_score": 2,
"selected": false,
"text": "public static IEnumerable<TSource> Distinct<TSource>(this IEnumerable<TSource> source, IEqualityComparer<TSource> comparer)\n{\n if (source == null)\n throw new ArgumentNullException(nameof(source));\n\n HashSet<TSource> set = new HashSet<TSource>(comparer);\n foreach (TSource item in source)\n {\n if (set.Add(item))\n {\n yield return item;\n }\n }\n}\n"
},
{
"answer_id": 55854713,
"author": "Rohan",
"author_id": 10154571,
"author_profile": "https://Stackoverflow.com/users/10154571",
"pm_score": -1,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\n\nnamespace Rextester\n{\n public class Program\n {\n public static void Main(string[] args)\n {\n List<int> listofint1 = new List<int> { 4, 8, 4, 1, 1, 4, 8 };\n List<int> updatedlist= removeduplicate(listofint1);\n foreach(int num in updatedlist)\n Console.WriteLine(num);\n }\n\n\n public static List<int> removeduplicate(List<int> listofint)\n {\n List<int> listofintwithoutduplicate= new List<int>();\n\n\n foreach(var num in listofint)\n {\n if(!listofintwithoutduplicate.Any(p=>p==num))\n {\n listofintwithoutduplicate.Add(num);\n }\n }\n return listofintwithoutduplicate;\n }\n }\n\n\n\n}\n"
},
{
"answer_id": 58223263,
"author": "Kudakwashe Mafutah",
"author_id": 2917482,
"author_profile": "https://Stackoverflow.com/users/2917482",
"pm_score": -1,
"selected": false,
"text": "strINvalues = \"1,1,2,2,3,3,4,4\";\nstrINvalues = string.Join(\",\", strINvalues .Split(',').Distinct().ToArray());\nDebug.Writeline(strINvalues);\n"
},
{
"answer_id": 61983714,
"author": "P_P",
"author_id": 1673752,
"author_profile": "https://Stackoverflow.com/users/1673752",
"pm_score": 1,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nclass Program\n{\n static void Main()\n {\n Random r = new Random(0); int[] a, b = new int[1000000];\n for (int i = b.Length - 1; i >= 0; i--) b[i] = r.Next(b.Length);\n a = new int[b.Length]; Array.Copy(b, a, b.Length);\n a = dedup0(a); Console.WriteLine(a.Length);\n a = new int[b.Length]; Array.Copy(b, a, b.Length);\n var w = System.Diagnostics.Stopwatch.StartNew();\n a = dedup0(a); Console.WriteLine(w.Elapsed); Console.Read();\n }\n\n static int[] dedup0(int[] a) // 48 ms \n {\n return new HashSet<int>(a).ToArray();\n }\n\n static int[] dedup1(int[] a) // 68 ms\n {\n Array.Sort(a); int i = 0, j = 1, k = a.Length; if (k < 2) return a;\n while (j < k) if (a[i] == a[j]) j++; else a[++i] = a[j++];\n Array.Resize(ref a, i + 1); return a;\n }\n\n static int[] dedup2(int[] a) // 8 ms\n {\n var b = new byte[a.Length]; int c = 0;\n for (int i = 0; i < a.Length; i++) \n if (b[a[i]] == 0) { b[a[i]] = 1; c++; }\n a = new int[c];\n for (int j = 0, i = 0; i < b.Length; i++) if (b[i] > 0) a[j++] = i;\n return a;\n }\n}\n static int[] dedupf(int[] a) // 4 ms\n {\n if (a.Length < 2) return a;\n var b = new byte[a.Length]; int c = 0, bi, ai, i, j;\n for (i = 0; i < a.Length; i++)\n { ai = a[i]; bi = 1 ^ b[ai]; b[ai] |= (byte)bi; c += bi; }\n a = new int[c]; i = 0; while (b[i] == 0) i++; a[0] = i++;\n for (j = 0; i < b.Length; i++) a[j += bi = b[i]] += bi * i; return a;\n }\n static int[] dedup(int[] a)\n {\n int i, j, k = a.Length - 1;\n for (i = 0; i < k; i++)\n for (j = i + 1; j <= k; j++) if (a[i] == a[j]) a[j--] = a[k--];\n Array.Resize(ref a, k + 1); return a;\n }\n"
},
{
"answer_id": 62239378,
"author": "Swathi Sriramaneni",
"author_id": 13697010,
"author_profile": "https://Stackoverflow.com/users/13697010",
"pm_score": 0,
"selected": false,
"text": "int size = a.Length;\n for (int i = 0; i < size; i++)\n {\n for (int j = i + 1; j < size; j++)\n {\n if (a[i] == a[j])\n {\n for (int k = j; k < size; k++)\n {\n if (k != size - 1)\n {\n int temp = a[k];\n a[k] = a[k + 1];\n a[k + 1] = temp;\n\n }\n }\n j--;\n size--;\n }\n }\n }\n"
},
{
"answer_id": 63166358,
"author": "Sourcephy",
"author_id": 8196012,
"author_profile": "https://Stackoverflow.com/users/8196012",
"pm_score": -1,
"selected": false,
"text": "string[] array = new string[] { \"A\", \"a\", \"b\", \"B\", \"a\", \"C\", \"c\", \"C\", \"A\", \"1\" };\nvar r = array.Distinct(StringComparer.InvariantCultureIgnoreCase).ToList();\nConsole.WriteLine(r.Count); // return 4 items\n"
},
{
"answer_id": 64519180,
"author": "AKINNUBI ABIOLA SYLVESTER",
"author_id": 6596443,
"author_profile": "https://Stackoverflow.com/users/6596443",
"pm_score": -1,
"selected": false,
"text": "class Program\n{\n static void Main(string[] args)\n {\n var nums = new int[] { 1, 4, 3, 3, 3, 5, 5, 7, 7, 7, 7, 9, 9, 9 };\n var result = removeDuplicates(nums);\n foreach (var item in result)\n {\n Console.WriteLine(item);\n }\n }\n static int[] removeDuplicates(int[] nums)\n {\n nums = nums.ToList().OrderBy(c => c).ToArray();\n int j = 1;\n int i = 0;\n int stop = 0;\n while (j < nums.Length)\n {\n if (nums[i] != nums[j])\n {\n nums[i + 1] = nums[j];\n stop = i + 2;\n i++;\n }\n j++;\n }\n nums = nums.Take(stop).ToArray();\n return nums;\n }\n}\n"
},
{
"answer_id": 68816360,
"author": "Faisal Ansari",
"author_id": 6898760,
"author_profile": "https://Stackoverflow.com/users/6898760",
"pm_score": 0,
"selected": false,
"text": "static void Sort()\n {\n try\n {\n int[] number = new int[Convert.ToInt32(Console.ReadLine())];\n for (int i = 0; i < number.Length; i++)\n {\n number[i] = Convert.ToInt32(Console.ReadLine());\n }\n Array.Sort(number);\n int[] num = number.Distinct().ToArray();\n for (int i = 0; i < num.Length; i++)\n {\n Console.WriteLine(num[i]);\n }\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex);\n }\n Console.Read();\n }\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9673",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/493/"
] |
9,687 |
<p>I'm looking for a pattern for performing a dynamic search on multiple tables.</p>
<p>I have no control over the legacy (and poorly designed) database table structure.</p>
<p>Consider a scenario similar to a resume search where a user may want to perform a search against any of the data in the resume and get back a list of resumes that match their search criteria. Any field can be searched at anytime and in combination with one or more other fields.</p>
<p>The actual sql query gets created dynamically depending on which fields are searched. Most solutions I've found involve complicated if blocks, but I can't help but think there must be a more elegant solution since this must be a solved problem by now.</p>
<hr>
<p>Yeah, so I've started down the path of dynamically building the sql in code. Seems godawful. If I really try to support the requested ability to query any combination of any field in any table this is going to be one MASSIVE set of if statements. <em>shiver</em></p>
<hr>
<p>I believe I read that COALESCE only works if your data does not contain NULLs. Is that correct? If so, no go, since I have NULL values all over the place.</p>
|
[
{
"answer_id": 9889,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "Users\n-----------\nName nvarchar(20)\nNickname nvarchar(10)\n SELECT Name, Nickname\nFROM Users\nWHERE\n Name = COALESCE(@name, Name) AND\n Nickname = COALESCE(@nick, Nickname)\n SELECT Name, Nickname\nFROM Users\nWHERE\n Name = 'brian' AND\n Nickname = Nickname\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9687",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1097/"
] |
9,734 |
<p>Why does C#.Net allow the declaration of the string object to be case-insensitive?</p>
<pre><code>String sHello = "Hello";
string sHello = "Hello";
</code></pre>
<p>Both the lower-case and upper-case S of the word String are acceptable and this seems to be the only object that allows this.</p>
<p>Can anyone explain why?</p>
|
[
{
"answer_id": 9742,
"author": "ZombieSheep",
"author_id": 377,
"author_profile": "https://Stackoverflow.com/users/377",
"pm_score": 0,
"selected": false,
"text": "string myString = \"Hello\";\n String.IsNullOrEmpty(myStringVariable);\n"
},
{
"answer_id": 9747,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 5,
"selected": true,
"text": "string System.String int System.Int32 long System.Int64 float System.Single double System.Double char System.Char byte System.Byte short System.Int16 ushort System.UInt16 uint System.UInt32 ulong System.UInt64 string"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9734",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/383/"
] |
9,750 |
<p>I was reading Joel's book where he was suggesting as interview question:</p>
<blockquote>
<p>Write a program to reverse the "ON" bits in a given byte.</p>
</blockquote>
<p>I only can think of a solution using C. </p>
<p>Asking here so you can show me how to do in a Non C way (if possible)</p>
|
[
{
"answer_id": 9752,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 2,
"selected": false,
"text": "; al is input register\n; bl is output register\n\nxor bl, bl ; clear output\n\n; first bit\nrcl al, 1 ; rotate al through carry\nrcr bl, 1 ; rotate carry into bl\n\n; duplicate above 2-line statements 7 more times for the other bits\n"
},
{
"answer_id": 9756,
"author": "Coincoin",
"author_id": 42,
"author_profile": "https://Stackoverflow.com/users/42",
"pm_score": 2,
"selected": false,
"text": "byte ReverseByte(byte b)\n{\n byte r = 0;\n for(int i=0; i<8; i++)\n {\n int mask = 1 << i;\n int bit = (b & mask) >> i;\n int reversedMask = bit << (7 - i);\n r |= (byte)reversedMask;\n }\n return r;\n}\n"
},
{
"answer_id": 9778,
"author": "James A. Rosen",
"author_id": 1190,
"author_profile": "https://Stackoverflow.com/users/1190",
"pm_score": 2,
"selected": false,
"text": "byte ReverseByte(byte b)\n {\n return b ^ 0xff;\n } ^ AND"
},
{
"answer_id": 9907,
"author": "Jason Day",
"author_id": 737,
"author_profile": "https://Stackoverflow.com/users/737",
"pm_score": 4,
"selected": false,
"text": "~ unsigned char b = 102; /* 0x66, 01100110 */\nunsigned char reverse = ~b; /* 0x99, 10011001 */\n"
},
{
"answer_id": 9929,
"author": "palmsey",
"author_id": 521,
"author_profile": "https://Stackoverflow.com/users/521",
"pm_score": 2,
"selected": false,
"text": "n = 0b11001100\n~n\n n = 0b11001100\neval(\"0b\" + n.to_s(2).reverse)\n n = 123\ncount = 0\n0.upto(8) { |i| count = count + n[i] }\n"
},
{
"answer_id": 10561,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 0,
"selected": false,
"text": "(define (bit-reverse k n)\n (do ((m (if (negative? n) (lognot n) n) (arithmetic-shift m -1))\n (k (+ -1 k) (+ -1 k))\n (rvs 0 (logior (arithmetic-shift rvs 1) (logand 1 m))))\n ((negative? k) (if (negative? n) (lognot rvs) rvs))))\n\n(define (reverse-bit-field n start end)\n (define width (- end start))\n (let ((mask (lognot (ash -1 width))))\n (define zn (logand mask (arithmetic-shift n (- start))))\n (logior (arithmetic-shift (bit-reverse width zn) start)\n (logand (lognot (ash mask start)) n))))\n int\nbit_reverse(int k, int n)\n{\n int m = n < 0 ? ~n : n;\n int rvs = 0;\n while (--k >= 0) {\n rvs = (rvs << 1) | (m & 1);\n m >>= 1;\n }\n return n < 0 ? ~rvs : rvs;\n}\n\nint\nreverse_bit_field(int n, int start, int end)\n{\n int width = end - start;\n int mask = ~(-1 << width);\n int zn = mask & (n >> start);\n return (bit_reverse(width, zn) << start) | (~(mask << start) & n);\n}\n"
},
{
"answer_id": 10563,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 2,
"selected": false,
"text": "public static int reverse(int i) {\n // HD, Figure 7-1\n i = (i & 0x55555555) << 1 | (i >>> 1) & 0x55555555;\n i = (i & 0x33333333) << 2 | (i >>> 2) & 0x33333333;\n i = (i & 0x0f0f0f0f) << 4 | (i >>> 4) & 0x0f0f0f0f;\n i = (i << 24) | ((i & 0xff00) << 8) |\n ((i >>> 8) & 0xff00) | (i >>> 24);\n return i;\n}\n public static long reverse(long i) {\n // HD, Figure 7-1\n i = (i & 0x5555555555555555L) << 1 | (i >>> 1) & 0x5555555555555555L;\n i = (i & 0x3333333333333333L) << 2 | (i >>> 2) & 0x3333333333333333L;\n i = (i & 0x0f0f0f0f0f0f0f0fL) << 4 | (i >>> 4) & 0x0f0f0f0f0f0f0f0fL;\n i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL;\n i = (i << 48) | ((i & 0xffff0000L) << 16) |\n ((i >>> 16) & 0xffff0000L) | (i >>> 48);\n return i;\n}\n"
},
{
"answer_id": 11412,
"author": "andrewrk",
"author_id": 432,
"author_profile": "https://Stackoverflow.com/users/432",
"pm_score": 2,
"selected": false,
"text": "#include <stdio.h>\n\nint countBits(unsigned char byte);\n\nint main(){\n FILE* out = fopen( \"bitcount.c\" ,\"w\");\n\n int i;\n fprintf(out, \"#include <stdio.h>\\n#include <stdlib.h>\\n#include <time.h>\\n\\n\");\n\n fprintf(out, \"int bitcount[256] = {\");\n for(i=0;i<256;i++){\n fprintf(out, \"%i\", countBits((unsigned char)i));\n if( i < 255 ) fprintf(out, \", \");\n }\n fprintf(out, \"};\\n\\n\");\n\n fprintf(out, \"int main(){\\n\");\n\n fprintf(out, \"srand ( time(NULL) );\\n\");\n fprintf(out, \"\\tint num = rand() %% 256;\\n\");\n fprintf(out, \"\\tprintf(\\\"The byte %%i has %%i bits set to ON.\\\\n\\\", num, bitcount[num]);\\n\");\n\n fprintf(out, \"\\treturn 0;\\n\");\n fprintf(out, \"}\\n\");\n fclose(out);\n\n return 0;\n}\n\nint countBits(unsigned char byte){\n unsigned char mask = 1;\n int count = 0;\n while(mask){\n if( mask&byte ) count++;\n mask <<= 1;\n }\n return count;\n}\n"
},
{
"answer_id": 124792,
"author": "ja.",
"author_id": 15467,
"author_profile": "https://Stackoverflow.com/users/15467",
"pm_score": 1,
"selected": false,
"text": "import Data.Bits\nimport Data.Int\n\ni = 123::Int\ni32 = 123::Int32\ni64 = 123::Int64\nvar2 = 123::Integer\n\ntest1 = sho i\ntest2 = sho i32\ntest3 = sho i64\ntest4 = sho var2 -- Exception\n\nsho i = putStrLn $ showBits i ++ \"\\n\" ++ (showBits $complement i)\nshowBits v = concatMap f (showBits2 v) where\n f False = \"0\"\n f True = \"1\"\nshowBits2 v = map (testBit v) [0..(bitSize v - 1)]\n"
},
{
"answer_id": 1282737,
"author": "Brad Ackerman",
"author_id": 113222,
"author_profile": "https://Stackoverflow.com/users/113222",
"pm_score": 1,
"selected": false,
"text": "eval n = 0b11001100\nn.to_s(2).rjust(8, '0').reverse.to_i(2)\n rjust 0b00101010 0b10101 0b01010100"
},
{
"answer_id": 1282817,
"author": "Jason",
"author_id": 100902,
"author_profile": "https://Stackoverflow.com/users/100902",
"pm_score": 1,
"selected": false,
"text": "bFlipped = -1 - bInput;\n"
},
{
"answer_id": 1282858,
"author": "GManNickG",
"author_id": 87234,
"author_profile": "https://Stackoverflow.com/users/87234",
"pm_score": 4,
"selected": false,
"text": "return 0;\n"
},
{
"answer_id": 1282893,
"author": "tsilb",
"author_id": 11112,
"author_profile": "https://Stackoverflow.com/users/11112",
"pm_score": 2,
"selected": false,
"text": "while (Read())\n Write(0);\n"
},
{
"answer_id": 1282970,
"author": "Matthew Iselin",
"author_id": 118364,
"author_profile": "https://Stackoverflow.com/users/118364",
"pm_score": 1,
"selected": false,
"text": " 10101010\n^11111111\n --------\n 01010101\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9750",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/123/"
] |
9,805 |
<p>I am currently writing a small calendar in ASP.Net C#. Currently to produce the rows of the weeks I do the following for loop:</p>
<pre><code>var iWeeks = 6;
for (int w = 0; w < iWeeks; w++) {
</code></pre>
<p>This works fine, however, some month will only have 5 weeks and in some rare cases, 4.</p>
<p>How can I calculate the number of rows that will be required for a particular month?</p>
<p>This is an example of what I am creating:</p>
<p><img src="https://i.stack.imgur.com/NkxN7.png" alt="enter image description here"></p>
<p>As you can see for the above month, there are only 5 rows required, however. Take the this month (August 2008) which started on a Saturday and ends on a Monday on the 6th Week/Row.</p>
<p><strong><em>Image found on google</em></strong></p>
<hr>
<p>This is an example of what I am creating:</p>
<p><img src="https://i.stack.imgur.com/NkxN7.png" alt="enter image description here"></p>
<p>As you can see for the above month, there are only 5 rows required, however. Take the this month (August 2008) which started on a Saturday and ends on a Monday on the 6th Week/Row.</p>
<p><strong><em>Image found on google</em></strong></p>
|
[
{
"answer_id": 9810,
"author": "kokos",
"author_id": 1065,
"author_profile": "https://Stackoverflow.com/users/1065",
"pm_score": 0,
"selected": false,
"text": "var days = DateTime.DaysInMonth(year, month) + \n WhatDayOfWeekTheMonthStarts(year, month); \nint rows = (days / 7); \nif (0 < days % 7) \n{ \n ++rows;\n} \n"
},
{
"answer_id": 9815,
"author": "darkdog",
"author_id": 1094,
"author_profile": "https://Stackoverflow.com/users/1094",
"pm_score": 0,
"selected": false,
"text": "DateTime.DaysInMonth\n"
},
{
"answer_id": 9821,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 2,
"selected": false,
"text": "Culture culture = Thread.CurrentThread.CurrentCulture;\nCalendar cal = culture.Calendar;\nInt32 week = cal.GetWeekOfYear(DateTime.Today,\n culture.DateTimeFormat.CalendarWeekRule,\n culture.DateTimeFormat.FirstDayOfWeek);\n"
},
{
"answer_id": 9830,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 0,
"selected": false,
"text": "public static Int32 GetWeekForDateCurrentCulture(DateTime dt)\n{\n CultureInfo culture = Thread.CurrentThread.CurrentCulture;\n Calendar cal = culture.Calendar;\n return cal.GetWeekOfYear(dt,\n culture.DateTimeFormat.CalendarWeekRule,\n culture.DateTimeFormat.FirstDayOfWeek);\n}\n\npublic static Int32 GetWeekSpanCountForMonth(DateTime dt)\n{\n DateTime firstDayInMonth = new DateTime(dt.Year, dt.Month, 1);\n DateTime lastDayInMonth = firstDayInMonth.AddMonths(1).AddDays(-1);\n return\n GetWeekForDateCurrentCulture(lastDayInMonth)\n - GetWeekForDateCurrentCulture(firstDayInMonth)\n + 1;\n}\n"
},
{
"answer_id": 9844,
"author": "DevelopingChris",
"author_id": 1220,
"author_profile": "https://Stackoverflow.com/users/1220",
"pm_score": 0,
"selected": false,
"text": "DateTime.DaysInMonth public static int RowsForMonth(int month, int year)\n{\n DateTime first = new DateTime(year, month, 1);\n\n //number of days pushed beyond monday this one sits\n int offset = ((int)first.DayOfWeek) - 1;\n\n int actualdays = DateTime.DaysInMonth(month, year) + offset;\n\n decimal rows = (actualdays / 7);\n if ((rows - ((int)rows)) > .1)\n {\n rows++;\n }\n return rows;\n}\n"
},
{
"answer_id": 9851,
"author": "Serhat Ozgel",
"author_id": 31505,
"author_profile": "https://Stackoverflow.com/users/31505",
"pm_score": 4,
"selected": true,
"text": "public int GetWeekRows(int year, int month)\n{\n DateTime firstDayOfMonth = new DateTime(year, month, 1);\n DateTime lastDayOfMonth = new DateTime(year, month, 1).AddMonths(1).AddDays(-1);\n System.Globalization.Calendar calendar = System.Threading.Thread.CurrentThread.CurrentCulture.Calendar;\n int lastWeek = calendar.GetWeekOfYear(lastDayOfMonth, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);\n int firstWeek = calendar.GetWeekOfYear(firstDayOfMonth, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);\n return lastWeek - firstWeek + 1;\n}\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9805",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/383/"
] |
9,831 |
<p>I've asked this question to the forums on the Mootools website and one person said that my class selection was corrupted before an admin came along and changed my post status to invalid. Needless to say this did not help much. I then posted to a google group for Mootools with no response. My question is why doesn't the 'enter', 'leave', 'drop' events fire for my '.drop' elements? The events for the .drag elements are working.</p>
<pre><code><title>Untitled Page</title>
<script type="text/javascript" src="/SDI/includes/mootools-1.2.js"></script>
<script type="text/javascript" src="/SDI/includes/mootools-1.2-more.js"></script>
<script type="text/javascript" charset="utf-8">
window.addEvent('domready', function() {
var fx = [];
$$('#draggables div').each(function(drag){
new Drag.Move(drag, {
droppables: $$('#droppables div'),
onDrop: function(element, droppable){
if(!droppable) {
}
else {
element.setStyle('background-color', '#1d1d20');
}
element.dispose();
},
onEnter: function(element, droppable){
element.setStyle('background-color', '#ffffff');
},
onLeave: function(element, droppable){
element.setStyle('background-color', '#000000');
}
});
});
$$('#droppables div').each(function(drop, index){
drop.addEvents({
'enter': function(el, obj){
drop.setStyle('background-color', '#78ba91');
},
'leave': function(el, obj){
drop.setStyle('background-color', '#1d1d20');
},
'drop': function(el, obj){
el.remove();
}
});
});
});
</script>
<form id="form1" runat="server">
<div>
<div id="draggables">
<div class="drag"></div>
<div class="drag"></div>
<div class="drag"></div>
<div class="drag"></div>
<div class="drag"></div>
<div class="drag"></div>
<div class="drag"></div>
<div class="drag"></div>
<div class="drag"></div>
<div class="drag"></div>
</div>
<div id="droppables">
<div class="drop"></div>
<div class="drop"></div>
<div class="drop"></div>
<div class="drop"></div>
<div class="drop"></div>
<div class="drop"></div>
</div>
</div>
</form>
</code></pre>
|
[
{
"answer_id": 9935722,
"author": "Neil",
"author_id": 1302175,
"author_profile": "https://Stackoverflow.com/users/1302175",
"pm_score": 1,
"selected": false,
"text": "droppables Drag.Move drop enter leave"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9831",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1491425/"
] |
9,882 |
<p>I am working on a project that requires the parsing of log files. I am looking for a fast algorithm that would take groups messages like this:</p>
<blockquote>
<p>The temperature at P1 is 35F.</p>
<p>The temperature at P1 is 40F.</p>
<p>The temperature at P3 is 35F.</p>
<p>Logger stopped.</p>
<p>Logger started.</p>
<p>The temperature at P1 is 40F.</p>
</blockquote>
<p>and puts out something in the form of a printf():</p>
<pre><code>"The temperature at P%d is %dF.", Int1, Int2"
{(1,35), (1, 40), (3, 35), (1,40)}
</code></pre>
<p>The algorithm needs to be generic enough to recognize almost any data load in message groups.</p>
<p>I tried searching for this kind of technology, but I don't even know the correct terms to search for.</p>
|
[
{
"answer_id": 10576,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 0,
"selected": false,
"text": "*scanf"
},
{
"answer_id": 10589,
"author": "Derek Park",
"author_id": 872,
"author_profile": "https://Stackoverflow.com/users/872",
"pm_score": 1,
"selected": false,
"text": "sscanf my @vals = ();\nwhile (defined(my $line = <>))\n{\n if ($line =~ /The temperature at P(\\d*) is (\\d*)F./)\n {\n push(@vals, \"($1,$2)\");\n }\n}\nprint \"The temperature at P%d is %dF. {\";\nfor (my $i = 0; $i < @vals; $i++)\n{\n print $vals[$i];\n if ($i < @vals - 1)\n {\n print \",\";\n }\n}\nprint \"}\\n\";\n The temperature at P%d is %dF. {(1,35),(1,40),(3,35),(1,40)}\n"
},
{
"answer_id": 12379,
"author": "Vincent Robert",
"author_id": 268,
"author_profile": "https://Stackoverflow.com/users/268",
"pm_score": 1,
"selected": false,
"text": "\"The temperature at P[1-3] is [0-9]{2}F.\" \"Logger (.+).\""
},
{
"answer_id": 12466,
"author": "jcsalterego",
"author_id": 1416,
"author_profile": "https://Stackoverflow.com/users/1416",
"pm_score": 4,
"selected": true,
"text": "Column 1: {The: 4}\nColumn 2: {car: 1, cat: 1, dog: 1, moon: 1}\nColumn 3: {jumped: 4}\nColumn 4: {over: 4}\nColumn 5: {the: 4}\nColumn 6: {moon: 4}\n /[a-z]+/i /The ([a-z]+?) jumps over the moon/\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9882",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
9,905 |
<p>Is there a way to check to see if an Microsoft Office process (i.e. Word, Excel) has hung when using Office Automation? Additionally, if the process is hung, is there a way to terminate it?</p>
|
[
{
"answer_id": 9947,
"author": "Ed Schwehm",
"author_id": 1206,
"author_profile": "https://Stackoverflow.com/users/1206",
"pm_score": 0,
"selected": false,
"text": "private Microsoft.Office.Interop.Excel.Application _excel;\n// ... do some stuff ...\n_excel.Quit();\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9905",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1185/"
] |
9,928 |
<p>I am working on a small webapp and I want to use Groovy to write some unit testing for my app. Most of my coding is done on Eclipse and I really want to run all the unit testing with the graphical test runner within Eclipse (I really like the green bar :) )</p>
<p>Sadly, after 4 hours of try-and-error, I'm still not able to setup properly. I tried to use the Eclipse Junit4 test runner to run a Groovy file with method annotated for testing using <code>@Test</code>. But it keeps complaining <code>NoClassDefFoundException</code></p>
<p>Anyone can help? </p>
<p>Here is content of my groovy file, named simpleTest.groovy</p>
<pre><code>import org.junit.Test
import static org.junit.Assert.assertEquals
class simpleTest{
@Test
void trial(){
assertEquals 6, 3+3
}
}
</code></pre>
<p>Anyone can help?</p>
|
[
{
"answer_id": 79907,
"author": "Peter Kelley",
"author_id": 14893,
"author_profile": "https://Stackoverflow.com/users/14893",
"pm_score": 1,
"selected": false,
"text": "_ECLIPSE"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
9,974 |
<p>This is a question I asked on another forum which received some decent answers, but I wanted to see if anyone here has more insight.</p>
<p>The problem is that you have one of your pages in a web application timing out when it gets to a stored procedure call, so you use Sql Profiler, or your application trace logs, to find the query and you paste it into management studio to figure our why it's running slow. But you run it from there and it just blazes along, returning in less than a second each time.</p>
<p>My particular case was using ASP.NET 2.0 and Sql Server 2005, but I think the problem could apply to any RDBMS system.</p>
|
[
{
"answer_id": 9982,
"author": "GateKiller",
"author_id": 383,
"author_profile": "https://Stackoverflow.com/users/383",
"pm_score": -1,
"selected": false,
"text": "DataAdapter.SelectCommand.CommandTimeout = 120;\n"
},
{
"answer_id": 9996,
"author": "Eric Z Beard",
"author_id": 1219,
"author_profile": "https://Stackoverflow.com/users/1219",
"pm_score": 6,
"selected": true,
"text": "-- network protocol: TCP/IP \nset quoted_identifier off \nset arithabort off \nset numeric_roundabort off \nset ansi_warnings on \nset ansi_padding on \nset ansi_nulls off \nset concat_null_yields_null on \nset cursor_close_on_commit off \nset implicit_transactions off \nset language us_english \nset dateformat mdy \nset datefirst 7 \nset transaction isolation level read committed \n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/9974",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1219/"
] |
10,006 |
<p>I have a silverlight 2 beta 2 application that accesses a WCF web service. Because of this, it currently can only use basicHttp binding. The webservice will return fairly large amounts of XML data. This seems fairly wasteful from a bandwidth usage standpoint as the response, if zipped, would be smaller by a factor of 5 (I actually pasted the response into a txt file and zipped it.). </p>
<p>The request does have the "Accept-Encoding: gzip, deflate" - Is there any way have the WCF service gzip (or otherwise compress) the response?</p>
<p>I did find this <a href="http://www.vistax64.com/indigo/113763-wcf-client-j2ee-server-using-gzip.html" rel="noreferrer">link</a> but it sure seems a bit complex for functionality that should be handled out-of-the-box IMHO.</p>
<p>OK - at first I marked the solution using the System.IO.Compression as the answer as I could never "seem" to get the IIS7 dynamic compression to work. Well, as it turns out:</p>
<ol>
<li><p>Dynamic Compression on IIS7 <strong>was</strong> working al along. It is just that Nikhil's Web Developer Helper plugin for IE did not show it working. My guess is that since SL hands the web service call off to the browser, that the browser handles it "under the covers" and Nikhil's tool never sees the compressed response. I was able to confirm this by using Fiddler which monitors traffic external to the browser application. In fiddler, the response was, in fact, gzip compressed!!</p></li>
<li><p>The other problem with the System.IO.Compression solution is that System.IO.Compression does not exist in the Silverlight CLR.</p></li>
</ol>
<p>So from my perspective, the EASIEST way to enable WCF compression in Silverlight is to enable Dynamic Compression in IIS7 and write no code at all.</p>
|
[
{
"answer_id": 10040,
"author": "Darren Kopp",
"author_id": 77,
"author_profile": "https://Stackoverflow.com/users/77",
"pm_score": 4,
"selected": false,
"text": "public static class CompressedSerializer\n{\n /// <summary>\n /// Decompresses the specified compressed data.\n /// </summary>\n /// <typeparam name=\"T\"></typeparam>\n /// <param name=\"compressedData\">The compressed data.</param>\n /// <returns></returns>\n public static T Decompress<T>(byte[] compressedData) where T : class\n {\n T result = null;\n using (MemoryStream memory = new MemoryStream())\n {\n memory.Write(compressedData, 0, compressedData.Length);\n memory.Position = 0L;\n\n using (GZipStream zip= new GZipStream(memory, CompressionMode.Decompress, true))\n {\n zip.Flush();\n var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();\n result = formatter.Deserialize(zip) as T;\n }\n }\n\n return result;\n }\n\n /// <summary>\n /// Compresses the specified data.\n /// </summary>\n /// <typeparam name=\"T\"></typeparam>\n /// <param name=\"data\">The data.</param>\n /// <returns></returns>\n public static byte[] Compress<T>(T data)\n {\n byte[] result = null;\n using (MemoryStream memory = new MemoryStream())\n {\n using (GZipStream zip= new GZipStream(memory, CompressionMode.Compress, true))\n {\n var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();\n formatter.Serialize(zip, data);\n }\n\n result = memory.ToArray();\n }\n\n return result;\n }\n}\n void ReceiveData(byte[] data);\n"
},
{
"answer_id": 3055643,
"author": "Mike H.",
"author_id": 368495,
"author_profile": "https://Stackoverflow.com/users/368495",
"pm_score": 2,
"selected": false,
"text": "applicationHost.config <httpCompression><dynamicTypes> <add mimeType=\"application/soap+msbin1\" enabled=\"true\" />\n NO_MATCHING_CONTENT_TYPE"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10006",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/313/"
] |
10,042 |
<p>What's the best way to make a linked list in Java?</p>
|
[
{
"answer_id": 12432,
"author": "Juha Syrjälä",
"author_id": 1431,
"author_profile": "https://Stackoverflow.com/users/1431",
"pm_score": 5,
"selected": false,
"text": "list = new java.util.LinkedList()\n"
},
{
"answer_id": 25311,
"author": "Aaron",
"author_id": 2628,
"author_profile": "https://Stackoverflow.com/users/2628",
"pm_score": 9,
"selected": true,
"text": "class Link {\n public int data1;\n public double data2;\n public Link nextLink;\n\n //Link constructor\n public Link(int d1, double d2) {\n data1 = d1;\n data2 = d2;\n }\n\n //Print Link data\n public void printLink() {\n System.out.print(\"{\" + data1 + \", \" + data2 + \"} \");\n }\n}\n\nclass LinkList {\n private Link first;\n\n //LinkList constructor\n public LinkList() {\n first = null;\n }\n\n //Returns true if list is empty\n public boolean isEmpty() {\n return first == null;\n }\n\n //Inserts a new Link at the first of the list\n public void insert(int d1, double d2) {\n Link link = new Link(d1, d2);\n link.nextLink = first;\n first = link;\n }\n\n //Deletes the link at the first of the list\n public Link delete() {\n Link temp = first;\n if(first == null){\n return null;\n //throw new NoSuchElementException(); // this is the better way. \n }\n first = first.nextLink;\n return temp;\n }\n\n //Prints list data\n public void printList() {\n Link currentLink = first;\n System.out.print(\"List: \");\n while(currentLink != null) {\n currentLink.printLink();\n currentLink = currentLink.nextLink;\n }\n System.out.println(\"\");\n }\n} \n\nclass LinkListTest {\n public static void main(String[] args) {\n LinkList list = new LinkList();\n\n list.insert(1, 1.01);\n list.insert(2, 2.02);\n list.insert(3, 3.03);\n list.insert(4, 4.04);\n list.insert(5, 5.05);\n\n list.printList();\n\n while(!list.isEmpty()) {\n Link deletedLink = list.delete();\n System.out.print(\"deleted: \");\n deletedLink.printLink();\n System.out.println(\"\");\n }\n list.printList();\n }\n}\n"
},
{
"answer_id": 1963840,
"author": "arnab sarkar",
"author_id": 238899,
"author_profile": "https://Stackoverflow.com/users/238899",
"pm_score": 4,
"selected": false,
"text": "public void insert(int d1, double d2) { \n Link link = new Link(d1, d2); \n\n if(first==null){\n link.nextLink = null;\n first = link; \n last=link;\n }\n else{\n last.nextLink=link;\n link.nextLink=null;\n last=link;\n }\n} \n"
},
{
"answer_id": 6674458,
"author": "Anitha A",
"author_id": 842022,
"author_profile": "https://Stackoverflow.com/users/842022",
"pm_score": 3,
"selected": false,
"text": "//slightly improved code without using collection framework\n\npackage com.test;\n\npublic class TestClass {\n\n private static Link last;\n private static Link first;\n\n public static void main(String[] args) {\n\n //Inserting\n for(int i=0;i<5;i++){\n Link.insert(i+5);\n }\n Link.printList();\n\n //Deleting\n Link.deletefromFirst();\n Link.printList();\n }\n\n\n protected static class Link {\n private int data;\n private Link nextlink;\n\n public Link(int d1) {\n this.data = d1;\n }\n\n public static void insert(int d1) {\n Link a = new Link(d1);\n a.nextlink = null;\n if (first != null) {\n last.nextlink = a;\n last = a;\n } else {\n first = a;\n last = a;\n }\n System.out.println(\"Inserted -:\"+d1);\n }\n\n public static void deletefromFirst() {\n if(null!=first)\n {\n System.out.println(\"Deleting -:\"+first.data);\n first = first.nextlink;\n }\n else{\n System.out.println(\"No elements in Linked List\");\n }\n }\n\n public static void printList() {\n System.out.println(\"Elements in the list are\");\n System.out.println(\"-------------------------\");\n Link temp = first;\n while (temp != null) {\n System.out.println(temp.data);\n temp = temp.nextlink;\n }\n }\n }\n}\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10042",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/571/"
] |
10,059 |
<p>I'm developing an MFC application and I've recently been searching for a good method to remove the icon from a Windows title bar, but retain the close button. The two obvious candidate solutions are turning off the system menu style or using the tool window style, but I would prefer not to disable the system menu or use the shrunken tool window title bar. Many MFC applications have this functionality, so I wonder: am I missing some standard way of doing this?</p>
|
[
{
"answer_id": 10539,
"author": "Aidan Ryan",
"author_id": 1042,
"author_profile": "https://Stackoverflow.com/users/1042",
"pm_score": 0,
"selected": false,
"text": "int clickX = GET_X_LPARAM(lParam);\nint clickY = GET_Y_LPARAM(lParam);\n\nCRect frameRect;\nmainFrame.GetWindowRect(&frameRect);\n\nint titleBarHeight = GetSystemMetrics(SM_CYCAPTION);\n\nif (clickX >= frameRect.left &&\n clickX <= frameRect.right &&\n clickY >= frameRect.top &&\n clickY <= frameRect.top + titleBarHeight)\n{\n TrackPopupMenu(m_systemMenu);\n}\n"
},
{
"answer_id": 10555,
"author": "Andrew Grant",
"author_id": 1043,
"author_profile": "https://Stackoverflow.com/users/1043",
"pm_score": 3,
"selected": true,
"text": "WM_NCRBUTTONDOWN"
},
{
"answer_id": 834720,
"author": "ezolotko",
"author_id": 71689,
"author_profile": "https://Stackoverflow.com/users/71689",
"pm_score": 2,
"selected": false,
"text": "WS_EX_DLGMODALFRAME"
},
{
"answer_id": 43352493,
"author": "Alex",
"author_id": 92713,
"author_profile": "https://Stackoverflow.com/users/92713",
"pm_score": 0,
"selected": false,
"text": "const\n WM_ResetIcon = WM_APP - 1;\n\ntype\n TForm1 = class(TForm)\n procedure FormShow(Sender: TObject);\n protected\n procedure WMResetIcon(var Message: TMessage); message WM_ResetIcon;\n end;\n\nimplementation\n\nprocedure TForm1.FormShow(Sender: TObject);\nbegin\n PostMessage(Handle, WM_ResetIcon, 0, 0);\nend;\n\nprocedure TForm1.WMResetIcon(var Message: TMessage);\nconst\n ICON_SMALL = 0;\n ICON_BIG = 1;\nbegin\n DestroyIcon(SendMessage(Handle, WM_SETICON, ICON_BIG, 0));\n DestroyIcon(SendMessage(Handle, WM_SETICON, ICON_SMALL, 0));\nend;\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10059",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
10,071 |
<p>I'm working on an app that grabs and installs a bunch of updates off an an external server, and need some help with threading. The user follows this process:</p>
<ul>
<li>Clicks button</li>
<li>Method checks for updates, count is returned.</li>
<li>If greater than 0, then ask the user if they want to install using MessageBox.Show().</li>
<li>If yes, it runs through a loop and call BeginInvoke() on the run() method of each update to run it in the background.</li>
<li>My update class has some events that are used to update a progress bar etc. </li>
</ul>
<p>The progress bar updates are fine, but the MessageBox is not fully cleared from the screen because the update loop starts right after the user clicks yes (see screenshot below).</p>
<ul>
<li>What should I do to make the messagebox disappear instantly before the update loop starts?</li>
<li>Should I be using Threads instead of BeginInvoke()?</li>
<li>Should I be doing the initial update check on a separate thread and calling MessageBox.Show() from that thread?</li>
</ul>
<p><strong>Code</strong></p>
<pre><code>// Button clicked event handler code...
DialogResult dlgRes = MessageBox.Show(
string.Format("There are {0} updates available.\n\nInstall these now?",
um2.Updates.Count), "Updates Available",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2
);
if (dlgRes == DialogResult.Yes)
{
ProcessAllUpdates(um2);
}
// Processes a bunch of items in a loop
private void ProcessAllUpdates(UpdateManager2 um2)
{
for (int i = 0; i < um2.Updates.Count; i++)
{
Update2 update = um2.Updates[i];
ProcessSingleUpdate(update);
int percentComplete = Utilities.CalculatePercentCompleted(i, um2.Updates.Count);
UpdateOverallProgress(percentComplete);
}
}
// Process a single update with IAsyncResult
private void ProcessSingleUpdate(Update2 update)
{
update.Action.OnStart += Action_OnStart;
update.Action.OnProgress += Action_OnProgress;
update.Action.OnCompletion += Action_OnCompletion;
//synchronous
//update.Action.Run();
// async
IAsyncResult ar = this.BeginInvoke((MethodInvoker)delegate() { update.Action.Run(); });
}
</code></pre>
<p><strong>Screenshot</strong></p>
<p><a href="http://www.flickr.com/photos/brianly/2760435228/" rel="nofollow noreferrer" title="Windows Mobile Bug by BrianLy, on Flickr"><img src="https://farm4.static.flickr.com/3043/2760435228_1af7dbf365_o.gif" width="233" height="266" alt="Windows Mobile Bug" /></a></p>
|
[
{
"answer_id": 10116,
"author": "JamesSugrue",
"author_id": 1075,
"author_profile": "https://Stackoverflow.com/users/1075",
"pm_score": 1,
"selected": false,
"text": "Application.DoEvents()\n if (dlgRes == DialogResult.Yes)\n{\n Application.DoEvents(); \n ProcessAllUpdates(um2); \n}\n"
},
{
"answer_id": 10157,
"author": "John Sibly",
"author_id": 1078,
"author_profile": "https://Stackoverflow.com/users/1078",
"pm_score": 4,
"selected": true,
"text": "this.BeginInvoke((MethodInvoker)delegate() {update.Action.Run(); }) \n Application.DoEvents()\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10071",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/636/"
] |
10,072 |
<p>How do I write code where a company icon appears on the left side next to the URL address in the browser's address bar?</p>
|
[
{
"answer_id": 10144,
"author": "y0mbo",
"author_id": 417,
"author_profile": "https://Stackoverflow.com/users/417",
"pm_score": 2,
"selected": false,
"text": "<head> <link> <link type=\"image/x-icon\" rel=\"shortcut icon\" href=\"favicon.ico\" />\n"
},
{
"answer_id": 11896,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<link href=\"sc/ph645.43/images/icons/mint.ico\" rel=\"icon\" type=\"text/x-icon\" />\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
10,123 |
<p>I'm trying to decode the result of the Python os.wait() function. This returns, according to the Python docs:</p>
<blockquote>
<p>a tuple containing its pid and exit status indication: a 16-bit number, whose low byte is the signal number that killed the process, and whose high byte is the exit status (if the signal number is zero); the high bit of the low byte is set if a core file was produced.</p>
</blockquote>
<p>How do I decode the exit status indication (which is an integer) to obtain the high and low byte? To be specific, how do I implement the decode function used in the following code snippet:</p>
<pre><code>(pid,status) = os.wait()
(exitstatus, signum) = decode(status)
</code></pre>
|
[
{
"answer_id": 10129,
"author": "Mark Harrison",
"author_id": 116,
"author_profile": "https://Stackoverflow.com/users/116",
"pm_score": 5,
"selected": true,
"text": "signum = status & 0xff\nexitstatus = (status & 0xff00) >> 8\n"
},
{
"answer_id": 10132,
"author": "Derek Park",
"author_id": 872,
"author_profile": "https://Stackoverflow.com/users/872",
"pm_score": 1,
"selected": false,
"text": "low = status & 0x00FF\nhigh = (status & 0xFF00) >> 8\n"
},
{
"answer_id": 10148,
"author": "Patrick",
"author_id": 429,
"author_profile": "https://Stackoverflow.com/users/429",
"pm_score": 0,
"selected": false,
"text": "(signum, exitstatus) = (status & 0xFF, (status >> 8) & 0xFF)\n"
},
{
"answer_id": 10213,
"author": "Jason Pratt",
"author_id": 99,
"author_profile": "https://Stackoverflow.com/users/99",
"pm_score": 4,
"selected": false,
"text": "pid, status = os.wait()\nexitstatus, signum = status & 0xFF, (status & 0xFF00) >> 8\n pid, status = os.wait()\nexitstatus, signum = os.WEXITSTATUS( status ), os.WTERMSIG( status )\n"
},
{
"answer_id": 686128,
"author": "RobM",
"author_id": 83100,
"author_profile": "https://Stackoverflow.com/users/83100",
"pm_score": 2,
"selected": false,
"text": "import struct\ni = 3235830701 # 0xC0DEDBAD\ns = struct.pack(\">L\", i) # \">\" = Big-endian, \"<\" = Little-endian\nprint s # '\\xc0\\xde\\xdb\\xad'\nprint s[0] # '\\xc0'\nprint ord(s[0]) # 192 (which is 0xC0)\n import struct\ni = 3235830701 # 0xC0DEDBAD\ns = struct.pack(\">L\", i) # \">\" = Big-endian, \"<\" = Little-endian\n\nimport array\na = array.array(\"B\") # B: Unsigned bytes\na.fromstring(s)\nprint a # array('B', [192, 222, 219, 173])\n"
},
{
"answer_id": 687977,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 2,
"selected": false,
"text": "exitstatus, signum= divmod(status, 256)\n"
},
{
"answer_id": 50074196,
"author": "Barish Ahsen",
"author_id": 9712098,
"author_profile": "https://Stackoverflow.com/users/9712098",
"pm_score": 0,
"selected": false,
"text": "import amp as amp\nimport status\nsignum = status & 0xff\nexitstatus = (status & 0xff00) >> 8\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10123",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/742/"
] |
10,149 |
<p>For context, I am something of an emacs newbie. I haven't used it for very long, but have been using it more and more (I like it a lot). Also I'm comfortable with lisp, but not super familiar with elisp.</p>
<p>What I need to do is bind a regular expression to a keyboard combination because I use this particular regex so often.</p>
<p>What I've been doing: </p>
<pre><code>M-C-s ^.*Table\(\(.*\n\)*?GO\)
</code></pre>
<p>Note, I used newline above, but I've found that for <code>isearch-forward-regexp</code>, you really need to replace the <code>\n</code> in the regular expression with the result of <kbd>C-q Q-j</kbd>. This inserts a literal newline (without ending the command) enabling me to put a newline into the expression and match across lines.</p>
<p>How can I bind this to a key combination? </p>
<p>I vaguely understand that I need to create an elisp function which executes <code>isearch-forward-regexp</code> with the expression, but I'm fuzzy on the details. I've searched google and found most documentation to be a tad confusing.</p>
<p><em>How can I bind a regular expression to a key combination in emacs?</em></p>
<hr>
<p><strong>Mike Stone had the best answer so far -- not <em>exactly</em> what I was looking for but it worked for what I needed</strong> </p>
<p>Edit - this sort of worked, but after storing the macro, when I went back to use it later, I couldn't use it with <kbd>C-x e</kbd>. (i.e., if I reboot emacs and then type <kbd>M-x macro-name</kbd>, and then <kbd>C-x e</kbd>, I get a message in the minibuffer like 'no last kbd macro' or something similar)</p>
<hr>
<p>@Mike Stone - Thanks for the information. I tried creating a macro like so:</p>
<pre><code>C-x( M-C-s ^.*Table\(\(.*C-q C-J\)*?GO\) C-x)
</code></pre>
<p>This created my macro, but when I executed my macro I didn't get the same highlighting that I ordinarily get when I use <code>isearch-forward-regexp</code>. Instead it just jumped to the end of the next match of the expression. So that doesn't really work for what I need. Any ideas?</p>
<p>Edit: It looks like I <em>can</em> use macros to do what I want, I just have to think outside the box of <code>isearch-forward-regexp</code>. I'll try what you suggested.</p>
|
[
{
"answer_id": 10161,
"author": "Mike Stone",
"author_id": 122,
"author_profile": "https://Stackoverflow.com/users/122",
"pm_score": 4,
"selected": true,
"text": ".emacs C-x( abc *return* C-x)\n C-xeee\n M-x name-last-kbd-macro testit\n M-x testit\n M-x insert-kbd-macro\n (fset 'testit\n [?a ?b ?c return])\n .emacs"
},
{
"answer_id": 24920,
"author": "Natalie Weizenbaum",
"author_id": 2518,
"author_profile": "https://Stackoverflow.com/users/2518",
"pm_score": 1,
"selected": false,
"text": "(define-key global-map (kbd \"C-c C-f\") 'function-name)\n define-key global-map (kbd \"C-c C-f\") C-c C-f 'function-name (defun function-name (args)\n (interactive)\n stuff\n ...)\n defun C-h f defun (interactive) M-x function-name isearch"
},
{
"answer_id": 60207,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "(defun search-maker (s)\n `(lambda ()\n (interactive)\n (let ((regexp-search-ring (cons ,s regexp-search-ring)) ;add regexp to history\n (isearch-mode-map (copy-keymap isearch-mode-map)))\n (define-key isearch-mode-map (vector last-command-event) 'isearch-repeat-forward) ;make last key repeat\n (isearch-forward-regexp)))) ;`\n\n(global-set-key (kbd \"C-. t\") (search-maker \"^.*Table\\\\(\\\\(.*\\\\n\\\\)*?GO\\\\)\"))\n(global-set-key (kbd \"<f6>\") (search-maker \"HELLO WORLD\"))\n (kbd ...) C-. t t t <f6> <f6> <f6> (defmacro define-isearch-yank (key string)\n `(define-key isearch-mode-map ,key \n (lambda ()\n (interactive) \n (isearch-yank-string ,string)))) ;`\n\n(define-isearch-yank (kbd \"C-. t\") \"^.*Table\\\\(\\\\(.*\\\\n\\\\)*?GO\\\\)\")\n(define-isearch-yank (kbd \"<f6>\") \"HELLO WORLD\")\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10149",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/92/"
] |
10,158 |
<p>What's the easiest way to do an "instring" type function with a regex? For example, how could I reject a whole string because of the presence of a single character such as <code>:</code>? For example: </p>
<ul>
<li><code>this</code> - okay</li>
<li><code>there:is</code> - not okay because of <code>:</code></li>
</ul>
<p>More practically, how can I match the following string: </p>
<pre><code>//foo/bar/baz[1]/ns:foo2/@attr/text()
</code></pre>
<p>For any node test on the xpath that doesn't include a namespace?</p>
<pre><code>(/)?(/)([^:/]+)
</code></pre>
<p>Will match the node tests but includes the namespace prefix which makes it faulty.</p>
|
[
{
"answer_id": 10168,
"author": "Adam Lerman",
"author_id": 673,
"author_profile": "https://Stackoverflow.com/users/673",
"pm_score": 0,
"selected": false,
"text": "[any alpha numeric]\\*:[any alphanumeric]\\*"
},
{
"answer_id": 10186,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "if(Regex.Match(\":\", input)) // reject\n"
},
{
"answer_id": 10325,
"author": "t3rse",
"author_id": 64,
"author_profile": "https://Stackoverflow.com/users/64",
"pm_score": 0,
"selected": false,
"text": "string xpath = \"//foo/bar/baz[1]/ns:foo2/@attr/text()\";\nstring[] nodetests = xpath.Split( new char[] { '/' } );\nfor (int i = 0; i < nodetests.Length; i++) \n{\n if (nodetests[i].Length > 0 && Regex.IsMatch( nodetests[i], @\"^(\\w|\\[|\\])+$\" ))\n {\n // does not have a \":\", we can manipulate it.\n }\n}\n\nxpath = String.Join( \"/\", nodetests );\n"
},
{
"answer_id": 10516,
"author": "OJ.",
"author_id": 611,
"author_profile": "https://Stackoverflow.com/users/611",
"pm_score": 2,
"selected": false,
"text": "class Program\n{\n static void Main(string[] args)\n {\n string withNamespace = @\"//foo/ns2:bar/baz[1]/ns:foo2/@attr/text()\";\n string withoutNamespace = @\"//foo/bar/baz[1]/foo2/@attr/text()\";\n\n ShowStuff(withNamespace);\n ShowStuff(withoutNamespace);\n }\n\n static void ShowStuff(string input)\n {\n Console.WriteLine(\"'{0}' does {1}contain namespaces\", input, ContainsNamespace(input) ? \"\" : \"not \");\n Console.WriteLine(\"'{0}' without namespaces is '{1}'\", input, StripNamespaces(input));\n }\n\n static bool ContainsNamespace(string input)\n {\n // a namspace must start with a character, but can have characters and numbers\n // from that point on.\n return Regex.IsMatch(input, @\"/?\\w[\\w\\d]+:\\w[\\w\\d]+/?\");\n }\n\n static string StripNamespaces(string input)\n {\n return Regex.Replace(input, @\"(/?)\\w[\\w\\d]+:(\\w[\\w\\d]+)(/?)\", \"$1$2$3\");\n }\n}\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10158",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/64/"
] |
10,190 |
<p>Many applications have grids that display data from a database table one page at a time. Many of them also let the user pick the number of records per page, sort by any column, and navigate back and forth through the results.</p>
<p>What's a good algorithm to implement this pattern without bringing the entire table to the client and then filtering the data on the client. How do you bring just the records you want to display to the user?</p>
<p>Does LINQ simplify the solution?</p>
|
[
{
"answer_id": 10194,
"author": "Michael Stum",
"author_id": 91,
"author_profile": "https://Stackoverflow.com/users/91",
"pm_score": 5,
"selected": true,
"text": "DECLARE @PageNum AS INT;\nDECLARE @PageSize AS INT;\nSET @PageNum = 2;\nSET @PageSize = 10;\n\nWITH OrdersRN AS\n(\n SELECT ROW_NUMBER() OVER(ORDER BY OrderDate, OrderID) AS RowNum\n ,OrderID\n ,OrderDate\n ,CustomerID\n ,EmployeeID\n FROM dbo.Orders\n)\n\nSELECT * \n FROM OrdersRN\n WHERE RowNum BETWEEN (@PageNum - 1) * @PageSize + 1 \n AND @PageNum * @PageSize\n ORDER BY OrderDate\n ,OrderID;\n"
},
{
"answer_id": 10227,
"author": "Mark Harrison",
"author_id": 116,
"author_profile": "https://Stackoverflow.com/users/116",
"pm_score": 1,
"selected": false,
"text": "select * from (\n select a.*, rownum rnum from (\n YOUR_QUERY_GOES_HERE -- including the order by\n ) a\n where rownum <= MAX_ROW\n ) where rnum >= MIN_ROW\n"
},
{
"answer_id": 10282,
"author": "Rory MacLeod",
"author_id": 1016,
"author_profile": "https://Stackoverflow.com/users/1016",
"pm_score": 3,
"selected": false,
"text": "MyDataContext db = new MyDataContext();\nvar results = db.Products\n .Skip((pageNumber - 1) * pageSize)\n .Take(pageSize);\n SELECT [ProductId], [Name], [Cost], and so on...\nFROM (\n SELECT [ProductId], [Name], [Cost], [ROW_NUMBER]\n FROM (\n SELECT ROW_NUMBER() OVER (ORDER BY [Name]) AS [ROW_NUMBER], \n [ProductId], [Name], [Cost]\n FROM [Products]\n )\n WHERE [ROW_NUMBER] BETWEEN 10 AND 20\n)\nORDER BY [ROW_NUMBER]\n"
},
{
"answer_id": 12799,
"author": "Grzegorz Gierlik",
"author_id": 1483,
"author_profile": "https://Stackoverflow.com/users/1483",
"pm_score": 1,
"selected": false,
"text": "@page = 2 -- input parameter\n@size = 10 -- can be optional input parameter\n\nif @page < 1 then begin\n @page = 1 -- check page number\nend\n@start = (@page-1) * @size + 1 -- @page starts at record no @start\n\n-- find the beginning of page @page\nSELECT TOP (@start)\n @forename = forename,\n @surname = surname\n @id = id\nFROM\n users\nORDER BY\n forename,\n surname,\n id -- to keep correct order in case of have two John Smith.\n\n-- select @size records starting from @start\nSELECT TOP (@size)\n id,\n forename,\n surname\nFROM\n users\nWHERE\n (forename = @forename and surname = @surname and id >= @id) -- the same name and surname, but bigger id\n OR (forename = @forename and surname > @surname) -- the same name, but bigger surname, id doesn't matter\n OR (forename > @forename) -- bigger forename, the rest doesn't matter\nORDER BY\n forename,\n surname,\n id\n"
},
{
"answer_id": 12820,
"author": "Adam Lassek",
"author_id": 1249,
"author_profile": "https://Stackoverflow.com/users/1249",
"pm_score": 2,
"selected": false,
"text": "var customers = from c in db.customers\n join p in db.purchases on c.CustomerID equals p.CustomerID\n where p.purchases > 5\n select c;\n customers = customers.Skip(pageNum * pageSize).Take(pageSize);\n customers = customers.OrderBy(c => c.LastName);\n var customers = from c in db.customers\n join p in db.purchases on c.CustomerID equals p.CustomerID\n where p.purchases > 5\n select new\n {\n CustomerID = c.CustomerID,\n FirstName = c.FirstName,\n LastName = c.LastName\n };\n var firstCustomer = customer.First();\nint id = firstCustomer.CustomerID;\n"
},
{
"answer_id": 19610367,
"author": "Lukas Eder",
"author_id": 521799,
"author_profile": "https://Stackoverflow.com/users/521799",
"pm_score": 3,
"selected": false,
"text": "ROW_NUMBER() OVER() OFFSET .. FETCH SELECT first_name, last_name, score\nFROM players\nORDER BY score DESC\nOFFSET 40 ROWS FETCH NEXT 10 ROWS ONLY\n SELECT TOP 10 first_name, last_name, score\nFROM players\nWHERE (score < @previousScore)\n OR (score = @previousScore AND player_id < @previousPlayerId)\nORDER BY score DESC, player_id DESC\n @previousScore @previousPlayerId ORDER BY ASC >"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10190",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/373/"
] |
10,205 |
<p>I'm looking at parsing a delimited string, something on the order of</p>
<p>a,b,c</p>
<p>But this is a very simple example, and parsing delimited data can get complex; for instance</p>
<p>1,"Your simple algorithm, it fails",True</p>
<p>would blow your naiive string.Split implementation to bits. Is there anything I can freely use/steal/copy and paste that offers a relatively bulletproof solution to parsing delimited text? .NET, plox.</p>
<p><em>Update:</em> I decided to go with the <a href="http://msdn.microsoft.com/en-us/library/f68t4563.aspx" rel="nofollow noreferrer">TextFieldParser</a>, which is part of VB.NET's pile of goodies hidden away in Microsoft.VisualBasic.DLL.</p>
|
[
{
"answer_id": 10223,
"author": "Stu",
"author_id": 414,
"author_profile": "https://Stackoverflow.com/users/414",
"pm_score": 2,
"selected": false,
"text": "var elements = new List<string>();\nvar current = new StringBuilder();\nvar p = 0;\n\nwhile (p < internalLine.Length) {\n if (internalLine[p] == '\"') {\n p++;\n\n while (internalLine[p] != '\"') {\n current.Append(internalLine[p]);\n p++;\n }\n\n // Skip past last ',\n p += 2;\n }\n else {\n while ((p < internalLine.Length) && (internalLine[p] != ',')) {\n current.Append(internalLine[p]);\n p++;\n }\n\n // Skip past ,\n p++;\n }\n\n elements.Add(current.ToString());\n current.Length = 0;\n}\n"
},
{
"answer_id": 10262,
"author": "Jedi Master Spooky",
"author_id": 1154,
"author_profile": "https://Stackoverflow.com/users/1154",
"pm_score": 3,
"selected": true,
"text": "string filename = @textBox1.Text;\nstring[] fields;\nstring[] delimiter = new string[] {\"|\"};\nusing (Microsoft.VisualBasic.FileIO.TextFieldParser parser =\n new Microsoft.VisualBasic.FileIO.TextFieldParser(filename)) {\n parser.Delimiters = delimiter;\n parser.HasFieldsEnclosedInQuotes = false;\n\n while (!parser.EndOfData) {\n fields = parser.ReadFields();\n //Do what you need\n }\n}\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10205",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
10,228 |
<p>Is there a way to get the tests inside of a <code>TestCase</code> to run in a certain order? For example, I want to separate the life cycle of an object from creation to use to destruction but I need to make sure that the object is set up first before I run the other tests.</p>
|
[
{
"answer_id": 24670,
"author": "Gary Richardson",
"author_id": 2506,
"author_profile": "https://Stackoverflow.com/users/2506",
"pm_score": 3,
"selected": false,
"text": "setUp() tearDown() sharedFixture"
},
{
"answer_id": 1915096,
"author": "mjs",
"author_id": 11543,
"author_profile": "https://Stackoverflow.com/users/11543",
"pm_score": 7,
"selected": false,
"text": "class StackTest extends PHPUnit_Framework_TestCase\n{\n public function testEmpty()\n {\n $stack = array();\n $this->assertEmpty($stack);\n\n return $stack;\n }\n\n /**\n * @depends testEmpty\n */\n public function testPush(array $stack)\n {\n array_push($stack, 'foo');\n $this->assertEquals('foo', $stack[count($stack)-1]);\n $this->assertNotEmpty($stack);\n\n return $stack;\n }\n\n /**\n * @depends testPush\n */\n public function testPop(array $stack)\n {\n $this->assertEquals('foo', array_pop($stack));\n $this->assertEmpty($stack);\n }\n}\n"
},
{
"answer_id": 2532582,
"author": "Bibek Shrestha",
"author_id": 84143,
"author_profile": "https://Stackoverflow.com/users/84143",
"pm_score": 2,
"selected": false,
"text": "<?php\n$app->createResource('resource');\n$this->assertTrue($app->hasResource('resource'));\n?>\n <?php\n$app->destroyResource('resource');\n$this->assertFalse($app->hasResource('resource'));\n?>\n <?php\n$app->createResource('resource');\n$this->assertTrue($app->hasResource('resource'));\n$app->deleteResource('resource');\n?>\n <?php\n$app->createResource('resource');\n$app->destroyResource('resource');\n$this->assertFalse($app->hasResource('resource'));\n?>\n"
},
{
"answer_id": 37879309,
"author": "Kamil Kiełczewski",
"author_id": 860099,
"author_profile": "https://Stackoverflow.com/users/860099",
"pm_score": 2,
"selected": false,
"text": "class LoginTest extends SeleniumClearTestCase\n{\n public function testAdminLogin()\n {\n self::adminLogin($this);\n }\n\n public function testLogout()\n {\n self::adminLogin($this);\n self::logout($this);\n }\n\n public static function adminLogin($t)\n {\n self::login($t, '[email protected]', 'pAs$w0rd');\n $t->assertEquals('John Smith', $t->getText('css=span.hidden-xs'));\n }\n\n // @source LoginTest.se\n public static function login($t, $login, $pass)\n {\n $t->open('/');\n $t->click(\"xpath=(//a[contains(text(),'Log In')])[2]\");\n $t->waitForPageToLoad('30000');\n $t->type('name=email', $login);\n $t->type('name=password', $pass);\n $t->click(\"//button[@type='submit']\");\n $t->waitForPageToLoad('30000');\n }\n\n // @source LogoutTest.se\n public static function logout($t)\n {\n $t->click('css=span.hidden-xs');\n $t->click('link=Logout');\n $t->waitForPageToLoad('30000');\n $t->assertEquals('PANEL', $t->getText(\"xpath=(//a[contains(text(),'Panel')])[2]\"));\n }\n}\n class ChangeBlogTitleTest extends SeleniumClearTestCase\n{\n public function testAddBlogTitle()\n {\n self::addBlogTitle($this,'I like my boobies');\n self::cleanAddBlogTitle();\n }\n\n public static function addBlogTitle($t,$title) {\n LoginTest::adminLogin($t);\n\n $t->click('link=ChangeTitle');\n ...\n $t->type('name=blog-title', $title);\n LoginTest::logout($t);\n LoginTest::login($t, '[email protected]','hilton');\n $t->screenshot(); // take some photos :)\n $t->assertEquals($title, $t->getText('...'));\n }\n\n public static function cleanAddBlogTitle() {\n $lastTitle = BlogTitlesHistory::orderBy('id')->first();\n $lastTitle->delete();\n }\n SeleniumClearTestCase MigrationToSelenium2 setUp"
},
{
"answer_id": 45323854,
"author": "Gino Pane",
"author_id": 2018304,
"author_profile": "https://Stackoverflow.com/users/2018304",
"pm_score": 5,
"selected": false,
"text": "phpunit.xml:\n\n<phpunit\n colors=\"true\"\n bootstrap=\"./tests/bootstrap.php\"\n convertErrorsToExceptions=\"true\"\n convertNoticesToExceptions=\"true\"\n convertWarningsToExceptions=\"true\"\n strict=\"true\"\n stopOnError=\"false\"\n stopOnFailure=\"false\"\n stopOnIncomplete=\"false\"\n stopOnSkipped=\"false\"\n stopOnRisky=\"false\"\n>\n <testsuites>\n <testsuite name=\"Your tests\">\n <file>file1</file> //this will be run before file2\n <file>file2</file> //this depends on file1\n </testsuite>\n </testsuites>\n</phpunit>\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10228",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/204/"
] |
10,229 |
<p>Consider this problem: I have a program which should fetch (let's say) 100 records from a database, and then for each one it should get updated information from a web service. There are two ways to introduce parallelism in this scenario:</p>
<ol>
<li><p>I start each request to the web service on a new Thread. The number of simultaneous threads is controlled by some external parameter (or dynamically adjusted somehow).</p></li>
<li><p>I create smaller batches (let's say of 10 records each) and launch each batch on a separate thread (so taking our example, 10 threads).</p></li>
</ol>
<p>Which is a better approach, and why do you think so?</p>
|
[
{
"answer_id": 10484,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": 4,
"selected": true,
"text": "using System.Net; // need this somewhere\n\n// need to declare an class so we can cast our state object back out\nclass RequestState {\n public WebRequest Request { get; set; }\n}\n\nstatic void Main( string[] args ) {\n // stupid cast neccessary to create the request\n HttpWebRequest request = WebRequest.Create( \"http://www.stackoverflow.com\" ) as HttpWebRequest;\n\n request.BeginGetResponse(\n /* callback to be invoked when finished */\n (asyncResult) => { \n // fetch the request object out of the AsyncState\n var state = (RequestState)asyncResult.AsyncState; \n var webResponse = state.Request.EndGetResponse( asyncResult ) as HttpWebResponse;\n\n // there we go;\n Debug.Assert( webResponse.StatusCode == HttpStatusCode.OK ); \n\n Console.WriteLine( \"Got Response from server:\" + webResponse.Server );\n },\n /* pass the request through to our callback */\n new RequestState { Request = request } \n );\n\n // blah\n Console.WriteLine( \"Waiting for response. Press a key to quit\" );\n Console.ReadKey();\n}\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10229",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/380/"
] |
10,230 |
<p>Which is more efficient for the compiler and the best practice for checking whether a string is blank? </p>
<ol>
<li>Checking whether the length of the string == 0</li>
<li>Checking whether the string is empty (strVar == "")</li>
</ol>
<p>Also, does the answer depend on language?</p>
|
[
{
"answer_id": 10233,
"author": "Stu",
"author_id": 414,
"author_profile": "https://Stackoverflow.com/users/414",
"pm_score": 5,
"selected": true,
"text": "Length = 0 [0] == 0 .IsNullOrEmpty"
},
{
"answer_id": 10234,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 2,
"selected": false,
"text": "string.IsNullOrEmpty( nystr );\n"
},
{
"answer_id": 10250,
"author": "Derek Park",
"author_id": 872,
"author_profile": "https://Stackoverflow.com/users/872",
"pm_score": 4,
"selected": false,
"text": "\"\""
},
{
"answer_id": 10305,
"author": "Mark Harrison",
"author_id": 116,
"author_profile": "https://Stackoverflow.com/users/116",
"pm_score": 1,
"selected": false,
"text": "if (s[0] == 0)\n if (strlen(s) == 0)\n if (strcmp(s, \"\") == 0)\n"
},
{
"answer_id": 10306,
"author": "Nathan Fellman",
"author_id": 1084,
"author_profile": "https://Stackoverflow.com/users/1084",
"pm_score": 2,
"selected": false,
"text": "char *mystring;\n/* do something with the string */\nif ((mystring != NULL) && (mystring[0] == '\\0')) {\n /* the string is empty */\n}\n"
},
{
"answer_id": 10312,
"author": "Derek Park",
"author_id": 872,
"author_profile": "https://Stackoverflow.com/users/872",
"pm_score": 0,
"selected": false,
"text": "strcmp() strlen() == 0"
},
{
"answer_id": 10902,
"author": "Surgical Coder",
"author_id": 1276,
"author_profile": "https://Stackoverflow.com/users/1276",
"pm_score": 2,
"selected": false,
"text": "String.IsNullOrEmpty() if (inputString == null || inputString == String.Empty)\n{\n // String is null or empty, do something clever here. Or just expload.\n}\n"
},
{
"answer_id": 163570,
"author": "Andy Lester",
"author_id": 8454,
"author_profile": "https://Stackoverflow.com/users/8454",
"pm_score": 0,
"selected": false,
"text": "#define IS_EMPTY(s) ((s)[0]==0)\n"
},
{
"answer_id": 2306659,
"author": "Shimmy Weitzhandler",
"author_id": 75500,
"author_profile": "https://Stackoverflow.com/users/75500",
"pm_score": 1,
"selected": false,
"text": "Module Module1\n Sub Main()\n Dim myString = \"\"\n\n\n Dim a, b, c, d As Long\n\n Console.WriteLine(\"Way 1...\")\n\n a = Now.Ticks\n For index = 0 To 10000000\n Dim isEmpty = myString = \"\"\n Next\n b = Now.Ticks\n\n Console.WriteLine(\"Way 2...\")\n\n c = Now.Ticks\n For index = 0 To 10000000\n Dim isEmpty = myString.Length = 0\n Next\n d = Now.Ticks\n\n Dim way1 = b - a, way2 = d - c\n\n Console.WriteLine(\"way 1 took {0} ticks\", way1)\n Console.WriteLine(\"way 2 took {0} ticks\", way2)\n Console.WriteLine(\"way 1 took {0} ticks more than way 2\", way1 - way2)\n Console.Read()\n End Sub\nEnd Module\n Way 1...\nWay 2...\nway 1 took 624001 ticks\nway 2 took 468001 ticks\nway 1 took 156000 ticks more than way 2\n"
},
{
"answer_id": 34248826,
"author": "David A. Gray",
"author_id": 3079037,
"author_profile": "https://Stackoverflow.com/users/3079037",
"pm_score": 1,
"selected": false,
"text": "strInstallString \"1\" string\n if ( strInstallString == \"\" )\n003126FB mov edx,dword ptr ds:[31B2184h]\n00312701 mov ecx,dword ptr [ebp-50h]\n00312704 call 59DEC0B0 ; On return, EAX = 0x00000000.\n00312709 mov dword ptr [ebp-9Ch],eax\n0031270F cmp dword ptr [ebp-9Ch],0\n00312716 sete al\n00312719 movzx eax,al\n0031271C mov dword ptr [ebp-64h],eax\n0031271F cmp dword ptr [ebp-64h],0\n00312723 jne 00312750\n\nif ( strInstallString == string.Empty )\n00452443 mov edx,dword ptr ds:[3282184h]\n00452449 mov ecx,dword ptr [ebp-50h]\n0045244C call 59DEC0B0 ; On return, EAX = 0x00000000.\n00452451 mov dword ptr [ebp-9Ch],eax\n00452457 cmp dword ptr [ebp-9Ch],0\n0045245E sete al\n00452461 movzx eax,al\n00452464 mov dword ptr [ebp-64h],eax\n00452467 cmp dword ptr [ebp-64h],0\n0045246B jne 00452498\n if ( strInstallString.Length == 0 )\n003E284B mov ecx,dword ptr [ebp-50h]\n003E284E cmp dword ptr [ecx],ecx\n003E2850 call 5ACBC87E ; On return, EAX = 0x00000001.\n003E2855 mov dword ptr [ebp-9Ch],eax\n003E285B cmp dword ptr [ebp-9Ch],0\n003E2862 setne al\n003E2865 movzx eax,al\n003E2868 mov dword ptr [ebp-64h],eax\n003E286B cmp dword ptr [ebp-64h],0\n003E286F jne 003E289C\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10230",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/288/"
] |
10,243 |
<p>Our (beloved) designer keeps creating PNG files with transparent backgrounds for use in our applications. I'd like to make sure that this feature of the PNG works in "older" browsers as well. What's the best solution?</p>
<p><em>edits below</em></p>
<p>@mabwi & @syd - Whether or not I agree about the use of a PNG is not the point. This is a problem that I need to solve!</p>
<p>@Tim Sullivan - IE7.js looks pretty cool, but I don't think I want to introduce all of the other changes an application. I'd like a solution that fixes the PNG issue exclusively. Thanks for the link.</p>
|
[
{
"answer_id": 92530,
"author": "hugoware",
"author_id": 17091,
"author_profile": "https://Stackoverflow.com/users/17091",
"pm_score": 2,
"selected": false,
"text": "div.theImage {\n background : url(smile.png) top left no-repeat;\n height : 100px;\n width : 100px;\n}\n\n* html div.theImage {\n background : none; \n progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\"layout/smile.png\", sizingMethod=\"scale\");\n}\n"
},
{
"answer_id": 479890,
"author": "Kornel",
"author_id": 27009,
"author_profile": "https://Stackoverflow.com/users/27009",
"pm_score": 3,
"selected": false,
"text": "background-position -repeat"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/326/"
] |
10,274 |
<p>When should I <strong>not</strong> use the ThreadPool in .Net?</p>
<p>It looks like the best option is to use a ThreadPool, in which case, why is it not the only option?</p>
<p>What are your experiences around this?</p>
|
[
{
"answer_id": 10287,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": true,
"text": "ThreadPool ThreadPool ThreadPool ThreadPool ThreadPool"
},
{
"answer_id": 10369,
"author": "Derek Park",
"author_id": 872,
"author_profile": "https://Stackoverflow.com/users/872",
"pm_score": 5,
"selected": false,
"text": "Thread t = new Thread(new ThreadStart(DoSomething)); \nt.Start(); \nt.Join(); \n Start() Join()"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/380/"
] |
10,300 |
<p>I've been playing around with the ASP.NET MVC Framework and the one thing that's really confusing me is how I'm meant to do server side validation of posted form data. I presume I don't post back to the same URL, but if I don't, how do I redisplay the form with the entered data and error messages? Also, where should the validation logic go? In the model or the controller? This seems to be one of the few areas where web forms are much stronger (I miss the validation controls).</p>
|
[
{
"answer_id": 10364,
"author": "Iain Holder",
"author_id": 1122,
"author_profile": "https://Stackoverflow.com/users/1122",
"pm_score": 0,
"selected": false,
"text": "Update(int id, string name, string foo)\n return View(\"Item\", yourObject)\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/203/"
] |
10,303 |
<p>I have some SQL Server DTS packages that import data from a FoxPro database. This was working fine until recently. Now the script that imports data from one of the FoxPro tables bombs out about 470,000 records into the import. I'm just pulling the data into a table with nullable varchar fields so I'm thinking it must be a weird/corrupt data problem.</p>
<p>What tools would you use to track down a problem like this?</p>
<p>FYI, this is the error I'm getting:</p>
<blockquote>
<p>Data for source column 1 ('field1') is not available. Your provider may require that all Blob columns be rightmost in the source result set.</p>
</blockquote>
<p>There should not be any blob columns in this table.</p>
<hr>
<p>Thanks for the suggestions. I don't know if it a corruption problem for sure. I just started downloading FoxPro from my MSDN Subscription, so I'll see if I can open the table. SSRS opens the table, it just chokes before running through all the records. I'm just trying to figure out which record it's having a problem with.</p>
|
[
{
"answer_id": 10934,
"author": "PabloG",
"author_id": 394,
"author_profile": "https://Stackoverflow.com/users/394",
"pm_score": 0,
"selected": false,
"text": "SET TABLEVALIDATE 11\nUSE \"YourTable\" EXCLUSIVE && If the table is damaged VFP must display an error here\nPACK && To reindex the table and deleted \"marked\" records\nPACK MEMO && If you have memo fields\n SELECT * FROM YourTable WHERE EMPTY(YourField) && All records with YourField empty\nSELECT * FROM YourTable WHERE LEN(YourMemoField) > 200 && All records with a long memo field, there can be corrupted data\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10303",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/571/"
] |
10,308 |
<p>Are you aware of any tool that creates diagrams showing the branch/merge activity in a SVN repository?</p>
<p>We've all seen these diagrams in various tutorials. Some good, some not so good. Can they be created automatically (or maybe with a little prodding -- you might have to tell it what if your branching philosophy is dev-test-prod, branch-per-release, etc.)</p>
<p>I'm looking at the TortoiseSVN Revision Graph right now, but it has more detail than I want and the wrong layout.</p>
<hr>
<p>Orion, thanks for the response. I guess since branching and merging are more a convention for managing files in a repository than a "built in feature of SVN, it would be pretty tough. I'll stick with the poorly-drawn diagram at the top of the whiteboard in our team's office.</p>
|
[
{
"answer_id": 41939,
"author": "m104",
"author_id": 4039,
"author_profile": "https://Stackoverflow.com/users/4039",
"pm_score": 3,
"selected": false,
"text": "git svn init \"http://host/repo/location/trunk\"\n gitk --all\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10308",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/763/"
] |
10,313 |
<p>Is it possible, in Windows XP, to copy files to a Network Place from the command line, a batch file or, even better, a PowerShell script?</p>
<p>What sent me down this road of research was trying to publish files to a WSS 3.0 document library from a user's machine. I can't map a drive to the library in question because the WSS site is only available to authenticate via NTLM on a port other than 80 or 443. I suppose I could alternately use the WSS web services to push the files out, but I'm really curious about the answer to this question now.</p>
|
[
{
"answer_id": 10317,
"author": "Nathan Fellman",
"author_id": 1084,
"author_profile": "https://Stackoverflow.com/users/1084",
"pm_score": 1,
"selected": false,
"text": "copy src \\\\dest-machine\\shared-library-name\\dest\n"
},
{
"answer_id": 10385,
"author": "Abs",
"author_id": 1245,
"author_profile": "https://Stackoverflow.com/users/1245",
"pm_score": 0,
"selected": false,
"text": "copy src \\\\dest-machine:45000\\shared-library-name\\dest\n"
},
{
"answer_id": 13899,
"author": "slipsec",
"author_id": 1635,
"author_profile": "https://Stackoverflow.com/users/1635",
"pm_score": 2,
"selected": false,
"text": "man *item* Copy-Item test.txt -Destination \\\\dest-machine\\share\n"
},
{
"answer_id": 14461,
"author": "seanyboy",
"author_id": 1726,
"author_profile": "https://Stackoverflow.com/users/1726",
"pm_score": 4,
"selected": false,
"text": "net use \\\\{dest-machine}\\{destfolder} {password} /user:{username}\ncopy {file} \\\\{dest-machine}\\{destfolder}\n net use \\\\Development\\myfolder mypassword /user:Administrator\ncopy newfile.c \\\\development\\myfolder\n"
},
{
"answer_id": 30296,
"author": "Abs",
"author_id": 1245,
"author_profile": "https://Stackoverflow.com/users/1245",
"pm_score": 2,
"selected": true,
"text": "net use"
},
{
"answer_id": 8193290,
"author": "jetzdax",
"author_id": 1055163,
"author_profile": "https://Stackoverflow.com/users/1055163",
"pm_score": 3,
"selected": false,
"text": "windows box xcopy xcopy xcopy src \\\\dest-machine\\shared-library-name\\dest\nxcopy \\\\src-machine\\shared-library-name\\dest src\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10313",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1245/"
] |
10,314 |
<p>Being new to Objective-C (but a long term C/++) programmer I'm looking for advice/recommendations on naming conventions for variables.</p>
<p>My personal preference would be to utilize a prefix for instance variables both for clarity within functions and to prevent shadowing of function parameters. However I'm a fan of properties which rules out prefixes (unless you also prefix your property names, which doesn't work too well and looks daft). Similarly I could use the "self.variable" convention, but only if I make EVERYTHING a property.</p>
<p>So given the code below what's your preferred naming style for instance/function variables? And if you don't bother, how do you deal with shadowing on function params?</p>
<pre><code>@interface GridItem : NSObject
{
CGRect _rect;
...
}
@end
-(void) initFromRect:(CGRect)rect
{
_rect = rect;
...
}
</code></pre>
<p>Cheers!</p>
|
[
{
"answer_id": 11994,
"author": "Chris Hanson",
"author_id": 714,
"author_profile": "https://Stackoverflow.com/users/714",
"pm_score": 5,
"selected": true,
"text": "IBOutlet IBOutlet IBOutlet _myField set_myField: self.myProp [self myProp] self self self->myProp // EmployeeWindowController.h\n#import <AppKit/NSWindowController.h>\n\n@interface EmployeeWindowController : NSWindowController {\n@private\n // model object this window is presenting\n Employee *_employee;\n\n // outlets connected to views in the window\n IBOutlet NSTextField *nameField;\n IBOutlet NSTextField *titleField;\n}\n\n- (id)initWithEmployee:(Employee *)employee;\n\n@property(readwrite, retain) Employee *employee;\n\n@end\n\n// EmployeeWindowController.m\n#import \"EmployeeWindowController.h\"\n\n@implementation EmployeeWindowController\n\n@synthesize employee = _employee;\n\n- (id)initWithEmployee:(Employee *)employee {\n if (self = [super initWithWindowNibName:@\"Employee\"]) {\n _employee = [employee retain];\n }\n return self;\n}\n\n- (void)dealloc {\n [_employee release];\n\n [super dealloc];\n}\n\n- (void)windowDidLoad {\n // populates the window's controls, not necessary if using bindings\n [nameField setStringValue:self.employee.name];\n [titleField setStringValue:self.employee.title];\n}\n\n@end\n Employee -init -dealloc -dealloc"
},
{
"answer_id": 64371,
"author": "Scott Marcy",
"author_id": 8168,
"author_profile": "https://Stackoverflow.com/users/8168",
"pm_score": 2,
"selected": false,
"text": "@synthesize foo = _foo;\n"
},
{
"answer_id": 157990,
"author": "schwa",
"author_id": 23113,
"author_profile": "https://Stackoverflow.com/users/23113",
"pm_score": 1,
"selected": false,
"text": "- (void)doSomethingWith:(id)inSomeObject error:(NSError **)outError;\n"
},
{
"answer_id": 278360,
"author": "Dave Dribin",
"author_id": 26825,
"author_profile": "https://Stackoverflow.com/users/26825",
"pm_score": 3,
"selected": false,
"text": "IBOutlet @property setNameField: @interface EmployeeWindowController : NSWindowController {\n@private\n // model object this window is presenting\n Employee *_employee;\n\n // outlets connected to views in the window\n NSTextField *_nameField;\n NSTextField *_titleField;\n}\n\n- (id)initWithEmployee:(Employee *)employee;\n\n@property(readwrite, retain) Employee *employee;\n@property(nonatomic, retain) IBOutlet NSTextField *nameField;\n@property(nonatomic, retain) IBOutlet NSTextField *titleField;\n\n@end\n"
},
{
"answer_id": 278387,
"author": "Dave Dribin",
"author_id": 26825,
"author_profile": "https://Stackoverflow.com/users/26825",
"pm_score": 1,
"selected": false,
"text": "@synthesize @synthesize employee = _employee;\n ddsynthesize(employee);\n #define ddsynthesize(_X_) @synthesize _X_ = _##_X_\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1043/"
] |
10,323 |
<p>I recently read a nice <a href="http://macdevelopertips.com/ruby/using-a-string-as-a-file-in-ruby.html" rel="noreferrer">post</a> on using <code>StringIO</code> in Ruby. What the author doesn't mention, though, is that <code>StringIO</code> is just an "I." There's no "O." You <em>can't</em> do this, for example:</p>
<pre><code>s = StringIO.new
s << 'foo'
s << 'bar'
s.to_s
# => should be "foo\nbar"
# => really is ''`
</code></pre>
<p>Ruby really needs a StringBuffer just like the one Java has. StringBuffers serve two important purposes. First, they let you test the output half of what Ruby's StringIO does. Second, they are useful for building up long strings from small parts -- something that Joel reminds us over and over again is otherwise very very slow.</p>
<p>Is there a good replacement?</p>
<p>It's true that Strings in Ruby are mutable, but that doesn't mean we should always rely on that functionality. If <code>stuff</code> is large, the performance and memory requirements of this, for example, is really bad.</p>
<pre><code>result = stuff.map(&:to_s).join(' ')
</code></pre>
<p>The "correct" way to do this in Java is:</p>
<pre><code>result = StringBuffer.new("")
for(String s : stuff) {
result.append(s);
}
</code></pre>
<p>Though my Java is a bit rusty.</p>
|
[
{
"answer_id": 10335,
"author": "Mike Stone",
"author_id": 122,
"author_profile": "https://Stackoverflow.com/users/122",
"pm_score": 2,
"selected": false,
"text": "first = \"Mike\"\nlast = \"Stone\"\nname = \"#{first} #{last}\"\n str = \"The count will be: #{count + 1}\"\ncount = count + 1\n"
},
{
"answer_id": 10350,
"author": "Mike Stone",
"author_id": 122,
"author_profile": "https://Stackoverflow.com/users/122",
"pm_score": 8,
"selected": true,
"text": "StringIO StringIO#string StringIO#to_s s = StringIO.new\ns << 'foo'\ns << 'bar'\ns.string\n"
},
{
"answer_id": 10358,
"author": "palmsey",
"author_id": 521,
"author_profile": "https://Stackoverflow.com/users/521",
"pm_score": 4,
"selected": false,
"text": "irb(main):001:0> require 'stringio'\n=> true\nirb(main):002:0> s = StringIO.new\n=> #<StringIO:0x2ced9a0>\nirb(main):003:0> s << 'foo'\n=> #<StringIO:0x2ced9a0>\nirb(main):004:0> s << 'bar'\n=> #<StringIO:0x2ced9a0>\nirb(main):005:0> s.string\n=> \"foobar\"\n"
},
{
"answer_id": 1252057,
"author": "Colin Curtin",
"author_id": 69464,
"author_profile": "https://Stackoverflow.com/users/69464",
"pm_score": 5,
"selected": false,
"text": ">> s = StringIO.new\n=> #<StringIO:0x3659d4>\n>> s << 'foo'\n=> #<StringIO:0x3659d4>\n>> s << 'bar'\n=> #<StringIO:0x3659d4>\n>> s.pos\n=> 6\n>> s.rewind\n=> 0\n>> s.read\n=> \"foobar\"\n"
},
{
"answer_id": 13276313,
"author": "jmanrubia",
"author_id": 469697,
"author_profile": "https://Stackoverflow.com/users/469697",
"pm_score": 5,
"selected": false,
"text": "String#<< StringIO s = \"\"; Benchmark.measure{5000000.times{s << \"some string\"}}\n=> 3.620000 0.100000 3.720000 ( 3.970463)\n\n>> s = StringIO.new; Benchmark.measure{5000000.times{s << \"some string\"}}\n=> 4.730000 0.120000 4.850000 ( 5.329215)\n String#+ s = \"\"; Benchmark.measure{10000.times{s = s + \"some string\"}}\n=> 0.700000 0.560000 1.260000 ( 1.420272)\n\ns = \"\"; Benchmark.measure{10000.times{s << \"some string\"}}\n=> 0.000000 0.000000 0.000000 ( 0.005639)\n StringBuffer String#<<"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10323",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1190/"
] |
10,324 |
<p>In C, what is the most efficient way to convert a string of hex digits into a binary <code>unsigned int</code> or <code>unsigned long</code>?</p>
<p>For example, if I have <code>0xFFFFFFFE</code>, I want an <code>int</code> with the base10 value <code>4294967294</code>.</p>
|
[
{
"answer_id": 10327,
"author": "Patrick",
"author_id": 429,
"author_profile": "https://Stackoverflow.com/users/429",
"pm_score": 6,
"selected": true,
"text": "strtol strtoul"
},
{
"answer_id": 10331,
"author": "Mark Harrison",
"author_id": 116,
"author_profile": "https://Stackoverflow.com/users/116",
"pm_score": 5,
"selected": false,
"text": "#include <stdio.h>\nint main()\n{\n char s[] = \"fffffffe\";\n int x;\n sscanf(s, \"%x\", &x);\n printf(\"%u\\n\", x);\n}\n"
},
{
"answer_id": 10552,
"author": "Derek Park",
"author_id": 872,
"author_profile": "https://Stackoverflow.com/users/872",
"pm_score": 2,
"selected": false,
"text": "unsigned int parseHex(const char * str)\n{\n unsigned int val = 0;\n char c;\n\n while(c = *str++)\n {\n val <<= 4;\n\n if (c >= '0' && c <= '9')\n {\n val += c & 0x0F;\n continue;\n }\n\n c &= 0xDF;\n if (c >= 'A' && c <= 'F')\n {\n val += (c & 0x07) + 9;\n continue;\n }\n\n errno = EINVAL;\n return 0;\n }\n\n return val;\n}\n"
},
{
"answer_id": 130552,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "unsigned long hex2int(char *a, unsigned int len)\n{\n int i;\n unsigned long val = 0;\n\n for(i=0;i<len;i++)\n if(a[i] <= 57)\n val += (a[i]-48)*(1<<(4*(len-1-i)));\n else\n val += (a[i]-55)*(1<<(4*(len-1-i)));\n\n return val;\n}\n"
},
{
"answer_id": 4054173,
"author": "Adam B.",
"author_id": 491552,
"author_profile": "https://Stackoverflow.com/users/491552",
"pm_score": -1,
"selected": false,
"text": "cout << \"\\nEnter a hexadecimal number: \";\ncin >> hexNumber;\norighex = hexNumber;\n\nstrlength = hexNumber.length();\n\nfor (i=0;i<strlength;i++)\n{\n hexa = hexNumber.substr(i,1);\n if ((hexa>=\"0\") && (hexa<=\"9\"))\n {\n //cout << \"This is a numerical value.\\n\";\n }\n else\n {\n //cout << \"This is a alpabetical value.\\n\";\n if (hexa==\"a\"){hexa=\"10\";}\n else if (hexa==\"b\"){hexa=\"11\";}\n else if (hexa==\"c\"){hexa=\"12\";}\n else if (hexa==\"d\"){hexa=\"13\";}\n else if (hexa==\"e\"){hexa=\"14\";}\n else if (hexa==\"f\"){hexa=\"15\";}\n else{cout << \"INVALID ENTRY! ANSWER WONT BE CORRECT\\n\";}\n }\n //convert from string to integer\n\n hx = atoi(hexa.c_str());\n finalhex = finalhex + (hx*pow(16.0,strlength-i-1));\n}\ncout << \"The hexadecimal number: \" << orighex << \" is \" << finalhex << \" in decimal.\\n\";\n"
},
{
"answer_id": 4054250,
"author": "AnT stands with Russia",
"author_id": 187690,
"author_profile": "https://Stackoverflow.com/users/187690",
"pm_score": 3,
"selected": false,
"text": "0xF 15 strto... strtol sprintf"
},
{
"answer_id": 4484238,
"author": "MBANZABUGABO Jean Bapitiste",
"author_id": 547846,
"author_profile": "https://Stackoverflow.com/users/547846",
"pm_score": 0,
"selected": false,
"text": " #include<stdio.h>\n #include<conio.h>\n\n int main(void)\n {\n int count=0,digit,n,i=0;\n int hex[5];\n clrscr();\n printf(\"enter a number \");\n scanf(\"%d\",&n);\n\n if(n<10)\n {\n printf(\"%d\",n);\n }\n\n switch(n)\n {\n case 10:\n printf(\"A\");\n break;\n case 11:\n printf(\"B\");\n break;\n case 12:\n printf(\"B\");\n break;\n case 13:\n printf(\"C\");\n break;\n case 14:\n printf(\"D\");\n break;\n case 15:\n printf(\"E\");\n break;\n case 16:\n printf(\"F\");\n break;\n default:;\n }\n\n while(n>16)\n {\n digit=n%16;\n hex[i]=digit;\n i++;\n count++;\n n=n/16;\n }\n\n hex[i]=n;\n\n for(i=count;i>=0;i--)\n {\n switch(hex[i])\n {\n case 10:\n printf(\"A\");\n break;\n case 11:\n printf(\"B\");\n break;\n case 12:\n printf(\"C\");\n break;\n case 13:\n printf(\"D\");\n break;\n case 14:\n printf(\"E\");\n break;\n case 15:\n printf(\"F\");\n break;\n default:\n printf(\"%d\",hex[i]);\n }\n }\n\n getch();\n\n return 0;\n}\n"
},
{
"answer_id": 8282059,
"author": "rishabh kedia",
"author_id": 1067351,
"author_profile": "https://Stackoverflow.com/users/1067351",
"pm_score": 2,
"selected": false,
"text": "#include<stdio.h>\nvoid main()\n{\n unsigned int i;\n scanf(\"%x\",&i);\n printf(\"%d\",i);\n}\n"
},
{
"answer_id": 11068850,
"author": "Orwellophile",
"author_id": 912236,
"author_profile": "https://Stackoverflow.com/users/912236",
"pm_score": 5,
"selected": false,
"text": "static const long hextable[] = {\n [0 ... 255] = -1, // bit aligned access into this table is considerably\n ['0'] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // faster for most modern processors,\n ['A'] = 10, 11, 12, 13, 14, 15, // for the space conscious, reduce to\n ['a'] = 10, 11, 12, 13, 14, 15 // signed char.\n};\n\n/** \n * @brief convert a hexidecimal string to a signed long\n * will not produce or process negative numbers except \n * to signal error.\n * \n * @param hex without decoration, case insensitive. \n * \n * @return -1 on error, or result (max (sizeof(long)*8)-1 bits)\n */\nlong hexdec(unsigned const char *hex) {\n long ret = 0; \n while (*hex && ret >= 0) {\n ret = (ret << 4) | hextable[*hex++];\n }\n return ret; \n}\n static const long hextable[] = { \n -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,\n -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,\n -1,-1, 0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,-1,\n -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,\n -1,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,\n -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,\n -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,\n -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,\n -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,\n -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,\n -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1\n};\n"
},
{
"answer_id": 11809169,
"author": "Sunday Efeh",
"author_id": 1576168,
"author_profile": "https://Stackoverflow.com/users/1576168",
"pm_score": 1,
"selected": false,
"text": "#include \"math.h\"\n#include \"stdio.h\"\n///////////////////////////////////////////////////////////////\n// The bits arg represents the bit say:8,16,32... \n/////////////////////////////////////////////////////////////\nvolatile long Hex_To_Int(long Hex,char bits)\n{\n long Hex_2_Int;\n char byte;\n Hex_2_Int=0;\n\n for(byte=0;byte<bits;byte++)\n {\n if(Hex&(0x0001<<byte))\n Hex_2_Int+=1*(pow(2,byte));\n else\n Hex_2_Int+=0*(pow(2,byte));\n }\n\n return Hex_2_Int;\n}\n///////////////////////////////////////////////////////////////\n// \n/////////////////////////////////////////////////////////////\n\nvoid main (void)\n{\n int Dec; \n char Hex=0xFA;\n Dec= Hex_To_Int(Hex,8); //convert an 8-bis hexadecimal value to a number in base 10\n printf(\"the number is %d\",Dec);\n}\n"
},
{
"answer_id": 39052834,
"author": "radhoo",
"author_id": 486907,
"author_profile": "https://Stackoverflow.com/users/486907",
"pm_score": 3,
"selected": false,
"text": "/**\n * hex2int\n * take a hex string and convert it to a 32bit number (max 8 hex digits)\n */\nuint32_t hex2int(char *hex) {\n uint32_t val = 0;\n while (*hex) {\n // get current character then increment\n char byte = *hex++; \n // transform hex character to the 4bit equivalent number, using the ascii table indexes\n if (byte >= '0' && byte <= '9') byte = byte - '0';\n else if (byte >= 'a' && byte <='f') byte = byte - 'a' + 10;\n else if (byte >= 'A' && byte <='F') byte = byte - 'A' + 10; \n // shift 4 to make space for new digit, and add the 4 bits of the new digit \n val = (val << 4) | (byte & 0xF);\n }\n return val;\n}\n char *z =\"82ABC1EF\";\nuint32_t x = hex2int(z);\nprintf(\"Number is [%X]\\n\", x);\n"
},
{
"answer_id": 45190525,
"author": "Cactus1549",
"author_id": 7152318,
"author_profile": "https://Stackoverflow.com/users/7152318",
"pm_score": -1,
"selected": false,
"text": "#include <stdio.h>\n\nint main(){\n unsigned char Hexadecimal = 0x6D; //example hex number\n int Decimal = 0; //decimal number initialized to 0\n\n\n Decimal = (int) Hexadecimal; //conversion\n\n printf(\"The decimal number is %d\\n\", Decimal); //output\n return 0;\n}\n"
},
{
"answer_id": 58253411,
"author": "Simon",
"author_id": 5951263,
"author_profile": "https://Stackoverflow.com/users/5951263",
"pm_score": 2,
"selected": false,
"text": "// makes a number from two ascii hexa characters\nint ahex2int(char a, char b){\n\n a = (a <= '9') ? a - '0' : (a & 0x7) + 9;\n b = (b <= '9') ? b - '0' : (b & 0x7) + 9;\n\n return (a << 4) + b;\n}\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10324",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
10,349 |
<p>I'm sure there is a good (or at least decent) reason for this. What is it?</p>
|
[
{
"answer_id": 10359,
"author": "John Sibly",
"author_id": 1078,
"author_profile": "https://Stackoverflow.com/users/1078",
"pm_score": 4,
"selected": true,
"text": "myControl.BeginInvoke(myControl.UpdateFunction);\n"
},
{
"answer_id": 10439,
"author": "Brian Ensink",
"author_id": 1254,
"author_profile": "https://Stackoverflow.com/users/1254",
"pm_score": 5,
"selected": false,
"text": "TextBox.Text {get; set;}"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10349",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/337/"
] |
10,366 |
<p>I have an absolutely positioned <code>div</code> that I want to show when the user clicks a link. The <code>onclick</code> of the link calls a js function that sets the display of the div to block (also tried: "", <code>inline</code>, <code>table-cell</code>, <code>inline-table</code>, etc). This works great in IE7, not at all in every other browser I've tried (FF2, FF3, Opera 9.5, Safari).</p>
<p>I've tried adding alerts before and after the call, and they show that the display has changed from <code>none</code> to <code>block</code> but the <code>div</code> does not display.</p>
<p>I can get the <code>div</code> to display in FF3 if I change the display value using Firebug's HTML inspector (but not by running javascript through Firebug's console) - so I know it's not just showing up off-screen, etc.</p>
<p>I've tried everything I can think of, including:</p>
<ul>
<li>Using a different doctype (XHTML 1, HTML 4, etc)</li>
<li>Using visibility visible/hidden instead of display block/none</li>
<li>Using inline javascript instead of a function call</li>
<li>Testing from different machines</li>
</ul>
<p>Any ideas about what could cause this?</p>
|
[
{
"answer_id": 10378,
"author": "Serhat Ozgel",
"author_id": 31505,
"author_profile": "https://Stackoverflow.com/users/31505",
"pm_score": 3,
"selected": false,
"text": "function show() {\n var d = document.getElementById('testdiv');\n d.style.display = 'block';\n} #testdiv {\n position: absolute;\n height: 20px;\n width: 20px; \n display: none;\n background-color: red;\n} <div id=\"testdiv\"></div>\n<a href=\"javascript:show();\">Click me</a>"
},
{
"answer_id": 11197,
"author": "palmsey",
"author_id": 521,
"author_profile": "https://Stackoverflow.com/users/521",
"pm_score": 4,
"selected": true,
"text": "function openPopup(popupID)\n{\n var divs = getObjectsByTagAndClass('div','popupDiv');\n if (divs != undefined && divs != null)\n {\n for (var i = 0; i < divs.length; i++)\n {\n if (divs[i].id == popupID)\n divs[i].style.display = 'block'; \n }\n }\n}\n"
},
{
"answer_id": 927045,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "document.getElementById('editRow').style.display = '';\n"
},
{
"answer_id": 5705775,
"author": "Neal Connolly",
"author_id": 713750,
"author_profile": "https://Stackoverflow.com/users/713750",
"pm_score": 2,
"selected": false,
"text": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n <html>\n"
},
{
"answer_id": 6952255,
"author": "fadzzz",
"author_id": 879981,
"author_profile": "https://Stackoverflow.com/users/879981",
"pm_score": 1,
"selected": false,
"text": "window.onload window.onload = document.getElementById('testdiv').style.display='inline';\n var d = document.getElementById('testdiv');\nwindow.onload = d.style.display = 'inline';\n"
},
{
"answer_id": 17100771,
"author": "Ron Lentjes",
"author_id": 2484613,
"author_profile": "https://Stackoverflow.com/users/2484613",
"pm_score": 0,
"selected": false,
"text": "<div style=\"...\" class=\"...\"> ... </div>\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10366",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/521/"
] |
10,435 |
<p>I have a website that works correctly under IIS 6.0: It authenticates users with windows credentials, and then when talking to the service that hits the DB, it passes the credentials.</p>
<p>In IIS 7.0, the same config settings do not pass the credentials, and the DB gets hit with NT AUTHORITY\ANONYMOUS.</p>
<p>Is there something I'm missing? I've turned ANONYMOUS access off in my IIS 7.0 website, but I can't get the thing to work.</p>
<p>These are the settings that I'm using on both IIS 6.0 and 7.0:</p>
<pre><code><authentication mode="Windows">
<identity impersonate="true">
</code></pre>
<p>What changed from 6.0 to 7.0?</p>
|
[
{
"answer_id": 267243,
"author": "Maxime Rouiller",
"author_id": 24975,
"author_profile": "https://Stackoverflow.com/users/24975",
"pm_score": 4,
"selected": true,
"text": "<validation validateIntegratedModeConfiguration=\"false\"\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10435",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/781/"
] |
10,443 |
<p>I have this program, we'll call it Host. Host does all kinds of good stuff, but it needs to be able to accept input through the command line <strong>while it's running</strong>. This means it has to somehow send its other process data and then quit. For example, I need to be able to do this:</p>
<pre><code>./Host --blahblah 3 6 3 5
</code></pre>
<p>This should somehow end up calling some function in Host called</p>
<pre><code>handleBlahBlah(int x1, int y1, int x2, int y2){
//do some more sweet stuff
}
</code></pre>
<p>Host is a C program, and does not need to support multiple instances.</p>
<p>An example of this is Amarok music player. With Amarok running and playing, you can type "amarok --pause" and it will pause the music.</p>
<p>I need to be able to do this in Linux or Windows. Preferably Linux.</p>
<p>What is the cleanest way to implement this?</p>
|
[
{
"answer_id": 10445,
"author": "Ed S.",
"author_id": 1053,
"author_profile": "https://Stackoverflow.com/users/1053",
"pm_score": -1,
"selected": false,
"text": " int main(int argc, *argv[])\n {\n /*loop through each argument and take action*/\n while (--argc > 0)\n {\n printf(%s%s, *++argv, (argc > 1) ? \" \" : \"\");\n }\n } \n"
},
{
"answer_id": 10450,
"author": "Derek Park",
"author_id": 872,
"author_profile": "https://Stackoverflow.com/users/872",
"pm_score": 3,
"selected": false,
"text": "./"
},
{
"answer_id": 3461155,
"author": "bta",
"author_id": 79566,
"author_profile": "https://Stackoverflow.com/users/79566",
"pm_score": 0,
"selected": false,
"text": "Host ./Host ./Host --send-message restart fork Host Host_core Host"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10443",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/432/"
] |
10,456 |
<p>The 'click sound' in question is actually a system wide preference, so I only want it to be disabled when my application has focus and then re-enable when the application closes/loses focus.</p>
<p>Originally, I wanted to ask this question here on stackoverflow, but I was not yet in the beta. So, after googling for the answer and finding only a little bit of information on it I came up with the following and decided to post it here now that I'm in the beta.</p>
<pre><code>using System;
using Microsoft.Win32;
namespace HowTo
{
class WebClickSound
{
/// <summary>
/// Enables or disables the web browser navigating click sound.
/// </summary>
public static bool Enabled
{
get
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"AppEvents\Schemes\Apps\Explorer\Navigating\.Current");
string keyValue = (string)key.GetValue(null);
return String.IsNullOrEmpty(keyValue) == false && keyValue != "\"\"";
}
set
{
string keyValue;
if (value)
{
keyValue = "%SystemRoot%\\Media\\";
if (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor > 0)
{
// XP
keyValue += "Windows XP Start.wav";
}
else if (Environment.OSVersion.Version.Major == 6)
{
// Vista
keyValue += "Windows Navigation Start.wav";
}
else
{
// Don't know the file name so I won't be able to re-enable it
return;
}
}
else
{
keyValue = "\"\"";
}
// Open and set the key that points to the file
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"AppEvents\Schemes\Apps\Explorer\Navigating\.Current", true);
key.SetValue(null, keyValue, RegistryValueKind.ExpandString);
isEnabled = value;
}
}
}
}
</code></pre>
<p>Then in the main form we use the above code in these 3 events: </p>
<ul>
<li>Activated </li>
<li>Deactivated </li>
<li><p>FormClosing</p>
<pre><code>private void Form1_Activated(object sender, EventArgs e)
{
// Disable the sound when the program has focus
WebClickSound.Enabled = false;
}
private void Form1_Deactivate(object sender, EventArgs e)
{
// Enable the sound when the program is out of focus
WebClickSound.Enabled = true;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Enable the sound on app exit
WebClickSound.Enabled = true;
}
</code></pre></li>
</ul>
<p>The one problem I see currently is if the program crashes they won't have the click sound until they re-launch my application, but they wouldn't know to do that.</p>
<p>What do you guys think? Is this a good solution? What improvements can be made?</p>
|
[
{
"answer_id": 10463,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 5,
"selected": true,
"text": "webBrowser1.DocumentText = \"<h1>Hello, world!</h1>\";\n webBrowser1.Document.OpenNew(true);\nwebBrowser1.Document.Write(\"<h1>Hello, world!</h1>\");\n"
},
{
"answer_id": 4588327,
"author": "DjCzermino",
"author_id": 561764,
"author_profile": "https://Stackoverflow.com/users/561764",
"pm_score": 0,
"selected": false,
"text": "// backup value\nRegistryKey key = Registry.CurrentUser.OpenSubKey(@\"AppEvents\\Schemes\\Apps\\Explorer\\Navigating\\.Current\");\nstring BACKUP_keyValue = (string)key.GetValue(null);\n\n// write nothing\nkey = Registry.CurrentUser.OpenSubKey(@\"AppEvents\\Schemes\\Apps\\Explorer\\Navigating\\.Current\", true);\nkey.SetValue(null, \"\", RegistryValueKind.ExpandString);\n\n// do navigation ...\n\n// write backup key\nRegistryKey key = Registry.CurrentUser.OpenSubKey(@\"AppEvents\\Schemes\\Apps\\Explorer\\Navigating\\.Current\", true);\nkey.SetValue(null, BACKUP_keyValue, RegistryValueKind.ExpandString);\n"
},
{
"answer_id": 4655871,
"author": "John black",
"author_id": 566868,
"author_profile": "https://Stackoverflow.com/users/566868",
"pm_score": 5,
"selected": false,
"text": "const int FEATURE_DISABLE_NAVIGATION_SOUNDS = 21;\nconst int SET_FEATURE_ON_PROCESS = 0x00000002;\n\n[DllImport(\"urlmon.dll\")]\n[PreserveSig]\n[return: MarshalAs(UnmanagedType.Error)]\nstatic extern int CoInternetSetFeatureEnabled(int FeatureEntry,\n [MarshalAs(UnmanagedType.U4)] int dwFlags,\n bool fEnable);\n\nstatic void DisableClickSounds()\n{\n CoInternetSetFeatureEnabled(FEATURE_DISABLE_NAVIGATION_SOUNDS,\n SET_FEATURE_ON_PROCESS,\n true);\n}\n"
},
{
"answer_id": 17822223,
"author": "user2612427",
"author_id": 2612427,
"author_profile": "https://Stackoverflow.com/users/2612427",
"pm_score": 1,
"selected": false,
"text": "Registry.SetValue(\"HKEY_CURRENT_USER\\\\AppEvents\\\\Schemes\\\\Apps\\\\Explorer\\\\Navigating\\\\.Current\",\"\",\"NULL\");\n Registry.SetValue(\"HKEY_CURRENT_USER\\\\AppEvents\\\\Schemes\\\\Apps\\\\Explorer\\\\Navigating\\\\.Current\",\"\",\"C:\\Windows\\Media\\Cityscape\\Windows Navigation Start.wav\");\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1147/"
] |
10,458 |
<p>Ideally, I'm looking for a templated logical Set class. It would have all of the standard set operations such as Union, Intersection, Etc., and collapse duplicated items.</p>
<p>I ended up creating my own set class based on the C# Dictionary<>- just using the Keys.</p>
|
[
{
"answer_id": 10459,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 6,
"selected": false,
"text": "HashSet<T>"
},
{
"answer_id": 50264359,
"author": "dharmatech",
"author_id": 268581,
"author_profile": "https://Stackoverflow.com/users/268581",
"pm_score": 1,
"selected": false,
"text": "public sealed class MathSet<T> : HashSet<T>, IEquatable<MathSet<T>>\n{\n public override int GetHashCode() => this.Select(elt => elt.GetHashCode()).Sum().GetHashCode();\n\n public bool Equals(MathSet<T> obj) => SetEquals(obj);\n\n public override bool Equals(object obj) => Equals(obj as MathSet<T>);\n\n public static bool operator ==(MathSet<T> a, MathSet<T> b) =>\n ReferenceEquals(a, null) ? ReferenceEquals(b, null) : a.Equals(b);\n\n public static bool operator !=(MathSet<T> a, MathSet<T> b) => !(a == b);\n}\n var a = new MathSet<int> { 1, 2, 3 };\nvar b = new MathSet<int> { 3, 2, 1 };\n\nvar c = a.Equals(b); // true\n\nvar d = new MathSet<MathSet<int>> { a, b }; // contains one element\n\nvar e = a == b; // true\n HashSet"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10458",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
10,477 |
<p>Currently, I'm attempting to make multiple beziers have equidistant points. I'm currently using cubic interpolation to find the points, but because the way beziers work some areas are more dense than others and proving gross for texture mapping because of the variable distance. <strong>Is there a way to find points on a bezier by distance rather than by percentage? Furthermore, is it possible to extend this to multiple connected curves?</strong></p>
|
[
{
"answer_id": 34804516,
"author": "enc_life",
"author_id": 3166209,
"author_profile": "https://Stackoverflow.com/users/3166209",
"pm_score": 2,
"selected": false,
"text": "UIBezierPath X Y extension UIBezierPath {\n\nfunc solveBezerAtY(start: CGPoint, point1: CGPoint, point2: CGPoint, end: CGPoint, y: CGFloat) -> [CGPoint] {\n\n // bezier control points\n let C0 = start.y - y\n let C1 = point1.y - y\n let C2 = point2.y - y\n let C3 = end.y - y\n\n // The cubic polynomial coefficients such that Bez(t) = A*t^3 + B*t^2 + C*t + D\n let A = C3 - 3.0*C2 + 3.0*C1 - C0\n let B = 3.0*C2 - 6.0*C1 + 3.0*C0\n let C = 3.0*C1 - 3.0*C0\n let D = C0\n\n let roots = solveCubic(A, b: B, c: C, d: D)\n\n var result = [CGPoint]()\n\n for root in roots {\n if (root >= 0 && root <= 1) {\n result.append(bezierOutputAtT(start, point1: point1, point2: point2, end: end, t: root))\n }\n }\n\n return result\n}\n\nfunc solveBezerAtX(start: CGPoint, point1: CGPoint, point2: CGPoint, end: CGPoint, x: CGFloat) -> [CGPoint] {\n\n // bezier control points\n let C0 = start.x - x\n let C1 = point1.x - x\n let C2 = point2.x - x\n let C3 = end.x - x\n\n // The cubic polynomial coefficients such that Bez(t) = A*t^3 + B*t^2 + C*t + D\n let A = C3 - 3.0*C2 + 3.0*C1 - C0\n let B = 3.0*C2 - 6.0*C1 + 3.0*C0\n let C = 3.0*C1 - 3.0*C0\n let D = C0\n\n let roots = solveCubic(A, b: B, c: C, d: D)\n\n var result = [CGPoint]()\n\n for root in roots {\n if (root >= 0 && root <= 1) {\n result.append(bezierOutputAtT(start, point1: point1, point2: point2, end: end, t: root))\n }\n }\n\n return result\n\n}\n\nfunc solveCubic(a: CGFloat?, var b: CGFloat, var c: CGFloat, var d: CGFloat) -> [CGFloat] {\n\n if (a == nil) {\n return solveQuadratic(b, b: c, c: d)\n }\n\n b /= a!\n c /= a!\n d /= a!\n\n let p = (3 * c - b * b) / 3\n let q = (2 * b * b * b - 9 * b * c + 27 * d) / 27\n\n if (p == 0) {\n return [pow(-q, 1 / 3)]\n\n } else if (q == 0) {\n return [sqrt(-p), -sqrt(-p)]\n\n } else {\n\n let discriminant = pow(q / 2, 2) + pow(p / 3, 3)\n\n if (discriminant == 0) {\n return [pow(q / 2, 1 / 3) - b / 3]\n\n } else if (discriminant > 0) {\n let x = crt(-(q / 2) + sqrt(discriminant))\n let z = crt((q / 2) + sqrt(discriminant))\n return [x - z - b / 3]\n } else {\n\n let r = sqrt(pow(-(p/3), 3))\n let phi = acos(-(q / (2 * sqrt(pow(-(p / 3), 3)))))\n\n let s = 2 * pow(r, 1/3)\n\n return [\n s * cos(phi / 3) - b / 3,\n s * cos((phi + CGFloat(2) * CGFloat(M_PI)) / 3) - b / 3,\n s * cos((phi + CGFloat(4) * CGFloat(M_PI)) / 3) - b / 3\n ]\n\n }\n\n }\n}\n\nfunc solveQuadratic(a: CGFloat, b: CGFloat, c: CGFloat) -> [CGFloat] {\n\n let discriminant = b * b - 4 * a * c;\n\n if (discriminant < 0) {\n return []\n\n } else {\n return [\n (-b + sqrt(discriminant)) / (2 * a),\n (-b - sqrt(discriminant)) / (2 * a)\n ]\n }\n\n}\n\nprivate func crt(v: CGFloat) -> CGFloat {\n if (v<0) {\n return -pow(-v, 1/3)\n }\n return pow(v, 1/3)\n}\n\nprivate func bezierOutputAtT(start: CGPoint, point1: CGPoint, point2: CGPoint, end: CGPoint, t: CGFloat) -> CGPoint {\n\n // bezier control points\n let C0 = start\n let C1 = point1\n let C2 = point2\n let C3 = end\n\n // The cubic polynomial coefficients such that Bez(t) = A*t^3 + B*t^2 + C*t + D\n let A = CGPointMake(C3.x - 3.0*C2.x + 3.0*C1.x - C0.x, C3.y - 3.0*C2.y + 3.0*C1.y - C0.y)\n let B = CGPointMake(3.0*C2.x - 6.0*C1.x + 3.0*C0.x, 3.0*C2.y - 6.0*C1.y + 3.0*C0.y)\n let C = CGPointMake(3.0*C1.x - 3.0*C0.x, 3.0*C1.y - 3.0*C0.y)\n let D = C0\n\n return CGPointMake(((A.x*t+B.x)*t+C.x)*t+D.x, ((A.y*t+B.y)*t+C.y)*t+D.y)\n}\n\n// TODO: - future implementation\nprivate func tangentAngleAtT(start: CGPoint, point1: CGPoint, point2: CGPoint, end: CGPoint, t: CGFloat) -> CGFloat {\n\n // bezier control points\n let C0 = start\n let C1 = point1\n let C2 = point2\n let C3 = end\n\n // The cubic polynomial coefficients such that Bez(t) = A*t^3 + B*t^2 + C*t + D\n let A = CGPointMake(C3.x - 3.0*C2.x + 3.0*C1.x - C0.x, C3.y - 3.0*C2.y + 3.0*C1.y - C0.y)\n let B = CGPointMake(3.0*C2.x - 6.0*C1.x + 3.0*C0.x, 3.0*C2.y - 6.0*C1.y + 3.0*C0.y)\n let C = CGPointMake(3.0*C1.x - 3.0*C0.x, 3.0*C1.y - 3.0*C0.y)\n\n return atan2(3.0*A.y*t*t + 2.0*B.y*t + C.y, 3.0*A.x*t*t + 2.0*B.x*t + C.x)\n}\n\n}\n"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10477",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1256/"
] |
10,478 |
<p>One of the things I'd like to do in my browser-based application is allow the user to select some text (not in a <textarea>, just plain ol' text!), and have my application pop up a small toolbar that then can interact with the next (in my case, add annotations).</p>
<p>I've found a lot of stuff on google that seems to be focused on writing WYSIWYG editors, <strong>but that isn't what I want</strong>, and most of it worked in IE but not in FF2 or 3. Ideally, I'd like some function that can return the currently selected text in the browser window that works in <strong>IE7 (and 6 if possible), FireFox 2 & 3 and Safari 2</strong>. If it works in Opera, that'd be a bonus, but it's not a requirement.</p>
<p>Anyone have a function that does this? Or an idea of where to start?</p>
|
[
{
"answer_id": 13914,
"author": "Polsonby",
"author_id": 137,
"author_profile": "https://Stackoverflow.com/users/137",
"pm_score": -1,
"selected": false,
"text": "var str = (window.getSelection) ? window.getSelection() : document.selection.createRange();\nstr = str.text || str;\nstr = str + ''; // the best way to make object a string...\n"
},
{
"answer_id": 169873,
"author": "Greg Borenstein",
"author_id": 10419,
"author_profile": "https://Stackoverflow.com/users/10419",
"pm_score": 4,
"selected": false,
"text": "function getSelectedText() {\n var txt = '';\n\n if (window.getSelection) {\n txt = window.getSelection();\n }\n else if (document.getSelection) {\n txt = document.getSelection();\n }\n else if (document.selection) {\n txt = document.selection.createRange().text;\n }\n else return; \n\n return txt;\n}\n"
},
{
"answer_id": 54039149,
"author": "YakovL",
"author_id": 3995261,
"author_profile": "https://Stackoverflow.com/users/3995261",
"pm_score": 2,
"selected": false,
"text": "function getSelectedText() {\n return window.getSelection ? window.getSelection().toString() : '';\n}\n ''"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10478",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/722/"
] |
10,486 |
<p>What kind of execution rate do you aim for with your unit tests (# test per second)? How long is too long for an individual unit test? </p>
<p>I'd be interested in knowing if people have any specific thresholds for determining whether their tests are too slow, or is it just when the friction of a long running test suite gets the better of you? </p>
<p>Finally, when you do decide the tests need to run faster, what techniques do you use to speed up your tests?</p>
<p><em>Note: integration tests are obviously a different matter again. We are strictly talking unit tests that need to be run as frequently as possible.</em></p>
<hr>
<p><strong>Response roundup:</strong> Thanks for the great responses so far. Most advice seems to be don't worry about the speed -- concentrate on quality and just selectively run them if they are too slow. Answers with specific numbers have included aiming for <10ms up to 0.5 and 1 second per test, or just keeping the entire suite of commonly run tests under 10 seconds. </p>
<p>Not sure whether it's right to mark one as an "accepted answer" when they're all helpful :)</p>
|
[
{
"answer_id": 313692,
"author": "Daniel Schierbeck",
"author_id": 20321,
"author_profile": "https://Stackoverflow.com/users/20321",
"pm_score": 0,
"selected": false,
"text": "app/models/foo.rb test/unit/foo_test.rb"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/906/"
] |
10,499 |
<p>Sometimes I get Oracle connection problems because I can't figure out which tnsnames.ora file my database client is using.</p>
<p>What's the best way to figure this out? ++happy for various platform solutions. </p>
|
[
{
"answer_id": 10501,
"author": "Mark Harrison",
"author_id": 116,
"author_profile": "https://Stackoverflow.com/users/116",
"pm_score": 5,
"selected": false,
"text": "$ strace sqlplus -L scott/tiger@orcl 2>&1| grep -i 'open.*tnsnames.ora'\n open(\"/opt/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora\",O_RDONLY)=7\n $ strace sqlplus -L scott/tiger@orcl 2>&1| grep -i 'tnsnames.ora'\n"
},
{
"answer_id": 29807,
"author": "stjohnroe",
"author_id": 2985,
"author_profile": "https://Stackoverflow.com/users/2985",
"pm_score": 7,
"selected": true,
"text": "tnsping R:\\>tnsping someconnection\n\nTNS Ping Utility for 32-bit Windows: Version 9.0.1.3.1 - Production on 27-AUG-20\n08 10:38:07\n\nCopyright (c) 1997 Oracle Corporation. All rights reserved.\n\nUsed parameter files:\nC:\\Oracle92\\network\\ADMIN\\sqlnet.ora\nC:\\Oracle92\\network\\ADMIN\\tnsnames.ora\n\nTNS-03505: Failed to resolve name\n\nR:\\>\n\n\nR:\\>tnsping entpr01\n\nTNS Ping Utility for 32-bit Windows: Version 9.0.1.3.1 - Production on 27-AUG-20\n08 10:39:22\n\nCopyright (c) 1997 Oracle Corporation. All rights reserved.\n\nUsed parameter files:\nC:\\Oracle92\\network\\ADMIN\\sqlnet.ora\nC:\\Oracle92\\network\\ADMIN\\tnsnames.ora\n\nUsed TNSNAMES adapter to resolve the alias\nAttempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (COMMUNITY = **)\n (PROTOCOL = TCP) (Host = ****) (Port = 1521))) (CONNECT_DATA = (SID = ENTPR0\n1)))\nOK (40 msec)\n\nR:\\>\n bin"
},
{
"answer_id": 35804,
"author": "Sir Rippov the Maple",
"author_id": 2822,
"author_profile": "https://Stackoverflow.com/users/2822",
"pm_score": 3,
"selected": false,
"text": "regedit My HKEY Local Machine/Software/ORACLE/KEY_OraClient10_home1 KEY_OraClient10_home1 TNS_ADMIN"
},
{
"answer_id": 189142,
"author": "DCookie",
"author_id": 8670,
"author_profile": "https://Stackoverflow.com/users/8670",
"pm_score": 2,
"selected": false,
"text": "C:\\Documents and Settings\\me>D:\\Oracle\\10.2.0_DB\\BIN\\tnsping orcl\n\nTNS Ping Utility for 32-bit Windows: Version 10.2.0.4.0 - Production on 09-OCT-2\n008 14:30:12\n\nCopyright (c) 1997, 2007, Oracle. All rights reserved.\n\nUsed parameter files:\nD:\\Oracle\\10.2.0_DB\\network\\admin\\sqlnet.ora\n\n\nUsed TNSNAMES adapter to resolve the alias\nAttempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = xxxx\n)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ORCL)))\n\nOK (40 msec)\n\nC:\\Documents and Settings\\me>tnsping orcl\n\nTNS Ping Utility for 32-bit Windows: Version 10.2.0.1.0 - Production on 09-OCT-2\n008 14:30:21\n\nCopyright (c) 1997, 2005, Oracle. All rights reserved.\n\nUsed parameter files:\nD:\\oracle\\10.2.0_Client\\network\\admin\\sqlnet.ora\n\n\nUsed TNSNAMES adapter to resolve the alias\nAttempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)\n(HOST = XXXX)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = ORCL)))\nOK (20 msec)\n\nC:\\Documents and Settings\\me>\n"
},
{
"answer_id": 200344,
"author": "Rene",
"author_id": 17323,
"author_profile": "https://Stackoverflow.com/users/17323",
"pm_score": 3,
"selected": false,
"text": "tnsnames.ora tnsnames.ora ifile=path_to_tnsnames.ora_file/tnsnames.ora\n tnsnames.ora"
},
{
"answer_id": 20523156,
"author": "sri",
"author_id": 3091747,
"author_profile": "https://Stackoverflow.com/users/3091747",
"pm_score": 1,
"selected": false,
"text": "strace sqlplus -L scott/tiger@orcl .tnsnames.ora /home/oracle $ORACLE_HOME/network/admin/tnsnames.ora"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10499",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/116/"
] |
10,506 |
<p>I am having a strange DB2 issue when I run DBUnit tests. My DBUnit tests are highly customized, but I don't think it is the issue. When I run the tests, I get a failure: </p>
<blockquote>
<p>SQLCODE: -1084, SQLSTATE: 57019</p>
</blockquote>
<p><a href="https://www1.columbia.edu/sec/acis/db2/db2m0/sql1000.htm" rel="nofollow noreferrer">which translates to</a> </p>
<blockquote>
<p>SQL1084C Shared memory segments cannot be allocated.</p>
</blockquote>
<p>It sounds like a weird memory issue, though here's the big strange thing. If I ssh to the test database server, then go in to db2 and do "connect to MY_DB", the tests start succeeding! This seems to have no relation to the supposed memory error that is being reported.</p>
<p>I have 2 tests, and the first one actually succeeds, the second one is the one that fails. However, it fails in the DBUnit setup code, when it is obtaining the connection to the DB server to load my xml dataset.</p>
<p>Any ideas what might be going on?</p>
|
[
{
"answer_id": 10501,
"author": "Mark Harrison",
"author_id": 116,
"author_profile": "https://Stackoverflow.com/users/116",
"pm_score": 5,
"selected": false,
"text": "$ strace sqlplus -L scott/tiger@orcl 2>&1| grep -i 'open.*tnsnames.ora'\n open(\"/opt/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora\",O_RDONLY)=7\n $ strace sqlplus -L scott/tiger@orcl 2>&1| grep -i 'tnsnames.ora'\n"
},
{
"answer_id": 29807,
"author": "stjohnroe",
"author_id": 2985,
"author_profile": "https://Stackoverflow.com/users/2985",
"pm_score": 7,
"selected": true,
"text": "tnsping R:\\>tnsping someconnection\n\nTNS Ping Utility for 32-bit Windows: Version 9.0.1.3.1 - Production on 27-AUG-20\n08 10:38:07\n\nCopyright (c) 1997 Oracle Corporation. All rights reserved.\n\nUsed parameter files:\nC:\\Oracle92\\network\\ADMIN\\sqlnet.ora\nC:\\Oracle92\\network\\ADMIN\\tnsnames.ora\n\nTNS-03505: Failed to resolve name\n\nR:\\>\n\n\nR:\\>tnsping entpr01\n\nTNS Ping Utility for 32-bit Windows: Version 9.0.1.3.1 - Production on 27-AUG-20\n08 10:39:22\n\nCopyright (c) 1997 Oracle Corporation. All rights reserved.\n\nUsed parameter files:\nC:\\Oracle92\\network\\ADMIN\\sqlnet.ora\nC:\\Oracle92\\network\\ADMIN\\tnsnames.ora\n\nUsed TNSNAMES adapter to resolve the alias\nAttempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (COMMUNITY = **)\n (PROTOCOL = TCP) (Host = ****) (Port = 1521))) (CONNECT_DATA = (SID = ENTPR0\n1)))\nOK (40 msec)\n\nR:\\>\n bin"
},
{
"answer_id": 35804,
"author": "Sir Rippov the Maple",
"author_id": 2822,
"author_profile": "https://Stackoverflow.com/users/2822",
"pm_score": 3,
"selected": false,
"text": "regedit My HKEY Local Machine/Software/ORACLE/KEY_OraClient10_home1 KEY_OraClient10_home1 TNS_ADMIN"
},
{
"answer_id": 189142,
"author": "DCookie",
"author_id": 8670,
"author_profile": "https://Stackoverflow.com/users/8670",
"pm_score": 2,
"selected": false,
"text": "C:\\Documents and Settings\\me>D:\\Oracle\\10.2.0_DB\\BIN\\tnsping orcl\n\nTNS Ping Utility for 32-bit Windows: Version 10.2.0.4.0 - Production on 09-OCT-2\n008 14:30:12\n\nCopyright (c) 1997, 2007, Oracle. All rights reserved.\n\nUsed parameter files:\nD:\\Oracle\\10.2.0_DB\\network\\admin\\sqlnet.ora\n\n\nUsed TNSNAMES adapter to resolve the alias\nAttempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = xxxx\n)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ORCL)))\n\nOK (40 msec)\n\nC:\\Documents and Settings\\me>tnsping orcl\n\nTNS Ping Utility for 32-bit Windows: Version 10.2.0.1.0 - Production on 09-OCT-2\n008 14:30:21\n\nCopyright (c) 1997, 2005, Oracle. All rights reserved.\n\nUsed parameter files:\nD:\\oracle\\10.2.0_Client\\network\\admin\\sqlnet.ora\n\n\nUsed TNSNAMES adapter to resolve the alias\nAttempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)\n(HOST = XXXX)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = ORCL)))\nOK (20 msec)\n\nC:\\Documents and Settings\\me>\n"
},
{
"answer_id": 200344,
"author": "Rene",
"author_id": 17323,
"author_profile": "https://Stackoverflow.com/users/17323",
"pm_score": 3,
"selected": false,
"text": "tnsnames.ora tnsnames.ora ifile=path_to_tnsnames.ora_file/tnsnames.ora\n tnsnames.ora"
},
{
"answer_id": 20523156,
"author": "sri",
"author_id": 3091747,
"author_profile": "https://Stackoverflow.com/users/3091747",
"pm_score": 1,
"selected": false,
"text": "strace sqlplus -L scott/tiger@orcl .tnsnames.ora /home/oracle $ORACLE_HOME/network/admin/tnsnames.ora"
}
] |
2008/08/13
|
[
"https://Stackoverflow.com/questions/10506",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/122/"
] |
10,515 |
<p>Having been a PHP developer on LAMP servers for quite a while, is there anything that I will need to take into consideration while preparing an application for <em>IIS</em> on windows.</p>
|
[
{
"answer_id": 10547,
"author": "Kev",
"author_id": 419,
"author_profile": "https://Stackoverflow.com/users/419",
"pm_score": 2,
"selected": false,
"text": "fcgiconfig.js"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10515",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/115/"
] |
10,532 |
<p>I've been using PHP & MySQL for ages and am about to start using PostgreSQL instead.</p>
<p>What's the preferred method? </p>
<p>Is it via the PDO objects or is there something better?</p>
|
[
{
"answer_id": 10689,
"author": "grom",
"author_id": 486,
"author_profile": "https://Stackoverflow.com/users/486",
"pm_score": 2,
"selected": false,
"text": "require_once 'Zend/Db.php';\n$DB_ADAPTER = 'Pdo_Pgsql';\n$DB_CONFIG = array(\n 'username' => 'app_db_user',\n 'password' => 'xxxxxxxxx',\n 'host' => 'localhost',\n 'port' => 5432,\n 'dbname' => 'mydb'\n);\n$db = Zend_Db::factory($DB_ADAPTER, $DB_CONFIG);\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10532",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/305/"
] |
10,533 |
<p>Here's a problem I ran into recently. I have attributes strings of the form</p>
<pre><code>"x=1 and y=abc and z=c4g and ..."
</code></pre>
<p>Some attributes have numeric values, some have alpha values, some have mixed, some have dates, etc.</p>
<p>Every string is <em>supposed</em> to have "<code>x=someval and y=anotherval</code>" at the beginning, but some don't. I have three things I need to do. </p>
<ol>
<li>Validate the strings to be certain that they have <code>x</code> and <code>y</code>. </li>
<li>Actually parse the values for <code>x</code> and <code>y</code>.</li>
<li>Get the rest of the string.</li>
</ol>
<p>Given the example at the top, this would result in the following variables:</p>
<pre><code>$x = 1;
$y = "abc";
$remainder = "z=c4g and ..."
</code></pre>
<p>My question is: Is there a (reasonably) simple way to parse these <em>and</em> validate with a single regular expression? i.e.:</p>
<pre><code>if ($str =~ /someexpression/)
{
$x = $1;
$y = $2;
$remainder = $3;
}
</code></pre>
<p>Note that the string may consist of <em>only</em> <code>x</code> and <code>y</code> attributes. This is a valid string.</p>
<p>I'll post my solution as an answer, but it doesn't meet my single-regex preference.</p>
|
[
{
"answer_id": 10537,
"author": "Derek Park",
"author_id": 872,
"author_profile": "https://Stackoverflow.com/users/872",
"pm_score": 0,
"selected": false,
"text": "($x_str, $y_str, $remainder) = split(/ and /, $str, 3);\n\nif ($x_str !~ /x=(.*)/)\n{\n # error\n}\n\n$x = $1;\n\nif ($y_str !~ /y=(.*)/)\n{\n # error\n}\n\n$y = $1;\n"
},
{
"answer_id": 10573,
"author": "Rudd Zwolinski",
"author_id": 219,
"author_profile": "https://Stackoverflow.com/users/219",
"pm_score": 2,
"selected": true,
"text": "/x=(.+) and y=([^ ]+)( and (.*))?/\n my @strs = (\"x=1 and y=abc and z=c4g and w=v4l\",\n \"x=yes and y=no\",\n \"z=nox and w=noy\");\n\nforeach (@strs) {\n if ($_ =~ /x=(.+) and y=([^ ]+)( and (.*))?/) {\n $x = $1;\n $y = $2;\n $remainder = $4;\n print \"x: $x; y: $y; remainder: $remainder\\n\";\n } else {\n print \"Failed.\\n\";\n }\n}\n x: 1; y: abc; remainder: z=c4g and w=v4l\nx: yes; y: no; remainder: \nFailed.\n"
},
{
"answer_id": 13677,
"author": "Cebjyre",
"author_id": 1612,
"author_profile": "https://Stackoverflow.com/users/1612",
"pm_score": 1,
"selected": false,
"text": "/^x=(.+) and y=([^ ]+)(?: and (.*))?/\n my @strs = (\"x=1 and y=abc and z=c4g and w=v4l\",\n \"x=yes and y=no\",\n \"z=nox and w=noy\",\n \"not-x=nox and y=present\",\n \"x=yes and w='there is no and y=something arg here'\");\n\nforeach (@strs) {\n if ($_ =~ /^x=(.+) and y=([^ ]+)(?: and (.*))?/) {\n $x = $1;\n $y = $2;\n $remainder = $3;\n print \"x: {$x}; y: {$y}; remainder: {$remainder}\\n\";\n } else {\n print \"$_ Failed.\\n\";\n }\n}\n x: {1}; y: {abc}; remainder: {z=c4g and w=v4l}\nx: {yes}; y: {no}; remainder: {}\nz=nox and w=noy Failed.\nnot-x=nox and y=present Failed.\nx: {yes and w='there is no}; y: {something}; remainder: {}\n"
},
{
"answer_id": 21003,
"author": "Brad Gilbert",
"author_id": 1337,
"author_profile": "https://Stackoverflow.com/users/1337",
"pm_score": 2,
"selected": false,
"text": "use 5.10.0;\nuse strict;\nuse warnings;\n\nmy %hash;\nwhile(\n $string =~ m{\n (?: ^ | \\G ) # start of string or previous match\n \\s*\n\n (?<key> \\w+ ) # word characters\n =\n (?<value> \\S+ ) # non spaces\n\n \\s* # get to the start of the next match\n (?: and )?\n }xgi\n){\n $hash{$+{key}} = $+{value};\n}\n\n# to make sure that x & y exist\ndie unless exists $hash{x} and exists $hash{y};\n use strict;\nuse warnings;\n\nmy %hash;\nwhile(\n $string =~ m{\n (?: ^ | \\G ) # start of string or previous match\n \\s*\n\n ( \\w+ ) = ( \\S+ )\n\n \\s* # get to the start of the next match\n (?: and )?\n }xgi\n){\n $hash{$1} = $2;\n}\n\n# to make sure that x & y exist\ndie unless exists $hash{x} and exists $hash{y};\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10533",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/872/"
] |
10,564 |
<p>I'm trying out <strong>Git on Windows</strong>. I got to the point of trying "git commit" and I got this error:</p>
<blockquote>
<p>Terminal is dumb but no VISUAL nor
EDITOR defined. Please supply the
message using either -m or -F option.</p>
</blockquote>
<p>So I figured out I need to have an environment variable called EDITOR. No problem. I set it to point to Notepad. That worked, almost. The default commit message opens in Notepad. But Notepad doesn't support bare line feeds. I went out and got <a href="http://notepad-plus.sourceforge.net/uk/site.htm" rel="noreferrer">Notepad++</a>, but I can't figure out how to get Notepad++ set up as the <code>%EDITOR%</code> in such a way that it works with Git as expected.</p>
<p>I'm not married to Notepad++. At this point I don't mind what editor I use. I just want to be able to <strong>type commit messages in an editor</strong> rather than the command line (with <code>-m</code>).</p>
<p>Those of you using Git on Windows: What tool do you use to edit your commit messages, and what did you have to do to make it work?</p>
|
[
{
"answer_id": 10574,
"author": "J Wynia",
"author_id": 1124,
"author_profile": "https://Stackoverflow.com/users/1124",
"pm_score": 1,
"selected": false,
"text": "git commit -m \"Fixed the LoadAll method\"\n"
},
{
"answer_id": 10625,
"author": "Patrick Johnmeyer",
"author_id": 363,
"author_profile": "https://Stackoverflow.com/users/363",
"pm_score": 4,
"selected": false,
"text": "EDITOR start /WAIT \"E:\\PortableApps\\Notepad++Portable\\Notepad++Portable.exe\" %*\n /WAIT C:\\src> echo %EDITOR%\nC:\\tools\\runeditor.bat\n"
},
{
"answer_id": 11129,
"author": "Matt McMinn",
"author_id": 1322,
"author_profile": "https://Stackoverflow.com/users/1322",
"pm_score": 3,
"selected": false,
"text": ">echo %EDITOR%\n\nc:\\Vim\\Vim71\\vim.exe\n"
},
{
"answer_id": 773973,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 10,
"selected": true,
"text": "git config core.editor notepad notepad.exe git config format.commitMessageColumns 72 dscho larsxschneider gitster gitster launch_editor() GIT_EDITOR git rebase -i git config --global core.editor \"\\\"c:\\Program Files\\Notepad++\\notepad++.exe\\\"\"\n# or\ngit config --global core.editor \"\\\"c:\\Program Files\\Notepad++\\notepad++.exe\\\" %*\"\n C:\\prog\\git>git config --global --edit\n\"c:\\Program Files\\Notepad++\\notepad++.exe\" %*: c:\\Program Files\\Notepad++\\notepad++.exe: command not found\nerror: There was a problem with the editor '\"c:\\Program Files\\Notepad++\\notepad++.exe\" %*'.\n \"c:\\Program Files\\Notepad++\\notepad++.exe\" %*\n C:\\prog\\git>git config --global core.editor C:\\prog\\git\\npp.bat\n start /WAIT... / \\ git config --global core.editor \\\n\"'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin\"\n git config --global core.editor \\\n\"'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin\"\n git config /bin/sh C:\\prog\\git>git config --global core.editor C:/prog/git/npp.bat\n C:/prog/git/npp.bat #!/bin/sh\n\"c:/Program Files/Notepad++/notepad++.exe\" -multiInst \"$*\"\n #!/bin/sh\n\"c:/Program Files/Notepad++/notepad++.exe\" -multiInst -notabbar -nosession -noPlugin \"$*\"\n git config --global --edit git rebase -i ... -multiInst \\ git\\bin PATH [git]\\cmd .bat .sh \"<path-to-n++\" .git/COMMIT_EDITMSG -<arguments>. \n"
},
{
"answer_id": 1083830,
"author": "Darren Bishop",
"author_id": 133330,
"author_profile": "https://Stackoverflow.com/users/133330",
"pm_score": 6,
"selected": false,
"text": "git config --global core.editor \"'C:/Program Files/TextPad 5/TextPad.exe' -m\"\n ' \" / \\ -m %*"
},
{
"answer_id": 1086587,
"author": "bjnortier",
"author_id": 35448,
"author_profile": "https://Stackoverflow.com/users/35448",
"pm_score": 2,
"selected": false,
"text": "export EDITOR=\"emacs -nw\"\n -nw no-windows"
},
{
"answer_id": 1380109,
"author": "Tom Dunham",
"author_id": 6402,
"author_profile": "https://Stackoverflow.com/users/6402",
"pm_score": 1,
"selected": false,
"text": "error: There was a problem with the editor 'ec'\n VISUAL=ec ec.bat c:\\emacs\\emacs-23.1\\bin\\emacsclient.exe %*\n ec <filename> VISUAL git commit ec ec.exe ec.bat GIT_EDITOR=ec.bat"
},
{
"answer_id": 1431003,
"author": "Bennett McElwee",
"author_id": 61754,
"author_profile": "https://Stackoverflow.com/users/61754",
"pm_score": 8,
"selected": false,
"text": "git config --global core.editor \"'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin\"\n C:/Program Files/Notepad++/notepad++.exe C:/Program Files (x86)/Notepad++/notepad++.exe"
},
{
"answer_id": 1574521,
"author": "Tim Henigan",
"author_id": 63147,
"author_profile": "https://Stackoverflow.com/users/63147",
"pm_score": 3,
"selected": false,
"text": "git_editor.bat \"C:/Program Files/Vim/vim72/gvim.exe\" --nofork \"%*\" git_editor.bat PATH GIT_EDITOR=git_editor.bat git commit --nofork"
},
{
"answer_id": 2583824,
"author": "Whome",
"author_id": 185565,
"author_profile": "https://Stackoverflow.com/users/185565",
"pm_score": 3,
"selected": false,
"text": "#!/bin/sh\n# Open a new instance\n\nfunction doUnix() {\n \"c:\\program files\\notepad++\\notepad++.exe\" -multiInst -nosession -notabbar $*\n exit\n}\n\ndoUnix $*\n\n:WINCALL\n\"c:\\program files\\notepad++\\notepad++.exe\" -multiInst -nosession -notabbar %*\n git config --global core.editor \"git-editor.bat\"\n"
},
{
"answer_id": 3319715,
"author": "Michael Steele",
"author_id": 71116,
"author_profile": "https://Stackoverflow.com/users/71116",
"pm_score": 2,
"selected": false,
"text": "c:\\emacs c:\\emacs\\bin\\addpm.exe (server-start) .emacs .emacs git config --global core.editor emacsclientw c:\\emacs\\bin\\runemacs.exe"
},
{
"answer_id": 3422569,
"author": "Gavin",
"author_id": 78216,
"author_profile": "https://Stackoverflow.com/users/78216",
"pm_score": 4,
"selected": false,
"text": "git config core.editor '\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\"'\n"
},
{
"answer_id": 3820077,
"author": "CharlesB",
"author_id": 11343,
"author_profile": "https://Stackoverflow.com/users/11343",
"pm_score": 2,
"selected": false,
"text": "git config --global core.editor C:/path/to/geany.bat\n geany.bat #!/bin/sh\n\"C:\\Program Files\\Geany\\bin\\Geany.exe\" --new-instance \"$*\"\n"
},
{
"answer_id": 4652019,
"author": "Nick Knowlson",
"author_id": 224354,
"author_profile": "https://Stackoverflow.com/users/224354",
"pm_score": 5,
"selected": false,
"text": "git config --global core.editor \"gvim --nofork '%*'\"\n git config --global core.editor \\\n\"'C:/Program Files/Vim/vim72/gvim.exe' --nofork '%*'\"\n"
},
{
"answer_id": 4792999,
"author": "Mike",
"author_id": 419934,
"author_profile": "https://Stackoverflow.com/users/419934",
"pm_score": 1,
"selected": false,
"text": "/ EDITOR=\"c:/Program Files (x86)/Notepad++/notepad++.exe\"\n"
},
{
"answer_id": 6626128,
"author": "lambacck",
"author_id": 108518,
"author_profile": "https://Stackoverflow.com/users/108518",
"pm_score": 3,
"selected": false,
"text": "TERM=dumb less export TERM=msys\n echo \"export TERM=msys\" >> ~/.bashrc\n TERM=dumb TERM=dumb TERM=dumb unset TERM git config --global core.editor $MYFAVORITEEDITOR"
},
{
"answer_id": 7163913,
"author": "mbx",
"author_id": 303290,
"author_profile": "https://Stackoverflow.com/users/303290",
"pm_score": 0,
"selected": false,
"text": "~/.git #!/usr/bin/perl\n# Detect which system I'm on and choose the right editor\n$unamea = `uname -a`;\nif($unamea =~ /mingw/i){\n if($unamea =~ /devsystem/i){#Check hostname\n exec('C:\\Program Files (x86)\\Notepad++\\notepad++.exe', '-multiInst', '-nosession', @ARGV);\n }\n if($unamea =~ /testsystem/i){\n exec('C:\\Program Files\\Notepad++\\notepad++.exe', '-multiInst', '-nosession', @ARGV);\n }\n}\n$MCEDIT=`which mcedit`;\nif($MCEDIT =~ /mcedit/){\n exec($MCEDIT, @ARGV);\n}\n$NANO=`which nano`;\nif($NANO =~ /nano/){\n exec($NANO, @ARGV);\n}\ndie \"You don't have a suitable editor!\\n\";\n /home/username/bin PATH .bashrc .profile git config --global core.editor giteditor.pl"
},
{
"answer_id": 7549705,
"author": "Edward J Beckett",
"author_id": 538921,
"author_profile": "https://Stackoverflow.com/users/538921",
"pm_score": 3,
"selected": false,
"text": "git config --global core.editor c:/msysgit/cmd/epp.sh\n #!/bin/sh\n\"C:/Program Files/JGsoft/EditPadPro6/EditPadPro.exe\" //newinstance \"$*\"\n"
},
{
"answer_id": 12899808,
"author": "kghastie",
"author_id": 1028062,
"author_profile": "https://Stackoverflow.com/users/1028062",
"pm_score": 0,
"selected": false,
"text": "~/.gitconfig [core]\n editor = ~/script/textpad.sh\n ~/script/textpad.sh #!/bin/bash\n\nAPP_PATH=`cygpath \"c:/program files (x86)/textpad 6/textpad.exe\"`\nFILE_PATH=`cygpath -w $1`\n\n\"$APP_PATH\" -m \"$FILE_PATH\"\n ~/script/textpad.sh \"`cygpath \"c:/program files (x86)/textpad 6/textpad.exe\"`\" -m \"`cygpath -w $1`\"\n"
},
{
"answer_id": 17024500,
"author": "Bill",
"author_id": 368316,
"author_profile": "https://Stackoverflow.com/users/368316",
"pm_score": 3,
"selected": false,
"text": "git config --global core.editor giteditor\n"
},
{
"answer_id": 28386190,
"author": "JaKXz",
"author_id": 1444541,
"author_profile": "https://Stackoverflow.com/users/1444541",
"pm_score": 1,
"selected": false,
"text": "git config --global core.editor vim\n"
},
{
"answer_id": 31757683,
"author": "rofrol",
"author_id": 588759,
"author_profile": "https://Stackoverflow.com/users/588759",
"pm_score": 1,
"selected": false,
"text": "~/.gitconfig [core]\n editor = 'c:/program files/sublime text 3/subl.exe' -w\n"
},
{
"answer_id": 33368301,
"author": "avg",
"author_id": 1295023,
"author_profile": "https://Stackoverflow.com/users/1295023",
"pm_score": 1,
"selected": false,
"text": "/Git/cmd/"
},
{
"answer_id": 37169060,
"author": "Daniel",
"author_id": 3592441,
"author_profile": "https://Stackoverflow.com/users/3592441",
"pm_score": 3,
"selected": false,
"text": "git config --global core.editor \"'C:/Program Files (x86)/Sublime Text 3/subl.exe' -wait\"\n -wait"
},
{
"answer_id": 37558341,
"author": "Jonathan Ramos",
"author_id": 5934012,
"author_profile": "https://Stackoverflow.com/users/5934012",
"pm_score": 1,
"selected": false,
"text": "git config --global core.editor C:/Users/YOURNAMEUSER/AppData/Local/atom/app-1.7.4/atom.exe\"\n \\ / / /"
},
{
"answer_id": 39900408,
"author": "OmgKemuel",
"author_id": 4318447,
"author_profile": "https://Stackoverflow.com/users/4318447",
"pm_score": 4,
"selected": false,
"text": "git config --global core.editor \"atom --wait\"\n git config --global core.editor \"code --wait\"\n git config --global core.editor \"subl -n -w\"\n"
},
{
"answer_id": 41315379,
"author": "Zombo",
"author_id": 1002260,
"author_profile": "https://Stackoverflow.com/users/1002260",
"pm_score": 0,
"selected": false,
"text": "#!/bin/dash -e\nif [ \"$1\" ]\nthen k=$(cygpath -w \"$1\")\nelif [ \"$#\" != 0 ]\nthen k=\nfi\nNotepad2 ${k+\"$k\"}\n export EDITOR=notepad2.sh\nexport GIT_EDITOR='dash /usr/local/bin/notepad2.sh'\n"
},
{
"answer_id": 41637069,
"author": "guwer",
"author_id": 5144040,
"author_profile": "https://Stackoverflow.com/users/5144040",
"pm_score": 3,
"selected": false,
"text": "[core]\neditor = 'C:\\\\Program files\\\\path\\\\to\\\\editor.exe'\n"
},
{
"answer_id": 53048541,
"author": "JL_SO",
"author_id": 4026629,
"author_profile": "https://Stackoverflow.com/users/4026629",
"pm_score": 3,
"selected": false,
"text": "editor = 'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin\n"
},
{
"answer_id": 65355708,
"author": "Ruan Nawe",
"author_id": 6069435,
"author_profile": "https://Stackoverflow.com/users/6069435",
"pm_score": 1,
"selected": false,
"text": "git config --global core.editor \"'C:\\Program Files\\Sublime Text 3\\sublime_text.exe'\""
},
{
"answer_id": 68527047,
"author": "cxxl",
"author_id": 1045800,
"author_profile": "https://Stackoverflow.com/users/1045800",
"pm_score": 1,
"selected": false,
"text": "GIT_EDITOR notepad2 GIT_EDITOR C:/tools/notepad2.exe GIT_EDITOR C:/tools/notepad2.exe //utf8 -utf8"
},
{
"answer_id": 71192747,
"author": "Tal Jacob - Sir Jacques",
"author_id": 14427765,
"author_profile": "https://Stackoverflow.com/users/14427765",
"pm_score": 0,
"selected": false,
"text": ".gitconfig .gitconfig C:\\Users\\USER_NAME\\.gitconfig [core]\n editor = code -w -n\n[diff]\n tool = vscode\n[difftool \"vscode\"]\n cmd = code -w -n --diff $LOCAL $REMOTE\n[merge]\n tool = vscode\n[mergetool \"vscode\"]\n cmd = code -w -n $MERGED\n -w git -n git code [core]\n editor = \"'C:/Users/Tal/AppData/Local/Programs/Microsoft VS Code/Code.exe'\" -w -n\n[diff]\n tool = vscode\n[difftool \"vscode\"]\n cmd = \"'C:/Users/Tal/AppData/Local/Programs/Microsoft VS Code/Code.exe'\" -w -n --diff $LOCAL $REMOTE\n[merge]\n tool = vscode\n[mergetool \"vscode\"]\n cmd = \"'C:/Users/Tal/AppData/Local/Programs/Microsoft VS Code/Code.exe'\" -w -n $MERGED\n '' / [core]\n editor = \\\"C:\\\\Users\\\\Tal\\\\AppData\\\\Local\\\\Programs\\\\Microsoft VS Code\\\\Code.exe\\\" -w -n\n\n[diff]\n tool = vscode\n[difftool \"vscode\"]\n cmd = \\\"C:\\\\Users\\\\Tal\\\\AppData\\\\Local\\\\Programs\\\\Microsoft VS Code\\\\Code.exe\\\" -w -n --diff $LOCAL $REMOTE\n\n[merge]\n tool = vscode\n[mergetool \"vscode\"]\n cmd = \\\"C:\\\\Users\\\\Tal\\\\AppData\\\\Local\\\\Programs\\\\Microsoft VS Code\\\\Code.exe\\\" -w -n $MERGED\n [mergetool \"vscode\"]\n cmd = code -w -n $MERGED\n [mergetool \"vscode\"]\n cmd = code -w -n --merge $REMOTE $LOCAL $BASE $MERGED\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/437/"
] |
10,580 |
<p>What is the difference between early and late binding?</p>
|
[
{
"answer_id": 10581,
"author": "Ed S.",
"author_id": 1053,
"author_profile": "https://Stackoverflow.com/users/1053",
"pm_score": 3,
"selected": false,
"text": " Dim oXL As Object\n Set oXL = CreateObject(\"Excel.Application\")\n Dim oXL As Object\n Set oXL = GetObject(, \"Excel.Application\")\n Dim oXL As Excel.Application\n Set oXL = New Excel.Application\n"
},
{
"answer_id": 10582,
"author": "James A. Rosen",
"author_id": 1190,
"author_profile": "https://Stackoverflow.com/users/1190",
"pm_score": 4,
"selected": false,
"text": "//early binding:\npublic create_a_foo(*args) {\n return new Foo(args)\n}\nmy_foo = create_a_foo();\n\n//late binding:\npublic create_something(Class klass, *args) {\n klass.new_instance(args)\n}\nmy_foo = create_something(Foo);\n Class<? extends Foo> klass"
},
{
"answer_id": 10584,
"author": "James A. Rosen",
"author_id": 1190,
"author_profile": "https://Stackoverflow.com/users/1190",
"pm_score": 2,
"selected": false,
"text": "# early binding:\ndef create_a_foo(*args)\n Foo.new(*args)\nend\nmy_foo = create_a_foo\n\n# late binding:\ndef create_something(klass, *args)\n klass.new(*args)\nend\nmy_foo = create_something(Foo)\n"
},
{
"answer_id": 34935823,
"author": "JBOND",
"author_id": 5823364,
"author_profile": "https://Stackoverflow.com/users/5823364",
"pm_score": 0,
"selected": false,
"text": "public class child()\n{ public void method1()\n { System.out.println(\"child1\");\n }\n public void method2()\n { System.out.println(\"child2\");\n }\n\n}\npublic class teenager extends child()\n{ public void method3()\n { System.out.println(\"teenager3\");\n }\n}\npublic class adult extends teenager()\n{ \n public void method1()\n { System.out.println(\"adult1);\n super.method1();\n }\n}\n\n\n//In java\npublic static void main(String []args)\n{ ((teenager)var).method1();\n}\n adult1\nchild1\n"
},
{
"answer_id": 66262725,
"author": "Michu93",
"author_id": 4952262,
"author_profile": "https://Stackoverflow.com/users/4952262",
"pm_score": 0,
"selected": false,
"text": "public class Duck {\n public static void quack(){\n System.out.println(\"Quack\");\n }\n}\n\npublic class RubberDuck extends Duck {\n public static void quack(){\n System.out.println(\"Piiiiiiiiii\");\n }\n}\n\npublic class EarlyTest {\n public static void main(String[] args) {\n Duck duck = new Duck();\n Duck rubberduck = new RubberDuck();\n\n duck.quack();\n rubberduck.quack(); //early binding - compile time\n }\n}\n Quack\nQuack\n public class Duck {\n public void quack(){\n System.out.println(\"Quack\");\n }\n}\n\npublic class RubberDuck extends Duck {\n public void quack(){\n System.out.println(\"Piiiiiiiiii\");\n }\n}\n\npublic class LateTest {\n public static void main(String[] args){\n Duck duck = new Duck();\n Duck rubberduck = new RubberDuck();\n\n duck.quack();\n rubberduck.quack(); //late binding - runtime\n }\n}\n Quack\nPiiiiiiiiii\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10580",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1190/"
] |
10,586 |
<p>I'm currently trying to read in an XML file, make some minor changes (alter the value of some attributes), and write it back out again.</p>
<p>I have intended to use a StAX parser (<code>javax.xml.stream.XMLStreamReader</code>) to read in each event, see if it was one I wanted to change, and then pass it straight on to the StAX writer (<code>javax.xml.stream.XMLStreamReader</code>) if no changes were required.</p>
<p>Unfortunately, that doesn't look to be so simple - The writer has no way to take an event type and a parser object, only methods like <code>writeAttribute</code> and <code>writeStartElement</code>. Obviously I could write a big switch statement with a case for every possible type of element which can occur in an XML document, and just write it back out again, but it seems like a lot of trouble for something which seems like it should be simple.</p>
<p>Is there something I'm missing that makes it easy to write out a very similar XML document to the one you read in with StAX?</p>
|
[
{
"answer_id": 3453006,
"author": "StaxMan",
"author_id": 59501,
"author_profile": "https://Stackoverflow.com/users/59501",
"pm_score": 2,
"selected": false,
"text": "XMLStreamWriter2.copyEventFromReader(XMLStreamReader2 r, boolean preserveEventData) \n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/797/"
] |
10,595 |
<p>I've grokked the code for all the aforementioned apps and I still can't find a straightforward way to create a static directory structure from a single command.</p>
|
[
{
"answer_id": 10613,
"author": "Derek Park",
"author_id": 872,
"author_profile": "https://Stackoverflow.com/users/872",
"pm_score": 0,
"selected": false,
"text": "cp -r <template> <destination>\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1263/"
] |
10,599 |
<p>I need to validate a date/time field on a webpage but want it to do it without reloading the page and would like 'instant' feedback for the users.</p>
<p>What's the best/easiest solution.
BTW: easiest scores 65% of total points</p>
<p>Edit:
What if best was 65% of total points?</p>
|
[
{
"answer_id": 10609,
"author": "mbillard",
"author_id": 810,
"author_profile": "https://Stackoverflow.com/users/810",
"pm_score": 0,
"selected": false,
"text": "... onSubmit=\"return validateForm();\" ...\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10599",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/730/"
] |
10,610 |
<p>Does anyone use have a good regex library that they like to use? Most of the regexes that you find online either contain bugs or are so focused on the edge cases that it turns into a competition to validate whatever spec 100%. Of course you can write your own, but when you are billing by the hour its handy to have a library around. </p>
|
[
{
"answer_id": 34544283,
"author": "gsl",
"author_id": 2048692,
"author_profile": "https://Stackoverflow.com/users/2048692",
"pm_score": 0,
"selected": false,
"text": "Regexp::Common::balanced\nProvides regexes for strings with balanced parenthesized delimiters.\n\nRegexp::Common::comment\nProvides regexes for comments of various languages (43 languages currently).\n\nRegexp::Common::delimited\nProvides regexes for delimited strings.\n\nRegexp::Common::lingua\nProvides regexes for palindromes.\n\nRegexp::Common::list\nProvides regexes for lists.\n\nRegexp::Common::net\nProvides regexes for IPv4 addresses and MAC addresses.\n\nRegexp::Common::number\nProvides regexes for numbers (integers and reals).\n\nRegexp::Common::profanity\nProvides regexes for profanity.\n\nRegexp::Common::whitespace\nProvides regexes for leading and trailing whitespace.\n\nRegexp::Common::zip\nProvides regexes for zip codes.\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10610",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/805/"
] |
10,616 |
<p>I'm an <a href="http://en.wikipedia.org/wiki/ASP.NET" rel="noreferrer">ASP.NET</a> developer who has used <code>Microsoft SQL Server</code> for all my database needs (both at work and for personal projects). </p>
<p>I am considering trying out the <a href="http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29" rel="noreferrer">LAMP</a> stack for some of my personal projects. </p>
<p>What are some of the main differences between <code>MySQL</code> and <code>SQL Server</code>? Is using <a href="http://en.wikipedia.org/wiki/Stored_procedure" rel="noreferrer">stored procedures</a> a common practice in <code>MySQL</code>? </p>
<p>Any advice or resources you'd recommend to help me with the switch? </p>
<p>To those who have experience with both, are there any missing features from <code>MySQL</code>?</p>
|
[
{
"answer_id": 10623,
"author": "Jeff Atwood",
"author_id": 1,
"author_profile": "https://Stackoverflow.com/users/1",
"pm_score": 8,
"selected": true,
"text": "SELECT age\nFROM person\nORDER BY age ASC\nLIMIT 1 OFFSET 2\n SELECT TOP 3 WITH TIES *\nFROM person\nORDER BY age ASC\n"
},
{
"answer_id": 51254,
"author": "Cebjyre",
"author_id": 1612,
"author_profile": "https://Stackoverflow.com/users/1612",
"pm_score": 2,
"selected": false,
"text": "mysql> SELECT CONVERT_TZ('2008-04-01 12:00:00', 'UTC', 'America/Los_Angeles');\n+-----------------------------------------------------------------+\n| CONVERT_TZ('2008-04-01 12:00:00', 'UTC', 'America/Los_Angeles') |\n+-----------------------------------------------------------------+\n| 2008-04-01 05:00:00 |\n+-----------------------------------------------------------------+\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10616",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/285/"
] |
10,635 |
<p>I wrote a simple batch file as a PowerShell script, and I am getting errors when they run.</p>
<p>It's in a scripts directory in my path. This is the error I get:</p>
<blockquote>
<p>Cannot be loaded because the execution of scripts is disabled on this system.
Please see "get-help about-signing".</p>
</blockquote>
<p>I looked in the help, but it's less than helpful.</p>
|
[
{
"answer_id": 10638,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 8,
"selected": true,
"text": "set-executionpolicy remotesigned\n"
},
{
"answer_id": 10640,
"author": "Leon Bambrick",
"author_id": 49,
"author_profile": "https://Stackoverflow.com/users/49",
"pm_score": 3,
"selected": false,
"text": ".\\ .\\scriptname.ps1\n"
},
{
"answer_id": 11549657,
"author": "ExchangeAdmin",
"author_id": 1536046,
"author_profile": "https://Stackoverflow.com/users/1536046",
"pm_score": 1,
"selected": false,
"text": "set-executionpolicy unrestricted set-executionpolicy signed"
},
{
"answer_id": 16141428,
"author": "Naveen",
"author_id": 2306339,
"author_profile": "https://Stackoverflow.com/users/2306339",
"pm_score": 5,
"selected": false,
"text": "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process\n"
},
{
"answer_id": 19974975,
"author": "Nadeem_MK",
"author_id": 2416510,
"author_profile": "https://Stackoverflow.com/users/2416510",
"pm_score": 6,
"selected": false,
"text": "Set-ExecutionPolicy Set-ExecutionPolicy Restricted <-- Will not allow any powershell scripts to run. Only individual commands may be run.\n\nSet-ExecutionPolicy AllSigned <-- Will allow signed powershell scripts to run.\n\nSet-ExecutionPolicy RemoteSigned <-- Allows unsigned local script and signed remote powershell scripts to run.\n\nSet-ExecutionPolicy Unrestricted <-- Will allow unsigned powershell scripts to run. Warns before running downloaded scripts.\n\nSet-ExecutionPolicy Bypass <-- Nothing is blocked and there are no warnings or prompts.\n"
},
{
"answer_id": 21922658,
"author": "user3335140",
"author_id": 3335140,
"author_profile": "https://Stackoverflow.com/users/3335140",
"pm_score": 3,
"selected": false,
"text": "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process\n Access to the registry key 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\PowerShell\\1\\ShellIds\\Microsoft.PowerShell' is denied.\n"
},
{
"answer_id": 34007144,
"author": "Be Kind To New Users",
"author_id": 192044,
"author_profile": "https://Stackoverflow.com/users/192044",
"pm_score": 4,
"selected": false,
"text": "powershell -executionpolicy bypass -File .\\MYSCRIPT.ps1\n -executionpolicy bypass if NOT \"%1\" == \"scheduler\" (\n @echo looks like you started the script by clicking on it.\n @echo press space to continue or control C to exit.\n pause\n)\n\nC:\ncd \\Scripts\n\npowershell -executionpolicy bypass -File .\\rundps.ps1\n\nset psexitcode=%errorlevel%\n\nif NOT \"%1\" == \"scheduler\" (\n @echo Powershell finished. Press space to exit.\n pause\n)\n\nexit /b %psexitcode%\n"
},
{
"answer_id": 64084268,
"author": "Wasif",
"author_id": 12269857,
"author_profile": "https://Stackoverflow.com/users/12269857",
"pm_score": 1,
"selected": false,
"text": "type file.ps1 | powershell -command -\n gc file.ps1|powershell -c -\n"
},
{
"answer_id": 67022880,
"author": "Christian Brüggemann",
"author_id": 1502352,
"author_profile": "https://Stackoverflow.com/users/1502352",
"pm_score": 0,
"selected": false,
"text": "powershell -executionpolicy bypass -File .\\MYSCRIPT.ps1\n [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes((Get-Content .\\MYSCRIPT.ps1)))\n powershell.exe -EncodedCommand \"put-your-base64-string-here\"\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10635",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1220/"
] |
10,658 |
<p>I'm looking for a good method of generating an iCalendar file (*.ics) in c# (asp.net). I've found a couple resources, but one thing that has been lacking is their support for <strong>quoted-printable</strong> fields - fields that have carriage returns and line feeds.</p>
<p>For example, if the <strong>description</strong> field isn't encoded properly, only the first line will display and possibly corrupting the rest of the information in the *.ics file.</p>
<p>I'm looking for existing classes that can generate *.ics files and/or a class that can generate <strong>quoted-printable</strong> fields.</p>
|
[
{
"answer_id": 870249,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": " DESCRIPTION:Meeting to provide technical review for \"Phoenix\"\n design.\\n Happy Face Conference Room. Phoenix design team\n MUST attend this meeting.\\n RSVP to team leader.\n"
},
{
"answer_id": 4763886,
"author": "atmarx",
"author_id": 253717,
"author_profile": "https://Stackoverflow.com/users/253717",
"pm_score": 2,
"selected": false,
"text": " Private Function RFC2445TextField(ByVal LongText As String) As String\n\n LongText = LongText.Replace(\"\\\", \"\\\\\")\n LongText = LongText.Replace(\";\", \"\\;\")\n LongText = LongText.Replace(\",\", \"\\,\")\n\n Dim sBuilder As New StringBuilder\n Dim charArray() As Char = LongText.ToCharArray\n\n For i = 1 To charArray.Length\n sBuilder.Append(charArray(i - 1))\n If i Mod 74 = 0 Then sBuilder.Append(vbCrLf & \" \")\n Next\n\n Return sBuilder.ToString\n\n End Function\n"
},
{
"answer_id": 43877173,
"author": "Manpreet Singh Dhillon",
"author_id": 3495713,
"author_profile": "https://Stackoverflow.com/users/3495713",
"pm_score": 0,
"selected": false,
"text": "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Calendly//EN\nCALSCALE:GREGORIAN\nMETHOD:PUBLISH\nBEGIN:VEVENT\nDTSTAMP:20170509T164109Z\nUID:your id-11273661\nDTSTART:20170509T190000Z\nDTEND:20170509T191500Z\nCLASS:PRIVATE\nDESCRIPTION:Event Name: 15 Minute Meeting\\nDate & Time: 03:00pm - 03:15pm (\n Eastern Time - US & Canada) on Tuesday\\, May 9\\, 2017\\n\\nBest Phone Number\n To Reach You :: xxxxxxxxx\\n\\nany \"link\": https://wwww.yahoo.com\\n\\n\nSUMMARY:15 Minute Meeting\nTRANSP:OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n"
},
{
"answer_id": 46837390,
"author": "VDWWD",
"author_id": 5836671,
"author_profile": "https://Stackoverflow.com/users/5836671",
"pm_score": 2,
"selected": false,
"text": "//set a couple of variables for demo purposes\nDateTime IcsDateStart = DateTime.Now.AddDays(2);\nDateTime IcsDateEnd = IcsDateStart.AddMinutes(90);\nstring IcsSummary = \"ASP.Net demo snippet\";\nstring IcsLocation = \"Amsterdam (Netherlands)\";\nstring IcsDescription = @\"This snippes show you how to create a calendar item file (.ics) in ASP.NET.\\nMay it be useful for you.\";\nstring IcsFileName = \"MyCalendarFile\";\n\n//create a new stringbuilder instance\nStringBuilder sb = new StringBuilder();\n\n//begin the calendar item\nsb.AppendLine(\"BEGIN:VCALENDAR\");\nsb.AppendLine(\"VERSION:2.0\");\nsb.AppendLine(\"PRODID:stackoverflow.com\");\nsb.AppendLine(\"CALSCALE:GREGORIAN\");\nsb.AppendLine(\"METHOD:PUBLISH\");\n\n//create a custom time zone if needed, TZID to be used in the event itself\nsb.AppendLine(\"BEGIN:VTIMEZONE\");\nsb.AppendLine(\"TZID:Europe/Amsterdam\");\nsb.AppendLine(\"BEGIN:STANDARD\");\nsb.AppendLine(\"TZOFFSETTO:+0100\");\nsb.AppendLine(\"TZOFFSETFROM:+0100\");\nsb.AppendLine(\"END:STANDARD\");\nsb.AppendLine(\"END:VTIMEZONE\");\n\n//add the event\nsb.AppendLine(\"BEGIN:VEVENT\");\n\n//with a time zone specified\nsb.AppendLine(\"DTSTART;TZID=Europe/Amsterdam:\" + IcsDateStart.ToString(\"yyyyMMddTHHmm00\"));\nsb.AppendLine(\"DTEND;TZID=Europe/Amsterdam:\" + IcsDateEnd.ToString(\"yyyyMMddTHHmm00\"));\n\n//or without a time zone\n//sb.AppendLine(\"DTSTART:\" + IcsDateStart.ToString(\"yyyyMMddTHHmm00\"));\n//sb.AppendLine(\"DTEND:\" + IcsDateEnd.ToString(\"yyyyMMddTHHmm00\"));\n\n//contents of the calendar item\nsb.AppendLine(\"SUMMARY:\" + IcsSummary + \"\");\nsb.AppendLine(\"LOCATION:\" + IcsLocation + \"\");\nsb.AppendLine(\"DESCRIPTION:\" + IcsDescription + \"\");\nsb.AppendLine(\"PRIORITY:3\");\nsb.AppendLine(\"END:VEVENT\");\n\n//close calendar item\nsb.AppendLine(\"END:VCALENDAR\");\n\n//create a string from the stringbuilder\nstring CalendarItemAsString = sb.ToString();\n\n//send the ics file to the browser\nResponse.ClearHeaders();\nResponse.Clear();\nResponse.Buffer = true;\nResponse.ContentType = \"text/calendar\";\nResponse.AddHeader(\"content-length\", CalendarItemAsString.Length.ToString());\nResponse.AddHeader(\"content-disposition\", \"attachment; filename=\\\"\" + IcsFileName + \".ics\\\"\");\nResponse.Write(CalendarItemAsString);\nResponse.Flush();\nHttpContext.Current.ApplicationInstance.CompleteRequest();\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10658",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/519/"
] |
10,668 |
<p>I've been trying to understand how to read the memory of other processes on Mac OS X, but I'm not having much luck. I've seen many examples online using <code>ptrace</code> with <code>PEEKDATA</code> and such, however it doesn't have that option on BSD <sup>[<a href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/ptrace.2.html" rel="noreferrer"><code>man ptrace</code></a>]</sup>.</p>
<pre><code>int pid = fork();
if (pid > 0) {
// mess around with child-process's memory
}
</code></pre>
<p>How is it possible to read from and write to the memory of another process on Mac OS X?</p>
|
[
{
"answer_id": 10676,
"author": "Derek Park",
"author_id": 872,
"author_profile": "https://Stackoverflow.com/users/872",
"pm_score": 4,
"selected": false,
"text": "ptrace() PT_ATTACH PT_DENY_ATTACH PT_GETREGS PT_SETREGS PT_GETFPREGS PT_SETFPREGS ptrace.h PT_READ_I PT_READ_D PT_READ_U"
},
{
"answer_id": 63033,
"author": "Trance Diviner",
"author_id": 7365,
"author_profile": "https://Stackoverflow.com/users/7365",
"pm_score": 4,
"selected": false,
"text": "task_for_pid() vm_read() vm_write()"
},
{
"answer_id": 64276,
"author": "Scott Marcy",
"author_id": 8168,
"author_profile": "https://Stackoverflow.com/users/8168",
"pm_score": 3,
"selected": false,
"text": "// Create shared memory block\nvoid* sharedMemory = NULL;\nsize_t shmemSize = 123456;\nconst char* shmName = \"mySharedMemPath\"; \nint shFD = shm_open(shmName, (O_CREAT | O_EXCL | O_RDWR), 0600);\nif (shFD >= 0) {\n if (ftruncate(shFD, shmemSize) == 0) {\n sharedMemory = mmap(NULL, shmemSize, (PROT_READ | PROT_WRITE), MAP_SHARED, shFD, 0);\n if (sharedMemory != MAP_FAILED) {\n // Initialize shared memory if needed\n // Send 'shmemSize' & 'shmemSize' to other process(es)\n } else handle error\n } else handle error\n close(shFD); // Note: sharedMemory still valid until munmap() called\n} else handle error\n\n...\nDo stuff with shared memory\n...\n\n// Tear down shared memory\nif (sharedMemory != NULL) munmap(sharedMemory, shmemSize);\nif (shFD >= 0) shm_unlink(shmName);\n\n\n\n\n\n// Get the shared memory block from another process\nvoid* sharedMemory = NULL;\nsize_t shmemSize = 123456; // Or fetched via some other form of IPC\nconst char* shmName = \"mySharedMemPath\";// Or fetched via some other form of IPC\nint shFD = shm_open(shmName, (O_RDONLY), 0600); // Can be R/W if you want\nif (shFD >= 0) {\n data = mmap(NULL, shmemSize, PROT_READ, MAP_SHARED, shFD, 0);\n if (data != MAP_FAILED) {\n // Check shared memory for validity\n } else handle error\n close(shFD); // Note: sharedMemory still valid until munmap() called\n} else handle error\n\n\n...\nDo stuff with shared memory\n...\n\n// Tear down shared memory\nif (sharedMemory != NULL) munmap(sharedMemory, shmemSize);\n// Only the creator should shm_unlink()\n"
},
{
"answer_id": 24985204,
"author": "Jona",
"author_id": 2029914,
"author_profile": "https://Stackoverflow.com/users/2029914",
"pm_score": 3,
"selected": false,
"text": "// Create new xnu_proc instance\nxnu_proc *Process = new xnu_proc();\n\n// Attach to pid (or process name)\nProcess->Attach(getpid());\n\n// Manipulate memory\nint i = 1337, i2 = 0;\ni2 = process->memory().Read<int>((uintptr_t)&i);\n\n// Detach from process\nProcess->Detach();\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10668",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1114/"
] |
10,680 |
<p>Is there any difference between</p>
<pre><code> int on_exit(void (*function)(int , void *), void *arg);
</code></pre>
<p>and</p>
<pre><code> int atexit(void (*function)(void));
</code></pre>
<p>other than the fact that the function used by on_exit gets the exit status?</p>
<p>That is, if I don't care about the exit status, is there any reason to use one or the other?</p>
<p><strong>Edit:</strong> Many of the answers warned against <code>on_exit</code> because it's non-standard. If I'm developing an app that is for internal corporate use and guaranteed to run on specific configurations, should I worry about this? </p>
|
[
{
"answer_id": 10684,
"author": "Derek Park",
"author_id": 872,
"author_profile": "https://Stackoverflow.com/users/872",
"pm_score": 4,
"selected": false,
"text": "atexit() on_exit() on_exit()"
},
{
"answer_id": 10686,
"author": "Mike Stone",
"author_id": 122,
"author_profile": "https://Stackoverflow.com/users/122",
"pm_score": 5,
"selected": true,
"text": "on_exit on_exit on_exit"
},
{
"answer_id": 10770,
"author": "Mike Stone",
"author_id": 122,
"author_profile": "https://Stackoverflow.com/users/122",
"pm_score": 0,
"selected": false,
"text": "on_exit"
},
{
"answer_id": 10796,
"author": "Derek Park",
"author_id": 872,
"author_profile": "https://Stackoverflow.com/users/872",
"pm_score": 1,
"selected": false,
"text": "atexit() on_exit() exited_cleanly atexit()"
},
{
"answer_id": 3273116,
"author": "R.. GitHub STOP HELPING ICE",
"author_id": 379897,
"author_profile": "https://Stackoverflow.com/users/379897",
"pm_score": 3,
"selected": false,
"text": "atexit on_exit"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10680",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1084/"
] |
10,752 |
<p>I know the so-called textbook definition of unit tests and integration tests. What I am curious about is when it is time to write unit tests... I will write them to cover as many sets of classes as possible.</p>
<p>For example, if I have a <code>Word</code> class, I will write some unit tests for the <code>Word</code> class. Then, I begin writing my <code>Sentence</code> class, and when it needs to interact with the <code>Word</code> class, I will often write my unit tests such that they test both <code>Sentence</code> and <code>Word</code>... at least in the places where they interact.</p>
<p><em>Have these tests essentially become integration tests because they now test the integration of these 2 classes, or is it just a unit test that spans 2 classes?</em></p>
<p>In general, because of this uncertain line, I will rarely actually write integration tests... or is my using the finished product to see if all the pieces work properly the actual integration tests, even though they are manual and rarely repeated beyond the scope of each individual feature?</p>
<p>Am I misunderstanding integration tests, or is there really just very little difference between integration and unit tests?</p>
|
[
{
"answer_id": 1223466,
"author": "Robert Koritnik",
"author_id": 75642,
"author_profile": "https://Stackoverflow.com/users/75642",
"pm_score": 5,
"selected": false,
"text": "Sentence Word Word Sentence"
},
{
"answer_id": 7876055,
"author": "Arialdo Martini",
"author_id": 202443,
"author_profile": "https://Stackoverflow.com/users/202443",
"pm_score": 8,
"selected": false,
"text": "public SomeResults DoSomething(someInput) {\n var someResult = [Do your job with someInput];\n Log.TrackTheFactYouDidYourJob();\n return someResults;\n}\n DoSomething Feature: To be able to do something\n In order to do something\n As someone\n I want the system to do this thing\n\nScenario: A sample one\n Given this situation\n When I do something\n Then what I get is what I was expecting for\n DoSomething public SomeResults DoSomething(someInput) {\n var someResult = [Do your job with someInput];\n FakeAlwaysWorkingLog.TrackTheFactYouDidYourJob(); // Using a mock Log\n return someResults;\n}\n Log.DoSomething() Log [Do your job with someInput] [Do your job with someInput] Log DoSomething Log DoSomething() [Do your job with someInput] Log Log"
},
{
"answer_id": 18725056,
"author": "Paulo Merson",
"author_id": 317522,
"author_profile": "https://Stackoverflow.com/users/317522",
"pm_score": 1,
"selected": false,
"text": "org.junit.Assume"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10752",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/122/"
] |
10,793 |
<p>I'm dynamically loading user controls adding them to the Controls collection of the web form.</p>
<p>I'd like to hide user controls if they cause a unhandled exception while rendering.</p>
<p>So, I tried hooking to the Error event of each UserControl but it seems that this event never fires for the UserControls as it does for Page class. </p>
<p>Did some googling around and it doesn't seem promising. Any ideas here?</p>
|
[
{
"answer_id": 10797,
"author": "Michael Stum",
"author_id": 91,
"author_profile": "https://Stackoverflow.com/users/91",
"pm_score": 0,
"selected": false,
"text": "void Page_Load(object sender, System.EventArgs e)\n{\n throw(new ArgumentNullException());\n}\n\npublic void Page_Error(object sender,EventArgs e)\n{\n Exception objErr = Server.GetLastError().GetBaseException();\n string err = \"<b>Error Caught in Page_Error event</b><hr><br>\" + \n \"<br><b>Error in: </b>\" + Request.Url.ToString() +\n \"<br><b>Error Message: </b>\" + objErr.Message.ToString()+\n \"<br><b>Stack Trace:</b><br>\" + \n objErr.StackTrace.ToString();\n Response.Write(err.ToString());\n Server.ClearError();\n}\n"
},
{
"answer_id": 10916,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 1,
"selected": false,
"text": "public abstract class SilentErrorControl : UserControl\n{\n protected override void Render( HtmlTextWriter writer )\n {\n //call the base's render method, but with a try catch\n try { base.Render( writer ); }\n catch ( Exception ex ) { /*do nothing*/ }\n }\n}\n"
},
{
"answer_id": 12055,
"author": "Rob Cooper",
"author_id": 832,
"author_profile": "https://Stackoverflow.com/users/832",
"pm_score": 5,
"selected": true,
"text": "public class SafeLoader\n{\n public static string LoadControl(Control ctl)\n {\n // In terms of what we could do here, its down\n // to you, I will just return some basic HTML saying\n // I screwed up.\n try\n {\n // Get the Controls HTML (which may throw)\n // And store it in our own writer away from the\n // actual Live page.\n StringWriter writer = new StringWriter();\n HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);\n ctl.RenderControl(htmlWriter);\n\n return writer.GetStringBuilder().ToString();\n }\n catch (Exception)\n {\n string ctlType = ctl.GetType().Name;\n return \"<span style=\\\"color: red; font-weight:bold; font-size: smaller;\\\">\" + \n \"Rob + Controls = FAIL (\" + \n ctlType + \" rendering failed) Sad face :(</span>\";\n }\n }\n}\n public class BadControl : WebControl\n{\n protected override void Render(HtmlTextWriter writer)\n {\n throw new ApplicationException(\"Rob can't program controls\");\n }\n}\n public class GoodControl : WebControl\n{\n protected override void Render(HtmlTextWriter writer)\n {\n writer.Write(\"<b>Holy crap this control works</b>\");\n }\n}\n protected void Page_Load(object sender, EventArgs e)\n {\n // Create some controls (BadControl will throw)\n string goodHtml = SafeLoader.LoadControl(new BadControl());\n Response.Write(goodHtml);\n\n string badHtml = SafeLoader.LoadControl(new GoodControl());\n Response.Write(badHtml);\n }\n protected override void CreateChildControls()\n{\n // Pass each control through the Loader to check\n // its not lame\n foreach (Control ctl in Controls)\n {\n string s = SafeLoader.LoadControl(ctl);\n // If its bad, smack it downnnn!\n if (s == string.Empty)\n {\n ctl.Visible = false; // Prevent Rendering\n string ctlType = ctl.GetType().Name;\n Response.Write(\"<b>Problem Occurred Rendering \" + \n ctlType + \" '\" + ctl.ID + \"'.</b>\");\n }\n }\n}\n"
},
{
"answer_id": 10954250,
"author": "ThisGuy",
"author_id": 910348,
"author_profile": "https://Stackoverflow.com/users/910348",
"pm_score": 0,
"selected": false,
"text": " protected override void Render(System.Web.UI.HtmlTextWriter writer)\n {\n try\n {\n // Render the module to a local a temporary writer so that if an Exception occurs\n // the control is not halfway rendered - \"it is all or nothing\" proposition\n System.IO.StringWriter sw = new System.IO.StringWriter();\n System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);\n base.Render(htw);\n\n // We made it! Copy the Control Render over\n writer.Write(sw.GetStringBuilder().ToString());\n }\n catch (System.Exception ex)\n {\n string message = string.Format(\"Error Rendering Control {0}\\n\", ID);\n Log.Error(message, ex);\n if (Page.IsDebug)\n writer.Write(string.Format(\"{0}<br>Exception:<br><pre>{1}\\n{2}</pre>\", message, ex.Message, ex.StackTrace));\n }\n }\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10793",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1269/"
] |
10,808 |
<p>Ok, so I've been refactoring my code in my little Rails app in an effort to remove duplication, and in general make my life easier (as I like an easy life). Part of this refactoring, has been to move code that's common to two of my models to a module that I can include where I need it.</p>
<p>So far, so good. Looks like it's going to work out, but I've just hit a problem that I'm not sure how to get around. The module (which I've called sendable), is just going to be the code that handles faxing, e-mailing, or printing a PDF of the document. So, for example, I have a purchase order, and I have Internal Sales Orders (imaginatively abbreviated to ISO).</p>
<p>The problem I've struck, is that I want some variables initialised (initialized for people who don't spell correctly :P ) after the object is loaded, so I've been using the <strong>after_initialize</strong> hook. No problem... until I start adding some more mixins.</p>
<p>The problem I have, is that I can have an <strong><code>after_initialize</code></strong> in any one of my mixins, so I need to include a <strong>super</strong> call at the start to make sure the other mixin <strong><code>after_initialize</code></strong> calls get called. Which is great, until I end up calling super and I get an error because there is no super to call.</p>
<p>Here's a little example, in case I haven't been confusing enough:</p>
<pre><code>class Iso < ActiveRecord::Base
include Shared::TracksSerialNumberExtension
include Shared::OrderLines
extend Shared::Filtered
include Sendable::Model
validates_presence_of :customer
validates_associated :lines
owned_by :customer
order_lines :despatched # Mixin
tracks_serial_numbers :items # Mixin
sendable :customer # Mixin
attr_accessor :address
def initialize( params = nil )
super
self.created_at ||= Time.now.to_date
end
end
</code></pre>
<p>So, if each one of the mixins have an after_initialize call, with a <strong>super</strong> call, how can I stop that last <strong>super</strong> call from raising the error? How can I test that the super method exists before I call it?</p>
|
[
{
"answer_id": 11719,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": 0,
"selected": false,
"text": "class ActiveRecord::Base\n def after_initialize\n end\nend\n"
},
{
"answer_id": 11744,
"author": "newtonapple",
"author_id": 1376,
"author_profile": "https://Stackoverflow.com/users/1376",
"pm_score": 2,
"selected": false,
"text": "alias_method_chain after_initialize"
},
{
"answer_id": 11866,
"author": "James A. Rosen",
"author_id": 1190,
"author_profile": "https://Stackoverflow.com/users/1190",
"pm_score": 2,
"selected": false,
"text": "ActiveRecord::Base Iso after_initialize alias_method_chain alias_method_chain"
},
{
"answer_id": 905638,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "super if respond_to?('super')\n"
},
{
"answer_id": 3867490,
"author": "valo",
"author_id": 467285,
"author_profile": "https://Stackoverflow.com/users/467285",
"pm_score": 6,
"selected": true,
"text": "super if defined?(super)\n class A\nend\n\nclass B < A\n def t\n super if defined?(super)\n puts \"Hi from B\"\n end\nend\n\nB.new.t\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10808",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/841/"
] |
10,810 |
<p>I'm doing a authorization check from a WinForms application with the help of the AzMan authorization provider from Enterprise Library and am receiving the the following error:</p>
<blockquote>
<p>Unable to update the password. The value provided as the current password is incorrect. (Exception from HRESULT: 0x8007052B) (Microsoft.Practices.EnterpriseLibrary.Security.AzMan) </p>
<hr>
<p>Unable to update the password. The value provided as the current password is incorrect. (Exception from HRESULT: 0x8007052B) (Microsoft.Interop.Security.AzRoles) </p>
</blockquote>
<p>The AzMan store is hosted in ADAM on another computer in the same domain. Other computers and users do not have this problem. The user making the call has read access to both ADAM and the AzMan store. The computer running the WinForms app and the computer running ADAM are both on Windows XP SP2.</p>
<p>I've had access problems with AzMan before that I've resolved, but this is a new one... What am I missing?</p>
|
[
{
"answer_id": 11719,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": 0,
"selected": false,
"text": "class ActiveRecord::Base\n def after_initialize\n end\nend\n"
},
{
"answer_id": 11744,
"author": "newtonapple",
"author_id": 1376,
"author_profile": "https://Stackoverflow.com/users/1376",
"pm_score": 2,
"selected": false,
"text": "alias_method_chain after_initialize"
},
{
"answer_id": 11866,
"author": "James A. Rosen",
"author_id": 1190,
"author_profile": "https://Stackoverflow.com/users/1190",
"pm_score": 2,
"selected": false,
"text": "ActiveRecord::Base Iso after_initialize alias_method_chain alias_method_chain"
},
{
"answer_id": 905638,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "super if respond_to?('super')\n"
},
{
"answer_id": 3867490,
"author": "valo",
"author_id": 467285,
"author_profile": "https://Stackoverflow.com/users/467285",
"pm_score": 6,
"selected": true,
"text": "super if defined?(super)\n class A\nend\n\nclass B < A\n def t\n super if defined?(super)\n puts \"Hi from B\"\n end\nend\n\nB.new.t\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10810",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/966/"
] |
10,819 |
<p>For certain types of sql queries, an auxiliary table of numbers can be very useful. It may be created as a table with as many rows as you need for a particular task or as a user defined function that returns the number of rows required in each query.</p>
<p>What is the optimal way to create such a function?</p>
|
[
{
"answer_id": 1479258,
"author": "Chadwick",
"author_id": 80714,
"author_profile": "https://Stackoverflow.com/users/80714",
"pm_score": 3,
"selected": false,
"text": "WITH Nbrs ( n ) AS (\n SELECT 1 UNION ALL\n SELECT 1 + n FROM Nbrs WHERE n < 500 )\nSELECT n FROM Nbrs\nOPTION ( MAXRECURSION 500 )\n"
},
{
"answer_id": 2663232,
"author": "Jeff Moden",
"author_id": 313265,
"author_profile": "https://Stackoverflow.com/users/313265",
"pm_score": 8,
"selected": true,
"text": "--===== Test for 1000000 rows ==================================\nGO\n--===== Traditional RECURSIVE CTE method\n WITH Tally (N) AS \n ( \n SELECT 1 UNION ALL \n SELECT 1 + N FROM Tally WHERE N < 1000000 \n ) \n SELECT N \n INTO #Tally1 \n FROM Tally \n OPTION (MAXRECURSION 0);\nGO\n--===== Traditional WHILE LOOP method\n CREATE TABLE #Tally2 (N INT);\n SET NOCOUNT ON;\nDECLARE @Index INT;\n SET @Index = 1;\n WHILE @Index <= 1000000 \n BEGIN \n INSERT #Tally2 (N) \n VALUES (@Index);\n SET @Index = @Index + 1;\n END;\nGO\n--===== Traditional CROSS JOIN table method\n SELECT TOP (1000000)\n ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS N\n INTO #Tally3\n FROM Master.sys.All_Columns ac1\n CROSS JOIN Master.sys.ALL_Columns ac2;\nGO\n--===== Itzik's CROSS JOINED CTE method\n WITH E00(N) AS (SELECT 1 UNION ALL SELECT 1),\n E02(N) AS (SELECT 1 FROM E00 a, E00 b),\n E04(N) AS (SELECT 1 FROM E02 a, E02 b),\n E08(N) AS (SELECT 1 FROM E04 a, E04 b),\n E16(N) AS (SELECT 1 FROM E08 a, E08 b),\n E32(N) AS (SELECT 1 FROM E16 a, E16 b),\n cteTally(N) AS (SELECT ROW_NUMBER() OVER (ORDER BY N) FROM E32)\n SELECT N\n INTO #Tally4\n FROM cteTally\n WHERE N <= 1000000;\nGO\n--===== Housekeeping\n DROP TABLE #Tally1, #Tally2, #Tally3, #Tally4;\nGO\n SPID TextData Dur(ms) CPU Reads Writes\n---- ---------------------------------------- ------- ----- ------- ------\n 51 --===== Test for 100 rows ============== 8 0 0 0\n 51 --===== Traditional RECURSIVE CTE method 16 0 868 0\n 51 --===== Traditional WHILE LOOP method CR 73 16 175 2\n 51 --===== Traditional CROSS JOIN table met 11 0 80 0\n 51 --===== Itzik's CROSS JOINED CTE method 6 0 63 0\n 51 --===== Housekeeping DROP TABLE #Tally 35 31 401 0\n\n 51 --===== Test for 1000 rows ============= 0 0 0 0\n 51 --===== Traditional RECURSIVE CTE method 47 47 8074 0\n 51 --===== Traditional WHILE LOOP method CR 80 78 1085 0\n 51 --===== Traditional CROSS JOIN table met 5 0 98 0\n 51 --===== Itzik's CROSS JOINED CTE method 2 0 83 0\n 51 --===== Housekeeping DROP TABLE #Tally 6 15 426 0\n\n 51 --===== Test for 10000 rows ============ 0 0 0 0\n 51 --===== Traditional RECURSIVE CTE method 434 344 80230 10\n 51 --===== Traditional WHILE LOOP method CR 671 563 10240 9\n 51 --===== Traditional CROSS JOIN table met 25 31 302 15\n 51 --===== Itzik's CROSS JOINED CTE method 24 0 192 15\n 51 --===== Housekeeping DROP TABLE #Tally 7 15 531 0\n\n 51 --===== Test for 100000 rows =========== 0 0 0 0\n 51 --===== Traditional RECURSIVE CTE method 4143 3813 800260 154\n 51 --===== Traditional WHILE LOOP method CR 5820 5547 101380 161\n 51 --===== Traditional CROSS JOIN table met 160 140 479 211\n 51 --===== Itzik's CROSS JOINED CTE method 153 141 276 204\n 51 --===== Housekeeping DROP TABLE #Tally 10 15 761 0\n\n 51 --===== Test for 1000000 rows ========== 0 0 0 0\n 51 --===== Traditional RECURSIVE CTE method 41349 37437 8001048 1601\n 51 --===== Traditional WHILE LOOP method CR 59138 56141 1012785 1682\n 51 --===== Traditional CROSS JOIN table met 1224 1219 2429 2101\n 51 --===== Itzik's CROSS JOINED CTE method 1448 1328 1217 2095\n 51 --===== Housekeeping DROP TABLE #Tally 8 0 415 0\n"
},
{
"answer_id": 4745368,
"author": "Ruskin",
"author_id": 581414,
"author_profile": "https://Stackoverflow.com/users/581414",
"pm_score": 0,
"selected": false,
"text": "WITH \n E00 (N) AS ( \n SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL \n SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 ),\n E01 (N) AS (SELECT a.N FROM E00 a CROSS JOIN E00 b),\n E02 (N) AS (SELECT a.N FROM E01 a CROSS JOIN E01 b ),\n E03 (N) AS (SELECT a.N FROM E02 a CROSS JOIN E02 b \n LIMIT 11000 -- end record 11,000 good for 30 yrs dates\n ), -- max is 100,000,000, starts slowing e.g. 1 million 1.5 secs, 2 mil 2.5 secs, 3 mill 4 secs\n Tally (N) as (SELECT row_number() OVER (ORDER BY a.N) FROM E03 a)\n\nSELECT N\nFROM Tally\n"
},
{
"answer_id": 6571438,
"author": "Anthony Faull",
"author_id": 63264,
"author_profile": "https://Stackoverflow.com/users/63264",
"pm_score": 2,
"selected": false,
"text": "int CREATE VIEW dbo.Numbers\nWITH SCHEMABINDING\nAS\n WITH Int1(z) AS (SELECT 0 UNION ALL SELECT 0)\n , Int2(z) AS (SELECT 0 FROM Int1 a CROSS JOIN Int1 b)\n , Int4(z) AS (SELECT 0 FROM Int2 a CROSS JOIN Int2 b)\n , Int8(z) AS (SELECT 0 FROM Int4 a CROSS JOIN Int4 b)\n , Int16(z) AS (SELECT 0 FROM Int8 a CROSS JOIN Int8 b)\n , Int32(z) AS (SELECT TOP 2147483647 0 FROM Int16 a CROSS JOIN Int16 b)\n SELECT ROW_NUMBER() OVER (ORDER BY z) AS n\n FROM Int32\nGO\n"
},
{
"answer_id": 26505041,
"author": "HansLindgren",
"author_id": 1202332,
"author_profile": "https://Stackoverflow.com/users/1202332",
"pm_score": 0,
"selected": false,
"text": "--===== Hans CROSS JOINED CTE method\nWITH Numbers_CTE (Digit)\nAS\n(SELECT 0 UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9)\nSELECT HundredThousand.Digit * 100000 + TenThousand.Digit * 10000 + Thousand.Digit * 1000 + Hundred.Digit * 100 + Ten.Digit * 10 + One.Digit AS Number\nINTO #Tally5\nFROM Numbers_CTE AS One CROSS JOIN Numbers_CTE AS Ten CROSS JOIN Numbers_CTE AS Hundred CROSS JOIN Numbers_CTE AS Thousand CROSS JOIN Numbers_CTE AS TenThousand CROSS JOIN Numbers_CTE AS HundredThousand\n Microsoft SQL Server 2012 - 11.0.5058.0 (X64) \nMay 14 2014 18:34:29 \nCopyright (c) Microsoft Corporation\nEnterprise Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: )\n"
},
{
"answer_id": 36987175,
"author": "Lukasz Szozda",
"author_id": 5070879,
"author_profile": "https://Stackoverflow.com/users/5070879",
"pm_score": 1,
"selected": false,
"text": "SQL Server 2016+ OPENJSON -- range from 0 to @max - 1\nDECLARE @max INT = 40000;\n\nSELECT rn = CAST([key] AS INT) \nFROM OPENJSON(CONCAT('[1', REPLICATE(CAST(',1' AS VARCHAR(MAX)),@max-1),']'));\n LiveDemo"
},
{
"answer_id": 71426969,
"author": "Martin Smith",
"author_id": 73226,
"author_profile": "https://Stackoverflow.com/users/73226",
"pm_score": 2,
"selected": false,
"text": "SELECT Value\nFROM GENERATE_SERIES(START = 1, STOP = 100, STEP=1)\n DECLARE @Value INT \n\nSELECT @Value =[value]\nFROM GENERATE_SERIES(START=1, STOP=10000000)\n CREATE TABLE dbo.NumberHeap(Number INT);\n\nINSERT INTO dbo.Numbers\nSELECT [value]\nFROM GENERATE_SERIES(START=1, STOP=10);\n SELECT [value]\nFROM GENERATE_SERIES(START=1, STOP=10)\nORDER BY [value] \n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/224/"
] |
10,822 |
<p>What would be a very fast way to determine if your connectionstring lets you connect to a database?</p>
<p>Normally a connection attempt keeps the user waiting a long time before notifying the attempt was futile anyway.</p>
|
[
{
"answer_id": 10824,
"author": "GateKiller",
"author_id": 383,
"author_profile": "https://Stackoverflow.com/users/383",
"pm_score": 5,
"selected": true,
"text": "server=<server>;database=<database>;uid=<user>;password=<password>;Connect Timeout=3\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1271/"
] |
10,825 |
<p>In SQL Server I have a <code>DATETIME</code> column which includes a time element.</p>
<p>Example: </p>
<pre><code>'14 AUG 2008 14:23:019'
</code></pre>
<p>What is the <strong>best</strong> method to only select the records for a particular day, ignoring the time part?</p>
<p>Example: (Not safe, as it does not match the time part and returns no rows)</p>
<pre><code>DECLARE @p_date DATETIME
SET @p_date = CONVERT( DATETIME, '14 AUG 2008', 106 )
SELECT *
FROM table1
WHERE column_datetime = @p_date
</code></pre>
<p><em>Note: Given this site is also about jotting down notes and techniques you pick up and then forget, I'm going to post my own answer to this question as DATETIME stuff in MSSQL is probably the topic I lookup most in SQLBOL.</em></p>
<hr>
<p><strong>Update</strong> Clarified example to be more specific.</p>
<hr>
<p><strong>Edit</strong> Sorry, But I've had to down-mod WRONG answers (answers that return wrong results).</p>
<p>@Jorrit: <code>WHERE (date>'20080813' AND date<'20080815')</code> will return the 13th and the 14th.</p>
<p>@wearejimbo: <em>Close, but no cigar!</em> badge awarded to you. You missed out records written at 14/08/2008 23:59:001 to 23:59:999 (i.e. Less than 1 second before midnight.)</p>
|
[
{
"answer_id": 10826,
"author": "Guy",
"author_id": 993,
"author_profile": "https://Stackoverflow.com/users/993",
"pm_score": 6,
"selected": true,
"text": " DECLARE @p_date DATETIME\n SET @p_date = CONVERT( DATETIME, '14 AUG 2008', 106 )\n\n SELECT *\n FROM table1\n WHERE column_datetime >= @p_date\n AND column_datetime < DATEADD(d, 1, @p_date)\n"
},
{
"answer_id": 10828,
"author": "Lars Mæhlum",
"author_id": 960,
"author_profile": "https://Stackoverflow.com/users/960",
"pm_score": 1,
"selected": false,
"text": "SELECT *\nFROM table1\nWHERE CONVERT(varchar(10),columnDatetime,121) = \n CONVERT(varchar(10),CONVERT('14 AUG 2008' ,smalldatetime),121)\n"
},
{
"answer_id": 10830,
"author": "Guy",
"author_id": 993,
"author_profile": "https://Stackoverflow.com/users/993",
"pm_score": 2,
"selected": false,
"text": "DECLARE @p_date DATETIME\nSET @p_date = CONVERT( DATETIME, '14 AUG 2008', 106 )\n\nSELECT *\nFROM table1\nWHERE DATEDIFF( d, column_datetime, @p_date ) = 0\n"
},
{
"answer_id": 10832,
"author": "Yaakov Ellis",
"author_id": 51,
"author_profile": "https://Stackoverflow.com/users/51",
"pm_score": 3,
"selected": false,
"text": "Declare @DateToSearch DateTime\nSet @DateToSearch = '14 AUG 2008'\n\nSELECT * \nFROM table1\nWHERE Year(column_datetime) = Year(@DateToSearch)\n AND Month(column_datetime) = Month(@DateToSearch)\n AND Day(column_datetime) = Day(@DateToSearch)\n"
},
{
"answer_id": 10833,
"author": "GateKiller",
"author_id": 383,
"author_profile": "https://Stackoverflow.com/users/383",
"pm_score": 2,
"selected": false,
"text": "Select\n*\nTable1\nWhere\nCast(Floor(Cast(Column_DateTime As Float)) As DateTime) = '14-AUG-2008'\n DECLARE @p_date DATETIME\nSET @p_date = Cast('14 AUG 2008' as DateTime)\n\nSELECT *\nFROM table1\nWHERE Cast(Floor(Cast(column_datetime As Float)) As DateTime) = @p_date\n"
},
{
"answer_id": 10834,
"author": "Jon Limjap",
"author_id": 372,
"author_profile": "https://Stackoverflow.com/users/372",
"pm_score": 1,
"selected": false,
"text": "SELECT *\nFROM (SELECT *, DATEPART(yy, column_dateTime) as Year, \n DATEPART(mm, column_dateTime) as Month, \n DATEPART(dd, column_dateTime) as Day \n FROM table1)\nWHERE Year = '2008'\nAND Month = '8'\nAND Day = '14'\n"
},
{
"answer_id": 10835,
"author": "ila",
"author_id": 1178,
"author_profile": "https://Stackoverflow.com/users/1178",
"pm_score": 2,
"selected": false,
"text": "SELECT *\nFROM table1\nWHERE convert(varchar, column_datetime, 111) = '2008/08/14'\n"
},
{
"answer_id": 10844,
"author": "vzczc",
"author_id": 224,
"author_profile": "https://Stackoverflow.com/users/224",
"pm_score": 4,
"selected": false,
"text": "DECLARE @pDate DATE='2008-08-14' \n\nSELECT colA, colB\nFROM table1\nWHERE convert(date, colDateTime) = @pDate \n"
},
{
"answer_id": 14581,
"author": "Guy",
"author_id": 993,
"author_profile": "https://Stackoverflow.com/users/993",
"pm_score": 2,
"selected": false,
"text": "DATEADD(dd, DATEDIFF( dd, 0, @DAY ), 0)\n DATEADD(dd, DATEDIFF( dd, -1, GetDate() - DAY(GetDate()) ), 0)\n DATEADD(m,-12,DATEADD(dd, DATEDIFF( dd, -1, GetDate() - DAY(GetDate()) ), 0))\n"
},
{
"answer_id": 2271064,
"author": "Jai",
"author_id": 274113,
"author_profile": "https://Stackoverflow.com/users/274113",
"pm_score": 0,
"selected": false,
"text": "SELECT CONVERT(VARCHAR(2),DATEPART(\"dd\",doj)) + \n '/' + CONVERT(VARCHAR(2),DATEPART(\"mm\",doj)) + \n '/' + CONVERT(VARCHAR(4),DATEPART(\"yy\",doj)) FROM emp\n"
},
{
"answer_id": 2271172,
"author": "Jai",
"author_id": 274113,
"author_profile": "https://Stackoverflow.com/users/274113",
"pm_score": 1,
"selected": false,
"text": "DECLARE @Dat\n\nSELECT * \nFROM Jai\nWHERE \nCONVERT(VARCHAR(2),DATEPART(\"dd\",Date)) +'/'+ \n CONVERT(VARCHAR(2),DATEPART(\"mm\",Date)) +'/'+ \n CONVERT(VARCHAR(4), DATEPART(\"yy\",Date)) = @Dat\n"
},
{
"answer_id": 2271336,
"author": "van",
"author_id": 99594,
"author_profile": "https://Stackoverflow.com/users/99594",
"pm_score": 2,
"selected": false,
"text": "DATE DATE ranges DATE ALTER TABLE \"table1\" \n ADD \"column_date\" AS CONVERT(DATE, \"column_datetime\") PERSISTED\n CREATE NONCLUSTERED INDEX \"table1_column_date_nu_nci\"\nON \"table1\" ( \"column_date\" ASC )\nGO\n DECLARE @p_date DATE\nSET @p_date = CONVERT( DATE, '14 AUG 2008', 106 )\n\nSELECT *\nFROM table1\nWHERE column_date = @p_date\n"
},
{
"answer_id": 2570952,
"author": "javad",
"author_id": 308248,
"author_profile": "https://Stackoverflow.com/users/308248",
"pm_score": -1,
"selected": false,
"text": "DECLARE @p_date DATE\n\nSELECT * \nFROM table1\nWHERE column_dateTime=@p_date\n"
},
{
"answer_id": 4373895,
"author": "Naresh Goradara",
"author_id": 284313,
"author_profile": "https://Stackoverflow.com/users/284313",
"pm_score": 1,
"selected": false,
"text": "DECLARE @strDate VARCHAR(15)\nSET @strDate ='07-12-2010'\n\n\nSELECT * FROM table\nWHERE CONVERT(VARCHAR(15),dtInvoice, 112)>= CONVERT(VARCHAR(15),@strDate , 112)\n"
},
{
"answer_id": 9061984,
"author": "Michael Gasa",
"author_id": 1177766,
"author_profile": "https://Stackoverflow.com/users/1177766",
"pm_score": 0,
"selected": false,
"text": "SELECT * FROM tablename\nWHERE CAST(FLOOR(CAST(column_datetime AS FLOAT))AS DATETIME) = '30 jan 2012'\n"
},
{
"answer_id": 9439193,
"author": "Jaider",
"author_id": 480700,
"author_profile": "https://Stackoverflow.com/users/480700",
"pm_score": 2,
"selected": false,
"text": "SELECT 'Same Date' WHERE CAST(getDate() as date) = cast('2/24/2012 2:23 PM' as date)\n SELECT 'Same Date' WHERE DATEDIFF(dd, cast(getDate() as date), cast('2/24/2012 2:23 PM' as date)) = 0\n"
},
{
"answer_id": 30414576,
"author": "user4932286",
"author_id": 4932286,
"author_profile": "https://Stackoverflow.com/users/4932286",
"pm_score": 0,
"selected": false,
"text": "SELECT * \nFROM table1\nWHERE DATE(column_datetime) = @p_date;\n"
},
{
"answer_id": 35849283,
"author": "Arun",
"author_id": 6030147,
"author_profile": "https://Stackoverflow.com/users/6030147",
"pm_score": 0,
"selected": false,
"text": "SELECT * FROM tablename where CONVERT(datetime,columnname,103) \n between '2016-03-01' and '2016-03-03'\n In CONVERT(DATETIME,COLUMNNAME,103) \"103\" SPECIFIES THE DATE FORMAT as dd/mm/yyyy\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10825",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/993/"
] |
10,848 |
<p>Does anybody know if it's possible, and how, to programmatically send a <strong>SMS</strong> from the <code>iPhone</code>, with the official SDK / Cocoa Touch?</p>
|
[
{
"answer_id": 59159,
"author": "millenomi",
"author_id": 6061,
"author_profile": "https://Stackoverflow.com/users/6061",
"pm_score": 6,
"selected": false,
"text": "sms:[target phone number]"
},
{
"answer_id": 59200,
"author": "Adam Davis",
"author_id": 2915,
"author_profile": "https://Stackoverflow.com/users/2915",
"pm_score": 9,
"selected": false,
"text": "viewController"
},
{
"answer_id": 2159464,
"author": "new soul",
"author_id": 239368,
"author_profile": "https://Stackoverflow.com/users/239368",
"pm_score": 2,
"selected": false,
"text": "CoreTelephony CTMessageCenter"
},
{
"answer_id": 3326464,
"author": "Daniel Amitay",
"author_id": 314042,
"author_profile": "https://Stackoverflow.com/users/314042",
"pm_score": 7,
"selected": false,
"text": "MFMessageComposeViewController MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];\nif([MFMessageComposeViewController canSendText])\n{\n controller.body = @\"SMS message here\";\n controller.recipients = [NSArray arrayWithObjects:@\"1(234)567-8910\", nil];\n controller.messageComposeDelegate = self;\n [self presentModalViewController:controller animated:YES];\n}\n"
},
{
"answer_id": 8419150,
"author": "Najeebullah Shah",
"author_id": 1032321,
"author_profile": "https://Stackoverflow.com/users/1032321",
"pm_score": 7,
"selected": false,
"text": "#import <MessageUI/MessageUI.h> MFMessageComposeViewControllerDelegate UINavigationControllerDelegate IBAction MFMessageComposeViewController messageInstance [MFMessageComposeViewController canSendText] if messageInstance messageInstance.body = @\"Hello from Shah\";\n messageInstance.recipients = [NSArray arrayWithObjects:@\"12345678\", @\"87654321\", nil];\n messageInstance.messageComposeDelegate = self;\n [self presentModalViewController:messageInstance animated:YES];\n"
},
{
"answer_id": 10647336,
"author": "Rock",
"author_id": 1136908,
"author_profile": "https://Stackoverflow.com/users/1136908",
"pm_score": 1,
"selected": false,
"text": "- (void)showSMSPicker\n{\n Class messageClass = (NSClassFromString(@\"MFMessageComposeViewController\"));\n\n if (messageClass != nil) { \n // Check whether the current device is configured for sending SMS messages\n if ([messageClass canSendText]) {\n [self displaySMSComposerSheet];\n } \n }\n}\n\n- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result\n{ \n //feedbackMsg.hidden = NO;\n // Notifies users about errors associated with the interface\n switch (result)\n {\n case MessageComposeResultCancelled:\n { \n UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@\"Message\" message:@\"SMS sending canceled!!!\" delegate:self cancelButtonTitle:nil otherButtonTitles:@\"OK\", nil];\n [alert1 show];\n [alert1 release];\n } \n\n // feedbackMsg.text = @\"Result: SMS sending canceled\";\n break;\n\n case MessageComposeResultSent:\n {\n UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@\"Message\" message:@\"SMS sent!!!\" delegate:self cancelButtonTitle:nil otherButtonTitles:@\"OK\", nil];\n [alert2 show];\n [alert2 release];\n } \n\n // feedbackMsg.text = @\"Result: SMS sent\";\n break;\n\n case MessageComposeResultFailed:\n { \n UIAlertView *alert3 = [[UIAlertView alloc] initWithTitle:@\"Message\" message:@\"SMS sending failed!!!\" delegate:self cancelButtonTitle:nil otherButtonTitles:@\"OK\", nil];\n [alert3 show];\n [alert3 release];\n } \n\n // feedbackMsg.text = @\"Result: SMS sending failed\";\n break;\n\n default:\n { \n UIAlertView *alert4 = [[UIAlertView alloc] initWithTitle:@\"Message\" message:@\"SMS not sent!!!\" delegate:self cancelButtonTitle:nil otherButtonTitles:@\"OK\", nil];\n [alert4 show];\n [alert4 release];\n } \n\n // feedbackMsg.text = @\"Result: SMS not sent\";\n break;\n }\n\n [self dismissModalViewControllerAnimated: YES];\n}\n"
},
{
"answer_id": 12142065,
"author": "Rushabh",
"author_id": 951996,
"author_profile": "https://Stackoverflow.com/users/951996",
"pm_score": 4,
"selected": false,
"text": "//Add the Framework in .h file\n\n#import <MessageUI/MessageUI.h>\n#import <MessageUI/MFMailComposeViewController.h>\n\n//Set the delegate methods\n\nUIViewController<UINavigationControllerDelegate,MFMessageComposeViewControllerDelegate>\n\n//add the below code in .m file\n\n\n- (void)viewDidAppear:(BOOL)animated{\n [super viewDidAppear:animated];\n\n MFMessageComposeViewController *controller = \n [[[MFMessageComposeViewController alloc] init] autorelease];\n\n if([MFMessageComposeViewController canSendText])\n { \n NSString *str= @\"Hello\";\n controller.body = str;\n controller.recipients = [NSArray arrayWithObjects:\n @\"\", nil];\n controller.delegate = self;\n [self presentModalViewController:controller animated:YES]; \n }\n\n\n}\n\n- (void)messageComposeViewController:\n(MFMessageComposeViewController *)controller\n didFinishWithResult:(MessageComposeResult)result \n{\n switch (result)\n {\n case MessageComposeResultCancelled: \n NSLog(@\"Cancelled\"); \n break; \n case MessageComposeResultFailed:\n NSLog(@\"Failed\");\n break; \n case MessageComposeResultSent: \n break; \n default: \n break; \n } \n [self dismissModalViewControllerAnimated:YES]; \n}\n"
},
{
"answer_id": 13063499,
"author": "isox",
"author_id": 1722481,
"author_profile": "https://Stackoverflow.com/users/1722481",
"pm_score": 5,
"selected": false,
"text": "xpc_connection_t myConnection;\n\ndispatch_queue_t queue = dispatch_queue_create(\"com.apple.chatkit.clientcomposeserver.xpc\", DISPATCH_QUEUE_CONCURRENT);\n\nmyConnection = xpc_connection_create_mach_service(\"com.apple.chatkit.clientcomposeserver.xpc\", queue, XPC_CONNECTION_MACH_SERVICE_PRIVILEGED);\n xpc_connection_set_event_handler(myConnection, ^(xpc_object_t event){\nxpc_type_t xtype = xpc_get_type(event);\nif(XPC_TYPE_ERROR == xtype)\n{\nNSLog(@\"XPC sandbox connection error: %s\\n\", xpc_dictionary_get_string(event, XPC_ERROR_KEY_DESCRIPTION));\n}\n// Always set an event handler. More on this later.\n\nNSLog(@\"Received a message event!\");\n\n});\n\nxpc_connection_resume(myConnection);\n NSArray *recipient = [NSArray arrayWithObjects:@\"+7 (90*) 000-00-00\", nil];\n\nNSData *ser_rec = [NSPropertyListSerialization dataWithPropertyList:recipient format:200 options:0 error:NULL];\n\nxpc_object_t mydict = xpc_dictionary_create(0, 0, 0);\nxpc_dictionary_set_int64(mydict, \"message-type\", 0);\nxpc_dictionary_set_data(mydict, \"recipients\", [ser_rec bytes], [ser_rec length]);\nxpc_dictionary_set_string(mydict, \"text\", \"hello from your application!\");\n xpc_connection_send_message(myConnection, mydict);\nxpc_connection_send_barrier(myConnection, ^{\nNSLog(@\"The message has been successfully delivered\");\n});\n"
},
{
"answer_id": 16491171,
"author": "Bharat Gulati",
"author_id": 781067,
"author_profile": "https://Stackoverflow.com/users/781067",
"pm_score": 5,
"selected": false,
"text": "#import <MessageUI/MessageUI.h> \n if ([MFMessageComposeViewController canSendText]) {\n MFMessageComposeViewController *messageComposer =\n [[MFMessageComposeViewController alloc] init];\n NSString *message = @\"Your Message here\";\n [messageComposer setBody:message];\n messageComposer.messageComposeDelegate = self;\n [self presentViewController:messageComposer animated:YES completion:nil];\n}\n - (void)messageComposeViewController:(MFMessageComposeViewController *)controller\n didFinishWithResult:(MessageComposeResult)result {\n [self dismissViewControllerAnimated:YES completion:nil];\n }\n"
},
{
"answer_id": 18697017,
"author": "mandeep",
"author_id": 2454925,
"author_profile": "https://Stackoverflow.com/users/2454925",
"pm_score": 2,
"selected": false,
"text": "- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients\n{\n UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];\n UIImage *ui =resultimg.image;\n pasteboard.image = ui;\n [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@\"sms:\"]];\n}\n"
},
{
"answer_id": 22034318,
"author": "Dinesh Reddy Chennuru",
"author_id": 2882811,
"author_profile": "https://Stackoverflow.com/users/2882811",
"pm_score": 4,
"selected": false,
"text": "[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@\"sms:MobileNumber\"]]\n"
},
{
"answer_id": 25013218,
"author": "Tunvir Rahman Tusher",
"author_id": 1918966,
"author_profile": "https://Stackoverflow.com/users/1918966",
"pm_score": 4,
"selected": false,
"text": "MessageUI.Framework #import <MessageUI/MessageUI.h> if ([MFMessageComposeViewController canSendText]) {\n MFMessageComposeViewController *messageComposer =\n [[MFMessageComposeViewController alloc] init];\n NSString *message = @\"Message!!!\";\n [messageComposer setBody:message];\n messageComposer.messageComposeDelegate = self;\n [self presentViewController:messageComposer animated:YES completion:nil];\n}\n delegate - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{\n\n\n ///your stuff here \n\n [self dismissViewControllerAnimated:YES completion:nil];\n}\n"
},
{
"answer_id": 25118840,
"author": "Rinku Sadhwani",
"author_id": 1037317,
"author_profile": "https://Stackoverflow.com/users/1037317",
"pm_score": 1,
"selected": false,
"text": "[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@\"sms:number\"]] \n"
},
{
"answer_id": 28964163,
"author": "ALOK KUMAR",
"author_id": 4628096,
"author_profile": "https://Stackoverflow.com/users/4628096",
"pm_score": 2,
"selected": false,
"text": "-(void)openMessageViewWithName:(NSString*)contactName withPhone:(NSString *)phone{\n\nCTTelephonyNetworkInfo *networkInfo=[[CTTelephonyNetworkInfo alloc]init];\n\nCTCarrier *carrier=networkInfo.subscriberCellularProvider;\n\nNSString *Countrycode = carrier.isoCountryCode;\n\nif ([Countrycode length]>0) //Check If Sim Inserted\n{\n\n [self sendSMS:msg recipientList:[NSMutableArray arrayWithObject:phone]];\n}\nelse\n{\n\n [AlertHelper showAlert:@\"Message\" withMessage:@\"No sim card inserted\"];\n}\n - (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSMutableArray *)recipients{ \n MFMessageComposeViewController *controller1 = [[MFMessageComposeViewController alloc] init] ;\n controller1 = [[MFMessageComposeViewController alloc] init] ;\n if([MFMessageComposeViewController canSendText])\n{\n controller1.body = bodyOfMessage;\n controller1.recipients = recipients;\n controller1.messageComposeDelegate = self;\n [self presentViewController:controller1 animated:YES completion:Nil];\n }\n}\n"
},
{
"answer_id": 30410240,
"author": "thomasdao",
"author_id": 1468878,
"author_profile": "https://Stackoverflow.com/users/1468878",
"pm_score": 3,
"selected": false,
"text": "import Foundation\nimport MessageUI\n\nclass MessageComposer: NSObject, MFMessageComposeViewControllerDelegate {\n // A wrapper function to indicate whether or not a text message can be sent from the user's device\n func canSendText() -> Bool {\n return MFMessageComposeViewController.canSendText()\n }\n\n // Configures and returns a MFMessageComposeViewController instance\n func configuredMessageComposeViewController(textMessageRecipients:[String] ,textBody body:String) -> MFMessageComposeViewController {\n let messageComposeVC = MFMessageComposeViewController()\n messageComposeVC.messageComposeDelegate = self // Make sure to set this property to self, so that the controller can be dismissed!\n messageComposeVC.recipients = textMessageRecipients\n messageComposeVC.body = body\n return messageComposeVC\n }\n\n // MFMessageComposeViewControllerDelegate callback - dismisses the view controller when the user is finished with it\n func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) {\n controller.dismissViewControllerAnimated(true, completion: nil)\n }\n}\n func openMessageComposerHelper(sender:AnyObject ,withIndexPath indexPath: NSIndexPath) {\n var recipients = [String]()\n\n //modify your recipients here\n\n if (messageComposer.canSendText()) {\n println(\"can send text\")\n // Obtain a configured MFMessageComposeViewController\n let body = Utility.createInvitationMessageText()\n\n let messageComposeVC = messageComposer.configuredMessageComposeViewController(recipients, textBody: body)\n\n // Present the configured MFMessageComposeViewController instance\n // Note that the dismissal of the VC will be handled by the messageComposer instance,\n // since it implements the appropriate delegate call-back\n presentViewController(messageComposeVC, animated: true, completion: nil)\n } else {\n // Let the user know if his/her device isn't able to send text messages\n self.displayAlerViewWithTitle(\"Cannot Send Text Message\", andMessage: \"Your device is not able to send text messages.\")\n }\n}\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10848",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
10,855 |
<p>I'm trying to perform a LINQ query on a DataTable object and bizarrely I am finding that performing such queries on DataTables is not straightforward. For example:</p>
<pre><code>var results = from myRow in myDataTable
where results.Field("RowNo") == 1
select results;
</code></pre>
<p>This is not allowed. How do I get something like this working?</p>
<p>I'm amazed that LINQ queries are not allowed on DataTables!</p>
|
[
{
"answer_id": 10857,
"author": "David Wengier",
"author_id": 489,
"author_profile": "https://Stackoverflow.com/users/489",
"pm_score": 4,
"selected": false,
"text": "var results = from myRow in myDataTable.Rows where myRow.Field(\"RowNo\") == 1 select myRow;\n"
},
{
"answer_id": 10893,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 6,
"selected": false,
"text": "using System.Data; //needed for the extension methods to work\n\n...\n\nvar results = \n from myRow in myDataTable.Rows \n where myRow.Field<int>(\"RowNo\") == 1 \n select myRow; //select the thing you want, not the collection\n System.Data.DataSetExtensions"
},
{
"answer_id": 11593,
"author": "Collin K",
"author_id": 1369,
"author_profile": "https://Stackoverflow.com/users/1369",
"pm_score": 11,
"selected": true,
"text": "DataTable DataRowCollection IEnumerable<T> AsEnumerable() DataTable var results = from myRow in myDataTable.AsEnumerable()\nwhere myRow.Field<int>(\"RowNo\") == 1\nselect myRow;\n AsEnumerable() IEnumerable<DataRow> IEnumerable<DataRow> DataTable CopyToDataTable() var result = myDataTable\n .AsEnumerable()\n .Where(myRow => myRow.Field<int>(\"RowNo\") == 1);\n"
},
{
"answer_id": 613431,
"author": "JoelFan",
"author_id": 16012,
"author_profile": "https://Stackoverflow.com/users/16012",
"pm_score": 7,
"selected": false,
"text": "var results = from DataRow myRow in myDataTable.Rows\n where (int)myRow[\"RowNo\"] == 1\n select myRow\n"
},
{
"answer_id": 2890640,
"author": "Ravi",
"author_id": 348127,
"author_profile": "https://Stackoverflow.com/users/348127",
"pm_score": 5,
"selected": false,
"text": "var query = from p in dt.AsEnumerable()\n where p.Field<string>(\"code\") == this.txtCat.Text\n select new\n {\n name = p.Field<string>(\"name\"),\n age= p.Field<int>(\"age\") \n };\n"
},
{
"answer_id": 6678063,
"author": "Salim",
"author_id": 842567,
"author_profile": "https://Stackoverflow.com/users/842567",
"pm_score": 5,
"selected": false,
"text": "var results = from myRow in tblCurrentStock.AsEnumerable()\n where myRow.Field<string>(\"item_name\").ToUpper().StartsWith(tbSearchItem.Text.ToUpper())\n select myRow;\nDataView view = results.AsDataView();\n"
},
{
"answer_id": 8739712,
"author": "sushil pandey",
"author_id": 843294,
"author_profile": "https://Stackoverflow.com/users/843294",
"pm_score": 5,
"selected": false,
"text": "//Create DataTable \nDataTable dt= new DataTable();\ndt.Columns.AddRange(new DataColumn[]\n{\n new DataColumn(\"ID\",typeof(System.Int32)),\n new DataColumn(\"Name\",typeof(System.String))\n\n});\n\n//Fill with data\n\ndt.Rows.Add(new Object[]{1,\"Test1\"});\ndt.Rows.Add(new Object[]{2,\"Test2\"});\n\n//Now Query DataTable with linq\n//To work with linq it should required our source implement IEnumerable interface.\n//But DataTable not Implement IEnumerable interface\n//So we call DataTable Extension method i.e AsEnumerable() this will return EnumerableRowCollection<DataRow>\n\n\n// Now Query DataTable to find Row whoes ID=1\n\nDataRow drow = dt.AsEnumerable().Where(p=>p.Field<Int32>(0)==1).FirstOrDefault();\n // \n"
},
{
"answer_id": 10648288,
"author": "midhun sankar",
"author_id": 1402739,
"author_profile": "https://Stackoverflow.com/users/1402739",
"pm_score": 4,
"selected": false,
"text": "var row = (from result in dt.AsEnumerable().OrderBy( result => Guid.NewGuid()) select result).Take(3) ; \n"
},
{
"answer_id": 12938526,
"author": "Abdul Saboor",
"author_id": 1176903,
"author_profile": "https://Stackoverflow.com/users/1176903",
"pm_score": 3,
"selected": false,
"text": "Dim results = From myRow In myDataTable \nWhere myRow.Field(Of Int32)(\"RowNo\") = 1 Select myRow\n"
},
{
"answer_id": 16198286,
"author": "xadriel",
"author_id": 618083,
"author_profile": "https://Stackoverflow.com/users/618083",
"pm_score": 4,
"selected": false,
"text": "var result = from myRow in myDataTable.Rows.OfType<CustomSet.CustomTableRow>()\n where myRow.RowNo == 1\n select myRow;\n var result = myDataTable.Rows.OfType<CustomSet.CustomTableRow>().Where(myRow => myRow.RowNo);\n"
},
{
"answer_id": 19756035,
"author": "AuthorProxy",
"author_id": 1763061,
"author_profile": "https://Stackoverflow.com/users/1763061",
"pm_score": 3,
"selected": false,
"text": "from prod in TenMostExpensiveProducts().Tables[0].AsEnumerable()\nwhere prod.Field<decimal>(\"UnitPrice\") > 62.500M\nselect prod\n TenMostExpensiveProducts().AsDynamic().Where (x => x.UnitPrice > 62.500M)\n System.Data.DataSetExtensions.dll"
},
{
"answer_id": 21497646,
"author": "Vinay",
"author_id": 2074385,
"author_profile": "https://Stackoverflow.com/users/2074385",
"pm_score": 3,
"selected": false,
"text": "var results = from myRow in myDataTable\nwhere results.Field<Int32>(\"RowNo\") == 1\nselect results;\n"
},
{
"answer_id": 22985291,
"author": "Uthaiah",
"author_id": 1488323,
"author_profile": "https://Stackoverflow.com/users/1488323",
"pm_score": 3,
"selected": false,
"text": "SqlCommand cmd = new SqlCommand( \"Select * from Employee\",con);\nSqlDataReader dr = cmd.ExecuteReader( );\nDataTable dt = new DataTable( \"Employee\" );\ndt.Load( dr );\nvar Data = dt.AsEnumerable( );\nvar names = from emp in Data select emp.Field<String>( dt.Columns[1] );\nforeach( var name in names )\n{\n Console.WriteLine( name );\n}\n"
},
{
"answer_id": 26367127,
"author": "LandedGently",
"author_id": 103965,
"author_profile": "https://Stackoverflow.com/users/103965",
"pm_score": 3,
"selected": false,
"text": "// Serialize the DataTable to a json string\nstring serializedTable = JsonConvert.SerializeObject(myDataTable); \nJarray dataRows = Jarray.Parse(serializedTable);\n\n// Run the LINQ query\nList<JToken> results = (from row in dataRows\n where (int) row[\"ans_key\"] == 42\n select row).ToList();\n\n// If you need the results to be in a DataTable\nstring jsonResults = JsonConvert.SerializeObject(results);\nDataTable resultsTable = JsonConvert.DeserializeObject<DataTable>(jsonResults);\n"
},
{
"answer_id": 29133713,
"author": "Matt Kemp",
"author_id": 631277,
"author_profile": "https://Stackoverflow.com/users/631277",
"pm_score": 4,
"selected": false,
"text": "var results = myDataTable.Select(\"\").FirstOrDefault(x => (int)x[\"RowNo\"] == 1)\n if(results != null) \n var foo = results[\"ColName\"].ToString()\n"
},
{
"answer_id": 31803241,
"author": "Iman",
"author_id": 184572,
"author_profile": "https://Stackoverflow.com/users/184572",
"pm_score": 3,
"selected": false,
"text": "IEnumerable<string> result = from myRow in dataTableResult.AsEnumerable()\n select myRow[\"server\"].ToString() ;\n"
},
{
"answer_id": 35164023,
"author": "vandsh",
"author_id": 2242217,
"author_profile": "https://Stackoverflow.com/users/2242217",
"pm_score": 6,
"selected": false,
"text": ".Cast<T>() .AsEnumerable() var results = from myRow in myDataTable.Rows.Cast<DataRow>() \n where myRow.Field<int>(\"RowNo\") == 1 select myRow;\n var results = myDataTable.Rows.Cast<DataRow>()\n .FirstOrDefault(x => x.Field<int>(\"RowNo\") == 1);\n System.Data.DataSetExtensions"
},
{
"answer_id": 36422555,
"author": "Mohit Verma",
"author_id": 6049604,
"author_profile": "https://Stackoverflow.com/users/6049604",
"pm_score": 5,
"selected": false,
"text": "var result=myDataTable.AsEnumerable().Where(myRow => myRow.Field<int>(\"RowNo\") == 1);\n"
},
{
"answer_id": 46937157,
"author": "Ryan Gavin",
"author_id": 6294612,
"author_profile": "https://Stackoverflow.com/users/6294612",
"pm_score": 3,
"selected": false,
"text": "DataSet dataSet = new DataSet(); //Create a dataset\ndataSet = _DataEntryDataLayer.ReadResults(); //Call to the dataLayer to return the data\n\n//LINQ query on a DataTable\nvar dataList = dataSet.Tables[\"DataTable\"]\n .AsEnumerable()\n .Select(i => new\n {\n ID = i[\"ID\"],\n Name = i[\"Name\"]\n }).ToList();\n"
},
{
"answer_id": 48572211,
"author": "Gabriel Martinez Bustos",
"author_id": 6328328,
"author_profile": "https://Stackoverflow.com/users/6328328",
"pm_score": 3,
"selected": false,
"text": "List<MyClass> result = myDataTable.AsEnumerable().Select(x=> new MyClass(){\n Property1 = (string)x.Field<string>(\"ColumnName1\"),\n Property2 = (int)x.Field<int>(\"ColumnName2\"),\n Property3 = (bool)x.Field<bool>(\"ColumnName3\"), \n});\n"
},
{
"answer_id": 57558642,
"author": "Alan",
"author_id": 10656609,
"author_profile": "https://Stackoverflow.com/users/10656609",
"pm_score": 0,
"selected": false,
"text": "DataView view = new DataView(myDataTable); \nview.RowFilter = \"RowNo = 1\";\nDataTable results = view.ToTable(true);\n SELECT *\nFROM myDataTable\nWHERE RowNo = 1\n FROM myDataTable\nWHERE RowNo = 1\nSELECT *\n DataView view = new DataView(myDataTable); //FROM myDataTable\nview.RowFilter = \"RowNo = 1\"; //WHERE RowNo = 1\nDataTable results = view.ToTable(true); //SELECT *\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10855",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/445/"
] |
10,860 |
<p>I am in the middle of a "discussion" with a colleague about the best way to implement the data layer in a new application.</p>
<p>One viewpoint is that the data layer should be aware of business objects (our own classes that represent an entity), and be able to work with that object natively. </p>
<p>The opposing viewpoint is that the data layer should be object-agnostic, and purely handle simple data types (strings, bools, dates, etc.)</p>
<p>I can see that both approaches may be valid, but my own viewpoint is that I prefer the former. That way, if the data storage medium changes, the business layer doesn't (necessarily) have to change to accommodate the new data layer. It would therefore be a trivial thing to change from a SQL data store to a serialized xml filesystem store.</p>
<p>My colleague's point of view is that the data layer shouldn't have to know about object definitions, and that as long as the data is passed about appropriately, that is enough. </p>
<p>Now, I know that this is one of those questions that has the potential to start a religious war, but I'd appreciate any feedback from the community on how you approach such things. </p>
<p>TIA</p>
|
[
{
"answer_id": 10863,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 0,
"selected": false,
"text": "public IList<Foo> GetFoosById(int id) { ... }\n public void GetFoosById(IList<Foo> foos, int id) { ... }\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10860",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/377/"
] |
10,870 |
<p>Once I've called <code>DragManager.acceptDrag</code> is there any way to "unaccept" the drag? Say that I have a view which can accept drag and drop, but only in certain areas. Once the user drags over one of these areas I call <code>DragManager.acceptDrag(this)</code> (from a <code>DragEvent.DRAG_OVER</code> handler), but if the user then moves out of this area I'd like to change the status of the drag to not accepted and show the <code>DragManager.NONE</code> feedback. However, neither calling <code>DragManager.acceptDrag(null)</code> nor <code>DragManager.showFeedback(DragManager.NONE)</code> seems to have any effect. Once I've accepted the drag an set the feedback type I can't seem to change it.</p>
<p>Just to make it clear: the areas where the user should be able to drop are not components or even display objects, in fact they are just ranges in the text of a text field (like the selection). Had they been components of their own I could have solved it by making each of them accept drag events individually. I guess I could create proxy components that float over the text to emulate it, but I'd rather not if it isn't necessary.</p>
<hr>
<p>I've managed to get it working in both AIR and the browser now, but only by putting proxy components on top of the ranges of text where you should be able to drop things. That way I get the right feedback and drops are automatically unaccepted on drag exit.</p>
<p>This is the oddest thing about D&D in AIR:</p>
<pre><code>DragManager.doDrag(initiator, source, event, dragImage, offsetX, offsetY);
</code></pre>
<p>In browser-based Flex, <code>offsetX</code> and <code>offsetY</code> should be negative (so says the documentation, and it works fine). However, when running <em>exactly the same code</em> in AIR you have to make the offsets positive. The same numbers, but positive. That is very, very weird.</p>
<hr>
<p>I've tested some more and what <a href="https://stackoverflow.com/questions/10870/how-can-i-unaccept-a-drag-in-flex#11209">@maclema</a> works, but not if you run in AIR. It seems like drag and drop in AIR is different. It's really, really weird because not only is the feedback not showing correctly, and it's not possible to unaccept, but the coordinates are also completely off. I just tried my application in a browser instead of AIR and dragging and dropping is completely broken.</p>
<p>Also, skipping the <code>dragEnter</code> handler works fine in AIR, but breaks everything when running in a browser.</p>
|
[
{
"answer_id": 11209,
"author": "Matt MacLean",
"author_id": 22,
"author_profile": "https://Stackoverflow.com/users/22",
"pm_score": 3,
"selected": false,
"text": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<mx:Application xmlns:mx=\"http://www.adobe.com/2006/mxml\" layout=\"absolute\">\n <mx:Script>\n <![CDATA[\n import mx.core.DragSource;\n import mx.managers.DragManager;\n import mx.events.DragEvent;\n\n private function onDragEnter(e:DragEvent):void {\n if ( e.target == lbl ) {\n\n if ( e.localX < lbl.width/2 ) {\n trace(\"accept\");\n DragManager.acceptDragDrop(this);\n }\n else {\n DragManager.acceptDragDrop(null);\n }\n }\n }\n\n private function doStartDrag(e:MouseEvent):void {\n if ( e.buttonDown ) {\n var ds:DragSource = new DragSource();\n ds.addData(\"test\", \"text\");\n\n DragManager.doDrag(btn, ds, e);\n }\n }\n ]]>\n </mx:Script>\n <mx:Label id=\"lbl\" text=\"hello world!\" left=\"10\" top=\"10\" dragEnter=\"onDragEnter(event)\" dragOver=\"onDragEnter(event)\" />\n <mx:Button id=\"btn\" x=\"47\" y=\"255\" label=\"Button\" mouseMove=\"doStartDrag(event)\"/>\n</mx:Application>\n"
},
{
"answer_id": 12552,
"author": "Matt MacLean",
"author_id": 22,
"author_profile": "https://Stackoverflow.com/users/22",
"pm_score": 0,
"selected": false,
"text": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<mx:WindowedApplication xmlns:mx=\"http://www.adobe.com/2006/mxml\" layout=\"absolute\">\n <mx:Script>\n <![CDATA[\n import mx.controls.Alert;\n import mx.events.DragEvent;\n import mx.managers.DragManager;\n import mx.core.DragSource;\n\n private function doStartDrag(e:MouseEvent):void {\n if ( e.buttonDown && !DragManager.isDragging ) {\n var ds:DragSource = new DragSource();\n ds.addData(\"test\", \"test\");\n\n DragManager.doDrag(btn, ds, e);\n }\n }\n\n private function handleDragOver(e:DragEvent):void {\n if ( e.localX < cvs.width/2 ) {\n //since null does nothing, lets just set to accept the drag\n //operation, but accept it to the dragInitiator\n DragManager.acceptDragDrop(e.dragInitiator);\n } \n else {\n //accept drag\n DragManager.acceptDragDrop(cvs);\n DragManager.showFeedback( DragManager.COPY );\n }\n }\n\n private function handleDragDrop(e:DragEvent):void {\n if ( e.dragSource.hasFormat(\"test\") ) {\n Alert.show(\"Got a drag drop!\");\n }\n }\n ]]>\n </mx:Script>\n <mx:Canvas x=\"265\" y=\"66\" width=\"321\" height=\"245\" backgroundColor=\"#FF0000\" id=\"cvs\" dragOver=\"handleDragOver(event)\" dragDrop=\"handleDragDrop(event)\">\n </mx:Canvas>\n <mx:Button id=\"btn\" x=\"82\" y=\"140\" label=\"Drag Me\" mouseDown=\"doStartDrag(event)\"/>\n</mx:WindowedApplication>\n"
},
{
"answer_id": 15009919,
"author": "bebbo",
"author_id": 1412279,
"author_profile": "https://Stackoverflow.com/users/1412279",
"pm_score": 1,
"selected": false,
"text": "function dragEnterHandler(event: DragEvent):void {\n if (data suites at least one location in this component)\n DragManager.acceptDragDrop(this);\n}\n function dragOverHandler(event: DragEvent):void {\n if (data suites at least no location in this component) {\n DragManager.showFeedback(DragManager.NONE);\n return;\n }\n\n ... // handle other cases and show the cursor / icon you want\n}\n function dragOverHandler(event: DragEvent):void {\n // handle the recieved data as you like.\n}\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10870",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1109/"
] |
10,877 |
<p>How can I left-align the numbers in an ordered list?</p>
<pre><code>1. an item
// skip some items for brevity
9. another item
10. notice the 1 is under the 9, and the item contents also line up
</code></pre>
<p>Change the character after the number in an ordered list?</p>
<pre><code>1) an item
</code></pre>
<p>Also is there a CSS solution to change from numbers to alphabetic/roman lists instead of using the type attribute on the ol element.</p>
<p>I am mostly interested in answers that work on Firefox 3.</p>
|
[
{
"answer_id": 10887,
"author": "Marcus Downing",
"author_id": 1000,
"author_profile": "https://Stackoverflow.com/users/1000",
"pm_score": 5,
"selected": false,
"text": "li {\n list-style-type: decimal;\n list-style-position: inside;\n}\n ol { counter-reset: item }\nli { display: block }\nli:before { content: counter(item) \") \"; counter-increment: item }\n"
},
{
"answer_id": 10889,
"author": "GateKiller",
"author_id": 383,
"author_profile": "https://Stackoverflow.com/users/383",
"pm_score": 1,
"selected": false,
"text": "<ol type=\"a\">\n <li>Turn left on Maple Street</li>\n <li>Turn right on Clover Court</li>\n</ol>\n"
},
{
"answer_id": 14738,
"author": "Marcus Downing",
"author_id": 1000,
"author_profile": "https://Stackoverflow.com/users/1000",
"pm_score": 3,
"selected": false,
"text": "li:before {\n content: counter(item) \") \";\n counter-increment: item;\n display: marker;\n width: 2em;\n}\n"
},
{
"answer_id": 24960,
"author": "Peter Hilton",
"author_id": 2670,
"author_profile": "https://Stackoverflow.com/users/2670",
"pm_score": 3,
"selected": false,
"text": "ol { list-style-type: decimal-leading-zero; }\n"
},
{
"answer_id": 486662,
"author": "grom",
"author_id": 486,
"author_profile": "https://Stackoverflow.com/users/486",
"pm_score": 8,
"selected": true,
"text": "ol {\n counter-reset: item;\n margin-left: 0;\n padding-left: 0;\n}\nli {\n display: block;\n margin-bottom: .5em;\n margin-left: 2em;\n}\nli::before {\n display: inline-block;\n content: counter(item) \") \";\n counter-increment: item;\n width: 2em;\n margin-left: -2em;\n} <ol>\n <li>One</li>\n <li>Two</li>\n <li>Three</li>\n <li>Four</li>\n <li>Five</li>\n <li>Six</li>\n <li>Seven</li>\n <li>Eight</li>\n <li>Nine<br>Items</li>\n <li>Ten<br>Items</li>\n</ol> li::before {\n content: counter(item, upper-roman) \") \";\n counter-increment: item;\n/* ... */\n"
},
{
"answer_id": 486704,
"author": "Stephen Denne",
"author_id": 11721,
"author_profile": "https://Stackoverflow.com/users/11721",
"pm_score": 1,
"selected": false,
"text": "list-style-position : outside LI:before { \n display: marker;\n content: \"(\" counter(counter) \")\";\n counter-increment: counter;\n width: 6em;\n text-align: center;\n }\n"
},
{
"answer_id": 487884,
"author": "Marcus Downing",
"author_id": 1000,
"author_profile": "https://Stackoverflow.com/users/1000",
"pm_score": -1,
"selected": false,
"text": "<html>\n<head>\n<style type='text/css'>\n\n ol { counter-reset: item; }\n\n li { display: block; }\n\n li:before { content: counter(item) \")\"; counter-increment: item; \n display: inline-block; width: 50px; }\n\n</style>\n</head>\n<body>\n<ol>\n <li>Something</li>\n <li>Something</li>\n <li>Something</li>\n <li>Something</li>\n <li>Something</li>\n <li>Something</li>\n <li>Something</li>\n <li>Something</li>\n <li>Something</li>\n <li>Something</li>\n <li>Something</li>\n <li>Something</li>\n</ol>\n</body>\n display: inline-block"
},
{
"answer_id": 488160,
"author": "Steve Perks",
"author_id": 16124,
"author_profile": "https://Stackoverflow.com/users/16124",
"pm_score": 3,
"selected": false,
"text": "upper-roman ol {\n counter-reset: item;\n margin-left: 0;\n padding-left: 0;\n}\nli {\n margin-bottom: .5em;\n}\nli:before {\n display: inline-block;\n content: counter(item, upper-roman) \")\";\n counter-increment: item;\n width: 3em;\n} <ol>\n <li>One</li>\n <li>Two</li>\n <li>Three</li>\n <li>Four</li>\n <li>Five</li>\n <li>Six</li>\n <li>Seven</li>\n <li>Eight</li>\n <li>Nine</li>\n <li>Ten</li>\n</ol>"
},
{
"answer_id": 489088,
"author": "strager",
"author_id": 39992,
"author_profile": "https://Stackoverflow.com/users/39992",
"pm_score": 2,
"selected": false,
"text": "ol {\n counter-reset: item;\n margin-left: 0;\n padding-left: 0;\n}\n\nli {\n display: block;\n margin-left: 3.5em; /* Change with margin-left on li:before. Must be -li:before::margin-left + li:before::padding-right. (Causes indention for other lines.) */\n}\n\nli:before {\n content: counter(item) \")\"; /* Change 'item' to 'item, upper-roman' or 'item, lower-roman' for upper- and lower-case roman, respectively. */\n counter-increment: item;\n display: inline-block;\n text-align: right;\n width: 3em; /* Must be the maximum width of your list's numbers, including the ')', for compatability (in case you use a fixed-width font, for example). Will have to beef up if using roman. */\n padding-right: 0.5em;\n margin-left: -3.5em; /* See li comments. */\n}\n"
},
{
"answer_id": 501153,
"author": "Marco Luglio",
"author_id": 14263,
"author_profile": "https://Stackoverflow.com/users/14263",
"pm_score": 0,
"selected": false,
"text": "<style type=\"text/css\">\nol {\n list-style-position: inside;\n}\nli:first-letter {\n white-space: pre;\n}\n</style>\n <ol>\n<li> an item</li>\n<li> another item</li>\n...\n</ol>\n li <style type=\"text/css\">\nol {\n list-style-position: inside;\n}\n</style>\n\n<ol>\n <li><pre> </pre>an item</li>\n <li><pre> </pre>another item</li>\n ...\n</ol>\n"
},
{
"answer_id": 8235507,
"author": "William Entriken",
"author_id": 300224,
"author_profile": "https://Stackoverflow.com/users/300224",
"pm_score": 1,
"selected": false,
"text": "dl { overflow:hidden; }\ndt {\n float:left;\n clear: left;\n width:4em; /* adjust the width; make sure the total of both is 100% */\n text-align: right\n}\ndd {\n float:left;\n width:50%; /* adjust the width; make sure the total of both is 100% */\n margin: 0 0.5em;\n}\n"
},
{
"answer_id": 31823704,
"author": "z0r",
"author_id": 320036,
"author_profile": "https://Stackoverflow.com/users/320036",
"pm_score": 4,
"selected": false,
"text": "ol {\n list-style: none;\n}\n\nol>li:before {\n content: attr(seq) \". \";\n} <ol>\n <li seq=\"1\">Item one</li>\n <li seq=\"20\">Item twenty</li>\n <li seq=\"300\">Item three hundred</li>\n</ol> seq content: counter(foo) content: attr(seq)"
},
{
"answer_id": 43049714,
"author": "Vlad Alivanov",
"author_id": 5622540,
"author_profile": "https://Stackoverflow.com/users/5622540",
"pm_score": 0,
"selected": false,
"text": "<style>\n h4 {font-size: 18px}\n ol.list-h4 {counter-reset: item; padding-left:27px}\n ol.list-h4 > li {display: block}\n ol.list-h4 > li::before {display: block; position:absolute; left:16px; top:auto; content: counter(item)\".\"; counter-increment: item; font-size: 18px}\n ol.list-h4 > li > h4 {padding-top:3px}\n</style>\n\n<ol class=\"list-h4\">\n <li>\n <h4>...</h4>\n <p>...</p> \n </li>\n <li>...</li>\n</ol>\n"
},
{
"answer_id": 60100741,
"author": "Flimm",
"author_id": 247696,
"author_profile": "https://Stackoverflow.com/users/247696",
"pm_score": 5,
"selected": false,
"text": "value value <ol>\n <li value=\"3\">This is item three.</li>\n <li value=\"50\">This is item fifty.</li>\n <li value=\"100\">This is item one hundred.</li>\n</ol> <ol> start"
},
{
"answer_id": 70883910,
"author": "TylerH",
"author_id": 2756409,
"author_profile": "https://Stackoverflow.com/users/2756409",
"pm_score": 0,
"selected": false,
"text": " \n .custom {\n list-style-type: none;\n }\n .custom li {\n counter-increment: step-counter;\n }\n .custom li::before {\n content: '(' counter(step-counter) ')';\n margin-right: 5px;\n }\n \n \n <ol class=\"custom\">\n <li>First</li>\n <li>Second</li>\n <li>Third</li>\n <li>Fourth</li>\n <li>Fifth</li>\n <li>Sixth</li>\n <li>Seventh</li>\n <li>Eighth</li>\n <li>Ninth</li>\n <li>Tenth</li>\n </ol>\n \n "
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10877",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/486/"
] |
10,905 |
<p>You should be able to create a generic form:</p>
<pre><code>public partial class MyGenericForm<T> :
Form where T : class
{
/* form code */
public List<T> TypedList { get; set; }
}
</code></pre>
<p>Is valid C#, and compiles. However the designer won't work and the form will throw a runtime exception if you have any images stating that it cannot find the resource.</p>
<p>I think this is because the windows forms designer assumes that the resources will be stored under the simple type's name.</p>
|
[
{
"answer_id": 10906,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 0,
"selected": false,
"text": "internal class MyGenericForm:\n MyGenericForm<object> { }\n <>"
},
{
"answer_id": 57163033,
"author": "Ali Osman Yavuz",
"author_id": 6342642,
"author_profile": "https://Stackoverflow.com/users/6342642",
"pm_score": 0,
"selected": false,
"text": "public partial class Form1<TEntity, TContext> : Formbase // where....\n partial class Form1<TEntity, TContext>\n partial class Form1\n{\n} \n"
},
{
"answer_id": 60053845,
"author": "Nando",
"author_id": 2139449,
"author_profile": "https://Stackoverflow.com/users/2139449",
"pm_score": 0,
"selected": false,
"text": " public static MyForm GetInstance<T>(T arg) where T : MyType\n{\n MyForm myForm = new MyForm();\n\n myForm.InitializeStuffs<T>(arg);\n myForm.StartPosition = myForm.CenterParent;\n\n return myForm;\n}\n var myFormInstance = MyForm.GetInstance<T>(arg); myFormInstance.ShowDialog(this);\n"
}
] |
2008/08/14
|
[
"https://Stackoverflow.com/questions/10905",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/905/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.