qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
70,779
<p>I need to be able to quickly convert an image (inside a rails controller) so that the hosting company using managing our application can quickly test at any time to ensure that rmagick is not only successfully installed, but can be called throgh the rails stiack, what is the quickest clean code I can use to do this?</p>
[ { "answer_id": 70952, "author": "Asaf Bartov", "author_id": 7483, "author_profile": "https://Stackoverflow.com/users/7483", "pm_score": 0, "selected": false, "text": "require 'RMagick'\ninclude Magick\nimg = ImageList.new('myfile.jpg')\nimg.crop(0,0,10,10) # or whatever\nimg.write('mycroppedfile.jpg')\n" }, { "answer_id": 71527, "author": "Laurie Young", "author_id": 7473, "author_profile": "https://Stackoverflow.com/users/7473", "pm_score": 3, "selected": true, "text": "class DiagnosticsController < ApplicationController\n require 'RMagick'\n\n def rmagick\n images_path = \"public/images\"\n file_name = \"rmagick_generated_thumb.jpg\"\n file_path = images_path + \"/\"+ file_name\n\n File.delete file_path if File.exists? file_path\n img = Magick::Image.read(\"lib/sample_images/magic.jpg\").first\n thumb = img.scale(0.25)\n @path = file_name\n thumb.write file_path\n end\nend #------\n <%= image_tag @path %>\n" }, { "answer_id": 72582, "author": "Scott", "author_id": 7399, "author_profile": "https://Stackoverflow.com/users/7399", "pm_score": 4, "selected": false, "text": "require 'RMagick'\n\nimage = Magick::Image.new(110, 30){ self.background_color = 'white' }\nimage.write('/tmp/test.jpg')\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/70779", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7473/" ]
70,782
<p>How to get a file's creation date or file size, for example this Hello.jpg at <a href="http://www.mywebsite.com/now/Hello.jpg(note" rel="nofollow noreferrer">http://www.mywebsite.com/now/Hello.jpg(note</a>: This URL does not exist)? The purpose of this question is to make my application re-download the files from the any website when it has detected that the website has an updated version of the files and the files in my local folder are out of date. Any ideas?</p>
[ { "answer_id": 70803, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 4, "selected": true, "text": "$ telnet www.google.com 80\nTrying 216.239.59.103...\nConnected to www.l.google.com.\nEscape character is '^]'.\nHEAD /intl/en_ALL/images/logo.gif HTTP/1.0\n\nHTTP/1.0 200 OK\nContent-Type: image/gif\nLast-Modified: Wed, 07 Jun 2006 19:38:24 GMT\nExpires: Sun, 17 Jan 2038 19:14:07 GMT\nCache-Control: public\nDate: Tue, 16 Sep 2008 09:45:42 GMT\nServer: gws\nContent-Length: 8558\nConnection: Close\n\nConnection closed by foreign host.\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/70782", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
70,785
<p>We want to try Ext JS on new project. Is there any well-known best practice for integrating Ext JS with server side Java (Spring/Hibernate/JS) application? Is DWR a good choice for that?</p>
[ { "answer_id": 75007, "author": "noah", "author_id": 12034, "author_profile": "https://Stackoverflow.com/users/12034", "pm_score": 1, "selected": false, "text": "var MyProxy = function(fn) {\n this.fn = fn;\n};\nExt.extend( MyProxy, Ext.data.DataProxy, {\n load: function(params,reader,callback,scope,arg) {\n this.fn(params,function(data) {\n callback.call(scope,reader.readRecords(data),arg,true);\n });\n },\n update: function() {}\n});\n var store = new Ext.data.Store({\n reader: myReader, proxy: new MyProxy(function(params,callback) {\n // params are used for paging and searching, if you need it\n callback(SomeService.getData(params));\n })\n // ...\n});\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/70785", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7292/" ]
70,797
<p>How do I have a Python script that a) can accept user input and how do I make it b) read in arguments if run from the command line?</p>
[ { "answer_id": 70814, "author": "lbz", "author_id": 11530, "author_profile": "https://Stackoverflow.com/users/11530", "pm_score": 9, "selected": false, "text": "var = raw_input(\"Please enter something: \")\nprint \"you entered\", var\n var = input(\"Please enter something: \")\nprint(\"You entered: \" + var)\n" }, { "answer_id": 70818, "author": "David Webb", "author_id": 3171, "author_profile": "https://Stackoverflow.com/users/3171", "pm_score": 5, "selected": false, "text": "argparse raw_input() readline module" }, { "answer_id": 70833, "author": "Antti Rasinen", "author_id": 8570, "author_profile": "https://Stackoverflow.com/users/8570", "pm_score": 10, "selected": true, "text": "cmd raw_input input text = raw_input(\"prompt\") # Python 2\ntext = input(\"prompt\") # Python 3\n sys.argv import sys\nprint (sys.argv)\n optparse argparse getopt fileinput" }, { "answer_id": 70841, "author": "Simon Peverett", "author_id": 6063, "author_profile": "https://Stackoverflow.com/users/6063", "pm_score": 4, "selected": false, "text": "$ python my_prog.py file_name.txt\n import sys\nprint sys.argv\n" }, { "answer_id": 70869, "author": "Vhaerun", "author_id": 11234, "author_profile": "https://Stackoverflow.com/users/11234", "pm_score": 4, "selected": false, "text": "input raw_input input eval" }, { "answer_id": 8334188, "author": "steampowered", "author_id": 404699, "author_profile": "https://Stackoverflow.com/users/404699", "pm_score": 8, "selected": false, "text": "raw_input raw_input input input_var = input(\"Enter something: \")\nprint (\"you entered \" + input_var) \n" }, { "answer_id": 13089887, "author": "Matt Olan", "author_id": 1776131, "author_profile": "https://Stackoverflow.com/users/1776131", "pm_score": 3, "selected": false, "text": "import argparse\n\nparser = argparse.ArgumentParser(description='Process some integers.')\nparser.add_argument('integers', metavar='N', type=int, nargs='+',\n help='an integer for the accumulator')\nparser.add_argument('--sum', dest='accumulate', action='store_const',\n const=sum, default=max,\n help='sum the integers (default: find the max)')\n\nargs = parser.parse_args()\nprint args.accumulate(args.integers)\n" }, { "answer_id": 30341035, "author": "Viswesn", "author_id": 527813, "author_profile": "https://Stackoverflow.com/users/527813", "pm_score": 4, "selected": false, "text": "import argparse\nimport sys\n\ntry:\n parser = argparse.ArgumentParser()\n parser.add_argument(\"square\", help=\"display a square of a given number\",\n type=int)\n args = parser.parse_args()\n\n #print the square of user input from cmd line.\n print args.square**2\n\n #print all the sys argument passed from cmd line including the program name.\n print sys.argv\n\n #print the second argument passed from cmd line; Note it starts from ZERO\n print sys.argv[1]\nexcept:\n e = sys.exc_info()[0]\n print e\n C:\\Users\\Desktop>python -i emp.py 5\n25\n['emp.py', '5']\n5\n C:\\Users\\bgh37516\\Desktop>python -i emp.py five\nusage: emp.py [-h] square\nemp.py: error: argument square: invalid int value: 'five'\n<type 'exceptions.SystemExit'>\n" }, { "answer_id": 42305071, "author": "CorpseDead", "author_id": 5539337, "author_profile": "https://Stackoverflow.com/users/5539337", "pm_score": 3, "selected": false, "text": "variantname = input()\n x = input()\n8\n a = int(x) * 1.1343\nprint(round(a, 2)) # '9.07'\n9.07\n" }, { "answer_id": 44314236, "author": "Mark", "author_id": 8075198, "author_profile": "https://Stackoverflow.com/users/8075198", "pm_score": 2, "selected": false, "text": "data = raw_input('Enter something: ')\nprint data\n data = input('Enter something: ')\nprint(data)\n" }, { "answer_id": 54241008, "author": "Will Charlton", "author_id": 2517989, "author_profile": "https://Stackoverflow.com/users/2517989", "pm_score": 2, "selected": false, "text": "import six\n\nif six.PY2:\n input = raw_input\n\nprint(input(\"What's your name? \"))\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/70797", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1384652/" ]
70,842
<p>How should I run another program from within my <code>C</code> program? I need to be able to write data into <code>STDIN</code> of the launched program (and maybe read from it's <code>STDOUT</code>)</p> <p>I am not sure if this is a standard C function. I need the solution that should work under Linux.</p>
[ { "answer_id": 70848, "author": "freespace", "author_id": 8297, "author_profile": "https://Stackoverflow.com/users/8297", "pm_score": 5, "selected": true, "text": "popen man popen\n popen popen popen" }, { "answer_id": 70857, "author": "Vhaerun", "author_id": 11234, "author_profile": "https://Stackoverflow.com/users/11234", "pm_score": 0, "selected": false, "text": "freopen" }, { "answer_id": 70858, "author": "Jorge Ferreira", "author_id": 6508, "author_profile": "https://Stackoverflow.com/users/6508", "pm_score": 3, "selected": false, "text": "pipe(...) stdin stdout fork(...) fork(...) dup (...) stdin stdout exec[v][e] fork stdout select(...) poll(...) read(...) waitpid(...) stdin close(...)" }, { "answer_id": 83456, "author": "Steve Baker", "author_id": 13566, "author_profile": "https://Stackoverflow.com/users/13566", "pm_score": 4, "selected": false, "text": "#include <sys/types.h>\n#include <unistd.h>\n#include <stdio.h>\n\nvoid error(char *s);\nchar *data = \"Some input data\\n\";\n\nmain()\n{\n int in[2], out[2], n, pid;\n char buf[255];\n\n /* In a pipe, xx[0] is for reading, xx[1] is for writing */\n if (pipe(in) < 0) error(\"pipe in\");\n if (pipe(out) < 0) error(\"pipe out\");\n\n if ((pid=fork()) == 0) {\n /* This is the child process */\n\n /* Close stdin, stdout, stderr */\n close(0);\n close(1);\n close(2);\n /* make our pipes, our new stdin,stdout and stderr */\n dup2(in[0],0);\n dup2(out[1],1);\n dup2(out[1],2);\n\n /* Close the other ends of the pipes that the parent will use, because if\n * we leave these open in the child, the child/parent will not get an EOF\n * when the parent/child closes their end of the pipe.\n */\n close(in[1]);\n close(out[0]);\n\n /* Over-write the child process with the hexdump binary */\n execl(\"/usr/bin/hexdump\", \"hexdump\", \"-C\", (char *)NULL);\n error(\"Could not exec hexdump\");\n }\n\n printf(\"Spawned 'hexdump -C' as a child process at pid %d\\n\", pid);\n\n /* This is the parent process */\n /* Close the pipe ends that the child uses to read from / write to so\n * the when we close the others, an EOF will be transmitted properly.\n */\n close(in[0]);\n close(out[1]);\n\n printf(\"<- %s\", data);\n /* Write some data to the childs input */\n write(in[1], data, strlen(data));\n\n /* Because of the small amount of data, the child may block unless we\n * close it's input stream. This sends an EOF to the child on it's\n * stdin.\n */\n close(in[1]);\n\n /* Read back any output */\n n = read(out[0], buf, 250);\n buf[n] = 0;\n printf(\"-> %s\",buf);\n exit(0);\n}\n\nvoid error(char *s)\n{\n perror(s);\n exit(1);\n}\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/70842", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6974/" ]
70,850
<p>What advantage, if any, is provided by formatting C code as follows:</p> <pre><code>while(lock_file(lockdir)==0) { count++; if(count==20) { fprintf(stderr,"Can't lock dir %s\n",lockdir); exit(1); } sleep(3); } if(rmdir(serverdir)!=0) { switch(errno) { case EEXIST: fprintf(stderr,"Server dir %s not empty\n",serverdir); break; default: fprintf(stderr,"Can't delete dir %s\n",serverdir); } exit(1); } unlock_file(lockdir); </code></pre> <p>versus something more typical such as</p> <pre><code>while(lock_file(lockdir)==0) { count++; if(count==20) { fprintf(stderr,"Can't lock dir %s\n",lockdir); exit(1); } sleep(3); } if(rmdir(serverdir)!=0) { switch(errno) { case EEXIST: fprintf(stderr,"Server dir %s not empty\n",serverdir); break; default: fprintf(stderr,"Can't delete dir %s\n",serverdir); } exit(1); } unlock_file(lockdir); </code></pre> <p>I just find the top version difficult to read and to get the indenting level correct for statements outside of a long block, especially for longs blocks containing several nested blocks.</p> <p>Only advantage I can see is just to be different and leave your fingerprints on code that you've written.</p> <p>I notice vim formatting would have to be hand-rolled to handle the top case.</p>
[ { "answer_id": 70923, "author": "Ben", "author_id": 11522, "author_profile": "https://Stackoverflow.com/users/11522", "pm_score": 2, "selected": false, "text": "if (x == 0) \n{\n if (y == 2)\n {\n if (z == 3)\n {\n do_something (x);\n }\n }\n}\n" }, { "answer_id": 272759, "author": "bendin", "author_id": 33412, "author_profile": "https://Stackoverflow.com/users/33412", "pm_score": 3, "selected": false, "text": "if if XXXXXXXXXXXXXXX if (test)\n XXXXXXXXXXXX one_thing();\n\nXXXXXXXXXXXXXXX if (test)\n X {\n XXXXX one_thing();\n XXXXX another_thing();\n X }\n XXXXXXXXXXXXXX X if (test) {\n XXXXXX one_thing();\n XXXXXX another_thing();\nX }\n IF test THEN\n oneThing;\n anotherThing\nEND\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/70850", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2974/" ]
70,855
<p>Is there a realistic way of implementing a multi-threaded model in PHP whether truly, or just simulating it. Some time back it was suggested that you could force the operating system to load another instance of the PHP executable and handle other simultaneous processes.</p> <p>The problem with this is that when the PHP code finished executing the PHP instance remains in memory because there is no way to kill it from within PHP. So if you are simulating several threads you can imagine whats going to happen. So I am still looking for a way multi-threading can be done or simulated effectively from within PHP. Any ideas?</p>
[ { "answer_id": 72605, "author": "Adam Hopkinson", "author_id": 12280, "author_profile": "https://Stackoverflow.com/users/12280", "pm_score": 4, "selected": false, "text": "exec(\"/path/to/php -f '/path/to/file.php' | '/path/to/output.txt'\");\n" }, { "answer_id": 1079624, "author": "Ricardo", "author_id": 132841, "author_profile": "https://Stackoverflow.com/users/132841", "pm_score": 5, "selected": false, "text": "$request = \"http://localhost/test/process1.php?sessionid=\".$_REQUEST[\"PHPSESSID\"];\n$ch = curl_init();\ncurl_setopt($ch, CURLOPT_URL, $request);\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\ncurl_setopt($ch, CURLOPT_TIMEOUT, 1);\ncurl_exec($ch);\ncurl_close($ch);\necho $_REQUEST[\"PHPSESSID\"];\n set_time_limit(0);\n\nif ($_REQUEST[\"sessionid\"])\n session_id($_REQUEST[\"sessionid\"]);\n\nfunction checkclose()\n{\n global $_SESSION;\n if ($_SESSION[\"closesession\"])\n {\n unset($_SESSION[\"closesession\"]);\n die();\n }\n}\n\nwhile(!$close)\n{\n session_start();\n $_SESSION[\"test\"] = rand();\n checkclose();\n session_write_close();\n sleep(5);\n}\n if ($_REQUEST[\"sessionid\"])\n session_id($_REQUEST[\"sessionid\"]);\n\nsession_start();\nvar_dump($_SESSION);\n if ($_REQUEST[\"sessionid\"])\n session_id($_REQUEST[\"sessionid\"]);\n\nsession_start();\n$_SESSION[\"closesession\"] = true;\nvar_dump($_SESSION);\n" }, { "answer_id": 4350418, "author": "masterb", "author_id": 529958, "author_profile": "https://Stackoverflow.com/users/529958", "pm_score": 6, "selected": false, "text": "for ($i=0; $i<10; $i++) {\n // open ten processes\n for ($j = 0; $j < 10; $j++) {\n $pipe[$j] = popen('script2.php', 'w');\n }\n\n // wait for them to finish\n for ($j = 0; $j < 10; ++$j) {\n pclose($pipe[$j]);\n }\n}\n" }, { "answer_id": 8844548, "author": "Jarrod", "author_id": 577306, "author_profile": "https://Stackoverflow.com/users/577306", "pm_score": 3, "selected": false, "text": "<?php\n\n $pid = pcntl_fork();\n if ($pid == -1) {\n die('could not fork');\n } else if ($pid) {\n // we are the parent\n pcntl_wait($status); //Protect against Zombie children\n } else {\n // we are the child\n }\n\n?>\n" }, { "answer_id": 9107047, "author": "Stilero", "author_id": 1180559, "author_profile": "https://Stackoverflow.com/users/1180559", "pm_score": 2, "selected": false, "text": "pcntl_fork" }, { "answer_id": 15501449, "author": "Baba", "author_id": 1226894, "author_profile": "https://Stackoverflow.com/users/1226894", "pm_score": 9, "selected": false, "text": "#!/usr/bin/php\n<?php\nclass AsyncOperation extends Thread {\n\n public function __construct($arg) {\n $this->arg = $arg;\n }\n\n public function run() {\n if ($this->arg) {\n $sleep = mt_rand(1, 10);\n printf('%s: %s -start -sleeps %d' . \"\\n\", date(\"g:i:sa\"), $this->arg, $sleep);\n sleep($sleep);\n printf('%s: %s -finish' . \"\\n\", date(\"g:i:sa\"), $this->arg);\n }\n }\n}\n\n// Create a array\n$stack = array();\n\n//Initiate Multiple Thread\nforeach ( range(\"A\", \"D\") as $i ) {\n $stack[] = new AsyncOperation($i);\n}\n\n// Start The Threads\nforeach ( $stack as $t ) {\n $t->start();\n}\n\n?>\n 12:00:06pm: A -start -sleeps 5\n12:00:06pm: B -start -sleeps 3\n12:00:06pm: C -start -sleeps 10\n12:00:06pm: D -start -sleeps 2\n12:00:08pm: D -finish\n12:00:09pm: B -finish\n12:00:11pm: A -finish\n12:00:16pm: C -finish\n 12:01:36pm: A -start -sleeps 6\n12:01:36pm: B -start -sleeps 1\n12:01:36pm: C -start -sleeps 2\n12:01:36pm: D -start -sleeps 1\n12:01:37pm: B -finish\n12:01:37pm: D -finish\n12:01:38pm: C -finish\n12:01:42pm: A -finish\n error_reporting(E_ALL);\nclass AsyncWebRequest extends Thread {\n public $url;\n public $data;\n\n public function __construct($url) {\n $this->url = $url;\n }\n\n public function run() {\n if (($url = $this->url)) {\n /*\n * If a large amount of data is being requested, you might want to\n * fsockopen and read using usleep in between reads\n */\n $this->data = file_get_contents($url);\n } else\n printf(\"Thread #%lu was not provided a URL\\n\", $this->getThreadId());\n }\n}\n\n$t = microtime(true);\n$g = new AsyncWebRequest(sprintf(\"http://www.google.com/?q=%s\", rand() * 10));\n/* starting synchronization */\nif ($g->start()) {\n printf(\"Request took %f seconds to start \", microtime(true) - $t);\n while ( $g->isRunning() ) {\n echo \".\";\n usleep(100);\n }\n if ($g->join()) {\n printf(\" and %f seconds to finish receiving %d bytes\\n\", microtime(true) - $t, strlen($g->data));\n } else\n printf(\" and %f seconds to finish, request failed\\n\", microtime(true) - $t);\n}\n" }, { "answer_id": 19789433, "author": "Pir Abdul", "author_id": 665485, "author_profile": "https://Stackoverflow.com/users/665485", "pm_score": -1, "selected": false, "text": "chdir(dirname(__FILE__)); //if you want to run this file as cron job\n for ($i = 0; $i < 2; $i += 1){\n exec(\"php test_1.php $i > test.txt &\");\n //this will execute test_1.php and will leave this process executing in the background and will go \n\n //to next iteration of the loop immediately without waiting the completion of the script in the \n\n //test_1.php , $i is passed as argument .\n $conn=mysql_connect($host,$user,$pass);\n$db=mysql_select_db($db);\n$i = $argv[1]; //this is the argument passed from index.php file\nfor($j = 0;$j<5000; $j ++)\n{\nmysql_query(\"insert into test set\n\n id='$i',\n\n comment='test',\n\n datetime=NOW() \");\n\n}\n" }, { "answer_id": 52125027, "author": "Martin Vahi", "author_id": 855783, "author_profile": "https://Stackoverflow.com/users/855783", "pm_score": -1, "selected": false, "text": "uname -a\n" }, { "answer_id": 61505176, "author": "Юрий Ярвинен", "author_id": 10738019, "author_profile": "https://Stackoverflow.com/users/10738019", "pm_score": 3, "selected": false, "text": "exec(\"nohup $php_path path/script.php > /dev/null 2>/dev/null &\")\n exec(\"nohup $php_path path/script.php $args > /dev/null 2>/dev/null &\")\n $args = $argv[1];\n $process = Process::fromShellCommandline(\"php \".base_path('script.php'));\n$process->setTimeout(0); \n$process->disableOutput(); \n$process->start();\n" }, { "answer_id": 71617864, "author": "Justin Jack", "author_id": 1678210, "author_profile": "https://Stackoverflow.com/users/1678210", "pm_score": 2, "selected": false, "text": "function threadproc($thread, $param) {\n \n echo \"\\tI'm a PHPThread. In this example, I was given only one parameter: \\\"\". print_r($param, true) .\"\\\" to work with, but I can accept as many as you'd like!\\n\";\n \n for ($i = 0; $i < 10; $i++) {\n usleep(1000000);\n echo \"\\tPHPThread working, very busy...\\n\";\n }\n \n return \"I'm a return value!\";\n}\n \n\n$thread_id = phpthread_create($thread, array(), \"threadproc\", null, array(\"123456\"));\n \necho \"I'm the main thread doing very important work!\\n\";\n \nfor ($n = 0; $n < 5; $n++) {\n usleep(1000000);\n echo \"Main thread...working!\\n\";\n}\n \necho \"\\nMain thread done working. Waiting on our PHPThread...\\n\";\n \nphpthread_join($thread_id, $retval);\n \necho \"\\n\\nOur PHPThread returned: \" . print_r($retval, true) . \"!\\n\";\n" }, { "answer_id": 74086559, "author": "gzhegow", "author_id": 2119205, "author_profile": "https://Stackoverflow.com/users/2119205", "pm_score": 0, "selected": false, "text": "// sleep.php\nset_error_handler(function ($severity, $error, $file, $line) {\n throw new ErrorException($error, -1, $severity, $file, $line);\n});\n\n$sleep = $argv[ 1 ];\n\nsleep($sleep);\n\necho $sleep . PHP_EOL;\n\nexit(0);\n // run.php\n<?php\n\n$procs = [];\n$pipes = [];\n\n$cmd = 'php %cd%/sleep.php';\n\n$desc = [\n 0 => [ 'pipe', 'r' ],\n 1 => [ 'pipe', 'w' ],\n 2 => [ 'pipe', 'a' ],\n];\n\nfor ( $i = 0; $i < 10; $i++ ) {\n $iCmd = $cmd . ' ' . ( 10 - $i ); // add SLEEP argument to each command 10, 9, ... etc.\n\n $proc = proc_open($iCmd, $desc, $pipes[ $i ], __DIR__);\n\n $procs[ $i ] = $proc;\n}\n\n$stdins = array_column($pipes, 0);\n$stdouts = array_column($pipes, 1);\n$stderrs = array_column($pipes, 2);\n\nwhile ( $procs ) {\n foreach ( $procs as $i => $proc ) {\n // @gzhegow > [OR] you can output while script is running (if child never finishes)\n $read = [ $stdins[ $i ] ];\n $write = [ $stdouts[ $i ], $stderrs[ $i ] ];\n $except = [];\n if (stream_select($read, $write, $except, $seconds = 0, $microseconds = 1000)) {\n foreach ( $write as $stream ) {\n echo stream_get_contents($stream);\n }\n }\n\n $status = proc_get_status($proc);\n\n if (false === $status[ 'running' ]) {\n $status = proc_close($proc);\n unset($procs[ $i ]);\n\n echo 'STATUS: ' . $status . PHP_EOL;\n }\n\n // @gzhegow > [OR] you can output once command finishes\n // $status = proc_get_status($proc);\n //\n // if (false === $status[ 'running' ]) {\n // if ($content = stream_get_contents($stderrs[ $i ])) {\n // echo '[ERROR]' . $content . PHP_EOL;\n // }\n //\n // echo stream_get_contents($stdouts[ $i ]) . PHP_EOL;\n //\n // $status = proc_close($proc);\n // unset($procs[ $i ]);\n //\n // echo 'STATUS: ' . $status . PHP_EOL;\n // }\n }\n\n usleep(1); // give your computer one tick to decide what thread should be used\n}\n\n// ensure you receive 1,2,3... but you've just run it 10,9,8...\n\nexit(0);\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/70855", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11190/" ]
70,880
<p>Say I have the following C++:</p> <pre><code>char *p = new char[cb]; SOME_STRUCT *pSS = (SOME_STRUCT *) p; delete pSS; </code></pre> <p>Is this safe according to the C++ standard? Do I need to cast back to a <code>char*</code> and then use <code>delete[]</code>? I know it'll work in most C++ compilers, because it's plain-ordinary-data, with no destructors. Is it guaranteed to be safe?</p>
[ { "answer_id": 70904, "author": "Daniel James", "author_id": 2434, "author_profile": "https://Stackoverflow.com/users/2434", "pm_score": 3, "selected": false, "text": "operator delete[] operator delete" }, { "answer_id": 70905, "author": "thudbang", "author_id": 11661, "author_profile": "https://Stackoverflow.com/users/11661", "pm_score": 4, "selected": true, "text": "[] char int" }, { "answer_id": 70942, "author": "Zooba", "author_id": 891, "author_profile": "https://Stackoverflow.com/users/891", "pm_score": 2, "selected": false, "text": "delete char delete[] char SOME_STRUCT* Allocate()\n{\n size_t cb; // Initialised to something\n return (SOME_STRUCT*)(new char[cb]);\n}\n void Free(SOME_STRUCT* obj)\n{\n delete[] (char*)obj;\n}\n new delete" }, { "answer_id": 108579, "author": "CB Bailey", "author_id": 19563, "author_profile": "https://Stackoverflow.com/users/19563", "pm_score": 2, "selected": false, "text": "size_of(SOME_STRUCT) operator new new new void* p = ::operator new( cb );\nSOME_STRUCT* pSS = new (p) SOME_STRUCT;\n\n// ...\n\ndelete pSS;\n SOME_STRUCT SOME_STRUCT SOME_STRUCT ::operator new ::operator delete malloc free new delete" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/70880", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8446/" ]
70,947
<p>I have a workbook with 20 different pivot tables. Is there any easy way to find all the pivot tables and refresh them in VBA?</p>
[ { "answer_id": 70976, "author": "GSerg", "author_id": 11683, "author_profile": "https://Stackoverflow.com/users/11683", "pm_score": 9, "selected": true, "text": "ThisWorkbook.RefreshAll\n Dim Sheet as WorkSheet, Pivot as PivotTable\nFor Each Sheet in ThisWorkbook.WorkSheets\n For Each Pivot in Sheet.PivotTables\n Pivot.RefreshTable\n Pivot.Update\n Next\nNext\n" }, { "answer_id": 71002, "author": "LohanJ", "author_id": 11286, "author_profile": "https://Stackoverflow.com/users/11286", "pm_score": 1, "selected": false, "text": "Sub RefreshPivotTables()\n Dim pivotTable As PivotTable\n For Each pivotTable In ActiveSheet.PivotTables\n pivotTable.RefreshTable\n Next\nEnd Sub\n" }, { "answer_id": 71084, "author": "Robert Mearns", "author_id": 5050, "author_profile": "https://Stackoverflow.com/users/5050", "pm_score": 5, "selected": false, "text": "Sub RefreshAllPivotTables()\n\nDim PT As PivotTable\nDim WS As Worksheet\n\n For Each WS In ThisWorkbook.Worksheets\n\n For Each PT In WS.PivotTables\n PT.RefreshTable\n Next PT\n\n Next WS\n\nEnd Sub\n" }, { "answer_id": 12478754, "author": "RBhandal", "author_id": 1680524, "author_profile": "https://Stackoverflow.com/users/1680524", "pm_score": -1, "selected": false, "text": "ActiveWorkbook.RefreshAll\n" }, { "answer_id": 12592078, "author": "Kevin", "author_id": 1698696, "author_profile": "https://Stackoverflow.com/users/1698696", "pm_score": 5, "selected": false, "text": "ActiveWorkbook.RefreshAll Sub RefreshPivotTables() \n Dim pivotTable As PivotTable \n For Each pivotTable In ActiveSheet.PivotTables \n pivotTable.RefreshTable \n Next \nEnd Sub \n" }, { "answer_id": 29474211, "author": "user3564681", "author_id": 3564681, "author_profile": "https://Stackoverflow.com/users/3564681", "pm_score": 0, "selected": false, "text": "Private Sub Worksheet_Activate()\n Dim PvtTbl As PivotTable\n Cells.EntireColumn.AutoFit\n For Each PvtTbl In Worksheets(\"Sales Details\").PivotTables\n PvtTbl.RefreshTable\n Next\nEnd Sub \n" }, { "answer_id": 34544128, "author": "Rajiv Singh", "author_id": 1527856, "author_profile": "https://Stackoverflow.com/users/1527856", "pm_score": 0, "selected": false, "text": "Sub UpdateConnection()\n Dim ServerName As String\n Dim ServerNameRaw As String\n Dim CubeName As String\n Dim CubeNameRaw As String\n Dim ConnectionString As String\n\n ServerNameRaw = ActiveWorkbook.SlicerCaches(\"Slicer_ServerName\").VisibleSlicerItemsList(1)\n ServerName = Replace(Split(ServerNameRaw, \"[\")(3), \"]\", \"\")\n\n CubeNameRaw = ActiveWorkbook.SlicerCaches(\"Slicer_CubeName\").VisibleSlicerItemsList(1)\n CubeName = Replace(Split(CubeNameRaw, \"[\")(3), \"]\", \"\")\n\n If CubeName = \"All\" Or ServerName = \"All\" Then\n MsgBox \"Please Select One Cube and Server Name\", vbOKOnly, \"Slicer Info\"\n Else\n ConnectionString = GetConnectionString(ServerName, CubeName)\n UpdateAllQueryTableConnections ConnectionString, CubeName\n End If\n End Sub\n\n Function GetConnectionString(ServerName As String, CubeName As String)\n Dim result As String\n result = \"OLEDB;Provider=MSOLAP.5;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=\" & CubeName & \";Data Source=\" & ServerName & \";MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error;Update Isolation Level=2\"\n '\"OLEDB;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=\" & CubeName & \";Data Source=\" & ServerName & \";Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Use Encryption for Data=False;Tag with column collation when possible=False\"\n GetConnectionString = result\n End Function\n\n Function GetConnectionString(ServerName As String, CubeName As String)\n Dim result As String\n result = \"OLEDB;Provider=MSOLAP.5;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=\" & CubeName & \";Data Source=\" & ServerName & \";MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error;Update Isolation Level=2\"\n GetConnectionString = result\nEnd Function\n\nSub UpdateAllQueryTableConnections(ConnectionString As String, CubeName As String)\n Dim cn As WorkbookConnection\n Dim oledbCn As OLEDBConnection\n Dim Count As Integer, i As Integer\n Dim DBName As String\n DBName = \"Initial Catalog=\" + CubeName\n\n Count = 0\n For Each cn In ThisWorkbook.Connections\n If cn.Name = \"ThisWorkbookDataModel\" Then\n Exit For\n End If\n\n oTmp = Split(cn.OLEDBConnection.Connection, \";\")\n For i = 0 To UBound(oTmp) - 1\n If InStr(1, oTmp(i), DBName, vbTextCompare) = 1 Then\n Set oledbCn = cn.OLEDBConnection\n oledbCn.SavePassword = True\n oledbCn.Connection = ConnectionString\n oledbCn.Refresh\n Count = Count + 1\n End If\n Next\n Next\n\n If Count = 0 Then\n MsgBox \"Nothing to update\", vbOKOnly, \"Update Connection\"\n ElseIf Count > 0 Then\n MsgBox \"Update & Refresh Connection Successfully\", vbOKOnly, \"Update Connection\"\n End If\nEnd Sub\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/70947", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8418/" ]
70,956
<p>Is there a good way to exclude certain pages from using a HTTP module?</p> <p>I have an application that uses a custom HTTP module to validate a session. The HTTPModule is set up like this in web config:</p> <pre><code>&lt;system.web&gt; &lt;!-- ... --&gt; &lt;httpModules&gt; &lt;add name="SessionValidationModule" type="SessionValidationModule, SomeNamespace" /&gt; &lt;/httpModules&gt; &lt;/system.web&gt; </code></pre> <p>To exclude the module from the page, I tried doing this (without success):</p> <pre><code>&lt;location path="ToBeExcluded"&gt; &lt;system.web&gt; &lt;!-- ... --&gt; &lt;httpModules&gt; &lt;remove name="SessionValidationModule" /&gt; &lt;/httpModules&gt; &lt;/system.web&gt; &lt;/location&gt; </code></pre> <p>Any thoughts?</p>
[ { "answer_id": 71790, "author": "Crob", "author_id": 2460, "author_profile": "https://Stackoverflow.com/users/2460", "pm_score": 5, "selected": true, "text": "<add verb=\"*\" path=\"/validate/*.aspx\" type=\"Handler,Assembly\"/>\n" }, { "answer_id": 18411217, "author": "Mr. Pumpkin", "author_id": 524605, "author_profile": "https://Stackoverflow.com/users/524605", "pm_score": 3, "selected": false, "text": "public class AuthenticationModule : IHttpModule\n{\n private static readonly List<string> extensionsToSkip = AuthenticationConfig.ExtensionsToSkip.Split('|').ToList();\n\n // In the Init function, register for HttpApplication \n // events by adding your handlers.\n public void Init(HttpApplication application)\n {\n application.BeginRequest += new EventHandler(this.Application_BeginRequest);\n application.EndRequest += new EventHandler(this.Application_EndRequest);\n }\n\n private void Application_BeginRequest(Object source, EventArgs e)\n {\n // we don't have to process all requests...\n if (extensionsToSkip.Contains(Path.GetExtension(HttpContext.Current.Request.Url.LocalPath)))\n return;\n\n Trace.WriteLine(\"Application_BeginRequest: \" + HttpContext.Current.Request.Url.AbsoluteUri);\n }\n\n private void Application_EndRequest(Object source, EventArgs e)\n {\n // we don't have to process all requests...\n if (extensionsToSkip.Contains(Path.GetExtension(HttpContext.Current.Request.Url.LocalPath)))\n return;\n\n Trace.WriteLine(\"Application_BeginRequest: \" + HttpContext.Current.Request.Url.AbsoluteUri);\n }\n}\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/70956", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6308/" ]
70,964
<p>Originally I am looking for a solution in Actionscript. The point of this question is the algorithm, which detects the exact Minute, when a clock has to switch the Daylight Saving Time. </p> <p>So for example between the 25th and the 31th of October we have to check, if the actual date is a sunday, it is before or after 2 o'clock...</p>
[ { "answer_id": 154765, "author": "Benno Richters", "author_id": 3565, "author_profile": "https://Stackoverflow.com/users/3565", "pm_score": 2, "selected": false, "text": "inDaylightTime import org.joda.time.DateTime;\nimport org.joda.time.DateTimeZone;\n\npublic class App {\n public static void main(String[] args) {\n DateTimeZone dtz = DateTimeZone.forID(\"Europe/Amsterdam\");\n\n System.out.println(startDST(dtz, 2008));\n System.out.println(endDST(dtz, 2008));\n }\n\n public static DateTime startDST(DateTimeZone zone, int year) {\n return new DateTime(zone.nextTransition(new DateTime(year, 1, 1, 0, 0, 0, 0, zone).getMillis()));\n }\n\n public static DateTime endDST(DateTimeZone zone, int year) {\n return new DateTime(zone.previousTransition(new DateTime(year + 1, 1, 1, 0, 0, 0, 0, zone).getMillis()));\n }\n}\n" }, { "answer_id": 50499119, "author": "Basil Bourque", "author_id": 642706, "author_profile": "https://Stackoverflow.com/users/642706", "pm_score": 1, "selected": false, "text": "ZonedDateTime ZoneId z = ZoneId.of( \"America/Montreal\" );\nLocalDate ld = LocalDate.of( 2018 , Month.MARCH , 11 ); // 2018-03-11.\nLocalTime lt = LocalTime.of( 2 , 0 ); // 2 AM.\nZonedDateTime zdt = ZonedDateTime.of( ld , lt , z );\n ZoneRules Duration d = z.getRules().getDaylightSavings​( Instant.now() ) ;\n ZoneOffsetTransition ZoneId z = ZoneId.of( \"America/Montreal\" );\nZoneOffsetTransition t = z.getRules().nextTransition( Instant.now() );\nString output = \"For zone: \" + z + \", on \" + t.getDateTimeBefore() + \" duration change: \" + t.getDuration() + \" to \" + t.getDateTimeAfter();\n continent/region America/Montreal Africa/Casablanca Pacific/Auckland EST IST java.util.Date Calendar SimpleDateFormat java.sql.* Interval YearWeek YearQuarter" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/70964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
70,992
<p>Relating to my <a href="https://stackoverflow.com/questions/48733/javahibernate-jpa-designing-the-server-data-reload">earlier question</a>, I want to ensure all the child objects are loaded as I have a multiple threads that may need to access the data (and thus avoid lazy loading exceptions). I understand the way to do this is to use the "fetch" keyword in the query (EJB QL). Like this:</p> <pre><code>select distinct o from Order o left join fetch o.orderLines </code></pre> <p>Assuming a model with an <code>Order</code> class which has a set of <code>OrderLines</code> in it.</p> <p>My question is that the "distinct" keyword seems to be needed as otherwise I seem to get back an <code>Order</code> for each <code>OrderLine</code>. Am I doing the right thing?</p> <p>Perhaps more importantly, is there a way to pull in all child objects, no matter how deep? We have around 10-15 classes and for the server we will need everything loaded... I was avoiding using <code>FetchType.EAGER</code> as that meant its always eager and in particular the web front end loads everything - but perhaps that is the way to go - is that what you do? I seem to remember us trying this before and then getting really slow webpages - but perhaps that means we should be using a second-level cache?</p>
[ { "answer_id": 74284, "author": "ncgz", "author_id": 12905, "author_profile": "https://Stackoverflow.com/users/12905", "pm_score": -1, "selected": false, "text": " <filter>\n <filter-name>hibernateFilter</filter-name>\n <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter\n </filter-class>\n </filter>\n <filter-mapping>\n <filter-name>hibernateFilter</filter-name>\n <url-pattern>/*</url-pattern>\n </filter-mapping>\n" }, { "answer_id": 75459, "author": "Mike Desjardins", "author_id": 10466, "author_profile": "https://Stackoverflow.com/users/10466", "pm_score": 2, "selected": false, "text": "Session s = ((HibernateEntityManager) em).getSession().getSessionFactory().openSession();\nDetachedCriteria dc = DetachedCriteria.forClass(MyEntity.class).add(Expression.idEq(id));\ndc.setFetchMode(\"innerTable\", FetchMode.JOIN);\nCriteria c = dc.getExecutableCriteria(s);\nMyEntity a = (MyEntity)c.uniqueResult();\n" }, { "answer_id": 227780, "author": "Miguel Ping", "author_id": 22992, "author_profile": "https://Stackoverflow.com/users/22992", "pm_score": 2, "selected": false, "text": "Criteria c = ((Session)em.getDelegate()).createCriteria(Order.class);\nc.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);\nc.list();\n em.getDelegate()" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/70992", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48310/" ]
70,993
<p>We all know the various ways of testing OO systems. However, it looks like I'll be going to do a project where I'll be dealing with PLC ladder logic (don't ask :/), and I was wondering if there's a good way of testing the validity of the system.</p> <p>The only way I see so far is simply constructing a huge table with all known states of the system and which output states that generates. This would do for simple 'if input A is on, turn output B on' cases. I don't think this will work for more complicated constructions though.</p>
[ { "answer_id": 71105, "author": "jbdavid", "author_id": 6314, "author_profile": "https://Stackoverflow.com/users/6314", "pm_score": 4, "selected": true, "text": "|---|R15|---+---|/R16|---------(R18)--------|\n| |\n|---|R12|---+\n always @(*) R18 = !R16 && ( R15 | R12);\n assign R18 = R16 && (R15 | R12); \n assign R18 = (set condition) || R18 && !(break condition);\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/70993", "https://Stackoverflow.com", "https://Stackoverflow.com/users/909/" ]
71,000
<p>I'm trying to create a Zip file from .Net that can be read from Java code.</p> <p>I've used SharpZipLib to create the Zip file but also if the file generated is valid according to the CheckZip function of the #ZipLib library and can be successfully uncompressed via WinZip or WinRar I always get an error when trying to uncompress it using the Java.Utils.Zip class in Java.</p> <p>Problem seems to be in the wrong header written by SharpZipLib, I've also posted a question on the SharpDevelop forum but with no results (see <a href="http://community.sharpdevelop.net/forums/t/8272.aspx" rel="nofollow noreferrer">http://community.sharpdevelop.net/forums/t/8272.aspx</a> for info) but with no result.</p> <p>Has someone a code sample of compressing a Zip file with .Net and de-compressing it with the Java.Utils.Zip class?</p> <p>Regards Massimo</p>
[ { "answer_id": 71072, "author": "Panos", "author_id": 8049, "author_profile": "https://Stackoverflow.com/users/8049", "pm_score": 4, "selected": true, "text": "using (ZipFile zipFile = new ZipFile())\n{\n zipFile.AddDirectory(sourceFolderPath);\n zipFile.Save(archiveFolderName);\n}\n" }, { "answer_id": 659397, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "ZipOutputStream s = new ZipOutputStream(File.Create(someZipFileName))\n\ns.UseZip64 = UseZip64.Off;\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71000", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11673/" ]
71,022
<p>How do you return 1 value per row of the max of several columns:</p> <p><strong>TableName</strong></p> <pre><code>[Number, Date1, Date2, Date3, Cost] </code></pre> <p>I need to return something like this:</p> <pre><code>[Number, Most_Recent_Date, Cost] </code></pre> <p>Query?</p>
[ { "answer_id": 71045, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 9, "selected": true, "text": "SELECT\n CASE\n WHEN Date1 >= Date2 AND Date1 >= Date3 THEN Date1\n WHEN Date2 >= Date1 AND Date2 >= Date3 THEN Date2\n WHEN Date3 >= Date1 AND Date3 >= Date2 THEN Date3\n ELSE Date1\n END AS MostRecentDate\n" }, { "answer_id": 71147, "author": "databyss", "author_id": 9094, "author_profile": "https://Stackoverflow.com/users/9094", "pm_score": 4, "selected": false, "text": "SELECT MAX(date_columns) AS max_date\nFROM ( (SELECT date1 AS date_columns\n FROM data_table )\n UNION\n ( SELECT date2 AS date_columns\n FROM data_table\n )\n UNION\n ( SELECT date3 AS date_columns\n FROM data_table\n )\n ) AS date_query\n SELECT MAX(MostRecentDate)\nFROM ( SELECT CASE WHEN date1 >= date2\n AND date1 >= date3 THEN date1\n WHEN date2 >= date1\n AND date2 >= date3 THEN date2\n WHEN date3 >= date1\n AND date3 >= date2 THEN date3\n ELSE date1\n END AS MostRecentDate\n FROM data_table\n ) AS date_query \n" }, { "answer_id": 331873, "author": "bajafresh4life", "author_id": 21339, "author_profile": "https://Stackoverflow.com/users/21339", "pm_score": 8, "selected": false, "text": "SELECT GREATEST(col1, col2 ...) FROM table\n" }, { "answer_id": 331933, "author": "Lance Fisher", "author_id": 571, "author_profile": "https://Stackoverflow.com/users/571", "pm_score": 2, "selected": false, "text": "create table dates \n(\n number int,\n date1 datetime,\n date2 datetime,\n date3 datetime \n)\n\ninsert into dates values (1, '1/1/2008', '2/4/2008', '3/1/2008')\ninsert into dates values (1, '1/2/2008', '2/3/2008', '3/3/2008')\ninsert into dates values (1, '1/3/2008', '2/2/2008', '3/2/2008')\ninsert into dates values (1, '1/4/2008', '2/1/2008', '3/4/2008')\n\nselect max(dateMaxes)\nfrom (\n select \n (select max(date1) from dates) date1max, \n (select max(date2) from dates) date2max,\n (select max(date3) from dates) date3max\n) myTable\nunpivot (dateMaxes For fieldName In (date1max, date2max, date3max)) as tblPivot\n\ndrop table dates\n" }, { "answer_id": 1398019, "author": "Niikola", "author_id": 130904, "author_profile": "https://Stackoverflow.com/users/130904", "pm_score": 6, "selected": false, "text": "UNPIVOT CREATE TABLE dates\n (\n number INT PRIMARY KEY ,\n date1 DATETIME ,\n date2 DATETIME ,\n date3 DATETIME ,\n cost INT\n )\n\nINSERT INTO dates\nVALUES ( 1, '1/1/2008', '2/4/2008', '3/1/2008', 10 )\nINSERT INTO dates\nVALUES ( 2, '1/2/2008', '2/3/2008', '3/3/2008', 20 )\nINSERT INTO dates\nVALUES ( 3, '1/3/2008', '2/2/2008', '3/2/2008', 30 )\nINSERT INTO dates\nVALUES ( 4, '1/4/2008', '2/1/2008', '3/4/2008', 40 )\nGO\n UNPIVOT SELECT number ,\n MAX(dDate) maxDate ,\n cost\nFROM dates UNPIVOT ( dDate FOR nDate IN ( Date1, Date2,\n Date3 ) ) as u\nGROUP BY number ,\n cost \nGO\n SELECT number ,\n ( SELECT MAX(dDate) maxDate\n FROM ( SELECT d.date1 AS dDate\n UNION\n SELECT d.date2\n UNION\n SELECT d.date3\n ) a\n ) MaxDate ,\n Cost\nFROM dates d\nGO\n UNPIVOT ;WITH maxD\n AS ( SELECT number ,\n MAX(CASE rn\n WHEN 1 THEN Date1\n WHEN 2 THEN date2\n ELSE date3\n END) AS maxDate\n FROM dates a\n CROSS JOIN ( SELECT 1 AS rn\n UNION\n SELECT 2\n UNION\n SELECT 3\n ) b\n GROUP BY Number\n )\n SELECT dates.number ,\n maxD.maxDate ,\n dates.cost\n FROM dates\n INNER JOIN MaxD ON dates.number = maxD.number\nGO\n\nDROP TABLE dates\nGO\n" }, { "answer_id": 4308539, "author": "Nat", "author_id": 13813, "author_profile": "https://Stackoverflow.com/users/13813", "pm_score": 3, "selected": false, "text": "SELECT \n CASE \n WHEN Date1 >= Date2 AND Date1 >= Date3 THEN Date1 \n WHEN Date2 >= Date3 THEN Date2 \n ELSE Date3\n END AS MostRecentDate \n" }, { "answer_id": 4308905, "author": "Martin Smith", "author_id": 73226, "author_profile": "https://Stackoverflow.com/users/73226", "pm_score": 3, "selected": false, "text": "DECLARE @TableName TABLE (Number INT, Date1 DATETIME, Date2 DATETIME, Date3 DATETIME, Cost MONEY)\n\nINSERT INTO @TableName \nSELECT 1, '20000101', '20010101','20020101',100 UNION ALL\nSELECT 2, '20000101', '19900101','19980101',99 \n\nSELECT Number,\n Cost ,\n (SELECT MAX([Date])\n FROM (SELECT Date1 AS [Date]\n UNION ALL\n SELECT Date2\n UNION ALL\n SELECT Date3\n )\n D\n )\n [Most Recent Date]\nFROM @TableName\n" }, { "answer_id": 4695172, "author": "DrYodo", "author_id": 576121, "author_profile": "https://Stackoverflow.com/users/576121", "pm_score": 0, "selected": false, "text": "create FUNCTION fxMost_Recent_Date \n declare @MostRecent smalldatetime\n\nset @MostRecent='1/1/1900'\n\nif @Date1>@MostRecent begin set @MostRecent=@Date1 end\nif @Date2>@MostRecent begin set @MostRecent=@Date2 end\nif @Date3>@MostRecent begin set @MostRecent=@Date3 end\nRETURN @MostRecent\n" }, { "answer_id": 4922103, "author": "MartinC", "author_id": 606510, "author_profile": "https://Stackoverflow.com/users/606510", "pm_score": 4, "selected": false, "text": "CREATE FUNCTION dbo.Get_Min_Max_Date\n(\n @Date1 datetime,\n @Date2 datetime,\n @Date3 datetime,\n @Date4 datetime,\n @Date5 datetime,\n @Date6 datetime,\n @Date7 datetime,\n @Date8 datetime,\n @Date9 datetime,\n @Date10 datetime\n)\nRETURNS TABLE\nAS\nRETURN\n(\n SELECT Max(DateValue) Max_Date,\n Min(DateValue) Min_Date\n FROM (\n VALUES (@Date1),\n (@Date2),\n (@Date3),\n (@Date4),\n (@Date5),\n (@Date6),\n (@Date7),\n (@Date8),\n (@Date9),\n (@Date10)\n ) AS Dates(DateValue)\n)\n" }, { "answer_id": 6650238, "author": "Michael Freidgeim", "author_id": 52277, "author_profile": "https://Stackoverflow.com/users/52277", "pm_score": 1, "selected": false, "text": "CREATE FUNCTION GetMaxOfDates13 (\n@value01 DateTime = NULL, \n@value02 DateTime = NULL,\n@value03 DateTime = NULL,\n@value04 DateTime = NULL,\n@value05 DateTime = NULL,\n@value06 DateTime = NULL,\n@value07 DateTime = NULL,\n@value08 DateTime = NULL,\n@value09 DateTime = NULL,\n@value10 DateTime = NULL,\n@value11 DateTime = NULL,\n@value12 DateTime = NULL,\n@value13 DateTime = NULL\n)\nRETURNS DateTime\nAS\nBEGIN\nRETURN (\nSELECT TOP 1 value\nFROM (\nSELECT @value01 AS value UNION ALL\nSELECT @value02 UNION ALL\nSELECT @value03 UNION ALL\nSELECT @value04 UNION ALL\nSELECT @value05 UNION ALL\nSELECT @value06 UNION ALL\nSELECT @value07 UNION ALL\nSELECT @value08 UNION ALL\nSELECT @value09 UNION ALL\nSELECT @value10 UNION ALL\nSELECT @value11 UNION ALL\nSELECT @value12 UNION ALL\nSELECT @value13\n) AS [values]\nORDER BY value DESC \n)\nEND –FUNCTION\nGO\nCREATE FUNCTION GetMaxOfDates3 (\n@value01 DateTime = NULL, \n@value02 DateTime = NULL,\n@value03 DateTime = NULL\n)\nRETURNS DateTime\nAS\nBEGIN\nRETURN dbo.GetMaxOfDates13(@value01,@value02,@value03,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)\nEND –FUNCTION\n" }, { "answer_id": 6871572, "author": "Sven", "author_id": 442204, "author_profile": "https://Stackoverflow.com/users/442204", "pm_score": 10, "selected": false, "text": "Max SELECT [Other Fields],\n (SELECT Max(v) \n FROM (VALUES (date1), (date2), (date3),...) AS value(v)) as [MaxDate]\nFROM [YourTableName]\n" }, { "answer_id": 8971789, "author": "Disillusioned", "author_id": 224704, "author_profile": "https://Stackoverflow.com/users/224704", "pm_score": 3, "selected": false, "text": "DECLARE @v1 INT ,\n @v2 INT ,\n @v3 INT\n--SET @v1 = 1 --Comment out SET statements to experiment with \n --various combinations of NULL values\nSET @v2 = 2\nSET @v3 = 3\n\nSELECT ( SELECT MAX(Vals)\n FROM ( SELECT v1 AS Vals\n UNION\n SELECT v2\n UNION\n SELECT v3\n ) tmp\n WHERE Vals IS NOT NULL -- This eliminates NULL warning\n\n ) AS MaxVal\nFROM ( SELECT @v1 AS v1\n ) t1\n CROSS JOIN ( SELECT @v2 AS v2\n ) t2\n CROSS JOIN ( SELECT @v3 AS v3\n ) t3\n" }, { "answer_id": 10831815, "author": "Luis Miguel Rosa", "author_id": 1428154, "author_profile": "https://Stackoverflow.com/users/1428154", "pm_score": 2, "selected": false, "text": "[MinRateValue] = \nCASE \n WHEN ISNULL(FitchRating.RatingValue, 100) < = ISNULL(MoodyRating.RatingValue, 99) \n AND ISNULL(FitchRating.RatingValue, 100) < = ISNULL(StandardPoorsRating.RatingValue, 99) \n THEN FitchgAgency.RatingAgencyName\n\n WHEN ISNULL(MoodyRating.RatingValue, 100) < = ISNULL(StandardPoorsRating.RatingValue , 99)\n THEN MoodyAgency.RatingAgencyName\n\n ELSE ISNULL(StandardPoorsRating.RatingValue, 'N/A') \nEND \n" }, { "answer_id": 23864329, "author": "TechDo", "author_id": 1367256, "author_profile": "https://Stackoverflow.com/users/1367256", "pm_score": 1, "selected": false, "text": "UNPIVOT SELECT MAX(MaxDt) MaxDt\n FROM tbl \nUNPIVOT\n (MaxDt FOR E IN \n (Date1, Date2, Date3)\n)AS unpvt;\n" }, { "answer_id": 23888942, "author": "EarlOfEnnui", "author_id": 3442468, "author_profile": "https://Stackoverflow.com/users/3442468", "pm_score": 2, "selected": false, "text": "SELECT MostRecentDate \nFROM SourceTable\n CROSS APPLY (SELECT MAX(d) MostRecentDate FROM (VALUES (Date1), (Date2), (Date3)) AS a(d)) md\n" }, { "answer_id": 24527258, "author": "abdulbasit", "author_id": 3678700, "author_profile": "https://Stackoverflow.com/users/3678700", "pm_score": 2, "selected": false, "text": " DECLARE @Date1 DATE='2014-07-03';\n DECLARE @Date2 DATE='2014-07-04';\n DECLARE @Date3 DATE='2014-07-05';\n\n SELECT IIF(@Date1>@Date2,\n IIF(@Date1>@Date3,@Date1,@Date3),\n IIF(@Date2>@Date3,@Date2,@Date3)) AS MostRecentDate\n" }, { "answer_id": 29385881, "author": "jjaskulowski", "author_id": 2053494, "author_profile": "https://Stackoverflow.com/users/2053494", "pm_score": 4, "selected": false, "text": "SELECT\n (SELECT\n MAX(MyMaxName) \n FROM ( VALUES \n (MAX(Field1)), \n (MAX(Field2)) \n ) MyAlias(MyMaxName)\n ) \nFROM MyTable1\n" }, { "answer_id": 31914496, "author": "danvasiloiu", "author_id": 4424087, "author_profile": "https://Stackoverflow.com/users/4424087", "pm_score": -1, "selected": false, "text": "CREATE function [dbo].[inLineMax] (@v1 float,@v2 float,@v3 float,@v4 float)\nreturns float\nas\nbegin\ndeclare @val float\nset @val = 0 \ndeclare @TableVal table\n(value float )\ninsert into @TableVal select @v1\ninsert into @TableVal select @v2\ninsert into @TableVal select @v3\ninsert into @TableVal select @v4\n\nselect @val= max(value) from @TableVal\n\nreturn @val\nend \n" }, { "answer_id": 37784473, "author": "claudio", "author_id": 6458642, "author_profile": "https://Stackoverflow.com/users/6458642", "pm_score": -1, "selected": false, "text": "MAXA(Value1;Value2;...)" }, { "answer_id": 49515362, "author": "M.A.Bell", "author_id": 8889436, "author_profile": "https://Stackoverflow.com/users/8889436", "pm_score": 0, "selected": false, "text": "SELECT CASE true \n WHEN max(row1) >= max(row2) THEN CASE true WHEN max(row1) >= max(row3) THEN max(row1) ELSE max(row3) end ELSE\n CASE true WHEN max(row2) >= max(row3) THEN max(row2) ELSE max(row3) END END\nFROM yourTable\n" }, { "answer_id": 54612018, "author": "Robert Lujo", "author_id": 565525, "author_profile": "https://Stackoverflow.com/users/565525", "pm_score": 1, "selected": false, "text": "SELECT\n CASE \n WHEN Date1 > coalesce(Date2,'0001-01-01') AND Date1 > coalesce(Date3,'0001-01-01') THEN Date1 \n WHEN Date2 > coalesce(Date3,'0001-01-01') THEN Date2 \n ELSE Date3\n END AS MostRecentDate\n , *\nfrom \n(values\n ( 1, cast('2001-01-01' as Date), cast('2002-01-01' as Date), cast('2003-01-01' as Date))\n ,( 2, cast('2001-01-01' as Date), cast('2003-01-01' as Date), cast('2002-01-01' as Date))\n ,( 3, cast('2002-01-01' as Date), cast('2001-01-01' as Date), cast('2003-01-01' as Date))\n ,( 4, cast('2002-01-01' as Date), cast('2003-01-01' as Date), cast('2001-01-01' as Date))\n ,( 5, cast('2003-01-01' as Date), cast('2001-01-01' as Date), cast('2002-01-01' as Date))\n ,( 6, cast('2003-01-01' as Date), cast('2002-01-01' as Date), cast('2001-01-01' as Date))\n ,( 11, cast(NULL as Date), cast('2002-01-01' as Date), cast('2003-01-01' as Date))\n ,( 12, cast(NULL as Date), cast('2003-01-01' as Date), cast('2002-01-01' as Date))\n ,( 13, cast('2003-01-01' as Date), cast(NULL as Date), cast('2002-01-01' as Date))\n ,( 14, cast('2002-01-01' as Date), cast(NULL as Date), cast('2003-01-01' as Date))\n ,( 15, cast('2003-01-01' as Date), cast('2002-01-01' as Date), cast(NULL as Date))\n ,( 16, cast('2002-01-01' as Date), cast('2003-01-01' as Date), cast(NULL as Date))\n ,( 21, cast('2003-01-01' as Date), cast(NULL as Date), cast(NULL as Date))\n ,( 22, cast(NULL as Date), cast('2003-01-01' as Date), cast(NULL as Date))\n ,( 23, cast(NULL as Date), cast(NULL as Date), cast('2003-01-01' as Date))\n ,( 31, cast(NULL as Date), cast(NULL as Date), cast(NULL as Date))\n\n) as demoValues(id, Date1,Date2,Date3)\norder by id\n;\n MostRecent id Date1 Date2 Date3\n2003-01-01 1 2001-01-01 2002-01-01 2003-01-01\n2003-01-01 2 2001-01-01 2003-01-01 2002-01-01\n2003-01-01 3 2002-01-01 2001-01-01 2002-01-01\n2003-01-01 4 2002-01-01 2003-01-01 2001-01-01\n2003-01-01 5 2003-01-01 2001-01-01 2002-01-01\n2003-01-01 6 2003-01-01 2002-01-01 2001-01-01\n2003-01-01 11 NULL 2002-01-01 2003-01-01\n2003-01-01 12 NULL 2003-01-01 2002-01-01\n2003-01-01 13 2003-01-01 NULL 2002-01-01\n2003-01-01 14 2002-01-01 NULL 2003-01-01\n2003-01-01 15 2003-01-01 2002-01-01 NULL\n2003-01-01 16 2002-01-01 2003-01-01 NULL\n2003-01-01 21 2003-01-01 NULL NULL\n2003-01-01 22 NULL 2003-01-01 NULL\n2003-01-01 23 NULL NULL 2003-01-01\nNULL 31 NULL NULL NULL\n" }, { "answer_id": 60684209, "author": "Brijesh Ray", "author_id": 5284448, "author_profile": "https://Stackoverflow.com/users/5284448", "pm_score": -1, "selected": false, "text": "select \n (select Max(salval) from( values (max(salary1)),(max(salary2)),(max(salary3)),(max(Salary4)))alias(salval)) as largest_val\n from EmployeeSalary\n select Max(salvalue) from(values (10001),(5098),(6070),(7500))alias(salvalue)\n" }, { "answer_id": 66815967, "author": "Hemendr", "author_id": 5139020, "author_profile": "https://Stackoverflow.com/users/5139020", "pm_score": 0, "selected": false, "text": "with x1 as\n(\n select 1 as N1, null as N2, 3 as N3\n union\n select 1 as N1, null as N2, null as N3\n union\n select null as N1, null as N2, null as N3\n)\n,x2 as\n(\nselect \nN1,N2,N3,\nIIF(Isnull(N1,0)>=Isnull(N2,0),N1,N2) as max1,\nIIF(Isnull(N2,0)>=Isnull(N3,0),N2,N3) as max2\nfrom x1\n)\n,x3 as\n(\n select N1,N2,N3,max1,max2,\n IIF(IsNull(max1,0)>=IsNull(max2,0),max1,max2) as MaxNo\n from x2\n)\nselect * from x3\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71022", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11703/" ]
71,030
<p>I'm aware I can add maven repositories for fetching dependencies in ~/.m2/settings.xml. But is it possible to add a repository using command line, something like:</p> <pre><code>mvn install -Dmaven.repository=http://example.com/maven2 </code></pre> <p>The reason I want to do this is because I'm using a continuous integration tool where I have full control over the command line options it uses to call maven, but managing the settings.xml for the user that runs the integration tool is a bit of a hassle.</p>
[ { "answer_id": 71132, "author": "Jorge Ferreira", "author_id": 6508, "author_profile": "https://Stackoverflow.com/users/6508", "pm_score": 3, "selected": false, "text": " <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n ...\n <repositories>\n <repository>\n <id>MavenCentral</id>\n <name>Maven repository</name>\n <url>http://repo1.maven.org/maven2</url>\n <releases>\n <enabled>true</enabled>\n </releases>\n <snapshots>\n <enabled>false</enabled>\n </snapshots>\n </repository>\n...\n <repository>\n <id>Codehaus Snapshots</id>\n <url>http://snapshots.repository.codehaus.org/</url>\n <snapshots>\n <enabled>true</enabled>\n </snapshots>\n <releases>\n <enabled>false</enabled>\n </releases>\n </repository>\n </repositories>\n\n ...\n\n <pluginRepositories>\n <pluginRepository>\n <id>apache.snapshots</id>\n <name>Apache Snapshot Repository</name>\n <url>\n http://people.apache.org/repo/m2-snapshot-repository\n </url>\n <releases>\n <enabled>false</enabled>\n </releases>\n </pluginRepository>\n <pluginRepository>\n <id>Codehaus Snapshots</id>\n <url>http://snapshots.repository.codehaus.org/</url>\n <snapshots>\n <enabled>true</enabled>\n </snapshots>\n <releases>\n <enabled>false</enabled>\n </releases>\n </pluginRepository>\n </pluginRepositories>\n\n ...\n\n </project>\n" }, { "answer_id": 95559, "author": "Eduard Wirch", "author_id": 17428, "author_profile": "https://Stackoverflow.com/users/17428", "pm_score": 2, "selected": false, "text": "mvn deploy -P MyRepo2\n\nmvn deploy -P MyRepo1\n" }, { "answer_id": 1193664, "author": "Rich Seller", "author_id": 123582, "author_profile": "https://Stackoverflow.com/users/123582", "pm_score": 7, "selected": true, "text": "mvn package -Dmaven.repo.remote=http://www.ibiblio.org/maven/,http://myrepo \n -Dmaven.repo.local=\"c:\\test\\repo\"\n" }, { "answer_id": 73148984, "author": "YGXXII", "author_id": 6102698, "author_profile": "https://Stackoverflow.com/users/6102698", "pm_score": 0, "selected": false, "text": "xmlstarlet XML_FULLPATH=\"$HOME/.m2/settings.xml\"\nMIRROR_ID='example'\nMIRROR_MIRROROF='*'\nMIRROR_NAME='Example Mirror'\nMIRROR_URL='http://example.com/maven2'\n\n\n## Preview settings without comment:\nxmlstarlet ed -d '//comment()' \"$XML_FULLPATH\"\n\n\n## Add Mirror settings:\nxmlstarlet ed -L \\\n --subnode \"/_:settings/_:mirrors\" --type elem --name \"mirrorTMP\" --value \"\" \\\n --subnode \"/_:settings/_:mirrors/mirrorTMP\" --type elem --name \"id\" --value \"$MIRROR_ID\" \\\n --subnode \"/_:settings/_:mirrors/mirrorTMP\" --type elem --name \"mirrorOf\" --value \"$MIRROR_MIRROROF\" \\\n --subnode \"/_:settings/_:mirrors/mirrorTMP\" --type elem --name \"name\" --value \"$MIRROR_NAME\" \\\n --subnode \"/_:settings/_:mirrors/mirrorTMP\" --type elem --name \"url\" --value \"$MIRROR_URL\" \\\n --rename \"/_:settings/_:mirrors/mirrorTMP\" --value \"mirror\" \\\n \"$XML_FULLPATH\"\n\n\n## Remove Mirror settings by id:\nxmlstarlet ed -L \\\n --delete \"/_:settings/_:mirrors/_:mirror[_:id=\\\"$MIRROR_ID\\\"]\" \\\n \"$XML_FULLPATH\"\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71030", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1113/" ]
71,069
<p>Maven spews out far too many lines of output to my taste (I like the Unix way: no news is good news).</p> <p>I want to get rid of all <code>[INFO]</code> lines, but I couldn't find any mention of an argument or config settings that controls the verbosity of Maven.</p> <p>Is there no LOG4J-like way to set the log level?</p>
[ { "answer_id": 71086, "author": "Jorge Ferreira", "author_id": 6508, "author_profile": "https://Stackoverflow.com/users/6508", "pm_score": 8, "selected": true, "text": "-q -q --quiet" }, { "answer_id": 40535065, "author": "Stanislav", "author_id": 2213164, "author_profile": "https://Stackoverflow.com/users/2213164", "pm_score": 5, "selected": false, "text": "-q -B --batch-mode" }, { "answer_id": 41002277, "author": "ankon", "author_id": 196315, "author_profile": "https://Stackoverflow.com/users/196315", "pm_score": 1, "selected": false, "text": "${MAVEN_HOME}/conf/logging/simplelogger.properties MAVEN_OPTS MAVEN_OPTS -Dorg.slf4j.simpleLogger.log.org.apache.maven.cl‌​i.transfer.Slf4jMave‌​nTransferListener=wa‌​rn -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" }, { "answer_id": 45345022, "author": "jgrtalk", "author_id": 8374743, "author_profile": "https://Stackoverflow.com/users/8374743", "pm_score": 5, "selected": false, "text": "-Dorg.slf4j.simpleLogger.defaultLogLevel=WARN\n" }, { "answer_id": 48989076, "author": "m13r", "author_id": 2249798, "author_profile": "https://Stackoverflow.com/users/2249798", "pm_score": 2, "selected": false, "text": "[INFO] mvn ... | fgrep -v \"[INFO]\"\n stdout /dev/null mvn ... 1>/dev/null\n bash" }, { "answer_id": 55963149, "author": "errant.info", "author_id": 496663, "author_profile": "https://Stackoverflow.com/users/496663", "pm_score": 1, "selected": false, "text": "--quiet Downloading: http://nexus:8081/nexus/content/groups/public/org/apache/maven/plugins/maven-compiler-plugin/maven-metadata.xml\n mvn clean install -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn\n" }, { "answer_id": 56118170, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 5, "selected": false, "text": "mvn --no-transfer-progress ....\n mvn -ntp ... ....\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71069", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7483/" ]
71,074
<p>I can make Firefox not display the ugly dotted focus outlines on <b>links</b> with this:</p> <pre class="lang-css prettyprint-override"><code>a:focus { outline: none; } </code></pre> <p>But how can I do this for <code>&lt;button&gt;</code> tags as well? When I do this:</p> <pre class="lang-css prettyprint-override"><code>button:focus { outline: none; } </code></pre> <p>the buttons still have the dotted focus outline when I click on them.</p> <p>(and yes, I know this is a usability issue, but I would like to provide my own focus hints which are appropriate to the design instead of ugly grey dots)</p>
[ { "answer_id": 71251, "author": "Vitaly Sharovatov", "author_id": 6647, "author_profile": "https://Stackoverflow.com/users/6647", "pm_score": 3, "selected": false, "text": "browser.display.focus_ring_width" }, { "answer_id": 71260, "author": "AlexWilson", "author_id": 2240, "author_profile": "https://Stackoverflow.com/users/2240", "pm_score": 2, "selected": false, "text": "browser.display.focus_ring_width = 0\n" }, { "answer_id": 199319, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 11, "selected": true, "text": "button::-moz-focus-inner {\n border: 0;\n}\n" }, { "answer_id": 857360, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "button::-moz-focus-inner {border: 2px solid transparent;}\n\nbutton:focus::-moz-focus-inner {border-color: blue} \n" }, { "answer_id": 1095624, "author": "Flatline", "author_id": 134628, "author_profile": "https://Stackoverflow.com/users/134628", "pm_score": 2, "selected": false, "text": ":focus blur() ::-moz-focus-inner" }, { "answer_id": 1622384, "author": "chinkchink", "author_id": 196344, "author_profile": "https://Stackoverflow.com/users/196344", "pm_score": 6, "selected": false, "text": "/*for FireFox*/\n input[type=\"submit\"]::-moz-focus-inner, input[type=\"button\"]::-moz-focus-inner\n { \n border : 0;\n } \n/*for IE8 and below */\n input[type=\"submit\"]:focus, input[type=\"button\"]:focus\n { \n outline : none; \n }\n" }, { "answer_id": 1750468, "author": "wavded", "author_id": 47158, "author_profile": "https://Stackoverflow.com/users/47158", "pm_score": 2, "selected": false, "text": "button::-moz-focus-inner { border: 0; }\n button" }, { "answer_id": 2021783, "author": "usual", "author_id": 245688, "author_profile": "https://Stackoverflow.com/users/245688", "pm_score": 0, "selected": false, "text": "button::-moz-focus-inner {border: 0px solid transparent;}" }, { "answer_id": 3129247, "author": "blizzyx", "author_id": 377621, "author_profile": "https://Stackoverflow.com/users/377621", "pm_score": 5, "selected": false, "text": ":focus, :active {\n outline: 0;\n border: 0;\n}\n" }, { "answer_id": 3844452, "author": "Anderson Custódio", "author_id": 464428, "author_profile": "https://Stackoverflow.com/users/464428", "pm_score": 8, "selected": false, "text": ":focus {outline:none;}\n::-moz-focus-inner {border:0;}\n" }, { "answer_id": 6635075, "author": "Dave Everitt", "author_id": 123033, "author_profile": "https://Stackoverflow.com/users/123033", "pm_score": 2, "selected": false, "text": ".button::-moz-focus-inner {\n border-color: transparent;\n}\n" }, { "answer_id": 7628310, "author": "foxybagga", "author_id": 95350, "author_profile": "https://Stackoverflow.com/users/95350", "pm_score": 5, "selected": false, "text": "a, a:visited, a:focus, a:active, a:hover{\n outline:0 none !important;\n}\n" }, { "answer_id": 15608143, "author": "Shannon Hochkins", "author_id": 1683943, "author_profile": "https://Stackoverflow.com/users/1683943", "pm_score": 3, "selected": false, "text": "::-moz-focus-inner, :active, :focus {\n outline:none;\n border:0;\n -moz-outline-style: none;\n}\n" }, { "answer_id": 18993053, "author": "Renato Carvalho", "author_id": 925560, "author_profile": "https://Stackoverflow.com/users/925560", "pm_score": 3, "selected": false, "text": "a:focus, a:active, \nbutton::-moz-focus-inner,\ninput[type=\"reset\"]::-moz-focus-inner,\ninput[type=\"button\"]::-moz-focus-inner,\ninput[type=\"submit\"]::-moz-focus-inner,\nselect::-moz-focus-inner,\ninput[type=\"file\"] > input[type=\"button\"]::-moz-focus-inner {\n border: 0;\n outline : 0;\n}\n" }, { "answer_id": 20731378, "author": "Fizer Khan", "author_id": 1154350, "author_profile": "https://Stackoverflow.com/users/1154350", "pm_score": 2, "selected": false, "text": "a:focus, a:active,\nbutton::-moz-focus-inner,\ninput[type=\"reset\"]::-moz-focus-inner,\ninput[type=\"button\"]::-moz-focus-inner,\ninput[type=\"submit\"]::-moz-focus-inner {\n border: 0;\n outline : 0;\n}\n" }, { "answer_id": 20833484, "author": "DPP", "author_id": 1766855, "author_profile": "https://Stackoverflow.com/users/1766855", "pm_score": 1, "selected": false, "text": " .buttonClassName:focus {\n outline:none;\n}\n" }, { "answer_id": 24791473, "author": "Vartox", "author_id": 2366511, "author_profile": "https://Stackoverflow.com/users/2366511", "pm_score": 3, "selected": false, "text": "button:focus {outline:0 !important;}\n" }, { "answer_id": 31893576, "author": "herci", "author_id": 3294466, "author_profile": "https://Stackoverflow.com/users/3294466", "pm_score": 2, "selected": false, "text": "!important !important a, a:active, a:focus{\n outline: none !important; /* Works in Firefox, Chrome, IE8 and above */\n}\n button::-moz-focus-inner {\n border: 0 !important;\n}\n" }, { "answer_id": 36897437, "author": "Madan Sapkota", "author_id": 782535, "author_profile": "https://Stackoverflow.com/users/782535", "pm_score": 3, "selected": false, "text": "input:focus, textarea:focus, button:focus {\n outline: none !important;\n}\n input[type=text] {\n outline: none !important;\n}\n" }, { "answer_id": 37482092, "author": "Syed Waqas Bukhary", "author_id": 3633267, "author_profile": "https://Stackoverflow.com/users/3633267", "pm_score": 1, "selected": false, "text": "*:focus, *:visited, *:active, *:hover { outline:0 !important;}\n*::-moz-focus-inner {border:0;}\n" }, { "answer_id": 37717454, "author": "Ehsan88", "author_id": 2571422, "author_profile": "https://Stackoverflow.com/users/2571422", "pm_score": 1, "selected": false, "text": "button::-moz-focus-inner {\n border: 0; /*removes dotted lines around buttons*/\n}\n\n.btn.active.focus, .btn.active:focus, .btn.focus, .btn.focus:active, .btn:active:focus, .btn:focus{\n outline:0;\n}\n" }, { "answer_id": 38766296, "author": "kurumkan", "author_id": 5714544, "author_profile": "https://Stackoverflow.com/users/5714544", "pm_score": 2, "selected": false, "text": "a:focus, a:active, \nbutton::-moz-focus-inner,\ninput[type=\"reset\"]::-moz-focus-inner,\ninput[type=\"button\"]::-moz-focus-inner,\ninput[type=\"submit\"]::-moz-focus-inner,\nselect::-moz-focus-inner,\ninput[type=\"file\"] > input[type=\"button\"]::-moz-focus-inner {\n border: 0;\n outline : 0;\n}\n" }, { "answer_id": 41631535, "author": "Abhay Singh", "author_id": 2063930, "author_profile": "https://Stackoverflow.com/users/2063930", "pm_score": 3, "selected": false, "text": "select:-moz-focusring {\n color: transparent;\n text-shadow: 0 0 0 #000;\n}\n" }, { "answer_id": 47195132, "author": "bob", "author_id": 1088866, "author_profile": "https://Stackoverflow.com/users/1088866", "pm_score": 3, "selected": false, "text": ":focus {\n outline:none;\n}\n::-moz-focus-inner {\n border:0;\n}\ninput[type=range]::-moz-focus-outer {\n border: 0;\n}\n" }, { "answer_id": 55434025, "author": "Riwaj Chalise", "author_id": 10003098, "author_profile": "https://Stackoverflow.com/users/10003098", "pm_score": 1, "selected": false, "text": "button::-moz-focus-inner {\n border: 0 !important;\n}\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71074", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4639/" ]
71,077
<p>I want to compress some files (into the <a href="http://en.wikipedia.org/wiki/ZIP_%28file_format%29" rel="nofollow noreferrer">ZIP</a> format) and encrypt them if possible using C#. Is there some way to do this?</p> <p>Can encryption be done as a part of the compression itself?</p>
[ { "answer_id": 71099, "author": "Skizz", "author_id": 1898, "author_profile": "https://Stackoverflow.com/users/1898", "pm_score": 5, "selected": true, "text": "System.IO.Compression System.Security.Cryptography" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71077", "https://Stackoverflow.com", "https://Stackoverflow.com/users/184/" ]
71,108
<p>Under what circumstances might you want to use multiple indirection (that is, a chain of pointers as in <code>Foo **</code>) in C++?</p>
[ { "answer_id": 71143, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 3, "selected": false, "text": "void test(int ** var)\n{\n ...\n}\n\nint *foo = ...\ntest(&foo);\n int ** array = new *int[2];\narray[0] = new int[2];\narray[1] = new int[3];\n" }, { "answer_id": 71154, "author": "Carl Seleborg", "author_id": 2095, "author_profile": "https://Stackoverflow.com/users/2095", "pm_score": 2, "selected": false, "text": "Foo** *ppFoo = pSomeOtherFoo" }, { "answer_id": 71160, "author": "dudico", "author_id": 11089, "author_profile": "https://Stackoverflow.com/users/11089", "pm_score": 1, "selected": false, "text": "int** foo_mat void* foo void** foo_pointer1 void** foo_pointer2 *foo_pointer1 == NULL" }, { "answer_id": 71164, "author": "Skizz", "author_id": 1898, "author_profile": "https://Stackoverflow.com/users/1898", "pm_score": 1, "selected": false, "text": "ErrorCode AllocateObject (void **object);\n *object = new Object;\n" }, { "answer_id": 71175, "author": "0124816", "author_id": 11521, "author_profile": "https://Stackoverflow.com/users/11521", "pm_score": 1, "selected": false, "text": "*p = x;\n" }, { "answer_id": 71250, "author": "John B", "author_id": 11773, "author_profile": "https://Stackoverflow.com/users/11773", "pm_score": 3, "selected": false, "text": "initialize(foo* my_foo)\n{\n my_foo = new Foo();\n}\n initialize(foo** my_foo)\n{\n *my_foo = new Foo();\n}\n Foo* my_foo;\n\ninitialize(&my_foo);\n" }, { "answer_id": 71298, "author": "Jorge Ferreira", "author_id": 6508, "author_profile": "https://Stackoverflow.com/users/6508", "pm_score": 5, "selected": true, "text": "#include <iostream>\n\nusing namespace std;\n\nstruct Foo {\n int a;\n};\n\nvoid CreateFoo(Foo** p) {\n *p = new Foo();\n (*p)->a = 12;\n}\n\nint main(int argc, char* argv[])\n{\n Foo* p = NULL;\n CreateFoo(&p);\n cout << p->a << endl;\n delete p;\n return 0;\n}\n 12\n #include <iostream>\n\nusing namespace std;\n\nint main(int argc, char* argv[])\n{\n const char* words[] = { \"first\", \"second\", NULL };\n for (const char** p = words; *p != NULL; ++p) {\n cout << *p << endl;\n }\n\n return 0;\n}\n" }, { "answer_id": 73382, "author": "mlbrock", "author_id": 9966, "author_profile": "https://Stackoverflow.com/users/9966", "pm_score": 1, "selected": false, "text": "int AddStringToList(unsigned int *count_ptr, char ***list_ptr, const char *string_to_add);\n unsigned int the_count = 0;\nchar **the_list = NULL;\n\nAddStringToList(&the_count, &the_list, \"The string I'm adding\");\n int AddStringToList(unsigned int &count_ptr, char **&list_ptr, const char *string_to_add);\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71108", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11575/" ]
71,151
<p>Using the Python Documentation I found the <a href="http://docs.python.org/lib/module-HTMLParser.html" rel="noreferrer">HTML parser</a> but I have no idea which library to import to use it, how do I find this out (bearing in mind it doesn't say on the page).</p>
[ { "answer_id": 71161, "author": "1077", "author_id": 10776, "author_profile": "https://Stackoverflow.com/users/10776", "pm_score": 5, "selected": true, "text": "import HTMLParser\n import html.parser\n import HTMLParser\n" }, { "answer_id": 71174, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 5, "selected": false, "text": ">>> import HTMLParser\n>>> h = HTMLParser.HTMLParser()\n>>> h.feed('<html></html>')\n>>> h.get_starttag_text()\n'<html>'\n>>> h.close()\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71151", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1384652/" ]
71,180
<p>How can I find the last row that contains data in a specific column and on a specific sheet?</p>
[ { "answer_id": 71197, "author": "Galwegian", "author_id": 3201, "author_profile": "https://Stackoverflow.com/users/3201", "pm_score": -1, "selected": false, "text": "Function LastRow(rng As Range) As Long\n Dim iRowN As Long\n Dim iRowI As Long\n Dim iColN As Integer\n Dim iColI As Integer\n iRowN = 0\n iColN = rng.Columns.count\n For iColI = 1 To iColN\n iRowI = rng.Columns(iColI).Offset(65536 - rng.Row, 0).End(xlUp).Row\n If iRowI > iRowN Then iRowN = iRowI\n Next\n LastRow = iRowN\nEnd Function \n" }, { "answer_id": 71296, "author": "GSerg", "author_id": 11683, "author_profile": "https://Stackoverflow.com/users/11683", "pm_score": 3, "selected": false, "text": "function LastRowIndex(byval w as worksheet, byval col as variant) as long\n dim r as range\n\n set r = application.intersect(w.usedrange, w.columns(col))\n if not r is nothing then\n set r = r.cells(r.cells.count)\n\n if isempty(r.value) then\n LastRowIndex = r.end(xlup).row\n else\n LastRowIndex = r.row\n end if\n end if\nend function\n ? LastRowIndex(ActiveSheet, 5)\n? LastRowIndex(ActiveSheet, \"AI\")\n" }, { "answer_id": 71310, "author": "Fionnuala", "author_id": 2548, "author_profile": "https://Stackoverflow.com/users/2548", "pm_score": 7, "selected": true, "text": "Function GetLastRow(strSheet, strColumn) As Long\n Dim MyRange As Range\n\n Set MyRange = Worksheets(strSheet).Range(strColumn & \"1\")\n GetLastRow = Cells(Rows.Count, MyRange.Column).End(xlUp).Row\nEnd Function\n Cells.Find(\"*\", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row\n" }, { "answer_id": 71349, "author": "databyss", "author_id": 9094, "author_profile": "https://Stackoverflow.com/users/9094", "pm_score": -1, "selected": false, "text": "Selection.End(xlDown).Select\nMsgBox(ActiveCell.Row)\n" }, { "answer_id": 73489, "author": "Jon Fournier", "author_id": 5106, "author_profile": "https://Stackoverflow.com/users/5106", "pm_score": 4, "selected": false, "text": ".End(xlup) sheetvar.Rows.Count\n" }, { "answer_id": 74282, "author": "Dick Kusleika", "author_id": 4280, "author_profile": "https://Stackoverflow.com/users/4280", "pm_score": 2, "selected": false, "text": "Public Function LastData(rCol As Range) As Range \n Set LastData = rCol.Find(\"*\", rCol.Cells(1), , , , xlPrevious) \nEnd Function\n ?lastdata(activecell.EntireColumn).Address" }, { "answer_id": 962530, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "Sub Macro1\n Sheets(\"Sheet1\").Select\n MsgBox \"The last row found is: \" & Last(1, ActiveSheet.Cells)\n MsgBox \"The last column (R1C1) found is: \" & Last(2, ActiveSheet.Cells)\n MsgBox \"The last cell found is: \" & Last(3, ActiveSheet.Cells)\n MsgBox \"The last column (A1) found is: \" & Last(4, ActiveSheet.Cells)\nEnd Sub\n\nFunction Last(choice As Integer, rng As Range)\n' 1 = last row\n' 2 = last column (R1C1)\n' 3 = last cell\n' 4 = last column (A1)\n Dim lrw As Long\n Dim lcol As Integer\n\n Select Case choice\n Case 1:\n On Error Resume Next\n Last = rng.Find(What:=\"*\", _\n After:=rng.Cells(1), _\n LookAt:=xlPart, _\n LookIn:=xlFormulas, _\n SearchOrder:=xlByRows, _\n SearchDirection:=xlPrevious, _\n MatchCase:=False).Row\n On Error GoTo 0\n\n Case 2:\n On Error Resume Next\n Last = rng.Find(What:=\"*\", _\n After:=rng.Cells(1), _\n LookAt:=xlPart, _\n LookIn:=xlFormulas, _\n SearchOrder:=xlByColumns, _\n SearchDirection:=xlPrevious, _\n MatchCase:=False).Column\n On Error GoTo 0\n\n Case 3:\n On Error Resume Next\n lrw = rng.Find(What:=\"*\", _\n After:=rng.Cells(1), _\n LookAt:=xlPart, _\n LookIn:=xlFormulas, _\n SearchOrder:=xlByRows, _\n SearchDirection:=xlPrevious, _\n MatchCase:=False).Row\n lcol = rng.Find(What:=\"*\", _\n After:=rng.Cells(1), _\n LookAt:=xlPart, _\n LookIn:=xlFormulas, _\n SearchOrder:=xlByColumns, _\n SearchDirection:=xlPrevious, _\n MatchCase:=False).Column\n Last = Cells(lrw, lcol).Address(False, False)\n If Err.Number > 0 Then\n Last = rng.Cells(1).Address(False, False)\n Err.Clear\n End If\n On Error GoTo 0\n Case 4:\n On Error Resume Next\n Last = rng.Find(What:=\"*\", _\n After:=rng.Cells(1), _\n LookAt:=xlPart, _\n LookIn:=xlFormulas, _\n SearchOrder:=xlByColumns, _\n SearchDirection:=xlPrevious, _\n MatchCase:=False).Column\n On Error GoTo 0\n Last = R1C1converter(\"R1C\" & Last, 1)\n For i = 1 To Len(Last)\n s = Mid(Last, i, 1)\n If Not s Like \"#\" Then s1 = s1 & s\n Next i\n Last = s1\n\n End Select\n\nEnd Function\n\nFunction R1C1converter(Address As String, Optional R1C1_output As Integer, Optional RefCell As Range) As String\n 'Converts input address to either A1 or R1C1 style reference relative to RefCell\n 'If R1C1_output is xlR1C1, then result is R1C1 style reference.\n 'If R1C1_output is xlA1 (or missing), then return A1 style reference.\n 'If RefCell is missing, then the address is relative to the active cell\n 'If there is an error in conversion, the function returns the input Address string\n Dim x As Variant\n If RefCell Is Nothing Then Set RefCell = ActiveCell\n If R1C1_output = xlR1C1 Then\n x = Application.ConvertFormula(Address, xlA1, xlR1C1, , RefCell) 'Convert A1 to R1C1\n Else\n x = Application.ConvertFormula(Address, xlR1C1, xlA1, , RefCell) 'Convert R1C1 to A1\n End If\n If IsError(x) Then\n R1C1converter = Address\n Else\n 'If input address is A1 reference and A1 is requested output, then Application.ConvertFormula\n 'surrounds the address in single quotes.\n If Right(x, 1) = \"'\" Then\n R1C1converter = Mid(x, 2, Len(x) - 2)\n Else\n x = Application.Substitute(x, \"$\", \"\")\n R1C1converter = x\n End If\n End If\nEnd Function\n" }, { "answer_id": 25509398, "author": "user2988717", "author_id": 2988717, "author_profile": "https://Stackoverflow.com/users/2988717", "pm_score": 3, "selected": false, "text": "Dim lastRow as long\nRange(\"A1\").select\nlastRow = Cells.Find(\"*\",SearchOrder:=xlByRows,SearchDirection:=xlPrevious).Row\n cells(lastRow,1)=\"Ultima Linha, Last Row. Youpi!!!!\"\n\n'or \n\nRange(\"A\" & lastRow).Value = \"FIM, THE END\"\n" }, { "answer_id": 33434570, "author": "Ashwith Ullal", "author_id": 1534035, "author_profile": "https://Stackoverflow.com/users/1534035", "pm_score": -1, "selected": false, "text": "Sub test()\n MsgBox Worksheets(\"sheet_name\").Range(\"A65536\").End(xlUp).Row\nEnd Sub\n A \"A65536\"" }, { "answer_id": 35975280, "author": "Stupid_Intern", "author_id": 5398127, "author_profile": "https://Stackoverflow.com/users/5398127", "pm_score": 0, "selected": false, "text": "UsedRange lastRow = Sheet1.UsedRange.Row + Sheet1.UsedRange.Rows.Count - 1\n ?Sheet1.UsedRange.Row+Sheet1.UsedRange.Rows.Count-1\n 21 \n" }, { "answer_id": 46419169, "author": "Phaithoon Jariyanantakul", "author_id": 8674380, "author_profile": "https://Stackoverflow.com/users/8674380", "pm_score": 0, "selected": false, "text": "Public Function GetLastRow(ByVal SheetName As String) As Integer\n Dim sht As Worksheet\n Dim FirstUsedRow As Integer 'the first row of UsedRange\n Dim UsedRows As Integer ' number of rows used\n\n Set sht = Sheets(SheetName)\n ''UsedRange.Rows.Count for the empty sheet is 1\n UsedRows = sht.UsedRange.Rows.Count\n FirstUsedRow = sht.UsedRange.Row\n GetLastRow = FirstUsedRow + UsedRows - 1\n\n Set sht = Nothing\nEnd Function\n" }, { "answer_id": 49971492, "author": "Nickolay", "author_id": 1026, "author_profile": "https://Stackoverflow.com/users/1026", "pm_score": 2, "selected": false, "text": ".Find .End Worksheet_Change UsedRange UsedRange ' Returns the 1-based row number of the last row having a non-empty value in the given column (0 if the whole column is empty)\nPrivate Function getLastNonblankRowInColumn(ws As Worksheet, colNo As Integer) As Long\n ' Force Excel to recalculate the \"last cell\" (the one you land on after CTRL+END) / \"used range\"\n ' and get the index of the row containing the \"last cell\". This is reasonably fast (~1 ms/10000 rows of a used range)\n Dim lastRow As Long: lastRow = ws.UsedRange.Rows(ws.UsedRange.Rows.Count).Row - 1 ' 0-based\n\n ' Since the \"last cell\" is not necessarily the one we're looking for (it may be in a different column, have some\n ' formatting applied but no value, etc), we loop backward from the last row towards the top of the sheet).\n Dim wholeRng As Range: Set wholeRng = ws.Columns(colNo)\n\n ' Since accessing cells one by one is slower than reading a block of cells into a VBA array and looping through the array,\n ' we process in chunks of increasing size, starting with 1 cell and doubling the size on each iteration, until MAX_CHUNK_SIZE is reached.\n ' In pathological cases where Excel thinks all the ~1M rows are in the used range, this will take around 100ms.\n ' Yet in a normal case where one of the few last rows contains the cell we're looking for, we don't read too many cells.\n Const MAX_CHUNK_SIZE = 2 ^ 10 ' (using large chunks gives no performance advantage, but uses more memory)\n Dim chunkSize As Long: chunkSize = 1\n Dim startOffset As Long: startOffset = lastRow + 1 ' 0-based\n Do ' Loop invariant: startOffset>=0 and all rows after startOffset are blank (i.e. wholeRng.Rows(i+1) for i>=startOffset)\n startOffset = IIf(startOffset - chunkSize >= 0, startOffset - chunkSize, 0)\n ' Fill `vals(1 To chunkSize, 1 To 1)` with column's rows indexed `[startOffset+1 .. startOffset+chunkSize]` (1-based, inclusive)\n Dim chunkRng As Range: Set chunkRng = wholeRng.Resize(chunkSize).Offset(startOffset)\n Dim vals() As Variant\n If chunkSize > 1 Then\n vals = chunkRng.Value2\n Else ' reading a 1-cell range requires special handling <http://www.cpearson.com/excel/ArraysAndRanges.aspx>\n ReDim vals(1 To 1, 1 To 1)\n vals(1, 1) = chunkRng.Value2\n End If\n\n Dim i As Long\n For i = UBound(vals, 1) To LBound(vals, 1) Step -1\n If Not IsEmpty(vals(i, 1)) Then\n getLastNonblankRowInColumn = startOffset + i\n Exit Function\n End If\n Next i\n\n If chunkSize < MAX_CHUNK_SIZE Then chunkSize = chunkSize * 2\n Loop While startOffset > 0\n\n getLastNonblankRowInColumn = 0\nEnd Function\n" }, { "answer_id": 55383256, "author": "Sumit Pokhrel", "author_id": 2690723, "author_profile": "https://Stackoverflow.com/users/2690723", "pm_score": 0, "selected": false, "text": "Last_Row = Range(\"A1\").End(xlDown).Row\n Range(\"C1\").Select\nLast_Row = Range(\"A1\").End(xlDown).Row\nActiveCell.FormulaR1C1 = Last_Row\n" }, { "answer_id": 71204877, "author": "Potocpe1", "author_id": 8867339, "author_profile": "https://Stackoverflow.com/users/8867339", "pm_score": 0, "selected": false, "text": "Function getLastRow(col As String, ws As Worksheet) As Long\n Dim lastNonEmptyRow As Long\n lastNonEmptyRow = 1\n Dim lastEmptyRow As Long\n\n lastEmptyRow = ws.Rows.Count + 1\n Dim nextTestedRow As Long\n \n Do While (lastEmptyRow - lastNonEmptyRow > 1)\n nextTestedRow = Application.WorksheetFunction.Ceiling _\n (lastNonEmptyRow + (lastEmptyRow - lastNonEmptyRow) / 2, 1)\n If (IsEmpty(ws.Range(col & nextTestedRow))) Then\n lastEmptyRow = nextTestedRow\n Else\n lastNonEmptyRow = nextTestedRow\n End If\n Loop\n \n getLastRow = lastNonEmptyRow\n \n\nEnd Function\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71180", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8418/" ]
71,201
<p>I'm developing a web service whose methods will be called from a "dynamic banner" that will show a sort of queue of messages read from a sql server table.</p> <p>The banner will have a heavy pressure in the home pages of high traffic sites; every time the banner will be loaded, it will call my web service, in order to obtain the new queue of messages.</p> <p>Now: I don't want that all this traffic drives queries to the database every time the banner is loaded, so I'm thinking to use the asp.net cache (i.e. HttpRuntime.Cache[cacheKey]) to limit database accesses; I will try to have a cache refresh every minute or so.</p> <p>Obviously I'll try have the messages as little as possible, to limit traffic.</p> <p>But maybe there are other ways to deal with such a scenario; for example I could write the last version of the queue on the file system, and have the web service access that file; or something mixing the two approaches...</p> <p>The solution is c# web service, asp.net 3.5, sql server 2000. </p> <p>Any hint? Other approaches? </p> <p>Thanks</p> <p>Andrea</p>
[ { "answer_id": 404798, "author": "Sklivvz", "author_id": 7028, "author_profile": "https://Stackoverflow.com/users/7028", "pm_score": 0, "selected": false, "text": " [Cached]\n public class MyTime : ContextBoundObject\n {\n [CachedMethod(1)]\n public DateTime Get()\n {\n Console.WriteLine(\"Get invoked.\");\n return DateTime.Now;\n }\n }\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71201", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1178/" ]
71,223
<p>I'm currently writing a TYPO3 extension which is configured with a list of <code>tt_content</code> UID's. These point to content elements of type "text" and i want to render them by my extension.</p> <p>Because of TYPO3s special way of transforming the text you enter in the rich text editing when it enters the database, and again transforming it when it is rendered to the frontend, i can not just output the database contents of the <code>bodytext</code> field.</p> <p>I want to render these texts as they would usually get rendered by TYPO3. How do I do that? </p>
[ { "answer_id": 71272, "author": "Jan Hančič", "author_id": 185527, "author_profile": "https://Stackoverflow.com/users/185527", "pm_score": 4, "selected": true, "text": "$output .= $this->pi_RTEcssText( $contentFromDb );" }, { "answer_id": 2592788, "author": "cweiske", "author_id": 282601, "author_profile": "https://Stackoverflow.com/users/282601", "pm_score": 3, "selected": false, "text": "function getCE($id)\n{\n $conf['tables'] = 'tt_content';\n $conf['source'] = $id;\n $conf['dontCheckPid'] = 1;\n return $GLOBALS['TSFE']->cObj->cObjGetSingle('RECORDS', $conf);\n}\n <!--INT_SCRIPT.0f1c1787dc3f62e40f944b93a2ad6a81--> content.render <v:content.render contentUids=\"{0: textelementid}\"/>\n content.get content.render <f:section name=\"Configuration>\n ... <flux:grid.column name=\"teaser\"/> ...\n</f:section>\n<f:section name=\"Main>\n <flux:content.render area=\"teaser\"/>\n<f:section>\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71223", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4186/" ]
71,226
<p>I am using a .NET Windows Forms DataGridView and I need to edit a DataBound column (that binds on a boolean DataTable column). For this I specify the cell template like this:</p> <p>DataGridViewColumn column = new DataGridViewColumn(new DataGridViewCheckBoxCell());</p> <p>You see that I need a CheckBox cell template.</p> <p>The problem I face is that this column is constantly readonly/disabled, as if it would be of TextBox type. It doesn't show a checkbox at all.</p> <p>Any thoughts on how to work with editable checkbox columns for DataGridView?</p> <p>Update: For windows forms, please.</p> <p>Thanks.</p>
[ { "answer_id": 71252, "author": "Biri", "author_id": 968, "author_profile": "https://Stackoverflow.com/users/968", "pm_score": 0, "selected": false, "text": "<asp:TemplateField HeaderText=\"Whatever\" SortExpression=\"fieldname\" ItemStyle-HorizontalAlign=\"Center\">\n <ItemTemplate>\n <asp:CheckBox runat=\"server\" ID=\"rowCheck\" key='<%# Eval(\"id\") %>' />\n </ItemTemplate>\n</asp:TemplateField>\n" }, { "answer_id": 81252, "author": "Vasile Tomoiaga", "author_id": 2130892, "author_profile": "https://Stackoverflow.com/users/2130892", "pm_score": 3, "selected": false, "text": "richDataGrid.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells;" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71226", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2130892/" ]
71,248
<p>I would like to debug an embedded system containing gdb remotely using some kind of gui (ie like ddd). The embedded system does not have the sources or build symbols. However my local x windows box has. However the execution must happen on the embedded system. How can I from my development box drive gdb remotely with some gui ? </p> <p>leds and jtag are not an option. </p>
[ { "answer_id": 4675868, "author": "FractalSpace", "author_id": 175169, "author_profile": "https://Stackoverflow.com/users/175169", "pm_score": 2, "selected": false, "text": "target> gdbserver localhost:1234 <application>\n host> gdb <application>\n gdb> set <path-to-libs-search>\ngdb> target remote <target-ip>:1234\ngdb> break main\ngdb> cont\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71248", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
71,254
<p>When viewing someone else's webpage containing an applet, how can I force Internet Explorer 6.0 to use a a particular JRE when I have several installed?</p>
[ { "answer_id": 71329, "author": "BrezzaP", "author_id": 11766, "author_profile": "https://Stackoverflow.com/users/11766", "pm_score": 2, "selected": false, "text": "<OBJECT \n classid=\"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93\"\n width=\"200\" height=\"200\">\n <PARAM name=\"code\" value=\"Applet1.class\">\n</OBJECT>\n classid=\"clsid:CAFEEFAC-xxxx-yyyy-zzzz-ABCDEFFEDCBA\"\n classid=\"clsid:CAFEEFAC-0015-0000-0000-ABCDEFFEDCBA\"\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71254", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
71,257
<p>How do I suspend a whole process (like the Process Explorer does when I click Suspend) in C#.</p> <p>I'm starting the Process with Process.Start, and on a certain event, I want to suspend the process to be able to do some investigation on a "snapshot" of it.</p>
[ { "answer_id": 71457, "author": "Magnus Johansson", "author_id": 3584, "author_profile": "https://Stackoverflow.com/users/3584", "pm_score": 6, "selected": true, "text": " [Flags]\n public enum ThreadAccess : int\n {\n TERMINATE = (0x0001),\n SUSPEND_RESUME = (0x0002),\n GET_CONTEXT = (0x0008),\n SET_CONTEXT = (0x0010),\n SET_INFORMATION = (0x0020),\n QUERY_INFORMATION = (0x0040),\n SET_THREAD_TOKEN = (0x0080),\n IMPERSONATE = (0x0100),\n DIRECT_IMPERSONATION = (0x0200)\n }\n\n [DllImport(\"kernel32.dll\")]\n static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);\n [DllImport(\"kernel32.dll\")]\n static extern uint SuspendThread(IntPtr hThread);\n [DllImport(\"kernel32.dll\")]\n static extern int ResumeThread(IntPtr hThread);\n [DllImport(\"kernel32\", CharSet = CharSet.Auto,SetLastError = true)]\n static extern bool CloseHandle(IntPtr handle);\n\n\nprivate static void SuspendProcess(int pid)\n{\n var process = Process.GetProcessById(pid); // throws exception if process does not exist\n\n foreach (ProcessThread pT in process.Threads)\n {\n IntPtr pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id);\n\n if (pOpenThread == IntPtr.Zero)\n {\n continue;\n }\n\n SuspendThread(pOpenThread);\n\n CloseHandle(pOpenThread);\n }\n}\n\npublic static void ResumeProcess(int pid)\n{\n var process = Process.GetProcessById(pid);\n\n if (process.ProcessName == string.Empty)\n return;\n\n foreach (ProcessThread pT in process.Threads)\n {\n IntPtr pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id);\n\n if (pOpenThread == IntPtr.Zero)\n {\n continue;\n }\n\n var suspendCount = 0;\n do\n {\n suspendCount = ResumeThread(pOpenThread);\n } while (suspendCount > 0);\n\n CloseHandle(pOpenThread);\n }\n}\n" }, { "answer_id": 13109774, "author": "Sarath", "author_id": 353241, "author_profile": "https://Stackoverflow.com/users/353241", "pm_score": 4, "selected": false, "text": "var process = Process.GetProcessById(param.PId);\nprocess.Suspend();\n public static class ProcessExtension\n{\n [DllImport(\"kernel32.dll\")]\n static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);\n [DllImport(\"kernel32.dll\")]\n static extern uint SuspendThread(IntPtr hThread);\n [DllImport(\"kernel32.dll\")]\n static extern int ResumeThread(IntPtr hThread);\n\n public static void Suspend(this Process process)\n {\n foreach (ProcessThread thread in process.Threads)\n {\n var pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)thread.Id);\n if (pOpenThread == IntPtr.Zero)\n {\n break;\n }\n SuspendThread(pOpenThread);\n }\n }\n public static void Resume(this Process process)\n {\n foreach (ProcessThread thread in process.Threads)\n {\n var pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)thread.Id);\n if (pOpenThread == IntPtr.Zero)\n {\n break;\n }\n ResumeThread(pOpenThread);\n }\n }\n}\n" }, { "answer_id": 61282905, "author": "gerrard", "author_id": 13148843, "author_profile": "https://Stackoverflow.com/users/13148843", "pm_score": 1, "selected": false, "text": "[DllImport(\"ntdll.dll\", PreserveSig = false)]\n public static extern void NtSuspendProcess(IntPtr processHandle);\n static IntPtr handle;\n\n string p = \"\";\n foreach (Process item in Process.GetProcesses())\n {\n if (item.ProcessName == \"GammaVPN\")\n {\n p = item.ProcessName;\n handle = item.Handle;\n NtSuspendProcess(handle);\n }\n }\n Console.WriteLine(p);\n Console.WriteLine(\"done\");\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71257", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9632/" ]
71,273
<p>Working with software day-to-day usually means you have to juggle project work, meetings, calls and other interrupts.</p> <p>What single technique, trick, or tool do you find most useful in managing your time?</p> <p>How do you stay focused?</p> <p>What is your single biggest distraction from your work?</p>
[ { "answer_id": 71443, "author": "Johan", "author_id": 11347, "author_profile": "https://Stackoverflow.com/users/11347", "pm_score": 2, "selected": false, "text": "C:\\windows\\system32\\cmd.exe /C \"start /B msg jpretori /W /V \"15-minute check\"\"" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71273", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11613/" ]
71,306
<p>The single timing column in the weblog naturally includes client transmission timing. For anamoly analysis, I want to differentiate pages that took excessive construction time from requests that simply had a slow client.</p> <p>For buffered pages, I've looked at the ASP.NET page lifecycle model and do not see where I can tap in and codewise measure just the page-processing time before the page is flushed to the client.</p> <p>I probably should have mentioned that my goal is production monitoring (not test or dev). In addition, the intent is to annotate the weblogs with this measurement for later analysis. Current we liberally annotate the weblogs with Response.AppendToLog(). I believe the desire to use Response.AppendToLog() somewhat limits my potential logpoints as for instance, the response-object is not viable in Application_EndRequest.</p> <p>Any insight would be appreciated.</p>
[ { "answer_id": 71632, "author": "Timothy Khouri", "author_id": 11917, "author_profile": "https://Stackoverflow.com/users/11917", "pm_score": 2, "selected": false, "text": "<%=DateTime.Now.Subtract(HttpContext.Current.Timestamp).TotalSeconds %>" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71306", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11791/" ]
71,309
<p>for example this code</p> <pre><code>var html = "&lt;p&gt;This text is &lt;a href=#&gt; good&lt;/a&gt;&lt;/p&gt;"; var newNode = Builder.node('div',{className: 'test'},[html]); $('placeholder').update(newNode); </code></pre> <p>casues the p and a tags to be shown, how do I prevent them from being escaped?</p>
[ { "answer_id": 71371, "author": "Leo Lännenmäki", "author_id": 2451, "author_profile": "https://Stackoverflow.com/users/2451", "pm_score": 3, "selected": true, "text": "var a = Builder.node('div').update(\"<a href='#'>foo</a>\")\n var a = Builder.node('div', {'class':'cool'}, \n [Builder.node('div', {'class': 'another_div'})]\n );\n var a = new Element('div').insert(\n new Element('div', {'class': 'inner_div'}).update(\"Text in the inner div\")\n );\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71309", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6892/" ]
71,323
<p>I'm trying to replace each <code>,</code> in the current file by a new line:</p> <pre><code>:%s/,/\n/g </code></pre> <p>But it inserts what looks like a <code>^@</code> instead of an actual newline. The file is not in DOS mode or anything.</p> <p>What should I do?</p> <p>If you are curious, like me, check the question <em><a href="https://stackoverflow.com/questions/71417/why-is-r-a-newline-for-vim">Why is \r a newline for Vim?</a></em> as well.</p>
[ { "answer_id": 71334, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 13, "selected": true, "text": "\\r \\n \\n \\r \\n \\n \\r \\n \\r \\n \\r xxd echo bar > test\n(echo 'Before:'; xxd test) > output.txt\nvim test '+s/b/\\n/' '+s/a/\\r/' +wq\n(echo 'After:'; xxd test) >> output.txt\nmore output.txt\n Before:\n0000000: 6261 720a bar.\nAfter:\n0000000: 000a 720a ..r.\n \\n \\r" }, { "answer_id": 71342, "author": "Lasar", "author_id": 9438, "author_profile": "https://Stackoverflow.com/users/9438", "pm_score": 5, "selected": false, "text": "\\r" }, { "answer_id": 71388, "author": "dogbane", "author_id": 7412, "author_profile": "https://Stackoverflow.com/users/7412", "pm_score": 6, "selected": false, "text": ":%s/,/^M/g\n ^M" }, { "answer_id": 136915, "author": "Logan", "author_id": 1127433, "author_profile": "https://Stackoverflow.com/users/1127433", "pm_score": 8, "selected": false, "text": ":set magic\n :s/,/,^M/g\n ^M q v" }, { "answer_id": 7324063, "author": "rickfoosusa", "author_id": 931265, "author_profile": "https://Stackoverflow.com/users/931265", "pm_score": 4, "selected": false, "text": "^M :s/\\r/\\r/g\n" }, { "answer_id": 9134411, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": ":%s/look_for/replace_with^M/g\n" }, { "answer_id": 9172870, "author": "Kiran K Telukunta", "author_id": 888574, "author_profile": "https://Stackoverflow.com/users/888574", "pm_score": 3, "selected": false, "text": ":%s/\\n/\\r\\|\\-\\r/g\n |- line1\nline2\nline3\n line1\n|-\nline2\n|-\nline3\n" }, { "answer_id": 9220288, "author": "Evan Donovan", "author_id": 263877, "author_profile": "https://Stackoverflow.com/users/263877", "pm_score": 3, "selected": false, "text": "sed 's/\\\\n/\\n/g' file > newfile\n" }, { "answer_id": 18961239, "author": "sjas", "author_id": 805284, "author_profile": "https://Stackoverflow.com/users/805284", "pm_score": 7, "selected": false, "text": "s/foo/bar \\r \\n foo \\r CR ^M \\n LF CRLF bar \\r LF CRLF \\n NUL ^@ ^M CR LF NUL ^@ LF CR ^M echo ^[[33;1mcolored.^[[0mnot colored.\n ^[ bash: $'\\r': command not found\n \\r foo \\n bar \\r" }, { "answer_id": 29514339, "author": "codeshot", "author_id": 962394, "author_profile": "https://Stackoverflow.com/users/962394", "pm_score": 4, "selected": false, "text": "\\r 0x0A \\n \\r \\n 0x00 \\0 \\n \\0 \\n \\n \\r 0x0D ^M" }, { "answer_id": 73473053, "author": "Rajashekhar Meesala", "author_id": 3888182, "author_profile": "https://Stackoverflow.com/users/3888182", "pm_score": 1, "selected": false, "text": ":%s/\\\\n/\\r/g\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71323", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5190/" ]
71,328
<p>I have PHP configured so that magic quotes are on and register globals are off.</p> <p>I do my best to always call htmlentities() for anything I am outputing that is derived from user input.</p> <p>I also occasionally seach my database for common things used in xss attached such as...</p> <pre><code>&lt;script </code></pre> <p>What else should I be doing and how can I make sure that the things I am trying to do are <strong>always</strong> done.</p>
[ { "answer_id": 71358, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 2, "selected": false, "text": "Referer javascript:" }, { "answer_id": 71444, "author": "Michał Niedźwiedzki", "author_id": 2169, "author_profile": "https://Stackoverflow.com/users/2169", "pm_score": 7, "selected": true, "text": "|escape:'htmlall' |e" }, { "answer_id": 75839, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "strip_tags(trim(stripslashes())); in_array($userData, array(...))" }, { "answer_id": 77376, "author": "barce", "author_id": 13518, "author_profile": "https://Stackoverflow.com/users/13518", "pm_score": 2, "selected": false, "text": "<?php\n\nfunction h($string, $esc_type = 'htmlall')\n{\n switch ($esc_type) {\n case 'css':\n $string = str_replace(array('<', '>', '\\\\'), array('&lt;', '&gt;', '&#47;'), $string);\n // get rid of various versions of javascript\n $string = preg_replace(\n '/j\\s*[\\\\\\]*\\s*a\\s*[\\\\\\]*\\s*v\\s*[\\\\\\]*\\s*a\\s*[\\\\\\]*\\s*s\\s*[\\\\\\]*\\s*c\\s*[\\\\\\]*\\s*r\\s*[\\\\\\]*\\s*i\\s*[\\\\\\]*\\s*p\\s*[\\\\\\]*\\s*t\\s*[\\\\\\]*\\s*:/i',\n 'blocked', $string);\n $string = preg_replace(\n '/@\\s*[\\\\\\]*\\s*i\\s*[\\\\\\]*\\s*m\\s*[\\\\\\]*\\s*p\\s*[\\\\\\]*\\s*o\\s*[\\\\\\]*\\s*r\\s*[\\\\\\]*\\s*t/i',\n 'blocked', $string);\n $string = preg_replace(\n '/e\\s*[\\\\\\]*\\s*x\\s*[\\\\\\]*\\s*p\\s*[\\\\\\]*\\s*r\\s*[\\\\\\]*\\s*e\\s*[\\\\\\]*\\s*s\\s*[\\\\\\]*\\s*s\\s*[\\\\\\]*\\s*i\\s*[\\\\\\]*\\s*o\\s*[\\\\\\]*\\s*n\\s*[\\\\\\]*\\s*/i',\n 'blocked', $string);\n $string = preg_replace('/b\\s*[\\\\\\]*\\s*i\\s*[\\\\\\]*\\s*n\\s*[\\\\\\]*\\s*d\\s*[\\\\\\]*\\s*i\\s*[\\\\\\]*\\s*n\\s*[\\\\\\]*\\s*g:/i', 'blocked', $string);\n return $string;\n\n case 'html':\n //return htmlspecialchars($string, ENT_NOQUOTES);\n return str_replace(array('<', '>'), array('&lt;' , '&gt;'), $string);\n\n case 'htmlall':\n return htmlentities($string, ENT_QUOTES);\n case 'url':\n return rawurlencode($string);\n case 'query':\n return urlencode($string);\n\n case 'quotes':\n // escape unescaped single quotes\n return preg_replace(\"%(?<!\\\\\\\\)'%\", \"\\\\'\", $string);\n\n case 'hex':\n // escape every character into hex\n $s_return = '';\n for ($x=0; $x < strlen($string); $x++) {\n $s_return .= '%' . bin2hex($string[$x]);\n }\n return $s_return;\n\n case 'hexentity':\n $s_return = '';\n for ($x=0; $x < strlen($string); $x++) {\n $s_return .= '&#x' . bin2hex($string[$x]) . ';';\n }\n return $s_return;\n\n case 'decentity':\n $s_return = '';\n for ($x=0; $x < strlen($string); $x++) {\n $s_return .= '&#' . ord($string[$x]) . ';';\n }\n return $s_return;\n\n case 'javascript':\n // escape quotes and backslashes, newlines, etc.\n return strtr($string, array('\\\\'=>'\\\\\\\\',\"'\"=>\"\\\\'\",'\"'=>'\\\\\"',\"\\r\"=>'\\\\r',\"\\n\"=>'\\\\n','</'=>'<\\/'));\n\n case 'mail':\n // safe way to display e-mail address on a web page\n return str_replace(array('@', '.'),array(' [AT] ', ' [DOT] '), $string);\n\n case 'nonstd':\n // escape non-standard chars, such as ms document quotes\n $_res = '';\n for($_i = 0, $_len = strlen($string); $_i < $_len; $_i++) {\n $_ord = ord($string{$_i});\n // non-standard char, escape it\n if($_ord >= 126){ \n $_res .= '&#' . $_ord . ';'; \n } else {\n $_res .= $string{$_i};\n }\n }\n return $_res;\n\n default:\n return $string;\n }\n}\n \n?>\n" }, { "answer_id": 77689, "author": "Adam", "author_id": 13320, "author_profile": "https://Stackoverflow.com/users/13320", "pm_score": -1, "selected": false, "text": "<script> <object>" }, { "answer_id": 209743, "author": "Kornel", "author_id": 27009, "author_profile": "https://Stackoverflow.com/users/27009", "pm_score": 2, "selected": false, "text": "htmlspecialchars() |escape" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71328", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4012/" ]
71,365
<p>Presently, we've got several main projects each in their own repository. We will have to version-control up to a dozen additional projects. VisualSVN recommends to create 1 respository for our company and then vc all projects inside that. </p> <blockquote> <p>It's a good practice to create one repository for the entire company or department and store all your projects in this repository. Creating separate repository for each project is not a good idea because in that case you will not be able to perform Subversion operations like copy, diff and merge cross-project. <a href="http://www.visualsvn.com/support/topic/00017/" rel="nofollow noreferrer" title="Visualsvn.com">VisualSvn.com</a></p> </blockquote> <p>Currently we're using post-commit hooks to update the testing server with the latest commit and do other project specific actions (such as emailing certain people for one project but not for others) depending on which project has been committed.</p> <p>As post-commit runs for the whole repository, is this still possible in such a situation? How would I go about decerning which project has changes? filter folder structure?</p>
[ { "answer_id": 71543, "author": "Bruno De Fraine", "author_id": 6918, "author_profile": "https://Stackoverflow.com/users/6918", "pm_score": 1, "selected": false, "text": "post-commit svnlook changed grep" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/997/" ]
71,374
<p>We need to optimize the text rendering for a C# <a href="http://en.wikipedia.org/wiki/Windows_Forms" rel="noreferrer">Windows Forms</a> application displaying a large number of small strings in an irregular grid. At any time there can be well over 5000 cells visible that update 4 times per second. The font family and size is consistent across the cells, though the color may vary from cell to cell, as will bold/italic/plain.</p> <p>I've seen conflicting information on the web about <code>TextRenderer.DrawText</code> vs. <code>Graphics.DrawString</code> being the fastest/best, which reduces to a <a href="http://en.wikipedia.org/wiki/Graphics_Device_Interface" rel="noreferrer">GDI</a> vs. <a href="http://en.wikipedia.org/wiki/Graphics_Device_Interface#GDI.2B" rel="noreferrer">GDI+</a> comparison at the <a href="http://en.wikipedia.org/wiki/Windows_API" rel="noreferrer">Win32</a> level. </p> <p>I've also seen radically different results on Windows XP vs. Windows Vista, but my main target is Windows XP. Articles promising great advances under <a href="http://en.wikipedia.org/wiki/.NET_Framework_3.0#.NET_Framework_3.0" rel="noreferrer">WinFX</a> and <a href="http://en.wikipedia.org/wiki/DirectX#DirectX_10" rel="noreferrer">DirectX 10</a> aren't helpful here :-)</p> <p>What's the best approach here? I'm not afraid of introducing a small C++/CLI layer and optimizing device context handling to squeeze out more performance, but I'd like some definitive advice about which direction to take.</p> <p>EDIT: Thanks for the initial responses. I'll be trying a combination of background bitmap rendering and sticking with the GDI equivalent calls.</p>
[ { "answer_id": 64655977, "author": "Chungalin", "author_id": 2989229, "author_profile": "https://Stackoverflow.com/users/2989229", "pm_score": 0, "selected": false, "text": "ExtTextOut ETO_GLYPH_INDEX ExtTextOut GetCharacterPlacement ExtTextOutW" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71374", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6996/" ]
71,413
<p>Given a table of votes (users vote for a choice, and must supply an email address):</p> <pre><code>votes -- id: int choice: int timestamp: timestamp ip: varchar email: varchar </code></pre> <p>What's the best way to count "unique" votes (a user being a unique combination of email + ip) given the constraint they may only vote <em>twice</em> per hour?</p> <p>It's possible to count the number of hours between first and last vote and determine the maximum number of allowed votes for that timeframe, but that allows users to compress all their votes into say, a single hour-long window, and still have them counted.</p> <p>I realize anonymous online voting is inherently flawed, but I'm not sure how to do this with SQL. Should I be using an external script or whatever instead? (For each choice, for each email+ip pair, get a vote, calculate the next +1h timestamp, count/discard/tally votes, move on to the next hour, etc...)</p>
[ { "answer_id": 71430, "author": "Galwegian", "author_id": 3201, "author_profile": "https://Stackoverflow.com/users/3201", "pm_score": 2, "selected": false, "text": "select email, ip, count(choice)\nfrom votes\ngroup by email, ip, datepart(hour, timestamp)\n" }, { "answer_id": 71489, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 0, "selected": false, "text": "Insert Into Votes\n(Choice, Timestamp, IP, Email)\nSelect\nTop 1\n@Choice, @Timestamp, @IP, @Email\nFrom\nVotes\nWhere\n(Select Count(*) From Votes Where\n IP = @IP\n and Email = @Email\n and Timestamp > DateAdd(h, -2, GetDate())) < 3\n" }, { "answer_id": 74262, "author": "AJ.", "author_id": 7211, "author_profile": "https://Stackoverflow.com/users/7211", "pm_score": 0, "selected": false, "text": "SELECT choice, count(*) \nFROM votes v \nWHERE \n ( SELECT count(*) \n FROM votes v2\n WHERE v.email = v2.email \n AND v.ip = v2.ip \n AND v2.timestamp BETWEEN dateadd(hour, -1, v.timestamp) AND v.timestamp \n ) < 2 \n SELECT choice, count(*) \nFROM votes v \nWHERE NOT EXTISTS \n ( SELECT * \n FROM votes v2\n WHERE v.email = v2.email \n AND v.ip = v2.ip \n AND v2.timestamp BETWEEN dateadd(h,v.timestamp,-1) AND v.timestamp \n ) \n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
71,416
<p>I'm trying to do something like the following:</p> <pre><code>enum E; void Foo(E e); enum E {A, B, C}; </code></pre> <p>which the compiler rejects. I've had a quick look on Google and the consensus seems to be "you can't do it", but I can't understand why. Can anyone explain?</p> <p>Clarification 2: I'm doing this as I have private methods in a class that take said enum, and I do not want the enum's values exposed - so, for example, I do not want anyone to know that E is defined as</p> <pre><code>enum E { FUNCTIONALITY_NORMAL, FUNCTIONALITY_RESTRICTED, FUNCTIONALITY_FOR_PROJECT_X } </code></pre> <p>as project X is not something I want my users to know about.</p> <p>So, I wanted to forward declare the enum so I could put the private methods in the header file, declare the enum internally in the cpp, and distribute the built library file and header to people.</p> <p>As for the compiler - it's GCC.</p>
[ { "answer_id": 71961, "author": "Laurie Cheers", "author_id": 12066, "author_profile": "https://Stackoverflow.com/users/12066", "pm_score": 3, "selected": false, "text": "typedef unsigned long E;\n\nvoid Foo(E e);\n enum Econtent { FUNCTIONALITY_NORMAL, FUNCTIONALITY_RESTRICTED, FUNCTIONALITY_FOR_PROJECT_X,\n FORCE_32BIT = 0xFFFFFFFF };\n" }, { "answer_id": 72599, "author": "KJAWolf", "author_id": 12302, "author_profile": "https://Stackoverflow.com/users/12302", "pm_score": 9, "selected": true, "text": "char int int int unsigned int sizeof() sizeof()" }, { "answer_id": 78426, "author": "paercebal", "author_id": 14089, "author_profile": "https://Stackoverflow.com/users/14089", "pm_score": 0, "selected": false, "text": "namespace\n{\n const int FUNCTIONALITY_NORMAL = 0 ;\n const int FUNCTIONALITY_RESTRICTED = 1 ;\n const int FUNCTIONALITY_FOR_PROJECT_X = 2 ;\n}\n namespace\n{\n const int FUNCTIONALITY_begin = 0 ;\n const int FUNCTIONALITY_NORMAL = 0 ;\n const int FUNCTIONALITY_RESTRICTED = 1 ;\n const int FUNCTIONALITY_FOR_PROJECT_X = 2 ;\n const int FUNCTIONALITY_end = 3 ;\n\n bool isFunctionalityCorrect(int i)\n {\n return (i >= FUNCTIONALITY_begin) && (i < FUNCTIONALITY_end) ;\n }\n}\n" }, { "answer_id": 78448, "author": "Vincent Robert", "author_id": 268, "author_profile": "https://Stackoverflow.com/users/268", "pm_score": 2, "selected": false, "text": "class A\n{\npublic:\n ...\nprivate:\n void* pImpl;\n};\n class AImpl\n{\npublic:\n AImpl(A* pThis): m_pThis(pThis) {}\n\n ... all private methods here ...\nprivate:\n A* m_pThis;\n};\n ((AImpl*)pImpl)->PrivateMethod();\n" }, { "answer_id": 686303, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 3, "selected": false, "text": "enum X;\n 7.1.5.3/1 enum X : int;\n 7.2" }, { "answer_id": 717633, "author": "zhaorufei", "author_id": 64469, "author_profile": "https://Stackoverflow.com/users/64469", "pm_score": 1, "selected": false, "text": "/W4 /W3 mov DWORD PTR[eax], 305419896 ; 12345678H\n" }, { "answer_id": 990983, "author": "mavam", "author_id": 1170277, "author_profile": "https://Stackoverflow.com/users/1170277", "pm_score": 1, "selected": false, "text": "enum namespace type\n{\n class legacy_type;\n typedef const legacy_type& type;\n}\n // May be defined here or pulled in via #include.\nnamespace legacy\n{\n enum evil { x , y, z };\n}\n\n\nnamespace type\n{\n using legacy::evil;\n\n class legacy_type\n {\n public:\n legacy_type(evil e)\n : e_(e)\n {}\n\n operator evil() const\n {\n return e_;\n }\n\n private:\n evil e_;\n };\n}\n #include \"forward.h\"\n\nclass foo\n{\npublic:\n void f(type::type t);\n};\n #include \"foo.h\"\n\n#include <iostream>\n#include \"enum.h\"\n\nvoid foo::f(type::type t)\n{\n switch (t)\n {\n case legacy::x:\n std::cout << \"x\" << std::endl;\n break;\n case legacy::y:\n std::cout << \"y\" << std::endl;\n break;\n case legacy::z:\n std::cout << \"z\" << std::endl;\n break;\n default:\n std::cout << \"default\" << std::endl;\n }\n}\n #include \"foo.h\"\n#include \"enum.h\"\n\nint main()\n{\n foo fu;\n fu.f(legacy::x);\n\n return 0;\n}\n foo.h legacy::evil legacy::evil enum.h" }, { "answer_id": 1280969, "author": "user119017", "author_id": 119017, "author_profile": "https://Stackoverflow.com/users/119017", "pm_score": 8, "selected": false, "text": "enum Enum1; // Illegal in C++03 and C++11; no size is explicitly specified.\nenum Enum2 : unsigned int; // Legal in C++11.\nenum class Enum3; // Legal in C++11, because enum class declarations have a default type of \"int\".\nenum class Enum4: unsigned int; // Legal C++11.\nenum Enum2 : unsigned short; // Illegal in C++11, because Enum2 was previously declared with a different type.\n" }, { "answer_id": 1932119, "author": "Brian R. Bondy", "author_id": 3153, "author_profile": "https://Stackoverflow.com/users/3153", "pm_score": 5, "selected": false, "text": "struct class function enum enum enum enum enum enum enum enum enum enum int int unsigned int sizeof() sizeof() sizeof enum enum enum Color : char { Red=0, Green=1, Blue=2};\nassert(sizeof Color == 1);\n enum enum" }, { "answer_id": 11382046, "author": "Leszek Swirski", "author_id": 1509804, "author_profile": "https://Stackoverflow.com/users/1509804", "pm_score": 2, "selected": false, "text": "#define ENUM_CLASS(NAME, TYPE, VALUES...) \\\nstruct NAME { \\\n enum e { VALUES }; \\\n explicit NAME(TYPE v) : val(v) {} \\\n NAME(e v) : val(v) {} \\\n operator e() const { return e(val); } \\\n private:\\\n TYPE val; \\\n}\n" }, { "answer_id": 11632184, "author": "Tom", "author_id": 274460, "author_profile": "https://Stackoverflow.com/users/274460", "pm_score": 7, "selected": false, "text": "enum E : short;\nvoid foo(E e);\n\n....\n\nenum E : short\n{\n VALUE_1,\n VALUE_2,\n ....\n}\n -std=c++0x -std=c++11" }, { "answer_id": 74655121, "author": "Sunandan Nandi", "author_id": 2722779, "author_profile": "https://Stackoverflow.com/users/2722779", "pm_score": -1, "selected": false, "text": "enum A : int;" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71416", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11437/" ]
71,417
<p>From question <em><a href="https://stackoverflow.com/questions/71323/how-to-replace-a-character-for-a-newline-in-vim">How to replace a character for a newline in Vim?</a></em>. You have to use \r when replacing text for a newline, like this</p> <pre><code>:%s/%/\r/g </code></pre> <p>But when replacing end of lines and newlines for a character, you can do it like:</p> <pre><code>:%s/\n/%/g </code></pre> <p>What section of the manual documents these behaviors, and what's the reasoning behind them?</p>
[ { "answer_id": 71531, "author": "Aristotle Pagaltzis", "author_id": 9410, "author_profile": "https://Stackoverflow.com/users/9410", "pm_score": 6, "selected": false, "text": ":help NL-used-for-Nul <Nul> <NL> ^@ <Nul> <NL> <NL> <Nul> <Nul>" }, { "answer_id": 73438, "author": "pjz", "author_id": 8002, "author_profile": "https://Stackoverflow.com/users/8002", "pm_score": 8, "selected": true, "text": "\\r \\n" }, { "answer_id": 12388814, "author": "lmat - Reinstate Monica", "author_id": 200985, "author_profile": "https://Stackoverflow.com/users/200985", "pm_score": 8, "selected": false, "text": "\\n \\r CR Ctrl-M ^M \\r \\n 0x00" }, { "answer_id": 12389839, "author": "rking", "author_id": 1410840, "author_profile": "https://Stackoverflow.com/users/1410840", "pm_score": 7, "selected": false, "text": "\\0 s//\\0/ & \\0 NULL \\n \\n \\n \\r \\r \\r" }, { "answer_id": 20491960, "author": "syockit", "author_id": 219229, "author_profile": "https://Stackoverflow.com/users/219229", "pm_score": 4, "selected": false, "text": ":h :s :[range]s[ubstitute]/{pattern}/{string}/[flags] [count]\n pattern string {pattern} |pattern| {string} |sub-replace-special| |pattern| |sub-replace-special| \\r :h :s%" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71417", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5190/" ]
71,419
<p>I've heard many programmers, particularly Delphi programmers scorn the use of 'with'. </p> <p>I thought it made programs run faster (only one reference to parent object) and that it was easier to read the code if used sensibly (less than a dozen lines of code and no nesting).</p> <p>Here's an example:</p> <pre><code>procedure TBitmap32.FillRectS(const ARect: TRect; Value: TColor32); begin with ARect do FillRectS(Left, Top, Right, Bottom, Value); end; </code></pre> <p>I like using <code>with</code>. What's wrong with me?</p>
[ { "answer_id": 71470, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 4, "selected": false, "text": ". With obj\n .Left = 10\n .Submit()\nEnd With\n with" }, { "answer_id": 71471, "author": "Lars Truijens", "author_id": 1242, "author_profile": "https://Stackoverflow.com/users/1242", "pm_score": 5, "selected": false, "text": "procedure TMyForm.ButtonClick(...)\nbegin\n with OtherForm do begin\n Left := 10;\n Top := 20;\n CallThisFunction;\n end;\nend;\n" }, { "answer_id": 71532, "author": "Matt Lacey", "author_id": 1755, "author_profile": "https://Stackoverflow.com/users/1755", "pm_score": -1, "selected": false, "text": "with foo do\nbegin\n bar := 1;\n bin := x;\n box := 'abc';\nend\n foo.bar := 1;\nfoo.bin := x;\nfoo.box := 'abc';\n" }, { "answer_id": 2384989, "author": "markus_ja", "author_id": 192292, "author_profile": "https://Stackoverflow.com/users/192292", "pm_score": 4, "selected": false, "text": "with with x := ARect do\nbegin\n x.Left := 0;\n x.Rigth := 0;\n ...\nend;\n" }, { "answer_id": 3126973, "author": "mmmm", "author_id": 85592, "author_profile": "https://Stackoverflow.com/users/85592", "pm_score": 2, "selected": false, "text": "with Object1, Object2, Object3 do\nbegin\n //... Confusing statements here\nend\n with" }, { "answer_id": 12267500, "author": "Arnaud Bouchez", "author_id": 458259, "author_profile": "https://Stackoverflow.com/users/458259", "pm_score": 3, "selected": false, "text": "procedure TBitmap32.FillRectS(const ARect: TRect; Value: TColor32);\nbegin\n with ARect do FillRectS(Left, Top, Right, Bottom, Value);\nend;\n procedure TBitmap32.FillRectS(const ARect: TRect; Value: TColor32);\nbegin\n FillRectS(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom, Value);\nend;\n with with MyRect do\nbegin\n Left := 0;\n Right := 0;\nend;\n var aRect: ^TRect;\n\naRect := @MyRect;\naRect^.Left := 0;\naRect^.Right := 0;\n aRect TRect record for i := 0 to ObjList.Count-1 do\n for j := 0 to ObjList[i].NestedList.Count-1 do\n begin\n ObjList[i].NestedList[j].Member := 'Toto';\n ObjList[i].NestedList[j].Count := 10;\n end;\n for i := 0 to ObjList.Count-1 do\n for j := 0 to ObjList[i].NestedList.Count-1 do\n with ObjList[i].NestedList[j] do\n begin\n Member := 'Toto';\n Count := 10;\n end;\n for i := 0 to ObjList.Count-1 do\n with ObjList[i] do\n for j := 0 to NestedList.Count-1 do\n with NestedList[j] do\n begin\n Member := 'Toto';\n Count := 10;\n end;\n for i := 0 to ObjList.Count-1 do\nbegin\n Obj := ObjList[i];\n for j := 0 to Obj.NestedList.Count-1 do\n begin\n Nested := Obj.NestedList[j];\n Nested.Member := 'Toto';\n Nested.Count := 10;\n end;\nend;\n with Obj Nested" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71419", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11781/" ]
71,423
<p>I want to disable the selection of certain rows in a datagridview.</p> <p>It must be possible to remove the select property for one or more datagridview rows in a datagridview shown in a winform. The goal is that the user can't select certain rows. (depending on a condition)</p> <p>Thankx,</p>
[ { "answer_id": 71665, "author": "szevvy", "author_id": 11437, "author_profile": "https://Stackoverflow.com/users/11437", "pm_score": 5, "selected": true, "text": "public class MyDataGridView : DataGridView\n{\n protected override void SetSelectedRowCore(int rowIndex, bool selected)\n {\n if (selected && WantRowSelection(rowIndex))\n {\n base.SetSelectedRowCore(rowIndex, selected);\n }\n }\n\n protected virtual void SetSelectedCellCore(int columnIndex, int rowIndex, bool selected)\n {\n if (selected && WantRowSelection(rowIndex))\n {\n base.SetSelectedRowCore(rowIndex, selected);\n }\n }\n\n bool WantRowSelection(int rowIndex)\n {\n //return true if you want the row to be selectable, false otherwise\n }\n}\n" }, { "answer_id": 15474300, "author": "Asad Naeem", "author_id": 390163, "author_profile": "https://Stackoverflow.com/users/390163", "pm_score": -1, "selected": false, "text": "Private Sub dgvSomeDataGridView_SelectionChanged(sender As Object, e As System.EventArgs) Handles dgvSomeDataGridView.SelectionChanged\n dgvSomeDataGridView.ClearSelection()\nEnd Sub\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4392/" ]
71,440
<p>I have a UserControl in my Asp.net project that has a public property. I do not want this property to show up in the Visual Studio Property Window when a user highlights an instance of the UserControl in the IDE. What attribute (or other method) should I use to prevent it from showing up?</p> <pre><code>class MyControl : System.Web.UI.UserControl { // Attribute to prevent property from showing in VS Property Window? public bool SampleProperty { get; set; } // other stuff } </code></pre>
[ { "answer_id": 71454, "author": "Phil Wright", "author_id": 6276, "author_profile": "https://Stackoverflow.com/users/6276", "pm_score": 5, "selected": true, "text": "using System.ComponentModel;\n\n[Browsable(false)]\npublic bool SampleProperty { get; set; }\n <System.ComponentModel.Browsable(False)>\n" }, { "answer_id": 71459, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "[Browsable(false)]\npublic bool HiddenProperty {get;set;}\n" }, { "answer_id": 71481, "author": "Codeslayer", "author_id": 4021, "author_profile": "https://Stackoverflow.com/users/4021", "pm_score": 2, "selected": false, "text": "System.ComponentModel.Browsable > ' VB\n> \n> <System.ComponentModel.Browsable(False)>\n // C#\n [System.ComponentModel.Browsable(false)]\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71440", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51/" ]
71,468
<p>Does anybody know of a tool to test OCSP responses? Preferably, something that can be used from a Windows Command-line and/or can be included (easily) in a Java/python program </p>
[ { "answer_id": 72957, "author": "JJarava", "author_id": 12344, "author_profile": "https://Stackoverflow.com/users/12344", "pm_score": 3, "selected": true, "text": "openssl ocsp -whatever\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
71,469
<p>Let's assume we've got the following Java code:</p> <pre><code>public class Maintainer { private Map&lt;Enum, List&lt;Listener&gt;&gt; map; public Maintainer() { this.map = new java.util.ConcurrentHashMap&lt;Enum, List&lt;Listener&gt;&gt;(); } public void addListener( Listener listener, Enum eventType ) { List&lt;Listener&gt; listeners; if( ( listeners = map.get( eventType ) ) == null ) { listeners = new java.util.concurrent.CopyOnWriteArrayList&lt;Listener&gt;(); map.put( eventType, listeners ); } listeners.add( listener ); } } </code></pre> <p>This code snippet is nothing but a bit improved listener pattern where each listener is telling what type of event it is interested in, and the provided method maintains a concurrent map of these relationships.</p> <p>Initially, I wanted this method to be called via my own annotation framework, but bumped into a brick wall of various annotation limitations (e.g. you can't have <em>java.lang.Enum</em> as annotation param, also there's a set of various classloader issues) therefore decided to use Spring.</p> <p>Could anyone tell me how do I Spring_ify_ this? What I want to achive is:<br> 1. Define <em>Maintainer</em> class as a Spring bean.<br> 2. Make it so that all sorts of listeners would be able to register themselves to <em>Maintainer</em> via XML by using <em>addListener</em> method. Spring doc nor Google are very generous in examples.</p> <p>Is there a way to achieve this easily?</p>
[ { "answer_id": 73129, "author": "Alexandre Victoor", "author_id": 11897, "author_profile": "https://Stackoverflow.com/users/11897", "pm_score": 0, "selected": false, "text": "public @interface MyAnnotation {\n MyEnum value();\n}\n" }, { "answer_id": 75192, "author": "flicken", "author_id": 12880, "author_profile": "https://Stackoverflow.com/users/12880", "pm_score": 1, "selected": false, "text": "<bean id=\"maintainer\" class=\"com.example.Maintainer\"/>\n MethodInvokingFactoryBean maintainer#addListener <bean id=\"listener\" class=\"com.example.Listener\"/>\n\n<bean id=\"maintainer.addListener\" class=\"org.springframework.beans.factory.config.MethodInvokingFactoryBean\">\n <property name=\"targetObject\" ref=\"maintainer\"/>\n <property name=\"targetMethod\" value=\"addListener\"/>\n <property name=\"arguments\">\n <list>\n <ref>listener</ref>\n <value>com.example.MyEnum</value>\n </list>\n </property>\n</bean>\n MyListener public interface MyListener extends Listener {\n public Enum[] getEventTypes()\n}\n public void addListener(MyListener listener)\n BeanFilteringSupport BeanPostProcessor ApplicationListener" }, { "answer_id": 93461, "author": "finnw", "author_id": 12048, "author_profile": "https://Stackoverflow.com/users/12048", "pm_score": 2, "selected": false, "text": " if( ( listeners = map.get( eventType ) ) == null ) {\n listeners = new java.util.concurrent.CopyOnWriteArrayList<Listener>();\n map.put( eventType, listeners );\n }\n listeners.add( listener );\n private Map<Enum, List<Listener>> map;\n\n...\n\nmap.put( eventType, listeners );\n private ConcurrentMap<Enum, List<Listener>> map;\n\n...\n\nmap.putIfAbsent( eventType, listeners );\nlisteners = map.get( eventType );\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71469", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7345/" ]
71,475
<p>I have created a namespace extension that is rooted under Desktop. The main purpose of the extension is to provide a virtual list of ZIP files that represent a list of configurable directories. When the user clicks one of the those items the contents of the related directory are zipped in place and the resulting ZIP file is stored in a cache folder.</p> <p>All this works well aside a minor issue. If we go to Windows Explorer, open the extension and double click an item the opened file is the one from the cache. [CORRECT]</p> <p>If on the other hand we open it by an Open Dialog the opened file is one from a Temporary Internet files directory. [INCORRECT]</p> <p>What do I have to change for the Open Dialog (when used for example trough notepad.exe) to open the file from the cache folder and not from Temporary Internet files. I have tried to send allways the qualified file name in IShellFolder::GetDisplayNameOf but without any luck.</p>
[ { "answer_id": 73129, "author": "Alexandre Victoor", "author_id": 11897, "author_profile": "https://Stackoverflow.com/users/11897", "pm_score": 0, "selected": false, "text": "public @interface MyAnnotation {\n MyEnum value();\n}\n" }, { "answer_id": 75192, "author": "flicken", "author_id": 12880, "author_profile": "https://Stackoverflow.com/users/12880", "pm_score": 1, "selected": false, "text": "<bean id=\"maintainer\" class=\"com.example.Maintainer\"/>\n MethodInvokingFactoryBean maintainer#addListener <bean id=\"listener\" class=\"com.example.Listener\"/>\n\n<bean id=\"maintainer.addListener\" class=\"org.springframework.beans.factory.config.MethodInvokingFactoryBean\">\n <property name=\"targetObject\" ref=\"maintainer\"/>\n <property name=\"targetMethod\" value=\"addListener\"/>\n <property name=\"arguments\">\n <list>\n <ref>listener</ref>\n <value>com.example.MyEnum</value>\n </list>\n </property>\n</bean>\n MyListener public interface MyListener extends Listener {\n public Enum[] getEventTypes()\n}\n public void addListener(MyListener listener)\n BeanFilteringSupport BeanPostProcessor ApplicationListener" }, { "answer_id": 93461, "author": "finnw", "author_id": 12048, "author_profile": "https://Stackoverflow.com/users/12048", "pm_score": 2, "selected": false, "text": " if( ( listeners = map.get( eventType ) ) == null ) {\n listeners = new java.util.concurrent.CopyOnWriteArrayList<Listener>();\n map.put( eventType, listeners );\n }\n listeners.add( listener );\n private Map<Enum, List<Listener>> map;\n\n...\n\nmap.put( eventType, listeners );\n private ConcurrentMap<Enum, List<Listener>> map;\n\n...\n\nmap.putIfAbsent( eventType, listeners );\nlisteners = map.get( eventType );\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6508/" ]
71,478
<p>Is it possible in <code>PHP (as it is in C++)</code> to declare a <code>class method</code> OUTSIDE the <code>class definition?</code></p>
[ { "answer_id": 71545, "author": "Michał Niedźwiedzki", "author_id": 2169, "author_profile": "https://Stackoverflow.com/users/2169", "pm_score": 3, "selected": false, "text": "__call class A {\n\n public function __call($method, $args) {\n if ($method == 'foo') {\n return call_user_func_array('bar', $args);\n }\n }\n\n}\n\nfunction bar($x) {\n echo $x;\n}\n\n$a = new A();\n$a->foo('12345'); // will result in calling bar('12345')\n" }, { "answer_id": 71551, "author": "Paul Dixon", "author_id": 6521, "author_profile": "https://Stackoverflow.com/users/6521", "pm_score": 2, "selected": false, "text": "class Foo {\n\n public function __call($method, $args) {\n $delegate=\"FooDelegate_\".$method;\n if (class_exists($delegate))\n {\n $handler=new $delegate($this);\n return call_user_func_array(array(&$handler, $method), $args);\n }\n\n\n }\n\n}\n" }, { "answer_id": 1267223, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "<?php\nclass A { }\nclasskit_method_add('A', 'bar', '$message', 'echo $message;', \n CLASSKIT_ACC_PUBLIC); \n$a = new A();\n$a->bar('Hello world!');\n <?php\nclass Example {\n function foo() {\n echo \"foo!\\n\";\n }\n}\n\n// create an Example object\n$e = new Example();\n\n// Add a new public method\nclasskit_method_add(\n 'Example',\n 'add',\n '$num1, $num2',\n 'return $num1 + $num2;',\n CLASSKIT_ACC_PUBLIC\n);\n\n// add 12 + 4\necho $e->add(12, 4);\n" }, { "answer_id": 8020459, "author": "jocap", "author_id": 305047, "author_profile": "https://Stackoverflow.com/users/305047", "pm_score": 2, "selected": false, "text": "$class->foo = function (&$self, $n) {\n print \"Current \\$var: \" . $self->var . \"\\n\";\n $self->var += $n;\n print \"New \\$var: \" .$self->var . \"\\n\";\n};\n $self $this & $class->foo(2);\n foo $class call_user_func call_user_func($class->foo, &$class, 2);\n# => Current $var: 0\n# => New $var: 2\n & __call class MyClass {\n public function __call ($method, $arguments) {\n if (isset($this->$method)) {\n call_user_func_array($this->$method, array_merge(array(&$this), $arguments));\n }\n }\n}\n $class->foo(2) __call $class->foo $class->var $class->foo" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71478", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
71,488
<p>I've currently got a set of reports with a number of common functions sitting in code blocks within the .rdl files. This obviously presents a maintainability issue and I as wondering if anyone knew a way for these different reports to share a library of common code?</p> <p>Ideally I'd like to have a .Net Assembly attached to my Reporting Services project, which all of my reports can access and call functions from. This would save the headache of trying to update and redeploy about 100 reports every time a change needs to be made to a common function.</p> <p>Any suggestions?</p>
[ { "answer_id": 1546774, "author": "Daver", "author_id": 68095, "author_profile": "https://Stackoverflow.com/users/68095", "pm_score": 2, "selected": false, "text": "<CodeGroup class=\"UnionCodeGroup\"\n version=\"1\"\n PermissionSetName=\"FullTrust\"\n Name=\"MyCodeGroup\"\n Description=\"Code group for my data processing extension\">\n <IMembershipCondition class=\"UrlMembershipCondition\"\n version=\"1\"\n Url=\"C:\\pathtocustomassembly\\customassembly.dll\"\n />\n</CodeGroup>\n Program Files\\Microsoft Visual Studio 8\\Common7\\IDE\\PrivateAssemblies \nProgram Files\\Microsoft SQL Server\\MSSQL.3\\Reporting Services\\ReportServer\\bin\n @ECHO OFF\nREM Name: SRSDeploy_Local.bat\nREM\nREM This batch files copies my custom assembly to my Reporting Services folders.\nREM\nREM This is the SQL Server 2005 version:\ncopy \"C:\\Projects\\Common\\lib\\SCI.Common.SSRSUtils.dll\" \"C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\IDE\\PrivateAssemblies\"\ncopy \"C:\\Projects\\Common\\lib\\SCI.Common.SSRSUtils.dll\" \"C:\\Program Files\\Microsoft SQL Server\\MSSQL.2\\Reporting Services\\ReportServer\\bin\" \n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71488", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4019/" ]
71,491
<p>I'm planning to write a simple J2SE application to aggregate information from multiple web sources.</p> <p>The most difficult part, I think, is extraction of meaningful information from web pages, if it isn't available as RSS or Atom feeds. For example, I might want to extract a list of questions from stackoverflow, but I absolutely don't need that huge tag cloud or navbar.</p> <p>What technique/library would you advice?</p> <p><strong>Updates/Remarks</strong></p> <ul> <li>Speed doesn't matter — as long as it can parse about 5MB of HTML in less than 10 minutes.</li> <li>It sould be really simple.</li> </ul>
[ { "answer_id": 71577, "author": "Vhaerun", "author_id": 11234, "author_profile": "https://Stackoverflow.com/users/11234", "pm_score": 0, "selected": false, "text": "GET /file.html HTTP/1.0\nHost: site.com\n<ENTER>\n<ENTER>\n Socket#getInputStream" }, { "answer_id": 71690, "author": "Joe Liversedge", "author_id": 4552, "author_profile": "https://Stackoverflow.com/users/4552", "pm_score": 2, "selected": false, "text": "<table>\n{\n for $d in //td[contains(a/small/text(), \"New York, NY\")]\n for $row in $d/parent::tr/parent::table/tr\n where contains($d/a/small/text()[1], \"New York\")\n return <tr><td>{data($row/td[1])}</td> \n <td>{data($row/td[2])}</td> \n <td>{$row/td[3]//img}</td> </tr>\n}\n</table>\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1764/" ]
71,518
<p>I just tried FxCop. It does detect unused private methods, but not unused public. Is there a custom rule that I can download, plug-in that will detect public methods that aren't called from within the same assembly?</p>
[ { "answer_id": 71730, "author": "Keith", "author_id": 905, "author_profile": "https://Stackoverflow.com/users/905", "pm_score": 3, "selected": false, "text": "public internal" }, { "answer_id": 71929, "author": "user7116", "author_id": 7116, "author_profile": "https://Stackoverflow.com/users/7116", "pm_score": 4, "selected": false, "text": "// <Name>Potentially unused methods</Name>\nWARN IF Count > 0 IN SELECT METHODS WHERE\n MethodCa == 0 AND // Ca=0 -> No Afferent Coupling -> The method \n // is not used in the context of this\n // application.\n\n IsPublic AND // Check for unused public methods\n\n !IsEntryPoint AND // Main() method is not used by-design.\n\n !IsExplicitInterfaceImpl AND // The IL code never explicitely calls \n // explicit interface methods implementation.\n\n !IsClassConstructor AND // The IL code never explicitely calls class\n // constructors.\n\n !IsFinalizer // The IL code never explicitely calls\n // finalizers.\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9328/" ]
71,534
<p>I hope I haven't painted myself into a corner. I've gotten what seems to be most of the way through implementing a Makefile and I can't get the last bit to work. I hope someone here can suggest a technique to do what I'm trying to do.</p> <p>I have what I'll call "bills of materials" in version controlled files in a source repository and I build something like:</p> <pre><code>make VER=x </code></pre> <p>I want my Makefile to use $(VER) as a tag to retrieve a BOM from the repository, generate a dependency file to include in the Makefile, rescan including that dependency, and then build the product. </p> <p>More generally, my Makefile may have several targets -- A, B, C, etc. -- and I can build different versions of each so I might do:</p> <pre><code>make A VER=x make B VER=y make C VER=z </code></pre> <p>and the dependency file includes information about all three targets.</p> <p>However, creating the dependency file is somewhat expensive so if I do:</p> <pre><code>make A VER=x ...make source (not BOM) changes... make A VER=x </code></pre> <p>I'd really like the Makefile to not regenerate the dependency. And just to make things as complicated as possible, I might do:</p> <pre><code>make A VER=x .. change version x of A's BOM and check it in make A VER=x </code></pre> <p>so I need to regenerate the dependency on the second build.</p> <p>The check out messes up the timestamps used to regenerate the dependencies so I think I need a way for the dependency file to depend not on the BOM but on some indication that the BOM changed.</p> <p>What I've come to is making the BOM checkout happen in a .PHONY target (so it always gets checked out) and keeping track of the contents of the last checkout in a ".sig" file (if the signature file is missing or the contents are different than the signature of the new file, then the BOM changed), and having the dependency generation depend on the signatures). At the top of my Makefile, I have some setup:</p> <pre><code>BOMS = $(addsuffix .bom,$(MAKECMDGOALS) SIGS = $(subst .bom,.sig,$(BOMS)) DEP = include.d -include $(DEP) </code></pre> <p>And it seems I always need to do:</p> <pre><code>.PHONY: $(BOMS) $(BOMS): ...checkout TAG=$(VER) $@ </code></pre> <p>But, as noted above, if i do just that, and continue:</p> <pre><code>$(DEP) : $(BOMS) ... recreate dependency </code></pre> <p>Then the dependency gets updated every time I invoke make. So I try:</p> <pre><code>$(DEP) : $(SIGS) ... recreate dependency </code></pre> <p>and</p> <pre><code>$(BOMS): ...checkout TAG=$(VER) $@ ...if $(subst .bom,.sig,$@) doesn't exist ... create signature file ...else ... if new signature is different from file contents ... update signature file ... endif ...endif </code></pre> <p>But the dependency generation doesn't get tripped when the signature changes. I think it's because because $(SIGS) isn't a target, so make doesn't notice when the $(BOMS) rule updates a signature.</p> <p>I tried creating a .sig:.bom rule and managing the timestamps of the checked out BOM with touch but that didn't work.</p> <p>Someone suggested something like:</p> <pre><code>$(DEP) : $(SIGS) ... recreate dependency $(BOMS) : $(SIGS) ...checkout TAG=$(VER) $@ $(SIGS) : ...if $(subst .bom,.sig,$(BOMS)) doesn't exist ... create it ...else ... if new signature is different from file contents ... update signature file ... endif ...endif </code></pre> <p>but how can the BOM depend on the SIG when the SIG is created from the BOM? As I read that it says, "create the SIG from the BOM and if the SIG is newer than the BOM then checkout the BOM". How do I bootstrap that process? Where does the first BOM come from?</p>
[ { "answer_id": 71623, "author": "mbyrne215", "author_id": 5241, "author_profile": "https://Stackoverflow.com/users/5241", "pm_score": 0, "selected": false, "text": "$(DEP) : $(SIGS)\n ... recreate dependency\n$(BOMS) : $(SIGS)\n ...checkout TAG=$(VER) $@\n$(SIGS) :\n ...if $(subst .bom,.sig,$(BOMS)) doesn't exist\n ... create it\n ...else\n ... if new signature is different from file contents\n ... update signature file\n ... endif\n ...endif\n $(DEP) : $(SIGS)\n ... recreate dependency\n$(NEWTARGET) : $(BOMS) $(SIGS)\n$(BOMS) : \n ...checkout TAG=$(VER) $@\n$(SIGS) :\n ...if $(subst .bom,.sig,$(BOMS)) doesn't exist\n ... create it\n ...else\n ... if new signature is different from file contents\n ... update signature file\n ... endif\n ...endif\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71534", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7685/" ]
71,561
<p>In a web interface, I've got a text field. When user enters text and accepts with enter, application performs an action.</p> <p>I wanted to test the behavior with Selenium. Unfortunately, invoking 'keypress' with chr(13) insert representation of the character into the field.</p> <p>Is there a way other then submitting the form? I'd like to mimic intended user interaction, without any shortcuts...</p>
[ { "answer_id": 71902, "author": "noah", "author_id": 12034, "author_profile": "https://Stackoverflow.com/users/12034", "pm_score": 4, "selected": true, "text": "selenium.keyDown(id, \"\\\\13\");\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71561", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9622/" ]
71,565
<p>If I have the following:</p> <pre><code>Public Class Product Public Id As Integer Public Name As String Public AvailableColours As List(Of Colour) Public AvailableSizes As List(Of Size) End Class </code></pre> <p>and I want to get a list of products from the database and display them on a page along with their available sizes and colours, should I </p> <ol> <li>have one method (GetProducts()) which makes use of a single view that joins the relevant tables, that then loops through each row and creates the objects as required? Or…</li> <li>have several methods which are responsible only for creating one object each? eg. GetProducts(), GetAvailableColoursForProduct(id), etc</li> </ol> <p>I'm currently doing a) but as I add other other properties (multiple images, optional tassels, etc) the code is getting very messy (having to check that this isn't the same product as the previous row, has this colour already been added, etc) so I'm tempted to go with b) however, this will really ramp up the number of round trips to the database.</p>
[ { "answer_id": 71624, "author": "Bob Dizzle", "author_id": 9581, "author_profile": "https://Stackoverflow.com/users/9581", "pm_score": 0, "selected": false, "text": "Public static function Load(Id as integer) as Product\n\nProduct.Load(Id)\n private _Colors as list(Of Color)\npublic property Colors() as List(Of Color)\n get\n if _Colors is nothing \n . .. . load colors here\n end if\n end get. . . . .\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71565", "https://Stackoverflow.com", "https://Stackoverflow.com/users/984/" ]
71,578
<p>I have a database in ISO-8859-2 format, but I need to create XML in UTF-8. This means that I must encode the database before prinitng in UTF-8. I know very little about ASP.Net, so I'm hoping someone can help.</p> <p>In PHP I would do something like this:</p> <pre><code>db_connect(); mysql_query("SET NAMES 'UTF8'"); mysql_query("SET character_set_client='UTF8'"); </code></pre> <p>This is my ASP.Net code for database connection:</p> <pre><code> 'CONNECTION TO DATABASE dim dbconn,sql,dbcomm dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" &amp; _ "Data Source=" &amp; Server.MapPath("../baze/test.mdb")) dbconn.Open() sql="SELECT * FROM nekretnine, tipovinekretnina WHERE nekretnine.idtipnekretnine = tipovinekretnina.idtipnekretnine ORDER BY nekretnine.idnekretnine" dbcomm=New OleDbCommand(sql,dbconn) dbread=dbcomm.ExecuteReader() while dbread.Read() </code></pre> <p>Where and how do I encode to UTF-8?</p>
[ { "answer_id": 71640, "author": "Omer van Kloeten", "author_id": 4979, "author_profile": "https://Stackoverflow.com/users/4979", "pm_score": 3, "selected": true, "text": "str var encoding = System.Text.Encoding.GetEncoding(\"iso-8859-2\");\n\nvar bytes = System.Text.Encoding.Convert(encoding, System.Text.Encoding.Default, encoding.GetBytes(str));\n\nvar newString = System.Text.Encoding.Default.GetString(bytes);\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/205368/" ]
71,585
<p>Since generics were introduced, Class is parametrized, so that List.class produces Class&lt;List>. This is clear.</p> <p>What I am not able to figure out is how to get a instance of Class of type which is parametrized itself, i.e. Class&lt;List&lt;String>>. Like in this snippet:</p> <pre><code>public class GenTest { static &lt;T&gt; T instantiate(Class&lt;T&gt; clazz) throws Exception { return clazz.newInstance(); } public static void main(String[] args) throws Exception { // Is there a way to avoid waring on the line below // without using @SuppressWarnings("unchecked")? // ArrayList.class is Class&lt;ArrayList&gt;, but I would like to // pass in Class&lt;ArrayList&lt;String&gt;&gt; ArrayList&lt;String&gt; l = GenTest.instantiate(ArrayList.class); } } </code></pre> <p>I run into variations of this problem quite often and I still don't know, if I just miss something, or if there is really no better way. Thanks for suggestions.</p>
[ { "answer_id": 71795, "author": "Dan Dyer", "author_id": 5171, "author_profile": "https://Stackoverflow.com/users/5171", "pm_score": 1, "selected": false, "text": "public class GenTest\n{\n private static <E> List<E> createList()\n {\n return new ArrayList<E>();\n }\n\n public static void main(String[] args)\n {\n List<String> list = createList();\n List<Integer> list2 = createList();\n }\n}\n" }, { "answer_id": 13365240, "author": "thSoft", "author_id": 90874, "author_profile": "https://Stackoverflow.com/users/90874", "pm_score": 0, "selected": false, "text": "List<String> getClass() instantiate(new List<String>() { ... }.getClass());\n List new ArrayList<String> Collections.<String>emptyList()" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71585", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7135/" ]
71,590
<p>With this code I can show an animated gif while the server script is running:</p> <pre><code>function calculateTotals() { $('#results').load('getResults.php', null, showStatusFinished); showLoadStatus(); } function showLoadStatus() { $('#status').html(''); } function showStatusFinished() { $('#status').html('Finished.'); } </code></pre> <p>However, I would like to display a status of how far along the script is, e.g. "Processing line 342 of 20000..." and have it count up until it is finished.</p> <p>How can I do that? I can make a server-script which constantly contains the updated information but where do I put the command to read this, say, every second?</p>
[ { "answer_id": 165872, "author": "matdumsa", "author_id": 1775, "author_profile": "https://Stackoverflow.com/users/1775", "pm_score": 3, "selected": true, "text": "function getStatus() {\n $.getJSON(\"/status.php\",{\"session\":0, \"requestID\":12345}, \n function(data) { //data is the returned JSON object from the server {name:\"value\"}\n setStatus(data.status);\n window.setTimeout(\"getStatus()\",intervalInMS)\n });\n}\n {\"status\":\"We are done row 1040/45983459\"}\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71590", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4639/" ]
71,608
<p>How do you set up your .NET development tree? I use a structure like this:</p> <pre><code>-projectname --config (where I put the configuration files) --doc (where I put all the document concerning the project: e-mails, documentation) --tools (all the tools I use: Nunit, Moq) --lib (all the libraries used by the solution: ninject or autofac) --src ---app (sourcefiles) ---test (unittests) solutionfile.sln build.csproj </code></pre> <p>The sign "-" marks directories.</p> <p>I think it's very important to have a good structure on this stuff. You should be able to get the source code from the source control system and then build the solution without opening Visual Studio or installing any third party libraries. </p> <p>Any thoughts on this?</p>
[ { "answer_id": 71738, "author": "Curro", "author_id": 10688, "author_profile": "https://Stackoverflow.com/users/10688", "pm_score": 0, "selected": false, "text": "\nsolutionfile.sln\n-src\n--projectname\n---config\n---doc\n---source files (structure representing namespaces)\n-test\n--testprojectname (usually, a test project per source project)\n---unit test files (structure mirroing the structure in the source project)\n-lib\n--libraryname (containing the libraries)\n-tools\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71608", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4093/" ]
71,625
<p>I have just found a static nested interface in our code-base.</p> <pre><code>class Foo { public static interface Bar { /* snip */ } /* snip */ } </code></pre> <p>I have never seen this before. The original developer is out of reach. Therefore I have to ask SO:</p> <p>What are the semantics behind a static interface? What would change, if I remove the <code>static</code>? Why would anyone do this?</p>
[ { "answer_id": 71654, "author": "Clinton Dreisbach", "author_id": 6262, "author_profile": "https://Stackoverflow.com/users/6262", "pm_score": 3, "selected": false, "text": "Foo.Bar public class Baz implements Foo.Bar {\n ...\n}\n" }, { "answer_id": 71708, "author": "Skizz", "author_id": 1898, "author_profile": "https://Stackoverflow.com/users/1898", "pm_score": -1, "selected": false, "text": "class Bob\n{\n void FuncA ()\n {\n Foo.Bar foobar;\n }\n}\n" }, { "answer_id": 74400, "author": "Jesse Glick", "author_id": 12916, "author_profile": "https://Stackoverflow.com/users/12916", "pm_score": 9, "selected": true, "text": "public class Foo {\n public interface Bar {\n void callback();\n }\n public static void registerCallback(Bar bar) {...}\n}\n// ...elsewhere...\nFoo.registerCallback(new Foo.Bar() {\n public void callback() {...}\n});\n" }, { "answer_id": 209158, "author": "ColinD", "author_id": 13792, "author_profile": "https://Stackoverflow.com/users/13792", "pm_score": 6, "selected": false, "text": "Listener Foo FooListener Foo.Listener Foo.Event" }, { "answer_id": 14354017, "author": "user1982892", "author_id": 1982892, "author_profile": "https://Stackoverflow.com/users/1982892", "pm_score": 3, "selected": false, "text": "class ConcreteA implements A {\n :\n}\n\nclass ConcreteB implements B {\n :\n}\n\nclass ConcreteC implements C {\n :\n}\n\nclass Zoo implements A, C {\n :\n}\n\nclass DoSomethingAlready {\n interface AC extends A, C { }\n\n private final AC ac;\n\n DoSomethingAlready(AC ac) {\n this.ac = ac;\n }\n}\n" }, { "answer_id": 31952505, "author": "Pindatjuh", "author_id": 252704, "author_profile": "https://Stackoverflow.com/users/252704", "pm_score": 0, "selected": false, "text": "// This code does NOT compile\nclass LangF<This extends LangF<This>> {\n interface Visitor<R> {\n public R forNum(int n);\n }\n\n interface Exp {\n // since Exp is non-static, it can refer to the type bound to This\n public <R> R visit(This.Visitor<R> v);\n }\n}\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1870/" ]
71,643
<p>Currently I monitoring a particular file with a simple shell one-liner:</p> <pre><code>filesize=$(ls -lah somefile | awk '{print $5}') </code></pre> <p>I'm aware that Perl has some nice modules to deal with Excel files so the idea is to, let's say, run that check daily, perhaps with cron, and write the result on a spreadsheet for further statistical use.</p>
[ { "answer_id": 71668, "author": "Aristotle Pagaltzis", "author_id": 9410, "author_profile": "https://Stackoverflow.com/users/9410", "pm_score": 3, "selected": false, "text": "-s" }, { "answer_id": 72229, "author": "Michael Cramer", "author_id": 1496728, "author_profile": "https://Stackoverflow.com/users/1496728", "pm_score": 2, "selected": false, "text": "#!/bin/bash\ndate=`date +%Y/%m/%d:%H:%M:%S`\nsize=$(ls -lah somefile | awk '{print $5}')\necho \"$date,$size\"\n 0 0 * * * /path/to/script.sh >/data/sizelog.csv\n" }, { "answer_id": 72868, "author": "Darren Meyer", "author_id": 7826, "author_profile": "https://Stackoverflow.com/users/7826", "pm_score": 2, "selected": false, "text": "#!/usr/bin/perl\npackage main;\nuse strict; use warnings; # always!\n\nuse Text::CSV_XS;\nuse IO::File;\n\n# set up the CSV file\nmy $csv = Text::CSV_XS->new( {eol=>\"\\r\\n\"} );\nmy $io = IO::File->new( 'report.csv', '>')\n or die \"Cannot create report.csv: $!\\n\";\n\n# for each file specified on command line\nfor my $file (@ARGV) {\n unless ( -f $file ) {\n # file doesn't exist\n warn \"$file doesn't exist, skipping\\n\";\n next;\n }\n\n # get its size\n my $size = -s $file;\n\n # write the filename and size to a row in CSV\n $csv->print( $io, [ $file, $size ] );\n}\n\n$io->close; # make sure CSV file is flushed and closed\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71643", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6992/" ]
71,647
<p>I have an ASP.Net 2.0 application in which the Session_Start event is not firing in my Global.asax file. Can anyone tell why this is happening and how I can get it working?</p> <p>The application worked fine on my Windows XP development machine, but stopped working when deployed to the server (Win Server 2003/IIS 6/ASP.Net 2.0). </p> <p>I'm not sure if this is relevant, but the server also hosts a SharePoint installation (WSS 3.0) which I know does change some settings at the default web site level.</p>
[ { "answer_id": 192433, "author": "craigmoliver", "author_id": 12252, "author_profile": "https://Stackoverflow.com/users/12252", "pm_score": 1, "selected": false, "text": "<session />" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71647", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1052/" ]
71,692
<p>I'm building small web site in Java (Spring MVC with JSP views) and am trying to find best solution for making and including few reusable modules (like "latest news" "upcoming events"...).</p> <p>So the question is: Portlets, tiles or some other technology?</p>
[ { "answer_id": 71807, "author": "jodonnell", "author_id": 4223, "author_profile": "https://Stackoverflow.com/users/4223", "pm_score": 1, "selected": false, "text": "public class MyApplication implements EntryPoint, HistoryListener\n{\n static final String INIT_STATE = \"status\";\n\n /**\n * This is the entry point method. Instantiates the home page.\n */\n public void onModuleLoad ()\n {\n RootPanel.get ().setStyleName (\"root\");\n initHistorySupport ();\n }\n\n private void initHistorySupport ()\n {\n History.addHistoryListener (this);\n\n // check to see if there are any tokens passed at startup via the browser’s URI\n String token = History.getToken ();\n if (token.length () == 0)\n {\n onHistoryChanged (INIT_STATE);\n }\n else\n {\n onHistoryChanged (token);\n }\n }\n\n\n /**\n * Fired when the user clicks the browser's 'back' or 'forward' buttons.\n *\n * @param historyToken the token representing the current history state\n */\n public void onHistoryChanged (String historyToken)\n {\n RootPanel.get ().clear ();\n Page page;\n if (Page1.TOKEN.equalsIgnoreCase (historyToken))\n {\n page = new Page1 ();\n }\n else if (Page2.TOKEN.equalsIgnoreCase (historyToken))\n {\n page = new Page2 ();\n }\n else if (Page3.TOKEN.equalsIgnoreCase (historyToken))\n {\n page = new Page3 ();\n }\n RootPanel.get ().add (page);\n }\n}\n" }, { "answer_id": 72118, "author": "pjesi", "author_id": 1296737, "author_profile": "https://Stackoverflow.com/users/1296737", "pm_score": 3, "selected": true, "text": "@RequestMapping(\"VIEW\")\n@Controller\npublic class NewsPortlet {\n\n private NewsService newsService;\n\n @Autowired\n public NewsPortlet(NewsService newsService) {\n this.newsService = newsService;\n }\n\n @RequestMapping(method = RequestMethod.GET)\n public String view(Model model) {\n model.addAttribute(newsService.getLatests(10));\n return \"news\"; \n }\n}\n <!-- look for controllers and services here -->\n<context:component-scan base-package=\"com.example.news\"/>\n\n<!-- look for views here -->\n<bean id=\"viewResolver\" class=\"org.springframework.web.servlet.view.InternalResourceViewResolver\">\n <property name=\"prefix\" value=\"/WEB-INF/jsp/news/\"/>\n <property name=\"suffix\" value=\".jsp\"/>\n</bean>\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71692", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11890/" ]
71,694
<p>Is there an api to bring the vista side bar to the front (Win+Space) programatically and to do the reverse (send it to the back ground).</p>
[ { "answer_id": 71785, "author": "Cory", "author_id": 11870, "author_profile": "https://Stackoverflow.com/users/11870", "pm_score": 1, "selected": false, "text": "SetWindowPos(sidebarHandle, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NORESIZE);\n SetWindowPos(sidebarHandle, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NORESIZE);\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71694", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11930/" ]
71,720
<p>I've been using OpenGL for years, but after trying to use D3D for the first time, I wasted a significant amount of time trying figure out how to make my scene lights stay fixed in the world rather than fixed on my objects.</p> <p>In OpenGL light positions get transformed just like everything else with the MODELVIEW matrix, so to get lights fixed in space, you set up your MODELVIEW the way you want for the lights, and call glLightPosition then set it up for your geometry and make geometry calls. In D3D that doesn't help.</p> <p>(Comment -- I eventually figured out the answer to this one, but I couldn't find anything helpful on the web or in the MSDN. It would have saved me a few hours of head scratching if I could have found this answer then.)</p>
[ { "answer_id": 71802, "author": "Baxissimo", "author_id": 9631, "author_profile": "https://Stackoverflow.com/users/9631", "pm_score": 2, "selected": false, "text": "MODELVIEW D3DTS_VIEW D3DTS_WORLD" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9631/" ]
71,740
<p>in our application we have a Java applet running inside a .NET browser control. It is a know issue from Sun that running an applet this way may crash the control.</p> <p>Has anyone come across the same problem and solved it?</p> <p>Atm we are running the applet in a Webbrowser but we need to run it in a browser control.</p> <p>Thx for any help.</p>
[ { "answer_id": 72084, "author": "Mike", "author_id": 1115144, "author_profile": "https://Stackoverflow.com/users/1115144", "pm_score": 0, "selected": false, "text": "Here is a link - http://msdn.microsoft.com/en-us/library/aa290083(VS.71).aspx\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71740", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11946/" ]
71,756
<p>If I remove all the ' characters from a SQL query, is there some other way to do a SQL injection attack on the database?</p> <p>How can it be done? Can anyone give me examples?</p>
[ { "answer_id": 71780, "author": "Bob Dizzle", "author_id": 9581, "author_profile": "https://Stackoverflow.com/users/9581", "pm_score": 2, "selected": false, "text": "5; drop table employees; -- select * from somewhere where number = 5; drop table employees; -- and sadfsf --" }, { "answer_id": 71782, "author": "Leigh Caldwell", "author_id": 3267, "author_profile": "https://Stackoverflow.com/users/3267", "pm_score": 0, "selected": false, "text": " String query = \"SELECT name_ from Customer WHERE ID = \" + request.getParameter(\"id\");\n" }, { "answer_id": 71784, "author": "Johan", "author_id": 11347, "author_profile": "https://Stackoverflow.com/users/11347", "pm_score": 6, "selected": true, "text": "\"SELECT * FROM data WHERE id = \" + a_variable + \";\" 1;DROP TABLE users SELECT * FROM DATA WHERE id=1;DROP TABLE users;" }, { "answer_id": 71830, "author": "hollystyles", "author_id": 2083160, "author_profile": "https://Stackoverflow.com/users/2083160", "pm_score": 0, "selected": false, "text": "\\;.*--\\\n" }, { "answer_id": 71943, "author": "Veynom", "author_id": 11670, "author_profile": "https://Stackoverflow.com/users/11670", "pm_score": 3, "selected": false, "text": "thingy users" }, { "answer_id": 72476, "author": "GvS", "author_id": 11492, "author_profile": "https://Stackoverflow.com/users/11492", "pm_score": 3, "selected": false, "text": "' Not Tested\nvar sql = \"SELECT * FROM data WHERE id = @id\";\nvar cmd = new SqlCommand(sql, myConnection);\ncmd.Parameters.AddWithValue(\"@id\", request.getParameter(\"id\"));\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71756", "https://Stackoverflow.com", "https://Stackoverflow.com/users/184/" ]
71,766
<p>In Delphi, I want to be able to create an private object that's associated with a class, and access it from all instances of that class. In Java, I'd use:</p> <pre><code>public class MyObject { private static final MySharedObject mySharedObjectInstance = new MySharedObject(); } </code></pre> <p>Or, if MySharedObject needed more complicated initialization, in Java I could instantiate and initialize it in a static initializer block.</p> <p>(You might have guessed... I know my Java but I'm rather new to Delphi...)</p> <p>Anyway, I don't want to instantiate a new MySharedObject each time I create an instance of MyObject, but I do want a MySharedObject to be accessible from each instance of MyObject. (It's actually logging that has spurred me to try to figure this out - I'm using Log4D and I want to store a TLogLogger as a class variable for each class that has logging functionality.)</p> <p>What's the neatest way to do something like this in Delphi?</p>
[ { "answer_id": 71811, "author": "CL.", "author_id": 11654, "author_profile": "https://Stackoverflow.com/users/11654", "pm_score": 0, "selected": false, "text": "implementation" }, { "answer_id": 71841, "author": "squadette", "author_id": 7754, "author_profile": "https://Stackoverflow.com/users/7754", "pm_score": 0, "selected": false, "text": "procedure TForm1.Button1Click(Sender: TObject) ;\nconst\n clicks : Integer = 1; //not a true constant\nbegin\n Form1.Caption := IntToStr(clicks) ;\n clicks := clicks + 1;\nend;\n implementation {$J+}" }, { "answer_id": 71889, "author": "Lars Fosdal", "author_id": 10002, "author_profile": "https://Stackoverflow.com/users/10002", "pm_score": 2, "selected": false, "text": " TMyObject = class\n private\n class var FLogger : TLogLogger;\n procedure SetLogger(value:TLogLogger);\n property Logger : TLogLogger read FLogger write SetLogger;\n end;\n\nprocedure TMyObject.SetLogger(value:TLogLogger);\nbegin\n // sanity checks here\n FLogger := Value;\nend;\n TMyObject = class\n private\n class var FLogger : TLogLogger;\n procedure SetLogger(value:TLogLogger);\n function GetLogger:TLogLogger;\n property Logger : TLogLogger read GetLogger write SetLogger;\n end;\n\nfunction TMyObject.GetLogger:TLogLogger;\nbegin\n if not Assigned(FLogger)\n then FLogger := TSomeLogLoggerClass.Create;\n Result := FLogger;\nend;\n\nprocedure TMyObject.SetLogger(value:TLogLogger);\nbegin\n // sanity checks here\n FLogger := Value;\nend;\n" }, { "answer_id": 71993, "author": "Graza", "author_id": 11820, "author_profile": "https://Stackoverflow.com/users/11820", "pm_score": 2, "selected": false, "text": " TMyClass = class(TObject)\n strict private\n class var\n FMySharedObjectRefCount: integer;\n FMySharedObject: TMySharedObjectClass;\n var\n FOtherNonClassField1: integer;\n function GetMySharedObject: TMySharedObjectClass;\n public\n constructor Create;\n destructor Destroy; override;\n property MySharedObject: TMySharedObjectClass read GetMySharedObject;\n end;\n\n\n{ TMyClass }\nconstructor TMyClass.Create;\nbegin\n if not Assigned(FMySharedObject) then\n FMySharedObject := TMySharedObjectClass.Create;\n Inc(FMySharedObjectRefCount);\nend;\n\ndestructor TMyClass.Destroy;\nbegin\n Dec(FMySharedObjectRefCount);\n if (FMySharedObjectRefCount < 1) then\n FreeAndNil(FMySharedObject);\n\n inherited;\nend;\n\nfunction TMyClass.GetMySharedObject: TMySharedObjectClass;\nbegin\n Result := FMySharedObject;\nend;\n" }, { "answer_id": 72047, "author": "Pierre-Jean Coudert", "author_id": 8450, "author_profile": "https://Stackoverflow.com/users/8450", "pm_score": 5, "selected": true, "text": "unit MyObject;\n\ninterface\n\ntype\n\nTMyObject = class\n private\n class var FLogger : TLogLogger;\n public\n class procedure SetLogger(value:TLogLogger);\n class procedure FreeLogger;\n end;\n\nimplementation\n\nclass procedure TMyObject.SetLogger(value:TLogLogger);\nbegin\n // sanity checks here\n FLogger := Value;\nend;\n\nclass procedure TMyObject.FreeLogger;\nbegin\n if assigned(FLogger) then \n FLogger.Free;\nend;\n\ninitialization\n TMyObject.SetLogger(TLogLogger.Create);\nfinalization\n TMyObject.FreeLogger;\nend.\n" }, { "answer_id": 73486, "author": "MB.", "author_id": 11961, "author_profile": "https://Stackoverflow.com/users/11961", "pm_score": 1, "selected": false, "text": "unit MyObject;\n\ninterface\n\ntype\n\nTMyObject = class\nprivate\n class var FLogger: TLogLogger;\nend;\n\nimplementation\n\ninitialization\n TMyObject.FLogger:= TLogLogger.GetLogger(TMyObject);\nfinalization\n // You'd typically want to free the class objects in the finalization block, but\n // TLogLoggers are actually managed by Log4D.\n\nend.\n unit MyObject;\n\ninterface\n\ntype\n\nTMyObject = class\nstrict private\n class var FLogger: TLogLogger;\nprivate\n class procedure InitClass;\n class procedure FreeClass;\nend;\n\nimplementation\n\nclass procedure TMyObject.InitClass;\nbegin\n FLogger:= TLogLogger.GetLogger(TMyObject);\nend;\n\nclass procedure TMyObject.FreeClass;\nbegin\n // Nothing to do here for a TLogLogger - it's freed by Log4D.\nend;\n\ninitialization\n TMyObject.InitClass;\nfinalization\n TMyObject.FreeClass;\n\nend.\n" }, { "answer_id": 81437, "author": "Graza", "author_id": 11820, "author_profile": "https://Stackoverflow.com/users/11820", "pm_score": 1, "selected": false, "text": "interface\ntype\n TMyObject = class(TObject)\n private\n FLogger: TLogLogger; //NB: pointer to shared threadvar\n public\n constructor Create;\n end;\nimplementation\nthreadvar threadGlobalLogger: TLogLogger = nil;\nconstructor TMyObject.Create;\nbegin\n if not Assigned(threadGlobalLogger) then\n threadGlobalLogger := TLogLogger.GetLogger(TMyObject); //NB: No need to reference count or explicitly free, as it's freed by Log4D\n FLogger := threadGlobalLogger;\nend;\n" }, { "answer_id": 1038253, "author": "Gedean Dias", "author_id": 101900, "author_profile": "https://Stackoverflow.com/users/101900", "pm_score": 2, "selected": false, "text": "TMyObject = class\npulic\n class function MySharedObject: TMySharedObject; // I'm lazy so it will be read only\nend;\n\nimplementation\n class function MySharedObject: TMySharedObject;\n{$J+} const MySharedObjectInstance: TMySharedObject = nil; {$J-} // {$J+} Makes the consts writable\nbegin\n // any conditional initialization ...\n if (not Assigned(MySharedObjectInstance)) then\n MySharedObjectInstance = TMySharedOject.Create(...);\n Result := MySharedObjectInstance;\nend;\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11961/" ]
71,775
<p>I have to read data from some files and insert the data into different tables in a database. Is Unix shell script powerful enough to do the job?</p> <p>Is it easy to do the job in shell script or should I go about doing this in Java?</p>
[ { "answer_id": 71789, "author": "Josti", "author_id": 11231, "author_profile": "https://Stackoverflow.com/users/11231", "pm_score": 0, "selected": false, "text": "echo \"INSERT INTO foo (b,a,r) VALUES (1,2,3);\" | \n mysql -u user -psecret -h host database\n" }, { "answer_id": 71799, "author": "Charles Ma", "author_id": 11708, "author_profile": "https://Stackoverflow.com/users/11708", "pm_score": 2, "selected": false, "text": "echo $sql | mysql -u[user] -p[password] -h[host]\n" }, { "answer_id": 71834, "author": "Yining", "author_id": 6506, "author_profile": "https://Stackoverflow.com/users/6506", "pm_score": 1, "selected": false, "text": "echo 'load data infile /path/to/the/file into table table_name ...' | \n mysql -u mysql_user_id -p \n" }, { "answer_id": 72018, "author": "Michael Cramer", "author_id": 1496728, "author_profile": "https://Stackoverflow.com/users/1496728", "pm_score": 3, "selected": true, "text": "mysqlimport \\\n --fields-terminated-by=, \\\n --ignore-lines=1 \\\n --fields-optionally-enclosed-by='\"' < datafile.txt\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71775", "https://Stackoverflow.com", "https://Stackoverflow.com/users/184/" ]
71,776
<p>I have 16,000 jpg's from a webcan screeb grabber that I let run for a year pointing into the back year. I want to find a way to grab every 4th image so that I can then put them into another directory so I can later turn them into a movie. Is there a simple bash script or other way under linux that I can do this.</p> <p>They are named like so......</p> <p>frame-44558.jpg</p> <p>frame-44559.jpg</p> <p>frame-44560.jpg</p> <p>frame-44561.jpg</p> <p>Thanks from a newb needing help.</p> <hr> <p>Seems to have worked. Couple of errors in my origonal post. There were actually 280,000 images and the naming was. /home/baldy/Desktop/webcamimages/webcam_2007-05-29_163405.jpg /home/baldy/Desktop/webcamimages/webcam_2007-05-29_163505.jpg /home/baldy/Desktop/webcamimages/webcam_2007-05-29_163605.jpg</p> <p>I ran. cp $(ls | awk '{nr++; if (nr % 10 == 0) print $0}') ../newdirectory/</p> <p>Which appears to have copied the images. 70-900 per day from the looks of it.</p> <p>Now I'm running mencoder mf://*.jpg -mf w=640:h=480:fps=30:type=jpg -ovc lavc -lavcopts vcodec=msmpeg4v2 -nosound -o ../output-msmpeg4v2.avi</p> <p>I'll let you know how the movie works out.</p> <p>UPDATE: Movie did not work. Only has images from 2007 in it even though the directory has 2008 as well. webcam_2008-02-17_101403.jpg webcam_2008-03-27_192205.jpg webcam_2008-02-17_102403.jpg webcam_2008-03-27_193205.jpg webcam_2008-02-17_103403.jpg webcam_2008-03-27_194205.jpg webcam_2008-02-17_104403.jpg webcam_2008-03-27_195205.jpg</p> <p>How can I modify my mencoder line so that it uses all the images?</p>
[ { "answer_id": 71798, "author": "Pat", "author_id": 238, "author_profile": "https://Stackoverflow.com/users/238", "pm_score": 1, "selected": false, "text": "ls -1 /path/to/files/ | perl -e 'while (<STDIN>) {($seq)=/(\\d*)\\.jpg$/; print $_ if $seq && $seq % 4 ==0}'\n file_9.jpg file_10.jpg" }, { "answer_id": 71819, "author": "Leigh Caldwell", "author_id": 3267, "author_profile": "https://Stackoverflow.com/users/3267", "pm_score": 2, "selected": false, "text": "#!/bin/sh\nmv $4 ../newdirectory/\n ls *.jpg | xargs -n 4 ./move.sh\n" }, { "answer_id": 71835, "author": "Alexey Feldgendler", "author_id": 10682, "author_profile": "https://Stackoverflow.com/users/10682", "pm_score": 1, "selected": false, "text": "seq -f 'frame-%g.jpg' 1 4 number-of-frames\n" }, { "answer_id": 71871, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "files=( frame-*.jpg )\ni=0\nwhile [[ $i -lt ${#files} ]] ; do\n cur_file=${files[$i]}\n mungle_frame $cur_file\n i=$( expr $i + 4 )\ndone\n" }, { "answer_id": 71918, "author": "masto", "author_id": 11974, "author_profile": "https://Stackoverflow.com/users/11974", "pm_score": 0, "selected": false, "text": "mkdir ../outdir\nls | sort -n | while read fname; do mv \"$fname\" ../outdir/; read; read; read; done\n sort -n ls frame-123.jpg frame-4.jpg" }, { "answer_id": 73038, "author": "Iain", "author_id": 12060, "author_profile": "https://Stackoverflow.com/users/12060", "pm_score": 1, "selected": false, "text": "ls | sed -n '1~4 p' | xargs -i mv {} ../destdir/" }, { "answer_id": 73125, "author": "pjz", "author_id": 8002, "author_profile": "https://Stackoverflow.com/users/8002", "pm_score": 2, "selected": false, "text": "seq -f 'frame-%g.jpg' 1 4 number-of-frames\n for f in `seq -f 'frame-%g.jpg' 1 4 number-of-frames` ; do\n mv $f destdir/\ndone\n" }, { "answer_id": 73146237, "author": "M.Viking", "author_id": 10276092, "author_profile": "https://Stackoverflow.com/users/10276092", "pm_score": 0, "selected": false, "text": "$ echo {0000..0010..2}\n0000 0002 0004 0006 0008 0010\n curl curl -O \"http://example.com/[0-100:4].png\"\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11950/" ]
71,788
<p>I'm writing an Emacs major mode for an APL dialect I use at work. I've gotten basic font locking to work, and after setting comment-start and comment-start-skip, comment/uncomment region and fill paragraph also work.</p> <p>However, comment blocks often contain javadoc style comments and i would like fill-paragraph to avoid glueing together lines starting with such commands.</p> <p>If I have this (\ instead of javadoc @):</p> <pre><code># This is a comment that is long and should be wrapped. # \arg Description of argument # \ret Description of return value </code></pre> <p>M-q gives me:</p> <pre><code># This is a comment that is long and # should be wrapped. \arg Description # of argument \ret Description of # return value </code></pre> <p>But I want:</p> <pre><code># This is a comment that is long and # should be wrapped. # \arg Description of argument # \ret Description of return value </code></pre> <p>I've tried setting up paragraph-start and paragraph-separate to appropriate values, but fill-paragraph still doesn't work inside a comment block. If I remove the comment markers, M-q works as I want to, so the regexp I use for paragraph-start seems to work.</p> <p>Do I have to write a custom fill-paragraph for my major mode? cc-mode has one that handles cases like this, but it's really complex, I'd like to avoid it if possible. </p>
[ { "answer_id": 72637, "author": "Allen", "author_id": 6043, "author_profile": "https://Stackoverflow.com/users/6043", "pm_score": 1, "selected": false, "text": "fill-paragraph-function" }, { "answer_id": 145431, "author": "Joakim Hårsman", "author_id": 11978, "author_profile": "https://Stackoverflow.com/users/11978", "pm_score": 3, "selected": true, "text": "(setq paragraph-start \"^\\\\s-*\\\\#\\\\s-*\\\\\\\\\\\\(arg\\\\|ret\\\\).*$\")\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71788", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11978/" ]
71,817
<p>The problem: I have a class which contains a template method <code>execute</code> which calls another method <code>_execute</code>. Subclasses are supposed to overwrite <code>_execute</code> to implement some specific functionality. This functionality should be documented in the docstring of <code>_execute</code>. Advanced users can create their own subclasses to extend the library. However, another user dealing with such a subclass should only use <code>execute</code>, so he won't see the correct docstring if he uses <code>help(execute)</code>.</p> <p>Therefore it would be nice to modify the base class in such a way that in a subclass the docstring of <code>execute</code> is automatically replaced with that of <code>_execute</code>. Any ideas how this might be done?</p> <p>I was thinking of metaclasses to do this, to make this completely transparent to the user.</p>
[ { "answer_id": 72126, "author": "John Montgomery", "author_id": 5868, "author_profile": "https://Stackoverflow.com/users/5868", "pm_score": 0, "selected": false, "text": "__doc__ _execute \n\nclass MyClass(object):\n def execute(self):\n '''original doc-string'''\n self._execute()\n\nclass SubClass(MyClass):\n def _execute(self):\n '''sub-class doc-string'''\n pass\n\n # re-assign doc-string of execute\n def execute(self,*args,**kw):\n return MyClass.execute(*args,**kw)\n execute.__doc__=_execute.__doc__\n\n\n\n SubClass MyClass" }, { "answer_id": 72192, "author": "dF.", "author_id": 3002, "author_profile": "https://Stackoverflow.com/users/3002", "pm_score": 2, "selected": false, "text": "execute class Base(object):\n def execute(self):\n ...\n\nclass Derived(Base):\n def execute(self):\n \"\"\"Docstring for derived class\"\"\"\n Base.execute(self)\n ...stuff specific to Derived...\n __doc__ __doc__ execute class Derived(Base):\n def execute(self):\n return Base.execute(self)\n\n class _execute(self):\n \"\"\"Docstring for subclass\"\"\"\n ...\n\n execute.__doc__= _execute.__doc__\n execute" }, { "answer_id": 72596, "author": "Sylvain Defresne", "author_id": 5353, "author_profile": "https://Stackoverflow.com/users/5353", "pm_score": 3, "selected": true, "text": "import new\n\ndef copyfunc(func):\n return new.function(func.func_code, func.func_globals, func.func_name,\n func.func_defaults, func.func_closure)\n\nclass Metaclass(type):\n def __new__(meta, name, bases, attrs):\n for key in attrs.keys():\n if key[0] == '_':\n skey = key[1:]\n for base in bases:\n original = getattr(base, skey, None)\n if original is not None:\n copy = copyfunc(original)\n copy.__doc__ = attrs[key].__doc__\n attrs[skey] = copy\n break\n return type.__new__(meta, name, bases, attrs)\n\nclass Class(object):\n __metaclass__ = Metaclass\n def execute(self):\n '''original doc-string'''\n return self._execute()\n\nclass Subclass(Class):\n def _execute(self):\n '''sub-class doc-string'''\n pass\n" }, { "answer_id": 72785, "author": "Eli Courtwright", "author_id": 1694, "author_profile": "https://Stackoverflow.com/users/1694", "pm_score": 0, "selected": false, "text": "class Sub(Base):\n def execute(self):\n \"\"\"New docstring goes here\"\"\"\n return Base.execute(self)\n __call__ class Executor(object):\n __doc__ = property(lambda self: self.inst._execute.__doc__)\n\n def __call__(self):\n return self.inst._execute()\n\nclass Base(object):\n execute = Executor()\n\nclass Sub(Base):\n def __init__(self):\n self.execute.inst = self\n\n def _execute(self):\n \"\"\"Actually does something!\"\"\"\n return \"Hello World!\"\n\nspam = Sub()\nprint spam.execute.__doc__ # prints \"Actually does something!\"\nhelp(spam) # the execute method says \"Actually does something!\"\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71817", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11992/" ]
71,820
<p>I need a function called <code>SizeOfPipe()</code> which should return the size of a pipe - I only want to know how much data is in the pipe and not actually read data off the pipe itself. </p> <p>I thought the following code would work:</p> <pre><code>fseek (pPipe, 0 , SEEK_END); *pBytes = ftell (pPipe); rewind (pPipe); </code></pre> <p>but <code>fseek()</code> doesn't work on file descriptors. Another option would be to read the pipe then write the data back but would like to avoid this if possible. Any suggestions?</p>
[ { "answer_id": 71925, "author": "CL.", "author_id": 11654, "author_profile": "https://Stackoverflow.com/users/11654", "pm_score": 3, "selected": false, "text": "st_size fstat()" }, { "answer_id": 77381, "author": "MSN", "author_id": 6210, "author_profile": "https://Stackoverflow.com/users/6210", "pm_score": -1, "selected": false, "text": "PeekNamedPipe" }, { "answer_id": 63974916, "author": "Thomas Guyot-Sionnest", "author_id": 969196, "author_profile": "https://Stackoverflow.com/users/969196", "pm_score": 0, "selected": false, "text": "O_RDWR|O_NONBLOCK PIPE_BUF <= PIPE_BUF EAGAIN \\0 PIPE_BUF" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71820", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
71,838
<p>Does anyone know if the Infragistics UltraGrid control provides functionality similar to that of DataGridView.HitTestInfo?</p>
[ { "answer_id": 72466, "author": "Andrew", "author_id": 5662, "author_profile": "https://Stackoverflow.com/users/5662", "pm_score": 0, "selected": false, "text": ".MousePosition System.Drawing.Point" }, { "answer_id": 72687, "author": "Ryan Spears", "author_id": 11948, "author_profile": "https://Stackoverflow.com/users/11948", "pm_score": 0, "selected": false, "text": "UltraGrid grid = (UltraGrid)sender;\n\nUIElement element = grid.DisplayLayout.UIElement.ElementFromPoint(new Point(e.X, e.Y));\n UltraGridCell cell = (UltraGridCell)element.GetContext(typeof(UltraGridCell));\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71838", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11948/" ]
71,853
<p>I'm using an Xml field in my Sql Server database table. I'm trying to search a word using the XQuery <strong>contains</strong> method but it seems to search <strong>only</strong> in case sensitive mode. The lower method isn't implemented on Sql Server XQuery implementation also. ¿Is there a simple solution to this problem?</p>
[ { "answer_id": 74594, "author": "JWHEAT", "author_id": 7079, "author_profile": "https://Stackoverflow.com/users/7079", "pm_score": 3, "selected": true, "text": "DECLARE @x xml = N'abcDEF!@4';\nSELECT @x.value('fn:upper-case(/text()[1])', 'nvarchar(10)');\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71853", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
71,864
<p>I want to delete all but the 4 newest directories in my parent directory. How would you do this in Bash?</p>
[ { "answer_id": 71891, "author": "Leigh Caldwell", "author_id": 3267, "author_profile": "https://Stackoverflow.com/users/3267", "pm_score": 4, "selected": true, "text": "ls -atrd */ | head --lines=-4 | xargs rm -rf\n" }, { "answer_id": 71972, "author": "mana", "author_id": 12016, "author_profile": "https://Stackoverflow.com/users/12016", "pm_score": 1, "selected": false, "text": "#!/bin/bash\n\n#store the listing of current directory in var\nmydir=`ls -t`\nit=1\n\nfor file in $mydir\n do\n if [ $it -gt 5 ]\n then\n echo file $it will be deleted: $file\n #rm -rf $file\n fi\n it=$((it+1))\n done\n" }, { "answer_id": 72115, "author": "mdxi", "author_id": 11164, "author_profile": "https://Stackoverflow.com/users/11164", "pm_score": 0, "selected": false, "text": "#!/bin/bash\nARRAY=( `ls -td */` )\nELEMENTS=${#ARRAY[@]}\nCOUNTER=4\nwhile [ $COUNTER -lt $ELEMENTS ]; do\n echo ${ARRAY[${COUNTER}]}\n let COUNTER=COUNTER+1\ndone\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71864", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12015/" ]
71,899
<p>I'm trying to write a simple audio player for a website, and am using the EMBED... tag to embed the audio and setting HIDDEN="true" and using various javascript commands to control the audio playback. It works fine for realplayer and mplayer but the quicktime plugin doesn't respond to javascript if the hidden bit is set - is there any workaround for this?</p>
[ { "answer_id": 72107, "author": "p4bl0", "author_id": 12043, "author_profile": "https://Stackoverflow.com/users/12043", "pm_score": 2, "selected": false, "text": "object embed hidden" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
71,913
<p>Here is a sample from Kernighan &amp; Ritchie's "The C Programming Language":</p> <pre><code>int getline(char s[], int lim) { int c, i = 0; while (--lim &gt; 0; &amp;&amp; (c=getchar()) !=EOF &amp;&amp; c !='\n') { s[i++] = c; } if (c =='\n') { s[i++] = c; } s[i] = '\0'; return i; } </code></pre> <p>Why do we should check if <code>c != '\n'</code>, despite we use <code>s[i++] = c</code> after that?</p>
[ { "answer_id": 71988, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 0, "selected": false, "text": "int getline(char s[], int lim)\n{\n int c, i;\n i=0;\n /* While staying withing limit and there is a char in stdin and it's not new line sign */\n while (--lim > 0; && (c=getchar()) !=EOF && c !='\\n')\n /* Store char at the current position in array, advance current pos by one */\n s[i++] = c;\n /* If While loop stopped on new-line, store it in array, advance current pos by one */\n if (c =='\\n') \n s[i++] = c;\n /* finally terminate string with \\0 */\n s[i] = '\\0';\n return i;\n}\n" }, { "answer_id": 72017, "author": "auramo", "author_id": 4110, "author_profile": "https://Stackoverflow.com/users/4110", "pm_score": 0, "selected": false, "text": "c !='\\n' s[i++] = c; s[i++] = c;" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71913", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11972/" ]
71,920
<p>How to implement a website with a recommendation system similar to stackoverflow/digg/reddit? I.e., users submit content and the website needs to calculate some sort of "hotness" according to how popular the item is. The flow is as follows:</p> <ul> <li>Users submit content</li> <li>Other users view and vote on the content (assume 90% of the users only views content and 10% actively votes up or down on content)</li> <li>New content is continuously submitted</li> </ul> <p>How do I implement an algorithm that calculates the "hotness" of a submitted item, preferably in real-time? Are there any best-practices or design patterns?</p> <p>I would assume that the algorithm takes the following into consideration:</p> <ul> <li>When an item was submitted</li> <li>When each vote was cast</li> <li>When the item was viewed</li> </ul> <p>E.g. an item that gets a constant trickle of votes would stay somewhat "hot" constantly while an item that receives a burst of votes when it is first submitted will jump to the top of the "hotness"-list but then fall down as the votes stop coming in.</p> <p>(I am using a MySQL+PHP but I am interested in general design patterns).</p>
[ { "answer_id": 13159442, "author": "Chris Broski", "author_id": 468111, "author_profile": "https://Stackoverflow.com/users/468111", "pm_score": 1, "selected": false, "text": "SELECT id, title\nFROM videos\nORDER BY \n LOG10(ABS(cached_votes_total) + 1) * SIGN(cached_votes_total) \n + (UNIX_TIMESTAMP(created_at) / 300000) DESC\nLIMIT 50\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71920", "https://Stackoverflow.com", "https://Stackoverflow.com/users/103373/" ]
71,932
<p>I'm missing the boat on something here, kids. This keeps rearing its head and I don't know what's going on with it, so I hope my homeys here can help.</p> <p>When working in Silverlight, when I create bindings in my c# code, they never hold up when the application is running. The declarative bindings from my xaml seem ok, but I'm doing something wrong when I create my bindings in C#. I'm hoping that there is something blindingly obvious I'm missing. Here's a typical binding that gets crushed:</p> <pre><code>TextBlock tb = new TextBlock(); Binding b = new Binding("FontSize"); b.Source = this; tb.SetBinding(TextBlock.FontSizeProperty, b); </code></pre>
[ { "answer_id": 72129, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "TextBlock tb = new TextBlock();\nBinding b = new Binding(\"FontSize\");\nb.Source = this;\ntb.SetBinding(TextBlock.FontSizeProperty, b);\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71932", "https://Stackoverflow.com", "https://Stackoverflow.com/users/93/" ]
71,944
<p>I am using <code>&lt;input type="file" id="fileUpload" runat="server"&gt;</code> to upload a file in an ASP.NET application. I would like to limit the file type of the upload (example: limit to .xls or .xlsx file extensions). </p> <p>Both JavaScript or server-side validation are OK (as long as the server side validation would take place before the files are being uploaded - there could be some very large files uploaded, so any validation needs to take place before the actual files are uploaded).</p>
[ { "answer_id": 72013, "author": "staktrace", "author_id": 12050, "author_profile": "https://Stackoverflow.com/users/12050", "pm_score": 3, "selected": false, "text": "<form onsubmit=\"if (document.getElementById('fileUpload').value.match(/xls$/) || document.getElementById('fileUpload').value.match(/xlsx$/)) { alert ('Bad file type') ; return false; } else { return true; }\">...</form>\n" }, { "answer_id": 72031, "author": "AlexWilson", "author_id": 2240, "author_profile": "https://Stackoverflow.com/users/2240", "pm_score": 2, "selected": false, "text": " <asp:RegularExpressionValidator id=\"FileUpLoadValidator\" runat=\"server\" ErrorMessage=\"Upload Excel files only.\" ValidationExpression=\"^(([a-zA-Z]:)|(\\\\{2}\\w+)\\$?)(\\\\(\\w[\\w].*))(.xls|.XLS|.xlsx|.XLSX)$\" ControlToValidate=\"fileUpload\"> </asp:RegularExpressionValidator>\n <input type=\"file\" accept=\"application/msexcel\" id=\"fileUpload\" runat=\"server\">\n" }, { "answer_id": 72221, "author": "Jamie", "author_id": 8391, "author_profile": "https://Stackoverflow.com/users/8391", "pm_score": 6, "selected": true, "text": "<input type=\"file\" name=\"FILENAME\" size=\"20\" onchange=\"check_extension(this.value,\"upload\");\"/>\n<input type=\"submit\" id=\"upload\" name=\"upload\" value=\"Attach\" disabled=\"disabled\" />\n var hash = {\n 'xls' : 1,\n 'xlsx' : 1,\n};\n\nfunction check_extension(filename,submitId) {\n var re = /\\..+$/;\n var ext = filename.match(re);\n var submitEl = document.getElementById(submitId);\n if (hash[ext]) {\n submitEl.disabled = false;\n return true;\n } else {\n alert(\"Invalid filename, please select another file\");\n submitEl.disabled = true;\n\n return false;\n }\n}\n" }, { "answer_id": 3188902, "author": "shailesh", "author_id": 264813, "author_profile": "https://Stackoverflow.com/users/264813", "pm_score": 5, "selected": false, "text": "<asp:RegularExpressionValidator\nid=\"RegularExpressionValidator1\"\nrunat=\"server\"\nErrorMessage=\"Only zip file is allowed!\"\nValidationExpression =\"^.+(.zip|.ZIP)$\"\nControlToValidate=\"FileUpload1\"\n> </asp:RegularExpressionValidator>\n" }, { "answer_id": 17468608, "author": "m_cheung", "author_id": 582032, "author_profile": "https://Stackoverflow.com/users/582032", "pm_score": 2, "selected": false, "text": "private bool FileIsValid(FileUpload fileUpload)\n{\n if (!fileUpload.HasFile)\n {\n return false;\n }\n if (fileUpload.PostedFile.ContentType == \"application/vnd.ms-excel\" ||\n fileUpload.PostedFile.ContentType == \"application/excel\" ||\n fileUpload.PostedFile.ContentType == \"application/x-msexcel\" ||\n fileUpload.PostedFile.ContentType == \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\" //this is xlsx format\n )\n return true;\n\n return false;\n}\n" }, { "answer_id": 54115000, "author": "Rana", "author_id": 1964270, "author_profile": "https://Stackoverflow.com/users/1964270", "pm_score": 0, "selected": false, "text": "<asp:FileUpload ID=\"FileUpload1\" runat=\"server\" />\n<asp:Button ID=\"btnUpload\" runat=\"server\" Text=\"Upload\" OnClientClick = \"return ValidateFile()\" OnClick=\"btnUpload_Click\" />\n<br />\n<asp:Label ID=\"Label1\" runat=\"server\" Text=\"\" />\n <script type =\"text/javascript\">\n\n var validFilesTypes=[\"bmp\",\"gif\",\"png\",\"jpg\",\"jpeg\",\"doc\",\"xls\"];\n\n function ValidateFile()\n\n {\n\n var file = document.getElementById(\"<%=FileUpload1.ClientID%>\");\n\n var label = document.getElementById(\"<%=Label1.ClientID%>\");\n\n var path = file.value;\n\n var ext=path.substring(path.lastIndexOf(\".\")+1,path.length).toLowerCase();\n\n var isValidFile = false;\n\n for (var i=0; i<validFilesTypes.length; i++) \n { \n if (ext==validFilesTypes[i]) \n { \n isValidFile=true; \n break; \n } \n }\n\n if (!isValidFile) \n { \n label.style.color=\"red\"; \n label.innerHTML=\"Invalid File. Please upload a File with\" + \n \" extension:\\n\\n\"+validFilesTypes.join(\", \"); \n } \n return isValidFile; \n } \n</script>\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71944", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51/" ]
71,959
<p>I have my own class inside the file "Particles.h" and the class's implementation is inside "Particles.cpp"</p> <p>I want the file "Load.h" to recognize my classes inside there, so I've added the line</p> <pre><code>#include "Particles.h" </code></pre> <p>and the file doesn't recognize it and in the past everything was OK (I haven't made any changes inside that class).</p> <p>What should I do?</p>
[ { "answer_id": 72021, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "Stone *stone[48];\n" }, { "answer_id": 72109, "author": "CariElf", "author_id": 12117, "author_profile": "https://Stackoverflow.com/users/12117", "pm_score": 1, "selected": false, "text": "#ifndef PARTICLES_H \n#define PARTICLES_H\n\nclass CParticleWrapper\n{\n...\n};\n\n#endif\n #ifndef LOAD_H\n#define LOAD_H\n\nclass CParticleWrapper;\n\nclass CLoader\n{\n CParticleWrapper * m_pParticle;\n\npublic:\n\n CLoader(CParticleWrapper * pParticle);\n ...\n}; \n\n#endif\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71959", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
71,971
<p>My web application generates pdf files and either e-mails or faxes them to our customers. Somehow IIS6 is keeping hold of the file and blocking any other requests for it claiming the old '..the process cannot access the file 'xxx.pdf' because it is being used by another process.'</p> <p>When I recycle the application pool all is ok. Does anybody know why this is happening and how can I stop it.</p> <p>Thanks</p>
[ { "answer_id": 72093, "author": "massimogentilini", "author_id": 11673, "author_profile": "https://Stackoverflow.com/users/11673", "pm_score": 0, "selected": false, "text": "byte[] asciiBytes = getPdf(...);\ntry{\nBinaryWriter bw = new BinaryWriter(File.Create(filename));\nbw.Write(pdfBytes);\n}\nfinally {\n if(null != bw)\n bw.Close();\n}\n Response.ContentType = \"application/pdf\";\nResponse.AppendHeader(\"Content-disposition\", \"attachment; filename=\" + PDID + \".pdf\");\nResponse.WriteFile(filename);\nResponse.Flush();\n" }, { "answer_id": 72268, "author": "chakrit", "author_id": 3055, "author_profile": "https://Stackoverflow.com/users/3055", "pm_score": 4, "selected": true, "text": "Close Dispose" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71971", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11707/" ]
71,979
<p>I just came across the proposed <a href="http://web.archive.org/web/20171008232044/http://dancinghacker.com:80/code/dataflow/dataflow/introduction/dataflow.html" rel="nofollow noreferrer">Boost::Dataflow</a> library. It seems like an interesting approach and I was wondering if there are other such alternative frameworks for C++, and if there are any related design patterns. I have not ruled out Boost::Dataflow, I am just looking into any available alternatives so I can understand the domain and my options better (or roll my own if necessary).</p>
[ { "answer_id": 13454268, "author": "Alexei Kaigorodov", "author_id": 1206301, "author_profile": "https://Stackoverflow.com/users/1206301", "pm_score": 2, "selected": false, "text": "tbb::flow" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71979", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
71,980
<p>I have a BSTR object that I would like to convert to copy to a wchar__t object. The tricky thing is the length of the BSTR object could be anywhere from a few kilobytes to a few hundred kilobytes. Is there an efficient way of copying the data across? I know I could just declare a wchar_t array and alway allocate the maximum possible data it would ever need to hold. However, this would mean allocating hundreds of kilobytes of data for something that potentially might only require a few kilobytes. Any suggestions?</p>
[ { "answer_id": 72760, "author": "Mike Dimmick", "author_id": 6970, "author_profile": "https://Stackoverflow.com/users/6970", "pm_score": 2, "selected": false, "text": "BSTR BSTR BSTR wchar_t BSTR unsigned short wchar_t wchar_t /Zc:wchar_t" }, { "answer_id": 72866, "author": "Nemanja Trifunovic", "author_id": 8899, "author_profile": "https://Stackoverflow.com/users/8899", "pm_score": 2, "selected": false, "text": "BSTR" }, { "answer_id": 73928, "author": "Euro Micelli", "author_id": 2230, "author_profile": "https://Stackoverflow.com/users/2230", "pm_score": 3, "selected": false, "text": "typedef BSTR wchar_t*;\n UINT length = SysStringLen(myBstr); // Ask COM for the size of the BSTR\nwchar_t *myString = new wchar_t[length+1]; // Note: SysStringLen doesn't \n // include the space needed for the NULL\n\nwcscpy(myString, myBstr); // Or your favorite safer string function\n\n// ...\n\ndelete myString; // Done\n CComBString use .Length();\n_bstr_t use .length();\n strcpy() wcscpy()" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71980", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
71,985
<p>How can I copy a line 10 times easily in Emacs? I can't find a copy-line shortcut or function. I can use C-aC-spcC-eM-w to laboriously copy the line but how can I then paste it more than once?</p> <p>Any ideas before I go and write my own functions.</p>
[ { "answer_id": 72181, "author": "ShreevatsaR", "author_id": 4958, "author_profile": "https://Stackoverflow.com/users/4958", "pm_score": 5, "selected": true, "text": "kill-ring-save kill-region (defadvice kill-ring-save (before slickcopy activate compile)\n \"When called interactively with no active region, copy a single line instead.\"\n (interactive\n (if mark-active (list (region-beginning) (region-end))\n (list (line-beginning-position)\n (line-beginning-position 2)))))\n(defadvice kill-region (before slickcut activate compile)\n \"When called interactively with no active region, kill a single line instead.\"\n (interactive\n (if mark-active (list (region-beginning) (region-end))\n (list (line-beginning-position)\n (line-beginning-position 2)))))\n kmacro-end-and-call-macro M-x viper-mode" }, { "answer_id": 73678, "author": "cjm", "author_id": 8355, "author_profile": "https://Stackoverflow.com/users/8355", "pm_score": 2, "selected": false, "text": ";; Author: Eberhard Mattes <[email protected]>\n(defun emx-dup-line (arg)\n \"Duplicate current line.\nSet mark to the beginning of the new line.\nWith argument, do this that many times.\"\n (interactive \"*p\")\n (setq last-command 'identity) ; Don't append to kill ring\n (let ((s (point)))\n (beginning-of-line)\n (let ((b (point)))\n (forward-line)\n (if (not (eq (preceding-char) ?\\n)) (insert ?\\n))\n (copy-region-as-kill b (point))\n (while (> arg 0)\n (yank)\n (setq arg (1- arg)))\n (goto-char s))))\n (global-set-key [f9 ?d] 'emx-dup-line)\n" }, { "answer_id": 1641331, "author": "quodlibetor", "author_id": 25616, "author_profile": "https://Stackoverflow.com/users/25616", "pm_score": 0, "selected": false, "text": "(defun yank-n-times (arg)\n \"yank prefix-arg number of times. Not safe in any way.\"\n (interactive \"*p\")\n (dotimes 'arg (yank)))\n (defun yank-n-times (&optional arg)\n \"yank prefix-arg number of times. Call yank-pop if last command was yank.\"\n (interactive \"*p\")\n (if (or (string= last-command \"yank\")\n (string= last-command \"yank-pop\"))\n (yank-pop arg)\n (if (> arg 1)\n (dotimes 'arg (yank))\n (message \"Previous arg was not a yank, and called without a prefix.\"))))\n" }, { "answer_id": 74419566, "author": "Sergey V", "author_id": 13256934, "author_profile": "https://Stackoverflow.com/users/13256934", "pm_score": 0, "selected": false, "text": ";; yank n times\n(global-set-key \"\\C-y\" (lambda (n) (interactive \"*p\") (dotimes (i n) (clipboard-yank))))\n C-a C-SPC C-n M-w C-u 10 C-y\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/71985", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9831/" ]
72,010
<p>Given the following example, why do I have to explicitly use the statement <code>b-&gt;A::DoSomething()</code> rather than just <code>b-&gt;DoSomething()</code>?</p> <p>Shouldn't the compiler's overload resolution figure out which method I'm talking about?</p> <p>I'm using Microsoft VS 2005. (Note: using virtual doesn't help in this case.)</p> <pre><code>class A { public: int DoSomething() {return 0;}; }; class B : public A { public: int DoSomething(int x) {return 1;}; }; int main() { B* b = new B(); b-&gt;A::DoSomething(); //Why this? //b-&gt;DoSomething(); //Why not this? (Gives compiler error.) delete b; return 0; } </code></pre>
[ { "answer_id": 72075, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 6, "selected": true, "text": "B::DoSomething A B class B : public A {\npublic:\n using A::DoSomething;\n // …\n}\n" }, { "answer_id": 72076, "author": "Pieter", "author_id": 5822, "author_profile": "https://Stackoverflow.com/users/5822", "pm_score": 4, "selected": false, "text": "class A \n{ \n public: \n int DoSomething() {return 0;}\n}; \n\nclass B : public A \n{ \n public: \n using A::DoSomething;\n int DoSomething(int x) {return 1;} \n}; \n\n\nint main(int argc, char** argv)\n{\n B* b = new B(); \n // b->A::DoSomething(); // still works, but...\n b->DoSomething(); // works now too\n delete b; \n return 0;\n}\n" }, { "answer_id": 72081, "author": "Anthony Williams", "author_id": 5597, "author_profile": "https://Stackoverflow.com/users/5597", "pm_score": 2, "selected": false, "text": "class B : public A \n{ \n public: \n int DoSomething(int x) {return 1;}; \n using A::DoSomething;\n}; \n" }, { "answer_id": 72082, "author": "Jono", "author_id": 6552, "author_profile": "https://Stackoverflow.com/users/6552", "pm_score": 1, "selected": false, "text": "class B : public A \n{ \n public:\n using A::DoSomething;\n int DoSomething(int x) {return 1;}; \n}; \n" }, { "answer_id": 74749, "author": "James Curran", "author_id": 12725, "author_profile": "https://Stackoverflow.com/users/12725", "pm_score": 3, "selected": false, "text": "class A {} ;\nclass B :public A\n{\n void DoSomething(long) {...}\n}\n\nB b;\nb.DoSomething(1); // calls B::DoSomething((long)1));\n class A\n{\n void DoSomething(int ) {...}\n}\n B b;\nb.DoSomething(1); // calls A::DoSomething(1);\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72010", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12083/" ]
72,036
<p>What is the best way to implement mutliple Default Buttons on a ASP.NET Webform?</p> <p>I have what I think is a pretty standard page. There is a login area with user/pass field and a login button. Then elsewhere on the same page there is a single search field with a search button.</p>
[ { "answer_id": 72095, "author": "jansokoly", "author_id": 12111, "author_profile": "https://Stackoverflow.com/users/12111", "pm_score": 4, "selected": true, "text": "asp:Panel DefaultButton" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3747/" ]
72,048
<p>I admit I know enough about COM and IE architecture only to be dangerous. I have a working C# .NET ActiveX control similar to this:</p> <pre><code>using System; using System.Runtime.InteropServices; using BrowseUI; using mshtml; using SHDocVw; using Microsoft.Win32; namespace CTI { public interface CTIActiveXInterface { [DispId(1)] string GetMsg(); } [ComVisible(true), ClassInterface(ClassInterfaceType.AutoDual)] public class CTIActiveX : CTIActiveXInterface { /*** Where can I get a reference to SHDocVw.WebBrowser? *****/ SHDocVw.WebBrowser browser; public string GetMsg() { return "foo"; } } } </code></pre> <p>I registered and created a type library using regasm:</p> <pre><code>regasm CTIActiveX.dll /tlb:CTIActiveXNet.dll /codebase </code></pre> <p>And can successfully instantiate this in javascript:</p> <pre><code>var CTIAX = new ActiveXObject("CTI.CTIActiveX"); alert(CTIAX.GetMsg()); </code></pre> <p>How can I get a reference to the client site (browser window) within CTIActiveX? I have done this in a BHO by implementing IObjectWithSite, but I don't think this is the correct approach for an ActiveX control. If I implement any interface (I mean COM interface like IObjectWithSite) on CTIActiveX when I try to instantiate in Javascript I get an error that the object does not support automation.</p>
[ { "answer_id": 75086, "author": "jlew", "author_id": 7450, "author_profile": "https://Stackoverflow.com/users/7450", "pm_score": 2, "selected": false, "text": "IHtmlDocument2 Document { set; }\n public IHtmlDocument2 Document\n{\n set { _doc = value;}\n}\n CTIAX.Document = document; \n" }, { "answer_id": 75982, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "private InternetExplorer GetIEWindow(string url)\n{\n SHDocVw.ShellWindowsClass sh = new ShellWindowsClass();\n InternetExplorer IE;\n\n for (int i = 1; i <= sh.Count; i++)\n {\n IE = (InternetExplorer)sh.Item(i);\n if (IE != null)\n {\n if (IE.LocationURL.Contains(url))\n {\n return IE;\n }\n }\n }\n\n return null;\n}\n" }, { "answer_id": 10417056, "author": "MarcoM", "author_id": 1307467, "author_profile": "https://Stackoverflow.com/users/1307467", "pm_score": 0, "selected": false, "text": "public void GetBrowser()\n {\n\n ShellWindows m_IEFoundBrowsers = new ShellWindows();\n\n foreach (InternetExplorer Browser in m_IEFoundBrowsers)\n {\n webBrowser = (SHDocVw.WebBrowser) Browser;\n // do what you want ...\n }\n\n }\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
72,057
<p>I would like to have a Guile script, which implements functions, which output test result messages according to the TAP protocol.</p>
[ { "answer_id": 21836368, "author": "Yawar", "author_id": 20371, "author_profile": "https://Stackoverflow.com/users/20371", "pm_score": 2, "selected": false, "text": "spec $ ggspec -f tap\n spec/lib-spec.scm" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11886/" ]
72,070
<p>I'm executing stored procedures using SET FMTONLY ON, in order to emulate what our code generator does. However, it seems that the results are cached when executed like this, as I'm still getting a <em>Conversion failed</em> error from a proc that I have just dropped! This happens even when I execute the proc without SET FMTONLY ON.</p> <p>Can anyone please tell me what's going on here?</p>
[ { "answer_id": 232380, "author": "Rick", "author_id": 14138, "author_profile": "https://Stackoverflow.com/users/14138", "pm_score": 2, "selected": true, "text": "SET FMTONLY ON set variable SET FMTONLY on\n\nselect 1 as a\n\ndeclare @a int\nset @a = 'a'\n" }, { "answer_id": 1145031, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "SET FMTONLY OFF\n CREATE TABLE TestTable (Column1 INT, Column2 INT)\n INSERT INTO TestTable (Column1, Column2)\nVALUES (1,2)\n SELECT * FROM TestTable\n SET FMTONLY ON\n SELECT * FROM TestTable\n DROP TABLE TestTable\n SET FMTONLY OFF\n SELECT * FROM TestTable\n\nDROP TABLE TestTable\n\nSELECT * FROM TestTable\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72070", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8741/" ]
72,090
<p>I'm trying to modify my GreaseMonkey script from firing on window.onload to window.DOMContentLoaded, but this event never fires.</p> <p>I'm using FireFox 2.0.0.16 / GreaseMonkey 0.8.20080609</p> <p><a href="https://stackoverflow.com/questions/59205/enhancing-stackoverflow-user-experience">This</a> is the full script that I'm trying to modify, changing:</p> <pre><code>window.addEventListener ("load", doStuff, false); </code></pre> <p>to</p> <pre><code>window.addEventListener ("DOMContentLoaded", doStuff, false); </code></pre>
[ { "answer_id": 72245, "author": "Sam Hasler", "author_id": 2541, "author_profile": "https://Stackoverflow.com/users/2541", "pm_score": 6, "selected": true, "text": "window.addEventListener (\"load\", function() { }, false);" }, { "answer_id": 72314, "author": "PabloG", "author_id": 394, "author_profile": "https://Stackoverflow.com/users/394", "pm_score": 1, "selected": false, "text": "// ==UserScript==\n// @name Stack Overflow highlight viewed questions\n// @namespace *\n// @include http://stackoverflow.com/questions\n// @include http://stackoverflow.com/questions?*\n// @include http://stackoverflow.com/questions\n// @include http://stackoverflow.com/questions?*\n// @version 0.55 (DOM-Ready instead of onload)\n// ==/UserScript==\n\n(function() {\n\n // Customizable items\n // var fav_tags = [\"python\", \"database\", \"mysql\"]; // Your favorite tags\n const UNSEEN_BACK_COLOR = \"rgb(225,210,210)\"; // Backcolor for the question already seen\n const FAV_TAG_BACK_COLOR = \"rgb(210,210,225)\"; // Backcolor for the favorite tags\n\n // Internal to the DOM\n // const QUESTION_URL = \"http:\\/\\/stackoverflow.com\\/questions\\/([0-9]+)\\/\";\n const QUESTION_URL = \"http:\\/\\/stackoverflow.com\\/questions\\/([0-9]+)\\/\";\n const TAG_PREFIX = \"show questions tagged \";\n\n const SEEN_MARK = \"x\";\n //\n\n var seen_q = [];\n var seen_q_str = \"\";\n\n var seen_q_str = GM_getValue (\"seen_q\", \"\");\n var seen_q = seen_q_str.split(\"|\");\n\n var fav_tags_str = GM_getValue (\"fav_tags\", \"\")\n var fav_tags = fav_tags_str.split(\" \")\n\n var already_run = false;\n\n GM_registerMenuCommand (\"Set favorite tags\", askTags);\n\n // window.addEventListener (\"DOMContentLoaded\", doStuff, false);\n if (! doStuff()) {\n window.addEventListener (\"load\", doStuff, false);\n }\n\n function doStuff() {\n\n var elements = window.document.getElementsByTagName('A');\n\n if (! elements || already_run) {\n return false;\n } else {\n already_run = true;\n }\n\n GM_log (\"here\");\n\n for (elem = 0; elem < elements.length; elem++) {\n if (elements[elem].href.match (QUESTION_URL)) {\n curr_q = RegExp.$1;\n\n // Already seen?\n if ((seen_q.length < curr_q) || (seen_q [curr_q] != SEEN_MARK)) {\n elements[elem].style.backgroundColor = UNSEEN_BACK_COLOR;\n seen_q [curr_q] = SEEN_MARK;\n }\n\n // Is a favorite tag?\n node = elements[elem].parentNode.parentNode;\n for (tag = 0; tag <= fav_tags.length; tag++) {\n if (node.innerHTML.match (\"'\" + fav_tags[tag] + \"'\")) {\n node.style.backgroundColor = FAV_TAG_BACK_COLOR;\n break;\n }\n }\n\n // return (0);\n }\n }\n\n seen_q_str = seen_q.join(\"|\");\n GM_setValue (\"seen_q\", seen_q_str);\n\n return true;\n }\n\n\n function askTags() {\n fav_tags_str = prompt(\"Favorite tags (separated by spaces)\", fav_tags_str);\n GM_setValue (\"fav_tags\", fav_tags_str)\n }\n\n})();\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72090", "https://Stackoverflow.com", "https://Stackoverflow.com/users/394/" ]
72,098
<p>When using MediaWiki's markup language, the only thing that I hate is creating numbered lists. The only way I know to create a list is to do something like this:</p> <pre><code>#Item1 #Item2 </code></pre> <p>However, if I want to add spaces or some other text between those lines, the numbering gets lost. For example, the following will create text that has two number one items:</p> <pre><code>#Item1 Somestuff #Item2 </code></pre> <p>Is there any way around this, or should I just use bullet points instead? I noticed just now that the stackoverflow system does not allow numbering like this, you have to do it all manually.</p>
[ { "answer_id": 72140, "author": "finnw", "author_id": 12048, "author_profile": "https://Stackoverflow.com/users/12048", "pm_score": 5, "selected": false, "text": "#Item1\n#:Somestuff\n#Item2\n" }, { "answer_id": 630617, "author": "Adrian Archer", "author_id": 65284, "author_profile": "https://Stackoverflow.com/users/65284", "pm_score": 2, "selected": false, "text": "#Item1\nSomestuff\n<ol start=\"2\">\n<li>Item2 </li>\n</ol>\n" }, { "answer_id": 1540899, "author": "josefwells", "author_id": 72935, "author_profile": "https://Stackoverflow.com/users/72935", "pm_score": 1, "selected": false, "text": "# one\n# two<br />spanning more lines<br />doesn't break numbering\n# three\n## three point one\n## three point two\n <br> <pre> <pre></pre> &#10; # one\n#: <pre>foo&#10;bar</pre>\n" }, { "answer_id": 5713294, "author": "Leon", "author_id": 204606, "author_profile": "https://Stackoverflow.com/users/204606", "pm_score": 2, "selected": false, "text": "<source lang=javascript>\n//...\n</source>\n" }, { "answer_id": 7981273, "author": "Yap Chin Hoong", "author_id": 1025742, "author_profile": "https://Stackoverflow.com/users/1025742", "pm_score": 4, "selected": false, "text": "<ol></ol> <li></li> <pre></pre>" }, { "answer_id": 11763416, "author": "Dirk", "author_id": 451093, "author_profile": "https://Stackoverflow.com/users/451093", "pm_score": 1, "selected": false, "text": "<p> <pre> # Item 1\n# Item 2 <p><pre>Item 2 Pre Stuff</pre></p>\n# Item 3\n 1. Item 1\n2. Item 2\n [ Item 2 Pre Stuff ]\n3. Item 3\n" }, { "answer_id": 16310778, "author": "Kory Lovre", "author_id": 1721315, "author_profile": "https://Stackoverflow.com/users/1721315", "pm_score": 2, "selected": false, "text": "# one\n#:<pre>\n#:some stuff\n#:some more stuff</pre>\n# two\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72098", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
72,103
<p>I'm using a winforms webbrowser control to display some content in a windows forms app. I'm using the DocumentText property to write the generated HTML. That part is working spectacularly. Now I want to use some images in the markup. (I also would prefer to use linked CSS and JavaScript, however, that can be worked around by just embedding it.)</p> <p>I have been googling over the course of several days and can't seem to find an answer to the title question. </p> <p>I tried using a relative reference: the app exe is in the bin\debug. The images live in the "Images" directory at the root of the project. I've set the images to be copied to the output directory on compile, so they end up in bin\debug\Images*. So I then use a reference like this "Images..." thinking it will be relative to the exe. However, when I look at the image properties in the embedded browser window, I see the image URL to be "about:blankImages/*". Everything seems to be relative to "about:blank" when HTML is written to the control. Lacking a location context, I can't figure out what to use for a relative file resource reference.</p> <p>I poked around the properties of the control to see if there is a way to set something to fix this. I created a blank html page, and pointed the browser at it using the "Navigate()" method, using the full local path to the file. This worked fine with the browser reporting the local "file:///..." path to the blank page. Then I again wrote to the browser, this time using Document.Write(). Again, the browser now reports "about:blank" as the URL.</p> <p>Short of writing the dynamic HTML results to a real file, is there no other way to reference a file resource?</p> <p>I am going to try one last thing: constructing absolute file paths to the images and writing those to the HTML. My HTML is being generated using an XSL transform of a serialized object's XML so I'll need to play with some XSL parameters which will take a little extra time as I'm not that familiar with them.</p>
[ { "answer_id": 72339, "author": "Ken Wootton", "author_id": 7357, "author_profile": "https://Stackoverflow.com/users/7357", "pm_score": 4, "selected": true, "text": "public class HtmlFormatter\n{\n /// <summary>\n /// Indicator that this is a URI referencing the local\n /// file path.\n /// </summary>\n public static readonly string FILE_URL_PREFIX = \n \"file://\";\n\n /// <summary>\n /// The path separator for HTML paths.\n /// </summary>\n public const string PATH_SEPARATOR = \"/\";\n}\n\n\n// We need to add the proper paths to each image source\n// designation that match where they are being placed on disk.\nString html = HtmlFormatter.ReplaceImagePath(\n myHtml, \n HtmlFormatter.FILE_URL_PREFIX + ApplicationPath.FullAppPath + \n HtmlFormatter.PATH_SEPARATOR);\n <img src=\"file://ApplicationPath/images/myImage.gif\">\n" }, { "answer_id": 72657, "author": "Peter", "author_id": 5496, "author_profile": "https://Stackoverflow.com/users/5496", "pm_score": 1, "selected": false, "text": "XsltArgumentList lstArgs = new XsltArgumentList();\nlstArgs.AddParam(\"absoluteRoot\", string.Empty, Path.GetFullPath(\".\"));\n <img src=\"{$absoluteRoot}/Images/SilkIcons/comment_add.gif\" align=\"middle\" border=\"0\" />\n" }, { "answer_id": 886989, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "html = HtmlFormatter.ReplaceImagePathAuto(html);\n public class HtmlFormatter\n{\n\n public static readonly string FILE_URL_PREFIX = \"file://\";\n public static readonly string PATH_SEPARATOR = \"/\";\n public static String ReplaceImagePath(String html, String path)\n {\n return html.Replace(\"file://ApplicationPath/\", path);\n }\n /// <summary>\n /// Replaces URLs matching file://ApplicationPath/... with Executable Path\n /// </summary>\n /// <param name=\"html\"></param>\n /// <returns></returns>\n public static String ReplaceImagePathAuto(String html)\n {\n String executableName = System.Windows.Forms.Application.ExecutablePath;\n System.IO.FileInfo executableFileInfo = new System.IO.FileInfo(executableName);\n String executableDirectoryName = executableFileInfo.DirectoryName;\n String replaceWith = HtmlFormatter.FILE_URL_PREFIX\n + executableDirectoryName\n + HtmlFormatter.PATH_SEPARATOR;\n\n return ReplaceImagePath(html, replaceWith);\n }\n}\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5496/" ]
72,116
<p>I understand about race conditions and how with multiple threads accessing the same variable, updates made by one can be ignored and overwritten by others, but what if each thread is writing the same value (not different values) to the same variable; can even this cause problems? Could this code:</p> <p>GlobalVar.property = 11;</p> <p>(assuming that property will never be assigned anything other than 11), cause problems if multiple threads execute it at the same time?</p>
[ { "answer_id": 72571, "author": "Torne", "author_id": 12345, "author_profile": "https://Stackoverflow.com/users/12345", "pm_score": 3, "selected": false, "text": "int x = 0, y = 0;\n\n//thread A does:\nx = 1;\ny = 2;\nif (y == 2)\n print(x);\n\n//thread B does, at the same time:\nif (y == 2)\n print(x);\n" }, { "answer_id": 111469, "author": "teeks99", "author_id": 17949, "author_profile": "https://Stackoverflow.com/users/17949", "pm_score": 1, "selected": false, "text": "bool flag = false\nthreadContainer tc\nthreadInputs inputs\n\ncheck(input)\n{\n ...do stuff to input\n if(success)\n flag = true\n}\n\nstart multiple threads\nforeach(i in inputs) \n t = startthread(check, i)\n tc.add(t) // Keep track of all the threads started\n\nforeach(t in tc)\n t.join( ) // Wait until each thread is done\n\nif(flag)\n print \"One of the threads were successful\"\nelse\n print \"None of the threads were successful\"\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72116", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
72,121
<p>Let me use the following example to explain my question:</p> <pre class="lang-csharp prettyprint-override"><code>public string ExampleFunction(string Variable) { return something; } string WhatIsMyName = &quot;Hello World&quot;; string Hello = ExampleFunction(WhatIsMyName); </code></pre> <p>When I pass the variable <code>WhatIsMyName</code> to the <code>ExampleFunction</code>, I want to be able to get a string of the <em>original</em> variable's name. Perhaps something like:</p> <pre class="lang-csharp prettyprint-override"><code>Variable.OriginalName.ToString() // == &quot;WhatIsMyName&quot; </code></pre> <p>Is there any way to do this?</p>
[ { "answer_id": 72139, "author": "Gishu", "author_id": 1695, "author_profile": "https://Stackoverflow.com/users/1695", "pm_score": -1, "selected": true, "text": "NamedParameter Name Param" }, { "answer_id": 72145, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 6, "selected": false, "text": "public void ExampleFunction(Expression<Func<string, string>> f) {\n Console.WriteLine((f.Body as MemberExpression).Member.Name);\n}\n\nExampleFunction(x => WhatIsMyName);\n" }, { "answer_id": 72467, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 1, "selected": false, "text": "string sMessages(ArrayList aMessages, String sType) {\n string sReturn = String.Empty;\n if (aMessages.Count > 0) {\n sReturn += \"<p class=\\\"\" + sType + \"\\\">\";\n for (int i = 0; i < aMessages.Count; i++) {\n sReturn += aMessages[i] + \"<br />\";\n }\n sReturn += \"</p>\";\n }\n return sReturn;\n}\n output += sMessages(aErrors, \"errors\");\n" }, { "answer_id": 72706, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 0, "selected": false, "text": "static string sMessages(Expression<Func<List<string>>> aMessages) {\n var messages = aMessages.Compile()();\n\n if (messages.Count == 0) {\n return \"\";\n }\n\n StringBuilder ret = new StringBuilder();\n string sType = ((MemberExpression)aMessages.Body).Member.Name;\n\n ret.AppendFormat(\"<p class=\\\"{0}\\\">\", sType);\n foreach (string msg in messages) {\n ret.Append(msg);\n ret.Append(\"<br />\");\n }\n ret.Append(\"</p>\");\n return ret.ToString();\n}\n var errors = new List<string>() { \"Hi\", \"foo\" };\nvar ret = sMessages(() => errors);\n" }, { "answer_id": 365413, "author": "Rinat Abdullin", "author_id": 47366, "author_profile": "https://Stackoverflow.com/users/47366", "pm_score": 5, "selected": false, "text": "static void Main(string[] args)\n{\n Console.WriteLine(\"Name is '{0}'\", GetName(new {args}));\n Console.ReadLine();\n}\n\nstatic string GetName<T>(T item) where T : class\n{\n var properties = typeof(T).GetProperties();\n Enforce.That(properties.Length == 1);\n return properties[0].Name;\n}\n" }, { "answer_id": 14671261, "author": "nawfal", "author_id": 661933, "author_profile": "https://Stackoverflow.com/users/661933", "pm_score": 4, "selected": false, "text": "GetParameterName1(new { variable });\n\npublic static string GetParameterName1<T>(T item) where T : class\n{\n if (item == null)\n return string.Empty;\n\n return item.ToString().TrimStart('{').TrimEnd('}').Split('=')[0].Trim();\n}\n GetParameterName2(new { variable });\n\npublic static string GetParameterName2<T>(T item) where T : class\n{\n if (item == null)\n return string.Empty;\n\n return typeof(T).GetProperties()[0].Name;\n}\n GetParameterName3(() => variable);\n\npublic static string GetParameterName3<T>(Expression<Func<T>> expr)\n{\n if (expr == null)\n return string.Empty;\n\n return ((MemberExpression)expr.Body).Member.Name;\n}\n public static string GetParameterInfo1<T>(T item) where T : class\n{\n if (item == null)\n return string.Empty;\n\n var param = item.ToString().TrimStart('{').TrimEnd('}').Split('=');\n return \"Parameter: '\" + param[0].Trim() +\n \"' = \" + param[1].Trim();\n}\n public static string GetParameterInfo2<T>(T item) where T : class\n{\n if (item == null)\n return string.Empty;\n\n var param = typeof(T).GetProperties()[0];\n return \"Parameter: '\" + param.Name +\n \"' = \" + param.GetValue(item, null);\n}\n public static string GetParameterInfo3<T>(Expression<Func<T>> expr)\n{\n if (expr == null)\n return string.Empty;\n\n var param = (MemberExpression)expr.Body;\n return \"Parameter: '\" + param.Member.Name +\n \"' = \" + ((FieldInfo)param.Member).GetValue(((ConstantExpression)param.Expression).Value);\n}\n" }, { "answer_id": 19835965, "author": "Dipon Roy", "author_id": 2948523, "author_profile": "https://Stackoverflow.com/users/2948523", "pm_score": 2, "selected": false, "text": "public static class Utility\n{\n public static Tuple<string, TSource> GetNameAndValue<TSource>(Expression<Func<TSource>> sourceExpression)\n {\n Tuple<String, TSource> result = null;\n Type type = typeof (TSource);\n Func<MemberExpression, Tuple<String, TSource>> process = delegate(MemberExpression memberExpression)\n {\n ConstantExpression constantExpression = (ConstantExpression)memberExpression.Expression;\n var name = memberExpression.Member.Name;\n var value = ((FieldInfo)memberExpression.Member).GetValue(constantExpression.Value);\n return new Tuple<string, TSource>(name, (TSource) value);\n };\n\n Expression exception = sourceExpression.Body;\n if (exception is MemberExpression)\n {\n result = process((MemberExpression)sourceExpression.Body);\n }\n else if (exception is UnaryExpression)\n {\n UnaryExpression unaryExpression = (UnaryExpression)sourceExpression.Body;\n result = process((MemberExpression)unaryExpression.Operand);\n }\n else\n {\n throw new Exception(\"Expression type unknown.\");\n }\n\n return result;\n }\n\n\n}\n /*ToDo : Test Result*/\n static void Main(string[] args)\n {\n /*Test : primivit types*/\n long maxNumber = 123123;\n Tuple<string, long> longVariable = Utility.GetNameAndValue(() => maxNumber);\n string longVariableName = longVariable.Item1;\n long longVariableValue = longVariable.Item2;\n\n /*Test : user define types*/\n Person aPerson = new Person() { Id = \"123\", Name = \"Roy\" };\n Tuple<string, Person> personVariable = Utility.GetNameAndValue(() => aPerson);\n string personVariableName = personVariable.Item1;\n Person personVariableValue = personVariable.Item2;\n\n /*Test : anonymous types*/\n var ann = new { Id = \"123\", Name = \"Roy\" };\n var annVariable = Utility.GetNameAndValue(() => ann);\n string annVariableName = annVariable.Item1;\n var annVariableValue = annVariable.Item2;\n\n /*Test : Enum tyoes*/\n Active isActive = Active.Yes;\n Tuple<string, Active> isActiveVariable = Utility.GetNameAndValue(() => isActive);\n string isActiveVariableName = isActiveVariable.Item1;\n Active isActiveVariableValue = isActiveVariable.Item2;\n }\n" }, { "answer_id": 21219225, "author": "blooop", "author_id": 951520, "author_profile": "https://Stackoverflow.com/users/951520", "pm_score": 4, "selected": false, "text": "int testVar = 1;\nbool testBoolVar = True;\nmyConsole.Writeline(testVar);\nmyConsole.Writeline(testBoolVar);\n testVar: 1\ntestBoolVar: True\n public Dictionary<string, string> nameOfAlreadyAcessed = new Dictionary<string, string>();\n public string nameOf(object obj, int level = 1)\n {\n StackFrame stackFrame = new StackTrace(true).GetFrame(level);\n string fileName = stackFrame.GetFileName();\n int lineNumber = stackFrame.GetFileLineNumber();\n string uniqueId = fileName + lineNumber;\n if (nameOfAlreadyAcessed.ContainsKey(uniqueId))\n return nameOfAlreadyAcessed[uniqueId];\n else\n {\n System.IO.StreamReader file = new System.IO.StreamReader(fileName);\n for (int i = 0; i < lineNumber - 1; i++)\n file.ReadLine();\n string varName = file.ReadLine().Split(new char[] { '(', ')' })[1];\n nameOfAlreadyAcessed.Add(uniqueId, varName);\n return varName;\n }\n }\n" }, { "answer_id": 24078293, "author": "kernowcode", "author_id": 2088673, "author_profile": "https://Stackoverflow.com/users/2088673", "pm_score": 2, "selected": false, "text": "var myVariable = 123;\nmyVariable.Named(() => myVariable);\nvar name = myVariable.Name();\n// use name how you like\n var myVariable = 123.Named(\"my variable\");\nvar name = myVariable.Name();\n public static class ObjectInstanceExtensions\n{\n private static Dictionary<object, string> namedInstances = new Dictionary<object, string>();\n\n public static void Named<T>(this T instance, Expression<Func<T>> expressionContainingOnlyYourInstance)\n {\n var name = ((MemberExpression)expressionContainingOnlyYourInstance.Body).Member.Name;\n instance.Named(name); \n }\n\n public static T Named<T>(this T instance, string named)\n {\n if (namedInstances.ContainsKey(instance)) namedInstances[instance] = named;\n else namedInstances.Add(instance, named);\n return instance;\n } \n\n public static string Name<T>(this T instance)\n {\n if (namedInstances.ContainsKey(instance)) return namedInstances[instance];\n throw new NotImplementedException(\"object has not been named\");\n } \n}\n" }, { "answer_id": 32314158, "author": "johnny 5", "author_id": 1938988, "author_profile": "https://Stackoverflow.com/users/1938988", "pm_score": 5, "selected": false, "text": "public string ExampleFunction(string variableName) {\n //Construct your log statement using c# 6.0 string interpolation\n return $\"Error occurred in {variableName}\";\n}\n\nstring WhatIsMyName = \"Hello World\";\nstring Hello = ExampleFunction(nameof(WhatIsMyName));\n GetParameterName2(new { variable });\n\n//Hack to assure compiler warning is generated specifying this method calling conventions\n[Obsolete(\"Note you must use a single parametered AnonymousType When Calling this method\")]\npublic static string GetParameterName<T>(T item) where T : class\n{\n if (item == null)\n return string.Empty;\n\n return typeof(T).GetProperties()[0].Name;\n}\n" }, { "answer_id": 67240523, "author": "Serdar", "author_id": 638990, "author_profile": "https://Stackoverflow.com/users/638990", "pm_score": 0, "selected": false, "text": "var trace = new StackTrace(true).GetFrame(1);\nvar line = File.ReadAllLines(trace.GetFileName())[trace.GetFileLineNumber()];\nvar argumentNames = line.Split(new[] { \",\", \"(\", \")\", \";\" }, \n StringSplitOptions.TrimEntries)\n .Where(x => x.Length > 0)\n .Skip(1).ToList();\n" }, { "answer_id": 68652267, "author": "fibriZo raZiel", "author_id": 1934546, "author_profile": "https://Stackoverflow.com/users/1934546", "pm_score": 3, "selected": false, "text": "Caller* CallerMemberName CallerFilePath CallerLineNumber public static void ThrowIfNullOrWhitespace(this string self, \n [CallerArgumentExpression(\"self\")] string paramName = default)\n{\n if (self is null)\n {\n throw new ArgumentNullException(paramName);\n }\n\n if (string.IsNullOrWhiteSpace(self))\n {\n throw new ArgumentOutOfRangeException(paramName, self, \"Value cannot be whitespace\");\n } \n}\n" }, { "answer_id": 68816481, "author": "Tormod", "author_id": 80577, "author_profile": "https://Stackoverflow.com/users/80577", "pm_score": -1, "selected": false, "text": "string Hello = ExampleFunction(WhatIsMyName);\n string Hello1 = ExampleFunction(WhatIsMyName,nameof(WhatIsMyName));\nstring Hello2 = ExampleFunction(SomebodyElse,nameof(SomebodyElse));\nstring Hello3 = ExampleFunction(HerName,nameof(HerName));\n" }, { "answer_id": 69441516, "author": "hossein sedighian", "author_id": 10143546, "author_profile": "https://Stackoverflow.com/users/10143546", "pm_score": 1, "selected": false, "text": " public void showname(dynamic obj) {\n obj.GetType().GetProperties().ToList().ForEach(state => {\n NameAndValue($\"{state.Name}:{state.GetValue(obj, null).ToString()}\");\n });\n }\n var myname = \"dddd\";\n showname(new { myname });\n" }, { "answer_id": 70038692, "author": "Greg M", "author_id": 17458960, "author_profile": "https://Stackoverflow.com/users/17458960", "pm_score": 5, "selected": false, "text": "// Will throw argument exception if string IsNullOrEmpty returns true\npublic static void ValidateNotNullorEmpty(\n this string str,\n [CallerArgumentExpression(\"str\")]string strName = null\n)\n{ \n if (string.IsNullOrEmpty(str))\n {\n throw new ArgumentException($\"'{strName}' cannot be null or empty.\", strName);\n }\n}\n param.ValidateNotNullorEmpty();\n \"param cannot be null or empty.\"" }, { "answer_id": 73902688, "author": "Andy", "author_id": 1204153, "author_profile": "https://Stackoverflow.com/users/1204153", "pm_score": 0, "selected": false, "text": "#nullable enable internal static class StringExtensions\n{\n public static void ValidateNotNull(\n [NotNull] this string? theString,\n [CallerArgumentExpression(\"theString\")] string? theName = default)\n {\n if (theString is null)\n {\n throw new ArgumentException($\"'{theName}' cannot be null.\", theName);\n }\n }\n\n public static void ValidateNotNullOrEmpty(\n [NotNull] this string? theString,\n [CallerArgumentExpression(\"theString\")] string? theName = default)\n {\n if (string.IsNullOrEmpty(theString))\n {\n throw new ArgumentException($\"'{theName}' cannot be null or empty.\", theName);\n }\n }\n\n public static void ValidateNotNullOrWhitespace(\n [NotNull] this string? theString,\n [CallerArgumentExpression(\"theString\")] string? theName = default)\n {\n if (string.IsNullOrWhiteSpace(theString))\n {\n throw new ArgumentException($\"'{theName}' cannot be null or whitespace\", theName);\n }\n }\n}\n [NotNull]" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72121", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383/" ]
72,125
<p>Lets say that you have websites www.xyz.com and www.abc.com.</p> <p>Lets say that a user goes to www.abc.com and they get authenticated through the normal ASP .NET membership provider. </p> <p>Then, from that site, they get sent to (redirection, linked, whatever works) site www.xyz.com, and the intent of site www.abc.com was to pass that user to the other site as the status of isAuthenticated, so that the site www.xyz.com does not ask for the credentials of said user again.</p> <p>What would be needed for this to work? I have some constraints on this though, the user databases are completely separate, it is not internal to an organization, in all regards, it is like passing from stackoverflow.com to google as authenticated, it is that separate in nature. A link to a relevant article will suffice.</p>
[ { "answer_id": 72517, "author": "Adam Pope", "author_id": 12226, "author_profile": "https://Stackoverflow.com/users/12226", "pm_score": 2, "selected": false, "text": "<authentication mode=\"Forms\">\n <forms name=\".ASPXAUTH\" loginUrl=\"~/Login.aspx\" path=\"/\" \n protection=\"All\" \n domain=\"datasharp.co.uk\" \n enableCrossAppRedirects=\"true\" />\n\n</authentication>\n" }, { "answer_id": 73077, "author": "craigmoliver", "author_id": 12252, "author_profile": "https://Stackoverflow.com/users/12252", "pm_score": 4, "selected": true, "text": "<authentication mode=\"Forms\">\n <forms name=\".ASPXAUTH\" requireSSL=\"true\" \n protection=\"All\" \n enableCrossAppRedirects=\"true\" />\n</authentication>\n <form id=\"form1\" runat=\"server\">\n <div>\n <p><asp:Button ID=\"btnTransfer\" runat=\"server\" Text=\"Go\" PostBackUrl=\"http://otherapp/\" /></p>\n <input id=\"hdnStreetCred\" runat=\"server\" type=\"hidden\" />\n </div>\n</form>\n protected void Page_Load(object sender, EventArgs e)\n{\n FormsIdentity cIdentity = Page.User.Identity as FormsIdentity;\n if (cIdentity != null)\n {\n this.hdnStreetCred.ID = FormsAuthentication.FormsCookieName;\n this.hdnStreetCred.Value = FormsAuthentication.Encrypt(((FormsIdentity)User.Identity).Ticket);\n }\n}\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72125", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7952/" ]
72,128
<p>Using C++ (and Qt), I need to process a big amount of 3D coordinates.</p> <p>Specifically, when I receive a 3D coordinate (made of 3 doubles), I need to check in a list if this coordinate has already been processed. If not, then I process it and add it to the list (or container).</p> <p>The amount of coordinates can become very big, so I need to store the processed coordinates in a container which will ensure that checking if a 3D coordinate is already contained in the container is fast.</p> <p>I was thinking of using a map of a map of a map, storing the x coordinate, then the y coordinate then the z coordinate, but this makes it quite tedious to use, so I'm actually hoping there is a much better way to do it that I cannot think of.</p>
[ { "answer_id": 72227, "author": "zweiterlinde", "author_id": 6592, "author_profile": "https://Stackoverflow.com/users/6592", "pm_score": 0, "selected": false, "text": "map<map<map<>>>" }, { "answer_id": 72350, "author": "Roel", "author_id": 11449, "author_profile": "https://Stackoverflow.com/users/11449", "pm_score": 0, "selected": false, "text": "struct Coor {\n Coor(double x, double y, double z)\n : X(x), Y(y), Z(z) {}\n double X, Y, Z;\n}\n\nstruct coords_thesame\n{\n bool operator()(const Coor& c1, const Coor& c2) const {\n return c1.X == c2.X && c1.Y == c2.Y && c1.Z == c2.Z;\n }\n};\n\nstd::hash_map<Coor, bool, hash<Coor>, coords_thesame> m_SeenCoordinates;\n" }, { "answer_id": 72374, "author": "finnw", "author_id": 12048, "author_profile": "https://Stackoverflow.com/users/12048", "pm_score": 2, "selected": false, "text": "struct coord_eq\n{\n bool operator()(const Coordinate &s1, const Coordinate &s2) const\n {\n return s1 == s2;\n // or: return s1.x() == s2.x() && s1.y() == s2.y() && s1.z() == s2.z();\n }\n};\n\nstruct coord_hash\n{\n size_t operator()(const Coordinate &s) const\n {\n union {double d, unsigned long ul} c[3];\n c[0].d = s.x();\n c[1].d = s.y();\n c[2].d = s.z();\n return static_cast<size_t> ((3 * c[0].ul) ^ (5 * c[1].ul) ^ (7 * c[2].ul));\n }\n};\n\nstd::hash_map<Coordinate, coord_hash, coord_eq> existing_coords;\n" }, { "answer_id": 72382, "author": "xtofl", "author_id": 6610, "author_profile": "https://Stackoverflow.com/users/6610", "pm_score": 0, "selected": false, "text": "std::map #include <map>\n#include <cassert>\n\n\nstruct Point {\n double x, y, z;\n};\n\nstruct PointResult {\n};\n\nPointResult point_function( const Point& p ) { return PointResult(); }\n\n// helper: binary function for comparison of two points\nstruct point_compare {\n bool operator()( const Point& p1, const Point& p2 ) const {\n return p1.x < p2.x\n || ( p1.x == p2.x && ( p1.y < p2.y \n || ( p1.y == p2.y && p1.z < p2.z ) \n )\n );\n }\n};\n\ntypedef std::map<Point, PointResult, point_compare> pointmap;\n\nint _tmain(int argc, _TCHAR* argv[])\n{\n\npointmap pm;\n\nPoint p1 = { 0.0, 0.0, 0.0 };\nPoint p2 = { 0.1, 1.0, 1.0 };\n\npm[ p1 ] = point_function( p1 );\npm[ p2 ] = point_function( p2 );\nassert( pm.find( p2 ) != pm.end() );\n return 0;\n}\n" }, { "answer_id": 72567, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "#include <set>\n#include <cassert>\n\nconst double epsilon(1e-8);\n\nclass Coordinate {\npublic:\nCoordinate(double x, double y, double z) :\n x_(x), y_(y), z_(z) {}\n\nprivate:\ndouble x_;\ndouble y_;\ndouble z_;\n\nfriend bool operator<(const Coordinate& cl, const Coordinate& cr);\n};\n\nbool operator<(const Coordinate& cl, const Coordinate& cr) {\n if (cl.x_ < cr.x_ - epsilon) return true;\n if (cl.x_ > cr.x_ + epsilon) return false;\n\n if (cl.y_ < cr.y_ - epsilon) return true;\n if (cl.y_ > cr.y_ + epsilon) return false;\n\n if (cl.z_ < cr.z_ - epsilon) return true;\n\n return false;\n\n}\n\ntypedef std::set<Coordinate> Coordinates;\n\n// Not thread safe!\n// Return true if real processing is done\nbool Process(const Coordinate& coordinate) {\n static Coordinates usedCoordinates;\n\n // Already processed?\n if (usedCoordinates.find(coordinate) != usedCoordinates.end()) {\n return false;\n }\n\n usedCoordinates.insert(coordinate);\n\n // Here goes your processing code\n\n\n\n return true;\n\n}\n\n// Test it\nint main() {\n assert(Process(Coordinate(1, 2, 3)));\n assert(Process(Coordinate(1, 3, 3)));\n assert(!Process(Coordinate(1, 3, 3)));\n assert(!Process(Coordinate(1+epsilon/2, 2, 3)));\n}\n" }, { "answer_id": 72600, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "std::set std::vector" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2796/" ]
72,151
<p>I'm using OLEDB provider for ADO.Net connecting to an Oracle database. In my loop, I am doing an insert:</p> <pre><code>insert into ps_tl_compleave_tbl values('2626899', 0, TO_DATE('01/01/2002', 'MM/DD/YYYY'), 'LTKN', 'LTKN', '52', TO_DATE('01/01/2002', 'MM/DD/YYYY'), 16.000000, 24.000)insert into ps_tl_compleave_tbl values('4327142', 0, TO_DATE('03/23/2002', 'MM/DD/YYYY'), 'LTKN', 'LTKN', '51', TO_DATE('03/23/2002', 'MM/DD/YYYY'), 0.000000, 0.000) </code></pre> <p>The first insert succeeds but the second one gives an error:</p> <pre><code>ORA-00933: SQL command not properly ended </code></pre> <p>What am I doing wrong?</p>
[ { "answer_id": 72170, "author": "ShoeLace", "author_id": 3825, "author_profile": "https://Stackoverflow.com/users/3825", "pm_score": 2, "selected": false, "text": "BEGIN\n insert (...) into (...);\n insert (...) into (...);\nEND;\n" }, { "answer_id": 72179, "author": "massimogentilini", "author_id": 11673, "author_profile": "https://Stackoverflow.com/users/11673", "pm_score": 3, "selected": true, "text": "; insert into ps_tl_compleave_tbl values('2626899', 0, TO_DATE('01/01/2002', 'MM/DD/YYYY'), 'LTKN', 'LTKN', '52', TO_DATE('01/01/2002', 'MM/DD/YYYY'), 16.000000, 24.000) ; insert into ps_tl_compleave_tbl values('4327142', 0, TO_DATE('03/23/2002', 'MM/DD/YYYY'), 'LTKN', 'LTKN', '51', TO_DATE('03/23/2002', 'MM/DD/YYYY'), 0.000000, 0.000) ; ;" }, { "answer_id": 6056951, "author": "taranjeet", "author_id": 760830, "author_profile": "https://Stackoverflow.com/users/760830", "pm_score": 4, "selected": false, "text": "Dim db As Database = DatabaseFactory.CreateDatabase(\"db\")\nDim cmd As System.Data.Common.DbCommand\nDim sql As String = \"\"\n\nsql = \"DELETE FROM iphone_applications WHERE appid = 1; DELETE FROM iphone_applications WHERE appid = 2; \"\n\ncmd = db.GetSqlStringCommand(sql)\ndb.ExecuteNonQuery(cmd)\n BEGIN END; sql = \"BEGIN DELETE FROM iphone_applications WHERE appid = 1; DELETE FROM iphone_applications WHERE appid = 2; END;\"\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72151", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10589/" ]
72,153
<p>How can I construct a MSBuild ItemGroup to exclude .svn directories and all files within (recursively). I've got:</p> <pre><code>&lt;ItemGroup&gt; &lt;LibraryFiles Include="$(LibrariesReleaseDir)\**\*.*" Exclude=".svn" /&gt; &lt;/ItemGroup&gt; </code></pre> <p>At the moment, but this does not exclude anything!</p>
[ { "answer_id": 72536, "author": "Kieran Benton", "author_id": 5777, "author_profile": "https://Stackoverflow.com/users/5777", "pm_score": 7, "selected": true, "text": "<ItemGroup>\n <LibraryFiles Include=\"$(LibrariesReleaseDir)\\**\\*.*\" \n Exclude=\"$(LibrariesReleaseDir)\\**\\.svn\\**\" />\n</ItemGroup>\n .svn .svn\\\\** .svn" }, { "answer_id": 380954, "author": "Dave Markle", "author_id": 24995, "author_profile": "https://Stackoverflow.com/users/24995", "pm_score": 2, "selected": false, "text": "<LibraryFiles \n Include=\"$(LibrariesReleaseDir)**\\*.*\" \n Exclude=\"$(LibrariesReleaseDir)**\\.svn\\**\\*.*\"/>\n" }, { "answer_id": 612742, "author": "abombss", "author_id": 31029, "author_profile": "https://Stackoverflow.com/users/31029", "pm_score": 4, "selected": false, "text": "<CreateItem Include=\"$(MSBuildProjectDirectory)\\..\\Client\\Web\\Foo.Web.UI\\**\\*.*\"\n Exclude=\"$(MSBuildProjectDirectory)\\..\\Client\\Web\\Foo.Web.UI\\**\\.svn\\**\">\n <Output TaskParameter=\"Include\" ItemName=\"WebFiles\" />\n</CreateItem>\n <PropertyGroup>\n <WebProjectDir>$(MSBuildProjectDirectory)\\..\\Client\\Web\\Foo.Web.UI</WebProjectDir>\n</PropertyGroup>\n<CreateItem Include=\"$(WebProjectDir)\\**\\*.*\"\n Exclude=\"$(WebProjectDir)\\**\\.svn\\**\">\n <Output TaskParameter=\"Include\" ItemName=\"WebFiles\" />\n</CreateItem>\n" }, { "answer_id": 10387041, "author": "Anton Backer", "author_id": 419876, "author_profile": "https://Stackoverflow.com/users/419876", "pm_score": 1, "selected": false, "text": "<ItemGroup>\n <MyFiles Include=\".\\PathToYourStuff\\**\" />\n <MyFiles Remove=\".\\PathToYourStuff\\**\\.svn\\**\" />\n</ItemGroup>\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5777/" ]
72,167
<p>How do I find out which sound files the user has configured in the control panel?</p> <p>Example: I want to play the sound for "Device connected".</p> <p>Which API can be used to query the control panel sound settings?</p> <p>I see that there are some custom entries made by third party programs in the control panel dialog, so there has to be a way for these programs to communicate with the global sound settings.</p> <p>Edit: Thank you. I did not know that PlaySound also just played appropriate sound file when specifying the name of the registry entry.</p> <p>To play the "Device Conntected" sound:</p> <pre><code>::PlaySound( TEXT("DeviceConnect"), NULL, SND_ALIAS|SND_ASYNC ); </code></pre>
[ { "answer_id": 72250, "author": "titanae", "author_id": 2387, "author_profile": "https://Stackoverflow.com/users/2387", "pm_score": 5, "selected": true, "text": "PlaySound" }, { "answer_id": 72488, "author": "Nidonocu", "author_id": 483, "author_profile": "https://Stackoverflow.com/users/483", "pm_score": 4, "selected": false, "text": "System.Media.SystemSounds.Asterisk.Play();\n// Plays the Asterisk sound (used for Information (i))\n// Also available:\n// Exclamation (Warning /!\\)\n// Hand (aka Critical Stop - Error (X))\n// Question (?)\n// Beep (aka Default Beep)\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1810/" ]
72,176
<p>While there are 100 ways to solve the conversion problem, I am focusing on performance.</p> <p>Give that the string only contains binary data, what is the fastest method, in terms of performance, of converting that data to a byte[] (not char[]) under C#?</p> <p>Clarification: This is not ASCII data, rather binary data that happens to be in a string.</p>
[ { "answer_id": 72500, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 0, "selected": false, "text": "byte[]" }, { "answer_id": 72822, "author": "Davy Landman", "author_id": 11098, "author_profile": "https://Stackoverflow.com/users/11098", "pm_score": 3, "selected": true, "text": "public Byte[] ConvertToBytes(Char[] source)\n{\n Byte[] result = new Byte[source.Length * sizeof(Char)];\n IntPtr tempBuffer = Marshal.AllocHGlobal(result.Length);\n try\n {\n Marshal.Copy(source, 0, tempBuffer, source.Length);\n Marshal.Copy(tempBuffer, result, 0, result.Length);\n }\n finally\n {\n Marshal.FreeHGlobal(tempBuffer);\n }\n return result;\n}\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72176", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12113/" ]
72,198
<p>This seemed like an easy thing to do. I just wanted to pop up a text window and display two columns of data -- a description on the left side and a corresponding value displayed on the right side. I haven't worked with Forms much so I just grabbed the first control that seemed appropriate, a TextBox. I thought using tabs would be an easy way to create the second column, but I discovered things just don't work that well.</p> <p>There seems to be two problems with the way I tried to do this (see below). First, I read on numerous websites that the MeasureString function isn't very precise due to how complex fonts are, with kerning issues and all. The second is that I have no idea what the TextBox control is using as its StringFormat underneath.</p> <p>Anyway, the result is that I invariably end up with items in the right column that are off by a tab. I suppose I could roll my own text window and do everything myself, but gee, isn't there a simple way to do this?</p> <pre><code> TextBox textBox = new TextBox(); textBox.Font = new Font("Calibri", 11); textBox.Dock = DockStyle.Fill; textBox.Multiline = true; textBox.WordWrap = false; textBox.ScrollBars = ScrollBars.Vertical; Form form = new Form(); form.Text = "Recipe"; form.Size = new Size(400, 600); form.FormBorderStyle = FormBorderStyle.Sizable; form.StartPosition = FormStartPosition.CenterScreen; form.Controls.Add(textBox); Graphics g = form.CreateGraphics(); float targetWidth = 230; foreach (PropertyInfo property in properties) { string text = String.Format("{0}:\t", Description); while (g.MeasureString(text,textBox.Font).Width &lt; targetWidth) text += "\t"; textBox.AppendText(text + value.ToString() + "\n"); } g.Dispose(); form.ShowDialog(); </code></pre>
[ { "answer_id": 72283, "author": "Matt Dawdy", "author_id": 232, "author_profile": "https://Stackoverflow.com/users/232", "pm_score": 1, "selected": true, "text": "Private Declare Function SendMessage _\n Lib \"user32\" Alias \"SendMessageA\" _\n (ByVal handle As IntPtr, ByVal wMsg As Integer, _\n ByVal wParam As Integer, ByRef lParam As Integer) As Integer\n\n\nPrivate Sub SetTabStops(ByVal ctlTextBox As TextBox)\n\n Const EM_SETTABSTOPS As Integer = &HCBS\n\n Dim tabs() As Integer = {20, 40, 80}\n\n SendMessage(ctlTextBox.Handle, EM_SETTABSTOPS, _\n tabs.Length, tabs(0))\n\nEnd Sub\n using System.Runtime.InteropServices;\n private const int EM_SETTABSTOPS = 0x00CB;\n [DllImport(\"User32.dll\", CharSet = CharSet.Auto)]\n public static extern IntPtr SendMessage(IntPtr h, int msg, int wParam, int[] lParam);\n private void SetTabStops(TextBox ctlTextBox)\n {\n const int EM_SETTABSTOPS = 203;\n int[] tabs = { 100, 40, 80 };\n SendMessage(textBox1.Handle, EM_SETTABSTOPS, tabs.Length, tabs);\n }\n private void Form1_Load(object sender, EventArgs e)\n {\n SetTabStops(textBox1);\n\n textBox1.Text = \"Hi\\tWorld\";\n }\n" }, { "answer_id": 72659, "author": "AZDean", "author_id": 12058, "author_profile": "https://Stackoverflow.com/users/12058", "pm_score": 1, "selected": false, "text": "// This is a better way to pass in what tab stops I want...\nSetTabStops(textBox, new int[] { 12,120 });\n\n// And the code for the SetTabsStops method itself...\nprivate const uint EM_SETTABSTOPS = 0x00CB;\n\n[DllImport(\"User32.dll\")]\nprivate static extern uint SendMessage(IntPtr hWnd, uint wMsg, int wParam, int[] lParam);\n\npublic static void SetTabStops(TextBox textBox, int[] tabs)\n{\n SendMessage(textBox.Handle, EM_SETTABSTOPS, tabs.Length, tabs);\n}\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72198", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12058/" ]
72,204
<p>Has anyone used <a href="http://www.ayende.com/Blog/archive/2007/09/03/Rhino-Igloo-ndash-MVC-Framework-for-Web-Forms.aspx" rel="nofollow noreferrer">Rhino igloo</a> in a non-trivial project? I am curious if it's worth, what are its drawbacks, does it enhance testability a lot, is it easy to use. How would you compare it to a pure MVC framework (ASP.NET MVC)? Please share the experience.</p>
[ { "answer_id": 72283, "author": "Matt Dawdy", "author_id": 232, "author_profile": "https://Stackoverflow.com/users/232", "pm_score": 1, "selected": true, "text": "Private Declare Function SendMessage _\n Lib \"user32\" Alias \"SendMessageA\" _\n (ByVal handle As IntPtr, ByVal wMsg As Integer, _\n ByVal wParam As Integer, ByRef lParam As Integer) As Integer\n\n\nPrivate Sub SetTabStops(ByVal ctlTextBox As TextBox)\n\n Const EM_SETTABSTOPS As Integer = &HCBS\n\n Dim tabs() As Integer = {20, 40, 80}\n\n SendMessage(ctlTextBox.Handle, EM_SETTABSTOPS, _\n tabs.Length, tabs(0))\n\nEnd Sub\n using System.Runtime.InteropServices;\n private const int EM_SETTABSTOPS = 0x00CB;\n [DllImport(\"User32.dll\", CharSet = CharSet.Auto)]\n public static extern IntPtr SendMessage(IntPtr h, int msg, int wParam, int[] lParam);\n private void SetTabStops(TextBox ctlTextBox)\n {\n const int EM_SETTABSTOPS = 203;\n int[] tabs = { 100, 40, 80 };\n SendMessage(textBox1.Handle, EM_SETTABSTOPS, tabs.Length, tabs);\n }\n private void Form1_Load(object sender, EventArgs e)\n {\n SetTabStops(textBox1);\n\n textBox1.Text = \"Hi\\tWorld\";\n }\n" }, { "answer_id": 72659, "author": "AZDean", "author_id": 12058, "author_profile": "https://Stackoverflow.com/users/12058", "pm_score": 1, "selected": false, "text": "// This is a better way to pass in what tab stops I want...\nSetTabStops(textBox, new int[] { 12,120 });\n\n// And the code for the SetTabsStops method itself...\nprivate const uint EM_SETTABSTOPS = 0x00CB;\n\n[DllImport(\"User32.dll\")]\nprivate static extern uint SendMessage(IntPtr hWnd, uint wMsg, int wParam, int[] lParam);\n\npublic static void SetTabStops(TextBox textBox, int[] tabs)\n{\n SendMessage(textBox.Handle, EM_SETTABSTOPS, tabs.Length, tabs);\n}\n" } ]
2008/09/16
[ "https://Stackoverflow.com/questions/72204", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1801/" ]