qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
289,434
<p>I'm making a Java application with an application-logic-thread and a database-access-thread. Both of them persist for the entire lifetime of the application and both need to be running at the same time (one talks to the server, one talks to the user; when the app is fully started, I need <em>both</em> of them to work).</p> <p>However, on startup, I need to make sure that initially the app thread waits until the db thread is ready (currently determined by polling a custom method <code>dbthread.isReady()</code>). I wouldn't mind if app thread blocks until the db thread was ready.</p> <p><code>Thread.join()</code> doesn't look like a solution - the db thread only exits at app shutdown.</p> <p><code>while (!dbthread.isReady()) {}</code> kind of works, but the empty loop consumes a lot of processor cycles.</p> <p>Any other ideas? Thanks.</p>
[ { "answer_id": 289448, "author": "Klathzazt", "author_id": 35223, "author_profile": "https://Stackoverflow.com/users/35223", "pm_score": 2, "selected": false, "text": "Thread-A Locks lock-a\nRun thread-B\nThread-B waits for lock-a\nThread-A unlocks lock-a (causing Thread-B to continue)\nThread-A waits for lock-b \nThread-B completes and unlocks lock-b\n" }, { "answer_id": 289463, "author": "Herman Lintvelt", "author_id": 27602, "author_profile": "https://Stackoverflow.com/users/27602", "pm_score": 8, "selected": true, "text": "dbThread //do some work\nsynchronized(objectYouNeedToLockOn){\n while (!dbThread.isReady()){\n objectYouNeedToLockOn.wait();\n }\n}\n//continue with work after dbThread is ready\n dbThread //do db work\nsynchronized(objectYouNeedToLockOn){\n //set ready flag to true (so isReady returns true)\n ready = true;\n objectYouNeedToLockOn.notifyAll();\n}\n//end thread run method here\n objectYouNeedToLockOn Object private final Object lock = new Object();\n//now use lock in your synchronized blocks\n CountdownLatches java.util.concurrent" }, { "answer_id": 289464, "author": "WMR", "author_id": 2844, "author_profile": "https://Stackoverflow.com/users/2844", "pm_score": 3, "selected": false, "text": "java.util.concurrent" }, { "answer_id": 289470, "author": "kgiannakakis", "author_id": 24054, "author_profile": "https://Stackoverflow.com/users/24054", "pm_score": 3, "selected": false, "text": "private Exchanger<String> myDataExchanger = new Exchanger<String>();\n\n// Wait for thread's output\nString data;\ntry {\n data = myDataExchanger.exchange(\"\");\n} catch (InterruptedException e1) {\n // Handle Exceptions\n}\n try {\n myDataExchanger.exchange(data)\n} catch (InterruptedException e) {\n\n}\n" }, { "answer_id": 289490, "author": "Mario Ortegón", "author_id": 2309, "author_profile": "https://Stackoverflow.com/users/2309", "pm_score": 2, "selected": false, "text": "while (!dbthread.isReady()) {\n Thread.sleep(250);\n}\n" }, { "answer_id": 289550, "author": "Bill Michell", "author_id": 7938, "author_profile": "https://Stackoverflow.com/users/7938", "pm_score": 2, "selected": false, "text": "java.lang.concurrent" }, { "answer_id": 289567, "author": "pdeva", "author_id": 14316, "author_profile": "https://Stackoverflow.com/users/14316", "pm_score": 7, "selected": false, "text": "CountDownLatch latch = new CountDownLatch(1);\n latch.await();\n latch.countDown();\n" }, { "answer_id": 980359, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "public class ThreadEvent {\n\n private final Object lock = new Object();\n\n public void signal() {\n synchronized (lock) {\n lock.notify();\n }\n }\n\n public void await() throws InterruptedException {\n synchronized (lock) {\n lock.wait();\n }\n }\n}\n ThreadEvent resultsReady = new ThreadEvent();\n resultsReady.await();\n resultsReady.signal();\n Thread 1: resultsReady.signal();\nThread 2: resultsReady.await();\n" }, { "answer_id": 8911433, "author": "Ash", "author_id": 890381, "author_profile": "https://Stackoverflow.com/users/890381", "pm_score": 5, "selected": false, "text": "import java.util.concurrent.Callable;\nimport java.util.concurrent.ExecutionException;\nimport java.util.concurrent.ExecutorService;\nimport java.util.concurrent.Executors;\n\nimport org.junit.Test;\n\npublic class ThreadTest {\n\n public void print(String m) {\n System.out.println(m);\n }\n\n public class One implements Callable<Integer> {\n\n public Integer call() throws Exception {\n print(\"One...\");\n Thread.sleep(6000);\n print(\"One!!\");\n return 100;\n }\n }\n\n public class Two implements Callable<String> {\n\n public String call() throws Exception {\n print(\"Two...\");\n Thread.sleep(1000);\n print(\"Two!!\");\n return \"Done\";\n }\n }\n\n public class Three implements Callable<Boolean> {\n\n public Boolean call() throws Exception {\n print(\"Three...\");\n Thread.sleep(2000);\n print(\"Three!!\");\n return true;\n }\n }\n\n /**\n * @See java.util.concurrent.Future.get() doc\n * <p>\n * Waits if necessary for the computation to complete, and then\n * retrieves its result.\n */\n @Test\n public void poolRun() throws InterruptedException, ExecutionException {\n int n = 3;\n // Build a fixed number of thread pool\n ExecutorService pool = Executors.newFixedThreadPool(n);\n // Wait until One finishes it's task.\n pool.submit(new One()).get();\n // Wait until Two finishes it's task.\n pool.submit(new Two()).get();\n // Wait until Three finishes it's task.\n pool.submit(new Three()).get();\n pool.shutdown();\n }\n}\n One...\nOne!!\nTwo...\nTwo!!\nThree...\nThree!!\n" }, { "answer_id": 37135753, "author": "Ravindra babu", "author_id": 4999394, "author_profile": "https://Stackoverflow.com/users/4999394", "pm_score": 1, "selected": false, "text": "join() ExecutorService invokeAll(Collection<? extends Callable<T>> tasks)\n Executors" }, { "answer_id": 41763437, "author": "Maher Abuthraa", "author_id": 2267723, "author_profile": "https://Stackoverflow.com/users/2267723", "pm_score": 4, "selected": false, "text": "CountDownLatch //inside your currentThread.. lets call it Thread_Main\n//1\nfinal CountDownLatch latch = new CountDownLatch(1);\n\n//2\n// launch thread#2\nnew Thread(new Runnable() {\n @Override\n public void run() {\n //4\n //do your logic here in thread#2\n\n //then release the lock\n //5\n latch.countDown();\n }\n}).start();\n\ntry {\n //3 this method will block the thread of latch untill its released later from thread#2\n latch.await();\n} catch (InterruptedException e) {\n e.printStackTrace();\n}\n\n//6\n// You reach here after latch.countDown() is called from thread#2\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289434", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19746/" ]
289,438
<p>My company is currently migrating some of their really old db's to sql server 2005. Some legacy apps have problems connecting to the new server. The connection string works in Asp.NET 2.0, probably because it assumes tcp:1433 automatically.</p> <p>I have to construct the connection string like this in ASP.NET 1.1 for it to work:</p> <pre><code>"Server=tcp:my.server.com,1433;..." </code></pre> <p>Without the protocol and the port, the connection fails ("Invalid Connection exception")</p> <p>TCP 1433 and UDP 1434 are open on our firewall. On SQL Server 2005 Remote Access is enabled, so is TCPIP, the SQL Browser service is running, I use the proper login credentials.</p> <p>Any ideas why I can't just specify the server name without protocol and port number?</p>
[ { "answer_id": 289576, "author": "Soraz", "author_id": 24610, "author_profile": "https://Stackoverflow.com/users/24610", "pm_score": 1, "selected": false, "text": " local address <stuff> PID\n 0.0.0.0:1433 <some number>\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289438", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13466/" ]
289,440
<p>I have a quite big XML output from an application. I need to process it with my program and then feed it back to the original program. There are pieces in this XML which needs to be filled out our replaced. The interesting part looks like this:</p> <pre><code>&lt;sys:customtag sys:sid="1" sys:type="Processtart" /&gt; &lt;sys:tag&gt;value&lt;/sys:tag&gt; here are some other tags &lt;sys:tag&gt;value&lt;/sys.tag&gt; &lt;sys:customtag sys:sid="1" sys:type="Procesend" /&gt; </code></pre> <p>and the document contains several pieces like this.</p> <p>I need to get all XML pieces inside these tags to be able to make modifications on it. I wrote a regular expression to get those pieces but it does not work:</p> <pre><code>XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(@"output.xml"); Regex regExp = new Regex(@"&lt;sys:customtag(.*?)Processtart(.*?)/&gt;(.*?)&lt;sys:customtag (.*?)Procesend(.*?)/&gt;", RegexOptions.Multiline &amp; RegexOptions.IgnorePatternWhitespace &amp; RegexOptions.CultureInvariant); MatchCollection matches = regExp.Matches(xmlDoc.InnerXml); </code></pre> <p>If I leave the whole stuff in one line and call this regexp without the multiline option, it does find every occurences. By leaving the file as it is and set the multiline option, it does not work. What is the problem, what should I change? Or is there any easier way to get the XML parts between these tags without regexp?</p>
[ { "answer_id": 289451, "author": "Owen", "author_id": 4853, "author_profile": "https://Stackoverflow.com/users/4853", "pm_score": 7, "selected": true, "text": "RegexOptions.Singleline RegexOptions.Multiline" }, { "answer_id": 289454, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 2, "selected": false, "text": "XmlNamespaceManager string xml = @\"<foo xmlns:sys=\"\"foobar\"\"><bar/><bar><sys:customtag sys:sid=\"\"1\"\" sys:type=\"\"Processtart\"\" />\n<sys:tag>value</sys:tag>\nhere are some other tags\n<sys:tag>value</sys:tag>\n<sys:customtag sys:sid=\"\"1\"\" sys:type=\"\"Procesend\"\" /></bar><bar/></foo>\";\n\n XmlDocument doc = new XmlDocument();\n doc.LoadXml(xml);\n XmlNamespaceManager mgr = new XmlNamespaceManager(new NameTable());\n mgr.AddNamespace(\"sys\", \"foobar\");\n var matches = doc.SelectNodes(\"//sys:customtag[@sys:type='Processtart']\", mgr);\n foreach (XmlElement start in matches)\n {\n XmlElement end = (XmlElement) start.SelectSingleNode(\"following-sibling::sys:customtag[@sys:type='Procesend'][1]\",mgr);\n XmlNode node = start.NextSibling;\n while (node != null && node != end)\n {\n Console.WriteLine(node.OuterXml);\n\n node = node.NextSibling;\n }\n }\n" }, { "answer_id": 289982, "author": "user19871", "author_id": 19871, "author_profile": "https://Stackoverflow.com/users/19871", "pm_score": 3, "selected": false, "text": "MultiLine [\\s\\S] MultiLine" }, { "answer_id": 335107, "author": "Charles", "author_id": 24898, "author_profile": "https://Stackoverflow.com/users/24898", "pm_score": 2, "selected": false, "text": "Regex regExp = new Regex(@\"<sys:customtag(.*?)Processtart(.*?)/>(.*?)<sys:customtag (.*?)Procesend(.*?)/>\",\nRegexOptions.Multiline & RegexOptions.IgnorePatternWhitespace & RegexOptions.CultureInvariant);\n Regex regExp = new Regex(@\"<sys:customtag(.*?)Processtart(.*?)/>(.*?)<sys:customtag (.*?)Procesend(.*?)/>\",\nRegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.CultureInvariant);\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289440", "https://Stackoverflow.com", "https://Stackoverflow.com/users/968/" ]
289,441
<p>Is it possible to set some image as title of Navigation bar?</p> <p>I think NYTimes application used a Navigation bar and title is look like image file (the reason why it's seems <code>UINavigationBar</code> is because they use right button to search).</p>
[ { "answer_id": 289446, "author": "Kendall Helmstetter Gelner", "author_id": 6330, "author_profile": "https://Stackoverflow.com/users/6330", "pm_score": 8, "selected": true, "text": "UIImageView UINavigationItem.titleView self.navigationItem.titleView = myImageView;\n" }, { "answer_id": 295880, "author": "adam", "author_id": 33604, "author_profile": "https://Stackoverflow.com/users/33604", "pm_score": 3, "selected": false, "text": "#import <UIKit/UIKit.h>\n\n@interface UINavigationBar (CustomImage)\n - (void) setBackgroundImage:(UIImage*)image;\n - (void) clearBackgroundImage;\n - (void) removeIfImage:(id)sender;\n@end\n #import \"UINavigationBar+CustomImage.h\"\n\n@implementation UINavigationBar (CustomImage)\n\n- (void) setBackgroundImage:(UIImage*)image {\n if (image == NULL) return;\n UIImageView *imageView = [[UIImageView alloc] initWithImage:image];\n imageView.frame = CGRectMake(110,5,100,30);\n [self addSubview:imageView];\n [imageView release];\n}\n\n- (void) clearBackgroundImage {\n NSArray *subviews = [self subviews];\n for (int i=0; i<[subviews count]; i++) {\n if ([[subviews objectAtIndex:i] isMemberOfClass:[UIImageView class]]) {\n [[subviews objectAtIndex:i] removeFromSuperview];\n }\n } \n}\n\n@end \n [[navController navigationBar] performSelectorInBackground:@selector(setBackgroundImage:) withObject:image];\n" }, { "answer_id": 428434, "author": "ck.", "author_id": 53346, "author_profile": "https://Stackoverflow.com/users/53346", "pm_score": 3, "selected": false, "text": "#import \"UINavigationBar+CustomImage.h\"\n\n@implementation UINavigationBar (CustomImage)\n\n- (void) setBackgroundImage:(UIImage*)image {\n if (image == NULL) return;\n UIImageView *imageView = [[UIImageView alloc] initWithImage:image];\n imageView.frame = CGRectMake(0, 0, 320, 44);\n [self insertSubview:imageView atIndex:0];\n [imageView release];\n}\n\n- (void) clearBackgroundImage {\n NSArray *subviews = [self subviews];\n for (int i=0; i<[subviews count]; i++) {\n if ([[subviews objectAtIndex:i] isMemberOfClass:[UIImageView class]]) {\n [[subviews objectAtIndex:i] removeFromSuperview];\n }\n } \n}\n\n@end\n" }, { "answer_id": 578760, "author": "Clifton Burt", "author_id": 67229, "author_profile": "https://Stackoverflow.com/users/67229", "pm_score": 4, "selected": false, "text": "- (void)awakeFromNib {\n\n//put logo image in the navigationBar\n\nUIImageView* img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@\"logo.png\"]];\nself.navigationItem.titleView = img;\n[img release];\n\n}\n" }, { "answer_id": 2334121, "author": "J.Raza", "author_id": 281217, "author_profile": "https://Stackoverflow.com/users/281217", "pm_score": 0, "selected": false, "text": "[navController.navigationBar insertSubview:myImage atIndex:0] ;\n" }, { "answer_id": 4085310, "author": "Mr. Propa", "author_id": 495675, "author_profile": "https://Stackoverflow.com/users/495675", "pm_score": 0, "selected": false, "text": "- (void)setBackgroundImage:(UIImage *)image\n{\n if (! image) return;\n UIImageView *imageView = [[UIImageView alloc] initWithImage:image];\n imageView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);\n [self addSubview:imageView];\n [imageView release];\n}\n\n- (void) clearBackgroundImage\n{\n // This runs on a separate thread, so give it it's own pool\n NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\n NSArray *mySubviews = self.subviews;\n\n // Move in reverse direction as not to upset the order of elements in the array\n for (int i = [mySubviews count] - 1; i >= 0; i--)\n {\n if ([[mySubviews objectAtIndex:i] isMemberOfClass:[UIImageView class]])\n {\n [[mySubviews objectAtIndex:i] removeFromSuperview];\n }\n }\n\n [pool release];\n}\n" }, { "answer_id": 7382873, "author": "Ian Vink", "author_id": 172861, "author_profile": "https://Stackoverflow.com/users/172861", "pm_score": 0, "selected": false, "text": "someNiceViewControllerYouMade.NavigationController.NavigationBar\n .InsertSubview(new UIImageView\n (MediaProvider.GetImage(ImageGeneral.navBar_667x44)),0);\n" }, { "answer_id": 8150291, "author": "snez", "author_id": 451989, "author_profile": "https://Stackoverflow.com/users/451989", "pm_score": 0, "selected": false, "text": "NSArray *mySubviews = navigationBar.subviews;\nUIImageView *iv = nil;\n\n// Move in reverse direction as not to upset the order of elements in the array\nfor (int i = [mySubviews count] - 1; i >= 0; i--)\n{\n if ([[mySubviews objectAtIndex:i] isMemberOfClass:[UIImageView class]])\n {\n NSLog(@\"found background at index %d\",i);\n iv = [mySubviews objectAtIndex:i];\n [[mySubviews objectAtIndex:i] removeFromSuperview];\n [navigationBar insertSubview:iv atIndex:0];\n }\n}\n" }, { "answer_id": 12066179, "author": "joneswah", "author_id": 143318, "author_profile": "https://Stackoverflow.com/users/143318", "pm_score": 0, "selected": false, "text": "- (void) customiseMyNav\n{\n // Create resizable images\n UIImage *portraitImage = [[UIImage imageNamed:@\"nav_bar_bg_portrait\"] \n resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];\n UIImage *landscapeImage = [[UIImage imageNamed:@\"nav_bar_bg_landscape\"] \n resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];\n\n // Set the background image\n [[UINavigationBar appearance] setBackgroundImage:portraitImage forBarMetrics:UIBarMetricsDefault];\n [[UINavigationBar appearance] setBackgroundImage:landscapeImage forBarMetrics:UIBarMetricsLandscapePhone];\n\n // set the title appearance\n [[UINavigationBar appearance] setTitleTextAttributes:\n [NSDictionary dictionaryWithObjectsAndKeys:\n [UIColor colorWithRed:50.0/255.0 green:150.0/255.0 blue:100/255.0 alpha:1.0], \n UITextAttributeTextColor, \n [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.6], \n UITextAttributeTextShadowColor, \n [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], \n UITextAttributeTextShadowOffset, \n [UIFont fontWithName:@\"Arial-Bold\" size:0.0], \n UITextAttributeFont, \n nil]];\n}\n" }, { "answer_id": 12359681, "author": "Ian Vink", "author_id": 172861, "author_profile": "https://Stackoverflow.com/users/172861", "pm_score": 0, "selected": false, "text": " this.NavigationItem.TitleView = myImageView;\n" }, { "answer_id": 12680143, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@\"imageNavBar.png\"] forBarMetrics:UIBarMetricsDefault];\n" }, { "answer_id": 30894336, "author": "MrChrisBarker", "author_id": 1910305, "author_profile": "https://Stackoverflow.com/users/1910305", "pm_score": 3, "selected": false, "text": "[self.navigationController.navigationBar.topItem setTitleView:[[UIImageView alloc]initWithImage:[UIImage imageNamed:@\"YourLogo\"]]];\n" }, { "answer_id": 37925124, "author": "Dr TJ", "author_id": 451383, "author_profile": "https://Stackoverflow.com/users/451383", "pm_score": 2, "selected": false, "text": "Xamarin Forms Renderer iOS [assembly: Xamarin.Forms.ExportRenderer(typeof(Xamarin.Forms.Page), typeof(MyApp.Renderers.NavigationPageRenderer))]\nnamespace MyApp.Renderers\n{\n #region using\n\n using UIKit;\n using Xamarin.Forms.Platform.iOS;\n\n #endregion\n\n public class NavigationPageRenderer : PageRenderer\n {\n public override void ViewDidLoad()\n {\n base.ViewDidLoad();\n SetTitleImage();\n }\n\n private void SetTitleImage()\n {\n UIImage logoImage = UIImage.FromFile(ResourceFiles.ImageResources.LogoImageName);\n UIImageView logoImageView = new UIImageView(logoImage);\n\n if (this.NavigationController != null)\n {\n this.NavigationController.NavigationBar.TopItem.TitleView = logoImageView;\n }\n }\n }\n}\n" }, { "answer_id": 39037586, "author": "user3378170", "author_id": 3378170, "author_profile": "https://Stackoverflow.com/users/3378170", "pm_score": 0, "selected": false, "text": "func setupNavigationBarWithTitleImage(titleImage: UIImage) {\n\n let imageView = UIImageView(image: titleImage)\n imageView.contentMode = .ScaleAspectFit\n imageView.clipsToBounds = true\n navigationItem.titleView = imageView\n\n}\n" }, { "answer_id": 41169195, "author": "Bartłomiej Semańczyk", "author_id": 2725435, "author_profile": "https://Stackoverflow.com/users/2725435", "pm_score": 2, "selected": false, "text": "@IBDesignable @IBDesignable class AttributedNavigationBar: UINavigationBar {\n\n @IBInspectable var imageTitle: UIImage? = nil {\n\n didSet {\n\n guard let imageTitle = imageTitle else {\n\n topItem?.titleView = nil\n\n return\n }\n\n let imageView = UIImageView(image: imageTitle)\n imageView.frame = CGRect(x: 0, y: 0, width: 40, height: 30)\n imageView.contentMode = .scaleAspectFit\n\n topItem?.titleView = imageView\n }\n }\n}\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289441", "https://Stackoverflow.com", "https://Stackoverflow.com/users/451867/" ]
289,443
<p>We have a custom project management tool built in ASP,net 3.5 and we use VisualSVN for our version management. However, we are looking a way to report the version changes through the project management tool by integrating VisualSVN with our project management tool, i.e. pretty much similar to what Trac [python based SCM tool] provides. </p> <p>Basically looking for a simple VisualSVN Client API to be able to detect &amp; report the file changes based on the revision set provided.</p>
[ { "answer_id": 827418, "author": "gbjbaanb", "author_id": 13744, "author_profile": "https://Stackoverflow.com/users/13744", "pm_score": 0, "selected": false, "text": "$url = `svnlook log -r $ARGV[1] $ARGV[0]`;\n\n# check the string contains the matching regexp, \n# quit if it doesn't so we don't waste time contacting the webserver\n# this is the g_source_control_regexp value in mantis.\n\nexit 1 if not $url =~ /\\b(?:bug|issue|mantis)\\s*[#]{0,1}(\\d+)\\b/i;\n\n\n$url = $url . \"---\\nSVN Revision: \" . $ARGV[1];\n$url = $url . \"\\n\" . `svnlook dirs-changed -r $ARGV[1] $ARGV[0]`;\n\n#urlencode the string\n$url =~ s/([^\\w\\-\\.\\@])/$1 eq \" \"?\"+\": sprintf(\"%%%2.2x\",ord($1))/eg;\n\nprint \"log=$url\";\n\nexit 0;\n d:\\tools\\curl -s -d user=svn -d @c:\\temp\\postcommit_mantis.txt http://<server>/mantis/core/checkincurl.php\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289443", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
289,452
<p>Try as I might, I'm unable to resolve an address to IP. The code snippet is shown below. I keep getting the No such host is known exception, even though I could access google with my browser (The DNS server is almost certainly working). I'm however behind company's firewall.</p> <pre><code>try { foreach (IPAddress address in Dns.GetHostAddresses("www.google.com")) { Console.WriteLine(address.ToString()); } } catch (SocketException e) { Console.WriteLine("Source : " + e.Source); // System Console.WriteLine("Message : " + e.Message); // No such host is known } </code></pre>
[ { "answer_id": 289556, "author": "Luk", "author_id": 5789, "author_profile": "https://Stackoverflow.com/users/5789", "pm_score": 2, "selected": false, "text": " protected void SetupProxy(string proxyUrl, string proxyLogin, string proxyPassword, string[] proxyBypass)\n {\n WebProxy proxy = new WebProxy(proxyUrl);\n proxy.Credentials = new NetworkCredential(proxyLogin, proxyPassword);\n proxy.BypassList = proxyBypass;\n proxy.BypassProxyOnLocal = true;\n WebRequest.DefaultWebProxy = proxy;\n }\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289452", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
289,468
<p>I am working on an algorithm that will try to pick out, given an HTML file, what it thinks is the parent element that most likely contains the majority of the page's content text. For example, it would pick the div "content" in the following HTML:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;div id="header"&gt;This is the header we don't care about&lt;/div&gt; &lt;div id="content"&gt;This is the &lt;b&gt;Main Page&lt;/b&gt; content. it is the longest block of text in this document and should be chosen as most likely being the important page content.&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I have come up with a few ideas, such as traversing the HTML document tree to its leaves, adding up the length of the text, and only seeing what other text the parent has if the parent gives us more content than the children do.</p> <p>Has anyone ever tried something like this, or know of an algorithm that can be applied? It doesn't have to be solid, but as long as it can guess a container that contains most of the page content text (for articles or blog posts, for example), that would be awesome.</p>
[ { "answer_id": 290157, "author": "Borgar", "author_id": 27388, "author_profile": "https://Stackoverflow.com/users/27388", "pm_score": 3, "selected": false, "text": "// get array of all elements (body is used as parent here but you could use whatever)\nvar elms = document.body.getElementsByTagName('*');\nvar nodes = Array.prototype.slice.call( elms, 0 );\n\n// get inline elements out of the way (incomplete list)\nnodes = nodes.filter(function (elm) {\n return !/^(a|br?|hr|code|i(ns|mg)?|u|del|em|s(trong|pan))$/i.test( elm.nodeName );\n});\n\n// sort elements by most text first\nnodes.sort(function(a,b){\n if (a.textContent.length == b.textContent.length) return 0;\n if (a.textContent.length > b.textContent.length) return -1;\n return 1;\n});\n a.compareDocumentPosition(b)" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32140/" ]
289,472
<p>I just uploaded my first ASP.NET (as part of my learning of vb.net) and got into awful mess with the connection pooling (funny things happen when there are more than 1 user of your web site) all sorted now by better use of the try catch statements (well the idea was to learn) BUT I was wondering if this is the best / final method, now if the try fails, then a LOT of the detail on the page isn't placed/updated, so if you are doing some database work and the try fails, do you reload the page ... redirect to self and hope it work the next time ... or just inform the user there was a error and they should try again ?</p> <p>Thanks</p>
[ { "answer_id": 290157, "author": "Borgar", "author_id": 27388, "author_profile": "https://Stackoverflow.com/users/27388", "pm_score": 3, "selected": false, "text": "// get array of all elements (body is used as parent here but you could use whatever)\nvar elms = document.body.getElementsByTagName('*');\nvar nodes = Array.prototype.slice.call( elms, 0 );\n\n// get inline elements out of the way (incomplete list)\nnodes = nodes.filter(function (elm) {\n return !/^(a|br?|hr|code|i(ns|mg)?|u|del|em|s(trong|pan))$/i.test( elm.nodeName );\n});\n\n// sort elements by most text first\nnodes.sort(function(a,b){\n if (a.textContent.length == b.textContent.length) return 0;\n if (a.textContent.length > b.textContent.length) return -1;\n return 1;\n});\n a.compareDocumentPosition(b)" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32336/" ]
289,475
<p>I mean what the most efficient way to get information about the quantity of your page's items and make sql query with LIMIT that you need. or I should get all items and then crop array with php functions?</p> <p>now I do 2 queries: first to count all items and second to get items that I need with LIMIT. </p> <p>OK, I'll be more concrete. For example I need to show a question on my page and 20 answers to this question. At the bottom there shold be page control: links to the next, prev page and so on. I want to show proper number of links (number of answers/20) and when I go to any link I want to recieve proper answers (for example 41 to 60 on the 3d page). So what's the best way to get number of items (answers) to show proper number of links and to get proper answers for each link?</p>
[ { "answer_id": 289497, "author": "Josh Smeaton", "author_id": 10583, "author_profile": "https://Stackoverflow.com/users/10583", "pm_score": 2, "selected": true, "text": "select count(*) as counted, name, address\nfrom contact\n SELECT SQL_CALC_FOUND_ROWS, name, address\nfrom contact\n" }, { "answer_id": 289641, "author": "Stein G. Strindhaug", "author_id": 26115, "author_profile": "https://Stackoverflow.com/users/26115", "pm_score": 2, "selected": false, "text": "select count(*) from tblX where something select * from tblX where something limit Y offset Z (requested_page - 1)*Y" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37590/" ]
289,483
<p>I have two machines setup to run Visual Studio 2008 (SP1) &amp; NET Framework 3.5 (SP1). If I create a .tt file in a console appliaction on machine #1 it automatically creates the sub .cs file for me, however if I do the exact same on machine #2 then no sub .cs file is created.</p> <p>I have tried toggling the "Show All Files" option, restarting visual studio (multiple times), added new <code>.tt</code> files (with the same outcome), tried it in both a C# and a VB.NET project and Google is drawing up blanks. </p> <p>Is it possible for T4 text templates to have been disabled somehow? If so, then how the heck do I turn them back on, it's annoying :-).?</p>
[ { "answer_id": 289497, "author": "Josh Smeaton", "author_id": 10583, "author_profile": "https://Stackoverflow.com/users/10583", "pm_score": 2, "selected": true, "text": "select count(*) as counted, name, address\nfrom contact\n SELECT SQL_CALC_FOUND_ROWS, name, address\nfrom contact\n" }, { "answer_id": 289641, "author": "Stein G. Strindhaug", "author_id": 26115, "author_profile": "https://Stackoverflow.com/users/26115", "pm_score": 2, "selected": false, "text": "select count(*) from tblX where something select * from tblX where something limit Y offset Z (requested_page - 1)*Y" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289483", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25319/" ]
289,498
<p>How do I run a batch file each time windows boots up also I need to run it in the back ground(without that command window getting displayed)? I use Windows Xp. My actuall requirement is I want to start the Tracd server using the command line commands whenever Windows boots up.</p>
[ { "answer_id": 289500, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 6, "selected": true, "text": "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run registry key\nHKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run registry key \n wscript.exe \"C:\\yourpath\\invis.vbs\" \"your_file.bat\"\n CreateObject(\"Wscript.Shell\").Run \"\"\"\" & WScript.Arguments(0) & \"\"\"\", 0, False\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289498", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13440/" ]
289,512
<p>I can't figure out how to define the default constructor (when it exists overloads) for a type in StructureMap (version 2.5) by code.</p> <p>I want to get an instance of a service and the container has to inject a Linq2Sql data context instance into it.</p> <p>I wrote this in my 'bootstrapper' method :</p> <pre><code>ForRequestedType&lt;MyDataContext&gt;().TheDefault.Is.OfConcreteType&lt;MyDataContext&gt;(); </code></pre> <p>When I run my app, I got this error :</p> <blockquote> <p>StructureMap Exception Code: 202<br> No Default Instance defined for PluginFamily MyNamespace.Data.SqlRepository.MyDataContext, MyNamespace.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</p> </blockquote> <p>If I comment out all Linq2Sql generated contructors that I don't need, it works fine.</p> <p>Update : Oh, and I forgot to say that I would not use the <code>[StructureMap.DefaultConstructor]</code> attribute.</p>
[ { "answer_id": 298392, "author": "PeterFromCologne", "author_id": 36546, "author_profile": "https://Stackoverflow.com/users/36546", "pm_score": 6, "selected": true, "text": "ForRequestedType<MyDataContext>().TheDefault.\nIs.ConstructedBy(() => new MyDataContext());\n" }, { "answer_id": 2437241, "author": "njappboy", "author_id": 37658, "author_profile": "https://Stackoverflow.com/users/37658", "pm_score": 3, "selected": false, "text": "ForRequestedType< MyDataContext >()\n .CacheBy( InstanceScope.PerRequest )\n .TheDefault.Is.OfConcreteType< MyDataContext >()\n\nSelectConstructor< MyDataContext >( () => new MyDataContext());\n SelectConstructor< MyDataContext >( () => new MyDataContext((IDatabaseFactory)null ));\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289512", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37592/" ]
289,513
<p>I need a javascript regex pattern to match a person's height to check if the input is valid. Here are some sample input:</p> <p>5' 9"</p> <p>6'</p> <p>5'8"</p> <p>Any ideas?</p>
[ { "answer_id": 289516, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 1, "selected": false, "text": "\\d'(?:\\s*\\d+'')?\n \\b\\d'(?:\\s*\\d+'')?\\b\n" }, { "answer_id": 289538, "author": "Andrew Hedges", "author_id": 11577, "author_profile": "https://Stackoverflow.com/users/11577", "pm_score": 0, "selected": false, "text": "^\\d'\\s?(\\d{1,2}\")?$\n" }, { "answer_id": 289546, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 3, "selected": false, "text": "/^(3-7)'(?:\\s*(?:1[01]|0-9)(''|\"))?$/\n \" ''" }, { "answer_id": 289547, "author": "Ruben", "author_id": 21733, "author_profile": "https://Stackoverflow.com/users/21733", "pm_score": 2, "selected": false, "text": "^(\\d{1,5})\\'((\\s?)(-?)(\\s?)([0-9]|(1[0-1]))\\\")?$ \n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289513", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
289,518
<p>How do I make icons for my exe file when compiling my Python program?</p>
[ { "answer_id": 289544, "author": "UnkwnTech", "author_id": 115, "author_profile": "https://Stackoverflow.com/users/115", "pm_score": 2, "selected": false, "text": "'name':APP_NAME,\n'version':'1.0',\n'description':'',\n'author':'',\n'author_email':'',\n'url':'',\n\n'py2exe.target':'',\n'py2exe.icon':'icon.ico', #64x64\n'py2exe.binary':APP_NAME, #leave off the .exe, it will be added\n\n'py2app.target':'',\n'py2app.icon':'icon.icns', #128x128\n\n'cx_freeze.cmd':'~/src/cx_Freeze-3.0.3/FreezePython',\n'cx_freeze.target':'',\n'cx_freeze.binary':APP_NAME,\n}\n" }, { "answer_id": 289590, "author": "Ali Afshar", "author_id": 28380, "author_profile": "https://Stackoverflow.com/users/28380", "pm_score": 2, "selected": false, "text": "png2ico myicon.ico logo16x16.png logo32x32.png\n" }, { "answer_id": 418579, "author": "mark", "author_id": 52232, "author_profile": "https://Stackoverflow.com/users/52232", "pm_score": 2, "selected": false, "text": "python Makespec.py -i 'mine.ico' /path/to/file.py\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
289,523
<p>I want to use Oracle exception to handle errors that might happen in the code below. If a user provides the book ID and/or employee ID that doesn't exist in the database, NO_DATA_FOUND exception will be raised. Thus, how can I know which statement raises this exception.</p> <pre><code>CREATE OR REPLACE PROCEDURE TEST_EXCEPTION ( book_id_in IN book.book_id%TYPE, emp_id_in IN emp.emp_id%TYPE ) IS v_book_desc book.description%TYPE; v_emp_name emp.emp_name%TYPE; BEGIN SELECT description into v_book_desc FROM book WHERE book_id = book_id_in; ... SELECT emp_name into v_emp_name FROM emp WHERE emp_id = emp_id_in; ... EXCEPTION WHEN NO_DATA_FOUND THEN /* Do something */ END TEST_EXCEPTION; </code></pre> <p>I appreciate any suggestion or guidance. Thank you.</p>
[ { "answer_id": 289530, "author": "Ali Ersöz", "author_id": 4215, "author_profile": "https://Stackoverflow.com/users/4215", "pm_score": 2, "selected": true, "text": "CREATE OR REPLACE PROCEDURE TEST_EXCEPTION ( book_id_in IN book.book_id%TYPE, emp_id_in IN emp.emp_id%TYPE ) IS\n\nv_book_desc book.description%TYPE; v_emp_name emp.emp_name%TYPE;\nstatementIndex number(1, 0);\n\nBEGIN\n\nstatementIndex := 1;\nSELECT description into v_book_desc FROM book WHERE book_id = book_id_in;\n\n...\n\nstatementIndex := 2;\nSELECT emp_name into v_emp_name FROM emp WHERE emp_id = emp_id_in;\n\n...\n\nEXCEPTION WHEN NO_DATA_FOUND THEN \nif statementIndex = 1\nthen \n/* Do something */\nelse\n/* Do something */\nendif;\n\nEND TEST_EXCEPTION;\n" }, { "answer_id": 289597, "author": "Dheer", "author_id": 17266, "author_profile": "https://Stackoverflow.com/users/17266", "pm_score": 3, "selected": false, "text": "CREATE OR REPLACE PROCEDURE TEST_EXCEPTION (\n book_id_in IN book.book_id%TYPE,\n emp_id_in IN emp.emp_id%TYPE )\nIS\n\nv_book_desc book.description%TYPE; v_emp_name emp.emp_name%TYPE;\nstatementIndex number(1, 0);\n\nBEGIN\n\n BEGIN\n\n SELECT description into v_book_desc FROM book WHERE book_id = book_id_in;\n\n EXCEPTION WHEN NO_DATA_FOUND THEN \n -- do your handling or raise a custom exception to be handled at end\n END; \n\n BEGIN\n\n SELECT emp_name into v_emp_name FROM emp WHERE emp_id = emp_id_in;\n\n EXCEPTION WHEN NO_DATA_FOUND THEN \n -- do your handling or raise a custom exception to be handled at end\n END; \n\nEXCEPTION WHEN_OTHERS THEN \n\nEND TEST_EXCEPTION;\n CREATE OR REPLACE PROCEDURE TEST_EXCEPTION ( book_id_in IN book.book_id%TYPE, emp_id_in IN emp.emp_id%TYPE ) IS\n\nv_book_desc book.description%TYPE; v_emp_name emp.emp_name%TYPE;\nstatementIndex number(1, 0);\n\nBEGIN\n\nstatementIndex := 1;\nSELECT description into v_book_desc FROM book WHERE book_id = book_id_in;\n\n...\n\nstatementIndex := 2;\nSELECT emp_name into v_emp_name FROM emp WHERE emp_id = emp_id_in;\n\n...\n\nEXCEPTION WHEN NO_DATA_FOUND THEN \nif statementIndex = 1\nthen \n/* Do something */\nelse\n/* Do something */\nendif;\n\nEND TEST_EXCEPTION;\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289523", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1602746/" ]
289,527
<p>I have checked in a huge Eclipse project from my desktop computer to the SVN server. I did it using the command line. However, by mistake I committed all the compiled classes also in the server.</p> <p>For every plug-in, there is a directory /bin/ that contains the compiled classes.</p> <p>Is there a way to quickly delete in the server all directories that match this pattern using the command line?</p> <p>Additionally, is there a way to tell svn to ignore bin directories by default?</p>
[ { "answer_id": 289531, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 3, "selected": true, "text": "'svn rm --keep-local'" }, { "answer_id": 289539, "author": "Jason Coco", "author_id": 34218, "author_profile": "https://Stackoverflow.com/users/34218", "pm_score": 2, "selected": false, "text": "~/.subversion/config\n HKCU\\Software\\Tigris.org\\Config\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289527", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2309/" ]
289,529
<p>I am new to decoding techniques and have just learnt about base64, sha-1, md5 and a few others yesterday. </p> <p>I have been trying to figure out what "orkut" worms actually contain. </p> <p>I was attacked by many orkut spammers and hackers in the past few days, and there is a similarity in the URLs that they send to us. </p> <p>I don't know what information it contains but I need to figure it out. </p> <p>The problem lies in the following texts:</p> <pre><code>Foo+bZGMiDsstRKVgpjhlfxMVpM= lmKpr4+L6caaXii9iokloJ1A4xQ= </code></pre> <p>The encoding above appears to be base64 but it is not, because whenever I try to decode it using online base64 decoders, I get raw output and it doesn't decode accurately. </p> <p>Maybe some other code has been mixed with base64. </p> <p>Can anyone please help me to decode it?</p>
[ { "answer_id": 294110, "author": "geocar", "author_id": 37507, "author_profile": "https://Stackoverflow.com/users/37507", "pm_score": 2, "selected": false, "text": "JSHDF[\"Page.signature.raw\"]" }, { "answer_id": 1035429, "author": "maxwellb", "author_id": 118098, "author_profile": "https://Stackoverflow.com/users/118098", "pm_score": 0, "selected": false, "text": "Foo+bZGMiDsstRKVgpjhlfxMVpM= bZGMiDsstRKVgpjhlfxMVpM= { 6D 91 8C 88 3B 2C B5 12 95 82 98 E1 95 FC 4C 56 93 } +" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289529", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37600/" ]
289,537
<p>Does anyone know a simple algorithm to check if a Sudoku-Configuration is valid? The simplest algorithm I came up with is (for a board of size n) in Pseudocode</p> <pre><code>for each row for each number k in 1..n if k is not in the row (using another for-loop) return not-a-solution ..do the same for each column </code></pre> <p>But I'm quite sure there must be a better (in the sense of more elegant) solution. Efficiency is quite unimportant.</p>
[ { "answer_id": 289666, "author": "Ralph M. Rickenbach", "author_id": 4549416, "author_profile": "https://Stackoverflow.com/users/4549416", "pm_score": 1, "selected": false, "text": "when the sum of each row/column/box equals n*(n+1)/2\nand the product equals n!\nwith n = number of rows or columns\n for i = 0 to n-1 do\n boxsum[i] := 0;\n colsum[i] := 0;\n rowsum[i] := 0;\n boxprod[i] := 1;\n colprod[i] := 1;\n rowprod[i] := 1; \nend;\n\nfor i = 0 to n-1 do\n for j = 0 to n-1 do\n box := (i div n^1/2) + (j div n^1/2)*n^1/2;\n boxsum[box] := boxsum[box] + cell[i,j];\n boxprod[box] := boxprod[box] * cell[i,j];\n colsum[i] := colsum[i] + cell[i,j];\n colprod[i] := colprod[i] * cell[i,j];\n rowsum[j] := colsum[j] + cell[i,j];\n rowprod[j] := colprod[j] * cell[i,j];\n end;\nend;\n\nfor i = 0 to n-1 do\n if boxsum[i] <> 45\n or colsum[i] <> 45\n or rowsum[i] <> 45\n or boxprod[i] <> 362880\n or colprod[i] <> 362880\n or rowprod[i] <> 362880\n return false;\n" }, { "answer_id": 289673, "author": "Marco M.", "author_id": 28375, "author_profile": "https://Stackoverflow.com/users/28375", "pm_score": 0, "selected": false, "text": "bool CheckSudoku(int[,] sudoku)\n{\n int flag = 0;\n\n// Check rows\nfor(int row = 0; row < 9; row++)\n{\n flag = 0;\n for (int col = 0; col < 9; col++)\n {\n // edited : check range step (see comments)\n if ((sudoku[row, col] < 1)||(sudoku[row, col] > 9)) \n {\n return false;\n }\n\n // if n-th bit is set.. but you can use a bool array for readability\n if ((flag & (1 << sudoku[row, col])) != 0) \n {\n return false;\n }\n\n // set the n-th bit\n flag |= (1 << sudoku[row, col]); \n }\n}\n\n// Check columns\nfor(int col= 0; col < 9; col++)\n{\n flag = 0;\n for (int row = 0; row < 9; row++)\n {\n if ((flag & (1 << sudoku[row, col])) != 0)\n {\n return false;\n }\n flag |= (1 << sudoku[row, col]);\n }\n}\n\n// Check 3x3 boxes\nfor(int box= 0; box < 9; box++)\n{\n flag = 0;\n for (int ofs = 0; ofs < 9; ofs++)\n {\n int col = (box % 3) * 3;\n int row = ((int)(box / 3)) * 3;\n\n if ((flag & (1 << sudoku[row, col])) != 0)\n {\n return false;\n }\n flag |= (1 << sudoku[row, col]);\n }\n}\nreturn true;\n" }, { "answer_id": 289749, "author": "Bryan", "author_id": 30418, "author_profile": "https://Stackoverflow.com/users/30418", "pm_score": 0, "selected": false, "text": "grid [0-(n-1)][0-(n-1)]; //this is the input grid\n//each verification takes n^2 bits, so three verifications gives us 3n^2\nboolean VArray (3*n*n) //make sure this is initialized to false\n\n\nfor i = 0 to n\n for j = 0 to n\n /*\n each coordinate consists of three parts\n row/col/box start pos, index offset, val offset \n */\n\n //to validate rows\n VArray( (0) + (j*n) + (grid[i][j]-1) ) = 1\n //to validate cols\n VArray( (n*n) + (i*n) + (grid[i][j]-1) ) = 1\n //to validate boxes\n VArray( (2*n*n) + (3*(floor (i/3)*n)+ floor(j/3)*n) + (grid[i][j]-1) ) = 1\n next \nnext\n\nif every array value is true then the solution is correct. \n" }, { "answer_id": 289906, "author": "Josh Smeaton", "author_id": 10583, "author_profile": "https://Stackoverflow.com/users/10583", "pm_score": 0, "selected": false, "text": "array = [1,2,3,4,5,6,7,8,9] \nsudoku = int [][]\npuzzle = 9 #9x9\ncolumns = map []\nunits = map [] # box \nunit_l = 3 # box width/height\ncheck_puzzle() \n\n\ndef strike_numbers(line, line_num, columns, units, unit_l):\n count = 0\n for n in line:\n # check which unit we're in\n unit = ceil(n / unit_l) + ceil(line_num / unit_l) # this line is wrong - rushed\n if units[unit].contains(n): #is n in unit already?\n return columns, units, 1\n units[unit].add(n)\n if columns[count].contains(n): #is n in column already?\n return columns, units, 1\n columns[count].add(n)\n line.remove(n) #remove num from temp row\n return columns, units, line.length # was a number not eliminated?\n\ndef check_puzzle(columns, sudoku, puzzle, array, units):\n for (i=0;i< puzzle;i++):\n columns, units, left_over = strike_numbers(sudoku[i], i, columns, units) # iterate through rows\n if (left_over > 0): return false\n" }, { "answer_id": 801916, "author": "Hao Wooi Lim", "author_id": 31728, "author_profile": "https://Stackoverflow.com/users/31728", "pm_score": 1, "selected": false, "text": "char VerifySudoku(char grid[81])\n{\n for (char r = 0; r < 9; ++r)\n {\n unsigned int bigFlags = 0;\n\n for (char c = 0; c < 9; ++c)\n {\n unsigned short buffer = r/3*3+c/3;\n\n // check horizontally\n bitFlags |= 1 << (27-grid[(r<<3)+r+c]) \n // check vertically\n | 1 << (18-grid[(c<<3)+c+r])\n // check subgrids\n | 1 << (9-grid[(buffer<<3)+buffer+r%3*3+c%3]);\n\n }\n\n if (bitFlags != 0x7ffffff)\n return 0; // invalid\n }\n\n return 1; // valid\n}\n" }, { "answer_id": 802109, "author": "SPWorley", "author_id": 74222, "author_profile": "https://Stackoverflow.com/users/74222", "pm_score": 3, "selected": false, "text": "result=0;\nfor each entry:\n result |= 1<<(value-1)\nreturn (result==511);\n" }, { "answer_id": 1562168, "author": "StriplingWarrior", "author_id": 120955, "author_profile": "https://Stackoverflow.com/users/120955", "pm_score": 2, "selected": false, "text": "5" }, { "answer_id": 5538117, "author": "Kami", "author_id": 588291, "author_profile": "https://Stackoverflow.com/users/588291", "pm_score": 3, "selected": false, "text": "def check(sud):\n zippedsud = zip(*sud)\n\n boxedsud=[]\n for li,line in enumerate(sud):\n for box in range(3):\n if not li % 3: boxedsud.append([]) # build a new box every 3 lines\n boxedsud[box + li/3*3].extend(line[box*3:box*3+3])\n\n for li in range(9):\n if [x for x in [set(sud[li]), set(zippedsud[li]), set(boxedsud[li])] if x != set(range(1,10))]:\n return False\n return True \n sudoku=[\n[7, 5, 1, 8, 4, 3, 9, 2, 6],\n[8, 9, 3, 6, 2, 5, 1, 7, 4], \n[6, 4, 2, 1, 7, 9, 5, 8, 3],\n[4, 2, 5, 3, 1, 6, 7, 9, 8],\n[1, 7, 6, 9, 8, 2, 3, 4, 5],\n[9, 3, 8, 7, 5, 4, 6, 1, 2],\n[3, 6, 4, 2, 9, 7, 8, 5, 1],\n[2, 8, 9, 5, 3, 1, 4, 6, 7],\n[5, 1, 7, 4, 6, 8, 2, 3, 9]]\n\nprint check(sudoku) \n" }, { "answer_id": 11055624, "author": "jpiasetz", "author_id": 379580, "author_profile": "https://Stackoverflow.com/users/379580", "pm_score": 0, "selected": false, "text": "int checkSudoku(int board[]) {\n int i;\n int check[13] = { 0 };\n\n for (i = 0; i < 81; i++) {\n if (i % 9 == 0) {\n check[9] = 0;\n if (i % 27 == 0) {\n check[10] = 0;\n check[11] = 0;\n check[12] = 0;\n }\n }\n\n if (check[i % 9] & (1 << board[i])) {\n return 0;\n }\n check[i % 9] |= (1 << board[i]);\n\n if (check[9] & (1 << board[i])) {\n return 0;\n }\n check[9] |= (1 << board[i]);\n\n if (i % 9 < 3) {\n if (check[10] & (1 << board[i])) {\n return 0;\n }\n check[10] |= (1 << board[i]);\n } else if (i % 9 < 6) {\n if (check[11] & (1 << board[i])) {\n return 0;\n }\n check[11] |= (1 << board[i]);\n } else {\n if (check[12] & (1 << board[i])) {\n return 0;\n }\n check[12] |= (1 << board[i]);\n }\n }\n}\n" }, { "answer_id": 16776436, "author": "user2425429", "author_id": 2425429, "author_profile": "https://Stackoverflow.com/users/2425429", "pm_score": 1, "selected": false, "text": "for(int i=0; i<field.length(); i++){\n for(int j=0; j<field[i].length; j++){\n if(field[i][j]>9||field[i][j]<1){\n checking=false;\n break;\n }\n else{\n col[field[i].length()-j][i]=field[i][j];\n }\n }\n}\n /*array name goes here*/[i].contains(1)&&/*array name goes here*/[i].contains(2)" }, { "answer_id": 16781751, "author": "user2425429", "author_id": 2425429, "author_profile": "https://Stackoverflow.com/users/2425429", "pm_score": 0, "selected": false, "text": "boolean checkers=true;\nString checking=\"\";\n if(a.length/3==1){}\n else{\n for(int l=1; l<a.length/3; l++){\n for(int n=0;n<3*l;n++){\n for(int lm=1; lm<a[n].length/3; lm++){\n for(int m=0;m<3*l;m++){\n System.out.print(\" \"+a[n][m]);\n if(a[n][m]<=0){\n System.out.print(\" (Values must be positive!) \");\n }\n if(n==0){\n if(m!=0){\n checking+=\", \"+a[n][m];\n }\n else{\n checking+=a[n][m];\n }\n }\n else{\n checking+=\", \"+a[n][m];\n }\n }\n }\n System.out.print(\" \"+checking);\n System.out.println();\n }\n }\n for (int i=1;i<=a.length*a[1].length;i++){\n if(checking.contains(Integer.toString(i))){\n\n }\n else{\n checkers=false;\n }\n }\n }\n checkers=checkCol(a);\n if(checking.contains(\"-\")&&!checking.contains(\"--\")){\n checkers=false;\n }\n System.out.println();\n if(checkers==true){\n System.out.println(\"This is correct! YAY!\");\n }\n else{\n System.out.println(\"Sorry, it's not right. :-(\");\n }\n}\nprivate static boolean checkCol(int[][]a){\n boolean checkers=true;\n int[][]col=new int[][]{{0,0,0},{0,0,0},{0,0,0}};\n for(int i=0; i<a.length; i++){\n for(int j=0; j<a[i].length; j++){\n if(a[i][j]>9||a[i][j]<1){\n checkers=false;\n break;\n }\n else{\n col[a[i].length-j][i]=a[i][j];\n }\n }\n }\n String alia=\"\";\n for(int i=0; i<col.length; i++){\n for(int j=1; j<=col[i].length; j++){\n alia=a[i].toString();\n if(alia.contains(\"\"+j)){\n alia=col[i].toString();\n if(alia.contains(\"\"+j)){}\n else{\n checkers=false;\n } \n }\n else{\n checkers=false;\n }\n }\n }\n return checkers;\n}\n" }, { "answer_id": 19331218, "author": "bjrnt", "author_id": 300664, "author_profile": "https://Stackoverflow.com/users/300664", "pm_score": 1, "selected": false, "text": "from itertools import chain \n\ndef valid(puzzle): \n def get_block(x,y): \n return chain(*[puzzle[i][3*x:3*x+3] for i in range(3*y, 3*y+3)]) \n rows = [set(row) for row in puzzle] \n columns = [set(column) for column in zip(*puzzle)] \n blocks = [set(get_block(x,y)) for x in range(0,3) for y in range(0,3)] \n return all(map(lambda s: s == set([1,2,3,4,5,6,7,8,9]), rows + columns + blocks)) \n" }, { "answer_id": 46186964, "author": "Nick Locking", "author_id": 37313, "author_profile": "https://Stackoverflow.com/users/37313", "pm_score": 0, "selected": false, "text": "import UIKit\n\nfunc check(_ sudoku:[[Int]]) -> Bool {\n\n var groups = Array(repeating: 0, count: 27)\n\n for x in 0...8 {\n for y in 0...8 {\n groups[x] += 1 << sudoku[x][y] // Column (group 0 - 8)\n groups[y + 9] += 1 << sudoku[x][y] // Row (group 9 - 17)\n groups[(x + y * 9) / 9 + 18] += 1 << sudoku[x][y] // Box (group 18 - 27)\n }\n }\n\n return groups.filter{ $0 != 1022 }.count == 0\n}\n\nlet sudoku = [\n [7, 5, 1, 8, 4, 3, 9, 2, 6],\n [8, 9, 3, 6, 2, 5, 1, 7, 4],\n [6, 4, 2, 1, 7, 9, 5, 8, 3],\n [4, 2, 5, 3, 1, 6, 7, 9, 8],\n [1, 7, 6, 9, 8, 2, 3, 4, 5],\n [9, 3, 8, 7, 5, 4, 6, 1, 2],\n [3, 6, 4, 2, 9, 7, 8, 5, 1],\n [2, 8, 9, 5, 3, 1, 4, 6, 7],\n [5, 1, 7, 4, 6, 8, 2, 3, 9]\n]\n\nif check(sudoku) {\n print(\"Pass\")\n} else {\n print(\"Fail\")\n}\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289537", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18670/" ]
289,559
<p>The C++ standard dictates that member variables inside a single access section must be layed out in memory in the same order they were declared in. At the same time, compilers are free to choose the mutual ordering of the access sections themselves. This freedom makes it impossible in theory to link binaries created by different compilers. So what are the remaining reasons for the strict in-section ordering? And does the <s>upcoming C++09</s> new C++11 standard provide a way to fully determine object layouts "by hand"?</p>
[ { "answer_id": 289671, "author": "Sunlight", "author_id": 33650, "author_profile": "https://Stackoverflow.com/users/33650", "pm_score": 4, "selected": true, "text": "operator new delete class struct [u]int[8|16|32|64]_t" }, { "answer_id": 289679, "author": "Ricardo Amores", "author_id": 10136, "author_profile": "https://Stackoverflow.com/users/10136", "pm_score": 0, "selected": false, "text": "struct example\n{\n int16 intData;\n byte byteData;\n int32 intData;\n byte intData;\n int32 intData;\n}\n struct example\n{\n int16 intData;\n byte byteData;\n byte intData;\n int32 intData;\n int32 intData;\n}\n" }, { "answer_id": 289988, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 0, "selected": false, "text": "offsetof std::pair<T, U>" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289559", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37602/" ]
289,568
<p>The C++ standard imposes an ordering on class member variables in memory. It says that the addresses of member variables have to increase in the order of declaration, but only inside one access section. Very specifically, this does not seem to prevent compilers from laying out access sections in an interleaved way. For example:</p> <pre><code>class X { public: int i; int j; private: int k; int n; } </code></pre> <p>Does the standard allow compilers to lay out the data members in the order i, k, j, n? This would give compilers some (limited) freedom in optimizing object layout without violating the standard.</p>
[ { "answer_id": 290159, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 2, "selected": false, "text": "Implementation alignment require-\nments might cause two adjacent members not to be allocated immediately after each other; so might\nrequirements for space for managing virtual functions (10.3) and virtual base classes (10.1).\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289568", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37602/" ]
289,572
<p>Is there a USB HID pen driver in Windows Vista? If so, what are the requirements for USB descriptors, in order to make Windows Vista recognize the pen and load the pen driver?</p> <p>What I'm searching for is the pen equivalent to the HID mouse driver, HID keyboard driver and mass storage driver. The mentioned example drivers makes it possible for Windows, Linux and Mac OS to recognize mouse, keyboard and memory sticks without installing new drivers.</p> <p>Windows Vista has a lot of native support for pen, and it is possible to define a USB pen device only using standard HID usage tables (from a USB protocol point of view). So far I'm able to make USB HID descriptors that qualify as mouse and keyboard (from OS point of view), and automatically uses the standard driver supplied by the OS. </p> <p>For my Pen, however, Windows Vista just loads the generic HID driver, and does not realize that the device is a "pen". The motivation for defining a pen rather than a mouse with absolute coordinates, is that Vista supports special features like "gestures", but this is only enabled for Pen/Digitizer devices.</p>
[ { "answer_id": 290159, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 2, "selected": false, "text": "Implementation alignment require-\nments might cause two adjacent members not to be allocated immediately after each other; so might\nrequirements for space for managing virtual functions (10.3) and virtual base classes (10.1).\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289572", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
289,578
<p>Recently when I looked into iPhone memory management, I tried to compare the convenience method and init method on the same object. For example, I have UIImageView where it displays a downloaded NSData:</p> <p>Convenience method:</p> <pre><code>imageView.image = [UIImage imageWithData:[downloads dataAtIndex:0]]; </code></pre> <p>init method:</p> <pre><code>UIImage *aImage = [[UIImage alloc] initWithData:[downloads dataAtIndex:0]]; imageView.image = aImage; [aImage release]; </code></pre> <p>When I try to go back and forth on the views to increase the memory usage and hit "Simulate Memory Warning", the memory usage for the app went from 20MB to 18MB with convenience method, and init method went from 20MB to 13MB immediately.</p> <p>I also waited and interacted with the app to give time on releasing on the convenience method's autorelease. But it didn't drop much.</p> <p>Other than the autorelease vs release, what else contributed the difference?</p>
[ { "answer_id": 290816, "author": "wisequark", "author_id": 33159, "author_profile": "https://Stackoverflow.com/users/33159", "pm_score": 2, "selected": false, "text": "NSAutoreleasePool" }, { "answer_id": 860623, "author": "Heat Miser", "author_id": 3484, "author_profile": "https://Stackoverflow.com/users/3484", "pm_score": 1, "selected": false, "text": "myProperty = [NSMutableArray arrayWithCapacity:10];\n self.myProperty = [NSMutableArray arrayWithCapacity:10];\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30883/" ]
289,586
<p>How can I check which version of Apache is installed on a Debian machine? </p> <p>Is there a command for doing this?</p>
[ { "answer_id": 289589, "author": "Todd Gamblin", "author_id": 9122, "author_profile": "https://Stackoverflow.com/users/9122", "pm_score": 9, "selected": false, "text": "$ apachectl -V\nServer version: Apache/2.2.9 (Unix)\nServer built: Sep 18 2008 21:54:05\nServer's Module Magic Number: 20051115:15\nServer loaded: APR 1.2.7, APR-Util 1.2.7\nCompiled using: APR 1.2.7, APR-Util 1.2.7\n... etc ...\n sudo" }, { "answer_id": 289595, "author": "Chad", "author_id": 37309, "author_profile": "https://Stackoverflow.com/users/37309", "pm_score": 2, "selected": false, "text": "nmap -A localhost -p 80" }, { "answer_id": 289617, "author": "pindiwala", "author_id": 37603, "author_profile": "https://Stackoverflow.com/users/37603", "pm_score": 2, "selected": false, "text": "apachectl -V apachectl fullstatus" }, { "answer_id": 6956524, "author": "eaykin", "author_id": 143179, "author_profile": "https://Stackoverflow.com/users/143179", "pm_score": 5, "selected": false, "text": "apache:/etc/apache2# apache2ctl -v\nServer version: Apache/2.2.16 (Debian)\nServer built: May 12 2011 11:58:18\n apache2 -V\nServer version: Apache/2.2.16 (Debian)\nServer built: May 12 2011 11:58:18\nServer's Module Magic Number: x\nServer loaded: APR 1.4.2, APR-Util 1.3.9\nCompiled using: APR 1.2.12, APR-Util 1.3.9\nArchitecture: 64-bit\nServer MPM: Worker\n threaded: yes (fixed thread count)\n forked: yes (variable process count)\nServer compiled with....\n" }, { "answer_id": 8972054, "author": "Elzo Valugi", "author_id": 95353, "author_profile": "https://Stackoverflow.com/users/95353", "pm_score": 7, "selected": false, "text": "$ /usr/sbin/apache2 -v\n" }, { "answer_id": 24468572, "author": "merlinuwe", "author_id": 3786265, "author_profile": "https://Stackoverflow.com/users/3786265", "pm_score": 3, "selected": false, "text": "/usr/local/apache/bin** $ **./apachectl -v\n" }, { "answer_id": 25894768, "author": "Yogesh Yadav", "author_id": 3790959, "author_profile": "https://Stackoverflow.com/users/3790959", "pm_score": 4, "selected": false, "text": "apachectl -V\n-bash: apachectl: command not found\n\nsudo apachectl -V\nServer version: Apache/2.4.6 (Debian)\nServer built: Aug 12 2013 18:20:23\nServer's Module Magic Number: 20120211:24\nServer loaded: APR 1.4.8, APR-UTIL 1.5.3\nCompiled using: APR 1.4.8, APR-UTIL 1.5.2\nArchitecture: 32-bit\nServer MPM: prefork\n threaded: no\n forked: yes (variable process count)\nServer compiled with....\nbla bla....\n" }, { "answer_id": 26012069, "author": "Dinesh", "author_id": 932345, "author_profile": "https://Stackoverflow.com/users/932345", "pm_score": 5, "selected": false, "text": "httpd -V\n" }, { "answer_id": 29534702, "author": "Balmipour", "author_id": 2472389, "author_profile": "https://Stackoverflow.com/users/2472389", "pm_score": 4, "selected": false, "text": "dpkg -l | grep apache\n" }, { "answer_id": 30995114, "author": "Raptor", "author_id": 188331, "author_profile": "https://Stackoverflow.com/users/188331", "pm_score": 3, "selected": false, "text": "apt-cache policy <package_name>\n apt-cache policy apache2\n Installed $ apt-cache policy apache2\napache2:\n Installed: (none)\n Candidate: 2.2.22-1ubuntu1.9\n Version table:\n 2.2.22-1ubuntu1.9 0\n 500 http://hk.archive.ubuntu.com/ubuntu/ precise-updates/main amd64 Packages\n 500 http://security.ubuntu.com/ubuntu/ precise-security/main amd64 Packages\n 2.2.22-1ubuntu1 0\n 500 http://hk.archive.ubuntu.com/ubuntu/ precise/main amd64 Packages\n" }, { "answer_id": 33664157, "author": "RDB", "author_id": 2792765, "author_profile": "https://Stackoverflow.com/users/2792765", "pm_score": 3, "selected": false, "text": "./apachectl -v\n Server version: Apache/2.2.20 (Unix)\nServer built: Sep 6 2012 17:22:16\n" }, { "answer_id": 35808757, "author": "Keshav Dial", "author_id": 6020784, "author_profile": "https://Stackoverflow.com/users/6020784", "pm_score": 5, "selected": false, "text": "apachectl -v\n httpd -v\n apache2 -v\n -v # gives you the version number\n-V # gives you the compile settings including version number.\n whereis whereis httpd\n" }, { "answer_id": 38796938, "author": "agc", "author_id": 6136214, "author_profile": "https://Stackoverflow.com/users/6136214", "pm_score": 1, "selected": false, "text": "dlocate -s apache2 | grep '^Version:'\n" }, { "answer_id": 39411499, "author": "luis.espinal", "author_id": 201722, "author_profile": "https://Stackoverflow.com/users/201722", "pm_score": 2, "selected": false, "text": "strings binutils httpd /foo/bar $ strings /foo/bar/httpd | grep 2.2\nGLIBC_2.2.5\nOracle-HTTP-Server/2.2.22 (Unix)\nSuccess_Accepted_202\n202 Accepted\n" }, { "answer_id": 40461707, "author": "xgqfrms", "author_id": 5934465, "author_profile": "https://Stackoverflow.com/users/5934465", "pm_score": 3, "selected": false, "text": "apachectl -V apachectl -v xgqfrms:~/workspace $ apachectl -v\n\n Server version: Apache/2.4.7 (Ubuntu)\n Server built: Jul 15 2016 15:34:04\n\n\n xgqfrms:~/workspace $ apachectl -V\n\n Server version: Apache/2.4.7 (Ubuntu)\n Server built: Jul 15 2016 15:34:04\n Server's Module Magic Number: 20120211:27\n Server loaded: APR 1.5.1-dev, APR-UTIL 1.5.3\n Compiled using: APR 1.5.1-dev, APR-UTIL 1.5.3\n Architecture: 64-bit\n Server MPM: prefork\n threaded: no\n forked: yes (variable process count)\n Server compiled with....\n -D APR_HAS_SENDFILE\n -D APR_HAS_MMAP\n -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)\n -D APR_USE_SYSVSEM_SERIALIZE\n -D APR_USE_PTHREAD_SERIALIZE\n -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n -D APR_HAS_OTHER_CHILD\n -D AP_HAVE_RELIABLE_PIPED_LOGS\n -D DYNAMIC_MODULE_LIMIT=256\n -D HTTPD_ROOT=\"/etc/apache2\"\n -D SUEXEC_BIN=\"/usr/lib/apache2/suexec\"\n -D DEFAULT_PIDLOG=\"/var/run/apache2.pid\"\n -D DEFAULT_SCOREBOARD=\"logs/apache_runtime_status\"\n -D DEFAULT_ERRORLOG=\"logs/error_log\"\n -D AP_TYPES_CONFIG_FILE=\"mime.types\"\n -D SERVER_CONFIG_FILE=\"apache2.conf\" apache2 -V apache2 -v xgqfrms:~/workspace $ apache2 -v\n\n Server version: Apache/2.4.7 (Ubuntu)\n Server built: Jul 15 2016 15:34:04\n\n\n xgqfrms:~/workspace $ apache2 -V\n\n Server version: Apache/2.4.7 (Ubuntu)\n Server built: Jul 15 2016 15:34:04\n Server's Module Magic Number: 20120211:27\n Server loaded: APR 1.5.1-dev, APR-UTIL 1.5.3\n Compiled using: APR 1.5.1-dev, APR-UTIL 1.5.3\n Architecture: 64-bit\n Server MPM: prefork\n threaded: no\n forked: yes (variable process count)\n Server compiled with....\n -D APR_HAS_SENDFILE\n -D APR_HAS_MMAP\n -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)\n -D APR_USE_SYSVSEM_SERIALIZE\n -D APR_USE_PTHREAD_SERIALIZE\n -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n -D APR_HAS_OTHER_CHILD\n -D AP_HAVE_RELIABLE_PIPED_LOGS\n -D DYNAMIC_MODULE_LIMIT=256\n -D HTTPD_ROOT=\"/etc/apache2\"\n -D SUEXEC_BIN=\"/usr/lib/apache2/suexec\"\n -D DEFAULT_PIDLOG=\"/var/run/apache2.pid\"\n -D DEFAULT_SCOREBOARD=\"logs/apache_runtime_status\"\n -D DEFAULT_ERRORLOG=\"logs/error_log\"\n -D AP_TYPES_CONFIG_FILE=\"mime.types\"\n -D SERVER_CONFIG_FILE=\"apache2.conf\"" }, { "answer_id": 42287593, "author": "Defrag", "author_id": 7503589, "author_profile": "https://Stackoverflow.com/users/7503589", "pm_score": 2, "selected": false, "text": "<?php\n phpinfo();\n?>\n" }, { "answer_id": 43596364, "author": "Tsvetomir Tsvetkov", "author_id": 7894013, "author_profile": "https://Stackoverflow.com/users/7894013", "pm_score": 4, "selected": false, "text": "dpkg -l |grep apache2\n dpkg -l |grep apache2\n ii apache2 2.4.10-10+deb8u8 amd64 Apache HTTP Server\nii apache2-bin 2.4.10-10+deb8u8 amd64 Apache HTTP Server (modules and other binary files)\nii apache2-data 2.4.10-10+deb8u8 all Apache HTTP Server (common files)\nii apache2-doc 2.4.10-10+deb8u8 all Apache HTTP Server (on-site documentation)\n apache2ctl -V |grep -i \"Server version\"\n" }, { "answer_id": 71149135, "author": "Mansoor", "author_id": 18060431, "author_profile": "https://Stackoverflow.com/users/18060431", "pm_score": 0, "selected": false, "text": "/usr/sbin/apache2 -v\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289586", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37603/" ]
289,601
<p><strong>Sorry answer found while typing</strong> </p> <p>I am trying to connect to an external webservice that requires username/password authentication through a proxy. I am using Visual Studio Express 2008 to generate a service reference</p> <ul> <li>I have connected to the same webservice using a web reference.We only had to set a larger timeout because it takes a long time to finish. </li> <li>I have connected to another webservice that does not require username/password authentication with a generated service reference and some settings to get it through the proxy. </li> </ul> <p>So my thought would be to take this reference, point it to the correct webservice and add authentication.</p> <p>The config I am using without security:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;configuration&gt; &lt;system.net&gt; &lt;defaultProxy useDefaultCredentials="true"&gt; &lt;proxy bypassonlocal="False" proxyaddress="http://***.***.****:80" /&gt; &lt;/defaultProxy&gt; &lt;/system.net&gt; &lt;system.serviceModel&gt; &lt;bindings&gt; &lt;customBinding&gt; &lt;binding name="AreaWebServiceSoap12"&gt; &lt;textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap12" writeEncoding="utf-8"&gt; &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt; &lt;/textMessageEncoding&gt; &lt;httpTransport manualAddressing="false" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous" realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true" /&gt; &lt;/binding&gt; &lt;/customBinding&gt; &lt;/bindings&gt; &lt;client&gt; &lt;endpoint address="http://www.****.*****.****.com/samplewebservice/service.asmx" binding="customBinding" bindingConfiguration="AreaWebServiceSoap12" contract="ServiceReference1.ServiceSoap" name="ServiceSoap" /&gt; &lt;/client&gt; &lt;/system.serviceModel&gt; &lt;/configuration&gt; </code></pre> <p>I have added te following code to my call for authentication:</p> <pre><code>static void Main(string[] args) { ServiceSoapClient s = new ServiceSoapClient(); s.ClientCredentials.UserName.UserName = @"username"; s.ClientCredentials.UserName.Password = @"password"; Service.RawGpsData[] result = s.GetRawGpsData(0); Console.WriteLine(String.Format("done:{0}",result.Length)); Console.ReadLine(); } </code></pre> <p>Just using this setup gives an error as expected:</p> <p><em>The HTTP request is not authorized with client authentication scheme Anonymous. The authentication header from the server is received, is NTLM.</em></p> <p>Now I get lost and start trying silly things because I am just starting to use WCF.</p> <p>When I add the following section to the config</p> <pre><code> &lt;security authenticationMode="UserNameOverTransport"&gt;&lt;/security&gt; </code></pre> <p>I get the following error:</p> <p><em>The binding CustomBinding.http: / / tempuri.org / for the contract AreaWebServiceSoap.AreaWebServices is configured with a verification mode for which a transport level with integrity and confidentiality is required. The transport can not provide integrity and confidentiality.</em></p> <p>Sorry, while typing this question I stumbled upon the answer myself. I still think people might be interested in this and all comments and thoughts are still welcome. So I will leave the question here and make it community and post the answer myself.</p>
[ { "answer_id": 289607, "author": "KeesDijk", "author_id": 6434, "author_profile": "https://Stackoverflow.com/users/6434", "pm_score": 3, "selected": true, "text": "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<customBinding>\n <binding name=\"AreaWebServiceSoap12\" closeTimeout=\"00:01:00\" openTimeout=\"00:10:00\"\n receiveTimeout=\"00:20:00\" sendTimeout=\"00:05:00\">\n <textMessageEncoding maxReadPoolSize=\"64\" maxWritePoolSize=\"16\"\n messageVersion=\"Soap12\" writeEncoding=\"utf-8\">\n <readerQuotas maxDepth=\"32\" maxStringContentLength=\"8192\" maxArrayLength=\"16384\"\n maxBytesPerRead=\"4096\" maxNameTableCharCount=\"16384\" />\n </textMessageEncoding> \n <httpTransport manualAddressing=\"false\" maxBufferPoolSize=\"524288\" \n maxReceivedMessageSize=\"65536\" allowCookies=\"false\" authenticationScheme=\"Ntlm\"\n bypassProxyOnLocal=\"false\" hostNameComparisonMode=\"StrongWildcard\"\n keepAliveEnabled=\"true\" maxBufferSize=\"65536\" proxyAuthenticationScheme=\"Anonymous\"\n realm=\"\" transferMode=\"Buffered\" unsafeConnectionNtlmAuthentication=\"false\"\n useDefaultWebProxy=\"true\" /> \n </binding>\n </customBinding>\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289601", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6434/" ]
289,622
<p>Now that I've finnaly moved to doing some development/support work for Windows 2008 I find myself annoyed by the lack of one feature I just can't enable: the desktop shortcut to "My Computer" I've grown used to. I know how to enable this on XP and 2003, but I just can't find the setting on 2008.</p> <p>How can a user configure which desktop icons (My Computer, My Documents, Recycling Bin etc) on Windows 2008 Server?</p>
[ { "answer_id": 4173037, "author": "IsiaNT", "author_id": 506773, "author_profile": "https://Stackoverflow.com/users/506773", "pm_score": 3, "selected": false, "text": ".reg Windows Registry Editor Version 5.00\n\n[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\HideDesktopIcons\\NewStartPanel]\n\n\"{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}\"=dword:00000000\n\n\"{20D04FE0-3AEA-1069-A2D8-08002B30309D}\"=dword:00000000\n\n\"{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}\"=dword:00000000\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289622", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17007/" ]
289,626
<p>As being quite a newbie in linux, I have the follwing question. I have list of files (this time resulting from svn status) and i want to create a script to loop them all and replace tabs with 4 spaces.</p> <p>So I want from </p> <pre><code>.... D HTML/templates/t_bla.tpl M HTML/templates/t_list_markt.tpl M HTML/templates/t_vip.tpl M HTML/templates/upsell.tpl M HTML/templates/t_warranty.tpl M HTML/templates/top.tpl A + HTML/templates/t_r1.tpl .... </code></pre> <p>to something like</p> <pre><code>for i in &lt;files&gt;; expand -t4;do cp $i /tmp/x;expand -t4 /tmp/x &gt; $i;done; </code></pre> <p>but I dont know how to do that...</p>
[ { "answer_id": 289640, "author": "Dan Fego", "author_id": 34426, "author_profile": "https://Stackoverflow.com/users/34426", "pm_score": 2, "selected": false, "text": "for i in files\ndo\n sed -i 's/\\t/ /' \"$i\"\ndone\n" }, { "answer_id": 289643, "author": "Adam Byrtek", "author_id": 36656, "author_profile": "https://Stackoverflow.com/users/36656", "pm_score": 5, "selected": true, "text": "svn st | cut -c8- | xargs ls\n grep cut /^M/ xargs ls" }, { "answer_id": 289690, "author": "xsl", "author_id": 11387, "author_profile": "https://Stackoverflow.com/users/11387", "pm_score": 2, "selected": false, "text": "svn st | cut -c8- | while read file; do expand -t4 $file > \"$file-temp\"; mv \"$file-temp\" \"$file\"; done\n svn st | cut -c8- read $file expand" }, { "answer_id": 289742, "author": "WMR", "author_id": 2844, "author_profile": "https://Stackoverflow.com/users/2844", "pm_score": 2, "selected": false, "text": "svn st | cut -c8- | xargs sed -i 's/\\t/ /'\n" }, { "answer_id": 289883, "author": "J.D. Fitz.Gerald", "author_id": 11542, "author_profile": "https://Stackoverflow.com/users/11542", "pm_score": 0, "selected": false, "text": "#!/bin/bash\nREPOS=\"$1\"\nTXN=\"$2\"\nPHP=\"/usr/bin/php\"\n\nSVNLOOK=/usr/bin/svnlook\n\n$SVNLOOK log -t \"$TXN\" \"$REPOS\" | grep \"[a-zA-Z0-9]\" > /dev/null\n\nif [ $? -ne 0 ]\nthen\n echo 1>&2\n echo \"You must enter a comment\" 1>&2\n exit 1\nfi\n\n\nCHANGED=`$SVNLOOK changed -t \"$TXN\" \"$REPOS\" | awk '{print $2}'`\n\nfor LINE in $CHANGED\n do\n FILE=`echo $LINE | egrep \\\\.php$`\n if [ $? == 0 ]\n then\n MESSAGE=`$SVNLOOK cat -t \"$TXN\" \"$REPOS\" \"${FILE}\" | $PHP -l`\n if [ $? -ne 0 ]\n then\n echo 1>&2\n echo \"***********************************\" 1>&2\n echo \"PHP error in: ${FILE}:\" 1>&2\n echo \"$MESSAGE\" | sed \"s| -| $FILE|g\" 1>&2\n echo \"***********************************\" 1>&2\n exit 1\n fi\n fi\ndone\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289626", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30759/" ]
289,628
<p>HI,</p> <p>I have 3 tables: <strong>Clips</strong>, <strong>Books</strong> and relationships between <strong>ClipBook</strong></p> <p><strong>Problem is:</strong> i need get <strong>book</strong> that has <strong>bookID=4</strong> with some clips i mean many-to-many</p> <p>in simple text sql it will be something like this:</p> <p><code>select * from Clips where clipID in (select clipID from ClipBook where bookID=4)</code></p> <p><strong>Question is:</strong></p> <p>How can i do this with <strong>Linq</strong> without operator <strong>Join</strong> of course</p>
[ { "answer_id": 289640, "author": "Dan Fego", "author_id": 34426, "author_profile": "https://Stackoverflow.com/users/34426", "pm_score": 2, "selected": false, "text": "for i in files\ndo\n sed -i 's/\\t/ /' \"$i\"\ndone\n" }, { "answer_id": 289643, "author": "Adam Byrtek", "author_id": 36656, "author_profile": "https://Stackoverflow.com/users/36656", "pm_score": 5, "selected": true, "text": "svn st | cut -c8- | xargs ls\n grep cut /^M/ xargs ls" }, { "answer_id": 289690, "author": "xsl", "author_id": 11387, "author_profile": "https://Stackoverflow.com/users/11387", "pm_score": 2, "selected": false, "text": "svn st | cut -c8- | while read file; do expand -t4 $file > \"$file-temp\"; mv \"$file-temp\" \"$file\"; done\n svn st | cut -c8- read $file expand" }, { "answer_id": 289742, "author": "WMR", "author_id": 2844, "author_profile": "https://Stackoverflow.com/users/2844", "pm_score": 2, "selected": false, "text": "svn st | cut -c8- | xargs sed -i 's/\\t/ /'\n" }, { "answer_id": 289883, "author": "J.D. Fitz.Gerald", "author_id": 11542, "author_profile": "https://Stackoverflow.com/users/11542", "pm_score": 0, "selected": false, "text": "#!/bin/bash\nREPOS=\"$1\"\nTXN=\"$2\"\nPHP=\"/usr/bin/php\"\n\nSVNLOOK=/usr/bin/svnlook\n\n$SVNLOOK log -t \"$TXN\" \"$REPOS\" | grep \"[a-zA-Z0-9]\" > /dev/null\n\nif [ $? -ne 0 ]\nthen\n echo 1>&2\n echo \"You must enter a comment\" 1>&2\n exit 1\nfi\n\n\nCHANGED=`$SVNLOOK changed -t \"$TXN\" \"$REPOS\" | awk '{print $2}'`\n\nfor LINE in $CHANGED\n do\n FILE=`echo $LINE | egrep \\\\.php$`\n if [ $? == 0 ]\n then\n MESSAGE=`$SVNLOOK cat -t \"$TXN\" \"$REPOS\" \"${FILE}\" | $PHP -l`\n if [ $? -ne 0 ]\n then\n echo 1>&2\n echo \"***********************************\" 1>&2\n echo \"PHP error in: ${FILE}:\" 1>&2\n echo \"$MESSAGE\" | sed \"s| -| $FILE|g\" 1>&2\n echo \"***********************************\" 1>&2\n exit 1\n fi\n fi\ndone\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2246271/" ]
289,649
<p>I'm trying to reorder/group a set of results using SQL. I have a few fields (which for the example have been renamed to something a bit less specific), and each logical group of records has a field which remains constant - the address field. There are also fields which are present for each address, these are the same for every address.</p> <pre><code>id forename surname address 1 John These Address1 2 Lucy Values Address1 3 Jenny Are Address1 4 John All Address2 5 Lucy Totally Address2 6 Jenny Different Address2 7 Steve And Address2 8 Richard Blah Address2 address John Lucy Jenny Steve Richard Address1 These Values Are (null) (null) Address2 All Totally Different And Blah </code></pre> <p>For example: John,Lucy,Jenny,Steve and Richard are the only possible names at each address. I know this because it's stored in another location.</p> <p>Can I select values from the actual records in the left hand image, and return them as a result set like the one on the right? I'm using MySQL if that makes a difference.</p>
[ { "answer_id": 289658, "author": "Chad", "author_id": 37309, "author_profile": "https://Stackoverflow.com/users/37309", "pm_score": 0, "selected": false, "text": "SELECT Address,Name FROM Table GROUP BY Name\n" }, { "answer_id": 289660, "author": "Jonathan", "author_id": 19272, "author_profile": "https://Stackoverflow.com/users/19272", "pm_score": 0, "selected": false, "text": "SELECT concat(column1,column2,column3) as main_column, address from table;\n" }, { "answer_id": 289849, "author": "Martin", "author_id": 37367, "author_profile": "https://Stackoverflow.com/users/37367", "pm_score": 2, "selected": true, "text": "select max(if(forename='john',surname,null)) as john,\n max(if(forename='lucy',surname,null)) as lucy,\n max(if(forename='jenny',surname,null)) as jenny, \n max(if(forename='steve',surname,null)) as steve, \n max(if(forename='richard',surname,null)) as richard,\n address\nfrom tablename \ngroup by address;\n select address, group_concat( concat( forename, surname ) ) tenants \nfrom tablename\ngroup by address;\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30512/" ]
289,665
<p>I'm an avid vim user and have started to write some SQL code recently. I like to write my SQL statements in CAPS and sometimes forget to switch <kbd>CapsLock</kbd> 'off' and I then quickly wreak havoc on my code before I realise what's happening.</p> <p>I have so far not found any way to tell whether the <kbd>CapsLock</kbd> key is on other than looking at my keyboard (which requires me to look away from the screen which I consider a big delay). </p> <p>Ideally I would like vim to automatically change my background colour whenever <kbd>CapsLock</kbd> is 'on' but I'd be willing to settle for some other on-screen indicator of <kbd>CapsLock</kbd> status as a compromise.</p>
[ { "answer_id": 289948, "author": "rampion", "author_id": 9859, "author_profile": "https://Stackoverflow.com/users/9859", "pm_score": 3, "selected": true, "text": " \" let the case be toggled in normal mode\n map <expr> <F3> ToggleInsertCase()\n \" let the case be toggled in insert mode\n imap <expr> <F3> ToggleInsertCase()\n\n let toUpper = 0\n func! ToggleInsertCase() \n let g:toUpper = 1 - g:toUpper\n if (g:toUpper == 1)\n highlight Normal ctermbg=Blue \" the background color you want when uppercased\n \" convert all the letters to uppercase in insert mode\n let i = char2nr('a')\n while i <= char2nr('z')\n let c = nr2char(i)\n exe 'inoremap' c toupper(c)\n let i = i + 1\n endwhile\n else\n highlight Normal ctermbg=Black \" the background color you want normally\n \" let letters be as normal in insert mode\n let i = char2nr('a')\n while i <= char2nr('z')\n let c = nr2char(i)\n exe 'iunmap' c \n let i = i + 1\n endwhile\n endif\n \" don't insert anything when this function is called in normal mode\n return \"\"\n endfunc\n" }, { "answer_id": 290084, "author": "Gowri", "author_id": 3253, "author_profile": "https://Stackoverflow.com/users/3253", "pm_score": 0, "selected": false, "text": "imap a A\nimap b B\nimap c C\nimap d D\nimap e E\nimap f F\nimap g G\nimap h H\nimap i I\nimap j J\nimap k K\nimap l L\nimap m M\nimap n N\nimap o O\nimap p P\nimap q Q\nimap r R\nimap s S\nimap t T\nimap u U\nimap v V\nimap w W\nimap x X\nimap y Y\nimap z Z\n" }, { "answer_id": 1005684, "author": "Steve K", "author_id": 121394, "author_profile": "https://Stackoverflow.com/users/121394", "pm_score": 3, "selected": false, "text": ":iab ATT American Telephone and Telegraph\n iab select SELECT\niab like LIKE\niab where WHERE\n...\n set nocompat\nfilet detect plugin on\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289665", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34772/" ]
289,668
<p>I don't know what commands to enter into the setup.py file when compiling a python program to use my icons. Can anyone help me? Thanks in advance.</p>
[ { "answer_id": 289784, "author": "Kirill Titov", "author_id": 25705, "author_profile": "https://Stackoverflow.com/users/25705", "pm_score": 3, "selected": false, "text": "from distutils.core import setup\nimport py2exe\nsetup(\n windows=[{\"script\": 'app.py', \"icon_resources\": [(1, \"icon.ico\")]}],\n options={\"py2exe\":{\"unbuffered\": True,\n \"optimize\": 2,\n \"bundle_files\" : 1,\n \"dist_dir\": \"bin\"}},\n zipfile = \"lib.zip\", \n)\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289668", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
289,672
<p>Delphi object inspector doesn't show TFrame descendants's additional properties by design. People tend to suggest using a known trick which is commonly used for showing TForm descendant's properties on the Object inspector. The trick is: registering custom module for TForm descendants to Delphi IDE via design time package like:</p> <pre><code>RegisterCustomModule(TMyFrame, TCustomModule); </code></pre> <p>The object inspector can show additional properties of the TFrame Descendant's instance with this way but it loses its frame behaviours while it is embedded in a form. Not redesignable, not possible to implement events for its subcomponents and it accepts child controls (which it musn't). But it behaves normally in its own design area.</p> <p>Looks like, those behaviours provided by Delphi IDE specially just for TFrame. They problaly are not kind of generic facilities. </p> <p>Is there any other way to accomplish this without losing frame behaviours ?</p> <p>I'm using Delphi 2007</p> <hr> <p>@Tondrej,</p> <p>Read comments for the problem, thanks in advance.</p> <p>frameunit.dfm :</p> <pre><code>object MyFrame: TMyFrame Left = 0 Top = 0 Width = 303 Height = 172 TabOrder = 0 object Edit1: TEdit Left = 66 Top = 60 Width = 151 Height = 21 TabOrder = 0 Text = 'Edit1' end end </code></pre> <hr> <pre><code>unit frameunit; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TBaseFrame = Class(TFrame) protected Fstr: string; procedure Setstr(const Value: string);virtual; published Property str:string read Fstr write Setstr; End; TMyFrame = class(TBaseFrame) Edit1: TEdit; private // This won't be called in designtime. But i need this to be called in designtime Procedure Setstr(const Value: string);override; end; implementation {$R *.dfm} { TBaseFrame } procedure TBaseFrame.Setstr(const Value: string); begin Fstr := Value; end; { TMyFrame } procedure TMyFrame.Setstr(const Value: string); begin inherited; Edit1.Text := Fstr; // Sadly this code won't work and Edit1 won't be updated in designtime. end; end. </code></pre> <hr> <pre><code>unit RegisterUnit; interface procedure Register; implementation uses Windows, DesignIntf, frameunit; procedure Register; var delphivclide: THandle; TFrameModule: TCustomModuleClass; begin delphivclide := GetModuleHandle('delphivclide100.bpl'); if delphivclide &lt;&gt; 0 then begin TFrameModule := GetProcAddress(delphivclide, '@Vclformcontainer@TFrameModule@'); if Assigned(TFrameModule) then begin RegisterCustomModule(frameunit.TBaseFrame, TFrameModule); // Just registering that won't cause Tmyframe to loose its frame behaviours // but additional properties won't work well. //RegisterCustomModule(frameunit.TMyFrame, TFrameModule); // That would cause Tmyframe to lose its frame behaviours // But additional properties would work well. end; end; end; end. </code></pre>
[ { "answer_id": 289934, "author": "Ondrej Kelle", "author_id": 11480, "author_profile": "https://Stackoverflow.com/users/11480", "pm_score": 2, "selected": false, "text": "unit FrameTestReg;\n\ninterface\n\nprocedure Register;\n\nimplementation\n\nuses\n Windows, DesignIntf,\n FrameTest;\n\nprocedure Register;\nvar\n delphivclide: THandle;\n TFrameModule: TCustomModuleClass;\nbegin\n delphivclide := GetModuleHandle('delphivclide100.bpl');\n if delphivclide <> 0 then\n begin\n TFrameModule := GetProcAddress(delphivclide, '@Vclformcontainer@TFrameModule@');\n if Assigned(TFrameModule) then\n RegisterCustomModule(TTestFrame, TFrameModule);\n end;\nend;\n\nend.\n unit FrameTest;\n\ninterface\n\nuses\n Forms;\n\ntype\n TTestFrame = class(TFrame)\n private\n FHello: string;\n published\n property Hello: string read FHello write FHello;\n end;\n\nimplementation\n\nend.\n" }, { "answer_id": 9652427, "author": "boojum", "author_id": 1261851, "author_profile": "https://Stackoverflow.com/users/1261851", "pm_score": 0, "selected": false, "text": "procedure TMyFrame.Setstr(const Value: string);\nbegin\n inherited;\n Edit1.Text := Fstr;\n // Sadly this code won't work and Edit1 won't be updated in designtime.\nend;\n procedure TBASEFrame.Setstr(const Value: string);\nbegin\n inherited;\n Edit1.Text := Fstr; \nend;\n" }, { "answer_id": 37989020, "author": "Mad Scientist", "author_id": 4555148, "author_profile": "https://Stackoverflow.com/users/4555148", "pm_score": 1, "selected": false, "text": "uses\n...\n DMForm,\n VCLFormContainer,\n...\n\nprocedure Register;\nbegin\n...\n RegisterCustomModule(TYourFrameClass, TFrameModule); // for frames\n RegisterCustomModule(TYourModuleClass, TDataModuleCustomModule); // for data modules\n...\nend;\n type\n TNestableWinControlCustomModule = class (TWinControlCustomModule)\n public\n function Nestable: Boolean; override;\n end;\n\nfunction TNestableWinControlCustomModule.Nestable: Boolean;\nbegin\n Result := True;\nend;\n RegisterCustomModule(TYourFrameClass, TNestableWinControlCustomModule);\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289672", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37601/" ]
289,680
<p>How do I get the difference in days between 2 dates in SQLite? I have already tried something like this:</p> <pre><code>SELECT Date('now') - DateCreated FROM Payment </code></pre> <p>It returns 0 every time.</p>
[ { "answer_id": 289686, "author": "Fred", "author_id": 33630, "author_profile": "https://Stackoverflow.com/users/33630", "pm_score": 8, "selected": true, "text": " SELECT julianday('now') - julianday(DateCreated) FROM Payment;\n" }, { "answer_id": 295665, "author": "converter42", "author_id": 28974, "author_profile": "https://Stackoverflow.com/users/28974", "pm_score": 5, "selected": false, "text": "sqlite> select julianday(datetime('now'));\n2454788.09219907\nsqlite> select datetime(julianday(datetime('now')));\n2008-11-17 14:13:55\n" }, { "answer_id": 14790580, "author": "Jan Bodnar", "author_id": 2008247, "author_profile": "https://Stackoverflow.com/users/2008247", "pm_score": 5, "selected": false, "text": "January 6, 2013 sqlite> SELECT julianday() - julianday('2013-01-06');\n34.7978485878557 \n julianday('now') date() datetime() julianday()" }, { "answer_id": 34383293, "author": "Abdul Saleem", "author_id": 1879188, "author_profile": "https://Stackoverflow.com/users/1879188", "pm_score": 7, "selected": false, "text": "Select Cast ((\n JulianDay(ToDate) - JulianDay(FromDate)\n) As Integer)\n Select Cast ((\n JulianDay(ToDate) - JulianDay(FromDate)\n) * 24 As Integer)\n Select Cast ((\n JulianDay(ToDate) - JulianDay(FromDate)\n) * 24 * 60 As Integer)\n Select Cast ((\n JulianDay(ToDate) - JulianDay(FromDate)\n) * 24 * 60 * 60 As Integer)\n" }, { "answer_id": 38901688, "author": "Gary", "author_id": 2197115, "author_profile": "https://Stackoverflow.com/users/2197115", "pm_score": 3, "selected": false, "text": "CAST ((julianday(clockOUT) - julianday(clockIN)) * 24 AS REAL) AS HoursWorked Clock In Clock Out HoursWorked\n2016-08-07 11:56 2016-08-07 18:46 6.83333332836628\n" }, { "answer_id": 41047742, "author": "vapcguy", "author_id": 1181535, "author_profile": "https://Stackoverflow.com/users/1181535", "pm_score": 4, "selected": false, "text": "Date('now') julianday() SELECT julianday('now') - julianday(DateCreated) FROM Payment;\n DateCreated julianday('now') SELECT julianday('now') - julianday(DateCreated, 'utc') FROM Payment;\n DateCreated SELECT julianday('now', 'localtime') - julianday(DateCreated) FROM Payment;\n 'Z' julianday(datetime('now', 'localtime')||'Z') - julianday(CREATED_DATE||'Z')\n" }, { "answer_id": 42951650, "author": "Matas Lesinskas", "author_id": 2156417, "author_profile": "https://Stackoverflow.com/users/2156417", "pm_score": 2, "selected": false, "text": "SELECT strftime('%H:%M',\n CAST((julianday(FinishTime) - julianday(StartTime)) AS REAL),\n '12:00')\nFROM something;\n" }, { "answer_id": 49526898, "author": "Rakesh Chaudhari", "author_id": 2861283, "author_profile": "https://Stackoverflow.com/users/2861283", "pm_score": 1, "selected": false, "text": "select count(col_Name) from dataset where cast(julianday(\"now\")- julianday(_Last_updated) as int)<=0;\n" }, { "answer_id": 49842137, "author": "Ashish Koshy", "author_id": 7148332, "author_profile": "https://Stackoverflow.com/users/7148332", "pm_score": 3, "selected": false, "text": "\n (strftime('%m', date1) + 12*strftime('%Y', date1)) - \n (strftime('%m', date2) + 12*strftime('%Y', date2))\n" }, { "answer_id": 53519296, "author": "Yusril Maulidan Raji", "author_id": 3097810, "author_profile": "https://Stackoverflow.com/users/3097810", "pm_score": 0, "selected": false, "text": "julianday() strftime() SELECT (strftime('%s', [UserEnd]) - strftime('%s', [UserStart])) / 60" }, { "answer_id": 53734915, "author": "Stephen Quan", "author_id": 881441, "author_profile": "https://Stackoverflow.com/users/881441", "pm_score": 2, "selected": false, "text": "strftime(\"%s\") CREATE TABLE Payment (DateCreated REAL);\nINSERT INTO Payment VALUES (strftime(\"%s\", \"2018-12-01\"));\n SELECT (strftime(\"%s\", \"now\") - DateCreated) / 86400.0 FROM Payment;\n-- Output: 11.066875\n SELECT (strftime(\"%s\", \"now\") - DateCreated) / 3600.0 FROM Payment;\n-- Output: 265.606388888889\n SELECT (strftime(\"%s\", \"now\") - DateCreated) / 60.0 FROM Payment;\n-- Output: 15936.4833333333\n SELECT (strftime(\"%s\", \"now\") - DateCreated) FROM Payment;\n-- Output: 956195.0\n" }, { "answer_id": 59139477, "author": "Sandris B", "author_id": 5471415, "author_profile": "https://Stackoverflow.com/users/5471415", "pm_score": 2, "selected": false, "text": "SELECT strftime('%s', '2019-12-02 12:32:53') - strftime('%s', '2019-12-02 11:32:53')\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289680", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
289,681
<p>I'm trying to use the &lt; C-a> (<kbd>CTRL</kbd>+<kbd>A</kbd>) shorcut under vim to increment a variable under the cursor. This works fine under vim running on Linux. However when I try to do this in gvim under windows it "selects all" (i.e. highlights or visually selects all text in the current window). How can I change this behaviour or alternatively how can I recover the increment variable functionality (e.g. perhaps with a different key mapping)?</p>
[ { "answer_id": 289691, "author": "Michael Madsen", "author_id": 27528, "author_profile": "https://Stackoverflow.com/users/27528", "pm_score": 2, "selected": false, "text": "*c_CTRL-A*\nCTRL-A All names that match the pattern in front of the cursor are\n inserted.\n" }, { "answer_id": 9055204, "author": "SingleNegationElimination", "author_id": 65696, "author_profile": "https://Stackoverflow.com/users/65696", "pm_score": 2, "selected": false, "text": "skip_loading_mswin let skip_loading_mswin=1\n $HOME/_vimrc" }, { "answer_id": 9978648, "author": "PeerBr", "author_id": 422903, "author_profile": "https://Stackoverflow.com/users/422903", "pm_score": 2, "selected": false, "text": "c:\\Program Files\\Vim\\vim73\\mswin.vim CTRL-A is Select all \" ggVG" }, { "answer_id": 13099182, "author": "Matthew Strawbridge", "author_id": 241605, "author_profile": "https://Stackoverflow.com/users/241605", "pm_score": 3, "selected": false, "text": "nnoremap <kPlus> <C-a>\nnnoremap <kMinus> <C-x>\n _vimrc" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289681", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34772/" ]
289,688
<p>I have hit a classic problem of needing to do a string replace on a text field in an sql 2000 database. This could either be an update over a whole column or a single field I'm not fussy.</p> <p>I have found a few examples of how to use updatetext to achieve it but they tend to be in stored procedures, does anyone know of a similar thing that is wrapped into a function so I can use it like I would usually use Replace(). The problem with the Replace() function for anyone who isn't aware is that it doesn't support text fields.</p> <p>Edit: I realised I could probably get away with varchar(8000) so have swapped the fields to this type which fixes the issue. I never found a true solution.</p>
[ { "answer_id": 289803, "author": "kristof", "author_id": 3241, "author_profile": "https://Stackoverflow.com/users/3241", "pm_score": 3, "selected": true, "text": "create function dbo.textReplace(\n@inText as text)\nreturns text\nas \nbegin\n return 'a' -- just dummy code\nend\n The text data type is invalid for return values.\n" }, { "answer_id": 304643, "author": "bitsprint", "author_id": 9948, "author_profile": "https://Stackoverflow.com/users/9948", "pm_score": 2, "selected": false, "text": "DECLARE @oldtext varchar(1000)\nDECLARE @newtext varchar(1000)\nDECLARE @textlen int\nDECLARE @ptr binary(16)\nDECLARE @pos int\nDECLARE @id uniqueidentifier\n\nSET @oldtext = 'oldtext'\nSET @newtext = 'newtext'\nSET @textlen = LEN(@oldtext)\n\nDECLARE mycursor CURSOR LOCAL FAST_FORWARD\nFOR\n SELECT [UniqueID]\n ,TEXTPTR([Text])\n ,CHARINDEX(@oldtext, [Text]) - 1\n FROM [dbo].[myTable] \n WHERE [Text] LIKE '%' + @oldtext +'%'\n\nOPEN mycursor\n\nFETCH NEXT FROM mycursor into @id, @ptr, @pos\n\nWHILE @@fetch_status = 0\nBEGIN \n UPDATETEXT [dbo].[myTable].Text @ptr @pos @textlen @newtext\n\n FETCH NEXT FROM mycursor into @id, @ptr, @pos \nEND\n\nCLOSE mycursor\nDEALLOCATE mycursor\n" }, { "answer_id": 1274049, "author": "Seth Petry-Johnson", "author_id": 23632, "author_profile": "https://Stackoverflow.com/users/23632", "pm_score": 1, "selected": false, "text": "MyVarchar = SUBSTRING(myTextField, 1, DATALENGTH(myTextField))\n MyVarchar100 = SUBSTRING(myTextField, 1, 100)\n" }, { "answer_id": 1623730, "author": "suryakiran", "author_id": 196499, "author_profile": "https://Stackoverflow.com/users/196499", "pm_score": 6, "selected": false, "text": "UPDATE <Table> set textcolumn=\nREPLACE(SUBSTRING(textcolumn,1,DATALENGTH(textcolumn)),'findtext','replacetext') \nWHERE <Condition>\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16989/" ]
289,702
<p>I am writing unit tests for a class, which has a static final variable. However, since the state of the static final var is modified in each test, I need some way to reinitialize it.</p> <p> How would this be possible? Would i need to use some sort of a custom classloader? </p> <p> The variable is initialized as - <pre> static final CountdownLatch latch = new CountdownLatch(1); </pre> </p>
[ { "answer_id": 289707, "author": "toolkit", "author_id": 3295, "author_profile": "https://Stackoverflow.com/users/3295", "pm_score": 2, "selected": false, "text": "perTest" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289702", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14316/" ]
289,712
<p>As a long time Pascal and Delphi developer, I always line up my begin and ends thus :</p> <pre><code>begin if x = y then begin ... ... end else for i := 0 to 20 do begin ... ... end; end; </code></pre> <p>What drives me nuts is code formatted thus :</p> <pre><code>begin if x = y then begin ... ... end else for i := 0 to 20 do begin ... ... end; end; </code></pre> <p>When there are a few levels of compound statements I find this hard to read. The above code is ok, because it's not that complicated, but for consistency I'd prefer all begins and ends aligned.</p> <p>As I start using c#, I find myself aligning curly brackets too. What's the norm in the C# world? </p> <p><strong>Edit :</strong></p> <p>Someone has pointed out that this is the type of question that shouldn't be asked on SO. I don't see why not. I'm in the process of setting up a coding guidelines document. I know I'll get some resistance to certain things, I'm hoping to get a few answers here, so I can be ready to meet that resistance head-on.</p>
[ { "answer_id": 289732, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 2, "selected": false, "text": "IF x = y THEN\n ....\nEND;\n if x = y then begin\n ....\nend;\n" }, { "answer_id": 289826, "author": "gabr", "author_id": 4997, "author_profile": "https://Stackoverflow.com/users/4997", "pm_score": 0, "selected": false, "text": "begin\n if x = y then begin\n ...\n end\n else begin\n for i := 0 to 20 do begin\n ...\n end;\n end;\nend;\n begin\n if x = y then begin\n ...\n end\n else for i := 0 to 20 do begin\n ...\n end;\n x := GetMeTheObject;\nif assigned(x) then try\n ...\nfinally FreeAndNil(x); end;\n" }, { "answer_id": 290077, "author": "Bruce McGee", "author_id": 19183, "author_profile": "https://Stackoverflow.com/users/19183", "pm_score": 2, "selected": false, "text": "if (SomeCondition) then begin\n ...\nend;\n if (SomeCondition)\n{\n ...\n}\n if (SomeCondition) then \nbegin\n ...\nend;\n if x = y then \nbegin\n ...\n ...\nend\nelse\nbegin\n for i := 0 to 20 do \n begin\n ...\n ...\n end;\nend;\n if (SomeCondition) then\n ...\n" }, { "answer_id": 290096, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 3, "selected": false, "text": "if Condition then\nbegin\n DoThis;\nend else\nbegin\n DoThat;\nend;\n // INCORRECT\nif A < B then begin\n DoSomething; \n DoSomethingElse;\nend else begin\n DoThis;\n DoThat;\nend;\n\n// CORRECT\nif A < B then \nbegin\n DoSomething; \n DoSomethingElse;\nend \nelse \nbegin\n DoThis;\n DoThat;\nend;\n // CORRECT\nif Condition then\nbegin\n DoThis;\nend else\nbegin\n DoThat;\nend;\n\n// CORRECT\nif Condition then\nbegin\n DoThis;\nend\nelse\n DoSomething;\n\n// CORRECT\nif Condition then\nbegin\n DoThis;\nend else\n DoSomething;\n" }, { "answer_id": 290125, "author": "Brian", "author_id": 18192, "author_profile": "https://Stackoverflow.com/users/18192", "pm_score": 0, "selected": false, "text": "end else" }, { "answer_id": 290132, "author": "Michael Madsen", "author_id": 27528, "author_profile": "https://Stackoverflow.com/users/27528", "pm_score": 2, "selected": false, "text": "if a=b then begin\n c;\nend else begin\n d;\nend;\n\nif x=y then z;\n" }, { "answer_id": 290176, "author": "Svante", "author_id": 31615, "author_profile": "https://Stackoverflow.com/users/31615", "pm_score": 1, "selected": false, "text": "if (I am nuts) {\n Psychiatry\n}\n if (I am nuts)\n{\n Psychiatry\n}\n if (I am nuts)\n {\n Psychiatry\n }\n if (I am nuts)\n {\n Psychiatry\n }\n if (I am nuts) {\n Psychiatry\n } else {\n I am free\n}\n if (I am completely nuts) {\n Psychiatry }\n else {\n I am free } \n" }, { "answer_id": 290257, "author": "Steve", "author_id": 22712, "author_profile": "https://Stackoverflow.com/users/22712", "pm_score": 0, "selected": false, "text": "if x=y then z;\n 1 if x=y then\n2 Z;\n" }, { "answer_id": 290369, "author": "Fabricio Araujo", "author_id": 10300, "author_profile": "https://Stackoverflow.com/users/10300", "pm_score": 0, "selected": false, "text": "if <cond> then\n begin\n ShowMessage('balablala');\n exit;\n end;\n if <cond> then\nbegin\n ShowMessage('balablala');\n exit;\nend;\n" }, { "answer_id": 290528, "author": "skamradt", "author_id": 9217, "author_profile": "https://Stackoverflow.com/users/9217", "pm_score": 1, "selected": false, "text": "if condition1 then\n begin\n // do something\n end\nelse // not condition1\n begin\n // do something else\n end;\n if condition1 or\n condition2 or\n condition3 and\n ( condition4 or\n condition5 )\nthen\n begin\n // do something\n end\nelse // not conditions\n begin\n // do something else\n end;\n" }, { "answer_id": 291928, "author": "orcmid", "author_id": 33810, "author_profile": "https://Stackoverflow.com/users/33810", "pm_score": 0, "selected": false, "text": "begin if x = y \n then begin (* stack to avoid getting too much indentation *)\n ... \n ... \n end \n else for i := 0 to 20 \n do begin \n ... \n ... \n end;\n end;\n { if (x == y)\n { ... /* Space as if 'then' is there */ \n ... \n }\n else for (int i = 0; i<21; i++)\n { ... /* space as if 'do' is there */\n ... \n }\n }\n" }, { "answer_id": 292384, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 0, "selected": false, "text": "if begin-end // if end; if A < B then \nbegin\n DoSomething; \nend; // if\n with qryTemp do\nbegin\n First;\n\n while not Eof do\n begin\n if (A < B)\n or (C < D)\n begin\n DoSomething;\n end else\n begin\n DoSomethingElse;\n end; // if-else \n\n Next;\n end; // while\nend; // with\n if (condition) {\n statements;\n} // if\n if ((condition1 && condition2)\n || (condition3 && condition4)\n ||!(condition5 && condition6)) {\n doSomethingAboutIt();\n} else {\n doSomethingElse();\n} // if-else\n" }, { "answer_id": 295445, "author": "Oliver Giesen", "author_id": 9784, "author_profile": "https://Stackoverflow.com/users/9784", "pm_score": 0, "selected": false, "text": "try\n if Condition1\n or ( Condition2\n and Condition3) then\n begin\n DoSomething\n DoSomeMore;\n end\n\n else if Condition4 then // I only do this if the nested \"if\" has \"case\"-like characteristics\n begin // otherwise the if would obviously be indented and on its own line\n DoSomethingElse;\n\n if Condition5 then\n begin\n DoThisToo;\n DoFoo;\n end;\n end\n\n else\n DoTheWholeShebang;\n\n case Whatever of\n A: DoIt;\n\n B, C, D:\n begin\n DoSomethingSlightly;\n MoreComplicated;\n end;\n\n else\n begin\n DoWhatever;\n DoLastResort; \n end;\n end;\nexcept\n on ESomeException do\n begin\n HandleIt;\n raise;\n end;\n on ESomeOtherException do\n DealWithIt;\n\n else\n DoWhateverItTakes;\nend;\n if (condition) {\n doSomething;\n} else {\n doSomethingElse;\n}\n" }, { "answer_id": 3584355, "author": "Andriy M", "author_id": 297408, "author_profile": "https://Stackoverflow.com/users/297408", "pm_score": 0, "selected": false, "text": "if (condition) then begin\n statement;\n ...\n statement; end\nelse begin\n ...\nend;\n end if if end else then else begin ... end case repeat if while then do if (some_long_conditional_expression) or\n (some_other_long_conditional_expression) or\n (some_even_longer_conditional_expression)\nthen\n Exit;\n else if for ... do with ... do try begin" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289712", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22712/" ]
289,715
<p>I am looking for the highest key value (a defined by the comparison operator) of a std::map.</p> <p>Is this guaranteed to be </p> <pre><code>map.rbegin()-&gt;first </code></pre> <p>? </p> <p>(I am a bit shaky on reverse iterators, and how much freedom there is in the implementation of std::map) </p> <p>If not, please advise. I cannot change the data structure.</p>
[ { "answer_id": 289834, "author": "CB Bailey", "author_id": 19563, "author_profile": "https://Stackoverflow.com/users/19563", "pm_score": 5, "selected": false, "text": "map.rbegin() != map.rend()" }, { "answer_id": 40734035, "author": "birubisht", "author_id": 1613219, "author_profile": "https://Stackoverflow.com/users/1613219", "pm_score": 4, "selected": false, "text": "if(!map.empty())\n (--map.end())->first;\n" }, { "answer_id": 64841106, "author": "Alam", "author_id": 417028, "author_profile": "https://Stackoverflow.com/users/417028", "pm_score": 4, "selected": false, "text": "std::prev(map.end())->first;\n" }, { "answer_id": 69942242, "author": "kuldeep singh", "author_id": 11091646, "author_profile": "https://Stackoverflow.com/users/11091646", "pm_score": 1, "selected": false, "text": "auto it=m.end();\nit--;\nint element=it->first;\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289715", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31317/" ]
289,727
<p>Since MySQL doesn't seem to have any 'boolean' data type, which data type do you 'abuse' for storing true/false information in MySQL?</p> <p>Especially in the context of writing and reading from/to a PHP script.</p> <p>Over time I have used and seen several approaches:</p> <ul> <li>tinyint, varchar fields containing the values 0/1,</li> <li>varchar fields containing the strings '0'/'1' or 'true'/'false'</li> <li>and finally enum Fields containing the two options 'true'/'false'.</li> </ul> <p>None of the above seems optimal. I tend to prefer the tinyint 0/1 variant, since automatic type conversion in PHP gives me boolean values rather simply.</p> <p>So which data type do you use? Is there a type designed for boolean values which I have overlooked? Do you see any advantages/disadvantages by using one type or another?</p>
[ { "answer_id": 289759, "author": "markus", "author_id": 11995, "author_profile": "https://Stackoverflow.com/users/11995", "pm_score": 11, "selected": true, "text": "BIT BOOL BOOLEAN" }, { "answer_id": 289767, "author": "Philip Morton", "author_id": 21709, "author_profile": "https://Stackoverflow.com/users/21709", "pm_score": 8, "selected": false, "text": "BOOL BOOLEAN TINYINT(1) false true" }, { "answer_id": 808172, "author": "Josh", "author_id": 75801, "author_profile": "https://Stackoverflow.com/users/75801", "pm_score": 5, "selected": false, "text": "CHAR(0) '' == true and NULL == false CHAR(0) CHAR(0) NULL NULL ''" }, { "answer_id": 6682868, "author": "Jonathan", "author_id": 843178, "author_profile": "https://Stackoverflow.com/users/843178", "pm_score": 4, "selected": false, "text": "bit_flags bit_flags & SELECT (t.bit_flags & 128) >> 7 AS myBool FROM myTable t;\n\nif bit_flags = 128 ==> 1 (true)\nif bit_flags = 0 ==> 0 (false)\n SELECT (128 & 128) >> 7;\n\nSELECT (0 & 128) >> 7;\n bit_flags" }, { "answer_id": 9232626, "author": "R. S.", "author_id": 643505, "author_profile": "https://Stackoverflow.com/users/643505", "pm_score": 6, "selected": false, "text": "some_flag CHAR(0) DEFAULT NULL\n some_flag = '' some_flag = NULL IS NOT NULL IS NULL" }, { "answer_id": 51040356, "author": "Lemures", "author_id": 9533866, "author_profile": "https://Stackoverflow.com/users/9533866", "pm_score": 2, "selected": false, "text": "bit(1) tinyint(1)" }, { "answer_id": 56316045, "author": "Paul Spiegel", "author_id": 5563083, "author_profile": "https://Stackoverflow.com/users/5563083", "pm_score": 3, "selected": false, "text": "bool_val TINYINT CHECK(bool_val IN(0,1))\n 0 1 NULL 0 1 '1' 0x00 b'1' TRUE FALSE NOT NULL bool_val TINYINT NOT NULL CHECK(bool_val IN(0,1))\n TINYINT TINYINT(1) TINYINT(123) BOOL BOOLEAN bool_val BOOL CHECK(bool_val IN(TRUE,FALSE))\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289727", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
289,729
<p>I'm just starting to try out phpunit on some existing code. The naming convention we use is that the MyClass class should be in MyClass.class.php. PHPUnit seems to require that the file should be called MyClass.php. </p> <p>Is there any way around this?</p> <p>I noticed it while trying to generate a skeleton test class:</p> <pre><code>phpunit --skeleton-test MyClass.class PHPUnit 3.3.4 by Sebastian Bergmann. Could not find class "MyClass.class" in "/home/jd/skeleton/classes/MyClass.class.php". Fatal error: Call to a member function getOutClassName() on a non-object in /usr/share/php/PHPUnit/TextUI/Command.php on line 470 </code></pre>
[ { "answer_id": 289758, "author": "Kent Fredric", "author_id": 15614, "author_profile": "https://Stackoverflow.com/users/15614", "pm_score": 4, "selected": true, "text": "phpunit --skeleton-test MyClass MyClass.class.php\n Usage: phpunit [switches] UnitTest [UnitTest.php]\n phpunit [switches] <directory>\n\n--skeleton-class Generate Unit class for UnitTest in UnitTest.php.\n--skeleton-test Generate UnitTest class for Unit in Unit.php.\n" }, { "answer_id": 4853146, "author": "Luke Cordingley", "author_id": 597015, "author_profile": "https://Stackoverflow.com/users/597015", "pm_score": 0, "selected": false, "text": "<?php\n\nnamespace my\\space;\nclass Foo\n{\n ...\n}\n user[/my/dir]$ phpunit --skeleton-test my\\\\dir\\\\Foo Foo.php\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289729", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11542/" ]
289,731
<p>During navigation of the <code>java.lang.reflect.Method</code> class I came across the method <code>isBridge</code>. Its Javadoc says that it returns true only if the Java spec declares the method as true.</p> <p>Please help me understand what this is used for! Can a custom class declare its method as a bridge if required?</p>
[ { "answer_id": 289745, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 6, "selected": true, "text": "class C<T> { abstract T id(T x); }\nclass D extends C<String> { String id(String x) { return x; } }\n C c = new D();\nc.id(new Object()); // fails with a ClassCastException\n D.id(String) C.id(Object) Object id(Object x) { return id((String) x); }\n c.id(new Object()) Object clone() MyObject clone() public bridge Object MyObject.clone();\n" }, { "answer_id": 2862013, "author": "samskivert", "author_id": 285820, "author_profile": "https://Stackoverflow.com/users/285820", "pm_score": 2, "selected": false, "text": "public static interface Function<A,R> {\n public R apply (A arg);\n}\npublic static <A, R> R applyFunc (Function<A,R> func, A arg) {\n return func.apply(arg);\n}\n Function<String, String> lower = new Function<String, String>() {\n public String apply (String arg) {\n return arg.toLowerCase();\n }\n};\napplyFunc(lower, \"Hello\");\n Function apply(Object)Object applyFunc apply(Object)Object Object apply(String)String Function Function apply(String)String Function<String, String> lower = ...;\nlower.apply(\"Hello\");\n apply(Object)Object apply(String)String new Function<String, String>() {\n public String apply (String arg) {\n return arg.toLowerCase();\n }\n}.apply(\"Hello\");\n" }, { "answer_id": 18450919, "author": "Jesse Glick", "author_id": 12916, "author_profile": "https://Stackoverflow.com/users/12916", "pm_score": 0, "selected": false, "text": "protected abstract class Super {\n public void m() {}\n}\npublic class Sub extends Super {}\nassert Sub.class.getMethod(\"m\").isBridge();\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289731", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11614/" ]
289,733
<p>I have a logical error. I provided the following as input:</p> <ul> <li>the salary is 30000</li> <li>the child n° is 9</li> </ul> <p>So the the net salary will be:</p> <ul> <li><p>the family bonus + salary - tax</p> <pre><code> (750) + (30000) - (3000) </code></pre></li> <li><p>but my program count them as </p> <pre><code> (1500) + (30000) + (6000) </code></pre></li> </ul> <p>My program doubled (accumulated) the family bonus and the tax. Can anyone explain why?</p> <pre><code>class Program { static void Main(string[] args) { Employee e = new Employee(); e.ReadEmployee(); e.PrintEmployee(); } } class Employee { private string n; private int byear; private double sal; private bool gen; private bool mar; private int child; public static double tax = 0; public static double familybonus = 0; public string Ename { get { return this.n; } set { this.n = value; } } public int Birthyear { get { return this.byear; } set { if (value &gt;= 1970 &amp;&amp; value &lt;= 1990) this.byear = value; else this.byear = 0; } } public double Salary { get { return this.sal; } set { if (value &gt;= 5000 &amp;&amp; value &lt;= 50000) this.sal = value; else this.sal = 0; } } public bool Gender { get { return this.gen; } set { this.gen = value; } } public bool Married { get { return this.mar; } set { this.mar = value; } } public int NChildren { get { return this.child; } set { if (value &gt;= 0 &amp;&amp; value &lt;= 12) this.child = value; else this.child = 0; } } public double getAge() { return 2008 - this.Birthyear; } public double getNet() { double net = getFamilyBonus() + this.Salary - getTax(); return net; } public double getFamilyBonus() { if (this.Married == true) familybonus += 300; if (this.NChildren == 1) familybonus += 200; else if (this.NChildren == 2) familybonus += 350; else if (this.NChildren &gt;= 3) familybonus += 450; return familybonus; } public double getTax() { if (Salary &lt; 10000) tax = 0; if (Salary &lt;= 10000 &amp;&amp; Salary &gt;= 20000) tax += Salary * 0.05; else tax += Salary * 0.1; return tax; } public void ReadEmployee() { Console.Write("Enter Employee Name: "); Ename = Console.ReadLine(); Console.Write("Enter Employee birth date: "); Birthyear = int.Parse(Console.ReadLine()); while (Birthyear &lt; 1970 || Birthyear &gt; 1990) { Console.WriteLine("Invalid Birthyear!"); Console.Write("Enter Employee Birth date: "); Birthyear = int.Parse(Console.ReadLine()); } string g = null; while (g != "M" &amp;&amp; g != "m" &amp;&amp; g != "F" &amp;&amp; g != "f") { Console.Write("Enter Employee Gender (M/F)"); g = Convert.ToString(Console.ReadLine()); } if (g == "M" || g == "m") Gender = true; else Gender = false; Console.Write("Enter Employee Salary: "); Salary = Double.Parse(Console.ReadLine()); while (Salary &lt; 5000 || Salary &gt; 50000) { Console.WriteLine("Invalid Salary!"); Console.Write("Enter Employee Salary: "); Salary = int.Parse(Console.ReadLine()); } string m = null; while (m != "true" &amp;&amp; m != "True" &amp;&amp; m != "false" &amp;&amp; m != "False") { Console.Write("Married (true/false)"); m = Console.ReadLine(); } if (m == "true") this.Married = true; else this.Married = false; Console.Write("Enter Employee Children count: "); NChildren = int.Parse(Console.ReadLine()); while (NChildren &lt; 0 || NChildren &gt; 12) { Console.WriteLine("Invalid NChildren!"); Console.Write("Enter Employee Children count: "); NChildren = int.Parse(Console.ReadLine()); } } public void PrintEmployee() { Console.Write("Hello "); { if (Gender == true) Console.Write("Mr. "); else Console.Write("Mrs. "); Console.WriteLine(Ename); } Console.WriteLine("You are {0} years old", getAge()); Console.WriteLine("Salary= {0}", Salary); Console.WriteLine("Tax= {0}", getTax()); Console.WriteLine("Family bonus= {0}", getFamilyBonus()); Console.WriteLine("Net= {0}", getNet()); } } </code></pre>
[ { "answer_id": 289755, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": true, "text": "public double getTax()\n{\n if (Salary < 10000)\n tax = 0;\n if (Salary <= 10000 && Salary >= 20000)\n tax += Salary * 0.05;\n else tax += Salary * 0.1;\n return tax;\n}\n tax Salary >= 10000 familyBouns getFamilyBonus <= 10000 >= 20000 Console.WriteLine(\"Tax= {0}\", getTax());\n Console.WriteLine(\"Tax= {0}\", getTax());\n Console.WriteLine(\"Tax= {0}\", getTax());\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289733", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
289,735
<pre><code>import sys words = { 1 : 'one', 2 : 'two', 3 : 'three', 4 : 'four', 5 : 'five', 6 : 'six', 7 : 'seven', 8 : 'eight', 9 : 'nine', 10 : 'ten', 11 : 'eleven', 12 : 'twelve', 13 : 'thirteen', 14 : 'fourteen', 15 : 'fifteen', 16 : 'sixteen', 17 : 'seventeen', 18 : 'eighteen', 19 : 'nineteen' } tens = [ '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety', ] placeholders = [ '', 'thousand', 'million', 'billion', 'trillion', 'quadrillion' ] # segMag = segment magnitude (starting at 1) def convertTrio(number): return ' '.join([words[int(number[0])], 'hundred', convertDuo(number[1:3])]) # convertDuo(number[1:3]) def convertDuo(number): #if teens or less if int(number[0]) == 1: return words[int(number)] #twenty-five else: return tens[int(number[0]) - 1] + '-' + words[int(number[1])] if __name__ == "__main__": string = [] numeralSegments = [] numeral = sys.argv[1] if int(numeral) &lt; 100: print convertDuo(numeral) else: # split number into lists, grouped in threes for i in range (0, len(numeral), 3): numeralSegments.append(numeral[i:i+3]) numeralSegments.reverse() # for every segment, convert to trio word and append thousand, million, etc depending on magnitude for i in range (len(numeralSegments)): string.append(convertTrio(numeralSegments[i]) + ' ' + placeholders[i]) # reverse the list of strings before concatenating to commas string.reverse() print ', '.join(string) </code></pre> <p><strong>Warning</strong>: I'm a total python novice. I'm aware there are probably many times more efficient ways of doing things. I'd appreciate any pointers to them.</p> <p><strong>Edit</strong>: The code currently only works for numbers whose digit counts are multiples of three. I'd appreciate a suggestion for an elegant way to fix that as well. Thanks.</p>
[ { "answer_id": 289766, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 3, "selected": true, "text": "range(0,len(),3) def segment( n ):\n segList= []\n while len(n) > 3:\n segList.insert( 0, n[-3:] )\n n= n[:-3]\n segList.insert( 0, n )\n return segList\n if __name__ == \"__main__\" sys.argv if __name__ == \"__main__\":\n import sys\n for number in sys.argv[1:]:\n print number2string( number )\n number2string" }, { "answer_id": 290706, "author": "A. Coady", "author_id": 36433, "author_profile": "https://Stackoverflow.com/users/36433", "pm_score": 2, "selected": false, "text": "def convert(n):\n q, r = divmod(n, 10)\n if q < 2:\n return words[n]\n result = tens[q-1] # offset because tens is missing first null value\n if r:\n result += '-' + words[r]\n return result\n" }, { "answer_id": 3217210, "author": "pwdyson", "author_id": 267048, "author_profile": "https://Stackoverflow.com/users/267048", "pm_score": 0, "selected": false, "text": "import inflect\np = inflect.engine()\np.numwords(123456789)\n 'one hundred and twenty-three million, four hundred and fifty-six thousand, seven hundred and eighty-nine'\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289735", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11110/" ]
289,743
<p>Our coding standards ask that we minimise the use of C# var (suggests limiting it's use to being in conjunction with Linq). However there are times when using generics where it's reasonably convenient e.g.</p> <pre><code>Dictionary&lt;DateTime, Dictionary&lt;string, float&gt;&gt; allValues = ... // ... foreach (var dateEntry in allValue) </code></pre> <p>is easier to type </p> <pre><code>foreach (KeyValue&lt;DateTime, Dictionary&lt;string, float&gt;&gt; dateEntry in allValue) </code></pre> <p>(and easier than remembering what the explicit type is in some cases). </p> <p>Do any of the refactoring tools have the ability to convert the former to the latter. I've had a look at Resharper but it doesn't seem to do (indeed it's default suggestion is to go in the opposite direction).</p>
[ { "answer_id": 289781, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 5, "selected": true, "text": "pair var i = 0" }, { "answer_id": 289816, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 2, "selected": false, "text": "IDictionary<,>.GetEnumerator() using using InnerPair = System.Collections.Generic.KeyValuePair<System.DateTime,\n System.Collections.Generic.Dictionary<string, float>>;\n foreach(InnerPair pair in dict) {...}\n" }, { "answer_id": 46372419, "author": "HaveSpacesuit", "author_id": 2908576, "author_profile": "https://Stackoverflow.com/users/2908576", "pm_score": 4, "selected": false, "text": "var" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289743", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5764/" ]
289,751
<p>During development I have to "clear cache" in Firefox all the time in order to make it use the latest version of JavaScript files.</p> <p>Is there some kind of setting (about:config) to turn off caching completely for JavaScript files? Or, if not, for all files?</p>
[ { "answer_id": 289771, "author": "tst", "author_id": 36232, "author_profile": "https://Stackoverflow.com/users/36232", "pm_score": 9, "selected": true, "text": "browser.cache.disk.enable = false\nbrowser.cache.memory.enable = false\n browser.cache.offline.enable = false\n" }, { "answer_id": 289775, "author": "Pat", "author_id": 238, "author_profile": "https://Stackoverflow.com/users/238", "pm_score": 2, "selected": false, "text": "network.http.use-cache = false\n" }, { "answer_id": 6674054, "author": "Kevin Jhangiani", "author_id": 283352, "author_profile": "https://Stackoverflow.com/users/283352", "pm_score": 2, "selected": false, "text": "<FilesMatch \"\\.(js|css)$\">\nFileETag None\n<IfModule mod_headers.c>\nHeader unset ETag\nHeader set Cache-Control \"max-age=0, no-cache, no-store, must-revalidate\"\nHeader set Pragma \"no-cache\"\nHeader set Expires \"Wed, 11 Jan 1984 05:00:00 GMT\"\n</IfModule>\n</FilesMatch>\n jquery.somefile.js?v=0.5\n" }, { "answer_id": 7307577, "author": "Darshan", "author_id": 536006, "author_profile": "https://Stackoverflow.com/users/536006", "pm_score": 0, "selected": false, "text": "<script language=\"javascript\" src=\"js/home.js\"></script>\n <script language=\"javascript\" src=\"js/home.js?id=${pageContext.session.id}\"></script>\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289751", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14955/" ]
289,756
<p>how do i make an autocomplete textbox in asp? but i need to get the autocomplete data by querying the database. I dont really know how to explain this, sory if theres not enough detail. i cant use ajax, because i think i will have compability issues with my old app. so im thinking of doing this using java script. or is there a way to do this by using .net? im using C# for codebehind. thanks</p>
[ { "answer_id": 289805, "author": "Phil Jenkins", "author_id": 35496, "author_profile": "https://Stackoverflow.com/users/35496", "pm_score": 2, "selected": false, "text": "ServiceMethod EnablePageMethods true <asp:ScriptManager>" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289756", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23491/" ]
289,760
<p>I need to automatically copy files from a linux machine to a windows one every day. </p> <p>I'm looking for something simple and secure like scp, rsync, sftp. Unfortunately, I'm at a loss of how to set this up on the Windows machine.</p> <p>Does anyone know how to do this?</p>
[ { "answer_id": 290470, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "man smbclient -c man expect mkdir /mnt/sharename smbclient -L WINDOWSHOSTNAME //WINDOWSHOSTNAME/sharename /mnt/sharename cifs credentials=/root/smblogin,uid=500,noauto,user 0 0 username=YOUR_WINDOWS_USERNAME\n password=YOUR_WINDOWS_PASSWOD mount /mnt/sharename #!/bin/sh\n df | grep -q /mnt/sharename\n if test $? -ne 0 ; then\n mount /mnt/sharename\n fi\n cp -r /path/to/dir /mnt/sharename/destination/ crontab -e PATH=/bin:/usr/bin\n # Backup at 2:15 A.M. every day. Run 'man 5 crontab' for help on the time format\n 15 2 * * * /path/to/backup.sh" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289760", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
289,770
<p>In the past I've always gone and called my namespace for a particular project the same as the project (and principle class) e.g.:</p> <pre><code>namespace KeepAlive { public partial class KeepAlive : ServiceBase {... </code></pre> <p>Then from other projects whenever i've called that class its always been:</p> <pre><code>KeepAlive.KeepAlive()... </code></pre> <p>I'm now beginning to think that this might not be such a good idea, but I'm sort of stumped what to actually call my namespace. What do other people do? Do you just have one namespace for all your projects?</p>
[ { "answer_id": 289827, "author": "splattne", "author_id": 6461, "author_profile": "https://Stackoverflow.com/users/6461", "pm_score": 4, "selected": true, "text": " CompanyName.ProductName\n CompanyName.ProductName.Data\n CompanyName.ProductName.Web\n CompanyName.ProductName.Web.Shop\n CompanyName.ProductName.Web.Newsletter\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289770", "https://Stackoverflow.com", "https://Stackoverflow.com/users/445/" ]
289,773
<p>I use the app.config file to store some values (path to a mapping database, data connection selections). These settings differ on the user machines and I would like the installer to set them right. Is there an installer that can work with .NET config files during setup and allow me to create some dialogs that would help me fill in these values ?</p> <p>I know this question may be similar to : <a href="https://stackoverflow.com/questions/75546/initializing-userconfig-or-appexeconfig-during-install">Initializing user.config or app.exe.config during install</a>, but I am not limited to VS 2008 setup project and I want to change the settings in the config files.</p> <p>EDIT: I see that using WIX is one option, but I feel like cracking a walnut with a sledgehammer. It may be the only solution, but I still hope for something simple.</p>
[ { "answer_id": 290374, "author": "CheGueVerra", "author_id": 17787, "author_profile": "https://Stackoverflow.com/users/17787", "pm_score": 7, "selected": true, "text": "<Component Id=\"ChangeConfig\" Guid=\"[YOUR_GUID_HERE]\">\n <File Id=\"App.config\" Name=\"MyApplication.exe.config\" Vital=\"yes\" KeyPath=\"yes\" Source=\"[Path to project dir]\\app.config\" />\n <util:XmlFile Id=\"AppConfigSetConnStr\" Action=\"setValue\" Permanent=\"yes\" File=\"[#App.config]\" \n ElementPath=\"/configuration/connectionStrings/add[\\[]@name='MyDatabaseName'[\\]]\" Name=\"connectionString\" \n Value=\"Your Connection string values here\" />\n\n</Component>\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289773", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4694/" ]
289,779
<p>I am working on a project where I need to create a boundary around a group of rectangles.</p> <p>Let's use this picture as an example of what I want to accomplish.</p> <p>EDIT: Couldn't get the image tag to work properly, so here is the full link: <a href="http://www.flickr.com/photos/21093416@N04/3029621742/" rel="nofollow noreferrer">http://www.flickr.com/photos/21093416@N04/3029621742/</a> </p> <p>We have rectangles A and C who are linked by a special link rectangle B. You could think of this as two nodes in a graph (A,C) and the edge between them (B). That means the rectangles have pointers to each other in the following manner: A->B, A&lt;-B->C, C->B</p> <p>Each rectangle has four vertices stored in an array where index 0 is bottom left, and index 3 is bottom right.</p> <p>I want to "traverse" this linked structure and calculate the vertices making up the boundary (red line) around it. I already have some small ideas around how to accomplish this, but want to know if some of you more mathematically inclined have some neat tricks up your sleeves.</p> <p>The reason I post this here is just that someone might have solved a similar problem before, and have some ideas I could use. I don't expect anyone to sit down and think this through long and hard. I'm going to work on a solution in parallell as I wait for answers.</p> <p>Any input is greatly appreciated.</p>
[ { "answer_id": 289829, "author": "Nailer", "author_id": 37346, "author_profile": "https://Stackoverflow.com/users/37346", "pm_score": 0, "selected": false, "text": " LinkRectsConnectedTo(Rectangle rectangle,Edge startEdge) // Edge can be West,North,East,South \n for each edge in rectangle starting with the edge facing last rectangle\n add vertices in the edge to the final boundary polygon\n if edge is connected to another rectangle\n if edge not equals startEdge\n recursively call LinkRectsConnectedTo(rectangle,startEdge)\n" }, { "answer_id": 290623, "author": "wimh", "author_id": 33499, "author_profile": "https://Stackoverflow.com/users/33499", "pm_score": 1, "selected": false, "text": " 1 2 3 4 5 6\n\n1 +---+---+\n | | \n2 + A +---+---+\n | | B |\n3 + + +---+---+\n | | | | |\n4 +---+---+---+---+ +\n | | \n5 + C +\n | |\n6 +---+---+\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289779", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37346/" ]
289,792
<p>What is the best way to convert an Int value to the corresponding Char in Utf16, given that the Int is in the range of valid values?</p>
[ { "answer_id": 289814, "author": "Corey Trager", "author_id": 9328, "author_profile": "https://Stackoverflow.com/users/9328", "pm_score": 6, "selected": false, "text": "int i = 65;\nchar c = Convert.ToChar(i);\n" }, { "answer_id": 289815, "author": "gimel", "author_id": 6491, "author_profile": "https://Stackoverflow.com/users/6491", "pm_score": 9, "selected": true, "text": "(char)myint;\n Console.WriteLine(\"(char)122 is {0}\", (char)122);\n" }, { "answer_id": 289966, "author": "Boaz", "author_id": 2892, "author_profile": "https://Stackoverflow.com/users/2892", "pm_score": 4, "selected": false, "text": "string s = Char.ConvertFromUtf32(56);\n" }, { "answer_id": 66606669, "author": "JohnL4", "author_id": 370611, "author_profile": "https://Stackoverflow.com/users/370611", "pm_score": 1, "selected": false, "text": "> [char]65\nA\n> [char]48\n0\n> [char]97\na\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289792", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2892/" ]
289,794
<p>I have an arraylist that contains items called Room. Each Room has a roomtype such as kitchen, reception etc. I want to check the arraylist to see if any rooms of that type exist before adding it to the list. Can anyone recommend a neat way of doing this without the need for multiple foreach loops?</p> <p>(.NET 2.0)</p> <hr> <p>I havent got access to the linq technology as am running on .net 2.0. I should have stated that in the question. Apologies</p>
[ { "answer_id": 289810, "author": "Bluenuance", "author_id": 33111, "author_profile": "https://Stackoverflow.com/users/33111", "pm_score": 1, "selected": false, "text": "if (!rooms.Any (r => r.RoomType == typeToFind /*kitchen, ...*/))\n //add it or whatever\n" }, { "answer_id": 289822, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 4, "selected": true, "text": "ArrayList List<T> List<Room> rooms = ...\nstring roomType = \"lounge\";\nbool exists = rooms.Exists(delegate(Room room) { return room.Type == roomType; });\n bool exists = rooms.Exists(room => room.Type == roomType);\n bool exists = rooms.Any(room => room.Type == roomType);\n Any List<T>" }, { "answer_id": 289908, "author": "Wolf5", "author_id": 37643, "author_profile": "https://Stackoverflow.com/users/37643", "pm_score": 0, "selected": false, "text": "O(n) Dictionary O(1) Dictionary Dictionary<Type, List<Room>> rooms = new Dictionary<Type, List<Room>>;\n\nvoid Main(){\n KitchenRoom kr = new KitchenRoom();\n DummyRoom dr = new DummyRoom();\n RoomType1 rt1 = new RoomType1();\n ... \n\n AddRoom(kr);\n AddRoom(dr);\n AddRoom(rt1);\n ...\n\n}\n\nvoid AddRoom(Room r){\n Type roomtype = r.GetType();\n if(!rooms.ContainsKey(roomtype){ //If the type is new, then add it with an empty list\n rooms.Add(roomtype, new List<Room>);\n }\n //And of course add the room.\n rooms[roomtype].Add(r);\n}\n List<string> Dictionary<mytype, bool>" }, { "answer_id": 291223, "author": "Robert Rossney", "author_id": 19403, "author_profile": "https://Stackoverflow.com/users/19403", "pm_score": 0, "selected": false, "text": "void AddRoom(Room r, IList<Room> rooms, IDictionary<string, bool> roomTypes)\n{\n if (!roomTypes.Contains(r.RoomType))\n {\n rooms.Add(r);\n roomTypes.Add(r.RoomType, true);\n }\n}\n" }, { "answer_id": 291297, "author": "Kennet Belenky", "author_id": 37788, "author_profile": "https://Stackoverflow.com/users/37788", "pm_score": 1, "selected": false, "text": "Room Room Dictionary<Type, Room> if(rooms.ContainsKey(room.GetType()))\n{\n // Can't add a second room of the same type\n ...\n}\nelse\n{\n rooms.Add(room.GetType(), room);\n}\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35441/" ]
289,800
<p>I have installed m2eclipse plugin from <a href="http://web.archive.org/web/20150524020820/http://m2eclipse.codehaus.org/" rel="nofollow noreferrer">http://m2eclipse.codehaus.org/</a>. Now I want to use that as a standalone build tool but I am unable to find the installation directory. Can anyone help me in this?</p>
[ { "answer_id": 289986, "author": "toolkit", "author_id": 3295, "author_profile": "https://Stackoverflow.com/users/3295", "pm_score": 3, "selected": false, "text": "C:\\Documents and Settings\\user\\.m2" }, { "answer_id": 39479104, "author": "Deepak Kumar Verma", "author_id": 5030747, "author_profile": "https://Stackoverflow.com/users/5030747", "pm_score": 4, "selected": false, "text": "mvn --version\n Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100)\nMaven home: `D:\\apache-maven-3.0.5\\bin`\\..\nJava version: 1.6.0_25, vendor: Sun Microsystems Inc.\nJava home: C:\\Program Files\\Java\\jdk1.6.0_25\\jre\nDefault locale: nl_NL, platform encoding: Cp1252\nOS name: \"windows 7\", version: \"6.1\", arch: \"amd64\", family: \"windows\"\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289800", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37626/" ]
289,801
<p>I'm searching for a way of developing a MethodInterceptor which prints the caller class.</p> <p>Is there any way of getting the caller object into the method interceptor?</p>
[ { "answer_id": 876341, "author": "bwobbones", "author_id": 213719, "author_profile": "https://Stackoverflow.com/users/213719", "pm_score": 3, "selected": true, "text": "\nThrowable t = new Throwable();\nStackTraceElement[] elements = t.getStackTrace();\n\nString calleeMethod = elements[0].getMethodName();\nString callerMethodName = elements[1].getMethodName();\nString callerClassName = elements[1].getClassName();\n\nSystem.out.println(\"CallerClassName=\" + callerClassName + \" , Caller method name: \" + callerMethodName);\nSystem.out.println(\"Callee method name: \" + calleeMethod);\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289801", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2937/" ]
289,804
<p>I've written a program that counts lines, words, and characters in a text: it does this with threads. It works great sometimes, but not so great other times. What ends up happening is the variables pointing to the number of words and characters counted sometimes come up short and sometimes don't.</p> <p>It seems to me that the threads are sometimes ending before they can count all the words or characters that they want to. Is it because these threads go out of scope when the while (true) loop breaks?</p> <p>I've included the code from the thready part of my problem below:</p> <pre><code>private void countText() { try { reader = new BufferedReader(new FileReader("this.txt")); while (true) { final String line = reader.readLine(); if(line == null) {break;} lines++; new Thread(new Runnable() {public void run() {chars += characterCounter(line);}}).start(); new Thread(new Runnable() {public void run() {words += wordCounter(line);}}).start(); println(line); } } catch(IOException ex) {return;} } </code></pre> <p>(Sub Question: This is the first time I've asked about something and posted code. I don't want to use StackOverflow in place of google and wikipedia and am worried that this isn't an appropriate question? I tried to make the question more general so that I'm not just asking for help with my code... but, is there another website where this kind of question might be more appropriate?)</p>
[ { "answer_id": 289851, "author": "WMR", "author_id": 2844, "author_profile": "https://Stackoverflow.com/users/2844", "pm_score": 2, "selected": false, "text": "chars words this this AtomicInteger chars = new AtomicInteger();\n...\nnew Thread(new Runnable() {public void run() { chars.addAndGet(characterCounter(line));}}).start();\n...\n run()" }, { "answer_id": 289869, "author": "Sam Stokes", "author_id": 20131, "author_profile": "https://Stackoverflow.com/users/20131", "pm_score": 4, "selected": true, "text": "chars words synchronized Atomic chars words" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289804", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29182/" ]
289,809
<p>how come this work </p> <pre><code>public IQueryable&lt;Category&gt; getCategories(int postId) { subnusMVCRepository&lt;Categories&gt; categories = new subnusMVCRepository&lt;Categories&gt;(); subnusMVCRepository&lt;Post_Category_Map&gt; postCategoryMap = new subnusMVCRepository&lt;Post_Category_Map&gt;(); var query = from c in categories.GetAll() join pcm in postCategoryMap.GetAll() on c.CategoryId equals pcm.CategoryId where pcm.PostId == 1 select new Category { Name = c.Name, CategoryId = c.CategoryId }; return query; } </code></pre> <p>but this does not</p> <pre><code>public IQueryable&lt;Category&gt; getCategories(int postId) { subnusMVCRepository&lt;Categories&gt; categories = new subnusMVCRepository&lt;Categories&gt;(); subnusMVCRepository&lt;Post_Category_Map&gt; postCategoryMap = new subnusMVCRepository&lt;Post_Category_Map&gt;(); var query = from c in categories.GetAll() join pcm in postCategoryMap.GetAll() on c.CategoryId equals pcm.CategoryId where pcm.PostId == postId select new Category { Name = c.Name, CategoryId = c.CategoryId }; return query; } </code></pre>
[ { "answer_id": 289844, "author": "Alexandre Brisebois", "author_id": 18619, "author_profile": "https://Stackoverflow.com/users/18619", "pm_score": 0, "selected": false, "text": "subnusMVCRepository<Categories> categories = new subnusMVCRepository<Categories>();\nsubnusMVCRepository<Post_Category_Map> postCategoryMap = new subnusMVCRepository<Post_Category_Map>();\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31296/" ]
289,812
<p>What is the best approach to play a sequence of flv video files in Flash (with actionscript)? My goal is to have the transitions occur as smoothly as possible.</p> <p>Currently i'm using the netStream class and capturing the onStatus events to play the next video when the current video has reached it's end duration. Althought this approach works fine, there is still a small gap between the ending of the current video and start of the next. Any ideas on how to optimize this method? </p> <p>Thanks in advance :) </p>
[ { "answer_id": 289844, "author": "Alexandre Brisebois", "author_id": 18619, "author_profile": "https://Stackoverflow.com/users/18619", "pm_score": 0, "selected": false, "text": "subnusMVCRepository<Categories> categories = new subnusMVCRepository<Categories>();\nsubnusMVCRepository<Post_Category_Map> postCategoryMap = new subnusMVCRepository<Post_Category_Map>();\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289812", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37630/" ]
289,825
<p>Why EAccessViolation is raised when executing the code below? </p> <pre><code>uses Generics.Collections; ... var list: TList&lt;TNotifyEvent&gt;; ... begin list := TList&lt;TNotifyEvent&gt;.Create(); try list.Add(myNotifyEvent); list.Remove(myNotifyEvent); // EAccessViolation at address... finally FreeAndNil(list); end; end; procedure myNotifyEvent(Sender: TObject); begin OutputDebugString('event'); // nebo cokoliv jineho end; </code></pre>
[ { "answer_id": 289870, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "uses \n Generics.Collections;\n\nprocedure TForm1.Button1Click(Sender: TObject);\nvar\n list: TList<TNotifyEvent>;\nbegin\n list := TList<TNotifyEvent>.Create();\n try\n list.Add(myNotifyEvent);\n list.Remove(myNotifyEvent); // EAccessViolation at address...\n finally\n FreeAndNil(list);\n end;\nend;\nprocedure TForm1.myNotifyEvent(Sender: TObject);\nbegin\n OutputDebugString('event'); // nebo cokoliv jineho\nend;\n" }, { "answer_id": 289885, "author": "Toon Krijthe", "author_id": 18061, "author_profile": "https://Stackoverflow.com/users/18061", "pm_score": 3, "selected": false, "text": "uses\n Generics.Defaults;\n\ntype\n TForm4 = class(TForm)\n ...\n private\n procedure myNotifyEvent(Sender: TObject);\n end;\n\nTComparer<T> = class (TInterfacedObject, IComparer<T>)\npublic\n function Compare(const Left, Right: T): Integer;\nend;\n\nimplementation\n\nuses\n Generics.Collections;\n\nvar\n list: TList<TNotifyEvent>;\nbegin\n list := TList<TNotifyEvent>.Create(TComparer<TNotifyEvent>.Create);\n try\n list.Add(myNotifyEvent);\n list.Remove(myNotifyEvent);\n finally\n FreeAndNil(list);\n end;\nend;\n\nprocedure TForm4.myNotifyEvent(Sender: TObject);\nbegin\n ShowMessage('event');\nend;\n\n{ TComparer<T> }\n\nfunction TComparer<T>.Compare(const Left, Right: T): Integer;\nbegin\n Result := 0;\nend;\n" }, { "answer_id": 289917, "author": "Steve", "author_id": 22712, "author_profile": "https://Stackoverflow.com/users/22712", "pm_score": 1, "selected": false, "text": "TList<T>" }, { "answer_id": 2066833, "author": "Just Jules", "author_id": 113086, "author_profile": "https://Stackoverflow.com/users/113086", "pm_score": 2, "selected": false, "text": "TList<TNotifyEvent>.Create(TComparer<TNotifyEvent>.Default);\n TObjectList<TNotifyEvent>.Create(TComparer<TNotifyEvent>.Default);\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289825", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
289,831
<p>During our build process we run <code>aspnet_compiler.exe</code> against our websites to make sure that all the late-bound stuff in ASP.NET/MVC actually builds (I know nothing about ASP.NET but am assured this is necessary to prevent finding the failures at runtime).</p> <p>Our sites are fairly large in size, with a few hundred pages/views/controls/etc. however the time taken seems excessive in the 10-15 minute range (for reference, this is longer than it takes the entire solution with approx 40 projects to compile, and we're only pre-compiling two website projects).</p> <p>I doubt that hardware is the issue as I'm running on the latest Quad core Intel chip, with 4GB RAM and a WD Velociraptor 10,000rpm hard disk. And part of what's odd is that the EXE doesn't seem to be using much CPU (1-5%) and doesn't seem to be doing an awful lot of I/O either.</p> <p>So... is this a known issue? Why is it so slow? And is there any way to speed it up?</p> <p><strong>Note:</strong> To clarify a couple of things people have answered about, I am not talking about the compilation of code within Visual Studio. We're using web application projects already, and the speed of compilation of those is not the issue. The problem is the pre-compilation of the site <em>after</em> these projects have already been compiled (<a href="http://msdn.microsoft.com/en-us/library/ms229863.aspx" rel="noreferrer">see this MSDN page for more details</a>) as part of the dev build script. We are performing in-place pre-compilation, not copying the files to a target directory.</p>
[ { "answer_id": 14349879, "author": "JerKimball", "author_id": 48692, "author_profile": "https://Stackoverflow.com/users/48692", "pm_score": 3, "selected": false, "text": "aspnet_compiler aspnet_compiler.exe" }, { "answer_id": 50762404, "author": "Alex from Jitbit", "author_id": 56621, "author_profile": "https://Stackoverflow.com/users/56621", "pm_score": -1, "selected": false, "text": "-fixednames aspnet_compiler.exe" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289831", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13552/" ]
289,841
<p>In OOP languages like C# or VB.NET, if I make the properties or methods in a super class <code>protected</code> I can't access them in my Form - they can only be accessed in my class that inherits from that super class.</p> <p>To access those properties or methods I need to make them <code>public</code>, which defeats encapsulation, or re-write them into my class, which defeats inheritance.</p> <p>What is the right way to do this?</p>
[ { "answer_id": 289891, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 2, "selected": true, "text": "private" }, { "answer_id": 10301924, "author": "supercat", "author_id": 363751, "author_profile": "https://Stackoverflow.com/users/363751", "pm_score": 0, "selected": false, "text": "private private" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289841", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
289,843
<p>Can anyone give me details of </p> <blockquote> <p>runtime error 3734</p> </blockquote> <p>in Access vba.</p> <p>For reference i am getting it from a code in the following thread</p> <p><a href="https://stackoverflow.com/questions/233026/how-to-run-a-loop-of-queries-in-access">How to run a loop of queries in access?</a></p> <pre><code>Sub plausibt_check() Dim rs As DAO.Recordset Dim rs2 As ADODB.Recordset Dim db As database Dim strsql As String Dim tdf As TableDef Set db = opendatabase("C:\Codebook.mdb") Set rs = db.OpenRecordset("querycrit") Set rs2 = CreateObject("ADODB.Recordset") rs2.ActiveConnection = CurrentProject.Connection For Each tdf In CurrentDb.TableDefs ' in this line the error occurs </code></pre>
[ { "answer_id": 294363, "author": "David-W-Fenton", "author_id": 9787, "author_profile": "https://Stackoverflow.com/users/9787", "pm_score": 1, "selected": false, "text": " Dim db As DAO.Database\n Dim qdf As DAO.QueryDef\n\n Set db = CurrentDB()\n\n For Each qdf in db.QueryDef\n [do whatever here]\n Next qdf\n\n Set qdf = Nothing\n Set db = Nothing\n Public Sub ProcessQueries(db As DAO.Database)\n Dim qdf As DAO.QueryDef\n\n For Each qdf in db.QueryDef\n [do whatever here]\n Next qdf\n\n Set qdf = Nothing\n End Sub\n Dim db As DAO.Database\n\n Set db = CurrentDB() \n Call ProcessQueries(db) \n Set db = Nothing\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289843", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31132/" ]
289,845
<p>Why must <code>Type.Equals(t1, t2)</code> be used to determine equivalent types, and not the equality operator (e.g. for VB.NET, <code>t1 = t2</code>)? </p> <p>It seems inconsistent with other parts of the .NET API.</p> <p>Example in VB.NET:</p> <p><code>If GetType(String) = GetType(String) Then Debug.Print("The same, of course") End If</code></p> <p>causes a compile-time error of "<code>Operator '=' is not defined for types 'System.Type' and 'System.Type'.</code>"</p>
[ { "answer_id": 289880, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 2, "selected": false, "text": "is IsInstanceOf Typeof a Is Boolean\n\na.GetType().IsAssignableFrom( b.GetType() )\n" }, { "answer_id": 290977, "author": "RS Conley", "author_id": 7890, "author_profile": "https://Stackoverflow.com/users/7890", "pm_score": 0, "selected": false, "text": "Public Class Form1\n\n Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click\n Dim X As New TestObject\n Dim Y As New TestObject\n\n If X Is Y Then MsgBox(\"The Same 1\")\n If Type.Equals(X, Y) Then MsgBox(\"The Same 2\")\n\n X = Y\n If X Is Y Then MsgBox(\"The Same 3\")\n\n If Type.Equals(X, Y) Then MsgBox(\"The Same 4\")\n End Sub\nEnd Class\n\nPublic Class TestObject\n Public Value As Double\nEnd Class\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289845", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
289,850
<p>There is a space of x*y for text to go on $im (GD Image Resource) how can I choose a font size (or write text such that) it does not overflow over that area?</p>
[ { "answer_id": 289880, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 2, "selected": false, "text": "is IsInstanceOf Typeof a Is Boolean\n\na.GetType().IsAssignableFrom( b.GetType() )\n" }, { "answer_id": 290977, "author": "RS Conley", "author_id": 7890, "author_profile": "https://Stackoverflow.com/users/7890", "pm_score": 0, "selected": false, "text": "Public Class Form1\n\n Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click\n Dim X As New TestObject\n Dim Y As New TestObject\n\n If X Is Y Then MsgBox(\"The Same 1\")\n If Type.Equals(X, Y) Then MsgBox(\"The Same 2\")\n\n X = Y\n If X Is Y Then MsgBox(\"The Same 3\")\n\n If Type.Equals(X, Y) Then MsgBox(\"The Same 4\")\n End Sub\nEnd Class\n\nPublic Class TestObject\n Public Value As Double\nEnd Class\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289850", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21559/" ]
289,865
<p>I have a web page that uses a frameset.</p> <p>Due to scripting and object dependencies, I need to load the frames in a specific order.</p> <p>I have used this example as a template: <a href="http://javascript.internet.com/navigation/frames-load-order.html" rel="nofollow noreferrer">The JavaScript Source: Navigation: Frames Load Order</a></p> <p>This loads an empty page in place of the page I need to load last, then replaces it with the correct page after the first page has loaded.</p> <p>However: I also need to use the browser Back button. If you run the sample at the above link, let both frames load, then click the Back button, the top frame reverts to the temporary blank page. It is then necessary to click the Back button again to navigate to the page before the frameset.</p> <p>Is there a way to force frames to load in a specific order without this Back button behavior - or a way to force the Back button to skip the empty page?</p> <p>This needs to work with Internet Explorer 6 and 7 and preferably with Firefox 3 as well.</p>
[ { "answer_id": 291419, "author": "Diodeus - James MacFarlane", "author_id": 12579, "author_profile": "https://Stackoverflow.com/users/12579", "pm_score": 0, "selected": false, "text": "<html>\n<head>\n<script>\nfunction makeFrame(frameName) {\n var newFrame = document.createElement('frame');\n newFrame.id=frameName;\n if(frameName==\"B\") {\n newFrame.onload=function() {makeFrame(\"C\")};\n newFrame.src = 'http://www.google.com';\n }\n else {\n newFrame.src = 'http://www.yahoo.com';\n }\n document.getElementById('A').appendChild(newFrame);\n\n}\n</script>\n</head>\n<frameset name='A' id='A' rows=\"80, *\" onload=\"makeFrame('B')\"></frameset>\n</html>\n" }, { "answer_id": 294079, "author": "geocar", "author_id": 37507, "author_profile": "https://Stackoverflow.com/users/37507", "pm_score": 0, "selected": false, "text": "<iframe id=\"a1\" src=\"page-to-load-first.htm\"></iframe>\n<iframe id=\"a2\" src=\"page-to-load-second.htm\"></iframe>\n<iframe id=\"a3\" src=\"page-to-load-third.htm\"></iframe>\n<script>\nfunction pos(elem,x,y,w,h) {\n if (!elem.style) elem=document.getElementById(elem);\n elem.style.position='absolute';\n elem.style.top = y+'px';\n elem.style.left= x+'px';\n elem.style.width=w+'px';\n elem.style.height=h+'px';\n}\nwindow.onload = function() {\n window.onresize=function() {\n var w = window.innerWidth || document.documentElement.clientWidth;\n var h = window.innerHeight || document.documentElement.clientHeight;\n var w3 = w/3;\n var h2 = h/2;\n pos('a1',0,0,w3,h); /* left 1/3rd */\n pos('a2',w3,0,w3+w3,h2);\n pos('a3',w3,h2,w3+w3,h2);\n };\n window.onresize();\n};\n</script>\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289865", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
289,875
<p>The assembly it's trying to find isn't the root assembly - it's a referenced one, but it's in the same folder, and Directory.GetCurrentDirectory() is the folder with all of the files in.</p> <p>I'm stuck - any suggestions?</p>
[ { "answer_id": 289877, "author": "Kent Boogaart", "author_id": 5380, "author_profile": "https://Stackoverflow.com/users/5380", "pm_score": 3, "selected": true, "text": "AppDomain AppDomain AppDomain.AssemblyResolve" }, { "answer_id": 290175, "author": "Chris Marisic", "author_id": 37055, "author_profile": "https://Stackoverflow.com/users/37055", "pm_score": 0, "selected": false, "text": "string myDll = string.Empty;\nstring location = Assembly.GetExecutingAssembly().Location;\nif (location != null)\n{\n myDll = string.Format(@\"{0}\\my.assembly.name.dll\", location.Substring(0, location.LastIndexOf(@\"\\\")));\n}\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289875", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26874/" ]
289,900
<p>I am working on turbo C on windows where char takes one byte.Now my problem is with the below union.</p> <pre><code>union a { unsigned char c:2; }b; void main() { printf("%d",sizeof(b)); \\or even sizeof(union a) } </code></pre> <p><p>This program is printing output as 2 where as union should be taking only 1 byte. Why is it so? <p>for struct it is fine giving 1 byte but this union is working inappropriately. <p><b>And one more </b>thing how to access these bit fields.</p> <pre><code>scanf("%d",&amp;b.c); //even scanf("%x",b.c); </code></pre> <p><p>is not working because we cannot have address for bits.So we have to use another variable like below</p> <pre><code>int x; scanf("%d",&amp;x); b.c=x; </code></pre> <p><p>cant we avoid it?? is there any other way???</p>
[ { "answer_id": 289925, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 1, "selected": false, "text": "The operand of the unary & operator shall be either a function\ndesignator or an lvalue that designates an object that is not a\nbit-field and is not declared with the register storage-class\nspecifier. void func(void) { struct bits f; { int x; scanf(\"%d\", &x); f.bitfield = x; } /* ... */ }\n" }, { "answer_id": 289993, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 3, "selected": true, "text": "#pragma pack(1)" }, { "answer_id": 2176417, "author": "Andrew", "author_id": 263489, "author_profile": "https://Stackoverflow.com/users/263489", "pm_score": 1, "selected": false, "text": "#pragma pack #pragma pack(1)\n #pragma pack() scanf" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289900", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31116/" ]
289,909
<p>I can't find a pre-built set of MSVC++ libs for Boost 1.37.0, only the source. I don't understand how their weird build system works... are there any places I can find a download of a visual studio project or something?</p>
[ { "answer_id": 289983, "author": "Ferruccio", "author_id": 4086, "author_profile": "https://Stackoverflow.com/users/4086", "pm_score": 2, "selected": false, "text": "bjam --help bjam --prefix=C:\\boost --build-dir=C:\\build --build-type=complete install\n" }, { "answer_id": 289995, "author": "MattyT", "author_id": 7405, "author_profile": "https://Stackoverflow.com/users/7405", "pm_score": 3, "selected": false, "text": "bjam --build-dir=\"C:\\boostsource\" --toolset=msvc --build-type=complete stage\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289909", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13220/" ]
289,914
<p>I know what I'm looking for is probably a security hole, but since I managed to do it in Oracle and SQL Server, I'll give it a shot:</p> <p>I'm looking for a way to execute a shell command from a SQL script on MySQL. It is possible to create and use a new stored procedure if necessary.</p> <p>Notice: I'm not looking for the SYSTEM command which the mysql command line tool offers. Instead I'm looking for something like this:</p> <blockquote> <p> BEGIN IF COND1... EXEC_OS cmd1; ELSE EXEC_OS cmd2; END;</p> </blockquote> <p>where EXEC_OS is the method to invocate my code.</p>
[ { "answer_id": 300845, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 2, "selected": true, "text": "START TRANSACTION;\nCALL MyProcedure();\nROLLBACK;\n MyProcedure" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289914", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9941/" ]
289,916
<p>I always hear that using "lastInsertId" (or mysql_insert_id() if you're not using PDO) is evil. In case of triggers it obviously is, because it could return something that's totally not the last ID that your INSERT created.</p> <pre><code>$DB-&gt;exec("INSERT INTO example (column1) VALUES ('test')"); // Usually returns your newly created ID. // However when a TRIGGER inserts into another table with auto-increment: // -&gt; Returns newly created ID of trigger's INSERT $id = $DB-&gt;lastInsertId(); </code></pre> <p>What's the alternative?</p>
[ { "answer_id": 289928, "author": "Peter Howe", "author_id": 24106, "author_profile": "https://Stackoverflow.com/users/24106", "pm_score": 0, "selected": false, "text": "INSERT INTO example (column1) VALUES ('test');\nSELECT id FROM example WHERE column1 = 'test';\n" }, { "answer_id": 11522839, "author": "mikeyD", "author_id": 1531827, "author_profile": "https://Stackoverflow.com/users/1531827", "pm_score": -1, "selected": false, "text": "$sql = \"SELECT id FROM files ORDER BY id DESC LIMIT 1\";\n$PS = $DB -> prepare($sql);\n$PS -> execute();\n$result = $PS -> fetch();\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289916", "https://Stackoverflow.com", "https://Stackoverflow.com/users/999/" ]
289,936
<p>How to get the number of years between two <code>java.util.Date</code>?</p> <p><strong>Note:</strong> using only <code>java.util.Date</code></p>
[ { "answer_id": 289947, "author": "Paul Tomblin", "author_id": 3333, "author_profile": "https://Stackoverflow.com/users/3333", "pm_score": 3, "selected": false, "text": "long msDiff = date1.getTime() - date2.getTime();\nint yearDiff = (int)(msDiff / 1000 / 60 / 60 / 24 / 365.25);\n" }, { "answer_id": 317449, "author": "Hubert", "author_id": 29525, "author_profile": "https://Stackoverflow.com/users/29525", "pm_score": 1, "selected": false, "text": "import org.joda.time.DateTime;\nimport org.joda.time.Period;\n\nimport static java.lang.System.out;\n\npublic class App {\n public static void main(String[] args) {\n final DateTime now = new DateTime();\n out.println(new Period(now.minusYears(2), now).getYears());\n out.println(new Period(now.minusYears(2).plusHours(1), now).getYears());\n }\n}\n 2\n1\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
289,951
<p>Can I use Xpath node set function position() in Delphi's function selectNodes() to select only a certain number of element from a node list? If I do like this: </p> <pre><code>selectNodes('Item[1]') </code></pre> <p>its all fine and I get the element with index 1, but when I try </p> <pre><code>selectNodes('Item[position()&lt;10]') </code></pre> <p>I get exception 'unknown method', when I try </p> <pre><code>selectNodes('Item[&lt;10]') </code></pre> <p>I get 'unexpected token &lt;'. Im using delphi7 and I also imported new type library into my project with newer versions of msxml.</p>
[ { "answer_id": 289968, "author": "Toon Krijthe", "author_id": 18061, "author_profile": "https://Stackoverflow.com/users/18061", "pm_score": 0, "selected": false, "text": "selectNodes('Item[position()<10]')\n" }, { "answer_id": 290029, "author": "Oliver Giesen", "author_id": 9784, "author_profile": "https://Stackoverflow.com/users/9784", "pm_score": 1, "selected": false, "text": "Item[position() &lt; 10] Item" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289951", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26207/" ]
289,965
<p>I would like to create a simple program (in Java) which edits text files - particularly one which performs inserting arbitrary pieces of text at random positions in a text file. This feature is part of a larger program I am currently writing.</p> <p>Reading the description about java.util.RandomAccessFile, it appears that any write operations performed in the middle of a file would actually overwrite the exiting content. This is a side-effect which I would like to avoid (if possible).</p> <p>Is there a simple way to achieve this?</p> <p>Thanks in advance.</p>
[ { "answer_id": 6235119, "author": "S.Yavari", "author_id": 526196, "author_profile": "https://Stackoverflow.com/users/526196", "pm_score": 2, "selected": false, "text": "BufferedReader reader = null;\nBufferedWriter writer = null;\nArrayList list = new ArrayList();\n\ntry {\n reader = new BufferedReader(new FileReader(fileName));\n String tmp;\n while ((tmp = reader.readLine()) != null)\n list.add(tmp);\n OUtil.closeReader(reader);\n\n list.add(0, \"Start Text\");\n list.add(\"End Text\");\n\n writer = new BufferedWriter(new FileWriter(fileName));\n for (int i = 0; i < list.size(); i++)\n writer.write(list.get(i) + \"\\r\\n\");\n} catch (Exception e) {\n e.printStackTrace();\n} finally {\n OUtil.closeReader(reader);\n OUtil.closeWriter(writer);\n}\n" }, { "answer_id": 17565931, "author": "xor_eq", "author_id": 350891, "author_profile": "https://Stackoverflow.com/users/350891", "pm_score": 5, "selected": true, "text": "public void insert(String filename, long offset, byte[] content) {\n RandomAccessFile r = new RandomAccessFile(new File(filename), \"rw\");\n RandomAccessFile rtemp = new RandomAccessFile(new File(filename + \"~\"), \"rw\");\n long fileSize = r.length();\n FileChannel sourceChannel = r.getChannel();\n FileChannel targetChannel = rtemp.getChannel();\n sourceChannel.transferTo(offset, (fileSize - offset), targetChannel);\n sourceChannel.truncate(offset);\n r.seek(offset);\n r.write(content);\n long newOffset = r.getFilePointer();\n targetChannel.position(0L);\n sourceChannel.transferFrom(targetChannel, newOffset, (fileSize - offset));\n sourceChannel.close();\n targetChannel.close();\n}\n" }, { "answer_id": 69457622, "author": "mdre", "author_id": 15110659, "author_profile": "https://Stackoverflow.com/users/15110659", "pm_score": 0, "selected": false, "text": "public static void insert(String filename, long offset, byte[] content) throws IOException {\n File temp = Files.createTempFile(\"insertTempFile\", \".temp\").toFile(); // Create a temporary file to save content to\n try (RandomAccessFile r = new RandomAccessFile(new File(filename), \"rw\"); // Open file for read & write\n RandomAccessFile rtemp = new RandomAccessFile(temp, \"rw\"); // Open temporary file for read & write\n FileChannel sourceChannel = r.getChannel(); // Channel of file\n FileChannel targetChannel = rtemp.getChannel()) { // Channel of temporary file\n long fileSize = r.length();\n sourceChannel.transferTo(offset, (fileSize - offset), targetChannel); // Copy content after insert index to\n // temporary file\n sourceChannel.truncate(offset); // Remove content past insert index from file\n r.seek(offset); // Goto back of file (now insert index)\n r.write(content); // Write new content\n long newOffset = r.getFilePointer(); // The current offset\n targetChannel.position(0L); // Goto start of temporary file\n sourceChannel.transferFrom(targetChannel, newOffset, (fileSize - offset)); // Copy all content of temporary\n // to end of file\n }\n Files.delete(temp.toPath()); // Delete the temporary file as not needed anymore\n} \n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289965", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37651/" ]
289,972
<p>Is it possible to use e.g. SQLite with PowerBuilder? I need an embedded open source database (no additional costs). </p>
[ { "answer_id": 854940, "author": "Dan Cooperstock", "author_id": 105734, "author_profile": "https://Stackoverflow.com/users/105734", "pm_score": 1, "selected": false, "text": "[Firebird]\nPBSyntax='Firebird_SYNTAX'\nPBNoCatalog='YES'\n\n[Firebird_SYNTAX]\nCreateTable='CREATE TABLE &TableName (::ColumnElement[::ColumnElement]...)'\nColumnElement='&ColumnName &DataType'\nDropTable='DROP TABLE &TableName'\nGetIdentity='Select gen_id(GEN_&TableName,0) from RDB$DATABASE'\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4235/" ]
289,978
<p>I've got mssql 2005 running on my personal computer with a database I'd like to run some python scripts on. I'm looking for a way to do some really simple access on the data. I'd like to run some select statements, process the data and maybe have python save a text file with the results.</p> <p>Unfortunately, even though I know a bit about python and a bit about databases, it's very difficult for me to tell, just from reading, if a library does what I want. Ideally, I'd like something that works for other versions of mssql, is free of charge and licensed to allow commercial use, is simple to use, and possibly works with ironpython.</p>
[ { "answer_id": 291473, "author": "ConcernedOfTunbridgeWells", "author_id": 15401, "author_profile": "https://Stackoverflow.com/users/15401", "pm_score": 4, "selected": false, "text": "import odbc\n\nCONNECTION_STRING=\"\"\"\nDriver={SQL Native Client};\nServer=[Insert Server Name Here];\nDatabase=[Insert DB Here];\nTrusted_Connection=yes;\n\"\"\"\n\ndb = odbc.odbc(CONNECTION_STRING)\nc = db.cursor()\nc.execute ('select foo from bar')\nrs = c.fetchall()\nfor r in rs:\n print r[0]\n" }, { "answer_id": 301746, "author": "babbageclunk", "author_id": 38851, "author_profile": "https://Stackoverflow.com/users/38851", "pm_score": 5, "selected": false, "text": "import clr\nclr.AddReference('System.Data')\nfrom System.Data.SqlClient import SqlConnection, SqlParameter\n\nconn_string = 'data source=<machine>; initial catalog=<database>; trusted_connection=True'\nconnection = SqlConnection(conn_string)\nconnection.Open()\ncommand = connection.CreateCommand()\ncommand.CommandText = 'select id, name from people where group_id = @group_id'\ncommand.Parameters.Add(SqlParameter('group_id', 23))\n\nreader = command.ExecuteReader()\nwhile reader.Read():\n print reader['id'], reader['name']\n\nconnection.Close()\n" }, { "answer_id": 7422797, "author": "shellster", "author_id": 315482, "author_profile": "https://Stackoverflow.com/users/315482", "pm_score": 0, "selected": false, "text": "def getSQLServerDriver():\n key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r\"SOFTWARE\\ODBC\\ODBCINST.INI\")\n sqlServerRegExp = re.compile('sql.*server', re.I | re.S)\n\n try:\n for i in range(0, 2048):\n folder = winreg.EnumKey(key, i)\n if sqlServerRegExp.match(folder):\n return folder.strip()\n except WindowsError:\n pass\n dbString = \"Driver={SQLDriver};Server=[SQL Server];Database=[Database Name];Trusted_Connection=yes;\".replace('{SQLDriver}', '{' + getSQLServerDriver() + '}')\n" }, { "answer_id": 12613800, "author": "pypyodbc", "author_id": 1699111, "author_profile": "https://Stackoverflow.com/users/1699111", "pm_score": 2, "selected": false, "text": "#import pyodbc <-- Comment out the original pyodbc importing line\n\nimport pypyodbc as pyodbc # Let pypyodbc \"pretend\" the pyodbc\n\npyodbc.connect(...) # pypyodbc has 99% same APIs as pyodbc\n\n...\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289978", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25680/" ]
289,979
<p>I want to automate tests on my web application, and it uses postgresql. Does anyone know how define a restore point on a postgresql database and restore to an earlier state? I heard something about point in time recovery, but i dont if this is what i need.</p> <p>Thanks in advance</p>
[ { "answer_id": 291473, "author": "ConcernedOfTunbridgeWells", "author_id": 15401, "author_profile": "https://Stackoverflow.com/users/15401", "pm_score": 4, "selected": false, "text": "import odbc\n\nCONNECTION_STRING=\"\"\"\nDriver={SQL Native Client};\nServer=[Insert Server Name Here];\nDatabase=[Insert DB Here];\nTrusted_Connection=yes;\n\"\"\"\n\ndb = odbc.odbc(CONNECTION_STRING)\nc = db.cursor()\nc.execute ('select foo from bar')\nrs = c.fetchall()\nfor r in rs:\n print r[0]\n" }, { "answer_id": 301746, "author": "babbageclunk", "author_id": 38851, "author_profile": "https://Stackoverflow.com/users/38851", "pm_score": 5, "selected": false, "text": "import clr\nclr.AddReference('System.Data')\nfrom System.Data.SqlClient import SqlConnection, SqlParameter\n\nconn_string = 'data source=<machine>; initial catalog=<database>; trusted_connection=True'\nconnection = SqlConnection(conn_string)\nconnection.Open()\ncommand = connection.CreateCommand()\ncommand.CommandText = 'select id, name from people where group_id = @group_id'\ncommand.Parameters.Add(SqlParameter('group_id', 23))\n\nreader = command.ExecuteReader()\nwhile reader.Read():\n print reader['id'], reader['name']\n\nconnection.Close()\n" }, { "answer_id": 7422797, "author": "shellster", "author_id": 315482, "author_profile": "https://Stackoverflow.com/users/315482", "pm_score": 0, "selected": false, "text": "def getSQLServerDriver():\n key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r\"SOFTWARE\\ODBC\\ODBCINST.INI\")\n sqlServerRegExp = re.compile('sql.*server', re.I | re.S)\n\n try:\n for i in range(0, 2048):\n folder = winreg.EnumKey(key, i)\n if sqlServerRegExp.match(folder):\n return folder.strip()\n except WindowsError:\n pass\n dbString = \"Driver={SQLDriver};Server=[SQL Server];Database=[Database Name];Trusted_Connection=yes;\".replace('{SQLDriver}', '{' + getSQLServerDriver() + '}')\n" }, { "answer_id": 12613800, "author": "pypyodbc", "author_id": 1699111, "author_profile": "https://Stackoverflow.com/users/1699111", "pm_score": 2, "selected": false, "text": "#import pyodbc <-- Comment out the original pyodbc importing line\n\nimport pypyodbc as pyodbc # Let pypyodbc \"pretend\" the pyodbc\n\npyodbc.connect(...) # pypyodbc has 99% same APIs as pyodbc\n\n...\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289979", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37650/" ]
289,980
<p>Given the following class: </p> <pre><code>class TestClass { public void SetValue(int value) { Value = value; } public int Value { get; set; } } </code></pre> <p>I can do </p> <pre><code>TestClass tc = new TestClass(); Action&lt;int&gt; setAction = tc.SetValue; setAction.Invoke(12); </code></pre> <p>which is all good. Is it possible to do the same thing using the property instead of the method? Preferably with something built in to .net. </p>
[ { "answer_id": 289985, "author": "Kieron", "author_id": 5791, "author_profile": "https://Stackoverflow.com/users/5791", "pm_score": 2, "selected": false, "text": "var propertyInfo = typeof (TestClass).GetProperty (\"Value\");\n\nvar setMethod = property.GetSetMethod (); // This will return a MethodInfo class.\n" }, { "answer_id": 290012, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 4, "selected": false, "text": " class TestClass\n {\n public int Value { get; set; }\n }\n static void Main()\n {\n Func<TestClass, int> lambdaGet = x => x.Value;\n Action<TestClass, int> lambdaSet = (x, val) => x.Value = val;\n\n var prop = typeof(TestClass).GetProperty(\"Value\");\n Func<TestClass, int> reflGet = (Func<TestClass, int>) Delegate.CreateDelegate(\n typeof(Func<TestClass, int>), prop.GetGetMethod());\n Action<TestClass, int> reflSet = (Action<TestClass, int>)Delegate.CreateDelegate(\n typeof(Action<TestClass, int>), prop.GetSetMethod());\n }\n TestClass foo = new TestClass();\n foo.Value = 1;\n Console.WriteLine(\"Via property: \" + foo.Value);\n\n lambdaSet(foo, 2);\n Console.WriteLine(\"Via lambda: \" + lambdaGet(foo));\n\n reflSet(foo, 3);\n Console.WriteLine(\"Via CreateDelegate: \" + reflGet(foo));\n" }, { "answer_id": 290017, "author": "Pop Catalin", "author_id": 4685, "author_profile": "https://Stackoverflow.com/users/4685", "pm_score": 5, "selected": true, "text": "Action<int> valueSetter = (Action<int>)Delegate.CreateDelegate(typeof(Action<int>), tc, tc.GetType().GetProperty(\"Value\").GetSetMethod());\n Action<int> valueSetter = v => tc.Value = v;\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289980", "https://Stackoverflow.com", "https://Stackoverflow.com/users/143/" ]
289,997
<p>What does "Overloaded"/"Overload" mean in regards to programming?</p>
[ { "answer_id": 290003, "author": "Filip Frącz", "author_id": 21704, "author_profile": "https://Stackoverflow.com/users/21704", "pm_score": 6, "selected": true, "text": "void doSomething();\nint doSomething(string x);\nint doSomething(int a, int b, int c);\n" }, { "answer_id": 290004, "author": "Gorpik", "author_id": 25824, "author_profile": "https://Stackoverflow.com/users/25824", "pm_score": 3, "selected": false, "text": "void print(int i);\nvoid print(char i);\nvoid print(UserDefinedType t);\n" }, { "answer_id": 290008, "author": "Aistina", "author_id": 37472, "author_profile": "https://Stackoverflow.com/users/37472", "pm_score": 2, "selected": false, "text": "void Print(std::string str) {\n std::cout << str << endl;\n}\n void Print(int i) {\n std::cout << i << endl;\n}\n" }, { "answer_id": 290010, "author": "The.Anti.9", "author_id": 2128, "author_profile": "https://Stackoverflow.com/users/2128", "pm_score": 1, "selected": false, "text": "foo(foo)\n\nfoo(foo, bar)\n int Convert(int i)\nint Convert(double i)\nint Convert(float i)\n" }, { "answer_id": 290031, "author": "Serhat Ozgel", "author_id": 31505, "author_profile": "https://Stackoverflow.com/users/31505", "pm_score": 4, "selected": false, "text": "new DateTime(2008, 11, 14).ToString(); // returns \"14/11/2008\" in America\n new DateTime(2008, 11, 14).ToString(\"dd MMM yyyy\"); // returns \"11 Nov 2008\"\n Convert.ToInt32(123m);\n Convert.ToInt32(\"123\");\n" }, { "answer_id": 419549, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 2, "selected": false, "text": "virtual override using System;\n\npublic class DrawingObject\n{\n public virtual void Draw()\n {\n Console.WriteLine(\"I'm just a generic drawing object.\");\n }\n}\n\npublic class Line : DrawingObject\n{\n public override void Draw()\n {\n Console.WriteLine(\"I'm a Line.\");\n }\n}\n" }, { "answer_id": 758399, "author": "Damien Pollet", "author_id": 63112, "author_profile": "https://Stackoverflow.com/users/63112", "pm_score": 0, "selected": false, "text": "Line Draw()" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/289997", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21559/" ]
290,007
<p>Imagine you had a group of product categories organized in a nice tree hierarchy and you wanted to provide hackable urls to browse these. You could do something like this</p> <pre><code>/catalog/categorya/categoryb/categoryc </code></pre> <p>You could then quite easily figure out which category you should list the products for (note that the full URL is needed since you could have categories with the same name but at different locations in the hierarchy)</p> <p>Now what would be a good approach to add product information in that as well? To give you an example, you wanted to display the product Oblivion for this category </p> <pre><code>/catalog/games/consoles/playstation/adventure </code></pre> <p>It's tempting to just add the product at the end of the url</p> <pre><code>/catalog/games/consoles/playstation/adventure/oblivion </code></pre> <p>but the moment you do so you loose the ability to know if its category or a product which is called oblivion. I personally feel that not being forced to add a suffix such as .html</p> <pre><code>/catalog/games/consoles/playstation/adventure/oblivion.html </code></pre> <p>would be the nicest solution and using some sort of prefix, such as </p> <pre><code>/catalog/games/consoles/playstation/adventure/product:oblivion </code></pre> <p>You could also add some sort of trigger like</p> <pre><code>/catalog/games/consoles/playstation/adventure/PRODUCT/oblivion </code></pre> <p>not as nice either and you would (even though its very unlikely it would be a problem) restrict yourself from having a category called <em>product</em></p> <p>So far a suffix solution looks like the most user-friendly approach that I can think of from the top of my head but I'm not fond of having to use an extension</p> <p>What are your thoughts on this?</p>
[ { "answer_id": 311192, "author": "Chris Lloyd", "author_id": 42413, "author_profile": "https://Stackoverflow.com/users/42413", "pm_score": 3, "selected": false, "text": "/catalog/games/consoles/playstation/adventure/oblivion\n adventure /catalog/games/consoles/playstation/oblivion\n /catalog/games/playstation/oblivion\n playstation games /catalog/oblivion\n /catalog/tags/playstation+adventure\n /catalog/tags/adventure/playstation\n tags /catalog /oblivion\n/tags/playstation/adventure\n oblivion /1234-oblivion\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25319/" ]
290,011
<p>I distribute my application using a VS2008 install package, which normally works great. When I create new versions of the app, I go in and increment the <code>Version</code> property on the install package and verify the <code>RemovePreviousVersions</code> property is set to True.</p> <p>This works just fine most of the time - I just run the install package for the newer version and the older version is uninstalled and the newer version replaces it.</p> <p>However, occasionally the install package will run successfully, but when I start the program the old version starts up. Apparently the old version of the .exe is still present.</p> <p>I end up having to completely uninstall the software and install the new version, which always works, but is a pain.</p> <p>The file isn't in use as far as I can tell and the install package doesn't tell me to reboot.</p> <p>Any ideas about what's going on here?</p>
[ { "answer_id": 2294911, "author": "Jinal Desai - LIVE", "author_id": 276758, "author_profile": "https://Stackoverflow.com/users/276758", "pm_score": 2, "selected": false, "text": " a. Install orca into your computer.\n b. Open orca\n c. Drag and drop your msi into orca UI\n d. Into left panel it will list the name of tables\n e. select property table\n f. go to right panel and right click\n g. click on 'Add Row'\n h. into 'Property' type REINSTALLMODE\n i. into 'Value' type amus\n j. save msi file\n k. and that's it\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290011", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35229/" ]
290,018
<p>I have a Repeater control on ASPX-page defined like this:</p> <pre><code>&lt;asp:Repeater ID="answerVariantRepeater" runat="server" onitemdatabound="answerVariantRepeater_ItemDataBound"&gt; &lt;ItemTemplate&gt; &lt;asp:RadioButton ID="answerVariantRadioButton" runat="server" GroupName="answerVariants" Text='&lt;%# DataBinder.Eval(Container.DataItem, "Text")%&gt;'"/&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt; </code></pre> <p>To allow select only one radio button in time I have used a trick form <a href="http://www.codeguru.com/csharp/csharp/cs_controls/custom/article.php/c12371/" rel="noreferrer">this article</a>.</p> <p>But now when form is submitted I want to determine which radio button is checked.</p> <p>I could do this:</p> <pre><code>RadioButton checkedButton = null; foreach (RepeaterItem item in answerVariantRepeater.Items) { RadioButton control=(RadioButton)item.FindControl("answerVariantRadioButton"); if (control.Checked) { checkedButton = control; break; } } </code></pre> <p>but hope it could be done somehow simplier (maybe via LINQ to objects).</p>
[ { "answer_id": 290295, "author": "Kevin Gorski", "author_id": 35806, "author_profile": "https://Stackoverflow.com/users/35806", "pm_score": 2, "selected": false, "text": "RadioButton checked = \n (from item in answerVariantRepeater.Items\n let radioButton = (RadioButton)item.FindControl(\"answerVariantRadioButton\")\n where radioButton.Checked\n select radioButton).FirstOrDefault();\n" }, { "answer_id": 5896805, "author": "Ian Oxley", "author_id": 1904, "author_profile": "https://Stackoverflow.com/users/1904", "pm_score": 3, "selected": false, "text": "Request.Form var value = Request.Form[\"answerVariants\"];\n <asp:RadioButton /> <asp:RadioButton /> <asp:RadioButton ID=\"answerVariantRadioButton\" runat=\"server\"\n GroupName=\"answerVariants\" \n Text='<%# DataBinder.Eval(Container.DataItem, \"Text\")%>'\"\n value='<%# DataBinder.Eval(Container.DataItem, \"SomethingToUseAsTheValue\")%>' />\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290018", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11256/" ]
290,034
<p>I've got a bunch of legacy code that I need to write unit tests for. It uses pre-compiled headers everywhere so almost all .cpp files have a dependecy on stdafx.h which is making it difficult to break dependencies in order to write tests.</p> <p>My first instinct is to remove all these stdafx.h files which, for the most part, contain #include directives and place those #includes directly in the source files as needed.</p> <p>This would make it necessary to turn off pre-compiled headers since they are dependent on having a file like stdafx.h to determine where the pre-compiled headers stop.</p> <p>Is there a way to keep pre-compiled headers without the stdafx.h dependencies? Is there a better way to approach this problem?</p>
[ { "answer_id": 35518943, "author": "riderBill", "author_id": 4079867, "author_profile": "https://Stackoverflow.com/users/4079867", "pm_score": 0, "selected": false, "text": "#include <bigHeader1.h>\n#include ...\n #include \"pch1.h\"\n #include \"pch1.h\"\n[code]\n #include <bigHeader2.h>\n#include ...\n #include \"pch2.h\"\n #include \"pch2.h\"\n[code]\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290034", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4086/" ]
290,035
<p>Does anyone know in .Net 2.0 - .Net 3.5 how to load a jpeg into a System.Windows.Forms.WebControl as a byte-array and with the right mimetypes set so it will show?</p> <p>Something like:<br></p> <pre><code>webBrowser1.DocumentStream = new MemoryStream(File.ReadAllBytes("mypic.jpg")); webBrowser1.DocumentType = "application/jpeg"; </code></pre> <p>The webBrowser1.DocumentType seems to be read only, so I do not know how to do this. In general I want to be able to load any kind of filesource with a mimetype defined into the browser to show it.</p> <p>Solutions with writing temp files are not good ones. Currently I have solved it with having a little local webserver socket listener that delivers the jpeg I ask for with the right mimetype.</p> <p>UPDATE: Since someone deleted a answer-my-own question where I had info that others could use, I will add it as an update instead. (to those who delete that way, please update the questions with the important info).</p> <p>Sample solution in C# here that works perfectly: <a href="http://www.codeproject.com/KB/aspnet/AspxProtocol.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/aspnet/AspxProtocol.aspx</a></p>
[ { "answer_id": 291839, "author": "hangy", "author_id": 11963, "author_profile": "https://Stackoverflow.com/users/11963", "pm_score": 0, "selected": false, "text": "WebBrowser Image someImage = Image.FromFile(\"mypic.jpg\");\n\n// Firstly, get the image as a base64 encoded string\nImageConverter imageConverter = new ImageConverter();\nbyte[] buffer = (byte[])imageConverter.ConvertTo(someImage, typeof(byte[]));\nstring base64 = Convert.ToBase64String(buffer, Base64FormattingOptions.InsertLineBreaks);\n\n// Then, dynamically create some XHTML for this (as this is just a sample, minimalistic XHTML :D)\nstring html = \"<img src=\\\"data:image/\" . someImage.RawFormat.ToString() . \";base64, \" . $base64 . \"\\\">\";\n\n// And put it into some stream\nusing (StreamWriter streamWriter = new StreamWriter(new MemoryStream()))\n{\n streamWriter.Write(html);\n streamWriter.Flush();\n webBrowser.DocumentStream = streamWriter.BaseStream;\n webBrowser.DocumentType = \"text/html\";\n}\n" }, { "answer_id": 15672559, "author": "Tim Ludwinski", "author_id": 1413201, "author_profile": "https://Stackoverflow.com/users/1413201", "pm_score": 0, "selected": false, "text": "res:" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290035", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37643/" ]
290,037
<p>Is there anything we can do either in code (ASP/JavaScript) or in Excel so that the comma separated values end up in separate columns in Excel?</p>
[ { "answer_id": 893506, "author": "ceetheman", "author_id": 16154, "author_profile": "https://Stackoverflow.com/users/16154", "pm_score": 0, "selected": false, "text": "private void ExportToXLSFromDataTable(DataTable dtExport, string filename)\n{\n StringBuilder dataToExport = new StringBuilder();\n\n dataToExport.Append(\"<table>\");\n dataToExport.Append(\"<tr>\");\n\n foreach (DataColumn dCol in dtExport.Columns)\n {\n dataToExport.Append(\"<td>\");\n dataToExport.Append(Server.HtmlEncode(dCol.ColumnName));\n dataToExport.Append(\"</td>\");\n }\n\n dataToExport.Append(\"</tr>\");\n\n foreach (DataRow dRow in dtExport.Rows)\n {\n dataToExport.Append(\"<tr>\");\n foreach (object obj in dRow.ItemArray)\n {\n dataToExport.Append(\"<td>\");\n dataToExport.Append(Server.HtmlEncode(obj.ToString()));\n dataToExport.Append(\"</td>\");\n }\n dataToExport.Append(\"</tr>\");\n }\n\n dataToExport.Append(\"</table>\");\n\n if (!string.IsNullOrEmpty(dataToExport.ToString()))\n {\n Response.Clear();\n\n HttpContext.Current.Response.ContentType = \"application/ms-excel\";\n HttpContext.Current.Response.AddHeader(\"Content-Disposition\", \"attachment;filename=\" + filename);\n\n HttpContext.Current.Response.Write(dataToExport.ToString());\n HttpContext.Current.Response.End();\n }\n}\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290037", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
290,038
<p>In C++, is the return type considered part of the function signature? and no overloading is allowed with just return type modified.</p>
[ { "answer_id": 290048, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 8, "selected": true, "text": "1.3.10 14.5.5.1 1.3.10 void f();\nint (*pf)() = &f; // different types!\n int f();\ndouble f(); // invalid\n template<typename T> int f();\ntemplate<typename T> double f(); // invalid?\n 13.1 7/2 7/5 14.5.5.1 1.3.11" }, { "answer_id": 292390, "author": "Nicola Bonelli", "author_id": 19630, "author_profile": "https://Stackoverflow.com/users/19630", "pm_score": 4, "selected": false, "text": "const volatile const volatile template <typename T>\nT foo(int a)\n{return T();}\n foo<int>(0);\nfoo<char>(0);\n template<class T> int foo(T)\n{}\n\ntemplate<class T> bool foo(T)\n{}\n\n// at the instantiation point it is necessary to specify the cast\n// in order not to face ambiguous overload\n\n((int(*)(char))foo<char>)('a'); \n" }, { "answer_id": 309660, "author": "Eclipse", "author_id": 8701, "author_profile": "https://Stackoverflow.com/users/8701", "pm_score": 2, "selected": false, "text": "int IntFunc() { return 0; }\nchar CharFunc() { return 0; }\n\nvoid FuncFunc(int(*func)()) { cout << \"int\\n\"; }\nvoid FuncFunc(char(*func)()) { cout << \"char\\n\"; }\n\n\nint main()\n{\n FuncFunc(&IntFunc); // calls void FuncFunc(int_func func)\n FuncFunc(&CharFunc); // calls void FuncFunc(char_func func)\n}\n" }, { "answer_id": 69332732, "author": "Yannis Kingdom", "author_id": 9813340, "author_profile": "https://Stackoverflow.com/users/9813340", "pm_score": 0, "selected": false, "text": "template <typename T>\nT f(double x, T dummy) {\n T output;\n output = x * 2;\nreturn output;\n}\n f(2, double(1))\n f(2, int(1))\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22076/" ]
290,043
<p>I’m trying to make the routing module works with default action or controller, but it doesn’t. I always face with 404 page not found. Did I forget to do something? I really like routing in ASP.NET MVC feature, but I’m not sure I could do the same in MR. I’m using IIS7 with the build from castle trunk for .NET 3.5.</p>
[ { "answer_id": 294672, "author": "Vorleak Chy", "author_id": 35719, "author_profile": "https://Stackoverflow.com/users/35719", "pm_score": 0, "selected": false, "text": "<system.web>\n<httpHandlers>\n <add verb=\"*\" path=\"*.rail\" type=\"Castle.MonoRail.Framework.MonoRailHttpHandlerFactory, Castle.MonoRail.Framework\" />\n <add verb=\"*\" path=\"*.vm\" type=\"System.Web.HttpForbiddenHandler\" />\n <add verb=\"*\" path=\"*.boo\" type=\"System.Web.HttpForbiddenHandler\" />\n <add verb=\"*\" path=\"*.st\" type=\"System.Web.HttpForbiddenHandler\" />\n</httpHandlers> \n<httpModules>\n <add name=\"routing\" type=\"Castle.MonoRail.Framework.Routing.RoutingModuleEx, Castle.MonoRail.Framework\" />\n</httpModules></system.web> \n<system.webServer>\n <handlers>\n <add name=\"MR\" path=\"*.rail\" verb=\"*\" modules=\"IsapiModule\" scriptProcessor=\"C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\aspnet_isapi.dll\" resourceType=\"Unspecified\" preCondition=\"classicMode,runtimeVersionv2.0,bitness32\" />\n </handlers>\n</system.webServer>\n" }, { "answer_id": 361138, "author": "Peter Mounce", "author_id": 20971, "author_profile": "https://Stackoverflow.com/users/20971", "pm_score": 3, "selected": false, "text": " <system.web>\n <authentication mode=\"None\" />\n\n <compilation debug=\"true\" />\n\n <!-- IIS6 / integrated dev server handler/module config -->\n <httpHandlers>\n <clear />\n <add path=\"favicon.ico\" verb=\"*\" type=\"System.Web.StaticFileHandler\"/>\n <add path=\"Trace.axd\" verb=\"*\" type=\"System.Web.Handlers.TraceHandler\"/>\n <add path=\"*.config\" verb=\"*\" type=\"System.Web.HttpForbiddenHandler\" />\n <add path=\"*.spark\" verb=\"*\" type=\"System.Web.HttpForbiddenHandler\" />\n <add path=\"*.sparkjs\" verb=\"*\" type=\"System.Web.HttpForbiddenHandler\" />\n <add path=\"/content/**/*.*\" verb=\"*\" type=\"System.Web.StaticFileHandler\" />\n <add path=\"/content/**/**/*.*\" verb=\"*\" type=\"System.Web.StaticFileHandler\" />\n <add path=\"/content/**/**/**/*.*\" verb=\"*\" type=\"System.Web.StaticFileHandler\" />\n <add path=\"/content/**/**/**/**/*.*\" verb=\"*\" type=\"System.Web.StaticFileHandler\" />\n <add path=\"*\" verb=\"*\" type=\"Castle.MonoRail.Framework.MonoRailHttpHandlerFactory, Castle.MonoRail.Framework\" />\n <add verb=\"*\" path=\"*.castle\" type=\"Castle.MonoRail.Framework.MonoRailHttpHandlerFactory, Castle.MonoRail.Framework\"/>\n </httpHandlers>\n\n <httpModules>\n <add name=\"routing\" type=\"Castle.MonoRail.Framework.Routing.RoutingModuleEx, Castle.MonoRail.Framework\" />\n <add name=\"PerRequestLifestyle\" type=\"Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel\" />\n </httpModules>\n\n <trace enabled=\"true\"/>\n\n</system.web>\n\n<!-- IIS 7 handler/module config -->\n<system.webServer>\n <handlers>\n <clear />\n <add name=\"FavIcon\" path=\"favicon.ico\" verb=\"*\" type=\"System.Web.StaticFileHandler\"/>\n <add name=\"Trace\" path=\"Trace.axd\" verb=\"*\" preCondition=\"integratedMode\" type=\"System.Web.Handlers.TraceHandler\"/>\n <add name=\"BlockConfig\" path=\"*.config\" verb=\"*\" preCondition=\"integratedMode\" type=\"System.Web.HttpForbiddenHandler\" />\n <add name=\"BlockSpark\" path=\"*.spark\" verb=\"*\" preCondition=\"integratedMode\" type=\"System.Web.HttpForbiddenHandler\" />\n <add name=\"BlockSparkJs\" path=\"*.sparkjs\" verb=\"*\" preCondition=\"integratedMode\" type=\"System.Web.HttpForbiddenHandler\" />\n <add name=\"content\" path=\"/content/**/*.*\" verb=\"*\" preCondition=\"integratedMode\" type=\"System.Web.StaticFileHandler\" />\n <add name=\"content2\" path=\"/content/**/**/*.*\" verb=\"*\" preCondition=\"integratedMode\" type=\"System.Web.StaticFileHandler\" />\n <add name=\"content3\" path=\"/content/**/**/**/*.*\" verb=\"*\" preCondition=\"integratedMode\" type=\"System.Web.StaticFileHandler\" />\n <add name=\"content4\" path=\"/content/**/**/**/**/*.*\" verb=\"*\" preCondition=\"integratedMode\" type=\"System.Web.StaticFileHandler\" />\n <add name=\"castle\" path=\"*\" verb=\"*\" type=\"Castle.MonoRail.Framework.MonoRailHttpHandlerFactory, Castle.MonoRail.Framework\" modules=\"ManagedPipelineHandler\" scriptProcessor=\"\" resourceType=\"Unspecified\" requireAccess=\"Script\" preCondition=\"integratedMode,runtimeVersionv2.0\" />\n </handlers>\n\n <modules>\n <add name=\"routing\" type=\"Castle.MonoRail.Framework.Routing.RoutingModuleEx, Castle.MonoRail.Framework\" />\n <add name=\"PerRequestLifestyle\" type=\"Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel\" />\n </modules>\n\n <validation validateIntegratedModeConfiguration=\"false\" />\n\n</system.webServer>\n protected virtual void RegisterRoutes(IRoutingRuleContainer engine)\n {\n engine.Add\n (\n new PatternRoute(ThorController.CtlrHome, \"/[controller]\")\n .DefaultForController().Is(ThorController.CtlrHome)\n .DefaultForArea().Is(ThorController.AreaPublic)\n .DefaultForAction().Is(ThorController.ActionIndex)\n );\n\n engine.Add\n (\n new PatternRoute(ThorController.KeyDefault, \"/<area>/<controller>/[action]/[id]\")\n .DefaultForArea().Is(ThorController.AreaPublic)\n .DefaultForAction().Is(ThorController.ActionIndex)\n .DefaultFor(ThorController.KeyId).IsEmpty\n );\n }\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290043", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35719/" ]
290,055
<p>I have an have an ASP.Net page which contains a button. This Page contains a ServerSide Paypal button.</p> <p>When pushed my server does various clever things on the back end and then rewrites the response as a form and some javascript which posts this form to paypal..</p> <p>This all works great.</p> <p>However, if the user then elects to click back, they will arrive at my generated self-posting form and that will forward them again to Paypal. </p> <p>I thought if I could find a way to have my generated form page not exist in the history, then this will solve my problem. but I have no idea how to correct this.</p> <p><strong>How can I remove my page from the history or just have it never appear?</strong></p> <p>Update: Thanks to all... Those are some great answers. Upvoted all good ones but went with splattne on account of clever use of hidden field rather than cookies for basis of decision.</p>
[ { "answer_id": 290107, "author": "Patrick McElhaney", "author_id": 437, "author_profile": "https://Stackoverflow.com/users/437", "pm_score": 2, "selected": false, "text": "window.history.back()" }, { "answer_id": 290114, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 4, "selected": false, "text": "window.location.replace(URL);\n" }, { "answer_id": 15700942, "author": "MistereeDevlord", "author_id": 1510837, "author_profile": "https://Stackoverflow.com/users/1510837", "pm_score": 1, "selected": false, "text": "window.history.go(-2);\n" }, { "answer_id": 61529384, "author": "elle0087", "author_id": 3061212, "author_profile": "https://Stackoverflow.com/users/3061212", "pm_score": 0, "selected": false, "text": "protected void Page_Load(object sender, EventArgs e)\n\n {\n\n Page.RegisterClientScriptBlock(\"\", \"<script>if(history.length>0)history.go(+1);</script>\");\n\n }\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290055", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11356/" ]
290,061
<p>I just came over this syntax in some of the questions in this forum, but Google and any other searchengine tends to block out anything but letters and number in the search so it is impossible to search out "=>".</p> <p>So can anyone tell me what it is and how it is used? </p>
[ { "answer_id": 290063, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 8, "selected": true, "text": "Func<Person, string> nameProjection = p => p.Name;\n Func<Person, string> nameProjection = delegate (Person p) { return p.Name; };\n Person // Expression-bodied property\npublic int IsValid => name != null && id != -1;\n\n// Expression-bodied method\npublic int GetHashCode() => id.GetHashCode();\n" }, { "answer_id": 290070, "author": "milot", "author_id": 22637, "author_profile": "https://Stackoverflow.com/users/22637", "pm_score": 3, "selected": false, "text": "somevar.Find(delegate(int n)\n{\n if(n < 10)\n return n;\n});\n somevar.Find(n => n < 10);\n" }, { "answer_id": 290072, "author": "Chris James", "author_id": 3193, "author_profile": "https://Stackoverflow.com/users/3193", "pm_score": 1, "selected": false, "text": "MyObjectReference => MyObjectReference.DoSomething()\n MyCollection.Where(myobj => myobj.Age>10)\n" }, { "answer_id": 290074, "author": "Serhat Ozgel", "author_id": 31505, "author_profile": "https://Stackoverflow.com/users/31505", "pm_score": 4, "selected": false, "text": "x => x + 1\n button.Click += new EventHandler((sender, e) => methodInfo.Invoke(null, new object[] { sender, e }));\n" }, { "answer_id": 290078, "author": "Steve", "author_id": 22712, "author_profile": "https://Stackoverflow.com/users/22712", "pm_score": 4, "selected": false, "text": "delegate int del(int i);\ndel myDelegate = x => x * x;\nint j = myDelegate(5); //j = 25\n" }, { "answer_id": 11404239, "author": "Dave Cousineau", "author_id": 621316, "author_profile": "https://Stackoverflow.com/users/621316", "pm_score": 5, "selected": false, "text": "// explicit method\nint MyFunc(int x) {\n return x;\n}\n\n// anonymous (name-less) method\n// note that the method is \"wrapped\" up in a hidden object (Delegate) this way\n// so there is a very tiny bit of overhead compared to an explicit method\n// (though it's really the assignment that causes that and would also happen\n// if you assigned an explicit method to a reference)\nFunc<int, int> MyFunc = \n delegate (int x) { return x; };\n\n// lambda expression (also anonymous)\n// basically identical to anonymous method,\n// except with everything inferred as much as possible, intended to be minimally verbose\nFunc<int, int> MyFunc =\n x => x;\n\n// and => is now also used for \"expression-bodied\" methods\n// which let you omit the return keyword and braces if you can evaluate\n// to something in one line\nint MyFunc(int x) =>\n x;\n x => x delegate Func<int, int> = delegate (int x) { return x; };\n Delegate delegate public delegate int TestFunc(int x, int y);\n\nTestFunc myFunc = delegate (int x, int y) { return x + y; };\n TestFunc int int" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290061", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37643/" ]
290,087
<p>I'm trying to build a method that will receive a Linq table, and should return a List&lt;> of values that will be a DropDownList Datasource.</p> <p>This is what I've got till now:</p> <pre><code>public static List&lt;Structs.NameValuePair&gt; GenDropDownItens&lt;T&gt;(string ValueField , string TextField ) where T: class </code></pre> <p>What i don't know how to do is, query the table getting only the fields that are passed ( ValueField, TextField)...</p> <p>Tks!</p>
[ { "answer_id": 290152, "author": "Nick Berardi", "author_id": 17, "author_profile": "https://Stackoverflow.com/users/17", "pm_score": 1, "selected": false, "text": "var dropDownValues = dataContext.SomeTable.ToDictionary(\n s => s.Name,\n s => s.Value\n);\n\nforeach(var item in dropDownValues) {\n var OptionName = item.Key;\n var OptionValue = item.Value\n};\n" }, { "answer_id": 290190, "author": "CodeChef", "author_id": 21786, "author_profile": "https://Stackoverflow.com/users/21786", "pm_score": 2, "selected": false, "text": "\nddl.DataSource = DataContext.Table.Select(o => new KeyValuePair<string, string>(o.ID, o.DisplayField));\nddl.DataBind();\n" }, { "answer_id": 290207, "author": "Timothy Khouri", "author_id": 11917, "author_profile": "https://Stackoverflow.com/users/11917", "pm_score": 0, "selected": false, "text": "private static Func<T, DictionaryEntry> GetNameValuePairFunc<T>(string valueField, string textField)\n{\n Func<T, DictionaryEntry> result = (item) =>\n {\n object key = typeof(T).GetProperty(valueField).GetValue(item, null);\n\n object text = typeof(T).GetProperty(textField).GetValue(item, null);\n\n return new DictionaryEntry(key, text);\n };\n\n return result;\n}\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290087", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32415/" ]
290,090
<p>I'm a bit new to jQuery and hope somebody can help me out.</p> <p>I'm trying to change an element (li) to another element (div) after the (li) has been dropped.</p> <p>Sample code:</p> <pre><code>$("#inputEl&gt;li").draggable({ revert: true, opacity: 0.4, helper: "clone" }); $("#dropEl") .droppable({ accept: ".drag", hoverClass: "dropElhover", drop: function(ev, ui) { // change the li element to div here } }); </code></pre> <p>The problem is, when i use</p> <pre><code>drop: function(ev, ui) { $(ui.draggable).replaceWith("&lt;div&gt;Some content&lt;/div&gt;"); } </code></pre> <p>the original draggable elements will be disabled when the function above is triggered.</p> <p>I'm using the latest jQuery and jQuery UI stable versions.</p>
[ { "answer_id": 290555, "author": "Ben Koehler", "author_id": 11996, "author_profile": "https://Stackoverflow.com/users/11996", "pm_score": 2, "selected": false, "text": "drop: function(ev,ui) {\n $(this).append(\"<div>Some content</div>\");\n}\n drop: function(ev, ui) {\n $(ui.draggable).replaceWith(\"<div>Some content</div>\");\n $(\"#inputEl>div\").draggable({ \n revert: true, \n opacity: 0.4,\n helper: \"clone\"\n });\n }\n" }, { "answer_id": 292053, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": " drop: function(ev, ui) {\n $(this).append(\"<div>Some content</div>\");\n $(\"#dropEl\").sortable();\n}\n drop: function(ev, ui) {\n revert: true;\n var this_id = $(ui.draggable).attr(\"id\");\n $(this).append('<div id=\"'+this_id+'\">Some content</div>');\n $(\"#dropEl\").sortable();\n }\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290090", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37667/" ]
290,099
<p>My organization is using CppUnit and I am trying to run the same test using different parameters. Running a loop inside the test is not a good option as any failure will abort the test. I have looked at <code>TestDecorator</code> and <code>TestCaller</code> but neither seems to really fit. Code samples would be helpful.</p>
[ { "answer_id": 290289, "author": "Rômulo Ceccon", "author_id": 23193, "author_profile": "https://Stackoverflow.com/users/23193", "pm_score": 0, "selected": false, "text": "class MyTestCase\n\n # this is your fixture\n def check_special_condition(param)\n some\n complex\n tests\n end\n\n # these are your test-cases\n def test_1\n check_special_condition(\"value_1\")\n end\n\n def test_2\n check_special_condition(\"value_2\")\n end\n\nend\n" }, { "answer_id": 291453, "author": "Matt Dillard", "author_id": 863, "author_profile": "https://Stackoverflow.com/users/863", "pm_score": 3, "selected": false, "text": "RepeatedTest RepeatedTest RepeatedTest TestCase TestCase RepeatedTest" }, { "answer_id": 2853411, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "class members : public CppUnit::TestFixture\n{\n int i;\n float f;\n};\n\nclass some_values : public members\n{\n void setUp()\n {\n // initialization here\n }\n};\n\nclass different_values : public members\n{\n void setUp()\n {\n // different initialization here\n }\n};\n\ntempalte<class F>\nclass my_test : public F\n{\n CPPUNIT_TEST_SUITE(my_test<F>);\n CPPUNIT_TEST(foo);\n CPPUNIT_TEST_SUITE_END();\n\n foo() {}\n};\n\nCPPUNIT_TEST_SUITE_REGISTRATION(my_test<some_values>);\nCPPUNIT_TEST_SUITE_REGISTRATION(my_test<different_values>);\n" }, { "answer_id": 16072289, "author": "Marcin Zukowski", "author_id": 1457258, "author_profile": "https://Stackoverflow.com/users/1457258", "pm_score": 0, "selected": false, "text": "std::vector<std::string> testParameters = { \"string1\", \"string2\" };\nsize_t testCounter = 0;\n void Test::genericTester()\n{\n const std::string &param = testParameters[testCounter++];\n\n // do something with param\n} \n CPPUNIT_TEST_SUITE(StatementTest);\n\ntestCounter = 0;\nfor (size_t i = 0; i < testParameters.size(); i++) {\n CPPUNIT_TEST_SUITE_ADD_TEST(\n ( new CPPUNIT_NS::TestCaller<TestFixtureType>(\n // Here we use the parameter name as the unit test name.\n // Of course, you can make test parameters more complex, \n // with test names as explicit fields for example.\n context.getTestNameFor( testParamaters[i] ),\n // Here we point to the generic tester function.\n &TestFixtureType::genericTester,\n context.makeFixture() ) ) );\n}\n\nCPPUNIT_TEST_SUITE_END();\n" }, { "answer_id": 22034707, "author": "user3354701", "author_id": 3354701, "author_profile": "https://Stackoverflow.com/users/3354701", "pm_score": 1, "selected": false, "text": "CPPUNIT_PARAMETERIZED_TEST_SUITE(<TestSuiteClass>, <ParameterType>);\n\n/*\n * put plain old tests here.\n */\n\nCPPUNIT_PARAMETERIZED_TEST_SUITE_END();\n CPPUNIT_PARAMETERIZED_TEST_SUITE_REGISTRATION ( <TestSuiteClass>, <ParameterType> )\n static std::vector parameters();\nvoid testWithParameter(ParameterType& parameter);\n" }, { "answer_id": 34672805, "author": "jpo38", "author_id": 3336423, "author_profile": "https://Stackoverflow.com/users/3336423", "pm_score": 0, "selected": false, "text": "class Param\n{\npublic:\n Param( int param1, std::string param2 ) :\n m_param1( param1 ),\n m_param2( param2 )\n {\n }\n\n int m_param1;\n std::string m_param2;\n};\n template <Param& T>\nclass my_test : public CPPUNIT_NS::TestFixture\n{\n CPPUNIT_TEST_SUITE(my_test<T>);\n CPPUNIT_TEST( doProcessingTest );\n CPPUNIT_TEST_SUITE_END();\n\n void doProcessingTest()\n {\n std::cout << \"Testing with \" << T.m_param1 << \" and \" << T.m_param2 << std::endl;\n };\n};\n #define REGISTER_TEST_WITH_PARAMS( name, param1, param2 ) \\\n Param name( param1, param2 ); \\\n CPPUNIT_TEST_SUITE_REGISTRATION(my_test<name>);\n REGISTER_TEST_WITH_PARAMS( test1, 1, \"foo\" );\nREGISTER_TEST_WITH_PARAMS( test2, 3, \"bar\" );\n my_test<class Param test1>::doProcessingTestTesting with 1 and foo : OK\nmy_test<class Param test2>::doProcessingTestTesting with 3 and bar : OK\nOK (2)\nTest completed, after 0 second(s). Press enter to exit\n" }, { "answer_id": 37814291, "author": "Rupert Nash", "author_id": 193291, "author_profile": "https://Stackoverflow.com/users/193291", "pm_score": 0, "selected": false, "text": "TestFixture PARAMETERISED_TEST(method_name, argument_type, argument_value) #include <cppunit/extensions/HelperMacros.h>\n#include <cppunit/ui/text/TestRunner.h>\n\ntemplate <class FixtureT, class ArgT>\nclass ParameterisedTest : public CppUnit::TestCase {\npublic:\n typedef void (FixtureT::*TestMethod)(ArgT);\n ParameterisedTest(std::string name, FixtureT* fix, TestMethod f, ArgT a) :\n CppUnit::TestCase(name), fixture(fix), func(f), arg(a) {\n }\n ParameterisedTest(const ParameterisedTest* other) = delete;\n ParameterisedTest& operator=(const ParameterisedTest& other) = delete;\n\n void runTest() {\n (fixture->*func)(arg);\n }\n void setUp() { \n fixture->setUp(); \n }\n void tearDown() { \n fixture->tearDown(); \n }\nprivate:\n FixtureT* fixture;\n TestMethod func;\n ArgT arg;\n};\n\n#define PARAMETERISED_TEST(Method, ParamT, Param) \\\n CPPUNIT_TEST_SUITE_ADD_TEST((new ParameterisedTest<TestFixtureType, ParamT>(context.getTestNameFor(#Method #Param), \\\n context.makeFixture(), \\\n &TestFixtureType::Method, \\\n Param)))\n\nclass FooTests : public CppUnit::TestFixture {\n CPPUNIT_TEST_SUITE(FooTests);\n PARAMETERISED_TEST(ParamTest, int, 0);\n PARAMETERISED_TEST(ParamTest, int, 1);\n PARAMETERISED_TEST(ParamTest, int, 2);\n CPPUNIT_TEST_SUITE_END();\npublic:\n void ParamTest(int i) {\n CPPUNIT_ASSERT(i > 0);\n }\n};\nCPPUNIT_TEST_SUITE_REGISTRATION(FooTests);\n\nint main( int argc, char **argv)\n{\n CppUnit::TextUi::TestRunner runner;\n CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();\n runner.addTest( registry.makeTest() );\n bool wasSuccessful = runner.run( \"\", false );\n return wasSuccessful;\n}\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290099", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22080/" ]
290,112
<p>I have a Panel and I am adding controls inside this panel. But there is a specific control that I would like to float. How would I go about doing that?</p> <p>pnlOverheadDetails is the panel name</p> <pre><code>pnlOverheadDetails.Controls.Add(lnkCalcOverhead); </code></pre> <p>The control named lnkCalcOverhead is the control I'd like to float.</p> <p>Thanks in advance</p> <p>EDIT: By float I meant the css style not anything fancy :)</p>
[ { "answer_id": 290131, "author": "Jeromy Irvine", "author_id": 8223, "author_profile": "https://Stackoverflow.com/users/8223", "pm_score": 6, "selected": true, "text": "Controls.Add lnkCalcOverhead.CssClass = \"MyClass\";\n lnkCalcOverhead.Style.Add(\"float\", \"left\");\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290112", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4144/" ]
290,116
<p>I'm trying to create number of Evenement instances and set the date for them:</p> <pre><code> for (int i=2004; i&lt;2009; i++){ evenementen.add(new Evenement("Rock Werchter", "Rock", "Werchter", 200000, (Date)formatter.parse(i+"/07/03"))); </code></pre> <p>But I can't seem to get it to work,</p> <p>Any ideas?</p>
[ { "answer_id": 290143, "author": "Powerlord", "author_id": 15880, "author_profile": "https://Stackoverflow.com/users/15880", "pm_score": 2, "selected": false, "text": "for (int i=2004; i<2009; i++) {\n Calendar cal = Calendar.getInstance();\n cal.clear();\n // Calendar.JULY may be different depending on the JDK language\n cal.set(i, Calendar.JULY, 3); // Alternatively, cal.set(i, 6, 3); \n evenementen.add(new Evenement(\"Rock Werchter\", \"Rock\", \"Werchter\", 200000,\n cal.getTime()));\n}\n" }, { "answer_id": 290155, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 2, "selected": false, "text": "Locale.ENGLISH formatter = new SimpleDateFormat(\"yyyy/MM/DD\");\n" }, { "answer_id": 67759786, "author": "Arvind Kumar Avinash", "author_id": 10819573, "author_profile": "https://Stackoverflow.com/users/10819573", "pm_score": 2, "selected": false, "text": "java.util SimpleDateFormat java.time import java.time.LocalDate;\nimport java.time.Month;\n\npublic class Main {\n public static void main(String[] args) {\n for (int i = 2004; i < 2009; i++) {\n System.out.println(LocalDate.of(i, Month.JULY, 3));\n }\n }\n}\n DateTimeFormatter import java.time.LocalDate;\nimport java.time.format.DateTimeFormatter;\nimport java.util.Locale;\n\npublic class Main {\n public static void main(String[] args) {\n DateTimeFormatter dtf = DateTimeFormatter.ofPattern(\"u/M/d\", Locale.ENGLISH);\n for (int i = 2004; i < 2009; i++) {\n LocalDate date = LocalDate.parse(i + \"/07/03\", dtf);\n System.out.println(date);\n }\n }\n}\n 2004-07-03\n2005-07-03\n2006-07-03\n2007-07-03\n2008-07-03\n java.time" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290116", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
290,121
<p>My website has been giving me intermittent errors when trying to perform <em>any</em> Ajax activities. The message I get is</p> <pre><code>Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near ' &lt;!DOCTYPE html P'. </code></pre> <p>So its obviously some sort of server timeout or the server's just returning back mangled garbage. This generally, unfortunately not always, happe</p>
[ { "answer_id": 2231865, "author": "brunosp86", "author_id": 100431, "author_profile": "https://Stackoverflow.com/users/100431", "pm_score": 1, "selected": false, "text": "Content-Type: Custom HTTP Headers HTTP Headers IIS Content-Type IIS ISO-8859-1" }, { "answer_id": 2884114, "author": "rahkim", "author_id": 77254, "author_profile": "https://Stackoverflow.com/users/77254", "pm_score": 1, "selected": false, "text": "if (Session.SessionID == \"\")\n{\n Page.Session.Add(\"SessionID\", Session.SessionID);\n}\n" }, { "answer_id": 3403942, "author": "Mathew M Mathew-Nest", "author_id": 402291, "author_profile": "https://Stackoverflow.com/users/402291", "pm_score": 1, "selected": false, "text": "Session[\"UseridJustregistered\"]=Id Respose.Redirect(\"regSucces.aspx?urlid='\" + Session[\"UseridJustregistered\"] + \"'\"); Session[\"UseridJustregistered\"]" }, { "answer_id": 6747745, "author": "CSharper", "author_id": 70799, "author_profile": "https://Stackoverflow.com/users/70799", "pm_score": 3, "selected": false, "text": " <asp:updatepanel ID=\"updatepanel1\" runat=\"server\">\n <Triggers>\n <asp:PostBackTrigger ControlID=\"button1\" /> \n </Triggers>\n <ContentTemplate>\n\n </ContentTemplate>\n </asp:updatepanel>\n" }, { "answer_id": 29629072, "author": "AFract", "author_id": 461444, "author_profile": "https://Stackoverflow.com/users/461444", "pm_score": 0, "selected": false, "text": "<add name=\"ScriptModule\" type=\"System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35\"/>\n" }, { "answer_id": 30514890, "author": "mivra", "author_id": 761883, "author_profile": "https://Stackoverflow.com/users/761883", "pm_score": 1, "selected": false, "text": "1|#||4|30502|updatePanel|pnlUpdate| ...\n 30502" }, { "answer_id": 62892954, "author": "Leo", "author_id": 7731479, "author_profile": "https://Stackoverflow.com/users/7731479", "pm_score": 0, "selected": false, "text": "<asp:ScriptManager ID=\"ScriptManager\" runat=\"server\" ScriptMode=\"Release\"></asp:ScriptManager>\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290121", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2995/" ]
290,128
<p>We've all read the benchmarks and know the facts - event-based asynchronous network servers are faster than their threaded counterparts. Think lighttpd or Zeus vs. Apache or IIS. Why is that?</p>
[ { "answer_id": 11267570, "author": "Left For Archive", "author_id": 195298, "author_profile": "https://Stackoverflow.com/users/195298", "pm_score": 2, "selected": false, "text": "We examine the claimed strengths of events over threads and show that the\nweaknesses of threads are artifacts of specific threading implementations\nand not inherent to the threading paradigm. As evidence, we present a\nuser-level thread package that scales to 100,000 threads and achieves\nexcellent performance in a web server.\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21712/" ]
290,133
<p>Our website uses Perl to provide a simple mechanism for our HR people to post vacancies to our website. It was developed by a third party, but they have been long since kicked into touch, and sadly we do not have any Perl skills in-house. This is what happens when Marketing people circumvent their in-house IT team!</p> <p>I need to make a simple change to this application. Currently, the vacancies page says 'We currently have the following vacancies:', regardless of whether there are any vacancies! So we want to change it so that this line is only displayed at the appropriate times.</p> <p>I could, obviously, start to learn a bit of Perl, but we are already planning a replacement site, and it certainly won't be using Perl. So since the solution will be trivial for those with these skills, I thought I'd ask for some focused help.</p> <p>Below is the start of the procedure that lists the vacancies. </p> <pre><code>sub list { require HTTP::Date; import HTTP::Date; my $date = [split /\s+/, HTTP::Date::time2iso(time())]-&gt;[0]; my $dbh = DBI-&gt;connect($dsn, $user, $password) || die "cannot connect to $database: $!\n"; my $sql = &lt;&lt;EOSQL; SELECT * FROM $table where expiry &gt;= '$date' order by expiry EOSQL my $sth = $dbh-&gt;prepare($sql); $sth-&gt;execute(); while (my $ref = $sth-&gt;fetchrow_hashref()) { my $temp = $template; $temp =~ s#__TITLE__#$ref-&gt;{'title'}#; my $job_spec = $ref-&gt;{'job_spec'}; ...etc... </code></pre> <p>The key line is <code>while (my $ref = $sth-&gt;fetchrow_hashref()) {</code>. I'm figuring that this is saying 'while I can pull off another vacancy from the returned recordset...'. If I place my print statement before this line, it will always be shown; after this line and it was be repeated for every vacancy.</p> <p>How do I determine that there are some vacancies to be displayed, without prematurely moving through the returned recordset?</p> <p>I could always copy the code within the while loop, and place it within an if() statement (preceding the while loop) which will also include my print statement. But I'd prefer to just have the simpler approach of <code>If any records then print "We currently have.." line</code>. Unfortunately, I haven't a clue to code even this simple line.</p> <p>See, I told you it was a trivial problem, even considering my fumbled explanation!</p> <p>TIA</p> <p>Chris</p>
[ { "answer_id": 290145, "author": "Paul Tomblin", "author_id": 3333, "author_profile": "https://Stackoverflow.com/users/3333", "pm_score": 2, "selected": false, "text": "my @results = ();\nwhile (my $ref = $sth->fetchrow_hashref()) {\n push @results, $ref;\n}\n\nif ($#results == 0) {\n ... no results\n} else {\n foreach $ref (@results) {\n my $temp = $template;\n ....\n }\n" }, { "answer_id": 290147, "author": "Graeme Perrow", "author_id": 1821, "author_profile": "https://Stackoverflow.com/users/1821", "pm_score": 5, "selected": true, "text": "$sth->execute();\n\nmy $first = 1;\nwhile (my $ref = $sth->fetchrow_hashref()) {\n if( $first ) {\n print \"We currently have the following vacancies:\\n\";\n $first = 0;\n }\n my $temp = $template;\n ...\n}\nif( $first ) {\n print \"No vacancies found\\n\";\n}\n" }, { "answer_id": 290162, "author": "Kev", "author_id": 16777, "author_profile": "https://Stackoverflow.com/users/16777", "pm_score": 1, "selected": false, "text": "my $output = '';\n $output .= \"whatever we would have printed\";\n if ($output eq '')\n{\n print 'We have no vacancies.';\n}\nelse\n{\n print \"We currently have the following vacancies:\\n\" . $output;\n}\n" }, { "answer_id": 290168, "author": "Dave Vogt", "author_id": 35189, "author_profile": "https://Stackoverflow.com/users/35189", "pm_score": 1, "selected": false, "text": "# count the vacancies \n$numinfo = $dbh->prepare(\"SELECT COUNT(*) FROM $table WHERE EXPIRY >= ?\");\n$numinfo->execute($date);\n$count = $numinfo->fetchrow_arrayref()->[0];\n\n# print a message\nmy $msg = '';\nif ($count == 0) $msg = 'We do not have any vacancies right now';\nelse $msg = 'We have the following vacancies';\nprint($msg);\n" }, { "answer_id": 290716, "author": "Michael Cramer", "author_id": 1496728, "author_profile": "https://Stackoverflow.com/users/1496728", "pm_score": 2, "selected": false, "text": "$sth->execute();\n\nif($sth->rows) {\n print \"We have data!\\n\";\n}\n\nwhile(my $ref = $sth->fetchrow_hashref()) {\n...\n}\n" }, { "answer_id": 290903, "author": "ysth", "author_id": 17389, "author_profile": "https://Stackoverflow.com/users/17389", "pm_score": 1, "selected": false, "text": "use Lingua::EN::Inflect 'PL';\n\n$sth->execute();\nmy $results = $sth->fetchall_arrayref( {}, $max_rows );\n\nif (@$results) {\n print \"We currently have the following \", PL(\"vacancy\",scalar @$results), \":\\n\";\n\n for my $ref (@$results) {\n ...\n }\n}\n" }, { "answer_id": 291071, "author": "Dave Sherohman", "author_id": 18914, "author_profile": "https://Stackoverflow.com/users/18914", "pm_score": 2, "selected": false, "text": "$sth->execute();\n\nmy $ref = $sth->fetchrow_hashref();\nif ($ref) {\n print \"We currently have the following vacancies:\\n\";\n while ($ref) {\n my $temp = $template;\n ...\n $ref = $sth->fetchrow_hashref();\n }\n} else {\n print \"No vacancies found\\n\";\n}\n" }, { "answer_id": 292155, "author": "Sam Kington", "author_id": 6832, "author_profile": "https://Stackoverflow.com/users/6832", "pm_score": -1, "selected": false, "text": " For a non-\"SELECT\" statement, \"execute\" returns the number of rows\n affected, if known. If no rows were affected, then \"execute\"\n returns \"0E0\", which Perl will treat as 0 but will regard as true.\n my $returnval = $sth->execute;\n if (defined $returnval && $returnval == 0) {\n carp \"Query executed successfully but returned nothing\";\n return;\n }\n" }, { "answer_id": 26407609, "author": "Paolo Rovelli", "author_id": 2128591, "author_profile": "https://Stackoverflow.com/users/2128591", "pm_score": 2, "selected": false, "text": "# Retrieve how many vacancies are currently offered:\nmy $query = \"SELECT COUNT(*) AS rows FROM $table WHERE expiry >= ?\";\n$sth = $dbh->prepare($query);\n$sth->execute($date);\n$numVacancies = $numinfo->fetchrow_arrayref()->[0];\n\n# Debug:\nprint \"Number of vacancies: \" . $numVacancies . \"\\n\";\n\nif ( $numVacancies == 0 ) { # no vacancy found...\n print \"No vacancies found!\\n\";\n}\nelse { # at least a vacancy has been found...\n print \"We currently have the following vacancies:\\n\";\n\n # Retrieve the vacancies:\n my $sql = \"SELECT * FROM $table where expiry >= '$date' ORDER BY expiry\";\n my $sth = $dbh->prepare($sql);\n $sth->execute();\n\n ...\n}\n # Retrieve how many vacancies are currently offered:\nmy $query = \"SELECT COUNT(*) AS rows FROM $table WHERE expiry >= ?\"; \nmy $numVacancies = $dbh->selectrow_array($query, undef, $date);\n\n# Debug:\nprint \"Number of vacancies: \" . $numVacancies . \"\\n\";\n # Retrieve how many vacancies are currently offered:\nmy $query = \"SELECT COUNT(*) AS rows FROM $table WHERE expiry >= ?\";\nmy $numVacancies = $dbh->selectall_arrayref($query, {Slice => {}}, $date);\n\n# Debug:\nprint \"Number of vacancies: \" . @$numVacancies[0]->{rows} . \"\\n\";\n # Retrieve the vacancies:\nmy $sql = \"SELECT * FROM $table where expiry >= ? ORDER BY expiry\";\nmy $vacancies = $dbh->selectall_arrayref($sql, {Slice => {}}, $date);\n\n# Debug:\nprint \"Number of vacancies: \" . scalar @{$vacancies} . \"\\n\";\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290133", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6898/" ]
290,187
<p>I have a script that takes a command and executes it on a remote host. It works fine, for example:</p> <pre><code>$ rexec "ant build_all" </code></pre> <p>will execute the "ant build_all" command on the remote system (passing it through SSH, etc).</p> <p>Because I'm lazy, I want to set up an alias for this command (and ultimately, several others), such that, for example, I can just invoke</p> <pre><code>$ rant build_all </code></pre> <p>and bash will it will automatically invoke </p> <pre><code>$ rexec "ant build_all" </code></pre> <p>I tried doing this with alias, but if I define</p> <pre><code>alias rant=rexec ant </code></pre> <p>then any arguments passed to "rant" will just be appended to the end, like so:</p> <pre><code>$ rant build_all -Dtarget=Win32 (interpreted as:) $ rexec "ant" build_all -Dtarget=Win32 </code></pre> <p>This fails, because rexec really takes just one argument, and ignores the others.</p> <p>I could probably do this with a bash wrapper script, but I was wondering if bash had any built-ins for doing this for me, perhaps a named-argument version of alias, or a perl-like quote string command (e.g. qw/ / ), or some such.</p>
[ { "answer_id": 290203, "author": "J.D. Fitz.Gerald", "author_id": 11542, "author_profile": "https://Stackoverflow.com/users/11542", "pm_score": 0, "selected": false, "text": "function rant { rexec \"ant $1\"; }\n" }, { "answer_id": 290204, "author": "Ken Gentle", "author_id": 8709, "author_profile": "https://Stackoverflow.com/users/8709", "pm_score": 3, "selected": true, "text": "function rant () {\n rexec \"ant $*\"\n}\n" }, { "answer_id": 290233, "author": "glamdringlfo", "author_id": 16226, "author_profile": "https://Stackoverflow.com/users/16226", "pm_score": 2, "selected": false, "text": "function rex {\n run_remote.sh -c \"$*\"\n}\n alias rant=\"rex ant\"\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290187", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16226/" ]
290,189
<p>What are the things to consider when choosing between ByRef and ByVal.</p> <p>I understand the difference between the two but I don't fully understand if ByRef saves resources or if we even need to worry about that in the .Net environment.</p> <p>How do you decide between the two if the functionality doesn't matter in a situation?</p>
[ { "answer_id": 290267, "author": "Charles Bretana", "author_id": 32632, "author_profile": "https://Stackoverflow.com/users/32632", "pm_score": 4, "selected": false, "text": " myVar = new object();\n" }, { "answer_id": 32906004, "author": "Ashwith Ullal", "author_id": 1534035, "author_profile": "https://Stackoverflow.com/users/1534035", "pm_score": 0, "selected": false, "text": "Sub last_column_process()\nDim last_column As Integer\n\nlast_column = 234\nMsgBox last_column\n\ntrying_byref x:=last_column\nMsgBox last_column\n\ntrying_byval v:=last_column\nMsgBox last_column\n\nEnd Sub\n\nSub trying_byref(ByRef x)\nx = 345\nEnd Sub\n\nSub trying_byval(ByRef v)\nv = 555\nEnd Sub\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290189", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6161/" ]
290,213
<p>When I serialize;</p> <pre><code>public class SpeedDial { public string Value { get; set; } public string TextTR { get; set; } public string TextEN { get; set; } public string IconId { get; set; } } </code></pre> <p>It results:</p> <pre><code>&lt;SpeedDial&gt; &lt;Value&gt;110&lt;/Value&gt; &lt;TextTR&gt;Yangın&lt;/TextTR&gt; &lt;TextEN&gt;Fire&lt;/TextEN&gt; &lt;IconId&gt;39&lt;/IconId&gt; &lt;/SpeedDial&gt; </code></pre> <p>But what I want is this: </p> <pre><code> &lt;speedDial&gt; &lt;value&gt;110&lt;/value&gt; &lt;text&gt; &lt;TR&gt;Yangın&lt;/TR&gt; &lt;EN&gt;Fire&lt;/EN&gt; &lt;/text&gt; &lt;iconId&gt;39&lt;/iconId&gt; &lt;/speedDial&gt; </code></pre> <p>I want to learn the canonical way...</p>
[ { "answer_id": 290333, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": true, "text": "[XmlIgnore] IXmlSerializable XmlSerializer [Serializable]\npublic class SpeedDial\n{\n static void Main()\n {\n XmlSerializer ser = new XmlSerializer(typeof(SpeedDial));\n SpeedDial foo = new SpeedDial { Value = \"110\", TextTR = \"Yangin\",\n TextEN = \"Fire\", IconId = \"39\" };\n ser.Serialize(Console.Out, foo);\n }\n public SpeedDial()\n {\n Text = new SpeedDialText();\n }\n\n [XmlElement(\"text\"), EditorBrowsable(EditorBrowsableState.Never)]\n public SpeedDialText Text { get; set; }\n\n public string Value { get; set; }\n [XmlIgnore]\n public string TextTR\n {\n get { return Text.Tr; }\n set { Text.Tr = value; }\n }\n [XmlIgnore]\n public string TextEN\n {\n get { return Text.En; }\n set { Text.En = value; }\n }\n\n public string IconId { get; set; }\n}\n[Serializable]\npublic class SpeedDialText\n{\n [XmlElement(\"EN\")]\n public string En { get; set; }\n [XmlElement(\"TR\")]\n public string Tr { get; set; }\n}\n" }, { "answer_id": 290361, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "public class SpeedDial\n{\n public string Value { get; set; }\n public TextClass text;\n public string IconId { get; set; }\n}\n\npublic class TextClass\n{\n public string TR { get; set; }\n public string EN { get; set; }\n}\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290213", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35012/" ]
290,214
<p>Is it possible to retrieve variable set in <code>onreadystatechange</code> function from outside the function? <bR>--edit--<BR> Regarding execution of functions:<BR> If its possible i would like to execute ajaxFunction() with one click<BR> and then popup() with next click, or somehow wait for ajax function to end and then call for alert box<BR></p> <p><BR>In pseudocode:</p> <pre><code>function ajaxFunction(){ //creating AJAX ... // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function (){ if(ajaxRequest.readyState == 4){ //success code ======&gt;Here i want to set variable &lt;===== var MyVariable='MyContent'; } } //Retrieving page .... } function popup(){ ajaxFunction(); alert(MyVariable); } </code></pre>
[ { "answer_id": 290217, "author": "Phil Jenkins", "author_id": 35496, "author_profile": "https://Stackoverflow.com/users/35496", "pm_score": 0, "selected": false, "text": "MyVariable var MyVariable; \nfunction ajaxFunction(){\n //creating AJAX \n ...\n // Create a function that will receive data sent from the server\n ajaxRequest.onreadystatechange = function (){\n if(ajaxRequest.readyState == 4){\n //success code\n ======>Here i want to set variable <=====\n MyVariable='MyContent';\n }\n }\n //Retrieving page\n ....\n}\n\nfunction popup(){\n ajaxFunction();\n alert(MyVariable);\n}\n" }, { "answer_id": 290248, "author": "sblundy", "author_id": 4893, "author_profile": "https://Stackoverflow.com/users/4893", "pm_score": 0, "selected": false, "text": "MyVariable popup() popup()" }, { "answer_id": 290283, "author": "digitalsanctum", "author_id": 22436, "author_profile": "https://Stackoverflow.com/users/22436", "pm_score": 0, "selected": false, "text": "var MyVariable; \nfunction ajaxFunction(){\n //creating AJAX \n ...\n // Create a function that will receive data sent from the server\n ajaxRequest.onreadystatechange = function (){\n if(ajaxRequest.readyState == 4){\n //success code\n ======>Here i want to set variable <=====\n MyVariable='MyContent';\n popup(MyVariable);\n }\n }\n //Retrieving page\n ....\n}\n\nfunction popup(x){\n ajaxFunction();\n alert(x);\n}\n" }, { "answer_id": 290288, "author": "some", "author_id": 36866, "author_profile": "https://Stackoverflow.com/users/36866", "pm_score": 4, "selected": true, "text": "function popup(){\n ajaxFunction();\n alert(MyVariable);\n}\n function ajaxFunction(callback){\n //creating AJAX \n ...\n // Create a function that will receive data sent from the server\n ajaxRequest.onreadystatechange = function (){\n if(ajaxRequest.readyState == 4){\n //success code\n callback('MyContent')\n }\n }\n //Retrieving page\n ....\n}\n\nfunction popup() {\n ajaxFunction(function(MyVariable){alert(MyVariable););\n}\n" }, { "answer_id": 290474, "author": "jamesmillerio", "author_id": 3552, "author_profile": "https://Stackoverflow.com/users/3552", "pm_score": 0, "selected": false, "text": "var TestClass = Class.create();\nTestClass.prototype = {\n\n MyVariable: null,\n AjaxURL: \"http://yourajaxurl.com/something.asmx\",\n DoAjaxCall: function() {\n new Ajax.Request(this.AjaxURL, \n method: 'get', \n onSuccess: this.AjaxCallback.bind(this),\n onFailure: this.DoSomethingSmart.bind(this));\n },\n\n AjaxCallback: function(returnVal) {\n this.MyVariable = returnVal.responseText; //ResponseText or whatever you need from the request...\n this.Popup(this.MyVariable);\n },\n\n DoSomethingSmart: function() {\n //Something smart\n },\n\n Popup: function(message) {\n alert(message);\n }\n\n};\n\nvar TestClassInstance = new TestClass();\nTestClassInstance.DoAjaxCall();\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290214", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27186/" ]
290,215
<p>What is the difference between HTML <code>&lt;input type='button' /&gt;</code> and <code>&lt;input type='submit' /&gt;</code>?</p>
[ { "answer_id": 290221, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 9, "selected": true, "text": "<input type=\"button\" /> <input type=\"submit\">" }, { "answer_id": 42872644, "author": "Eugen Mihailescu", "author_id": 327614, "author_profile": "https://Stackoverflow.com/users/327614", "pm_score": 3, "selected": false, "text": "name=button1 name=submit1 <form action=\"checkout.php\" method=\"POST\">\n\n <!-- this won't get submitted despite being named -->\n <input type=\"button\" name=\"button1\" value=\"a button\">\n\n <!-- this one does; so the input's TYPE is important! -->\n <input type=\"submit\" name=\"submit1\" value=\"a submit button\">\n\n</form>\n <?php var_dump($_POST); ?>\n php -S localhost:3000 -t /tmp/test/\n Place Order" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290215", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2472/" ]
290,226
<p>I have a query that works on Postgresql 7.4 but not on Postgresql 8.3 with same database.</p> <p>Query:</p> <pre><code>SELECT * FROM login_session WHERE (now()-modified) &gt; timeout; </code></pre> <p>Gets the following error:</p> <pre><code>ERROR: operator does not exist: interval &gt; integer LINE 1: ...ELECT * FROM login_session WHERE (now()-modified) &gt; timeout ... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. </code></pre> <p>Column <code>modified</code> is a <code>timestamp</code> and <code>timeout</code> is an <code>integer</code>.</p> <p>Is there some settings I need to change on server?</p> <p>I'm installing an application for a client on new server (ubuntu) so I can't change queries in the application.</p>
[ { "answer_id": 290419, "author": "Milen A. Radev", "author_id": 15785, "author_profile": "https://Stackoverflow.com/users/15785", "pm_score": 4, "selected": false, "text": "SELECT\n *\nFROM\n login_session\nWHERE\n (CURRENT_TIMESTAMP - modified) > (timeout * '1 sec'::interval);\n" }, { "answer_id": 290458, "author": "geocar", "author_id": 37507, "author_profile": "https://Stackoverflow.com/users/37507", "pm_score": 3, "selected": true, "text": "create or replace function int2interval (x integer) returns interval as $$ select $1*'1 sec'::interval $$ language sql;\ncreate cast (integer as interval) with function int2interval (integer) as implicit;\n" }, { "answer_id": 290489, "author": "alasdairg", "author_id": 15768, "author_profile": "https://Stackoverflow.com/users/15768", "pm_score": 1, "selected": false, "text": "CREATE OR REPLACE FUNCTION intToInterval(arg integer)\n RETURNS interval AS\n$BODY$\n BEGIN \n return CAST( arg || ' seconds' AS interval ); \n END;\n$BODY$\n LANGUAGE 'plpgsql';\n\nCREATE CAST (integer AS interval)\nWITH FUNCTION intToInterval ( integer )\nAS IMPLICIT;\n" } ]
2008/11/14
[ "https://Stackoverflow.com/questions/290226", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24595/" ]