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
479,751
<p>I'm building a simple web-based RSS reader in Python, but I'm having trouble parsing the XML. I started out by trying some stuff in the Python command line.</p> <pre><code>&gt;&gt;&gt; from xml.dom import minidom &gt;&gt;&gt; import urllib2 &gt;&gt;&gt; url ='http://www.digg.com/rss/index.xml' &gt;&gt;&gt; xmldoc ...
[ { "answer_id": 479766, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": true, "text": "<p>For RSS feeds you should try the <a href=\"http://code.google.com/p/feedparser/\" rel=\"nofollow noreferrer\">Universal Feed...
2009/01/26
[ "https://Stackoverflow.com/questions/479751", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2128/" ]
I'm building a simple web-based RSS reader in Python, but I'm having trouble parsing the XML. I started out by trying some stuff in the Python command line. ``` >>> from xml.dom import minidom >>> import urllib2 >>> url ='http://www.digg.com/rss/index.xml' >>> xmldoc = minidom.parse(urllib2.urlopen(url)) >>> channeln...
For RSS feeds you should try the [Universal Feed Parser](http://code.google.com/p/feedparser/) library. It simplifies the handling of RSS feeds immensly. ``` import feedparser d = feedparser.parse('http://www.digg.com/rss/index.xml') title = d.channel.title ```
479,762
<p>I am writing a little program that creates an index of all files on my directories. It basically iterates over each file on the disk and stores it into a searchable database, much like Unix's locate. The problem is, that index generation is quite slow since I have about a million files.</p> <p>Once I have generated...
[ { "answer_id": 479772, "author": "krosenvold", "author_id": 23691, "author_profile": "https://Stackoverflow.com/users/23691", "pm_score": 3, "selected": false, "text": "<p>Unfortunately there's no standard way to listen to file system events in java. This <em>may</em> be coming in java7....
2009/01/26
[ "https://Stackoverflow.com/questions/479762", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48181/" ]
I am writing a little program that creates an index of all files on my directories. It basically iterates over each file on the disk and stores it into a searchable database, much like Unix's locate. The problem is, that index generation is quite slow since I have about a million files. Once I have generated an index,...
I've done this in my tool MetaMake. Here is the recipe: 1. If the index is empty, add the root directory to the index with a timestamp == dir.lastModified()-1. 2. Find all directories in the index 3. Compare the timestamp of the directory in the index with the one from the filesystem. This is a fast operation since yo...
479,770
<p>What is the best way to monitor disks against file activities. I mean that getting the full file name (c:\temp\abc.txt), action(created/deleted/modified/renamed), and also the user (user1) and process name (notepad.exe) causing the file (multiple delete) activities.</p> <p>I heard about Some APIs and ShellNotificat...
[ { "answer_id": 479801, "author": "mghie", "author_id": 30568, "author_profile": "https://Stackoverflow.com/users/30568", "pm_score": 3, "selected": false, "text": "<p>There is a Windows API to receive notifications about changes in directories and optionally subdirectories of that, see <...
2009/01/26
[ "https://Stackoverflow.com/questions/479770", "https://Stackoverflow.com", "https://Stackoverflow.com/users/59003/" ]
What is the best way to monitor disks against file activities. I mean that getting the full file name (c:\temp\abc.txt), action(created/deleted/modified/renamed), and also the user (user1) and process name (notepad.exe) causing the file (multiple delete) activities. I heard about Some APIs and ShellNotifications but c...
One of my favorite blogs answered this question (with full source and a demo application) quite a while ago. Checkout the [Delphi About.com article here](http://delphi.about.com/od/kbwinshell/l/aa030403a.htm) which has a more in depth explanation. Code provided by Zarko Gajic at <http://delphi.about.com> *Wanna get no...
479,791
<p>It's well known that you cannot set foreign key IDs directly in Linq to SQL if the entities have already been loaded. You can however look up the entity by it's foreign key and then set the entity as the foreign entity using the entity relationship. (I've taken out the enum here and used integer values for simplic...
[ { "answer_id": 2036511, "author": "Meligy", "author_id": 146656, "author_profile": "https://Stackoverflow.com/users/146656", "pm_score": 0, "selected": false, "text": "<p>Normally the setter of AppointmentStatusId looks like: (Code in C# but it should be easy to get it)</p>\n\n<pre><code...
2009/01/26
[ "https://Stackoverflow.com/questions/479791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29411/" ]
It's well known that you cannot set foreign key IDs directly in Linq to SQL if the entities have already been loaded. You can however look up the entity by it's foreign key and then set the entity as the foreign entity using the entity relationship. (I've taken out the enum here and used integer values for simplicity)....
There are two main schools of thought on this: 1. Put the logic in the `DataContext` (partial class, or actual class if you code your `DataContext` by hand). The rationale behind this is that your `DataContext` already knows about all of your different entities, so this isn't creating any additional coupling and isn't...
479,799
<p>What is the nicest way of replacing the host-part of an Uri using .NET?</p> <p>I.e.:</p> <pre><code>string ReplaceHost(string original, string newHostName); //... string s = ReplaceHost("http://oldhostname/index.html", "newhostname"); Assert.AreEqual("http://newhostname/index.html", s); //... string s = ReplaceHos...
[ { "answer_id": 479812, "author": "Ishmael", "author_id": 8930, "author_profile": "https://Stackoverflow.com/users/8930", "pm_score": 8, "selected": true, "text": "<p><a href=\"https://learn.microsoft.com/en-us/dotnet/api/system.uribuilder\" rel=\"noreferrer\">System.UriBuilder</a> is wha...
2009/01/26
[ "https://Stackoverflow.com/questions/479799", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5542/" ]
What is the nicest way of replacing the host-part of an Uri using .NET? I.e.: ``` string ReplaceHost(string original, string newHostName); //... string s = ReplaceHost("http://oldhostname/index.html", "newhostname"); Assert.AreEqual("http://newhostname/index.html", s); //... string s = ReplaceHost("http://user:pass@o...
[System.UriBuilder](https://learn.microsoft.com/en-us/dotnet/api/system.uribuilder) is what you are after... ``` string ReplaceHost(string original, string newHostName) { var builder = new UriBuilder(original); builder.Host = newHostName; return builder.Uri.ToString(); } ```
479,809
<p>To make a long story short I have to use processing in a class and I'm completely blind. The ide is completely inaccessible so I use the JavaScript version of processing to create a page and have a sited person describe the output to me. Unfortunately if the code has errors the page appears blank and there is no exp...
[ { "answer_id": 479852, "author": "fmsf", "author_id": 26004, "author_profile": "https://Stackoverflow.com/users/26004", "pm_score": 2, "selected": true, "text": "<p>Well for debuging (when the code compiles) you can use the println() command.</p>\n\n<p>I've been using processing for 2 mo...
2009/01/26
[ "https://Stackoverflow.com/questions/479809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14744/" ]
To make a long story short I have to use processing in a class and I'm completely blind. The ide is completely inaccessible so I use the JavaScript version of processing to create a page and have a sited person describe the output to me. Unfortunately if the code has errors the page appears blank and there is no explan...
Well for debuging (when the code compiles) you can use the println() command. I've been using processing for 2 months now and i have the same problem and haven't been able to find a solution for it. Here in SO for what I've seen almost no one uses Processing or knows how to use it. You can try the processing forums, ...
479,817
<p>I know that when an item is restored from the recycle bin, the ItemAdded event is fired. However, how can I detect if the item added comes from the recycle bin or if it is a new file.</p>
[ { "answer_id": 480359, "author": "webwires", "author_id": 13135, "author_profile": "https://Stackoverflow.com/users/13135", "pm_score": 0, "selected": false, "text": "<p>You could check the Created Date of the item. Items from the Recycle bin should have a previous created date.</p>\n" ...
2009/01/26
[ "https://Stackoverflow.com/questions/479817", "https://Stackoverflow.com", "https://Stackoverflow.com/users/59005/" ]
I know that when an item is restored from the recycle bin, the ItemAdded event is fired. However, how can I detect if the item added comes from the recycle bin or if it is a new file.
This is a very old thread, but it comes up in the top results for searches on the topic. From my experiments with SP2010, it looks like [properties.AfterProperties](http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventproperties.afterproperties.aspx) is empty when the item is coming from the Recycle...
479,819
<p>I am trying to insert a .csv file into a database with unix linebreaks. The command I am running is:</p> <pre><code>BULK INSERT table_name FROM 'C:\file.csv' WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' ) </code></pre> <p>If I convert the file into Windows format the load works, but I don't wa...
[ { "answer_id": 479874, "author": "ConcernedOfTunbridgeWells", "author_id": 15401, "author_profile": "https://Stackoverflow.com/users/15401", "pm_score": 1, "selected": false, "text": "<p>One option would be to use <a href=\"http://msdn.microsoft.com/en-us/library/aa174646.aspx\" rel=\"no...
2009/01/26
[ "https://Stackoverflow.com/questions/479819", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24108/" ]
I am trying to insert a .csv file into a database with unix linebreaks. The command I am running is: ``` BULK INSERT table_name FROM 'C:\file.csv' WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' ) ``` If I convert the file into Windows format the load works, but I don't want to do this extra step if...
I felt compelled to contribute as I was having the same issue, and I need to read 2 UNIX files from SAP at least a couple of times a day. Therefore, instead of using unix2dos, I needed something with less manual intervention and more automatic via programming. As noted, the Char(10) works within the sql string. I didn...
479,825
<p>I have the following string (japanese) " ユーザー名" , the first character is "like" whitespace but its number in unicode is 12288, so if I do " ユーザー名".trim() I get the same string (trim doesn't work). If i do trim in c++ it works ok. Does anyone know how to solve this issue in java? Is there a special trim method for un...
[ { "answer_id": 479842, "author": "Paul Whelan", "author_id": 3050, "author_profile": "https://Stackoverflow.com/users/3050", "pm_score": 2, "selected": false, "text": "<p>From the java docs, it explains why this doesn't work. </p>\n\n<blockquote>\n <p>If this String object represents an...
2009/01/26
[ "https://Stackoverflow.com/questions/479825", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30729/" ]
I have the following string (japanese) " ユーザー名" , the first character is "like" whitespace but its number in unicode is 12288, so if I do " ユーザー名".trim() I get the same string (trim doesn't work). If i do trim in c++ it works ok. Does anyone know how to solve this issue in java? Is there a special trim method for unico...
As an alternative to the `StringUtils` class mentioned by Mike, you can also use a Unicode-aware regular expression, using only Java's own libraries: ``` " ユーザー名".replaceAll("\\p{Z}", "") ``` Or, to really only trim, and not remove whitespace inside the string: ``` " ユーザ ー名 ".replaceAll("(^\\p{Z}+|\\p{Z}+$)", "") ...
479,827
<p>I have an ASPX page that is dynamically creating a gridview from a database table. Each time the gridview is created on postback, I set the AutoGenerateDeleteButton attribute to true. However, the first time the gridview is created the delete button isn't displaying. I wrote the value of AutoGenerateDeleteButton ...
[ { "answer_id": 479842, "author": "Paul Whelan", "author_id": 3050, "author_profile": "https://Stackoverflow.com/users/3050", "pm_score": 2, "selected": false, "text": "<p>From the java docs, it explains why this doesn't work. </p>\n\n<blockquote>\n <p>If this String object represents an...
2009/01/26
[ "https://Stackoverflow.com/questions/479827", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1972/" ]
I have an ASPX page that is dynamically creating a gridview from a database table. Each time the gridview is created on postback, I set the AutoGenerateDeleteButton attribute to true. However, the first time the gridview is created the delete button isn't displaying. I wrote the value of AutoGenerateDeleteButton and it...
As an alternative to the `StringUtils` class mentioned by Mike, you can also use a Unicode-aware regular expression, using only Java's own libraries: ``` " ユーザー名".replaceAll("\\p{Z}", "") ``` Or, to really only trim, and not remove whitespace inside the string: ``` " ユーザ ー名 ".replaceAll("(^\\p{Z}+|\\p{Z}+$)", "") ...
479,837
<p>How can i hook-up WMD editor on to my django forms?</p>
[ { "answer_id": 480005, "author": "Harper Shelby", "author_id": 21196, "author_profile": "https://Stackoverflow.com/users/21196", "pm_score": 2, "selected": false, "text": "<p>From the readme.txt in the current WMD download:</p>\n\n<blockquote>\n <p>To install the editor, include wmd.js\...
2009/01/26
[ "https://Stackoverflow.com/questions/479837", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
How can i hook-up WMD editor on to my django forms?
Here is complete Django widget class: ``` class WMDEditor(forms.Textarea): def __init__(self, *args, **kwargs): attrs = kwargs.setdefault('attrs', {}) if 'cols' not in attrs: attrs['cols'] = 58 if 'rows' not in attrs: attrs['rows'] = 8 super(WMDEditor, self)...
479,847
<p>i'm developing a simple C# Editor for one of my university courses and I need to send a .cs file to Compiler and collect errors (if they exist) and show them in my app. In other words i want to add a C# Compiler to my Editor. Is there anything like this for the debugger?</p>
[ { "answer_id": 479858, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 1, "selected": false, "text": "<p>Use the <code>System.Diagnostics.Process</code> class to start a generic process and collect the I/O from standard input/ou...
2009/01/26
[ "https://Stackoverflow.com/questions/479847", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55555/" ]
i'm developing a simple C# Editor for one of my university courses and I need to send a .cs file to Compiler and collect errors (if they exist) and show them in my app. In other words i want to add a C# Compiler to my Editor. Is there anything like this for the debugger?
If you use the CodeDomProvider ``` using System.CodeDom; using System.CodeDom.Compiler; using Microsoft.CSharp; // the compilation part // change the parameters as you see fit CompilerParameters cp = CreateCompilerParameters(); var options = new System.Collections.Generic.Dictionary<string, string>(); if (/* you wa...
479,855
<p>Spring has a very handy convenience class called <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html" rel="noreferrer">PropertyPlaceholderConfigurer</a>, which takes a standard .properties file and injects values from it into yo...
[ { "answer_id": 480413, "author": "toolkit", "author_id": 3295, "author_profile": "https://Stackoverflow.com/users/3295", "pm_score": 4, "selected": true, "text": "<p>I just tested this, and it should just work. </p>\n\n<p>PropertiesPlaceholderConfigurer contains a setPropertiesPersister ...
2009/01/26
[ "https://Stackoverflow.com/questions/479855", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1035/" ]
Spring has a very handy convenience class called [PropertyPlaceholderConfigurer](http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html), which takes a standard .properties file and injects values from it into your bean.xml config. Does anyon...
I just tested this, and it should just work. PropertiesPlaceholderConfigurer contains a setPropertiesPersister method, so you can use your own subclass of [PropertiesPersister](http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/util/PropertiesPersister.html). The default PropertiesPersister a...
479,865
<p>I used the code below to compress files and they keep growing instead of shrinking. I comressed a 4 kb file and it became 6. That is understandable for a small file because of the compression overhead. I tried a 400 mb file and it became 628 mb after compressing. What is wrong? See the code. (.net 2.0)</p> <pre><co...
[ { "answer_id": 479876, "author": "Tamas Czinege", "author_id": 8954, "author_profile": "https://Stackoverflow.com/users/8954", "pm_score": 3, "selected": true, "text": "<p>Are you sure that writing byte by byte to the stream is a really good idea? It will certainly not have ideal perform...
2009/01/26
[ "https://Stackoverflow.com/questions/479865", "https://Stackoverflow.com", "https://Stackoverflow.com/users/487/" ]
I used the code below to compress files and they keep growing instead of shrinking. I comressed a 4 kb file and it became 6. That is understandable for a small file because of the compression overhead. I tried a 400 mb file and it became 628 mb after compressing. What is wrong? See the code. (.net 2.0) ``` Public Sub ...
Are you sure that writing byte by byte to the stream is a really good idea? It will certainly not have ideal performance characteristics and maybe that's what confuses the gzip compressing algorithm too. Also, it might happen that the data you are trying to compress is just not really well-compressable. If I were you ...
479,891
<p>There's some code in our project that looks a bit like this:</p> <pre><code>Private Sub Method1() Call InnerMethod End Sub Private Sub Method2() InnerMethod End Sub Private Sub InnerMethod() '' stuff End Sub </code></pre> <p>What's the advantage of doing Method1 over Method2?</p>
[ { "answer_id": 479900, "author": "James Sun", "author_id": 24482, "author_profile": "https://Stackoverflow.com/users/24482", "pm_score": 2, "selected": false, "text": "<p>There's no difference.</p>\n" }, { "answer_id": 479904, "author": "Patrick Cuff", "author_id": 7903, ...
2009/01/26
[ "https://Stackoverflow.com/questions/479891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11529/" ]
There's some code in our project that looks a bit like this: ``` Private Sub Method1() Call InnerMethod End Sub Private Sub Method2() InnerMethod End Sub Private Sub InnerMethod() '' stuff End Sub ``` What's the advantage of doing Method1 over Method2?
From the [MSDN](http://msdn.microsoft.com/en-us/library/wcx04ck5(VS.85).aspx): > > You are not required to use the Call > keyword when calling a procedure. > However, if you use the Call keyword > to call a procedure that requires > arguments, argumentlist must be > enclosed in parentheses. If you omit > the Ca...
479,896
<p>I created an empty project in Xcode and have added all of my source code files to it. I do not have any build options/configurations set since the project was empty and I use my old Makefile from the command-line to build the app. Everything works - but...</p> <p>My problem is that it is a tad annoying not to have ...
[ { "answer_id": 479960, "author": "Mark Thistle", "author_id": 54651, "author_profile": "https://Stackoverflow.com/users/54651", "pm_score": 2, "selected": false, "text": "<p>When using Xcode with Research Assistant displayed, I find it only shows info when you highlight something in your...
2009/01/26
[ "https://Stackoverflow.com/questions/479896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53930/" ]
I created an empty project in Xcode and have added all of my source code files to it. I do not have any build options/configurations set since the project was empty and I use my old Makefile from the command-line to build the app. Everything works - but... My problem is that it is a tad annoying not to have the inform...
When using Xcode with Research Assistant displayed, I find it only shows info when you highlight something in your code. For example, if you had: ``` NSString *foo; ``` And you highlighted (clicked on) NSString then the Research Assistant will give you definitions of NSString, the API is belongs in, etc.
479,897
<p>Given a list of strings, I want to sort it alphabetically and remove duplicates. I know I can do this:</p> <pre><code>from sets import Set [...] myHash = Set(myList) </code></pre> <p>but I don't know how to retrieve the list members from the hash in alphabetical order.</p> <p>I'm not married to the hash, so any w...
[ { "answer_id": 479917, "author": "Rod Daunoravicius", "author_id": 20989, "author_profile": "https://Stackoverflow.com/users/20989", "pm_score": 9, "selected": true, "text": "<p>A list can be sorted and deduplicated using built-in functions:</p>\n\n<pre><code>myList = sorted(set(myList))...
2009/01/26
[ "https://Stackoverflow.com/questions/479897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58994/" ]
Given a list of strings, I want to sort it alphabetically and remove duplicates. I know I can do this: ``` from sets import Set [...] myHash = Set(myList) ``` but I don't know how to retrieve the list members from the hash in alphabetical order. I'm not married to the hash, so any way to accomplish this will work. ...
A list can be sorted and deduplicated using built-in functions: ``` myList = sorted(set(myList)) ``` * [`set`](http://docs.python.org/library/functions.html#func-set) is a built-in function for Python >= 2.3 * [`sorted`](http://docs.python.org/library/functions.html#sorted) is a built-in function for Python >= 2.4
479,919
<p>I have a list of about a hundreds unique strings in C++, I need to check if a value exists in this list, but preferrably lightning fast.</p> <p>I am currenly using a hash_set with std::strings (since I could not get it to work with const char*) like so:</p> <pre><code>stdext::hash_set&lt;const std::string&gt; _ite...
[ { "answer_id": 479949, "author": "David Thornley", "author_id": 14148, "author_profile": "https://Stackoverflow.com/users/14148", "pm_score": 2, "selected": false, "text": "<p>I doubt you'd come up with a better hashtable; if the list varies from time to time you've probably got the best...
2009/01/26
[ "https://Stackoverflow.com/questions/479919", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1830/" ]
I have a list of about a hundreds unique strings in C++, I need to check if a value exists in this list, but preferrably lightning fast. I am currenly using a hash\_set with std::strings (since I could not get it to work with const char\*) like so: ``` stdext::hash_set<const std::string> _items; _items.insert("LONG_N...
If your list of strings are fixed at compile time, use gperf <http://www.gnu.org/software/gperf/> QUOTE: gperf is a perfect hash function generator. For a given list of strings, it produces a hash function and hash table, in form of C or C++ code, for looking up a value depending on the input string. The hash function...
479,923
<p>I'm trying to understand what single and multiple dispatch are, exactly.</p> <p>I just read this:<br> <a href="http://en.wikipedia.org/wiki/Multiple_dispatch" rel="noreferrer">http://en.wikipedia.org/wiki/Multiple_dispatch</a></p> <p>And from that definition is seems to me that C# and VB.Net are multiple-dispatch,...
[ { "answer_id": 479951, "author": "JoshBerke", "author_id": 26160, "author_profile": "https://Stackoverflow.com/users/26160", "pm_score": 3, "selected": false, "text": "<p>C# is single dispatch but there are some blog posts which by their title looks like they are trying to emulate multim...
2009/01/26
[ "https://Stackoverflow.com/questions/479923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3314/" ]
I'm trying to understand what single and multiple dispatch are, exactly. I just read this: <http://en.wikipedia.org/wiki/Multiple_dispatch> And from that definition is seems to me that C# and VB.Net are multiple-dispatch, even though the choice of which overload to call is made at compile-time. Am I correct here,...
OK, I understood the subtle difference where function overloading is different from multiple-dispatch. Basically, the difference is whether which method to call is chosen at run-time or compile-time. Now, I know everybody's said this, but without a clear example this sounds VERY obvious, given that C# is statically ty...
479,962
<p>I have been using the mysql api in PHP, and am now converting to mysqli for the increased security. The example syntax I have seen uses printf, and I would like to know if this is necessary. At the moment I use echo, like so:</p> <pre><code>echo "&lt;h1&gt;".$row['ARTICLE_NAME']."&lt;/h1&gt; &lt;div id='leftlayer' ...
[ { "answer_id": 479996, "author": "Ionuț G. Stan", "author_id": 58808, "author_profile": "https://Stackoverflow.com/users/58808", "pm_score": 0, "selected": false, "text": "<p>You should escape the output when serving XML/HTML pages. For that use <a href=\"http://www.php.net/manual/en/fun...
2009/01/26
[ "https://Stackoverflow.com/questions/479962", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1246613/" ]
I have been using the mysql api in PHP, and am now converting to mysqli for the increased security. The example syntax I have seen uses printf, and I would like to know if this is necessary. At the moment I use echo, like so: ``` echo "<h1>".$row['ARTICLE_NAME']."</h1> <div id='leftlayer' class='leftlayer'> <p><strong...
I'm not sure that binding makes your application more secure when you are getting data out of the database, however it will help when you are writing into the DB as you will have no risk of SQL injection. Whatever approach you take to reading from the DB, you still need to escape the output using `htmlspecialchars()` ...
479,966
<p>I've got a custom object (example only code for ease of understanding) ...</p> <pre><code>public class MyClass { private string name; private int increment; private Guid id; public string Name { get { return name; } set { name = value; } } public int Increment { ...
[ { "answer_id": 479993, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 2, "selected": false, "text": "<p>Reflection would be the way to go - look at <code>Type.GetProperty(string name)</code>. Creating the right comparer m...
2009/01/26
[ "https://Stackoverflow.com/questions/479966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33116/" ]
I've got a custom object (example only code for ease of understanding) ... ``` public class MyClass { private string name; private int increment; private Guid id; public string Name { get { return name; } set { name = value; } } public int Increment { get { ret...
After hitting my head against the problem for a while and hoping on a train home last night I decided that I would try and bash out an answer. Using a combination of Jon's pointers and Frederik's use of the PropertyInfo class and keeping the original idea of switching on the underlying object type, this is what I came ...
479,976
<p>I recently saw this video <a href="http://channel9.msdn.com/pdc2008/TL51/" rel="nofollow noreferrer">http://channel9.msdn.com/pdc2008/TL51/</a> about the managed Contract tools library which certainly looks very interesting. Sadly it seems they won't include this into the language itself which would have been more e...
[ { "answer_id": 495854, "author": "Zen", "author_id": 59825, "author_profile": "https://Stackoverflow.com/users/59825", "pm_score": 2, "selected": false, "text": "<p>I'm trying it, but I think that the library is too young to be used seriously on big projects, at least with the static che...
2009/01/26
[ "https://Stackoverflow.com/questions/479976", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29519/" ]
I recently saw this video <http://channel9.msdn.com/pdc2008/TL51/> about the managed Contract tools library which certainly looks very interesting. Sadly it seems they won't include this into the language itself which would have been more elegant as in Spec#. It would be nice to have is as both options in C#4.0 in fact...
I'm trying it, but I think that the library is too young to be used seriously on big projects, at least with the static checks enabled: compiling is very slow and the specific warning are not very clear to read. Runtime checkings can be used without problems, because they seems to be implemented as Debug.Assert. At l...
479,977
<p>Whenever we run our Java client from within Eclipse to contact a server app using RMI, we get an exception: java.io.StreamCorruptedException: invalid type code: 01</p> <p>This only happens from within Eclipse, nowhere else (IntelliJ, command line, etc.).</p> <p>Does anyone know what's going on?</p>
[ { "answer_id": 479998, "author": "duffymo", "author_id": 37213, "author_profile": "https://Stackoverflow.com/users/37213", "pm_score": 0, "selected": false, "text": "<p>Could it be incompatibility between server and client code? What JVM did you use to compile each one?</p>\n" }, { ...
2009/01/26
[ "https://Stackoverflow.com/questions/479977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55499/" ]
Whenever we run our Java client from within Eclipse to contact a server app using RMI, we get an exception: java.io.StreamCorruptedException: invalid type code: 01 This only happens from within Eclipse, nowhere else (IntelliJ, command line, etc.). Does anyone know what's going on?
You seem to have [encountered this issue before ;)](https://stackoverflow.com/questions/308430) and it is [seen with JBoss too](http://dev.eclipse.org/newslists/news.eclipse.platform.rcp/msg19181.html). It usually is a: * classpath problem (you need to include some j2ee libraries). * Or your stream is used by another...
479,979
<p>I'm possibly just blind, but is there a command line to specify conditional compilation symbols in MSBUILD?</p> <p>I currently have this Line in my buildscript:</p> <pre><code>SET MSBUILD=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe SET CONFIG=Debug %MSBUILD% /p:Configuration=%CONFIG% /p:OutputPath=.....
[ { "answer_id": 480207, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 8, "selected": true, "text": "<p>Have you seen <a href=\"http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/95bf6b1d-9dae-48ba-b56d-08fa5ae265...
2009/01/26
[ "https://Stackoverflow.com/questions/479979", "https://Stackoverflow.com", "https://Stackoverflow.com/users/91/" ]
I'm possibly just blind, but is there a command line to specify conditional compilation symbols in MSBUILD? I currently have this Line in my buildscript: ``` SET MSBUILD=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe SET CONFIG=Debug %MSBUILD% /p:Configuration=%CONFIG% /p:OutputPath=..\..\output source\MyP...
Have you seen [this](http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/95bf6b1d-9dae-48ba-b56d-08fa5ae26563/)? (most info is in the penultimate post) ``` /p:DefineConstants="MYSYMBOL1;MYSYMBOL2" ```
480,007
<p>The title pretty much says it all. When I'm doing some reflection through my classes, will the MemberInfo.GetCustomAttributes() method preserve the order of attributes on a member, or not? The official documentation does not say anything one way or the other.</p> <hr> <p>In case you're wondering why I would need t...
[ { "answer_id": 480017, "author": "Andrew Hare", "author_id": 34211, "author_profile": "https://Stackoverflow.com/users/34211", "pm_score": 1, "selected": false, "text": "<p>Unfortunately no, you cannot guarantee that the order will be the same as the order in which you specified them.</p...
2009/01/26
[ "https://Stackoverflow.com/questions/480007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41360/" ]
The title pretty much says it all. When I'm doing some reflection through my classes, will the MemberInfo.GetCustomAttributes() method preserve the order of attributes on a member, or not? The official documentation does not say anything one way or the other. --- In case you're wondering why I would need this, here's...
I'd put a single extra (optional) value in the MenuItemAttribute constructor, which is "order" or "priority": ``` [MenuItem(0, "Company", "Clients", "Orders")] [MenuItem(1, "Foo", "Bar", "Baz")] ``` I'm not saying it would be pretty, but it would effectively allow you to specify the ordering.
480,020
<p>Lets assume that I'm dealing with a service that involves sending large amounts of data.</p> <p>If I implement this with WCF, will WCF throttle the service based on how much memory each request takes to serve? Or will I be getting continuous out of memory exceptions each time I receive a large number of hits to my ...
[ { "answer_id": 480191, "author": "Andrew Hare", "author_id": 34211, "author_profile": "https://Stackoverflow.com/users/34211", "pm_score": 2, "selected": false, "text": "<p>WCF does have a default payload size limit that will reject messages over a certain number of bytes. This is confi...
2009/01/26
[ "https://Stackoverflow.com/questions/480020", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53771/" ]
Lets assume that I'm dealing with a service that involves sending large amounts of data. If I implement this with WCF, will WCF throttle the service based on how much memory each request takes to serve? Or will I be getting continuous out of memory exceptions each time I receive a large number of hits to my service? ...
While using the binding attributes and readerQuotas like Andrew Hare suggests will allow for essentially an unlimited size for most practical uses, keep in mind that the you will run into other issues such as timeouts if you accept a long running command, no matter how that service is constructed (using WCF or not). ...
480,030
<p>Can anyone set my MySQL syntax straight please? I am trying to set a user variable called "seconds" to equal the output of the query shown below (and it does work by it's self), but I am constantly geting "You have an error in your SQL syntax" errors.</p> <pre><code>SET @seconds=AVG(t2.epoch-t1.epoch) ...
[ { "answer_id": 480054, "author": "Pondidum", "author_id": 1500, "author_profile": "https://Stackoverflow.com/users/1500", "pm_score": 1, "selected": false, "text": "<p>If i remember correctly (and it works on MS SQL Server at work), this should do it:</p>\n\n<pre><code>Select @seconds=AV...
2009/01/26
[ "https://Stackoverflow.com/questions/480030", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Can anyone set my MySQL syntax straight please? I am trying to set a user variable called "seconds" to equal the output of the query shown below (and it does work by it's self), but I am constantly geting "You have an error in your SQL syntax" errors. ``` SET @seconds=AVG(t2.epoch-t1.epoch) FROM tmp_4045_...
If i remember correctly (and it works on MS SQL Server at work), this should do it: ``` Select @seconds=AVG(t2.epoch-t1.epoch) FROM tmp_4045_metrics AS t1, tmp_4045_metrics AS t2 WHERE t1.seq+1 = t2.seq ```
480,033
<p>I have two List's which I want to check for corresponding numbers.</p> <p>for example</p> <pre><code>List&lt;int&gt; a = new List&lt;int&gt;(){1, 2, 3, 4, 5}; List&lt;int&gt; b = new List&lt;int&gt;() {0, 4, 8, 12}; </code></pre> <p>Should give the result 4. Is there an easy way to do this without too much loopin...
[ { "answer_id": 480036, "author": "Otávio Décio", "author_id": 48684, "author_profile": "https://Stackoverflow.com/users/48684", "pm_score": 2, "selected": false, "text": "<p>You can sort the second list and loop through the first one and for each value do a binary search on the second on...
2009/01/26
[ "https://Stackoverflow.com/questions/480033", "https://Stackoverflow.com", "https://Stackoverflow.com/users/57036/" ]
I have two List's which I want to check for corresponding numbers. for example ``` List<int> a = new List<int>(){1, 2, 3, 4, 5}; List<int> b = new List<int>() {0, 4, 8, 12}; ``` Should give the result 4. Is there an easy way to do this without too much looping through the lists? I'm on 3.0 for the project where I ...
You can use the .net 3.5 .Intersect() extension method:- ``` List<int> a = new List<int>() { 1, 2, 3, 4, 5 }; List<int> b = new List<int>() { 0, 4, 8, 12 }; List<int> common = a.Intersect(b).ToList(); ```
480,042
<p>After trying to understand why client code is not rendered in a page (injected by user control) I found this <a href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=105002" rel="nofollow noreferrer">link</a>, it turns out you must have a form tag for it to work (<a href="http://msdn....
[ { "answer_id": 480081, "author": "Mitchel Sellers", "author_id": 13279, "author_profile": "https://Stackoverflow.com/users/13279", "pm_score": 2, "selected": false, "text": "<p>As far as I know this functions the same in current versions, you can test it very simply though.</p>\n\n<p><st...
2009/01/26
[ "https://Stackoverflow.com/questions/480042", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48317/" ]
After trying to understand why client code is not rendered in a page (injected by user control) I found this [link](http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=105002), it turns out you must have a form tag for it to work ([Page.RegisterClientScriptBlock](http://msdn.microsoft.com/en...
Got it! My mistake was not doing it in the **OnPreRender** method (I used the **Render** method). Now all that is needed is - like Mitchel Sellers wrote, set the header to runat server and than add to it's controls: ``` HtmlGenericControl x = new HtmlGenericControl("script"); x.InnerText = GetScriptSection(); ...
480,048
<p>I am using C# and a console app and I am using this script to download files from a remote server. There area a couple of things I want to add. First, when it writes to a file, it doesn't take into consideration a newline. This seems to run a certain amount of bytes and then goes to a newline. I would like it to kee...
[ { "answer_id": 480058, "author": "mqp", "author_id": 55943, "author_profile": "https://Stackoverflow.com/users/55943", "pm_score": 1, "selected": false, "text": "<p>The reason you're getting spurious newlines in the result file is because StreamWriter.WriteLine() puts them there. Try us...
2009/01/26
[ "https://Stackoverflow.com/questions/480048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45429/" ]
I am using C# and a console app and I am using this script to download files from a remote server. There area a couple of things I want to add. First, when it writes to a file, it doesn't take into consideration a newline. This seems to run a certain amount of bytes and then goes to a newline. I would like it to keep t...
Why don't you use `WebClient.DownloadData` or `WebClient.DownloadFile` instead? ``` WebClient client = new WebClient(); client.Credentials = new NetworkCredentials("id", "pass"); client.DownloadFile(remoteUrl, localFile); ``` By the way the correct way to copy a stream to another is not what you did. You shouldn't r...
480,065
<p>i'd like to add a tag to a blogpost with a single sql statement.</p> <p>say my tables would look as follows:</p> <pre><code>tags +-------+-----------+ | tagid | tag | +-------+-----------+ | 1 | news | | 2 | top-story | +-------+-----------+ tag2post +----+--------+-------+ | id | postid | ta...
[ { "answer_id": 480074, "author": "Michael Haren", "author_id": 29, "author_profile": "https://Stackoverflow.com/users/29", "pm_score": 3, "selected": false, "text": "<p>You can't do this as a single insert because inserts are atomic--that is, the ID isn't determined until the statement c...
2009/01/26
[ "https://Stackoverflow.com/questions/480065", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1532/" ]
i'd like to add a tag to a blogpost with a single sql statement. say my tables would look as follows: ``` tags +-------+-----------+ | tagid | tag | +-------+-----------+ | 1 | news | | 2 | top-story | +-------+-----------+ tag2post +----+--------+-------+ | id | postid | tagid | +----+----...
You can't do this as a single insert because inserts are atomic--that is, the ID isn't determined until the statement completes. Wrap both statements in a transaction and you will get your ID, and atomicity.
480,098
<p>I have a project with an XmlDataProvider bound to a WPF DataGrid control. I have the bindings on the DataGrid set up as follows:</p> <pre><code>&lt;dg:DataGrid ItemsSource="{Binding Source={StaticResource XmlData}, XPath=Root/People/Person}" AutoGenerateColumns="False"&gt; &lt;dg:DataGrid.Columns&g...
[ { "answer_id": 499748, "author": "user61073", "author_id": 61073, "author_profile": "https://Stackoverflow.com/users/61073", "pm_score": 0, "selected": false, "text": "<p>Have you tried setting CanUserAddRows=\"True\" on the DataGrid?</p>\n" }, { "answer_id": 1044904, "author...
2009/01/26
[ "https://Stackoverflow.com/questions/480098", "https://Stackoverflow.com", "https://Stackoverflow.com/users/59027/" ]
I have a project with an XmlDataProvider bound to a WPF DataGrid control. I have the bindings on the DataGrid set up as follows: ``` <dg:DataGrid ItemsSource="{Binding Source={StaticResource XmlData}, XPath=Root/People/Person}" AutoGenerateColumns="False"> <dg:DataGrid.Columns> <dg:DataGridTex...
Make sure that you set: `CanUserAddRows="True"` and that the default constructor of a bound class is available.
480,099
<p>Java has a regex function called "LookingAt()" which will allow partial matches against patterns, my question is:</p> <p>Does .net have an equivalent of "LookingAt()"?</p> <p>I may or may not use it for KeyPress validation but I just would like to know for future reference.</p> <p>Thanks in advance</p> <p>Jon</p...
[ { "answer_id": 480124, "author": "Thomas Tempelmann", "author_id": 43615, "author_profile": "https://Stackoverflow.com/users/43615", "pm_score": 1, "selected": false, "text": "<p>This may not be relevant to your case, but in general this is not a good idea because some languages often ne...
2009/01/26
[ "https://Stackoverflow.com/questions/480099", "https://Stackoverflow.com", "https://Stackoverflow.com/users/52349/" ]
Java has a regex function called "LookingAt()" which will allow partial matches against patterns, my question is: Does .net have an equivalent of "LookingAt()"? I may or may not use it for KeyPress validation but I just would like to know for future reference. Thanks in advance Jon
I don't think `lookingAt()` is the correct model for what you're trying to do. All it does is anchor the match to the beginning of the input, as if you had used the `^` start anchor at the beginning of your regex and called `find()`, and that would be trivial to emulate in .NET. I think what you're trying to do is pr...
480,108
<p>I'm retro-fitting an older vb.net application to bring it into compliance with LUA principles in Vista. Up until now, the application has used a hodgepodge of logging mechanisms, but the core one involved writing a log to c:\temp\ if the folder existed. I want to replace this current logging with a more standard l...
[ { "answer_id": 480115, "author": "Greg D", "author_id": 6932, "author_profile": "https://Stackoverflow.com/users/6932", "pm_score": 0, "selected": false, "text": "<p>One possibility might be to skip the <code>My.Application.Log</code> altogether and go straight to the <code>System.Diagno...
2009/01/26
[ "https://Stackoverflow.com/questions/480108", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6932/" ]
I'm retro-fitting an older vb.net application to bring it into compliance with LUA principles in Vista. Up until now, the application has used a hodgepodge of logging mechanisms, but the core one involved writing a log to c:\temp\ if the folder existed. I want to replace this current logging with a more standard loggin...
I believe this is configurable. It may be configured in the machine.config file, or you can override that in your application config file - which you will want to do so you can control it and create a link to it. You will want to add a `FileLogTraceListener` to the app.config. It goes in the `system.diagnostics\share...
480,109
<p>I have written a Ruby application which parses lots of data from sources in different formats html, xml and csv files. How can I find out what areas of the code are taking the longest? </p> <p>Is there any good resources on how to improve the performance of Ruby applications? Or do you have any performance coding s...
[ { "answer_id": 480130, "author": "Rafael Mueller", "author_id": 50227, "author_profile": "https://Stackoverflow.com/users/50227", "pm_score": 2, "selected": false, "text": "<p>The answer to the string concatenation is here: <a href=\"https://web.archive.org/web/20090122123342/http://blog...
2009/01/26
[ "https://Stackoverflow.com/questions/480109", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6009/" ]
I have written a Ruby application which parses lots of data from sources in different formats html, xml and csv files. How can I find out what areas of the code are taking the longest? Is there any good resources on how to improve the performance of Ruby applications? Or do you have any performance coding standards y...
Well, there are certain well known practices like string concatenation is way slower than "#{value}" but in order to find out where you script is consuming most of its time or more time than required, you need to do profiling. There is a ruby gem called ruby-prof. The profiler can bring to your notice even those perfor...
480,162
<p>I'm trying to learn TDD by applying it to a simple project of mine. Some details (and an earlier question) are here:</p> <p><a href="https://stackoverflow.com/questions/473679/tdd-help-with-writing-testable-class">TDD: Help with writing Testable Class</a></p> <p>The specifics are I have a PurchaseOrderCollection ...
[ { "answer_id": 480192, "author": "BFree", "author_id": 15861, "author_profile": "https://Stackoverflow.com/users/15861", "pm_score": 0, "selected": false, "text": "<p>I'm no expert in unit testing, but here's what I've done in the past. If you have a PurchaseOder class that can be valid/...
2009/01/26
[ "https://Stackoverflow.com/questions/480162", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36602/" ]
I'm trying to learn TDD by applying it to a simple project of mine. Some details (and an earlier question) are here: [TDD: Help with writing Testable Class](https://stackoverflow.com/questions/473679/tdd-help-with-writing-testable-class) The specifics are I have a PurchaseOrderCollection class that has a private List...
You are on the right track with either creating a stub or a mock. I prefer using a Mocking framework. How it would work using a mocking framework is that you would want to mock your PurchaseOrder class therefore abstracting away it's implementation. Then setup expectations that IsValid is called and when it is called ...
480,178
<p>I know of <code>@staticmethod</code>, <code>@classmethod</code>, and <code>@property</code>, but only through scattered documentation. What are all the function decorators that are built into Python? Is that in the docs? Is there an up-to-date list maintained somewhere?</p>
[ { "answer_id": 480266, "author": "Abgan", "author_id": 46308, "author_profile": "https://Stackoverflow.com/users/46308", "pm_score": 6, "selected": true, "text": "<p>I don't think so. Decorators don't differ from ordinary functions, you only call them in a fancier way. </p>\n\n<p>For fi...
2009/01/26
[ "https://Stackoverflow.com/questions/480178", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49018/" ]
I know of `@staticmethod`, `@classmethod`, and `@property`, but only through scattered documentation. What are all the function decorators that are built into Python? Is that in the docs? Is there an up-to-date list maintained somewhere?
I don't think so. Decorators don't differ from ordinary functions, you only call them in a fancier way. For finding all of them try searching [Built-in functions](http://docs.python.org/library/functions.html) list, because as you can see in [Python glossary](http://docs.python.org/3.0/glossary.html) the decorator sy...
480,195
<p>i have a repeater than creates a table:</p> <pre><code>&lt;itemtemplate&gt; &lt;tr id="theTableRow" runat="server"&gt; &lt;td&gt; &lt;asp:LinkButton runat="server" OnClientClick="todo" Text="Do Something" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/itemtemplate&gt; </code><...
[ { "answer_id": 480259, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 1, "selected": true, "text": "<p>You can use the <code>OnItemDataBound</code> event to alter each element in your code. Since you're particular abou...
2009/01/26
[ "https://Stackoverflow.com/questions/480195", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12597/" ]
i have a repeater than creates a table: ``` <itemtemplate> <tr id="theTableRow" runat="server"> <td> <asp:LinkButton runat="server" OnClientClick="todo" Text="Do Something" /> </td> </tr> </itemtemplate> ``` **Note:** the `OnClientClick="todo"` line. In the final ...
You can use the `OnItemDataBound` event to alter each element in your code. Since you're particular about the HTML I might also recommend using hybrid controls rather than asp controls. For example: ``` <itemtemplate> <tr id="theTableRow" runat="server"> <td> <a runat="server" onclick="t...
480,211
<p>I have a template class for thread-safe vector:</p> <pre><code>template &lt;class T&gt; class SharedVector { std::vector&lt;T&gt; vect; CRITICAL_SECTION cs; SharedVector(const SharedVector&lt;T&gt;&amp; rhs) {} public: typedef typename std::vector&lt;T&gt;::size_type SizeType; SharedVector(); ...
[ { "answer_id": 480232, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 2, "selected": true, "text": "<p>You have to provide a type argument for the SharedVector template:</p>\n\n<pre><code>SharedVector&lt;Conn...
2009/01/26
[ "https://Stackoverflow.com/questions/480211", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28298/" ]
I have a template class for thread-safe vector: ``` template <class T> class SharedVector { std::vector<T> vect; CRITICAL_SECTION cs; SharedVector(const SharedVector<T>& rhs) {} public: typedef typename std::vector<T>::size_type SizeType; SharedVector(); void PushBack(const T& value); void ...
You have to provide a type argument for the SharedVector template: ``` SharedVector<Connection*>::SizeType size(); .... SharedVector<Connection*>::SizeType TCPClientManager::size() { return connections.size(); } ``` Because that `Connection*` type is not a template parameter in TCPClientManager, but an explicit...
480,214
<p>How do I remove duplicates from a list, while preserving order? Using a set to remove duplicates destroys the original order. Is there a built-in or a Pythonic idiom?</p>
[ { "answer_id": 480227, "author": "Markus Jarderot", "author_id": 22364, "author_profile": "https://Stackoverflow.com/users/22364", "pm_score": 11, "selected": true, "text": "<p>Here you have some alternatives: <a href=\"http://www.peterbe.com/plog/uniqifiers-benchmark\" rel=\"noreferrer\...
2009/01/26
[ "https://Stackoverflow.com/questions/480214", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58994/" ]
How do I remove duplicates from a list, while preserving order? Using a set to remove duplicates destroys the original order. Is there a built-in or a Pythonic idiom?
Here you have some alternatives: <http://www.peterbe.com/plog/uniqifiers-benchmark> Fastest one: ``` def f7(seq): seen = set() seen_add = seen.add return [x for x in seq if not (x in seen or seen_add(x))] ``` Why assign `seen.add` to `seen_add` instead of just calling `seen.add`? Python is a dynamic lan...
480,248
<p>So I was just working with function pointers and I remembered that you could do this:</p> <pre><code>void Foo() { } int main() { void(&amp; func)() = Foo; func(); //::Foo(); } </code></pre> <p>The obvious advantage being that references reference valid objects (unless they're misused), or functions in th...
[ { "answer_id": 480253, "author": "Robert Gould", "author_id": 15124, "author_profile": "https://Stackoverflow.com/users/15124", "pm_score": 4, "selected": false, "text": "<p>I've used them before to add customization to classes by passing them to the constructor in a way like the strateg...
2009/01/26
[ "https://Stackoverflow.com/questions/480248", "https://Stackoverflow.com", "https://Stackoverflow.com/users/59042/" ]
So I was just working with function pointers and I remembered that you could do this: ``` void Foo() { } int main() { void(& func)() = Foo; func(); //::Foo(); } ``` The obvious advantage being that references reference valid objects (unless they're misused), or functions in this case. The obvious disadvan...
I've used them before to add customization to classes by passing them to the constructor in a way like the strategy pattern
480,251
<p>I have a flex line chart. Instead of the default behavior of having to hover over parts of the line to see the data points, is there a way to change the rendering of each point and have them always displayed? (almost like a connect the dots type view).</p>
[ { "answer_id": 480366, "author": "James Hay", "author_id": 47339, "author_profile": "https://Stackoverflow.com/users/47339", "pm_score": 2, "selected": false, "text": "<p>you will need to set the 'showAllDataTips' property of the LineChart to true e.g.</p>\n\n<pre><code> &lt;mx:LineChart...
2009/01/26
[ "https://Stackoverflow.com/questions/480251", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a flex line chart. Instead of the default behavior of having to hover over parts of the line to see the data points, is there a way to change the rendering of each point and have them always displayed? (almost like a connect the dots type view).
Try this ``` <mx:LineChart> <mx:series> <mx:LineSeries dataProvider="{arr1}"> <mx:itemRenderer> <mx:Component> <mx:CrossItemRenderer/> </mx:Component> </mx:itemRenderer> </mx:LineSeries> </mx:series> </mx:LineChart> ``...
480,258
<p>I have a WiX project that installs a few EXE files. One is the 'Main' executable and the others are supporting programs to help diagnose problems.</p> <p>The main executable is optional, and the support programs will run on their own. Often, the end user will install a third-party program instead of my main executa...
[ { "answer_id": 480466, "author": "Rob Mensching", "author_id": 23852, "author_profile": "https://Stackoverflow.com/users/23852", "pm_score": 4, "selected": true, "text": "<p>The SetProperty element can be used to change the value of a Property before or after an action. To set a value ba...
2009/01/26
[ "https://Stackoverflow.com/questions/480258", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30/" ]
I have a WiX project that installs a few EXE files. One is the 'Main' executable and the others are supporting programs to help diagnose problems. The main executable is optional, and the support programs will run on their own. Often, the end user will install a third-party program instead of my main executable. At t...
The SetProperty element can be used to change the value of a Property before or after an action. To set a value based on the install state of an executable I would use a combination of Component states documented in the [Conditional Statement Syntax in MSI SDK](http://msdn.microsoft.com/en-us/library/aa368012.aspx). Yo...
480,261
<p>In Swing, is there a way to define mouseover text (or tool tip text) for each item in a JComboBox? </p>
[ { "answer_id": 480287, "author": "Paul Tomblin", "author_id": 3333, "author_profile": "https://Stackoverflow.com/users/3333", "pm_score": 0, "selected": false, "text": "<p>I've never tried it, but you should be able to define a ListCellRenderer, and have it return a JLabel or whatever wi...
2009/01/26
[ "https://Stackoverflow.com/questions/480261", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2197/" ]
In Swing, is there a way to define mouseover text (or tool tip text) for each item in a JComboBox?
There is a much better way to do this than the `ToolTipComboBox` answer already given. First, make a custom `ListCellRenderer`: ``` package com.example; import javax.swing.*; import java.awt.*; import java.util.List; public class ComboboxToolTipRenderer extends DefaultListCellRenderer { List<String> tooltips; ...
480,262
<p>When you load an UserControl in the WinForm designer, VisualStudio executes the InitializeComponent() method of the control, but not its constructor. This really makes a difference because it's quite common to have some code in the constructor which cannot run at design time.</p> <p>Unfortunately, when you add an U...
[ { "answer_id": 480293, "author": "Brann", "author_id": 47341, "author_profile": "https://Stackoverflow.com/users/47341", "pm_score": 0, "selected": false, "text": "<p>The workaround I'm using is to put my runtime initialization code in an InitializeRuntime() method, which I recursively c...
2009/01/26
[ "https://Stackoverflow.com/questions/480262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47341/" ]
When you load an UserControl in the WinForm designer, VisualStudio executes the InitializeComponent() method of the control, but not its constructor. This really makes a difference because it's quite common to have some code in the constructor which cannot run at design time. Unfortunately, when you add an UserControl...
wrap the runtime only parts with: ``` If Not me.DesignMode Then 'Runtime only here End If ```
480,263
<p>What I am trying to achieve is to merge three strings. Two are provided as strings; firstname and lastname, while the third is a simple comma/space separator. Given the following lines of code:</p> <pre><code>//Working code var sep = ", "; var fullName = myNewBO[0].LastName + sep + myNewBO[0].FirstName; //Erronous...
[ { "answer_id": 480276, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 3, "selected": false, "text": "<pre><code>string.Join(sep, new string[] {myNewBO[0].LastName, myNewBO[0].FirstName});\n</code></pre>\n" }, { ...
2009/01/26
[ "https://Stackoverflow.com/questions/480263", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45704/" ]
What I am trying to achieve is to merge three strings. Two are provided as strings; firstname and lastname, while the third is a simple comma/space separator. Given the following lines of code: ``` //Working code var sep = ", "; var fullName = myNewBO[0].LastName + sep + myNewBO[0].FirstName; //Erronous code var full...
I suspect you have something else happening in your code, and you're mistaking where the error is occurring. I can't for the life of me see why those two would behave differently at all. I suggest you log the value after the assignment for both cases - I'm sure you'll find they're the same.
480,274
<p>Why would an event handler work one day, and then stop working the next day without <em>any</em> code changes?</p> <p>I have run into the problem many times, but always have to play around and somehow the event handler magically works again. Below is an example where this happened to me again today. Do you know a...
[ { "answer_id": 480282, "author": "Andrew Hare", "author_id": 34211, "author_profile": "https://Stackoverflow.com/users/34211", "pm_score": 1, "selected": false, "text": "<p>I know you said that no code had changed but you ought to check to make sure that <code>AutoEventWireup</code> is s...
2009/01/26
[ "https://Stackoverflow.com/questions/480274", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49275/" ]
Why would an event handler work one day, and then stop working the next day without *any* code changes? I have run into the problem many times, but always have to play around and somehow the event handler magically works again. Below is an example where this happened to me again today. Do you know a quick way to fix t...
Kieran was right with his comment... Something actually had changed! Big wow there... The TFS Check-in alert ended up in my Junk E-mail folder and stupid me didn't do a comparison on the history of the file. The EnableViewState was set to false in the codebehind by a coworker. As a side note: he did this because it d...
480,288
<p>Sorry for the slightly noobish question, as I am writing my first rails app.</p> <p>I get the idea of the layout view, but if you are using them, is there any way to include a view specific js or css file? For example, I have <code>layouts/products.html.erb</code>, and for <code>products/edit.html.erb</code> I want...
[ { "answer_id": 480385, "author": "Otto", "author_id": 9594, "author_profile": "https://Stackoverflow.com/users/9594", "pm_score": -1, "selected": false, "text": "<p>You can't if your <code>&lt;/head&gt;</code> tag is in your layout.</p>\n\n<p>You may want a different layout for that cont...
2009/01/26
[ "https://Stackoverflow.com/questions/480288", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10771/" ]
Sorry for the slightly noobish question, as I am writing my first rails app. I get the idea of the layout view, but if you are using them, is there any way to include a view specific js or css file? For example, I have `layouts/products.html.erb`, and for `products/edit.html.erb` I want `products_edit.css`, but I don'...
If you have a generic edit.css file, I would suggest an if in your layout ``` <%= stylesheet_link_tag 'edit' if params[:action] == 'edit' %> ``` Otherwise you can use [`content_for`](https://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#method-i-content_for) with a `yield` to add additional tags ...
480,294
<p>Strange one. We have a multi-threaded app which pulls messages off a MSMQ Queue and then subsequently performs actions based on the messages. All of this is done using DTC.</p> <p>Sometimes, for some reason I can't describe, we get message read errors when pulling Messages off the queue.</p> <p>The code that is be...
[ { "answer_id": 835029, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>I have seen it as well, and have tried initializing it with the properties I'm accessing explicitly set, and not setting th...
2009/01/26
[ "https://Stackoverflow.com/questions/480294", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1088682/" ]
Strange one. We have a multi-threaded app which pulls messages off a MSMQ Queue and then subsequently performs actions based on the messages. All of this is done using DTC. Sometimes, for some reason I can't describe, we get message read errors when pulling Messages off the queue. The code that is being used in the a...
As alluded to earlier, you could explicitly set the boolean values on the `System.Messaging.MessagePropertyFilter` object that is accessible on your `messageQueue` object via the `MessageReadPropertyFilter` property. If you want all data to be extracted from a message when received or peaked, use: ```cs this.messageQ...
480,300
<p>while trying to figure out how to tag a blog post with a single sql statement <a href="https://stackoverflow.com/questions/480065/nested-insert-in-mysql-for-tagging">here</a>, the following thought crossed my mind: using a relation table tag2post that references tags by id as follows just isn't necessary:</p> <pre>...
[ { "answer_id": 480302, "author": "Seldaek", "author_id": 6512, "author_profile": "https://Stackoverflow.com/users/6512", "pm_score": 2, "selected": false, "text": "<p>This sounds fine to me, using an ID to reference something that you delegated into another table makes sense when you hav...
2009/01/26
[ "https://Stackoverflow.com/questions/480300", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1532/" ]
while trying to figure out how to tag a blog post with a single sql statement [here](https://stackoverflow.com/questions/480065/nested-insert-in-mysql-for-tagging), the following thought crossed my mind: using a relation table tag2post that references tags by id as follows just isn't necessary: ``` tags +-------+-----...
It works, but it is not normalized, because you have redundancy in the tags. You also lose the ability to use the "same" tags to tag things besides posts. For small N, optimization doesn't matter, so I have no problems if you run with it. As a practical matter, your indexes will be larger (assuming you are going to in...
480,309
<p>Is there a way to reserve or skip or increment value of identity column? </p> <p>I Have two tables joined in one-to-one relation ship. First one has IDENTITY PK column, and second one int PK (not IDENTITY). I used to insert in first, get ID and insert in second. And it works ok.</p> <p>Now I need to insert values ...
[ { "answer_id": 480327, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 2, "selected": false, "text": "<p>Use a <a href=\"http://technet.microsoft.com/en-us/library/ms176057.aspx\" rel=\"nofollow noreferrer\"><code>DBCC CHECKIDEN...
2009/01/26
[ "https://Stackoverflow.com/questions/480309", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39233/" ]
Is there a way to reserve or skip or increment value of identity column? I Have two tables joined in one-to-one relation ship. First one has IDENTITY PK column, and second one int PK (not IDENTITY). I used to insert in first, get ID and insert in second. And it works ok. Now I need to insert values in second table w...
This situation will make your overall data structure very hard to understand. If there is not a relationship between the values, then break the relationship. There are ways to get around this to do what you are looking for, but typically it is in a distributed environment and not done because of what appears to be a ...
480,324
<p>I'm trying to run this JPQL query:</p> <pre><code>SELECT DISTINCT i FROM Table i JOIN i.other o </code></pre> <p>which promptly fails with:</p> <blockquote> <p>"Internal Exception: java.sql.SQLException: Columns of type 'BLOB' may not be used in CREATE INDEX, ORDER BY, GROUP BY, UNION, INTERSECT, EXCEPT or DIST...
[ { "answer_id": 480345, "author": "DanSingerman", "author_id": 43965, "author_profile": "https://Stackoverflow.com/users/43965", "pm_score": 2, "selected": false, "text": "<p>You could store a hash or checksum of the blob object in another column, and use your distinct operator on that.</...
2009/01/26
[ "https://Stackoverflow.com/questions/480324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48234/" ]
I'm trying to run this JPQL query: ``` SELECT DISTINCT i FROM Table i JOIN i.other o ``` which promptly fails with: > > "Internal Exception: java.sql.SQLException: Columns of type 'BLOB' may not be used in CREATE INDEX, ORDER BY, GROUP BY, UNION, INTERSECT, EXCEPT or DISTINCT statements because comparisons are not...
You could store a hash or checksum of the blob object in another column, and use your distinct operator on that. Example: ``` SELECT i from Table WHERE id IN ( SELECT id FROM ( SELECT MIN(id) AS id, hash_of_i FROM Table GROUP BY hash_of_i ) t ) ``` I'm sure yo...
480,358
<p>I'm currently using a homegrown method to run a process as a different user in Vista, and I can't escape the feeling that's it hack-ish and less than ideal (in addition to the fact that it craps out UAC, crashing my app with a security exception, and forcing me to disable UAC altogether). My process consists of two ...
[ { "answer_id": 480741, "author": "Sunny Milenov", "author_id": 8220, "author_profile": "https://Stackoverflow.com/users/8220", "pm_score": 1, "selected": false, "text": "<p>You may try to run runas from your app. Some examples and options <a href=\"http://social.technet.microsoft.com/For...
2009/01/26
[ "https://Stackoverflow.com/questions/480358", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8114/" ]
I'm currently using a homegrown method to run a process as a different user in Vista, and I can't escape the feeling that's it hack-ish and less than ideal (in addition to the fact that it craps out UAC, crashing my app with a security exception, and forcing me to disable UAC altogether). My process consists of two pro...
Chances are that you have to create your own "shell" function using the Win32 API. Using the CreateProcessWithLogonW API you can create new processes under different credentials and optionally load user profile information. In the code snippet below if you replace * username - with your username * domain - with your...
480,360
<p>I'm working on implementing sprited buttons in Stackoverflow's beloved WMD markdown editor and I've run into an odd bug. On all versions of IE, the selected text is lost upon button clicks, so, say, highlighting a block of text and clicking the code button acts like you placed the cursor at the end of the selection...
[ { "answer_id": 480459, "author": "Christoph", "author_id": 48015, "author_profile": "https://Stackoverflow.com/users/48015", "pm_score": 0, "selected": false, "text": "<p>You have to <code>blur()</code> a button before IE can select anything else on a page.</p>\n\n<p>Can you provide a mi...
2009/01/26
[ "https://Stackoverflow.com/questions/480360", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3161/" ]
I'm working on implementing sprited buttons in Stackoverflow's beloved WMD markdown editor and I've run into an odd bug. On all versions of IE, the selected text is lost upon button clicks, so, say, highlighting a block of text and clicking the code button acts like you placed the cursor at the end of the selection and...
I know what the answer to my own question is. The sprited buttons are implemented using an HTML list and CSS, where all the list items have a background image. The background image is moved around using CSS to show different buttons and states (like mouseover highlights). Standard CSS button spriting stuff. This work...
480,363
<p>I tend to make the length of character strings some power of two (16, 32, 64). Is there any optimaztion benefit in doing this for objects of type string such as a string variable, a collection of strings, or a column in a database of type string? This is in a .net/sql server environment.</p>
[ { "answer_id": 480379, "author": "AnthonyWJones", "author_id": 17516, "author_profile": "https://Stackoverflow.com/users/17516", "pm_score": 1, "selected": false, "text": "<p>No. What would you be doing with the chunk of string you aren't using because its just padding. The cost of thi...
2009/01/26
[ "https://Stackoverflow.com/questions/480363", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7899/" ]
I tend to make the length of character strings some power of two (16, 32, 64). Is there any optimaztion benefit in doing this for objects of type string such as a string variable, a collection of strings, or a column in a database of type string? This is in a .net/sql server environment.
Since .NET strings aren't null-terminated, you'd have to be very clever to actually consume the perfect number of characters in every single string. ``` String message = "hello world!!!!!"; // Exactly 16 chars ``` Besides, the power-of-two sizing of strings is only important when your implementation uses "malloc" to...
480,389
<p>The .Net C# offers two (well four) constructors:</p> <pre><code>Regex(String) Regex(String,RegexOptions) </code></pre> <p>The first constructs a regular expression with default options, while the second gives you somewhat more control. Take a peak under the hood with Reflector shows that the first constructor cal...
[ { "answer_id": 480440, "author": "cheng81", "author_id": 46754, "author_profile": "https://Stackoverflow.com/users/46754", "pm_score": 3, "selected": true, "text": "<p>Some J2ME javadocs' can be found at <a href=\"http://www.gotapi.com\" rel=\"nofollow noreferrer\">gotapi</a>, and you ca...
2009/01/26
[ "https://Stackoverflow.com/questions/480389", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2892/" ]
The .Net C# offers two (well four) constructors: ``` Regex(String) Regex(String,RegexOptions) ``` The first constructs a regular expression with default options, while the second gives you somewhat more control. Take a peak under the hood with Reflector shows that the first constructor calls the second with a Regex...
Some J2ME javadocs' can be found at [gotapi](http://www.gotapi.com), and you can always download the jsr documentation at the [java community process](http://jcp.org/en/jsr/overview) site. Another resource I found is the [j2me page on mobilezoo](http://mobilezoo.biz/j2me.php) (ie. the api you are looking for, the [jsr...
480,392
<p>The Script Resource and the Web Resource files are generating intermittent errors in my application. I have been trying to chase the cause of the problem but to no avail. I notice that the “d” parameter that is passed is some how corrupted and I can’t for the life of me figure out what’s causing this parameter to be...
[ { "answer_id": 480476, "author": "Matt Briggs", "author_id": 10771, "author_profile": "https://Stackoverflow.com/users/10771", "pm_score": 1, "selected": false, "text": "<p>Ok, welcome to the living hell that is MS ajax.</p>\n\n<p>this bit is interesting </p>\n\n<blockquote>\n <p>Reques...
2009/01/26
[ "https://Stackoverflow.com/questions/480392", "https://Stackoverflow.com", "https://Stackoverflow.com/users/59046/" ]
The Script Resource and the Web Resource files are generating intermittent errors in my application. I have been trying to chase the cause of the problem but to no avail. I notice that the “d” parameter that is passed is some how corrupted and I can’t for the life of me figure out what’s causing this parameter to be co...
I have been analyzing the data that I have been collecting and I have drawn a few conclusions. I noticed that a large majority of the errors that I have been getting are coming from windows Vista computers running IE 8 or Firefox 3. There where also a few cases where it was Vista and IE 7. This could explain why the er...
480,397
<p>I need an algorithm that can map the runs in a permutation to a single number, but also reduce the subsequent numbers. </p> <p>So a run is a sequential set of numbers in a permutation that is sorted and in-order. In the list, 1;2;3;5;6;4 there are two runs, 1;2;3 and 5;6. I want to replace these with a single numbe...
[ { "answer_id": 480890, "author": "Jorge Córdoba", "author_id": 2695, "author_profile": "https://Stackoverflow.com/users/2695", "pm_score": 0, "selected": false, "text": "<p><strong>Edited for clarificaton</strong></p>\n\n<p>step 1: Run the algorithm but instead of producing only one hash...
2009/01/26
[ "https://Stackoverflow.com/questions/480397", "https://Stackoverflow.com", "https://Stackoverflow.com/users/157/" ]
I need an algorithm that can map the runs in a permutation to a single number, but also reduce the subsequent numbers. So a run is a sequential set of numbers in a permutation that is sorted and in-order. In the list, 1;2;3;5;6;4 there are two runs, 1;2;3 and 5;6. I want to replace these with a single number, a minim...
Notation: * counting starts at 1 * `l.i` is element `i` of list `l` * `l+m` is the concatenation of lists `l` and `m` * a run is a maximal sublist that is an list `[n,n+1,n+2,...,m]` for some `n` and `m` with `n <= m` So we are given a permutation `p` of the list `[1,2,...,N]`. We divide `p` up into runs `r_1,r_2,......
480,399
<p>Is there a way to convert a <code>List(of Object)</code> to a <code>List(of String)</code> in c# or vb.net without iterating through all the items? (Behind the scenes iteration is fine – I just want concise code)</p> <p><strong>Update:</strong> The best way is probably just to do a new select</p> <pre><code>myList...
[ { "answer_id": 480408, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 8, "selected": true, "text": "<p>Not possible without iterating to build a new list. You can wrap the list in a container that implements IList.</p>\n\n<p>Yo...
2009/01/26
[ "https://Stackoverflow.com/questions/480399", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7793/" ]
Is there a way to convert a `List(of Object)` to a `List(of String)` in c# or vb.net without iterating through all the items? (Behind the scenes iteration is fine – I just want concise code) **Update:** The best way is probably just to do a new select ``` myList.Select(function(i) i.ToString()).ToList(); ``` or ``...
Not possible without iterating to build a new list. You can wrap the list in a container that implements IList. You can use LINQ to get a lazy evaluated version of `IEnumerable<string>` from an object list like this: ``` var stringList = myList.OfType<string>(); ```
480,405
<p>Consider the following problem. You have a bit-string that represents the current scheduled slave in one-hot encoding. For example, "00000100" (with the leftmost bit being #7 and rightmost #0) means that slave #2 is scheduled. </p> <p>Now, I want to pick the next scheduled slave in a round-robin scheduling scheme, ...
[ { "answer_id": 480462, "author": "Doug Currie", "author_id": 33252, "author_profile": "https://Stackoverflow.com/users/33252", "pm_score": 2, "selected": false, "text": "<p>Assuming twos complement representation, call your two words <code>mask</code> and <code>current</code>, in C:</p>\...
2009/01/26
[ "https://Stackoverflow.com/questions/480405", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8206/" ]
Consider the following problem. You have a bit-string that represents the current scheduled slave in one-hot encoding. For example, "00000100" (with the leftmost bit being #7 and rightmost #0) means that slave #2 is scheduled. Now, I want to pick the next scheduled slave in a round-robin scheduling scheme, with a twi...
I've found the following Verilog code for implementing the task in the Altera advanced synthesis cookbook. ``` // 'base' is a one hot signal indicating the first request // that should be considered for a grant. Followed by higher // indexed requests, then wrapping around. // module arbiter ( req, grant, base )...
480,424
<p>I'm currently in charge of a process that seems to be very intimate with the database. My program/script/framework's goal is to make uniformity out of disparate data sources. Using a form of dependency injection, my process at a very high level works fine. The implementation of each data source type is hidden from t...
[ { "answer_id": 480547, "author": "Dave Swersky", "author_id": 34796, "author_profile": "https://Stackoverflow.com/users/34796", "pm_score": 0, "selected": false, "text": "<p>I think you're describing dynamic SQL- building the request programmatically at runtime. This is a common feature...
2009/01/26
[ "https://Stackoverflow.com/questions/480424", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40725/" ]
I'm currently in charge of a process that seems to be very intimate with the database. My program/script/framework's goal is to make uniformity out of disparate data sources. Using a form of dependency injection, my process at a very high level works fine. The implementation of each data source type is hidden from the ...
You want to look at **[Fey](http://p3rl.org/Fey::SQL)**. I started using it a few months ago on the job, and while the implementation still has rough corners due to young age, the idea behind it is solid. F.ex., take a query lightly adapted from the manual: ``` my $user = $schema->table( 'user' ); my $q = Fey::SQL ...
480,425
<p>We have a multilingual site that utilizes asp.net 2.0 cultures. The current culture is set through the url rewritten as a query string. (~/es/blah.aspx is the spanish version of ~/blah.aspx - rewritten as ~/blah.aspx?lang=es)</p> <p>The code that tests the culture is as follows:</p> <pre><code> System.Globali...
[ { "answer_id": 480434, "author": "Michael Haren", "author_id": 29, "author_profile": "https://Stackoverflow.com/users/29", "pm_score": 2, "selected": false, "text": "<p><a href=\"http://stribny.name/netbits/validating-culture-name-using-linq\" rel=\"nofollow noreferrer\">This site</a> ha...
2009/01/26
[ "https://Stackoverflow.com/questions/480425", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
We have a multilingual site that utilizes asp.net 2.0 cultures. The current culture is set through the url rewritten as a query string. (~/es/blah.aspx is the spanish version of ~/blah.aspx - rewritten as ~/blah.aspx?lang=es) The code that tests the culture is as follows: ``` System.Globalization.CultureInfo ci; ...
I thought I'd have a quick go at measuring this so knocked up a quick console application. It basically uses all 3 methods (constructor, LINQ and foreach) to get a CultureInfo from a string 10000 times in a loop. I removed the stopwatch and console output for brevity. ``` string culture = "en-GB"; CultureInfo[] cult...
480,426
<p>I have two tables (in postgres) - ads and logs. After every insert into logs table, depending on the action it should increment the count of a column in the ads table. </p> <p>I have tried to write a function which the trigger will call, but it throws a error while trying to create the function. I am new to postgre...
[ { "answer_id": 480436, "author": "Tina Orooji", "author_id": 58404, "author_profile": "https://Stackoverflow.com/users/58404", "pm_score": 0, "selected": false, "text": "<p>I'm not hugely familiar with postgresql, but based on what I do know... shouldn't it be \"$$ case\" instead of \"$...
2009/01/26
[ "https://Stackoverflow.com/questions/480426", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1448/" ]
I have two tables (in postgres) - ads and logs. After every insert into logs table, depending on the action it should increment the count of a column in the ads table. I have tried to write a function which the trigger will call, but it throws a error while trying to create the function. I am new to postgresql trigge...
First off, your UPDATE call should be: ``` UPDATE ads SET views = views + 1, updated = NOW() WHERE id = ad_id; ``` According to [the documentation](http://www.postgresql.org/docs/8.1/static/sql-createfunction.html), something like this should do it: ``` CREATE FUNCTION update_ad_count (action CHARACTER(4), ad_id IN...
480,430
<p>I have one console app that is doing some lengthy syncing to an ftp server.<br> Another console app prepares a local filesystem with some needed updated files.<br> Then the second one will wait for the first one to finish before swapping a final directory name so it becomes visible on the web.</p> <p>I searched for...
[ { "answer_id": 480451, "author": "Matt Brunell", "author_id": 24970, "author_profile": "https://Stackoverflow.com/users/24970", "pm_score": 3, "selected": false, "text": "<p>Other popular options for IPC include:</p>\n\n<ul>\n<li>Named Pipes </li>\n<li>Remoting (.NET) </li>\n<li>WCF</li>...
2009/01/26
[ "https://Stackoverflow.com/questions/480430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11333/" ]
I have one console app that is doing some lengthy syncing to an ftp server. Another console app prepares a local filesystem with some needed updated files. Then the second one will wait for the first one to finish before swapping a final directory name so it becomes visible on the web. I searched for the best wa...
If all you need is to notify one application that the other has completed its task, the easiest way would be to use a named EventWaitHandle. The object is created in its unsignaled state. The first app waits on the handle, and the second app signals the handle when it's finished doing its job. For example: ``` // Firs...
480,431
<p>I'm trying to determine whether an XML element exists with Groovy's XmlSlurper. Is there a way to do this? For example:</p> <pre><code>&lt;foo&gt; &lt;bar/&gt; &lt;/foo&gt; </code></pre> <p>How do I check whether the bar element exists?</p>
[ { "answer_id": 480490, "author": "Josh Brown", "author_id": 2030, "author_profile": "https://Stackoverflow.com/users/2030", "pm_score": 4, "selected": false, "text": "<p>The isEmpty method on GPathResult works.</p>\n\n<pre><code>def text = \"&lt;foo&gt;&lt;bar/&gt;&lt;/foo&gt;\"\ndef xml...
2009/01/26
[ "https://Stackoverflow.com/questions/480431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2030/" ]
I'm trying to determine whether an XML element exists with Groovy's XmlSlurper. Is there a way to do this? For example: ``` <foo> <bar/> </foo> ``` How do I check whether the bar element exists?
The API is a little screwy, but I think that there are a couple of better ways to look for children. What you're getting when you ask for "xml.bar" (which exists) or "xml.quux" which doesn't, is a [groovy.util.slurpersupport.NodeChildren](http://groovy.codehaus.org/gapi/groovy/util/slurpersupport/NodeChildren.html) obj...
480,438
<p>Is it possible to link to someone's outlook calendar (assuming you have priveleges to view it through outlook itself) from a web page?</p> <p>I am working on an intranet site and would like to provide a link to someone's calendar similar to:</p> <pre> outlook:\\Public Folders\All Public Folders\Shared Calendar...
[ { "answer_id": 480725, "author": "eft", "author_id": 2680373, "author_profile": "https://Stackoverflow.com/users/2680373", "pm_score": -1, "selected": false, "text": "<p>Does the <a href=\"http://office.microsoft.com/en-us/outlook/HA101743551033.aspx?pid=CH102499821033\" rel=\"nofollow n...
2009/01/26
[ "https://Stackoverflow.com/questions/480438", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2849/" ]
Is it possible to link to someone's outlook calendar (assuming you have priveleges to view it through outlook itself) from a web page? I am working on an intranet site and would like to provide a link to someone's calendar similar to: ``` outlook:\\Public Folders\All Public Folders\Shared Calendar ``` However,...
***Bottom line*: Use OWA!** *Explanation*: I was trying to link to an shared calendar in outlook from our corporate intranet and was having similar problems to this and I think that the solution I came up with might apply to you. The problem essentially was the outlook:// protocol wasn't working and xnk files wouldn'...
480,439
<p>I really want to be able to have a function pass some responsiblity to another object and then return on a different thread. I know this means the caller would not know that it had switched threads, but I REALLY want to know if there is ANY way to have the function return on a different thread than it was called on...
[ { "answer_id": 480615, "author": "ShuggyCoUk", "author_id": 12748, "author_profile": "https://Stackoverflow.com/users/12748", "pm_score": 2, "selected": false, "text": "<p>You seem to have some misunderstanding of how threads work.\nYou cannot enter a function in one thread and exit it i...
2009/01/26
[ "https://Stackoverflow.com/questions/480439", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14101/" ]
I really want to be able to have a function pass some responsiblity to another object and then return on a different thread. I know this means the caller would not know that it had switched threads, but I REALLY want to know if there is ANY way to have the function return on a different thread than it was called on.
Async workflows give the illusion of something like this, e.g. ``` async { printfn "on thread 1..." let! r = stream.ReadAsync() printfn "on thread 2 now..." ... } ``` but it's just an illusion to make the code easy to read, write, and reason about; under the hood it's doing all the normal async stuff...
480,443
<p>Is it the same as overloading, if not, can you please provide and example of each in C#</p> <p>I have read the responses to a similar question asked in SO ... i did not understand the responses posted to it.</p> <p>Similar question asked <a href="https://stackoverflow.com/questions/479923/is-c-a-single-dispatch-or...
[ { "answer_id": 480496, "author": "Eclipse", "author_id": 8701, "author_profile": "https://Stackoverflow.com/users/8701", "pm_score": 1, "selected": false, "text": "<p>Single / multiple dispatch are a kind of run-time overloading. Single dispatch is more commonly known as virtual functio...
2009/01/26
[ "https://Stackoverflow.com/questions/480443", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1443363/" ]
Is it the same as overloading, if not, can you please provide and example of each in C# I have read the responses to a similar question asked in SO ... i did not understand the responses posted to it. Similar question asked [here](https://stackoverflow.com/questions/479923/is-c-a-single-dispatch-or-multiple-dispatch-...
C# uses single dispatch, which includes overloaded methods. When you have the code ``` stringBuilder.Append(parameter); ``` the dispatcher looks at all methods defined on the stringBuilder's class, and finds the correct one. For a multiple dispatch example, let's look at Prolog (which is the first one I could think...
480,454
<p>I'm using reflection to add some data to a private variable inside a class from a third-party library. Along the way there are about four different Exceptions that can be thrown; all of them are related to reflection, and all of them are very unlikely to occur. I'm hardcoding the name of the class and variable inv...
[ { "answer_id": 480472, "author": "matt b", "author_id": 4249, "author_profile": "https://Stackoverflow.com/users/4249", "pm_score": 3, "selected": false, "text": "<p>I usually ask myself these questions:</p>\n\n<ul>\n<li>Can whomever calls this method handle these different exception typ...
2009/01/26
[ "https://Stackoverflow.com/questions/480454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18103/" ]
I'm using reflection to add some data to a private variable inside a class from a third-party library. Along the way there are about four different Exceptions that can be thrown; all of them are related to reflection, and all of them are very unlikely to occur. I'm hardcoding the name of the class and variable involved...
You can turn all the Exceptions into an AssertionError if you never expect them to occur. InvocationTargetException can be unwrapped if you want to deal with a specific exception. If you want to throw the actual exception thrown by the method rather than InvocationTargetException you can use this trick, but it may be m...
480,482
<p>I have a logger system which basically is a fancy way of writing my data to std::clog in a thread safe way. </p> <p>I also, redirect <code>std::clog</code> to a file like this:</p> <pre><code>int main() { std::ofstream logfile(config::logname, std::ios::app); std::streambuf *const old_buffer = std::clog.rd...
[ { "answer_id": 480499, "author": "Paul Tomblin", "author_id": 3333, "author_profile": "https://Stackoverflow.com/users/3333", "pm_score": 5, "selected": true, "text": "<p>You can use the built-in log rotation method configured in /etc/logrotate.conf and/or /etc/logrotate.d/ - it's common...
2009/01/26
[ "https://Stackoverflow.com/questions/480482", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13430/" ]
I have a logger system which basically is a fancy way of writing my data to std::clog in a thread safe way. I also, redirect `std::clog` to a file like this: ``` int main() { std::ofstream logfile(config::logname, std::ios::app); std::streambuf *const old_buffer = std::clog.rdbuf(logfile.rdbuf()); // .....
You can use the built-in log rotation method configured in /etc/logrotate.conf and/or /etc/logrotate.d/ - it's common to have logrotate send your app a SIGUSR1 as a signal to close and re-open all your log files.
480,495
<p>Is there a way that I can get a list of the models that a particular model belongs to in Rails?</p> <p>For example:</p> <pre><code>class Project &lt; ActiveRecord::Base has_one :status ... end class Task &lt; ActiveRecord::Base has_one :status ... end class Status &lt; ActiveRecord::Base belongs_to :pr...
[ { "answer_id": 480610, "author": "Abdullah Jibaly", "author_id": 47110, "author_profile": "https://Stackoverflow.com/users/47110", "pm_score": 2, "selected": false, "text": "<p>You can use one array to define the associations and use in the validations like:</p>\n\n<pre><code>BELONGS_TO_...
2009/01/26
[ "https://Stackoverflow.com/questions/480495", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22687/" ]
Is there a way that I can get a list of the models that a particular model belongs to in Rails? For example: ``` class Project < ActiveRecord::Base has_one :status ... end class Task < ActiveRecord::Base has_one :status ... end class Status < ActiveRecord::Base belongs_to :project belongs_to :task # ...
This will get you a hash of objects describing the associations and other things on a given model `Model.reflections`. You want all the values in the hash that are `Reflection::AssociationReflection` classes. This code should get you the array you want: ``` association_names = [] Model.reflections.each { |key, value| ...
480,525
<p>I open a FIFO file as <code>ifstream</code>. As soon as the object is created the thread is blocked until I send something into the FIFO (which is OK for me). Then I call <code>getline()</code> to get the data from the stream.</p> <p>How do I read-block the thread again until more data is written into FIFO file?</p...
[ { "answer_id": 480704, "author": "Michael Kristofik", "author_id": 46821, "author_profile": "https://Stackoverflow.com/users/46821", "pm_score": 1, "selected": false, "text": "<p>The <code>getline</code> function provided by <code>&lt;string&gt;</code> returns a reference to the stream o...
2009/01/26
[ "https://Stackoverflow.com/questions/480525", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48461/" ]
I open a FIFO file as `ifstream`. As soon as the object is created the thread is blocked until I send something into the FIFO (which is OK for me). Then I call `getline()` to get the data from the stream. How do I read-block the thread again until more data is written into FIFO file? Thanks
I haven't tested this code but I'm wondering if the FIFO is simply setting the EOF bit when you read all available data. In that case, you might be able to do this: ``` std::ifstream fifo; std::string line; bool done = false; /* code to open your FIFO */ while (!done) { while (std::getline(fifo, line)...
480,533
<p>In my code I get the following error message </p> <blockquote> <p>c:\dpdata_copy2.vbs(114,13) Microsoft VBScript compilation error: Expected identifier</p> </blockquote> <p>line 114 points to a blank line so I assuemd it was throwing an error at the following line: </p> <pre><code>Lastprop = f.DateLastModif...
[ { "answer_id": 480558, "author": "Svante Svenson", "author_id": 19707, "author_profile": "https://Stackoverflow.com/users/19707", "pm_score": 0, "selected": false, "text": "<p>Are you running this using the Windows Scripting Host? If so, add //D as a parameter to CSCRIPT or WSCRIPT to ac...
2009/01/26
[ "https://Stackoverflow.com/questions/480533", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18853/" ]
In my code I get the following error message > > c:\dpdata\_copy2.vbs(114,13) Microsoft > VBScript compilation error: Expected > identifier > > > line 114 points to a blank line so I assuemd it was throwing an error at the following line: ``` Lastprop = f.DateLastModified ``` in the code ``` strComputer =...
Are you running this using the Windows Scripting Host? If so, add //D as a parameter to CSCRIPT or WSCRIPT to activate the debug mode that let's you go through the stack and view all variables etc. in Visual Studio or any windows script debugger you have installed.
480,539
<p>Ok, so I'm having a hard time coming up with a 'good' way to do the following:</p> <p>Group 4 objects so that if I Object A I can easily and without having to go through Objects B &amp; C to find out if Object D relates to Object A. As well as any other combination of referencing.</p> <p>I am currently using Sorte...
[ { "answer_id": 480580, "author": "Jay S", "author_id": 30440, "author_profile": "https://Stackoverflow.com/users/30440", "pm_score": 1, "selected": false, "text": "<p>You could use the generic Dictionary class to specify key/value pairs between the objects.</p>\n\n<p>This would allow you...
2009/01/26
[ "https://Stackoverflow.com/questions/480539", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45533/" ]
Ok, so I'm having a hard time coming up with a 'good' way to do the following: Group 4 objects so that if I Object A I can easily and without having to go through Objects B & C to find out if Object D relates to Object A. As well as any other combination of referencing. I am currently using SortedLists to link A to B...
First of all, if you have a relationship like A->B->C->D the only way to see if A relates to D is to go all the way from A to D. You can nontheless apply a few tricks This will involve manually keeping track of each indirect reference present in the program, that is, you'll be in charge of adding the A->D reference di...
480,552
<p>What's the best way to add children to a WrapPanel in silverlight? I'm using C# and I'm reading in a JSON Object containing images with thumbnails and related information.</p> <p>The end goal is to have a grid of thumbnails (13 thumbs horizontally across 950px by 6 thumbs vertically).</p>
[ { "answer_id": 480766, "author": "Maurice", "author_id": 19676, "author_profile": "https://Stackoverflow.com/users/19676", "pm_score": 0, "selected": false, "text": "<p>The WrapPanel is derives from Panel so you can just use Children.Add(control). The WrapPanel will take care of all the ...
2009/01/26
[ "https://Stackoverflow.com/questions/480552", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
What's the best way to add children to a WrapPanel in silverlight? I'm using C# and I'm reading in a JSON Object containing images with thumbnails and related information. The end goal is to have a grid of thumbnails (13 thumbs horizontally across 950px by 6 thumbs vertically).
When you're faced with adding items in code, generally there's a better way. How about making a ListBox and setting its ItemsSource to your list (or binding it to the DataContext). Make a DataTemplate to display your thumbnail + info and then (this is the important part) make a ItemsPanelTemplate using a WrapPanel. ...
480,555
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/164194/why-do-i-get-a-segmentation-fault-when-writing-to-a-string">Why do I get a segmentation fault when writing to a string?</a> </p> </blockquote> <p>I want to write a function that reverses the given string...
[ { "answer_id": 480600, "author": "Binary Worrier", "author_id": 18797, "author_profile": "https://Stackoverflow.com/users/18797", "pm_score": 3, "selected": false, "text": "<p><em>Because this is homework I'll give advice but I won't post a complete solution.</em></p>\n\n<p>I'm guessing ...
2009/01/26
[ "https://Stackoverflow.com/questions/480555", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
> > **Possible Duplicate:** > > [Why do I get a segmentation fault when writing to a string?](https://stackoverflow.com/questions/164194/why-do-i-get-a-segmentation-fault-when-writing-to-a-string) > > > I want to write a function that reverses the given string passed into it. But, I can not. If I supply the `d...
The simplest solution is to change the declaration of `str` to ``` char str[] = "abc"; ``` This makes `str` an array of char that is initialized to the string "abc". Currently you have `str` as a pointer-to-char initialized to point to a string described by a string literal. There is a key difference: string literal...
480,562
<p>I have a software project in which I sometimes get strange results from small, simple floating point operations. I assume there is something I have missed, and would like some tips about how to debug the following problems:</p> <p>(the compiler used is MS VC 6.0, that is version 12 of the Microsoft C compiler)</p> ...
[ { "answer_id": 480626, "author": "David Segonds", "author_id": 13673, "author_profile": "https://Stackoverflow.com/users/13673", "pm_score": 0, "selected": false, "text": "<p>While I am not providing you with an exact solution, I suggest you start by reading this <a href=\"http://msdn.mi...
2009/01/26
[ "https://Stackoverflow.com/questions/480562", "https://Stackoverflow.com", "https://Stackoverflow.com/users/59060/" ]
I have a software project in which I sometimes get strange results from small, simple floating point operations. I assume there is something I have missed, and would like some tips about how to debug the following problems: (the compiler used is MS VC 6.0, that is version 12 of the Microsoft C compiler) First anomaly...
If you're using the windows QueryPerformanceCounter and QueryPerformanceFrequency functions on a system that supports MMX try inserting the femms instruction after querying the frequency/counter and before the computation. ``` __asm femms ``` I've encountered trouble from these function before where they were doing...
480,566
<p>Given the code:</p> <pre><code> new Thread(new BackgroundWorker()).start(); </code></pre> <p>Intuitively it feels like the BackgroundWorker instance should be safe from GC until the thread exits, but is this the case ? And why ? </p> <p><strong>Edit:</strong></p> <p>All this heat is basically generated by me ask...
[ { "answer_id": 480584, "author": "Michael Myers", "author_id": 13531, "author_profile": "https://Stackoverflow.com/users/13531", "pm_score": 1, "selected": false, "text": "<p>Yes, because the <code>Thread</code> keeps a reference to the <code>Runnable</code> internally (it <a href=\"http...
2009/01/26
[ "https://Stackoverflow.com/questions/480566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23691/" ]
Given the code: ``` new Thread(new BackgroundWorker()).start(); ``` Intuitively it feels like the BackgroundWorker instance should be safe from GC until the thread exits, but is this the case ? And why ? **Edit:** All this heat is basically generated by me asking at least two different questions in the same post...
Yes, because GC can only collect objects not reachable by any thread, and Thread must hold a reference to it's runnable (or it would not be able to invoke it). So, clearly, your Runnable object is reachable while your thread is running. Regardless of the semantics required for *execution*, your object will not be GC'd...
480,567
<p>So I have a DIV that contains some dynamic text. Let's say I know the text and font-size but I don't know the size of the DIV. I'd like the display of the text in the DIV to be intelligent enough to show indentation when text wraps.</p> <p>Say my original text looked something like this:</p> <pre> Lorem ipsum do...
[ { "answer_id": 480596, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 6, "selected": false, "text": "<p>If I understand what you're asking for, this works for me: </p>\n\n<pre><code>div {\n padding-left: 2em;\n t...
2009/01/26
[ "https://Stackoverflow.com/questions/480567", "https://Stackoverflow.com", "https://Stackoverflow.com/users/341642/" ]
So I have a DIV that contains some dynamic text. Let's say I know the text and font-size but I don't know the size of the DIV. I'd like the display of the text in the DIV to be intelligent enough to show indentation when text wraps. Say my original text looked something like this: ``` Lorem ipsum dolor sit amet, co...
If I understand what you're asking for, this works for me: ``` div { padding-left: 2em; text-indent: -2em; } ```
480,573
<p>I have a websphere 6.1 configuration and the application is running, but some requests go to j_security_check but the last one (there are filters associated with J_security_check) will generate a 404 error.</p> <p>For example: </p> <p>(1) User posts to: <a href="http://localhost:9081/Page/j_security_check" rel="no...
[ { "answer_id": 480596, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 6, "selected": false, "text": "<p>If I understand what you're asking for, this works for me: </p>\n\n<pre><code>div {\n padding-left: 2em;\n t...
2009/01/26
[ "https://Stackoverflow.com/questions/480573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10522/" ]
I have a websphere 6.1 configuration and the application is running, but some requests go to j\_security\_check but the last one (there are filters associated with J\_security\_check) will generate a 404 error. For example: (1) User posts to: <http://localhost:9081/Page/j_security_check> And it works on Filter1, but...
If I understand what you're asking for, this works for me: ``` div { padding-left: 2em; text-indent: -2em; } ```
480,589
<p>i'have a js client with JQuery, this js call a page (GET HTTP) and set timeout. The aim of timeout is: "do something if the server not responds". If i use Apache web server for manage a page, the timeout perform. If i use IIS 6.0 the timeout is "skipped" and the page attempt (anyway) the server response. This is th...
[ { "answer_id": 480711, "author": "Herms", "author_id": 1409, "author_profile": "https://Stackoverflow.com/users/1409", "pm_score": 2, "selected": true, "text": "<p>As Paolo mentioned in a comment, you're missing a comma after the timeout declaration. I very recently had a situation wher...
2009/01/26
[ "https://Stackoverflow.com/questions/480589", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56606/" ]
i'have a js client with JQuery, this js call a page (GET HTTP) and set timeout. The aim of timeout is: "do something if the server not responds". If i use Apache web server for manage a page, the timeout perform. If i use IIS 6.0 the timeout is "skipped" and the page attempt (anyway) the server response. This is the s...
As Paolo mentioned in a comment, you're missing a comma after the timeout declaration. I very recently had a situation where a missing comma in an object declaration like that would cause IE to choke on the script and not run it properly (while firefox had no problems running it). That wouldn't explain why the differe...
480,604
<p>I'm looking for the correct way to write my own interface objects.</p> <p>Say, I want an image that can be double-tapped.</p> <pre><code>@interface DoubleTapButtonView : UIView { UILabel *text; UIImage *button; UIImage *button_selected; BOOL selected; } // detect tapCount == 2 - (void)touchesBegan:...
[ { "answer_id": 480858, "author": "August", "author_id": 30966, "author_profile": "https://Stackoverflow.com/users/30966", "pm_score": 2, "selected": false, "text": "<p>The delegate is definitely the way to go here.</p>\n" }, { "answer_id": 480871, "author": "Noah Witherspoon"...
2009/01/26
[ "https://Stackoverflow.com/questions/480604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18158/" ]
I'm looking for the correct way to write my own interface objects. Say, I want an image that can be double-tapped. ``` @interface DoubleTapButtonView : UIView { UILabel *text; UIImage *button; UIImage *button_selected; BOOL selected; } // detect tapCount == 2 - (void)touchesBegan:(NSSet *)touches with...
The delegate is definitely the way to go here.
480,617
<p>I'm writing some code that uses dynamic shared libraries as plugins.</p> <p>My command line for building the shared libraries looks like:</p> <pre><code>cc -shared -fPIC -o module.so -g -Wall module.c </code></pre> <p>Within the module, I can call functions that are in any other shared library that has been loade...
[ { "answer_id": 480662, "author": "Alnitak", "author_id": 6782, "author_profile": "https://Stackoverflow.com/users/6782", "pm_score": 4, "selected": true, "text": "<p>I've found the answer myself.</p>\n\n<p>I had to add the <code>--export-dynamic</code> flags to the link options for the m...
2009/01/26
[ "https://Stackoverflow.com/questions/480617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6782/" ]
I'm writing some code that uses dynamic shared libraries as plugins. My command line for building the shared libraries looks like: ``` cc -shared -fPIC -o module.so -g -Wall module.c ``` Within the module, I can call functions that are in any other shared library that has been loaded within the main executable. Ho...
I've found the answer myself. I had to add the `--export-dynamic` flags to the link options for the main executable. > > When creating a dynamically linked > executable, add all symbols to the > dynamic symbol table. The dynamic > symbol table is the set of symbols > which are visible from dynamic objects > at ...
480,619
<p>I am trying to automate some upload/download tasks from an ftp web server. When I connect to the server through client, or through Firefox even, in order to get to my directory, I have to specify a path like this:</p> <pre><code>ftp://ftpserver.com/../AB00000/incoming/files </code></pre> <p>If I try to access this...
[ { "answer_id": 480744, "author": "BFree", "author_id": 15861, "author_profile": "https://Stackoverflow.com/users/15861", "pm_score": -1, "selected": false, "text": "<p>Have you tried using the @ symbol like so?</p>\n\n<pre><code>Uri target = new Uri(@\"ftp://ftpserver.com/../AB00000/inco...
2009/01/26
[ "https://Stackoverflow.com/questions/480619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53007/" ]
I am trying to automate some upload/download tasks from an ftp web server. When I connect to the server through client, or through Firefox even, in order to get to my directory, I have to specify a path like this: ``` ftp://ftpserver.com/../AB00000/incoming/files ``` If I try to access this: ``` ftp://ftpserver.com...
Try escaping the .. with something like: ``` Uri target = new Uri("ftp://ftpserver.com/%2E%2E/AB00000/incoming/files"); ``` That works according to this [blog](http://blogs.msdn.com/mariya/default.aspx) which I found in this [discussion](http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/76d3a3a2-48b6-...
480,623
<p>Is there any way i can access the page object from within the global.asax Application_EndRequest function ?</p> <p>I'm trying to set the text of a label at the end of the request but accessing the page is proving to be more difficult than I thought.</p> <p>here is what i have that's currently NOT working:</p> <pr...
[ { "answer_id": 480633, "author": "Noldorin", "author_id": 44389, "author_profile": "https://Stackoverflow.com/users/44389", "pm_score": 4, "selected": true, "text": "<p>It's probably best just to create a BasePage class from which all your pages should inherit. Then you can put the code ...
2009/01/26
[ "https://Stackoverflow.com/questions/480623", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2847/" ]
Is there any way i can access the page object from within the global.asax Application\_EndRequest function ? I'm trying to set the text of a label at the end of the request but accessing the page is proving to be more difficult than I thought. here is what i have that's currently NOT working: ``` protected void Appl...
It's probably best just to create a BasePage class from which all your pages should inherit. Then you can put the code within the Unload event of the page and there will be no issue.
480,632
<p>Does anyone know why <code>java.lang.Number</code> does not implement <code>Comparable</code>? This means that you cannot sort <code>Number</code>s with <code>Collections.sort</code> which seems to me a little strange.</p> <p><strong>Post discussion update:</strong></p> <p>Thanks for all the helpful responses. I ...
[ { "answer_id": 480651, "author": "Pete Kirkham", "author_id": 1527, "author_profile": "https://Stackoverflow.com/users/1527", "pm_score": 2, "selected": false, "text": "<p>Very probably because it would be rather inefficient to compare numbers - the only representation into which every N...
2009/01/26
[ "https://Stackoverflow.com/questions/480632", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32174/" ]
Does anyone know why `java.lang.Number` does not implement `Comparable`? This means that you cannot sort `Number`s with `Collections.sort` which seems to me a little strange. **Post discussion update:** Thanks for all the helpful responses. I ended up doing [some more research about this topic](http://radioeiffel.blo...
It's worth mentioning that the following expression: ``` new Long(10).equals(new Integer(10)) ``` is always `false`, which tends to trip everyone up at some point or another. So not only can you not compare arbitrary `Number`s but you can't even determine if they're equal or not. Also, with the real primitive types...
480,640
<p>Probably best illustrated with a small example.<br> Given the relations</p> <pre><code>A &lt; B &lt; C A &lt; P &lt; Q </code></pre> <p>Correct outputs would be</p> <pre><code>ABCPQ or APQBC or APBCQ ... etc. </code></pre> <p>In other words, any ordering is valid in which the given relationships hold.</p> <p>I...
[ { "answer_id": 480746, "author": "user54579", "author_id": 54579, "author_profile": "https://Stackoverflow.com/users/54579", "pm_score": 1, "selected": false, "text": "<p>Do several sorts. First sort according to the first rule, then according to the second one and so on. Should work, un...
2009/01/26
[ "https://Stackoverflow.com/questions/480640", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53722/" ]
Probably best illustrated with a small example. Given the relations ``` A < B < C A < P < Q ``` Correct outputs would be ``` ABCPQ or APQBC or APBCQ ... etc. ``` In other words, any ordering is valid in which the given relationships hold. I am most interested in the solution that is easiest to implement, but...
This is called [topological sorting](http://en.wikipedia.org/wiki/Topological_sorting). The standard algorithm is to output a minimal element, then remove it and repeat until done.
480,665
<p>I have Windows XP/Django/apache/mod_python working on localhost. All parts are working with the exception of the admin CSS not rendering. The admin works, but no html formatting. I've made additions in:</p> <pre><code>settings.py INSTALLED_APPS 'django.contrib.admin', urls.py from django.contrib import ...
[ { "answer_id": 480682, "author": "Harper Shelby", "author_id": 21196, "author_profile": "https://Stackoverflow.com/users/21196", "pm_score": 5, "selected": false, "text": "<p>Does your ADMIN_MEDIA_PREFIX exist? Is it different from MEDIA_URL? Did you include the trailing slash? Is Apache...
2009/01/26
[ "https://Stackoverflow.com/questions/480665", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have Windows XP/Django/apache/mod\_python working on localhost. All parts are working with the exception of the admin CSS not rendering. The admin works, but no html formatting. I've made additions in: ``` settings.py INSTALLED_APPS 'django.contrib.admin', urls.py from django.contrib import admin admin.au...
Does your ADMIN\_MEDIA\_PREFIX exist? Is it different from MEDIA\_URL? Did you include the trailing slash? Is Apache handled to correctly serve up the admin media? The default Django configuration has the admin media located at {Django install dir}/contrib/admin/media. ADMIN\_MEDIA\_PREFIX defaults to /media/. So you ...
480,679
<p>I'm studying ICT. One of my courses is C# and another is Physics. Our Physics teacher used Visual Studio to animate some movements gave us some of the code he used to do it. He told us to look it up. Here's something I don't recognize:</p> <pre><code>public static Vector operator + (Vector v1, Vector v2) { retu...
[ { "answer_id": 480687, "author": "Alex Fort", "author_id": 12624, "author_profile": "https://Stackoverflow.com/users/12624", "pm_score": 2, "selected": false, "text": "<p>He's overloading the \"+\" operator for the Vector class. See <a href=\"http://www.csharphelp.com/archives/archive135...
2009/01/26
[ "https://Stackoverflow.com/questions/480679", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11795/" ]
I'm studying ICT. One of my courses is C# and another is Physics. Our Physics teacher used Visual Studio to animate some movements gave us some of the code he used to do it. He told us to look it up. Here's something I don't recognize: ``` public static Vector operator + (Vector v1, Vector v2) { return new Vector(...
It's not a constructor. It's an operator method for the '+' operator. It defines what happens when you do somethig like the following:- ``` var Vector v1 = new Vector(1,2,3); var Vector v2 = new Vector(1,2,3); var Vector v3 = v1 + v2; ```
480,681
<p>I'm basically looking for the event that is the opposite of FormsAuthentication_OnAuthenticate. I want to remove some values from the database when a user logs out. I tried putting it into the Session_End event, but it seems that the user is already gone by the time this executes.</p> <p>Update: If I can't determ...
[ { "answer_id": 480689, "author": "DCNYAM", "author_id": 30419, "author_profile": "https://Stackoverflow.com/users/30419", "pm_score": 0, "selected": false, "text": "<p>I would imagine you have them logging out via the click of a button or link or something like that. Why not just put th...
2009/01/26
[ "https://Stackoverflow.com/questions/480681", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24908/" ]
I'm basically looking for the event that is the opposite of FormsAuthentication\_OnAuthenticate. I want to remove some values from the database when a user logs out. I tried putting it into the Session\_End event, but it seems that the user is already gone by the time this executes. Update: If I can't determine when a...
Session\_End isn't guarenteed to fire - if you're not using InProc sessions for example, then it won't fire at all. If your application recycles or dies, again, it won't fire. Your best bet would be to have this code in a shared method that you can call from numerous places: 1. In your [LoginStatus](http://msdn.micro...
480,696
<p>I want to determine if a native assembly is complied as x64 or x86 from a managed code application (<a href="http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29" rel="noreferrer">C#</a>).</p> <p>I think it must be somewhere in the PE header since the OS loader needs to know this information, but I could...
[ { "answer_id": 480727, "author": "Steven Behnke", "author_id": 42588, "author_profile": "https://Stackoverflow.com/users/42588", "pm_score": 0, "selected": false, "text": "<p>Apparently you can find it in the header of the portable executable. The corflags.exe utility is able to show yo...
2009/01/26
[ "https://Stackoverflow.com/questions/480696", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17212/" ]
I want to determine if a native assembly is complied as x64 or x86 from a managed code application ([C#](http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29)). I think it must be somewhere in the PE header since the OS loader needs to know this information, but I couldn't find it. Of course I prefer to do ...
You can use [DUMPBIN](http://msdn.microsoft.com/en-us/library/c1h23y6c%28v=vs.71%29.aspx) too. Use the `/headers` or `/all` flag and its the first file header listed. ``` dumpbin /headers cv210.dll ``` ### 64-bit ``` Microsoft (R) COFF/PE Dumper Version 10.00.30319.01 Copyright (C) Microsoft Corporation. All right...
480,717
<p>I have a list of objects output from <code>ldapsearch</code> as follows:</p> <pre><code>dn: cn=HPOTTER,ou=STUDENTS,ou=HOGWARTS,o=SCHOOL dn: cn=HGRANGER,ou=STUDENTS,ou=HOGWARTS,o=SCHOOL dn: cn=RWEASLEY,ou=STUDENTS,ou=HOGWARTS,o=SCHOOL dn: cn=DMALFOY,ou=STUDENTS,ou=HOGWARTS,o=SCHOOL dn: cn=SSNAPE,ou=FACULTY,ou=HOGWAR...
[ { "answer_id": 480729, "author": "duffymo", "author_id": 37213, "author_profile": "https://Stackoverflow.com/users/37213", "pm_score": -1, "selected": true, "text": "<p>Sounds more like a simple parsing problem and not regex. An ANTLR grammar would sort this out in no time.</p>\n" }, ...
2009/01/26
[ "https://Stackoverflow.com/questions/480717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/43263/" ]
I have a list of objects output from `ldapsearch` as follows: ``` dn: cn=HPOTTER,ou=STUDENTS,ou=HOGWARTS,o=SCHOOL dn: cn=HGRANGER,ou=STUDENTS,ou=HOGWARTS,o=SCHOOL dn: cn=RWEASLEY,ou=STUDENTS,ou=HOGWARTS,o=SCHOOL dn: cn=DMALFOY,ou=STUDENTS,ou=HOGWARTS,o=SCHOOL dn: cn=SSNAPE,ou=FACULTY,ou=HOGWARTS,o=SCHOOL dn: cn=ADUMBL...
Sounds more like a simple parsing problem and not regex. An ANTLR grammar would sort this out in no time.
480,722
<p>I'm trying to set a column width of a table, which works fine until it gets to the point where child elements would be visually truncated ... then it won't size any smaller. ("visually truncated"-what doesn't fit appears to be hidden behind the next column)</p> <p>Here is some sample code to demonstrate my problem...
[ { "answer_id": 480780, "author": "Darryl Braaten", "author_id": 1834, "author_profile": "https://Stackoverflow.com/users/1834", "pm_score": 2, "selected": false, "text": "<pre><code>&lt;td id=\"td1\" style=\"overflow-x:hidden;\"&gt;\n</code></pre>\n\n<p>Should be </p>\n\n<pre><code>&lt;t...
2009/01/26
[ "https://Stackoverflow.com/questions/480722", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29043/" ]
I'm trying to set a column width of a table, which works fine until it gets to the point where child elements would be visually truncated ... then it won't size any smaller. ("visually truncated"-what doesn't fit appears to be hidden behind the next column) Here is some sample code to demonstrate my problem: ``` <!DO...
I just tried adding `table-layout: fixed;` to the `<table>` and it worked for me on IE7. > > In a fixed table layout, the horizontal layout only depends on the table's width, the width of the columns, and not the content of the cells > > > Check out [the documentation](http://www.w3.org/TR/CSS2/tables.html#width-...
480,730
<p>Assume I have two data tables and a linking table as such:</p> <pre> A B A_B_Link ----- ----- ----- ID ID A_ID Name Name B_ID </pre> <p>2 Questions:</p> <ol> <li><p>I would like to write a query so that I have all of A's columns and a count of how many B...
[ { "answer_id": 480740, "author": "Ray Booysen", "author_id": 42124, "author_profile": "https://Stackoverflow.com/users/42124", "pm_score": 2, "selected": false, "text": "<p>For #1</p>\n\n<pre><code>SELECT A.*, \n(SELECT COUNT(*) FROM A_B_Link WHERE A_B_Link.A_ID = AOuter.A_ID)\nFROM A as...
2009/01/26
[ "https://Stackoverflow.com/questions/480730", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1638/" ]
Assume I have two data tables and a linking table as such: ``` A B A_B_Link ----- ----- ----- ID ID A_ID Name Name B_ID ``` 2 Questions: 1. I would like to write a query so that I have all of A's columns and a count of how many B's are linked to A, what is ...
For your first question: ``` SELECT A.ID, A.Name, COUNT(ab.B_ID) AS bcount FROM A LEFT JOIN A_B_Link ab ON (ab.A_ID = A.ID) GROUP BY A.ID, A.Name; ``` This outputs one row per row of A, with the count of matching B's. Note that you must list all columns of A in the GROUP BY statement; there's no way to use a wildcar...
480,735
<p>What is a Vanilla JS or jQuery solution that will select all of the contents of a textbox when the textbox receives focus?</p>
[ { "answer_id": 480754, "author": "John Sheehan", "author_id": 1786, "author_profile": "https://Stackoverflow.com/users/1786", "pm_score": 10, "selected": true, "text": "<pre><code>$(document).ready(function() {\n $(\"input:text\").focus(function() { $(this).select(); } );\n});\n</code...
2009/01/26
[ "https://Stackoverflow.com/questions/480735", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1950/" ]
What is a Vanilla JS or jQuery solution that will select all of the contents of a textbox when the textbox receives focus?
``` $(document).ready(function() { $("input:text").focus(function() { $(this).select(); } ); }); ```
480,742
<p>Let's say I have two tables, "Parent" and "Child". Parent-to-Child is a many:many relationship, implemented through a standard cross-referencing table.</p> <p>I want to find all records of Parent that are referenced by ALL members of a given set of Child using SQL (in particular MS SQL Server's T-SQL; 2005 syntax i...
[ { "answer_id": 480785, "author": "Cade Roux", "author_id": 18255, "author_profile": "https://Stackoverflow.com/users/18255", "pm_score": 4, "selected": true, "text": "<p>Relying on a numerical trick (where the number of parent-child links = the number of children, that parent is linked t...
2009/01/26
[ "https://Stackoverflow.com/questions/480742", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3488/" ]
Let's say I have two tables, "Parent" and "Child". Parent-to-Child is a many:many relationship, implemented through a standard cross-referencing table. I want to find all records of Parent that are referenced by ALL members of a given set of Child using SQL (in particular MS SQL Server's T-SQL; 2005 syntax is acceptab...
Relying on a numerical trick (where the number of parent-child links = the number of children, that parent is linked to all children): ``` SELECT Parent.ParentID, COUNT(*) FROM Parent INNER JOIN ChildParent ON ChildParent.ParentID = Parent.ParentID INNER JOIN Child ON ChildParent.ChildID = Child.ChildID WHERE ...
480,743
<p>At first I want to say that sample below is oversimplification. Suppose you have bound WPF control.</p> <pre><code>&lt;Window Title="Window1" Height="300" Width="300"&gt; &lt;Grid&gt; &lt;StackPanel&gt; &lt;TextBox Text="{Binding Name}" Margin="10"/&gt; &lt;Button HorizontalAlignment="Center" ...
[ { "answer_id": 480772, "author": "Jobi Joy", "author_id": 8091, "author_profile": "https://Stackoverflow.com/users/8091", "pm_score": 0, "selected": false, "text": "<p>The reason is because you have hardcoded the 'Some Name' in the setter. When you changed the textBox value the setter is...
2009/01/26
[ "https://Stackoverflow.com/questions/480743", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47856/" ]
At first I want to say that sample below is oversimplification. Suppose you have bound WPF control. ``` <Window Title="Window1" Height="300" Width="300"> <Grid> <StackPanel> <TextBox Text="{Binding Name}" Margin="10"/> <Button HorizontalAlignment="Center" Content="Click Me" Margin="5" ...
The PropertyChanged event is ignored by the TextBox because it is the initiator of the event. Some clarification: The TextBox (or the binding on the textbox) knows it is the initiator because it receives the PropertyChanged event in the same call. By doing an asynchronous call, the textbox (or binding) has no way to ...
480,757
<p>I have an extension method on the HttpApplicationState object for getting my IoC container out of the application. This same code will also create the container if it doesn't exist.</p> <p>I have 2 questions:</p> <ol> <li>Is my code actually thread safe as I intend it to be</li> <li>Is this considered the best pra...
[ { "answer_id": 480802, "author": "casperOne", "author_id": 50776, "author_profile": "https://Stackoverflow.com/users/50776", "pm_score": 1, "selected": false, "text": "<p>Technically, that won't work given the EMCA specification. Jon Skeet goes into this in his C# FAQ:</p>\n\n<p><a href...
2009/01/26
[ "https://Stackoverflow.com/questions/480757", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37055/" ]
I have an extension method on the HttpApplicationState object for getting my IoC container out of the application. This same code will also create the container if it doesn't exist. I have 2 questions: 1. Is my code actually thread safe as I intend it to be 2. Is this considered the best practice for dealing with the...
You need to put ``` var container = application[GlobalContainerKey] as IUnityContainer; ``` in the lock as well, otherwise many threads may create a new container in sequence. ``` private const string GlobalContainerKey = "UnityContainerKey"; private const object lockObject = new object(); public static IUnityCon...
480,764
<p>Program is part of the Xenomai test suite, cross-compiled from Linux PC into Linux+Xenomai ARM toolchain.</p> <pre><code># echo $LD_LIBRARY_PATH /lib ...
[ { "answer_id": 480786, "author": "Paul Tomblin", "author_id": 3333, "author_profile": "https://Stackoverflow.com/users/3333", "pm_score": 8, "selected": true, "text": "<p><strong>Update</strong><br />\nWhile what I write below is true as a general answer about shared libraries, I think t...
2009/01/26
[ "https://Stackoverflow.com/questions/480764", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39702/" ]
Program is part of the Xenomai test suite, cross-compiled from Linux PC into Linux+Xenomai ARM toolchain. ``` # echo $LD_LIBRARY_PATH /lib ...
**Update** While what I write below is true as a general answer about shared libraries, I think the most frequent cause of these sorts of message is because you've installed a package, but not installed the `-dev` version of that package. --- Well, it's not lying - there is no `libpthread_rt.so.1` in that listing....
480,769
<p>I'm fairly new to F# and I wanted to compare two values with the (match ... with ...) syntax</p> <p>The problem arises when I attempt to compare two values like this:</p> <pre><code>let value1 = 19 let isValue1 y = match y with | value1 -&gt; y + 1 | _ -&gt; y </code></pre> <p>I get a warning that the...
[ { "answer_id": 480804, "author": "Noldorin", "author_id": 44389, "author_profile": "https://Stackoverflow.com/users/44389", "pm_score": 4, "selected": false, "text": "<p>The value1 within the match statement is defined as a new variable, the value of which is set to y (as a match). The v...
2009/01/26
[ "https://Stackoverflow.com/questions/480769", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58444/" ]
I'm fairly new to F# and I wanted to compare two values with the (match ... with ...) syntax The problem arises when I attempt to compare two values like this: ``` let value1 = 19 let isValue1 y = match y with | value1 -> y + 1 | _ -> y ``` I get a warning that the "| \_ -> y" portion of the code will n...
The value1 within the match statement is defined as a new variable, the value of which is set to y (as a match). The value1 you define just above is ignored, just as if you were declaring a local variable in a C# function with the same name as a class variable. For this reason, the first match condition will match *eve...