qid
int64
4
8.14M
question
stringlengths
20
48.3k
answers
list
date
stringlengths
10
10
metadata
list
input
stringlengths
12
45k
output
stringlengths
2
31.8k
173,366
<p>V8's documentation explains <a href="http://code.google.com/apis/v8/embed.html#dynamic" rel="noreferrer">how to create a Javascript object that wraps a C++ object</a>. The Javascript object holds on to a pointer to a C++ object instance. My question is, let's say you create the C++ object on the heap, how can you ge...
[ { "answer_id": 175500, "author": "Javier", "author_id": 11649, "author_profile": "https://Stackoverflow.com/users/11649", "pm_score": 0, "selected": false, "text": "<p>In general, if a garbage-collected language can hold references to resources outside of the language engine (files, sock...
2008/10/06
[ "https://Stackoverflow.com/questions/173366", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1892/" ]
V8's documentation explains [how to create a Javascript object that wraps a C++ object](http://code.google.com/apis/v8/embed.html#dynamic). The Javascript object holds on to a pointer to a C++ object instance. My question is, let's say you create the C++ object on the heap, how can you get a notification when the Javas...
The trick is to create a `Persistent` handle (second bullet point from the linked-to API reference: "`Persistent` handles are not held on a stack and are deleted only when you specifically remove them. ... Use a persistent handle when you need to keep a reference to an object for more than one function call, or when ha...
173,389
<p>I've build my WinForm app on windows machine and the app is working ok. When I user nhibernate 1.2.1 the app also worked on linux machine using mono, but now when i upgraded app to nhibernate 2.0.1 it works only in windows. I've get error: NHibernate.InvalidProxyTypeException: The following types may not be used as...
[ { "answer_id": 173528, "author": "Kev", "author_id": 419, "author_profile": "https://Stackoverflow.com/users/419", "pm_score": 0, "selected": false, "text": "<p>This might be of interest:</p>\n\n<p><a href=\"http://softwaredevscott.spaces.live.com/blog/cns!1A9E939F7373F3B7!251.entry\" re...
2008/10/06
[ "https://Stackoverflow.com/questions/173389", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I've build my WinForm app on windows machine and the app is working ok. When I user nhibernate 1.2.1 the app also worked on linux machine using mono, but now when i upgraded app to nhibernate 2.0.1 it works only in windows. I've get error: NHibernate.InvalidProxyTypeException: The following types may not be used as pr...
You can try and disable the NHibernate Config proxy validator. it seems to not work with mono. You can do this by adding: `<property name="use_proxy_validator">false</property>` in your app/web.config nhibernate section. For an example config with this property set, see here: <http://www.mail-archive.com/nhusers@goog...
173,400
<p>PHP treats all arrays as associative, so there aren't any built in functions. Can anyone recommend a fairly efficient way to check if an array <em>&quot;is a list&quot;</em> (contains only numeric keys starting from 0)?</p> <p>Basically, I want to be able to differentiate between this:</p> <pre><code>$sequentialArra...
[ { "answer_id": 173412, "author": "Daren Thomas", "author_id": 2260, "author_profile": "https://Stackoverflow.com/users/2260", "pm_score": 0, "selected": false, "text": "<p>Unless PHP has a builtin for that, you won't be able to do it in less than O(n) - enumerating over all the keys and ...
2008/10/06
[ "https://Stackoverflow.com/questions/173400", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5291/" ]
PHP treats all arrays as associative, so there aren't any built in functions. Can anyone recommend a fairly efficient way to check if an array *"is a list"* (contains only numeric keys starting from 0)? Basically, I want to be able to differentiate between this: ``` $sequentialArray = [ 'apple', 'orange', 'tomato...
You have asked two questions that are not quite equivalent: * Firstly, how to determine whether an array has only numeric keys * Secondly, how to determine whether an array has *sequential* numeric keys, starting from 0 Consider which of these behaviours you actually need. (It may be that either will do for your purp...
173,433
<p>I have built a .dll under WinXP that claims it can't find DWMAPI.DLL when it's loaded. The problem is that this DLL is a Vista DLL, and this a known issue for XP users that have IE7 installed. The recommendation is to uninstall IE7 or repair the .NET Framework via Add/Remove programs. I did the repair, and nothing c...
[ { "answer_id": 173505, "author": "Gerald", "author_id": 19404, "author_profile": "https://Stackoverflow.com/users/19404", "pm_score": 2, "selected": false, "text": "<p>This is a tricky one. There's really 2 main ways you will get this error.</p>\n\n<p>1) You have your project set to forc...
2008/10/06
[ "https://Stackoverflow.com/questions/173433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2666/" ]
I have built a .dll under WinXP that claims it can't find DWMAPI.DLL when it's loaded. The problem is that this DLL is a Vista DLL, and this a known issue for XP users that have IE7 installed. The recommendation is to uninstall IE7 or repair the .NET Framework via Add/Remove programs. I did the repair, and nothing chan...
Based on your updated problem, DWMAPI.dll is probably not your problem. Dependency walker will always give you that error whenever you are linking to mshtml as it always checks delay loaded DLLs. At this point my best guess is that you have your project set to dynamically load the runtime libraries and the search path...
173,473
<p>I have a generated HTML page with flash content in it. I am trying to reposition the flash content and make it "absolute". I have tried to wrap the object tags with a div tag, but to no avail. Can anyone tell me how to do this? Removing the generated positioning attributes does not work. </p> <p>See relevant code b...
[ { "answer_id": 173507, "author": "Fuzzy76", "author_id": 15932, "author_profile": "https://Stackoverflow.com/users/15932", "pm_score": 2, "selected": false, "text": "<p>Since your div is wrapped in noscript it will only be shown if javascript is turned off, are you sure that is the behav...
2008/10/06
[ "https://Stackoverflow.com/questions/173473", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25280/" ]
I have a generated HTML page with flash content in it. I am trying to reposition the flash content and make it "absolute". I have tried to wrap the object tags with a div tag, but to no avail. Can anyone tell me how to do this? Removing the generated positioning attributes does not work. See relevant code below (it i...
you should place the JS script that actually creates you object inside your div not before it.
173,487
<h1> 1st phase</h1> <p>I have a problem shutting down my running JBoss instance under Eclipse since I changed the JNDI port of JBoss. Of course I can shut it down from the console view but not with the stop button (it still searches JNDI port at the default 1099 port). I'm looking forward to any solutions. Than...
[ { "answer_id": 173543, "author": "huo73", "author_id": 15657, "author_profile": "https://Stackoverflow.com/users/15657", "pm_score": 0, "selected": false, "text": "<p>In MyEclipse server configuration, you find the field \"Optional Shutdown Argument\", which is filled with the default va...
2008/10/06
[ "https://Stackoverflow.com/questions/173487", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19621/" ]
1st phase ========== I have a problem shutting down my running JBoss instance under Eclipse since I changed the JNDI port of JBoss. Of course I can shut it down from the console view but not with the stop button (it still searches JNDI port at the default 1099 port). I'm looking forward to any solutions. Thank you!...
OK, what you have to do is File->New->Other->Server, and set up your JBoss server there. It will then appear in Preferences->JBossTools->Servers. Convoluted.
173,498
<p>I am trying to take a rather large CSV file and insert it into a MySQL database for referencing in a project. I would like to use the first line of the file to create the table using proper data types and not varchar for each column. The ultimate goal is to automate this process as I have several similar files but t...
[ { "answer_id": 173526, "author": "pilsetnieks", "author_id": 6615, "author_profile": "https://Stackoverflow.com/users/6615", "pm_score": 2, "selected": false, "text": "<p>Try casting the value and comparing it with the original one:</p>\n\n<pre><code>define('DECIMAL_SEPARATOR', '.');\n\n...
2008/10/06
[ "https://Stackoverflow.com/questions/173498", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24802/" ]
I am trying to take a rather large CSV file and insert it into a MySQL database for referencing in a project. I would like to use the first line of the file to create the table using proper data types and not varchar for each column. The ultimate goal is to automate this process as I have several similar files but the ...
Building on [Nouveau](https://stackoverflow.com/questions/173498/using-php-to-take-the-first-line-of-a-csv-file-and-create-a-mysql-table-with-th#173526)'s code you could do this ``` for($i = 0; $i <= count($fieldList); $i++) { if (is_numeric($fieldList[$i])) { if (strpos($fieldList[$i],'.') !== false){...
173,503
<p>I've got a "little" problem with Zend Framework Zend_Pdf class. Multibyte characters are stripped from generated pdf files. E.g. when I write aąbcčdeę it becomes abcd with lithuanian letters stripped.</p> <p>I'm not sure if it's particularly Zend_Pdf problem or php in general. </p> <p>Source text is encoded in utf...
[ { "answer_id": 173964, "author": "leek", "author_id": 3765, "author_profile": "https://Stackoverflow.com/users/3765", "pm_score": 1, "selected": false, "text": "<p>I believe Zend_Pdf got UTF-8 support in 1.5 - What version of Zend Framework are you running?</p>\n\n<p>Also - what font are...
2008/10/06
[ "https://Stackoverflow.com/questions/173503", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25413/" ]
I've got a "little" problem with Zend Framework Zend\_Pdf class. Multibyte characters are stripped from generated pdf files. E.g. when I write aąbcčdeę it becomes abcd with lithuanian letters stripped. I'm not sure if it's particularly Zend\_Pdf problem or php in general. Source text is encoded in utf-8, as well as ...
`Zend_Pdf` supports UTF-8 in version 1.5 of Zend Framework. However, the standard PDF fonts support only the Latin1 character set. This means you can't use `Zend_Pdf_Font::FONT_TIMES_BOLD` or any other "built-in" font. To use special characters you must load another TTF font that includes characters from other characte...
173,527
<p>I have some old rrdtool databases, for which the exact creation recipe has long been since lost. I need to create a new database with the same characteristics as the current ones. I've dumped a couple of old databases and pored over the contents but I'm not sure how to interpret the metadata. I think it appears in t...
[ { "answer_id": 173547, "author": "Stu Thompson", "author_id": 2961, "author_profile": "https://Stackoverflow.com/users/2961", "pm_score": 3, "selected": true, "text": "<p>rrdtools' <a href=\"http://oss.oetiker.ch/rrdtool/doc/rrdinfo.en.html\" rel=\"nofollow noreferrer\">rrdinfo</a> is yo...
2008/10/06
[ "https://Stackoverflow.com/questions/173527", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18625/" ]
I have some old rrdtool databases, for which the exact creation recipe has long been since lost. I need to create a new database with the same characteristics as the current ones. I've dumped a couple of old databases and pored over the contents but I'm not sure how to interpret the metadata. I think it appears in the ...
rrdtools' [rrdinfo](http://oss.oetiker.ch/rrdtool/doc/rrdinfo.en.html) is your friend! It will tell you how the rrd file's data source(s) and archive(s) were created. Example ``` $ rrdtool info random.rrd filename = "random.rrd" rrd_version = "0001" step = 300 last_update = 955892996 ds[a].type = "GAUGE" ds[a].minima...
173,579
<p>I am writing a very specialized app in C# that floats as a mostly transparent window over the entire desktop. I want to be able to create and pass mouse events to applications behind mine, and have them appear to operate "normally", responding to those events. It would also be preferable if the window manager could ...
[ { "answer_id": 173602, "author": "Fionn", "author_id": 21566, "author_profile": "https://Stackoverflow.com/users/21566", "pm_score": 2, "selected": false, "text": "<p>Sounds like you want to do something like filtering user input.</p>\n\n<p>Maybe you just need an keyboard/mouse hook.</p>...
2008/10/06
[ "https://Stackoverflow.com/questions/173579", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23407/" ]
I am writing a very specialized app in C# that floats as a mostly transparent window over the entire desktop. I want to be able to create and pass mouse events to applications behind mine, and have them appear to operate "normally", responding to those events. It would also be preferable if the window manager could res...
After looking at System hooks and other low level solutions I found a much simpler method. First, set the TransparencyKey and BackColor of the form to be the same. This didn't make any visual difference to me as my form was visually transparent already, but this will help in letting mouse events through. Second, the ...
173,593
<p>I've tried to override WndProc, but no message show up on paste event.</p> <p>Then I tried to create custom filter and using method PreFilterMessage I was able to catch message with value 257 (KEYUP event), but that's not enough...</p>
[ { "answer_id": 173610, "author": "Goran", "author_id": 23164, "author_profile": "https://Stackoverflow.com/users/23164", "pm_score": 4, "selected": false, "text": "<p>Use:</p>\n\n<pre><code> protected override void OnKeyDown(KeyEventArgs e)\n {\n if (e.KeyCode == Keys.V &amp;&amp; e...
2008/10/06
[ "https://Stackoverflow.com/questions/173593", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I've tried to override WndProc, but no message show up on paste event. Then I tried to create custom filter and using method PreFilterMessage I was able to catch message with value 257 (KEYUP event), but that's not enough...
Use: ``` protected override void OnKeyDown(KeyEventArgs e) { if (e.KeyCode == Keys.V && e.Modifiers == Keys.Control) { MessageBox.Show("Hello world"); } base.OnKeyDown(e); } ``` Make sure your form KeyPreview = true.
173,617
<p>I read that you could call JavaScript code from a Java Applet by calling</p> <pre><code>JApplet.getAppletContext().showDocument( "javascript:alert('Hello World');" ); </code></pre> <p>However, when I do this i get the following error:</p> <pre><code>java.net.MalformedURLException: unknown protocol: javascript </c...
[ { "answer_id": 173743, "author": "RuntimeException", "author_id": 15789, "author_profile": "https://Stackoverflow.com/users/15789", "pm_score": 2, "selected": false, "text": "<pre><code> try {\n this.getAppletContext().showDocument(new URL(\"javascript:alert('hello world');\"))...
2008/10/06
[ "https://Stackoverflow.com/questions/173617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20298/" ]
I read that you could call JavaScript code from a Java Applet by calling ``` JApplet.getAppletContext().showDocument( "javascript:alert('Hello World');" ); ``` However, when I do this i get the following error: ``` java.net.MalformedURLException: unknown protocol: javascript ``` How do I work around this?
I get the same exception as you do because of that the URL class does not accept javascript: as a valid protocol. There is a workaround though; supply an URLStreamHandler to the URL constructor. Example: ``` final URLStreamHandler streamHandler = new URLStreamHandler() { @Override protected URLConnection op...
173,618
<p>In MSVC, <a href="http://msdn.microsoft.com/en-us/library/ms679297.aspx" rel="noreferrer">DebugBreak()</a> or <a href="http://msdn.microsoft.com/fr-fr/library/f408b4et.aspx" rel="noreferrer">__debugbreak</a> cause a debugger to break. On x86 it is equivalent to writing "_asm int 3", on x64 it is something different....
[ { "answer_id": 173630, "author": "Jorge Ferreira", "author_id": 6508, "author_profile": "https://Stackoverflow.com/users/6508", "pm_score": 5, "selected": true, "text": "<p>What about defining a conditional macro based on #ifdef that expands to different constructs based on the current a...
2008/10/06
[ "https://Stackoverflow.com/questions/173618", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23740/" ]
In MSVC, [DebugBreak()](http://msdn.microsoft.com/en-us/library/ms679297.aspx) or [\_\_debugbreak](http://msdn.microsoft.com/fr-fr/library/f408b4et.aspx) cause a debugger to break. On x86 it is equivalent to writing "\_asm int 3", on x64 it is something different. When compiling with gcc (or any other standard compiler...
What about defining a conditional macro based on #ifdef that expands to different constructs based on the current architecture or platform. Something like: ``` #ifdef _MSC_VER #define DEBUG_BREAK __debugbreak() #else ... #endif ``` This would be expanded by the preprocessor the correct debugger break instruction ba...
173,641
<p>I'm trying to use TestDriven.Net not only to test my code, but to call a function on my code whose purpose is to print out the internal state of the code to the Debug window.</p> <p>Here's a very simplified example of what I'm trying to do..</p> <pre><code>&lt;TestFixture()&gt; _ Public Class UnitTest &lt;Tes...
[ { "answer_id": 173651, "author": "Jon Limjap", "author_id": 372, "author_profile": "https://Stackoverflow.com/users/372", "pm_score": 5, "selected": true, "text": "<p>I found that while Debug.Writeline() doesn't work with unit tests, Console.WriteLine() does. </p>\n\n<p>The reason is tha...
2008/10/06
[ "https://Stackoverflow.com/questions/173641", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5662/" ]
I'm trying to use TestDriven.Net not only to test my code, but to call a function on my code whose purpose is to print out the internal state of the code to the Debug window. Here's a very simplified example of what I'm trying to do.. ``` <TestFixture()> _ Public Class UnitTest <Test()> _ Public Sub TestDebu...
I found that while Debug.Writeline() doesn't work with unit tests, Console.WriteLine() does. The reason is that when you run tests, the debugger process isn't invoked, and Debug.WriteLine() is ignored. However, if you use "Test with Debugger", I think (haven't tried) Debug.WriteLine() will work.
173,642
<p>I only want a list of files that have been added (not ones that have been modified) since a certain date. Is there an easy way to do this?</p> <p><strong>Answer</strong>: Here's what ended up working for me, thanks guys!</p> <blockquote> <p>svn log -v -r{2008-10-1}:HEAD svn://path.to.repo/ | grep "^&nbsp;&nbsp;&...
[ { "answer_id": 173665, "author": "Matthias Winkelmann", "author_id": 4494, "author_profile": "https://Stackoverflow.com/users/4494", "pm_score": 4, "selected": true, "text": "<pre><code>svn log -v -r{2008-10-1}:HEAD | grep \"^ A\"\n</code></pre>\n" }, { "answer_id": 173669, ...
2008/10/06
[ "https://Stackoverflow.com/questions/173642", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6583/" ]
I only want a list of files that have been added (not ones that have been modified) since a certain date. Is there an easy way to do this? **Answer**: Here's what ended up working for me, thanks guys! > > svn log -v -r{2008-10-1}:HEAD svn://path.to.repo/ | grep "^   A" | grep ".java" | sort -u > > >
``` svn log -v -r{2008-10-1}:HEAD | grep "^ A" ```
173,646
<p>Most often the cleanup rules (Preferences > Java > Code Style > Clean Up) in Eclipse work perfectly and create nice-looking code.</p> <p>But sometimes, especially with comments and concatenated string snippets (like inline SQL queries), the cleanup just messes things up, and destroys my formatting.</p> <p>Is there...
[ { "answer_id": 173984, "author": "Epaga", "author_id": 6583, "author_profile": "https://Stackoverflow.com/users/6583", "pm_score": 0, "selected": false, "text": "<p>No. (To the best of my knowledge, and I have had the same problem and have looked many times hard and long...)</p>\n" }, ...
2008/10/06
[ "https://Stackoverflow.com/questions/173646", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2238/" ]
Most often the cleanup rules (Preferences > Java > Code Style > Clean Up) in Eclipse work perfectly and create nice-looking code. But sometimes, especially with comments and concatenated string snippets (like inline SQL queries), the cleanup just messes things up, and destroys my formatting. Is there a way to say to ...
I assume you do not really mean ‘Clean Up’, but the ‘Format source code’ option hidden within. It is configured in Preferences > Java > Code Style > Formatter. And, indeed, there is an option called ‘On/Off Tags’. Sadly, it’s off by default. You would now write it like so: ``` // @formatter:off StringBuilder sql = new...
173,652
<p>I have a WPF Window which has a among other controls hosts a Frame. In that frame I display different pages. Is there way to make a dialog modal to only a page? When I'm showing the dialog it should not be possible to click on any control on the page but it should be possible to click on a control on the same window...
[ { "answer_id": 173702, "author": "Mez", "author_id": 20010, "author_profile": "https://Stackoverflow.com/users/20010", "pm_score": 1, "selected": false, "text": "<p>You are not looking for a modal dialog here. You need a function that will disable the \"page\" control, show a dialog, and...
2008/10/06
[ "https://Stackoverflow.com/questions/173652", "https://Stackoverflow.com", "https://Stackoverflow.com/users/143/" ]
I have a WPF Window which has a among other controls hosts a Frame. In that frame I display different pages. Is there way to make a dialog modal to only a page? When I'm showing the dialog it should not be possible to click on any control on the page but it should be possible to click on a control on the same window th...
If I am correct in interpreting your message, you want something that works similar to what [Billy Hollis demonstrates in his StaffLynx application](http://www.dnrtv.com/default.aspx?showNum=115). I recently built a similar control and it turns out that this sort of idea is relatively simple to implement in WPF. I cr...
173,670
<p>Being primarily a C++ developer the absence of <a href="http://en.wikipedia.org/wiki/Resource_acquisition_is_initialization" rel="noreferrer">RAII (Resource Acquisition Is Initialization)</a> in Java and .NET has always bothered me. The fact that the onus of cleaning up is moved from the class writer to its consumer...
[ { "answer_id": 173677, "author": "leppie", "author_id": 15541, "author_profile": "https://Stackoverflow.com/users/15541", "pm_score": 1, "selected": false, "text": "<p>The closest you get to that is the very limited stackalloc operator.</p>\n" }, { "answer_id": 173689, "autho...
2008/10/06
[ "https://Stackoverflow.com/questions/173670", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3848/" ]
Being primarily a C++ developer the absence of [RAII (Resource Acquisition Is Initialization)](http://en.wikipedia.org/wiki/Resource_acquisition_is_initialization) in Java and .NET has always bothered me. The fact that the onus of cleaning up is moved from the class writer to its consumer (by means of `try finally` or ...
A better title would be "Why is there no RAII in C#/VB". C++/CLI (The evolution of the abortion that was Managed C++) has RAII in the exact same sense as C++. It's all just syntax sugar for the same finalisation pattern that the rest of the CLI languages use (Destructors in managed objects for C++/CLI are effectively f...
173,681
<p>Are the string literals we use inside functions automatic variables? Or are they allocated in heap which we have to free manually?</p> <p>I've a situation like the code shown below wherein I'm assigning a string literal to a private field of the class (marked as ONE in the code) and retrieving it much later in my p...
[ { "answer_id": 173686, "author": "Serafina Brocious", "author_id": 4977, "author_profile": "https://Stackoverflow.com/users/4977", "pm_score": 4, "selected": true, "text": "<p>String literals will be placed in the initialized data or text (code) segment of your binary by the compiler, ra...
2008/10/06
[ "https://Stackoverflow.com/questions/173681", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7205/" ]
Are the string literals we use inside functions automatic variables? Or are they allocated in heap which we have to free manually? I've a situation like the code shown below wherein I'm assigning a string literal to a private field of the class (marked as ONE in the code) and retrieving it much later in my program and...
String literals will be placed in the initialized data or text (code) segment of your binary by the compiler, rather than residing in (runtime allocated) memory or the stack. So you should be using a pointer, since you're going to be referencing the string literal that the compiler has already produced for you. Note th...
173,687
<p>I haven't found an answer elsewhere and this doesn't appear to have been asked yet on SO.</p> <p>When creating an event binding in wxPython, is it possible to pass additional arguments to the event? For example, this is the normal way:</p> <pre><code>b = wx.Button(self, 10, "Default Button", (20, 20)) self...
[ { "answer_id": 173694, "author": "Florian Bösch", "author_id": 19435, "author_profile": "https://Stackoverflow.com/users/19435", "pm_score": 6, "selected": false, "text": "<p>You can always use a lambda or another function to wrap up your method and pass another argument, not WX specific...
2008/10/06
[ "https://Stackoverflow.com/questions/173687", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18676/" ]
I haven't found an answer elsewhere and this doesn't appear to have been asked yet on SO. When creating an event binding in wxPython, is it possible to pass additional arguments to the event? For example, this is the normal way: ``` b = wx.Button(self, 10, "Default Button", (20, 20)) self.Bind(wx.EVT_BUTTON, ...
You can always use a lambda or another function to wrap up your method and pass another argument, not WX specific. ``` b = wx.Button(self, 10, "Default Button", (20, 20)) self.Bind(wx.EVT_BUTTON, lambda event: self.OnClick(event, 'somevalue'), b) def OnClick(self, event, somearg): self.log.write("Click...
173,706
<p>I am having the problem that I cannot select a specific XML node which needs to be deleted. I have already tried to select the node by using the XPath which works fine for some XML files but I cannot figure out the correct XPath for a node in a more complex file.</p> <p>Does anybody know a freeware tool which can l...
[ { "answer_id": 173748, "author": "mdb", "author_id": 8562, "author_profile": "https://Stackoverflow.com/users/8562", "pm_score": 0, "selected": false, "text": "<p>Given the following XML:</p>\n\n<pre><code>&lt;root&gt;\n &lt;anything foo=\"bar\"&gt;value1&lt;/anything&gt;\n &lt;anythin...
2008/10/06
[ "https://Stackoverflow.com/questions/173706", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25428/" ]
I am having the problem that I cannot select a specific XML node which needs to be deleted. I have already tried to select the node by using the XPath which works fine for some XML files but I cannot figure out the correct XPath for a node in a more complex file. Does anybody know a freeware tool which can load a XML ...
This is a default namespace issue. Try including the following code after you load in the XML: ``` objDom.SetProperty "SelectionNamespaces", "xmlns:cf=""http://schemas.microsoft.com/SystemsManagementServer/2005/03/ConsoleFramework""" ``` You then use this `cf` prefix in your XPath eg: ``` objDom.SelectSingleNode("/...
173,717
<p>What is the easiest way to copy the all the values from a column in a table to another column in the same table?</p>
[ { "answer_id": 173720, "author": "Ilya Kochetov", "author_id": 15329, "author_profile": "https://Stackoverflow.com/users/15329", "pm_score": 4, "selected": false, "text": "<p>This script will update ALL values in the field1 with the values from the field2 in the corresponding row</p>\n\n...
2008/10/06
[ "https://Stackoverflow.com/questions/173717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25438/" ]
What is the easiest way to copy the all the values from a column in a table to another column in the same table?
With a single statement (if the columns have the same datatype) ``` UPDATE <tablename> SET <destination column name> = <source column name> ```
173,727
<p>I would like to save data in cookies (user name, email address, etc...) but I don't the user to easily read it or modify it. I need to be able able to read the data back. How can I do that with php 5.2+?</p> <p>It would be used for "welcome back bob" kind of feature. It is not a replacement for persistence or sessi...
[ { "answer_id": 173731, "author": "fijter", "author_id": 3215, "author_profile": "https://Stackoverflow.com/users/3215", "pm_score": 3, "selected": false, "text": "<p>If you don't want your users to read it don't put it in a cookie;\nIn stead use Session's with a cookie that stays for a l...
2008/10/06
[ "https://Stackoverflow.com/questions/173727", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1771/" ]
I would like to save data in cookies (user name, email address, etc...) but I don't the user to easily read it or modify it. I need to be able able to read the data back. How can I do that with php 5.2+? It would be used for "welcome back bob" kind of feature. It is not a replacement for persistence or session storage...
We use mcrypt in our projects to achieve encryption. Below is a code sample based on content found on the internet: ``` <?php class MyProjCrypt { private $td; private $iv; private $ks; private $salt; private $encStr; private $decStr; /** * The constructor initializes the cryptograph...
173,745
<p>I'm looking for a query which will return me an extra column at the end of my current query which is the count of all columns within the return set which contain a null column. For example:</p> <pre><code>Col 1 - Col 2 - Col 3 A B 0 A NULL 1 NULL NULL 2 </code></pre> <p>Is there a simple...
[ { "answer_id": 173794, "author": "Alexander Morland", "author_id": 4013, "author_profile": "https://Stackoverflow.com/users/4013", "pm_score": 0, "selected": false, "text": "<p>If there isnt a very good reason you need to do this in the SQL, you should just do a for loop through the resu...
2008/10/06
[ "https://Stackoverflow.com/questions/173745", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm looking for a query which will return me an extra column at the end of my current query which is the count of all columns within the return set which contain a null column. For example: ``` Col 1 - Col 2 - Col 3 A B 0 A NULL 1 NULL NULL 2 ``` Is there a simple way to get this return se...
Ugly solution: ``` select Col1, Col2, case when Col1 is null then 1 else 0 end + case when Col2 is null then 1 else 0 end as Col3 from ( select 'A' as Col1, 'B' as Col2 union select 'A', NULL union select NULL, NULL ) z ``` This returns ``` Col1 Col2 Col3 NULL NULL 2 A NULL 1 A B 0 ```
173,757
<p>We run a medium-size site that gets a few hundred thousand pageviews a day. Up until last weekend we ran with a load usually below 0.2 on a virtual machine. The OS is Ubuntu.</p> <p>When deploying the latest version of our application, we also did an apt-get dist-upgrade before deploying. After we had deployed we n...
[ { "answer_id": 173788, "author": "Paul Whelan", "author_id": 3050, "author_profile": "https://Stackoverflow.com/users/3050", "pm_score": 1, "selected": false, "text": "<p>Perhaps you where using worker MPM before and now you are not?</p>\n\n<p>I know PHP5 does not work with the Worker MP...
2008/10/06
[ "https://Stackoverflow.com/questions/173757", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1606/" ]
We run a medium-size site that gets a few hundred thousand pageviews a day. Up until last weekend we ran with a load usually below 0.2 on a virtual machine. The OS is Ubuntu. When deploying the latest version of our application, we also did an apt-get dist-upgrade before deploying. After we had deployed we noticed tha...
The answer ended up being not-Apache related. As mentioned, we were on a virtual machine. Our user sessions are pretty big (think 500kB per active user), so we had a lot of disk IO. The disk was nearly full, meaning that Ubuntu spent a lot of time moving things around (or so we think). There was no easy way to extend t...
173,786
<p>I have a UIScrollView that shows vertical data, but where the horizontal component is no wider than the screen of the iPhone. The problem is that the user is still able to drag horizontally, and basically expose blank sections of the UI. I have tried setting:</p> <pre><code>scrollView.alwaysBounceHorizontal = NO; s...
[ { "answer_id": 173852, "author": "Darron", "author_id": 22704, "author_profile": "https://Stackoverflow.com/users/22704", "pm_score": 3, "selected": false, "text": "<p>Try setting scrollView.bounces to NO and scrollView.alwaysBounceVertical to YES.</p>\n" }, { "answer_id": 174920...
2008/10/06
[ "https://Stackoverflow.com/questions/173786", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6044/" ]
I have a UIScrollView that shows vertical data, but where the horizontal component is no wider than the screen of the iPhone. The problem is that the user is still able to drag horizontally, and basically expose blank sections of the UI. I have tried setting: ``` scrollView.alwaysBounceHorizontal = NO; scrollView.dire...
That's strange, because whenever I create a scroll view with frame and content size within the bounds of the screen on either dimension, the scroll view does not scroll (or bounce) in that direction. ``` // Should scroll vertically but not horizontally UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGR...
173,814
<p>How can ALTER be used to drop a column in a MySQL table if that column exists? </p> <p>I know I can use <code>ALTER TABLE my_table DROP COLUMN my_column</code>, but that will throw an error if <code>my_column</code> does not exist. Is there alternative syntax for dropping the column conditionally?</p> <p>I'm using...
[ { "answer_id": 173820, "author": "Matthias Winkelmann", "author_id": 4494, "author_profile": "https://Stackoverflow.com/users/4494", "pm_score": 7, "selected": true, "text": "<p><strong>For MySQL, there is none:</strong> <a href=\"http://bugs.mysql.com/bug.php?id=10789\" rel=\"noreferrer...
2008/10/06
[ "https://Stackoverflow.com/questions/173814", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7362/" ]
How can ALTER be used to drop a column in a MySQL table if that column exists? I know I can use `ALTER TABLE my_table DROP COLUMN my_column`, but that will throw an error if `my_column` does not exist. Is there alternative syntax for dropping the column conditionally? I'm using MySQL version 4.0.18.
**For MySQL, there is none:** [MySQL Feature Request](http://bugs.mysql.com/bug.php?id=10789). Allowing this is arguably a really bad idea, anyway: `IF EXISTS` indicates that you're running destructive operations on a database with (to you) unknown structure. There may be situations where this is acceptable for quick...
173,821
<p>I want to output the function name each time it is called, I can easily copy and paste the function name, however I wondered if there was a shortcut that would do the job for me?</p> <p>At the moment I am doing:</p> <pre><code>SlideInfoHeader* lynxThreeFile::readSlideInfoHeader(QDataStream &amp; in) { qDebug("...
[ { "answer_id": 173828, "author": "Torbjörn Gyllebring", "author_id": 21182, "author_profile": "https://Stackoverflow.com/users/21182", "pm_score": 6, "selected": true, "text": "<p>\"<code>__FUNCTION__</code>\" is supported by both MSVC and GCC and should give you the information you need...
2008/10/06
[ "https://Stackoverflow.com/questions/173821", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24459/" ]
I want to output the function name each time it is called, I can easily copy and paste the function name, however I wondered if there was a shortcut that would do the job for me? At the moment I am doing: ``` SlideInfoHeader* lynxThreeFile::readSlideInfoHeader(QDataStream & in) { qDebug("lynxThreeFile::readSlideI...
"`__FUNCTION__`" is supported by both MSVC and GCC and should give you the information you need.
173,834
<p>Given an SQLConnection object how can you get a schema for a single table?</p> <p>I seemed to be able to get the schema from a <code>DataSet</code> which I'd gotten from running a query, but all the schema info I could get from the connection seemed to be related to what tables were available and not the actual deta...
[ { "answer_id": 173863, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": true, "text": "<p>I think accessing the schema from the query (via GetSchemaTable) is the only way to do it. \nYou can run a query which retur...
2008/10/06
[ "https://Stackoverflow.com/questions/173834", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20400/" ]
Given an SQLConnection object how can you get a schema for a single table? I seemed to be able to get the schema from a `DataSet` which I'd gotten from running a query, but all the schema info I could get from the connection seemed to be related to what tables were available and not the actual details on the tables.
I think accessing the schema from the query (via GetSchemaTable) is the only way to do it. You can run a query which returns no rows (select \* from table where 1=2) if the schema is all you're interested in. You should use the KeyInfo CommandBehaviour to execute the source query, as otherwise not all the information...
173,835
<p>I am using Spry (<code>SpryData.js,xpath.js</code>)</p> <pre><code> var ds1 = new Spry.Data.XMLDataSet("_db/db.xml", "bildiriler/bildiri",{useCache:false}); // load the xml tree </code></pre> <p>....</p> <pre><code>&lt;!-- use it in a loop - Sometimes the page use "ds1.loadData();" to refresh the data --&gt...
[ { "answer_id": 173859, "author": "Alex Gyoshev", "author_id": 25427, "author_profile": "https://Stackoverflow.com/users/25427", "pm_score": 1, "selected": false, "text": "<p>I am not quite good at Spry, but can't you add a css background to the div placeholder (&lt;div spry:region=\"ds1\...
2008/10/06
[ "https://Stackoverflow.com/questions/173835", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24439/" ]
I am using Spry (`SpryData.js,xpath.js`) ``` var ds1 = new Spry.Data.XMLDataSet("_db/db.xml", "bildiriler/bildiri",{useCache:false}); // load the xml tree ``` .... ``` <!-- use it in a loop - Sometimes the page use "ds1.loadData();" to refresh the data --> <div spry:region="ds1" spry:repeatchildren="ds1"> ...
I am not quite good at Spry, but can't you add a css background to the div placeholder (<div spry:region="ds1" ...) which will be shown at all time (and probably can be replaced through an observer that sets the background-image of the placeholder when the rows are loaded)...
173,846
<p>I'm trying to have my Struts2 app redirect to a generated URL. In this case, I want the URL to use the current date, or a date I looked up in a database. So <code>/section/document</code> becomes <code>/section/document/2008-10-06</code></p> <p>What's the best way to do this?</p>
[ { "answer_id": 174100, "author": "Sietse", "author_id": 6400, "author_profile": "https://Stackoverflow.com/users/6400", "pm_score": 2, "selected": false, "text": "<p>I ended up subclassing Struts' <code>ServletRedirectResult</code> and overriding it's <code>doExecute()</code> method to d...
2008/10/06
[ "https://Stackoverflow.com/questions/173846", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6400/" ]
I'm trying to have my Struts2 app redirect to a generated URL. In this case, I want the URL to use the current date, or a date I looked up in a database. So `/section/document` becomes `/section/document/2008-10-06` What's the best way to do this?
Here's how we do it: In Struts.xml, have a dynamic result such as: ``` <result name="redirect" type="redirect">${url}</result> ``` In the action: ``` private String url; public String getUrl() { return url; } public String execute() { [other stuff to setup your date] url = "/section/document" + date; return ...
173,851
<p>I have a PHP script that needs to determine if it's been executed via the command-line or via HTTP, primarily for output-formatting purposes. What's the canonical way of doing this? I had thought it was to inspect <code>SERVER['argc']</code>, but it turns out this is populated, even when using the 'Apache 2.0 Handle...
[ { "answer_id": 173856, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 3, "selected": false, "text": "<p>I think</p>\n\n<pre><code>$_SERVER['REMOTE_ADDR']\n</code></pre>\n\n<p>will not be populated from the CLI.</p>\n\...
2008/10/06
[ "https://Stackoverflow.com/questions/173851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5058/" ]
I have a PHP script that needs to determine if it's been executed via the command-line or via HTTP, primarily for output-formatting purposes. What's the canonical way of doing this? I had thought it was to inspect `SERVER['argc']`, but it turns out this is populated, even when using the 'Apache 2.0 Handler' server API.
Use the [`php_sapi_name()`](http://php.net/php_sapi_name) function. ```php if (php_sapi_name() == "cli") { // In cli-mode } else { // Not in cli-mode } ``` Here are some relevant notes from the docs: > > **php\_sapi\_name** — Returns the type of interface between web server and PHP > > > Although not exh...
173,866
<p>I have a web page which contains a select box. When I open a jQuery Dialog it is displayed partly behind the select box.</p> <p>How should I approach this problem? Should I hide the select box or does jQuery offer some kind of 'shim' solution. (I have Googled but didn't find anything)</p> <p>Here is some code:</p...
[ { "answer_id": 173856, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 3, "selected": false, "text": "<p>I think</p>\n\n<pre><code>$_SERVER['REMOTE_ADDR']\n</code></pre>\n\n<p>will not be populated from the CLI.</p>\n\...
2008/10/06
[ "https://Stackoverflow.com/questions/173866", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11249/" ]
I have a web page which contains a select box. When I open a jQuery Dialog it is displayed partly behind the select box. How should I approach this problem? Should I hide the select box or does jQuery offer some kind of 'shim' solution. (I have Googled but didn't find anything) Here is some code: ``` <!DOCTYPE html>...
Use the [`php_sapi_name()`](http://php.net/php_sapi_name) function. ```php if (php_sapi_name() == "cli") { // In cli-mode } else { // Not in cli-mode } ``` Here are some relevant notes from the docs: > > **php\_sapi\_name** — Returns the type of interface between web server and PHP > > > Although not exh...
173,868
<p>This is a question you can read everywhere on the web with various answers:</p> <pre><code>$ext = end(explode('.', $filename)); $ext = substr(strrchr($filename, '.'), 1); $ext = substr($filename, strrpos($filename, '.') + 1); $ext = preg_replace('/^.*\.([^.]+)$/D', '$1', $filename); $exts = split("[/\\.]", $filena...
[ { "answer_id": 173872, "author": "Adam Wright", "author_id": 1200, "author_profile": "https://Stackoverflow.com/users/1200", "pm_score": 8, "selected": false, "text": "<p><a href=\"http://uk.php.net/manual/en/function.pathinfo.php\" rel=\"noreferrer\"><code>pathinfo()</code></a></p>\n\n<...
2008/10/06
[ "https://Stackoverflow.com/questions/173868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9951/" ]
This is a question you can read everywhere on the web with various answers: ``` $ext = end(explode('.', $filename)); $ext = substr(strrchr($filename, '.'), 1); $ext = substr($filename, strrpos($filename, '.') + 1); $ext = preg_replace('/^.*\.([^.]+)$/D', '$1', $filename); $exts = split("[/\\.]", $filename); $n = c...
People from other scripting languages always think theirs is better because they have a built-in function to do that and not PHP (I am looking at Pythonistas right now :-)). In fact, it does exist, but few people know it. Meet [`pathinfo()`](http://php.net/manual/en/function.pathinfo.php): ``` $ext = pathinfo($filena...
173,870
<p>I knew I should never have started using c++ io, the whole "type safety" argument is a red herring (does anyone <em>really</em> find that it's one of their most pressing problems?). Anyhow, I did, and discovered a strange difference between ifstreams and FILE*s and plain old file descriptors: ifstreams cannot read f...
[ { "answer_id": 174095, "author": "Lou Franco", "author_id": 3937, "author_profile": "https://Stackoverflow.com/users/3937", "pm_score": 0, "selected": false, "text": "<p>I have found random issues like this in C++ I/O for years. It has always seemed like a backwards step to me.</p>\n\n<...
2008/10/06
[ "https://Stackoverflow.com/questions/173870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22147/" ]
I knew I should never have started using c++ io, the whole "type safety" argument is a red herring (does anyone *really* find that it's one of their most pressing problems?). Anyhow, I did, and discovered a strange difference between ifstreams and FILE\*s and plain old file descriptors: ifstreams cannot read from a dev...
The device is unbuffered and must be read from in 512 byte multiples. ifstream does it's own buffering and strangely decided to read *1023* bytes ahead, which fails with "Invalid argument". Interestingly, this ifstream is implemented on top of a FILE\*. However, FILE\* left to its own devices was reading ahead using a ...
173,886
<p>Please consider this example class:</p> <pre><code>[Serializable] public class SomeClass { private DateTime _SomeDateTime; public DateTime SomeDateTime { get { return _SomeDateTime; } set { _SomeDateTime = value; } } } </code></pre> <p>I would like to alter the serialization of any...
[ { "answer_id": 173894, "author": "Josh", "author_id": 11702, "author_profile": "https://Stackoverflow.com/users/11702", "pm_score": 2, "selected": false, "text": "<p>Have you thought about simply using a Nullable date time</p>\n\n<pre><code>public DateTime? SomeDateTime {get; set;}\n</co...
2008/10/06
[ "https://Stackoverflow.com/questions/173886", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6651/" ]
Please consider this example class: ``` [Serializable] public class SomeClass { private DateTime _SomeDateTime; public DateTime SomeDateTime { get { return _SomeDateTime; } set { _SomeDateTime = value; } } } ``` I would like to alter the serialization of any DateTime declared in the ...
look at the OnSerializing and OnDeserializing attributes to call custom methods when your objects are serialized. you can impelment some custom logic in there and decouple the serializing process from the actual datatypes.
173,919
<p>When merging topic branch &quot;B&quot; into &quot;A&quot; using <code>git merge</code>, I get some conflicts. I know all the conflicts can be solved using the version in &quot;B&quot;.</p> <p>I am aware of <code>git merge -s ours</code>. But what I want is something like <code>git merge -s theirs</code>.</p> <p>Why...
[ { "answer_id": 173954, "author": "elmarco", "author_id": 1277510, "author_profile": "https://Stackoverflow.com/users/1277510", "pm_score": 4, "selected": false, "text": "<p>I solved my problem using</p>\n\n<pre><code>git checkout -m old\ngit checkout -b new B\ngit merge -s ours old\n</co...
2008/10/06
[ "https://Stackoverflow.com/questions/173919", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1277510/" ]
When merging topic branch "B" into "A" using `git merge`, I get some conflicts. I know all the conflicts can be solved using the version in "B". I am aware of `git merge -s ours`. But what I want is something like `git merge -s theirs`. Why doesn't it exist? How can I achieve the same result after the conflicting mer...
A similar alternative is the `--strategy-option` (short form `-X`) option, which accepts `theirs`. For example: ``` git checkout branchA git merge -X theirs branchB ``` However, this is more equivalent to `-X ours` than `-s ours`. The key difference being that `-X` performs a regular recursive merge, resolving any c...
173,980
<p>There are numerous times you have an interface that accepts similar type arguments that have a separate domain logic meaning:</p> <pre><code>public static class Database { public static bool HasAccess(string userId, string documentId) { return true; } } </code></pre> <p>Now it's quite easy to have someone key d...
[ { "answer_id": 173985, "author": "Johan Bresler", "author_id": 3535708, "author_profile": "https://Stackoverflow.com/users/3535708", "pm_score": 2, "selected": false, "text": "<p>I think you answered your own question - better data integrity and validation, better system</p>\n" }, { ...
2008/10/06
[ "https://Stackoverflow.com/questions/173980", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23164/" ]
There are numerous times you have an interface that accepts similar type arguments that have a separate domain logic meaning: ``` public static class Database { public static bool HasAccess(string userId, string documentId) { return true; } } ``` Now it's quite easy to have someone key documentId instead of userI...
Interesting, but I suspect that in many cases (particularly seialization / RPC APIs) this will only add confustion/overhead. Also - a minor implementation detail, but given this approach I'd make the wrappers fully immutable, not just "internal set" immutable. TBH - I'd probably rather use unit tests for most of this....
173,995
<p>As a function argument I get a <code>vector&lt;double&gt;&amp; vec</code> (an output vector, hence non-const) with unknown length and values. I want to initialise this vector to a specific length n with all zeroes.</p> <p>This will work </p> <pre><code>vec.clear(); vec.resize( n, 0.0 ); </code></pre> <p>And this ...
[ { "answer_id": 173998, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 3, "selected": false, "text": "<pre><code>std::vector&lt;double&gt;(n).swap(vec);\n</code></pre>\n\n<p>This has the advantage of actually compacting your v...
2008/10/06
[ "https://Stackoverflow.com/questions/173995", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19863/" ]
As a function argument I get a `vector<double>& vec` (an output vector, hence non-const) with unknown length and values. I want to initialise this vector to a specific length n with all zeroes. This will work ``` vec.clear(); vec.resize( n, 0.0 ); ``` And this will work as well: ``` vec.resize( n ); vec.assign( n...
``` std::vector<double>(n).swap(vec); ``` After this, vec is guaranteed to have size and capacity n, with all values 0.0. Perhaps the more idiomatic way since C++11 is ``` vec.assign(n, 0.); vec.shrink_to_fit(); ``` with the second line optional. In the case where `vec` starts off with more than `n` elements, whe...
174,005
<p>I have an xml file providing data for a datagrid in Flex 2 that includes an unformatted Price field (ie: it is just a number). Can anyone tell me how I take that datafield and format it - add a currency symbol, put in thousand separators etc. Thanks. S.</p>
[ { "answer_id": 174057, "author": "Simon", "author_id": 24039, "author_profile": "https://Stackoverflow.com/users/24039", "pm_score": 0, "selected": false, "text": "<p>How about the CurrencyFormatter class</p>\n\n<p>See <a href=\"http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common...
2008/10/06
[ "https://Stackoverflow.com/questions/174005", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25463/" ]
I have an xml file providing data for a datagrid in Flex 2 that includes an unformatted Price field (ie: it is just a number). Can anyone tell me how I take that datafield and format it - add a currency symbol, put in thousand separators etc. Thanks. S.
As stated above an easy way to do this would be to add a labelFunction to the specified column and format the data within there. Frequently I find that its much easier to work with objects then straight XML so normally if I am receiving XML from a function I would create an object and parser for that XML and you can f...
174,024
<p>Consider the following method signatures:</p> <pre><code>public fooMethod (Foo[] foos) { /*...*/ } </code></pre> <p>and</p> <pre><code>public fooMethod (Foo... foos) { /*...*/ } </code></pre> <p><em>Explanation: The former takes an array of Foo-objects as an argument - <code>fooMethod(new Foo[]{..})</code> - whi...
[ { "answer_id": 174032, "author": "Garth Gilmour", "author_id": 2635682, "author_profile": "https://Stackoverflow.com/users/2635682", "pm_score": 1, "selected": false, "text": "<p>The latter was introduced in Java 5 and existing libraries are gradually being reworked to support it. You mi...
2008/10/06
[ "https://Stackoverflow.com/questions/174024", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2238/" ]
Consider the following method signatures: ``` public fooMethod (Foo[] foos) { /*...*/ } ``` and ``` public fooMethod (Foo... foos) { /*...*/ } ``` *Explanation: The former takes an array of Foo-objects as an argument - `fooMethod(new Foo[]{..})` - while the latter takes an arbitrary amount of arguments of type Fo...
These methods are actually the same. This feature is called varargs and it is a compiler feature. Behind the scenes is is translates to the former version. There is a pitfall if you define a method that accepts Object... and you sent one parameter of type Object[]!
174,025
<p>How do you trigger a javascript function using actionscript in flash?</p> <p>The goal is to trigger jQuery functionality from a flash movie</p>
[ { "answer_id": 174034, "author": "jochil", "author_id": 23794, "author_profile": "https://Stackoverflow.com/users/23794", "pm_score": 5, "selected": true, "text": "<p>Take a look at the <a href=\"http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.h...
2008/10/06
[ "https://Stackoverflow.com/questions/174025", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2908/" ]
How do you trigger a javascript function using actionscript in flash? The goal is to trigger jQuery functionality from a flash movie
Take a look at the [ExternalInterface](http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html)-Class. From the AS3-Language Reference: > > The ExternalInterface class is the > External API, an application > programming interface that enables > straightforward communicat...
174,069
<p>How can I, in Java or using some other programming language, add a new program group in the applications menu in both KDE and Gnome? </p> <p>I am testing with Ubuntu and Kubuntu 8. Putting a simple .menu file in ~/.config/menus/applications-merged worked in Kubuntu, but the same procedure does nothing in Ubuntu.</p...
[ { "answer_id": 174082, "author": "fly.floh", "author_id": 25442, "author_profile": "https://Stackoverflow.com/users/25442", "pm_score": 0, "selected": false, "text": "<p>In Gnome use System -> Settings -> Menu then just choose New Menu or New Entry.</p>\n" }, { "answer_id": 17408...
2008/10/06
[ "https://Stackoverflow.com/questions/174069", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16873/" ]
How can I, in Java or using some other programming language, add a new program group in the applications menu in both KDE and Gnome? I am testing with Ubuntu and Kubuntu 8. Putting a simple .menu file in ~/.config/menus/applications-merged worked in Kubuntu, but the same procedure does nothing in Ubuntu. The content...
Maybe xdg-desktop-menu does that? See `man xdg-desktop-menu` or <http://manpages.ubuntu.com/manpages/hardy/en/man1/xdg-desktop-menu.html> .
174,093
<p>Assuming I have an ArrayList</p> <pre><code>ArrayList&lt;MyClass&gt; myList; </code></pre> <p>And I want to call toArray, is there a performance reason to use</p> <pre><code>MyClass[] arr = myList.toArray(new MyClass[myList.size()]); </code></pre> <p>over</p> <pre><code>MyClass[] arr = myList.toArray(new MyClas...
[ { "answer_id": 174105, "author": "Matthew Murdoch", "author_id": 4023, "author_profile": "https://Stackoverflow.com/users/4023", "pm_score": -1, "selected": false, "text": "<p>Using 'toArray' with the array of the correct size will perform better as the alternative will create first the ...
2008/10/06
[ "https://Stackoverflow.com/questions/174093", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7581/" ]
Assuming I have an ArrayList ``` ArrayList<MyClass> myList; ``` And I want to call toArray, is there a performance reason to use ``` MyClass[] arr = myList.toArray(new MyClass[myList.size()]); ``` over ``` MyClass[] arr = myList.toArray(new MyClass[0]); ``` ? I prefer the second style, since it's less verbose...
Counterintuitively, the fastest version, on Hotspot 8, is: ``` MyClass[] arr = myList.toArray(new MyClass[0]); ``` I have run a micro benchmark using jmh the results and code are below, showing that the version with an empty array consistently outperforms the version with a presized array. Note that if you can reuse...
174,119
<p>I see this often in the build scripts of projects that use autotools (autoconf, automake). When somebody wants to check the value of a shell variable, they frequently use this idiom:</p> <pre><code>if test "x$SHELL_VAR" = "xyes"; then ... </code></pre> <p>What is the advantage to this over simply checking the val...
[ { "answer_id": 174125, "author": "Ken", "author_id": 20621, "author_profile": "https://Stackoverflow.com/users/20621", "pm_score": -1, "selected": false, "text": "<p>I used to do that in DOS when the SHELL_VAR might be undefined.</p>\n" }, { "answer_id": 174156, "author": "Ke...
2008/10/06
[ "https://Stackoverflow.com/questions/174119", "https://Stackoverflow.com", "https://Stackoverflow.com/users/78437/" ]
I see this often in the build scripts of projects that use autotools (autoconf, automake). When somebody wants to check the value of a shell variable, they frequently use this idiom: ``` if test "x$SHELL_VAR" = "xyes"; then ... ``` What is the advantage to this over simply checking the value like this: ``` if test ...
If you're using a shell that does *simple* substitution and the `SHELL_VAR` variable does not exist (or is blank), then you need to watch out for the edge cases. The following translations will happen: ``` if test $SHELL_VAR = yes; then --> if test = yes; then if test x$SHELL_VAR = xyes; then --> if test...
174,143
<p>In SQL Server 2005, is there a way of deleting rows and being told how many were <strong>actually</strong> deleted? </p> <p>I could do a <code>select count(*)</code> with the same conditions, but I need this to be utterly trustworthy. </p> <p>My first guess was to use the <code>@@ROWCOUNT</code> variables - but t...
[ { "answer_id": 174157, "author": "Corey Trager", "author_id": 9328, "author_profile": "https://Stackoverflow.com/users/9328", "pm_score": -1, "selected": false, "text": "<p>Create temp table with one column, id.</p>\n\n<p>Insert into temp table selecting the ids you want to delete. That...
2008/10/06
[ "https://Stackoverflow.com/questions/174143", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2902/" ]
In SQL Server 2005, is there a way of deleting rows and being told how many were **actually** deleted? I could do a `select count(*)` with the same conditions, but I need this to be utterly trustworthy. My first guess was to use the `@@ROWCOUNT` variables - but that isn't set, e.g. ``` delete from mytable where...
Have you tried `SET NOCOUNT OFF`?
174,153
<p>In C#, does anybody know why the following will compile:</p> <pre><code>int i = 1; ++i; i++; </code></pre> <p>but this will not compile?</p> <pre><code>int i = 1; ++i++; </code></pre> <p>(Compiler error: The operand of an increment or decrement operator must be a variable, property or indexer.)</p>
[ { "answer_id": 174160, "author": "steffenj", "author_id": 15328, "author_profile": "https://Stackoverflow.com/users/15328", "pm_score": -1, "selected": false, "text": "<p>My guess: to avoid such ugly and unnecessary constructs. Also it would use 2 operations (2x INC) instead of one (1x A...
2008/10/06
[ "https://Stackoverflow.com/questions/174153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1463/" ]
In C#, does anybody know why the following will compile: ``` int i = 1; ++i; i++; ``` but this will not compile? ``` int i = 1; ++i++; ``` (Compiler error: The operand of an increment or decrement operator must be a variable, property or indexer.)
you are running one of the operands on the result of the other, the result of a increment/decrement is a value - and you can not use increment/decrement on a value it has to be a variable that can be set.
174,155
<p>Switch statement fallthrough is one of my personal major reasons for loving <code>switch</code> vs. <code>if/else if</code> constructs. An example is in order here:</p> <pre><code>static string NumberToWords(int number) { string[] numbers = new string[] { "", "one", "two", "three", "four", "five", ...
[ { "answer_id": 174176, "author": "Ken", "author_id": 20621, "author_profile": "https://Stackoverflow.com/users/20621", "pm_score": 2, "selected": false, "text": "<p>They changed the switch statement (from C/Java/C++) behavior for c#. I guess the reasoning was that people forgot about th...
2008/10/06
[ "https://Stackoverflow.com/questions/174155", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15537/" ]
Switch statement fallthrough is one of my personal major reasons for loving `switch` vs. `if/else if` constructs. An example is in order here: ``` static string NumberToWords(int number) { string[] numbers = new string[] { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nin...
(Copy/paste of an [answer I provided elsewhere](https://stackoverflow.com/questions/9033/hidden-features-of-c?answer=90432#90432)) Falling through `switch`-`case`s can be achieved by having no code in a `case` (see `case 0`), or using the special `goto case` (see `case 1`) or `goto default` (see `case 2`) forms: ``` ...
174,163
<p>Is entity framework just a fancy name for another CRUD code generator?</p> <p>Or is there more to it?</p>
[ { "answer_id": 174176, "author": "Ken", "author_id": 20621, "author_profile": "https://Stackoverflow.com/users/20621", "pm_score": 2, "selected": false, "text": "<p>They changed the switch statement (from C/Java/C++) behavior for c#. I guess the reasoning was that people forgot about th...
2008/10/06
[ "https://Stackoverflow.com/questions/174163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Is entity framework just a fancy name for another CRUD code generator? Or is there more to it?
(Copy/paste of an [answer I provided elsewhere](https://stackoverflow.com/questions/9033/hidden-features-of-c?answer=90432#90432)) Falling through `switch`-`case`s can be achieved by having no code in a `case` (see `case 0`), or using the special `goto case` (see `case 1`) or `goto default` (see `case 2`) forms: ``` ...
174,190
<p>I have a Rails application for project management where there are Project and Task models. A project can have many tasks, but a task can also have many tasks, ad infinitum.</p> <p>Using nested resources, we can have /projects/1/tasks, /projects/1/tasks/new, /projects/1/tasks/3/edit etc.</p> <p>However, how do you ...
[ { "answer_id": 174227, "author": "Kent Fredric", "author_id": 15614, "author_profile": "https://Stackoverflow.com/users/15614", "pm_score": 2, "selected": false, "text": "<p>there's no reason they should have decendant URLS. </p>\n\n<p>logically:</p>\n\n<pre>\n/projects/1 --> project 1 ...
2008/10/06
[ "https://Stackoverflow.com/questions/174190", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25484/" ]
I have a Rails application for project management where there are Project and Task models. A project can have many tasks, but a task can also have many tasks, ad infinitum. Using nested resources, we can have /projects/1/tasks, /projects/1/tasks/new, /projects/1/tasks/3/edit etc. However, how do you represent the rec...
Going anywhere beyond a single nested route is generally considered a bad idea. From page 108 of **The Rails Way**: ["*Jamis Busk a very influential figure in the Rails community, almost as much as David himself. In February 2007, vis his blog, he basically told us that deep nesting was a \_bad\_ thing, and proposed ...
174,198
<p>With the new approach of having the get/set within the attribut of the class like that :</p> <pre><code>public string FirstName { get; set; } </code></pre> <p>Why simply not simply put the attribute FirstName public without accessor?</p>
[ { "answer_id": 174201, "author": "Coincoin", "author_id": 42, "author_profile": "https://Stackoverflow.com/users/42", "pm_score": 4, "selected": false, "text": "<p>Because, in the future, if you change the implementation, code using the current interface won't break.</p>\n\n<p>For instan...
2008/10/06
[ "https://Stackoverflow.com/questions/174198", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21386/" ]
With the new approach of having the get/set within the attribut of the class like that : ``` public string FirstName { get; set; } ``` Why simply not simply put the attribute FirstName public without accessor?
Two of the big problems with direct access to variable inside class (field/attribute) are: 1) You can't easily databind against fields. 2) If you expose public fields from your classes you can't later change them to properties (for example: to add validation logic to the setters)
174,232
<p>Basically I'm trying to accomplish the same thing that "mailto:bgates@microsoft.com" does in Internet Explorer Mobile.</p> <p>But I want to be able to do it from a managed Windows Mobile application. I don't want to send an email pro grammatically in the background.</p> <p>I want to be able to create the email in ...
[ { "answer_id": 174312, "author": "Petros", "author_id": 2812, "author_profile": "https://Stackoverflow.com/users/2812", "pm_score": 4, "selected": true, "text": "<p>I assume you use C#. You add a reference to System.Diagnostics and then write the following code:</p>\n\n<pre><code>Process...
2008/10/06
[ "https://Stackoverflow.com/questions/174232", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23294/" ]
Basically I'm trying to accomplish the same thing that "mailto:bgates@microsoft.com" does in Internet Explorer Mobile. But I want to be able to do it from a managed Windows Mobile application. I don't want to send an email pro grammatically in the background. I want to be able to create the email in Pocket Outlook an...
I assume you use C#. You add a reference to System.Diagnostics and then write the following code: ``` ProcessStartInfo psi = new ProcessStartInfo("mailto:bla@bla.com?subject=MySubject", ""); Process.Start(psi); ``` This will start the default email client on your mobile device. The [mailto protocol definition](h...
174,239
<p>I have inherited a c# class 'Button' (which I can't change) which clashes with the BCL class 'Windows.Forms.Button'. Normally, Id be very happy to go:</p> <pre><code>MyPackage.MyClass.Button; </code></pre> <p>But there are a large number or references to this class which is a pain to have to re-type.</p> <p>Is th...
[ { "answer_id": 174252, "author": "Vincent McNabb", "author_id": 16299, "author_profile": "https://Stackoverflow.com/users/16299", "pm_score": 2, "selected": false, "text": "<p>You could remove <code>using Windows.Forms;</code> from the top of the code. That would of course mean that you ...
2008/10/06
[ "https://Stackoverflow.com/questions/174239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1816/" ]
I have inherited a c# class 'Button' (which I can't change) which clashes with the BCL class 'Windows.Forms.Button'. Normally, Id be very happy to go: ``` MyPackage.MyClass.Button; ``` But there are a large number or references to this class which is a pain to have to re-type. Is there any way to get the compiler (...
Add this to the top of the file: ``` using MyButton = MyPackage.MyClass.Button; ``` Now you can reference your custom button using a distinct name. You may need to do something similar for the stock button if you use that anywhere in the same file.
174,263
<p>This may be simple one, but 5 mins of Googling didn't give me the answer. How do you save and load bitmaps using .Net librabries?</p> <p>I have an Image object and I need to save it to disk in some format (preferably png) and load back in later. A C# example would be great.</p>
[ { "answer_id": 174276, "author": "Mitchel Sellers", "author_id": 13279, "author_profile": "https://Stackoverflow.com/users/13279", "pm_score": 0, "selected": false, "text": "<p>About 10 seconds of google lead me to <a href=\"http://msdn.microsoft.com/en-us/library/9t4syfhh.aspx\" rel=\"n...
2008/10/06
[ "https://Stackoverflow.com/questions/174263", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1660/" ]
This may be simple one, but 5 mins of Googling didn't give me the answer. How do you save and load bitmaps using .Net librabries? I have an Image object and I need to save it to disk in some format (preferably png) and load back in later. A C# example would be great.
Here's a really simple example. **Top of code file** ``` using System.Drawing; ``` **In code** ``` Image test = new Bitmap("picture.bmp"); test.Save("picture.png", System.Drawing.Imaging.ImageFormat.Png); ``` Remember to give write permissions to the ASPNET user for the folder where the image is to be saved.
174,292
<p>The array has lots of data and I need to delete two elements. </p> <p>Below is the code snippet I am using,</p> <pre><code>my @array = (1,2,3,4,5,5,6,5,4,9); my $element_omitted = 5; @array = grep { $_ != $element_omitted } @array; </code></pre>
[ { "answer_id": 174298, "author": "spoulson", "author_id": 3347, "author_profile": "https://Stackoverflow.com/users/3347", "pm_score": 4, "selected": false, "text": "<p><a href=\"http://www.perlmonks.org/?node=perlfunc%3Asplice\" rel=\"noreferrer\">splice</a> will remove array element(s) ...
2008/10/06
[ "https://Stackoverflow.com/questions/174292", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21246/" ]
The array has lots of data and I need to delete two elements. Below is the code snippet I am using, ``` my @array = (1,2,3,4,5,5,6,5,4,9); my $element_omitted = 5; @array = grep { $_ != $element_omitted } @array; ```
Use splice if you already know the index of the element you want to delete. Grep works if you are searching. If you need to do a lot of these, you will get much better performance if you keep your array in sorted order, since you can then do binary search to find the necessary index. If it makes sense in your contex...
174,297
<p>Try running these two simple statements on Oracle 10.2:</p> <pre><code>CREATE TABLE mytest (table_name varchar2(30), index_name varchar2(30), column_expression clob, column_position number); INSERT INTO mytest (table_name, index_name, column_expression, column_position) SELECT table_nam...
[ { "answer_id": 175474, "author": "Michael OShea", "author_id": 13178, "author_profile": "https://Stackoverflow.com/users/13178", "pm_score": 1, "selected": false, "text": "<p>If Michel Cadot <a href=\"http://www.orafaq.com/forum/mv/msg/125912/352199/0/\" rel=\"nofollow noreferrer\">says<...
2008/10/06
[ "https://Stackoverflow.com/questions/174297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Try running these two simple statements on Oracle 10.2: ``` CREATE TABLE mytest (table_name varchar2(30), index_name varchar2(30), column_expression clob, column_position number); INSERT INTO mytest (table_name, index_name, column_expression, column_position) SELECT table_name, index_name,...
If Michel Cadot [says](http://www.orafaq.com/forum/mv/msg/125912/352199/0/) its a bug, then its almost certainly a bug.
174,308
<p>Eclipse is a really great editor, which I prefer to use, but the GUI design tools for Eclipse are lacking. On the other hand, NetBeans works really well for GUI design. </p> <p>Are there any tips, tricks or pitfalls for using NetBeans for GUI design and Eclipse for everything else on the same project?</p> <p><st...
[ { "answer_id": 174377, "author": "Tom", "author_id": 22850, "author_profile": "https://Stackoverflow.com/users/22850", "pm_score": 3, "selected": false, "text": "<p>MyEclipse offers an integration of the Netbeans GUI editor (Matisse) with Eclipse.</p>\n\n<p>See <a href=\"http://www.myecl...
2008/10/06
[ "https://Stackoverflow.com/questions/174308", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17712/" ]
Eclipse is a really great editor, which I prefer to use, but the GUI design tools for Eclipse are lacking. On the other hand, NetBeans works really well for GUI design. Are there any tips, tricks or pitfalls for using NetBeans for GUI design and Eclipse for everything else on the same project? **EDIT:** I tried Mave...
Create your GUI with Netbeans. copy a Eclipse .project file (like below) into the project folder change the MyProjectName. Open Eclipse and import the project into your workspace, so you can open the projekt from your Eclipse workspace with Netbeans. Now you able to use Netbeans to create and change the GUI and editing...
174,348
<p>Will content requested over https still be cached by web browsers or do they consider this insecure behaviour? If this is the case is there anyway to tell them it's ok to cache?</p>
[ { "answer_id": 174485, "author": "ConroyP", "author_id": 2287, "author_profile": "https://Stackoverflow.com/users/2287", "pm_score": 8, "selected": true, "text": "<p>By default web browsers should cache content over HTTPS the same as over HTTP, unless explicitly told otherwise via the <a...
2008/10/06
[ "https://Stackoverflow.com/questions/174348", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21030/" ]
Will content requested over https still be cached by web browsers or do they consider this insecure behaviour? If this is the case is there anyway to tell them it's ok to cache?
By default web browsers should cache content over HTTPS the same as over HTTP, unless explicitly told otherwise via the [HTTP Headers](http://en.wikipedia.org/wiki/List_of_HTTP_headers) received. [This link](https://www.mnot.net/cache_docs/) is a good introduction to setting cache setting in HTTP headers. > > is the...
174,351
<p>What is an effective algorithm for nesting 1 dimensional lengths into predefined stock lengths?</p> <p>For example, If you required steel bars in the following quantities and lengths,</p> <ul> <li>5 x 2 metres </li> <li>5 x 3 metres</li> <li>5 x 4 metres</li> </ul> <p>and these can be cut from 10 metre bars. How ...
[ { "answer_id": 174357, "author": "plinth", "author_id": 20481, "author_profile": "https://Stackoverflow.com/users/20481", "pm_score": 3, "selected": false, "text": "<p><a href=\"http://www.nist.gov/dads/HTML/binpacking.html\" rel=\"nofollow noreferrer\">Least Cost Bin Packing</a></p>\n\n...
2008/10/06
[ "https://Stackoverflow.com/questions/174351", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18966/" ]
What is an effective algorithm for nesting 1 dimensional lengths into predefined stock lengths? For example, If you required steel bars in the following quantities and lengths, * 5 x 2 metres * 5 x 3 metres * 5 x 4 metres and these can be cut from 10 metre bars. How could you calculate the pattern for cutting the 10...
Actually, there's an even more specific problem that applies: The [cutting stock problem](http://en.wikipedia.org/wiki/Cutting_stock_problem): > > The cutting stock problem is an > optimization problem, or more > specifically, an integer linear > programming problem. It arises from > many applications in industry...
174,352
<p>I currently have a DetailsView in ASP.NET that gets data from the database based on an ID passed through a QueryString. What I've been trying to do now is to then use that same ID in a new cookie that is created when a user clicks either a ButtonField or a HyperLinkField.</p> <p>What I have in the .aspx is this:</p...
[ { "answer_id": 174391, "author": "Rob", "author_id": 2595, "author_profile": "https://Stackoverflow.com/users/2595", "pm_score": 0, "selected": false, "text": "<p>I noticed you're putting the key in the grid itself (DataKeyNames=\"ArtID\"). You have access to that in your event handler ...
2008/10/06
[ "https://Stackoverflow.com/questions/174352", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17020/" ]
I currently have a DetailsView in ASP.NET that gets data from the database based on an ID passed through a QueryString. What I've been trying to do now is to then use that same ID in a new cookie that is created when a user clicks either a ButtonField or a HyperLinkField. What I have in the .aspx is this: ``` <asp:De...
Use the CommandName and the CommandArgument parameters of the Button class. Specifying a CommandName will expose the ItemCommand event. From there you can check for the CommandName, easily grab the CommandArgument (the ID of your row or item) then push whatever data your need into your cookie that way. More formally, ...
174,356
<p>I'm tidying up some older code that uses 'magic numbers' all over the place to set hardware registers, and I would like to use constants instead of these numbers to make the code somewhat more expressive (in fact they will map to the names/values used to document the registers).</p> <p>However, I'm concerned that w...
[ { "answer_id": 174360, "author": "Christian.K", "author_id": 21567, "author_profile": "https://Stackoverflow.com/users/21567", "pm_score": 4, "selected": false, "text": "<p>Checkout boost's <a href=\"http://www.boost.org/doc/libs/1_36_0/doc/html/boost_staticassert.html\" rel=\"noreferrer...
2008/10/06
[ "https://Stackoverflow.com/questions/174356", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4071/" ]
I'm tidying up some older code that uses 'magic numbers' all over the place to set hardware registers, and I would like to use constants instead of these numbers to make the code somewhat more expressive (in fact they will map to the names/values used to document the registers). However, I'm concerned that with the vo...
**NEW ANSWER** : In my original answer (below), I had to have two different macros to support assertions in a function scope and at the global scope. I wondered if it was possible to come up with a single solution that would work in both scopes. I was able to find a solution that worked for Visual Studio and Comeau c...
174,375
<p>I am using my own db for phpbb3 forum, and I wish to insert some data from the forum into my own tables. Now, I can make my own connection and it runs my query but in trying to use the $db variable(which I think is what you're meant to use??) it gives me an error.</p> <p>I would like someone to show me the bare bon...
[ { "answer_id": 174395, "author": "Cetra", "author_id": 15087, "author_profile": "https://Stackoverflow.com/users/15087", "pm_score": 1, "selected": false, "text": "<p>Well.. You haven't given us very much information, but there are two things you need to do to connect and query to a data...
2008/10/06
[ "https://Stackoverflow.com/questions/174375", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25491/" ]
I am using my own db for phpbb3 forum, and I wish to insert some data from the forum into my own tables. Now, I can make my own connection and it runs my query but in trying to use the $db variable(which I think is what you're meant to use??) it gives me an error. I would like someone to show me the bare bones which i...
Well.. You haven't given us very much information, but there are two things you need to do to connect and query to a database. For phpbb, you may want to read the documentation they have presented: <http://wiki.phpbb.com/Database_Abstraction_Layer> Here is a general overview of how you'd execute a query: ``` includ...
174,380
<p>Within a spring webflow, i need to implement a navigation bar that will allow to "step back" or resume the flow to one of the previous view.</p> <p>For example :</p> <ul> <li>View 1 = login</li> <li>View 2 = My informations</li> <li>View 3 = My messages</li> <li>View 4 = Close session</li> </ul> <p>For this examp...
[ { "answer_id": 175279, "author": "MetroidFan2002", "author_id": 8026, "author_profile": "https://Stackoverflow.com/users/8026", "pm_score": 2, "selected": false, "text": "<p>It depends how you're going about doing this. If you're doing this within a single flow, you'll have something li...
2008/10/06
[ "https://Stackoverflow.com/questions/174380", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25492/" ]
Within a spring webflow, i need to implement a navigation bar that will allow to "step back" or resume the flow to one of the previous view. For example : * View 1 = login * View 2 = My informations * View 3 = My messages * View 4 = Close session For this example, i would like to return back to view 2 from the view ...
It depends how you're going about doing this. If you're doing this within a single flow, you'll have something like this: ``` <view-state id="loginView" view="login.jsp"> <action-state bean="someBean" method="login" /> <transition on="success" to="informationView" /> </view-state> <view-state id="information...
174,381
<p>I am trying to match floating-point decimal numbers with a regular expression. There may or may not be a number before the decimal, and the decimal may or may not be present, and if it is present it may or may not have digits after it. (For this application, a leading +/- or a trailing "E123" is not allowed). I h...
[ { "answer_id": 174392, "author": "Andru Luvisi", "author_id": 5922, "author_profile": "https://Stackoverflow.com/users/5922", "pm_score": 4, "selected": true, "text": "<p>I think this will do what you want. It either starts with a digit, in which case the decimal point and digits after ...
2008/10/06
[ "https://Stackoverflow.com/questions/174381", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18511/" ]
I am trying to match floating-point decimal numbers with a regular expression. There may or may not be a number before the decimal, and the decimal may or may not be present, and if it is present it may or may not have digits after it. (For this application, a leading +/- or a trailing "E123" is not allowed). I have wr...
I think this will do what you want. It either starts with a digit, in which case the decimal point and digits after it are optional, or it starts with a decimal point, in which case at least one digit is mandatory after it. ``` /^\d+(\.\d*)?|\.\d+$/ ```
174,393
<p>This PHP code...</p> <pre><code>207 if (getenv(HTTP_X_FORWARDED_FOR)) { 208 $ip = getenv('HTTP_X_FORWARD_FOR'); 209 $host = gethostbyaddr($ip); 210 } else { 211 $ip = getenv('REMOTE_ADDR'); 212 $host = gethostbyaddr($ip); 213 } </code></pre> <p>Throws this warning...</p> <...
[ { "answer_id": 174422, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 2, "selected": false, "text": "<p>Why don't you use </p>\n\n<pre><code>$_SERVER['REMOTE_ADDR'] \n</code></pre>\n\n<p>and </p>\n\n<pre><code>$_SERVE...
2008/10/06
[ "https://Stackoverflow.com/questions/174393", "https://Stackoverflow.com", "https://Stackoverflow.com/users/83/" ]
This PHP code... ``` 207 if (getenv(HTTP_X_FORWARDED_FOR)) { 208 $ip = getenv('HTTP_X_FORWARD_FOR'); 209 $host = gethostbyaddr($ip); 210 } else { 211 $ip = getenv('REMOTE_ADDR'); 212 $host = gethostbyaddr($ip); 213 } ``` Throws this warning... > > **Warning:** gethostbyaddr...
on php.net it says the following: > > The function `getenv` does not work if your Server API is ASAPI (IIS). > So, try to don't use `getenv('REMOTE_ADDR')`, but `$_SERVER["REMOTE_ADDR"]`. > > > Did you maybe try to do it with `$_SERVER`?
174,403
<p>In my vb.net program, I am using a webbrowser to show the user an HTML preview. I was previously hitting a server to grab the HTML, then returning on an asynchronous thread and raising an event to populate the WebBrowser.DocumentText with the HTML string I was returning.</p> <p>Now I set it up to grab all of the i...
[ { "answer_id": 174483, "author": "David Mohundro", "author_id": 4570, "author_profile": "https://Stackoverflow.com/users/4570", "pm_score": 7, "selected": true, "text": "<p>Try the following:</p>\n<pre class=\"lang-cs prettyprint-override\"><code>browser.Navigate(&quot;about:blank&quot;)...
2008/10/06
[ "https://Stackoverflow.com/questions/174403", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13244/" ]
In my vb.net program, I am using a webbrowser to show the user an HTML preview. I was previously hitting a server to grab the HTML, then returning on an asynchronous thread and raising an event to populate the WebBrowser.DocumentText with the HTML string I was returning. Now I set it up to grab all of the information ...
Try the following: ```cs browser.Navigate("about:blank"); HtmlDocument doc = browser.Document; doc.Write(String.Empty); browser.DocumentText = _emailHTML; ``` I've found that the `WebBrowser` control usually needs to be initialized to `about:blank` anyway. The same needs to be done between navigates to different typ...
174,412
<p>I'm having trouble figuring out how to access a cookie from a compiled object. I'm trying to make a compiled (DLL) object that will check the users cookie and then compare that to a database to confirm they have the correct access. </p> <p>I can pass in the cookie info fine and the component will work, but I'm tryi...
[ { "answer_id": 174427, "author": "martin", "author_id": 8421, "author_profile": "https://Stackoverflow.com/users/8421", "pm_score": 3, "selected": true, "text": "<p>Objects (App_Code/ compiled dlls) can only access Request via the static HttpContext.Current object</p>\n\n<pre><code>HttpC...
2008/10/06
[ "https://Stackoverflow.com/questions/174412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9581/" ]
I'm having trouble figuring out how to access a cookie from a compiled object. I'm trying to make a compiled (DLL) object that will check the users cookie and then compare that to a database to confirm they have the correct access. I can pass in the cookie info fine and the component will work, but I'm trying to have...
Objects (App\_Code/ compiled dlls) can only access Request via the static HttpContext.Current object ``` HttpCookie cookie = HttpContext.Current.Request.Cookies["CookieName"]; ``` (If it's not called from a web app, HttpContext.Current is null, so you may want to check for that when running in unit testing) (If this...
174,418
<p>I've written a little script to iterate across files in folders to count lines of code.</p> <p>The heart of the script is this function to count lines of whitespace, comments, and code. (Note that for the moment it is tailored to C# and doesn't know about multi-line comments).</p> <p>It just doesn't look very nice...
[ { "answer_id": 174429, "author": "Tom Ritter", "author_id": 8435, "author_profile": "https://Stackoverflow.com/users/8435", "pm_score": 1, "selected": false, "text": "<p>A better site for this might be <a href=\"http://refactormycode.com/\" rel=\"nofollow noreferrer\">refactormycode</a> ...
2008/10/06
[ "https://Stackoverflow.com/questions/174418", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11410/" ]
I've written a little script to iterate across files in folders to count lines of code. The heart of the script is this function to count lines of whitespace, comments, and code. (Note that for the moment it is tailored to C# and doesn't know about multi-line comments). It just doesn't look very nice to me - has anyo...
I think what you have is fine, but here's some variety to mix it up. (This solution repeats your problem of ignoring trailing whitespace.) ``` type Line = | Whitespace = 0 | Comment = 1 | Code = 2 let Classify (l:string) = let s = l.TrimStart([|' ';'\t'|]) match s with | "" | "...
174,430
<p>I decided to use <a href="http://logging.apache.org/log4net/index.html" rel="noreferrer">log4net</a> as a logger for a new webservice project. Everything is working fine, but I get a lot of messages like the one below, for every log4net tag I am using in my <code>web.config</code>:</p> <blockquote> <p>Could not f...
[ { "answer_id": 174463, "author": "wcm", "author_id": 2173, "author_profile": "https://Stackoverflow.com/users/2173", "pm_score": 1, "selected": false, "text": "<p>Have you tried using a separate log4net.config file?</p>\n" }, { "answer_id": 174534, "author": "Wheelie", "a...
2008/10/06
[ "https://Stackoverflow.com/questions/174430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11387/" ]
I decided to use [log4net](http://logging.apache.org/log4net/index.html) as a logger for a new webservice project. Everything is working fine, but I get a lot of messages like the one below, for every log4net tag I am using in my `web.config`: > > Could not find schema information for > the element 'log4net'... > >...
I had a different take, and needed the following syntax: ``` [assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.xml", Watch = true)] ``` which differs from xsl's last post, but made a difference for me. Check out this [blog post](https://web.archive.org/web/20160314225551/http://verysimple.com/2007/02/0...
174,438
<p>I have two tables, <strong>Book</strong> and <strong>Tag</strong>, and books are tagged using the association table <strong>BookTag</strong>. I want to create a report that contains a list of books, and for each book a list of the book's tags. Tag IDs will suffice, tag names are not necessary.</p> <p>Example:</p> ...
[ { "answer_id": 174466, "author": "Bob Probst", "author_id": 12424, "author_profile": "https://Stackoverflow.com/users/12424", "pm_score": 0, "selected": false, "text": "<p>Unless you know what the tag ids/names are and can hard code them into your query, I'm afraid the answer is no.</p>\...
2008/10/06
[ "https://Stackoverflow.com/questions/174438", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6120/" ]
I have two tables, **Book** and **Tag**, and books are tagged using the association table **BookTag**. I want to create a report that contains a list of books, and for each book a list of the book's tags. Tag IDs will suffice, tag names are not necessary. Example: ``` Book table: Book ID | Book Name 28 | Dracula...
You can almost do it. The only problem I haven't resolved is the comma delimiter. Here is a query on a similar structure that separates the tags using a space. ``` SELECT em.Code, (SELECT et.Name + ' ' AS 'data()' FROM tblEmployeeTag et JOIN tblEmployeeTagAssignment eta ON et.Id = eta.Employee...
174,446
<p>I have about 200 Excel files that are in standard Excel 2003 format. </p> <p>I need them all to be saved as Excel xml - basically the same as opening each file and choosing <strong>Save As...</strong> and then choosing <strong>Save as type:</strong> <em>XML Spreadsheet</em></p> <p>Would you know any simple way of ...
[ { "answer_id": 174493, "author": "Lou Franco", "author_id": 3937, "author_profile": "https://Stackoverflow.com/users/3937", "pm_score": 2, "selected": false, "text": "<p>You could adapt the code I posted here:</p>\n\n<p><a href=\"http://www.atalasoft.com/cs/blogs/loufranco/archive/2008/0...
2008/10/06
[ "https://Stackoverflow.com/questions/174446", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3241/" ]
I have about 200 Excel files that are in standard Excel 2003 format. I need them all to be saved as Excel xml - basically the same as opening each file and choosing **Save As...** and then choosing **Save as type:** *XML Spreadsheet* Would you know any simple way of automating that task?
Here is a routine that will convert all files in a single directory that have a .xls extension. It takes a straight forward approach. Any VBA code in a workbook is stripped out, the workbook is not saved with a .xlsm extension. Any incompatability warning are not dislayed, instead the changes are automatically accepte...
174,458
<p>There is <a href="https://stackoverflow.com/questions/134698/catching-exceptions-as-expected-program-execution-flow-control">an interesting post over here</a> about this, in relation to cross-application flow of control. </p> <p>Well, recently, I've come across an interesting problem. Generating the nth value in a ...
[ { "answer_id": 174469, "author": "Mitchel Sellers", "author_id": 13279, "author_profile": "https://Stackoverflow.com/users/13279", "pm_score": 4, "selected": true, "text": "<p>In this case I would be looking at your Walk_r method, you should have something that returns a value, throwing ...
2008/10/06
[ "https://Stackoverflow.com/questions/174458", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15537/" ]
There is [an interesting post over here](https://stackoverflow.com/questions/134698/catching-exceptions-as-expected-program-execution-flow-control) about this, in relation to cross-application flow of control. Well, recently, I've come across an interesting problem. Generating the nth value in a potentially (practica...
In this case I would be looking at your Walk\_r method, you should have something that returns a value, throwing an exception to indicate success, is NOT a common practice, and at minimum is going to be VERY confusing to anyone that sees the code. Not to mention the overhead associated with exceptions.
174,502
<p>Seeing as Java doesn't have nullable types, nor does it have a TryParse(), how do you handle input validation without throwing an exceptions?</p> <p>The usual way:</p> <pre><code>String userdata = /*value from gui*/ int val; try { val = Integer.parseInt(userdata); } catch (NumberFormatException nfe) { // bad...
[ { "answer_id": 174519, "author": "arinte", "author_id": 22763, "author_profile": "https://Stackoverflow.com/users/22763", "pm_score": -1, "selected": false, "text": "<p>Put some if statements in front of it.\nif (null != userdata )</p>\n" }, { "answer_id": 174523, "author": "...
2008/10/06
[ "https://Stackoverflow.com/questions/174502", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18907/" ]
Seeing as Java doesn't have nullable types, nor does it have a TryParse(), how do you handle input validation without throwing an exceptions? The usual way: ``` String userdata = /*value from gui*/ int val; try { val = Integer.parseInt(userdata); } catch (NumberFormatException nfe) { // bad data - set to sentin...
That's pretty much it, although returning MIN\_VALUE is kind of questionable, unless you're sure it's the right thing to use for what you're essentially using as an error code. At the very least I'd document the error code behavior, though. Might also be useful (depending on the application) to log the bad input so yo...
174,515
<p>I need to copy several tables from one DB to another in SQL Server 2000, using C# (VS 2005). The call needs to be parameterized - I need to be able to pass in the name of the database to which I am going to be copying these tables.</p> <p>I could use DTS with parameters, but I can't find any sample code that does ...
[ { "answer_id": 174539, "author": "Kev", "author_id": 419, "author_profile": "https://Stackoverflow.com/users/419", "pm_score": 1, "selected": false, "text": "<p>If the destination table is being dropped every time then why not do SELECT INTO? Doesn't seem like a kludge at all. </p>\n\n<p...
2008/10/06
[ "https://Stackoverflow.com/questions/174515", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7850/" ]
I need to copy several tables from one DB to another in SQL Server 2000, using C# (VS 2005). The call needs to be parameterized - I need to be able to pass in the name of the database to which I am going to be copying these tables. I could use DTS with parameters, but I can't find any sample code that does this from C...
For SQL Server 7.0 and 2000, we have SQLDMO for this. For SQL Server 2005 there is SMO. This allows you do to pretty much everything related to administering the database, scripting objects, enumerating databases, and much more. This is better, IMO, than trying a "roll your own" approach. SQL 2000: [Developing SQL-DMO...
174,516
<p>I have a table that records a sequence of actions with a field that records the sequence order:</p> <pre><code>user data sequence 1 foo 0 1 bar 1 1 baz 2 2 foo 0 3 bar 0 3 foo 1 </code></pre> <p>Selecting the first item for each user is easy enough ...
[ { "answer_id": 174537, "author": "Keith", "author_id": 905, "author_profile": "https://Stackoverflow.com/users/905", "pm_score": 4, "selected": true, "text": "<p>This sql will return the record with the highest sequence value for each user:</p>\n\n<pre><code>select a.user, a.data, a.sequ...
2008/10/06
[ "https://Stackoverflow.com/questions/174516", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11651/" ]
I have a table that records a sequence of actions with a field that records the sequence order: ``` user data sequence 1 foo 0 1 bar 1 1 baz 2 2 foo 0 3 bar 0 3 foo 1 ``` Selecting the first item for each user is easy enough with WHERE sequence = '0' ...
This sql will return the record with the highest sequence value for each user: ``` select a.user, a.data, a.sequence from table as a inner join ( select user, max(sequence) as 'last' from table group by user) as b on a.user = b.user and a.sequence = b.last ```
174,531
<p>What is the simplest way (least error-prone, least lines of code, however you want to interpret it) to open a file in C and read its contents into a string (char*, char[], whatever)?</p>
[ { "answer_id": 174552, "author": "Nils Pipenbrinck", "author_id": 15955, "author_profile": "https://Stackoverflow.com/users/15955", "pm_score": 8, "selected": true, "text": "<p>I tend to just load the entire buffer as a raw memory chunk into memory and do the parsing on my own. That way ...
2008/10/06
[ "https://Stackoverflow.com/questions/174531", "https://Stackoverflow.com", "https://Stackoverflow.com/users/422/" ]
What is the simplest way (least error-prone, least lines of code, however you want to interpret it) to open a file in C and read its contents into a string (char\*, char[], whatever)?
I tend to just load the entire buffer as a raw memory chunk into memory and do the parsing on my own. That way I have best control over what the standard lib does on multiple platforms. This is a stub I use for this. you may also want to check the error-codes for fseek, ftell and fread. (omitted for clarity). ``` cha...
174,532
<p>I recently inherited a database on which one of the tables has the primary key composed of encoded values (Part1*1000 + Part2).<br> I normalized that column, but I cannot change the old values. So now I have</p> <pre><code>select ID from table order by ID ID 100001 100002 101001 ... </code></pre> <p>I want to find...
[ { "answer_id": 174561, "author": "Santiago Palladino", "author_id": 12791, "author_profile": "https://Stackoverflow.com/users/12791", "pm_score": 4, "selected": false, "text": "<pre><code>SELECT (ID+1) FROM table AS t1\nLEFT JOIN table as t2\nON t1.ID+1 = t2.ID\nWHERE t2.ID IS NULL\n</co...
2008/10/06
[ "https://Stackoverflow.com/questions/174532", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25324/" ]
I recently inherited a database on which one of the tables has the primary key composed of encoded values (Part1\*1000 + Part2). I normalized that column, but I cannot change the old values. So now I have ``` select ID from table order by ID ID 100001 100002 101001 ... ``` I want to find the "holes" in the table ...
``` select ID +1 From Table t1 where not exists (select * from Table t2 where t1.id +1 = t2.id); ``` not sure if this version would be faster than the one you mentioned originally.
174,560
<p>How can you depend on test code from another module in Maven? </p> <p>Example, I have 2 modules:</p> <ul> <li>Base</li> <li>Main</li> </ul> <p>I would like a test case in Main to extend a base test class in Base. Is this possible?</p> <p>Update: Found an <a href="https://stackoverflow.com/questions/174560/shar...
[ { "answer_id": 174572, "author": "Steve Moyer", "author_id": 17008, "author_profile": "https://Stackoverflow.com/users/17008", "pm_score": -1, "selected": false, "text": "<p>Yep ... just include the Base module as a dependency in Main. If you're only inheriting test code, then you can u...
2008/10/06
[ "https://Stackoverflow.com/questions/174560", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12880/" ]
How can you depend on test code from another module in Maven? Example, I have 2 modules: * Base * Main I would like a test case in Main to extend a base test class in Base. Is this possible? Update: Found an [acceptable answer](https://stackoverflow.com/questions/174560/sharing-test-code-in-maven#174670), which in...
I recommend using [type instead of classifier](https://maven.apache.org/pom.html#Dependencies) (see also: [classifier](http://maven.apache.org/plugins/maven-deploy-plugin/examples/deploying-with-classifiers.html)). It tells Maven a bit more explicitly what you are doing (and I've found that m2eclipse and q4e both like ...
174,570
<p>I have the following code in one of my aspx pages:</p> <pre><code>&lt;% foreach (Dependency dep in this.Common.GetDependencies(this.Request.QueryString["Name"])) { %&gt; &lt;ctl:DependencyEditor DependencyKey='&lt;%= dep.Key %&gt;' runat="server" /&gt; &lt;% } %&gt; </code></pre> <p>When I run it, I get...
[ { "answer_id": 174626, "author": "steve_c", "author_id": 769, "author_profile": "https://Stackoverflow.com/users/769", "pm_score": 1, "selected": false, "text": "<p>The key property of the Dependency object may be a Guid, but is the DependencyKey Property of the DependencyEditor a Guid t...
2008/10/06
[ "https://Stackoverflow.com/questions/174570", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3226/" ]
I have the following code in one of my aspx pages: ``` <% foreach (Dependency dep in this.Common.GetDependencies(this.Request.QueryString["Name"])) { %> <ctl:DependencyEditor DependencyKey='<%= dep.Key %>' runat="server" /> <% } %> ``` When I run it, I get the following error: ``` **Parser Error Message:...
The key property of the Dependency object may be a Guid, but is the DependencyKey Property of the DependencyEditor a Guid too? If not it should be, otherwise the correct TypeConverter won't be invoked upon assignment. If I'm not mistaken, you could also use dep.Key.ToString() also.
174,582
<p>If I wish to simply rename a column (not change its type or constraints, just its name) in an SQL database using SQL, how do I do that? Or is it not possible?</p> <p>This is for any database claiming to support SQL, I'm simply looking for an SQL-specific query that will work regardless of actual database implement...
[ { "answer_id": 174586, "author": "Galwegian", "author_id": 3201, "author_profile": "https://Stackoverflow.com/users/3201", "pm_score": 7, "selected": false, "text": "<p>Specifically for SQL Server, use <a href=\"http://msdn.microsoft.com/en-us/library/ms188351.aspx\" rel=\"noreferrer\"><...
2008/10/06
[ "https://Stackoverflow.com/questions/174582", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8026/" ]
If I wish to simply rename a column (not change its type or constraints, just its name) in an SQL database using SQL, how do I do that? Or is it not possible? This is for any database claiming to support SQL, I'm simply looking for an SQL-specific query that will work regardless of actual database implementation.
On PostgreSQL (and many other RDBMS), you can do it with regular `ALTER TABLE` statement: ``` => SELECT * FROM Test1; id | foo | bar ----+-----+----- 2 | 1 | 2 => ALTER TABLE Test1 RENAME COLUMN foo TO baz; ALTER TABLE => SELECT * FROM Test1; id | baz | bar ----+-----+----- 2 | 1 | 2 ```
174,595
<p>What is the difference between <code>ROWNUM</code> and <code>ROW_NUMBER</code> ? </p>
[ { "answer_id": 174628, "author": "Tony Andrews", "author_id": 18747, "author_profile": "https://Stackoverflow.com/users/18747", "pm_score": 6, "selected": true, "text": "<p>ROWNUM is a \"pseudocolumn\" that assigns a number to each row returned by a query:</p>\n\n<pre><code>SQL&gt; selec...
2008/10/06
[ "https://Stackoverflow.com/questions/174595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9581/" ]
What is the difference between `ROWNUM` and `ROW_NUMBER` ?
ROWNUM is a "pseudocolumn" that assigns a number to each row returned by a query: ``` SQL> select rownum, ename, deptno 2 from emp; ROWNUM ENAME DEPTNO ---------- ---------- ---------- 1 SMITH 99 2 ALLEN 30 3 WARD 30 4 JONES ...
174,600
<p>In SQL Server 2005, is there a way for a trigger to find out what object is responsible for firing the trigger? I would like to use this to disable the trigger for one stored procedure.</p> <p>Is there any other way to disable the trigger only for the current transaction? I could use the following code, but if I'm ...
[ { "answer_id": 174695, "author": "devio", "author_id": 21336, "author_profile": "https://Stackoverflow.com/users/21336", "pm_score": 2, "selected": false, "text": "<p>ALTER TABLE tbl DISABLE TRIGGER trg</p>\n\n<p><a href=\"http://doc.ddart.net/mssql/sql70/aa-az_5.htm\" rel=\"nofollow nor...
2008/10/06
[ "https://Stackoverflow.com/questions/174600", "https://Stackoverflow.com", "https://Stackoverflow.com/users/357/" ]
In SQL Server 2005, is there a way for a trigger to find out what object is responsible for firing the trigger? I would like to use this to disable the trigger for one stored procedure. Is there any other way to disable the trigger only for the current transaction? I could use the following code, but if I'm not mistak...
I just saw this article recently highlighted on the SQL Server Central newsletter and it appears to offer a way which you may find useful using the Context\_Info on the connection: <http://www.mssqltips.com/tip.asp?tip=1591> --- EDIT by Terrapin: The above link includes the following code: ``` USE AdventureWorks; ...
174,602
<p>It seems like searching with CAML and SPQuery doesn't work properly against custom metadata, when searching for SPFolders instead of files, or when searching for custom content types. I've been using U2U to test a variety of queries, and just not getting anywhere. The doc's aren't very complete on the topic, and g...
[ { "answer_id": 175986, "author": "Nat", "author_id": 13813, "author_profile": "https://Stackoverflow.com/users/13813", "pm_score": 1, "selected": false, "text": "<p>Try adding <a href=\"http://www.codeplex.com/spm\" rel=\"nofollow noreferrer\">SharePoint Manager</a> and <a href=\"http://...
2008/10/06
[ "https://Stackoverflow.com/questions/174602", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1181217/" ]
It seems like searching with CAML and SPQuery doesn't work properly against custom metadata, when searching for SPFolders instead of files, or when searching for custom content types. I've been using U2U to test a variety of queries, and just not getting anywhere. The doc's aren't very complete on the topic, and google...
After more research, I'm answering my own question. Apparently the methods that I'm using to query don't return SPFolders as items in the result set. Only list items are returned, basically just documents. My fix was to execute a CAML query for all the documents with a certain metadata tag/value, and then using the p...
174,612
<p>On a cross platform c/c++ project (Win32, Linux, OSX), I need to use the *printf functions to print some variables of type size_t. In some environments size_t's are 8 bytes and on others they are 4. On glibc I have %zd, and on Win32 I can use <a href="http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx" rel="nor...
[ { "answer_id": 174648, "author": "Head Geek", "author_id": 12193, "author_profile": "https://Stackoverflow.com/users/12193", "pm_score": 1, "selected": false, "text": "<p>I don't know of any satisfying solution, but you might consider a specialized function to format size_t items to a st...
2008/10/06
[ "https://Stackoverflow.com/questions/174612", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23524/" ]
On a cross platform c/c++ project (Win32, Linux, OSX), I need to use the \*printf functions to print some variables of type size\_t. In some environments size\_t's are 8 bytes and on others they are 4. On glibc I have %zd, and on Win32 I can use [%Id](http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx). Is there an ...
The `PRIuPTR` macro (from <inttypes.h>) defines a decimal format for `uintptr_t`, which should always be large enough that you can cast a `size_t` to it without truncating, e.g. ``` fprintf(stream, "Your size_t var has value %" PRIuPTR ".", (uintptr_t) your_var); ```
174,633
<p>My regular expression needs to be able to find the strings:</p> <ol> <li>Visual Studio 2008</li> <li>Visual Studio Express 2008</li> <li>Visual Basic 2008</li> <li>Visual Basic Express 2008</li> <li>Visual C++ 2008</li> <li>Visual C++ Express 2008</li> </ol> <p>and a host of other similar variants, to be replaced ...
[ { "answer_id": 174638, "author": "leppie", "author_id": 15541, "author_profile": "https://Stackoverflow.com/users/15541", "pm_score": 2, "selected": false, "text": "<p>You need to escape the special characters (like +). Also the 'express' bit, should have a space on either side.</p>\n" ...
2008/10/06
[ "https://Stackoverflow.com/questions/174633", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3834/" ]
My regular expression needs to be able to find the strings: 1. Visual Studio 2008 2. Visual Studio Express 2008 3. Visual Basic 2008 4. Visual Basic Express 2008 5. Visual C++ 2008 6. Visual C++ Express 2008 and a host of other similar variants, to be replaced with this one single string > > Visual Studio 2005 > >...
It should be ``` "Visual (Basic|C\+\+|Studio)( Express)? 2008" >>> import re >>> repl = 'Visual Studio 2005' >>> regexp = re.compile('Visual (Studio|Basic|C\+\+)( Express)? 2008') >>> test1 = 'Visual Studio 2008' >>> test2 = 'Visual Studio Express 2008' >>> test3 = 'Visual C++ Express 2008' >>> test4 = 'Visual C++ Ex...
174,659
<p>I'm writing a little tile-based game, for which I'd like to support light sources. But my algorithm-fu is too weak, hence I come to you for help.</p> <p>The situation is like this: There is a tile-based map (held as a 2D array), containing a single light source and several items standing around. I want to calculate...
[ { "answer_id": 174679, "author": "TK.", "author_id": 1816, "author_profile": "https://Stackoverflow.com/users/1816", "pm_score": 3, "selected": false, "text": "<p>Quick and dirty:</p>\n\n<p>(Depending on how big the array is)</p>\n\n<ul>\n<li>Loop through each tile </li>\n<li>draw a li...
2008/10/06
[ "https://Stackoverflow.com/questions/174659", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15255/" ]
I'm writing a little tile-based game, for which I'd like to support light sources. But my algorithm-fu is too weak, hence I come to you for help. The situation is like this: There is a tile-based map (held as a 2D array), containing a single light source and several items standing around. I want to calculate which til...
The roguelike development community has a bit of an obsession with line-of-sight, field-of-view algorithms. Here's a link to a roguelike wiki article on the subject: <http://roguebasin.roguelikedevelopment.org/index.php?title=Field_of_Vision> For my roguelike game, I implemented a shadow casting algorithm (<http://ro...
174,662
<p>I hope this isn't considered a duplicate since it's more pointed than similar questions (I'm curious about a specific weakness in C# to VB.net conversion utilities).</p> <p>I've been looking at using a tool like this <a href="http://www.developerfusion.com/tools/convert/csharp-to-vb/" rel="nofollow noreferrer">.net...
[ { "answer_id": 174677, "author": "Chad Moran", "author_id": 25416, "author_profile": "https://Stackoverflow.com/users/25416", "pm_score": 2, "selected": false, "text": "<p>I'd recommend compiling the code and using something like Red-Gate's reflector <a href=\"http://www.red-gate.com/pro...
2008/10/06
[ "https://Stackoverflow.com/questions/174662", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8513/" ]
I hope this isn't considered a duplicate since it's more pointed than similar questions (I'm curious about a specific weakness in C# to VB.net conversion utilities). I've been looking at using a tool like this [.net code converter](http://www.developerfusion.com/tools/convert/csharp-to-vb/) to convert a class library ...
We've now updated the code generator to support this scenario. If you spot any others that we're not doing very well, please do drop me a line.
174,664
<p>I need to evaluate a mathmatical expression that is presented to me as a string in C#. Example noddy but gets the point across that the string as the expression.</p> <p>I need the evaluate to then populate an int.</p> <p>There is no Eval() in C# like in others langugaes...</p> <pre><code>String myString = "3*4";...
[ { "answer_id": 174678, "author": "NotMe", "author_id": 2424, "author_profile": "https://Stackoverflow.com/users/2424", "pm_score": 2, "selected": false, "text": "<p>You can use the jscript interpreter.\nA great article for it is here: <a href=\"http://www.odetocode.com/Articles/80.aspx\"...
2008/10/06
[ "https://Stackoverflow.com/questions/174664", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I need to evaluate a mathmatical expression that is presented to me as a string in C#. Example noddy but gets the point across that the string as the expression. I need the evaluate to then populate an int. There is no Eval() in C# like in others langugaes... ``` String myString = "3*4"; ``` Edit: I am on VS2008 ...
The way I see it, you have two options - use an expression evaluator or construct, compile and run C# code on the fly. I would go with an expression evaluator library, as you do not have to worry about any security issues. That is, you might not be able to use code generation in medium trust environments, such as mos...
174,705
<p>We have TFS 2008 our build set up to checkout all AssemblyInfo.cs files in the project, update them with AssemblyInfoTask, and then either undo the checkout or checkin depending on whether the build passed or not. Unfortunately, when two builds are queued close together this results in a Partially completed build a...
[ { "answer_id": 174710, "author": "Whisk", "author_id": 908, "author_profile": "https://Stackoverflow.com/users/908", "pm_score": 2, "selected": false, "text": "<p>Have you tried running it in <a href=\"http://msdn.microsoft.com/en-us/library/xee0c8y7(VS.80).aspx\" rel=\"nofollow noreferr...
2008/10/06
[ "https://Stackoverflow.com/questions/174705", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12565/" ]
We have TFS 2008 our build set up to checkout all AssemblyInfo.cs files in the project, update them with AssemblyInfoTask, and then either undo the checkout or checkin depending on whether the build passed or not. Unfortunately, when two builds are queued close together this results in a Partially completed build as th...
Have you tried running it in [safe mode](http://msdn.microsoft.com/en-us/library/xee0c8y7(VS.80).aspx) - if that doesn't let you sort it out you can try the /resetsettings switch, which has sorted out similar problems for me in the past. /resetuserdata can also help.
174,727
<p>Oracle FAQ defines temp table space as follows:</p> <blockquote> <p>Temporary tablespaces are used to manage space for database sort operations and for storing global temporary tables. For example, if you join two large tables, and Oracle cannot do the sort in memory, space will be allocated in a temp...
[ { "answer_id": 174765, "author": "Michael OShea", "author_id": 13178, "author_profile": "https://Stackoverflow.com/users/13178", "pm_score": 5, "selected": true, "text": "<p>I'm not sure exactly what information you have to hand already, but using the following query will point out which...
2008/10/06
[ "https://Stackoverflow.com/questions/174727", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13935/" ]
Oracle FAQ defines temp table space as follows: > > Temporary tablespaces are used to > manage space for database sort > operations and for storing global > temporary tables. For example, if you > join two large tables, and Oracle > cannot do the sort in memory, space > will be allocated in a temporary > table...
I'm not sure exactly what information you have to hand already, but using the following query will point out which program/user/sessions etc are currently using your temp space. ``` SELECT b.TABLESPACE , b.segfile# , b.segblk# , ROUND ( ( ( b.blocks * p.VALUE ) / 1024 / 1024 ), 2 ) size_mb ...
174,730
<p>Given a credit card number and no additional information, what is the best way in PHP to determine whether or not it is a valid number?</p> <p>Right now I need something that will work with American Express, Discover, MasterCard, and Visa, but it might be helpful if it will also work with other types.</p>
[ { "answer_id": 174738, "author": "Chad Moran", "author_id": 25416, "author_profile": "https://Stackoverflow.com/users/25416", "pm_score": -1, "selected": false, "text": "<p>This is only to make sure that the numbers are valid using some basic RegEX patterns.</p>\n\n<p>Note, this does not...
2008/10/06
[ "https://Stackoverflow.com/questions/174730", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18986/" ]
Given a credit card number and no additional information, what is the best way in PHP to determine whether or not it is a valid number? Right now I need something that will work with American Express, Discover, MasterCard, and Visa, but it might be helpful if it will also work with other types.
There are three parts to the validation of the card number: 1. **PATTERN** - does it match an issuers pattern (e.g. VISA/Mastercard/etc.) 2. **CHECKSUM** - does it actually check-sum (e.g. not just 13 random numbers after "34" to make it an AMEX card number) 3. **REALLY EXISTS** - does it actually have an associated a...
174,748
<p>I have a table with one field that can point to a foreign key in one of 3 other tables based on what the descriminator value is (Project, TimeKeep, or CostCenter. Usually this is implemented with subclasses, and I am wondering if what I have below will work. <strong>Note the subclass name is the same as the parent...
[ { "answer_id": 175046, "author": "skaffman", "author_id": 21234, "author_profile": "https://Stackoverflow.com/users/21234", "pm_score": 4, "selected": true, "text": "<p>Discriminators are used for storing class hierarchies in a single table. What you have there is a single class with mul...
2008/10/06
[ "https://Stackoverflow.com/questions/174748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16404/" ]
I have a table with one field that can point to a foreign key in one of 3 other tables based on what the descriminator value is (Project, TimeKeep, or CostCenter. Usually this is implemented with subclasses, and I am wondering if what I have below will work. **Note the subclass name is the same as the parent class and ...
Discriminators are used for storing class hierarchies in a single table. What you have there is a single class with multiple meanings. <http://docs.jboss.org/hibernate/core/3.5/reference/en-US/html/mapping.html#mapping-declaration-discriminator> > > The element is > required for polymorphic persistence > using th...
174,752
<p>I've got a lightbox textbox that is displayed using an AJAX call from an ASP.NET UpdatePanel. When the lightbox is displayed, I use the <code>focus()</code> method of a textbox that is in the lightbox to bring focus to the textbox right away.</p> <p>When in Firefox, the text box gains focus with no problem. In IE, ...
[ { "answer_id": 175046, "author": "skaffman", "author_id": 21234, "author_profile": "https://Stackoverflow.com/users/21234", "pm_score": 4, "selected": true, "text": "<p>Discriminators are used for storing class hierarchies in a single table. What you have there is a single class with mul...
2008/10/06
[ "https://Stackoverflow.com/questions/174752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/392/" ]
I've got a lightbox textbox that is displayed using an AJAX call from an ASP.NET UpdatePanel. When the lightbox is displayed, I use the `focus()` method of a textbox that is in the lightbox to bring focus to the textbox right away. When in Firefox, the text box gains focus with no problem. In IE, the text box does not...
Discriminators are used for storing class hierarchies in a single table. What you have there is a single class with multiple meanings. <http://docs.jboss.org/hibernate/core/3.5/reference/en-US/html/mapping.html#mapping-declaration-discriminator> > > The element is > required for polymorphic persistence > using th...
174,762
<p>I have a form that I would like to style. specifcally I would like to chnage the background color of the form item's label. (the backgorundColor attribute changes both the label and the inputs background color)</p> <p>i.e.</p> <pre> <code> &lt;mx:Form> &lt;mx:FormItem label="username:"> &lt;mx:TextInpu...
[ { "answer_id": 175076, "author": "Brandon", "author_id": 23133, "author_profile": "https://Stackoverflow.com/users/23133", "pm_score": -1, "selected": false, "text": "<p>Try using the flex style explorers to create your desired style:</p>\n\n<ul>\n<li><p><a href=\"http://examples.adobe.c...
2008/10/06
[ "https://Stackoverflow.com/questions/174762", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1638/" ]
I have a form that I would like to style. specifcally I would like to chnage the background color of the form item's label. (the backgorundColor attribute changes both the label and the inputs background color) i.e. ``` <mx:Form> <mx:FormItem label="username:"> <mx:TextInput /> </mx:FormItem> </mx:Fo...
A formitem has an object it uses to display the label called the FormItemLabel, this objects purpose is so you can style the label of a form item. In flex 2 to change the style you can try: ``` FormItemLabel { } ``` However I looked over the flex 2 lang ref and it doesn't seem like you can change the background co...
174,773
<p>I have TurtoiseSVN and ankhSVN installed. I created a repository on my computer.. "C:\Documents and Settings\user1\My Documents\Subversion\Repository\"</p> <p>I am trying to connect to this repository from my co-workers computer. What should this URL be?</p> <p>Any help would be great. Thanks.</p>
[ { "answer_id": 174789, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": 1, "selected": false, "text": "<p>Try svn://xxx.xxx.xxx.xxx/Repository/</p>\n\n<p>The default port is 3690 if you have a firewall to configure.</p>\n" }, ...
2008/10/06
[ "https://Stackoverflow.com/questions/174773", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1316/" ]
I have TurtoiseSVN and ankhSVN installed. I created a repository on my computer.. "C:\Documents and Settings\user1\My Documents\Subversion\Repository\" I am trying to connect to this repository from my co-workers computer. What should this URL be? Any help would be great. Thanks.
You will need to run the svnserve daemon on your computer, or run an apache server with the necessary modules, to allow your colleague to access this locally stored repository. For a simple case like this I would recommend svnserve, it should be simpler to configure and run. The url would then be: ``` svn://<your_ip>...
174,774
<p>I created an <code>ObjectInputSteam</code> and <code>ObjectOutputStream</code> on a blocking <code>SocketChannel</code> and am trying to read and write concurrently. My code is something like this:</p> <pre><code>socketChannel = SocketChannel.open(destNode); objectOutputStream = new ObjectOutputStream(Channels.new...
[ { "answer_id": 175025, "author": "Tom Hawtin - tackline", "author_id": 4725, "author_profile": "https://Stackoverflow.com/users/4725", "pm_score": 2, "selected": false, "text": "<p>If you want to use InputStream and OutputStream concurrently with SocketChannel, from looking at the source...
2008/10/06
[ "https://Stackoverflow.com/questions/174774", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4792/" ]
I created an `ObjectInputSteam` and `ObjectOutputStream` on a blocking `SocketChannel` and am trying to read and write concurrently. My code is something like this: ``` socketChannel = SocketChannel.open(destNode); objectOutputStream = new ObjectOutputStream(Channels.newOutputStream(socketChannel)); objectInputStream ...
This seems to be a bug in `java.nio.channels.Channels` (thanks to Tom Hawtin; post it as an answer next time). A good description and workaround are described [here](http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4774871) (actually a duplicate of the bug Tom listed): I tested the workaround and it works.
174,841
<p>Why is it that when I use a converter in my binding expression in WPF, the value is not updated when the data is updated.</p> <p>I have a simple Person data model:</p> <pre><code>class Person : INotifyPropertyChanged { public string FirstName { get; set; } public string LastName { get; set; } } </code></pr...
[ { "answer_id": 175050, "author": "Joel B Fant", "author_id": 22211, "author_profile": "https://Stackoverflow.com/users/22211", "pm_score": 5, "selected": true, "text": "<p><strong>(see edits below; latest: #2)</strong></p>\n\n<p>It isn't updating because your <code>Person</code> object i...
2008/10/06
[ "https://Stackoverflow.com/questions/174841", "https://Stackoverflow.com", "https://Stackoverflow.com/users/373/" ]
Why is it that when I use a converter in my binding expression in WPF, the value is not updated when the data is updated. I have a simple Person data model: ``` class Person : INotifyPropertyChanged { public string FirstName { get; set; } public string LastName { get; set; } } ``` My binding expression look...
**(see edits below; latest: #2)** It isn't updating because your `Person` object is not capable of notifying anything that the value of `FirstName` or `LastName` has changed. [See this Question](https://stackoverflow.com/questions/159088/dependencyproperty-and-databinding). And here's how you implement `INotifyProper...
174,849
<p>I've read <a href="http://chriscavanagh.wordpress.com/2008/03/11/aspnet-routing-goodbye-url-rewriting/" rel="noreferrer">ASP.NET Routing… Goodbye URL rewriting?</a> and <a href="http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx" rel="noreferrer">Using Routing With WebForms</a> which are great ar...
[ { "answer_id": 174867, "author": "Chad Moran", "author_id": 25416, "author_profile": "https://Stackoverflow.com/users/25416", "pm_score": 2, "selected": false, "text": "<p>Not sure if this is your answer but this may get you in the right direction it's Scott Hanselman (MSFT) showing how ...
2008/10/06
[ "https://Stackoverflow.com/questions/174849", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20377/" ]
I've read [ASP.NET Routing… Goodbye URL rewriting?](http://chriscavanagh.wordpress.com/2008/03/11/aspnet-routing-goodbye-url-rewriting/) and [Using Routing With WebForms](http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx) which are great articles, but limited to simple, illustrative, "hello world"-...
A simple example of how to use routing in ASP.NET 1. Create Empty Web Application 2. Add first form - Default.aspx 3. Add second form - Second.aspx 4. Add third form - Third.aspx 5. Add to default.aspx 3 buttons - ``` protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("Second.aspx"); } ...
174,853
<p>A python script need to spawn multiple sub-processes via fork(). All of those child processes should run simultaneously and the parent process should be waiting for all of them to finish. Having an ability to set some timeout on a "slow" child would be nice. The parent process goes on processing the rest of the scr...
[ { "answer_id": 174984, "author": "Bryan Oakley", "author_id": 7432, "author_profile": "https://Stackoverflow.com/users/7432", "pm_score": 2, "selected": false, "text": "<p>Have you looked at the <a href=\"http://pyprocessing.berlios.de/\" rel=\"nofollow noreferrer\">pyprocessing</a> modu...
2008/10/06
[ "https://Stackoverflow.com/questions/174853", "https://Stackoverflow.com", "https://Stackoverflow.com/users/140995/" ]
A python script need to spawn multiple sub-processes via fork(). All of those child processes should run simultaneously and the parent process should be waiting for all of them to finish. Having an ability to set some timeout on a "slow" child would be nice. The parent process goes on processing the rest of the script ...
Simple example: ``` import os chidren = [] for job in jobs: child = os.fork() if child: children.append(child) else: pass # really should exec the job for child in children: os.waitpid(child, 0) ``` Timing out a slow child is a little more work; you can use `wait` instead of `waitpid...
174,881
<p>I'm using jmockit with my tests and with one class I wish to test, uses <code>InitialContext</code> directly. So I have the following:</p> <pre><code>public class MyClass { public void myMethod() { InitialContext ic = new InitialContext(); javax.mail.Session mailSession = ic.lookup("my.mail.session"); ...
[ { "answer_id": 175207, "author": "cynicalman", "author_id": 410, "author_profile": "https://Stackoverflow.com/users/410", "pm_score": 2, "selected": false, "text": "<p>In general, to mock JNDI, you will need to use a framework, such as EJBMock, that can provide a mock container in which ...
2008/10/06
[ "https://Stackoverflow.com/questions/174881", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm using jmockit with my tests and with one class I wish to test, uses `InitialContext` directly. So I have the following: ``` public class MyClass { public void myMethod() { InitialContext ic = new InitialContext(); javax.mail.Session mailSession = ic.lookup("my.mail.session"); // rest of method follo...
In general, to mock JNDI, you will need to use a framework, such as EJBMock, that can provide a mock container in which to deploy your beans. The other alternative is to refactor creating the context out of your code so that it is passed in (this is dependency injection refactoring), and then you should be able to sub...