qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
270,438
|
<p>I'm implementing my app as a drag source. When I call DoDragDrop (Win32 call, not MFC) it enters into a modal loop and I don't get repaint messages in my main window until DoDragDrop returns. Unfortunately if I do a drop in the shell (a file) and the filename is already there the shell asks if I want to replace the file. But since me app is blocked because DoDragDrop hasn't returned it isn't repainting and looks 'frozen'. </p>
<p>Any clues ?</p>
|
[
{
"answer_id": 9114170,
"author": "user1185359",
"author_id": 1185359,
"author_profile": "https://Stackoverflow.com/users/1185359",
"pm_score": 2,
"selected": false,
"text": "DoDragDrop() SHFileOperation() SetTimer() DoDragDrop() DoDragDrop() DoDragDrop() WM_USER DoDragDrop() WndProc() WM_USER DoDragDrop() SetTimer() SetTimer() WM_TIMER WM_TIMER"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270438",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
270,444
|
<p>I'm getting this error:</p>
<pre><code>javax.servlet.ServletException: bean not found within scope
</code></pre>
<p>on a page with this at the top.</p>
<pre class="lang-html prettyprint-override"><code><jsp:useBean id="bean" type="com.example.Bean" scope="request" />
</code></pre>
<p>The class exists in the classpath, it worked this morning, and I don't get what not found within scope means.</p>
<p>How is this caused and how can I solve it?</p>
|
[
{
"answer_id": 904223,
"author": "victor hugo",
"author_id": 70616,
"author_profile": "https://Stackoverflow.com/users/70616",
"pm_score": 1,
"selected": false,
"text": "<jsp:useBean id=\"givingFormBean\" type=\"some.packg.GivingForm\" scope=\"request\" />\n"
},
{
"answer_id": 3029379,
"author": "BalusC",
"author_id": 157882,
"author_profile": "https://Stackoverflow.com/users/157882",
"pm_score": 6,
"selected": true,
"text": "class type <jsp:useBean id=\"bean\" type=\"com.example.Bean\" scope=\"request\" />\n Bean bean = (Bean) pageContext.getAttribute(\"bean\", PageContext.REQUEST_SCOPE);\n\nif (bean == null) {\n throw new ServletException(\"bean not found within scope\");\n}\n\n// Use bean ...\n <jsp:useBean id=\"bean\" class=\"com.example.Bean\" scope=\"request\" />\n Bean bean = (Bean) pageContext.getAttribute(\"bean\", PageContext.REQUEST_SCOPE);\n\nif (bean == null) {\n bean = new Bean();\n pageContext.setAttribute(\"bean\", bean, PageContext.REQUEST_SCOPE);\n}\n\n// Use bean ...\n doGet() request.setAttribute(\"bean\", new Bean());\nrequest.getRequestDispatcher(\"page.jsp\").forward(request, response);\n /WEB-INF"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270444",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12386/"
] |
270,445
|
<p>Is there a way to compile multiple java source directories in a single maven project? </p>
|
[
{
"answer_id": 270451,
"author": "sal",
"author_id": 13753,
"author_profile": "https://Stackoverflow.com/users/13753",
"pm_score": 6,
"selected": false,
"text": "<build>\n <sourceDirectory>.</sourceDirectory>\n <plugins>\n <plugin>\n <groupId>org.apache.maven.plugins</groupId>\n <artifactId>maven-compiler-plugin</artifactId>\n <configuration>\n <includes>\n <include>src/main/java/**/*.java</include>\n <include>src/main2/java/**/*.java</include>\n </includes>\n </configuration>\n </plugin>\n </plugins>\n</build>\n"
},
{
"answer_id": 270490,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 9,
"selected": true,
"text": "<build>\n <plugins>\n <plugin>\n <groupId>org.codehaus.mojo</groupId>\n <artifactId>build-helper-maven-plugin</artifactId>\n <version>3.2.0</version>\n <executions>\n <execution>\n <phase>generate-sources</phase>\n <goals>\n <goal>add-source</goal>\n </goals>\n <configuration>\n <sources>\n <source>src/main/generated</source>\n </sources>\n </configuration>\n </execution>\n </executions>\n </plugin>\n </plugins>\n</build>\n"
},
{
"answer_id": 9395142,
"author": "domi.vds",
"author_id": 1225863,
"author_profile": "https://Stackoverflow.com/users/1225863",
"pm_score": 5,
"selected": false,
"text": "<plugin>\n <groupId>org.apache.maven.plugins</groupId>\n <artifactId>maven-compiler-plugin</artifactId>\n <version>3.8.1</version>\n <configuration>\n <generatedSourcesDirectory>src/main/generated</generatedSourcesDirectory>\n </configuration>\n</plugin>\n"
},
{
"answer_id": 14913197,
"author": "ursa",
"author_id": 2078908,
"author_profile": "https://Stackoverflow.com/users/2078908",
"pm_score": 1,
"selected": false,
"text": "${build.directory} jetty:run"
},
{
"answer_id": 18284281,
"author": "sendon1982",
"author_id": 2680640,
"author_profile": "https://Stackoverflow.com/users/2680640",
"pm_score": 3,
"selected": false,
"text": " <resources>\n <resource>\n <directory>src/main/java</directory>\n <includes>\n <include>**/*.java</include>\n <include>**/*.properties</include>\n <include>**/*.xml</include>\n </includes>\n </resource>\n\n <resource>\n <directory>src/main/resources</directory>\n <includes>\n <include>**/*.java</include>\n <include>**/*.properties</include>\n <include>**/*.xml</include>\n </includes>\n </resource>\n\n <resource>\n <directory>src/main/generated</directory>\n <includes>\n <include>**/*.java</include>\n <include>**/*.properties</include>\n <include>**/*.xml</include>\n </includes>\n </resource>\n </resources>\n"
},
{
"answer_id": 23625612,
"author": "comeGetSome",
"author_id": 1005652,
"author_profile": "https://Stackoverflow.com/users/1005652",
"pm_score": 6,
"selected": false,
"text": "<build>\n <finalName>osmwse</finalName>\n <sourceDirectory>src/main/java, src/interfaces, src/services</sourceDirectory>\n</build>\n"
},
{
"answer_id": 56923240,
"author": "Prabhu",
"author_id": 11750839,
"author_profile": "https://Stackoverflow.com/users/11750839",
"pm_score": 1,
"selected": false,
"text": "<compileSourceRoots> oal: org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-cli)\n[DEBUG] Style: Regular\n[DEBUG] Configuration: <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<configuration>\n <basedir default-value=\"${basedir}\"/>\n <buildDirectory default-value=\"${project.build.directory}\"/>\n <compilePath default-value=\"${project.compileClasspathElements}\"/>\n <compileSourceRoots default-value=\"${project.compileSourceRoots}\"/>\n <compilerId default-value=\"javac\">${maven.compiler.compilerId}</compilerId>\n <compilerReuseStrategy default-value=\"${reuseCreated}\">${maven.compiler.compilerReuseStrategy}</compilerReuseStrategy>\n <compilerVersion>${maven.compiler.compilerVersion}</compilerVersion>\n <debug default-value=\"true\">${maven.compiler.debug}</debug>\n <debuglevel>${maven.compiler.debuglevel}</debuglevel>\n <encoding default-value=\"${project.build.sourceEncoding}\">${encoding}</encoding>\n <executable>${maven.compiler.executable}</executable>\n <failOnError default-value=\"true\">${maven.compiler.failOnError}</failOnError>\n <failOnWarning default-value=\"false\">${maven.compiler.failOnWarning}</failOnWarning>\n <forceJavacCompilerUse default-value=\"false\">${maven.compiler.forceJavacCompilerUse}</forceJavacCompilerUse>\n <fork default-value=\"false\">${maven.compiler.fork}</fork>\n <generatedSourcesDirectory default-value=\"${project.build.directory}/generated-sources/annotations\"/>\n <maxmem>${maven.compiler.maxmem}</maxmem>\n <meminitial>${maven.compiler.meminitial}</meminitial>\n <mojoExecution default-value=\"${mojoExecution}\"/>\n <optimize default-value=\"false\">${maven.compiler.optimize}</optimize>\n <outputDirectory default-value=\"${project.build.outputDirectory}\"/>\n <parameters default-value=\"false\">${maven.compiler.parameters}</parameters>\n <project default-value=\"${project}\"/>\n <projectArtifact default-value=\"${project.artifact}\"/>\n <release>${maven.compiler.release}</release>\n <session default-value=\"${session}\"/>\n <showDeprecation default-value=\"false\">${maven.compiler.showDeprecation}</showDeprecation>\n <showWarnings default-value=\"false\">${maven.compiler.showWarnings}</showWarnings>\n <skipMain>${maven.main.skip}</skipMain>\n <skipMultiThreadWarning default-value=\"false\">${maven.compiler.skipMultiThreadWarning}</skipMultiThreadWarning>\n <source default-value=\"1.6\">${maven.compiler.source}</source>\n <staleMillis default-value=\"0\">${lastModGranularityMs}</staleMillis>\n <target default-value=\"1.6\">${maven.compiler.target}</target>\n <useIncrementalCompilation default-value=\"true\">${maven.compiler.useIncrementalCompilation}</useIncrementalCompilation>\n <verbose default-value=\"false\">${maven.compiler.verbose}</verbose>\n</configuration>\n -X mvn clean install -X\nmvn compiler:compile -X\n"
},
{
"answer_id": 58694915,
"author": "Maksym",
"author_id": 7179509,
"author_profile": "https://Stackoverflow.com/users/7179509",
"pm_score": 3,
"selected": false,
"text": "<plugin>\n <groupId>org.apache.maven.plugins</groupId>\n <artifactId>maven-compiler-plugin</artifactId>\n <version>3.3</version>\n <configuration>\n <generatedSourcesDirectory>src/main/generated</generatedSourcesDirectory> \n </configuration>\n</plugin>\n"
},
{
"answer_id": 59879607,
"author": "radzimir",
"author_id": 632331,
"author_profile": "https://Stackoverflow.com/users/632331",
"pm_score": 2,
"selected": false,
"text": "<execution>\n <phase>generate-sources</phase>\n <goals>\n <goal>add-test-source</goal>\n </goals>\n <configuration>\n <sources>\n <source>target/generated/some-test-classes</source>\n </sources>\n </configuration>\n</execution>\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270445",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13753/"
] |
270,453
|
<p>I recently got a notification from a McAfee service (what used to be called HackerSafe) that my website is using SSLv2 and it should be using SSLv3. I don't know anything about the versions of SSL. My site is using IIS 6.0, is there a setting somewhere to turn on SSLv3 or do I need to install something to make this happen? Also, is there any drawbacks to only using SSLv3? Are there browsers that can only use v2?</p>
|
[
{
"answer_id": 288661,
"author": "Saul Dolgin",
"author_id": 8305,
"author_profile": "https://Stackoverflow.com/users/8305",
"pm_score": 3,
"selected": false,
"text": "Windows Registry Editor Version 5.00\n\n[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\SecurityProviders\\SCHANNEL\\Protocols\\SSL 2.0\\Server]\n\"Enabled\"=dword:00000000\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270453",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33731/"
] |
270,455
|
<p>I'm all for language diversity, but Objective C is insane. So I'm curious: is it possible to code iPhone apps with C++ while using the Cocoa API, etc?</p>
|
[
{
"answer_id": 3441001,
"author": "Arpad Goretity",
"author_id": 415188,
"author_profile": "https://Stackoverflow.com/users/415188",
"pm_score": 0,
"selected": false,
"text": "#import \"ObjectiveX.h\"\n\nvoid GUIApplicationMain() { \n GUIAlert Alert;\n GUILabel Label;\n GUIScreen MainScreen;\n\n Alert.set_text(@\"Just a lovely alert box!\");\n Alert.set_title(@\"Hello!\");\n Alert.set_button(@\"Okay\");\n Alert.show();\n\n Label.set_text(@\"Ciao!\");\n Label.set_position(100, 200, 120, 40);\n\n MainScreen.init();\n MainScreen.addGUIControl(Label.init()); \n}\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9476/"
] |
270,458
|
<p>I am building a really basic Cocoa application using WebKit, to display a Flash/Silverlight application within it. Very basic, no intentions for it to be a browser itself.</p>
<p>So far I have been able to get it to open basic html links (<code><a href="..." /></code>) in a new instance of Safari using </p>
<pre><code>[[NSWorkspace sharedWorkspace] openURL:[request URL]];
</code></pre>
<p>Now my difficulty is opening a link in a new instance of Safari when <code>window.open()</code> is used in JavaScript. I "think" (and by this, I have been hacking away at the code and am unsure if i actually did or not) I got this kind of working by setting the WebView's <code>policyDelegate</code> and implementing its</p>
<pre><code>-webView:decidePolicyForNavigationAction:request:frame:decisionListener:
</code></pre>
<p>delegate method. However this led to some erratic behavior.</p>
<p>So the simple question, what do I need to do so that when <code>window.open()</code> is called, the link is opened in a new instance of Safari.</p>
<p>Thanks</p>
<p>Big point, I am normally a .NET developer, and have only been working with Cocoa/WebKit for a few days.</p>
|
[
{
"answer_id": 272546,
"author": "FireWire",
"author_id": 35263,
"author_profile": "https://Stackoverflow.com/users/35263",
"pm_score": 3,
"selected": false,
"text": "webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener: window.open() webView:createWebViewWithRequest:request createWebViewWithRequest decidePolicyForNewWindowAction"
},
{
"answer_id": 510789,
"author": "Yoni Shalom",
"author_id": 29614,
"author_profile": "https://Stackoverflow.com/users/29614",
"pm_score": 3,
"selected": false,
"text": "- (void)webView:decidePolicyForNavigationAction:actionInformation :request:frame:decisionListener:\n - (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request {\n //this is a hack because request URL is null here due to a bug in webkit \n return [newWindowHandler webView];\n}\n @implementation NewWindowHandler\n\n-(NewWindowHandler*)initWithWebView:(WebView*)newWebView {\n webView = newWebView;\n\n [webView setUIDelegate:self];\n [webView setPolicyDelegate:self]; \n [webView setResourceLoadDelegate:self];\n\n return self;\n}\n\n- (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {\n [[NSWorkspace sharedWorkspace] openURL:[actionInformation objectForKey:WebActionOriginalURLKey]];\n}\n\n-(WebView*)webView {\n return webView;\n}\n"
},
{
"answer_id": 15382439,
"author": "lmirosevic",
"author_id": 399772,
"author_profile": "https://Stackoverflow.com/users/399772",
"pm_score": 2,
"selected": false,
"text": "webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener: nil target=\"_blank\" webView.UIDelegate = self;\n webView:createWebViewWithRequest: -(WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request {\n return [GBWebViewExternalLinkHandler riggedWebViewWithLoadHandler:^(NSURL *url) {\n [[NSWorkspace sharedWorkspace] openURL:url];\n }];\n}\n // GBWebViewExternalLinkHandler.h\n// TabApp2\n//\n// Created by Luka Mirosevic on 13/03/2013.\n// Copyright (c) 2013 Goonbee. All rights reserved.\n//\n\n#import <Foundation/Foundation.h>\n\n@class WebView;\n\ntypedef void(^NewWindowCallback)(NSURL *url);\n\n@interface GBWebViewExternalLinkHandler : NSObject\n\n+(WebView *)riggedWebViewWithLoadHandler:(NewWindowCallback)handler;\n\n@end\n // GBWebViewExternalLinkHandler.m\n// TabApp2\n//\n// Created by Luka Mirosevic on 13/03/2013.\n// Copyright (c) 2013 Goonbee. All rights reserved.\n//\n\n#import \"GBWebViewExternalLinkHandler.h\"\n\n#import <WebKit/WebKit.h>\n\n@interface GBWebViewExternalLinkHandler ()\n\n@property (strong, nonatomic) WebView *attachedWebView;\n@property (strong, nonatomic) GBWebViewExternalLinkHandler *retainedSelf;\n@property (copy, nonatomic) NewWindowCallback handler;\n\n@end\n\n@implementation GBWebViewExternalLinkHandler\n\n-(id)init {\n if (self = [super init]) {\n //create a new webview with self as the policyDelegate, and keep a ref to it\n self.attachedWebView = [WebView new];\n self.attachedWebView.policyDelegate = self;\n }\n\n return self;\n}\n\n-(void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {\n //execute handler\n if (self.handler) {\n self.handler(actionInformation[WebActionOriginalURLKey]);\n }\n\n //our job is done so safe to unretain yourself\n self.retainedSelf = nil;\n}\n\n+(WebView *)riggedWebViewWithLoadHandler:(NewWindowCallback)handler {\n //create a new handler\n GBWebViewExternalLinkHandler *newWindowHandler = [GBWebViewExternalLinkHandler new];\n\n //store the block\n newWindowHandler.handler = handler;\n\n //retain yourself so that we persist until the webView:decidePolicyForNavigationAction:request:frame:decisionListener: method has been called\n newWindowHandler.retainedSelf = newWindowHandler;\n\n //return the attached webview\n return newWindowHandler.attachedWebView;\n}\n\n@end\n"
},
{
"answer_id": 20481412,
"author": "kmarin",
"author_id": 2312866,
"author_profile": "https://Stackoverflow.com/users/2312866",
"pm_score": 2,
"selected": false,
"text": "- (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request {\n\n return [self externalWebView:sender];\n}\n\n\n\n\n- (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener\n{\n [[NSWorkspace sharedWorkspace] openURL:[actionInformation objectForKey:WebActionOriginalURLKey]];\n}\n\n-(WebView*)externalWebView:(WebView*)newWebView\n{\n WebView *webView = newWebView;\n\n [webView setUIDelegate:self];\n [webView setPolicyDelegate:self];\n [webView setResourceLoadDelegate:self];\n return webView;\n}\n"
},
{
"answer_id": 32174149,
"author": "adam.wulf",
"author_id": 173244,
"author_profile": "https://Stackoverflow.com/users/173244",
"pm_score": 0,
"selected": false,
"text": "loadRequest: window.open myWebView.frameLoadDelegate = self;\n window.open - (void)webView:(WebView *)webView didCreateJavaScriptContext:(JSContext *)context forFrame:(WebFrame *)frame{\ncontext[@\"window\"][@\"open\"] = ^(id url){\n NSLog(@\"url to load: %@\", url);\n };\n}\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270458",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35263/"
] |
270,468
|
<p>Can anyone please let me know the procedure to perform silent installation of SQL Server Express 2005 and the way to specify the installation parameters.</p>
|
[
{
"answer_id": 270521,
"author": "GeekyMonkey",
"author_id": 29900,
"author_profile": "https://Stackoverflow.com/users/29900",
"pm_score": 3,
"selected": false,
"text": "string InstallFile = \"SSCERuntime-ENU-x86.msi\"\nstring LogFile = \"C:\\Install.log\"\n\nProcess proc;\nproc = Process.Start(\"msiexec\", \"/l \" + LogFile + \" /quiet /i \" + InstallFile);\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270468",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
270,479
|
<p>My solution includes these two projects:</p>
<ul>
<li>MyNamespace.Web.UI</li>
<li>MyNamespace.Web.Core</li>
</ul>
<p>UI references Core, and Core references Foobar.dll, which exists nowhere except my library. When I build from Visual Studio 2008 Foobar.dll is in the UI project's Bin folder as expected. I have made certain it was not there before the build. </p>
<p>But when I build from NAnt, it is not there, which results in a runtime exception. Here's what the NAnt task looks like:</p>
<pre><code><target name="compile" depends="init">
<exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe"
commandline="${solution.file} /m /t:Clean /p:Configuration=${project.config} /v:q" workingdir="." />
<exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe"
commandline="${solution.file} /m /t:Rebuild /p:Configuration=${project.config} /v:q" workingdir="." />
</target>
</code></pre>
<p>In VS I have tried building, rebuilding, rebuilding all in release mode and debug mode, etc. It's always the same. Foobar.dll is in the Bin folder. Not so with NAnt. I have tried also to remove the /m switch from the NAnt script. Same result.</p>
<p>There are several other dlls referenced in Core and not in UI, and they appear in Bin as expected after the NAnt build.</p>
<p>My workaround is to reference Foobar.dll in the UI project, but that makes me a little nauseous. Any idea what can cause this?</p>
<p>(Incidentally Foobar.dll is actually NHibernate.ProxyGenerators.CastleDynamicProxy.dll)</p>
|
[
{
"answer_id": 34050070,
"author": "Hinesh Mandalia",
"author_id": 5631656,
"author_profile": "https://Stackoverflow.com/users/5631656",
"pm_score": 0,
"selected": false,
"text": "<Reference Include=\"Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL\">\n <SpecificVersion>False</SpecificVersion>\n <HintPath>..\\lib\\Microsoft.Web.Infrastructure.1.0.0.0\\lib\\net40\\Microsoft.Web.Infrastructure.dll</HintPath>\n <Private>True</Private>\n</Reference>\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270479",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29493/"
] |
270,488
|
<p>I am using VC++. Is <code>assert(false)</code> ignored in release mode?</p>
|
[
{
"answer_id": 9836791,
"author": "RzR",
"author_id": 149841,
"author_profile": "https://Stackoverflow.com/users/149841",
"pm_score": 1,
"selected": false,
"text": " #ifdef NDEBUG\n\n # define assert(expr) (__ASSERT_VOID_CAST (0))\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270488",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3153/"
] |
270,493
|
<p>I need two divs to look a bit like this: </p>
<pre><code> | |
---| LOGO |------------------------
| |_______________| LINKS |
| CONTENT |
</code></pre>
<p>What's the neatest/most elegant way of making them overlap neatly? The logo will have a fixed height and width and will be touching the top edge of the page.</p>
|
[
{
"answer_id": 270501,
"author": "sblundy",
"author_id": 4893,
"author_profile": "https://Stackoverflow.com/users/4893",
"pm_score": 3,
"selected": false,
"text": "div#logo {\n position: absolute;\n left: 100px; // or whatever\n}\n"
},
{
"answer_id": 270503,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 2,
"selected": false,
"text": "#logo\n{\n position: absolute:\n z-index: 2000;\n left: 100px;\n width: 100px;\n height: 50px;\n}\n"
},
{
"answer_id": 270511,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 8,
"selected": true,
"text": "html,\nbody {\n margin: 0px;\n}\n#logo {\n position: absolute; /* Reposition logo from the natural layout */\n left: 75px;\n top: 0px;\n width: 300px;\n height: 200px;\n z-index: 2;\n}\n#content {\n margin-top: 100px; /* Provide buffer for logo */\n}\n#links {\n height: 75px;\n margin-left: 400px; /* Flush links (with a 25px \"padding\") right of logo */\n} <div id=\"logo\">\n <img src=\"https://via.placeholder.com/200x100\" />\n</div>\n<div id=\"content\">\n \n <div id=\"links\">dssdfsdfsdfsdf</div>\n</div>"
},
{
"answer_id": 270512,
"author": "TravisO",
"author_id": 35116,
"author_profile": "https://Stackoverflow.com/users/35116",
"pm_score": 7,
"selected": false,
"text": "<div style=\"margin-top: -25px;\">\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270493",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
270,494
|
<p>I have a form with a textbox and a button. IE is the only browser that will not submit the form when Enter is pressed (works in FF, Opera, Safari, Chrome, etc.). I found this javascript function to try to coax IE into behaving; but no avail:</p>
<pre><code>function checkEnter(e){
var characterCode
if (e && e.which) {
e = e
characterCode = e.which
} else {
e = event
characterCode = e.keyCode
}
if (characterCode == 13) {
document.forms[0].submit()
return false
} else {
return true
}
}
</code></pre>
<p>Implementation: </p>
<pre><code>searchbox.Attributes("OnKeyUp") = "checkEnter(event)"
</code></pre>
<p>Any advice?</p>
<p><strong>EDIT:</strong> <a href="http://www.codeproject.com/KB/aspnet/EnterKeyToButtonClick.aspx" rel="noreferrer">This page</a> on <a href="http://www.codeproject.com/" rel="noreferrer">CodeProject</a> outlines what Dillie was saying, and it works perfectly.</p>
|
[
{
"answer_id": 270505,
"author": "TravisO",
"author_id": 35116,
"author_profile": "https://Stackoverflow.com/users/35116",
"pm_score": 2,
"selected": false,
"text": "// Use the following Javascript in your HTML view\n// put it somewhere between <head> and </head>\n\n <script language=\"JavaScript\" type=\"text/javascript\"><!--\n function KeyDownHandler(btn)\n {\n if (event.keyCode == 13)\n {\n event.returnValue=false;\n event.cancel = true;\n btn.click();\n }\n }\n // -->\n </script>\n\n // Put this in your TextBox(es) aka inside <asp:textbox ... >\n onkeydown=\"KeyDownHandler(ButtonID)\"\n"
},
{
"answer_id": 487965,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": " <!-- Fix for IE bug (One text input and submit, disables submit on pressing \"Enter\") -->\n <div style=\"display:none\">\n <input type=\"text\" name=\"hiddenText\"/>\n </div>\n"
},
{
"answer_id": 937241,
"author": "Alec",
"author_id": 115681,
"author_profile": "https://Stackoverflow.com/users/115681",
"pm_score": 1,
"selected": false,
"text": "display:none z-index position:absolute; bottom: -20px; left: -20px; z-index: -1;"
},
{
"answer_id": 9699405,
"author": "pro",
"author_id": 352728,
"author_profile": "https://Stackoverflow.com/users/352728",
"pm_score": 0,
"selected": false,
"text": "<input type=\"text\" name=\"hidden\" style=\"visibility:hidden;display:none;\" />\n"
},
{
"answer_id": 11036546,
"author": "svandragt",
"author_id": 997,
"author_profile": "https://Stackoverflow.com/users/997",
"pm_score": 1,
"selected": false,
"text": "position: absolute; /* no longer takes up layout space */\nvisibility: hidden; /* no longer clickable / visible */\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270494",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25515/"
] |
270,510
|
<p>I am looking to encrypt some data using <a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard" rel="noreferrer">Rijndael/AES</a> in <a href="http://en.wikipedia.org/wiki/VBScript" rel="noreferrer">VBScript</a> using a specific key and <a href="http://en.wikipedia.org/wiki/Initialization_vector" rel="noreferrer">IV</a> value. Are there any good function libraries or COM components that would be good to use?</p>
<p>I looked at <a href="http://en.wikipedia.org/wiki/CAPICOM" rel="noreferrer">CAPICOM</a>; it allows a passphrase only, and won't allow setting specific key and IV values.</p>
|
[
{
"answer_id": 858525,
"author": "Cheeso",
"author_id": 48082,
"author_profile": "https://Stackoverflow.com/users/48082",
"pm_score": 2,
"selected": false,
"text": "RijndaelManaged <?xml version=\"1.0\"?>\n\n<!--\n\n//\n// Ionic.COM.SlowAES.wsc\n//\n// This is a Windows Script Component that exposes the SlowAES\n// encryption engine via COM. This AES can be used from any \n// COM-capable environment, including Javascript or VBScript. \n//\n//\n// This code is licensed under the Microsoft Public License. See the\n// accompanying License.txt file for details.\n//\n// Copyright 2009 Dino Chiesa\n//\n\n-->\n\n<package>\n\n<component id=\"Ionic.Com.SlowAES\">\n\n <comment>\nSlowAES is a Javascript implementation of AES. \n See http://code.google.com/p/slowaes. \nThis is a COM package for SlowAES.\n </comment>\n\n<?component error=\"true\" debug=\"true\"?>\n\n<registration\n description=\"WSC Component for SlowAES\"\n progid=\"Ionic.Com.SlowAES\"\n version=\"1.00\"\n classid=\"{ba78383f-1bcc-4df6-9fb9-61cd639ebc94}\"\n remotable=\"False\">\n\n <!-- boilerplate registration/unregistration logic -->\n <script language=\"VBScript\">\n <![CDATA[\n\nstrComponent = \"Ionic SlowAES\"\n\nFunction Register\n MsgBox strComponent & \" - registered.\"\nEnd Function\n\nFunction Unregister\n MsgBox strComponent & \" - unregistered.\"\nEnd Function\n\n ]]>\n </script>\n</registration>\n\n<public>\n <method name=\"EncryptString\">\n<parameter name=\"plainText\"/>\n </method>\n\n <method name=\"DecryptBytes\">\n<parameter name=\"cipherText\"/>\n </method>\n\n <method name=\"DecryptBytesToString\">\n<parameter name=\"cipherText\"/>\n </method>\n\n <method name=\"DecryptHexString\">\n<parameter name=\"hexStringCipherText\"/>\n </method>\n\n <method name=\"DecryptCommaDelimitedStringToString\">\n<parameter name=\"cipherText\"/>\n </method>\n\n <property name=\"Key\">\n <put/>\n </property>\n\n <property name=\"Mode\">\n <put/>\n <get/>\n </property>\n\n <property name=\"IV\">\n <put/>\n <get/>\n </property>\n\n <property name=\"KeySize\">\n <put/>\n <get/>\n </property>\n</public>\n\n<script language=\"JavaScript\">\n<![CDATA[\n\n// ...insert slowAES code here... //\n\n// defaults\nvar _keysize = slowAES.aes.SIZE_128;\nvar _mode = slowAES.modeOfOperation.CBC;\nvar _iv = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];\nvar _key;\n\n/* \n* byteArrayToHexString\n* convert a byte array to hex string.\n*/\nfunction byteArrayToHexString(a)\n{\ntry { hexcase } catch(e) { hexcase=0; }\nvar hex_tab = hexcase ? \"0123456789ABCDEF\" : \"0123456789abcdef\";\nvar r= \"\";\nfor (var i = 0; i < a.length; i++)\n{\n var b = hex_tab.charAt((a[i] >> 4) & 0x0F) + \n hex_tab.charAt(a[i] & 0x0F);\n r+= b;\n}\nreturn r;\n}\n\n/* \n* hexStringToByteArray\n* convert a string of hex byts to a byte array\n*/\nfunction hexStringToByteArray(s)\n{\nvar r= Array(s.length/2);\nfor (var i = 0; i < s.length; i+=2)\n{\n r[i/2] = parseInt(s.substr(i,2),16);\n}\nreturn r;\n}\n\nfunction EncryptString(plainText)\n{\n var bytesToEncrypt = cryptoHelpers.convertStringToByteArray(plainText);\n var result = slowAES.encrypt(bytesToEncrypt, \n _mode,\n _key,\n _keysize,\n _iv);\nreturn result['cipher'];\n}\n\nfunction DecryptBytesToString(cipherText)\n{\nvar d = DecryptBytes(cipherText);\nvar s = cryptoHelpers.convertByteArrayToString(d);\ns[cipherText.length]= 0;\nreturn s;\n}\n\nfunction DecryptHexString(hexStringCipherText)\n{\nvar cipherText = hexStringToByteArray(hexStringCipherText);\nreturn DecryptBytesToString(cipherText);\n}\n\nfunction DecryptCommaDelimitedStringToString(cipherText)\n{\nvar c = [];\nvar atoms = cipherText.split(\",\");\nfor (i=0; i < atoms.length; i++)\n{\n c.push(parseInt(atoms[i], 10));\n}\nvar d = DecryptBytes(c);\nreturn cryptoHelpers.convertByteArrayToString(d);\n}\n\nfunction DecryptBytes(cipherText)\n{\nif (cipherText == undefined) return null;\n\nvar originalSize = cipherText.length;\n\nvar result = slowAES.decrypt(cipherText, \n originalSize,\n _mode,\n _key,\n _keysize,\n _iv);\n\nreturn result;\n}\n\nfunction put_Key(keyString)\n{\n _key = hexStringToByteArray(keyString);\n}\n\nfunction put_KeySize(size)\n{\nif (size == 128) _keysize = slowAES.aes.keySize.SIZE_128;\nelse if (size == 192) _keysize = slowAES.aes.keySize.SIZE_192;\nelse if (size == 256) _keysize = slowAES.aes.keySize.SIZE_256;\nelse\n throw \"Unsupported key size. Must be one of { 128, 192, 256 }.\";\n}\n\nfunction get_KeySize()\n{\nif (_keysize == slowAES.aes.keySize.SIZE_128) return 128;\nelse if (_keysize == slowAES.aes.keySize.SIZE_192) return 192;\nelse if (_keysize == slowAES.aes.keySize.SIZE_256) return 256;\nelse return -1;\n}\n\nfunction put_IV(ivString)\n{\n _iv = hexStringToByteArray(ivString);\n}\n\nfunction get_IV()\n{\nreturn byteArrayToHexString(_iv);\n}\n\nfunction put_Mode(mode)\n{\nif (mode == \"CBC\") _mode= slowAES.modeOfOperation.CBC;\nelse if (mode == \"OFB\") _mode= slowAES.modeOfOperation.OFB;\nelse if (mode == \"CFB\") _mode= slowAES.modeOfOperation.CFB;\nelse throw \"Unsupported mode. Must be one of {CBC, OFB, CFB}\";\n}\n\nfunction get_Mode()\n{\nif (_mode == slowAES.modeOfOperation.CBC) return \"CBC\";\nif (_mode == slowAES.modeOfOperation.OFB) return \"OFB\";\nif (_mode == slowAES.modeOfOperation.CFB) return \"CFB\";\nreturn \"???\";\n}\n\n]]>\n\n</script>\n\n</component>\n\n</package>\n ' '\n' byteArrayToHexString'\n' convert a byte array to hex string.'\n' '\nFunction byteArrayToHexString(a)\nDim r,b,i\nr = \"\"\nFor i = 0 To UBound(a)\n b = Hex( (a(i) And &HF0) / 16) & Hex(a(i) And &HF)\n r= r & b\nNext\nbyteArrayToHexString= r\nEnd Function\n\n' '\n' hexStringToByteArray'\n' convert a string of hex byts to a byte array'\n' '\nFunction hexStringToByteArray(s)\nDim r()\nReDim r(Len(s)/2-1)\nDim x\nFor i = 0 To Len(s)-2 Step 2\n x= \"&H\" & Mid(s,i+1,2)\n r(i/2) = CInt(x)\nNext\nhexStringToByteArray= r\nEnd Function\n\nFunction DemoEncryption()\nWScript.echo \"Testing Ionic.Com.SlowAES...\"\n\nWScript.echo \"key: \" & byteArrayToHexString(key)\nWScript.echo \"iv: \" & byteArrayToHexString(iv)\nWScript.echo \"key length: \" & keyLengthInBytes & \" bytes\"\nWScript.echo \"key length: \" & (keyLengthInBytes*8) & \" bits\"\nWScript.echo \"plaintext: \" & plaintext\nWScript.echo \"plaintext.length: \" & Len(plaintext)\n\nWScript.echo \"instantiate Ionic.Com.SlowAES\"\nDim aes\nset aes = CreateObject(\"Ionic.Com.SlowAES\")\n\nWScript.echo \"keysize\"\naes.KeySize = keyLengthInBytes * 8\n\nWScript.echo \"key\"\naes.Key = byteArrayToHexString(key)\n\nWScript.echo \"iv \"\naes.IV= byteArrayToHexString(iv)\n\nWScript.echo \"mode \"\naes.Mode = \"CBC\"\n\nWScript.echo \"encrypting... \"\nDim result\nresult= aes.EncryptString(plaintext)\n\n' result is a comma-separated string '\n' if we Eval() on it we convert it to an array '\nDim expr\nexpr = \"Array(\" & result & \")\" \n\nresult= Eval( expr )\n\nWScript.echo \"Cryptotext/Eval: \" & byteArrayToHexString(result)\nWScript.echo \"Cryptotext.length: \" & UBound(result)+1\n\nWScript.echo \"decrypting... \"\nDim decrypted\n'The javascript way to do this is to pass the byte array.'\n' Like so:'\n' var decrypted = aes.DecryptBytesToString(result);'\n' '\n'This does not work from VBScript. So, convert to a hexstring,'\n'pass the hex string, and then convert back, in the COM component.'\ndecrypted= aes.DecryptHexString(byteArrayToHexString(result))\n\nWScript.echo \"decrypted: \" & decrypted\nEnd Function\n\ndim plaintext, iv, key, keyLengthInBytes\n\nplaintext= \"Hello. This is a test. of the emergency broadcasting system.\"\n' iv must be a hexstring representation of an array of bytes, length=16'\niv = hexStringToByteArray(\"feedbeeffeedbeefbaadf00dbaadf00d\")\n' key must be a hexstring representation of an array of bytes, length=16 or 32'\nkey = hexStringToByteArray(\"cafebabe0099887766554433221100AA\")\nkeyLengthInBytes= UBound(key)+1\n\nIf Err.Number <> 0 Then Err.Clear\n\nCall DemoEncryption\n\nIf (Err.Number <> 0) Then WScript.echo(\"Error: \" & Err.Description)\n"
},
{
"answer_id": 28129895,
"author": "Grnd Xhef",
"author_id": 4490604,
"author_profile": "https://Stackoverflow.com/users/4490604",
"pm_score": 3,
"selected": false,
"text": "'-----------------------------------------------------\nDim obj,arr,i,r,str,enc,asc\ndim bytes,bytesd,s,sc,sd\nset obj=WScript.CreateObject(\"System.Security.Cryptography.RijndaelManaged\")\nSet asc = CreateObject(\"System.Text.UTF8Encoding\")\ns=\"This is a private message\"\nbytes=asc.GetBytes_4(s)\nobj.GenerateKey()\nobj.GenerateIV()\nset enc=obj.CreateEncryptor()\nset dec=obj.CreateDecryptor()\n\nbytec=enc.TransformFinalBlock((bytes),0,lenb(bytes))\nsc=asc.GetString((bytec))\nmsgbox sc\n\nbyted=dec.TransformFinalBlock((bytec),0,lenb(bytec))\nsd=asc.GetString((byted))\nmsgbox sd\n'-----------------------------------------------------\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270510",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
270,531
|
<p>I've got an arbitrary list of .NET assemblies.</p>
<p>I need to programmatically check if each DLL was built for x86 (as opposed to x64 or Any CPU). Is this possible?</p>
|
[
{
"answer_id": 270545,
"author": "cfeduke",
"author_id": 5645,
"author_profile": "https://Stackoverflow.com/users/5645",
"pm_score": 8,
"selected": false,
"text": "PE Option | PE | 32BIT\n----------|-------|---------\nx86 | PE32 | 1\nAny CPU | PE32 | 0\nx64 | PE32+ | 0\n corflags Module.GetPEKind PortableExecutableKinds PE32Plus Required32Bit ILOnly"
},
{
"answer_id": 270549,
"author": "x0n",
"author_id": 6920,
"author_profile": "https://Stackoverflow.com/users/6920",
"pm_score": 9,
"selected": true,
"text": "System.Reflection.AssemblyName.GetAssemblyName(string assemblyFile)"
},
{
"answer_id": 1002800,
"author": "JoshL",
"author_id": 20625,
"author_profile": "https://Stackoverflow.com/users/20625",
"pm_score": 7,
"selected": false,
"text": "corflags MyAssembly.dll Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 3.5.21022.8\nCopyright (c) Microsoft Corporation. All rights reserved.\n\nVersion : v2.0.50727\nCLR Header: 2.5\nPE : PE32\nCorFlags : 3\nILONLY : 1\n32BIT : 1\nSigned : 0\n"
},
{
"answer_id": 9767750,
"author": "Jason",
"author_id": 1278235,
"author_profile": "https://Stackoverflow.com/users/1278235",
"pm_score": 5,
"selected": false,
"text": " public static ushort GetPEArchitecture(string pFilePath)\n {\n ushort architecture = 0;\n try\n {\n using (System.IO.FileStream fStream = new System.IO.FileStream(pFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))\n {\n using (System.IO.BinaryReader bReader = new System.IO.BinaryReader(fStream))\n {\n // Check the MZ signature\n if (bReader.ReadUInt16() == 23117)\n {\n // Seek to e_lfanew.\n fStream.Seek(0x3A, System.IO.SeekOrigin.Current);\n\n // Seek to the start of the NT header.\n fStream.Seek(bReader.ReadUInt32(), System.IO.SeekOrigin.Begin);\n\n if (bReader.ReadUInt32() == 17744) // Check the PE\\0\\0 signature.\n {\n // Seek past the file header,\n fStream.Seek(20, System.IO.SeekOrigin.Current);\n\n // Read the magic number of the optional header.\n architecture = bReader.ReadUInt16();\n }\n }\n }\n }\n }\n catch (Exception) { /* TODO: Any exception handling you want\n to do, personally I just take 0\n as a sign of failure */\n }\n\n // If architecture returns 0, there has been an error.\n return architecture;\n }\n}\n 0x10B - PE32 format.\n0x20B - PE32+ format.\n"
},
{
"answer_id": 19035620,
"author": "Morgan Mellor",
"author_id": 2820702,
"author_profile": "https://Stackoverflow.com/users/2820702",
"pm_score": 3,
"selected": false,
"text": "[TestMethod]\npublic void EnsureKWLLibrariesAreAll64Bit()\n{\n var assemblies = Assembly.GetExecutingAssembly().GetReferencedAssemblies().Where(x => x.FullName.StartsWith(\"YourCommonProjectName\")).ToArray();\n foreach (var assembly in assemblies)\n {\n var myAssemblyName = AssemblyName.GetAssemblyName(assembly.FullName.Split(',')[0] + \".dll\");\n Assert.AreEqual(ProcessorArchitecture.MSIL, myAssemblyName.ProcessorArchitecture);\n }\n}\n"
},
{
"answer_id": 36316170,
"author": "Eric Lease",
"author_id": 4342563,
"author_profile": "https://Stackoverflow.com/users/4342563",
"pm_score": 3,
"selected": false,
"text": "@echo off\n\necho.\necho Target architecture for all exes and dlls:\necho.\n\nREM For each exe and dll in this directory and all subdirectories...\nfor %%a in (.exe, .dll) do forfiles /s /m *%%a /c \"cmd /c echo @relpath\" > testfiles.txt\n\nfor /f %%b in (testfiles.txt) do (\n REM Dump corflags results to a text file\n corflags /nologo %%b > corflagsdeets.txt\n\n REM Parse the corflags results to look for key markers\n findstr /C:\"PE32+\">nul .\\corflagsdeets.txt && (\n REM `PE32+` indicates x64\n echo %%~b = x64\n ) || (\n REM pre-v8 Windows SDK listed only \"32BIT\" line item,\n REM newer versions list \"32BITREQ\" and \"32BITPREF\" line items\n findstr /C:\"32BITREQ : 0\">nul /C:\"32BIT : 0\" .\\corflagsdeets.txt && (\n REM `PE32` and NOT 32bit required indicates Any CPU\n echo %%~b = Any CPU\n ) || (\n REM `PE32` and 32bit required indicates x86\n echo %%~b = x86\n )\n )\n\n del corflagsdeets.txt\n)\n\ndel testfiles.txt\necho.\n"
},
{
"answer_id": 39852004,
"author": "Wernfried Domscheit",
"author_id": 3027266,
"author_profile": "https://Stackoverflow.com/users/3027266",
"pm_score": 1,
"selected": false,
"text": "sigcheck c:\\Windows\\winhlp32.exe\n Sigcheck v2.71 - File version and signature viewer\nCopyright (C) 2004-2018 Mark Russinovich\nSysinternals - www.sysinternals.com\n\nc:\\windows\\winhlp32.exe:\n Verified: Signed\n Signing date: 20:05 02.05.2022\n Publisher: Microsoft Windows\n Company: Microsoft Corporation\n Description: Windows Winhlp32 Stub\n Product: Microsoft® Windows® Operating System\n Prod version: 10.0.19041.1\n File version: 10.0.19041.1 (WinBuild.160101.0800)\n MachineType: 32-bit\n sigcheck -nobanner c:\\Windows\\HelpPane.exe\n c:\\windows\\HelpPane.exe:\n Verified: Signed\n Signing date: 00:42 23.04.2022\n Publisher: Microsoft Windows\n Company: Microsoft Corporation\n Description: Microsoft Help and Support\n Product: Microsoft® Windows® Operating System\n Prod version: 10.0.19041.1151\n File version: 10.0.19041.1151 (WinBuild.160101.0800)\n MachineType: 64-bit\n"
},
{
"answer_id": 45365087,
"author": "Ayush joshi",
"author_id": 2594972,
"author_profile": "https://Stackoverflow.com/users/2594972",
"pm_score": 2,
"selected": false,
"text": "dumpbin.exe /HEADERS <your DLL file path>\n FILE HEADER VALUE\n 14C machine (x86)\n 4 number of sections\n 5885AC36 time date stamp Mon Jan 23 12:39:42 2017\n 0 file pointer to symbol table\n 0 number of symbols\n E0 size of optional header\n 2102 characteristics\n Executable\n 32 bit word machine\n DLL\n dumpbin.exe /EXPORTS <PATH OF THE DLL FILE>\n"
},
{
"answer_id": 49516509,
"author": "BlackGad",
"author_id": 2310482,
"author_profile": "https://Stackoverflow.com/users/2310482",
"pm_score": 2,
"selected": false,
"text": "public static CompilationMode GetCompilationMode(this FileInfo info)\n{\n if (!info.Exists)\n throw new ArgumentException($\"{info.FullName} does not exist\");\n\n var intPtr = IntPtr.Zero;\n try\n {\n uint unmanagedBufferSize = 4096;\n intPtr = Marshal.AllocHGlobal((int)unmanagedBufferSize);\n\n using (var stream = File.Open(info.FullName, FileMode.Open, FileAccess.Read))\n {\n var bytes = new byte[unmanagedBufferSize];\n stream.Read(bytes, 0, bytes.Length);\n Marshal.Copy(bytes, 0, intPtr, bytes.Length);\n }\n\n // Check DOS header magic number\n if (Marshal.ReadInt16(intPtr) != 0x5a4d)\n return CompilationMode.Invalid;\n\n // This will get the address for the WinNT header\n var ntHeaderAddressOffset = Marshal.ReadInt32(intPtr + 60);\n\n // Check WinNT header signature\n var signature = Marshal.ReadInt32(intPtr + ntHeaderAddressOffset);\n if (signature != 0x4550)\n return CompilationMode.Invalid;\n\n // Determine file bitness by reading magic from IMAGE_OPTIONAL_HEADER\n var magic = Marshal.ReadInt16(intPtr + ntHeaderAddressOffset + 24);\n\n var result = CompilationMode.Invalid;\n uint clrHeaderSize;\n if (magic == 0x10b)\n {\n clrHeaderSize = (uint)Marshal.ReadInt32(intPtr + ntHeaderAddressOffset + 24 + 208 + 4);\n result |= CompilationMode.Bit32;\n }\n else if (magic == 0x20b)\n {\n clrHeaderSize = (uint)Marshal.ReadInt32(intPtr + ntHeaderAddressOffset + 24 + 224 + 4);\n result |= CompilationMode.Bit64;\n }\n else return CompilationMode.Invalid;\n\n result |= clrHeaderSize != 0\n ? CompilationMode.CLR\n : CompilationMode.Native;\n\n return result;\n }\n finally\n {\n if (intPtr != IntPtr.Zero)\n Marshal.FreeHGlobal(intPtr);\n }\n}\n [Flags]\npublic enum CompilationMode\n{\n Invalid = 0,\n Native = 0x1,\n CLR = Native << 1,\n Bit32 = CLR << 1,\n Bit64 = Bit32 << 1\n}\n"
},
{
"answer_id": 67100044,
"author": "Maxim",
"author_id": 3137536,
"author_profile": "https://Stackoverflow.com/users/3137536",
"pm_score": 0,
"selected": false,
"text": "// linq2db, Version=3.0.0.0, Culture=neutral, PublicKeyToken=e41013125f9e410a\n// Global type: <Module>\n// Architecture: AnyCPU (64-bit preferred)\n// Runtime: v4.0.30319\n// This assembly is signed with a strong name key.\n// This assembly was compiled using the /deterministic option.\n// Hash algorithm: SHA1\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/536/"
] |
270,541
|
<p>What algorithms could i use to determine common characters in a set of strings?</p>
<p>To make the example simple, I only care about 2+ characters in a row and if it shows up in 2 or more of the sample. For instance:</p>
<ol>
<li>0000abcde0000 </li>
<li>0000abcd00000 </li>
<li>000abc0000000</li>
<li>00abc000de000</li>
</ol>
<p>I'd like to know:</p>
<p>00 was used in 1,2,3,4<br>
000 was used in 1,2,3,4<br>
0000 was used in 1,2,3<br>
00000 was used in 2,3<br>
ab was used in 1,2,3,4<br>
abc was used in 1,2,3,4<br>
abcd was used in 1,2<br>
bc was used in 1,2,3,4<br>
bcd was used in 1,2<br>
cd was used in 1,2<br>
de was used in 1,4 </p>
|
[
{
"answer_id": 270638,
"author": "BCS",
"author_id": 1343,
"author_profile": "https://Stackoverflow.com/users/1343",
"pm_score": 2,
"selected": false,
"text": "abc\nabd\nabde\nacc\nbde\n a : 4\n b : 3\n c : 1\n d : 2\n e : 1\n c : 1\n c : 1\nb : 4\n d : 3\n e : 2\n c : 1\nc : 3\n c : 1\nd : 3\n e : 2\n"
},
{
"answer_id": 270880,
"author": "joel.neely",
"author_id": 3525,
"author_profile": "https://Stackoverflow.com/users/3525",
"pm_score": 3,
"selected": true,
"text": "O(m**2 * n) m n Occurrence commonOccurrences captureOccurrences captureOccurrences Occurrence commonOccurrences Occurrences \"00ab\" package com.stackoverflow.answers;\n\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.TreeSet;\n\npublic class CommonSubstringFinder {\n\n public static final int MINIMUM_SUBSTRING_LENGTH = 2;\n\n public static class Occurrence implements Comparable<Occurrence> {\n private final String value;\n private final Set<Integer> indices;\n public Occurrence(String value) {\n this.value = value == null ? \"\" : value;\n indices = new TreeSet<Integer>();\n }\n public String getValue() {\n return value;\n }\n public Set<Integer> getIndices() {\n return Collections.unmodifiableSet(indices);\n }\n public void occur(int index) {\n indices.add(index);\n }\n public String toString() {\n StringBuilder result = new StringBuilder();\n result.append('\"').append(value).append('\"');\n String separator = \": \";\n for (Integer i : indices) {\n result.append(separator).append(i);\n separator = \",\";\n }\n return result.toString();\n }\n public int compareTo(Occurrence that) {\n return this.value.compareTo(that.value);\n }\n }\n\n public static Set<Occurrence> commonOccurrences(String[] strings) {\n Map<String,Occurrence> work = new HashMap<String,Occurrence>();\n if (strings != null) {\n int index = 0;\n for (String string : strings) {\n if (string != null) {\n captureOccurrences(index, work, string);\n }\n ++index;\n }\n }\n Set<Occurrence> result = new TreeSet<Occurrence>();\n for (Occurrence occurrence : work.values()) {\n if (occurrence.indices.size() > 1) {\n result.add(occurrence);\n }\n }\n return result;\n }\n\n private static void captureOccurrences(int index, Map<String,Occurrence> work, String string) {\n final int maxLength = string.length();\n for (int i = 0; i < maxLength; ++i) {\n for (int j = i + MINIMUM_SUBSTRING_LENGTH; j < maxLength; ++j) {\n String partial = string.substring(i, j);\n Occurrence current = work.get(partial);\n if (current == null) {\n current = new Occurrence(partial);\n work.put(partial, current);\n }\n current.occur(index);\n }\n }\n }\n\n private static final String[] TEST_DATA = {\n \"0000abcde0000\",\n \"0000abcd00000\",\n \"000abc0000000\",\n \"00abc000de000\",\n };\n public static void main(String[] args) {\n Set<Occurrence> found = commonOccurrences(TEST_DATA);\n for (Occurrence occurrence : found) {\n System.out.println(occurrence);\n }\n }\n\n}\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270541",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16794/"
] |
270,542
|
<p>I use the Boost Test framework to unit test my C++ code and wondered if it is possible to test if a function will assert? Yes, sounds a bit strange but bear with me! Many of my functions check the input parameters upon entry, asserting if they are invalid, and it would be useful to test for this. For example:</p>
<pre><code>void MyFunction(int param)
{
assert(param > 0); // param cannot be less than 1
...
}
</code></pre>
<p>I would like to be able to do something like this:</p>
<pre><code>BOOST_CHECK_ASSERT(MyFunction(0), true);
BOOST_CHECK_ASSERT(MyFunction(-1), true);
BOOST_CHECK_ASSERT(MyFunction(1), false);
...
</code></pre>
<p>You can check for exceptions being thrown using Boost Test so I wondered if there was some assert magic too...</p>
|
[
{
"answer_id": 1150324,
"author": "legalize",
"author_id": 139855,
"author_profile": "https://Stackoverflow.com/users/139855",
"pm_score": 3,
"selected": false,
"text": "catch catch (...) catch (...) main WinMain"
},
{
"answer_id": 1772832,
"author": "Grafoid",
"author_id": 215570,
"author_profile": "https://Stackoverflow.com/users/215570",
"pm_score": 4,
"selected": false,
"text": "boost::execution_monitor <boost/test/execution_monitor.hpp> boost::execution_exception BOOST_REQUIRE_THROW #include <boost/test/unit_test.hpp>\n#include <boost/test/execution_monitor.hpp> // for execution_exception\n\nBOOST_AUTO_TEST_CASE(case_1)\n{\n BOOST_REQUIRE_THROW(function_w_failing_assert(),\n boost::execution_exception);\n}\n"
},
{
"answer_id": 6837339,
"author": "grokus",
"author_id": 203091,
"author_profile": "https://Stackoverflow.com/users/203091",
"pm_score": 2,
"selected": false,
"text": "#if GROKUS_TESTABLE\n#define GROKUS_ASSERT ... // exception\n#define GROKUS_CHECK_THROW BOOST_CHECK_THROW\n#else\n#define GROKUS_ASSERT ... // assert\n#define GROKUS_CHECK_THROW(statement, exception) {} // no-op\n#endif\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270542",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9236/"
] |
270,561
|
<p>Developing a website and just trying to get back into the swing of (clever) SQL queries etc, my mind had totally gone tonight!</p>
<p>There is a website <a href="http://www.ufindus.com/" rel="nofollow noreferrer">http://www.ufindus.com/</a> which has a textbox allowing you to enter either a place name or a postcode/zipcode. I am trying to do something similiar but I am rubbish at SQL - so how do you construct an SQL statement that could potentially look at 2 columns (i.e. place and postcode) because you can't query both fields for the same value e.g </p>
<pre><code>place = 'YORK' AND postcode = 'YORK'
</code></pre>
<p>or</p>
<pre><code>place = 'YO21 5EA' AND postcode = 'YO21 5EA'
</code></pre>
<p>so do you have to put some logic in to be intelligent enough to detect whether it looks like a place name or a postcode - that just seems too complicated to me!! Any help would be much appreciated.</p>
|
[
{
"answer_id": 270577,
"author": "Steven A. Lowe",
"author_id": 9345,
"author_profile": "https://Stackoverflow.com/users/9345",
"pm_score": 2,
"selected": false,
"text": "place = @textboxvalue OR post = @textboxvalue\n"
},
{
"answer_id": 271547,
"author": "Jørn Jensen",
"author_id": 34585,
"author_profile": "https://Stackoverflow.com/users/34585",
"pm_score": 0,
"selected": false,
"text": "\nselect @textboxstring = RTRIM(@textboxstring) + '%';\nselect postcode, postplace \nfrom postcode \nwhere postcode like @textboxstring or postplace like @textboxstring;\n like \nselect @textboxstring = RTRIM(@textboxstring) + '%';\nselect postcode, postplace \nfrom postcode \nwhere postcode = @textboxint or postplace like @textboxstring;\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5175/"
] |
270,592
|
<pre><code>class AbstractQuery {
virtual bool isCanBeExecuted()=0;
public:
AbstractQuery() {}
virtual bool Execute()=0;
};
class DropTableQuery: public AbstractQuery {
vector< std::pair< string, string> > QueryContent;
QueryValidate qv;
public:
explicit DropTableQuery(const string& qr): AbstractQuery(), qv(qr) {}
bool Execute();
};
</code></pre>
<p>Is it necessary to call base contructor in derived class constructor?</p>
|
[
{
"answer_id": 270599,
"author": "Evan Teran",
"author_id": 13430,
"author_profile": "https://Stackoverflow.com/users/13430",
"pm_score": 4,
"selected": true,
"text": "class MyInterface {\npublic:\n virtual ~MyInterface() {}\n virtual void execute() = 0;\n};\n MyInterface* iface = GetMeSomeThingThatSupportsInterface();\ndelete iface; // this is undefined behaviour if MyInterface doesn't have a virtual destructor\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270592",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28298/"
] |
270,598
|
<p>I've got an application that loads .so files as plugins at startup, using <code>dlopen()</code></p>
<p>The build environment is running on x86 hardware, but the application is being cross compiled for another platform.</p>
<p>It would be great if I could (as part of the automated build process) do a check to make sure that there aren't any unresolved symbols in a combination of the .so files and the application, without having to actually deploy the application.</p>
<p>Before I write a script to test symbols using the output of <code>nm</code>, I'm wondering if anyone knows of a utility that already does this?</p>
<hr>
<p>edit 1: changed the description slightly - I'm not just trying to test symbols in the .so, but rather in a combination of several .so's and the application itself - ie. after the application loaded all of the .so's whether there would still be unresolved symbols.</p>
<p>As has been suggested in answers (thanks Martin v. Löwis and tgamblin), <code>nm</code> will easily identify missing symbols in a single file but won't easily identify which of those symbols has been resolved in one of the other loaded modules.</p>
|
[
{
"answer_id": 270632,
"author": "Todd Gamblin",
"author_id": 9122,
"author_profile": "https://Stackoverflow.com/users/9122",
"pm_score": 1,
"selected": false,
"text": " --no-undefined\n Report unresolved symbol references from regular object files.\n This is done even if the linker is creating a non-symbolic shared \n library. The switch --[no-]allow-shlib-undefined controls the \n behaviour for reporting unresolved references found in shared\n libraries being linked in.\n\n --allow-shlib-undefined\n --no-allow-shlib-undefined\n Allows (the default) or disallows undefined symbols in shared \n libraries. This switch is similar to --no-undefined except\n that it determines the behaviour when the undefined symbols are\n in a shared library rather than a regular object file. It does \n not affect how undefined symbols in regular object files are \n handled.\n\n The reason that --allow-shlib-undefined is the default is that the \n shared library being specified at link time may not be the \n same as the one that is available at load time, so the symbols might \n actually be resolvable at load time. Plus there are some systems, \n (eg BeOS) where undefined symbols in shared libraries is normal. \n (The kernel patches them at load time to select which function is most\n appropriate for the current architecture. This is used for example to\n dynamically select an appropriate memset function). Apparently it is \n also normal for HPPA shared libraries to have undefined symbols.\n"
},
{
"answer_id": 688102,
"author": "Andrew Edgecombe",
"author_id": 11694,
"author_profile": "https://Stackoverflow.com/users/11694",
"pm_score": 1,
"selected": false,
"text": "nm nm readelf readelf dlopen()"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270598",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11694/"
] |
270,611
|
<p>Is it a good idea to store my SQL queries in a global resource file instead of having it in my codebehind? I know stored procedures would be a better solution but I don't have that luxury on this project. </p>
<p>I don't want queries all over my pages and thought a central repository would be a better idea.</p>
|
[
{
"answer_id": 270844,
"author": "Robert Paulson",
"author_id": 14033,
"author_profile": "https://Stackoverflow.com/users/14033",
"pm_score": 4,
"selected": true,
"text": "public static class SqlResource\n{\n private static Dictionary<string,SqlQuery> dictionary;\n\n public static void Initialize(string file)\n {\n List<SqlQuery> list;\n\n // deserialize the xml file\n using (StreamReader streamReader = new StreamReader(file))\n {\n XmlSerializer deserializer = new XmlSerializer(typeof(List<SqlQuery>));\n list = (List<SqlQuery>)deserializer.Deserialize(streamReader);\n }\n dictionary = new Dictionary<string,SqlQuery>();\n foreach(var item in list )\n {\n dictionary.Add(item.Name,item);\n }\n }\n public static SqlQuery GetQueryByName(string name)\n {\n SqlQuery query = dictionary[name];\n\n if( query == null )\n throw new ArgumentException(\"The query '\" + name + \"' is not valid.\");\n\n if( query.IsObsolete )\n {\n // TODO - log this.\n }\n return query;\n\n }\n}\n\npublic sealed class SqlQuery\n{\n [XmlAttributeAttribute(\"name\")]\n public bool Name { get; set; }\n\n [XmlElement(\"Sql\")]\n public bool Sql { get; set; }\n\n [XmlAttributeAttribute(\"obsolete\")]\n public bool IsObsolete { get; set; }\n\n [XmlIgnore]\n public TimeSpan Timeout { get; set;}\n\n /// <summary>\n /// Serialization only - XmlSerializer can't serialize normally\n /// </summary>\n [XmlAttribute(\"timeout\")]\n public string Timeout_String \n {\n get { return Timeout.ToString(); }\n set { Timeout = TimeSpan.Parse(value); } \n }\n}\n <?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ArrayOfSqlQuery xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n <SqlQuery name=\"EmployeeByEmployeeID\" timeout=\"00:00:30\" >\n <Sql>\nSELECT * From Employee WHERE EmployeeID = @T0 \n </Sql>\n </SqlQuery>\n <SqlQuery name=\"EmployeesForManager\" timeout=\"00:05:00\" obsolete=\"true\" >\n <Sql>\nSELECT * From Employee WHERE ManagerID = @T0 \n </Sql>\n </SqlQuery>\n</ArrayOfSqlQuery>\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270611",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18234/"
] |
270,612
|
<p>I am creating a chat using Ajax requests and I'm trying to get messages div to scroll to the bottom without much luck.</p>
<p>I am wrapping everything in this div:</p>
<pre><code>#scroll {
height:400px;
overflow:scroll;
}
</code></pre>
<p>Is there a way to keep it scrolled to the bottom by default using JS?</p>
<p>Is there a way to keep it scrolled to the bottom after an ajax request?</p>
|
[
{
"answer_id": 270628,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 12,
"selected": true,
"text": "var objDiv = document.getElementById(\"your_div\");\nobjDiv.scrollTop = objDiv.scrollHeight;\n"
},
{
"answer_id": 2664878,
"author": "andsien",
"author_id": 319963,
"author_profile": "https://Stackoverflow.com/users/319963",
"pm_score": 9,
"selected": false,
"text": "$(\"#mydiv\").scrollTop($(\"#mydiv\")[0].scrollHeight);\n"
},
{
"answer_id": 12391116,
"author": "DadViegas",
"author_id": 1354106,
"author_profile": "https://Stackoverflow.com/users/1354106",
"pm_score": 7,
"selected": false,
"text": "$('#DebugContainer').stop().animate({\n scrollTop: $('#DebugContainer')[0].scrollHeight\n}, 800);\n"
},
{
"answer_id": 21048661,
"author": "Akira Yamamoto",
"author_id": 475876,
"author_profile": "https://Stackoverflow.com/users/475876",
"pm_score": 5,
"selected": false,
"text": "var mydiv = $(\"#scroll\");\nmydiv.scrollTop(mydiv.prop(\"scrollHeight\"));\n"
},
{
"answer_id": 24139276,
"author": "Benny Neugebauer",
"author_id": 451634,
"author_profile": "https://Stackoverflow.com/users/451634",
"pm_score": 4,
"selected": false,
"text": "scrollHeight $('#scroll').scrollTop(1000000);\n"
},
{
"answer_id": 24555718,
"author": "Bruno Jennrich",
"author_id": 1557690,
"author_profile": "https://Stackoverflow.com/users/1557690",
"pm_score": 2,
"selected": false,
"text": "var objDiv = document.getElementById(id);\nvar doScroll=objDiv.scrollTop>=(objDiv.scrollHeight-objDiv.clientHeight); \n\n// add new content to div\n$('#' + id ).append(\"new line at end<br>\"); // this is jquery!\n\n// doScroll is true, if we the bottom line is already visible\nif( doScroll) objDiv.scrollTop = objDiv.scrollHeight;\n"
},
{
"answer_id": 25426631,
"author": "mylescc",
"author_id": 1863795,
"author_profile": "https://Stackoverflow.com/users/1863795",
"pm_score": 2,
"selected": false,
"text": "$timeout(function(){\n var messageThread = document.getElementById('message-thread-div-id');\n messageThread.scrollTop = messageThread.scrollHeight;\n},0)\n"
},
{
"answer_id": 26293764,
"author": "tnt-rox",
"author_id": 913620,
"author_profile": "https://Stackoverflow.com/users/913620",
"pm_score": 6,
"selected": false,
"text": "this.scrollIntoView(false);\n"
},
{
"answer_id": 27025520,
"author": "Muhammad Soliman",
"author_id": 1334561,
"author_profile": "https://Stackoverflow.com/users/1334561",
"pm_score": 3,
"selected": false,
"text": "var myDiv = $(\"#div_id\").get(0);\nmyDiv.scrollTop = myDiv.scrollHeight;\n var myDiv = $(\"#div_id\").get(0);\nmyDiv.animate({\n scrollTop: myDiv.scrollHeight\n }, 500);\n"
},
{
"answer_id": 31979138,
"author": "Navaneeth",
"author_id": 4255204,
"author_profile": "https://Stackoverflow.com/users/4255204",
"pm_score": 2,
"selected": false,
"text": "$('html, body').animate({scrollTop:$(document).height()}, 1000);\n"
},
{
"answer_id": 32592634,
"author": "devonj",
"author_id": 4736349,
"author_profile": "https://Stackoverflow.com/users/4736349",
"pm_score": 3,
"selected": false,
"text": "angular.module('myApp').controller('myController', ['$scope', '$document',\n function($scope, $document) {\n\n var overflowScrollElement = $document[0].getElementById('your_overflow_scroll_div');\n overflowScrollElement[0].scrollTop = overflowScrollElement[0].scrollHeight;\n\n }\n]);\n"
},
{
"answer_id": 33031853,
"author": "Benkinass",
"author_id": 1348531,
"author_profile": "https://Stackoverflow.com/users/1348531",
"pm_score": 3,
"selected": false,
"text": "Mutation Observers var scrollContainer = document.getElementById(\"myId\");\n\n// Define the Mutation Observer\nvar observer = new MutationObserver(function(mutations) {\n\n // Compute sum of the heights of added Nodes\n var newNodesHeight = mutations.reduce(function(sum, mutation) {\n return sum + [].slice.call(mutation.addedNodes)\n .map(function (node) { return node.scrollHeight || 0; })\n .reduce(function(sum, height) {return sum + height});\n }, 0);\n\n // Scroll to bottom if it was already scrolled to bottom\n if (scrollContainer.clientHeight + scrollContainer.scrollTop + newNodesHeight + 10 >= scrollContainer.scrollHeight) {\n scrollContainer.scrollTop = scrollContainer.scrollHeight;\n }\n\n});\n\n// Observe the DOM Element\nobserver.observe(scrollContainer, {childList: true});\n"
},
{
"answer_id": 33193694,
"author": "Tho",
"author_id": 875775,
"author_profile": "https://Stackoverflow.com/users/875775",
"pm_score": 7,
"selected": false,
"text": "const scrollToBottom = (id) => {\n const element = document.getElementById(id);\n element.scrollTop = element.scrollHeight;\n}\n const scrollSmoothlyToBottom = (id) => {\n const element = $(`#${id}`);\n element.animate({\n scrollTop: element.prop(\"scrollHeight\")\n }, 500);\n}\n"
},
{
"answer_id": 33398636,
"author": "John Dunne",
"author_id": 1351403,
"author_profile": "https://Stackoverflow.com/users/1351403",
"pm_score": 2,
"selected": false,
"text": "html,body $(\"html,body\").animate({scrollTop:$(\"#div-id\")[0].offsetTop}, 1000);"
},
{
"answer_id": 38443916,
"author": "Lay Leangsros",
"author_id": 4466122,
"author_profile": "https://Stackoverflow.com/users/4466122",
"pm_score": 3,
"selected": false,
"text": "var scroll = document.getElementById('messages');\n scroll.scrollTop = scroll.scrollHeight;\n scroll.animate({scrollTop: scroll.scrollHeight});\n .messages\n {\n height: 100%;\n overflow: auto;\n }\n"
},
{
"answer_id": 41108721,
"author": "BrianLegg",
"author_id": 2921935,
"author_profile": "https://Stackoverflow.com/users/2921935",
"pm_score": 0,
"selected": false,
"text": "$(\"#html, body\").stop().animate({\n scrollTop: $(\"#last-message\").offset().top\n}, 2000);\n"
},
{
"answer_id": 46915549,
"author": "Barath Sankar",
"author_id": 6801721,
"author_profile": "https://Stackoverflow.com/users/6801721",
"pm_score": 3,
"selected": false,
"text": "document.getElementById('messages').scrollIntoView(false);"
},
{
"answer_id": 46958777,
"author": "aravk33",
"author_id": 8532064,
"author_profile": "https://Stackoverflow.com/users/8532064",
"pm_score": 1,
"selected": false,
"text": "scroll to var myDiv = document.getElementById(\"myDiv\");\nwindow.scrollTo(0, myDiv.innerHeight);\n"
},
{
"answer_id": 54501285,
"author": "mjaque",
"author_id": 1857487,
"author_profile": "https://Stackoverflow.com/users/1857487",
"pm_score": 2,
"selected": false,
"text": "myDiv.scrollTop = myDiv.lastChild.offsetTop\n"
},
{
"answer_id": 55902894,
"author": "adl",
"author_id": 1112483,
"author_profile": "https://Stackoverflow.com/users/1112483",
"pm_score": 5,
"selected": false,
"text": "document.getElementById('messages').scrollIntoView({ behavior: 'smooth', block: 'end' });"
},
{
"answer_id": 56880885,
"author": "Mahdi Bagheri",
"author_id": 8515569,
"author_profile": "https://Stackoverflow.com/users/8515569",
"pm_score": -1,
"selected": false,
"text": "var element= $('element');\nvar maxScrollTop = element[0].scrollHeight - element.outerHeight();\nelement.scrollTop(maxScrollTop);\n var element = $(element);\n var maxScrollTop = element[0].scrollHeight - element.outerHeight();\n element.on('scroll', function() {\n if ( element.scrollTop() >= maxScrollTop ) {\n alert('scroll to bottom');\n }\n });\n"
},
{
"answer_id": 58219558,
"author": "veritas",
"author_id": 2181576,
"author_profile": "https://Stackoverflow.com/users/2181576",
"pm_score": -1,
"selected": false,
"text": "let lastChatBox = document.querySelectorAll('.chatContentBox'); \nlastChatBox = lastChatBox[lastChatBox.length-1]; \nlastChatBox.scrollIntoView(); \n"
},
{
"answer_id": 59604580,
"author": "SeekLoad",
"author_id": 7371886,
"author_profile": "https://Stackoverflow.com/users/7371886",
"pm_score": -1,
"selected": false,
"text": "window.scrollTo(x=0,y=150);\n"
},
{
"answer_id": 60104604,
"author": "user2341537",
"author_id": 2341537,
"author_profile": "https://Stackoverflow.com/users/2341537",
"pm_score": -1,
"selected": false,
"text": "const element = this.shadowRoot.getElementById('my-scrollable-div')\nelement.scrollTop = element.scrollHeight\n"
},
{
"answer_id": 60254536,
"author": "moreirapontocom",
"author_id": 1202416,
"author_profile": "https://Stackoverflow.com/users/1202416",
"pm_score": 1,
"selected": false,
"text": "postMessage() {\n // post functions here\n let history = document.getElementById('history')\n let interval \n interval = setInterval(function() {\n history.scrollTop = history.scrollHeight\n clearInterval(interval)\n }, 1)\n}\n"
},
{
"answer_id": 60606751,
"author": "Anatol",
"author_id": 11804213,
"author_profile": "https://Stackoverflow.com/users/11804213",
"pm_score": 3,
"selected": false,
"text": "var element = document.getElementById(\"scroll\");\nelement.scrollIntoView();\n"
},
{
"answer_id": 61717100,
"author": "ngShravil.py",
"author_id": 6635464,
"author_profile": "https://Stackoverflow.com/users/6635464",
"pm_score": 3,
"selected": false,
"text": "setTimeOut() setTimeout(() => {\n var objDiv = document.getElementById('div_id');\n objDiv.scrollTop = objDiv.scrollHeight\n}, 0)\n"
},
{
"answer_id": 62789931,
"author": "Mike Taverne",
"author_id": 763546,
"author_profile": "https://Stackoverflow.com/users/763546",
"pm_score": 2,
"selected": false,
"text": "//get the div that contains all the messages\nlet div = document.getElementById('message-container');\n\n//make the last element (a message) to scroll into view, smoothly!\ndiv.lastElementChild.scrollIntoView({ behavior: 'smooth' });\n"
},
{
"answer_id": 64230698,
"author": "jocassid",
"author_id": 3335674,
"author_profile": "https://Stackoverflow.com/users/3335674",
"pm_score": 0,
"selected": false,
"text": "function scrollTo(event){\n // In my proof of concept, I had a few <button>s with value \n // attributes containing strings with id selector expressions\n // like \"#item1\".\n let selectItem = $($(event.target).attr('value'));\n let selectedDivTop = selectItem.offset().top;\n\n let scrollingDiv = selectItem.parent();\n\n let firstItem = scrollingDiv.children('div').first();\n let firstItemTop = firstItem.offset().top;\n\n let newScrollValue = selectedDivTop - firstItemTop;\n scrollingDiv.scrollTop(newScrollValue);\n } <div id=\"scrolling\" style=\"height: 2rem; overflow-y: scroll\">\n <div id=\"item1\">One</div>\n <div id=\"item2\">Two</div>\n <div id=\"item3\">Three</div>\n <div id=\"item4\">Four</div>\n <div id=\"item5\">Five</div>\n</div>"
},
{
"answer_id": 64701883,
"author": "Adonis Gaitatzis",
"author_id": 5671180,
"author_profile": "https://Stackoverflow.com/users/5671180",
"pm_score": 1,
"selected": false,
"text": "function scrollToBottom() {\n const scrollContainer = document.getElementById('container');\n scrollContainer.scrollTo({\n top: scrollContainer.scrollHeight,\n left: 0,\n behavior: 'smooth'\n });\n}\n\n// initialize dummy content\nconst scrollContainer = document.getElementById('container');\nconst numCards = 100;\nlet contentInnerHtml = '';\nfor (let i=0; i<numCards; i++) {\n contentInnerHtml += `<div class=\"card mb-2\"><div class=\"card-body\">Card ${i + 1}</div></div>`;\n}\nscrollContainer.innerHTML = contentInnerHtml; .overflow-y-scroll {\n overflow-y: scroll;\n} <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css\" rel=\"stylesheet\"/>\n\n<div class=\"d-flex flex-column vh-100\">\n <div id=\"container\" class=\"overflow-y-scroll flex-grow-1\"></div>\n <div>\n <button class=\"btn btn-primary\" onclick=\"scrollToBottom()\">Scroll to bottom</button>\n </div>\n</div>"
},
{
"answer_id": 65371198,
"author": "Ahmet Şimşek",
"author_id": 3986712,
"author_profile": "https://Stackoverflow.com/users/3986712",
"pm_score": 5,
"selected": false,
"text": "function scrollToBottom(element) {\n element.scroll({ top: element.scrollHeight, behavior: 'smooth' });\n}\n"
},
{
"answer_id": 68585424,
"author": "Spankied",
"author_id": 8723748,
"author_profile": "https://Stackoverflow.com/users/8723748",
"pm_score": 1,
"selected": false,
"text": ".scroll-container {\n overflow-anchor: none;\n}\n"
},
{
"answer_id": 71930402,
"author": "Marcio Duarte",
"author_id": 2394994,
"author_profile": "https://Stackoverflow.com/users/2394994",
"pm_score": 3,
"selected": false,
"text": " .wrapper > div {\n background-color: white;\n border-radius: 5px;\n padding: 5px 10px;\n text-align: center;\n font-family: system-ui, sans-serif;\n }\n\n .wrapper {\n display: flex;\n padding: 5px;\n background-color: #ccc;\n border-radius: 5px;\n flex-direction: column;\n gap: 5px;\n margin: 10px;\n max-height: 150px;\n\n /* Control snap from here */\n overflow-y: auto;\n overscroll-behavior-y: contain;\n scroll-snap-type: y mandatory;\n }\n\n .wrapper > div:last-child {\n scroll-snap-align: start;\n } <div class=\"wrapper\">\n <div>01</div>\n <div>02</div>\n <div>03</div>\n <div>04</div>\n <div>05</div>\n <div>06</div>\n <div>07</div>\n <div>08</div>\n <div>09</div>\n <div>10</div>\n</div>"
},
{
"answer_id": 72136483,
"author": "PanDe",
"author_id": 3964056,
"author_profile": "https://Stackoverflow.com/users/3964056",
"pm_score": 2,
"selected": false,
"text": "Here is a working example. https://codepen.io/jimbol/pen/YVJzBg\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10258/"
] |
270,623
|
<p>I can use VS08's MFC/ActiveX template to create a C++ ActiveX object that I can load into a HTML page and script with Javascript. But I can't figure out how to create an interface that allows me to call custom methods on my component with Javascript.</p>
<p>Could you please tell me how to accomplish that? I have spent over two hours on google with no luck.</p>
<p>Thanks.</p>
|
[
{
"answer_id": 301687,
"author": "korona",
"author_id": 25731,
"author_profile": "https://Stackoverflow.com/users/25731",
"pm_score": 1,
"selected": false,
"text": "<html> \n<body> \n<object height=\"0\" width=\"0\" id=\"myControl\" classid=\"CLSID:AC12D6F8-AEB7-4935-B3C9-0E4FB6CF7FB1\" type=\"application/x-oleobject\">\n</object>\n<script>\n var activexObj = document.getElementById('myControl');\n if(activexObj != null)\n {\n var result = myControl.myMethod();\n document.write(\"Result: \" + result + \"<br/>\");\n }\n else\n {\n document.write(\"ActiveX component not found!<br/>\");\n }\n</script>\n</body>\n</html>\n"
},
{
"answer_id": 832351,
"author": "Adam A",
"author_id": 37685,
"author_profile": "https://Stackoverflow.com/users/37685",
"pm_score": 0,
"selected": false,
"text": "afx_msg void AboutBox();\n\nDECLARE_DISPATCH_MAP()\n // Dispatch map\n\nBEGIN_DISPATCH_MAP(CActiveXOutlookCtrl, COleControl)\n DISP_FUNCTION_ID(yourCtrl, \"AboutBox\", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)\nEND_DISPATCH_MAP()\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270623",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
270,630
|
<p>I am an upper level Software Engineering student currently in a Data Structures and Algorithms class. Our professor wants us to write a program using the List structure found in the C++ STL. I have been trying to use C# more and more, and was wondering if the ArrayList structure in .NET is a good substitute for the STL List implementation. </p>
|
[
{
"answer_id": 270641,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": true,
"text": "List<T> ArrayList"
},
{
"answer_id": 270642,
"author": "Tamas Czinege",
"author_id": 8954,
"author_profile": "https://Stackoverflow.com/users/8954",
"pm_score": 0,
"selected": false,
"text": "List<int> myList = new List<int>();\nmyList.Add(1);\nmyList.Add(2);\nSystem.Console.WriteLine(myList[0]);\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
270,648
|
<p>How do you invoke a tkinter <code>event</code> from a separate object? </p>
<p>I'm looking for something like wxWidgets <code>wx.CallAfter</code>. For example, If I create an object, and pass to it my <code>Tk</code> root instance, and then try to call a method of that root window from my object, my app locks up.</p>
<p>The best I can come up with is to use the the <code>after</code> method and check the status from my separate object, but that seems wasteful.</p>
|
[
{
"answer_id": 276069,
"author": "Bryan Oakley",
"author_id": 7432,
"author_profile": "https://Stackoverflow.com/users/7432",
"pm_score": 6,
"selected": true,
"text": "event_generate from tkinter import *\n\ndef doFoo(*args):\n print(\"Hello, world\")\n\nroot = Tk()\nroot.bind(\"<<Foo>>\", doFoo)\n\n# some time later, inject the \"<<Foo>>\" virtual event at the\n# tail of the event queue\nroot.event_generate(\"<<Foo>>\", when=\"tail\")\n event_generate from tkinter import *\n\nclass myClass:\n def __init__(self, root):\n print(\"root background is %s\" % root.cget(\"background\"))\n\nroot = Tk()\nnewObj = myClass(root)\n"
},
{
"answer_id": 36778730,
"author": "user110954",
"author_id": 2787591,
"author_profile": "https://Stackoverflow.com/users/2787591",
"pm_score": 3,
"selected": false,
"text": "w.event_generate(sequence, **kw)"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16363/"
] |
270,651
|
<p>I recently found a log statement in my projects codebase that says
"here i am with search parameter==>===========11/30/2008===1====00:00 AM"</p>
<p>what guidelines do you adhere to for writing good log messages in an application?</p>
|
[
{
"answer_id": 270687,
"author": "madlep",
"author_id": 14160,
"author_profile": "https://Stackoverflow.com/users/14160",
"pm_score": 3,
"selected": false,
"text": "LOGGER.debug(\"The variable was \" + myVariable + \" and we are doing \" + foo);\n if (LOGGER.isDebugEnabled()) {\n LOGGER.debug(\"put your debug statement here \" + foo + \" and \" + bar);\n}\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270651",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1129162/"
] |
270,658
|
<p>I'm looking at building basic CMS functionality into our web product and am researching tips and design ideas for versioning content. I'm specifically looking for database schemas in use today.</p>
<p>What are you using for content versioning? What patterns apply if you have different types of content that need versions stored? How is question versioning handled on Stack Overflow?</p>
<p>Thanks</p>
|
[
{
"answer_id": 270803,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 2,
"selected": false,
"text": "node node_revision\n---- -------------\nnid* vid*\nvid nid\n... body\n ...\n vid node_revision"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270658",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2656/"
] |
270,672
|
<p>Is there anyway to use unicode strings (most probably in UTF-8, but could be any encoding) in PostScript?</p>
<p>So far, i've been using this function to transforms fonts to Latin1 encoding:</p>
<pre><code>/latinize {
findfont
dup length dict begin
{ 1 index /FID ne {def}{pop pop} ifelse }forall
/Encoding ISOLatin1Encoding def
currentdict
end
definefont pop
}bind def
/HelveLat /Helvetica latinize
/HelveLatbold /Helvetica-Bold latinize
</code></pre>
<p>but i really don't like it.</p>
|
[
{
"answer_id": 12524359,
"author": "luser droog",
"author_id": 733077,
"author_profile": "https://Stackoverflow.com/users/733077",
"pm_score": 2,
"selected": false,
"text": "show OPFN_ void show(state *st, object s) {\n char str[s.u.c.n+1];\n memcpy(str, STR(s), s.u.c.n); str[s.u.c.n] = '\\0';\n //printf(\"showing (%s)\\n\", str);\n if (st->cr) {\n cairo_show_text(st->cr, str);\n cairo_surface_flush(st->surface);\n XFlush(st->dis);\n }\n}\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11649/"
] |
270,674
|
<p>I've generated a pdf using iTextSharp and I can preview it very well in ASP.Net but I need to send it directly to printer without a preview. I want the user to click the print button and automatically the document prints.</p>
<p>I know that a page can be sent directly to printer using the javascript window.print() but I don't know how to make it for a PDF.</p>
<p>Edit: it is not embedded, I generate it like this;</p>
<pre><code> ...
FileStream stream = new FileStream(Request.PhysicalApplicationPath + "~1.pdf", FileMode.Create);
Document pdf = new Document(PageSize.LETTER);
PdfWriter writer = PdfWriter.GetInstance(pdf, stream);
pdf.Open();
pdf.Add(new Paragraph(member.ToString()));
pdf.Close();
Response.Redirect("~1.pdf");
...
</code></pre>
<p>And here I am.</p>
|
[
{
"answer_id": 270733,
"author": "Stefan",
"author_id": 19307,
"author_profile": "https://Stackoverflow.com/users/19307",
"pm_score": 1,
"selected": false,
"text": "var x = document.getElementById(\"mypdfembeddobject\"); \nx.click();\nx.setActive();\nx.focus();\nx.print();\n"
},
{
"answer_id": 270759,
"author": "Stefan",
"author_id": 19307,
"author_profile": "https://Stackoverflow.com/users/19307",
"pm_score": 0,
"selected": false,
"text": "<link ref=\"mypdf\" media=\"print\" href=\"mypdf.pdf\">\n"
},
{
"answer_id": 270848,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "var pp = this.getPrintParams();\npp.interactive = pp.constants.interactionLevel.automatic;\nthis.print(pp);\n"
},
{
"answer_id": 271257,
"author": "Nelson Miranda",
"author_id": 1130097,
"author_profile": "https://Stackoverflow.com/users/1130097",
"pm_score": 3,
"selected": false,
"text": "Document pdf = new Document(PageSize.LETTER);\nPdfWriter writer = PdfWriter.GetInstance(pdf, \nnew FileStream(Request.PhysicalApplicationPath + \"~1.pdf\", FileMode.Create));\npdf.Open();\n\n//This action leads directly to printer dialogue\nPdfAction jAction = PdfAction.JavaScript(\"this.print(true);\\r\", writer);\nwriter.AddJavaScript(jAction);\n\npdf.Add(new Paragraph(\"My first PDF on line\"));\npdf.Close();\n\n//Open the pdf in the frame\nframe1.Attributes[\"src\"] = \"~1.pdf\";\n"
},
{
"answer_id": 6749843,
"author": "frenchone",
"author_id": 461581,
"author_profile": "https://Stackoverflow.com/users/461581",
"pm_score": 1,
"selected": false,
"text": "PdfDocument document = new PdfDocument();\nPdfPage page = document.AddPage(); \nXGraphics gfx = XGraphics.FromPdfPage(page); \nXFont font = new XFont(\"Verdana\", 20, XFontStyle.BoldItalic); \n// Draw the text \ngfx.DrawString(\"Hello, World!\", font, XBrushes.Black, \n new XRect(0, 0, page.Width, page.Height), \n XStringFormats.Center); \n\n// real stuff starts here\n\n// current version of pdfsharp doesn't support actions \n// http://www.pdfsharp.net/wiki/WorkOnPdfObjects-sample.ashx\n// so we got to get close to the metal see chapter 12.6.4 of \n// http://partners.adobe.com/public/developer/pdf/index_reference.html\nPdfDictionary dict = new PdfDictionary(document); // \ndict.Elements[\"/S\"] = new PdfName(\"/JavaScript\"); // \ndict.Elements[\"/JS\"] = new PdfString(\"this.print(true);\\r\");\ndocument.Internals.AddObject(dict);\ndocument.Internals.Catalog.Elements[\"/OpenAction\"] = \n PdfInternals.GetReference(dict);\ndocument.Save(Server.MapPath(\"2.pdf\"));\nframe1.Attributes[\"src\"] = \"2.pdf\"; \n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270674",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1130097/"
] |
270,677
|
<p>How do I access specific sections of man pages?</p>
|
[
{
"answer_id": 270694,
"author": "Jason Coco",
"author_id": 34218,
"author_profile": "https://Stackoverflow.com/users/34218",
"pm_score": 5,
"selected": true,
"text": "man 3 sysctl\n man 8 sysctl\n"
},
{
"answer_id": 270718,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 2,
"selected": false,
"text": "man -a topic\n printf"
},
{
"answer_id": 270727,
"author": "Rob Wells",
"author_id": 2974,
"author_profile": "https://Stackoverflow.com/users/2974",
"pm_score": 0,
"selected": false,
"text": "man -s 2 read\n man intro\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270677",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30924/"
] |
270,695
|
<p>Working with an Oracle 9i database from an ASP.NET 2.0 (VB) application using OLEDB. Is there a way to have an insert statement return a value? I have a sequence set up to number entries as they go into the database, but I need that value to come back after the insert so I can do some manipulation to the set I just entered in the code-behind VB.</p>
|
[
{
"answer_id": 270726,
"author": "jishi",
"author_id": 33663,
"author_profile": "https://Stackoverflow.com/users/33663",
"pm_score": 2,
"selected": false,
"text": "last_insert_id()"
},
{
"answer_id": 270901,
"author": "Mark Stock",
"author_id": 19737,
"author_profile": "https://Stackoverflow.com/users/19737",
"pm_score": 0,
"selected": false,
"text": "SELECT my_seq.nextval FROM dual\n INSERT ...\nINSERT ...\n"
},
{
"answer_id": 271669,
"author": "Tony Andrews",
"author_id": 18747,
"author_profile": "https://Stackoverflow.com/users/18747",
"pm_score": 4,
"selected": true,
"text": "INSERT INTO emp (empno, ename) VALUES (emp_seq.NEXTVAL, 'ANDREWS')\nRETURNING empno INTO :variable;\n INSERT INTO emp (empno, ename) VALUES (emp_seq.NEXTVAL, 'ANDREWS');\nSELECT emp_seq.CURRVAL INTO :variable FROM DUAL;\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270695",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12545/"
] |
270,703
|
<p>Our company is looking to integrate invoices into a new system we are developing.</p>
<p>We require a solution to create a layout of the invoice and then convert to pdf.</p>
<p>We have considered just laying out the invoice in html/css then converting to pdf.
We have also considered using SVG->PDf conversion.</p>
<p>Both of these solutions integrate well into our existing templating language used for our web application.</p>
<p>Historically we have been a Microsoft based business and used Crystal Reports for such a task but we are looking for an open source Linux solution for this project.</p>
<p>Does any one have any suggestions of an approach or technology we could use for such a task?</p>
|
[
{
"answer_id": 270723,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 3,
"selected": false,
"text": "ps2pdf"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270703",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35293/"
] |
270,708
|
<p>I have a char array buffer that I am using to store characters that the user will input one by one. My code below works but has a few glitches that I can't figure out:</p>
<ol>
<li>when I execute a printf to see what's in Buffer, it does fill up but I get garbage characters at the end</li>
<li>it won't stop at 8 characters despite being declared as char Buffer[8];</li>
</ol>
<p>Can somebody please explain to me what is going on and perhaps how I could fix this? Thanks.</p>
<pre><code>char Buffer[8]; //holds the byte stream
int i=0;
if (/* user input event has occurred */)
{
Buffer[i] = charInput;
i++;
// Display a response to input
printf("Buffer is %s!\n", Buffer);
}
</code></pre>
<p>Output:</p>
<pre>
tagBuffer is 1┬┬w!
tagBuffer is 12┬w!
tagBuffer is 123w!
tagBuffer is 1234!
tagBuffer is 12345!
tagBuffer is 123456=!
tagBuffer is 1234567!
tagBuffer is 12345678!</pre>
<p>tagBuffer is 123456789!</p>
|
[
{
"answer_id": 270713,
"author": "Toon Krijthe",
"author_id": 18061,
"author_profile": "https://Stackoverflow.com/users/18061",
"pm_score": 6,
"selected": true,
"text": "\\0 \\0"
},
{
"answer_id": 270719,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 3,
"selected": false,
"text": "char Buffer[9]; //holds the byte stream\nint i=0;\n\nif( //user input event has occured ) \n{\n Buffer[i] = charInput;\n i++;\n\n Buffer[i] = 0; // You can also assign the char '\\0' to it to get the same result.\n\n // Display a response to input\n printf(\"Buffer is %s!\\n\", Buffer);\n\n}\n"
},
{
"answer_id": 270730,
"author": "Brian",
"author_id": 18192,
"author_profile": "https://Stackoverflow.com/users/18192",
"pm_score": -1,
"selected": false,
"text": "stringstream"
},
{
"answer_id": 270743,
"author": "joel.neely",
"author_id": 3525,
"author_profile": "https://Stackoverflow.com/users/3525",
"pm_score": 2,
"selected": false,
"text": "#define DATA_LENGTH 8\n#define BUFFER_LENGTH (DATA_LENGTH + 1)\n\nchar Buffer[BUFFER_LENGTH]; //holds the byte stream\nint charPos=0; //index to next character position to fill\n\nwhile (charPos <= DATA_LENGTH ) { //user input event has occured\n Buffer[i] = charInput;\n\n Buffer[i+1] = '\\0';\n\n // Display a response to input\n printf(\"Buffer is %s!\\n\", Buffer);\n\n i++; \n\n}\n"
},
{
"answer_id": 271377,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 0,
"selected": false,
"text": "char Buffer[8]; //holds the byte stream\nint i = 0;\n\nwhile (i < sizeof(Buffer) && (charInput = get_the_users_character()) != EOF)\n{\n Buffer[i] = charInput;\n i++;\n\n // Display a response to input\n printf(\"Buffer is %.*s!\\n\", i, Buffer);\n}\n while if '\\0' sizeof(Buffer) - 1"
},
{
"answer_id": 41102124,
"author": "Mani Kanth",
"author_id": 6355827,
"author_profile": "https://Stackoverflow.com/users/6355827",
"pm_score": 0,
"selected": false,
"text": "Buffer 'T' 'T' 'W' '\\0' '\\0' '=' '\\0' '\\0' '\\0' '\\0' '\\0'"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270708",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28462/"
] |
270,724
|
<p>I'm checking out the Delphi 2009 Trial, but run into problems with the generics stuff right away.</p>
<p>The following code does not compile, and I haven't the slightest idea why it's giving me E2015 for the Equals() method:</p>
<pre><code>type
TPrimaryKey<T> = class(TObject)
strict private
fValue: T;
public
constructor Create(AValue: T);
function Equals(Obj: TObject): boolean; override;
function GetValue: T;
end;
constructor TPrimaryKey<T>.Create(AValue: T);
begin
inherited Create;
fValue := AValue;
end;
function TPrimaryKey<T>.Equals(Obj: TObject): boolean;
begin
Result := (Obj <> nil) and (Obj is TPrimaryKey<T>)
and (TPrimaryKey<T>(Obj).GetValue = fValue);
end;
function TPrimaryKey<T>.GetValue: T;
begin
Result := fValue;
end;
</code></pre>
<p>Why does the compiler think that fValue and the result of GetValue() can not be compared?</p>
|
[
{
"answer_id": 270789,
"author": "Angus Glashier",
"author_id": 35063,
"author_profile": "https://Stackoverflow.com/users/35063",
"pm_score": 2,
"selected": false,
"text": "TPrimaryKey<T: class> = class(TObject)\n"
},
{
"answer_id": 270814,
"author": "Toon Krijthe",
"author_id": 18061,
"author_profile": "https://Stackoverflow.com/users/18061",
"pm_score": 1,
"selected": false,
"text": "type\n TPrimaryKey<T> = class(TObject)\n public\n type\n TCompare<T1> = reference to function(const A1, A2: TPrimaryKey<T1>): Boolean;\n private\n fValue: T;\n fCompare : TCompare<T>;\n public\n constructor Create(AValue: T; ACompare: TCompare<T>);\n function Equals(Obj: TPrimaryKey<T>): Boolean; reintroduce;\n function GetValue: T;\n function CreateNew(const AValue: T): TPrimaryKey<T>;\n\n end;\n\nconstructor TPrimaryKey<T>.Create(AValue: T; ACompare: TCompare<T>);\nbegin\n inherited Create;\n fValue := AValue;\n fCompare := ACompare;\nend;\n\nfunction TPrimaryKey<T>.Equals(Obj: TPrimaryKey<T>): Boolean;\nbegin\n Result := FCompare(self, Obj);\nend;\n\nfunction TPrimaryKey<T>.GetValue: T;\nbegin\n Result := fValue;\nend;\n\nfunction TPrimaryKey<T>.CreateNew(const AValue: T): TPrimaryKey<T>;\nbegin\n Result := TPrimaryKey<T>.Create(AValue, FCompare);\nend;\n var\n p1, p2 : TPrimaryKey<Integer>;\nbegin\n p1 := TPrimaryKey<Integer>.Create(10,\n function(const A1, A2: TPrimaryKey<Integer>): Boolean\n begin\n Result := (A1<>nil) and (A2<>nil) and (A1.GetValue=A2.GetValue);\n end);\n p2 := p1.CreateNew(10);\n\n p1.Equals(p2);\nend;\n"
},
{
"answer_id": 270837,
"author": "Barry Kelly",
"author_id": 3712,
"author_profile": "https://Stackoverflow.com/users/3712",
"pm_score": 4,
"selected": true,
"text": "TEqualityComparer<T>.Default.Equals(x, y)\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30568/"
] |
270,737
|
<p>In Joel's article for Inc. entitled <a href="http://www.inc.com/magazine/20081101/how-hard-could-it-be-the-unproven-path.html" rel="nofollow noreferrer">How Hard Could It Be?: The Unproven Path</a>, he wrote:</p>
<blockquote>
<p>...it turns out that Jeff and his
programmers were so good that they
built a site that could serve 80,000
visitors a day (roughly 755,000 page
views)</p>
</blockquote>
<p>How would I go about figuring out the maximum load my server(s) can handle?</p>
|
[
{
"answer_id": 270742,
"author": "Jasper Bekkers",
"author_id": 31486,
"author_profile": "https://Stackoverflow.com/users/31486",
"pm_score": 1,
"selected": false,
"text": "ab"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16794/"
] |
270,745
|
<p>I have multiple Network Interface Cards on my computer, each with its own IP address.</p>
<p>When I use <code>gethostbyname(gethostname())</code> from Python's (built-in) <code>socket</code> module, it will only return one of them. How do I get the others?</p>
|
[
{
"answer_id": 274644,
"author": "Harley Holcombe",
"author_id": 1057,
"author_profile": "https://Stackoverflow.com/users/1057",
"pm_score": 7,
"selected": true,
"text": "netifaces >>> import netifaces\n>>> netifaces.interfaces()\n['lo', 'eth0']\n>>> netifaces.ifaddresses('eth0')\n{17: [{'broadcast': 'ff:ff:ff:ff:ff:ff', 'addr': '00:11:2f:32:63:45'}], 2: [{'broadcast': '10.0.0.255', 'netmask': '255.255.255.0', 'addr': '10.0.0.2'}], 10: [{'netmask': 'ffff:ffff:ffff:ffff::', 'addr': 'fe80::211:2fff:fe32:6345%eth0'}]}\n>>> for interface in netifaces.interfaces():\n... print netifaces.ifaddresses(interface)[netifaces.AF_INET]\n...\n[{'peer': '127.0.0.1', 'netmask': '255.0.0.0', 'addr': '127.0.0.1'}]\n[{'broadcast': '10.0.0.255', 'netmask': '255.255.255.0', 'addr': '10.0.0.2'}]\n>>> for interface in netifaces.interfaces():\n... for link in netifaces.ifaddresses(interface)[netifaces.AF_INET]:\n... print link['addr']\n...\n127.0.0.1\n10.0.0.2\n from netifaces import interfaces, ifaddresses, AF_INET\n\ndef ip4_addresses():\n ip_list = []\n for interface in interfaces():\n for link in ifaddresses(interface)[AF_INET]:\n ip_list.append(link['addr'])\n return ip_list\n AF_INET6 AF_INET netifaces"
},
{
"answer_id": 1491617,
"author": "DamonJW",
"author_id": 180219,
"author_profile": "https://Stackoverflow.com/users/180219",
"pm_score": 0,
"selected": false,
"text": "addrinfo_ipv4 = socket.getaddrinfo(hostname,port,socket.AF_INET,socket.SOCK_DGRAM)\naddrinfo_ipv6 = []\ntry:\n addrinfo_ipv6 = socket.getaddrinfo(hostname,port,socket.AF_INET6,socket.SOCK_DGRAM)\nexcept socket.gaierror:\n pass\naddrinfo = [(f,t,a) for f,t,p,cn,a in addrinfo_ipv4+addrinfo_ipv6]\naddrinfo_local = [(socket.AF_INET,socket.SOCK_DGRAM,('127.0.0.1',port))]\nif addrinfo_ipv6: \n addrinfo_local.append( (socket.AF_INET6,socket.SOCK_DGRAM,('::1',port)) )\n[addrinfo.append(ai) for ai in addrinfo_local if ai not in addrinfo]\n"
},
{
"answer_id": 16412986,
"author": "Nakilon",
"author_id": 322020,
"author_profile": "https://Stackoverflow.com/users/322020",
"pm_score": 4,
"selected": false,
"text": "import socket\n[i[4][0] for i in socket.getaddrinfo(socket.gethostname(), None)]\n"
},
{
"answer_id": 27494105,
"author": "The Demz",
"author_id": 844700,
"author_profile": "https://Stackoverflow.com/users/844700",
"pm_score": 3,
"selected": false,
"text": "#!/env/python3.4\nimport socket\nimport fcntl\nimport struct\n\ndef active_nic_addresses():\n \"\"\"\n Return a list of IPv4 addresses that are active on the computer.\n \"\"\"\n\n addresses = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith(\"127.\")][:1]\n\n return addresses\n\ndef get_ip_address( NICname ):\n s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n return socket.inet_ntoa(fcntl.ioctl(\n s.fileno(),\n 0x8915, # SIOCGIFADDR\n struct.pack('256s', NICname[:15].encode(\"UTF-8\"))\n )[20:24])\n\n\ndef nic_info():\n \"\"\"\n Return a list with tuples containing NIC and IPv4\n \"\"\"\n nic = []\n\n for ix in socket.if_nameindex():\n name = ix[1]\n ip = get_ip_address( name )\n\n nic.append( (name, ip) )\n\n return nic\n\nif __name__ == \"__main__\":\n\n print( active_nic_addresses() )\n print( nic_info() )\n ['192.168.0.2']\n[('lo', '127.0.0.1'), ('enp3s0', '192.168.0.2')]\n"
},
{
"answer_id": 33946251,
"author": "Elemag",
"author_id": 2436840,
"author_profile": "https://Stackoverflow.com/users/2436840",
"pm_score": 3,
"selected": false,
"text": "netifaces [netifaces.ifaddresses(iface)[netifaces.AF_INET][0]['addr'] for iface in netifaces.interfaces() if netifaces.AF_INET in netifaces.ifaddresses(iface)]\n"
},
{
"answer_id": 35776008,
"author": "Tlili Marwen",
"author_id": 5854219,
"author_profile": "https://Stackoverflow.com/users/5854219",
"pm_score": 0,
"selected": false,
"text": "import netifaces\n\nfor interface in netifaces.interfaces():\n print netifaces.ifaddresses(interface)\n"
},
{
"answer_id": 39951087,
"author": "Sandeep",
"author_id": 218857,
"author_profile": "https://Stackoverflow.com/users/218857",
"pm_score": 1,
"selected": false,
"text": "import itertools\nfrom netifaces import interfaces, ifaddresses, AF_INET\n\nlinks = filter(None, (ifaddresses(x).get(AF_INET) for x in interfaces()))\nlinks = itertools.chain(*links)\nip_addresses = [x['addr'] for x in links]\n"
},
{
"answer_id": 43478599,
"author": "pmav99",
"author_id": 592289,
"author_profile": "https://Stackoverflow.com/users/592289",
"pm_score": 4,
"selected": false,
"text": "import socket\nimport psutil\n\ndef get_ip_addresses(family):\n for interface, snics in psutil.net_if_addrs().items():\n for snic in snics:\n if snic.family == family:\n yield (interface, snic.address)\n\nipv4s = list(get_ip_addresses(socket.AF_INET))\nipv6s = list(get_ip_addresses(socket.AF_INET6))\n net_if_addrs import psutil\npsutil.net_if_addrs()\n {'br-ae4880aa80cf': [snic(family=<AddressFamily.AF_INET: 2>, address='172.18.0.1', netmask='255.255.0.0', broadcast='172.18.0.1', ptp=None),\n snic(family=<AddressFamily.AF_PACKET: 17>, address='02:42:e5:ae:39:94', netmask=None, broadcast='ff:ff:ff:ff:ff:ff', ptp=None)],\n 'docker0': [snic(family=<AddressFamily.AF_INET: 2>, address='172.17.0.1', netmask='255.255.0.0', broadcast='172.17.0.1', ptp=None),\n snic(family=<AddressFamily.AF_PACKET: 17>, address='02:42:38:d2:4d:77', netmask=None, broadcast='ff:ff:ff:ff:ff:ff', ptp=None)],\n 'eno1': [snic(family=<AddressFamily.AF_PACKET: 17>, address='54:be:f7:0b:cf:a9', netmask=None, broadcast='ff:ff:ff:ff:ff:ff', ptp=None)],\n 'lo': [snic(family=<AddressFamily.AF_INET: 2>, address='127.0.0.1', netmask='255.0.0.0', broadcast=None, ptp=None),\n snic(family=<AddressFamily.AF_PACKET: 17>, address='00:00:00:00:00:00', netmask=None, broadcast=None, ptp=None)],\n 'wlp2s0': [snic(family=<AddressFamily.AF_INET: 2>, address='192.168.1.4', netmask='255.255.255.0', broadcast='192.168.1.255', ptp=None),\n snic(family=<AddressFamily.AF_PACKET: 17>, address='00:21:27:ee:d6:03', netmask=None, broadcast='ff:ff:ff:ff:ff:ff', ptp=None)]}\n {'br-ae4880aa80cf': [snic(family=2, address='172.18.0.1', netmask='255.255.0.0', broadcast='172.18.0.1', ptp=None),\n snic(family=17, address='02:42:e5:ae:39:94', netmask=None, broadcast='ff:ff:ff:ff:ff:ff', ptp=None)],\n 'docker0': [snic(family=2, address='172.17.0.1', netmask='255.255.0.0', broadcast='172.17.0.1', ptp=None),\n snic(family=17, address='02:42:38:d2:4d:77', netmask=None, broadcast='ff:ff:ff:ff:ff:ff', ptp=None)],\n 'eno1': [snic(family=17, address='54:be:f7:0b:cf:a9', netmask=None, broadcast='ff:ff:ff:ff:ff:ff', ptp=None)],\n 'lo': [snic(family=2, address='127.0.0.1', netmask='255.0.0.0', broadcast=None, ptp=None),\n snic(family=17, address='00:00:00:00:00:00', netmask=None, broadcast=None, ptp=None)],\n 'wlp2s0': [snic(family=2, address='192.168.1.4', netmask='255.255.255.0', broadcast='192.168.1.255', ptp=None),\n snic(family=17, address='00:21:27:ee:d6:03', netmask=None, broadcast='ff:ff:ff:ff:ff:ff', ptp=None)]}\n snic namedtuple family AF_INET AF_INET6 psutil.AF_LINK address netmask broadcast ptp"
},
{
"answer_id": 54338977,
"author": "yongdi",
"author_id": 6947023,
"author_profile": "https://Stackoverflow.com/users/6947023",
"pm_score": 0,
"selected": false,
"text": "def get_lan_ip():\nfor interface in interfaces():\n try:\n for link in ifaddresses(interface)[AF_INET]:\n if str(link['addr']).startswith(\"172.\"):\n return str(link['addr'])\n except:\n pass\n"
},
{
"answer_id": 54629245,
"author": "chjortlund",
"author_id": 209532,
"author_profile": "https://Stackoverflow.com/users/209532",
"pm_score": 2,
"selected": false,
"text": "getaddrinfo() from socket import getaddrinfo, AF_INET, gethostname\n\nfor ip in getaddrinfo(host=gethostname(), port=None, family=AF_INET): \n print(ip[4][0])\n 192.168.55.1\n192.168.170.234\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270745",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35305/"
] |
270,771
|
<p>Can anyone suggest me on what data structure to use for a <a href="http://en.wikipedia.org/wiki/Soundex" rel="nofollow noreferrer">soundex algorithm</a> program? The language to be used is Java. If anybody has worked on this before in Java. The program should have these features:
be able to read about 50,000 words
should be able to read a word and return the related words having the same soundex</p>
<p>I don't want the program implementation just few advices on what data structure to use.</p>
|
[
{
"answer_id": 270783,
"author": "Edward Kmett",
"author_id": 34707,
"author_profile": "https://Stackoverflow.com/users/34707",
"pm_score": 2,
"selected": false,
"text": "#!/usr/bin/perl\nuse Text::Soundex;\nuse Data::Dumper;\nopen(DICT,\"</usr/share/dict/linux.words\");\nmy %dictionary = ();\nwhile (<DICT>) {\n chomp();\n chomp();\n push @{$dictionary{soundex($_)}},$_;\n}\nclose(DICT);\nwhile (<>) {\n my @words = split / +/;\n foreach (@words) {\n print Dumper $dictionary{soundex($_)};\n }\n}\n"
},
{
"answer_id": 270863,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 1,
"selected": false,
"text": "class SpellChecker\n{\n\n interface Hash {\n String hash(String);\n }\n\n private final Hash hash;\n\n private final Map<String, Set<String>> collisions;\n\n SpellChecker(Hash hash) {\n this.hash = hash;\n collisions = new TreeSet<String, Set<String>>();\n }\n\n boolean addWord(String word) {\n String key = hash.hash(word);\n Set<String> similar = collisions.get(key);\n if (similar == null)\n collisions.put(key, similar = new TreeSet<String>());\n return similar.add(word);\n }\n\n Set<String> similar(String word) {\n Set<String> similar = collisions.get(hash.hash(word));\n if (similar == null)\n return Collections.emptySet();\n else\n return Collections.unmodifiableSet(similar);\n }\n\n}\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270771",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35307/"
] |
270,772
|
<p>The Emacs cperl-mode seems to get confused less than perl-mode, but the Skittles effect makes the thing unusable for me. Does anyone have or know of an example of a .emacs block that causes cperl-mode to use the colorization from perl-mode, ideally in a form readable enough that I can go back and turn back on the default colors one element at a time until I reach something I'm comfortable with?</p>
<p>In particular there is a hideously shade of light green used for some builtins that I find quite unreadable, and I prefer my variables to not have the leading <code>$</code> and <code>$$</code> and such tinted red along with the variable name. Most of the rest are merely distracting.</p>
|
[
{
"answer_id": 5903300,
"author": "Sam Kington",
"author_id": 6832,
"author_profile": "https://Stackoverflow.com/users/6832",
"pm_score": 2,
"selected": false,
"text": "(custom-set-faces\n '(cperl-array-face ((t (:weight normal))))\n '(cperl-hash-face ((t (:weight normal))))\n)\n"
},
{
"answer_id": 37451330,
"author": "zk_phi",
"author_id": 6384159,
"author_profile": "https://Stackoverflow.com/users/6384159",
"pm_score": 1,
"selected": false,
"text": "(require 'perl-mode)\n\n(add-hook 'cperl-mode-hook\n (lambda ()\n (setq font-lock-defaults\n '((perl-font-lock-keywords perl-font-lock-keywords-1 perl-font-lock-keywords-2)\n nil nil ((?\\_ . \"w\")) nil\n (font-lock-syntactic-face-function . perl-font-lock-syntactic-face-function)))\n (font-lock-refresh-defaults)))\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270772",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19202/"
] |
270,788
|
<p>I have a system in which different server processes are handling requests passed as JMS messages from various clients via a JMS broker.</p>
<p>I am trying to identify the source of the messages. Is there a way to get the IP or some identifying information about the origin ?</p>
<p>Clarification: I already have the client deployed by unknown users, so I'm trying to avoid changing message classes... </p>
|
[
{
"answer_id": 271197,
"author": "John M",
"author_id": 20734,
"author_profile": "https://Stackoverflow.com/users/20734",
"pm_score": 0,
"selected": false,
"text": "// client code\nString myIPString = ...;\nMessage m = session.createTextMessage();\nm.setStringProperty(\"IPOfSender\", myIPString);\n...\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270788",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23072/"
] |
270,800
|
<p>I have several server processes that once in a while respond to messages from the clients and perform read-only transactions.</p>
<p>After about a few days that the servers are running, they stop working correctly and when I check it turns out that there's a whole bunch of messages about the connection being closed.</p>
<p>When I checked it out, it turned out that hibernate by default works in some sort of development mode where connections are dropped after a few hours, and I started using c3po for connection pooling. </p>
<p>However, even with c3po, I get that problem about 24 hours or so after the servers are started.</p>
<p>Has anyone encountered that problem and knows how to address it? I'm not familiar enough with the intricacies of configuring hibernate.</p>
|
[
{
"answer_id": 270857,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 5,
"selected": true,
"text": "autoReconnect=true autoReconnect SQLException"
},
{
"answer_id": 847036,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "autoReconnect=true"
},
{
"answer_id": 25129022,
"author": "Bourkadi",
"author_id": 1565794,
"author_profile": "https://Stackoverflow.com/users/1565794",
"pm_score": 2,
"selected": false,
"text": " <property name=\"connection.autoReconnect\">true</property>\n <property name=\"connection.autoReconnectForPools\">true</property>\n <property name=\"connection.is-connection-validation-required\">true</property>\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270800",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23072/"
] |
270,811
|
<pre><code>cmd /C "myshortcut1.lnk"
cmd /C "myshortcut2.lnk"
</code></pre>
<p>Works, but gives me a pop-up DOS window which, when closed, kills my two loaded programs. Same is true for this:</p>
<pre><code>start /B cmd /C "1.lnk"
start /B cmd /C "2.lnk"
start /B cmd /C "3.lnk"
start /B cmd /C "4.lnk"
</code></pre>
|
[
{
"answer_id": 270857,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 5,
"selected": true,
"text": "autoReconnect=true autoReconnect SQLException"
},
{
"answer_id": 847036,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "autoReconnect=true"
},
{
"answer_id": 25129022,
"author": "Bourkadi",
"author_id": 1565794,
"author_profile": "https://Stackoverflow.com/users/1565794",
"pm_score": 2,
"selected": false,
"text": " <property name=\"connection.autoReconnect\">true</property>\n <property name=\"connection.autoReconnectForPools\">true</property>\n <property name=\"connection.is-connection-validation-required\">true</property>\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270811",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34594/"
] |
270,822
|
<p>I control access to some of my static web resources with some PHP logic. Because directory-based authorization through the webserver is not suitable or easily possible.</p>
<p>A combination of things determines whether access is granted or denied. And these rules change from time to time.</p>
<p>In the beginning it was a simple regex path match, and a check of one session variable. It's more complicated now as there's a few more variables involved.</p>
<p>I'm wondering how to go about refactoring this so it's quick and easy to change the rules. When it was a simple "if this AND this, then deliver, else 403." it was fine to do it in straight PHP. Now the conditions are more complex and there's a couple levels of nesting each with common but slightly different conditions within. This is all easy enough to refactor, but it's not the most intuitive and easy to update.</p>
<p>I'm thinking of one of two things.</p>
<ol>
<li><p>Establish classes for each of the top level of conditions and use a Strategy Factory to pick the right one authorize. Derive them all from a base class containing the common bits and overload whatever's necessary. I think this could still be prone to some shuffling around when some conditions change.</p></li>
<li><p>Make a simple engine that iterates a 2d array of ordered rules sort of like firewall rules. Something like: <code><allow|deny>, <auth_group>, <path_regex>, <other vars></code></p></li>
</ol>
<p>I haven't fully thought this one through but it seems like it would be easier to update and also to read as a human.</p>
<p>What would you do? Is there an established pattern or library I can use for this?</p>
<p>I faced this similar problem in another app some time ago. Where I wanted an easy to update way of chaining rules and outcomes together based on several levels of conditions. This isn't as complicated as that app, but I'd be interested to hear about patterns people use to solve this kind of problem.</p>
|
[
{
"answer_id": 10503977,
"author": "Saulo Vallory",
"author_id": 219838,
"author_profile": "https://Stackoverflow.com/users/219838",
"pm_score": 0,
"selected": false,
"text": "IsSatisfiedBy()"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
270,825
|
<p>Has anyone else run into this problem before? I've got a method that calls a generic method with a delegate, inside of a generic class. I've marked the class as Serializable, and it serializes without complaint. But, when I try to deserialize an object of this class, it pegs the CPU and hangs the machine.</p>
<p>Code example:</p>
<pre><code>public delegate T CombinationFunctionDelegate<T,U,V>(U a, V b);
[Serializable]
public class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
{
public SDictionary()
: base()
{
}
protected SDictionary(SerializationInfo info, StreamingContext context)
: base(info, context)
{}
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
public List<ListItem> ToListItems()
{
return Convert(delegate(TKey key, TValue value)
{
return new ListItem(key.ToString(), value.ToString());
});
}
public List<U> Convert<U>(CombinationFunctionDelegate<U, TKey, TValue> converterFunction)
{
List<U> res = new List<U>();
foreach (TKey key in Keys)
res.Add(converterFunction(key, this[key]));
return res;
}
}
</code></pre>
<p>I can put an instance of this class into ViewState (for example) just fine, but when I try to extract the object from ViewState again, the CPU on the machine spikes and the deserialization call never returns (ie, infinite loop).</p>
<p>When I remove the ToListItems() method, everything works wonderfully. Is this really weird, or do I just not understand serialization? =)</p>
|
[
{
"answer_id": 270858,
"author": "OJ.",
"author_id": 611,
"author_profile": "https://Stackoverflow.com/users/611",
"pm_score": 0,
"selected": false,
"text": "public override void GetObjectData(SerializationInfo info, StreamingContext context)\n{\n // deserialize the dictionary first\n base.GetObjectData(info, context);\n\n // the rest of your code\n // ...\n}\n"
},
{
"answer_id": 270886,
"author": "OJ.",
"author_id": 611,
"author_profile": "https://Stackoverflow.com/users/611",
"pm_score": 1,
"selected": false,
"text": " [Serializable]\n public class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>\n {\n public SDictionary()\n : base()\n {\n }\n\n protected SDictionary(SerializationInfo info, StreamingContext context)\n : base(info, context)\n {\n }\n\n public List<ListItem> ToListItems()\n {\n return this.Convert(delegate(TKey key, TValue value)\n {\n return new ListItem(key.ToString(), value.ToString());\n });\n }\n\n public List<U> Convert<U>(CombinationFunctionDelegate<U, TKey, TValue> converterFunction)\n {\n List<U> res = new List<U>();\n foreach (TKey key in Keys)\n res.Add(converterFunction(key, this[key]));\n\n return res;\n }\n\n\n }\n\n class Program\n {\n\n static void Main(string[] args)\n {\n SDictionary<string, string> b = new SDictionary<string, string>();\n b.Add(\"foo\", \"bar\");\n\n System.IO.MemoryStream memStream = new System.IO.MemoryStream();\n System.Runtime.Serialization.Formatters.Binary.BinaryFormatter f = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();\n f.Serialize(memStream, b);\n memStream.Position = 0;\n\n b = f.Deserialize(memStream) as SDictionary<string, string>;\n }\n\n }\n"
},
{
"answer_id": 271004,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 0,
"selected": false,
"text": "public ListItem ToListItem(TKey key, TValue value)\n{\n return new ListItem(key.ToString(), value.ToString());\n}\n public static List<ListItem> ToListItems(this Dictionary<T, U> source)\n{\n return source\n .Select(x => new ListItem(x.key.ToString(), x.value.ToString()))\n .ToList();\n}\n\npublic static List<V> Convert<V>\n(\n this Dictionary<T, U> source,\n Func<T, U, V> converterFunction\n)\n{\n return source\n .Select(x => converterFunction(x.Key, x.Value))\n .ToList();\n}\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270825",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35308/"
] |
270,829
|
<p>So we are sure that we will be taking our product internationally and will eventually need to internationalize it. How much internationalizing would you recommend we do as we go along?</p>
<p>I guess in other words, is there any internationalization that is easy now but can be much worse if we let the code base mature and that won't slow us down very much if we choose to start doing it now?</p>
<p>Tech used: C#, WPF, WinForms</p>
|
[
{
"answer_id": 55414355,
"author": "Robert Jørgensgaard Engdahl",
"author_id": 2154774,
"author_profile": "https://Stackoverflow.com/users/2154774",
"pm_score": 1,
"selected": false,
"text": "NGettext.Wpf.CompositionRoot.Compose(\"ExampleDomainName\");\n \"ExampleDomainName\" \"da-DK\" \"Locale\\da-DK\\LC_MESSAGES\\ExampleDomainName.mo\" <Button CommandParameter=\"en-US\" \n Command=\"{StaticResource ChangeCultureCommand}\" \n Content=\"{wpf:Gettext English}\" />\n Content ChangeCultureCommand \"en-US\""
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270829",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9401/"
] |
270,835
|
<p>I am trying to provide my own labelFunction for a CategoryAxis programatically but am completely stumped. The regular way is to do it in your MXML file, but I want to do it in my Actionscript file.</p>
<p>The regular way of doing it is:</p>
<pre><code><mx:Script>
<![CDATA[
private function categoryAxis_labelFunc(item:Object,
prevValue:Object,
axis:CategoryAxis,
categoryItem:Object):String {
return "Some String";
}
]]>
</mx:Script>
<mx:CategoryAxis labelFunction="categoryAxis_labelFunc" />
</code></pre>
<p>But I want to achieve the same thing in my subclass of CategoryAxis, something like:</p>
<pre><code>public class FauxDateAxis extends CategoryAxis {
public function FauxDateAxis() {
super();
labelFunction = categoryAxis_labelFunc // Doesn't work of course.
}
private function categoryAxis_labelFunc(item:Object,
prevValue:Object,
axis:CategoryAxis,
categoryItem:Object):String {
return "Another String";
}
}
</code></pre>
|
[
{
"answer_id": 271352,
"author": "Mitch Haile",
"author_id": 28807,
"author_profile": "https://Stackoverflow.com/users/28807",
"pm_score": 1,
"selected": false,
"text": "function(item:Object, field:String, index:int, pct:Number)\n public function FauxDateAxis() {\n super();\n labelFunction = function(item:Object, field:String, index:int, pct:Number) {\n return \"string\";\n }\n}\n"
},
{
"answer_id": 278855,
"author": "Randy Stegbauer",
"author_id": 34301,
"author_profile": "https://Stackoverflow.com/users/34301",
"pm_score": 3,
"selected": true,
"text": "<mx:CategoryAxis id=\"haxis\" categoryField=\"Date\" title=\"Date\"/>\n <local:FauxDateAxis id=\"haxis\" categoryField=\"Date\" title=\"Date\"/>\n"
}
] |
2008/11/06
|
[
"https://Stackoverflow.com/questions/270835",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3410/"
] |
270,845
|
<p>I've been trying to come up with a way to write generic repositories that work against various data stores:</p>
<pre><code>public interface IRepository
{
IQueryable<T> GetAll<T>();
void Save<T>(T item);
void Delete<T>(T item);
}
public class MemoryRepository : IRepository {...}
public class SqlRepository : IRepository {...}
</code></pre>
<p>I'd like to work against the same POCO domain classes in each. I'm also considering a similar approach, where each domain class has it's own repository:</p>
<pre><code>public interface IRepository<T>
{
IQueryable<T> GetAll();
void Save(T item);
void Delete(T item);
}
public class MemoryCustomerRepository : IRepository {...}
public class SqlCustomerRepository : IRepository {...}
</code></pre>
<p>My questions: 1)Is the first approach even feasible? 2)Is there any advantage to the second approach. </p>
|
[
{
"answer_id": 271216,
"author": "cfeduke",
"author_id": 5645,
"author_profile": "https://Stackoverflow.com/users/5645",
"pm_score": 3,
"selected": false,
"text": "XmlWriter XmlReader SelectByLastName DeleteFromParent Memory*Repository WithXXX AsSomeProfile AsSomeProfile // Moq mocking the concrete PersonMapper through the IPersonMapper interface\nvar personMock = new Mock<IPersonMapper>(MockBehavior.Strict);\npersonMock.Expect(pm => pm.Select(It.IsAny<int>())).Returns(\n new PersonBuilder().AsMike().Build()\n);\n\n// StructureMap's ObjectFactory\nObjectFactory.Inject(personMock.Object);\n\n// now anywhere in my actual code where an IPersonMapper instance is requested from\n// ObjectFactory, Moq will satisfy the requirement and return a Person instance\n// set with the PersonBuilder's Mike profile unit test data\n"
},
{
"answer_id": 522657,
"author": "thinkbeforecoding",
"author_id": 47001,
"author_profile": "https://Stackoverflow.com/users/47001",
"pm_score": 2,
"selected": false,
"text": "Table<T> ITable<T> Table<T> ITable<T> ITable<T> List<T> IQueryable<T> public class InMemoryTable<T> : ITable<T>\n{\n private List<T> list;\n private IQueryable<T> queryable;\n\n public InMemoryTable<T>(List<T> list)\n { \n this.list = list;\n this.queryable = list.AsQueryable();\n }\n\n public void Add(T entity) { list.Add(entity); }\n public void Remove(T entity) { list.Remove(entity); }\n\n public IEnumerator<T> GetEnumerator() { return list.GetEnumerator(); }\n\n public Type ElementType { get { return queryable.ElementType; } }\n public IQueryProvider Provider { get { return queryable.Provider; } }\n ...\n}\n"
},
{
"answer_id": 2418996,
"author": "Val",
"author_id": 290726,
"author_profile": "https://Stackoverflow.com/users/290726",
"pm_score": 2,
"selected": false,
"text": "* Supports all CRUD methods ( Create, Retrieve, Update, Delete )\n* Supports aggregate methods Min, Max, Sum, Avg, Count\n* Supports Find methods using ICriteria<T>\n* Supports Distinct, and GroupBy\n* Supports interface IRepository<T> so you can use an In-Memory table for unit-testing\n* Supports versioning of your entities\n* Supports paging, eg. Get(page, pageSize)\n* Supports audit fields ( CreateUser, CreatedDate, UpdateDate etc )\n* Supports the use of Mapper<T> so you can map any table record to some entity\n* Supports creating entities only if it isn't there already, by checking for field values.\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270845",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
270,874
|
<p>I have a DataTrigger defined in my XAML which I want to use in several places. Is it possible to define it as a resource and then share it?</p>
<p>Here's my trigger:</p>
<pre><code><TextBlock.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding HasCurrentTest}" Value="True">
<Setter Property="TextBlock.Visibility" Value="Hidden" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</code></pre>
<p>While I can define this in my Window.Resources and give it a key, how do I refer to it in the rest of my XAML?</p>
|
[
{
"answer_id": 270904,
"author": "MrSlippers",
"author_id": 35290,
"author_profile": "https://Stackoverflow.com/users/35290",
"pm_score": 1,
"selected": false,
"text": "<Window.Resources>\n <Style x:Key=\"YourStyleKey\">\n <!-- Your Style -->\n </Style>\n</Window.Resources>\n\n<TextBox Text=\"SomeText\" Style=\"{StaticResource YourStyleKey}\"/>\n<TextBox Text=\"SomeOtherText\" Style=\"{StaticResource YourStyleKey}\"/>\n"
},
{
"answer_id": 271005,
"author": "Craig Shearer",
"author_id": 14537,
"author_profile": "https://Stackoverflow.com/users/14537",
"pm_score": 2,
"selected": false,
"text": "<Window.Resources>\n <BooleanToVisibilityConverter x:Key=\"BoolToVis\" />\n</Window.Resources>\n <TextBlock Visibility=\"{Binding HasNoCurrentTest, \n Converter={StaticResource BoolToVis}}\" />\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270874",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14537/"
] |
270,879
|
<p>I'm starting a new application and looking at using an ORM -- in particular, SQLAlchemy.</p>
<p>Say I've got a column 'foo' in my database and I want to increment it. In straight sqlite, this is easy:</p>
<pre><code>db = sqlite3.connect('mydata.sqlitedb')
cur = db.cursor()
cur.execute('update table stuff set foo = foo + 1')
</code></pre>
<p>I figured out the SQLAlchemy SQL-builder equivalent:</p>
<pre><code>engine = sqlalchemy.create_engine('sqlite:///mydata.sqlitedb')
md = sqlalchemy.MetaData(engine)
table = sqlalchemy.Table('stuff', md, autoload=True)
upd = table.update(values={table.c.foo:table.c.foo+1})
engine.execute(upd)
</code></pre>
<p>This is slightly slower, but there's not much in it.</p>
<p>Here's my best guess for a SQLAlchemy ORM approach:</p>
<pre><code># snip definition of Stuff class made using declarative_base
# snip creation of session object
for c in session.query(Stuff):
c.foo = c.foo + 1
session.flush()
session.commit()
</code></pre>
<p>This does the right thing, but it takes just under fifty times as long as the other two approaches. I presume that's because it has to bring all the data into memory before it can work with it.</p>
<p>Is there any way to generate the efficient SQL using SQLAlchemy's ORM? Or using any other python ORM? Or should I just go back to writing the SQL by hand?</p>
|
[
{
"answer_id": 270891,
"author": "Matthew Schinckel",
"author_id": 188,
"author_profile": "https://Stackoverflow.com/users/188",
"pm_score": 1,
"selected": false,
"text": "for c in session.query(Stuff).all():\n c.foo = c.foo+1\nsession.commit()\n"
},
{
"answer_id": 278606,
"author": "Ants Aasma",
"author_id": 107366,
"author_profile": "https://Stackoverflow.com/users/107366",
"pm_score": 9,
"selected": true,
"text": "for c in session.query(Stuff).all():\n c.foo = c.foo+1\nsession.commit()\n session.execute(update(stuff_table, values={stuff_table.c.foo: stuff_table.c.foo + 1}))\nsession.commit()\n session.query(Stuff).update({Stuff.foo: Stuff.foo + 1})\nsession.commit()\n synchronize_session=False"
},
{
"answer_id": 4540110,
"author": "Vin",
"author_id": 555137,
"author_profile": "https://Stackoverflow.com/users/555137",
"pm_score": 7,
"selected": false,
"text": "session.query(Clients).filter(Clients.id == client_id_list).update({'status': status})\nsession.commit()\n"
},
{
"answer_id": 32447458,
"author": "plowman",
"author_id": 426794,
"author_profile": "https://Stackoverflow.com/users/426794",
"pm_score": 4,
"selected": false,
"text": "from sqlalchemy import Column, ForeignKey, Integer, String, Date, DateTime, text, create_engine\nfrom sqlalchemy.exc import IntegrityError\nfrom sqlalchemy.ext.declarative import declarative_base\nfrom sqlalchemy.orm import sessionmaker\nfrom sqlalchemy.orm.attributes import InstrumentedAttribute\n\nengine = create_engine('postgres://postgres@localhost:5432/database')\nsession = sessionmaker()\nsession.configure(bind=engine)\n\nBase = declarative_base()\n\n\nclass Media(Base):\n __tablename__ = 'media'\n id = Column(Integer, primary_key=True)\n title = Column(String, nullable=False)\n slug = Column(String, nullable=False)\n type = Column(String, nullable=False)\n\n def update(self):\n s = session()\n mapped_values = {}\n for item in Media.__dict__.iteritems():\n field_name = item[0]\n field_type = item[1]\n is_column = isinstance(field_type, InstrumentedAttribute)\n if is_column:\n mapped_values[field_name] = getattr(self, field_name)\n\n s.query(Media).filter(Media.id == self.id).update(mapped_values)\n s.commit()\n media = Media(id=123, title=\"Titular Line\", slug=\"titular-line\", type=\"movie\")\nmedia.update()\n"
},
{
"answer_id": 33638391,
"author": "Nima Soroush",
"author_id": 1952158,
"author_profile": "https://Stackoverflow.com/users/1952158",
"pm_score": 5,
"selected": false,
"text": "1) for c in session.query(Stuff).all():\n c.foo += 1\n session.commit()\n\n2) session.query(Stuff).update({\"foo\": Stuff.foo + 1})\n session.commit()\n\n3) conn = engine.connect()\n table = Stuff.__table__\n stmt = table.update().values({'foo': Stuff.foo + 'a'})\n conn.execute(stmt)\n conn.commit()\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270879",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15154/"
] |
270,884
|
<p>I've been doing some socket programming to transmit information across the wire. I've run into a problem with DataOutputStream.writeUTF(). It seems to allow strings of up to 64k but I have a few situations where I can run over this. Are there any good alternatives that support larger strings or do I need to roll my own?</p>
|
[
{
"answer_id": 270915,
"author": "Bill the Lizard",
"author_id": 1288,
"author_profile": "https://Stackoverflow.com/users/1288",
"pm_score": 1,
"selected": false,
"text": "Writer osw = new OutputStreamWriter(out, \"UTF-8\");\n out"
},
{
"answer_id": 270922,
"author": "kasperjj",
"author_id": 34240,
"author_profile": "https://Stackoverflow.com/users/34240",
"pm_score": 5,
"selected": true,
"text": "// Write data\nString str=\"foo\";\nbyte[] data=str.getBytes(\"UTF-8\");\nout.writeInt(data.length);\nout.write(data);\n\n// Read data\nint length=in.readInt();\nbyte[] data=new byte[length];\nin.readFully(data);\nString str=new String(data,\"UTF-8\");\n"
},
{
"answer_id": 9073621,
"author": "ebruchez",
"author_id": 5144,
"author_profile": "https://Stackoverflow.com/users/5144",
"pm_score": 3,
"selected": false,
"text": "ObjectOutputStream.writeObject() ObjectOutputStream oos = new ObjectOutputStream(out);\n... other write operations ...\noos.writeObject(myString);\n... other write operations ...\n ObjectInputStream ois = new ObjectInputStream(in);\n... other read operations ...\nString myString = (String) ois.readObject();\n... other read operations ...\n DataOutputStream ObjectOutputStream"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/269171/"
] |
270,895
|
<p>This fails:</p>
<pre><code>my @a = ("a", "b", "c", "d", "e");
my %h = map { "prefix-$_" => 1 } @a;
</code></pre>
<p>with this error:</p>
<pre><code>Not enough arguments for map at foo.pl line 4, near "} @a"
</code></pre>
<p>but this works:</p>
<pre><code>my @a = ("a", "b", "c", "d", "e");
my %h = map { "prefix-" . $_ => 1 } @a;
</code></pre>
<p>why?</p>
|
[
{
"answer_id": 270905,
"author": "Leonardo Herrera",
"author_id": 7841,
"author_profile": "https://Stackoverflow.com/users/7841",
"pm_score": 5,
"selected": true,
"text": "my @a = (\"a\", \"b\", \"c\", \"d\", \"e\");\nmy %h = map { +\"prefix-$_\" => 1 } @a;\n"
},
{
"answer_id": 270912,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 4,
"selected": false,
"text": "perldoc -f map \"{\" starts both hash references and blocks, so \"map { ...\"\n could be either the start of map BLOCK LIST or map EXPR, LIST.\n Because perl doesn’t look ahead for the closing \"}\" it has to\n take a guess at which its dealing with based what it finds just\n after the \"{\". Usually it gets it right, but if it doesn’t it\n won’t realize something is wrong until it gets to the \"}\" and\n encounters the missing (or unexpected) comma. The syntax error\n will be reported close to the \"}\" but you’ll need to change\n something near the \"{\" such as using a unary \"+\" to give perl\n some help:\n\n %hash = map { \"\\L$_\", 1 } @array # perl guesses EXPR. wrong\n %hash = map { +\"\\L$_\", 1 } @array # perl guesses BLOCK. right\n %hash = map { (\"\\L$_\", 1) } @array # this also works\n %hash = map { lc($_), 1 } @array # as does this.\n %hash = map +( lc($_), 1 ), @array # this is EXPR and works!\n %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array)\n\n or to force an anon hash constructor use \"+{\"\n\n @hashes = map +{ lc($_), 1 }, @array # EXPR, so needs , at end\n\n and you get list of anonymous hashes each with only 1 entry.\n"
},
{
"answer_id": 271078,
"author": "Andy Lester",
"author_id": 8454,
"author_profile": "https://Stackoverflow.com/users/8454",
"pm_score": 4,
"selected": false,
"text": "my %h = map { (\"prefix-$_\" => 1) } @a;\n"
},
{
"answer_id": 271086,
"author": "Andy Lester",
"author_id": 8454,
"author_profile": "https://Stackoverflow.com/users/8454",
"pm_score": 3,
"selected": false,
"text": "my @a = qw( a b c d e );\nmy %h;\n@h{@a} = ();\n @h{@a} = (1) x @a;\n @h{$_} = 1 for @a;\n"
},
{
"answer_id": 271374,
"author": "Axeman",
"author_id": 11289,
"author_profile": "https://Stackoverflow.com/users/11289",
"pm_score": 1,
"selected": false,
"text": "map { ; \"prefix-$_\" => 1 } @a;\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14032/"
] |
270,917
|
<p>I know it is a good practice to declare virtual destructors for base classes in C++, but is it always important to declare <code>virtual</code> destructors even for abstract classes that function as interfaces? Please provide some reasons and examples why.</p>
|
[
{
"answer_id": 270925,
"author": "Airsource Ltd",
"author_id": 18017,
"author_profile": "https://Stackoverflow.com/users/18017",
"pm_score": 9,
"selected": true,
"text": "class Interface\n{\n virtual void doSomething() = 0;\n};\n\nclass Derived : public Interface\n{\n Derived();\n ~Derived() \n {\n // Do some important cleanup...\n }\n};\n\nvoid myFunc(void)\n{\n Interface* p = new Derived();\n // The behaviour of the next line is undefined. It probably \n // calls Interface::~Interface, not Derived::~Derived\n delete p; \n}\n"
},
{
"answer_id": 270926,
"author": "OJ.",
"author_id": 611,
"author_profile": "https://Stackoverflow.com/users/611",
"pm_score": 4,
"selected": false,
"text": "class IFoo\n{\n public:\n virtual void DoFoo() = 0;\n};\n\nclass Bar : public IFoo\n{\n char* dooby = NULL;\n public:\n virtual void DoFoo() { dooby = new char[10]; }\n void ~Bar() { delete [] dooby; }\n};\n\nIFoo* baz = new Bar();\nbaz->DoFoo();\ndelete baz; // memory leak - dooby isn't deleted\n"
},
{
"answer_id": 270929,
"author": "Evan Teran",
"author_id": 13430,
"author_profile": "https://Stackoverflow.com/users/13430",
"pm_score": 3,
"selected": false,
"text": "Base *p = new Derived;\n// use p as you see fit\ndelete p;\n Base Base *"
},
{
"answer_id": 270931,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 3,
"selected": false,
"text": "Animal* pAnimal = GetAnimal();\ndelete pAnimal;\n"
},
{
"answer_id": 14056241,
"author": "fatma.ekici",
"author_id": 1678760,
"author_profile": "https://Stackoverflow.com/users/1678760",
"pm_score": 2,
"selected": false,
"text": " Base *ptr = new Derived();\n delete ptr; // Here the call order of destructors: first Derived then Base.\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270917",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4599/"
] |
270,918
|
<p>I would like to create a batch script, to go through 20,000 links in a DB, and weed out all the 404s and such. How would I get the HTTP status code for a remote url?</p>
<p>Preferably not using curl, since I dont have it installed. </p>
|
[
{
"answer_id": 270966,
"author": "Adam Pierce",
"author_id": 5324,
"author_profile": "https://Stackoverflow.com/users/5324",
"pm_score": 5,
"selected": true,
"text": "<?php\n\n$url = parse_url('http://www.example.com/index.html');\n\n$host = $url['host'];\n$port = $url['port'];\n$path = $url['path'];\n$query = $url['query'];\nif(!$port)\n $port = 80;\n\n$request = \"HEAD $path?$query HTTP/1.1\\r\\n\"\n .\"Host: $host\\r\\n\"\n .\"Connection: close\\r\\n\"\n .\"\\r\\n\";\n\n$address = gethostbyname($host);\n$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);\nsocket_connect($socket, $address, $port);\n\nsocket_write($socket, $request, strlen($request));\n\n$response = split(' ', socket_read($socket, 1024));\n\nprint \"<p>Response: \". $response[1] .\"</p>\\r\\n\";\n\nsocket_close($socket);\n\n?>\n"
},
{
"answer_id": 270994,
"author": "J.C. Inacio",
"author_id": 35292,
"author_profile": "https://Stackoverflow.com/users/35292",
"pm_score": 2,
"selected": false,
"text": "parse url => $host, $port, $path\n$http_request = \"GET $path HTTP/1.0\\nHhost: $host\\n\\n\";\n$fp = fsockopen($host, $port, $errno, $errstr, $timeout), check for any errors\nfwrite($fp, $request)\nwhile (!feof($fp)) {\n $headers .= fgets($fp, 4096);\n $status = <parse $headers >\n if (<status read>)\n break;\n}\nfclose($fp)\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270918",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
270,919
|
<p>I am looking for an example of how to do the following in VB.net with Parallel Extensions.</p>
<pre><code>Dim T As Thread = New Thread(AddressOf functiontodowork)
T1.Start(InputValueforWork)
</code></pre>
<p>Where I'm getting stuck is on how to pass into the task my parameter InputValueforWork</p>
<pre><code>Dim T As Tasks.Task = Tasks.Task.Create(AddressOf functiontodowork)
</code></pre>
<p>Any suggests and possibly a coding example would be welcome.</p>
<p>Andrew</p>
|
[
{
"answer_id": 271266,
"author": "Ana Betts",
"author_id": 5728,
"author_profile": "https://Stackoverflow.com/users/5728",
"pm_score": 0,
"selected": false,
"text": "var T = Tasks.Task.Create( () => functionToDoWork(SomeParameter) )\n"
},
{
"answer_id": 349731,
"author": "Mauricio Scheffer",
"author_id": 21239,
"author_profile": "https://Stackoverflow.com/users/21239",
"pm_score": 0,
"selected": false,
"text": "Action<T> public class VBHelpers {\n public static Action<T> FuncToAction<T>(Func<T, object> f) {\n return p => f(p);\n }\n}\n Public Sub DoSomething()\n Dim T As Task = Task.Create(VBHelpers.FuncToAction(Function(p) FunctionToDoWork(p)))\nEnd Sub\n\nPublic Function FunctionToDoWork(ByVal e As Object) As Integer\n ' this does the real work\nEnd Function\n"
},
{
"answer_id": 353454,
"author": "Middletone",
"author_id": 35331,
"author_profile": "https://Stackoverflow.com/users/35331",
"pm_score": 2,
"selected": true,
"text": "Dim A(0) as Int32\nA(0) = 1\nTasks.Task.Create(AddressOf TransferData, A)\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35331/"
] |
270,924
|
<p>I've been reading a text about an extension to C# and at one point it says that "An attribute decoration X may only be applied to fields of type Y."</p>
<p>I haven't been able to find a definition for attribute decoration, and I'm not making much sense out of this by exchanging the two.</p>
|
[
{
"answer_id": 271266,
"author": "Ana Betts",
"author_id": 5728,
"author_profile": "https://Stackoverflow.com/users/5728",
"pm_score": 0,
"selected": false,
"text": "var T = Tasks.Task.Create( () => functionToDoWork(SomeParameter) )\n"
},
{
"answer_id": 349731,
"author": "Mauricio Scheffer",
"author_id": 21239,
"author_profile": "https://Stackoverflow.com/users/21239",
"pm_score": 0,
"selected": false,
"text": "Action<T> public class VBHelpers {\n public static Action<T> FuncToAction<T>(Func<T, object> f) {\n return p => f(p);\n }\n}\n Public Sub DoSomething()\n Dim T As Task = Task.Create(VBHelpers.FuncToAction(Function(p) FunctionToDoWork(p)))\nEnd Sub\n\nPublic Function FunctionToDoWork(ByVal e As Object) As Integer\n ' this does the real work\nEnd Function\n"
},
{
"answer_id": 353454,
"author": "Middletone",
"author_id": 35331,
"author_profile": "https://Stackoverflow.com/users/35331",
"pm_score": 2,
"selected": true,
"text": "Dim A(0) as Int32\nA(0) = 1\nTasks.Task.Create(AddressOf TransferData, A)\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
270,930
|
<p>As a follow-up to <a href="https://stackoverflow.com/questions/269812/how-to-quickly-get-started-at-using-and-learning-emacs">this question</a>, it's trying to find out how to do something like this which should be easy, that especially stops me from getting more used to using Emacs and instead starting up the editor I'm already familiar with. I use the example here fairly often in editing multiple files.</p>
<p>In Ultraedit I'd do Alt+s then p to display a dialog box with the options: Find (includes using regular expressions across multiple lines), Replace with, In Files/Types, Directory, Match Case, Match Whole Word Only, List Changed Files and Search Sub Directories. Usually I'll first use the mouse to click-drag select the text that I want to replace.</p>
<p>Using only Emacs itself (on Windows XP), without calling any external utility, how to replace all foo\nbar with bar\nbaz in <code>*.c</code> and <code>*.h</code> files in some folder and all folders beneath it. Maybe Emacs is not the best tool to do this with, but how can it be done easily with a minimal command?</p>
|
[
{
"answer_id": 271013,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 4,
"selected": false,
"text": "(defun findr-query-replace (from to name dir)\n \"Do `query-replace-regexp' of FROM with TO, on each file found by findr.\n"
},
{
"answer_id": 271136,
"author": "Chris Conway",
"author_id": 1412,
"author_profile": "https://Stackoverflow.com/users/1412",
"pm_score": 10,
"selected": true,
"text": "M-x find-name-dired t Q query-replace-regexp SPACE n C-x s y n !"
},
{
"answer_id": 8016053,
"author": "Frank Henard",
"author_id": 59439,
"author_profile": "https://Stackoverflow.com/users/59439",
"pm_score": 5,
"selected": false,
"text": "M-x find-name-dired RET M-> find finished t Q y N N Y C-x C-b M-x ibuffer RET * u S * * RET D"
},
{
"answer_id": 8147267,
"author": "Drew",
"author_id": 729907,
"author_profile": "https://Stackoverflow.com/users/729907",
"pm_score": 2,
"selected": false,
"text": "*Completions* y/n grep"
},
{
"answer_id": 11691104,
"author": "yPhil",
"author_id": 1729094,
"author_profile": "https://Stackoverflow.com/users/1729094",
"pm_score": 2,
"selected": false,
"text": "(defun px-query-replace-in-open-buffers (arg1 arg2)\n \"query-replace in all open files\"\n (interactive \"sRegexp:\\nsReplace with:\")\n (mapcar\n (lambda (x)\n (find-file x)\n (save-excursion\n (goto-char (point-min))\n (query-replace-regexp arg1 arg2)))\n (delq\n nil\n (mapcar\n (lambda (x)\n (buffer-file-name x))\n (buffer-list)))))\n"
},
{
"answer_id": 19397275,
"author": "ocodo",
"author_id": 311660,
"author_profile": "https://Stackoverflow.com/users/311660",
"pm_score": 4,
"selected": false,
"text": "wgrep rgrep iedit iedit wgrep M-x package-list-packages M-x rgrep wgrep C-s C-p rgrep iedit-mode C-; C-x C-s wgrep C-x s ! iedit-mode M-; rgrep"
},
{
"answer_id": 19527215,
"author": "Zack Murray",
"author_id": 2908712,
"author_profile": "https://Stackoverflow.com/users/2908712",
"pm_score": 2,
"selected": false,
"text": "M-X Dired Q i subdirs dired"
},
{
"answer_id": 21369033,
"author": "Drew",
"author_id": 729907,
"author_profile": "https://Stackoverflow.com/users/729907",
"pm_score": 2,
"selected": false,
"text": "find-name-dired find-dired find find(-name)-dired M-+ M-+ Q Q Q M-+ M-i M-i find(-name)-dired ls"
},
{
"answer_id": 30430842,
"author": "Andrzej Pronobis",
"author_id": 1576602,
"author_profile": "https://Stackoverflow.com/users/1576602",
"pm_score": 1,
"selected": false,
"text": "helm-find-files helm-find-files M-SPC F6 F7"
},
{
"answer_id": 69747660,
"author": "young_souvlaki",
"author_id": 4682839,
"author_profile": "https://Stackoverflow.com/users/4682839",
"pm_score": 1,
"selected": false,
"text": "M-x project-query-replace-regexp RET M-x rgrep RET query-replace"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270930",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25093/"
] |
270,933
|
<p>I have a shell script which copies a few files to the current directory, compresses them, and streams the compressed file to stdout.</p>
<p>On the client side I use plink to execute the script and stream stdin to a file.</p>
<p>This almost works.</p>
<p>It seems that the cp command outputs the file name being copied when its executed from inside the script. If I execute '<strong>cp /path/to/file1 .</strong>' in the shell it does it quietly; if I execute it in a script it outputs "file1".</p>
<p>How do I prevent this? I've tried piping the output of the cp command to /dev/null and to a dummy text file but with no luck.</p>
<p>thanks for any help.</p>
<h3>the script</h3>
<pre><code>#!/bin/bash
cp /path/to/file1 .
cp /path/to/file2 .
cp /path/to/file3 .
tar -cvzf package.tgz file1 file2 file3
cat package.tgz
</code></pre>
<h3>the output</h3>
<pre><code>file1
file2
file3
<<binary data>>
</code></pre>
|
[
{
"answer_id": 271345,
"author": "bendin",
"author_id": 33412,
"author_profile": "https://Stackoverflow.com/users/33412",
"pm_score": 2,
"selected": false,
"text": "stderr stdout -v stderr $ tar cvf - share > /dev/null\nshare/ # this must be going\nshare/.DS_Store # to stderr since we\nshare/man/ # redirected stdout to\nshare/man/.DS_Store # /dev/null above.\nshare/man/man1/\nshare/man/man1/diffmerge.man1\n $ tar cvf blah.tar share > /dev/null\n /dev/null"
},
{
"answer_id": 8102364,
"author": "bigendian",
"author_id": 1013642,
"author_profile": "https://Stackoverflow.com/users/1013642",
"pm_score": 0,
"selected": false,
"text": "tar zcf - file1 file2 file3\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1851/"
] |
270,941
|
<p>I'm using a large open-source control and I can't seem to find the code that handles a double-click event. Could I perhaps have the debugger break when a double-click occurs or otherwise learn what code is associated with that event?</p>
|
[
{
"answer_id": 271345,
"author": "bendin",
"author_id": 33412,
"author_profile": "https://Stackoverflow.com/users/33412",
"pm_score": 2,
"selected": false,
"text": "stderr stdout -v stderr $ tar cvf - share > /dev/null\nshare/ # this must be going\nshare/.DS_Store # to stderr since we\nshare/man/ # redirected stdout to\nshare/man/.DS_Store # /dev/null above.\nshare/man/man1/\nshare/man/man1/diffmerge.man1\n $ tar cvf blah.tar share > /dev/null\n /dev/null"
},
{
"answer_id": 8102364,
"author": "bigendian",
"author_id": 1013642,
"author_profile": "https://Stackoverflow.com/users/1013642",
"pm_score": 0,
"selected": false,
"text": "tar zcf - file1 file2 file3\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22820/"
] |
270,947
|
<p>I write a singleton c++ in the follow way:</p>
<pre><code>class A {
private:
static A* m_pA;
A();
virtual ~A();
public:
static A* GetInstance();
static void FreeInstance();
void WORK1();
void WORK2();
void WORK3();
}
}
A* A::GetInstance() {
if (m_pA == NULL)
m_pA = new A();
return m_pA;
}
A::~A() {
FreeInstance() // Can I write this? are there any potential error?
}
void A::FreeInstance() {
delete m_pA;
m_pA = NULL;
}
</code></pre>
<p>Thanks! Evan Teran and sep61.myopenid.com 's answer is right, and really good!
My way is wrong, I wish any one writting such code can avoid my silly mistake.</p>
<p>My singleton A in my project has a vector of smart pointer, and another thread can also edit this vector, so when the application is closing, it always become unstable even I add lots of CMutex. Multithread error + singleton error wasted me 1 day.<p>
//-----------------------------------------------------------
A new singleton, you are welcome to edit if you think there is any problem in the following sample:</p>
<pre><code>class A {
private:
static A* m_pA;
explicit A();
void A(const A& a);
void A(A &a);
const A& operator=(const A& a);
virtual ~A();
public:
static A* GetInstance();
static void FreeInstance();
void WORK1();
void WORK2();
void WORK3();
}
}
A* A::GetInstance() {
if (m_pA == NULL){
static A self;
m_pA = &self;
}
return m_pA;
}
A::~A() {
}
</code></pre>
|
[
{
"answer_id": 270957,
"author": "Evan Teran",
"author_id": 13430,
"author_profile": "https://Stackoverflow.com/users/13430",
"pm_score": 5,
"selected": true,
"text": "if(m_pA == 0) {\n static A static_instance;\n m_pA = &static_instance;\n}\n"
},
{
"answer_id": 270973,
"author": "sep",
"author_id": 30333,
"author_profile": "https://Stackoverflow.com/users/30333",
"pm_score": 2,
"selected": false,
"text": "static A* A::GetInstance() {\n static A sin;\n return &sin;\n}\n"
},
{
"answer_id": 271104,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 8,
"selected": false,
"text": "class S\n{\n public:\n static S& getInstance()\n {\n static S instance;\n return instance;\n }\n private:\n S() {}\n S(S const&); // Don't Implement.\n void operator=(S const&); // Don't implement\n };\n"
},
{
"answer_id": 54118306,
"author": "amightywind",
"author_id": 7303716,
"author_profile": "https://Stackoverflow.com/users/7303716",
"pm_score": 0,
"selected": false,
"text": "//! @file singleton.h\n//!\n//! @brief Variadic template to make a singleton out of an ordinary type.\n//!\n//! This template makes a singleton out of a type without a default\n//! constructor.\n\n#ifndef SINGLETON_H\n#define SINGLETON_H\n\n#include <stdexcept>\n\ntemplate <typename C, typename ...Args>\nclass singleton\n{\nprivate:\n singleton() = default;\n static C* m_instance;\n\npublic:\n singleton(const singleton&) = delete;\n singleton& operator=(const singleton&) = delete;\n singleton(singleton&&) = delete;\n singleton& operator=(singleton&&) = delete;\n\n ~singleton()\n {\n delete m_instance;\n m_instance = nullptr;\n }\n\n static C& create(Args...args)\n {\n if (m_instance != nullptr)\n {\n delete m_instance;\n m_instance = nullptr;\n }\n m_instance = new C(args...);\n return *m_instance;\n }\n\n static C& instance()\n {\n if (m_instance == nullptr)\n throw std::logic_error(\n \"singleton<>::create(...) must precede singleton<>::instance()\");\n return *m_instance;\n }\n};\n\ntemplate <typename C, typename ...Args>\nC* singleton<C, Args...>::m_instance = nullptr;\n\n#endif // SINGLETON_H\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25749/"
] |
270,948
|
<p>Are there any tricks for preventing SQL Server from entitizing chars like &, <, and >? I'm trying to output a URL in my XML file but SQL wants to replace any '&' with '<code>&amp;</code>'</p>
<p>Take the following query:</p>
<pre><code>SELECT 'http://foosite.com/' + RTRIM(li.imageStore)
+ '/ImageStore.dll?id=' + RTRIM(li.imageID)
+ '&raw=1&rev=' + RTRIM(li.imageVersion) AS imageUrl
FROM ListingImages li
FOR XML PATH ('image'), ROOT ('images'), TYPE
</code></pre>
<p>The output I get is like this (&s are entitized):</p>
<pre><code><images>
<image>
<imageUrl>http://foosite.com/pics4/ImageStore.dll?id=7E92BA08829F6847&amp;raw=1&amp;rev=0</imageUrl>
</image>
</images>
</code></pre>
<p>What I'd like is this (&s are not entitized):</p>
<pre><code><images>
<image>
<imageUrl>http://foosite.com/pics4/ImageStore.dll?id=7E92BA08829F6847&raw=1&rev=0</imageUrl>
</image>
</images>
</code></pre>
<p>How does one prevent SQL server from entitizing the '&'s into '<code>&amp;</code>'?</p>
|
[
{
"answer_id": 271000,
"author": "ykaganovich",
"author_id": 10026,
"author_profile": "https://Stackoverflow.com/users/10026",
"pm_score": 5,
"selected": true,
"text": "& & &"
},
{
"answer_id": 8686690,
"author": "Janmonn",
"author_id": 1124038,
"author_profile": "https://Stackoverflow.com/users/1124038",
"pm_score": 6,
"selected": false,
"text": "select\n stuff(\n (select ', <' + name + '>'\n from sys.databases\n where database_id > 4\n order by name\n for xml path(''), root('MyString'), type\n ).value('/MyString[1]','varchar(max)')\n , 1, 2, '') as namelist;\n"
},
{
"answer_id": 22935091,
"author": "Siva Sankar Gorantla",
"author_id": 2763735,
"author_profile": "https://Stackoverflow.com/users/2763735",
"pm_score": 3,
"selected": false,
"text": "select \n stuff( \n (select ', <' + name + '>' \n from sys.databases \n where database_id > 4 \n order by name \n for xml path(''), root('MyString'), type \n ).value('/MyString[1]','varchar(max)') \n , 1, 2, '') as namelist;\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270948",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19389/"
] |
270,950
|
<p>What is a doubly linked list's remove method?</p>
|
[
{
"answer_id": 271011,
"author": "albertein",
"author_id": 23020,
"author_profile": "https://Stackoverflow.com/users/23020",
"pm_score": 2,
"selected": false,
"text": "public void remove ()\n{\n if (getPreviousNode () != null)\n getPreviousNode ().setNextNode (getNextNode ());\n if (getNextNode () != null)\n getNextNode ().setPreviousNode (getPreviousNode ()); \n}\n"
},
{
"answer_id": 278551,
"author": "ashokgelal",
"author_id": 33203,
"author_profile": "https://Stackoverflow.com/users/33203",
"pm_score": 1,
"selected": false,
"text": "public void remove(int index) {\n if(index<0 || index>size())\n throw new IndexOutOfBoundsException(\"Index out of bounds. Can't remove a node. No node exists at the specified index\");\n if(size()==0) {\n throw new NullPointerException(\"Empty list\");\n }\n if(!isEmpty()) {\n Node current;\n //starting next one to our head\n current = head.next;\n for(int i=0;i<index;i++) {\n current = current.next;\n }\n current.previous.next = current.next;\n current.next.previous = current.previous;\n numOfNodes--;\n sizeChangeCount++;\n }\n}\n\npublic boolean remove(T o) {\n Node current = head;\n for(int i=0;i<size();i++) {\n current=current.next;\n if(current.data.equals(o)) {\n current.previous.next = current.next;\n current.next.previous = current.previous;\n numOfNodes--;\n sizeChangeCount++;\n return true;\n } \n }\n return false;\n}\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270950",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27570/"
] |
270,969
|
<p>I have a migration in Rails that inserts a record into the database. The Category model depends on this record. Since RSpec clears the database before each example, this record is lost and furthermore never seems to be created since RSpec does not seem to generate the database from migrations. What is the best way to create/recreate this record in the database? Would it be using before(:all)?</p>
|
[
{
"answer_id": 271297,
"author": "James Baker",
"author_id": 9365,
"author_profile": "https://Stackoverflow.com/users/9365",
"pm_score": 4,
"selected": true,
"text": "before(:all)"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270969",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34991/"
] |
270,984
|
<p>I'm pretty new to the C++ build flow, and I'm thinking of switching to use partial linking for my libraries instead of creating <code>ar</code> archives. I'm hoping to reduce link time in an inevitable final compilation step that I have, and I figure partial linking some libraries once could save me time over linking everything in that final step.</p>
<p>Is what I'm describing possible? I figure it should be something along the lines <code>ld -Ur -o mylib.o [components]</code>. Are there important build considerations that I'm not taking into account?</p>
|
[
{
"answer_id": 270995,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https://Stackoverflow.com/users/28258",
"pm_score": 4,
"selected": true,
"text": "ar foo.o foo bar ar foo foo.o bar"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270984",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3594/"
] |
270,997
|
<p>I'm looking for an open-source web search library that does not use a search index file.
Do you know any?</p>
<p>Thanks,
Kenneth</p>
|
[
{
"answer_id": 271037,
"author": "Will Hartung",
"author_id": 13663,
"author_profile": "https://Stackoverflow.com/users/13663",
"pm_score": 1,
"selected": false,
"text": "#/bin/sh\narg=`echo $QUERY | sed -e 's/^s=//' -e 's/&.*$//'`\ncd /var/www/httpd\nfind . -type f | xargs egrep -l \"$arg\" | awk 'BEGIN { \n print \"Content-type: text/html\"; \n print \"\";\n print \"<HTML><HEAD><TITLE>Search Result</TITLE></HEAD>\";\n print \"<BODY><P>Here are your search results, sorry it took so long.</P>\";\n print \"<UL>\";\n }\n { print \"<LI><A HREF=\\\"http://yourhost.com/\" $1 \"\\\">\" $1 \"</A></LI>\"; }\n END {\n print \"</UL></BODY>\";\n }'\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/270997",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16139/"
] |
271,007
|
<p>Lots of people have things that their systems do for them or for their teams. Source control post-commit hooks are a standard example: have an automated build system that checks out the latest source, compiles, tests, and packages it is a back-office hack that most of us probably use.</p>
<p>What other cool things have you done?</p>
|
[
{
"answer_id": 543664,
"author": "gradbot",
"author_id": 17919,
"author_profile": "https://Stackoverflow.com/users/17919",
"pm_score": 2,
"selected": false,
"text": "joe.jetfuel.test-example.com htdocs/tag/project setup.test-example.com jquery-menu-hack.jetfuel.test-example.com"
},
{
"answer_id": 544809,
"author": "James Matta",
"author_id": 60483,
"author_profile": "https://Stackoverflow.com/users/60483",
"pm_score": 0,
"selected": false,
"text": "-include prereqs.mk\nHEADERS=$(SRC_DIR)/gs_lib.h $(SRC_DIR)/gs_structs.h\nSOURCES=$(SRC_DIR)/main.cpp $(SRC_DIR)/gs_lib.cpp\nOBJECTS=$(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SOURCES))\n\nrelease: FLAGS=$(GEN_FLAGS)$(OPT_FLAGS)\nrelease: $(OBJECTS) prereqs.mk\n $(CXX) $(FLAGS) $(LINKER_FLAGS) $(OUTPUT_FLAG) $(EXECUTABLE) $(OBJECTS)\n\nprereqs.mk: $(SOURCES) $(HEADERS)\n $(CXX) $(DIR_FLAGS) $(MAKE_FLAG) $(SOURCES) | sed 's,\\([abcdefghijklmnopqrstuvwxyz_]*\\).o:,\\1= \\\\\\n,' > $@\n\n.SECONDEXPANSION:\n$(OBJECTS): $$($$(patsubst $(OBJ_DIR)/%.o,%,$$@))\n $(CXX) $(FLAGS) $(NO_LINK_FLAG) $(OUTPUT_FLAG) $@ $(patsubst $(OBJ_DIR)/%.o,$(SRC_DIR)/%.cpp,$@)\n"
},
{
"answer_id": 650888,
"author": "Macke",
"author_id": 72312,
"author_profile": "https://Stackoverflow.com/users/72312",
"pm_score": 0,
"selected": false,
"text": "f:/maya/my-textures/newproject/xxxx.png"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271007",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6010/"
] |
271,015
|
<p>I need to write a Stored procedure in SQL server whose data returned will be used to generate a XML file.</p>
<p>My XML file to be in structure of </p>
<pre><code><root>
<ANode></ANode>
<BNode></BNode>
<CNode>
<C1Node>
<C11Node></C11Node>
<C12Node></C12Node>
</C1Node>
<C2Node>
<C21Node></C21Node>
<C22Node></C22Node>
</C2Node>
<C3Node>
<C31Node></C31Node>
<C32Node></C32Node>
</C3Node>
</CNode>
</root>
</code></pre>
<p>My question is, in the stored procedure we can select values for ANode and BNode as a simple SELECT statement like</p>
<pre><code>Select ANodeVal,BNodeVal from Table
</code></pre>
<p>But how to design the stored procedure to get records for the CNode which is a subtree which has 3 or more(dynamic) separate nodes in it for each record in addition to the normal ANode and BNode.</p>
|
[
{
"answer_id": 271202,
"author": "Doug L.",
"author_id": 19179,
"author_profile": "https://Stackoverflow.com/users/19179",
"pm_score": 0,
"selected": false,
"text": "SELECT"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3113/"
] |
271,021
|
<p>I've recently seen occasional problems with stored procedures on a legacy system which displays error messages like this:</p>
<blockquote>
<p>Server Message: Number 10901, Severity 17:
This query requires <em>X</em> auxiliary scan
descriptors but currently there are
only <em>Y</em> auxiliary scan descriptors
available. Either raise the value of
the 'number of aux scan descriptors'
configuration parameter or try your
query later.</p>
</blockquote>
<p>where <em>X</em> is slightly lower than <em>Y</em>. The Sybase manual usefully tells me that I should redesign my table to use less auxiliary scan descriptors (how?!), or increase the number available on the system. The weird thing is, it's been working fine for years and the only thing that's changed is that we amended the data types of a couple of columns and added an index. Can anyone shed any light on this?</p>
|
[
{
"answer_id": 271660,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": true,
"text": "update statistics *table_name*\n sp_monitorconfig \"aux scan descriptors\"\n sp_configure \"aux scan descriptors\", x\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271021",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1030/"
] |
271,031
|
<p>My application needs to store the users email address in a cookie so that I can pre-populate a login form <code>(username == email address)</code>. I set the cookie value in JavaScript. If I read it from JavaScript, I get <code>foo@bar.com</code>. If I look at it in the cookie viewer in Firefox I get <code>foo@bar.com</code>.</p>
<p>When I try to read it on the server-side in Java however, I only get <code>foo</code>. </p>
<p>Do I need to do some sort of encoding/decoding here? If so, how do I do it in a way that can be decoded by both JavaScript and Java? </p>
<p>Thanks in advance!
-Michael</p>
|
[
{
"answer_id": 271038,
"author": "Glen",
"author_id": 269171,
"author_profile": "https://Stackoverflow.com/users/269171",
"pm_score": 0,
"selected": false,
"text": "document.cookie = name + \"=\" +escape( value ) \n + ( ( expires ) ? \";expires=\" + expires_date.toGMTString() : \"\" )\n + ( ( path ) ? \";path=\" + path : \"\" ) \n + ( ( domain ) ? \";domain=\" + domain : \"\" ) \n + ( ( secure ) ? \";secure\" : \"\" );\n"
},
{
"answer_id": 273584,
"author": "bowmanmc",
"author_id": 3700,
"author_profile": "https://Stackoverflow.com/users/3700",
"pm_score": 0,
"selected": false,
"text": "public class CookieDecoder {\n\nprivate static final Log log = LogFactory.getLog(CookieDecoder.class);\n\n/**\n * @param cookieValue The value of the cookie to decode\n * @return Returns the decoded string\n */\npublic String decode(String cookieValue) {\n if (cookieValue == null || \"\".equals(cookieValue)) {\n return null;\n }\n if (!cookieValue.endsWith(\"=\")) {\n cookieValue = padString(cookieValue);\n }\n if (log.isDebugEnabled()) {\n log.debug(\"Decoding string: \" + cookieValue);\n }\n Base64 base64 = new Base64();\n byte[] encodedBytes = cookieValue.getBytes();\n byte[] decodedBytes = base64.decode(encodedBytes);\n String result = new String(decodedBytes);\n if (log.isDebugEnabled()) {\n log.debug(\"Decoded string to: \" + result);\n }\n return result;\n}\n\nprivate String padString(String value) {\n int mod = value.length() % 4;\n if (mod <= 0) {\n return value;\n }\n int numEqs = 4 - mod;\n if (log.isDebugEnabled()) {\n log.debug(\"Padding value with \" + numEqs + \" = signs\");\n }\n for (int i = 0; i < numEqs; i++) {\n value += \"=\";\n }\n return value;\n}\n}\n var encodedValue = this.base64.encode(value);\ndocument.cookie = name + \"=\" + encodedValue + \n \"; expires=\" + this.expires.toGMTString() + \n \"; path=\" + this.path;\n"
},
{
"answer_id": 273595,
"author": "bowmanmc",
"author_id": 3700,
"author_profile": "https://Stackoverflow.com/users/3700",
"pm_score": 0,
"selected": false,
"text": "public class CookieDecoder {\n\n private static final Log log = LogFactory.getLog(CookieDecoder.class);\n\n /**\n * @param cookieValue The value of the cookie to decode\n * @return Returns the decoded string\n */\n public String decode(String cookieValue) {\n if (cookieValue == null || \"\".equals(cookieValue)) {\n return null;\n }\n if (log.isDebugEnabled()) {\n log.debug(\"Decoding string: \" + cookieValue);\n }\n URLCodec urlCodec = new URLCodec();\n String b64Str;\n try {\n b64Str = urlCodec.decode(cookieValue);\n }\n catch (DecoderException e) {\n log.error(\"Error decoding string: \" + cookieValue);\n return null;\n }\n Base64 base64 = new Base64();\n byte[] encodedBytes = b64Str.getBytes();\n byte[] decodedBytes = base64.decode(encodedBytes);\n String result = new String(decodedBytes);\n if (log.isDebugEnabled()) {\n log.debug(\"Decoded string to: \" + result);\n }\n return result;\n }\n}\n var encodedValue = this.base64.encode(value);\ndocument.cookie = name + \"=\" + escape(encodedValue) + \n \"; expires=\" + this.expires.toGMTString() + \n \"; path=\" + this.path;\n var nameEQ = name + \"=\";\nvar ca = document.cookie.split(';');\nfor(var i = 0; i < ca.length; i++) {\n var c = ca[i];\n while (c.charAt(0)==' ') {\n c = c.substring(1,c.length);\n }\n if (c.indexOf(nameEQ) == 0) {\n var encodedValue = c.substring(nameEQ.length,c.length);\n return this.base64.decode(unescape(encodedValue));\n }\n}\nreturn null;\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3700/"
] |
271,042
|
<p>Here's something I know is probably possible but I've never managed to do<br>
In VS2005(C++), While debugging, to be able to invoke a function from the code which I'm debugging.<br>
This feature is sometimes essential when debugging complex data structures which can't be explored easily using just the normal capabilities of the watch window.<br>
The watch window seem to allow writing function calls but every time I try it it gives me one error or another. </p>
<p><code>Error: symbol "func" not found</code><br>
<code>Error: argument list does not match function</code><br>
<code>Error: member function not present</code></p>
<p>Did anyone ever succeed in making this work properly?
What am I missing here?</p>
<p><strong>Edit:</strong> clearly, the function called should be a symbol that exists in the current scope the debugger is in.</p>
|
[
{
"answer_id": 271091,
"author": "shoosh",
"author_id": 9611,
"author_profile": "https://Stackoverflow.com/users/9611",
"pm_score": 5,
"selected": true,
"text": "The C expression evaluator does not support implicit conversions involving constructor calls. Overloaded functions can be called only if there is an exact parameter match or a match that does not require the construction of an object. 'String' 'const String&'"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271042",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9611/"
] |
271,043
|
<p>I'm using jQuery to post a form to a php file, simple script to verify user details.</p>
<pre><code>var emailval = $("#email").val();
var invoiceIdval = $("#invoiceId").val();
$.post("includes/verify.php",
{invoiceId:invoiceIdval , email:emailval },
function(data) {
//stuff here.
});
</code></pre>
<p>PHP Code:</p>
<pre><code><?php
print_r($_POST);
?>
</code></pre>
<p>I look at the response in firebug, it is an empty array. The array should have at least some value.</p>
<p>I can not work out why the <code>$_POST</code> isn't working in the php file. Firebug shows the post to contain the contents posted, email and invoice id, just nothing is actually received in the php file.</p>
<p>The form:</p>
<pre><code><form method="post" action="<?=$_SERVER['PHP_SELF']; ?>" enctype="application/x-www-form-urlencoded">
</code></pre>
<p>Anyone know what its doing?</p>
<p>thanks</p>
<hr>
<p>found this - <a href="http://www.bradino.com/php/empty-post-array/" rel="nofollow noreferrer">http://www.bradino.com/php/empty-post-array/</a></p>
<p>that a sensible route to go?</p>
|
[
{
"answer_id": 271064,
"author": "Douglas Mayle",
"author_id": 8458,
"author_profile": "https://Stackoverflow.com/users/8458",
"pm_score": 1,
"selected": false,
"text": "application/x-www-form-urlencoded\n"
},
{
"answer_id": 271094,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 5,
"selected": true,
"text": "$.post() $.ajax() application/x-www-form-urlencoded var post = $('#myForm').serialize(); \n\n$.post(\"includes/verify.php\", post, function(data) { \n alert(data);\n});\n serialize() form.myForm"
},
{
"answer_id": 7413265,
"author": "Josh P",
"author_id": 477361,
"author_profile": "https://Stackoverflow.com/users/477361",
"pm_score": -1,
"selected": false,
"text": "$('input').attr('disabled',true);\n $('input[type=button]').attr('disabled',true);\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271043",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34975/"
] |
271,045
|
<p>I'm new to the MVC framework and wondering how to pass the RSS data from the controller to a view. I know there is a need to convert to an IEnumerable list of some sort. I have seen some examples of creating an anonymous type but can not figure out how to convert an RSS feed to a generic list and pass it to the view. </p>
<p>I don't want it to be strongly typed either as there will be multiple calls to various RSS feeds. </p>
<p>Any suggestions. </p>
|
[
{
"answer_id": 272576,
"author": "Matthew",
"author_id": 20162,
"author_profile": "https://Stackoverflow.com/users/20162",
"pm_score": 4,
"selected": true,
"text": "using (XmlReader reader = XmlReader.Create(feed))\n{\n SyndicationFeed rssData = SyndicationFeed.Load(reader);\n\n return View(rssData);\n }\n using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Web;\nusing System.Web.Mvc;\nusing System.Web.Mvc.Ajax;\nusing System.Xml;\nusing System.ServiceModel.Syndication;\nusing System.Security;\nusing System.IO;\n\nnamespace MvcWidgets.Controllers\n{\n public class RssWidgetController : Controller\n {\n public ActionResult Index(string feed)\n {\n string errorString = \"\";\n\n try\n {\n if (String.IsNullOrEmpty(feed))\n {\n throw new ArgumentNullException(\"feed\");\n }\n **using (XmlReader reader = XmlReader.Create(feed))\n {\n SyndicationFeed rssData = SyndicationFeed.Load(reader);\n\n return View(rssData);\n }**\n }\n catch (ArgumentNullException)\n {\n errorString = \"No url for Rss feed specified.\";\n }\n catch (SecurityException)\n {\n errorString = \"You do not have permission to access the specified Rss feed.\";\n }\n catch (FileNotFoundException)\n {\n errorString = \"The Rss feed was not found.\";\n }\n catch (UriFormatException)\n {\n errorString = \"The Rss feed specified was not a valid URI.\";\n }\n catch (Exception)\n {\n errorString = \"An error occured accessing the RSS feed.\";\n }\n\n var errorResult = new ContentResult();\n errorResult.Content = errorString;\n return errorResult;\n\n }\n }\n}\n <%@ Control Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"Index.ascx.cs\" Inherits=\"MvcWidgets.Views.RssWidget.Index\" %>\n<div class=\"RssFeedTitle\"><%= Html.Encode(ViewData.Model.Title.Text) %> <%= Html.Encode(ViewData.Model.LastUpdatedTime.ToString(\"MMM dd, yyyy hh:mm:ss\") )%></div>\n\n<div class='RssContent'>\n<% foreach (var item in ViewData.Model.Items)\n {\n string url = item.Links[0].Uri.OriginalString;\n %>\n <p><a href='<%= url %>'><b> <%= item.Title.Text%></b></a>\n <% if (item.Summary != null)\n {%>\n <br/> <%= item.Summary.Text %>\n <% }\n } %> </p>\n</div>\n using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Web;\nusing System.Web.Mvc;\nusing System.ServiceModel.Syndication;\n\nnamespace MvcWidgets.Views.RssWidget\n{\n public partial class Index : System.Web.Mvc.ViewUserControl<SyndicationFeed>\n {\n }\n}\n"
},
{
"answer_id": 3146522,
"author": "viperguynaz",
"author_id": 379677,
"author_profile": "https://Stackoverflow.com/users/379677",
"pm_score": 3,
"selected": false,
"text": "<%@ Page Language=\"C#\" MasterPageFile=\"~/Views/Shared/Site.Master\" Inherits=\"System.Web.Mvc.ViewPage<SyndicationFeed>\" %> \n<%@ Import Namespace=\"System.ServiceModel.Syndication\" %>\n"
},
{
"answer_id": 8838606,
"author": "lko",
"author_id": 878612,
"author_profile": "https://Stackoverflow.com/users/878612",
"pm_score": 1,
"selected": false,
"text": "public ActionResult RSS(string id)\n{ \n return return File(MyModel.CreateFeed(id), \"application/rss+xml; charset=utf-8\");\n}\n CreateFeed(string id)\n{ \n SyndicationFeed feed = new SyndicationFeed( ... as in the MS link above)\n\n .... (as in the MS link)\n\n //(from the SO Link)\n var settings = new XmlWriterSettings \n { \n Encoding = Encoding.UTF8, \n NewLineHandling = NewLineHandling.Entitize, \n NewLineOnAttributes = true, \n Indent = true \n };\n using (var stream = new MemoryStream())\n using (var writer = XmlWriter.Create(stream, settings))\n {\n feed.SaveAsRss20(writer);\n writer.Flush();\n return stream.ToArray();\n }\n\n\n}\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271045",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31148/"
] |
271,062
|
<p>I'm using Emgu.CV which is a C# wrapper for the OpenCV libraries. </p>
<p>I changed the Emgu.CV source to invoke from the latest OpenCV library cv110.dll instead of cv100.dll and now I get this error (where ????? is cv110.dll). I have placed the cv110.dll file in all the same locations as the cv100.dll file however this does not help.</p>
<p>On a broader scale, what is the folder search order when looking for dlls, and are there anyone other reasons for this error.</p>
|
[
{
"answer_id": 272576,
"author": "Matthew",
"author_id": 20162,
"author_profile": "https://Stackoverflow.com/users/20162",
"pm_score": 4,
"selected": true,
"text": "using (XmlReader reader = XmlReader.Create(feed))\n{\n SyndicationFeed rssData = SyndicationFeed.Load(reader);\n\n return View(rssData);\n }\n using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Web;\nusing System.Web.Mvc;\nusing System.Web.Mvc.Ajax;\nusing System.Xml;\nusing System.ServiceModel.Syndication;\nusing System.Security;\nusing System.IO;\n\nnamespace MvcWidgets.Controllers\n{\n public class RssWidgetController : Controller\n {\n public ActionResult Index(string feed)\n {\n string errorString = \"\";\n\n try\n {\n if (String.IsNullOrEmpty(feed))\n {\n throw new ArgumentNullException(\"feed\");\n }\n **using (XmlReader reader = XmlReader.Create(feed))\n {\n SyndicationFeed rssData = SyndicationFeed.Load(reader);\n\n return View(rssData);\n }**\n }\n catch (ArgumentNullException)\n {\n errorString = \"No url for Rss feed specified.\";\n }\n catch (SecurityException)\n {\n errorString = \"You do not have permission to access the specified Rss feed.\";\n }\n catch (FileNotFoundException)\n {\n errorString = \"The Rss feed was not found.\";\n }\n catch (UriFormatException)\n {\n errorString = \"The Rss feed specified was not a valid URI.\";\n }\n catch (Exception)\n {\n errorString = \"An error occured accessing the RSS feed.\";\n }\n\n var errorResult = new ContentResult();\n errorResult.Content = errorString;\n return errorResult;\n\n }\n }\n}\n <%@ Control Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"Index.ascx.cs\" Inherits=\"MvcWidgets.Views.RssWidget.Index\" %>\n<div class=\"RssFeedTitle\"><%= Html.Encode(ViewData.Model.Title.Text) %> <%= Html.Encode(ViewData.Model.LastUpdatedTime.ToString(\"MMM dd, yyyy hh:mm:ss\") )%></div>\n\n<div class='RssContent'>\n<% foreach (var item in ViewData.Model.Items)\n {\n string url = item.Links[0].Uri.OriginalString;\n %>\n <p><a href='<%= url %>'><b> <%= item.Title.Text%></b></a>\n <% if (item.Summary != null)\n {%>\n <br/> <%= item.Summary.Text %>\n <% }\n } %> </p>\n</div>\n using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Web;\nusing System.Web.Mvc;\nusing System.ServiceModel.Syndication;\n\nnamespace MvcWidgets.Views.RssWidget\n{\n public partial class Index : System.Web.Mvc.ViewUserControl<SyndicationFeed>\n {\n }\n}\n"
},
{
"answer_id": 3146522,
"author": "viperguynaz",
"author_id": 379677,
"author_profile": "https://Stackoverflow.com/users/379677",
"pm_score": 3,
"selected": false,
"text": "<%@ Page Language=\"C#\" MasterPageFile=\"~/Views/Shared/Site.Master\" Inherits=\"System.Web.Mvc.ViewPage<SyndicationFeed>\" %> \n<%@ Import Namespace=\"System.ServiceModel.Syndication\" %>\n"
},
{
"answer_id": 8838606,
"author": "lko",
"author_id": 878612,
"author_profile": "https://Stackoverflow.com/users/878612",
"pm_score": 1,
"selected": false,
"text": "public ActionResult RSS(string id)\n{ \n return return File(MyModel.CreateFeed(id), \"application/rss+xml; charset=utf-8\");\n}\n CreateFeed(string id)\n{ \n SyndicationFeed feed = new SyndicationFeed( ... as in the MS link above)\n\n .... (as in the MS link)\n\n //(from the SO Link)\n var settings = new XmlWriterSettings \n { \n Encoding = Encoding.UTF8, \n NewLineHandling = NewLineHandling.Entitize, \n NewLineOnAttributes = true, \n Indent = true \n };\n using (var stream = new MemoryStream())\n using (var writer = XmlWriter.Create(stream, settings))\n {\n feed.SaveAsRss20(writer);\n writer.Flush();\n return stream.ToArray();\n }\n\n\n}\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271062",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31045/"
] |
271,063
|
<p>I would like to to try Emacs, and want to give it the best chance possible.</p>
<p>To do this, it seems like having a good <code>.emacs</code> file is important.</p>
<p>I primarily use Mac OS X (so I have looked at Aquamacs), and I mainly do Python programming, so anything specifically for that would be great.</p>
|
[
{
"answer_id": 281944,
"author": "Tim Visher",
"author_id": 16562,
"author_profile": "https://Stackoverflow.com/users/16562",
"pm_score": 2,
"selected": false,
"text": "Caps-lock = Control\nControl = Option\nOption = Inactive\nCommand = Command\n sudo port install emacs-app\n"
},
{
"answer_id": 12220507,
"author": "whunmr",
"author_id": 201794,
"author_profile": "https://Stackoverflow.com/users/201794",
"pm_score": 2,
"selected": false,
"text": "(require 'smooth-scrolling)\n(require 'multiple-cursors)\n(require 'ace-jump-mode)\n(require 'expand-region)\n(require 'inline-string-rectangle)\n(require 'mark-more-like-this)\n(require 'key-chord)\n(require 'browse-kill-ring)\n(require 'idle-highlight-mode)\n(require 'htmlize)\n(require 'icicles)\n(require 'highlight-parentheses)\n(require 'golden-ratio)\n(require 'projectile)\n(require 'helm-projectile)\n(require 'rainbow-mode)\n(require 'anything-config)\n(require 'highlight-symbol)\n(require 'markerpen)\n(require 'flyspell)\n (define-key input-decode-map (kbd \"C-i\") (kbd \"H-i\"))\n(define-key input-decode-map (kbd \"C-M-i\") (kbd \"H-M-i\"))\n(global-set-key (kbd \"H-i\") 'kill-ring-save)\n(global-set-key (kbd \"M-i\") 'kill-ring-save)\n(global-set-key (kbd \"H-M-i\") 'ace-jump-line-mode)\n(global-set-key (kbd \"C-c H-i\") 'ido-switch-buffer)\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271063",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/745/"
] |
271,067
|
<p>I have the following CSS and HTML snippet being rendered.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>textarea
{
border:1px solid #999999;
width:100%;
margin:5px 0;
padding:3px;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div style="display: block;" id="rulesformitem" class="formitem">
<label for="rules" id="ruleslabel">Rules:</label>
<textarea cols="2" rows="10" id="rules"></textarea>
</div></code></pre>
</div>
</div>
</p>
<p>Is the problem is that the text area ends up being 8px wider (2px for border + 6px for padding) than the parent. Is there a way to continue to use border and padding but constrain the total size of the <code>textarea</code> to the width of the parent?</p>
|
[
{
"answer_id": 272632,
"author": "Dave Sherohman",
"author_id": 18914,
"author_profile": "https://Stackoverflow.com/users/18914",
"pm_score": 7,
"selected": false,
"text": "textarea\n{\n width:100%;\n}\n.textwrapper\n{\n border:1px solid #999999;\n margin:5px 0;\n padding:3px;\n} <div style=\"display: block;\" id=\"rulesformitem\" class=\"formitem\">\n <label for=\"rules\" id=\"ruleslabel\">Rules:</label>\n <div class=\"textwrapper\"><textarea cols=\"2\" rows=\"10\" id=\"rules\"/></div>\n</div>"
},
{
"answer_id": 272733,
"author": "Chris James",
"author_id": 3193,
"author_profile": "https://Stackoverflow.com/users/3193",
"pm_score": 4,
"selected": false,
"text": "textarea\n{\n border:1px solid #999999;\n width:98%;\n margin:5px 0;\n padding:1%;\n}\n"
},
{
"answer_id": 2499203,
"author": "Emanuele Del Grande",
"author_id": 299801,
"author_profile": "https://Stackoverflow.com/users/299801",
"pm_score": 5,
"selected": false,
"text": ".container { \n width: 400px; \n border: 3px \n solid #f7c; \n }\n.textareaContainer {\n display: block;\n border: 3px solid #38c;\n padding: 10px;\n }\ntextarea { \n width: 100%; \n margin: 0; \n padding: 0; \n border-width: 0; \n } <body>\n<div class=\"container\">\n I am the container\n <label class=\"textareaContainer\">\n <textarea name=\"text\">I am the padded textarea with a styled border...</textarea>\n </label>\n</div>\n</body>"
},
{
"answer_id": 4156343,
"author": "Piet Bijl",
"author_id": 232872,
"author_profile": "https://Stackoverflow.com/users/232872",
"pm_score": 11,
"selected": true,
"text": ".boxsizingBorder {\n -webkit-box-sizing: border-box;\n -moz-box-sizing: border-box;\n box-sizing: border-box;\n}\n"
},
{
"answer_id": 6876052,
"author": "Brian",
"author_id": 244191,
"author_profile": "https://Stackoverflow.com/users/244191",
"pm_score": 4,
"selected": false,
"text": "textarea{\n border:1px solid #999999;\n width:100%;\n margin:5px 0;\n padding:3px;\n}\n.textareacontainer{\n padding-right: 8px; /* 1 + 3 + 3 + 1 */\n}\n <div class=\"textareacontainer\">\n <textarea></textarea>\n</div>\n"
},
{
"answer_id": 11041279,
"author": "meustrus",
"author_id": 710377,
"author_profile": "https://Stackoverflow.com/users/710377",
"pm_score": 0,
"selected": false,
"text": "textarea {\n border:1px solid #999999;\n width:100%;\n margin:5px -4px; /* 4px = border+padding on one side */\n padding:3px;\n}\n"
},
{
"answer_id": 15798921,
"author": "commonpike",
"author_id": 95733,
"author_profile": "https://Stackoverflow.com/users/95733",
"pm_score": 1,
"selected": false,
"text": "textarea\n{\n border:1px solid #999999;\n width:100%;\n padding: 7px 0 7px 7px; \n position:relative; left:-8px; /* 1px border, too */\n}\n"
},
{
"answer_id": 19942900,
"author": "Jeff Guest",
"author_id": 2985580,
"author_profile": "https://Stackoverflow.com/users/2985580",
"pm_score": 4,
"selected": false,
"text": "<td>\n <textarea style=\"width:100%\" rows=3 name=\"abc\">Modify width:% accordingly</textarea>\n</td>\n"
},
{
"answer_id": 25103051,
"author": "user3074446",
"author_id": 3074446,
"author_profile": "https://Stackoverflow.com/users/3074446",
"pm_score": 1,
"selected": false,
"text": "-moz-box-sizing:border-box; \n-webkit-box-sizing:border-box; \nbox-sizing:border-box;\n"
},
{
"answer_id": 25185897,
"author": "Gwi7d31",
"author_id": 1659082,
"author_profile": "https://Stackoverflow.com/users/1659082",
"pm_score": 1,
"selected": false,
"text": "textarea.form-conrtol{\n height:auto;\n}\n"
},
{
"answer_id": 40606642,
"author": "Jeroen Bellemans",
"author_id": 4118983,
"author_profile": "https://Stackoverflow.com/users/4118983",
"pm_score": 1,
"selected": false,
"text": "calc() textarea {\n border: 0px;\n width: calc(100% -10px);\n padding: 5px; \n}\n textarea {\n border: 1px;\n width: calc(100% -12px); /* plus the total left and right border */\n padding: 5px; \n}\n"
},
{
"answer_id": 48556129,
"author": "antelove",
"author_id": 7656367,
"author_profile": "https://Stackoverflow.com/users/7656367",
"pm_score": 0,
"selected": false,
"text": "* {\n box-sizing: border-box;\n}\n\n.container {\n border-radius: 5px;\n background-color: #f2f2f2;\n padding: 20px;\n}\n\n/* Clear floats after the columns */\n.row:after {\n content: \"\";\n display: table;\n clear: both;\n}\n\ninput[type=text], select, textarea{\n width: 100%;\n padding: 12px;\n border: 1px solid #ccc;\n border-radius: 4px;\n box-sizing: border-box;\n resize: vertical;\n} <div class=\"container\">\n <div class=\"row\">\n <label for=\"name\">Name</label>\n <input type=\"text\" id=\"name\" name=\"name\" placeholder=\"Your name..\">\n </div>\n <div class=\"row\">\n <label for=\"country\">Country</label>\n <select id=\"country\" name=\"country\">\n <option value=\"australia\">UK</option>\n <option value=\"canada\">USA</option>\n <option value=\"usa\">RU</option>\n </select>\n </div> \n <div class=\"row\">\n <label for=\"subject\">Subject</label>\n <textarea id=\"subject\" name=\"subject\" placeholder=\"Write something..\" style=\"height:200px\"></textarea>\n </div>\n</div>"
},
{
"answer_id": 52925521,
"author": "Jee Mok",
"author_id": 9206753,
"author_profile": "https://Stackoverflow.com/users/9206753",
"pm_score": 3,
"selected": false,
"text": "<div style=\"width: 100%; max-width: 500px;\">\n <textarea style=\"width: 100%;\"></textarea>\n</div>\n"
},
{
"answer_id": 67253039,
"author": "Ali Baghban",
"author_id": 10617518,
"author_profile": "https://Stackoverflow.com/users/10617518",
"pm_score": 2,
"selected": false,
"text": "box-sizing box-sizing content-box textarea {\n border:1px solid #999999;\n width:100%;\n margin:5px 0;\n padding:3px;\n box-sizing: content-box;\n}\n box-sizing: content-box; box-sizing: border-box; horizontal border + horizontal padding + width of content box = width\n"
},
{
"answer_id": 73535847,
"author": "Stokely",
"author_id": 5555938,
"author_profile": "https://Stackoverflow.com/users/5555938",
"pm_score": 0,
"selected": false,
"text": "<style type=\"text/css\">\n body textarea,\n body textarea:visited,\n body textarea:hover,\n body textarea:focus,\n body textarea:active {\n display: block;\n width: auto;\n height: auto;\n min-width: 100%;\n min-height: 10em;\n padding: 1em;\n margin: 0;\n -webkit-appearance: textarea;\n -moz-appearance: textfield-multiline;\n cursor: text;\n overflow: auto;\n resize: both;\n background-color: #eee;\n word-wrap: normal;\n border: 2px solid #bbb;\n border-radius: .2em;\n font-family:inherit;\n line-height: normal;\n}\n\ndiv {\n border:2px solid blue;\n}\n\ntextarea,div {\n box-sizing: border-box;\n -webkit-box-sizing: border-box;\n -moz-box-sizing: border-box;\n}\n</style>\n\n<div>\n <textarea>Some test text...</textarea>\n</div>\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271067",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] |
271,076
|
<p>Correct me if I am wrong,</p>
<p>int is 4 bytes, with a range of values from -2,147,483,648 to 2,147,483,647 (2^31)<br>
long is 4 bytes, with a range of values from -2,147,483,648 to 2,147,483,647 (2^31)</p>
<p>What is the difference in C++? Can they be used interchangeably?</p>
|
[
{
"answer_id": 271087,
"author": "Rob Walker",
"author_id": 3631,
"author_profile": "https://Stackoverflow.com/users/3631",
"pm_score": 8,
"selected": true,
"text": " OS arch size\nWindows IA-32 4 bytes\nWindows Intel 64 4 bytes\nWindows IA-64 4 bytes\nLinux IA-32 4 bytes\nLinux Intel 64 8 bytes\nLinux IA-64 8 bytes\nMac OS X IA-32 4 bytes\nMac OS X Intel 64 8 bytes \n"
},
{
"answer_id": 271107,
"author": "Kevin Haines",
"author_id": 10410,
"author_profile": "https://Stackoverflow.com/users/10410",
"pm_score": 4,
"selected": false,
"text": "signed char short int int long int <climits>"
},
{
"answer_id": 271132,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 6,
"selected": false,
"text": "sizeof(char) == 1\nsizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)\n\n// FROM @KTC. The C++ standard also has:\nsizeof(signed char) == 1\nsizeof(unsigned char) == 1\n\n// NOTE: These size are not specified explicitly in the standard.\n// They are implied by the minimum/maximum values that MUST be supported\n// for the type. These limits are defined in limits.h\nsizeof(short) * CHAR_BIT >= 16\nsizeof(int) * CHAR_BIT >= 16\nsizeof(long) * CHAR_BIT >= 32\nsizeof(long long) * CHAR_BIT >= 64\nCHAR_BIT >= 8 // Number of bits in a byte\n long"
},
{
"answer_id": 271143,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 3,
"selected": false,
"text": "UINT_MAX USHRT_MAX ULONG_MAX CHAR_BIT CHAR_BIT"
},
{
"answer_id": 271200,
"author": "Roger Nelson",
"author_id": 14964,
"author_profile": "https://Stackoverflow.com/users/14964",
"pm_score": 3,
"selected": false,
"text": "int8_t uint8_t int16_t int32_t uint32_t INT8 UINT8 INT16 UINT16 INT32 UINT32 int8 uint8 int16 uint16 int32 uint32 #include #ifndef primitiveH\n#define primitiveH\n// Header file primitive.h\n// Primitive types\n// For C and/or C++\n// This header file is intended to define a set of primitive types\n// that will always be the same number bytes on any operating operating systems\n// and/or for several popular C/C++ compiler vendors.\n// Currently the type definitions cover:\n// Windows (16 or 32 bit)\n// Linux\n// UNIX (HP/US, Solaris)\n// And the following compiler vendors\n// Microsoft, Borland/Imprise/CodeGear, SunStudio, HP/UX\n// (maybe GNU C/C++)\n// This does not currently include 64bit primitives.\n#define float64 double\n#define float32 float\n// Some old C++ compilers didn't have bool type\n// If your compiler does not have bool then add emulate_bool\n// to your command line -D option or defined macros.\n#ifdef emulate_bool\n# ifdef TVISION\n# define bool int\n# define true 1\n# define false 0\n# else\n# ifdef __BCPLUSPLUS__\n //BC++ bool type not available until 5.0\n# define BI_NO_BOOL\n# include <classlib/defs.h>\n# else\n# define bool int\n# define true 1\n# define false 0\n# endif\n# endif\n#endif\n#ifdef __BCPLUSPLUS__\n# include <systypes.h>\n#else\n# ifdef unix\n# ifdef hpux\n# include <sys/_inttypes.h>\n# endif\n# ifdef sun\n# include <sys/int_types.h>\n# endif\n# ifdef linux\n# include <idna.h>\n# endif\n# define int8 int8_t\n# define uint8 uint8_t\n# define int16 int16_t\n# define int32 int32_t\n# define uint16 uint16_t\n# define uint32 uint32_t\n# else\n# ifdef _MSC_VER\n# include <BaseTSD.h>\n# define int8 INT8\n# define uint8 UINT8\n# define int16 INT16\n# define int32 INT32\n# define uint16 UINT16\n# define uint32 UINT32\n# else\n# ifndef OWL6\n// OWL version 6 already defines these types\n# define int8 char\n# define uint8 unsigned char\n# ifdef __WIN32_\n# define int16 short int\n# define int32 long\n# define uint16 unsigned short int\n# define uint32 unsigned long\n# else\n# define int16 int\n# define int32 long\n# define uint16 unsigned int\n# define uint32 unsigned long\n# endif\n# endif\n# endif\n# endif\n#endif\ntypedef int8 sint8;\ntypedef int16 sint16;\ntypedef int32 sint32;\ntypedef uint8 nat8;\ntypedef uint16 nat16;\ntypedef uint32 nat32;\ntypedef const char * cASCIIz; // constant null terminated char array\ntypedef char * ASCIIz; // null terminated char array\n#endif\n//primitive.h\n"
},
{
"answer_id": 3618662,
"author": "Jérôme Radix",
"author_id": 3673,
"author_profile": "https://Stackoverflow.com/users/3673",
"pm_score": 3,
"selected": false,
"text": "<climits>"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271076",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25632/"
] |
271,077
|
<p>In my views.py, I'm building a list of two-tuples, where the second item in the tuple is another list, like this:</p>
<pre><code>[ Product_Type_1, [ product_1, product_2 ],
Product_Type_2, [ product_3, product_4 ]]
</code></pre>
<p>In plain old Python, I could iteration the list like this:</p>
<pre><code>for product_type, products in list:
print product_type
for product in products:
print product
</code></pre>
<p>I can't seem to do the same thing in my Django template:</p>
<pre><code>{% for product_type, products in product_list %}
print product_type
{% for product in products %}
print product
{% endfor %}
{% endfor %}
</code></pre>
<p>I get this error from Django:</p>
<p><strong>Caught an exception while rendering: zip argument #2 must support iteration</strong></p>
<p>Of course, there is some HTML markup in the template, not print statements. Is tuple unpacking not supported in the Django template language? Or am I going about this the wrong way? All I am trying to do is display a simple hierarchy of objects - there are several product types, each with several products (in models.py, Product has a foreign key to Product_type, a simple one-to-many relationship).</p>
<p>Obviously, I am quite new to Django, so any input would be appreciated.</p>
|
[
{
"answer_id": 271098,
"author": "Harley Holcombe",
"author_id": 1057,
"author_profile": "https://Stackoverflow.com/users/1057",
"pm_score": 2,
"selected": false,
"text": "{% for product_type in product_type_list %}\n {{ product_type }}\n {% for product in product_type.products.all %}\n {{ product }}\n {% endfor %}\n{% endfor %}\n"
},
{
"answer_id": 271128,
"author": "Jake",
"author_id": 24730,
"author_profile": "https://Stackoverflow.com/users/24730",
"pm_score": 7,
"selected": true,
"text": "[ (Product_Type_1, ( product_1, product_2 )),\n (Product_Type_2, ( product_3, product_4 )) ]\n {% for product_type, products in product_type_list %}\n {{ product_type }}\n {% for product in products %}\n {{ product }}\n {% endfor %}\n{% endfor %}\n"
},
{
"answer_id": 1168438,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "{% for product_type, products in product_list.items %}\n {{ product_type }}\n {% for product in products %}\n {{ product }}\n {% endfor %}\n{% endfor %}\n"
},
{
"answer_id": 4756748,
"author": "Ashwin Rao",
"author_id": 584161,
"author_profile": "https://Stackoverflow.com/users/584161",
"pm_score": 7,
"selected": false,
"text": "mylst = [(a, b, c), (x, y, z), (l, m, n)]\n {% for item in mylst %} \n {{ item.0 }} {{ item.1}} {{ item.2 }} \n{% endfor %}\n"
},
{
"answer_id": 35512819,
"author": "famousfilm",
"author_id": 5911260,
"author_profile": "https://Stackoverflow.com/users/5911260",
"pm_score": 2,
"selected": false,
"text": "my_dict = {'parrot': ('dead', 'stone'), 'lumberjack': ('sleep_all_night', 'work_all_day')}\n <select>\n {% for key, tuple in my_dict.items %}\n <option value=\"{{ key }}\" important-attr=\"{{ tuple.0 }}\">{{ tuple.1 }}</option>\n {% endfor %}\n</select>\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271077",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21245/"
] |
271,090
|
<p>Is there a way to pass a password to ssh automatically. I would like to automatically ssh to a server <b>without</b> using public key authentication or expect scripts, by somehow getting ssh to read the password from stdin or a file.</p>
<p>The reason it has to be that way is that I would like to backup my files to a server using rsync/ssh running as a cron job. This server mounts my home directory <i>after</i> it authenticates me, so using public key authentication does not work since ~/.ssh isn't available until after the login is successful. expect(1) is out of the question because I would like to run it as a cron job, and since cron jobs don't run under a terminal the combination of expect/ssh just doesn't work. I do not have root access to that server, and it would be difficult to get the admins to make any changes to the way things work there.</p>
|
[
{
"answer_id": 271112,
"author": "Harley Holcombe",
"author_id": 1057,
"author_profile": "https://Stackoverflow.com/users/1057",
"pm_score": -1,
"selected": false,
"text": "authorized_keys"
},
{
"answer_id": 363519,
"author": "Jay",
"author_id": 20840,
"author_profile": "https://Stackoverflow.com/users/20840",
"pm_score": 3,
"selected": false,
"text": "#!/usr/bin/python\n\nimport pexpect\n\nFILE=\"/path/to/file\"\nREMOTE_FILE=\"\"\nUSER=\"user\"\nHOST=\"example.com\"\nPASS=\"mypass\"\nCOMMAND=\"scp -oPubKeyAuthentication=no %s %s@%s:%s\" % (FILE, USER, HOST, REMOTE_FILE)\n\nchild = pexpect.spawn(COMMAND)\nchild.expect('password:')\nchild.sendline(PASS)\nchild.expect(pexpect.EOF)\nprint child.before\n"
},
{
"answer_id": 20748503,
"author": "uvsmtid",
"author_id": 441652,
"author_profile": "https://Stackoverflow.com/users/441652",
"pm_score": 3,
"selected": true,
"text": "sshpass password.txt sshpass -fpassword.txt ssh username@hostname\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271090",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11688/"
] |
271,106
|
<p>I am trying to get this program to give me an out put that when I do an addition, subtraction, multiplication, or division problem it will give me the answer. However, it is not working can anyone help.</p>
<pre><code>int main ()
{
int choice;
float a, b;
float sum;
float difference;
float product;
float quotiont;
printf("This program adds, subtracts, multiplies, and divides.\n");
printf("**************\n");
printf("* Calculator *\n");
printf("**************\n");
printf("Enter an expression: ");
scanf("%f %f", &a, &b);
scanf("%f %f %f %f", &sum, &difference, &product, &quotiont);
sum = a + b;
difference = a - b;
product = a * b;
quotiont = a / b;
if(a + b)
printf("Answer = %f\n", &sum);
else if(a - b)
printf("Answer = %f\n", &difference);
else if(a * b)
printf("Answer = %f\n", &product);
else if(a / b)
printf("Answer = %f\n", &quotiont);
else
printf("Error");
}
</code></pre>
|
[
{
"answer_id": 271146,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 4,
"selected": false,
"text": "scanf(\"%f %f %f %f\", &sum, &difference, &product, "iont); \n if else if if(a + b)\n printf(\"Answer = %f\\n\", &sum);\n a b sum sum printf(\"Answer = %f\\n\", sum);\n choice else if choice choice + - * / choice char choice;\n scanf(\"%c\", &choice);\n choice if if (choice == '+')\n printf(\"Answer = %f\\n\", sum);\nelse if (choice == '-')\n printf(\"Answer = %f\\n\", difference);\nelse\n printf(\"Error: invalid choice.\\n\");\n switch"
},
{
"answer_id": 17675089,
"author": "zuber mirza",
"author_id": 2587075,
"author_profile": "https://Stackoverflow.com/users/2587075",
"pm_score": -1,
"selected": false,
"text": "#include<stdio.h>\n#include<conio.h>\n\n\nint main ()\n{ \n int choice; \n float a, b; \n float sum; \n float difference;\n float product;\n float quotiont;\n\n printf(\"This program adds, subtracts, multiplies, and divides.\\n\"); \n printf(\"**************\\n\"); \n printf(\"* Calculator *\\n\"); \n printf(\"**************\\n\"); \n printf(\"Enter thee value of a: \"); \n scanf(\"%f\",&a);\n printf(\"Enter the value of y:\");\n scanf(\"%f\",&b);\n sum=a+b;\n if (sum = a + b); \n printf(\"sum is %f\",sum);\n\n difference = a - b; \n if(difference=a-b)\n printf(\"\\n difference is %f\",difference);\n\n product = a * b; \n if(product=a*b)\n printf(\"\\n product is %f\",product);\n\n quotient = a / b; \n if(quotient=a/b)\n printf(\"\\n quotient is %f\",quotient);\n\n return(main());\n}\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271106",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
271,109
|
<p>I have a simple question. Is there a way ( using reflections I suppose ) to iterate all the static values of a class?</p>
<p>For instance </p>
<pre><code>class Any {
static int one = 1;
static int two = 2;
static int three = 3;
public static void main( String [] args ) {
for( int i : magicMethod( Any.class ) ){
System.out.println( i );
}
}
}
</code></pre>
<p>Output</p>
<pre><code> 1
2
3
</code></pre>
<p>Thanks.</p>
|
[
{
"answer_id": 271127,
"author": "OscarRyz",
"author_id": 20654,
"author_profile": "https://Stackoverflow.com/users/20654",
"pm_score": 2,
"selected": false,
"text": " Field [] constants = Main.class.getFields();\n Object some = new Main();\n for( Field field : constants ){\n if(Modifier.isStatic(field.getModifiers() ) && \n field.getType() == int.class ) {\n System.out.println( field.getInt( some ) );\n }\n }\n"
},
{
"answer_id": 271134,
"author": "Jason Coco",
"author_id": 34218,
"author_profile": "https://Stackoverflow.com/users/34218",
"pm_score": 1,
"selected": false,
"text": "import java.lang.reflect.*;\n\npublic class Foo {\n\npublic static int one = 1;\npublic static int two = 2;\npublic static int three = 3;\n\npublic static void magicMethod( Class clz ) throws Exception {\n Field[] fields = clz.getFields();\n System.out.println(\"\"+fields);\n for( Field field : fields ) {\n int modifiers = field.getModifiers();\n if( ! Modifier.isStatic(modifiers) )\n continue;\n System.out.println(\"\" + field.get(null));\n }\n}\n\npublic static void main(String[] args) throws Exception {\n Foo.magicMethod( Foo.class );\n}}\n"
},
{
"answer_id": 271156,
"author": "Skip Head",
"author_id": 23271,
"author_profile": "https://Stackoverflow.com/users/23271",
"pm_score": 5,
"selected": true,
"text": "import java.util.*;\nimport java.lang.reflect.*;\n\nclass Any {\n static int one = 1;\n static int two = 2;\n static int three = 3;\n\n public static void main( String [] args ) {\n for( int i : magicMethod( Any.class ) ){\n System.out.println( i );\n }\n }\n\n public static Integer[] magicMethod(Class<Any> c) {\n List<Integer> list = new ArrayList<Integer>();\n Field[] fields = c.getDeclaredFields();\n for (Field field : fields) {\n try {\n if (field.getType().equals(int.class) && Modifier.isStatic(field.getModifiers())) {\n list.add(field.getInt(null));\n }\n }\n catch (IllegalAccessException e) {\n // Handle exception here\n }\n }\n return list.toArray(new Integer[list.size()]);\n }\n }\n"
},
{
"answer_id": 7992587,
"author": "helpermethod",
"author_id": 1178669,
"author_profile": "https://Stackoverflow.com/users/1178669",
"pm_score": 0,
"selected": false,
"text": "class Any {\n enum Number {\n ONE(1),\n TWO(2),\n THREE(3);\n\n Number(int number) {\n this.number = number;\n }\n\n int number;\n };\n\n public static void main(String [] args) {\n for (Number value : Number.values()) {\n System.out.println(value.number);\n }\n }\n}\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271109",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20654/"
] |
271,115
|
<p>I'm working on kernel design, and I've got some questions concerning paging.</p>
<p>The basic idea that I have so far is this: Each program gets its own (or so it thinks) 4G of memory, minus a section somewhere that I reserve for kernel functions that the program can call. So, the OS needs to figure out some way to load the pages in memory that the program needs to use during its operation.</p>
<p>Now, assuming that we had infinite amounts of memory and processor time, I could load/allocate any page the program wrote to or read from as it happened using page faults for pages that didn't exist (or were swapped out) so the OS could quickly allocate them or swap them in. In the real world though, I need to optimize this process, so that we don't have a program constantly consuming all memory that it ever touched.</p>
<p>So I guess my question is, how does an OS generally go about this? My initial thought is to create a function that the program calls to set/free pages, which it can then memory manage on its own, but does a program generally do this, or does the compiler assume it has free reign? Also, how does the compiler handle situations where it needs to allocate a fairly large segment of memory? Do I need to provide a function that tries to give it X pages in order?</p>
<p>This is obviously not a language specific question, but I'm partial to standard C and good with C++, so I'd like any code examples to be in either that or assembly. (Assembly shouldn't be necessary, I fully intend to make it work with as much C code as possible, and optimize as a last step.)</p>
<p>Another thing that should be easier to answer as well: How does one generally handle kernel functions that a program needs to call? Is it OK just to have a set area of memory (I was thinking toward the end of virtual space) that contains most basic functions/process specific memory that the program can call? My thought from there would be to have the kernel functions do something very fancy and swap the pages out (so that programs couldn't see sensitive kernel functions in their own space) when programs needed to do anything major, but I'm not really focusing on security at this point.</p>
<p>So I guess I'm more worried about the general design ideas than the specifics. I'd like to make the kernel completely compatible with GCC (somehow) and I need to make sure that it provides everything that a normal program would need.</p>
<p>Thanks for any advice.</p>
|
[
{
"answer_id": 271154,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 3,
"selected": false,
"text": "int"
},
{
"answer_id": 271229,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https://Stackoverflow.com/users/28258",
"pm_score": 5,
"selected": true,
"text": "brk() malloc() mmap() mmap mmap"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271115",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19521/"
] |
271,145
|
<p>Given a UTC time string like this:</p>
<pre><code>2005-11-01T00:00:00-04:00
</code></pre>
<p>What is the best way to convert it to a DateTime using a Crystal Reports formula?</p>
<p>My best solution is posted below.</p>
<p>I hope someone out there can blow me away with a one-liner...</p>
|
[
{
"answer_id": 271147,
"author": "JosephStyons",
"author_id": 672,
"author_profile": "https://Stackoverflow.com/users/672",
"pm_score": 1,
"selected": false,
"text": "//assume a date stored as a string in this format:\n//2005-11-01T00:00:00-04:00\n//return a DateTime value\nStringVar fieldValue;\nStringVar datePortion;\nStringVar timePortion;\nNumberVar yearPortion;\nNumberVar monthPortion;\nNumberVar dayPortion;\nNumberVar hourPortion;\nNumberVar minutePortion;\nNumberVar secondPortion;\n\n//store the field locally so i can easily copy-paste into another formula\n//(where the field name will be different)\n//Crystal formulas do not use a powerful language.\nfieldValue := {PACT.ReferralDate};\n\n//break up the date & time parts.\n//ignore the -04:00 offset part of the time.\ndatePortion := Split (fieldValue,\"T\")[1];\ntimePortion := Split(Split (fieldValue,\"T\")[2],\"-\")[1];\n\nyearPortion := ToNumber(Split(datePortion,\"-\")[1]);\nmonthPortion := ToNumber(Split(datePortion,\"-\")[2]);\ndayPortion := ToNumber(Split(datePortion,\"-\")[3]);\n\nhourPortion := ToNumber(Split(timePortion,\":\")[1]);\nminutePortion := ToNumber(Split(timePortion,\":\")[2]);\nsecondPortion := ToNumber(Split(timePortion,\":\")[3]);\n\n//finally, return the result as a date-time\nDateTime(yearPortion,monthPortion,dayPortion,hourPortion,minutePortion,secondPortion);\n"
},
{
"answer_id": 271167,
"author": "jons911",
"author_id": 34375,
"author_profile": "https://Stackoverflow.com/users/34375",
"pm_score": 3,
"selected": true,
"text": "CDateTime(CDate(Split({?UTCDateString}, \"T\")[1]) , CTime(Split(Split({?UTCDateString}, \"T\")[2], \"-\")[1]))\n"
},
{
"answer_id": 288744,
"author": "Anthony K",
"author_id": 1682,
"author_profile": "https://Stackoverflow.com/users/1682",
"pm_score": 2,
"selected": false,
"text": "CDateTime(CDate(Left({@UTCString}, 10)), CTime(Mid({@UTCString}, 12, 8))); \n"
},
{
"answer_id": 869505,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "StringVar fieldValue;\nStringVar datePortion;\nStringVar timePortion;\nNumberVar yearPortion;\nNumberVar monthPortion;\nNumberVar dayPortion;\nNumberVar hourPortion;\nNumberVar minutePortion;\nNumberVar secondPortion;\ndatetimevar dtlimite;\n\nfieldValue := {dtsecretaria.Data_limite};\n\ndatePortion := Split (fieldValue,\"T\")[1];\ntimePortion := Split(Split (fieldValue,\"T\")[2],\"-\")[1];\n\nyearPortion := ToNumber(Split(datePortion,\"-\")[1]);\nmonthPortion := ToNumber(Split(datePortion,\"-\")[2]);\ndayPortion := ToNumber(Split(datePortion,\"-\")[3]);\n\nhourPortion := ToNumber(Split(timePortion,\":\")[1]);\nminutePortion := ToNumber(Split(timePortion,\":\")[2]);\nsecondPortion := ToNumber(Split(timePortion,\":\")[3]);\n\ndtlimite := DateTime(yearPortion,monthPortion,dayPortion,hourPortion,minutePortion,secondPortion);\n\n\nif dtlimite > CurrentDateTime then\n\nColor(255,0,0)\n\nelse\n\nColor(255,255,0)\n\n\n\nerror of nError in formula <Back_Color>. \\n'\\r'\\nA string is required here.\"\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271145",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/672/"
] |
271,149
|
<p>how do i check if an item is selected or not in my listbox?
so i have a button remove, but i only want that button to execute if an item is selected in the list box. im using asp.net code behind C#. I'd prefer if this validation occurred on the server side.</p>
<p>cheers..</p>
|
[
{
"answer_id": 271164,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 1,
"selected": false,
"text": "protected void removeButton_Click( object sender, EventArgs e )\n{\n if (listBox.SelectedIndex >= 0)\n {\n listBox.Items.RemoveAt( listBox.SelectedIndex );\n }\n}\n"
},
{
"answer_id": 271245,
"author": "Gishu",
"author_id": 1695,
"author_profile": "https://Stackoverflow.com/users/1695",
"pm_score": 0,
"selected": false,
"text": "protected void removeButton_Click( object sender, EventArgs e )\n{\n if (listBox.SelectedIndex < 0) { return; }\n // do whatever you wish to here to remove the list item \n}\n"
},
{
"answer_id": 271476,
"author": "Adyt",
"author_id": 23491,
"author_profile": "https://Stackoverflow.com/users/23491",
"pm_score": -1,
"selected": true,
"text": "for (int i = 0; i < lbSrc.Items.Count; i++)\n{\n if (lbSrc.Items[i].Selected == true)\n {\n lbSrc.Items.RemoveAt(lbSrc.SelectedIndex);\n }\n}\n"
},
{
"answer_id": 271511,
"author": "Joacim Andersson",
"author_id": 25203,
"author_profile": "https://Stackoverflow.com/users/25203",
"pm_score": 0,
"selected": false,
"text": "for (int i=lbSrc.Items.Count - 1, i>=0, i--)\n{\n //code to check the selected state and remove the item\n}\n"
},
{
"answer_id": 271513,
"author": "Sani Singh Huttunen",
"author_id": 26742,
"author_profile": "https://Stackoverflow.com/users/26742",
"pm_score": 1,
"selected": false,
"text": "protected void removeButton_Click(object sender, EventArgs e)\n{\n for (int i = listBox.Items.Count - 1; i >= 0; i--)\n listBox.Items.RemoveAt(i);\n}\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271149",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23491/"
] |
271,150
|
<p>In adobe Flex datagrid height is equally to fix height . I want to make datagrid height is depend data . </p>
|
[
{
"answer_id": 404639,
"author": "cliff.meyers",
"author_id": 41754,
"author_profile": "https://Stackoverflow.com/users/41754",
"pm_score": 3,
"selected": false,
"text": "dataGrid.rowCount = yourCollection.length;\n <mx:DataGrid rowCount=\"{yourCollection.length}\"/>\n"
},
{
"answer_id": 891021,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "<mx:DataGrid rowCount=\"{yourCollection.length}\"/>\n"
},
{
"answer_id": 1240219,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "dg.height = dg.measureHeightOfItems(0, dgDataProvider.length) + dg.headerHeight;\n"
},
{
"answer_id": 1630779,
"author": "Nikhil",
"author_id": 197337,
"author_profile": "https://Stackoverflow.com/users/197337",
"pm_score": 0,
"selected": false,
"text": "verticalScrollPolicy = \"off\""
},
{
"answer_id": 4849603,
"author": "Fletch",
"author_id": 159178,
"author_profile": "https://Stackoverflow.com/users/159178",
"pm_score": 2,
"selected": false,
"text": "<mx:DataGrid rowCount=\"{yourCollection.length}\"/>\n <mx:DataGrid rowCount=\"{yourCollection.length + 1}\"/>\n"
},
{
"answer_id": 6421512,
"author": "Mahesh ",
"author_id": 807938,
"author_profile": "https://Stackoverflow.com/users/807938",
"pm_score": 1,
"selected": false,
"text": "var rwcnt = xmllist.length();// dataprovider.length\n\nADG.rowHeight = 20;\n\nvar rht = ADG.rowHeight;\n\nADG.height = (rwcnt * rht) + 26;\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271150",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33016/"
] |
271,168
|
<p>Is there a built-in way to know if a given session variable is a serialized object? Say I retrieve a value like $_SESSION['foo'], but I don't know if it was originally a string or if it is a serialized object. Is there some way to check, or once serialized does PHP just see a string as a string as a string? </p>
|
[
{
"answer_id": 271174,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 1,
"selected": false,
"text": "unserialize()"
},
{
"answer_id": 271601,
"author": "troelskn",
"author_id": 18180,
"author_profile": "https://Stackoverflow.com/users/18180",
"pm_score": 3,
"selected": true,
"text": "$_SESSION"
},
{
"answer_id": 271797,
"author": "DreamWerx",
"author_id": 15487,
"author_profile": "https://Stackoverflow.com/users/15487",
"pm_score": 1,
"selected": false,
"text": "if (is_a($_SESSION['foo'], 'UserInfoObject')) {\n // We have one\n}\n if ($_SESSION['foo'] instanceof UserInfoObject) {\n // We have one\n}\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271168",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5291/"
] |
271,171
|
<p>This is a little confusing to explain, so bear with me here...</p>
<p>I want to set up a system where a user can send templated emails via my website, except it's not actually sent using my server - it instead just opens up their own local mail client with an email ready to go. The application would fill out the body of the email with predefined variables, to save the user having to type it themselves. They can then edit the message as desired, should it not exactly suit their purposes.</p>
<p>There's a number of reasons I want it to go via the user's local mail client, so getting the server to send the email is not an option: it has to be 100% client-side.</p>
<p>I already have a mostly-working solution running, and I'll post the details of that as an answer, I'm wondering if there's any better way?</p>
|
[
{
"answer_id": 271172,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 8,
"selected": true,
"text": "<textarea id=\"myText\">\n Lorem ipsum...\n</textarea>\n<button onclick=\"sendMail(); return false\">Send</button>\n function sendMail() {\n var link = \"mailto:me@example.com\"\n + \"?cc=myCCaddress@example.com\"\n + \"&subject=\" + encodeURIComponent(\"This is my subject\")\n + \"&body=\" + encodeURIComponent(document.getElementById('myText').value)\n ;\n \n window.location.href = link;\n}\n"
},
{
"answer_id": 271181,
"author": "Ryan Doherty",
"author_id": 956,
"author_profile": "https://Stackoverflow.com/users/956",
"pm_score": 4,
"selected": false,
"text": "<a href=\"mailto:me@me.com\">email me here!</a>\n"
},
{
"answer_id": 271186,
"author": "alex",
"author_id": 31671,
"author_profile": "https://Stackoverflow.com/users/31671",
"pm_score": 3,
"selected": false,
"text": "<span class=\"launchEmailClientLink\">launch what you have in your email client</span> .launchEmailClientLink {\ncursor: pointer;\ncolor: #00F;\n}\n $('.launchEmailClientLink').bind('click',sendMail);\n"
},
{
"answer_id": 9366054,
"author": "Reignier Julien",
"author_id": 1221702,
"author_profile": "https://Stackoverflow.com/users/1221702",
"pm_score": 4,
"selected": false,
"text": "$('#element').click(function(){\n $(location).attr('href', 'mailto:?subject='\n + encodeURIComponent(\"This is my subject\")\n + \"&body=\" \n + encodeURIComponent(\"This is my body\")\n );\n});\n $('#input1').val() $.get('...')"
},
{
"answer_id": 33041167,
"author": "Vitaly Zdanevich",
"author_id": 1879101,
"author_profile": "https://Stackoverflow.com/users/1879101",
"pm_score": 1,
"selected": false,
"text": "var xhttp = new XMLHttpRequest();\nxhttp.onreadystatechange = function() {\n if (xhttp.readyState == 4 && xhttp.status == 200) {\n console.log(xhttp.responseText);\n }\n}\nxhttp.open('GET', 'https://mandrillapp.com/api/1.0/messages/send.json?message[from_email]=mail@7995.by&message[to][0][email]=zdanevich.vitaly@yaa.ru&message[subject]=Заявка%20с%207995.by&message[html]=xxxxxx&key=oxddROOvCpKCp6InvVDqiGw', true);\nxhttp.send();\n"
},
{
"answer_id": 48368936,
"author": "julianm",
"author_id": 3530707,
"author_profile": "https://Stackoverflow.com/users/3530707",
"pm_score": 3,
"selected": false,
"text": "<script src=\"https://smtpjs.com/v2/smtp.js\"></script> Email.send(\n \"from@you.com\",\n \"to@them.com\",\n \"This is a subject\",\n \"this is the body\",\n \"smtp.yourisp.com\",\n \"username\",\n \"password\"\n);\n"
},
{
"answer_id": 65701460,
"author": "jvel07",
"author_id": 3885769,
"author_profile": "https://Stackoverflow.com/users/3885769",
"pm_score": 1,
"selected": false,
"text": "<head> <script src=\"https://smtpjs.com/v3/smtp.js\"></script>\n\n<script type=\"text/javascript\">\n function sendEmail() {\n Email.send({\n SecureToken: \"security token of your smtp\",\n To: \"someone@gmail.com\",\n From: \"someone@gmail.com\",\n Subject: \"Subject...\",\n Body: document.getElementById('text').value\n }).then( \n message => alert(\"mail sent successfully\")\n );\n }\n</script>\n <textarea id=\"text\">write text here...</textarea>\n<input type=\"button\" value=\"Send Email\" onclick=\"sendEmail()\">\n <textarea id=\"subject\">write text here...</textarea>"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271171",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9021/"
] |
271,198
|
<p>One of the frequent causes of memory leaks in .Net are event handlers which are never removed from their source objects. </p>
<p>Will this WCF code cause a memory leak, or will the lambda go out of scope too, allowing both the proxy class and the handler to be GCed?</p>
<pre><code>void AMethod()
{
WCFClient proxy;
proxy = new WCFClient();
proxy.RemoteOperationCompleted += (sender, e) => proxy.Close();
proxy.Open();
proxy.RemoteOperationAsync();
}
</code></pre>
|
[
{
"answer_id": 271282,
"author": "cfeduke",
"author_id": 5645,
"author_profile": "https://Stackoverflow.com/users/5645",
"pm_score": 3,
"selected": true,
"text": "proxy null WeakReference public class Proxy\n{\n private bool _isOpen;\n\n public event EventHandler Complete;\n\n public void Close() \n {\n _isOpen = false;\n }\n\n public void Open() \n { \n _isOpen = true; \n }\n\n public void RemoteOperationAsync()\n {\n if (!_isOpen)\n throw new ApplicationException();\n Thread.Sleep(1000);\n if (Complete != null)\n Complete(this, EventArgs.Empty);\n }\n}\n\npublic static class Program\n{\n public static void Main()\n {\n WeakReference wr = null;\n\n {\n var proxy = new Proxy();\n proxy.Complete += (sender, e) =>\n {\n proxy.Close();\n wr = new WeakReference(proxy);\n proxy = null;\n };\n proxy.Open();\n proxy.RemoteOperationAsync();\n }\n\n GC.Collect(GC.GetGeneration(wr));\n GC.WaitForPendingFinalizers();\n\n Console.WriteLine(\"[LAMBDA] Is WeakReference alive? \" + wr.IsAlive);\n }\n}\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25201/"
] |
271,204
|
<p>This loop is slower than I would expect, and I'm not sure where yet. See anything?</p>
<p>I'm reading an Accces DB, using client-side cursors. When I have 127,000 rows with 20 columns, this loop takes about 10 seconds. The 20 columns are string, int, and date types. All the types get converted to ANSI strings before they are put into the ostringstream buffer.</p>
<pre><code>void LoadRecordsetIntoStream(_RecordsetPtr& pRs, ostringstream& ostrm)
{
ADODB::FieldsPtr pFields = pRs->Fields;
char buf[80];
::SYSTEMTIME sysTime;
_variant_t var;
while(!pRs->EndOfFile) // loop through rows
{
for (long i = 0L; i < nColumns; i++) // loop through columns
{
var = pFields->GetItem(i)->GetValue();
if (V_VT(&var) == VT_BSTR)
{
ostrm << (const char*) (_bstr_t) var;
}
else if (V_VT(&var) == VT_I4
|| V_VT(&var) == VT_UI1
|| V_VT(&var) == VT_I2
|| V_VT(&var) == VT_BOOL)
{
ostrm << itoa(((int)var),buf,10);
}
else if (V_VT(&var) == VT_DATE)
{
::VariantTimeToSystemTime(var,&sysTime);
_stprintf(buf, _T("%4d-%02d-%02d %02d:%02d:%02d"),
sysTime.wYear, sysTime.wMonth, sysTime.wDay,
sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
ostrm << buf;
}
}
pRs->MoveNext();
}
}
</code></pre>
<p>EDIT: After more experimentation...</p>
<p>I know now that about half the time is used by this line:<br>
var = pFields->GetItem(i)->GetValue();</p>
<p>If I bypass the Microsoft generated COM wrappers, will my code be faster? My guess is no.</p>
<p>The othe half of the time is spent in the statements which convert data and stream it into the ostringstream.</p>
<p>I don't know right now as I write this whether it's the conversions or the streaming that is taking more time.</p>
<p>Would it be faster if I didn't use ostringstream and instead managed my own buffer, with my own logic to grow the buffer (re-alloc, copy, delete)? Would it be faster if my logic made a pessimistic guesstimate and reserved a lot of space for the ostringstream buffer up front? These might be experiments worth trying.</p>
<p>Finally, the conversions themselves. None of the three stand out in my timings as being bad. One answer says that my itoa might be slower than an alternative. Worth checking out.</p>
|
[
{
"answer_id": 271430,
"author": "Andreas Magnusson",
"author_id": 5811,
"author_profile": "https://Stackoverflow.com/users/5811",
"pm_score": 0,
"selected": false,
"text": "#define TIME_CALL(x) \\\ndo { \\\n const DWORD t1 = timeGetTime();\\\n x;\\\n const DWORD t2 = timeGetTime();\\\n std::cout << \"Call to '\" << #x << \"' took \" << (t2 - t1) << \" ms.\\n\";\\\n}while(false)\n TIME_CALL(var = pFields->GetItem(i)->GetValue());\nTIME_CALL(ostrm << (const char*) (_bstr_t) var);\n"
},
{
"answer_id": 272513,
"author": "Andreas Magnusson",
"author_id": 5811,
"author_profile": "https://Stackoverflow.com/users/5811",
"pm_score": 0,
"selected": false,
"text": "_stprintf(buf, _T(\"%4d-%02d-%02d %02d:%02d:%02d\"),\n sysTime.wYear, sysTime.wMonth, sysTime.wDay, \n sysTime.wHour, sysTime.wMinute, sysTime.wSecond);\n\nostrm << buf;\n ostrm.fill('0');\nostrm.width(4);\nostrm << sysTime.wYear << _T(\"-\");\nostrm.width(2);\nostrm << sysTime.wMonth;\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9328/"
] |
271,210
|
<p>I have a build server running CruiseControl.NET. It works well for the 7 projects that are configured to run on that server (let's call it server A).</p>
<p>Now I have a new project that I wish to build on a different server (server B), but I want it to appear in the same ccnet dashboard as the existing projects. </p>
<p>How do I configure CCNet for this scenario?</p>
|
[
{
"answer_id": 271858,
"author": "John Lemp",
"author_id": 12915,
"author_profile": "https://Stackoverflow.com/users/12915",
"pm_score": 4,
"selected": true,
"text": "dashboard.config c:\\Program Files\\CruiseControl.NET\\webdashboard\\dashboard.config <servers>\n <server name=\"local\" url=\"tcp://localhost:21234/CruiseManager.rem\"\n allowForceBuild=\"true\" allowStartStopBuild=\"true\" />\n </servers>\n <server />"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30183/"
] |
271,218
|
<p>I am trying something very simple, but for some reason it does not work. Basically, I need to rename some nodes in an XML document. Thus, I created an XSLT file to do the transformation.</p>
<p>Here is an example of the XML:</p>
<p>EDIT: Addresses and Address elements occur at many levels. This is what caused me to have to try and apply an XSLT. The Visual Studio typed dataset feature, which creates typed datasets from XSD files does not permit you to have nested references to the same table. Thus, having Businesses/Business/Addresses and Businesses/Business/Contact/Addresses causes the Load() to fail. This is a known issue, and all they tell you is something like "Don't have nested table references...edit your XSD to stop having that." Unfortunately, this means that we have to apply XSLT to make the XML conform to the "hacked" XSD, since the files are coming from a third party vendor.</p>
<p>So, we are very close with the help rendered here. The last couple of things are these:</p>
<p>1.) How can I use the namespace reference in the match attribute of the xsl:template in order to specify that I want to rename Businesses/Business/Addresses to BusinessAddresses, but rename Businesses/Business/Contacts/Contact/Addresses to ContactAddresses?</p>
<p>2.) How can I stop the XSLT from cluttering every new element with explicit namespace references? It is causing extreme bloat in the output.</p>
<p>I created a namespace called "steel", and was having good success with:</p>
<pre><code><xsl:template match="steel:Addresses>
<xsl:element name="BusinessAddresses>
</xsl:template>
</code></pre>
<p>The obvious problem here is that it renames <strong>ALL</strong> of the Addresses elements to BusinessAddresses, even though I want some of them named ContactAddresses, and so on. The needless addition of explicit namespace references to all of the renamed nodes is also troublesome.</p>
<p>I tried this sort of thing, but as soon as I add slashes to the match attribute, it is a a syntax error in the XSLT, like so:</p>
<pre><code><xsl:template match="steel:/Businesses/Business/Addresses">
</code></pre>
<p>I feel very close, but need some guidance on how to mix both the namespace usage and a way to use the slashes to select <strong>ANY</strong> nodes under specific paths.</p>
<pre><code><?xml version="1.0"?>
<Businesses>
<Business>
<BusinessName>Steel Stretching</BusinessName>
<Addresses>
<Address>
<City>Pittsburgh</City>
</Address>
<Address>
<City>Philadelphia</City>
</Address>
</Addresses>
<Contacts>
<Contact>
<FirstName>Paul</FirstName>
<LastName>Jones</LastName>
<Addresses>
<Address>
<City>Pittsburgh</City>
</Address>
</Addresses>
</Contact>
</Contacts>
</Business>
<Business>
<BusinessName>Iron Works</BusinessName>
<Addresses>
<Address>
<City>Harrisburg</City>
</Address>
<Address>
<City>Lancaster</City>
</Address>
</Addresses>
</Business>
</Businesses>
</code></pre>
<p>I need to rename Addresses to BusinessAddresses, and I need to rename Address to BusinessAddress, for every instance of Addresses and Address directly under a Business node. I also need to rename Addresses to ContactAddresses, and I need to rename Address to ContactAddress, for every instance of Addresses and Address directly under a Contact Node.</p>
<p>I have tried several solutions, but none seem to work. They all end up producing the same XML as the original file.</p>
<p>Here is an example of what I have tried:</p>
<pre><code> <xsl:template match="/">
<xsl:apply-templates select="@*|node()" />
</xsl:template>
<xsl:template match="@*|*">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="Addresses">
<BusinessAddresses>
<xsl:apply-templates select="@*|node()" />
</BusinessAddresses>
</xsl:template>
</code></pre>
<p>This has been tried in at least 6 different flavors, complete with stepping through the XSLT debugger in VB.Net. It never executes the template match for Addresses.</p>
<p>Why?</p>
|
[
{
"answer_id": 271301,
"author": "Jeff Yates",
"author_id": 23234,
"author_profile": "https://Stackoverflow.com/users/23234",
"pm_score": 4,
"selected": true,
"text": "xmlns:business business mynamespace.uri <xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\"\n xmlns:business=\"mynamespace.uri\"\n exclude-result-prefixes=\"msxsl\">\n <xsl:template match=\"/\">\n <xsl:apply-templates select=\"@*|node()\"/>\n </xsl:template>\n\n <xsl:template match=\"@*|node()\">\n <xsl:copy>\n <xsl:apply-templates select=\"@*|node()\"/>\n </xsl:copy>\n </xsl:template>\n\n <xsl:template match=\"business:Addresses\">\n <xsl:element name=\"BusinessAddresses\">\n <xsl:apply-templates select=\"@*|node()\" />\n </xsl:element>\n </xsl:template>\n\n <xsl:template match=\"business:Address\">\n <xsl:element name=\"BusinessAddress\">\n <xsl:apply-templates select=\"@*|node()\"/>\n </xsl:element>\n </xsl:template>\n</xsl:stylesheet>\n match match <xsl:template match=\"business:Business/business:Addresses>\n</xsl:template>\n\n<xsl:template match=\"business:Business/business:Addresses/business:Address\">\n</xsl:template>\n\n<xsl:template match=\"business:Contact/business:Addresses\">\n</xsl:template>\n\n<xsl:template match=\"business:Contact/business:Addresses/business:Address\">\n</xsl:template>\n match"
},
{
"answer_id": 274416,
"author": "Pride Fallon",
"author_id": 35458,
"author_profile": "https://Stackoverflow.com/users/35458",
"pm_score": 0,
"selected": false,
"text": "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n\n<xsl:template match=\"Businesses\">\n <Businesses>\n <xsl:apply-templates/>\n </Businesses>\n</xsl:template>\n\n<xsl:template match=\"*\">\n <xsl:copy-of select=\".\"/>\n</xsl:template>\n\n<xsl:template match=\"Addresses\">\n <BusinessAddresses>\n <xsl:apply-templates/>\n </BusinessAddresses>\n</xsl:template>\n\n<xsl:template match=\"Addresses/Address\">\n <BusinessAddress>\n <xsl:value-of select=\".\"/>\n </BusinessAddress>\n</xsl:template>\n\n</xsl:stylesheet> \n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271218",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10224/"
] |
271,224
|
<p>Can anyone reccomend a .net control (winforms) that can be used to as a designer to edit xml files / DSL files ??</p>
|
[
{
"answer_id": 271301,
"author": "Jeff Yates",
"author_id": 23234,
"author_profile": "https://Stackoverflow.com/users/23234",
"pm_score": 4,
"selected": true,
"text": "xmlns:business business mynamespace.uri <xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\"\n xmlns:business=\"mynamespace.uri\"\n exclude-result-prefixes=\"msxsl\">\n <xsl:template match=\"/\">\n <xsl:apply-templates select=\"@*|node()\"/>\n </xsl:template>\n\n <xsl:template match=\"@*|node()\">\n <xsl:copy>\n <xsl:apply-templates select=\"@*|node()\"/>\n </xsl:copy>\n </xsl:template>\n\n <xsl:template match=\"business:Addresses\">\n <xsl:element name=\"BusinessAddresses\">\n <xsl:apply-templates select=\"@*|node()\" />\n </xsl:element>\n </xsl:template>\n\n <xsl:template match=\"business:Address\">\n <xsl:element name=\"BusinessAddress\">\n <xsl:apply-templates select=\"@*|node()\"/>\n </xsl:element>\n </xsl:template>\n</xsl:stylesheet>\n match match <xsl:template match=\"business:Business/business:Addresses>\n</xsl:template>\n\n<xsl:template match=\"business:Business/business:Addresses/business:Address\">\n</xsl:template>\n\n<xsl:template match=\"business:Contact/business:Addresses\">\n</xsl:template>\n\n<xsl:template match=\"business:Contact/business:Addresses/business:Address\">\n</xsl:template>\n match"
},
{
"answer_id": 274416,
"author": "Pride Fallon",
"author_id": 35458,
"author_profile": "https://Stackoverflow.com/users/35458",
"pm_score": 0,
"selected": false,
"text": "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n\n<xsl:template match=\"Businesses\">\n <Businesses>\n <xsl:apply-templates/>\n </Businesses>\n</xsl:template>\n\n<xsl:template match=\"*\">\n <xsl:copy-of select=\".\"/>\n</xsl:template>\n\n<xsl:template match=\"Addresses\">\n <BusinessAddresses>\n <xsl:apply-templates/>\n </BusinessAddresses>\n</xsl:template>\n\n<xsl:template match=\"Addresses/Address\">\n <BusinessAddress>\n <xsl:value-of select=\".\"/>\n </BusinessAddress>\n</xsl:template>\n\n</xsl:stylesheet> \n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271224",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
271,238
|
<p>I'm just concerned about Windows, so there's no need to go into esoterica about Mono compatibility or anything like that.</p>
<p>I should also add that the app that I'm writing is WPF, and I'd prefer to avoid taking a dependency on <code>System.Windows.Forms</code> if at all possible.</p>
|
[
{
"answer_id": 271251,
"author": "Josh Stodola",
"author_id": 54420,
"author_profile": "https://Stackoverflow.com/users/54420",
"pm_score": 5,
"selected": true,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Management;\n\nnamespace WMITestConsolApplication\n{\n\n class Program\n {\n\n static void Main(string[] args)\n {\n\n AddInsertUSBHandler();\n AddRemoveUSBHandler();\n while (true) {\n }\n\n }\n\n static ManagementEventWatcher w = null;\n\n static void AddRemoveUSBHandler()\n {\n\n WqlEventQuery q;\n ManagementScope scope = new ManagementScope(\"root\\\\CIMV2\");\n scope.Options.EnablePrivileges = true;\n\n try {\n\n q = new WqlEventQuery();\n q.EventClassName = \"__InstanceDeletionEvent\";\n q.WithinInterval = new TimeSpan(0, 0, 3);\n q.Condition = \"TargetInstance ISA 'Win32_USBControllerdevice'\";\n w = new ManagementEventWatcher(scope, q);\n w.EventArrived += USBRemoved;\n\n w.Start();\n }\n catch (Exception e) {\n\n\n Console.WriteLine(e.Message);\n if (w != null)\n {\n w.Stop();\n\n }\n }\n\n }\n\n static void AddInsertUSBHandler()\n {\n\n WqlEventQuery q;\n ManagementScope scope = new ManagementScope(\"root\\\\CIMV2\");\n scope.Options.EnablePrivileges = true;\n\n try {\n\n q = new WqlEventQuery();\n q.EventClassName = \"__InstanceCreationEvent\";\n q.WithinInterval = new TimeSpan(0, 0, 3);\n q.Condition = \"TargetInstance ISA 'Win32_USBControllerdevice'\";\n w = new ManagementEventWatcher(scope, q);\n w.EventArrived += USBInserted;\n\n w.Start();\n }\n catch (Exception e) {\n\n Console.WriteLine(e.Message);\n if (w != null)\n {\n w.Stop();\n\n }\n }\n\n }\n\n static void USBInserted(object sender, EventArgs e)\n {\n\n Console.WriteLine(\"A USB device inserted\");\n\n }\n\n static void USBRemoved(object sender, EventArgs e)\n {\n\n Console.WriteLine(\"A USB device removed\");\n\n }\n }\n\n}\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271238",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26628/"
] |
271,244
|
<p>Given a Django.db models class:</p>
<pre><code>class P(models.Model):
type = models.ForeignKey(Type) # Type is another models.Model class
name = models.CharField()
</code></pre>
<p>where one wishes to create a new P with a specified type, i.e. how does one make "type" to be a default, hidden field (from the user), where type is given likeso:</p>
<pre><code>http://x.y/P/new?type=3
</code></pre>
<p>So that in the form no "type" field will appear, but when the P is saved, its type will have id 3 (i.e. Type.objects.get(pk=3)).</p>
<p>Secondarily, how does one (& is it possible) specify a "default" type in the url, via urls.py, when using generic Django views, viz.</p>
<pre><code>urlpatterns = ('django.generic.views.create_update',
url(r'^/new$', 'create_object', { 'model': P }, name='new_P'),
)
</code></pre>
<p>I found that terribly difficult to describe, which may be part of the problem. :) Input is much appreciated!</p>
|
[
{
"answer_id": 271252,
"author": "Harley Holcombe",
"author_id": 1057,
"author_profile": "https://Stackoverflow.com/users/1057",
"pm_score": 3,
"selected": false,
"text": "mydefault = Type.objects.get(pk=3)\n\nclass P(models.Model):\n type = models.ForeignKey(Type, default=mydefault) # Type is another models.Model class\n name = models.CharField()\n pk=x # URLconf\nurlpatterns = patterns('',\n (r'^blog/$', 'blog.views.page'),\n (r'^blog/page(?P<num>\\d+)/$', 'blog.views.page'),\n)\n\n# View (in blog/views.py)\ndef page(request, num=\"1\"):\n # Output the appropriate page of blog entries, according to num.\n"
},
{
"answer_id": 271303,
"author": "Daniel Naab",
"author_id": 32638,
"author_profile": "https://Stackoverflow.com/users/32638",
"pm_score": 3,
"selected": false,
"text": "django.forms.widgets.HiddenInput <form action=\"new/{{your_hidden_value}}\" method=\"post\">\n....\n</form>\n ^/new/(?P<hidden_value>\\w+)/\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271244",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19212/"
] |
271,254
|
<p>Pretty self explanatory. I just need to export lists easily to xml format. Are there any tools that accomplish this?</p>
|
[
{
"answer_id": 302472,
"author": "jwmiller5",
"author_id": 7824,
"author_profile": "https://Stackoverflow.com/users/7824",
"pm_score": 2,
"selected": false,
"text": "http://server/_vti_bin/Lists.asmx"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271254",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5469/"
] |
271,260
|
<p>I was in need of a way to compress images in .net so i looked into using the .net GZipStream class (or DeflateStream). However i found that decompression was not always successful, sometimes the images would decompress fine and other times i would get a GDI+ error that something is corrupted.</p>
<p>After investigating the issue i found that the decompression was not giving back all the bytes it compressed. So if i compressed 2257974 bytes i would sometimes get back only 2257870 bytes (real numbers).</p>
<p>The most funny thing is that sometimes it would work. So i created this little test method that compresses only 10 bytes and now i don't get back anything at all.</p>
<p>I tried it with both compression classes GZipStream and DeflateStream and i double checked my code for possible errors. I even tried positioning the stream to 0 and flushing all the streams but with no luck.</p>
<p>Here is my code:</p>
<pre><code> public static void TestCompression()
{
byte[] test = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
byte[] result = Decompress(Compress(test));
// This will fail, result.Length is 0
Debug.Assert(result.Length == test.Length);
}
public static byte[] Compress(byte[] data)
{
var compressedStream = new MemoryStream();
var zipStream = new GZipStream(compressedStream, CompressionMode.Compress);
zipStream.Write(data, 0, data.Length);
return compressedStream.ToArray();
}
public static byte[] Decompress(byte[] data)
{
var compressedStream = new MemoryStream(data);
var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress);
var resultStream = new MemoryStream();
var buffer = new byte[4096];
int read;
while ((read = zipStream.Read(buffer, 0, buffer.Length)) > 0) {
resultStream.Write(buffer, 0, read);
}
return resultStream.ToArray();
}
</code></pre>
|
[
{
"answer_id": 271264,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 7,
"selected": true,
"text": "Close() ZipStream Flush() Stream IDisposable using MemoryStream Stream public static byte[] Compress(byte[] data)\n{\n using (var compressedStream = new MemoryStream())\n using (var zipStream = new GZipStream(compressedStream, CompressionMode.Compress))\n {\n zipStream.Write(data, 0, data.Length);\n zipStream.Close();\n return compressedStream.ToArray();\n }\n}\n\npublic static byte[] Decompress(byte[] data)\n{\n using(var compressedStream = new MemoryStream(data))\n using(var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress))\n using (var resultStream = new MemoryStream())\n { ... }\n}\n using MemoryStream MemoryStream using IDisposable Dispose()"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271260",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35371/"
] |
271,265
|
<p>I'm using JMX to save some diagnostic information from a remote process. Looking at the interface in jconsole shows that the return type is <a href="http://java.sun.com/j2se/1.5.0/docs/api/javax/management/openmbean/CompositeData.html" rel="noreferrer">CompositeData</a> (the data actually comes back as <a href="http://java.sun.com/j2se/1.5.0/docs/api/javax/management/openmbean/CompositeDataSupport.html" rel="noreferrer">CompositeDataSupport</a>). I want to output all the key/value pairs that are associated with this object.</p>
<p>The problem is that the interface just seems to have a "values()" method with no way of getting the keys. Am I missing something here? Is there some other way to approach this task?</p>
<p>Thanks!</p>
|
[
{
"answer_id": 271400,
"author": "Tyler Levine",
"author_id": 35339,
"author_profile": "https://Stackoverflow.com/users/35339",
"pm_score": 4,
"selected": true,
"text": "Set< String > keys = cData.getCompositeType().keySet();\n"
},
{
"answer_id": 271408,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 2,
"selected": false,
"text": "StringBuffer writeCompositeData(StringBuffer buffer, \n String prefix, String name, CompositeData data) {\n if (data == null)\n return writeSimple(buffer,prefix,name,null,true);\n writeSimple(buffer,prefix,name,\"CompositeData(\"+\n data.getCompositeType().getTypeName()+\")\",true);\n buffer.append(prefix).append(\"{\").append(\"\\n\");\n final String fieldprefix = prefix + \" \";\n for (String key : data.getCompositeType().keySet()) {\n write(buffer,fieldprefix,name+\".\"+key,data.get(key));\n }\n buffer.append(prefix).append(\"}\").append(\"\\n\");\n return buffer;\n }\n for (String key : data.getCompositeType().keySet()) {\n [...] data.get(key) [...];\n}\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271265",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18437/"
] |
271,273
|
<p>I'm trying to take advantage of the constant memory, but I'm having a hard time figuring out how to nest arrays. What I have is an array of data that has counts for internal data but those are different for each entry. So based around the following simplified code I have two problems. First I don't know how to allocate the data pointed to by the members of my data structure. Second, since I can't use cudaGetSymbolAddress for constant memory I'm not sure if I can just pass the global pointer (which you cannot do with plain __device__ memory).</p>
<pre><code>
struct __align(16)__ data{
int nFiles;
int nNames;
int* files;
int* names;
};
__device__ __constant__ data *mydata;
__host__ void initMemory(...)
{
cudaMalloc( (void **) &(mydata), sizeof(data)*dynamicsize );
for(int i=; i lessthan dynamicsize; i++)
{
cudaMemcpyToSymbol(mydata, &(nFiles[i]), sizeof(int), sizeof(data)*i, cudaMemcpyHostToDevice);
//...
//Problem 1: Allocate & Set mydata[i].files
}
}
__global__ void myKernel(data *constDataPtr)
{
//Problem 2: Access constDataPtr[n].files, etc
}
int main()
{
//...
myKernel grid, threads (mydata);
}
</code></pre>
<p>Thanks for any help offered. :-)</p>
|
[
{
"answer_id": 672941,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "struct data\n{\n int nFiles;\n int nNames;\n int* files;\n int* names;\n}\n [struct data (7*4=28 bytes)\n [int nFiles=3 (4 bytes)]\n [int nNames=2 (4 bytes)]\n [file0 (4 bytes)]\n [file1 (4 bytes)]\n [file2 (4 bytes)]\n [name0 (4 bytes)]\n [name1 (4 bytes)]\n]\n"
},
{
"answer_id": 1261307,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "cudaMalloc __constant__ data mydata[100];\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35373/"
] |
271,274
|
<p>I am adding objects into a java Vector using its add(Object) method.
In my example, the first 5 objects are identical, followed by 2 instances different from the first five.
For some reasons, as soon as I insert the first one that is different, it changes the entire vector to that value!</p>
<p>'values' is an iterator containing something like
'1','1','1','1','1','2','2'</p>
<pre><code>
Vector temp = new Vector();
while (values.hasNext()) {
temp.add(values.next());
System.out.println(temp.toString());
}
</code></pre>
<p>It will output something like</p>
<blockquote>
<p>[1]<br>
[1,1]<br>
[1,1,1]<br>
[1,1,1,1]<br>
[1,1,1,1,1]<br>
[2,2,2,2,2,2]<br>
[2,2,2,2,2,2,2] </p>
</blockquote>
<p>I tried using a LinkedList, as well as using add(object, index). Same thing happened.</p>
|
[
{
"answer_id": 271293,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 3,
"selected": false,
"text": "values"
},
{
"answer_id": 271362,
"author": "dlinsin",
"author_id": 198,
"author_profile": "https://Stackoverflow.com/users/198",
"pm_score": 2,
"selected": false,
"text": "import java.util.Arrays;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Vector;\n\n public class Test{ \n\n public static void main( String ... args ){ \n List list = Arrays.asList(new String[] {\"1\",\"1\",\"1\",\"1\",\"1\",\"2\",\"2\"});\n Iterator values = list.iterator();\n Vector temp = new Vector(); \n while (values.hasNext()) {\n temp.add(values.next());\n System.out.println(temp.toString());\n }\n } \n } \n [1]\n[1, 1]\n[1, 1, 1]\n[1, 1, 1, 1]\n[1, 1, 1, 1, 1]\n[1, 1, 1, 1, 1, 2]\n[1, 1, 1, 1, 1, 2, 2]\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25645/"
] |
271,285
|
<p>My webapp (ASP.NET 2.0) consumes a webservice (asmx on 1.1 framework)
on the same machine. After getting XML in return, I pass it to
<code>XslCompiledTransform</code> for transform XML to HTML and it works fine.</p>
<p>Yesterday I got a <code>System.IO.FileNotFoundException</code> frequently and don't know what causes this kind of problem.</p>
<p>First look I thought it's about read/write permission on c:\windows\temp and then I made sure give it full permission for Network Service (also Everybody at last -_-!) but
it doesn't help.</p>
<p>Any ideas or solutions would be appreciate.</p>
<pre><code>-------------------- stack trace --------------------------
Exception: **System.IO.FileNotFoundException**
**Could not find file 'C:\WINDOWS\TEMP\sivvt5f6.dll'.**
at System.IO.__Error**.WinIOError**(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32
rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames)
at Microsoft.CSharp.CSharpCodeGenerator.FromDomBatch(CompilerParameters options, CodeCompileUnit[] ea)
at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromDomBatch(CompilerParameters options, CodeCompileUnit[] ea)
at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromDom(CompilerParameters options, CodeCompileUnit[] compilationUnits)
at System.Xml.Xsl.Xslt.Scripts.CompileAssembly(List`1 scriptsForLang)
at System.Xml.Xsl.Xslt.Scripts.CompileScripts()
at System.Xml.Xsl.Xslt.QilGenerator.Compile(Compiler compiler)
at System.Xml.Xsl.Xslt.**Compiler.
Compile**(Object stylesheet, XmlResolver xmlResolver, QilExpression& qil)
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at System.Xml.Xsl.**XslCompiledTransform.Load**(String stylesheetUri, XsltSettings settings, XmlResolver stylesheetResolver)
</code></pre>
|
[
{
"answer_id": 271304,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 1,
"selected": false,
"text": "XslCompiledTransform XmlResolver XslTransform XslCompiledTransform"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35682/"
] |
271,311
|
<p>Is there some nice documentation for Windows batch scripting I can download and refer to while offline?</p>
|
[
{
"answer_id": 271334,
"author": "Paulius",
"author_id": 1353085,
"author_profile": "https://Stackoverflow.com/users/1353085",
"pm_score": 2,
"selected": false,
"text": "<command> /?\nhelp <command>\n help\n"
},
{
"answer_id": 2035347,
"author": "Peter Mortensen",
"author_id": 63550,
"author_profile": "https://Stackoverflow.com/users/63550",
"pm_score": 5,
"selected": true,
"text": "help"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271311",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14966/"
] |
271,318
|
<p>If you have a Property that gets and sets to an instance variable then normally you always use the Property from outside that class to access it. </p>
<p>My question is should you also always do so within the class? I've always used the Property if there is one, even within the class, but would like to hear some arguments for and against as to which is the most correct and why. </p>
<p>Or is it just a matter of coding standards being used on the project?</p>
|
[
{
"answer_id": 271327,
"author": "Brannon",
"author_id": 5745,
"author_profile": "https://Stackoverflow.com/users/5745",
"pm_score": 0,
"selected": false,
"text": "class Foo {\n public string Value { get; set; }\n\n public void Write() {\n Console.Write(Value);\n }\n}\n"
},
{
"answer_id": 271333,
"author": "LizB",
"author_id": 13616,
"author_profile": "https://Stackoverflow.com/users/13616",
"pm_score": 0,
"selected": false,
"text": "private int mVariable;\nprivate int _Variable;\n"
},
{
"answer_id": 271339,
"author": "Mikael Sundberg",
"author_id": 4422,
"author_profile": "https://Stackoverflow.com/users/4422",
"pm_score": 1,
"selected": false,
"text": "class Test {\n private int _checksum = -1;\n private int Checksum {\n get {\n if (_checksum == -1)\n _checksum = calculateChecksum();\n return checksum;\n }\n }\n}\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271318",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24395/"
] |
271,319
|
<p>Could you recommend a lightweight SQL database which doesn't require installation on a client computer to work and could be accessed easily from .NET application? Only basic SQL capabilities are needed.</p>
<p>Now I am using Access database in simple projects and distribute .MDB and .EXE files together. Looking for any alternatives.</p>
|
[
{
"answer_id": 15044689,
"author": "nawfal",
"author_id": 661933,
"author_profile": "https://Stackoverflow.com/users/661933",
"pm_score": 6,
"selected": true,
"text": " no of files cumulative size of files db size\n\nFirebird 2.5 5 6.82 MB 250 KB\n\nSqlServerCe 4 7 2.08 MB 64 KB\n\nSqlite 3.7.11.0 1 0.83 MB 15 KB\n\nVistaDb 4.3.3.34 1 1.04 MB 48 KB\n\nno of files - includes the .net connector and excludes the db file\n SqlServerCe VistaDb"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271319",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11256/"
] |
271,329
|
<p>I have problems with how to design some classes. I have three classes. One superclass, and two subclasses. </p>
<p>One subclass (AnimatedCharacter) is made by flash, and is used to display the object on screen. The other (CharacterPhysics) is made by myself to extend the superclass.</p>
<p>The problem is that the object I use, is of the type AnimatedCharacter, so I can't just put it in a variable of type CharacterPhysics.</p>
<p>What I tried is some sort of Decorator pattern, by giving the object of type CharacterPhysics a reference to the other object. But now I have to override all the methods of the superclass and pass the methodcalls to the reference. Not an ideal situation.</p>
<p>Does someone know how to solve this kind of problem?</p>
<p><a href="http://www.freeimagehosting.net/uploads/7a95f8352c.png" rel="nofollow noreferrer">alt text http://www.freeimagehosting.net/uploads/7a95f8352c.png</a></p>
|
[
{
"answer_id": 281794,
"author": "hasseg",
"author_id": 4111,
"author_profile": "https://Stackoverflow.com/users/4111",
"pm_score": 1,
"selected": false,
"text": "AnimatedCharacter CharacterPhysics callProperty()"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271329",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20261/"
] |
271,337
|
<p>How do I pick/ delete all the documents from Solr using the boolean NOT notion?</p>
<p>i.e. How do I delete all the documents from Solr who's id does NOT start with A59?</p>
|
[
{
"answer_id": 379890,
"author": "Mauricio Scheffer",
"author_id": 21239,
"author_profile": "https://Stackoverflow.com/users/21239",
"pm_score": 7,
"selected": true,
"text": "- NOT -id:A59* /solr/select/?q=-id:A59* NOT"
},
{
"answer_id": 12351946,
"author": "Rick Tonoli",
"author_id": 1514547,
"author_profile": "https://Stackoverflow.com/users/1514547",
"pm_score": 4,
"selected": false,
"text": "/solr/select/?q=!id:A59*\n"
},
{
"answer_id": 23962419,
"author": "Simcha Khabinsky",
"author_id": 643761,
"author_profile": "https://Stackoverflow.com/users/643761",
"pm_score": 0,
"selected": false,
"text": "GET http://<url>/solr/<core>/update?stream.body=<delete><query>-id:A59*</query></delete>\nGET http://<url>/solr/<core>/update?stream.body=<commit/>\n"
},
{
"answer_id": 42757202,
"author": "Gautam",
"author_id": 582421,
"author_profile": "https://Stackoverflow.com/users/582421",
"pm_score": 1,
"selected": false,
"text": "http://localhost:8983/solr/HQ_SOLR_Hotels/select?q=*:*&fq=HQ_National_Code:TH&fq=HQ_TYPE:hotel_EN&fq=HQ_Country_Code:AU&**fq=-HQ_City_Code:MEL**&wt=json&indent=true\n"
}
] |
2008/11/07
|
[
"https://Stackoverflow.com/questions/271337",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2220518/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.