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
90,092
<p>I have a table in <code>MySQL</code> that has 3 fields and I want to enforce uniqueness among two of the fields. Here is the table <code>DDL</code>:</p> <pre><code>CREATE TABLE `CLIENT_NAMES` ( `ID` int(11) NOT NULL auto_increment, `CLIENT_NAME` varchar(500) NOT NULL, `OWNER_ID` int(11) NOT NULL, PRIMARY KEY (`ID...
[ { "answer_id": 90111, "author": "J D OConal", "author_id": 17023, "author_profile": "https://Stackoverflow.com/users/17023", "pm_score": 0, "selected": false, "text": "<p>Have you looked at CONSTRAINT ... UNIQUE?</p>\n" }, { "answer_id": 90116, "author": "Gili", "author_i...
2008/09/18
[ "https://Stackoverflow.com/questions/90092", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4082/" ]
I have a table in `MySQL` that has 3 fields and I want to enforce uniqueness among two of the fields. Here is the table `DDL`: ``` CREATE TABLE `CLIENT_NAMES` ( `ID` int(11) NOT NULL auto_increment, `CLIENT_NAME` varchar(500) NOT NULL, `OWNER_ID` int(11) NOT NULL, PRIMARY KEY (`ID`), ) ENGINE=InnoDB DEFAULT CHARSET=u...
MySQL cannot enforce uniqueness on keys that are longer than 765 bytes (and apparently 500 UTF8 characters can surpass this limit). 1. Does CLIENT\_NAME really need to be 500 characters long? Seems a bit excessive. 2. Add a new (shorter) column that is hash(CLIENT\_NAME). Get MySQL to enforce uniqueness on that hash i...
90,151
<p>Anyone got a working example of using ruby to post to a presigned URL on s3</p>
[ { "answer_id": 90708, "author": "Dan Harper", "author_id": 14530, "author_profile": "https://Stackoverflow.com/users/14530", "pm_score": 0, "selected": false, "text": "<p>Does anything on the <a href=\"http://amazon.rubyforge.org/\" rel=\"nofollow noreferrer\">s3 library page</a> cover w...
2008/09/18
[ "https://Stackoverflow.com/questions/90151", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17232/" ]
Anyone got a working example of using ruby to post to a presigned URL on s3
I have used aws-sdk and right\_aws both. Here is the code to do this. ``` require 'rubygems' require 'aws-sdk' require 'right_aws' require 'net/http' require 'uri' require 'rack' access_key_id = 'AAAAAAAAAAAAAAAAA' secret_access_key = 'ASDFASDFAS4646ASDFSAFASDFASDFSADF' s3 = AWS::S3.new( :access_key_id => acce...
90,178
<p>I am working on a web application where I want the content to fill the height of the entire screen.</p> <p>The page has a header, which contains a logo, and account information. This could be an arbitrary height. I want the content div to fill the rest of the page to the bottom.</p> <p>I have a header <code>div</c...
[ { "answer_id": 90414, "author": "Jerph", "author_id": 1701, "author_profile": "https://Stackoverflow.com/users/1701", "pm_score": 4, "selected": false, "text": "<pre><code>&lt;!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transit...
2008/09/18
[ "https://Stackoverflow.com/questions/90178", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16299/" ]
I am working on a web application where I want the content to fill the height of the entire screen. The page has a header, which contains a logo, and account information. This could be an arbitrary height. I want the content div to fill the rest of the page to the bottom. I have a header `div` and a content `div`. At...
### 2015 update: the flexbox approach There are two other answers briefly mentioning [flexbox](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes); however, that was more than two years ago, and they don't provide any examples. The specification for flexbox has definitely settled now. > > Note: Th...
90,181
<p>I've just run into a display glitch in IE6 with the ExtJS framework. - Hopefully someone can point me in the right direction.</p> <p>In the following example, the bbar for the panel is displayed 2ems narrower than the panel it is attached to (it's left aligned) in IE6, where as in Firefox it is displayed as the sam...
[ { "answer_id": 90414, "author": "Jerph", "author_id": 1701, "author_profile": "https://Stackoverflow.com/users/1701", "pm_score": 4, "selected": false, "text": "<pre><code>&lt;!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transit...
2008/09/18
[ "https://Stackoverflow.com/questions/90181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/797/" ]
I've just run into a display glitch in IE6 with the ExtJS framework. - Hopefully someone can point me in the right direction. In the following example, the bbar for the panel is displayed 2ems narrower than the panel it is attached to (it's left aligned) in IE6, where as in Firefox it is displayed as the same width as...
### 2015 update: the flexbox approach There are two other answers briefly mentioning [flexbox](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes); however, that was more than two years ago, and they don't provide any examples. The specification for flexbox has definitely settled now. > > Note: Th...
90,238
<p>As an example in pseudocode:</p> <pre><code>if ((a mod 2) == 0) { isEven = true; } else { isEven = false; } </code></pre>
[ { "answer_id": 90242, "author": "martinatime", "author_id": 1353, "author_profile": "https://Stackoverflow.com/users/1353", "pm_score": 7, "selected": false, "text": "<p>Here is the representation of your pseudo-code in minimal Java code;</p>\n\n<pre><code>boolean isEven = a % 2 == 0;\n<...
2008/09/18
[ "https://Stackoverflow.com/questions/90238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17245/" ]
As an example in pseudocode: ``` if ((a mod 2) == 0) { isEven = true; } else { isEven = false; } ```
Instead of the modulo operator, which has slightly different semantics, for non-negative integers, you can use the *remainder* operator `%`. For your exact example: ``` if ((a % 2) == 0) { isEven = true; } else { isEven = false; } ``` This can be simplified to a one-liner: ``` isEven = (a % 2) == 0; ```
90,350
<p>I have 3 PDF documents that are generated on the fly by a legacy library that we use, and written to disk. What's the easiest way for my JAVA server code to grab these 3 documents and turn them into one long PDF document where it's just all the pages from document #1, followed by all the pages from document #2, etc....
[ { "answer_id": 90372, "author": "JohnnyLambada", "author_id": 9648, "author_profile": "https://Stackoverflow.com/users/9648", "pm_score": 2, "selected": false, "text": "<p>I've used <a href=\"http://www.accesspdf.com/pdftk/\" rel=\"nofollow noreferrer\">pdftk</a> to great effect. It's a...
2008/09/18
[ "https://Stackoverflow.com/questions/90350", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6044/" ]
I have 3 PDF documents that are generated on the fly by a legacy library that we use, and written to disk. What's the easiest way for my JAVA server code to grab these 3 documents and turn them into one long PDF document where it's just all the pages from document #1, followed by all the pages from document #2, etc. I...
@J D OConal, thanks for the tip, the article you sent me was very outdated, but it did point me towards iText. I found this page that explains how to do exactly what I need: <http://java-x.blogspot.com/2006/11/merge-pdf-files-with-itext.html> Thanks for the other answers, but I don't really want to have to spawn other...
90,360
<p>I was investigating the rapid growth of a SQL Server 2005 transaction log when I found that transaction logs will only truncate correctly - if the sys.databases "log_reuse_wait" column is set to 0 - meaning that nothing is keeping the transaction log from reusing existing space. </p> <p>One day when I was intend...
[ { "answer_id": 91571, "author": "Jonas Lincoln", "author_id": 17436, "author_profile": "https://Stackoverflow.com/users/17436", "pm_score": -1, "selected": false, "text": "<p>Hm, tricky. Could it be that the question it self to sys.databases is causing the ACTIVE_TRANSACTION? In that cas...
2008/09/18
[ "https://Stackoverflow.com/questions/90360", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14947/" ]
I was investigating the rapid growth of a SQL Server 2005 transaction log when I found that transaction logs will only truncate correctly - if the sys.databases "log\_reuse\_wait" column is set to 0 - meaning that nothing is keeping the transaction log from reusing existing space. One day when I was intending to back...
I still don't know why I was seeing the ACTIVE\_TRANSACTION in the sys.databases log\_reuse\_wait\_desc column - when there were no transactions running, but my subsequent experience indicates that the log\_reuse\_wait column for the tempdb changes for reasons that are not very clear, and for my purposes, not very rele...
90,374
<p>Why doesn't this Google Chart API URL render both data sets on this XY scatter plot? </p> <pre><code>http://chart.apis.google.com/chart?cht=lxy&amp;chd=t:10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200|0.10,0.23,0.33,0.44,0.56,0.66,0.79,0.90,0.99,1.12,1.22,1.33,1.44,1.56,1.68,1.79,1.90,2.02,...
[ { "answer_id": 90410, "author": "Christian Davén", "author_id": 12534, "author_profile": "https://Stackoverflow.com/users/12534", "pm_score": -1, "selected": true, "text": "<p>I think it actually does render both data sets, but you can only se one of them because there's only one scale o...
2008/09/18
[ "https://Stackoverflow.com/questions/90374", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3499/" ]
Why doesn't this Google Chart API URL render both data sets on this XY scatter plot? ``` http://chart.apis.google.com/chart?cht=lxy&chd=t:10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200|0.10,0.23,0.33,0.44,0.56,0.66,0.79,0.90,0.99,1.12,1.22,1.33,1.44,1.56,1.68,1.79,1.90,2.02,2.12,2.22|0.28,0.56...
I think it actually does render both data sets, but you can only se one of them because there's only one scale on the y axis. (In other words, 0.10 is too small to show.) And, you should really be using percentages. 100 is the highest accepted value: > > Where chart data string consists of positive floating point nu...
90,418
<p>I have a shell script that executes a number of commands. How do I make the shell script exit if any of the commands exit with a non-zero exit code?</p>
[ { "answer_id": 90434, "author": "Martin W", "author_id": 14199, "author_profile": "https://Stackoverflow.com/users/14199", "pm_score": 4, "selected": false, "text": "<p>In Bash this is easy. Just tie them together with <code>&amp;&amp;</code>:</p>\n<pre><code>command1 &amp;&amp; command2...
2008/09/18
[ "https://Stackoverflow.com/questions/90418", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9940/" ]
I have a shell script that executes a number of commands. How do I make the shell script exit if any of the commands exit with a non-zero exit code?
After each command, the exit code can be found in the `$?` variable so you would have something like: ``` ls -al file.ext rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi ``` You need to be careful of piped commands since the `$?` only gives you the return code of the last element in the pipe so, in the code: ``` ls -al...
90,428
<p>I'm looking for an LDAP libracy in C or C++ that allows me to specify a list of LDAP hostnames instead of a single hostname. The library should then use the first one it can connect to in case one or more of the servers is/are down. I'm sure it'd be easy to wrap an existing library to create this, but why reinvent t...
[ { "answer_id": 90649, "author": "Kamil Kisiel", "author_id": 15061, "author_profile": "https://Stackoverflow.com/users/15061", "pm_score": -1, "selected": false, "text": "<p>I can't say I've ever heard of one. Furthermore, most LDAP-capable software I've used supported failover poorly or...
2008/09/18
[ "https://Stackoverflow.com/questions/90428", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm looking for an LDAP libracy in C or C++ that allows me to specify a list of LDAP hostnames instead of a single hostname. The library should then use the first one it can connect to in case one or more of the servers is/are down. I'm sure it'd be easy to wrap an existing library to create this, but why reinvent the ...
Use multiple A records, each with a different IP. ``` ldapserver.example.com. IN A 1.2.3.4 ldapserver.example.com. IN A 2.3.4.5 ``` The OpenLDAP client libs will try each host in turn. Failover is (unfortunately) as slow as your TCP connection timeout...
90,493
<p>How can I cast long to HWND (C++ visual studio 8)?</p> <pre><code>Long lWindowHandler; HWND oHwnd = (HWND)lWindowHandler; </code></pre> <p>But I got the following warning:</p> <blockquote> <p>warning C4312: 'type cast' : conversion from 'LONG' to 'HWND' of greater size</p> </blockquote> <p>Thanks.</p>
[ { "answer_id": 90508, "author": "Roger Lipscombe", "author_id": 8446, "author_profile": "https://Stackoverflow.com/users/8446", "pm_score": 3, "selected": false, "text": "<p>As long as you're sure that the LONG you have is really an HWND, then it's as simple as:</p>\n\n<pre><code>HWND hW...
2008/09/18
[ "https://Stackoverflow.com/questions/90493", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
How can I cast long to HWND (C++ visual studio 8)? ``` Long lWindowHandler; HWND oHwnd = (HWND)lWindowHandler; ``` But I got the following warning: > > warning C4312: 'type cast' : conversion from 'LONG' to 'HWND' of greater size > > > Thanks.
HWND is a handle to a window. This type is declared in WinDef.h as follows: > > typedef HANDLE HWND; > > > HANDLE is handle to an object. This type is declared in WinNT.h as follows: > > typedef PVOID HANDLE; > > > Finally, PVOID is a pointer to any type. This type is declared in WinNT.h as follows: > > t...
90,517
<p>When a user goes to my site, my script checks for 2 cookies which store the user id + part of the password, to automatically log them in. </p> <p>It's possible to edit the contents of cookies via a cookie editor, so I guess it's possible to add some malicious content to a written cookie?</p> <p>Should I add <code>...
[ { "answer_id": 90526, "author": "Jeremy Privett", "author_id": 560, "author_profile": "https://Stackoverflow.com/users/560", "pm_score": 0, "selected": false, "text": "<p>You should mysql_real_escape_string <strong><em>anything</em></strong> that could be potentially harmful. Never trust...
2008/09/18
[ "https://Stackoverflow.com/questions/90517", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
When a user goes to my site, my script checks for 2 cookies which store the user id + part of the password, to automatically log them in. It's possible to edit the contents of cookies via a cookie editor, so I guess it's possible to add some malicious content to a written cookie? Should I add `mysql_real_escape_stri...
What you *really* need to do is not send these cookie values that are hackable in the first place. Instead, why not hash the username and password and a (secret) salt and set that as the cookie value? i.e.: ``` define('COOKIE_SALT', 'secretblahblahlkdsfklj'); $cookie_value = sha1($username.$password.COOKIE_SALT); ```...
90,553
<p>I've kind of backed myself into a corner here.</p> <p>I have a series of UserControls that inherit from a parent, which contains a couple of methods and events to simplify things so I don't have to write lines and lines of near-identical code. As you do. The parent contains no other controls.</p> <p>What I want to...
[ { "answer_id": 90566, "author": "Jon Limjap", "author_id": 372, "author_profile": "https://Stackoverflow.com/users/372", "pm_score": 0, "selected": false, "text": "<p>If your event is already defined in your parent class, you do not need to rewire it again in your child class. That will ...
2008/09/18
[ "https://Stackoverflow.com/questions/90553", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5133/" ]
I've kind of backed myself into a corner here. I have a series of UserControls that inherit from a parent, which contains a couple of methods and events to simplify things so I don't have to write lines and lines of near-identical code. As you do. The parent contains no other controls. What I want to do is just have ...
Declare the parent method virtual, override it in the child classes and call ``` base.checkReadyness(sender, e); ``` (or derevation thereof) from within the child class. This allows for future design evolution say if you want to do some specific error checking code before calling the parent event handler. You might ...
90,578
<p>I've recently started developing applications for the Blackberry. Consequently, I've had to jump to Java-ME and learn that and its associated tools. The syntax is easy, but I keep having issues with various gotchas and the environment. </p> <p>For instance, something that surprised me and wasted a lot of time is...
[ { "answer_id": 90601, "author": "Noel Grandin", "author_id": 6591, "author_profile": "https://Stackoverflow.com/users/6591", "pm_score": 2, "selected": false, "text": "<p>The short answer is - it's going to be annoying, but not difficult.</p>\n\n<p>Java and C# have all the same underlyin...
2008/09/18
[ "https://Stackoverflow.com/questions/90578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9382/" ]
I've recently started developing applications for the Blackberry. Consequently, I've had to jump to Java-ME and learn that and its associated tools. The syntax is easy, but I keep having issues with various gotchas and the environment. For instance, something that surprised me and wasted a lot of time is absence of r...
This [guy here](http://crfdesign.net/programming/top-10-differences-between-java-and-c) had to make the inverse transition. So he listed the top 10 differences of Java and C#. I'll take his topics and show how it is made in Java: Gotcha #10 - Give me my standard output! ---------------------------------------- To pri...
90,579
<p>How to center text over an image in a table cell using javascript, css, and/or html?</p> <p>I have an HTML table containing images - all the same size - and I want to center a text label over each image. The text in the labels may vary in size. Horizontal centering is not difficult, but vertical centering is.</p> ...
[ { "answer_id": 90596, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 5, "selected": true, "text": "<p>you could try putting the images in the background.</p>\n\n<pre><code>&lt;table&gt;\n &lt;tr&gt;\n &lt;td style=\"b...
2008/09/18
[ "https://Stackoverflow.com/questions/90579", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9345/" ]
How to center text over an image in a table cell using javascript, css, and/or html? I have an HTML table containing images - all the same size - and I want to center a text label over each image. The text in the labels may vary in size. Horizontal centering is not difficult, but vertical centering is. ADDENDUM: i di...
you could try putting the images in the background. ``` <table> <tr> <td style="background: url(myImg.jpg) no-repeat; vertical-align: middle; text-align: center"> Here is my text </td> </tr> </table> ``` You'll just need to set the height and width on the cell and that should be i...
90,595
<p>How to implement a web page that scales when the browser window is resized?</p> <p>I can lay out the elements of the page using either a table or CSS float sections, but i want the display to rescale when the browser window is resized</p> <p>i have a working solution using AJAX PRO and DIVs with overflow:auto and ...
[ { "answer_id": 90603, "author": "Fire Lancer", "author_id": 6266, "author_profile": "https://Stackoverflow.com/users/6266", "pm_score": 5, "selected": true, "text": "<p>instead of using in css say \"width: 200px\", use stuff like \"width: 50%\"</p>\n\n<p>This makes it use 50% of whatever...
2008/09/18
[ "https://Stackoverflow.com/questions/90595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9345/" ]
How to implement a web page that scales when the browser window is resized? I can lay out the elements of the page using either a table or CSS float sections, but i want the display to rescale when the browser window is resized i have a working solution using AJAX PRO and DIVs with overflow:auto and an onwindowresize...
instead of using in css say "width: 200px", use stuff like "width: 50%" This makes it use 50% of whatever it's in, so in the case of: ``` <body> <div style="width:50%"> <!--some stuff--> </div> </body> ``` The div will now always take up half the window horizontaly.
90,657
<p>I'm trying to find a way to fake the result of a method called from within another method.</p> <p>I have a "LoadData" method which calls a separate helper to get some data and then it will transform it (I'm interested in testing the transformed result).</p> <p>So I have code like this:</p> <pre><code>public class...
[ { "answer_id": 90670, "author": "Kevin Pang", "author_id": 1574, "author_profile": "https://Stackoverflow.com/users/1574", "pm_score": 0, "selected": false, "text": "<p>Yes, a mocking framework is exactly what you're looking for. You can record / arrange how you want certain mocked out ...
2008/09/18
[ "https://Stackoverflow.com/questions/90657", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11388/" ]
I'm trying to find a way to fake the result of a method called from within another method. I have a "LoadData" method which calls a separate helper to get some data and then it will transform it (I'm interested in testing the transformed result). So I have code like this: ``` public class MyClass(){ public void Lo...
As far as I know, you should create an interface or a base abstract class for the Helper object. With Rhino Mocks you can then return the value you want. Alternatively, you can add an overload for LoadData that accepts as parameters the data that you normally retrieve from the Helper object. This might even be easier.
90,682
<p>Is it possible to get a thread dump of a Java Web Start application? And if so, how?</p> <p>It would be nice if there were a simple solution, which would enable a non-developer (customer) to create a thread dump. Alternatively, is it possible to create a thread dump programmatically?</p> <p>In the Java Web Start C...
[ { "answer_id": 90711, "author": "Amir Arad", "author_id": 11813, "author_profile": "https://Stackoverflow.com/users/11813", "pm_score": 2, "selected": false, "text": "<p>Try</p>\n\n<pre><code>StackTraceElement[] stack = Thread.currentThread().getStackTrace();\n</code></pre>\n\n<p>Then yo...
2008/09/18
[ "https://Stackoverflow.com/questions/90682", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15646/" ]
Is it possible to get a thread dump of a Java Web Start application? And if so, how? It would be nice if there were a simple solution, which would enable a non-developer (customer) to create a thread dump. Alternatively, is it possible to create a thread dump programmatically? In the Java Web Start Console I can get ...
In the console, press V rather than T: ``` t: dump thread list v: dump thread stack ``` This works under JDK6. Don't know about others. Alternative, under JDK5 (and possibly earlier) you can send a full stack trace of all threads to standard out: *Under Windows:* type ctrl-break in the Java console. *Under Un...
90,693
<p>I have tree control object created using CTreeCtrl MFC class. The tree control needs to support rename. When I left click on any of item in Tree the TVN_SELCHANGED event is called from which I can get the selected item of the tree as below : HTREEITEM h = m_moveListTree.GetSelectedItem(); CString s = m_moveListT...
[ { "answer_id": 90773, "author": "jussij", "author_id": 14738, "author_profile": "https://Stackoverflow.com/users/14738", "pm_score": 1, "selected": true, "text": "<p>I created my own MFC like home grown C++ GUI library on top of the Win32 API and looking at my code, this is how it handle...
2008/09/18
[ "https://Stackoverflow.com/questions/90693", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have tree control object created using CTreeCtrl MFC class. The tree control needs to support rename. When I left click on any of item in Tree the TVN\_SELCHANGED event is called from which I can get the selected item of the tree as below : HTREEITEM h = m\_moveListTree.GetSelectedItem(); CString s = m\_moveListTre...
I created my own MFC like home grown C++ GUI library on top of the Win32 API and looking at my code, this is how it handles that situation: ``` LRESULT xTreeCtrl::onRightClick(NMHDR *) { xPoint pt; //-- get the cursor at the time the mesage was posted DWORD dwPos = ::GetMessagePos(); pt.x = GET_X_LPARAM(dwPo...
90,697
<p>How do I create a resource that I can reference and use in various parts of my program easily?</p> <p>My specific problem is that I have a NotifyIcon that I want to change the icon of depending on the state of the program. A common problem, but one I've been struggling with for a long time. </p>
[ { "answer_id": 90699, "author": "Matthew Scharley", "author_id": 15537, "author_profile": "https://Stackoverflow.com/users/15537", "pm_score": 9, "selected": true, "text": "<p>Well, after searching around and cobbling together various points from around StackOverflow (gee, I love this pl...
2008/09/18
[ "https://Stackoverflow.com/questions/90697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15537/" ]
How do I create a resource that I can reference and use in various parts of my program easily? My specific problem is that I have a NotifyIcon that I want to change the icon of depending on the state of the program. A common problem, but one I've been struggling with for a long time.
Well, after searching around and cobbling together various points from around StackOverflow (gee, I love this place already), most of the problems were already past this stage. I did manage to work out an answer to my problem though. **How to create a resource:** In my case, I want to create an icon. It's a similar p...
90,751
<p>Do C#/.NET floating point operations differ in precision between debug mode and release mode?</p>
[ { "answer_id": 90783, "author": "Dark Shikari", "author_id": 11206, "author_profile": "https://Stackoverflow.com/users/11206", "pm_score": 2, "selected": false, "text": "<p>In fact, they may differ if debug mode uses the x87 FPU and release mode uses SSE for float-ops.</p>\n" }, { ...
2008/09/18
[ "https://Stackoverflow.com/questions/90751", "https://Stackoverflow.com", "https://Stackoverflow.com/users/288629/" ]
Do C#/.NET floating point operations differ in precision between debug mode and release mode?
They can indeed be different. According to the CLR ECMA specification: > > Storage locations for floating-point > numbers (statics, array elements, and > fields of classes) are of fixed size. > The supported storage sizes are > float32 and float64. Everywhere else > (on the evaluation stack, as > arguments, as ...
90,755
<p>How do I get a list of the active IP-addresses, MAC-addresses and <a href="http://en.wikipedia.org/wiki/NetBIOS" rel="nofollow noreferrer">NetBIOS</a> names on the LAN?</p> <p>I'd like to get NetBIOS name, IP and <a href="http://en.wikipedia.org/wiki/MAC_address" rel="nofollow noreferrer">MAC addresses</a> for ever...
[ { "answer_id": 90806, "author": "Tubs", "author_id": 11924, "author_profile": "https://Stackoverflow.com/users/11924", "pm_score": 2, "selected": false, "text": "<p>If you're using DHCP then the server will give you a list of all that information.</p>\n\n<p>This website has a good tutori...
2008/09/18
[ "https://Stackoverflow.com/questions/90755", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6069/" ]
How do I get a list of the active IP-addresses, MAC-addresses and [NetBIOS](http://en.wikipedia.org/wiki/NetBIOS) names on the LAN? I'd like to get NetBIOS name, IP and [MAC addresses](http://en.wikipedia.org/wiki/MAC_address) for every host on the LAN, preferably not having to walk to every single PC and take note of...
As Daren Thomas said, use nmap. ``` nmap -sP 192.168.1.1/24 ``` to scan the network 192.168.1.\* ``` nmap -O 192.168.1.1/24 ``` to get the operating system of the user. For more information, read the manpage ``` man nmap ``` regards
90,758
<p>I'm currently using ImageMagick to determine the size of images uploaded to the website. By calling ImageMagick's "identify" on the command line it takes about 0.42 seconds to determine a 1MB JPEG's dimensions along with the fact that it's a JPEG. I find that a bit slow.</p> <p>Using the Imagick PHP library is even...
[ { "answer_id": 90768, "author": "J D OConal", "author_id": 17023, "author_profile": "https://Stackoverflow.com/users/17023", "pm_score": 3, "selected": false, "text": "<p>If you're using PHP with GD support, you can try <a href=\"http://www.php.net/manual/en/function.getimagesize.php\" r...
2008/09/18
[ "https://Stackoverflow.com/questions/90758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10024/" ]
I'm currently using ImageMagick to determine the size of images uploaded to the website. By calling ImageMagick's "identify" on the command line it takes about 0.42 seconds to determine a 1MB JPEG's dimensions along with the fact that it's a JPEG. I find that a bit slow. Using the Imagick PHP library is even slower as...
Sorry I can't add this as a comment to a previous answer but I don't have the rep. Doing some quick and dirty testing I also found that exec("identify -ping... is about 20 times faster than without the -ping. But getimagesize() appears to be about 200 times faster still. So I would say getimagesize() is the faster met...
90,775
<p>I have an exe file generated with py2exe. In the setup.py I specify an icon to be embedded in the exe:</p> <pre><code>windows=[{'script': 'my_script.py','icon_resources': [(0, 'my_icon.ico')], ... </code></pre> <p>I tried loading the icon using:</p> <pre><code>hinst = win32api.GetModuleHandle(None) hicon = win32g...
[ { "answer_id": 91245, "author": "efotinis", "author_id": 12320, "author_profile": "https://Stackoverflow.com/users/12320", "pm_score": 0, "selected": false, "text": "<p>You should set the icon ID to something other than 0:</p>\n\n<pre><code>'icon_resources': [(42, 'my_icon.ico')]\n</code...
2008/09/18
[ "https://Stackoverflow.com/questions/90775", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1531/" ]
I have an exe file generated with py2exe. In the setup.py I specify an icon to be embedded in the exe: ``` windows=[{'script': 'my_script.py','icon_resources': [(0, 'my_icon.ico')], ... ``` I tried loading the icon using: ``` hinst = win32api.GetModuleHandle(None) hicon = win32gui.LoadImage(hinst, 0, win32con.IMAGE...
@efotinis: You're right. Here is a workaround until py2exe gets fixed and you don't want to include the same icon twice: ``` hicon = win32gui.CreateIconFromResource(win32api.LoadResource(None, win32con.RT_ICON, 1), True) ``` Be aware that **1** is not the ID you gave the icon in setup.py (which is the icon group I...
90,885
<p>I want to make an entity that has an autogenerated primary key, but also a unique compound key made up of two other fields. How do I do this in JPA?<br> I want to do this because the primary key should be used as foreign key in another table and making it compound would not be good.</p> <p>In the following snippet,...
[ { "answer_id": 90960, "author": "Michel", "author_id": 7198, "author_profile": "https://Stackoverflow.com/users/7198", "pm_score": 5, "selected": true, "text": "<p>You can use <a href=\"http://java.sun.com/javaee/5/docs/api/javax/persistence/UniqueConstraint.html\" rel=\"nofollow norefer...
2008/09/18
[ "https://Stackoverflow.com/questions/90885", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16152/" ]
I want to make an entity that has an autogenerated primary key, but also a unique compound key made up of two other fields. How do I do this in JPA? I want to do this because the primary key should be used as foreign key in another table and making it compound would not be good. In the following snippet, I need the...
You can use [`@UniqueConstraint`](http://java.sun.com/javaee/5/docs/api/javax/persistence/UniqueConstraint.html) something like this : ``` @Entity @Table(name = "dm_action_plan", uniqueConstraints={ @UniqueConstraint(columnNames= "command","model") } ) public class ActionPlan { @Id private int pk; ...
90,899
<p>How can I get all items from a specific calendar (for a specific date). Lets say for instance that I have a calendar with a recurring item every Monday evening. When I request all items like this:</p> <pre><code>CalendarItems = CalendarFolder.Items; CalendarItems.IncludeRecurrences = true; </code></pre> <p>I only...
[ { "answer_id": 91652, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 5, "selected": true, "text": "<p>I believe that you must Restrict or Find in order to get recurring appointments, otherwise Outlook won't expand them....
2008/09/18
[ "https://Stackoverflow.com/questions/90899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
How can I get all items from a specific calendar (for a specific date). Lets say for instance that I have a calendar with a recurring item every Monday evening. When I request all items like this: ``` CalendarItems = CalendarFolder.Items; CalendarItems.IncludeRecurrences = true; ``` I only get 1 item... Is there a...
I believe that you must Restrict or Find in order to get recurring appointments, otherwise Outlook won't expand them. Also, you must Sort by Start *before* setting IncludeRecurrences.
90,940
<p>I'm writing the memory manager for an application, as part of a team of twenty-odd coders. We're running out of memory quota and we need to be able to see what's going on, since we only appear to be using about 700Mb. I need to be able to report where it's all going - fragmentation etc. Any ideas?</p>
[ { "answer_id": 91054, "author": "Suma", "author_id": 16673, "author_profile": "https://Stackoverflow.com/users/16673", "pm_score": 3, "selected": true, "text": "<p>You can use existing memory debugging tools for this, I found Memory Validator <a href=\"http://www.vmvalidator.com/cpp/memo...
2008/09/18
[ "https://Stackoverflow.com/questions/90940", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11483/" ]
I'm writing the memory manager for an application, as part of a team of twenty-odd coders. We're running out of memory quota and we need to be able to see what's going on, since we only appear to be using about 700Mb. I need to be able to report where it's all going - fragmentation etc. Any ideas?
You can use existing memory debugging tools for this, I found Memory Validator [1](http://www.vmvalidator.com/cpp/memory/index.html "Memory Validator") quite useful, it is able to track both API level (heap, new...) and OS level (Virtual Memory) allocations and show virtual memory maps. The other option which I also f...
90,949
<p>There is no documentation on cakephp.org and I am unable to find one on google. Please link me some documentation or supply one!</p>
[ { "answer_id": 100658, "author": "David Heggie", "author_id": 4309, "author_profile": "https://Stackoverflow.com/users/4309", "pm_score": 5, "selected": true, "text": "<p>The translate behavior is another of CakePHP's very useful but poorly documented features. I've implemented it a coup...
2008/09/18
[ "https://Stackoverflow.com/questions/90949", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4013/" ]
There is no documentation on cakephp.org and I am unable to find one on google. Please link me some documentation or supply one!
The translate behavior is another of CakePHP's very useful but poorly documented features. I've implemented it a couple of times with reasonable success in multi-lingual websites along the following lines. Firstly, the translate behavior will only internationalize the database content of your site. If you've any more ...
90,971
<p>Let's say I have a class:</p> <pre><code>class Foo { public string Bar { get { ... } } public string this[int index] { get { ... } } } </code></pre> <p>I can bind to these two properties using "{Binding Path=Bar}" and "{Binding Path=[x]}". Fine.</p> <p>Now let's say I want to implement INotif...
[ { "answer_id": 91020, "author": "Cameron MacFarland", "author_id": 3820, "author_profile": "https://Stackoverflow.com/users/3820", "pm_score": 2, "selected": false, "text": "<p>Don't know for sure if this'll work, but reflector shows that the get and set methods for an indexed property a...
2008/09/18
[ "https://Stackoverflow.com/questions/90971", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6604/" ]
Let's say I have a class: ``` class Foo { public string Bar { get { ... } } public string this[int index] { get { ... } } } ``` I can bind to these two properties using "{Binding Path=Bar}" and "{Binding Path=[x]}". Fine. Now let's say I want to implement INotifyPropertyChanged: ``` class Foo ...
Thanks to Cameron's suggestion, I've found the correct syntax, which is: ``` Item[] ``` Which updates everything (all index values) bound to that indexed property.
90,977
<p>Emacs Lisp has <code>replace-string</code> but has no <code>replace-char</code>. I want to replace "typographic" curly quotes (Emacs code for this character is hexadecimal 53979) with regular ASCII quotes, and I can do so with:</p> <pre><code>(replace-string (make-string 1 ?\x53979) "'") </code></pre> <p>I think i...
[ { "answer_id": 91043, "author": "0124816", "author_id": 11521, "author_profile": "https://Stackoverflow.com/users/11521", "pm_score": 2, "selected": false, "text": "<blockquote>\n <p>which would certainly be better with replace-char. Any way to improve my code?</p>\n</blockquote>\n\n<p>...
2008/09/18
[ "https://Stackoverflow.com/questions/90977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15625/" ]
Emacs Lisp has `replace-string` but has no `replace-char`. I want to replace "typographic" curly quotes (Emacs code for this character is hexadecimal 53979) with regular ASCII quotes, and I can do so with: ``` (replace-string (make-string 1 ?\x53979) "'") ``` I think it would be better with `replace-char`. What is...
Why not just use ``` (replace-string "\x53979" "'") ``` or ``` (while (search-forward "\x53979" nil t) (replace-match "'" nil t)) ``` as recommended in the documentation for replace-string?
90,982
<p>I'm looking for a good, clean way to go around the fact that PHP5 still doesn't support multiple inheritance. Here's the class hierarchy:</p> <p>Message<br> -- TextMessage<br> -------- InvitationTextMessage<br> -- EmailMessage<br> -------- InvitationEmailMessage </p> <p>The two types of Invitation* cl...
[ { "answer_id": 90991, "author": "danio", "author_id": 12663, "author_profile": "https://Stackoverflow.com/users/12663", "pm_score": 2, "selected": false, "text": "<p>It sounds like the <a href=\"http://en.wikipedia.org/wiki/Decorator_pattern\" rel=\"nofollow noreferrer\">decorator patter...
2008/09/18
[ "https://Stackoverflow.com/questions/90982", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16668/" ]
I'm looking for a good, clean way to go around the fact that PHP5 still doesn't support multiple inheritance. Here's the class hierarchy: Message -- TextMessage -------- InvitationTextMessage -- EmailMessage -------- InvitationEmailMessage The two types of Invitation\* classes have a lot in common; i...
Alex, most of the times you need multiple inheritance is a signal your object structure is somewhat incorrect. In situation you outlined I see you have class responsibility simply too broad. If Message is part of application business model, it should not take care about rendering output. Instead, you could split respon...
90,988
<p>Using eclipse 3.3.2 with MyEclipse installed. For some reason if a file isn't called build.xml then it isnt' recognised as an ant file. The file association for *.xml includes ant and says "locked by 'Ant Buildfile' content type.</p> <p>The run-as menu is broken. Even if the editor association works run-as doesn't....
[ { "answer_id": 91324, "author": "Ashley Mercer", "author_id": 13065, "author_profile": "https://Stackoverflow.com/users/13065", "pm_score": 0, "selected": false, "text": "<p>If you open the \"File Associations\" page (Window -> Preferences -> General -> Editors -> File Associations) you ...
2008/09/18
[ "https://Stackoverflow.com/questions/90988", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Using eclipse 3.3.2 with MyEclipse installed. For some reason if a file isn't called build.xml then it isnt' recognised as an ant file. The file association for \*.xml includes ant and says "locked by 'Ant Buildfile' content type. The run-as menu is broken. Even if the editor association works run-as doesn't. The ant...
The environment inspects the file contents to determine if it is an Ant file (if it isn't called "build.xml"). Add the following to the XML file: ``` <?xml version="1.0" encoding="UTF-8"?> <project name="myproject" default="t1"> <target name="t1"></target> </project> ``` You should now see the "Ant Editor" in t...
90,996
<p>I have an IList that contains items ( parent first ), they need to be added to a Diagram Document in the reverse order so that the parent is added last, drawn on top so that it is the first thing to be selected by the user.</p> <p>What's the best way to do it? Something better/more elegant than what I am doing curr...
[ { "answer_id": 90998, "author": "Gishu", "author_id": 1695, "author_profile": "https://Stackoverflow.com/users/1695", "pm_score": 0, "selected": false, "text": "<p>NewItems is my List here... This is a bit clunky though. </p>\n\n<pre><code>for(int iLooper = obEvtArgs.NewItems.Count-1; iL...
2008/09/18
[ "https://Stackoverflow.com/questions/90996", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1695/" ]
I have an IList that contains items ( parent first ), they need to be added to a Diagram Document in the reverse order so that the parent is added last, drawn on top so that it is the first thing to be selected by the user. What's the best way to do it? Something better/more elegant than what I am doing currently whic...
If you have .NET 3.5 you could use LINQ's Reverse? ``` foreach(var item in obEvtArgs.NewItems.Reverse()) { ... } ``` (Assuming you're talking about the generic IList)
91,108
<p>How do I get my C# program to sleep (pause execution) for 50 milliseconds?</p>
[ { "answer_id": 91119, "author": "Isak Savo", "author_id": 8521, "author_profile": "https://Stackoverflow.com/users/8521", "pm_score": 10, "selected": true, "text": "<pre><code>System.Threading.Thread.Sleep(50);\n</code></pre>\n\n<p>Remember though, that doing this in the main GUI thread ...
2008/09/18
[ "https://Stackoverflow.com/questions/91108", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1816/" ]
How do I get my C# program to sleep (pause execution) for 50 milliseconds?
``` System.Threading.Thread.Sleep(50); ``` Remember though, that doing this in the main GUI thread will block your GUI from updating (it will feel "sluggish") Just remove the `;` to make it work for VB.net as well.
91,110
<p>How to match a single quote in sed if the expression is enclosed in single quotes:</p> <pre><code>sed -e '...' </code></pre> <p>For example need to match this text:</p> <pre><code>'foo' </code></pre>
[ { "answer_id": 91176, "author": "tzot", "author_id": 6899, "author_profile": "https://Stackoverflow.com/users/6899", "pm_score": 7, "selected": true, "text": "\n\n<p>You can either use:</p>\n\n<pre class=\"lang-none prettyprint-override\"><code>\"texta'textb\" (APOSTROPHE inside QUOTATIO...
2008/09/18
[ "https://Stackoverflow.com/questions/91110", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1692070/" ]
How to match a single quote in sed if the expression is enclosed in single quotes: ``` sed -e '...' ``` For example need to match this text: ``` 'foo' ```
You can either use: ```none "texta'textb" (APOSTROPHE inside QUOTATION MARKs) ``` or ```none 'texta'\''textb' (APOSTROPHE text APOSTROPHE, then REVERSE SOLIDUS, APOSTROPHE, then APOSTROPHE more text APOSTROPHE) ``` I used unicode character names. REVERSE SOLIDUS is more commonly known as backslash. In the latter...
91,116
<p>I'm using this formula to calculate the distance between entries in my (My)SQL database which have latitude and longitude fields in decimal format:</p> <pre><code>6371 * ACOS(SIN(RADIANS( %lat1% )) * SIN(RADIANS( %lat2% )) + COS(RADIANS( %lat1% )) * COS(RADIANS( %lat2% )) * COS(RADIANS( %lon2% ) - RADIANS( %lon1% ...
[ { "answer_id": 91144, "author": "Adam Hopkinson", "author_id": 12280, "author_profile": "https://Stackoverflow.com/users/12280", "pm_score": 2, "selected": false, "text": "<p>Am i right in thinking this is the Haversine formula?</p>\n" }, { "answer_id": 91481, "author": "Vale...
2008/09/18
[ "https://Stackoverflow.com/questions/91116", "https://Stackoverflow.com", "https://Stackoverflow.com/users/476/" ]
I'm using this formula to calculate the distance between entries in my (My)SQL database which have latitude and longitude fields in decimal format: ``` 6371 * ACOS(SIN(RADIANS( %lat1% )) * SIN(RADIANS( %lat2% )) + COS(RADIANS( %lat1% )) * COS(RADIANS( %lat2% )) * COS(RADIANS( %lon2% ) - RADIANS( %lon1% ))) ``` Sub...
For databases (such as SQLite) that don't support trigonometric functions you can use the Pythagorean theorem. This is a faster method, even if your database does support trigonometric functions, with the following caveats: * you need to store coords in x,y grid instead of (or as well as) lat,lng; * the calculation a...
91,124
<p>Suppose I have a string 'nvarchar(50)', which is for example the T-SQL string segment used in creating a table of that type. How do I best convert that to an enum representation of System.Data.DbType?</p> <p>Could it handle the many different possible ways of writing the type in T-SQL, such as:</p> <pre><code>[nva...
[ { "answer_id": 91139, "author": "m_pGladiator", "author_id": 446104, "author_profile": "https://Stackoverflow.com/users/446104", "pm_score": 2, "selected": false, "text": "<p>In addition to yours I will put:</p>\n\n<ul>\n<li>Unit Test Strategy</li>\n<li>Integration Test Strategy</li>\n<l...
2008/09/18
[ "https://Stackoverflow.com/questions/91124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5790/" ]
Suppose I have a string 'nvarchar(50)', which is for example the T-SQL string segment used in creating a table of that type. How do I best convert that to an enum representation of System.Data.DbType? Could it handle the many different possible ways of writing the type in T-SQL, such as: ``` [nvarchar](50) nvarchar ...
As a preliminary answer, check out the Joel test: <http://www.joelonsoftware.com/articles/fog0000000043.html> Just an appetizer: > > 1. Do you use source control? > 2. Can you make a build in one step? > 3. Do you make daily builds? > 4. Do you have a bug database? > 5. Do you fix bugs before writing new code? > 6. ...
91,127
<p>I want to verify a drag &amp; drop operation is allowed. A valid item can come from another one of our "controls", or internally from within the custom treeview. Currently I have this:</p> <pre><code>bool CanDrop(DragEventArgs e) { bool allow = false; Point point = tree.PointToClient(new Point(e.X, e.Y)); ...
[ { "answer_id": 91995, "author": "Hallgrim", "author_id": 15454, "author_profile": "https://Stackoverflow.com/users/15454", "pm_score": 3, "selected": true, "text": "<p>I use the TreeNode.Tag property to store small \"controller\" objects that makes up the logic. E.g.:</p>\n\n<pre><code>c...
2008/09/18
[ "https://Stackoverflow.com/questions/91127", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15608/" ]
I want to verify a drag & drop operation is allowed. A valid item can come from another one of our "controls", or internally from within the custom treeview. Currently I have this: ``` bool CanDrop(DragEventArgs e) { bool allow = false; Point point = tree.PointToClient(new Point(e.X, e.Y)); TreeNode target...
I use the TreeNode.Tag property to store small "controller" objects that makes up the logic. E.g.: ``` class TreeNodeController { Entity data; virtual bool IsReadOnly { get; } virtual bool CanDrop(TreeNodeController source, DragDropEffects effect); virtual bool CanDrop(DataInfoObject info, DragDropEffects ef...
91,160
<p>How do I best convert a System.Data.DbType enumeration value to the corresponding (or at least one of the possible corresponding) System.Type values?</p> <p>For example:</p> <pre><code>DbType.StringFixedLength -&gt; System.String DbType.String -&gt; System.String DbType.Int32 -&gt; System.Int32 </code></pre> <p>...
[ { "answer_id": 91177, "author": "Jorge Ferreira", "author_id": 6508, "author_profile": "https://Stackoverflow.com/users/6508", "pm_score": 4, "selected": true, "text": "<p>AFAIK there is no built-in converter in .NET for converting a SqlDbType to a System.Type. But knowing the mapping yo...
2008/09/18
[ "https://Stackoverflow.com/questions/91160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5790/" ]
How do I best convert a System.Data.DbType enumeration value to the corresponding (or at least one of the possible corresponding) System.Type values? For example: ``` DbType.StringFixedLength -> System.String DbType.String -> System.String DbType.Int32 -> System.Int32 ``` I've only seen very "dirty" solutions but ...
AFAIK there is no built-in converter in .NET for converting a SqlDbType to a System.Type. But knowing the mapping you can easily roll your own converter ranging from a simple dictionary to more advanced (XML based for extensability) solutions. The mapping can be found here: <http://www.carlprothman.net/Default.aspx?ta...
91,169
<p>So I log into a Solaris box, try to start Apache, and find that there is already a process listening on port 80, and it's not Apache. Our boxes don't have lsof installed, so I can't query with that. I guess I could do:</p> <pre><code>pfiles `ls /proc` | less </code></pre> <p>and look for "port: 80", but if anyone ...
[ { "answer_id": 91188, "author": "Christoffer", "author_id": 15514, "author_profile": "https://Stackoverflow.com/users/15514", "pm_score": -1, "selected": false, "text": "<p>If you have access to <code>netstat</code>, that can do precisely that. </p>\n" }, { "answer_id": 91194, ...
2008/09/18
[ "https://Stackoverflow.com/questions/91169", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
So I log into a Solaris box, try to start Apache, and find that there is already a process listening on port 80, and it's not Apache. Our boxes don't have lsof installed, so I can't query with that. I guess I could do: ``` pfiles `ls /proc` | less ``` and look for "port: 80", but if anyone has a better solution, I'm...
I found this script somewhere. I don't remember where, but it works for me: ``` #!/bin/ksh line='---------------------------------------------' pids=$(/usr/bin/ps -ef | sed 1d | awk '{print $2}') if [ $# -eq 0 ]; then read ans?"Enter port you would like to know pid for: " else ans=$1 fi for f in $pids do /...
91,223
<p>I'm using Microsoft.XMLHTTP to get some information from another server from an old ASP/VBScript site. But that other server is restarted fairly often, so I want to check that it's up and running before trying to pull information from it (or avoid my page from giving an HTTP 500 by detecting the problem some other w...
[ { "answer_id": 91334, "author": "Jordi", "author_id": 1893, "author_profile": "https://Stackoverflow.com/users/1893", "pm_score": 2, "selected": false, "text": "<p>You could try making a ping to the server and check the response.\nTake a look at this <a href=\"http://classicasp.aspfaq.co...
2008/09/18
[ "https://Stackoverflow.com/questions/91223", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1367/" ]
I'm using Microsoft.XMLHTTP to get some information from another server from an old ASP/VBScript site. But that other server is restarted fairly often, so I want to check that it's up and running before trying to pull information from it (or avoid my page from giving an HTTP 500 by detecting the problem some other way)...
All you need to do is have the code continue on error, then post to the other server and read the status from the post. Something like this: ``` PostURL = homelink & "CustID.aspx?SearchFlag=PO" set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.3.0") ``` **on error resume next** ``` xmlhttp.open "POST", PostURL, fals...
91,263
<p>Part of the install for an app I am responsible for, compiles some C code libraries. This is done in a console using GNU Make.</p> <p>So, as part of the install, a console window pops open, you see the make file output wiz by as it compiles and links, when finished the console window closes and the installer contin...
[ { "answer_id": 91273, "author": "Amir Arad", "author_id": 11813, "author_profile": "https://Stackoverflow.com/users/11813", "pm_score": 4, "selected": true, "text": "<p>this should do the trick:</p>\n\n<p></p>\n\n<pre><code>if not ERRORLEVEL 0 pause\n</code></pre>\n\n<p>type <code>help i...
2008/09/18
[ "https://Stackoverflow.com/questions/91263", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6063/" ]
Part of the install for an app I am responsible for, compiles some C code libraries. This is done in a console using GNU Make. So, as part of the install, a console window pops open, you see the make file output wiz by as it compiles and links, when finished the console window closes and the installer continues. All ...
this should do the trick: ``` if not ERRORLEVEL 0 pause ``` type `help if` in DOS for more info on errorlevel usage.
91,275
<p>I'm writing a small tool in C# which will need to send and receive data to/from a website using POST and json formatting. I've never done anything like this before in C# (or any language really) so I'm struggling to find some useful information to get me started.</p> <p>I've found some information on the WebReques...
[ { "answer_id": 91296, "author": "Seb Rose", "author_id": 12405, "author_profile": "https://Stackoverflow.com/users/12405", "pm_score": 0, "selected": false, "text": "<p>I have used WebRequest for interacting with websites. It is the right 'tool'</p>\n\n<p>I can't comment on the JSON aspe...
2008/09/18
[ "https://Stackoverflow.com/questions/91275", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm writing a small tool in C# which will need to send and receive data to/from a website using POST and json formatting. I've never done anything like this before in C# (or any language really) so I'm struggling to find some useful information to get me started. I've found some information on the WebRequest class in ...
WebRequest and more specifically the HttpWebRequest class is a good starting point for what you want to achieve. To create the request you will use the WebRequest.Create and cast the created request to an HttpWebRequest to actually use it. You will then create your post data and send it to the stream like: ``` HttpWeb...
91,289
<p>I have a migration that runs an SQL script to create a new Postgres schema. When creating a new database in Postgres by default it creates a schema called 'public', which is the main schema we use. The migration to create the new database schema seems to be working fine, however the problem occurs after the migratio...
[ { "answer_id": 91449, "author": "Dan Harper", "author_id": 14530, "author_profile": "https://Stackoverflow.com/users/14530", "pm_score": 1, "selected": false, "text": "<p>I'm not sure I understand what you're asking exactly, but, rake will be expecting to update the version of the Rails ...
2008/09/18
[ "https://Stackoverflow.com/questions/91289", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11557/" ]
I have a migration that runs an SQL script to create a new Postgres schema. When creating a new database in Postgres by default it creates a schema called 'public', which is the main schema we use. The migration to create the new database schema seems to be working fine, however the problem occurs after the migration h...
Well that depends what your migration looks like, what your database.yml looks like and what exactly you are trying to attempt. Anyway more information is needed change the names if you have to and post an example database.yml and the migration. does the migration change the search\_path for the adapter for example ? ...
91,305
<p>Is there a easy way to do this? Or do I have to parse the file and do some search/replacing on my own?</p> <p>The ideal would be something like:</p> <pre><code>var myXML: XML = ???; // ... load xml data into the XML object myXML.someAttribute = newValue; </code></pre>
[ { "answer_id": 91952, "author": "Swaroop C H", "author_id": 4869, "author_profile": "https://Stackoverflow.com/users/4869", "pm_score": 5, "selected": true, "text": "<p>Attributes are accessible in AS3 using the <code>@</code> prefix.</p>\n\n<p>For example:</p>\n\n<pre><code>var myXML:XM...
2008/09/18
[ "https://Stackoverflow.com/questions/91305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Is there a easy way to do this? Or do I have to parse the file and do some search/replacing on my own? The ideal would be something like: ``` var myXML: XML = ???; // ... load xml data into the XML object myXML.someAttribute = newValue; ```
Attributes are accessible in AS3 using the `@` prefix. For example: ``` var myXML:XML = <test name="something"></test>; trace(myXML.@name); myXML.@name = "new"; trace(myXML.@name); ``` Output: ``` something new ```
91,355
<p>Environment: HP laptop with Windows XP SP2</p> <p>I had created some encrypted files using GnuPG (gpg) for Windows. Yesterday, my hard disk failed so I had reimage the hard disk. I have now reinstalled gpg and regenerated my keys using the same passphrase as earlier. But, I am now unable to decrypt the files. I...
[ { "answer_id": 91371, "author": "David Precious", "author_id": 4040, "author_profile": "https://Stackoverflow.com/users/4040", "pm_score": 3, "selected": false, "text": "<p>Yes, your secret key appears to be missing. Without it, you will not be able to decrypt the files.</p>\n\n<p>Do yo...
2008/09/18
[ "https://Stackoverflow.com/questions/91355", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Environment: HP laptop with Windows XP SP2 I had created some encrypted files using GnuPG (gpg) for Windows. Yesterday, my hard disk failed so I had reimage the hard disk. I have now reinstalled gpg and regenerated my keys using the same passphrase as earlier. But, I am now unable to decrypt the files. I get the follo...
when reimporting your keys from the old keyring, you need to specify the command: ``` gpg --allow-secret-key-import --import <keyring> ``` otherwise it will only import the public keys, not the private keys.
91,357
<p>I want to log in to Stack Overflow with Techorati OpenID hosted at my site.</p> <p><a href="https://stackoverflow.com/users/login">https://stackoverflow.com/users/login</a> has some basic information.</p> <p>I understood that I should change</p> <pre><code>&lt;link rel="openid.delegate" href="http://yourname.x.co...
[ { "answer_id": 91371, "author": "David Precious", "author_id": 4040, "author_profile": "https://Stackoverflow.com/users/4040", "pm_score": 3, "selected": false, "text": "<p>Yes, your secret key appears to be missing. Without it, you will not be able to decrypt the files.</p>\n\n<p>Do yo...
2008/09/18
[ "https://Stackoverflow.com/questions/91357", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17469/" ]
I want to log in to Stack Overflow with Techorati OpenID hosted at my site. <https://stackoverflow.com/users/login> has some basic information. I understood that I should change ``` <link rel="openid.delegate" href="http://yourname.x.com" /> ``` to ``` <link rel="openid.delegate" href="http://technorati.com/peopl...
when reimporting your keys from the old keyring, you need to specify the command: ``` gpg --allow-secret-key-import --import <keyring> ``` otherwise it will only import the public keys, not the private keys.
91,360
<p>I need to sum points on each level earned by a tree of users. Level 1 is the sum of users' points of the users 1 level below the user. Level 2 is the Level 1 points of the users 2 levels below the user, etc...</p> <p>The calculation happens once a month on a non production server, no worries about performance.</p> ...
[ { "answer_id": 91372, "author": "Grad van Horck", "author_id": 12569, "author_profile": "https://Stackoverflow.com/users/12569", "pm_score": 1, "selected": false, "text": "<p>I would say: create a stored procedure, probably has the best performance.\nOr if you have a maximum number of le...
2008/09/18
[ "https://Stackoverflow.com/questions/91360", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6681/" ]
I need to sum points on each level earned by a tree of users. Level 1 is the sum of users' points of the users 1 level below the user. Level 2 is the Level 1 points of the users 2 levels below the user, etc... The calculation happens once a month on a non production server, no worries about performance. What would th...
If you were using Oracle DBMS that would be pretty straightforward since Oracle supports tree queries with the **CONNECT BY/STARTS WITH** syntax. For SQL Server I think you might find [Common Table Expressions](http://searchwindevelopment.techtarget.com/tip/0,289483,sid8_gci1277481,00.html) useful
91,362
<p>How can brackets be escaped in using <code>string.Format</code>?</p> <p>For example:</p> <pre><code>String val = &quot;1,2,3&quot; String.Format(&quot; foo {{0}}&quot;, val); </code></pre> <p>This example doesn't throw an exception, but it outputs the string <code>foo {0}</code>.</p> <p>Is there a way to escape the ...
[ { "answer_id": 91375, "author": "Jorge Ferreira", "author_id": 6508, "author_profile": "https://Stackoverflow.com/users/6508", "pm_score": 11, "selected": true, "text": "<p>For you to output <code> foo {1, 2, 3}</code> you have to do something like:</p>\n<pre><code>string t = &quot;1, 2,...
2008/09/18
[ "https://Stackoverflow.com/questions/91362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4685/" ]
How can brackets be escaped in using `string.Format`? For example: ``` String val = "1,2,3" String.Format(" foo {{0}}", val); ``` This example doesn't throw an exception, but it outputs the string `foo {0}`. Is there a way to escape the brackets?
For you to output `foo {1, 2, 3}` you have to do something like: ``` string t = "1, 2, 3"; string v = String.Format(" foo {{{0}}}", t); ``` To output a `{` you use `{{` and to output a `}` you use `}}`. **Or now, you can also use C# string interpolation like this (a feature available in C# 6.0)** **Escaping brack...
91,368
<p>From a shell script, how do I check if a directory contains files?</p> <p>Something similar to this</p> <pre class="lang-sh prettyprint-override"><code>if [ -e /some/dir/* ]; then echo "huzzah"; fi; </code></pre> <p>but which works if the directory contains one or several files (the above one only works with exac...
[ { "answer_id": 91387, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 5, "selected": false, "text": "<p>Try:</p>\n\n<pre><code>if [ ! -z `ls /some/dir/*` ]; then echo \"huzzah\"; fi\n</code></pre>\n" }, { "answer_id...
2008/09/18
[ "https://Stackoverflow.com/questions/91368", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17491/" ]
From a shell script, how do I check if a directory contains files? Something similar to this ```sh if [ -e /some/dir/* ]; then echo "huzzah"; fi; ``` but which works if the directory contains one or several files (the above one only works with exactly 0 or 1 files).
The solutions so far use `ls`. Here's an all bash solution: ``` #!/bin/bash shopt -s nullglob dotglob # To include hidden files files=(/some/dir/*) if [ ${#files[@]} -gt 0 ]; then echo "huzzah"; fi ```
91,420
<p>I have a static library written in C++ and I have a structure describing data format, i.e.<br></p> <pre><code>struct Format{ long fmtId; long dataChunkSize; long headerSize; Format(long, long, long); bool operator==(Format const &amp; other) const; }; </code></pre> <p>Some of data formats are...
[ { "answer_id": 91433, "author": "yrp", "author_id": 7228, "author_profile": "https://Stackoverflow.com/users/7228", "pm_score": 2, "selected": false, "text": "<p>Are they defined in .cpp file as well? Roughly, it should look like:</p>\n\n<pre><code>struct Format\n{\n [...]\n static...
2008/09/18
[ "https://Stackoverflow.com/questions/91420", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17481/" ]
I have a static library written in C++ and I have a structure describing data format, i.e. ``` struct Format{ long fmtId; long dataChunkSize; long headerSize; Format(long, long, long); bool operator==(Format const & other) const; }; ``` Some of data formats are widely used, like `{fmtId=0, da...
Don't use the static keyword on global declarations. [Here is an article explain the visibility of variables with/without static](http://msdn.microsoft.com/en-us/library/s1sb61xd.aspx). The static gives globals internal linkage, that is, only visible in the translation unit they are declared in.
91,434
<p>I want to display an error message on my asp.net application. This message is a warning message, this is the way I did it:</p> <pre class="lang-js prettyprint-override"><code>CmdCalcInvoke.Attributes[&quot;onclick&quot;] = &quot;return confirm('Are you sure you want to calculate the certification? WARNING: If the qu...
[ { "answer_id": 91461, "author": "redsquare", "author_id": 6440, "author_profile": "https://Stackoverflow.com/users/6440", "pm_score": 2, "selected": false, "text": "<p>you can if you dont use the default alert boxes. Try using a javascript modal window which is just normal div markup tha...
2008/09/18
[ "https://Stackoverflow.com/questions/91434", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I want to display an error message on my asp.net application. This message is a warning message, this is the way I did it: ```js CmdCalcInvoke.Attributes["onclick"] = "return confirm('Are you sure you want to calculate the certification? WARNING: If the quarter has not finished, all the partners status will change')";...
you can if you dont use the default alert boxes. Try using a javascript modal window which is just normal div markup that you can control the styling of. Look at blockui for jquery (there are loads of others)
91,479
<p>By default data extracted by the <code>GROUP BY</code> clause is ordered as ascending. How to change it to descending.</p>
[ { "answer_id": 91485, "author": "RB.", "author_id": 15393, "author_profile": "https://Stackoverflow.com/users/15393", "pm_score": 3, "selected": false, "text": "<p>Add <code>DESC</code> to the <code>GROUP BY</code> clause, e.g. :</p>\n\n<pre><code>GROUP BY myDate DESC\n</code></pre>\n" ...
2008/09/18
[ "https://Stackoverflow.com/questions/91479", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
By default data extracted by the `GROUP BY` clause is ordered as ascending. How to change it to descending.
You should use the derived tables on your SQL. For example if you want to pick up the most recent row for an specific activity you're attempt to use: ``` select * from activities group by id_customer order by creation_date ``` but it doesn't work. Try instead: ``` SELECT * FROM ( select * from activiti...
91,480
<p>I would like to know where can I find the code which eclipse uses to display the forms in the plugin.xml file. In particular I am looking for the form layout used in the extension tab in the plugin.xml</p>
[ { "answer_id": 91485, "author": "RB.", "author_id": 15393, "author_profile": "https://Stackoverflow.com/users/15393", "pm_score": 3, "selected": false, "text": "<p>Add <code>DESC</code> to the <code>GROUP BY</code> clause, e.g. :</p>\n\n<pre><code>GROUP BY myDate DESC\n</code></pre>\n" ...
2008/09/18
[ "https://Stackoverflow.com/questions/91480", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17512/" ]
I would like to know where can I find the code which eclipse uses to display the forms in the plugin.xml file. In particular I am looking for the form layout used in the extension tab in the plugin.xml
You should use the derived tables on your SQL. For example if you want to pick up the most recent row for an specific activity you're attempt to use: ``` select * from activities group by id_customer order by creation_date ``` but it doesn't work. Try instead: ``` SELECT * FROM ( select * from activiti...
91,487
<p>I keep running into this problem when debugging JSP pages in OpenNMS. The Jetty wiki talks about keepGenerated (<a href="http://docs.codehaus.org/display/JETTY/KeepGenerated" rel="nofollow noreferrer">http://docs.codehaus.org/display/JETTY/KeepGenerated</a>) in webdefault.xml but it seems unclear how this works in e...
[ { "answer_id": 92213, "author": "Javaxpert", "author_id": 15241, "author_profile": "https://Stackoverflow.com/users/15241", "pm_score": 0, "selected": false, "text": "<p>It is dumped already.\nfor example if you have a file called <code>index.jsp</code>, a file will be created called <co...
2008/09/18
[ "https://Stackoverflow.com/questions/91487", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17507/" ]
I keep running into this problem when debugging JSP pages in OpenNMS. The Jetty wiki talks about keepGenerated (<http://docs.codehaus.org/display/JETTY/KeepGenerated>) in webdefault.xml but it seems unclear how this works in embedded setups.
If you are using Jetty 6 you can use the following code: ``` String webApp = "./web/myapp"; // Location of the jsp files String contextPath = "/myapp"; WebAppContext webAppContext = new WebAppContext(webApp, contextPath); ServletHandler servletHandler = webAppContext.getServletHandler(); ServletHolder holder = new Se...
91,511
<p>I have a memory buffer corresponding to my screen resolution (1280x800 at 24-bits-per-pixel) that contains my screen contents at 24bpp. I want to convert this to 8-bpp (ie. Halftone color palette in Windows). I currently do this: 1. Use CreateDIBSection to allocate a new 1280x800 24-bpp buffer and access it as a DC,...
[ { "answer_id": 91575, "author": "Ray Hayes", "author_id": 7093, "author_profile": "https://Stackoverflow.com/users/7093", "pm_score": 3, "selected": true, "text": "<p>OK, to address the two parts of the problem.</p>\n\n<ol>\n<li><p>the following code shows how to get at the pixels inside...
2008/09/18
[ "https://Stackoverflow.com/questions/91511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17465/" ]
I have a memory buffer corresponding to my screen resolution (1280x800 at 24-bits-per-pixel) that contains my screen contents at 24bpp. I want to convert this to 8-bpp (ie. Halftone color palette in Windows). I currently do this: 1. Use CreateDIBSection to allocate a new 1280x800 24-bpp buffer and access it as a DC, as...
OK, to address the two parts of the problem. 1. the following code shows how to get at the pixels inside of a bitmap, change them and put them back into the bitmap. You could always generate a dummy bitmap of the correct size and format, open it up, copy over your data and you then have a bitmap object with your data:...
91,518
<p>Suppose I have a simple XHTML document that uses a custom namespace for attributes:</p> <pre><code>&lt;html xmlns="..." xmlns:custom="http://www.example.com/ns"&gt; ... &lt;div class="foo" custom:attr="bla"/&gt; ... &lt;/html&gt; </code></pre> <p>How do I match each element that has a certain custom at...
[ { "answer_id": 91607, "author": "redsquare", "author_id": 6440, "author_profile": "https://Stackoverflow.com/users/6440", "pm_score": 2, "selected": false, "text": "<p>You should use <code>$('div').attr('custom:attr')</code>.</p>\n" }, { "answer_id": 91807, "author": "Devon",...
2008/09/18
[ "https://Stackoverflow.com/questions/91518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7779/" ]
Suppose I have a simple XHTML document that uses a custom namespace for attributes: ``` <html xmlns="..." xmlns:custom="http://www.example.com/ns"> ... <div class="foo" custom:attr="bla"/> ... </html> ``` How do I match each element that has a certain custom attribute using jQuery? Using ``` $("div[cust...
[jQuery](https://jquery.com/) does not support custom namespaces directly, but you can find the divs you are looking for by using filter function. ``` // find all divs that have custom:attr $('div').filter(function() { return $(this).attr('custom:attr'); }).each(function() { // matched a div with custom::attr $(th...
91,563
<p>How can I make this work?</p> <pre><code>switch(property.PropertyType){ case typeof(Boolean): //doStuff break; case typeof(String): //doOtherStuff break; default: break; } </code></pre> <p>I don't want to use the name since string comparing for types is just awfull and...
[ { "answer_id": 91590, "author": "Phil Wright", "author_id": 6276, "author_profile": "https://Stackoverflow.com/users/6276", "pm_score": 0, "selected": false, "text": "<p>Do not worry about using strings within a switch because if you have several the compiler will automatically convert i...
2008/09/18
[ "https://Stackoverflow.com/questions/91563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11333/" ]
How can I make this work? ``` switch(property.PropertyType){ case typeof(Boolean): //doStuff break; case typeof(String): //doOtherStuff break; default: break; } ``` I don't want to use the name since string comparing for types is just awfull and can be subject to change.
``` System.Type propertyType = typeof(Boolean); System.TypeCode typeCode = Type.GetTypeCode(propertyType); switch (typeCode) { case TypeCode.Boolean: //doStuff break; case TypeCode.String: //doOtherStuff ...
91,576
<p>I'm building a project using a GNU tool chain and everything works fine until I get to linking it, where the linker complains that it is missing/can't find <code>crti.o</code>. This is not one of my object files, it seems to be related to libc but I can't understand why it would need this <code>crti.o</code>, wouldn...
[ { "answer_id": 91595, "author": "stsquad", "author_id": 17507, "author_profile": "https://Stackoverflow.com/users/17507", "pm_score": 6, "selected": true, "text": "<p><code>crti.o</code> is the bootstrap library, generally quite small. It's usually statically linked into your binary. It ...
2008/09/18
[ "https://Stackoverflow.com/questions/91576", "https://Stackoverflow.com", "https://Stackoverflow.com/users/76121/" ]
I'm building a project using a GNU tool chain and everything works fine until I get to linking it, where the linker complains that it is missing/can't find `crti.o`. This is not one of my object files, it seems to be related to libc but I can't understand why it would need this `crti.o`, wouldn't it use a library file,...
`crti.o` is the bootstrap library, generally quite small. It's usually statically linked into your binary. It should be found in `/usr/lib`. If you're running a binary distribution they tend to put all the developer stuff into -dev packages (e.g. libc6-dev) as it's not needed to run compiled programs, just to build th...
91,617
<p>I am looking for a tool that can take a unit test, like </p> <pre><code>IPerson p = new Person(); p.Name = "Sklivvz"; Assert.AreEqual("Sklivvz", p.Name); </code></pre> <p>and generate, automatically, the corresponding stub class and interface</p> <pre><code>interface IPerson // inferred from IPerson p = n...
[ { "answer_id": 91665, "author": "Carlos Villela", "author_id": 16944, "author_profile": "https://Stackoverflow.com/users/16944", "pm_score": -1, "selected": false, "text": "<p>I find that whenever I need a code generation tool like this, I am probably writing code that could be made a li...
2008/09/18
[ "https://Stackoverflow.com/questions/91617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7028/" ]
I am looking for a tool that can take a unit test, like ``` IPerson p = new Person(); p.Name = "Sklivvz"; Assert.AreEqual("Sklivvz", p.Name); ``` and generate, automatically, the corresponding stub class and interface ``` interface IPerson // inferred from IPerson p = new Person(); { string Name {...
What you appear to need is a parser for your language (Java), and a name and type resolver. ("Symbol table builder"). After parsing the source text, a compiler usually has a name resolver, that tries to record the definition of names and their corresponding types, and a type checker, that verifies that each expressio...
91,628
<p>I would like to automatically increment a field named `incrementID' anytime any field in any row within the table named 'tb_users' is updated. Currently I am doing it via the sql update statement. i.e "UPDATE tb_users SET name = @name, incrementID = incrementID + 1 .....WHERE id = @id;</p> <p>I'm wondering how I ca...
[ { "answer_id": 91684, "author": "Galwegian", "author_id": 3201, "author_profile": "https://Stackoverflow.com/users/3201", "pm_score": 2, "selected": false, "text": "<p>You could use a trigger for this (if I've read you correctly and you want the value incremented each time you update the...
2008/09/18
[ "https://Stackoverflow.com/questions/91628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17510/" ]
I would like to automatically increment a field named `incrementID' anytime any field in any row within the table named 'tb\_users' is updated. Currently I am doing it via the sql update statement. i.e "UPDATE tb\_users SET name = @name, incrementID = incrementID + 1 .....WHERE id = @id; I'm wondering how I can do thi...
This trigger should do the trick: ``` create trigger update_increment for update as if not update(incrementID) UPDATE tb_users SET incrementID = incrementID + 1 from inserted WHERE tb_users.id = inserted.id ```
91,629
<p>I'm trying to match elements with a name that is <code>'container1$container2$chkChecked'</code>, using a regex of <code>'.+\$chkChecked'</code>, but I'm not getting the matches I expect when the element name is as described. What am I doing wrong?</p>
[ { "answer_id": 91647, "author": "Kent Fredric", "author_id": 15614, "author_profile": "https://Stackoverflow.com/users/15614", "pm_score": 2, "selected": false, "text": "<p>try</p>\n\n<pre><code>string.match( /[$]chkChecked$/ ) \n</code></pre>\n\n<p>alternatively, you could try </p>\n\n<...
2008/09/18
[ "https://Stackoverflow.com/questions/91629", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8741/" ]
I'm trying to match elements with a name that is `'container1$container2$chkChecked'`, using a regex of `'.+\$chkChecked'`, but I'm not getting the matches I expect when the element name is as described. What am I doing wrong?
my guess, by your use of quotes, is you did something like ``` re = new RegExp('.+\$chkChecked'); ``` which won't work because js takes advantage of the \ in its string interpretation as an escape so it never makes it into the regex interpreter instead you want ``` re = new RegExp('.+\\$chkChecked'); ```
91,635
<p>I am considering using Postsharp framework to ease the burden of application method logging. It basically allows me to adorn methods with logging attribute and at compile time injects the logging code needed into the il. I like this solution as it keeps the noise out of the deign time code environment. Any thoughts,...
[ { "answer_id": 91659, "author": "Chris Canal", "author_id": 5802, "author_profile": "https://Stackoverflow.com/users/5802", "pm_score": 4, "selected": true, "text": "<p>I apply logging with AOP using Castle Windsor DynamicProxies. I was already using Castle for it's IoC container, so us...
2008/09/18
[ "https://Stackoverflow.com/questions/91635", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6440/" ]
I am considering using Postsharp framework to ease the burden of application method logging. It basically allows me to adorn methods with logging attribute and at compile time injects the logging code needed into the il. I like this solution as it keeps the noise out of the deign time code environment. Any thoughts, ex...
I apply logging with AOP using Castle Windsor DynamicProxies. I was already using Castle for it's IoC container, so using it for AOP was the path of least resistence for me. If you want more info let me know, I'm in the process of tidying the code up for releasing it as a blog post Edit Ok, here's the basic Intercept...
91,672
<p>In an application where users can belong to multiple groups, I'm currently storing their groups in a column called <code>groups</code> as a binary. Every four bytes is a 32 bit integer which is the <code>GroupID</code>. However, this means that to enumerate all the users in a group I have to programatically select a...
[ { "answer_id": 91686, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 1, "selected": false, "text": "<p>The more standard, usable and comprehensible way is the join table. It's easily supported by many ORMs, in additio...
2008/09/18
[ "https://Stackoverflow.com/questions/91672", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16299/" ]
In an application where users can belong to multiple groups, I'm currently storing their groups in a column called `groups` as a binary. Every four bytes is a 32 bit integer which is the `GroupID`. However, this means that to enumerate all the users in a group I have to programatically select all users, and manually fi...
You have a many-to-many relationship between users and groups. This calls for a separate table to combine users with groups: ``` User: (UserId[PrimaryKey], UserName etc.) Group: (GroupId[PrimaryKey], GroupName etc.) UserInGroup: (UserId[ForeignKey], GroupId[ForeignKey]) ``` To find all users in a given group, you ju...
91,678
<p>My Tomcat instance is listening to multiple IP addresses, but I want to control which source IP address is used when opening a <code>URLConnection</code>. </p> <p>How can I specify this?</p>
[ { "answer_id": 91998, "author": "Tom Hawtin - tackline", "author_id": 4725, "author_profile": "https://Stackoverflow.com/users/4725", "pm_score": 1, "selected": false, "text": "<p>The obvious portable way would be to set a Proxy in URL.openConnection. The proxy can be in local host, you ...
2008/09/18
[ "https://Stackoverflow.com/questions/91678", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17542/" ]
My Tomcat instance is listening to multiple IP addresses, but I want to control which source IP address is used when opening a `URLConnection`. How can I specify this?
This should do the trick: ``` URL url = new URL(yourUrlHere); Proxy proxy = new Proxy(Proxy.Type.DIRECT, new InetSocketAddress( InetAddress.getByAddress( new byte[]{your, ip, interface, here}), yourTcpPortHere)); URLConnection conn = url.openConnection(proxy); ``` And you are done. Dont for...
91,692
<p>Can anyone recommend a framework for templating/formatting messages in a standalone application along the lines of the JSP EL (Expression Language)?</p> <p>I would expect to be able to instantiate a an object of some sort, give it a template along the lines of</p> <pre><code>Dear ${customer.firstName}. You order w...
[ { "answer_id": 91755, "author": "arturh", "author_id": 4186, "author_profile": "https://Stackoverflow.com/users/4186", "pm_score": 2, "selected": false, "text": "<p>I would recommend looking into <a href=\"http://velocity.apache.org/\" rel=\"nofollow noreferrer\">Apache Velocity</a>. It ...
2008/09/18
[ "https://Stackoverflow.com/questions/91692", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15452/" ]
Can anyone recommend a framework for templating/formatting messages in a standalone application along the lines of the JSP EL (Expression Language)? I would expect to be able to instantiate a an object of some sort, give it a template along the lines of ``` Dear ${customer.firstName}. You order will be dispatched on ...
You can just use the Universal Expression Language itself. You need an implementation (but there are a few to choose from). After that, you need to implement three classes: ELResolver, FunctionMapper and VariableMapper. This blog post describes how to do it: [Java: using EL outside J2EE](http://illegalargumentexceptio...
91,699
<p>Python's convention is that variables are created by first assignment, and trying to read their value before one has been assigned raises an exception. PHP by contrast implicitly creates a variable when it is read, with a null value. This means it is easy to do this in PHP:</p> <pre><code>function mymodule_importan...
[ { "answer_id": 91713, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 2, "selected": false, "text": "<p>There is no way to make it fail as far as I know, but with E_NOTICE in error_reporting settings you can make it th...
2008/09/18
[ "https://Stackoverflow.com/questions/91699", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8925/" ]
Python's convention is that variables are created by first assignment, and trying to read their value before one has been assigned raises an exception. PHP by contrast implicitly creates a variable when it is read, with a null value. This means it is easy to do this in PHP: ``` function mymodule_important_calculation(...
**PHP** doesn't do much forward checking of things at parse time. The best you can do is crank up the warning level to report your mistakes, but by the time you get an E\_NOTICE, its too late, and its not possible to force E\_NOTICES to occur in advance yet. A lot of people are toting the "error\_reporting E\_STRICT...
91,715
<p>I've not used C++ very much in the past, and have recently been doing a lot of C#, and I'm really struggling to get back into the basics of C++ again. This is particularly tricky as work mandates that none of the most handy C++ constructs can be used, so all strings must be char *'s, and there is no provision for ST...
[ { "answer_id": 91749, "author": "Maximilian", "author_id": 1733, "author_profile": "https://Stackoverflow.com/users/1733", "pm_score": 1, "selected": false, "text": "<p>Edit: I guess I misunderstood your question. There is no constness problem in this code I'm aware of.</p>\n\n<p>I'm doi...
2008/09/18
[ "https://Stackoverflow.com/questions/91715", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15667/" ]
I've not used C++ very much in the past, and have recently been doing a lot of C#, and I'm really struggling to get back into the basics of C++ again. This is particularly tricky as work mandates that none of the most handy C++ constructs can be used, so all strings must be char \*'s, and there is no provision for STL ...
You'll probably need to use strcmp to see if the string is already stored: ``` for (int index=0; index<=lastIndex; index++) { if (strcmp(registeredNames[index], name) == 0) { return; // Already registered } } ``` Then if you really need to store a copy of the string, then you'll need to allocate a buffer a...
91,734
<p>I'm a little blockheaded right now…</p> <p>I have a date string in european format <strong>dd.mm.yyyy</strong> and need to transform it to <strong>mm.dd.yyyy</strong> with classic ASP. Any quick ideas?</p>
[ { "answer_id": 91780, "author": "Anheledir", "author_id": 5703, "author_profile": "https://Stackoverflow.com/users/5703", "pm_score": 2, "selected": false, "text": "<p>OK, I just found a solution myself:</p>\n\n<pre><code>payment_date = MID(payment_date,4,3) &amp; LEFT(payment_date,3) &a...
2008/09/18
[ "https://Stackoverflow.com/questions/91734", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5703/" ]
I'm a little blockheaded right now… I have a date string in european format **dd.mm.yyyy** and need to transform it to **mm.dd.yyyy** with classic ASP. Any quick ideas?
If its always in that format you could use split ``` d = split(".","dd.mm.yyyy") s = d(1) & "." & d(0) & "." & d(2) ``` this would allow for dates like 1.2.99 as well
91,745
<p>I am building a table using the DataGridView where a user can select items from a dropdown in each cell. To simplify the problem, lets say i have 1 column. I am using the DataGridViewComboBoxColumn in the designer. I am trying to support having each row in that column have a different list of items to choose fro...
[ { "answer_id": 163247, "author": "WaterBoy", "author_id": 3270, "author_profile": "https://Stackoverflow.com/users/3270", "pm_score": 5, "selected": true, "text": "<p>Yes. This can be done using the DataGridViewComboBoxCell.</p>\n\n<p>Here is an example method to add the items to just on...
2008/09/18
[ "https://Stackoverflow.com/questions/91745", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
I am building a table using the DataGridView where a user can select items from a dropdown in each cell. To simplify the problem, lets say i have 1 column. I am using the DataGridViewComboBoxColumn in the designer. I am trying to support having each row in that column have a different list of items to choose from. Is ...
Yes. This can be done using the DataGridViewComboBoxCell. Here is an example method to add the items to just one cell, rather than the whole column. ``` private void setCellComboBoxItems(DataGridView dataGrid, int rowIndex, int colIndex, object[] itemsToAdd) { DataGridViewComboBoxCell dgvcbc = (DataGridViewComboB...
91,747
<p>How can I set the background color of a specific item in a <em>System.Windows.Forms.ListBox</em>?</p> <p>I would like to be able to set multiple ones if possible.</p>
[ { "answer_id": 91758, "author": "Grad van Horck", "author_id": 12569, "author_profile": "https://Stackoverflow.com/users/12569", "pm_score": 7, "selected": true, "text": "<p>Probably the only way to accomplish that is to draw the items yourself.</p>\n<p>Set the <code>DrawMode</code> to <...
2008/09/18
[ "https://Stackoverflow.com/questions/91747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11137/" ]
How can I set the background color of a specific item in a *System.Windows.Forms.ListBox*? I would like to be able to set multiple ones if possible.
Probably the only way to accomplish that is to draw the items yourself. Set the `DrawMode` to `OwnerDrawFixed` and code something like this on the DrawItem event: ``` private void listBox_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); Graphics g = e.Graphics; g.FillRectangle(new Solid...
91,766
<p>I have a DataGrid where each column has a SortExpression. I would like the sort expression to be the equivalent of "ORDER BY LEN(myField)".</p> <p>I have tried </p> <pre><code>SortExpression="LEN(myField)" </code></pre> <p>but this throws an exception as it is not valid syntax. Any ideas?</p>
[ { "answer_id": 91788, "author": "Biri", "author_id": 968, "author_profile": "https://Stackoverflow.com/users/968", "pm_score": 3, "selected": true, "text": "<p>What about returning the len by the query already, but don't show that column, only use it as your original column's sortexpress...
2008/09/18
[ "https://Stackoverflow.com/questions/91766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15393/" ]
I have a DataGrid where each column has a SortExpression. I would like the sort expression to be the equivalent of "ORDER BY LEN(myField)". I have tried ``` SortExpression="LEN(myField)" ``` but this throws an exception as it is not valid syntax. Any ideas?
What about returning the len by the query already, but don't show that column, only use it as your original column's sortexpression? I don't think that your idea is supported by default.
91,778
<p>To create a new event handler on a control you can do this</p> <pre><code>c.Click += new EventHandler(mainFormButton_Click); </code></pre> <p>or this</p> <pre><code>c.Click += mainFormButton_Click; </code></pre> <p>and to remove an event handler you can do this</p> <pre><code>c.Click -= mainFormButton_Click; </...
[ { "answer_id": 91803, "author": "Jorge Ferreira", "author_id": 6508, "author_profile": "https://Stackoverflow.com/users/6508", "pm_score": 6, "selected": false, "text": "<p>From <em><a href=\"http://bytes.com/forum/thread274921.html\" rel=\"noreferrer\">Removing All Event Handlers</a></e...
2008/09/18
[ "https://Stackoverflow.com/questions/91778", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7297/" ]
To create a new event handler on a control you can do this ``` c.Click += new EventHandler(mainFormButton_Click); ``` or this ``` c.Click += mainFormButton_Click; ``` and to remove an event handler you can do this ``` c.Click -= mainFormButton_Click; ``` But how do you remove all event handlers from an event?
I found a solution on the [MSDN forums](http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/576f69e7-55aa-4574-8d31-417422954689/). The sample code below will remove all `Click` events from `button1`. ``` public partial class Form1 : Form { public Form1() { InitializeComponent(); ...
91,784
<p>I have a table with say 3 columns. There's no primary key so there can be duplicate rows. I need to just keep one and delete the others. Any idea how to do this is Sql Server?</p>
[ { "answer_id": 91792, "author": "Ian Nelson", "author_id": 2084, "author_profile": "https://Stackoverflow.com/users/2084", "pm_score": 3, "selected": false, "text": "<p>Add an identity column to act as a surrogate primary key, and use this to identify two of the three rows to be deleted....
2008/09/18
[ "https://Stackoverflow.com/questions/91784", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1688440/" ]
I have a table with say 3 columns. There's no primary key so there can be duplicate rows. I need to just keep one and delete the others. Any idea how to do this is Sql Server?
I'd SELECT DISTINCT the rows and throw them into a temporary table, then drop the source table and copy back the data from the temp. **EDIT:** now with code snippet! ``` INSERT INTO TABLE_2 SELECT DISTINCT * FROM TABLE_1 GO DELETE FROM TABLE_1 GO INSERT INTO TABLE_1 SELECT * FROM TABLE_2 GO ```
91,800
<p>I'm using a FullTextSqlQuery in SharePoint 2007 (MOSS) and need to order the results by two columns:</p> <pre><code>SELECT WorkId FROM SCOPE() ORDER BY Author ASC, Rank DESC </code></pre> <p>However it seems that only the first column from ORDER BY is taken into account when returning results. In this case the res...
[ { "answer_id": 93524, "author": "Adam Hawkes", "author_id": 6703, "author_profile": "https://Stackoverflow.com/users/6703", "pm_score": 0, "selected": false, "text": "<p>I have no experience in SharePoint, but if it is the case where only one ORDER BY clause is being honored I would chan...
2008/09/18
[ "https://Stackoverflow.com/questions/91800", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15682/" ]
I'm using a FullTextSqlQuery in SharePoint 2007 (MOSS) and need to order the results by two columns: ``` SELECT WorkId FROM SCOPE() ORDER BY Author ASC, Rank DESC ``` However it seems that only the first column from ORDER BY is taken into account when returning results. In this case the results are ordered correctly...
Microsoft *finally* posted a knowledge base article about this issue. "When using RANK in the ORDER BY clause of a SharePoint Search query, no other properties should be used" <http://support.microsoft.com/kb/970830> Symptom: When using RANK in the ORDER BY clause of a SharePoint Search query only the first ORDER BY...
91,810
<p>Working with python interactively, it's sometimes necessary to display a result which is some arbitrarily complex data structure (like lists with embedded lists, etc.) The default way to display them is just one massive linear dump which just wraps over and over and you have to parse carefully to read it.</p> <p>Is...
[ { "answer_id": 91818, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 6, "selected": true, "text": "<pre><code>from pprint import pprint\na = [0, 1, ['a', 'b', 'c'], 2, 3, 4]\npprint(a)\n</code></pre>\n\n<p>Note that for a ...
2008/09/18
[ "https://Stackoverflow.com/questions/91810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4086/" ]
Working with python interactively, it's sometimes necessary to display a result which is some arbitrarily complex data structure (like lists with embedded lists, etc.) The default way to display them is just one massive linear dump which just wraps over and over and you have to parse carefully to read it. Is there som...
``` from pprint import pprint a = [0, 1, ['a', 'b', 'c'], 2, 3, 4] pprint(a) ``` Note that for a short list like my example, pprint will in fact print it all on one line. However, for more complex structures it does a pretty good job of pretty printing data.
91,817
<p>I discovered that you can start your variable name with a '@' character in C#. In my C# project I was using a web service (I added a web reference to my project) that was written in Java. One of the interface objects defined in the WSDL had a member variable with the name "params". Obviously this is a reserved word...
[ { "answer_id": 91822, "author": "rslite", "author_id": 15682, "author_profile": "https://Stackoverflow.com/users/15682", "pm_score": 6, "selected": false, "text": "<p>It just lets you use a reserved word as a variable name. Not recommended IMHO (except in cases like you have).</p>\n" }...
2008/09/18
[ "https://Stackoverflow.com/questions/91817", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13287/" ]
I discovered that you can start your variable name with a '@' character in C#. In my C# project I was using a web service (I added a web reference to my project) that was written in Java. One of the interface objects defined in the WSDL had a member variable with the name "params". Obviously this is a reserved word in...
Straight from the [C# Language Specification](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/), [Identifiers (C#)](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/lexical-structure#identifiers) : > > The prefix "@" enables the use of...
91,821
<p>I have a model class:</p> <pre><code>class Person(db.Model): first_name = db.StringProperty(required=True) last_name = db.StringProperty(required=True) </code></pre> <p>I have an instance of this class in <code>p</code>, and string <code>s</code> contains the value <code>'first_name'</code>. I would like to do...
[ { "answer_id": 91859, "author": "Jim", "author_id": 8427, "author_profile": "https://Stackoverflow.com/users/8427", "pm_score": 1, "selected": false, "text": "<pre><code>getattr(p, s)\nsetattr(p, s, new_value)\n</code></pre>\n" }, { "answer_id": 91911, "author": "Jim", "a...
2008/09/18
[ "https://Stackoverflow.com/questions/91821", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3154/" ]
I have a model class: ``` class Person(db.Model): first_name = db.StringProperty(required=True) last_name = db.StringProperty(required=True) ``` I have an instance of this class in `p`, and string `s` contains the value `'first_name'`. I would like to do something like: ``` print p[s] ``` and ``` p[s] = new...
If the model class is sufficiently intelligent, it should recognize the standard Python ways of doing this. Try: ``` getattr(p, s) setattr(p, s, new_value) ``` There is also hasattr available.
91,826
<p>Is there a version of FitNesse that works on Delphi 2006/2007/2009?</p> <p>If so where can I find It?</p> <p>Are there any other programs like FitNesse that work on Delphi 2006?</p>
[ { "answer_id": 91859, "author": "Jim", "author_id": 8427, "author_profile": "https://Stackoverflow.com/users/8427", "pm_score": 1, "selected": false, "text": "<pre><code>getattr(p, s)\nsetattr(p, s, new_value)\n</code></pre>\n" }, { "answer_id": 91911, "author": "Jim", "a...
2008/09/18
[ "https://Stackoverflow.com/questions/91826", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17560/" ]
Is there a version of FitNesse that works on Delphi 2006/2007/2009? If so where can I find It? Are there any other programs like FitNesse that work on Delphi 2006?
If the model class is sufficiently intelligent, it should recognize the standard Python ways of doing this. Try: ``` getattr(p, s) setattr(p, s, new_value) ``` There is also hasattr available.
91,831
<p>Say I have the following web.config:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;configuration&gt; &lt;system.web&gt; &lt;authentication mode="Windows"&gt;&lt;/authentication&gt; &lt;/system.web&gt; &lt;/configuration&gt; </code></pre> <p>Using ASP.NET C#, how can I detect the M...
[ { "answer_id": 91836, "author": "redsquare", "author_id": 6440, "author_profile": "https://Stackoverflow.com/users/6440", "pm_score": 3, "selected": true, "text": "<p>Try <code>Context.User.Identity.AuthenticationType</code></p>\n\n<p>Go for PB's answer folks</p>\n" }, { "answer_...
2008/09/18
[ "https://Stackoverflow.com/questions/91831", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383/" ]
Say I have the following web.config: ``` <?xml version="1.0" encoding="utf-8"?> <configuration> <system.web> <authentication mode="Windows"></authentication> </system.web> </configuration> ``` Using ASP.NET C#, how can I detect the Mode value of the Authentication tag?
Try `Context.User.Identity.AuthenticationType` Go for PB's answer folks
91,856
<p>Would the following SQL remove also the index - or does it have to be removed separately?</p> <pre><code>CREATE TABLE #Tbl (field int) CREATE NONCLUSTERED INDEX idx ON #Tbl (field) DROP TABLE #Tbl </code></pre>
[ { "answer_id": 91863, "author": "Nick Craver", "author_id": 13249, "author_profile": "https://Stackoverflow.com/users/13249", "pm_score": 3, "selected": false, "text": "<p>It will be removed automatically, as there is nothing left to index. Think of it as a child object in this respect....
2008/09/18
[ "https://Stackoverflow.com/questions/91856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2133/" ]
Would the following SQL remove also the index - or does it have to be removed separately? ``` CREATE TABLE #Tbl (field int) CREATE NONCLUSTERED INDEX idx ON #Tbl (field) DROP TABLE #Tbl ```
Yes they are. You can search in MSSQL help for CREATE INDEX article it is said there: > > "Indexes can be created on a temporary > table. When the table is dropped or > the session ends, all indexes and > triggers are dropped." > > >
91,899
<p>I'm using grep to generate a list of files I need to move:</p> <pre><code>grep -L -r 'Subject: \[SPAM\]' . </code></pre> <p>How can I pass this list to the mv command and move the files somewhere else?</p>
[ { "answer_id": 91901, "author": "Confusion", "author_id": 16784, "author_profile": "https://Stackoverflow.com/users/16784", "pm_score": -1, "selected": false, "text": "<p>You can pass the result to the next command by using\ngrep ... | xargs mv {} destination</p>\n\n<p>Check man xargs fo...
2008/09/18
[ "https://Stackoverflow.com/questions/91899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17582/" ]
I'm using grep to generate a list of files I need to move: ``` grep -L -r 'Subject: \[SPAM\]' . ``` How can I pass this list to the mv command and move the files somewhere else?
If you want to find and move files that do not match your pattern (move files that don't contain `'Subject \[SPAM\]'` in this example) use: ``` grep -L -Z -r 'Subject: \[SPAM\]' . | xargs -0 -I{} mv {} DIR ``` The -Z means output with zeros (\0) after the filenames (so spaces are not used as delimeters). ``` xargs ...
91,905
<p>I want to add a mailto link on our web page. I want to add a urgent priority to this mail.</p>
[ { "answer_id": 91921, "author": "Robit", "author_id": 17026, "author_profile": "https://Stackoverflow.com/users/17026", "pm_score": 4, "selected": true, "text": "<p>mailto links just doesn't support this feature , sorry.</p>\n\n<p>however, you could use a specific subject and filter it i...
2008/09/18
[ "https://Stackoverflow.com/questions/91905", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17584/" ]
I want to add a mailto link on our web page. I want to add a urgent priority to this mail.
mailto links just doesn't support this feature , sorry. however, you could use a specific subject and filter it in your inbox ``` <a href="mailto:[email protected]?subject=Urgent">Send a email</a> ```
91,932
<p>How does it work, what is it used for and when should one use it?</p>
[ { "answer_id": 91961, "author": "Bill the Lizard", "author_id": 1288, "author_profile": "https://Stackoverflow.com/users/1288", "pm_score": 3, "selected": false, "text": "<p>Directly from the <a href=\"http://en.wikipedia.org/wiki/Strategy_pattern\" rel=\"nofollow noreferrer\">Strategy P...
2008/09/18
[ "https://Stackoverflow.com/questions/91932", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2695/" ]
How does it work, what is it used for and when should one use it?
Let's explain the strategy pattern the easy way: You have a class `Car()` with a method `run()`, so you use it this way in a pseudo language: ``` mycar = new Car() mycar.run() ``` Now, you may want to change the `run()` behavior on the fly, while the program is executing. For example, you might want to simulate a m...
91,933
<p>I've been working on a project where I need to iterate through a collection of data and remove entries where the "primary key" is duplicated. I have tried using a</p> <pre><code>List&lt;int&gt; </code></pre> <p>and </p> <pre><code>Dictionary&lt;int, bool&gt; </code></pre> <p>With the dictionary I found slightly ...
[ { "answer_id": 91951, "author": "leppie", "author_id": 15541, "author_profile": "https://Stackoverflow.com/users/15541", "pm_score": 3, "selected": true, "text": "<p>They have added the HashSet class in .NET 3.5. But I guess it will be on par with the Dictionary. If you have less than s...
2008/09/18
[ "https://Stackoverflow.com/questions/91933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4660/" ]
I've been working on a project where I need to iterate through a collection of data and remove entries where the "primary key" is duplicated. I have tried using a ``` List<int> ``` and ``` Dictionary<int, bool> ``` With the dictionary I found slightly better performance, even though I never need the Boolean tagg...
They have added the HashSet class in .NET 3.5. But I guess it will be on par with the Dictionary. If you have less than say a 100 elements a List will probably perform better.
91,957
<p>How do I use groovy to search+replace in XML?</p> <p>I need something as short/easy as possible, since I'll be giving this code to the testers for their SoapUI scripting.</p> <p>More specifically, how do I turn:</p> <pre><code>&lt;root&gt;&lt;data&gt;&lt;/data&gt;&lt;/root&gt; </code></pre> <p>into:</p> <pre><c...
[ { "answer_id": 91976, "author": "Bob Dizzle", "author_id": 9581, "author_profile": "https://Stackoverflow.com/users/9581", "pm_score": -1, "selected": false, "text": "<p>check this:\n<a href=\"http://today.java.net/pub/a/today/2004/08/12/groovyxml.html?page=2\" rel=\"nofollow noreferrer\...
2008/09/18
[ "https://Stackoverflow.com/questions/91957", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17554/" ]
How do I use groovy to search+replace in XML? I need something as short/easy as possible, since I'll be giving this code to the testers for their SoapUI scripting. More specifically, how do I turn: ``` <root><data></data></root> ``` into: ``` <root><data>value</data></root> ```
Some of the stuff you can do with an XSLT you can also do with some form of 'search & replace'. It all depends on how complex your problem is and how 'generic' you want to implement the solution. To make your own example slightly more generic: ``` xml.replaceFirst("<Mobiltlf>[^<]*</Mobiltlf>", '<Mobiltlf>32165487</Mob...
91,981
<p>Is there a way to mock object construction using JMock in Java? </p> <p>For example, if I have a method as such:</p> <pre class="lang-java prettyprint-override"><code>public Object createObject(String objectType) { if(objectType.equals("Integer") { return new Integer(); } else if (objectType.equal...
[ { "answer_id": 92064, "author": "Gishu", "author_id": 1695, "author_profile": "https://Stackoverflow.com/users/1695", "pm_score": -1, "selected": false, "text": "<p>I hope there is none. \nMocks are supposed to mock interfaces, which have no constructors... just methods. </p>\n\n<p>Somet...
2008/09/18
[ "https://Stackoverflow.com/questions/91981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4120/" ]
Is there a way to mock object construction using JMock in Java? For example, if I have a method as such: ```java public Object createObject(String objectType) { if(objectType.equals("Integer") { return new Integer(); } else if (objectType.equals("String") { return new String(); } } ``` ...
The only thing I can think of is to have the create method on at factory object, which you would than mock. But in terms of mocking a constructor call, no. Mock objects presuppose the existence of the object, whereas a constructor presuppose that the object doesn't exist. At least in java where allocation and initial...
91,986
<p>I've got the following SQL:</p> <pre><code>select * from transaction_log where stoptime like '%2008%' </code></pre> <p>How do I write this in LINQ to SQL syntax?</p>
[ { "answer_id": 92009, "author": "Nick Craver", "author_id": 13249, "author_profile": "https://Stackoverflow.com/users/13249", "pm_score": 6, "selected": true, "text": "<p>If you want to use the literal method, it's like this:</p>\n\n<pre><code>var query = from l in transaction_log\n ...
2008/09/18
[ "https://Stackoverflow.com/questions/91986", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1683/" ]
I've got the following SQL: ``` select * from transaction_log where stoptime like '%2008%' ``` How do I write this in LINQ to SQL syntax?
If you want to use the literal method, it's like this: ``` var query = from l in transaction_log where SqlMethods.Like(l.stoptime, "%2008%") select l; ``` Another option is: ``` var query = from l in transaction_log where l.stoptime.Contains("2008") select l; ``` If it's a ...
91,994
<p>This is probably a silly question, but curiosity has gotten the better of me. I've been seeing code lately that seems to "reverse" the order of expressions for relational operators e.g.:</p> <pre><code>if (0 == someVariable) </code></pre> <p>As opposed to what I normally see/write:</p> <pre><code>if (someVariable...
[ { "answer_id": 91997, "author": "William Keller", "author_id": 17095, "author_profile": "https://Stackoverflow.com/users/17095", "pm_score": 2, "selected": false, "text": "<p>Order does not matter, however, the former implies that it\ns the zero you're checking. Convention dictates the u...
2008/09/18
[ "https://Stackoverflow.com/questions/91994", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9324/" ]
This is probably a silly question, but curiosity has gotten the better of me. I've been seeing code lately that seems to "reverse" the order of expressions for relational operators e.g.: ``` if (0 == someVariable) ``` As opposed to what I normally see/write: ``` if (someVariable == 0) ``` To me, the second method...
I understand that this is personal preference. Although by putting the variable second you can ensure that you don't accidentally assign the constant to the variable which used to concearn c developers. This is probably why you are seeing it in c# as developers switch language.
92,008
<p>How do I programmatically set the record pointer in a C# DataGridView? </p> <p>I've tried "DataGridView.Rows[DesiredRowIndex].Selected=true;", and that does not work. All it does is highlight that row within the grid; it doesn not move the record pointer to that row.</p>
[ { "answer_id": 92105, "author": "Wolfwyrd", "author_id": 15570, "author_profile": "https://Stackoverflow.com/users/15570", "pm_score": 3, "selected": true, "text": "<p>To change the active row for the datagrid you need to set the current cell property of the datagrid to a non-hidden non-...
2008/09/18
[ "https://Stackoverflow.com/questions/92008", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7148/" ]
How do I programmatically set the record pointer in a C# DataGridView? I've tried "DataGridView.Rows[DesiredRowIndex].Selected=true;", and that does not work. All it does is highlight that row within the grid; it doesn not move the record pointer to that row.
To change the active row for the datagrid you need to set the current cell property of the datagrid to a non-hidden non-disabled, non-header cell on the row that you have selected. You'd do this like: ``` dataGridView1.CurrentCell = this.dataGridView1[YourColumn,YourRow]; ``` Making sure that the cell matches the ab...
92,027
<p>For a registration form I have something simple like:</p> <pre><code> &lt;tr:panelLabelAndMessage label="Zip/City" showRequired="true"&gt; &lt;tr:inputText id="zip" value="#{data['registration'].zipCode}" contentStyle="widt...
[ { "answer_id": 107817, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<p>I know this won't be ideal, but if you remove the <code>panelLabelAndMessage</code> tag and just use the label attribute on...
2008/09/18
[ "https://Stackoverflow.com/questions/92027", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11705/" ]
For a registration form I have something simple like: ``` <tr:panelLabelAndMessage label="Zip/City" showRequired="true"> <tr:inputText id="zip" value="#{data['registration'].zipCode}" contentStyle="width:36px" ...
Problem is, the fields must layout horizontally. It's a no-go to put ZIP field and city not next to each other in one line. At least for me. A co-worker has pointed me to set a faclets variable inside the first tr:message and to put a rendered attribute at the second one that reacts on this variable. Havn't got the ti...
92,035
<p>I have a datagridview with a DataGridViewComboboxColumn column with 3 values:</p> <p>"Small", "Medium", "Large"</p> <p>I get back the users default which in this case is "Medium"</p> <p>I want to show a dropdown cell in the datagridview but default the value to "Medium". i would do this in a regular combobox by...
[ { "answer_id": 92186, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<p>Are you retrieving the user data and attempting to set values in the DataGridView manually, or have you actually bound the D...
2008/09/18
[ "https://Stackoverflow.com/questions/92035", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
I have a datagridview with a DataGridViewComboboxColumn column with 3 values: "Small", "Medium", "Large" I get back the users default which in this case is "Medium" I want to show a dropdown cell in the datagridview but default the value to "Medium". i would do this in a regular combobox by doing selected index or j...
When you get into the datagridview it is probably best to get into databinding. This will take care of all of the selected index stuff you are talking about. However, if you want to get in there by yourself, ``` DataGridView.Rows[rowindex].Cells[columnindex].Value ``` will let you get and set the value associated...
92,043
<p>I've tried the tools listed <a href="http://wiki.postgresql.org/wiki/Converting_from_other_Databases_to_PostgreSQL" rel="noreferrer">here</a>, some with more success than others, but none gave me valid postgres syntax I could use (tinyint errors etc.)</p>
[ { "answer_id": 92077, "author": "Dana the Sane", "author_id": 2567, "author_profile": "https://Stackoverflow.com/users/2567", "pm_score": 0, "selected": false, "text": "<p>Have a look at <a href=\"http://pgfoundry.org/\" rel=\"nofollow noreferrer\">PG Foundry</a>, extra utilities for Pos...
2008/09/18
[ "https://Stackoverflow.com/questions/92043", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4196/" ]
I've tried the tools listed [here](http://wiki.postgresql.org/wiki/Converting_from_other_Databases_to_PostgreSQL), some with more success than others, but none gave me valid postgres syntax I could use (tinyint errors etc.)
There's a `mysqldump` option which makes it output PostgreSQL code: ``` mysqldump --compatible=postgresql ... ``` But that doesn't work too well. Instead, please see the [mysql-to-postgres](https://github.com/maxlapshin/mysql2postgres) tool as [described in Linus Oleander's answer](https://stackoverflow.com/a/1567...
92,076
<p>I'm writing some xlst file which I want to use under linux and Windows. In this file I use node-set function which declared in different namespaces for MSXML and xsltproc ("urn:schemas-microsoft-com:xslt" and "<a href="http://exslt.org/common" rel="nofollow noreferrer">http://exslt.org/common</a>" respectively). Is...
[ { "answer_id": 92119, "author": "Ben", "author_id": 15480, "author_profile": "https://Stackoverflow.com/users/15480", "pm_score": 1, "selected": false, "text": "<p>Firefox 3 implements node-set (as part of the EXSLT 2.0 namespace improvements) in it's client-side XSLT processing.</p>\n\n...
2008/09/18
[ "https://Stackoverflow.com/questions/92076", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17569/" ]
I'm writing some xlst file which I want to use under linux and Windows. In this file I use node-set function which declared in different namespaces for MSXML and xsltproc ("urn:schemas-microsoft-com:xslt" and "<http://exslt.org/common>" respectively). Is there any platform independent way of using node-set?
You can use the function function-available() to determine which function you should use: ``` <xsl:choose> <xsl:when test="function-available('exslt:node-set')"> <xsl:apply-templates select="exslt:node-set($nodelist)" /> </xsl:when> <xsl:when test="function-available('msxsl:node-set')"> <xsl:apply-templa...
92,082
<p>How can I add a column with a default value to an existing table in <a href="http://en.wikipedia.org/wiki/Microsoft_SQL_Server#Genesis" rel="noreferrer">SQL Server 2000</a> / <a href="http://en.wikipedia.org/wiki/Microsoft_SQL_Server#SQL_Server_2005" rel="noreferrer">SQL Server 2005</a>?</p>
[ { "answer_id": 92092, "author": "Benjamin Autin", "author_id": 1440933, "author_profile": "https://Stackoverflow.com/users/1440933", "pm_score": 6, "selected": false, "text": "<pre><code>ALTER TABLE ADD ColumnName {Column_Type} Constraint\n</code></pre>\n\n<p>The MSDN article <em><a href...
2008/09/18
[ "https://Stackoverflow.com/questions/92082", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7241/" ]
How can I add a column with a default value to an existing table in [SQL Server 2000](http://en.wikipedia.org/wiki/Microsoft_SQL_Server#Genesis) / [SQL Server 2005](http://en.wikipedia.org/wiki/Microsoft_SQL_Server#SQL_Server_2005)?
Syntax: ------- ``` ALTER TABLE {TABLENAME} ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL} CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE} WITH VALUES ``` Example: -------- ``` ALTER TABLE SomeTable ADD SomeCol Bit NULL --Or NOT NULL. CONSTRAINT D_SomeTable_SomeCol --When Omitted a Default-Constraint Name ...
92,093
<p>I am working on a SQL query that reads from a SQLServer database to produce an extract file. One of the requirements to remove the leading zeroes from a particular field, which is a simple <code>VARCHAR(10)</code> field. So, for example, if the field contains '00001A', the SELECT statement needs to return the data ...
[ { "answer_id": 92363, "author": "Ian Horwill", "author_id": 5816, "author_profile": "https://Stackoverflow.com/users/5816", "pm_score": 8, "selected": true, "text": "<pre><code>select substring(ColumnName, patindex('%[^0]%',ColumnName), 10)\n</code></pre>\n" }, { "answer_id": 450...
2008/09/18
[ "https://Stackoverflow.com/questions/92093", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7585/" ]
I am working on a SQL query that reads from a SQLServer database to produce an extract file. One of the requirements to remove the leading zeroes from a particular field, which is a simple `VARCHAR(10)` field. So, for example, if the field contains '00001A', the SELECT statement needs to return the data as '1A'. Is th...
``` select substring(ColumnName, patindex('%[^0]%',ColumnName), 10) ```
92,100
<p>Is it possible to set code behind a resource dictionary in WPF. For example in a usercontrol for a button you declare it in XAML. The event handling code for the button click is done in the code file behind the control. If I was to create a data template with a button how can I write the event handler code for it's ...
[ { "answer_id": 92205, "author": "Gishu", "author_id": 1695, "author_profile": "https://Stackoverflow.com/users/1695", "pm_score": -1, "selected": false, "text": "<p>XAML is for constructing object graphs not containing code.<br>\nA Data template is used to indicate how a custom user-obje...
2008/09/18
[ "https://Stackoverflow.com/questions/92100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6204/" ]
Is it possible to set code behind a resource dictionary in WPF. For example in a usercontrol for a button you declare it in XAML. The event handling code for the button click is done in the code file behind the control. If I was to create a data template with a button how can I write the event handler code for it's but...
I think what you're asking is you want a code-behind file for a ResourceDictionary. You can totally do this! In fact, you do it the same way as for a Window: Say you have a ResourceDictionary called MyResourceDictionary. In your MyResourceDictionary.xaml file, put the x:Class attribute in the root element, like so: `...
92,103
<p>What do you find is the optimal setting for mysql slow query log parameter, and why?</p>
[ { "answer_id": 92140, "author": "David Precious", "author_id": 4040, "author_profile": "https://Stackoverflow.com/users/4040", "pm_score": 2, "selected": false, "text": "<p>Whatever time /you/ feel is unacceptably slow for a query on your systems.</p>\n\n<p>It depends on the kind of quer...
2008/09/18
[ "https://Stackoverflow.com/questions/92103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10596/" ]
What do you find is the optimal setting for mysql slow query log parameter, and why?
I recommend these three lines ``` log_slow_queries set-variable = long_query_time=1 log-queries-not-using-indexes ``` The first and second will log any query over a second. As others have pointed out a one second query is pretty far gone if you are a shooting for a high transaction rate on your website, but I find ...
92,114
<p>There is a limitation on Windows Server 2003 that prevents you from copying extremely large files, in proportion to the amount of RAM you have. The limitation is in the CopyFile and CopyFileEx functions, which are used by xcopy, Explorer, Robocopy, and the .NET FileInfo class.</p> <p>Here is the error that you get...
[ { "answer_id": 92165, "author": "jabial", "author_id": 16995, "author_profile": "https://Stackoverflow.com/users/16995", "pm_score": 5, "selected": true, "text": "<p>The best option is to just open the original file for reading, the destination file for writing and then loop copying it b...
2008/09/18
[ "https://Stackoverflow.com/questions/92114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1219/" ]
There is a limitation on Windows Server 2003 that prevents you from copying extremely large files, in proportion to the amount of RAM you have. The limitation is in the CopyFile and CopyFileEx functions, which are used by xcopy, Explorer, Robocopy, and the .NET FileInfo class. Here is the error that you get: > > Can...
The best option is to just open the original file for reading, the destination file for writing and then loop copying it block by block. In pseudocode : ``` f1 = open(filename1); f2 = open(filename2, "w"); while( !f1.eof() ) { buffer = f1.read(buffersize); err = f2.write(buffer, buffersize); if err != NO_ERROR_C...
92,239
<p>If you have several <code>div</code>s on a page, you can use CSS to size, float them and move them round a little... but I can't see a way to get past the fact that the first <code>div</code> will show near the top of the page and the last <code>div</code> will be near the bottom! I cannot completely override the or...
[ { "answer_id": 92264, "author": "workmad3", "author_id": 16035, "author_profile": "https://Stackoverflow.com/users/16035", "pm_score": 2, "selected": false, "text": "<p>You don't need position:absolute on every element to do what you want.</p>\n\n<p>You just use it on a few key items and...
2008/09/18
[ "https://Stackoverflow.com/questions/92239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11461/" ]
If you have several `div`s on a page, you can use CSS to size, float them and move them round a little... but I can't see a way to get past the fact that the first `div` will show near the top of the page and the last `div` will be near the bottom! I cannot completely override the order of the elements as they come fro...
With Floating, and with position absolute, you can pull some pretty good positioning magic to change some of the order of the page. For instance, with StackOverflow, if the markup was setup right, the title, and main body content could be the first 2 things in the markup, and then the navigation/search, and finally th...