qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
64,748
<p>How can I poll disk activity in Applescript? Check to see if disk X is being read, written, or idle every N seconds and do something.</p>
[ { "answer_id": 65954, "author": "jackrabbit", "author_id": 3707, "author_profile": "https://Stackoverflow.com/users/3707", "pm_score": 2, "selected": false, "text": "call method" }, { "answer_id": 158032, "author": "Milhous", "author_id": 17712, "author_profile": "https://Stackoverflow.com/users/17712", "pm_score": 0, "selected": false, "text": "#!/usr/sbin/dtrace -s\n/*\n * bitesize.d - analyse disk I/O size by process.\n * Written using DTrace (Solaris 10 build 63).\n *\n * This produces a report for the size of disk events caused by \n * processes. These are the disk events sent by the block I/O driver.\n *\n * If applications must use the disks, we generally prefer they do so\n * sequentially with large I/O sizes. \n *\n * 15-Jun-2005, ver 1.00\n *\n * USAGE: bitesize.d # wait several seconds, then hit Ctrl-C\n *\n * FIELDS:\n * PID process ID\n * CMD command and argument list\n * value size in bytes\n * count number of I/O operations\n *\n * NOTES: \n * The application may be requesting smaller sized operations, which\n * are being rounded up to the nearest sector size or UFS block size.\n * To analyse what the application is requesting, DTraceToolkit programs\n * such as Proc/fddist may help.\n *\n * SEE ALSO: seeksize.d, iosnoop\n *\n * Standard Disclaimer: This is freeware, use at your own risk.\n *\n * 31-Mar-2004 Brendan Gregg Created this, build 51.\n * 10-Oct-2004 \" \" Rewrote to use the io provider, build 63.\n */\n\n#pragma D option quiet\n\n/*\n * Print header\n */\ndtrace:::BEGIN\n{\n printf(\"Sampling... Hit Ctrl-C to end.\\n\");\n}\n\n/*\n * Process io start\n */\nio:::start\n{\n /* fetch details */\n this->size = args[0]->b_bcount;\n cmd = (string)curpsinfo->pr_psargs;\n\n /* store details */\n @Size[pid,cmd] = quantize(this->size);\n}\n\n/*\n * Print final report\n */\ndtrace:::END \n{\n printf(\"\\n%8s %s\\n\",\"PID\",\"CMD\");\n printa(\"%8d %s\\n%@d\\n\",@Size);\n}\n" }, { "answer_id": 366058, "author": "Darryl Hein", "author_id": 5441, "author_profile": "https://Stackoverflow.com/users/5441", "pm_score": 0, "selected": false, "text": " iostat -c 50 -w 5\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7216/" ]
64,749
<p>When I run a particular SQL script in Unix environments, I see a '^M' character at the end of each line of the SQL script as it is echoed to the command line.<br /> I don't know on which OS the SQL script was initially created.</p> <p>What is causing this and how do I fix it?</p>
[ { "answer_id": 64788, "author": "Bill the Lizard", "author_id": 1288, "author_profile": "https://Stackoverflow.com/users/1288", "pm_score": 3, "selected": false, "text": "perl -pie 's/\\r//g' filename.txt\n" }, { "answer_id": 64792, "author": "dogbane", "author_id": 7412, "author_profile": "https://Stackoverflow.com/users/7412", "pm_score": 3, "selected": false, "text": ":%s/^M//g" }, { "answer_id": 64798, "author": "ColinYounger", "author_id": 1223, "author_profile": "https://Stackoverflow.com/users/1223", "pm_score": 5, "selected": false, "text": "0x0D0A" }, { "answer_id": 64959, "author": "Bernie Perez", "author_id": 1992, "author_profile": "https://Stackoverflow.com/users/1992", "pm_score": 5, "selected": false, "text": "vi" }, { "answer_id": 65404, "author": "Scottie T", "author_id": 6688, "author_profile": "https://Stackoverflow.com/users/6688", "pm_score": -1, "selected": false, "text": ":%s/.$//" }, { "answer_id": 65449, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "C:\\tmp\\text>dos2unix hello.txt helloUNIX.txt\n" }, { "answer_id": 66264, "author": "Allan Wind", "author_id": 9706, "author_profile": "https://Stackoverflow.com/users/9706", "pm_score": 0, "selected": false, "text": "od -a $file" }, { "answer_id": 73859, "author": "Tim Abell", "author_id": 10245, "author_profile": "https://Stackoverflow.com/users/10245", "pm_score": 6, "selected": false, "text": "vi" }, { "answer_id": 15263125, "author": "Ariel Monaco", "author_id": 445845, "author_profile": "https://Stackoverflow.com/users/445845", "pm_score": 0, "selected": false, "text": "$var =~ /\\r\\n//g;\n" }, { "answer_id": 16062926, "author": "leela", "author_id": 451502, "author_profile": "https://Stackoverflow.com/users/451502", "pm_score": 2, "selected": false, "text": "vi t1.txt\n" }, { "answer_id": 17716712, "author": "g4th", "author_id": 905598, "author_profile": "https://Stackoverflow.com/users/905598", "pm_score": 3, "selected": false, "text": "dos2unix" }, { "answer_id": 21632415, "author": "kenorb", "author_id": 55075, "author_profile": "https://Stackoverflow.com/users/55075", "pm_score": 1, "selected": false, "text": "sed -i'.bak' s/\\r//g *.*\n" }, { "answer_id": 24024068, "author": "Mason Wright", "author_id": 998179, "author_profile": "https://Stackoverflow.com/users/998179", "pm_score": 1, "selected": false, "text": "tr '\\r\\n' '\\n' < dosFile.txt > unixFile.txt\n" }, { "answer_id": 70804987, "author": "Nagev", "author_id": 5362795, "author_profile": "https://Stackoverflow.com/users/5362795", "pm_score": 0, "selected": false, "text": "\\r\\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64749", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7648/" ]
64,759
<p>I have a pdf file of a logo, about 1"x2" in dimension. Can anybody provide the code snippet to import that PDF logo into another PDF file using the <a href="http://framework.zend.com/manual/en/zend.pdf.html" rel="nofollow noreferrer">Zend_PDF</a> API's? </p> <p>Ideally, I'd like to be able to place it like the PNG, TIFF or JPG objects with the Zend_Pdf_Image object. </p> <p>In other words, I want to be able to place the little 1x2" pdf document on top of a 8.5x11" page, not use the original pdf as a background. </p> <p>Thanks!</p>
[ { "answer_id": 75021, "author": "user6824", "author_id": 6824, "author_profile": "https://Stackoverflow.com/users/6824", "pm_score": 2, "selected": false, "text": "$pdf = & new FPDI ('P', 'in', 'Letter' );\n$pagecount = $pdf->setSourceFile ( APP . 'logo.pdf' );\n$tplidx = $pdf->importPage ( 1, '/MediaBox' );\n\n$pdf->addPage ();\n$pdf->useTemplate ( $tplidx, 1, 1 );\n$pdf->Output ( 'output.pdf', 'F' );\n" }, { "answer_id": 198422, "author": "gnud", "author_id": 27204, "author_profile": "https://Stackoverflow.com/users/27204", "pm_score": 0, "selected": false, "text": "convert" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6824/" ]
64,781
<p>I have a web application that receives messages through an HTTP interface, e.g.:</p> <pre><code>http://server/application?source=123&amp;destination=234&amp;text=hello </code></pre> <p>This request contains the ID of the sender, the ID of the recipient and the text of the message.</p> <p>This message should be processed like:</p> <ul> <li>finding the matching User object for both the source and the destination from the database</li> <li>creating a tree of objects: a Message that contains a field for the message text and two User objects for the source and the destination</li> <li>persisting this tree to a database.</li> </ul> <p>The tree will be loaded by other applications that I can't touch.</p> <p>I use Oracle as the backing database and JPA with Toplink for the database handling tasks. If possible, I'd stay with these.</p> <p>Without much optimization I can achieve ~30 requests/sec throughput in my environment. That's not much, I'd require ~300 requests/sec. So I measured where the performance bottleneck is and found that the calls to <code>em.persist()</code> takes most of the time. If I simply comment out that line, the throughput go well over 1000 requests/sec.</p> <p>I tried to write a small test application that used simple JDBC calls to persist 1 million messages to the same database. I used batching, meaning I did 100 inserts then a commit, and repeated until all the records was in the database. I measured ~500 requests/sec throughput in this scenario, that would meet my needs.</p> <p>It is clear that I need to optimize insert performance here. However as I mentioned earlier I would like to keep using JPA and Toplink for this, not pure JDBC.</p> <p>Do you know a way to create batch inserts with JPA and Toplink? Can you recommend any other technique for improving JPA persist performance?</p> <p><strong>ADDITIONAL INFO:</strong></p> <p>"requests/sec" means here: total number of requests / total time from beginning of test to last record written to database.</p> <p>I tried to make the calls to <code>em.persist()</code> asynchronous by creating an in-memory queue between the servlet stuff and the persister. It helped the performance greatly. However the queue did grow really fast and as the application will receive ~200 requests/second continuously, It is not an acceptable solution for me.</p> <p>In this decoupled approach I collected requests for 100 msec and called <code>em.persist()</code> on all collected items before commiting the transaction. The EntityManagerFactory is cached between each transaction.</p>
[ { "answer_id": 66373, "author": "Christian", "author_id": 9817, "author_profile": "https://Stackoverflow.com/users/9817", "pm_score": 3, "selected": true, "text": "uow=sess.acquireUnitOfWork();\nfor (job in batch) {\n thingyCl=uow.registerObject(new Thingy());\n user1Cl=uow.registerObject(user1);\n user2Cl=uow.registerObject(user2);\n thingyCl.setUsers(user1Cl,user2Cl);\n}\nuow.commit();\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64781", "https://Stackoverflow.com", "https://Stackoverflow.com/users/686/" ]
64,782
<pre><code>int i = 4; string text = "Player "; cout &lt;&lt; (text + i); </code></pre> <p>I'd like it to print <code>Player 4</code>.</p> <p>The above is obviously wrong but it shows what I'm trying to do here. Is there an easy way to do this or do I have to start adding new includes?</p>
[ { "answer_id": 64794, "author": "rupello", "author_id": 635, "author_profile": "https://Stackoverflow.com/users/635", "pm_score": 0, "selected": false, "text": "cout << \"Player\" << i ;\n" }, { "answer_id": 64795, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "cout << text << i;\n" }, { "answer_id": 64796, "author": "jjnguy", "author_id": 2598, "author_profile": "https://Stackoverflow.com/users/2598", "pm_score": 3, "selected": false, "text": "cout << text << \" \" << i << endl;\n" }, { "answer_id": 64797, "author": "introp", "author_id": 8398, "author_profile": "https://Stackoverflow.com/users/8398", "pm_score": 0, "selected": false, "text": "cout << text << i;\n" }, { "answer_id": 64804, "author": "GEOCHET", "author_id": 5640, "author_profile": "https://Stackoverflow.com/users/5640", "pm_score": 0, "selected": false, "text": "cout << text << \" \" << i << endl;\n" }, { "answer_id": 64805, "author": "Jason Baker", "author_id": 2147, "author_profile": "https://Stackoverflow.com/users/2147", "pm_score": 3, "selected": false, "text": "std::stringstream" }, { "answer_id": 64811, "author": "Fire Lancer", "author_id": 6266, "author_profile": "https://Stackoverflow.com/users/6266", "pm_score": 4, "selected": false, "text": "MyStr += boost::lexical_cast<std::string>(MyInt);\n" }, { "answer_id": 64815, "author": "Eric", "author_id": 4540, "author_profile": "https://Stackoverflow.com/users/4540", "pm_score": 7, "selected": false, "text": "printf(\"Player %d\", i);\n" }, { "answer_id": 64817, "author": "Sebastian Redl", "author_id": 8922, "author_profile": "https://Stackoverflow.com/users/8922", "pm_score": 8, "selected": false, "text": "std::cout << text << i;\n" }, { "answer_id": 65309, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "std::cout << text << i;\n" }, { "answer_id": 941229, "author": "Daniel James", "author_id": 2434, "author_profile": "https://Stackoverflow.com/users/2434", "pm_score": 2, "selected": false, "text": "#include <boost/format.hpp>\n#include <iostream>\n#include <string>\n\nint main() {\n int i = 4;\n std::string text = \"Player\";\n std::cout << boost::format(\"%1% %2%\\n\") % text % i;\n}\n" }, { "answer_id": 6455164, "author": "Brian Lenoski", "author_id": 577587, "author_profile": "https://Stackoverflow.com/users/577587", "pm_score": 2, "selected": false, "text": "QString" }, { "answer_id": 6490852, "author": "Mr. Y", "author_id": 817063, "author_profile": "https://Stackoverflow.com/users/817063", "pm_score": -1, "selected": false, "text": "int i = 4;\nCString strOutput;\nstrOutput.Format(\"Player %d\", i);\n" }, { "answer_id": 6705708, "author": "Robert Parcus", "author_id": 814180, "author_profile": "https://Stackoverflow.com/users/814180", "pm_score": 2, "selected": false, "text": "#include <string>\n#include <sstream>\n#include <iostream>\n\nusing namespace std;\n\nint main(){\nstring str;\nint i = 321;\nstd::stringstream ss;\nss << 123;\nstr = \"/dev/video\";\ncout << str << endl;\ncout << str << 456 << endl;\ncout << str << i << endl;\nstr += ss.str();\ncout << str << endl;\n}\n" }, { "answer_id": 15182224, "author": "user2037225", "author_id": 2037225, "author_profile": "https://Stackoverflow.com/users/2037225", "pm_score": -1, "selected": false, "text": "int i = 4;\nstring text = \"Player \";\ntext+=(i+'0');\ncout << (text);\n" }, { "answer_id": 16600810, "author": "Richard", "author_id": 752843, "author_profile": "https://Stackoverflow.com/users/752843", "pm_score": 3, "selected": false, "text": "string text = \"Player: \";\nint i = 4;\ncout << text << i << endl;\n" }, { "answer_id": 18997915, "author": "headmyshoulder", "author_id": 625476, "author_profile": "https://Stackoverflow.com/users/625476", "pm_score": 8, "selected": false, "text": "#include <string> // to use std::string, std::to_string() and \"+\" operator acting on strings \n\nint i = 4;\nstd::string text = \"Player \";\ntext += std::to_string(i);\n" }, { "answer_id": 32389356, "author": "Saurabh Mishra", "author_id": 5299089, "author_profile": "https://Stackoverflow.com/users/5299089", "pm_score": 1, "selected": false, "text": "cout << text << i;\n" }, { "answer_id": 33784419, "author": "Code Black", "author_id": 5367912, "author_profile": "https://Stackoverflow.com/users/5367912", "pm_score": 0, "selected": false, "text": "#include<iostream>\n #include<string>\n using namespace std;\n int main() {\n\n string names[] = { \"amz\",\"Waq\",\"Mon\",\"Sam\",\"Has\",\"Shak\",\"GBy\" }; //simple array\n int length = sizeof(names) / sizeof(names[0]); //give you size of array\n int id;\n string append[7]; //as length is 7 just for sake of storing and printing output \n for (size_t i = 0; i < length; i++) {\n id = rand() % 20000 + 2;\n append[i] = names[i] + to_string(id);\n }\n for (size_t i = 0; i < length; i++) {\n cout << append[i] << endl;\n }\n\n\n}\n" }, { "answer_id": 37435228, "author": "Евгений Яковлев", "author_id": 6380629, "author_profile": "https://Stackoverflow.com/users/6380629", "pm_score": -1, "selected": false, "text": "std::string::push_back" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64782", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
64,786
<p>What is your favorite method to handle errors in Bash? The best example of handling errors I have found on the web was written by William Shotts, Jr at <a href="http://www.linuxcommand.org" rel="noreferrer">http://www.linuxcommand.org</a>. </p> <p>He suggests using the following function for error handling in Bash:</p> <pre><code>#!/bin/bash # A slicker error handling routine # I put a variable in my scripts named PROGNAME which # holds the name of the program being run. You can get this # value from the first item on the command line ($0). # Reference: This was copied from &lt;http://www.linuxcommand.org/wss0150.php&gt; PROGNAME=$(basename $0) function error_exit { # ---------------------------------------------------------------- # Function for exit due to fatal program error # Accepts 1 argument: # string containing descriptive error message # ---------------------------------------------------------------- echo "${PROGNAME}: ${1:-"Unknown Error"}" 1&gt;&amp;2 exit 1 } # Example call of the error_exit function. Note the inclusion # of the LINENO environment variable. It contains the current # line number. echo "Example of error with line number and message" error_exit "$LINENO: An error has occurred." </code></pre> <p>Do you have a better error handling routine that you use in Bash scripts?</p>
[ { "answer_id": 64880, "author": "pjz", "author_id": 8002, "author_profile": "https://Stackoverflow.com/users/8002", "pm_score": 2, "selected": false, "text": "die() {\n echo $1\n kill $$\n}\n" }, { "answer_id": 69808, "author": "Bruno De Fraine", "author_id": 6918, "author_profile": "https://Stackoverflow.com/users/6918", "pm_score": 7, "selected": false, "text": "set -e\n" }, { "answer_id": 182080, "author": "yukondude", "author_id": 726, "author_profile": "https://Stackoverflow.com/users/726", "pm_score": 3, "selected": false, "text": "1" }, { "answer_id": 185900, "author": "Charles Duffy", "author_id": 14122, "author_profile": "https://Stackoverflow.com/users/14122", "pm_score": 8, "selected": false, "text": "tempfiles=( )\ncleanup() {\n rm -f \"${tempfiles[@]}\"\n}\ntrap cleanup 0\n\nerror() {\n local parent_lineno=\"$1\"\n local message=\"$2\"\n local code=\"${3:-1}\"\n if [[ -n \"$message\" ]] ; then\n echo \"Error on or near line ${parent_lineno}: ${message}; exiting with status ${code}\"\n else\n echo \"Error on or near line ${parent_lineno}; exiting with status ${code}\"\n fi\n exit \"${code}\"\n}\ntrap 'error ${LINENO}' ERR\n" }, { "answer_id": 1771722, "author": "Michael Nooner", "author_id": 215602, "author_profile": "https://Stackoverflow.com/users/215602", "pm_score": 4, "selected": false, "text": "#This function is used to cleanly exit any script. It does this displaying a\n# given error message, and exiting with an error code.\nfunction error_exit {\n echo\n echo \"$@\"\n exit 1\n}\n#Trap the killer signals so that we can exit with a good message.\ntrap \"error_exit 'Received signal SIGHUP'\" SIGHUP\ntrap \"error_exit 'Received signal SIGINT'\" SIGINT\ntrap \"error_exit 'Received signal SIGTERM'\" SIGTERM\n\n#Alias the function so that it will print a message with the following format:\n#prog-name(@line#): message\n#We have to explicitly allow aliases, we do this because they make calling the\n#function much easier (see example).\nshopt -s expand_aliases\nalias die='error_exit \"Error ${0}(@`echo $(( $LINENO - 1 ))`):\"'\n" }, { "answer_id": 1877000, "author": "Ben Scholbrock", "author_id": 228321, "author_profile": "https://Stackoverflow.com/users/228321", "pm_score": 5, "selected": false, "text": "set -o errexit\n" }, { "answer_id": 6290175, "author": "l0b0", "author_id": 96588, "author_profile": "https://Stackoverflow.com/users/96588", "pm_score": 2, "selected": false, "text": "# Custom errors\nEX_UNKNOWN=1\n\nwarning()\n{\n # Output warning messages\n # Color the output red if it's an interactive terminal\n # @param $1...: Messages\n\n test -t 1 && tput setf 4\n\n printf '%s\\n' \"$@\" >&2\n\n test -t 1 && tput sgr0 # Reset terminal\n true\n}\n\nerror()\n{\n # Output error messages with optional exit code\n # @param $1...: Messages\n # @param $N: Exit code (optional)\n\n messages=( \"$@\" )\n\n # If the last parameter is a number, it's not part of the messages\n last_parameter=\"${messages[@]: -1}\"\n if [[ \"$last_parameter\" =~ ^[0-9]*$ ]]\n then\n exit_code=$last_parameter\n unset messages[$((${#messages[@]} - 1))]\n fi\n\n warning \"${messages[@]}\"\n\n exit ${exit_code:-$EX_UNKNOWN}\n}\n" }, { "answer_id": 11564455, "author": "Olivier Delrieu", "author_id": 769749, "author_profile": "https://Stackoverflow.com/users/769749", "pm_score": 3, "selected": false, "text": "#!/bin/bash\nset -o pipefail # trace ERR through pipes\nset -o errtrace # trace ERR through 'time command' and other functions\nfunction error() {\n JOB=\"$0\" # job name\n LASTLINE=\"$1\" # line of error occurrence\n LASTERR=\"$2\" # error code\n echo \"ERROR in ${JOB} : line ${LASTLINE} with exit code ${LASTERR}\"\n exit 1\n}\ntrap 'error ${LINENO} ${?}' ERR\n" }, { "answer_id": 12414661, "author": "Nelson Rodriguez", "author_id": 1037940, "author_profile": "https://Stackoverflow.com/users/1037940", "pm_score": 2, "selected": false, "text": "#!/bin/bash\n\nerror_exit()\n{\n if [ \"$?\" != \"0\" ]; then\n log.sh \"$1\"\n exit 1\n fi\n}\n" }, { "answer_id": 13099228, "author": "Luca Borrione", "author_id": 1032370, "author_profile": "https://Stackoverflow.com/users/1032370", "pm_score": 7, "selected": false, "text": "lib_name='trap'\nlib_version=20121026\n\nstderr_log=\"/dev/shm/stderr.log\"\n\n#\n# TO BE SOURCED ONLY ONCE:\n#\n###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##\n\nif test \"${g_libs[$lib_name]+_}\"; then\n return 0\nelse\n if test ${#g_libs[@]} == 0; then\n declare -A g_libs\n fi\n g_libs[$lib_name]=$lib_version\nfi\n\n\n#\n# MAIN CODE:\n#\n###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##\n\nset -o pipefail # trace ERR through pipes\nset -o errtrace # trace ERR through 'time command' and other functions\nset -o nounset ## set -u : exit the script if you try to use an uninitialised variable\nset -o errexit ## set -e : exit the script if any statement returns a non-true return value\n\nexec 2>\"$stderr_log\"\n\n\n###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##\n#\n# FUNCTION: EXIT_HANDLER\n#\n###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##\n\nfunction exit_handler ()\n{\n local error_code=\"$?\"\n\n test $error_code == 0 && return;\n\n #\n # LOCAL VARIABLES:\n # ------------------------------------------------------------------\n # \n local i=0\n local regex=''\n local mem=''\n\n local error_file=''\n local error_lineno=''\n local error_message='unknown'\n\n local lineno=''\n\n\n #\n # PRINT THE HEADER:\n # ------------------------------------------------------------------\n #\n # Color the output if it's an interactive terminal\n test -t 1 && tput bold; tput setf 4 ## red bold\n echo -e \"\\n(!) EXIT HANDLER:\\n\"\n\n\n #\n # GETTING LAST ERROR OCCURRED:\n # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #\n\n #\n # Read last file from the error log\n # ------------------------------------------------------------------\n #\n if test -f \"$stderr_log\"\n then\n stderr=$( tail -n 1 \"$stderr_log\" )\n rm \"$stderr_log\"\n fi\n\n #\n # Managing the line to extract information:\n # ------------------------------------------------------------------\n #\n\n if test -n \"$stderr\"\n then \n # Exploding stderr on :\n mem=\"$IFS\"\n local shrunk_stderr=$( echo \"$stderr\" | sed 's/\\: /\\:/g' )\n IFS=':'\n local stderr_parts=( $shrunk_stderr )\n IFS=\"$mem\"\n\n # Storing information on the error\n error_file=\"${stderr_parts[0]}\"\n error_lineno=\"${stderr_parts[1]}\"\n error_message=\"\"\n\n for (( i = 3; i <= ${#stderr_parts[@]}; i++ ))\n do\n error_message=\"$error_message \"${stderr_parts[$i-1]}\": \"\n done\n\n # Removing last ':' (colon character)\n error_message=\"${error_message%:*}\"\n\n # Trim\n error_message=\"$( echo \"$error_message\" | sed -e 's/^[ \\t]*//' | sed -e 's/[ \\t]*$//' )\"\n fi\n\n #\n # GETTING BACKTRACE:\n # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #\n _backtrace=$( backtrace 2 )\n\n\n #\n # MANAGING THE OUTPUT:\n # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #\n\n local lineno=\"\"\n regex='^([a-z]{1,}) ([0-9]{1,})$'\n\n if [[ $error_lineno =~ $regex ]]\n\n # The error line was found on the log\n # (e.g. type 'ff' without quotes wherever)\n # --------------------------------------------------------------\n then\n local row=\"${BASH_REMATCH[1]}\"\n lineno=\"${BASH_REMATCH[2]}\"\n\n echo -e \"FILE:\\t\\t${error_file}\"\n echo -e \"${row^^}:\\t\\t${lineno}\\n\"\n\n echo -e \"ERROR CODE:\\t${error_code}\" \n test -t 1 && tput setf 6 ## white yellow\n echo -e \"ERROR MESSAGE:\\n$error_message\"\n\n\n else\n regex=\"^${error_file}\\$|^${error_file}\\s+|\\s+${error_file}\\s+|\\s+${error_file}\\$\"\n if [[ \"$_backtrace\" =~ $regex ]]\n\n # The file was found on the log but not the error line\n # (could not reproduce this case so far)\n # ------------------------------------------------------\n then\n echo -e \"FILE:\\t\\t$error_file\"\n echo -e \"ROW:\\t\\tunknown\\n\"\n\n echo -e \"ERROR CODE:\\t${error_code}\"\n test -t 1 && tput setf 6 ## white yellow\n echo -e \"ERROR MESSAGE:\\n${stderr}\"\n\n # Neither the error line nor the error file was found on the log\n # (e.g. type 'cp ffd fdf' without quotes wherever)\n # ------------------------------------------------------\n else\n #\n # The error file is the first on backtrace list:\n\n # Exploding backtrace on newlines\n mem=$IFS\n IFS='\n '\n #\n # Substring: I keep only the carriage return\n # (others needed only for tabbing purpose)\n IFS=${IFS:0:1}\n local lines=( $_backtrace )\n\n IFS=$mem\n\n error_file=\"\"\n\n if test -n \"${lines[1]}\"\n then\n array=( ${lines[1]} )\n\n for (( i=2; i<${#array[@]}; i++ ))\n do\n error_file=\"$error_file ${array[$i]}\"\n done\n\n # Trim\n error_file=\"$( echo \"$error_file\" | sed -e 's/^[ \\t]*//' | sed -e 's/[ \\t]*$//' )\"\n fi\n\n echo -e \"FILE:\\t\\t$error_file\"\n echo -e \"ROW:\\t\\tunknown\\n\"\n\n echo -e \"ERROR CODE:\\t${error_code}\"\n test -t 1 && tput setf 6 ## white yellow\n if test -n \"${stderr}\"\n then\n echo -e \"ERROR MESSAGE:\\n${stderr}\"\n else\n echo -e \"ERROR MESSAGE:\\n${error_message}\"\n fi\n fi\n fi\n\n #\n # PRINTING THE BACKTRACE:\n # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #\n\n test -t 1 && tput setf 7 ## white bold\n echo -e \"\\n$_backtrace\\n\"\n\n #\n # EXITING:\n # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #\n\n test -t 1 && tput setf 4 ## red bold\n echo \"Exiting!\"\n\n test -t 1 && tput sgr0 # Reset terminal\n\n exit \"$error_code\"\n}\ntrap exit_handler EXIT # ! ! ! TRAP EXIT ! ! !\ntrap exit ERR # ! ! ! TRAP ERR ! ! !\n\n\n###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##\n#\n# FUNCTION: BACKTRACE\n#\n###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##\n\nfunction backtrace\n{\n local _start_from_=0\n\n local params=( \"$@\" )\n if (( \"${#params[@]}\" >= \"1\" ))\n then\n _start_from_=\"$1\"\n fi\n\n local i=0\n local first=false\n while caller $i > /dev/null\n do\n if test -n \"$_start_from_\" && (( \"$i\" + 1 >= \"$_start_from_\" ))\n then\n if test \"$first\" == false\n then\n echo \"BACKTRACE IS:\"\n first=true\n fi\n caller $i\n fi\n let \"i=i+1\"\n done\n}\n\nreturn 0\n" }, { "answer_id": 18118450, "author": "Orwellophile", "author_id": 912236, "author_profile": "https://Stackoverflow.com/users/912236", "pm_score": 2, "selected": false, "text": "function handle_error {\n status=$?\n last_call=$1\n\n # 127 is 'command not found'\n (( status != 127 )) && return\n\n echo \"you tried to call $last_call\"\n return\n}\n\n# Trap errors.\ntrap 'handle_error \"$_\"' ERR\n" }, { "answer_id": 30019669, "author": "niieani", "author_id": 595157, "author_profile": "https://Stackoverflow.com/users/595157", "pm_score": 4, "selected": false, "text": "set -e" }, { "answer_id": 34726287, "author": "skozin", "author_id": 804678, "author_profile": "https://Stackoverflow.com/users/804678", "pm_score": 1, "selected": false, "text": "set -e" }, { "answer_id": 41852435, "author": "xarxziux", "author_id": 5463687, "author_profile": "https://Stackoverflow.com/users/5463687", "pm_score": 2, "selected": false, "text": "action () {\n # Test if the first parameter is non-zero\n # and return straight away if so\n if test $1 -ne 0\n then\n return $1\n fi\n\n # Discard the control parameter\n # and execute the rest\n shift 1\n \"$@\"\n local status=$?\n\n # Test the exit status of the command run\n # and display an error message on failure\n if test ${status} -ne 0\n then\n echo Command \\\"\"$@\"\\\" failed >&2\n fi\n\n return ${status}\n}\n" }, { "answer_id": 68857236, "author": "NITHIN KIRTHICK", "author_id": 13744498, "author_profile": "https://Stackoverflow.com/users/13744498", "pm_score": 1, "selected": false, "text": "set -e" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64786", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
64,790
<p>I have breakpoints set but Xcode appears to ignore them.</p>
[ { "answer_id": 67957, "author": "pestophagous", "author_id": 10278, "author_profile": "https://Stackoverflow.com/users/10278", "pm_score": 8, "selected": true, "text": "Load Symbols Lazily" }, { "answer_id": 11310391, "author": "brian.clear", "author_id": 181947, "author_profile": "https://Stackoverflow.com/users/181947", "pm_score": 1, "selected": false, "text": "- Product menu > Manage Schemes\n- Select the scheme thats having debugging problems (if only one choose that)\n- Click Edit button at bottom\n- Edit Scheme dialog appears\n- in left panel click on Run APPNAME.app\n- on Right hand panel make sure youre on INFO tab\n- look for drop down DEBUGGER:\n- someone had set this to None\n- set to LLDB if this is your preferred debugger\n- can also change BUILD CONFIGURATION drop down to Debug \n- but I have other targets set to AdHoc which debug fine once Debugger is set\n" }, { "answer_id": 12974214, "author": "MANIAK_dobrii", "author_id": 1032151, "author_profile": "https://Stackoverflow.com/users/1032151", "pm_score": 0, "selected": false, "text": "XCode 4.2" }, { "answer_id": 13684779, "author": "evya", "author_id": 1442541, "author_profile": "https://Stackoverflow.com/users/1442541", "pm_score": 2, "selected": false, "text": "go Product -> Debug -> Activate Breakpoints\n" }, { "answer_id": 20190550, "author": "Perumal", "author_id": 1395957, "author_profile": "https://Stackoverflow.com/users/1395957", "pm_score": 1, "selected": false, "text": "Product->Debug Workflow->Show Disassembly" }, { "answer_id": 26398151, "author": "Dave", "author_id": 981499, "author_profile": "https://Stackoverflow.com/users/981499", "pm_score": 2, "selected": false, "text": "#line" }, { "answer_id": 29576169, "author": "William Jockusch", "author_id": 246568, "author_profile": "https://Stackoverflow.com/users/246568", "pm_score": 2, "selected": false, "text": "void BreakPoint(void) {\n int i=1;\n #if !__OPTIMIZE__\n printf(\"Code is waiting; hit pause to see.\\n\");\n while(i);\n #endif\n}\n" }, { "answer_id": 33099960, "author": "hbk", "author_id": 2012219, "author_profile": "https://Stackoverflow.com/users/2012219", "pm_score": 4, "selected": false, "text": "DeploymentPostprocessing" }, { "answer_id": 33753788, "author": "Oded Regev", "author_id": 583425, "author_profile": "https://Stackoverflow.com/users/583425", "pm_score": 6, "selected": false, "text": "Target > Scheme > Run" }, { "answer_id": 69503397, "author": "crifan", "author_id": 1616263, "author_profile": "https://Stackoverflow.com/users/1616263", "pm_score": 3, "selected": false, "text": "Xcode" }, { "answer_id": 70875649, "author": "Mujahid Daud Khan", "author_id": 1735196, "author_profile": "https://Stackoverflow.com/users/1735196", "pm_score": 0, "selected": false, "text": "path" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8761/" ]
64,808
<p>Most text editors have a navigation pane that lets you see all the files you currently have open. Or a pane that lets you browse a file directory.</p> <p>How do I do this in Emacs?</p>
[ { "answer_id": 64818, "author": "Mike Stone", "author_id": 122, "author_profile": "https://Stackoverflow.com/users/122", "pm_score": 2, "selected": false, "text": "Buffers" }, { "answer_id": 64850, "author": "Robᵩ", "author_id": 8747, "author_profile": "https://Stackoverflow.com/users/8747", "pm_score": 3, "selected": false, "text": "*Buffer List*" }, { "answer_id": 65437, "author": "Allen", "author_id": 6043, "author_profile": "https://Stackoverflow.com/users/6043", "pm_score": 2, "selected": false, "text": "ibuffer-mode" }, { "answer_id": 84376, "author": "EfForEffort", "author_id": 14113, "author_profile": "https://Stackoverflow.com/users/14113", "pm_score": 2, "selected": false, "text": "speedbar-supported-extension-expressions" }, { "answer_id": 46381893, "author": "mszmurlo", "author_id": 1483318, "author_profile": "https://Stackoverflow.com/users/1483318", "pm_score": 1, "selected": false, "text": "neotree" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64808", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8913/" ]
64,813
<p>These days, i came across a problem with Team System Unit Testing. I found that the automatically created accessor class ignores generic constraints - at least in the following case:</p> <p>Assume you have the following class:</p> <pre><code>namespace MyLibrary { public class MyClass { public Nullable&lt;T&gt; MyMethod&lt;T&gt;(string s) where T : struct { return (T)Enum.Parse(typeof(T), s, true); } } } </code></pre> <p>If you want to test MyMethod, you can create a test project with the following test method:</p> <pre><code>public enum TestEnum { Item1, Item2, Item3 } [TestMethod()] public void MyMethodTest() { MyClass c = new MyClass(); PrivateObject po = new PrivateObject(c); MyClass_Accessor target = new MyClass_Accessor(po); // The following line produces the following error: // Unit Test Adapter threw exception: GenericArguments[0], 'T', on // 'System.Nullable`1[T]' violates the constraint of type parameter 'T'.. TestEnum? e1 = target.MyMethod&lt;TestEnum&gt;("item2"); // The following line works great but does not work for testing private methods. TestEnum? e2 = c.MyMethod&lt;TestEnum&gt;("item2"); } </code></pre> <p>Running the test will fail with the error mentioned in the comment of the snippet above. The problem is the accessor class created by Visual Studio. If you go into it, you will come up to the following code:</p> <pre><code>namespace MyLibrary { [Shadowing("MyLibrary.MyClass")] public class MyClass_Accessor : BaseShadow { protected static PrivateType m_privateType; [Shadowing(".ctor@0")] public MyClass_Accessor(); public MyClass_Accessor(PrivateObject __p1); public static PrivateType ShadowedType { get; } public static MyClass_Accessor AttachShadow(object __p1); [Shadowing("MyMethod@1")] public T? MyMethod(string s); } } </code></pre> <p>As you can see, there is no constraint for the generic type parameter of the MyMethod method.</p> <p>Is that a bug? Is that by design? Who knows how to work around that problem?</p>
[ { "answer_id": 168453, "author": "Zachary Yates", "author_id": 8360, "author_profile": "https://Stackoverflow.com/users/8360", "pm_score": 1, "selected": false, "text": "TestEnum? e1 = target.MyMethod(\"item2\");\n" }, { "answer_id": 3570884, "author": "Igor Zevaka", "author_id": 129404, "author_profile": "https://Stackoverflow.com/users/129404", "pm_score": 1, "selected": false, "text": "internal" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64813", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6777/" ]
64,820
<p>ASP.NET 2.0 web application, how to implement shortcut key combination of <kbd>CTRL + Letter</kbd>, preferably through JavaScript, to make web application ergonomically better? How to capture multiple-key keyboard events through JavaScript?</p>
[ { "answer_id": 65212, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 3, "selected": false, "text": "window.onkeyup = function(e) {\n if (e.altKey) alert(\"Alt pressed\");\n if (e.shiftKey) alert(\"Shift pressed\");\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64820", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8832/" ]
64,825
<p>Is there a way to substring in JSP files, using struts2 technologies? I mean, struts2 has its own taglib and also uses ognl. How can I get a substring from a stacked value or bean value?</p>
[ { "answer_id": 6848438, "author": "bakoyaro", "author_id": 455020, "author_profile": "https://Stackoverflow.com/users/455020", "pm_score": 1, "selected": false, "text": "fn:substring(YOUR_FIELD, START_INDEX, END_INDEX)\n" }, { "answer_id": 12646878, "author": "Aleksandr M", "author_id": 1700321, "author_profile": "https://Stackoverflow.com/users/1700321", "pm_score": 1, "selected": false, "text": "<s:property value=\"str.substring(0, 5)\"/>\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64825", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
64,827
<p>I've created a learning application using <a href="http://jimneath.org/2008/09/09/bort-base-rails-application/" rel="noreferrer">Bort</a>, which is a base app that includes Restful Authentication and RSpec. I've got it up and running and added a new object that requires users to be logged in before they can do anything(<code>before_filter :login_required</code> in the controller). [edit: I should also mention that the user <code>has_many</code> of the new class and only the user should be able to see it.]</p> <p>I've created the new model/controller using Rspec's generators which have created a number of default tests. They all pass if there is no <code>before_filter</code> but several fail, as should be expected, once the <code>before_filter</code> is in place.</p> <p>How do I get the generated tests to run as if there is/is not a logged in user? Do I need a whole batch of matching not logged in - redirect tests? I assume it is some sort of mocking or fixture technique but I am new to RSpec and a bit adrift. Good RSpec tutorial links would also be appreciated.</p>
[ { "answer_id": 65748, "author": "TALlama", "author_id": 5657, "author_profile": "https://Stackoverflow.com/users/5657", "pm_score": 4, "selected": true, "text": "describe" }, { "answer_id": 71633, "author": "srboisvert", "author_id": 6805, "author_profile": "https://Stackoverflow.com/users/6805", "pm_score": 2, "selected": false, "text": "restful_authentication" }, { "answer_id": 143976, "author": "mislav", "author_id": 11687, "author_profile": "https://Stackoverflow.com/users/11687", "pm_score": 1, "selected": false, "text": "@current_user" }, { "answer_id": 1943616, "author": "Marcos Oliveira", "author_id": 127209, "author_profile": "https://Stackoverflow.com/users/127209", "pm_score": 3, "selected": false, "text": "before(:each) do\n controller.stub!(:authenticate).and_return(true)\nend\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64827", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6805/" ]
64,833
<p>I am writing a C# client that calls a web service written in Java (by another person). I have added a web reference to my client and I'm able to call methods in the web service ok.</p> <p>The service was changed to return an array of objects, and the client does not properly parse the returned SOAP message.</p> <pre><code>MyResponse[] MyFunc(string p) class MyResponse { long id; string reason; } </code></pre> <p>When my generated C# proxy calls the web service (using SoapHttpClientProtocol.Invoke), I am expecting a MyResponse[] array with length of 1, ie a single element. What I am getting after the Invoke call is an element with id=0 and reason=null, regardless of what the service actually returns. Using a packet sniffer, I can see that the service is returning what appears to be a legitimate soap message with id and reason set to non-null values.</p> <p>Is there some trick to getting a C# client to call a Java web service that returns someobject[] ? I will work on getting a sanitized demo if necessary.</p> <p><strong>Edit</strong>: This is a web reference via "Add Web Reference...". VS 2005, .NET 3.0.</p>
[ { "answer_id": 66834, "author": "David Chappelle", "author_id": 7475, "author_profile": "https://Stackoverflow.com/users/7475", "pm_score": 3, "selected": false, "text": "<import namespace=\"http://mynamespace.company.com\"/>\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64833", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7475/" ]
64,841
<p>I believe I need a DTD to define the schema and an XSLT if I want to display it in a browser and have it look "pretty". But I'm not sure what else I would need to have a well-defined XML document that can be queried using XQuery and displayed in a web browser.</p>
[ { "answer_id": 64942, "author": "Jorge Ferreira", "author_id": 6508, "author_profile": "https://Stackoverflow.com/users/6508", "pm_score": 2, "selected": true, "text": "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<?xml-stylesheet type=\"text/xsl\" href=\"info.xslt\"?>\n<info>\n <appName>My App</appName>\n <version>1.0.129</version>\n <buildTime>10-09-2008 12:44:03</buildTime>\n</info>\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64841", "https://Stackoverflow.com", "https://Stackoverflow.com/users/572/" ]
64,843
<p>I am building a site that uses a simple AJAX Servlet to talk JMS (ActiveMQ) and when a message arrives from the topic to update the site.</p> <p>I have Javascript that creates an XMLHttpRequest for data. The Servlet processes the Get Request and sends back JSON. However I have no idea how to connect my Servlet into my ActiveMQ Message Broker. It just sends back dummy data right now.</p> <p>I am thinking the Servelt should implement the messagelistener. Then onMessage send data to the JavaScript page. But I'm not sure how to do this.</p>
[ { "answer_id": 64883, "author": "jodonnell", "author_id": 4223, "author_profile": "https://Stackoverflow.com/users/4223", "pm_score": 0, "selected": false, "text": "Properties props = new Properties();\nprops.setProperty(Context.INITIAL_CONTEXT_FACTORY,\n \"org.apache.activemq.jndi.ActiveMQInitialContextFactory\");\nprops.setProperty(Context.PROVIDER_URL,\n \"tcp://hostname:61616\");\njavax.naming.Context ctx = new InitialContext(props);\n// lookup the connection factory\njavax.jms.TopicConnectionFactory factory = \n (javax.jms.TopicConnectionFactory)ctx.lookup(\"ConnectionFactory\");\n// create a new TopicConnection for pub/sub messaging\njavax.jms.TopicConnection conn = factory.getTopicConnection();\n// lookup an existing topic\njavax.jms.Topic mytopic = (javax.jms.Topic)ctx.lookup(\"MyTopic\");\n// create a new TopicSession for the client\njavax.jms.TopicSession session = \n conn.createTopicSession(false,TopicSession.AUTO_ACKNOWLEDGE);\n// create a new subscriber to receive messages\njavax.jms.TopicSubscriber subscriber = session.createSubscriber(mytopic);\n" }, { "answer_id": 2361633, "author": "Henryk Konsek", "author_id": 80711, "author_profile": "https://Stackoverflow.com/users/80711", "pm_score": 2, "selected": false, "text": "MessageListenerContainer" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64843", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1992/" ]
64,848
<p>Has anybody used C# to write a sample screen scraper for IBM as400?</p>
[ { "answer_id": 54542089, "author": "Ashetynw", "author_id": 9911023, "author_profile": "https://Stackoverflow.com/users/9911023", "pm_score": 1, "selected": false, "text": "using AutOIATypeLibrary;\nusing AutPSTypeLibrary;\n\nnamespace MyNamespace\n{\n public class Program \n {\n public AutPS PS = new AutPS();\n public AutOIA OI = new AutOIA();\n static void Main()\n {\n PS.SetConnectionByName(\"A\");\n OI.SetConnectionByName(\"A\");\n // Gets a string from the presentation space at row 1, col 1, length 5\n PS.GetText(1, 1, 5); \n\n // Gets the entire screen as a string. parse as needed.\n PS.GetText(1, 1, PS.NumRows * PS.NumCols);\n\n // Searches for a literal string in the presentation space by going forward from your row/col\n PS.SearchText(\"LiteralString\".ToUpper(), PsDir.pcSrchForward, 1, 1);\n }\n }\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64848", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
64,851
<p>How would you write (in C/C++) a macro which tests if an integer type (given as a parameter) is signed or unsigned?</p> <pre> #define is_this_type_signed (my_type) ... </pre>
[ { "answer_id": 64908, "author": "ChrisN", "author_id": 3853, "author_profile": "https://Stackoverflow.com/users/3853", "pm_score": 5, "selected": false, "text": "std::numeric_limits<type>::is_signed" }, { "answer_id": 64911, "author": "Fabio Ceconello", "author_id": 8999, "author_profile": "https://Stackoverflow.com/users/8999", "pm_score": 6, "selected": true, "text": "#define is_type_signed(my_type) (((my_type)-1) < 0)\n" }, { "answer_id": 64923, "author": "user7116", "author_id": 7116, "author_profile": "https://Stackoverflow.com/users/7116", "pm_score": 2, "selected": false, "text": "#define is_numeric_type_signed(typ) ( (((typ)0 - (typ)1)<(typ)0) && (((typ)0 - (typ)1) < (typ)1) )\n" }, { "answer_id": 64963, "author": "Frank Szczerba", "author_id": 8964, "author_profile": "https://Stackoverflow.com/users/8964", "pm_score": 1, "selected": false, "text": "#define is_signed(t) ( ((t)-1) < 0 )\n" }, { "answer_id": 64964, "author": "Doug T.", "author_id": 8123, "author_profile": "https://Stackoverflow.com/users/8123", "pm_score": -1, "selected": false, "text": " template <typename T>\n bool IsSignedType()\n {\n // A lot of assumptions on T here\n T instanceAsOne = 1;\n\n if (-instanceAsOne > 0)\n {\n return true;\n }\n else\n {\n return false;\n }\n}\n" }, { "answer_id": 64985, "author": "Greg Rogers", "author_id": 5963, "author_profile": "https://Stackoverflow.com/users/5963", "pm_score": 1, "selected": false, "text": "\nbool is_signed = std::numeric_limits<typeof(some_integer_variable)>::is_signed;\n" }, { "answer_id": 64988, "author": "Kevin", "author_id": 6386, "author_profile": "https://Stackoverflow.com/users/6386", "pm_score": -1, "selected": false, "text": "template <typename T>\nstruct is_signed_integer\n{\n static const bool value = false;\n};\n\ntemplate <>\nstruct is_signed_integer<int>\n{\n static const bool value = true;\n};\n\ntemplate <>\nstruct is_signed_integer<short>\n{\n static const bool value = true;\n};\n\ntemplate <>\nstruct is_signed_integer<signed char>\n{\n static const bool value = true;\n};\n\ntemplate <>\nstruct is_signed_integer<long>\n{\n static const bool value = true;\n};\n\n// assuming your C++ compiler supports 'long long'...\ntemplate <>\nstruct is_signed_integer<long long>\n{\n static const bool value = true;\n};\n\n#define is_this_type_signed(my_type) is_signed_integer<my_type>::value\n" }, { "answer_id": 65240, "author": "Calliphony", "author_id": 9050, "author_profile": "https://Stackoverflow.com/users/9050", "pm_score": 2, "selected": false, "text": "#define IS_SIGNED( T ) (((T)-1)<0)\n" }, { "answer_id": 67109, "author": "Bronek", "author_id": 10042, "author_profile": "https://Stackoverflow.com/users/10042", "pm_score": 1, "selected": false, "text": "typeof" }, { "answer_id": 41602832, "author": "Mikhail", "author_id": 314290, "author_profile": "https://Stackoverflow.com/users/314290", "pm_score": 0, "selected": false, "text": "type_traits" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4528/" ]
64,860
<p>What is the fastest, easiest tool or method to convert text files between character sets?</p> <p>Specifically, I need to convert from UTF-8 to ISO-8859-15 and vice versa.</p> <p>Everything goes: one-liners in your favorite scripting language, command-line tools or other utilities for OS, web sites, etc.</p> <h2>Best solutions so far:</h2> <p>On Linux/UNIX/OS X/cygwin:</p> <ul> <li><p>Gnu <a href="http://www.gnu.org/software/libiconv/documentation/libiconv/iconv.1.html" rel="noreferrer">iconv</a> suggested by <a href="https://stackoverflow.com/questions/64860/best-way-to-convert-text-files-between-character-sets#64889">Troels Arvin</a> is best used <strong>as a filter</strong>. It seems to be universally available. Example:</p> <pre><code> $ iconv -f UTF-8 -t ISO-8859-15 in.txt &gt; out.txt </code></pre> <p>As pointed out by <a href="https://stackoverflow.com/questions/64860/best-way-to-convert-text-files-between-character-sets#64991">Ben</a>, there is an <a href="http://www.iconv.com/iconv.htm" rel="noreferrer">online converter using iconv</a>.</p> </li> <li><p><a href="https://github.com/rrthomas/recode/" rel="noreferrer">recode</a> (<a href="http://www.informatik.uni-hamburg.de/RZ/software/gnu/utilities/recode_toc.html" rel="noreferrer">manual</a>) suggested by <a href="https://stackoverflow.com/questions/64860/best-way-to-convert-text-files-between-character-sets#64888">Cheekysoft</a> will convert <strong>one or several files in-place</strong>. Example:</p> <pre><code> $ recode UTF8..ISO-8859-15 in.txt </code></pre> <p>This one uses shorter aliases:</p> <pre><code> $ recode utf8..l9 in.txt </code></pre> <p>Recode also supports <em>surfaces</em> which can be used to convert between different line ending types and encodings:</p> <p>Convert newlines from LF (Unix) to CR-LF (DOS):</p> <pre><code> $ recode ../CR-LF in.txt </code></pre> <p>Base64 encode file:</p> <pre><code> $ recode ../Base64 in.txt </code></pre> <p>You can also combine them.</p> <p>Convert a Base64 encoded UTF8 file with Unix line endings to Base64 encoded Latin 1 file with Dos line endings:</p> <pre><code> $ recode utf8/Base64..l1/CR-LF/Base64 file.txt </code></pre> </li> </ul> <p>On Windows with <a href="https://learn.microsoft.com/en-us/powershell/" rel="noreferrer">Powershell</a> (<a href="https://stackoverflow.com/questions/64860/best-way-to-convert-text-files-between-character-sets#64937">Jay Bazuzi</a>):</p> <ul> <li><code>PS C:\&gt; gc -en utf8 in.txt | Out-File -en ascii out.txt</code></li> </ul> <p>(No ISO-8859-15 support though; it says that supported charsets are unicode, utf7, utf8, utf32, ascii, bigendianunicode, default, and oem.)</p> <h2>Edit</h2> <p>Do you mean iso-8859-1 support? Using &quot;String&quot; does this e.g. for vice versa</p> <pre><code>gc -en string in.txt | Out-File -en utf8 out.txt </code></pre> <p>Note: The possible enumeration values are &quot;Unknown, String, Unicode, Byte, BigEndianUnicode, UTF8, UTF7, Ascii&quot;.</p> <ul> <li>CsCvt - <a href="http://www.cscvt.de" rel="noreferrer">Kalytta's Character Set Converter</a> is another great command line based conversion tool for Windows.</li> </ul>
[ { "answer_id": 64878, "author": "Daniel Papasian", "author_id": 7548, "author_profile": "https://Stackoverflow.com/users/7548", "pm_score": 5, "selected": false, "text": "iconv -f FROM-ENCODING -t TO-ENCODING file.txt\n" }, { "answer_id": 64889, "author": "Troels Arvin", "author_id": 4462, "author_profile": "https://Stackoverflow.com/users/4462", "pm_score": 8, "selected": false, "text": "iconv -f ISO-8859-1 -t UTF-8 in.txt > out.txt\n" }, { "answer_id": 64937, "author": "Jay Bazuzi", "author_id": 5314, "author_profile": "https://Stackoverflow.com/users/5314", "pm_score": 5, "selected": false, "text": "Get-Content -Encoding UTF8 FILE-UTF8.TXT | Out-File -Encoding UTF7 FILE-UTF7.TXT\n" }, { "answer_id": 80494, "author": "user15096", "author_id": 15096, "author_profile": "https://Stackoverflow.com/users/15096", "pm_score": 2, "selected": false, "text": "iconv(\"UTF-8\", \"ISO-8859-15\", $input);" }, { "answer_id": 8401721, "author": "Arne Evertsson", "author_id": 16686, "author_profile": "https://Stackoverflow.com/users/16686", "pm_score": 4, "selected": false, "text": ".bashrc" }, { "answer_id": 10933885, "author": "Jeremy Glover", "author_id": 524314, "author_profile": "https://Stackoverflow.com/users/524314", "pm_score": 4, "selected": false, "text": "\"Encoding\"" }, { "answer_id": 32861628, "author": "Boop", "author_id": 2282427, "author_profile": "https://Stackoverflow.com/users/2282427", "pm_score": 7, "selected": false, "text": "vim" }, { "answer_id": 39195151, "author": "Serge Stroobandt", "author_id": 2192488, "author_profile": "https://Stackoverflow.com/users/2192488", "pm_score": 4, "selected": false, "text": "utf-8" }, { "answer_id": 40852057, "author": "Maciel Escudero Bombonato", "author_id": 1096326, "author_profile": "https://Stackoverflow.com/users/1096326", "pm_score": 1, "selected": false, "text": "$ native2ascii filename.properties\n" }, { "answer_id": 44788426, "author": "lalthomas", "author_id": 2182047, "author_profile": "https://Stackoverflow.com/users/2182047", "pm_score": 2, "selected": false, "text": "chcp 65001>NUL\ntype ascii.txt > unicode.txt\n" }, { "answer_id": 51036143, "author": "Dorian", "author_id": 407213, "author_profile": "https://Stackoverflow.com/users/407213", "pm_score": 1, "selected": false, "text": "ruby -e \"File.write('output.txt', File.read('input.txt').encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: ''))\"\n" }, { "answer_id": 63176205, "author": "Amr Ali", "author_id": 4208440, "author_profile": "https://Stackoverflow.com/users/4208440", "pm_score": 1, "selected": false, "text": "function Recode($InCharset, $InFile, $OutCharset, $OutFile) {\n # Read input file in the source encoding\n $Encoding = [System.Text.Encoding]::GetEncoding($InCharset)\n $Text = [System.IO.File]::ReadAllText($InFile, $Encoding)\n \n # Write output file in the destination encoding\n $Encoding = [System.Text.Encoding]::GetEncoding($OutCharset) \n [System.IO.File]::WriteAllText($OutFile, $Text, $Encoding)\n}\n\nRecode Windows-1252 \"$pwd\\in.txt\" utf8 \"$pwd\\out.txt\" \n" }, { "answer_id": 64214053, "author": "Marcelo Teixeira Ruggeri", "author_id": 2368184, "author_profile": "https://Stackoverflow.com/users/2368184", "pm_score": 3, "selected": false, "text": "iconv -f $(chardetect input.text | awk '{print $2}') -t utf-8 -o output.text\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64860", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2948/" ]
64,881
<p>During the load of my cocoa application, my program crashes with the messsage EXC_BAD_ACCESS. The stack trace is not helpful. Any clues to how I can find the problem?</p>
[ { "answer_id": 64938, "author": "AlanKley", "author_id": 8761, "author_profile": "https://Stackoverflow.com/users/8761", "pm_score": -1, "selected": false, "text": "#0 0x90a594c7 in objc_msgSend\n#1 0xbffff7b8 in ??\n#2 0x932899d8 in loadNib\n#3 0x932893d9 in +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:]\n#4 0x9328903a in +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:]\n#5 0x93288f7c in +[NSBundle(NSNibLoading) loadNibNamed:owner:]\n#6 0x93288cc3 in NSApplicationMain\n#7 0x00009f80 in main at main.mm:17\n" }, { "answer_id": 209000, "author": "mmalc", "author_id": 23233, "author_profile": "https://Stackoverflow.com/users/23233", "pm_score": 2, "selected": false, "text": "@interface MyClass : MySuperclass {\n UIClass *myOutlet;\n}\n@property (nonatomic, retain) IBOutlet UIClass *myOutlet;\n@end\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64881", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8761/" ]
64,894
<p>Is it possible to select from <code>show tables</code> in MySQL?</p> <pre><code>SELECT * FROM (SHOW TABLES) AS `my_tables` </code></pre> <p>Something along these lines, though the above does not work (on 5.0.51a, at least).</p>
[ { "answer_id": 64918, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "SELECT ic.Table_Name,\n ic.Column_Name,\n ic.data_Type,\n IFNULL(Character_Maximum_Length,'') AS `Max`,\n ic.Numeric_precision as `Precision`,\n ic.numeric_scale as Scale,\n ic.Character_Maximum_Length as VarCharSize,\n ic.is_nullable as Nulls, \n ic.ordinal_position as OrdinalPos, \n ic.column_default as ColDefault, \n ku.ordinal_position as PK,\n kcu.constraint_name,\n kcu.ordinal_position,\n tc.constraint_type\nFROM INFORMATION_SCHEMA.COLUMNS ic\n left outer join INFORMATION_SCHEMA.key_column_usage ku\n on ku.table_name = ic.table_name\n and ku.column_name = ic.column_name\n left outer join information_schema.key_column_usage kcu\n on kcu.column_name = ic.column_name\n and kcu.table_name = ic.table_name\n left outer join information_schema.table_constraints tc\n on kcu.constraint_name = tc.constraint_name\norder by ic.table_name, ic.ordinal_position;\n" }, { "answer_id": 64921, "author": "Andrew", "author_id": 8871, "author_profile": "https://Stackoverflow.com/users/8871", "pm_score": 6, "selected": false, "text": "SELECT * FROM INFORMATION_SCHEMA.TABLES" }, { "answer_id": 64945, "author": "Sören Kuklau", "author_id": 1600, "author_profile": "https://Stackoverflow.com/users/1600", "pm_score": 2, "selected": false, "text": "SELECT * FROM INFORMATION_SCHEMA.TABLES\n" }, { "answer_id": 64946, "author": "Derek B. Bell", "author_id": 8944, "author_profile": "https://Stackoverflow.com/users/8944", "pm_score": 1, "selected": false, "text": "SELECT * FROM" }, { "answer_id": 64994, "author": "Lucas Oman", "author_id": 6726, "author_profile": "https://Stackoverflow.com/users/6726", "pm_score": 4, "selected": false, "text": "INFORMATION_SCHEMA" }, { "answer_id": 4108393, "author": "Brian", "author_id": 498605, "author_profile": "https://Stackoverflow.com/users/498605", "pm_score": 2, "selected": false, "text": "SELECT column_comment FROM information_schema.columns WHERE table_name = 'myTable' AND column_name = 'myColumnName'\n" }, { "answer_id": 8561638, "author": "Srdjan", "author_id": 1105899, "author_profile": "https://Stackoverflow.com/users/1105899", "pm_score": 2, "selected": false, "text": "SELECT concat('DROP TABLE ', table_name, ';') FROM INFORMATION_SCHEMA.TABLES\nWHERE table_schema = '*name_of_your_database*'\nAND table_name LIKE 'wp_old_%';\n" }, { "answer_id": 16576049, "author": "MT467", "author_id": 2183883, "author_profile": "https://Stackoverflow.com/users/2183883", "pm_score": 2, "selected": false, "text": "show tables like 'user%';\n" }, { "answer_id": 16576727, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 3, "selected": false, "text": "SHOW" }, { "answer_id": 18019612, "author": "Bob Stein", "author_id": 673991, "author_profile": "https://Stackoverflow.com/users/673991", "pm_score": 3, "selected": false, "text": "$pdo = new PDO(\"mysql:host=$host;dbname=$dbname\",$user,$pass);\nforeach ($pdo->query(\"SHOW TABLES\") as $row) {\n print \"Table $row[Tables_in_$dbname]\\n\";\n}\n" }, { "answer_id": 28628228, "author": "Ivan Ferrer", "author_id": 3455502, "author_profile": "https://Stackoverflow.com/users/3455502", "pm_score": 4, "selected": false, "text": "SELECT COUNT(*) as total FROM (SELECT TABLE_NAME as tab, TABLES.* FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='database_name' GROUP BY tab) tables;\n" }, { "answer_id": 46242383, "author": "Bridget Arrington", "author_id": 355838, "author_profile": "https://Stackoverflow.com/users/355838", "pm_score": 2, "selected": false, "text": "CREATE PROCEDURE `ShowFromTables`()\nBEGIN\n\nDECLARE v_finished INTEGER DEFAULT 0;\nDECLARE c_table varchar(100) DEFAULT \"\";\n\nDECLARE table_cursor CURSOR FOR \nSELECT table_name FROM information_schema.tables WHERE table_name like 'wp_1%';\n\nDECLARE CONTINUE HANDLER \n FOR NOT FOUND SET v_finished = 1;\n\nOPEN table_cursor;\n\nget_data: LOOP\n\nFETCH table_cursor INTO c_table;\n\nIF v_finished = 1 THEN \nLEAVE get_data;\nEND IF;\n\nSET @s=CONCAT(\"SELECT * FROM \",c_table,\";\");\n\nPREPARE stmt FROM @s;\nEXECUTE stmt;\nDEALLOCATE PREPARE stmt;\n\nEND LOOP get_data;\n\nCLOSE table_cursor;\n\nEND\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
64,904
<p>I need to support exact phrases (enclosed in quotes) in an otherwise space-separated list of terms. Thus splitting the respective string by the space-character is not sufficient anymore.</p> <p>Example:</p> <pre><code>input : 'foo bar "lorem ipsum" baz' output: ['foo', 'bar', 'lorem ipsum', 'baz'] </code></pre> <p>I wonder whether this could be achieved with a single RegEx, rather than performing complex parsing or split-and-rejoin operations.</p> <p>Any help would be greatly appreciated!</p>
[ { "answer_id": 65033, "author": "shyam", "author_id": 7616, "author_profile": "https://Stackoverflow.com/users/7616", "pm_score": 1, "selected": false, "text": "'foo bar \"lorem ipsum\" baz'.match(/\"[^\"]*\"|\\w+/g);\n" }, { "answer_id": 65085, "author": "A Nony Mouse", "author_id": 7182, "author_profile": "https://Stackoverflow.com/users/7182", "pm_score": 2, "selected": false, "text": "'foo bar \"lorem ipsum\" baz'.match(/(\"[^\"]*\")|([^\\s\"]+)/g)\noutput: ['foo', 'bar', '\"lorem ipsum\"', 'baz']\n" }, { "answer_id": 65092, "author": "davidnicol", "author_id": 7420, "author_profile": "https://Stackoverflow.com/users/7420", "pm_score": 1, "selected": false, "text": "output = /(\".+?\"|\\w+)/g.exec(input)\n" }, { "answer_id": 65177, "author": "yoz", "author_id": 9070, "author_profile": "https://Stackoverflow.com/users/9070", "pm_score": 5, "selected": true, "text": "var str = 'foo bar \"lorem ipsum\" baz'; \nvar results = str.match(/(\"[^\"]+\"|[^\"\\s]+)/g);\n" }, { "answer_id": 65338, "author": "Sam Hasler", "author_id": 2541, "author_profile": "https://Stackoverflow.com/users/2541", "pm_score": 2, "selected": false, "text": "var input = 'foo bar \"lorem ipsum\" baz';\nvar R = /(\\w|\\s)*\\w(?=\")|\\w+/g;\nvar output = input.match(R);\n\noutput is [\"foo\", \"bar\", \"lorem ipsum\", \"baz\"]\n" }, { "answer_id": 65577, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "var input = 'foo bar \"lorem ipsum\" baz';\n\noutput = input.match(/(\"[^\"]+\"|[^\"\\s]+)/g);\noutput = input.match(/\"[^\"]*\"|\\w+/g);\noutput = input.match(/(\"[^\"]*\")|([^\\s\"]+)/g)\noutput = /(\".+?\"|\\w+)/g.exec(input);\noutput = /\"(.+?)\"|(\\w+)/g.exec(input);\n" }, { "answer_id": 16945284, "author": "tigerswithguitars", "author_id": 726986, "author_profile": "https://Stackoverflow.com/users/726986", "pm_score": 0, "selected": false, "text": "\"hello my name is 'jon delaware smith fred' I have a 'long name'\"" }, { "answer_id": 26626761, "author": "Suganthan Madhavan Pillai", "author_id": 2534236, "author_profile": "https://Stackoverflow.com/users/2534236", "pm_score": 0, "selected": false, "text": "([\\w]+|\\\"[\\w\\s]+\\\")\n" }, { "answer_id": 46946542, "author": "Tsuneo Yoshioka", "author_id": 1309218, "author_profile": "https://Stackoverflow.com/users/1309218", "pm_score": 1, "selected": false, "text": "input.match(/\\\\?.|^$/g).reduce((p, c) => {\n if(c === '\"'){\n p.quote ^= 1;\n }else if(!p.quote && c === ' '){\n p.a.push('');\n }else{\n p.a[p.a.length-1] += c.replace(/\\\\(.)/,\"$1\");\n }\n return p;\n }, {a: ['']}).a\n" }, { "answer_id": 64447893, "author": "Rob Hawkins", "author_id": 2636364, "author_profile": "https://Stackoverflow.com/users/2636364", "pm_score": 0, "selected": false, "text": "const matchOrIncludes = (str, search, useMatch = true) => {\n if (useMatch) {\n let result = false\n try {\n result = str.match(search)\n } catch (err) {\n return false\n }\n return result\n }\n return str.includes(search)\n}\n\n\nconst itemMatches = (item, searchString, fields) => {\n const keywords = searchString.toString().replace(/\\s\\s+/g, ' ').trim().toLocaleLowerCase().match(/(-?\"[^\"]+\"|[^\"\\s]+)/g) || []\n for (let i = 0; i < keywords.length; i++) {\n const negateWord = keywords[i].startsWith('-') ? true : false\n let word = keywords[i].replace(/^-/,'')\n const isPhraseRegex = word.startsWith('\"') ? true : false\n if (isPhraseRegex) {\n word = word.replace(/^\"(.+)\"$/,\"$1\")\n }\n let word_in_item = false\n for (const field of fields) {\n if (item[field] && matchOrIncludes(item[field].toLocaleLowerCase(), word, isPhraseRegex)) {\n word_in_item = true\n break\n }\n }\n if ((! negateWord && ! word_in_item) || (negateWord && word_in_item)) {\n return false\n }\n }\n return true\n}\n\nconst item = {title: 'My title', body: 'Some text'}\nconsole.log(itemMatches(item, 'text', ['title', 'body']))" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64904", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
64,958
<p>Yacc does not permit objects to be passed around. Because the %union can only contain POD types, complex objects must be new'd and passed around by pointer. If a syntax error occurs, the yacc parser just stops running, and references to all of those created objects are lost.</p> <p>The only solution I've come up with is that all new'd object inherit a particular base class, be added to a container when allocated, and if there is an error everything in that container can be deleted.</p> <p>Does anyone know of any better yacc tricks to solve this problem?</p> <p>Please don't tell me to choose a different parser.</p>
[ { "answer_id": 65424, "author": "Michael L Perry", "author_id": 7668, "author_profile": "https://Stackoverflow.com/users/7668", "pm_score": 3, "selected": true, "text": "class IExpressionOwner\n{\npublic:\n virtual ExpressionAdd *newExpressionAdd() = 0;\n virtual ExpressionSubstract *newExpressionSubtract() = 0;\n virtual ExpressionMultiply *newExpressionMultiply() = 0;\n virtual ExpressionDivide *newExpressionDivide() = 0;\n};\n\nclass ExpressionAdd : public Expression, public IExpressionOwner\n{\nprivate:\n std::auto_ptr<Expression> left;\n std::auto_ptr<Expression> right;\n\npublic:\n ExpressionAdd *newExpressionAdd()\n {\n ExpressionAdd *newExpression = new ExpressionAdd();\n std::auto_ptr<Expression> autoPtr(newExpression);\n if (left.get() == NULL)\n left = autoPtr;\n else\n right = autoPtr;\n return newExpression;\n }\n\n ...\n};\n\nclass Parser\n{\nprivate:\n std::stack<IExpressionOwner *> expressionOwner;\n\n ...\n};\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64958", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8566/" ]
64,977
<p>How do you create SQL Server 2005 stored procedure templates in SQL Server 2005 Management Studio?</p>
[ { "answer_id": 64997, "author": "Chris Woodruff", "author_id": 7001, "author_profile": "https://Stackoverflow.com/users/7001", "pm_score": 5, "selected": true, "text": "-- ======================================================\n-- Create basic stored procedure template with TRY CATCH\n-- ======================================================\n\nSET ANSI_NULLS ON\nGO\nSET QUOTED_IDENTIFIER ON\nGO\n-- =============================================\n-- Author: <Author,,Name>\n-- Create date: <Create Date,,>\n-- Description: <Description,,>\n-- =============================================\nCREATE PROCEDURE <Procedure_Name, sysname, ProcedureName>\n -- Add the parameters for the stored procedure here\n <@Param1, sysname, @p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>,\n <@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>\nAS\n BEGIN TRY\n BEGIN TRANSACTION -- Start the transaction\n\n SELECT @p1, @p2\n\n -- If we reach here, success!\n COMMIT\n END TRY\n BEGIN CATCH\n -- there was an error\n IF @@TRANCOUNT > 0\n ROLLBACK\n\n -- Raise an error with the details of the exception\n DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int\n SELECT @ErrMsg = ERROR_MESSAGE(), @ErrSeverity = ERROR_SEVERITY()\n\n RAISERROR(@ErrMsg, @ErrSeverity, 1)\n END CATCH\nGO\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7001/" ]
64,981
<p>How do I create a unique constraint on an existing table in SQL Server 2005?</p> <p>I am looking for both the TSQL and how to do it in the Database Diagram.</p>
[ { "answer_id": 65003, "author": "Ivan Bosnic", "author_id": 3221, "author_profile": "https://Stackoverflow.com/users/3221", "pm_score": 4, "selected": false, "text": "ALTER TABLE dbo.<tablename> ADD CONSTRAINT\n <namingconventionconstraint> UNIQUE NONCLUSTERED\n (\n <columnname>\n ) ON [PRIMARY]\n" }, { "answer_id": 65022, "author": "Thunder3", "author_id": 2832, "author_profile": "https://Stackoverflow.com/users/2832", "pm_score": 3, "selected": false, "text": "ALTER TABLE dbo.doc_exz\nADD CONSTRAINT col_b_def\nUNIQUE column_b\n" }, { "answer_id": 65047, "author": "WildJoe", "author_id": 9052, "author_profile": "https://Stackoverflow.com/users/9052", "pm_score": 5, "selected": false, "text": "ALTER TABLE [TableName] ADD CONSTRAINT [constraintName] UNIQUE ([columns])\n" }, { "answer_id": 65123, "author": "Rory", "author_id": 8479, "author_profile": "https://Stackoverflow.com/users/8479", "pm_score": 9, "selected": true, "text": "ALTER TABLE <tablename> ADD CONSTRAINT\n <constraintname> UNIQUE NONCLUSTERED\n (\n <columnname>\n )\n" }, { "answer_id": 537780, "author": "Squirrel", "author_id": 11835, "author_profile": "https://Stackoverflow.com/users/11835", "pm_score": 4, "selected": false, "text": "CREATE UNIQUE NONCLUSTERED INDEX idx_col1\nON dbo.MyTable(col1)\nWHERE col1 IS NOT NULL;\n" }, { "answer_id": 27223345, "author": "Rafiq", "author_id": 847501, "author_profile": "https://Stackoverflow.com/users/847501", "pm_score": 3, "selected": false, "text": "ALTER TABLE TableName ADd UNIQUE (ColumnName1,ColumnName2, ColumnName3, ...)\n" }, { "answer_id": 49405468, "author": "Mario Vázquez", "author_id": 8928707, "author_profile": "https://Stackoverflow.com/users/8928707", "pm_score": 0, "selected": false, "text": "IF Exists(SELECT * FROM sys.indexes WHERE name Like '<index_name>')\n ALTER TABLE dbo.<target_table_name> DROP CONSTRAINT <index_name> \nGO\n\nALTER TABLE dbo.<target_table_name> ADD CONSTRAINT <index_name> UNIQUE NONCLUSTERED (<col_1>, <col_2>, ..., <col_n>) \nGO\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2469/" ]
64,989
<p>What could be the cause of JVM thread dumps that show threads waiting to lock on a monitor, but the monitors do not have corresponding locking threads? </p> <p>Java 1.5_14 on Windows 2003</p>
[ { "answer_id": 79671, "author": "tgdavies", "author_id": 11002, "author_profile": "https://Stackoverflow.com/users/11002", "pm_score": 1, "selected": false, "text": "-verbose:gc with -XX:+PrintGCDetails" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8530/" ]
64,992
<p>I'm working with a support person who is supposed to be able to install SSL certs on a web server he maintains. He has local admin rights to the server via a domain security group. He also has permissions on our internal CA running Windows 2003 Server Certificate Authority: "Request cert" and "Issue and Manage certs".</p> <p>The server he's working with is running Windows 2000 SP4 / IIS 5. When he attempts to create an online server cert the IIS wizard ends with "Failed to install. Access is Denied.". The event viewer is not working properly, so I can't find any details there. I suspect the permission issue is locally and not with the CA.</p> <p>My account is a domain admin account and I know I am able to do this operation, however I need to make this work for others that are not domain admins.</p> <p>Any ideas why he can't perform this operation?</p>
[ { "answer_id": 65542, "author": "JWHEAT", "author_id": 7079, "author_profile": "https://Stackoverflow.com/users/7079", "pm_score": 3, "selected": false, "text": "\\Documents and Settings\\All Users\\Application Data\\Microsoft\\Crypto\\RSA\\MachineKeys\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64992", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3347/" ]
65,001
<p>What sort of database schema would you use to store email messages, with as much header information as practical/possible, into a database?</p> <p>Assume that they have been fed into a script from the MTA and parsed into the relevant headers/body/attachments.</p> <p>Would you store the message body whole in the database table, or split any MIME-parts apart? What about attachments?</p>
[ { "answer_id": 4149301, "author": "Gareth Rees", "author_id": 68063, "author_profile": "https://Stackoverflow.com/users/68063", "pm_score": 2, "selected": false, "text": "In-Reply-To" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65001", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6216/" ]
65,008
<p>I am experimenting with using the FaultException and FaultException&lt;T&gt; to determine the best usage pattern in our applications. We need to support WCF as well as non-WCF service consumers/clients, including SOAP 1.1 and SOAP 1.2 clients.</p> <p>FYI: using FaultExceptions with wsHttpBinding results in SOAP 1.2 semantics whereas using FaultExceptions with basicHttpBinding results in SOAP 1.1 semantics. </p> <p>I am using the following code to throw a FaultException&lt;FaultDetails&gt;:</p> <pre><code> throw new FaultException&lt;FaultDetails&gt;( new FaultDetails("Throwing FaultException&lt;FaultDetails&gt;."), new FaultReason("Testing fault exceptions."), FaultCode.CreateSenderFaultCode(new FaultCode("MySubFaultCode")) ); </code></pre> <p>The FaultDetails class is just a simple test class that contains a string "Message" property as you can see below.</p> <p>When using wsHttpBinding the response is:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-16"?&gt; &lt;Fault xmlns="http://www.w3.org/2003/05/soap-envelope"&gt; &lt;Code&gt; &lt;Value&gt;Sender&lt;/Value&gt; &lt;Subcode&gt; &lt;Value&gt;MySubFaultCode&lt;/Value&gt; &lt;/Subcode&gt; &lt;/Code&gt; &lt;Reason&gt; &lt;Text xml:lang="en-US"&gt;Testing fault exceptions.&lt;/Text&gt; &lt;/Reason&gt; &lt;Detail&gt; &lt;FaultDetails xmlns="http://schemas.datacontract.org/2004/07/ClassLibrary" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;Message&gt;Throwing FaultException&amp;lt;FaultDetails&amp;gt;.&lt;/Message&gt; &lt;/FaultDetails&gt; &lt;/Detail&gt; </code></pre> <p></p> <p>This looks right according to the SOAP 1.2 specs. The main/root “Code” is “Sender”, which has a “Subcode” of “MySubFaultCode”. If the service consumer/client is using WCF the FaultException on the client side also mimics the same structure, with the faultException.Code.Name being “Sender” and faultException.Code.SubCode.Name being “MySubFaultCode”.</p> <p>When using basicHttpBinding the response is:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-16"?&gt; &lt;s:Fault xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;faultcode&gt;s:MySubFaultCode&lt;/faultcode&gt; &lt;faultstring xml:lang="en-US"&gt;Testing fault exceptions.&lt;/faultstring&gt; &lt;detail&gt; &lt;FaultDetails xmlns="http://schemas.datacontract.org/2004/07/ClassLibrary" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;Message&gt;Throwing FaultException&amp;lt;FaultDetails&amp;gt;.&lt;/Message&gt; &lt;/FaultDetails&gt; &lt;/detail&gt; &lt;/s:Fault&gt; </code></pre> <p>This does not look right. Looking at the SOAP 1.1 specs, I was expecting to see the “faultcode” to have a value of “s:Client.MySubFaultCode” when I use FaultCode.CreateSenderFaultCode(new FaultCode("MySubFaultCode")). Also a WCF client gets an incorrect structure. The faultException.Code.Name is “MySubFaultCode” instead of being “Sender”, and the faultException.Code.SubCode is null instead of faultException.Code.SubCode.Name being “MySubFaultCode”. Also, the faultException.Code.IsSenderFault is false.</p> <p>Similar problem when using FaultCode.CreateReceiverFaultCode(new FaultCode("MySubFaultCode")):</p> <ul> <li>works as expected for SOAP 1.2</li> <li>generates “s:MySubFaultCode” instead of “s:Server.MySubFaultCode” and the faultException.Code.IsReceiverFault is false for SOAP 1.1</li> </ul> <p>This item was also posted by someone else on <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=669420&amp;SiteID=1" rel="nofollow noreferrer">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=669420&amp;SiteID=1</a> in 2006 and no one has answered it. I find it very hard to believe that no one has run into this, yet. </p> <p>Here is someone else having a similar problem: <a href="http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3883110&amp;SiteID=1&amp;mode=1" rel="nofollow noreferrer">http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3883110&amp;SiteID=1&amp;mode=1</a></p> <p>Microsoft Connect bug: <a href="https://connect.microsoft.com/wcf/feedback/ViewFeedback.aspx?FeedbackID=367963" rel="nofollow noreferrer">https://connect.microsoft.com/wcf/feedback/ViewFeedback.aspx?FeedbackID=367963</a></p> <p>Description of how faults should work: <a href="http://blogs.msdn.com/drnick/archive/2006/12/19/creating-faults-part-3.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/drnick/archive/2006/12/19/creating-faults-part-3.aspx</a></p> <p>Am I doing something wrong or is this truly a bug in WCF?</p>
[ { "answer_id": 69390, "author": "wojo", "author_id": 9022, "author_profile": "https://Stackoverflow.com/users/9022", "pm_score": 4, "selected": true, "text": " /// <summary>\n /// Replacement for the static methods on FaultCode to generate Sender and Receiver fault codes due\n /// to what seems like bugs in the implementation for basicHttpBinding (SOAP 1.1). wsHttpBinding \n /// (SOAP 1.2) seems to work just fine.\n /// \n /// The subCode parameter for FaultCode.CreateReceiverFaultCode and FaultCode.CreateSenderFaultCode\n /// seem to take over the main 'faultcode' value in the SOAP 1.1 response, whereas in SOAP 1.2 the\n /// subCode is correctly put under the 'Code->SubCode->Value' value in the XML response.\n /// \n /// This workaround is to create the FaultCode with Sender/Receiver (SOAP 1.2 terms, but gets\n /// translated by WCF depending on the binding) and an agnostic namespace found by using reflector\n /// on the FaultCode class. When that NS is passed in WCF seems to be able to generate the proper\n /// response with SOAP 1.1 (Client/Server) and SOAP 1.2 (Sender/Receiver) fault codes automatically.\n /// \n /// This means that it is not possible to create a FaultCode that works in both bindings with\n /// subcodes.\n /// </summary>\n /// <remarks>\n /// See http://stackoverflow.com/questions/65008/net-wcf-faults-generating-incorrect-soap-11-faultcode-values\n /// for more details.\n /// </remarks>\n public static class FaultCodeFactory\n {\n private const string _ns = \"http://schemas.microsoft.com/ws/2005/05/envelope/none\";\n\n /// <summary>\n /// Creates a sender fault code.\n /// </summary>\n /// <returns>A FaultCode object.</returns>\n /// <remarks>Does not support subcodes due to a WCF bug.</remarks>\n public static FaultCode CreateSenderFaultCode()\n {\n return new FaultCode(\"Sender\", _ns);\n }\n\n /// <summary>\n /// Creates a receiver fault code.\n /// </summary>\n /// <returns>A FaultCode object.</returns>\n /// <remarks>Does not support subcodes due to a WCF bug.</remarks>\n public static FaultCode CreateReceiverFaultCode()\n {\n return new FaultCode(\"Receiver\", _ns);\n }\n }\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65008", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9022/" ]
65,034
<p>How would I remove the border from an iframe embedded in my web app? An example of the iframe is:</p> <pre><code>&lt;iframe src="myURL" width="300" height="300"&gt;Browser not compatible.&lt;/iframe&gt; </code></pre> <p>I would like the transition from the content on my page to the contents of the iframe to be seamless, assuming the background colors are consistent. The target browser is IE6 only and unfortunately solutions for others will not help.</p>
[ { "answer_id": 65052, "author": "David Basarab", "author_id": 2469, "author_profile": "https://Stackoverflow.com/users/2469", "pm_score": 11, "selected": true, "text": "frameBorder" }, { "answer_id": 65126, "author": "xenox", "author_id": 8952, "author_profile": "https://Stackoverflow.com/users/8952", "pm_score": 6, "selected": false, "text": "<iframe src=\"myURL\" width=\"300\" height=\"300\" frameBorder=\"0\" scrolling=\"no\">Browser not compatible. </iframe > \n" }, { "answer_id": 257406, "author": "Adam", "author_id": 33503, "author_profile": "https://Stackoverflow.com/users/33503", "pm_score": 7, "selected": false, "text": "<iframe frameBorder=\"0\"></iframe>\n" }, { "answer_id": 4861373, "author": "Marnix Bras", "author_id": 598204, "author_profile": "https://Stackoverflow.com/users/598204", "pm_score": 5, "selected": false, "text": "frameborder=\"0\" hspace=\"0\" vspace=\"0\" marginheight=\"0\" marginwidth=\"0\"" }, { "answer_id": 8437926, "author": "Roberto Chiaretti", "author_id": 1088611, "author_profile": "https://Stackoverflow.com/users/1088611", "pm_score": 7, "selected": false, "text": "<iframe src=\"test.html\" style=\"width: 100%; height: 400px; border: 0\"></iframe>\n" }, { "answer_id": 8979112, "author": "FirstFraktal", "author_id": 1165845, "author_profile": "https://Stackoverflow.com/users/1165845", "pm_score": 3, "selected": false, "text": "// =========================================================================\n// Remove borders on iFrames\n\nvar iFrameElements = window.document.getElementsByTagName(\"iframe\");\nfor (var i = 0; i < iFrameElements.length; i++)\n{\n iFrameElements[i].frameBorder=\"0\"; // For other browsers.\n iFrameElements[i].setAttribute(\"frameBorder\", \"0\"); // For other browsers (just a backup for the above).\n iFrameElements[i].contentWindow.document.body.style.border=\"none\"; // For IE.\n}\n" }, { "answer_id": 17451583, "author": "David Tuite", "author_id": 574190, "author_profile": "https://Stackoverflow.com/users/574190", "pm_score": 3, "selected": false, "text": "seamless" }, { "answer_id": 21143344, "author": "master of dissaster", "author_id": 3199154, "author_profile": "https://Stackoverflow.com/users/3199154", "pm_score": -1, "selected": false, "text": "iframe src=\"XXXXXXXXXXXXXXX\"\nmarginwidth=\"0\" marginheight=\"0\" width=\"xxx\" height=\"xxx\"\n" }, { "answer_id": 24192742, "author": "th0ward", "author_id": 3415690, "author_profile": "https://Stackoverflow.com/users/3415690", "pm_score": 3, "selected": false, "text": "* {\n padding:0px;\n margin:0px;\n }\n" }, { "answer_id": 24671048, "author": "Shubham Badal", "author_id": 2634872, "author_profile": "https://Stackoverflow.com/users/2634872", "pm_score": 3, "selected": false, "text": "<iframe src=\"http://example.org\" width=\"200\" height=\"200\" style=\"border:0\">\n" }, { "answer_id": 28573794, "author": "Tropilac", "author_id": 4391687, "author_profile": "https://Stackoverflow.com/users/4391687", "pm_score": 3, "selected": false, "text": "{\n padding:0px;\n margin:0px;\n border: 0px\n\n}\n" }, { "answer_id": 33294377, "author": "Shan Eapen Koshy", "author_id": 3284379, "author_profile": "https://Stackoverflow.com/users/3284379", "pm_score": 4, "selected": false, "text": "style=\"border:0;\"" }, { "answer_id": 36028076, "author": "Harden Rahul", "author_id": 4956341, "author_profile": "https://Stackoverflow.com/users/4956341", "pm_score": 3, "selected": false, "text": "<iframe src=\"myURL\" width=\"300\" height=\"300\" frameBorder=\"0\">Browser not compatible. </iframe>\n" }, { "answer_id": 38487002, "author": "Michael Herr", "author_id": 6614949, "author_profile": "https://Stackoverflow.com/users/6614949", "pm_score": 3, "selected": false, "text": "<body style=\"margin:0px;\">\n" }, { "answer_id": 39307736, "author": "IamGuest", "author_id": 6790845, "author_profile": "https://Stackoverflow.com/users/6790845", "pm_score": 3, "selected": false, "text": "<iframe src=\"mywebsite\" frameborder=\"0\" style=\"border: 0px solid white;\">HTML iFrame is not compatible with your browser</iframe>\n" }, { "answer_id": 41484926, "author": "Ajesh Kolakkadan", "author_id": 7271451, "author_profile": "https://Stackoverflow.com/users/7271451", "pm_score": 2, "selected": false, "text": " <iframe src=\"yoururl\" width=\"100%\" height=\"100%\" frameBorder=\"0\"></iframe>\n" }, { "answer_id": 42175307, "author": "Arpan Saini", "author_id": 7353562, "author_profile": "https://Stackoverflow.com/users/7353562", "pm_score": 3, "selected": false, "text": "<iframe src=\"demo.htm\" style=\"border:none;\"></iframe>\n" }, { "answer_id": 44858921, "author": "Amaan Iqbal", "author_id": 8176563, "author_profile": "https://Stackoverflow.com/users/8176563", "pm_score": 2, "selected": false, "text": "<iframe src=\"url\" style=\"border:none;\"></iframe>\n" }, { "answer_id": 45252756, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<iframe src=\"myURL\" width=\"300\" height=\"300\" style=\"border: none\">Browser not compatible.</iframe>\n" }, { "answer_id": 46261906, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "style=\"border:none;\n" }, { "answer_id": 48166005, "author": "Divya Chugh", "author_id": 9192311, "author_profile": "https://Stackoverflow.com/users/9192311", "pm_score": 3, "selected": false, "text": "<iframe src=\"myURL\" width=\"300\" height=\"300\" style=\"border-width:0px;\">Browser not compatible.</iframe>\n\n<iframe src=\"myURL\" width=\"300\" height=\"300\" frameborder=\"0\">Browser not compatible.</iframe>\n\n<iframe src=\"myURL\" width=\"300\" height=\"300\" style=\"border:none;\">Browser not compatible.</iframe>" }, { "answer_id": 48856587, "author": "Chetan Chauhan", "author_id": 7570937, "author_profile": "https://Stackoverflow.com/users/7570937", "pm_score": 2, "selected": false, "text": "<iframe src=\"\" width=\"200\" height=\"200\" frameborder=\"0\"></iframe>" }, { "answer_id": 52228749, "author": "Md Shahriar", "author_id": 4211947, "author_profile": "https://Stackoverflow.com/users/4211947", "pm_score": -1, "selected": false, "text": "<iframe src=\"URL\" frameborder=\"0\" width=\"100%\" height=\"200\">\n<p>Your browser does not support iframes.</p>\n</iframe>\n\n<iframe frameborder=\"1|0\">\n\n(OR)\n\n<iframe src=\"URL\" width=\"100%\" height=\"300\" style=\"border: none\">Your browser \ndoes not support iframes.</iframe>\n\nThe <iframe> frameborder attribute is not supported in HTML5. Use CSS \ninstead.\n" }, { "answer_id": 60167355, "author": "Samir Lakhani", "author_id": 6128516, "author_profile": "https://Stackoverflow.com/users/6128516", "pm_score": 2, "selected": false, "text": " <iframe src=\"display_file.html\" style=\"height: 400px; width:\n 100%;border: 0;\">HTML iFrame is not compatible with your browser\n </iframe>\n" }, { "answer_id": 60772418, "author": "menepet", "author_id": 3074131, "author_profile": "https://Stackoverflow.com/users/3074131", "pm_score": 0, "selected": false, "text": "display:block;" }, { "answer_id": 70296032, "author": "Japi Sandhu", "author_id": 7989522, "author_profile": "https://Stackoverflow.com/users/7989522", "pm_score": 2, "selected": false, "text": ".iframe{\nbox-shadow: none !important;\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65034", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2650/" ]
65,035
<p>Considering this code, can I be <em>absolutely sure</em> that the <code>finally</code> block always executes, no matter what <code>something()</code> is?</p> <pre><code>try { something(); return success; } catch (Exception e) { return failure; } finally { System.out.println("I don't know if this will get printed out"); } </code></pre>
[ { "answer_id": 65049, "author": "jodonnell", "author_id": 4223, "author_profile": "https://Stackoverflow.com/users/4223", "pm_score": 13, "selected": true, "text": "finally" }, { "answer_id": 65185, "author": "Kevin", "author_id": 1058366, "author_profile": "https://Stackoverflow.com/users/1058366", "pm_score": 9, "selected": false, "text": "public static void main(String[] args) {\n System.out.println(Test.test());\n}\n\npublic static int test() {\n try {\n return 0;\n }\n finally {\n System.out.println(\"something is printed\");\n }\n}\n" }, { "answer_id": 65282, "author": "user9189", "author_id": 9189, "author_profile": "https://Stackoverflow.com/users/9189", "pm_score": 4, "selected": false, "text": "System.exit(0)" }, { "answer_id": 65362, "author": "MooBob42", "author_id": 9271, "author_profile": "https://Stackoverflow.com/users/9271", "pm_score": 9, "selected": false, "text": "try { return true; } finally { return false; }\n" }, { "answer_id": 296053, "author": "vibhash", "author_id": 38266, "author_profile": "https://Stackoverflow.com/users/38266", "pm_score": 7, "selected": false, "text": "public static void main(final String[] args) {\n System.out.println(test());\n}\n\npublic static int test() {\n int i = 0;\n try {\n i = 2;\n return i;\n } finally {\n i = 12;\n System.out.println(\"finally trumps return.\");\n }\n}\n" }, { "answer_id": 2824754, "author": "Motti", "author_id": 3848, "author_profile": "https://Stackoverflow.com/users/3848", "pm_score": 4, "selected": false, "text": "try" }, { "answer_id": 2824758, "author": "Jay Riggs", "author_id": 52249, "author_profile": "https://Stackoverflow.com/users/52249", "pm_score": 3, "selected": false, "text": "System.exit()" }, { "answer_id": 2824759, "author": "Chris Cooper", "author_id": 300807, "author_profile": "https://Stackoverflow.com/users/300807", "pm_score": 6, "selected": false, "text": "System.exit(int)" }, { "answer_id": 2824998, "author": "Eyal Schneider", "author_id": 196211, "author_profile": "https://Stackoverflow.com/users/196211", "pm_score": 7, "selected": false, "text": "public static int getMonthsInYear() {\n try {\n return 10;\n }\n finally {\n return 12;\n }\n}\n" }, { "answer_id": 2902505, "author": "Wasim", "author_id": 349636, "author_profile": "https://Stackoverflow.com/users/349636", "pm_score": 3, "selected": false, "text": "public static int test() {\n int i = 0;\n try {\n return i;\n } finally {\n i = 12;\n System.out.println(\"finally trumps return.\");\n return i;\n }\n}\n" }, { "answer_id": 2902578, "author": "polygenelubricants", "author_id": 276101, "author_profile": "https://Stackoverflow.com/users/276101", "pm_score": 8, "selected": false, "text": "try" }, { "answer_id": 10188271, "author": "eric2323223", "author_id": 44512, "author_profile": "https://Stackoverflow.com/users/44512", "pm_score": 2, "selected": false, "text": "public class TestTryCatchFinally {\n static int x = 0;\n\n public static void main(String[] args){\n System.out.println(f1() );\n System.out.println(f2() );\n }\n\n public static int f1(){\n try{\n x = 1;\n return x;\n }finally{\n x = 2;\n }\n }\n\n public static int f2(){\n return x;\n }\n}\n" }, { "answer_id": 17634958, "author": "Rajendra Jadi", "author_id": 2287871, "author_profile": "https://Stackoverflow.com/users/2287871", "pm_score": 4, "selected": false, "text": " class A {\n public static void main(String args[]){\n DataInputStream cin = new DataInputStream(System.in);\n try{\n int i=Integer.parseInt(cin.readLine());\n }catch(ArithmeticException e){\n }catch(Exception e){\n System.exit(0);//Program terminates before executing finally block\n }finally{\n System.out.println(\"Won't be executed\");\n System.out.println(\"No error\");\n }\n }\n}\n" }, { "answer_id": 20363941, "author": "WoodenKitty", "author_id": 2684342, "author_profile": "https://Stackoverflow.com/users/2684342", "pm_score": 7, "selected": false, "text": "finally" }, { "answer_id": 27540550, "author": "Utkarsh Bhatt", "author_id": 3201107, "author_profile": "https://Stackoverflow.com/users/3201107", "pm_score": 3, "selected": false, "text": "finally" }, { "answer_id": 30213111, "author": "milton", "author_id": 873900, "author_profile": "https://Stackoverflow.com/users/873900", "pm_score": 3, "selected": false, "text": "try { \n System.out.println(\"try\"); \n return;\n //int i =5/0;\n //System.exit(0 ) ;\n} catch (Exception e) { \n System.out.println(\"catch\");\n return;\n //int i =5/0;\n //System.exit(0 ) ;\n} finally { \n System.out.println(\"Print me FINALLY\");\n}\n" }, { "answer_id": 34240980, "author": "Anonymous Coward", "author_id": 956880, "author_profile": "https://Stackoverflow.com/users/956880", "pm_score": 4, "selected": false, "text": "try" }, { "answer_id": 36116269, "author": "dkb", "author_id": 2987755, "author_profile": "https://Stackoverflow.com/users/2987755", "pm_score": 3, "selected": false, "text": "public static void main(String args[]) throws Exception {\n Object obj = new Object();\n try {\n synchronized (obj) {\n obj.wait();\n System.out.println(\"after wait()\");\n }\n } catch (Exception ignored) {\n } finally {\n System.out.println(\"finally\");\n }\n}\n" }, { "answer_id": 36926373, "author": "HopefullyHelpful", "author_id": 5191731, "author_profile": "https://Stackoverflow.com/users/5191731", "pm_score": 2, "selected": false, "text": "finally" }, { "answer_id": 38187529, "author": "dibo", "author_id": 6547976, "author_profile": "https://Stackoverflow.com/users/6547976", "pm_score": 2, "selected": false, "text": "static int f() {\n while (true) {\n try {\n return 1;\n } finally {\n break;\n }\n }\n return 2;\n}\n" }, { "answer_id": 38930134, "author": "Meet Vora", "author_id": 5373110, "author_profile": "https://Stackoverflow.com/users/5373110", "pm_score": 3, "selected": false, "text": "try{\n int divideByZeroException = 5 / 0;\n} catch (Exception e){\n System.out.println(\"catch\");\n return; // also tried with break; in switch-case, got same output\n} finally {\n System.out.println(\"finally\");\n}\n" }, { "answer_id": 39462828, "author": "Akash Manngroliya", "author_id": 5089473, "author_profile": "https://Stackoverflow.com/users/5089473", "pm_score": 2, "selected": false, "text": "try{\n//risky code\n}catch(Exception e){\n//exception handling code\n}\nfinally(){\n//It always execute but before this block if there is any statement like System.exit(0); then this block not execute.\n}\n" }, { "answer_id": 47847227, "author": "Dávid Horváth", "author_id": 3948862, "author_profile": "https://Stackoverflow.com/users/3948862", "pm_score": 3, "selected": false, "text": "finally" }, { "answer_id": 49752573, "author": "Pradeep Kumaresan", "author_id": 2851699, "author_profile": "https://Stackoverflow.com/users/2851699", "pm_score": 3, "selected": false, "text": "public static void main(String[] args) {\n System.out.println(test().toString());\n}\n\npublic static StringBuffer test() {\n StringBuffer s = new StringBuffer();\n try {\n s.append(\"sb\");\n return s;\n } finally {\n s.append(\"updated \");\n }\n}\n" }, { "answer_id": 49850492, "author": "Poorna Senani Gamage", "author_id": 8111997, "author_profile": "https://Stackoverflow.com/users/8111997", "pm_score": 3, "selected": false, "text": "try" }, { "answer_id": 50096809, "author": "sam", "author_id": 7538821, "author_profile": "https://Stackoverflow.com/users/7538821", "pm_score": 3, "selected": false, "text": "public class SomeTest {\n\n private static StringBuilder sb = new StringBuilder();\n\n public static void main(String args[]) {\n\n System.out.println(someString());\n System.out.println(\"---AGAIN---\");\n System.out.println(someString());\n System.out.println(\"---PRINT THE RESULT---\");\n System.out.println(sb.toString());\n }\n\n private static String someString() {\n\n try {\n sb.append(\"-abc-\");\n return sb.toString();\n\n } finally {\n sb.append(\"xyz\");\n }\n }\n}\n" }, { "answer_id": 57402744, "author": "Mike", "author_id": 448078, "author_profile": "https://Stackoverflow.com/users/448078", "pm_score": 2, "selected": false, "text": "public class TestDaemon {\n private static Runnable runnable = new Runnable() {\n @Override\n public void run() {\n try {\n while (true) {\n System.out.println(\"Is alive\");\n Thread.sleep(10);\n // throw new RuntimeException();\n }\n } catch (Throwable t) {\n t.printStackTrace();\n } finally {\n System.out.println(\"This will never be executed.\");\n }\n }\n };\n\n public static void main(String[] args) throws InterruptedException {\n Thread daemon = new Thread(runnable);\n daemon.setDaemon(true);\n daemon.start();\n Thread.sleep(100);\n // daemon.stop();\n System.out.println(\"Last non-daemon thread exits.\");\n }\n}\n" }, { "answer_id": 59932063, "author": "hellzone", "author_id": 1379734, "author_profile": "https://Stackoverflow.com/users/1379734", "pm_score": 3, "selected": false, "text": "finally" }, { "answer_id": 60123997, "author": "Youngrok Ko", "author_id": 2862834, "author_profile": "https://Stackoverflow.com/users/2862834", "pm_score": 1, "selected": false, "text": "static class IamAutoCloseable implements AutoCloseable {\n private final String name;\n IamAutoCloseable(String name) {\n this.name = name;\n }\n public void close() {\n System.out.println(name);\n }\n}\n\n@Test\npublic void withResourceFinally() {\n try (IamAutoCloseable closeable1 = new IamAutoCloseable(\"closeable1\");\n IamAutoCloseable closeable2 = new IamAutoCloseable(\"closeable2\")) {\n System.out.println(\"try\");\n } finally {\n System.out.println(\"finally\");\n }\n}\n" }, { "answer_id": 70623392, "author": "kevinarpe", "author_id": 257299, "author_profile": "https://Stackoverflow.com/users/257299", "pm_score": 0, "selected": false, "text": "something()" }, { "answer_id": 70841158, "author": "tquadrat", "author_id": 1554195, "author_profile": "https://Stackoverflow.com/users/1554195", "pm_score": 0, "selected": false, "text": "private final Lock m_Lock = new ReentrantLock();\n…\npublic final SomeObject doSomething( final SomeObject arg )\n{\n final SomeObject retValue;\n try\n {\n lock.lock();\n retValue = SomeObject( arg );\n }\n finally\n {\n out.println( \"Entering finally block\");\n callingAnotherMethod( arg, retValue );\n lock.unlock();\n }\n \n return retValue;\n}\n…\ntry\n{\n final var result = doSomething( new SomeObject() );\n}\ncatch( final StackOverflowError e ) { /* Deliberately ignored */ }\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65035", "https://Stackoverflow.com", "https://Stackoverflow.com/users/885027/" ]
65,037
<p>As far as I know, in gcc you can write something like:</p> <pre><code>#define DBGPRINT(fmt...) printf(fmt); </code></pre> <p>Is there a way to do that in VC++?</p>
[ { "answer_id": 65067, "author": "kfh", "author_id": 6597, "author_profile": "https://Stackoverflow.com/users/6597", "pm_score": -1, "selected": false, "text": "#define DBGPRINT(DBGPRINT_ARGS) printf DBGPRINT_ARGS // note: do not use '(' & ')'\n" }, { "answer_id": 65077, "author": "Mark", "author_id": 4405, "author_profile": "https://Stackoverflow.com/users/4405", "pm_score": 2, "selected": false, "text": "#define DBGPRINTF(fmt, ...) printf(fmt, __VA_ARGS__)\n" }, { "answer_id": 65087, "author": "David Dolson", "author_id": 8566, "author_profile": "https://Stackoverflow.com/users/8566", "pm_score": 0, "selected": false, "text": "# define DBGPRINTF(fmt,...) \\\n do { \\\n printf(fmt, __VA_ARGS__); \\\n } while(0)\n" }, { "answer_id": 65103, "author": "Gareth Simpson", "author_id": 147, "author_profile": "https://Stackoverflow.com/users/147", "pm_score": 6, "selected": true, "text": "#define DBGPRINT(fmt, ...) printf(fmt, __VA_ARGS__)\n" }, { "answer_id": 65388, "author": "yrp", "author_id": 7228, "author_profile": "https://Stackoverflow.com/users/7228", "pm_score": 2, "selected": false, "text": "#define DBGPRINT(args) printf(args);\nDBGPRINT((\"%s\\n\", \"Hello World\"));\n" }, { "answer_id": 69151, "author": "bk1e", "author_id": 8090, "author_profile": "https://Stackoverflow.com/users/8090", "pm_score": 1, "selected": false, "text": "__FILE__" }, { "answer_id": 16365801, "author": "amarcruz", "author_id": 2347894, "author_profile": "https://Stackoverflow.com/users/2347894", "pm_score": 1, "selected": false, "text": "#if defined(DETAILED_DEBUG)\n#define DBGPRINT fprintf\n#else\n__forceinline void __DBGPRINT(...){}\n#define DBGPRINT __DBGPRINT\n#endif\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65037", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9102/" ]
65,039
<p>I am refactoring some CSS on a website. I have been working on, and noticed the absence of traditional HTML IDs in the code. </p> <p>There is heavy use of <code>CssClass='&amp;hellip;'</code>, or sometimes just <code>class='&amp;hellip;'</code>, but I can't seem to find a way to say id='&hellip;' and not have it swapped out by the server.</p> <p>Here is an example:</p> <pre><code>&lt;span id='position_title' runat='server'&gt;Manager&lt;/span&gt; </code></pre> <p>When the response comes back from the server, I get:</p> <pre><code>&lt;span id='$aspnet$crap$here$position_title'&gt;Manager&lt;/span&gt;</code></pre> <p>Any help here?</p>
[ { "answer_id": 65082, "author": "David Thibault", "author_id": 5903, "author_profile": "https://Stackoverflow.com/users/5903", "pm_score": 3, "selected": false, "text": "<script type=\"text/javascript\">\n var theSpan = document.getElementById('<%= position_title.ClientID %>');\n</script>\n" }, { "answer_id": 65147, "author": "B0fh", "author_id": 9159, "author_profile": "https://Stackoverflow.com/users/9159", "pm_score": 0, "selected": false, "text": "span" }, { "answer_id": 65327, "author": "rp.", "author_id": 2536, "author_profile": "https://Stackoverflow.com/users/2536", "pm_score": 3, "selected": false, "text": "$(\"span[id$='position_title']\")....\n" }, { "answer_id": 65586, "author": "Joshua Carmody", "author_id": 8409, "author_profile": "https://Stackoverflow.com/users/8409", "pm_score": 0, "selected": false, "text": "<style type=\"text/css\">\n#position_title { // Whatever\n}\n<span id=\"position_titleserver\" runat=\"server\"><span id=\"position_title\">Manager</span></span>\n" }, { "answer_id": 72735, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "[style type=\"text/css\"]\n #<%= AspNetId.ClientID %> {\n ... styles go here...\n }\n[/style]\n\n[script type=\"text/javascript\"]\n document.getElementById(\"<%= AspNetId.ClientID %>\");\n[/script]\n" }, { "answer_id": 112821, "author": "Herb Caudill", "author_id": 239663, "author_profile": "https://Stackoverflow.com/users/239663", "pm_score": 1, "selected": false, "text": " <span id=\"FooContainer\">\n <span runat=\"server\" id=\"Foo\" >\n ......\n <span>\n </span>\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65039", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
65,060
<p>If i have a simple named query defined, the preforms a count function, on one column:</p> <pre><code> &lt;query name="Activity.GetAllMiles"&gt; &lt;![CDATA[ select sum(Distance) from Activity ]]&gt; &lt;/query&gt; </code></pre> <p>How do I get the result of a sum or any query that dont return of one the mapped entities, with NHibernate using Either IQuery or ICriteria?</p> <p>Here is my attempt (im unable to test it right now), would this work?</p> <pre><code> public decimal Find(String namedQuery) { using (ISession session = NHibernateHelper.OpenSession()) { IQuery query = session.GetNamedQuery(namedQuery); return query.UniqueResult&lt;decimal&gt;(); } } </code></pre>
[ { "answer_id": 67675, "author": "Matt Hinze", "author_id": 2676, "author_profile": "https://Stackoverflow.com/users/2676", "pm_score": 2, "selected": false, "text": "var session = GetSession();\nvar criteria = session.CreateCriteria(typeof(Order))\n .Add(Restrictions.Eq(\"Product\", product))\n .SetProjection(Projections.CountDistinct(\"Price\"));\nreturn (int) criteria.UniqueResult();\n" }, { "answer_id": 84348, "author": "Dan", "author_id": 230, "author_profile": "https://Stackoverflow.com/users/230", "pm_score": 3, "selected": true, "text": "var criteria = session.CreateCriteria(typeof(Activity))\n .SetProjection(Projections.Sum(\"Distance\"));\n return (double)criteria.UniqueResult();\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65060", "https://Stackoverflow.com", "https://Stackoverflow.com/users/230/" ]
65,071
<p>Is there a performant equivalent to the isnull function for DB2?</p> <p>Imagine some of our products are internal, so they don't have names:</p> <pre><code>Select product.id, isnull(product.name, "Internal) From product </code></pre> <p>Might return:</p> <pre><code>1 Socks 2 Shoes 3 Internal 4 Pants </code></pre>
[ { "answer_id": 65111, "author": "Chris Shaffer", "author_id": 6744, "author_profile": "https://Stackoverflow.com/users/6744", "pm_score": 2, "selected": false, "text": "\nSELECT Product.ID, COALESCE(product.Name, \"Internal\") AS ProductName\nFROM Product\n" }, { "answer_id": 163321, "author": "Fuangwith S.", "author_id": 24550, "author_profile": "https://Stackoverflow.com/users/24550", "pm_score": 0, "selected": false, "text": "COALESCE" }, { "answer_id": 256672, "author": "venkatram", "author_id": 33392, "author_profile": "https://Stackoverflow.com/users/33392", "pm_score": 0, "selected": false, "text": "COALESCE" }, { "answer_id": 1122917, "author": "MadMurf", "author_id": 46527, "author_profile": "https://Stackoverflow.com/users/46527", "pm_score": 5, "selected": false, "text": "IFNULL(expr1, default)\n" }, { "answer_id": 23872455, "author": "Jnn", "author_id": 2303472, "author_profile": "https://Stackoverflow.com/users/2303472", "pm_score": 2, "selected": false, "text": "Select Product.ID, VALUE(product.Name, \"Internal\") AS ProductName from Product\n" }, { "answer_id": 46464702, "author": "turnmoil", "author_id": 7755586, "author_profile": "https://Stackoverflow.com/users/7755586", "pm_score": 0, "selected": false, "text": " SELECT \n.... FROM XXX XX\nWHERE\n....\nAND(\n param1 IS NULL\n OR XX.param1 = param1\n )\n" }, { "answer_id": 69189273, "author": "Rafael Rossi", "author_id": 7129619, "author_profile": "https://Stackoverflow.com/users/7129619", "pm_score": 0, "selected": false, "text": "NVL2 (string_to_be_tested, string_if_not_null, string_if_null);\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65071", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9056/" ]
65,074
<p>I've just started writing unit tests for a legacy code module with large physical dependencies using the #include directive. I've been dealing with them a few ways that felt overly tedious (providing empty headers to break long #include dependency lists, and using #define to prevent classes from being compiled) and was looking for some better strategies for handling these problems.</p> <p>I've been frequently running into the problem of duplicating almost every header file with a blank version in order to separate the class I'm testing in it's entirety, and then writing substantial stub/mock/fake code for objects that will need to be replaced since they're now undefined.</p> <p>Anyone know some better practices?</p>
[ { "answer_id": 65923, "author": "Gishu", "author_id": 1695, "author_profile": "https://Stackoverflow.com/users/1695", "pm_score": 4, "selected": true, "text": "#include \"TestHarness.h\"\n#include \"Scheduler.h\"\nTEST(create, Scheduler) // your fave C++ test framework macro\n{\n Scheduler scheduler(\"fred\");\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65074", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8908/" ]
65,076
<p>I've trouble setting up Vim (7.1.xxx) for editing Python files (*.py). Indenting seems to be broken (optimal 4 spaces). I've followed some tutorials I found via Google. Still no effect :/ Please help.</p>
[ { "answer_id": 65122, "author": "Daren Thomas", "author_id": 2260, "author_profile": "https://Stackoverflow.com/users/2260", "pm_score": 6, "selected": false, "text": "\" configure expanding of tabs for various file types\nau BufRead,BufNewFile *.py set expandtab\nau BufRead,BufNewFile *.c set expandtab\nau BufRead,BufNewFile *.h set expandtab\nau BufRead,BufNewFile Makefile* set noexpandtab\n\n\" --------------------------------------------------------------------------------\n\" configure editor with tabs and nice stuff...\n\" --------------------------------------------------------------------------------\nset expandtab \" enter spaces when tab is pressed\nset textwidth=120 \" break lines when line length increases\nset tabstop=4 \" use 4 spaces to represent tab\nset softtabstop=4\nset shiftwidth=4 \" number of spaces to use for auto indent\nset autoindent \" copy indent from current line when starting a new line\n\n\" make backspaces more powerfull\nset backspace=indent,eol,start\n\nset ruler \" show line and column number\nsyntax on \" syntax highlighting\nset showcmd \" show (partial) command in status line\n" }, { "answer_id": 66818, "author": "Jamie", "author_id": 3363, "author_profile": "https://Stackoverflow.com/users/3363", "pm_score": 2, "selected": false, "text": ":help vimrc" }, { "answer_id": 1868984, "author": "Skylar Saveland", "author_id": 177293, "author_profile": "https://Stackoverflow.com/users/177293", "pm_score": 3, "selected": false, "text": "set softtabstop=4\n" }, { "answer_id": 11830841, "author": "thanos", "author_id": 244849, "author_profile": "https://Stackoverflow.com/users/244849", "pm_score": 4, "selected": false, "text": "$ cat ~/.vimrc\nsyntax on\nset showmatch\nset ts=4\nset sts=4\nset sw=4\nset autoindent\nset smartindent\nset smarttab\nset expandtab\nset number\n" }, { "answer_id": 44339554, "author": "Teddy Belay", "author_id": 4325298, "author_profile": "https://Stackoverflow.com/users/4325298", "pm_score": 4, "selected": false, "text": " if has(\"autocmd\")\n filetype plugin indent on\n endif\n" }, { "answer_id": 60205582, "author": "Flávio Brito", "author_id": 6580920, "author_profile": "https://Stackoverflow.com/users/6580920", "pm_score": 1, "selected": false, "text": "-----\n\" configure expanding of tabs for various file types\nau BufRead,BufNewFile *.py set expandtab\nau BufRead,BufNewFile *.c set noexpandtab\nau BufRead,BufNewFile *.h set noexpandtab\nau BufRead,BufNewFile Makefile* set noexpandtab\n\n\" --------------------------------------------------------------------------------\n\" configure editor with tabs and nice stuff...\n\" --------------------------------------------------------------------------------\nset expandtab \" enter spaces when tab is pressed\nset textwidth=120 \" break lines when line length increases\nset tabstop=4 \" use 4 spaces to represent tab\nset softtabstop=4\nset shiftwidth=4 \" number of spaces to use for auto indent\nset autoindent \" copy indent from current line when starting a new line\nset smartindent\nset smarttab\nset expandtab\nset number\n\n\" make backspaces more powerfull\nset backspace=indent,eol,start\n\nset ruler \" show line and column number\nsyntax on \" syntax highlighting\nset showcmd \" show (partial) command in status line" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65076", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9099/" ]
65,091
<p>I'd like to be able to write a PHP class that behaves like an array and uses normal array syntax for getting &amp; setting.</p> <p>For example (where Foo is a PHP class of my making):</p> <pre><code>$foo = new Foo(); $foo['fooKey'] = 'foo value'; echo $foo['fooKey']; </code></pre> <p>I know that PHP has the _get and _set magic methods but those don't let you use array notation to access items. Python handles it by overloading __getitem__ and __setitem__.</p> <p>Is there a way to do this in PHP? If it makes a difference, I'm running PHP 5.2.</p>
[ { "answer_id": 65136, "author": "Mat Mannion", "author_id": 6282, "author_profile": "https://Stackoverflow.com/users/6282", "pm_score": 6, "selected": true, "text": "ArrayObject" }, { "answer_id": 5986293, "author": "Ron Cemer", "author_id": 751626, "author_profile": "https://Stackoverflow.com/users/751626", "pm_score": 2, "selected": false, "text": "class CaseInsensitiveArray extends ArrayObject {\n public function __construct($input = array(), $flags = 0, $iterator_class = 'ArrayIterator') {\n if (isset($input) && is_array($input)) {\n $tmpargs = func_get_args();\n $tmpargs[0] = array_change_key_case($tmpargs[0], CASE_LOWER);\n return call_user_func_array(array('parent', __FUNCTION__), $tmp args);\n }\n return call_user_func_array(array('parent', __FUNCTION__), func_get_args());\n }\n\n public function offsetExists($index) {\n if (is_string($index)) return parent::offsetExists(strtolower($index));\n return parent::offsetExists($index);\n }\n\n public function offsetGet($index) {\n if (is_string($index)) return parent::offsetGet(strtolower($index));\n return parent::offsetGet($index);\n }\n\n public function offsetSet($index, $value) {\n if (is_string($index)) return parent::offsetSet(strtolower($index, $value));\n return parent::offsetSet($index, $value);\n }\n\n public function offsetUnset($index) {\n if (is_string($index)) return parent::offsetUnset(strtolower($index));\n return parent::offsetUnset($index);\n }\n}\n\n$blah = new CaseInsensitiveArray(array(\n 'A'=>'hello',\n 'bcD'=>'goodbye',\n 'efg'=>'Aloha',\n));\n\necho \"is array: \".is_array($blah).\"\\n\";\n\nprint_r($blah);\nprint_r(array_keys($blah));\n\necho $blah['a'].\"\\n\";\necho $blah['BCD'].\"\\n\";\necho $blah['eFg'].\"\\n\";\necho $blah['A'].\"\\n\";\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65091", "https://Stackoverflow.com", "https://Stackoverflow.com/users/305/" ]
65,095
<p>What are the common algorithms being used to measure the processor frequency?</p>
[ { "answer_id": 65159, "author": "Todd Gamblin", "author_id": 9122, "author_profile": "https://Stackoverflow.com/users/9122", "pm_score": 0, "selected": false, "text": "> cat /proc/cpuinfo\n" }, { "answer_id": 65369, "author": "Nathan Fellman", "author_id": 1084, "author_profile": "https://Stackoverflow.com/users/1084", "pm_score": 4, "selected": false, "text": "; read MPERF\nmov ecx, 0xe7\nrdmsr\nmov mperf_var_lo, eax\nmov mperf_var_hi, edx\n\n; read APERF\nmov ecx, 0xe8\nrdmsr\nmov aperf_var_lo, eax\nmov aperf_var_hi, edx\n" }, { "answer_id": 1048120, "author": "matja", "author_id": 115567, "author_profile": "https://Stackoverflow.com/users/115567", "pm_score": 2, "selected": false, "text": "#include <stdio.h>\n#include <stdint.h>\n#include <unistd.h>\n\nuint64_t rdtsc(void) {\n uint64_t result;\n __asm__ __volatile__ (\"rdtsc\" : \"=A\" (result));\n return result;\n}\n\nint main(void) {\n uint64_t ts0, ts1; \n ts0 = rdtsc();\n sleep(1);\n ts1 = rdtsc(); \n printf(\"clock frequency = %llu\\n\", ts1 - ts0);\n return 0;\n}\n" }, { "answer_id": 6953905, "author": "Olof Forshell", "author_id": 501673, "author_profile": "https://Stackoverflow.com/users/501673", "pm_score": 2, "selected": false, "text": "basetime=time(); /* time returns seconds */\n\nwhile (time()==basetime);\nstclk=rdtsc(); /* rdtsc is an assembly instruction */\n\nbasetime=time();\nwhile (time()==basetime\nendclk=rdtsc();\n\nnclks=encdclk-stclk;\n" }, { "answer_id": 33160613, "author": "Patrick", "author_id": 4919054, "author_profile": "https://Stackoverflow.com/users/4919054", "pm_score": 1, "selected": false, "text": "> 7z b\n7-Zip 9.38 beta Copyright (c) 1999-2014 Igor Pavlov 2015-01-03\n\nCPU Freq: 4266 4000 4266 4000 2723 4129 3261 3644 3362\n" }, { "answer_id": 61429118, "author": "maxschlepzig", "author_id": 427158, "author_profile": "https://Stackoverflow.com/users/427158", "pm_score": 1, "selected": false, "text": "CPU_freq = tsc_freq * (aperf_t1 - aperf_t0) / (mperf_t1 - mperf_t0)\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65095", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
65,128
<p>I have a huge ear that uses log4j and there is a single config file that is used to set it up. In this config file there is no mention of certain log files but, additional files apart from those specified in the config file get generated in the logs folder. I've searched for other combinations of (logger|log4j|log).(properties|xml) and haven't found anything promising in all of the jar files included in the ear. How do I track down which is the offending thread/class that is creating these extra files?</p>
[ { "answer_id": 65957, "author": "James A. N. Stauffer", "author_id": 6770, "author_profile": "https://Stackoverflow.com/users/6770", "pm_score": 2, "selected": false, "text": "-Dlog4j.debug" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7616/" ]
65,129
<p>We are planning to use the jQuery library to augment our client side JavaScript needs. </p> <p>Are there any major issues in trying to use both ASP.Net AJAX and jQuery? Both libraries seem to use $ for special purposes. Are there any conflicts that we need to be aware of? </p> <p>We also use Telerik controls that use ASP.Net AJAX.</p> <p>TIA</p>
[ { "answer_id": 67754, "author": "Chris James", "author_id": 3193, "author_profile": "https://Stackoverflow.com/users/3193", "pm_score": 1, "selected": false, "text": "<input type=\"text\" id=\"whatever\" />\n" }, { "answer_id": 67907, "author": "gregmac", "author_id": 7913, "author_profile": "https://Stackoverflow.com/users/7913", "pm_score": 2, "selected": false, "text": "<asp:panel id=\"panel1\" runat=\"server\"></asp:panel>\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65129", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3635/" ]
65,133
<p>I'm running into a perplexing problem with an ActiveX control I'm writing - sometimes, Internet Explorer appears to fail to properly unload the control on process shutdown. This results in the control instance's destructor not being called.</p> <p>The control is written in C++, uses ATL and it's compiled using Visual Studio 2005. The control instance's destructor is always called when the user browses away from the page the control is embedded in - the problem only occurs when the browser is closed. </p> <p>When I run IE under a debugger, I don't see anything unusual - the debugger doesn't catch any exceptions, access violations or assertion failures, but the problem is still there - I can set a breakpoint in the control's destructor and it's never hit when I close the broswer.</p> <p>In addition, when I load a simple HTML page that embeds multiple instances of the control I don't see the problem. The problem only appears to happen when the control is instantiated from our web application, which inserts tags dynamically into the web page - of course, not knowing what causes this problem, I don't know whether this bit of information is relevant or not, but it does seem to indicate that this might be an IE problem, since it's data dependent. </p> <p>When I run the simple test case under the debugger, I can set a breakpoint in the control's destructor and it's hit every time. I believe this rules out a problem with the control itself (say, an error that would prevent the destructor from ever being called, like an interface leak.)</p> <p>I do most of my testing with IE 6, but I've seen the problem occur on IE 7, as well. I haven't tested IE 8.</p> <p>My working hypothesis right now is that there's something in the dynamic HTML code that causes the browser to leak an interface on the ActiveX control. So far, I haven't been able to produce a good test case that reproduces this outside of the application, and the application is a bit too large to make a good test case.</p> <p>I was hoping that someone might be able to provide insight into possible IE bugs that are known to cause this kind of behavior. The answer provided below, by the way, is too general - I'm looking for a specific set of circumstances that is known to cause this. Surely someone out there has seen this before.</p>
[ { "answer_id": 165477, "author": "Bruce", "author_id": 6310, "author_profile": "https://Stackoverflow.com/users/6310", "pm_score": 0, "selected": false, "text": "BOOL WINAPI DllMain(HINSTANCE, DWORD dwReason, LPVOID) {\n if (dwReason == DLL_PROCESS_DETACH) {\n CleanUpAnyObjectsStillAlive();\n }\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65133", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9047/" ]
65,164
<p>Some 4 years back, I followed this <a href="http://msdn.microsoft.com/en-us/library/ms973825.aspx" rel="noreferrer">MSDN article</a> for DateTime usage best practices for building a .Net client on .Net 1.1 and ASMX web services (with SQL 2000 server as the backend). I still remember the serialization issues I had with DateTime and the testing effort it took for servers in different time zones.</p> <p>My questions is this: Is there a similar best practices document for some of the new technologies like WCF and SQL server 2008, especially with the addition of new datetime types for storing time zone aware info.</p> <p>This is the environment:</p> <ol> <li>SQL server 2008 on Pacific Time.</li> <li>Web Services layer on a different time zone.</li> <li>Clients could be using .Net 2.0 or .Net 3.5 on different time zones. If it makes it easy, we can force everyone to upgrade to .Net 3.5. :)</li> </ol> <p>Any good suggestions/best practices for the data types to be used in each layer?</p>
[ { "answer_id": 65474, "author": "Jesse C. Slicer", "author_id": 3312, "author_profile": "https://Stackoverflow.com/users/3312", "pm_score": 2, "selected": false, "text": "[Serializable]\npublic sealed class MyDateTime\n{\n public MyDateTime()\n {\n this.Now = DateTime.Now;\n this.IsDaylightSavingTime = this.Now.IsDaylightSavingTime();\n this.TimeZone = this.IsDaylightSavingTime\n ? System.TimeZone.CurrentTimeZone.DaylightName\n : System.TimeZone.CurrentTimeZone.StandardName;\n }\n\n public DateTime Now\n {\n get;\n\n set;\n }\n\n public string TimeZone\n {\n get;\n\n set;\n }\n\n public bool IsDaylightSavingTime\n {\n get;\n\n set;\n }\n}\n" }, { "answer_id": 70202, "author": "Ray Lu", "author_id": 11413, "author_profile": "https://Stackoverflow.com/users/11413", "pm_score": 2, "selected": false, "text": "dateTimeValueUtcKind = DateTime.SpecifyKind(dateTimeValue, DateTimeKind.Utc);\n" }, { "answer_id": 65071586, "author": "Laobu", "author_id": 7426767, "author_profile": "https://Stackoverflow.com/users/7426767", "pm_score": 0, "selected": false, "text": "DateTime now = DateTime.Now;\nstring json = JsonConvert.SerializeObject(now);\nDateTime nowJson = JsonConvert.DeserializeObject<DateTime>(json);\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65164", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4337/" ]
65,170
<p>What's the easiest way to get the filename associated with an open HANDLE in Win32?</p>
[ { "answer_id": 65254, "author": "Taylor Price", "author_id": 3805, "author_profile": "https://Stackoverflow.com/users/3805", "pm_score": 2, "selected": false, "text": "GetFileInformationByHandleEx( fileHandle, FILE_NAME_INFO, lpFileInformation, sizeof(FILE_NAME_INFO));\n" }, { "answer_id": 65417, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "GetMappedFileName(...)" }, { "answer_id": 65775, "author": "Max Caceres", "author_id": 4842, "author_profile": "https://Stackoverflow.com/users/4842", "pm_score": 1, "selected": false, "text": "from ctypes import *\n# get handle to c:\\boot.ini to test\nhandle = windll.kernel32.CreateFileA(\"c:\\\\boot.ini\", 0x80000000, 3, 0, 3, 0x80, 0)\nhfilemap = windll.kernel32.CreateFileMappingA(handle, 0, 2, 0, 1, 0)\npmem = windll.kernel32.MapViewOfFile(hfilemap, 4, 0, 0, 1)\nname = create_string_buffer(1024)\nwindll.psapi.GetMappedFileNameA(windll.kernel32.GetCurrentProcess(), pmem, name, 1024)\nprint \"The name for the handle 0x%08x is %s\" % (handle, name.value)\n# convert device name to drive letter\nbuf = create_string_buffer(512)\nsize = windll.kernel32.GetLogicalDriveStringsA(511, buf)\nnames = buf.raw[0:size-1].split(\"\\0\")\nfor drive in names:\n windll.kernel32.QueryDosDeviceA(drive[0:2], buf, 512)\n if name.value.startswith(buf.value):\n print \"%s%s\" % (drive[0:2], name.value[len(buf.value):])\n break\n" }, { "answer_id": 5286888, "author": "user541686", "author_id": 541686, "author_profile": "https://Stackoverflow.com/users/541686", "pm_score": 4, "selected": false, "text": "WInternl.h" }, { "answer_id": 18792477, "author": "Elmue", "author_id": 1487529, "author_profile": "https://Stackoverflow.com/users/1487529", "pm_score": 4, "selected": false, "text": "GetFileInformationByHandleEx()" }, { "answer_id": 35863703, "author": "Holger", "author_id": 4727717, "author_profile": "https://Stackoverflow.com/users/4727717", "pm_score": 1, "selected": false, "text": "char buf[MAX_PATH];\nGetFinalPathNameByHandleA(fileHandle, buf, sizeof(buf), VOLUME_NAME_DOS)\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65170", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4842/" ]
65,173
<p>I'm trying to run PHP from the command line under <a href="https://en.wikipedia.org/wiki/Windows_XP" rel="nofollow noreferrer">Windows XP</a>.</p> <p>That works, except for the fact that I am not able to provide parameters to my PHP script.</p> <p>My test case:</p> <pre><code>echo &quot;param = &quot; . $param . &quot;\n&quot;; var_dump($argv); </code></pre> <p>I want to call this as:</p> <pre><code>php.exe -f test.php -- param=test </code></pre> <p>But I never get the script to accept my parameter.</p> <p>The result I get from the above script:</p> <blockquote> <p>PHP Notice: Undefined variable: param in C:\test.php on line 2</p> </blockquote> <pre><code>param = '' array(2) { [0]=&gt; string(8) &quot;test.php&quot; [1]=&gt; string(10) &quot;param=test&quot; } </code></pre> <p>I am trying this using PHP 5.2.6. Is this a bug in PHP 5?</p> <p>The parameter passing is handled in the <a href="http://us3.php.net/features.commandline" rel="nofollow noreferrer">online help</a>:</p> <blockquote> <p>Note: If you need to pass arguments to your scripts you need to pass -- as the first argument when using the -f switch.</p> </blockquote> <p>This seemed to be working under PHP 4, but not under PHP 5.</p> <p>Under PHP 4 I could use the same script that could run on the server without alteration on the command line. This is handy for local debugging, for example, saving the output in a file, to be studied.</p>
[ { "answer_id": 65269, "author": "Ben", "author_id": 5005, "author_profile": "https://Stackoverflow.com/users/5005", "pm_score": 0, "selected": false, "text": "$tmp = $argv[1]; // $tmp=\"param=test\"\n$tmp = explode(\"=\", $tmp); // $tmp=Array( 0 => param, 1 => test)\n\n$param = $tmp[1]; // $param = \"test\";\n" }, { "answer_id": 65299, "author": "Jeremy Weathers", "author_id": 8794, "author_profile": "https://Stackoverflow.com/users/8794", "pm_score": 1, "selected": false, "text": "ARGV" }, { "answer_id": 65308, "author": "Derek Kurth", "author_id": 1418, "author_profile": "https://Stackoverflow.com/users/1418", "pm_score": 0, "selected": false, "text": "if($argc > 1){\n if($argv[1] == 'param=test'){\n $param = 'test';\n }\n}\n" }, { "answer_id": 65359, "author": "Mark Biek", "author_id": 305, "author_profile": "https://Stackoverflow.com/users/305", "pm_score": 2, "selected": false, "text": "php -e -n -f myScript.php -- -f -n -e\n" }, { "answer_id": 65709, "author": "farzad", "author_id": 9394, "author_profile": "https://Stackoverflow.com/users/9394", "pm_score": -1, "selected": false, "text": "<?php\n echo $argv[1];\n?>\n" }, { "answer_id": 66690, "author": "rcphq", "author_id": 9114, "author_profile": "https://Stackoverflow.com/users/9114", "pm_score": 0, "selected": false, "text": "if (isset($argv[1]) {\n $arg1 = $argv[1];\n $arg1 = explode(\"=\", $arg1);\n $param = $arg1[1];\n}\n" }, { "answer_id": 6156922, "author": "Gerrit", "author_id": 773654, "author_profile": "https://Stackoverflow.com/users/773654", "pm_score": 2, "selected": false, "text": "<?php\n parse_str($argv[1]);\n?>\n" }, { "answer_id": 26269594, "author": "M.Hefny", "author_id": 637718, "author_profile": "https://Stackoverflow.com/users/637718", "pm_score": 1, "selected": false, "text": " php myserver.php host=192.168.1.4 port=9000\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
65,200
<p>I was reading a book on programming skills wherein the author asks the interviewee, "How do you crash a JVM?" I thought that you could do so by writing an infinite for-loop that would eventually use up all the memory.</p> <p>Anybody has any idea?</p>
[ { "answer_id": 65290, "author": "Mike Stone", "author_id": 122, "author_profile": "https://Stackoverflow.com/users/122", "pm_score": 0, "selected": false, "text": "public static void main(String[] args) {\n causeStackOverflow();\n}\n\npublic void causeStackOverflow() {\n causeStackOverflow();\n}\n" }, { "answer_id": 65291, "author": "Leigh Caldwell", "author_id": 3267, "author_profile": "https://Stackoverflow.com/users/3267", "pm_score": 4, "selected": true, "text": "System.exit()" }, { "answer_id": 74780, "author": "ralfs", "author_id": 13107, "author_profile": "https://Stackoverflow.com/users/13107", "pm_score": 7, "selected": false, "text": "public class Crash {\n public static void main(String[] args) {\n Object[] o = null;\n\n while (true) {\n o = new Object[] {o};\n }\n }\n}\n" }, { "answer_id": 74867, "author": "eckes", "author_id": 13189, "author_profile": "https://Stackoverflow.com/users/13189", "pm_score": 2, "selected": false, "text": "SIGSEGV" }, { "answer_id": 799757, "author": "Peter Lawrey", "author_id": 57695, "author_profile": "https://Stackoverflow.com/users/57695", "pm_score": 2, "selected": false, "text": "public static void main(String[] args) {\n throw new OutOfmemoryError();\n}\n" }, { "answer_id": 1378388, "author": "Dave Griffiths", "author_id": 15379, "author_profile": "https://Stackoverflow.com/users/15379", "pm_score": 6, "selected": false, "text": "import sun.misc.Unsafe;\n\npublic class Crash {\n private static final Unsafe unsafe = Unsafe.getUnsafe();\n public static void crash() {\n unsafe.putAddress(0, 0);\n }\n public static void main(String[] args) {\n crash();\n }\n}\n" }, { "answer_id": 2849632, "author": "Rob Mayhew", "author_id": 49393, "author_profile": "https://Stackoverflow.com/users/49393", "pm_score": 4, "selected": false, "text": "import sun.dc.pr.PathDasher; \n\npublic class Crash\n{\n public static void main(String[] args)\n { \n PathDasher dasher = new PathDasher(null) ;\n }\n}\n" }, { "answer_id": 7291092, "author": "Prabath Siriwardena", "author_id": 804637, "author_profile": "https://Stackoverflow.com/users/804637", "pm_score": 4, "selected": false, "text": "Double.parseDouble(\"2.2250738585072012e-308\");\n" }, { "answer_id": 11636338, "author": "George Armhold", "author_id": 93995, "author_profile": "https://Stackoverflow.com/users/93995", "pm_score": 5, "selected": false, "text": "$ echo 'crap crap crap' > crap.class\n$ java crap\nException in thread \"main\" java.lang.ClassFormatError: Incompatible magic value 1668440432 in class file crap\n" }, { "answer_id": 22905184, "author": "RRM", "author_id": 1439122, "author_profile": "https://Stackoverflow.com/users/1439122", "pm_score": 3, "selected": false, "text": "public class Crash\n{\n public static void main(String[] args)\n {\n main(args);\n }\n}\n" }, { "answer_id": 28650035, "author": "Hot Licks", "author_id": 581994, "author_profile": "https://Stackoverflow.com/users/581994", "pm_score": 5, "selected": false, "text": "public class Recur {\n public static void main(String[] argv) {\n try {\n recur();\n }\n catch (Error e) {\n System.out.println(e.toString());\n }\n System.out.println(\"Ended normally\");\n }\n static void recur() {\n Object[] o = null;\n try {\n while(true) {\n Object[] newO = new Object[1];\n newO[0] = o;\n o = newO;\n }\n }\n finally {\n recur();\n }\n }\n}\n" }, { "answer_id": 35111507, "author": "Sankarganesh Eswaran", "author_id": 2629588, "author_profile": "https://Stackoverflow.com/users/2629588", "pm_score": -1, "selected": false, "text": "public static void main(String args[]){\n int i = 1/0;\n System.out.print(i); // This part will not be executed due to above unhandled exception\n }\n" }, { "answer_id": 37839185, "author": "henry", "author_id": 640224, "author_profile": "https://Stackoverflow.com/users/640224", "pm_score": 3, "selected": false, "text": "System.exit" }, { "answer_id": 46211034, "author": "Lightfire228", "author_id": 2716305, "author_profile": "https://Stackoverflow.com/users/2716305", "pm_score": 2, "selected": false, "text": "public class Crash {\n public static void main(String[] args) {\n\n Runnable[] arr = new Runnable[1];\n arr[0] = () -> {\n\n while (true) {\n new Thread(arr[0]).start();\n }\n };\n\n arr[0].run();\n }\n}\n" }, { "answer_id": 55381501, "author": "mszmurlo", "author_id": 1483318, "author_profile": "https://Stackoverflow.com/users/1483318", "pm_score": 1, "selected": false, "text": "long pid = ProcessHandle.current().pid();\ntry { Runtime.getRuntime().exec(\"kill -9 \"+pid); } catch (Exception e) {}\n" }, { "answer_id": 57697108, "author": "charlie arehart", "author_id": 90802, "author_profile": "https://Stackoverflow.com/users/90802", "pm_score": 2, "selected": false, "text": " -Xmx10m -XX:+CrashOnOutOfMemoryError\n" }, { "answer_id": 60860170, "author": "Frank Teng", "author_id": 10787741, "author_profile": "https://Stackoverflow.com/users/10787741", "pm_score": 1, "selected": false, "text": "-XX:+CrashOnOutOfMemoryError" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65200", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9195/" ]
65,205
<p>What's the best way to store a linked list in a MySQL database so that inserts are simple (i.e. you don't have to re-index a bunch of stuff every time) and such that the list can easily be pulled out in order?</p>
[ { "answer_id": 65238, "author": "Adrian Dunston", "author_id": 8344, "author_profile": "https://Stackoverflow.com/users/8344", "pm_score": 5, "selected": true, "text": " alter table linked_list add column position integer not null default 0;\n alter table linked_list add index position_index (position);\n select * from linked_list order by position;\n" }, { "answer_id": 65295, "author": "B0fh", "author_id": 9159, "author_profile": "https://Stackoverflow.com/users/9159", "pm_score": 4, "selected": false, "text": "create table tblDummy\n{\n PKColumn int not null, \n PreviousID int null, \n DataColumn1 varchar(50) not null, \n DataColumn2 varchar(50) not null, \n DataColumn3 varchar(50) not null, \n DataColumn4 varchar(50) not null, \n DataColumn5 varchar(50) not null, \n DataColumn6 varchar(50) not null, \n DataColumn7 varchar(50) not null, \n NextID int null\n}\n" }, { "answer_id": 65330, "author": "Rory", "author_id": 8479, "author_profile": "https://Stackoverflow.com/users/8479", "pm_score": 2, "selected": false, "text": "create table linked_list\n( list_id integer not null\n, position integer not null \n, data varchar(100) not null\n);\nalter table linked_list add primary key ( list_id, position );\n" }, { "answer_id": 7025913, "author": "Poncho", "author_id": 889912, "author_profile": "https://Stackoverflow.com/users/889912", "pm_score": 0, "selected": false, "text": "Datetime" }, { "answer_id": 21038546, "author": "FlyTigert", "author_id": 657921, "author_profile": "https://Stackoverflow.com/users/657921", "pm_score": 2, "selected": false, "text": "Create Table A{\nId int primary key identity(1,1),\nData varchar(10) not null\nB_Id int\n}\n\nCreate Table B{\nId int primary key Identity(1,1),\nGroupName varchat(10) not null,\nOrder varchar(max) null\n}\n" }, { "answer_id": 29475498, "author": "HumbleWebDev", "author_id": 3496058, "author_profile": "https://Stackoverflow.com/users/3496058", "pm_score": 2, "selected": false, "text": "create table linkedlist00 (\n\nkey1 int primary key not null identity(1,1),\n\ninfo varchar(10),\n\nkey2 int\n\n)\n" }, { "answer_id": 63198185, "author": "Cal", "author_id": 5785894, "author_profile": "https://Stackoverflow.com/users/5785894", "pm_score": -1, "selected": false, "text": "create table queue (\n primary_key,\n queue_key\n ordinal,\n data\n)\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
65,206
<p>Using <a href="http://en.wikipedia.org/wiki/JQuery" rel="noreferrer">jQuery</a>, how can I dynamically set the size attribute of a select box?</p> <p>I would like to include it in this code:</p> <pre><code>$("#mySelect").bind("click", function() { $("#myOtherSelect").children().remove(); var options = '' ; for (var i = 0; i &lt; myArray[this.value].length; i++) { options += '&lt;option value="' + myArray[this.value][i] + '"&gt;' + myArray[this.value][i] + '&lt;/option&gt;'; } $("#myOtherSelect").html(options).attr [... use myArray[this.value].length here ...]; }); }); </code></pre>
[ { "answer_id": 65239, "author": "Loren Segal", "author_id": 6436, "author_profile": "https://Stackoverflow.com/users/6436", "pm_score": 6, "selected": true, "text": "$('#mySelect').attr('size', value)\n" }, { "answer_id": 65261, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "$(\"#mySelect\").bind(\"click\", function(){\n $(\"#myOtherSelect\").children().remove();\n var myArray = [ \"value1\", \"value2\", \"value3\" ];\n for (var i = 0; i < myArray.length; i++) {\n $(\"#myOtherSelect\").append( '<option value=\"' + myArray[i] + '\">' + myArray[i] + '</option>' );\n }\n $(\"#myOtherSelect\").attr( \"size\", myArray.length );\n});\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65206", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2755/" ]
65,209
<p>I was recently asked to come up with a script that will allow the end user to upload a PSD (Photoshop) file, and split it up and create images from each of the layers.</p> <p>I would love to stay with PHP for this, but I am open to Python or Perl as well.</p> <p>Any ideas would be greatly appreciated.</p>
[ { "answer_id": 65239, "author": "Loren Segal", "author_id": 6436, "author_profile": "https://Stackoverflow.com/users/6436", "pm_score": 6, "selected": true, "text": "$('#mySelect').attr('size', value)\n" }, { "answer_id": 65261, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "$(\"#mySelect\").bind(\"click\", function(){\n $(\"#myOtherSelect\").children().remove();\n var myArray = [ \"value1\", \"value2\", \"value3\" ];\n for (var i = 0; i < myArray.length; i++) {\n $(\"#myOtherSelect\").append( '<option value=\"' + myArray[i] + '\">' + myArray[i] + '</option>' );\n }\n $(\"#myOtherSelect\").attr( \"size\", myArray.length );\n});\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65209", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9176/" ]
65,250
<p>Convert a .doc or .pdf to an image and display a thumbnail in Ruby?<br> Does anyone know how to generate document thumbnails in Ruby (or C, python...)</p>
[ { "answer_id": 69015, "author": "Federico Builes", "author_id": 161, "author_profile": "https://Stackoverflow.com/users/161", "pm_score": 0, "selected": false, "text": "´convert -size 300x300 doc.pdf doc.png´\n" }, { "answer_id": 69804, "author": "tomafro", "author_id": 7126, "author_profile": "https://Stackoverflow.com/users/7126", "pm_score": 6, "selected": true, "text": "require 'RMagick'\npdf = Magick::ImageList.new(\"doc.pdf\")\nthumb = pdf.scale(300, 300)\nthumb.write \"doc.png\"\n" }, { "answer_id": 24267898, "author": "SciPhi", "author_id": 765063, "author_profile": "https://Stackoverflow.com/users/765063", "pm_score": 2, "selected": false, "text": "require 'rmagick'\npdf_path = \"/path/to/interesting/file.pdf\"\npage_index_path = pdf_path + \"[0]\" # first page in PDF\npdf_page = Magick::Image.read( page_index_path ).first # first item in Magick::ImageList\npdf_page.write( \"/tmp/indexed-page.png\" ) # implicit conversion based on file extension\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65250", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
65,266
<p>Each time a python file is imported that contains a large quantity of static regular expressions, cpu cycles are spent compiling the strings into their representative state machines in memory.</p> <pre><code>a = re.compile("a.*b") b = re.compile("c.*d") ... </code></pre> <p>Question: Is it possible to store these regular expressions in a cache on disk in a pre-compiled manner to avoid having to execute the regex compilations on each import?</p> <p>Pickling the object simply does the following, causing compilation to happen anyway:</p> <pre><code>&gt;&gt;&gt; import pickle &gt;&gt;&gt; import re &gt;&gt;&gt; x = re.compile(".*") &gt;&gt;&gt; pickle.dumps(x) "cre\n_compile\np0\n(S'.*'\np1\nI0\ntp2\nRp3\n." </code></pre> <p>And <code>re</code> objects are unmarshallable:</p> <pre><code>&gt;&gt;&gt; import marshal &gt;&gt;&gt; import re &gt;&gt;&gt; x = re.compile(".*") &gt;&gt;&gt; marshal.dumps(x) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ValueError: unmarshallable object </code></pre>
[ { "answer_id": 65440, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 5, "selected": true, "text": "sre" }, { "answer_id": 65844, "author": "Pat Notz", "author_id": 825, "author_profile": "https://Stackoverflow.com/users/825", "pm_score": -1, "selected": false, "text": "\nimport re\nimport shelve\na_pattern = \"a.*b\"\nb_pattern = \"c.*d\"\na = re.compile(a_pattern)\nb = re.compile(b_pattern)\n\nx = shelve.open('re_cache')\nx[a_pattern] = a\nx[b_pattern] = b\nx.close()\n\n# ...\nx = shelve.open('re_cache')\na = x[a_pattern]\nb = x[b_pattern]\nx.close()\n\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65266", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9241/" ]
65,268
<p>I have a sample held in a buffer from DirectX. It's a sample of a note played and captured from an instrument. How do I analyse the frequency of the sample (like a guitar tuner does)? I believe FFTs are involved, but I have no pointers to HOWTOs.</p>
[ { "answer_id": 77946, "author": "AShelly", "author_id": 10396, "author_profile": "https://Stackoverflow.com/users/10396", "pm_score": 2, "selected": false, "text": "FFT(N, input, output);\nmax = max_i = 0;\nfor(i=0;i<N;i++)\n if (output[i]>max) max_i = i;\nroot = S/2.0 * max_i/N ;\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65268", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
65,310
<p>I am using Apache Axis to connect my Java app to a web server. I used wsdl2java to create the stubs for me, but when I try to use the stubs, I get the following exception:</p> <blockquote> <p>org.apache.axis.ConfigurationException: No service named <code>&lt;web service name&gt;</code> is available</p> </blockquote> <p>any idea?</p>
[ { "answer_id": 65575, "author": "ScArcher2", "author_id": 1310, "author_profile": "https://Stackoverflow.com/users/1310", "pm_score": 0, "selected": false, "text": "SomeServiceLocator locator = new SomeServiceLocator();\nSomeService service = null;\ntry\n{\n service = locator.getSomeServiceImplPort();\n}\ncatch (ServiceException e)\n{\n e.printStackTrace();\n}\n" }, { "answer_id": 179414, "author": "KC Baltz", "author_id": 9910, "author_profile": "https://Stackoverflow.com/users/9910", "pm_score": 3, "selected": true, "text": "throw new ConfigurationException(\"No service named\" + serviceName + \" is available\");\n" }, { "answer_id": 17981199, "author": "kldavis4", "author_id": 290918, "author_profile": "https://Stackoverflow.com/users/290918", "pm_score": 5, "selected": false, "text": "log4j.logger.org.apache.axis.ConfigurationException = INFO\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65310", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2328/" ]
65,351
<p>I have a generic method defined like this:</p> <pre><code>public void MyMethod&lt;T&gt;(T myArgument) </code></pre> <p>The first thing I want to do is check if the value of myArgument is the default value for that type, something like this:</p> <pre><code>if (myArgument == default(T)) </code></pre> <p>But this doesn't compile because I haven't guaranteed that T will implement the == operator. So I switched the code to this:</p> <pre><code>if (myArgument.Equals(default(T))) </code></pre> <p>Now this compiles, but will fail if myArgument is null, which is part of what I'm testing for. I can add an explicit null check like this:</p> <pre><code>if (myArgument == null || myArgument.Equals(default(T))) </code></pre> <p>Now this feels redundant to me. ReSharper is even suggesting that I change the myArgument == null part into myArgument == default(T) which is where I started. Is there a better way to solve this problem?</p> <p>I need to support <b>both</b> references types and value types.</p>
[ { "answer_id": 65423, "author": "Eric Schoonover", "author_id": 3957, "author_profile": "https://Stackoverflow.com/users/3957", "pm_score": 5, "selected": false, "text": "public class Test<T> where T : Exception\n" }, { "answer_id": 65445, "author": "Kent Boogaart", "author_id": 5380, "author_profile": "https://Stackoverflow.com/users/5380", "pm_score": 7, "selected": false, "text": "if (object.Equals(myArgument, default(T)))\n{\n //...\n}\n" }, { "answer_id": 65457, "author": "caryden", "author_id": 313, "author_profile": "https://Stackoverflow.com/users/313", "pm_score": -1, "selected": false, "text": "public void MyMethod<T>(T myArgument) where T : IComparable\n...\nif (0 == myArgument.ComparesTo(default(T)))\n" }, { "answer_id": 65461, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 4, "selected": false, "text": "if (EqualityComparer<T>.Default.Equals(myArgument, default(T)))\n" }, { "answer_id": 65498, "author": "cfeduke", "author_id": 5645, "author_profile": "https://Stackoverflow.com/users/5645", "pm_score": -1, "selected": false, "text": "public class Class<T> where T : IComparable\n{\n public T Value { get; set; }\n public void MyMethod(T val)\n {\n if (Value == val)\n return;\n }\n}\n" }, { "answer_id": 677151, "author": "Damian Powell", "author_id": 30321, "author_profile": "https://Stackoverflow.com/users/30321", "pm_score": 1, "selected": false, "text": "public static bool IsNullOrEmpty<T>(T value)\n{\n if (IsNull(value))\n {\n return true;\n }\n if (value is string)\n {\n return string.IsNullOrEmpty(value as string);\n }\n return value.Equals(default(T));\n}\n\npublic static bool IsNull<T>(T value)\n{\n if (value is ValueType)\n {\n return false;\n }\n return null == (object)value;\n}\n" }, { "answer_id": 864292, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 3, "selected": false, "text": "public static class TypeHelper<T>\n{\n public static bool IsDefault(T val)\n {\n return EqualityComparer<T>.Default.Equals(obj,default(T));\n }\n}\n\nstatic void Main(string[] args)\n{\n // value type\n Console.WriteLine(TypeHelper<int>.IsDefault(1)); //False\n Console.WriteLine(TypeHelper<int>.IsDefault(0)); // True\n\n // reference type\n Console.WriteLine(TypeHelper<string>.IsDefault(\"test\")); //False\n Console.WriteLine(TypeHelper<string>.IsDefault(null)); //True //True\n\n Console.ReadKey();\n}\n" }, { "answer_id": 864306, "author": "Nick Farina", "author_id": 66673, "author_profile": "https://Stackoverflow.com/users/66673", "pm_score": 3, "selected": false, "text": " T Get<T>(Func<T> createObject)\n {\n T obj = createObject();\n if (obj == null || obj.Equals(default(T)))\n return obj;\n\n // .. do a bunch of stuff\n return obj;\n }\n" }, { "answer_id": 864860, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 10, "selected": true, "text": "EqualityComparer<T>.Default" }, { "answer_id": 6857841, "author": "Scott McKay", "author_id": 684911, "author_profile": "https://Stackoverflow.com/users/684911", "pm_score": -1, "selected": false, "text": "if (myArgument.Equals(default(T)))\n" }, { "answer_id": 51236830, "author": "kofifus", "author_id": 460084, "author_profile": "https://Stackoverflow.com/users/460084", "pm_score": 0, "selected": false, "text": "public class MyClass<T>\n{\n private bool IsNull() \n {\n var nullable = Nullable.GetUnderlyingType(typeof(T)) != null;\n return nullable ? EqualityComparer<T>.Default.Equals(Value, default(T)) : false;\n }\n}\n" }, { "answer_id": 60281314, "author": "dynamiclynk", "author_id": 1427166, "author_profile": "https://Stackoverflow.com/users/1427166", "pm_score": 2, "selected": false, "text": " public static bool IsDefault<T>(this T inObj)\n {\n return EqualityComparer<T>.Default.Equals(inObj, default);\n }\n" }, { "answer_id": 66327304, "author": "Kosmas", "author_id": 2833737, "author_profile": "https://Stackoverflow.com/users/2833737", "pm_score": 0, "selected": false, "text": "private static int o;\npublic static void Main()\n{\n //output: IsNull = False -> IsDefault = True\n Console.WriteLine( \"IsNull = \" + IsNull( o ) + \" -> IsDefault = \" + IsDefault(o)); \n}\n\npublic static bool IsNull<T>(T paramValue)\n{\n if( string.IsNullOrEmpty(paramValue + \"\" ))\n return true;\n return false;\n}\n\npublic static bool IsDefault<T>(T val)\n{\n return EqualityComparer<T>.Default.Equals(val, default(T));\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65351", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8739/" ]
65,364
<p>I've created a seperate assembly with a class that is intended to be published through wmi. Then I've created a windows forms app that references that assembly and attempts to publish the class. When I try to publish the class, I get an exception of type System.Management.Instrumentation.WmiProviderInstallationException. The message of the exception says "Exception of type 'System.Management.Instrumentation.WMIInfraException' was thrown.". I have no idea what this means. I've tried .Net2.0 and .Net3.5 (sp1 too) and get the same results.</p> <p>Below is my wmi class, followed by the code I used to publish it.</p> <pre><code>//Interface.cs in assembly WMI.Interface.dll using System; using System.Collections.Generic; using System.Text; [assembly: System.Management.Instrumentation.WmiConfiguration(@"root\Test", HostingModel = System.Management.Instrumentation.ManagementHostingModel.Decoupled)] namespace WMI { [System.ComponentModel.RunInstaller(true)] public class MyApplicationManagementInstaller : System.Management.Instrumentation.DefaultManagementInstaller { } [System.Management.Instrumentation.ManagementEntity(Singleton = true)] [System.Management.Instrumentation.ManagementQualifier("Description", Value = "Obtain processor information.")] public class Interface { [System.Management.Instrumentation.ManagementBind] public Interface() { } [System.Management.Instrumentation.ManagementProbe] [System.Management.Instrumentation.ManagementQualifier("Descriiption", Value="The number of processors.")] public int ProcessorCount { get { return Environment.ProcessorCount; } } } } </code></pre> <p><BR/></p> <pre><code>//Button click in windows forms application to publish class try { System.Management.Instrumentation.InstrumentationManager.Publish(new WMI.Interface()); } catch (System.Management.Instrumentation.InstrumentationException exInstrumentation) { MessageBox.Show(exInstrumentation.ToString()); } catch (System.Management.Instrumentation.WmiProviderInstallationException exProvider) { MessageBox.Show(exProvider.ToString()); } catch (Exception exPublish) { MessageBox.Show(exPublish.ToString()); } </code></pre>
[ { "answer_id": 97083, "author": "Jeremy", "author_id": 9266, "author_profile": "https://Stackoverflow.com/users/9266", "pm_score": 2, "selected": false, "text": "// the namespace used for publishing the WMI classes and object instances \n[assembly: Instrumented(\"root/mytest\")]\n\nusing System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Management;\nusing System.Management.Instrumentation;\nusing System.Configuration.Install;\nusing System.ComponentModel;\n\nnamespace WMITest\n{\n\n [InstrumentationClass(System.Management.Instrumentation.InstrumentationType.Instance)] \n //[ManagementEntity()]\n //[ManagementQualifier(\"Description\",Value = \"Obtain processor information.\")]\n public class MyWMIInterface\n {\n //[System.Management.Instrumentation.ManagementBind]\n public MyWMIInterface()\n {\n }\n\n //[ManagementProbe]\n //[ManagementQualifier(\"Descriiption\", Value=\"The number of processors.\")]\n public int ProcessorCount\n {\n get { return Environment.ProcessorCount; }\n }\n }\n\n /// <summary>\n /// This class provides static methods to publish messages to WMI\n /// </summary>\n public static class InstrumentationProvider\n {\n /// <summary>\n /// publishes a message to the WMI repository\n /// </summary>\n /// <param name=\"MessageText\">the message text</param>\n /// <param name=\"Type\">the message type</param>\n public static MyWMIInterface Publish()\n {\n // create a new message\n MyWMIInterface pInterface = new MyWMIInterface();\n\n Instrumentation.Publish(pInterface);\n\n return pInterface;\n }\n\n /// <summary>\n /// revoke a previously published message from the WMI repository\n /// </summary>\n /// <param name=\"Message\">the message to revoke</param>\n public static void Revoke(MyWMIInterface pInterface)\n {\n Instrumentation.Revoke(pInterface);\n } \n }\n\n /// <summary>\n /// Installer class which will publish the InfoMessage to the WMI schema\n /// (the assembly attribute Instrumented defines the namespace this\n /// class gets published too\n /// </summary>\n [RunInstaller(true)]\n public class WMITestManagementInstaller :\n DefaultManagementProjectInstaller\n {\n }\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65364", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9266/" ]
65,400
<p>How do I add an instance method to a class using a metaclass (yes I do need to use a metaclass)? The following kind of works, but the func_name will still be "foo":</p> <pre><code>def bar(self): print "bar" class MetaFoo(type): def __new__(cls, name, bases, dict): dict["foobar"] = bar return type(name, bases, dict) class Foo(object): __metaclass__ = MetaFoo &gt;&gt;&gt; f = Foo() &gt;&gt;&gt; f.foobar() bar &gt;&gt;&gt; f.foobar.func_name 'bar' </code></pre> <p>My problem is that some library code actually uses the func_name and later fails to find the 'bar' method of the Foo instance. I could do:</p> <pre><code>dict["foobar"] = types.FunctionType(bar.func_code, {}, "foobar") </code></pre> <p>There is also types.MethodType, but I need an instance that does'nt exist yet to use that. Am I missing someting here?</p>
[ { "answer_id": 65682, "author": "Nathan Shively-Sanders", "author_id": 7851, "author_profile": "https://Stackoverflow.com/users/7851", "pm_score": 2, "selected": false, "text": ">>> class Foo():\n... def __init__(self, x):\n... self.x = x\n... \n>>> def bar(self):\n... print 'bar:', self.x\n... \n>>> bar.func_name = 'foobar'\n>>> Foo.foobar = bar\n>>> f = Foo(12)\n>>> f.foobar()\nbar: 12\n>>> f.foobar.func_name\n'foobar'\n" }, { "answer_id": 65716, "author": "Aaron Maenpaa", "author_id": 2603, "author_profile": "https://Stackoverflow.com/users/2603", "pm_score": 5, "selected": true, "text": "class Parent(object):\n def bar(self):\n print \"bar\"\n\nclass MetaFoo(type):\n def __new__(cls, name, bases, dict):\n return type(name, (Parent,) + bases, dict)\n\nclass Foo(object):\n __metaclass__ = MetaFoo\n\nif __name__ == \"__main__\":\n f = Foo()\n f.bar()\n print f.bar.func_name\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65400", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5179/" ]
65,427
<p>As I understand it, anything created with an <strong>alloc</strong>, <strong>new</strong>, or <strong>copy</strong> needs to be manually released. For example:</p> <pre><code>int main(void) { NSString *string; string = [[NSString alloc] init]; /* use the string */ [string release]; } </code></pre> <p>My question, though, is wouldn't this be just as valid?:</p> <pre><code>int main(void) { NSAutoreleasePool *pool; pool = [[NSAutoreleasePool alloc] init]; NSString *string; string = [[[NSString alloc] init] autorelease]; /* use the string */ [pool drain]; } </code></pre>
[ { "answer_id": 65517, "author": "Loren Segal", "author_id": 6436, "author_profile": "https://Stackoverflow.com/users/6436", "pm_score": -1, "selected": false, "text": "-drain" }, { "answer_id": 181043, "author": "mmalc", "author_id": 23233, "author_profile": "https://Stackoverflow.com/users/23233", "pm_score": 5, "selected": false, "text": "drain" }, { "answer_id": 7991256, "author": "Neovibrant", "author_id": 655292, "author_profile": "https://Stackoverflow.com/users/655292", "pm_score": 4, "selected": false, "text": "int main(void) {\n @autoreleasepool {\n NSString *string;\n string = [[[NSString alloc] init] autorelease];\n /* use the string */\n }\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65427", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7979/" ]
65,431
<p>Is there a reliable way to detect whether or not WinHelp is installed on Windows Vista or newer versions of Windows? If possible, I'd like a solution that's not specific to any particular version of Windows.</p> <p>I've posted this question to other message boards and got back answers regarding the size of Winhlp32.exe before and after installing WinHelp and Registry entries that Microsoft has documented, but none of them were correct.</p>
[ { "answer_id": 129698, "author": "TrevH", "author_id": 10124, "author_profile": "https://Stackoverflow.com/users/10124", "pm_score": 2, "selected": false, "text": "wmic qfe list full /format:htable >C:\\hotfixes.htm\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
65,434
<p>I know there are some ways to get notified when the page body has loaded (before all the images and 3rd party resources load which fires the <strong>window.onload</strong> event), but it's different for every browser.</p> <p>Is there a definitive way to do this on all the browsers?</p> <p>So far I know of:</p> <ul> <li><p><strong>DOMContentLoaded</strong> : On Mozilla, Opera 9 and newest WebKits. This involves adding a listener to the event:</p> <p>document.addEventListener( "DOMContentLoaded", [init function], false );</p></li> <li><p><strong>Deferred script</strong>: On IE, you can emit a SCRIPT tag with a @defer attribute, which will reliably only load after the closing of the BODY tag.</p></li> <li><p><strong>Polling</strong>: On other browsers, you can keep polling, but is there even a standard thing to poll for, or do you need to do different things on each browser?</p></li> </ul> <p>I'd like to be able to go without using document.write or external files.</p> <p>This can be done simply via jQuery:</p> <pre><code>$(document).ready(function() { ... }) </code></pre> <p>but, I'm writing a JS library and can't count on jQuery always being there.</p>
[ { "answer_id": 65476, "author": "Dave Ward", "author_id": 60, "author_profile": "https://Stackoverflow.com/users/60", "pm_score": -1, "selected": false, "text": "setTimeout(MyInitFunction, 0);\n" }, { "answer_id": 65527, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 4, "selected": true, "text": "DOMContentLoaded" }, { "answer_id": 66209, "author": "Pat", "author_id": 238, "author_profile": "https://Stackoverflow.com/users/238", "pm_score": 2, "selected": false, "text": "$(document).ready ( function () {\n //your code here\n});\n" }, { "answer_id": 70595, "author": "hulver", "author_id": 11496, "author_profile": "https://Stackoverflow.com/users/11496", "pm_score": -1, "selected": false, "text": "setTimeout(myFunction, 0);\nsetTimeout(anotherFunction, 0);\nsetTimeout(function(){ doSomething ...}, 0);\n" }, { "answer_id": 71085, "author": "Slartibartfast", "author_id": 4433, "author_profile": "https://Stackoverflow.com/users/4433", "pm_score": 0, "selected": false, "text": "<body> \n <!-- various content --> \n <script type=\"text/javascript\"> \n <!-- \n myInit(); \n -->\n </script> \n</body> \n" }, { "answer_id": 15338341, "author": "Justus Romijn", "author_id": 334243, "author_profile": "https://Stackoverflow.com/users/334243", "pm_score": 0, "selected": false, "text": "polling" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65434", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4465/" ]
65,447
<p>A sample perl script that connects to an oracle database, does a simple SELECT query, and spits the results to stdout in CSV format would be great. Python or any other language available in a typical unix distribution would be fine too. </p> <p>Note that I'm starting from scratch with nothing but a username/password for a remote Oracle database. Is there more to this than just having the right oracle connection library?</p> <p>If there's a way to do this directly in mathematica, that would be ideal (presumably it should be possible with J/Link (mathematica's java integration thingy)).</p>
[ { "answer_id": 65568, "author": "Jumpy", "author_id": 9416, "author_profile": "https://Stackoverflow.com/users/9416", "pm_score": 3, "selected": true, "text": "use DBI; \nuse DBD::Oracle;\n\n$dbh = DBI->connect( \"dbi:Oracle:host=127.0.0.1;sid=XE\", \"username\", \"password\" );\n\n# some settings that you usually want for oracle 10\n$dbh->{LongReadLen} = 65535;\n$dbh->{PrintError} = 0; \n\n$sth = $dbh->prepare(\"SELECT * FROM PEOPLE\");\n\n$sth->execute();\n\n# one example for error handling just to show how it's done in principle\nif ( $dbh->err() ) { die $dbh->errstr(); }\n\n# you can also do other types of fetchrow, see perldoc DBI \nwhile ( $arrayref = $sth->fetchrow_arrayref ) {\n print join \";\", @$arrayref;\n print \"\\n\";\n}\n\n$dbh->disconnect();\n" }, { "answer_id": 65689, "author": "Galuvian", "author_id": 1566663, "author_profile": "https://Stackoverflow.com/users/1566663", "pm_score": 2, "selected": false, "text": "import cx_Oracle, csv\n\norcl = cx_Oracle.connect('ohd/john@ohddb')\ncurs = orcl.cursor()\n\ncsv_file_dest = \"C:\\\\test.csv\"\n\noutput = csv.writer(open(csv_file_dest,'wb'))\n\nsql = \"select * from parameter\"\n\ncurs.execute(sql)\n\nheaders_printed = False\nfor row_data in curs: \n if not headers_printed:\n cols = []\n for col in curs.description:\n cols.append(col[0])\n output.writerow(cols)\n headers_printed = True\n\n output.writerow(row_data)\n" }, { "answer_id": 84764, "author": "Mike McAllister", "author_id": 16247, "author_profile": "https://Stackoverflow.com/users/16247", "pm_score": 0, "selected": false, "text": "CREATE TABLE MY_TABLE\n(\n COL1 NUMBER(2),\n COL2 VARCHAR2(20 BYTE)\n)\nORGANIZATION EXTERNAL\n ( TYPE ORACLE_LOADER\n DEFAULT DIRECTORY SOME_DIRECTORY_NAME\n ACCESS PARAMETERS \n ( FIELDS TERMINATED BY ','\n MISSING FIELD VALUES ARE NULL\n )\n LOCATION (SOME_DIRECTORY_NAME:'my_file.csv')\n )\nREJECT LIMIT UNLIMITED;\n" }, { "answer_id": 110013, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "set echo off heading off feedback off colsep ,;\nspool file.csv;\nselect owner, table_name\nfrom all_tables;\nspool off;\n" }, { "answer_id": 603665, "author": "jfklein", "author_id": 72919, "author_profile": "https://Stackoverflow.com/users/72919", "pm_score": 2, "selected": false, "text": "Needs[\"DatabaseLink`\"]\nconn = OpenSQLConnection[JDBC[\"mysql\",\"hostname/dbname\"], Username->\"user\", Password->\"secret\"]\nExport[\"file.csv\", SQLSelect[conn, \"MyTable\"]]\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65447", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4234/" ]
65,456
<p>I'm specifically interested in tools that can be plugged into Vim to allow CScope-style source browsing (1-2 keystroke commands to locate function definitions, callers, global symbols and so on) for languages besides C/C++ such as Java and C# (since Vim and Cscope already integrate very well for browsing C/C++). I'm not interested in IDE-based tools since I know Microsoft and other vendors already address that space -- I prefer to use Vim for editing and browsing, but but don't know of tools for C# and/or Java that give me the same power as CScope.</p> <p>The original answer to this question included a pointer to the CSWrapper application which apparently fixes a bug that some users experience integrating Vim and CScope. However, my Vim/CScope installation works fine; I'm just trying to expand the functionality to allow using Vim to edit code in other languages.</p>
[ { "answer_id": 164864, "author": "alps123", "author_id": 22337, "author_profile": "https://Stackoverflow.com/users/22337", "pm_score": 3, "selected": true, "text": "find . -name '*.java' > cscope.files\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65456", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8998/" ]
65,458
<p>There are many SCM systems out there. Some open, some closed, some free, some quite expensive. Which one <em>(please choose only one)</em> would you use for a 3000+ developer organization with several sites (some behind a very slow link)? Explain why you chose the one you chose. (Give some reasons, not just "because".)</p>
[ { "answer_id": 66332, "author": "Lanny", "author_id": 9127, "author_profile": "https://Stackoverflow.com/users/9127", "pm_score": 3, "selected": false, "text": "git" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65458", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9362/" ]
65,475
<p>What characters are valid in a Java class name? What other rules govern Java class names (for instance, Java class names cannot begin with a number)?</p>
[ { "answer_id": 65531, "author": "Ivan Bosnic", "author_id": 3221, "author_profile": "https://Stackoverflow.com/users/3221", "pm_score": 4, "selected": false, "text": "static final int NUM_GEARS = 6" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8720/" ]
65,491
<p>When working with large and/or many Javascript and CSS files, what's the best way to reduce the file sizes?</p>
[ { "answer_id": 65505, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 0, "selected": false, "text": "function compressCSS($css) {\n return\n preg_replace(\n array('@\\s\\s+@','@(\\w+:)\\s*([\\w\\s,#]+;?)@'),\n array(' ','$1$2'),\n str_replace(\n array(\"\\r\",\"\\n\",\"\\t\",' {','} ',';}'),\n array('','','','{','}','}'),\n preg_replace('@/\\*[^*]*\\*+([^/][^*]*\\*+)*/@', '', $css)\n )\n )\n ;\n}\n" }, { "answer_id": 66436, "author": "Jim", "author_id": 8987, "author_profile": "https://Stackoverflow.com/users/8987", "pm_score": 5, "selected": true, "text": "background: #fff url(image.gif) no-repeat top left;\n" }, { "answer_id": 77511, "author": "Dave Lockhart", "author_id": 9960, "author_profile": "https://Stackoverflow.com/users/9960", "pm_score": 2, "selected": false, "text": "<script src=\"my_js_file.js?1.2.0.1\" type=\"text/javascript\"></script>" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
65,512
<p>I've heard that <code>SELECT *</code> is generally bad practice to use when writing SQL commands because it is more efficient to <code>SELECT</code> columns you specifically need.</p> <p>If I need to <code>SELECT</code> every column in a table, should I use </p> <pre><code>SELECT * FROM TABLE </code></pre> <p>or </p> <pre><code>SELECT column1, colum2, column3, etc. FROM TABLE </code></pre> <p>Does the efficiency really matter in this case? I'd think <code>SELECT *</code> would be more optimal internally if you really need all of the data, but I'm saying this with no real understanding of database.</p> <p>I'm curious to know what the best practice is in this case.</p> <p><strong>UPDATE:</strong> I probably should specify that the only situation where I would really <em>want</em> to do a <code>SELECT *</code> is when I'm selecting data from one table where I know all columns will always need to be retrieved, even when new columns are added. </p> <p>Given the responses I've seen however, this still seems like a bad idea and <code>SELECT *</code> should never be used for a lot more technical reasons that I ever though about.</p>
[ { "answer_id": 67380, "author": "IDisposable", "author_id": 2076, "author_profile": "https://Stackoverflow.com/users/2076", "pm_score": 6, "selected": false, "text": "SELECT *" }, { "answer_id": 2972041, "author": "Matthew Abbott", "author_id": 357693, "author_profile": "https://Stackoverflow.com/users/357693", "pm_score": 2, "selected": false, "text": "SELECT Field1, Field2 FROM SomeTable WHERE --(constraints)\n" }, { "answer_id": 2972058, "author": "bkaid", "author_id": 265570, "author_profile": "https://Stackoverflow.com/users/265570", "pm_score": 0, "selected": false, "text": "SELECT *" }, { "answer_id": 2972114, "author": "pkh", "author_id": 334871, "author_profile": "https://Stackoverflow.com/users/334871", "pm_score": 5, "selected": false, "text": "select *" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65512", "https://Stackoverflow.com", "https://Stackoverflow.com/users/392/" ]
65,515
<p>What techniques or tools are recommended for finding broken links on a website?</p> <p>I have access to the logfiles, so could conceivably parse these looking for 404 errors, but would like something automated which will follow (or attempt to follow) all links on a site.</p>
[ { "answer_id": 65625, "author": "ConroyP", "author_id": 2287, "author_profile": "https://Stackoverflow.com/users/2287", "pm_score": 0, "selected": false, "text": "// Pseudo-code to recursively check for broken links\n// logging all errors centrally\nfunction check_links($page)\n{\n $html = fetch_page($page);\n if(!$html)\n {\n // Log page to failures log\n ...\n }\n else\n {\n // Find all html, img, etc links on page\n $links = find_links_on_page($html);\n foreach($links as $link)\n {\n check_links($link);\n }\n }\n}\n" }, { "answer_id": 15029100, "author": "wjbrown", "author_id": 2100180, "author_profile": "https://Stackoverflow.com/users/2100180", "pm_score": 5, "selected": false, "text": "wget --spider -o wget.log -e robots=off --wait 1 -r -p http://www.example.com\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65515", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2084/" ]
65,524
<p>What is the best way to generate a Unique ID from two (or more) short ints in C++? I am trying to uniquely identify vertices in a graph. The vertices contain two to four short ints as data, and ideally the ID would be some kind of a hash of them. Prefer portability and uniqueness over speed or ease. </p> <p>There are a lot of great answers here, I will be trying them all tonight to see what fits my problem the best. A few more words on what I'm doing. </p> <p>The graph is a collection of samples from an audio file. I use the graph as a Markov Chain to generate a new audio file from the old file. Since each vertex stores a few samples and points to another sample, and the samples are all short ints, it seemed natural to generate an ID from the data. Combining them into a long long sounds good, but maybe something as simple as just a 0 1 2 3 <code>generateID</code> is all I need. not sure how much space is necessary to guarantee uniqueness, if each vertex stores 2 16 bit samples, there are 2^32 possible combinations correct? and so if each vertex stores 4 samples, there are 2^64 possible combinations? </p> <p>Library and platform specific solutions not really relevant to this question. I don't want anyone else who might compile my program to have to download additional libraries or change the code to suit their OS. </p>
[ { "answer_id": 65551, "author": "Fire Lancer", "author_id": 6266, "author_profile": "https://Stackoverflow.com/users/6266", "pm_score": 0, "selected": false, "text": "int ID = ((int)short1 << 16) | short2;\n" }, { "answer_id": 65589, "author": "Doug T.", "author_id": 8123, "author_profile": "https://Stackoverflow.com/users/8123", "pm_score": 4, "selected": true, "text": "uint64_t generateId( uint16_t v1, uint16_t v2, uint16_t v3, uint16_t v4)\n{ \n uint64_t id;\n id = v1 | (((uint64_t)v2) << 16) | (((uint64_t)v3) << 32) | (((uint64_t)v4) << 48);\n return id;\n}\n" }, { "answer_id": 65599, "author": "Jeroen Dirks", "author_id": 7743, "author_profile": "https://Stackoverflow.com/users/7743", "pm_score": 3, "selected": false, "text": "static int sNextId = 0;\nint getNextId() { return ++sNextId; }\n" }, { "answer_id": 65632, "author": "basszero", "author_id": 287, "author_profile": "https://Stackoverflow.com/users/287", "pm_score": -1, "selected": false, "text": "id = 3 * value1 + 5 * value2 + .... + somePrime * valueN\n" }, { "answer_id": 65835, "author": "David Dolson", "author_id": 8566, "author_profile": "https://Stackoverflow.com/users/8566", "pm_score": 0, "selected": false, "text": "typedef boost::tuple<uint16,uint16,uint16,uint16> VertexID;\n" }, { "answer_id": 65884, "author": "xtofl", "author_id": 6610, "author_profile": "https://Stackoverflow.com/users/6610", "pm_score": 0, "selected": false, "text": "std::map" }, { "answer_id": 67500572, "author": "Arslan Tariq", "author_id": 15904952, "author_profile": "https://Stackoverflow.com/users/15904952", "pm_score": 0, "selected": false, "text": "int generateID()\n{\n static int s_itemID{ 0 };\n return s_itemID++; // makes copy of s_itemID,\n increments the real s_itemID, \n then returns the value in the copy\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65524", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8264/" ]
65,530
<p>In Tomcat 5.5 the server.xml can have many connectors, typically port only 8080, but for my application a user might configure their servlet.xml to also have other ports open (say 8081-8088). I would like for my servlet to figure out what socket connections ports will be vaild (During the Servlet.init() tomcat has not yet started the connectors.) </p> <p>I could find and parse the server.xml myself (grotty), I could look at the thread names (after tomcat starts up - but how would I know when a good time to do that is? ) But I would prefer a solution that can execute in my servlet.init() and determine what will be the valid port range. Any ideas? A solution can be tightly bound to Tomcat for my application that's ok.</p>
[ { "answer_id": 65656, "author": "jrudolph", "author_id": 7647, "author_profile": "https://Stackoverflow.com/users/7647", "pm_score": 3, "selected": true, "text": "org.apache.catalina.ServerFactory.getServer().getServices \n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65530", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6580/" ]
65,536
<p>How would I get the <code>here</code> and <code>and here</code> to be on the right, on the same lines as the lorem ipsums? See the following:</p> <pre class="lang-none prettyprint-override"><code>Lorem Ipsum etc........here blah....................... blah blah.................. blah....................... lorem ipsums.......and here </code></pre>
[ { "answer_id": 65572, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<div>" }, { "answer_id": 65591, "author": "AdamB", "author_id": 2176, "author_profile": "https://Stackoverflow.com/users/2176", "pm_score": 0, "selected": false, "text": "<div>" }, { "answer_id": 65594, "author": "ceejayoz", "author_id": 1902010, "author_profile": "https://Stackoverflow.com/users/1902010", "pm_score": 0, "selected": false, "text": "position: relative" }, { "answer_id": 65600, "author": "Garry Shutler", "author_id": 6369, "author_profile": "https://Stackoverflow.com/users/6369", "pm_score": 6, "selected": true, "text": "<div style=\"position: relative; width: 250px;\">\n <div style=\"position: absolute; top: 0; right: 0; width: 100px; text-align:right;\">\n here\n </div>\n <div style=\"position: absolute; bottom: 0; right: 0; width: 100px; text-align:right;\">\n and here\n </div>\n Lorem Ipsum etc <br />\n blah <br />\n blah blah <br />\n blah <br />\n lorem ipsums\n</div>" }, { "answer_id": 65612, "author": "Loren Segal", "author_id": 6436, "author_profile": "https://Stackoverflow.com/users/6436", "pm_score": 1, "selected": false, "text": "<style>\n #content { width: 300px; height: 300px; border: 1px solid black; position: relative; }\n .topright { position: absolute; top: 5px; right: 5px; text-align: right; }\n .bottomright { position: absolute; bottom: 5px; right: 5px; text-align: right; }\n</style>\n<div id=\"content\">\n <div class=\"topright\">here</div>\n <div class=\"bottomright\">and here</div>\n Lorem ipsum etc................\n</div>\n" }, { "answer_id": 65652, "author": "BrewinBombers", "author_id": 5989, "author_profile": "https://Stackoverflow.com/users/5989", "pm_score": 1, "selected": false, "text": "print(\"<div id=\"lipsum\">\");\nprint(\"<div id=\"here\">\");\nprint(\" here\");\nprint(\"</div>\");\nprint(\"<div id=\"andhere\">\");\nprint(\"and here\");\nprint(\"</div>\");\nprint(\"blah\");\nprint(\"</div>\");\n" }, { "answer_id": 66205, "author": "Bruce", "author_id": 9698, "author_profile": "https://Stackoverflow.com/users/9698", "pm_score": 0, "selected": false, "text": "<dl>\n <dt>Lorem Ipsum etc <em>here</em></dt>\n <dd>blah</dd>\n <dd>blah blah</dd>\n <dd>blah</dd>\n <dt>lorem ipsums <em>and here</em></dt>\n</dl>\n" }, { "answer_id": 66210, "author": "phloopy", "author_id": 8507, "author_profile": "https://Stackoverflow.com/users/8507", "pm_score": 2, "selected": false, "text": "<html>\n <body>\n <div>\n <span style=\"float:right\">here</span>Lorem Ipsum etc<br/>\n blah<br/>\n blah blah<br/>\n blah<br/>\n <span style=\"float:right\">and here</span>lorem ipsums<br/>\n </div>\n </body>\n</html>\n" }, { "answer_id": 9856362, "author": "trillions", "author_id": 962382, "author_profile": "https://Stackoverflow.com/users/962382", "pm_score": 0, "selected": false, "text": "#date {\n margin-right:5px;\n position:relative;\n float:right;\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65536", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9328/" ]
65,566
<p>I have a control that, upon postback, saves form results back to the database. It populates the values to be saved by iterating through the querystring. So, for the following SQL statement (vastly simplified for the sake of discussion)...</p> <pre><code>UPDATE MyTable SET MyVal1 = @val1, MyVal2 = @val2 WHERE @id = @id </code></pre> <p>...it would cycle through the querystring keys thusly:</p> <pre><code>For Each Key As String In Request.QueryString.Keys Command.Parameters.AddWithValue("@" &amp; Key, Request.QueryString(Key)) Next </code></pre> <p>HOWEVER, I'm now running into a situation where, under certain circumstances, some of these variables may not be present in the querystring. If I don't pass along val2 in the querystring, I get an error: <code>System.Data.SqlClient.SqlException: Must declare the scalar value "@val2"</code>.</p> <p>Attempts to detect the missing value in the SQL statement...</p> <pre><code>IF @val2 IS NOT NULL UPDATE MyTable SET MyVal1 = @val1, MyVal2 = @val2 WHERE @id = @id </code></pre> <p>... have failed.</p> <p>What's the best way to attack this? Must I parse the SQL block with RegEx, scanning for variable names not present in the querystring? Or, is there a more elegant way to approach?</p> <p>UPDATE: Detecting null values in the VB codebehind defeats the purpose of decoupling the code from its context. I'd rather not litter my function with conditions for every conceivable variable that might be passed, or not passed.</p>
[ { "answer_id": 65629, "author": "Sander Rijken", "author_id": 5555, "author_profile": "https://Stackoverflow.com/users/5555", "pm_score": 3, "selected": false, "text": "Command.Parameters.AddWithValue(\"@val2\", null)\n" }, { "answer_id": 65676, "author": "user7658", "author_id": 7658, "author_profile": "https://Stackoverflow.com/users/7658", "pm_score": 0, "selected": false, "text": "AddWithValue" }, { "answer_id": 66698, "author": "dansays", "author_id": 1923, "author_profile": "https://Stackoverflow.com/users/1923", "pm_score": 1, "selected": true, "text": "Dim FieldRegEx As New Regex(\"@([A-Z_]+)\", RegexOptions.IgnoreCase)\nDim Fields As Match = FieldRegEx.Match(Query)\nDim Processed As New ArrayList\n\nWhile Fields.Success\n Dim Key As String = Fields.Groups(1).Value\n Dim Val As Object = Request.QueryString(Key)\n If Val = \"\" Then Val = DBNull.Value\n If Not Processed.Contains(Key) Then\n Command.Parameters.AddWithValue(\"@\" & Key, Val)\n Processed.Add(Key)\n End If\n Fields = Fields.NextMatch()\nEnd While\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1923/" ]
65,585
<p>I want to delete foo() if foo() isn't called from anywhere.</p>
[ { "answer_id": 65740, "author": "Helen Toomik", "author_id": 9449, "author_profile": "https://Stackoverflow.com/users/9449", "pm_score": 3, "selected": false, "text": "public" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65585", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9328/" ]
65,607
<p>I've been attempting to write a Lisp macro that would perfom the equivalent of ++ in other programming languages for semantic reasons. I've attempted to do this in several different ways, but none of them seem to work, and all are accepted by the interpreter, so I don't know if I have the correct syntax or not. My idea of how this would be defined would be</p> <pre><code>(defmacro ++ (variable) (incf variable)) </code></pre> <p>but this gives me a SIMPLE-TYPE-ERROR when trying to use it. What would make it work?</p>
[ { "answer_id": 65641, "author": "Kyle Cronin", "author_id": 658, "author_profile": "https://Stackoverflow.com/users/658", "pm_score": 5, "selected": true, "text": "(defmacro ++ (variable)\n `(incf ,variable))\n" }, { "answer_id": 65657, "author": "Drew Olson", "author_id": 9434, "author_profile": "https://Stackoverflow.com/users/9434", "pm_score": -1, "selected": false, "text": "(defmacro ++ (variable)\n `(setq ,variable (+ ,variable 1)))\n" }, { "answer_id": 66863, "author": "user10029", "author_id": 10029, "author_profile": "https://Stackoverflow.com/users/10029", "pm_score": 4, "selected": false, "text": "(++ varname)\n" }, { "answer_id": 77562, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "(define-modify-macro my-incf () 1+)\n" }, { "answer_id": 241721, "author": "Svante", "author_id": 31615, "author_profile": "https://Stackoverflow.com/users/31615", "pm_score": 3, "selected": false, "text": "(defmacro post-inc (number &optional (delta 1))\n \"Returns the current value of number, and afterwards increases it by delta (default 1).\"\n (let ((value (gensym)))\n `(let ((,value ,number))\n (incf ,number ,delta)\n ,value)))\n" }, { "answer_id": 10567794, "author": "Kaz", "author_id": 1250772, "author_profile": "https://Stackoverflow.com/users/1250772", "pm_score": 4, "selected": false, "text": "(++ a)" }, { "answer_id": 36115653, "author": "fr_andres", "author_id": 4511978, "author_profile": "https://Stackoverflow.com/users/4511978", "pm_score": 2, "selected": false, "text": "make-dispatch-macro-character" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65607", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1256/" ]
65,627
<p>In a Flex <code>AdvancedDatGrid</code>, we're doing a lot of grouping. Most of the columns are the same for the parents and for the children, so I'd like to show the first value of the group as the summary rather than the MAX, MIN or AVG</p> <p>This code works on numerical but not textual values (without the commented line you get NaN's):</p> <pre><code>private function firstValue(itr:IViewCursor,field:String, str:String=null):Object { //if(isNaN(itr.current[field])) return 0 //Theory: Only works on Numeric Values? return itr.current[field] } </code></pre> <p>The XML:</p> <pre><code>(mx:GroupingField name="Offer") (mx:summaries) (mx:SummaryRow summaryPlacement="group") (mx:fields) (mx:SummaryField dataField="OfferDescription" label="OfferDescription" summaryFunction="firstValue"/) (mx:SummaryField dataField="OfferID" label="OfferID" summaryFunction="firstValue"/) (/mx:fields) (/mx:SummaryRow) (/mx:summaries) (/mx:GroupingField) </code></pre> <p><code>OfferID</code>'s work Correctly, <code>OfferDescription</code>s don't.</p>
[ { "answer_id": 1406545, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": " private function getNestedItem(item:Object):Object {\n\n try {\n if (item.undefined[0]) {\n item = getNestedItem(item.undefined[0]);\n }\n } catch (e:Error) {\n // leave item alone\n }\n return item;\n } \n private function formatColumn(item:Object, column:AdvancedDataGridColumn):String {\n\n var output:String;\n // If this is a summary row\n if (item.GroupLabel) {\n\n item = getNestedItem(item);\n } \n\n switch (column.dataField) {\n\n case 'comment':\n\n return item.comment;\n\n\n }\n\n }\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65627", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9056/" ]
65,651
<p>I'm a longtime Java programmer working on a PHP project, and I'm trying to get PHPUnit up and working. When unit testing in Java, it's common to put test case classes and regular classes into separate directories, like this -</p> <pre><code>/src MyClass.java /test MyClassTest.java </code></pre> <p>and so on.</p> <p>When unit testing with PHPUnit, is it common to follow the same directory structure, or is there a better way to lay out test classes? So far, the only way I can get the "include("MyClass.php")" statement to work correctly is to include the test class in the same directory, but I don't want to include the test classes when I push to production.</p>
[ { "answer_id": 65754, "author": "Brian Phillips", "author_id": 7230, "author_profile": "https://Stackoverflow.com/users/7230", "pm_score": 2, "selected": false, "text": "include()" }, { "answer_id": 65814, "author": "Mattias", "author_id": 261, "author_profile": "https://Stackoverflow.com/users/261", "pm_score": 5, "selected": true, "text": "/myapp/src/ <- my classes\n/myapp/tests/ <- my tests for the classes\n/myapp/public/ <- document root\n" }, { "answer_id": 614392, "author": "willw", "author_id": 66081, "author_profile": "https://Stackoverflow.com/users/66081", "pm_score": 2, "selected": false, "text": "set_include_path(get_include_path() . PATH_SEPARATOR . \n dirname(__FILE__) . \"/../src\");\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65651", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8770/" ]
65,668
<p>Someone told me it's more efficient to use <code>StringBuffer</code> to concatenate strings in Java than to use the <code>+</code> operator for <code>String</code>s. What happens under the hood when you do that? What does <code>StringBuffer</code> do differently?</p>
[ { "answer_id": 65677, "author": "André Chalella", "author_id": 4850, "author_profile": "https://Stackoverflow.com/users/4850", "pm_score": 4, "selected": false, "text": "String" }, { "answer_id": 65678, "author": "jodonnell", "author_id": 4223, "author_profile": "https://Stackoverflow.com/users/4223", "pm_score": 3, "selected": false, "text": "String s = \"a\" + \"b\" + \"c\";\n" }, { "answer_id": 65684, "author": "Loren Segal", "author_id": 6436, "author_profile": "https://Stackoverflow.com/users/6436", "pm_score": 1, "selected": false, "text": "myString = myString + \"XYZ\"\n" }, { "answer_id": 65727, "author": "Calum", "author_id": 8434, "author_profile": "https://Stackoverflow.com/users/8434", "pm_score": 6, "selected": false, "text": "String third = first + second;\n" }, { "answer_id": 65891, "author": "tkokoszka", "author_id": 42201, "author_profile": "https://Stackoverflow.com/users/42201", "pm_score": 5, "selected": false, "text": "String s = \"a\" + \"b\" + \"c\";\n" }, { "answer_id": 65893, "author": "jb.", "author_id": 7918, "author_profile": "https://Stackoverflow.com/users/7918", "pm_score": 2, "selected": false, "text": "String foo = \"a\" + \"b\" + \"c\";\n" }, { "answer_id": 65964, "author": "Brian", "author_id": 9493, "author_profile": "https://Stackoverflow.com/users/9493", "pm_score": 3, "selected": false, "text": "string myString=\"\";\nfor(int i=0;i<x;i++)\n{\n myString += \"x\";\n}\n" }, { "answer_id": 1156919, "author": "Eric Yung", "author_id": 103340, "author_profile": "https://Stackoverflow.com/users/103340", "pm_score": 2, "selected": false, "text": "\npublic final class StringBuffer extends AbstractStringBuilder\n implements Serializable, CharSequence\n{\n// .. skip ..\n public synchronized StringBuffer append(StringBuffer stringbuffer)\n {\n super.append(stringbuffer);\n return this;\n }\n// .. skip ..\n}\n" }, { "answer_id": 58792872, "author": "Priyantha", "author_id": 7467246, "author_profile": "https://Stackoverflow.com/users/7467246", "pm_score": 2, "selected": false, "text": "Hello" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65668", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
65,683
<p>I would like to know how to write PHPUnit tests with Zend_Test and in general with PHP.</p>
[ { "answer_id": 70082, "author": "Stefan Gehrig", "author_id": 11354, "author_profile": "https://Stackoverflow.com/users/11354", "pm_score": 4, "selected": false, "text": "abstract class Controller_TestCase extends Zend_Test_PHPUnit_ControllerTestCase\n{\n protected function setUp()\n {\n $this->bootstrap=array($this, 'appBootstrap');\n Zend_Auth::getInstance()->setStorage(new Zend_Auth_Storage_NonPersistent());\n parent::setUp();\n }\n\n protected function tearDown()\n {\n Zend_Auth::getInstance()->clearIdentity();\n }\n\n protected function appBootstrap()\n {\n Application::setup();\n }\n}\n" }, { "answer_id": 2399785, "author": "Alex", "author_id": 288568, "author_profile": "https://Stackoverflow.com/users/288568", "pm_score": 1, "selected": false, "text": "phpunit --bootstrap ../bootstrap.php PersonControllerTest.php \n" }, { "answer_id": 5709984, "author": "KdPurvesh", "author_id": 708903, "author_profile": "https://Stackoverflow.com/users/708903", "pm_score": 0, "selected": false, "text": "public function setUp() {\n\n\n\n YOUR_ZEND_DB_INSTANCE::getInstance()->setUnitTestMode(true);\n\n\n\n YOUR_ZEND_DB_INSTANCE::getInstance()->query(\"BEGIN\");\n\n YOUR_ZEND_DB_INSTANCE::getInstance()->getCache()->clear();\n\n // Manually Start a Doctrine Transaction so we can roll it back\n Doctrine_Manager::connection()->beginTransaction();\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65683", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
65,687
<p>Can someone tell me how to get path geometry from a WPF FlowDocument object? Please note that I do <strong>not</strong> want to use <code>FormattedText</code>. Thanks.</p>
[ { "answer_id": 87716, "author": "Tim Erickson", "author_id": 8787, "author_profile": "https://Stackoverflow.com/users/8787", "pm_score": 1, "selected": false, "text": "FlowDocument myFlowDocument = new FlowDocument(); //get your FlowDocument\n\n//put in some (or it already has) text\nstring inText = \"Hello, WPF World!\";\nTextRange tr = new TextRange(FlowDocument.ContentStart, FlowDocument.ContentEnd);\ntr.Text = inText;\n\n//get the current text out of the FlowDocument\nTextRange trPrime = new TextRange(FlowDocument.ContentStart, FlowDocument.ContentEnd);\nstring outText = trPrime.Text;\n\n//now outText == \"Hello, WPF World!\";\n\n//to get formatting, looks like you would use myFlowDocument.TextEffects\n" }, { "answer_id": 640230, "author": "Robert Macnee", "author_id": 19273, "author_profile": "https://Stackoverflow.com/users/19273", "pm_score": 2, "selected": true, "text": "FlowDocument" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65687", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9476/" ]
65,718
<p>Maybe this is a silly question, but I've always assumed each number delineated by a period represented a single component of the software. If that's true, do they ever represent something different? I'd like to start assigning versions to the different builds of my software, but I'm not really sure how it should be structured. My software has five distinct components.</p>
[ { "answer_id": 65807, "author": "Thomas Jespersen", "author_id": 8547, "author_profile": "https://Stackoverflow.com/users/8547", "pm_score": 1, "selected": false, "text": "// Version information for an assembly consists of the following four values:\n//\n// Major Version\n// Minor Version \n// Build Number\n// Revision\n//\n/ You can specify all the values or you can default the Build and Revision Numbers \n// by using the '*' as shown below:\n// [assembly: AssemblyVersion(\"1.0.*\")]\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65718", "https://Stackoverflow.com", "https://Stackoverflow.com/users/191808/" ]
65,724
<p>As everyone knows, the <a href="http://en.wikipedia.org/wiki/Visual_C%2B%2B" rel="nofollow noreferrer">Visual C++</a> runtime marks uninitialized or just freed memory blocks with special non-zero markers. Is there any way to disable this behavior entirely without manually setting all uninitialized memory to zeros? It's causing havoc with my valid not null checks, since <code>0xFEEEFEEE != 0</code>.</p> <p>Hrm, perhaps I should explain a bit better. I create and initialize a variable (via new), and that all goes just fine. When I free it (via delete), it sets the pointer to <code>0xFEEEFEEE</code> instead of <code>NULL</code>. When I insert a proper check for <code>NULL</code>, as all good programs that manage their own memory should, I come up with problems as <code>0xFEEEFEEE</code> passes a <code>NULL</code> check without problems. Is there any good way, other than manually setting all pointers to <code>NULL</code> when deleting them, to detect when memory has already been freed? I would prefer to not use <a href="http://en.wikipedia.org/wiki/Boost_C%2B%2B_Libraries" rel="nofollow noreferrer">Boost</a> simply because I don't want the overhead, small though it may be, since that's the only thing I'd be using Boost for.</p>
[ { "answer_id": 65760, "author": "Eclipse", "author_id": 8701, "author_profile": "https://Stackoverflow.com/users/8701", "pm_score": 4, "selected": false, "text": "NULL" }, { "answer_id": 65777, "author": "Fire Lancer", "author_id": 6266, "author_profile": "https://Stackoverflow.com/users/6266", "pm_score": 0, "selected": false, "text": "int *ptr=0;\n" }, { "answer_id": 66036, "author": "Ted", "author_id": 8965, "author_profile": "https://Stackoverflow.com/users/8965", "pm_score": 4, "selected": true, "text": "delete" }, { "answer_id": 69116, "author": "Curro", "author_id": 10688, "author_profile": "https://Stackoverflow.com/users/10688", "pm_score": 2, "selected": false, "text": "NULL" }, { "answer_id": 69199, "author": "Cliff Cawley", "author_id": 10957, "author_profile": "https://Stackoverflow.com/users/10957", "pm_score": 0, "selected": false, "text": "#define SafeDelete(mem) { delete mem; mem = NULL; }\n#define SafeDeleteArray(mem) { delete [] mem; mem = NULL; }" }, { "answer_id": 79170, "author": "Michael Burr", "author_id": 12711, "author_profile": "https://Stackoverflow.com/users/12711", "pm_score": 1, "selected": false, "text": "0xFEEEFEEE" }, { "answer_id": 79587, "author": "Dan Shield", "author_id": 4633, "author_profile": "https://Stackoverflow.com/users/4633", "pm_score": 2, "selected": false, "text": "NULL" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65724", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8844/" ]
65,734
<p>This link describes an exploit into my app using fckEditor: <a href="http://knitinr.blogspot.com/2008/07/script-exploit-via-fckeditor.html" rel="nofollow noreferrer">http://knitinr.blogspot.com/2008/07/script-exploit-via-fckeditor.html</a></p> <p>How do I make my app secure while still using fckEditor? Is it an fckEditor configuration? Is it some processing I'm supposed to do server-side after I grab the text from fckEditor?</p> <p>It's a puzzle because fckEditor <em>USES</em> html tags for its formatting, so I can't just HTML encode when I display back the text.</p>
[ { "answer_id": 65851, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 2, "selected": false, "text": "<b><script>evil here</script></b>" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65734", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9328/" ]
65,820
<p>I worked on an embedded system this summer written in straight C. It was an existing project that the company I work for had taken over. I have become quite accustomed to writing unit tests in Java using JUnit but was at a loss as to the best way to write unit tests for existing code (which needed refactoring) as well as new code added to the system.</p> <p>Are there any projects out there that make unit testing plain C code as easy as unit testing Java code with JUnit? Any insight that would apply specifically to embedded development (cross-compiling to arm-linux platform) would be greatly appreciated.</p>
[ { "answer_id": 69820, "author": "Ovid", "author_id": 8003, "author_profile": "https://Stackoverflow.com/users/8003", "pm_score": 5, "selected": false, "text": "#include <tap.h>\n\nint main () {\n plan(5);\n\n ok(3 == 3);\n is(\"fnord\", \"eek\", \"two different strings not that way?\");\n ok(3 <= 8732, \"%d <= %d\", 3, 8732);\n like(\"fnord\", \"f(yes|no)r*[a-f]$\");\n cmp_ok(3, \">=\", 10);\n\n done_testing();\n}\n" }, { "answer_id": 72495, "author": "navicore", "author_id": 7223, "author_profile": "https://Stackoverflow.com/users/7223", "pm_score": 4, "selected": false, "text": "check_PROGRAMS = test_oe_amqp\n\ntest_oe_amqp_SOURCES = test_oe_amqp.c\ntest_oe_amqp_LDADD = -L$(top_builddir)/components/common -loecommon\ntest_oe_amqp_CFLAGS = -I$(top_srcdir)/components/common -static\n\nTESTS = test_oe_amqp\n" }, { "answer_id": 1410143, "author": "mikelong", "author_id": 5775, "author_profile": "https://Stackoverflow.com/users/5775", "pm_score": 8, "selected": false, "text": "#include \"myimplementationfile.c\"\n#include <gtest/gtest.h>\n\n// Mock out external dependency on mylogger.o\nvoid Logger_log(...){}\n\nTEST(FactorialTest, Zero) {\n EXPECT_EQ(1, Factorial(0));\n}\n" }, { "answer_id": 7700365, "author": "chelmertz", "author_id": 49879, "author_profile": "https://Stackoverflow.com/users/49879", "pm_score": 4, "selected": false, "text": "assert()" }, { "answer_id": 8047799, "author": "Johan", "author_id": 51425, "author_profile": "https://Stackoverflow.com/users/51425", "pm_score": 6, "selected": false, "text": "#include <unity.h>\n\nvoid test_true_should_be_true(void)\n{\n TEST_ASSERT_TRUE(true);\n}\n\nint main(void)\n{\n UNITY_BEGIN();\n RUN_TEST(test_true_should_be_true);\n return UNITY_END();\n}\n" }, { "answer_id": 14425102, "author": "asn", "author_id": 577774, "author_profile": "https://Stackoverflow.com/users/577774", "pm_score": 5, "selected": false, "text": "#include <stdarg.h>\n#include <stddef.h>\n#include <setjmp.h>\n#include <cmocka.h>\n\n/* A test case that does nothing and succeeds. */\nstatic void null_test_success(void **state) {\n (void) state; /* unused */\n}\n\nint main(void) {\n const struct CMUnitTest tests[] = {\n cmocka_unit_test(null_test_success),\n };\n return cmocka_run_group_tests(tests, NULL, NULL);\n}\n" }, { "answer_id": 26183598, "author": "Tuplanolla", "author_id": 1729079, "author_profile": "https://Stackoverflow.com/users/1729079", "pm_score": 4, "selected": false, "text": "#include <cheat.h>\n\nCHEAT_TEST(mathematics_still_work,\n cheat_assert(2 + 2 == 4);\n cheat_assert_not(2 + 2 == 5);\n)\n" }, { "answer_id": 27771116, "author": "kirbyfan64sos", "author_id": 2097780, "author_profile": "https://Stackoverflow.com/users/2097780", "pm_score": 0, "selected": false, "text": "#include <libcut.h>\n\nLIBCUT_TEST(test_abc) {\n LIBCUT_TEST_EQ(1, 1);\n LIBCUT_TEST_NE(1, 0);\n LIBCUT_TEST_STREQ(\"abc\", \"abc\");\n LIBCUT_TEST_STRNE(\"abc\", \"def\");\n}\n\nLIBCUT_MAIN(test_abc);\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65820", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7049/" ]
65,849
<p>I'm writing a web service, and I want to return the data as XHTML. Because it's data, not markup, I want to keep it very clean - no extra <code>&lt;div&gt;</code>s or <code>&lt;span&gt;</code>s. However, as a convenience to developers, I'd also like to make the returned data reasonably readable in a browser. To do so, I'm thinking a good way to go about it would be to use CSS. </p> <p>The thing I specifically want to do is to insert linebreaks at certain places. I'm aware of <code>display: block</code>, but it doesn't really work in the situation I'm trying to handle now - a <code>form</code> with <code>&lt;input&gt;</code> fields. Something like this: </p> <pre><code>&lt;form&gt; Thingy 1: &lt;input class="a" type="text" name="one" /&gt; Thingy 2: &lt;input class="a" type="text" name="two" /&gt; Thingy 3: &lt;input class="b" type="checkbox" name="three" /&gt; Thingy 4: &lt;input class="b" type="checkbox" name="four" /&gt; &lt;/form&gt; </code></pre> <p>I'd like it to render so that each label displays on the same line as the corresponding input field. I've tried this: </p> <pre class="lang-css prettyprint-override"><code>input.a:after { content: "\a" } </code></pre> <p>But that didn't seem to do anything. </p>
[ { "answer_id": 65929, "author": "Dergachev", "author_id": 9621, "author_profile": "https://Stackoverflow.com/users/9621", "pm_score": -1, "selected": false, "text": "$(\"input.a\").after(\"<br/>\")\n" }, { "answer_id": 65941, "author": "Thunder3", "author_id": 2832, "author_profile": "https://Stackoverflow.com/users/2832", "pm_score": 0, "selected": false, "text": "<span>" }, { "answer_id": 65946, "author": "Jimmy", "author_id": 4435, "author_profile": "https://Stackoverflow.com/users/4435", "pm_score": 2, "selected": false, "text": "form { white-space: pre }\n" }, { "answer_id": 65950, "author": "BrewinBombers", "author_id": 5989, "author_profile": "https://Stackoverflow.com/users/5989", "pm_score": 7, "selected": true, "text": "<label>\n Thingy one: <input type=\"text\" name=\"one\">;\n</label>\n" }, { "answer_id": 65979, "author": "Jon Galloway", "author_id": 5, "author_profile": "https://Stackoverflow.com/users/5", "pm_score": 4, "selected": false, "text": "<form>\n <ul>\n <li><label>Thingy 1:</label><input class=\"a\" type=\"text\" name=\"one\" /></li>\n <li><label>Thingy 1:</label><input class=\"a\" type=\"text\" name=\"one\" /></li>\n </ul>\n</form>\n" }, { "answer_id": 66000, "author": "Jim", "author_id": 8427, "author_profile": "https://Stackoverflow.com/users/8427", "pm_score": 5, "selected": false, "text": "<label>" }, { "answer_id": 66310, "author": "daniels", "author_id": 9789, "author_profile": "https://Stackoverflow.com/users/9789", "pm_score": 2, "selected": false, "text": "<form>\n <label>Thingy 1: <input class=\"a\" type=\"text\" name=\"one\" /></label>\n <label>Thingy 2: <input class=\"a\" type=\"text\" name=\"two\" /></label>\n <label>Thingy 3: <input class=\"b\" type=\"checkbox\" name=\"three\" /></label>\n <label>Thingy 4: <input class=\"b\" type=\"checkbox\" name=\"four\" /></label>\n</form>\n" }, { "answer_id": 66337, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "<style type=\"text/css\">\n .lb {\n display:block;\n clear:both;\n }\n</style>\n" }, { "answer_id": 66338, "author": "Galen", "author_id": 7894, "author_profile": "https://Stackoverflow.com/users/7894", "pm_score": 2, "selected": false, "text": "<style type=\"text/css\">\nlabel, input { float: left; }\nlabel { clear:left; }\n</style>\n\n<form>\n <label>thing 1:</label><input />\n <label>thing 2:</label><input />\n</form>\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65849", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
65,856
<p>VMware ESX, ESXi, and VirtualCenter are supposed to be able to support HTTP PUT uploads since version 3.5. I know how to do downloads, that's easy. I've never done PUT before.</p> <p>Background information on the topic is here: <a href="http://communities.vmware.com/thread/117504" rel="nofollow noreferrer">http://communities.vmware.com/thread/117504</a></p>
[ { "answer_id": 67048, "author": "Jaykul", "author_id": 8718, "author_profile": "https://Stackoverflow.com/users/8718", "pm_score": 2, "selected": false, "text": "Send-PoshCode" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6637/" ]
65,865
<p>I get this error:</p> <p><code>Can't locate Foo.pm in @INC</code></p> <p>Is there an easier way to install it than downloading, untarring, making, etc?</p>
[ { "answer_id": 65876, "author": "dreeves", "author_id": 4234, "author_profile": "https://Stackoverflow.com/users/4234", "pm_score": 4, "selected": false, "text": "sudo perl -MCPAN -e 'install Foo'" }, { "answer_id": 65883, "author": "Benedikt Waldvogel", "author_id": 4308, "author_profile": "https://Stackoverflow.com/users/4308", "pm_score": 9, "selected": true, "text": "$ cpan" }, { "answer_id": 65960, "author": "JWHEAT", "author_id": 7079, "author_profile": "https://Stackoverflow.com/users/7079", "pm_score": 2, "selected": false, "text": "ppm> install foo\n" }, { "answer_id": 67720, "author": "brian d foy", "author_id": 2766176, "author_profile": "https://Stackoverflow.com/users/2766176", "pm_score": 4, "selected": false, "text": "$prompt> cpan Foo::Bar\n" }, { "answer_id": 73546, "author": "Dave Cross", "author_id": 7231, "author_profile": "https://Stackoverflow.com/users/7231", "pm_score": 3, "selected": false, "text": "CPAN.pm" }, { "answer_id": 75985, "author": "mikegrb", "author_id": 13462, "author_profile": "https://Stackoverflow.com/users/13462", "pm_score": 3, "selected": false, "text": "$ sudo apt-get install dh-make-perl build-essential apt-file\n$ sudo apt-file update\n" }, { "answer_id": 309989, "author": "Bruce Alderman", "author_id": 311, "author_profile": "https://Stackoverflow.com/users/311", "pm_score": 2, "selected": false, "text": "# yum install foo\n" }, { "answer_id": 3590064, "author": "Philip Potter", "author_id": 276952, "author_profile": "https://Stackoverflow.com/users/276952", "pm_score": 6, "selected": false, "text": "# cpanm Chocolate::Belgian\n" }, { "answer_id": 6089068, "author": "Mandar Pande", "author_id": 673018, "author_profile": "https://Stackoverflow.com/users/673018", "pm_score": 2, "selected": false, "text": "cpan -i module_name\n" }, { "answer_id": 6089839, "author": "clt60", "author_id": 632407, "author_profile": "https://Stackoverflow.com/users/632407", "pm_score": 3, "selected": false, "text": "curl -L http://cpanmin.us | perl - --sudo App::cpanminus\n" }, { "answer_id": 13318638, "author": "jaxbihani", "author_id": 1813823, "author_profile": "https://Stackoverflow.com/users/1813823", "pm_score": 3, "selected": false, "text": "perl -MCPAN -e \"CPAN::Shell->force(qw(install Foo::Bar));\"\n" }, { "answer_id": 15024907, "author": "Myforwik", "author_id": 70189, "author_profile": "https://Stackoverflow.com/users/70189", "pm_score": 2, "selected": false, "text": "Foo::Bar" }, { "answer_id": 18748245, "author": "venkrao", "author_id": 1508423, "author_profile": "https://Stackoverflow.com/users/1508423", "pm_score": 2, "selected": false, "text": " #wget <URL to the module.tgz>\n ##unpack\n perl Build.PL\n./Build destdir=$HOME install_base=$HOME\n./Build destdir=$HOME install_base=$HOME install\n" }, { "answer_id": 23646437, "author": "Chankey Pathak", "author_id": 257635, "author_profile": "https://Stackoverflow.com/users/257635", "pm_score": 3, "selected": false, "text": "cpan Modulename" }, { "answer_id": 23754365, "author": "Chris Forever", "author_id": 3655058, "author_profile": "https://Stackoverflow.com/users/3655058", "pm_score": 2, "selected": false, "text": "yum search foo" }, { "answer_id": 26650808, "author": "Michal Ingeli", "author_id": 830716, "author_profile": "https://Stackoverflow.com/users/830716", "pm_score": 2, "selected": false, "text": "Fedora Linux" }, { "answer_id": 32884636, "author": "Kamal Nayan", "author_id": 4414367, "author_profile": "https://Stackoverflow.com/users/4414367", "pm_score": 1, "selected": false, "text": "cpan Foo::Bar" }, { "answer_id": 40426333, "author": "Ed Dunn", "author_id": 4204127, "author_profile": "https://Stackoverflow.com/users/4204127", "pm_score": 1, "selected": false, "text": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n#I've gotten into the habit of setting this on all my scripts, prevents weird path issues if the script is not being run by root\n$ENV{'PATH'} = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin';\n\n#Fill this with the perl modules required for your project\nmy @perl = qw(LWP::Simple XML::LibXML MIME::Lite DBI DateTime Config::Tiny Proc::ProcessTable);\n\nchomp(my $curl = `which curl`);\n\nif(!$curl){ system('apt-get install curl -y > /dev/null'); }\n\nchomp(my $cpanm = system('/bin/bash', '-c', 'which cpanm &>/dev/null'));\n\n#installs cpanm if missing\nif($cpanm){ system('curl -s -L http://cpanmin.us | perl - --sudo App::cpanminus'); }\n\n#loops through required modules and installs them if missing\nforeach my $x (@perl){\n eval \"use $x\";\n if($@){\n system(\"cpanm $x\");\n eval \"use $x\";\n }\n}\n" }, { "answer_id": 41360933, "author": "Mister X", "author_id": 2422264, "author_profile": "https://Stackoverflow.com/users/2422264", "pm_score": 2, "selected": false, "text": "PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install DateTime::TimeZone'\n" }, { "answer_id": 58559309, "author": "vinc17", "author_id": 3782797, "author_profile": "https://Stackoverflow.com/users/3782797", "pm_score": 2, "selected": false, "text": "cpan" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65865", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4234/" ]
65,925
<p>From time to time am I working in a completely disconnected environment with a Macbook Pro. For testing purposes I need to run a local DNS server in a VMWare session. I've configured the lookup system to use the DNS server (/etc/resolve.conf and through the network configuration panel, which is using configd underneath), and commands like "dig" and "nslookup" work. For example, my DNS server is configured to resolve www.example.com to 127.0.0.1, this is the output of "dig www.example.com":</p> <pre><code>; &lt;&lt;&gt;&gt; DiG 9.3.5-P1 &lt;&lt;&gt;&gt; www.example.com ;; global options: printcmd ;; Got answer: ;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 64859 ;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;www.example.com. IN A ;; ANSWER SECTION: www.example.com. 86400 IN A 127.0.0.1 ;; Query time: 2 msec ;; SERVER: 172.16.35.131#53(172.16.35.131) ;; WHEN: Mon Sep 15 21:13:15 2008 ;; MSG SIZE rcvd: 49 </code></pre> <p>Unfortunately, if I try to ping or setup a connection in a browser, the DNS name is not resolved. This is the output of "ping www.example.com":</p> <pre><code>ping: cannot resolve www.example.com: Unknown host </code></pre> <p>It seems that those tools, that are more integrated within Mac OS X 10.4 (and up), are not using the "/etc/resolv.conf" system anymore. Configuring them through scutil is no help, because it seems that if the wireless or the buildin ethernet interface is <strong>inactive</strong>, basic network functions don't seem to work.</p> <p>In Linux (for example Ubuntu), it is possible to turn off the wireless adapter, without turning of the network capabilities. So in Linux it seems that I can work completely disconnected.</p> <p>A solution could be using an ethernet loopback connector, but I would rather like a software solution, as both Windows and Linux don't have this problem.</p>
[ { "answer_id": 66756, "author": "Nicholas Riley", "author_id": 6372, "author_profile": "https://Stackoverflow.com/users/6372", "pm_score": 1, "selected": false, "text": "/etc/resolv.conf" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9504/" ]
65,926
<p>When using a browser to transform XML (Google Chrome or IE7) is it possible to pass a parameter to the XSLT stylesheet through the URL?</p> <p>example:</p> <p><strong>data.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;?xml-stylesheet type="text/xsl" href="sample.xsl"?&gt; &lt;root&gt; &lt;document type="resume"&gt; &lt;author&gt;John Doe&lt;/author&gt; &lt;/document&gt; &lt;document type="novella"&gt; &lt;author&gt;Jane Doe&lt;/author&gt; &lt;/document&gt; &lt;/root&gt; </code></pre> <p><strong>sample.xsl</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt; &lt;xsl:output method="html" /&gt; &lt;xsl:template match="/"&gt; &lt;xsl:param name="doctype" /&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;List of &lt;xsl:value-of select="$doctype" /&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;xsl:for-each select="//document[@type = $doctype]"&gt; &lt;p&gt;&lt;xsl:value-of select="author" /&gt;&lt;/p&gt; &lt;/xsl:for-each&gt; &lt;/body&gt; &lt;/html&gt; &lt;/&lt;xsl:stylesheet&gt; </code></pre>
[ { "answer_id": 66017, "author": "Peter Boughton", "author_id": 9360, "author_profile": "https://Stackoverflow.com/users/9360", "pm_score": 3, "selected": true, "text": "<?xml-stylesheet type=\"text/xsl\"href=\"/myscript.cfm/sample.xsl?paramter=something\" ?>\n" }, { "answer_id": 635032, "author": "Tawani", "author_id": 61525, "author_profile": "https://Stackoverflow.com/users/61525", "pm_score": 3, "selected": false, "text": "xmlDoc.documentElement.setAttribute(\"myparam\",getParameter(\"myparam\"))\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9547/" ]
65,940
<p>This should be simple. I'm trying to import data from Access into SQL Server. I don't have direct access to the SQL Server database - it's on GoDaddy and they only allow web access. So I can't use the Management Studio tools, or other third-party Access upsizing programs that require remote access to the database.</p> <p>I wrote a query on the Access database and I'm trying to loop through and insert each record into the corresponding SQL Server table. But it keeps erroring out. I'm fairly certain it's because of the HTML and God knows what other weird characters are in one of the Access text fields. I tried using CFQUERYPARAM but that doesn't seem to help either.</p> <p>Any ideas would be helpful. Thanks.</p>
[ { "answer_id": 66324, "author": "David-W-Fenton", "author_id": 9787, "author_profile": "https://Stackoverflow.com/users/9787", "pm_score": -1, "selected": false, "text": "INSERT INTO tblSQLServer (ID, OtherField ) \nSELECT ID, OtherField\nFROM [c:\\MyDBs\\Access.mdb].tblSQLServer \n" }, { "answer_id": 88441, "author": "Andy Waschick", "author_id": 6000, "author_profile": "https://Stackoverflow.com/users/6000", "pm_score": 0, "selected": false, "text": "<cfexecute>" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65940", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
65,969
<p>In C# documentation tags allow you to produce output similar to MSDN. What are a list of allowable tags for use inside the /// (triple slash) comment area above classes, methods, and properties?</p>
[ { "answer_id": 66022, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 4, "selected": false, "text": "/// <\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65969", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9587/" ]
65,970
<p>I was asked this question in a job interview. The interviewer and I disagreed on what the correct answer was. I'm wondering if anyone has any data on this.</p> <p>Update: I should have mentioned that the use of shuffle() was strictly forbidden... sorry.</p>
[ { "answer_id": 65978, "author": "Loren Segal", "author_id": 6436, "author_profile": "https://Stackoverflow.com/users/6436", "pm_score": 2, "selected": false, "text": "shuffle($arr);\n" }, { "answer_id": 66688, "author": "Scott Swezey", "author_id": 9439, "author_profile": "https://Stackoverflow.com/users/9439", "pm_score": 0, "selected": false, "text": "array_rand()" }, { "answer_id": 66754, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "\nfor (i is 1 to n)\n Swap i with random position between 1 and n \n" }, { "answer_id": 66805, "author": "fixedd", "author_id": 9557, "author_profile": "https://Stackoverflow.com/users/9557", "pm_score": 2, "selected": false, "text": "function randomize_array_1($array_to_randomize) {\n $new_array = array();\n while (count($array_to_randomize) > 0) {\n $rand_num = rand(0, count($array_to_randomize)-1);\n $extracted = array_splice($array_to_randomize, $rand_num, 1);\n $new_array[] = $extracted[0];\n }\n return $new_array;\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65970", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9557/" ]
65,994
<p>I want to use a file to store the current version number for a piece of customer software which can be used by a start-up script to run the binary in the correct directory.</p> <p>For Example, if the run directory looks like this:</p> <pre><code>. .. 1.2.1 1.2.2 1.3.0 run.sh current_version </code></pre> <p>And current_version contains:</p> <pre><code>1.2.2 </code></pre> <p>I want <code>run.sh</code> to descend into 1.2.2 and run the program <code>foo</code>.</p> <p>The current solution is this:</p> <pre><code>#!/bin/sh version = `cat current_version` cd $version ./foo </code></pre> <p>It works but is not very robust. It does not check for file existence, cannot cope with multiple lines, leading spaces, commented lines, blank files, etc.</p> <p>What is the most survivable way to do this with either a shell or perl script?</p>
[ { "answer_id": 66087, "author": "slipset", "author_id": 9422, "author_profile": "https://Stackoverflow.com/users/9422", "pm_score": -1, "selected": false, "text": "!#/bin/sh\n\nif [ -e 'current_version' ]; then\n version=`cat current_version`;\n version=`echo $version | tr -ds [[:blank:]]`\n if [ -n \"$version\" ]; then\n if [ -d \"$version\" ]; then\n cd \"$version\"\n else\n echo $version is not a directory\n fi\n else\n echo version_file contained only blanks\n fi\nelse \n No file named current_version exists\nfi\n" }, { "answer_id": 66124, "author": "Peter Boughton", "author_id": 9360, "author_profile": "https://Stackoverflow.com/users/9360", "pm_score": 0, "selected": false, "text": "ls | grep ^[0-9]\\.[0-9]\\.[0-9]$ | sort -nr | head -n 1\n" }, { "answer_id": 72602, "author": "Peter Stuifzand", "author_id": 1633, "author_profile": "https://Stackoverflow.com/users/1633", "pm_score": 0, "selected": false, "text": "#!/usr/bin/perl -w\nuse strict;\nuse warnings;\n\nmy $version_file = 'current_version';\nopen my $fh, '<', $version_file or die \"Can't open $version_file: $!\";\n\n# Read version from file\nmy $version = <$fh>;\nchomp $version;\n\n# Remove whitespace (and match version)\ndie \"Version format not recognized\" if $version !~ m/(\\d+\\.\\d+\\.\\d+)/;\n\nmy $dir = $1;\ndie \"Directory not found: $dir\" unless -d $dir;\n\n# Execute program in versioned directory.\nchdir $dir;\nsystem(\"./foo\");\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/65994", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7476/" ]
66,006
<p>Is it possible to have XML-embedded JavaScript executed to assist in client-side (browser-based) XSL transformations? How is it done and how official is it?</p> <p>Microsoft's XML DOM objects allow this on the server-side (i.e. in ASP/ASP.NET).</p> <p><strong>Clarification:</strong> I do not mean HTML DOM scripting performed <em>after</em> the document is transformed, nor do I mean XSL transformations <em>initiated</em> by JavaScript in the browser (e.g. what the W3Schools page shows). I am referring to actual script blocks located within the XSL during the transformation.</p>
[ { "answer_id": 74836, "author": "Neil C. Obremski", "author_id": 9642, "author_profile": "https://Stackoverflow.com/users/9642", "pm_score": 3, "selected": true, "text": "<?xml version=\"1.0\"?>\n<?xml-stylesheet type=\"text/xsl\" href=\"scripted.xsl\"?>\n<data a=\"v\">\n ding dong\n</data>\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/66006", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9642/" ]
66,009
<p>I know you could make a helper pretty easily given the data. So, if possible, please only submit answers that also include getting the data.</p>
[ { "answer_id": 67644, "author": "Matt Hinze", "author_id": 2676, "author_profile": "https://Stackoverflow.com/users/2676", "pm_score": 5, "selected": true, "text": " public override void OnActionExecuting(ActionExecutingContext filterContext)\n {\n var controller = (Controller) filterContext.Controller;\n Breadcrumb[] breadcrumbs = _breadcrumbManager.PushBreadcrumb(_breadcrumbLinkText);\n controller.ViewData.Add(breadcrumbs);\n }\n" }, { "answer_id": 110283, "author": "Matt Hinze", "author_id": 2676, "author_profile": "https://Stackoverflow.com/users/2676", "pm_score": 2, "selected": false, "text": " <% \n foreach (var item in ViewData.Get<Breadcrumb[]>())\n {\n %>\n <a href=\"<%= Server.HtmlEncode(item.Url) %>\"><%= item.LinkText %></a> &raquo;\n <% \n } \n %>\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/66009", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1946/" ]
66,016
<p>Most program languages have some kind of exception handling; some languages have return codes, others have try/catch, or rescue/retry, etc., each with its own pecularities in readability, robustness, and practical effectiveness in a large group development effort. Which one is the best and why ?</p>
[ { "answer_id": 66145, "author": "squadette", "author_id": 7754, "author_profile": "https://Stackoverflow.com/users/7754", "pm_score": 0, "selected": false, "text": "Control.Exception" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/66016", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9613/" ]
66,032
<p>The DOM method <code>getChildNodes()</code> returns a <code>NodeList</code> of the children of the current <code>Node</code>. Whilst a <code>NodeList</code> is ordered, is the list guaranteed to be in document order?</p> <p>For example, given <code>&lt;a&gt;&lt;b/&gt;&lt;c/&gt;&lt;d/&gt;&lt;/a&gt;</code> is <code>a.getChildNodes()</code> guaranteed to return a <code>NodeList</code> with <code>b</code>, <code>c</code> and <code>d</code> <em>in that order</em>?</p> <p>The <a href="http://java.sun.com/javase/6/docs/api/org/w3c/dom/Node.html#getChildNodes()" rel="noreferrer">javadoc</a> isn't clear on this.</p>
[ { "answer_id": 66116, "author": "sblundy", "author_id": 4893, "author_profile": "https://Stackoverflow.com/users/4893", "pm_score": 4, "selected": true, "text": "current = node.firstChild;\nwhile(null != current) {\n ...\n current = current.nextSibling;\n}\n" }, { "answer_id": 66160, "author": "BrewinBombers", "author_id": 5989, "author_profile": "https://Stackoverflow.com/users/5989", "pm_score": 0, "selected": false, "text": "\n<a><b/><c/><d/></a>\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/66032", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4332/" ]
66,066
<p>I've seen examples like this: </p> <pre><code>public class MaxSeconds { public static final int MAX_SECONDS = 25; } </code></pre> <p>and supposed that I could have a Constants class to wrap constants in, declaring them static final. I know practically no Java at all and am wondering if this is the best way to create constants. </p>
[ { "answer_id": 66076, "author": "jjnguy", "author_id": 2598, "author_profile": "https://Stackoverflow.com/users/2598", "pm_score": 10, "selected": true, "text": "(public/private) static final TYPE NAME = VALUE;\n" }, { "answer_id": 66142, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "public interface MyConstants {\n String CONSTANT_ONE = \"foo\";\n}\n\npublic class NeddsConstant implements MyConstants {\n\n}\n" }, { "answer_id": 66143, "author": "Andrew Harmel-Law", "author_id": 2455, "author_profile": "https://Stackoverflow.com/users/2455", "pm_score": 0, "selected": false, "text": "public interface MyGlobalConstants {\n public static final int TIMEOUT_IN_SECS = 25;\n}\n" }, { "answer_id": 66307, "author": "Marcio Aguiar", "author_id": 4213, "author_profile": "https://Stackoverflow.com/users/4213", "pm_score": 7, "selected": false, "text": "// Constant utility class\npackage com.effectivejava.science;\npublic class PhysicalConstants {\n private PhysicalConstants() { } // Prevents instantiation\n\n public static final double AVOGADROS_NUMBER = 6.02214199e23;\n public static final double BOLTZMANN_CONSTANT = 1.3806503e-23;\n public static final double ELECTRON_MASS = 9.10938188e-31;\n}\n" }, { "answer_id": 66343, "author": "Rob Dickerson", "author_id": 7530, "author_profile": "https://Stackoverflow.com/users/7530", "pm_score": 3, "selected": false, "text": "public|private static final TYPE NAME = VALUE;" }, { "answer_id": 66768, "author": "mmansoor", "author_id": 9984, "author_profile": "https://Stackoverflow.com/users/9984", "pm_score": 0, "selected": false, "text": "public enum myEnum {\n Option1(\"String1\", 2), \n Option2(\"String2\", 2) \n ;\n String str;\n int i;\n\n myEnum(String str1, int i1) { this.str = str1 ; this.i1 = i }\n\n\n}\n" }, { "answer_id": 67057, "author": "Ryan Delucchi", "author_id": 9931, "author_profile": "https://Stackoverflow.com/users/9931", "pm_score": 1, "selected": false, "text": "final" }, { "answer_id": 68558, "author": "big_peanut_horse", "author_id": 10720, "author_profile": "https://Stackoverflow.com/users/10720", "pm_score": 3, "selected": false, "text": "public int getMaxConnections() {return 10;}" }, { "answer_id": 4403167, "author": "chandrayya", "author_id": 537066, "author_profile": "https://Stackoverflow.com/users/537066", "pm_score": 1, "selected": false, "text": "public interface MyGlobalConstants {\n public static final int TIMEOUT_IN_SECS = 25;\n}\n" }, { "answer_id": 6486803, "author": "Lorand Bendig", "author_id": 1050422, "author_profile": "https://Stackoverflow.com/users/1050422", "pm_score": 2, "selected": false, "text": "public class Constants {\n\n private Constants() {\n throw new AssertionError();\n }\n\n public interface ConstantType {}\n\n public enum StringConstant implements ConstantType {\n DB_HOST(\"localhost\");\n // other String constants come here\n\n private String value;\n private StringConstant(String value) {\n this.value = value;\n }\n public String value() {\n return value;\n }\n }\n\n public enum IntConstant implements ConstantType {\n DB_PORT(3128), \n MAX_PAGE_SIZE(100);\n // other int constants come here\n\n private int value;\n private IntConstant(int value) {\n this.value = value;\n }\n public int value() {\n return value;\n }\n }\n\n public enum SimpleConstant implements ConstantType {\n STATE_INIT,\n STATE_START,\n STATE_END;\n }\n\n}\n" }, { "answer_id": 8809578, "author": "albus.ua", "author_id": 697116, "author_profile": "https://Stackoverflow.com/users/697116", "pm_score": 4, "selected": false, "text": "public final class Constants {\n public final class File {\n public static final int MIN_ROWS = 1;\n public static final int MAX_ROWS = 1000;\n\n private File() {}\n }\n\n public final class DB {\n public static final String name = \"oups\";\n\n public final class Connection {\n public static final String URL = \"jdbc:tra-ta-ta\";\n public static final String USER = \"testUser\";\n public static final String PASSWORD = \"testPassword\";\n\n private Connection() {}\n }\n\n private DB() {}\n }\n\n private Constants() {}\n}\n" }, { "answer_id": 12207932, "author": "wulfgarpro", "author_id": 512994, "author_profile": "https://Stackoverflow.com/users/512994", "pm_score": 0, "selected": false, "text": "static final" }, { "answer_id": 16565371, "author": "bincob", "author_id": 1619065, "author_profile": "https://Stackoverflow.com/users/1619065", "pm_score": 0, "selected": false, "text": "static final" }, { "answer_id": 38639581, "author": "Quinn Turner", "author_id": 4400318, "author_profile": "https://Stackoverflow.com/users/4400318", "pm_score": 0, "selected": false, "text": "@Retention(SOURCE)\n@IntDef({NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST,NAVIGATION_MODE_TABS})\npublic @interface NavigationMode {}\npublic static final int NAVIGATION_MODE_STANDARD = 0;\npublic static final int NAVIGATION_MODE_LIST = 1;\npublic static final int NAVIGATION_MODE_TABS = 2;\n...\npublic abstract void setNavigationMode(@NavigationMode int mode);\n@NavigationMode\npublic abstract int getNavigationMode();\n" }, { "answer_id": 41526147, "author": "djangofan", "author_id": 118228, "author_profile": "https://Stackoverflow.com/users/118228", "pm_score": 2, "selected": false, "text": "public, so that they are accessible from everywhere\nstatic, so that they can be accessed without any instance. Since they are constants it\n makes little sense to duplicate them for every object.\nfinal, since they should not be allowed to change\n" }, { "answer_id": 44452756, "author": "davidxxx", "author_id": 270371, "author_profile": "https://Stackoverflow.com/users/270371", "pm_score": 2, "selected": false, "text": "static final String/Integer" }, { "answer_id": 48186688, "author": "Blessed Geek", "author_id": 140803, "author_profile": "https://Stackoverflow.com/users/140803", "pm_score": 0, "selected": false, "text": "public interface CustomerService {\n public interface Label{\n char AssignmentCharacter = ':';\n public interface Address{\n String Street = \"Street\";\n String Unit= \"Unit/Suite\";\n String Municipal = \"City\";\n String County = \"County\";\n String Provincial = \"State\";\n String PostalCode = \"Zip\"\n }\n\n public interface Person {\n public interface NameParts{\n String Given = \"First/Given name\"\n String Auxiliary = \"Middle initial\"\n String Family = \"Last name\"\n }\n }\n }\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/66066", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1797/" ]
66,094
<p>Have been trying out the new Dynamic Data site create tool that shipped with .NET 3.5. The tool uses LINQ Datasources to get the data from the database using a .dmbl context file for a reference. I am interseted in customizing a data grid but I need to show data from more than one table. Does anyone know how to do this using the LINQ Datasource object?</p>
[ { "answer_id": 84141, "author": "naspinski", "author_id": 14777, "author_profile": "https://Stackoverflow.com/users/14777", "pm_score": 3, "selected": true, "text": "<%# Bind(\"unit1.unit_name\") %>\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/66094", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9626/" ]
66,107
<p>I need to get the number of digits containing the number 1. I know in java I can take the input as a <code>String</code> and use <code>charAt</code>, but I understand there is no implicit String function in C. How can I accomplish this?</p>
[ { "answer_id": 66122, "author": "Aaron Maenpaa", "author_id": 2603, "author_profile": "https://Stackoverflow.com/users/2603", "pm_score": 3, "selected": false, "text": "#include \"stdio.h\"\n\nint main(){\n int digits[] = {0,0,0,0,0,0,0,0,0,0};\n int i = 11031;\n\n while(i > 0){\n digits[i % 10]++;\n i = i / 10;\n }\n\n printf(\"There are %d ones.\\n\", digits[1]);\n}\n" }, { "answer_id": 66138, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 1, "selected": false, "text": "char*" }, { "answer_id": 66151, "author": "Patrick", "author_id": 429, "author_profile": "https://Stackoverflow.com/users/429", "pm_score": 1, "selected": false, "text": " int val; //Input\n ...\n int ones = 0;\n while(val != 0) {\n ones += ((val % 10) == 1) ? 1 : 0;\n val /= 10;\n }\n" }, { "answer_id": 66154, "author": "kfh", "author_id": 6597, "author_profile": "https://Stackoverflow.com/users/6597", "pm_score": 0, "selected": false, "text": "int val=11031;\nint count=0;\nint i=0;\nchar buf[100];\nsprint(buf, \"%d\", val);\nfor(i=0; (i < sizeof(buf)) && (buf[i]); i++) {\n if(buf[i] == '1')\n count++;\n}\n" }, { "answer_id": 66171, "author": "Jarrett Meyer", "author_id": 5834, "author_profile": "https://Stackoverflow.com/users/5834", "pm_score": 1, "selected": false, "text": "int digit = 0;\nint value = 11031;\n\nwhile(value > 0)\n{\n digit = value % 10;\n /* Do something with digit... */\n value = value / 10;\n}\n" }, { "answer_id": 66176, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "int count_digit(int nr, int digit) {\n int count=0;\n while(nr>0) {\n if(nr%10==digit)\n count++;\n nr=nr/10;\n }\n return count;\n}\n" }, { "answer_id": 66214, "author": "Robᵩ", "author_id": 8747, "author_profile": "https://Stackoverflow.com/users/8747", "pm_score": 0, "selected": false, "text": "int countOnes(int input)\n{\n int result = 0;\n while(input) {\n result += ((input%10)==1);\n result /= 10;\n }\n return result;\n}\n" }, { "answer_id": 66256, "author": "Robert Deml", "author_id": 9516, "author_profile": "https://Stackoverflow.com/users/9516", "pm_score": 0, "selected": false, "text": "int countDigit(int Number, int Digit)\n{\n int counter = 0;\n\n do\n {\n if( (Number%10) == Digit)\n {\n counter++;\n }\n }while(Digit>0)\n\n return counter;\n}\n" }, { "answer_id": 66347, "author": "Mr Shark", "author_id": 6093, "author_profile": "https://Stackoverflow.com/users/6093", "pm_score": 0, "selected": false, "text": "#include <stdio.h>\n\nmain() {\n char buf[100];\n char *p = buf;\n int n = 0;\n scanf(\"%s\", buf);\n while (*p) {\n if (*p == '1') {\n n++;\n }\n p++;\n }\n printf (\"'%s' contains %i ones\\n\", buf, n);\n}\n" }, { "answer_id": 67196, "author": "hoyhoy", "author_id": 3499, "author_profile": "https://Stackoverflow.com/users/3499", "pm_score": 0, "selected": false, "text": "int count_digits(int n, int d) {\n int count = 0;\n while(n*10/=10) if (n%10==d) count++\n return count;\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/66107", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9628/" ]
66,117
<p>When I am working with ASP.NET, I find that there are always unexpected things I run into that take forever to debug. I figure that having a consolidated list of these would be great for those "weird error" circumstances, plus to expand our knowledge of oddness in the platform.</p> <p>So: answer with one of your "Gotcha"s!</p> <p>I'll start: Under ASP.NET (VB), performing a Response.Redirect inside a try/catch block does not stop execution of the current Response, which can lead to two concurrent Responses executing against the same Session.</p>
[ { "answer_id": 66401, "author": "Thunder3", "author_id": 2832, "author_profile": "https://Stackoverflow.com/users/2832", "pm_score": -1, "selected": false, "text": "UpdateName(ByRef aName as String)" }, { "answer_id": 179298, "author": "Adam Lassek", "author_id": 1249, "author_profile": "https://Stackoverflow.com/users/1249", "pm_score": 2, "selected": false, "text": "<%# FormatNameHelper(Bind(\"Name\")) %>\n" }, { "answer_id": 1404000, "author": "Shaul Behr", "author_id": 7850, "author_profile": "https://Stackoverflow.com/users/7850", "pm_score": 1, "selected": false, "text": "SubmitChanges()" }, { "answer_id": 1820967, "author": "vdboor", "author_id": 146289, "author_profile": "https://Stackoverflow.com/users/146289", "pm_score": 2, "selected": false, "text": "INamingContainer" }, { "answer_id": 5110350, "author": "rlb.usa", "author_id": 449902, "author_profile": "https://Stackoverflow.com/users/449902", "pm_score": 2, "selected": false, "text": "<" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/66117", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2832/" ]
66,164
<p>I'm responsible for some test database servers. Historically, too many other poeple have access to them. They run on <code>SQL Server 2005</code>. </p> <p>I've been writing queries and wrapping them in scripts so I can run a regular audit of rights. Finding out which users had Administrator rights on the server itself was fine, as was finding out who had the <code>sysadmin</code> role on their login - it was a single line query for the latter.</p> <p>But how to find out which logins have a User Mapping to a particular (or any) database? </p> <p>I can find the <code>sys.database_principals</code> and <code>sys.server_principals</code> tables. I have located the <code>sys.databases table</code>. I haven't worked out how to find out which users have rights on a database, and if so, what. </p> <p>Every Google search brings up people manually using the User Mapping pane of the Login dialog, rather than using a query to do so. Any ideas?</p>
[ { "answer_id": 66349, "author": "Jason Punyon", "author_id": 6212, "author_profile": "https://Stackoverflow.com/users/6212", "pm_score": 1, "selected": false, "text": "\nselect * from Master.dbo.syslogins l inner join sys.sysusers u on l.sid = u.sid\n" }, { "answer_id": 66511, "author": "Amy B", "author_id": 8155, "author_profile": "https://Stackoverflow.com/users/8155", "pm_score": 2, "selected": false, "text": "SELECT *\nFROM\n sys.database_principals AS u\n LEFT OUTER JOIN sys.database_permissions AS dp\n ON dp.grantee_principal_id = u.principal_id and dp.type = N'CO'\nWHERE (u.type in ('U', 'S', 'G', 'C', 'K'))\nORDER BY [Name] ASC\n" }, { "answer_id": 73846, "author": "Julian Simpson", "author_id": 9727, "author_profile": "https://Stackoverflow.com/users/9727", "pm_score": 2, "selected": true, "text": "select DbRole = g.name, MemberName = u.name\n from @NAME.sys.database_principals u, @NAME.sys.database_principals g, @NAME.sys.database_role_members m\n where g.principal_id = m.role_principal_id\n and u.principal_id = m.member_principal_id\n and g.name in (''db_ddladmin'', ''db_owner'', ''db_securityadmin'') \n and u.name not in (''dbo'')\n order by 1, 2\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/66164", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9727/" ]
66,293
<p>I have a Visual Studio application with a splash screen image cut into "slices". The positions are specified in the Form Designer so they line up properly on the screen. However, the images are out of place when the application is run on the Chinese version of Windows XP. It looks as if the image slices were "exploded" apart.</p> <p>What's going on here? Do international versions of Windows have a different meaning of the "top left" coordinate of the picture? How can I force the images to be precisely displayed where I want them?</p>
[ { "answer_id": 67007, "author": "Benjamin Autin", "author_id": 1440933, "author_profile": "https://Stackoverflow.com/users/1440933", "pm_score": 0, "selected": false, "text": "images[0].Location = new Point(0,0);\nfor (int i = 1; i < images.Length; i++)\n{\n images[i].Location = new Point(images[i - 1].Location.X + images[i - 1].Width, 0);\n}\n" }, { "answer_id": 74788, "author": "Todd Myhre", "author_id": 5626, "author_profile": "https://Stackoverflow.com/users/5626", "pm_score": 2, "selected": false, "text": "Me.PictureBoxIcon.Width = Me.PictureBoxIcon.Image.Width\nMe.PictureBoxIcon.Height = Me.PictureBoxIcon.Image.Height\n\nDim loc As New Point\nloc.X = Me.PictureBoxIcon.Location.X\nloc.Y = Me.PictureBoxIcon.Location.Y + Me.PictureBoxIcon.Height\nMe.PictureBoxAbout.Location = loc\nMe.PictureBoxAbout.Width = Me.PictureBoxAbout.Image.Width\nMe.PictureBoxAbout.Height = Me.PictureBoxAbout.Image.Height\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/66293", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5626/" ]
66,330
<p>Is there a Perl module that allows me to view diffs between actual and reference output of programs (or functions)? The test fails if there are differences.</p> <p>Also, in case there are differences but the output is OK (because the functionality has changed) I want to be able to commit the actual output as future reference output.</p>
[ { "answer_id": 68725, "author": "Yanick", "author_id": 10356, "author_profile": "https://Stackoverflow.com/users/10356", "pm_score": 2, "selected": false, "text": "use Test::Command tests => 3;\n\nmy $echo_test = Test::Command->new( cmd => 'echo out' );\n\n$echo_test->exit_is_num(0, 'exit normally');\n$echo_test->stdout_is_eq(\"out\\n\", 'echoes out');\n$echo_test->stderr_unlike( qr/something went (wrong|bad)/, 'nothing went bad' )\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/66330", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9792/" ]