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
52,794
<p>How do I create a branch in subversion that is deeper' than just the 'branches' directory?</p> <p>I have the standard <code>trunk</code>, <code>tags</code> and <code>branches</code> structure and I want to create a branch that is several directories deeper than the 'branches' tag.</p> <p>Using the standard svn mov...
[ { "answer_id": 52799, "author": "Blair Conrad", "author_id": 1199, "author_profile": "https://Stackoverflow.com/users/1199", "pm_score": 5, "selected": true, "text": "<pre><code>svn copy --parents http://url/to/subproject http://url/to/repository/branches/version_1/project/subproject\n</...
2008/09/09
[ "https://Stackoverflow.com/questions/52794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/277/" ]
How do I create a branch in subversion that is deeper' than just the 'branches' directory? I have the standard `trunk`, `tags` and `branches` structure and I want to create a branch that is several directories deeper than the 'branches' tag. Using the standard svn move method, it gives me a **folder not found** error...
``` svn copy --parents http://url/to/subproject http://url/to/repository/branches/version_1/project/subproject ``` That should create the directory you want to put the subproject in (`--parents` means "create the intermediate directories for me").
52,797
<p>Is there a way to get the path for the assembly in which the current code resides? I do not want the path of the calling assembly, just the one containing the code. </p> <p>Basically my unit test needs to read some xml test files which are located relative to the dll. I want the path to always resolve correctly ...
[ { "answer_id": 52802, "author": "jodonnell", "author_id": 4223, "author_profile": "https://Stackoverflow.com/users/4223", "pm_score": 5, "selected": false, "text": "<p>This should work, unless the assembly is <em>shadow copied</em>:</p>\n\n<pre><code>string path = System.Reflection.Assem...
2008/09/09
[ "https://Stackoverflow.com/questions/52797", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056/" ]
Is there a way to get the path for the assembly in which the current code resides? I do not want the path of the calling assembly, just the one containing the code. Basically my unit test needs to read some xml test files which are located relative to the dll. I want the path to always resolve correctly regardless of...
**Note**: Assembly.CodeBase is deprecated in .NET Core/.NET 5+: <https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.codebase?view=net-5.0> **Original answer:** I've defined the following property as we use this often in unit testing. ``` public static string AssemblyDirectory { get { ...
52,806
<p>As part of a larger web-app (using CakePHP), I'm putting together a simple blog system. The relationships are exceedingly simple: each User has a Blog, which has many Entries, which have many Comments.</p> <p>An element I'd like to incorporate is a list of "Popular Entries." Popular Entries have been defined as tho...
[ { "answer_id": 52814, "author": "jodonnell", "author_id": 4223, "author_profile": "https://Stackoverflow.com/users/4223", "pm_score": 2, "selected": false, "text": "<p>Shouldn't be too bad, you just need a group by (this is off the type of my head, so forgive syntax errors):</p>\n\n<pre>...
2008/09/09
[ "https://Stackoverflow.com/questions/52806", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5030/" ]
As part of a larger web-app (using CakePHP), I'm putting together a simple blog system. The relationships are exceedingly simple: each User has a Blog, which has many Entries, which have many Comments. An element I'd like to incorporate is a list of "Popular Entries." Popular Entries have been defined as those with th...
Heh, I was just about to come back with essentially the same answer (using Cake's Model::find): ``` $this->loadModel('Comment'); $this->Comment->find( 'all', array( 'fields' => array('COUNT(Comment.id) AS popularCount'), 'conditions' => array( 'Comment.created >' => strtotime('-1 month') ), 'g...
52,821
<pre><code>var e1 = new E1(); e1.e2s.Add(new e2()); //e2s is null until e1 is saved, i want to save them all at the same time context.e1s.imsertonsubmit(e1); context.submitchanges(); </code></pre>
[ { "answer_id": 52870, "author": "John Christensen", "author_id": 1194, "author_profile": "https://Stackoverflow.com/users/1194", "pm_score": 0, "selected": false, "text": "<p>Well - I don't know if your initial code block would work, but I'm guessing you have to mark your new e2 as inser...
2008/09/09
[ "https://Stackoverflow.com/questions/52821", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5236/" ]
``` var e1 = new E1(); e1.e2s.Add(new e2()); //e2s is null until e1 is saved, i want to save them all at the same time context.e1s.imsertonsubmit(e1); context.submitchanges(); ```
The sub items will be saved along with the main item, and even identities will be set properly, if you give your DataClasses an association between these classes. You do this by adding LoadOptions to your O/R-Designer DataClasses like this: ``` MyDataContext mydc = new MyDataContext(); System.Data.Linq.DataLoadOp...
52,822
<p>How can you import a foxpro DBF file in SQL Server?</p>
[ { "answer_id": 52828, "author": "SQLMenace", "author_id": 740, "author_profile": "https://Stackoverflow.com/users/740", "pm_score": 5, "selected": true, "text": "<p>Use a linked server or use openrowset, example</p>\n\n<pre><code>SELECT * into SomeTable\nFROM OPENROWSET('MSDASQL', 'Drive...
2008/09/09
[ "https://Stackoverflow.com/questions/52822", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4685/" ]
How can you import a foxpro DBF file in SQL Server?
Use a linked server or use openrowset, example ``` SELECT * into SomeTable FROM OPENROWSET('MSDASQL', 'Driver=Microsoft Visual FoxPro Driver; SourceDB=\\SomeServer\SomePath\; SourceType=DBF', 'SELECT * FROM SomeDBF') ```
52,824
<p>Is it possible to merge to a branch that is not a direct parent or child in TFS? I suspect that the answer is no as this is what I've experienced while using it. However, it seems that at certain times it would be really useful when there are different features being worked on that may have different approval cycl...
[ { "answer_id": 52841, "author": "Ben Scheirman", "author_id": 3381, "author_profile": "https://Stackoverflow.com/users/3381", "pm_score": 1, "selected": false, "text": "<p>AFAIK you can do this as long as the branches were created off of the same original folder.</p>\n\n<ul>\n<li>trunk/<...
2008/09/09
[ "https://Stackoverflow.com/questions/52824", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5416/" ]
Is it possible to merge to a branch that is not a direct parent or child in TFS? I suspect that the answer is no as this is what I've experienced while using it. However, it seems that at certain times it would be really useful when there are different features being worked on that may have different approval cycles (i...
I agree with Harpreet that you may want to revisit how you you have setup you branching structure. However you if you really want to perform this type of merge you can through something called a baseless merge. It runs from the tfs command prompt, ``` Tf merge /baseless <<source path>> <<target path>> /recursive ```...
52,842
<p><code>System.IO.Directory.GetFiles()</code> returns a <code>string[]</code>. What is the default sort order for the returned values? I'm assuming by name, but if so how much does the current culture effect it? Can you change it to something like creation date? </p> <p><strong>Update:</strong> MSDN points out tha...
[ { "answer_id": 52847, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": 3, "selected": false, "text": "<p></p>\n\n<pre class=\"lang-vb prettyprint-override\"><code>Dim Files() As String\nFiles = System.IO.Directory.GetFiles(\"C:\...
2008/09/09
[ "https://Stackoverflow.com/questions/52842", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3043/" ]
`System.IO.Directory.GetFiles()` returns a `string[]`. What is the default sort order for the returned values? I'm assuming by name, but if so how much does the current culture effect it? Can you change it to something like creation date? **Update:** MSDN points out that the sort order is not guaranteed for .Net 3.5,...
If you're interested in properties of the files such as CreationTime, then it would make more sense to use System.IO.DirectoryInfo.GetFileSystemInfos(). You can then sort these using one of the extension methods in System.Linq, e.g.: ``` DirectoryInfo di = new DirectoryInfo("C:\\"); FileSystemInfo[] files = di.GetFil...
52,844
<p>I am using a wxGenericDirCtrl, and I would like to know if there is a way to hide directories, I'd especially like to hide siblings of parent nodes.</p> <p>For example if my directory structure looks like this:</p> <pre><code>+-a | +-b | | | +-whatever | +-c | | | +-d | | | +-e | | | ...
[ { "answer_id": 60745, "author": "Gareth Simpson", "author_id": 147, "author_profile": "https://Stackoverflow.com/users/147", "pm_score": 0, "selected": false, "text": "<p>I don't think that's possible.</p>\n\n<p>It would be relatively easy to add this functionality to the underlying C++ ...
2008/09/09
[ "https://Stackoverflow.com/questions/52844", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3051/" ]
I am using a wxGenericDirCtrl, and I would like to know if there is a way to hide directories, I'd especially like to hide siblings of parent nodes. For example if my directory structure looks like this: ``` +-a | +-b | | | +-whatever | +-c | | | +-d | | | +-e | | | +-f | +-g ...
Listing/walking directories in Python is very easy, so I would recommend trying to "roll your own" using one of the simple tree controls (such as TreeCtrl or CustomTreeCtrl). It should really be quite easy to call the directory listing code when some directory is expanded and return the result.
52,874
<p>I have a piece of server-ish software written in Java to run on Windows and OS X. (It is not running on a server, but just a normal user's PC - something like a torrent client.) I would like the software to signal to the OS to keep the machine awake (prevent it from going into sleep mode) while it is active.</p> <p...
[ { "answer_id": 52882, "author": "Gulzar Nazim", "author_id": 4337, "author_profile": "https://Stackoverflow.com/users/4337", "pm_score": 0, "selected": false, "text": "<p>Run a command inside a timer like pinging the server..</p>\n" }, { "answer_id": 52885, "author": "zigdon"...
2008/09/09
[ "https://Stackoverflow.com/questions/52874", "https://Stackoverflow.com", "https://Stackoverflow.com/users/338/" ]
I have a piece of server-ish software written in Java to run on Windows and OS X. (It is not running on a server, but just a normal user's PC - something like a torrent client.) I would like the software to signal to the OS to keep the machine awake (prevent it from going into sleep mode) while it is active. Of course...
I use this code to keep my workstation from locking. It's currently only set to move the mouse once every minute, you could easily adjust it though. It's a hack, not an elegant solution. ``` import java.awt.*; import java.util.*; public class Hal{ public static void main(String[] args) throws Exception{ ...
52,880
<p>Does Google Reader have an API and if so, how can I get the count of the number of unread posts for a specific user knowing their username and password?</p>
[ { "answer_id": 52886, "author": "Gulzar Nazim", "author_id": 4337, "author_profile": "https://Stackoverflow.com/users/4337", "pm_score": 4, "selected": false, "text": "<p>It is <a href=\"http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI\" rel=\"nofollow noreferrer\">there</a>. Still ...
2008/09/09
[ "https://Stackoverflow.com/questions/52880", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383/" ]
Does Google Reader have an API and if so, how can I get the count of the number of unread posts for a specific user knowing their username and password?
This URL will give you a count of unread posts per feed. You can then iterate over the feeds and sum up the counts. <http://www.google.com/reader/api/0/unread-count?all=true> Here is a minimalist example in Python...parsing the xml/json and summing the counts is left as an exercise for the reader: ```py import urlli...
52,898
<p>I've noticed that Visual Studio 2008 is placing square brackets around column names in sql. Do the brackets offer any advantage? When I hand code T-SQL I've never bothered with them.</p> <p>Example:</p> <p>Visual Studio:</p> <pre><code>SELECT [column1], [column2] etc... </code></pre> <p>My own way:</p> <pre><co...
[ { "answer_id": 52900, "author": "Torlack", "author_id": 5243, "author_profile": "https://Stackoverflow.com/users/5243", "pm_score": 3, "selected": false, "text": "<p>The brackets can be used when column names are reserved words.</p>\n\n<p>If you are programatically generating the SQL sta...
2008/09/09
[ "https://Stackoverflow.com/questions/52898", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5433/" ]
I've noticed that Visual Studio 2008 is placing square brackets around column names in sql. Do the brackets offer any advantage? When I hand code T-SQL I've never bothered with them. Example: Visual Studio: ``` SELECT [column1], [column2] etc... ``` My own way: ``` SELECT column1, column2 etc... ```
The brackets are required if you use keywords or special chars in the column names or identifiers. You could name a column `[First Name]` (with a space) – but then you'd need to use brackets every time you referred to that column. The newer tools add them everywhere just in case or for consistency.
52,927
<p>I frequently find myself writing code like this:</p> <pre><code>List&lt;int&gt; list = new List&lt;int&gt; { 1, 3, 5 }; foreach (int i in list) { Console.Write("{0}\t", i.ToString()); } Console.WriteLine(); </code></pre> <p>Better would be something like this:</p> <pre><code>List&lt;int&gt; list = new List&lt...
[ { "answer_id": 52940, "author": "Jason Bunting", "author_id": 1790, "author_profile": "https://Stackoverflow.com/users/1790", "pm_score": 8, "selected": true, "text": "<p>Do this:</p>\n\n<pre><code>list.ForEach(i =&gt; Console.Write(\"{0}\\t\", i));\n</code></pre>\n\n<hr>\n\n<p>EDIT: To ...
2008/09/09
[ "https://Stackoverflow.com/questions/52927", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4593/" ]
I frequently find myself writing code like this: ``` List<int> list = new List<int> { 1, 3, 5 }; foreach (int i in list) { Console.Write("{0}\t", i.ToString()); } Console.WriteLine(); ``` Better would be something like this: ``` List<int> list = new List<int> { 1, 3, 5 }; Console.WriteLine("{0}\t", list); ``` ...
Do this: ``` list.ForEach(i => Console.Write("{0}\t", i)); ``` --- EDIT: To others that have responded - he wants them all on the same line, with tabs between them. :)
52,950
<p>I'm not too sure what is going on here, but sometimes a particular file in my repository will change the case of its name. e.g.,:</p> <p>before: <code>File.h</code></p> <p>after: <code>file.h</code></p> <p>I don't really care why this is happening, but this causes git to think it is a new file, and then I have to go...
[ { "answer_id": 53116, "author": "MarkB", "author_id": 2996, "author_profile": "https://Stackoverflow.com/users/2996", "pm_score": 9, "selected": true, "text": "<p>Since version 1.5.6 there is an <code>ignorecase</code> option available in the <code>[core]</code> section of <code>.git/con...
2008/09/09
[ "https://Stackoverflow.com/questions/52950", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3146/" ]
I'm not too sure what is going on here, but sometimes a particular file in my repository will change the case of its name. e.g.,: before: `File.h` after: `file.h` I don't really care why this is happening, but this causes git to think it is a new file, and then I have to go and change the file name back. Can you jus...
Since version 1.5.6 there is an `ignorecase` option available in the `[core]` section of `.git/config` e.g. add `ignorecase = true` To change it for just one repo, from that folder run: ``` git config core.ignorecase true ``` To change it globally: ``` git config --global core.ignorecase true ```
52,952
<p>So I'm using an IDataReader to hydrate some business objects, but I don't know at runtime exactly what fields will be in the reader. Any fields that aren't in the reader would be left null on the resulting object. How do you test if a reader contains a specific field without just wrapping it in a try/catch?</p>
[ { "answer_id": 299772, "author": "adparadox", "author_id": 1962, "author_profile": "https://Stackoverflow.com/users/1962", "pm_score": -1, "selected": false, "text": "<p>You can't just test reader[\"field\"] for null or DBNull because a IndexOutOfRangeException is thrown if the column is...
2008/09/09
[ "https://Stackoverflow.com/questions/52952", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4541/" ]
So I'm using an IDataReader to hydrate some business objects, but I don't know at runtime exactly what fields will be in the reader. Any fields that aren't in the reader would be left null on the resulting object. How do you test if a reader contains a specific field without just wrapping it in a try/catch?
This should do the trick: ``` Public Shared Function ReaderContainsColumn(ByVal reader As IDataReader, ByVal name As String) As Boolean For i As Integer = 0 To reader.FieldCount - 1 If reader.GetName(i).Equals(name, StringComparison.CurrentCultureIgnoreCase) Then Return True Next ...
52,954
<p>Right now my ant task looks like.</p> <pre><code>&lt;javadoc sourcepath="${source}" destdir="${doc}"&gt; &lt;link href="http://java.sun.com/j2se/1.5.0/docs/api/" /&gt; &lt;/javadoc&gt; </code></pre> <p>And I'm getting this warning:</p> <pre><code>javadoc: warning - Error fetching URL: http://java.sun.com/j2se...
[ { "answer_id": 52973, "author": "erickson", "author_id": 3474, "author_profile": "https://Stackoverflow.com/users/3474", "pm_score": 4, "selected": true, "text": "<p>You probably need the <a href=\"http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html\" rel=\"noreferrer\">http.pr...
2008/09/09
[ "https://Stackoverflow.com/questions/52954", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5118/" ]
Right now my ant task looks like. ``` <javadoc sourcepath="${source}" destdir="${doc}"> <link href="http://java.sun.com/j2se/1.5.0/docs/api/" /> </javadoc> ``` And I'm getting this warning: ``` javadoc: warning - Error fetching URL: http://java.sun.com/j2se/1.5.0/docs/api/package-list ``` How do I get the jav...
You probably need the [http.proxyHost and http.proxyPort system properties](http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html) set. For example, `ANT_OPTS="-Dhttp.proxyHost=proxy.y.com" ant doc` Alternatively, you could set the "offline" flag and provide a package list, but that could be a pain for the Jav...
52,964
<p>What is the best way to sort the results of a sql query into a random order within a stored procedure?</p>
[ { "answer_id": 52976, "author": "Jimmy", "author_id": 4435, "author_profile": "https://Stackoverflow.com/users/4435", "pm_score": 4, "selected": false, "text": "<pre><code>select foo from Bar order by newid()\n</code></pre>\n" }, { "answer_id": 52982, "author": "harpo", "...
2008/09/09
[ "https://Stackoverflow.com/questions/52964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5466/" ]
What is the best way to sort the results of a sql query into a random order within a stored procedure?
This is a duplicate of [SO# 19412](https://stackoverflow.com/questions/19412/how-to-request-a-random-row-in-sql). Here's the answer I gave there: ``` select top 1 * from mytable order by newid() ``` In SQL Server 2005 and up, you can use TABLESAMPLE to get a random sample that's repeatable: ``` SELECT FirstName, La...
52,981
<p>So, I have 2 database instances, one is for development in general, another was copied from development for unit tests.</p> <p>Something changed in the development database that I can't figure out, and I don't know how to see what is different.</p> <p>When I try to delete from a particular table, with for example:...
[ { "answer_id": 53000, "author": "w4ik", "author_id": 4232, "author_profile": "https://Stackoverflow.com/users/4232", "pm_score": 0, "selected": false, "text": "<p>You might have an open transaction on the dev db...that gets me sometimes on SQL Server</p>\n" }, { "answer_id": 5301...
2008/09/09
[ "https://Stackoverflow.com/questions/52981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/122/" ]
So, I have 2 database instances, one is for development in general, another was copied from development for unit tests. Something changed in the development database that I can't figure out, and I don't know how to see what is different. When I try to delete from a particular table, with for example: ``` delete from...
Hmm, applying the great oracle to this question, I came up with: <http://bytes.com/forum/thread830774.html> It seems to suggest that another table has a foreign key pointing at the problematic one, when that FK on the other table is dropped, the delete should work again. (Presumably you can re-create the foreign key ...
52,984
<p>How do I setup an Ant task to generate <a href="http://emma.sourceforge.net" rel="noreferrer">Emma</a> code coverage reports?</p>
[ { "answer_id": 52994, "author": "Rob Spieldenner", "author_id": 5118, "author_profile": "https://Stackoverflow.com/users/5118", "pm_score": 5, "selected": true, "text": "<p>To answer questions about where the source and instrumented directories are (these can be switched to whatever your...
2008/09/09
[ "https://Stackoverflow.com/questions/52984", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5118/" ]
How do I setup an Ant task to generate [Emma](http://emma.sourceforge.net) code coverage reports?
To answer questions about where the source and instrumented directories are (these can be switched to whatever your standard directory structure is): ``` <property file="build.properties" /> <property name="source" location="src/main/java" /> <property name="test.source" location="src/test/java" /> <property name="tar...
52,989
<p>I have a generic Repository&lt;T&gt; class I want to use with an ObjectDataSource. Repository&lt;T&gt; lives in a separate project called DataAccess. According to <a href="http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/767f1a821d9b23da/b1e045958ae427a5?lnk=st#b1e045958ae...
[ { "answer_id": 53106, "author": "Darren Kopp", "author_id": 77, "author_profile": "https://Stackoverflow.com/users/77", "pm_score": 5, "selected": true, "text": "<p>Do something like this.</p>\n\n<pre><code>Type type = typeof(Repository&lt;MessageCategory);\nstring assemblyQualifiedName ...
2008/09/09
[ "https://Stackoverflow.com/questions/52989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4160/" ]
I have a generic Repository<T> class I want to use with an ObjectDataSource. Repository<T> lives in a separate project called DataAccess. According to [this post from the MS newsgroups](http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/767f1a821d9b23da/b1e045958ae427a5?lnk=st#...
Do something like this. ``` Type type = typeof(Repository<MessageCategory); string assemblyQualifiedName = type.AssemblyQualifiedName; ``` get the value of assemblyQualifiedName and paste it into the TypeName field. Note that Type.GetType(string), the value passed in must be > > The assembly-qualified name of the ...
53,025
<p>I've been utilizing the <a href="http://en.wikipedia.org/wiki/Command_pattern" rel="nofollow noreferrer">command pattern</a> in my Flex projects, with asynchronous callback routes required between:</p> <ul> <li>whoever instantiated a given command object and the command object,</li> <li>the command object and the "...
[ { "answer_id": 53743, "author": "Theo", "author_id": 1109, "author_profile": "https://Stackoverflow.com/users/1109", "pm_score": 1, "selected": false, "text": "<p>Many of the Flex RPC classes, like <code>RemoteObject</code>, <code>HTTPService</code>, etc. return <a href=\"http://livedocs...
2008/09/09
[ "https://Stackoverflow.com/questions/53025", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4111/" ]
I've been utilizing the [command pattern](http://en.wikipedia.org/wiki/Command_pattern) in my Flex projects, with asynchronous callback routes required between: * whoever instantiated a given command object and the command object, * the command object and the "data access" object (i.e. someone who handles the remote p...
I'll try one more idea: Have your Data Access Object return their own AsyncTokens (or some other objects that encapsulate a pending call), instead of the AsyncToken that comes from the RPC call. So, in the DAO it would look something like this (this is very sketchy code): ``` public function deleteThing( id : String ...
53,026
<p>I have a table with an XML column. This column is storing some values I keep for configuring my application. I created it to have a more flexible schema. I can't find a way to update this column directly from the table view in SQL Management Studio. Other (INT or Varchar for example) columns are editable. I know I c...
[ { "answer_id": 53032, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 0, "selected": false, "text": "<p>I do not think you can use the Management Studio GUI to update XML-columns without writing the UPDATE-command yourself.</p>\n...
2008/09/09
[ "https://Stackoverflow.com/questions/53026", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1363/" ]
I have a table with an XML column. This column is storing some values I keep for configuring my application. I created it to have a more flexible schema. I can't find a way to update this column directly from the table view in SQL Management Studio. Other (INT or Varchar for example) columns are editable. I know I can ...
This is an old question, but I needed to do this today. The best I can come up with is to write a query that generates SQL code that can be edited in the query editor - it's sort of lame but it saves you copy/pasting stuff. Note: you may need to go into Tools > Options > Query Results > Results to Text and set the max...
53,041
<p>Visual Studio Solution files contain two GUID's per project entry. I figure one of them is from the AssemblyInfo.cs</p> <p>Does anyone know for sure where these come from, and what they are used for?</p>
[ { "answer_id": 53048, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 3, "selected": false, "text": "<p><a href=\"http://msdn.microsoft.com/en-us/library/bb165951(VS.80).aspx\" rel=\"noreferrer\">According to MSDN</a>: </p>\n\n<bl...
2008/09/09
[ "https://Stackoverflow.com/questions/53041", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1965/" ]
Visual Studio Solution files contain two GUID's per project entry. I figure one of them is from the AssemblyInfo.cs Does anyone know for sure where these come from, and what they are used for?
Neither GUID is the same GUID as from AssemblyInfo.cs (that is the GUID for the assembly itself, not tied to Visual Studio but the end product of the build). So, for a typical line in the sln file (open the .sln in notepad or editor-of-choice if you wish to see this): ``` Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFB...
53,046
<p>In python, there are some special variables and filenames that are surrounded by double-underscores. For example, there is the</p> <pre><code>__file__ </code></pre> <p>variable. I am only able to get them to show up correctly inside of a code block. What do I need to enter to get double underscores in regular ...
[ { "answer_id": 53052, "author": "Blorgbeard", "author_id": 369, "author_profile": "https://Stackoverflow.com/users/369", "pm_score": 6, "selected": true, "text": "<p>__file__</p>\n\n<p>Put a backslash before the first underscore.</p>\n\n<p>Like this:</p>\n\n<pre><code>\\__file__\n</code>...
2008/09/09
[ "https://Stackoverflow.com/questions/53046", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
In python, there are some special variables and filenames that are surrounded by double-underscores. For example, there is the ``` __file__ ``` variable. I am only able to get them to show up correctly inside of a code block. What do I need to enter to get double underscores in regular text without having them inte...
\_\_file\_\_ Put a backslash before the first underscore. Like this: ``` \__file__ ```
53,064
<p>I want to embed an .asp page on an html page. I cannot use an iframe. I tried:</p> <pre><code>&lt;object width="100%" height="1500" type="text/html" data="url.asp"&gt; alt : &lt;a href="url.asp"&gt;url&lt;/a&gt; &lt;/object&gt;" </code></pre> <p>works great in ff but not ie7. Any ideas? Is it possible to use th...
[ { "answer_id": 53083, "author": "Matthew Crumley", "author_id": 2214, "author_profile": "https://Stackoverflow.com/users/2214", "pm_score": 1, "selected": false, "text": "<p>You might be able to fake it using javascript. You could either use AJAX to load the page, then insert the HTML, o...
2008/09/09
[ "https://Stackoverflow.com/questions/53064", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5234/" ]
I want to embed an .asp page on an html page. I cannot use an iframe. I tried: ``` <object width="100%" height="1500" type="text/html" data="url.asp"> alt : <a href="url.asp">url</a> </object>" ``` works great in ff but not ie7. Any ideas? Is it possible to use the object tag to embed .asp pages for IE or does it on...
I've solved it in the past using Javascript and XMLHttp. It can get a bit hacky depending on the circumstances. In particular, you have to watch out for the inner page failing and how it affects/downgrades the outer one (hopefully you can keep it downgrading elegantly). Search for XMLHttp (or check [this great tutoria...
53,102
<p>From the <em>Immediate Window</em> in Visual Studio: </p> <pre><code>&gt; Path.Combine(@"C:\x", "y") "C:\\x\\y" &gt; Path.Combine(@"C:\x", @"\y") "\\y" </code></pre> <p>It seems that they should both be the same. </p> <p>The old FileSystemObject.BuildPath() didn't work this way...</p>
[ { "answer_id": 53110, "author": "elarson", "author_id": 5434, "author_profile": "https://Stackoverflow.com/users/5434", "pm_score": 2, "selected": false, "text": "<p>Not knowing the actual details, my guess is that it makes an attempt to join like you might join relative URIs. For exampl...
2008/09/09
[ "https://Stackoverflow.com/questions/53102", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3798/" ]
From the *Immediate Window* in Visual Studio: ``` > Path.Combine(@"C:\x", "y") "C:\\x\\y" > Path.Combine(@"C:\x", @"\y") "\\y" ``` It seems that they should both be the same. The old FileSystemObject.BuildPath() didn't work this way...
This is kind of a philosophical question (which perhaps only Microsoft can truly answer), since it's doing exactly what the documentation says. [System.IO.Path.Combine](http://msdn.microsoft.com/en-us/library/system.io.path.combine.aspx) "If path2 contains an absolute path, this method returns path2." [Here's the ac...
53,108
<p>I have a table similar to this:</p> <pre><code>CREATE TABLE example ( id integer primary key, name char(200), parentid integer, value integer); </code></pre> <p>I can use the parentid field to arrange data into a tree structure.</p> <p>Now here's the bit I can't work out. Given a parentid, is it possible ...
[ { "answer_id": 53119, "author": "George Mauer", "author_id": 5056, "author_profile": "https://Stackoverflow.com/users/5056", "pm_score": 0, "selected": false, "text": "<p>is this SQL Server? Couldn't you write a TSQL stored procedure that loops through and unions the results together? ...
2008/09/09
[ "https://Stackoverflow.com/questions/53108", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5324/" ]
I have a table similar to this: ``` CREATE TABLE example ( id integer primary key, name char(200), parentid integer, value integer); ``` I can use the parentid field to arrange data into a tree structure. Now here's the bit I can't work out. Given a parentid, is it possible to write an SQL statement to add ...
There are a few ways to do what you need in PostgreSQL. * If you can install modules, look at the tablefunc contrib. It has a connectby() function that handles traversing trees. <http://www.postgresql.org/docs/8.3/interactive/tablefunc.html> * Also check out the ltree contrib, which you could adapt your table to use: ...
53,112
<p>What are good ways of dealing with the issues surrounding plugin code that interacts with outside system?</p> <p>To give a concrete and representative example, suppose I would like to use Subversion and Eclipse to develop plugins for WordPress. The main code body of WordPress is installed on the webserver, and the ...
[ { "answer_id": 53119, "author": "George Mauer", "author_id": 5056, "author_profile": "https://Stackoverflow.com/users/5056", "pm_score": 0, "selected": false, "text": "<p>is this SQL Server? Couldn't you write a TSQL stored procedure that loops through and unions the results together? ...
2008/09/09
[ "https://Stackoverflow.com/questions/53112", "https://Stackoverflow.com", "https://Stackoverflow.com/users/277/" ]
What are good ways of dealing with the issues surrounding plugin code that interacts with outside system? To give a concrete and representative example, suppose I would like to use Subversion and Eclipse to develop plugins for WordPress. The main code body of WordPress is installed on the webserver, and the plugin cod...
There are a few ways to do what you need in PostgreSQL. * If you can install modules, look at the tablefunc contrib. It has a connectby() function that handles traversing trees. <http://www.postgresql.org/docs/8.3/interactive/tablefunc.html> * Also check out the ltree contrib, which you could adapt your table to use: ...
53,128
<p>I have a webapp that uses JNDI lookups to get a connection to the database.</p> <p>The connection works fine and returns the query no problems. The issue us that the connection does not close properly and is stuck in the 'sleep' mode (according to mysql administrator). This means that they become unusable nad then ...
[ { "answer_id": 53285, "author": "Binil Thomas", "author_id": 3973, "author_profile": "https://Stackoverflow.com/users/3973", "pm_score": 2, "selected": false, "text": "<p>You seem to be closing the connection properly - except for the case where prepStmt.close() throws a SQLException, I ...
2008/09/09
[ "https://Stackoverflow.com/questions/53128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3431280/" ]
I have a webapp that uses JNDI lookups to get a connection to the database. The connection works fine and returns the query no problems. The issue us that the connection does not close properly and is stuck in the 'sleep' mode (according to mysql administrator). This means that they become unusable nad then I run out ...
> > The issue us that the connection does not close properly and is stuck in the 'sleep' mode > > > This was actually only half right. The problem I ran into was actually that each app was defining a new connection to the database sever. So each time I closed all the connections App A would make a bunch of new co...
53,161
<p>what I'm after is something I can feed a number into and it will return the highest order bit. I'm sure there's a simple way. Below is an example output (left is the input)</p> <pre>1 -> 1 2 -> 2 3 -> 2 4 -> 4 5 -> 4 6 -> 4 7 -> 4 8 -> 8 9 -> 8 ... 63 -> 32</pre>
[ { "answer_id": 53174, "author": "nlucaroni", "author_id": 157, "author_profile": "https://Stackoverflow.com/users/157", "pm_score": 3, "selected": false, "text": "<p>Continually remove the low order bit comes to mind...</p>\n\n<pre><code>int highest_order_bit( int x )\n{\n int y = x;\...
2008/09/09
[ "https://Stackoverflow.com/questions/53161", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1057/" ]
what I'm after is something I can feed a number into and it will return the highest order bit. I'm sure there's a simple way. Below is an example output (left is the input) ``` 1 -> 1 2 -> 2 3 -> 2 4 -> 4 5 -> 4 6 -> 4 7 -> 4 8 -> 8 9 -> 8 ... 63 -> 32 ```
This should do the trick. ``` int hob (int num) { if (!num) return 0; int ret = 1; while (num >>= 1) ret <<= 1; return ret; } ``` hob(1234) returns 1024 hob(1024) returns 1024 hob(1023) returns 512
53,162
<p>Given:</p> <pre><code>e = 'a' + 'b' + 'c' + 'd' </code></pre> <p>How do I write the above in two lines?</p> <pre><code>e = 'a' + 'b' + 'c' + 'd' </code></pre>
[ { "answer_id": 53173, "author": "SCdF", "author_id": 1666, "author_profile": "https://Stackoverflow.com/users/1666", "pm_score": 5, "selected": false, "text": "<p>Put a <code>\\</code> at the end of your line or enclose the statement in parens <code>( .. )</code>. From <a href=\"http://w...
2008/09/09
[ "https://Stackoverflow.com/questions/53162", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4872/" ]
Given: ``` e = 'a' + 'b' + 'c' + 'd' ``` How do I write the above in two lines? ``` e = 'a' + 'b' + 'c' + 'd' ```
What is the line? You can just have arguments on the next line without any problems: ``` a = dostuff(blahblah1, blahblah2, blahblah3, blahblah4, blahblah5, blahblah6, blahblah7) ``` Otherwise you can do something like this: ``` if (a == True and b == False): ``` or with explicit line break: ``` ...
53,208
<p>In C++ Windows app, I launch several long running child processes (currently I use CreateProcess(...) to do this. </p> <p>I want the child processes to be automatically closed <strong>if my main processes crashes</strong> or is closed.</p> <p>Because of the requirement that this needs to work for a crash of the "p...
[ { "answer_id": 53212, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": -1, "selected": false, "text": "<p>You'd probably have to keep a list of the processes you start, and kill them off one by one when you exit your program. I...
2008/09/10
[ "https://Stackoverflow.com/questions/53208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/814/" ]
In C++ Windows app, I launch several long running child processes (currently I use CreateProcess(...) to do this. I want the child processes to be automatically closed **if my main processes crashes** or is closed. Because of the requirement that this needs to work for a crash of the "parent", I believe this would n...
The Windows API supports objects called "Job Objects". The following code will create a "job" that is configured to shut down all processes when the main application ends (when its handles are cleaned up). This code should only be run once.: ```cpp HANDLE ghJob = CreateJobObject( NULL, NULL); // GLOBAL if( ghJob == NU...
53,224
<p>I want to scrape some information off a football (soccer) web page using simple python regexp's. The problem is that players such as the first chap, ÄÄRITALO, comes out as &amp;#196;&amp;#196;RITALO!<br> That is, html uses escaped markup for the special characters, such as &amp;#196;</p> <p>Is there a simple way o...
[ { "answer_id": 53226, "author": "Nick Fortescue", "author_id": 5346, "author_profile": "https://Stackoverflow.com/users/5346", "pm_score": 0, "selected": false, "text": "<p>I haven't tried it myself, but have you tried</p>\n\n<p><a href=\"http://zesty.ca/python/scrape.html\" rel=\"nofoll...
2008/09/10
[ "https://Stackoverflow.com/questions/53224", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5346/" ]
I want to scrape some information off a football (soccer) web page using simple python regexp's. The problem is that players such as the first chap, ÄÄRITALO, comes out as &#196;&#196;RITALO! That is, html uses escaped markup for the special characters, such as &#196; Is there a simple way of reading the html into ...
I would recommend [BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/) for HTML scraping. You also need to tell it to convert HTML entities to the corresponding Unicode characters, like so: ``` >>> from BeautifulSoup import BeautifulSoup >>> html = "<html>&#196;&#196;RITALO!</html>" >>> soup = BeautifulS...
53,225
<p>Given a reference to a method, is there a way to check whether the method is bound to an object or not? Can you also access the instance that it's bound to?</p>
[ { "answer_id": 53237, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 2, "selected": false, "text": "<p><a href=\"https://docs.python.org/2/reference/datamodel.html?highlight=im_self\" rel=\"nofollow noreferrer\"><strong>i...
2008/09/10
[ "https://Stackoverflow.com/questions/53225", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
Given a reference to a method, is there a way to check whether the method is bound to an object or not? Can you also access the instance that it's bound to?
```py def isbound(method): return method.im_self is not None def instance(bounded_method): return bounded_method.im_self ``` [User-defined methods:](https://docs.python.org/2.7/reference/datamodel.html#index-40) > > When a user-defined method object is > created by retrieving a user-defined > function obje...
53,256
<p>I have two elements:</p> <pre><code>&lt;input a&gt; &lt;input b onclick="..."&gt; </code></pre> <p>When b is clicked, I want to access a and manipulate some of its data. A does not have a globally unique name, so <code>document.getElementsByName</code> is out. Looking into the event object, I thought <code>event.t...
[ { "answer_id": 53261, "author": "17 of 26", "author_id": 2284, "author_profile": "https://Stackoverflow.com/users/2284", "pm_score": 4, "selected": true, "text": "<p>If <code>a</code> and <code>b</code> are next to each other and have the same parent, you can use the <code>prevSibling</c...
2008/09/10
[ "https://Stackoverflow.com/questions/53256", "https://Stackoverflow.com", "https://Stackoverflow.com/users/429/" ]
I have two elements: ``` <input a> <input b onclick="..."> ``` When b is clicked, I want to access a and manipulate some of its data. A does not have a globally unique name, so `document.getElementsByName` is out. Looking into the event object, I thought `event.target.parentNode` would have some function like `getEl...
If `a` and `b` are next to each other and have the same parent, you can use the `prevSibling` property of `b` to find `a`.
53,260
<p>Say a user is browsing a website, and then performs some action which changes the database (let's say they add a comment). When the request to actually add the comment comes in, however, we find we need to force them to login before they can continue.</p> <p>Assume the login page asks for a username and password, a...
[ { "answer_id": 53267, "author": "Gulzar Nazim", "author_id": 4337, "author_profile": "https://Stackoverflow.com/users/4337", "pm_score": 4, "selected": false, "text": "<p>This is one good place where Ajax techniques might be helpful. When the user clicks the submit button, show the login...
2008/09/10
[ "https://Stackoverflow.com/questions/53260", "https://Stackoverflow.com", "https://Stackoverflow.com/users/797/" ]
Say a user is browsing a website, and then performs some action which changes the database (let's say they add a comment). When the request to actually add the comment comes in, however, we find we need to force them to login before they can continue. Assume the login page asks for a username and password, and redirec...
2 choices: 1. Write out the messy form from the login page, and JavaScript form.submit() it to the page. 2. Have the login page itself POST to the requesting page (with the previous values), and have that page's controller perform the login verification. Roll this into whatever logic you already have for detecting the...
53,292
<p>I'm trying to use the <a href="http://optiflag.rubyforge.org/discussion.html" rel="nofollow noreferrer">Optiflag</a> package in my Ruby code and whenever I try to do the necessary <code>require optiflag.rb</code>, my program fails with the standard <code>no such file to load -- optiflag</code> message. I added the d...
[ { "answer_id": 53313, "author": "Purfideas", "author_id": 4615, "author_profile": "https://Stackoverflow.com/users/4615", "pm_score": 3, "selected": true, "text": "<p>is it a gem? Are you doing </p>\n\n<pre><code>require 'rubygems'\nrequire 'optiflag'\n</code></pre>\n\n<p>or equivalent?<...
2008/09/10
[ "https://Stackoverflow.com/questions/53292", "https://Stackoverflow.com", "https://Stackoverflow.com/users/422/" ]
I'm trying to use the [Optiflag](http://optiflag.rubyforge.org/discussion.html) package in my Ruby code and whenever I try to do the necessary `require optiflag.rb`, my program fails with the standard `no such file to load -- optiflag` message. I added the directory with that library to my $PATH variable, but it's stil...
is it a gem? Are you doing ``` require 'rubygems' require 'optiflag' ``` or equivalent?
53,316
<p>I have a one to many relationship between two tables. The many table contains a clob column. The clob column looks like this in hibernate:</p> <pre><code>@CollectionOfElements(fetch = EAGER) @JoinTable(name = NOTE_JOIN_TABLE, joinColumns = @JoinColumn(name = "note")) @Column(name = "substitution") @IndexColumn(name...
[ { "answer_id": 53308, "author": "jodonnell", "author_id": 4223, "author_profile": "https://Stackoverflow.com/users/4223", "pm_score": 0, "selected": false, "text": "<p>Are you trying to implement a client to a web service hosted somewhere else? If so, Java's not necessary. You can do w...
2008/09/10
[ "https://Stackoverflow.com/questions/53316", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1666/" ]
I have a one to many relationship between two tables. The many table contains a clob column. The clob column looks like this in hibernate: ``` @CollectionOfElements(fetch = EAGER) @JoinTable(name = NOTE_JOIN_TABLE, joinColumns = @JoinColumn(name = "note")) @Column(name = "substitution") @IndexColumn(name = "listIndex"...
To follow up with jodonnell's comment, a Web service connection can be made in just about any server-side language. It is just that the API example they provided was in Java probably because PlanPlusOnline is written in Java. If you have a URL for the service, and an access key, then all you really need to do is figure...
53,353
<p>Below I present three options for simplifying my database access when only a single connection is involved (this is often the case for the web apps I work on).</p> <p>The general idea is to make the DB connection transparent, such that it connects the first time my script executes a query, and then it remains conne...
[ { "answer_id": 53399, "author": "Dhaust", "author_id": 242, "author_profile": "https://Stackoverflow.com/users/242", "pm_score": 4, "selected": true, "text": "<p>Doh! Someone else here at work figured this out. It was really simple and I should have been able to sort it, but hey, that's...
2008/09/10
[ "https://Stackoverflow.com/questions/53353", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Below I present three options for simplifying my database access when only a single connection is involved (this is often the case for the web apps I work on). The general idea is to make the DB connection transparent, such that it connects the first time my script executes a query, and then it remains connected until...
Doh! Someone else here at work figured this out. It was really simple and I should have been able to sort it, but hey, that's how it goes sometimes. Here the fix: On the web server, copy the 'aspnet\_client' folder from 'C:\Inetpub\wwwroot' to 'C:\Inetpub\wwwroot\your-website-name'. That's all we did and it's now...
53,365
<p><em>(see <a href="https://stackoverflow.com/questions/53316/hibernate-crops-clob-values-oddly">here</a> for the problem I'm trying to solve)</em></p> <p>How do you get hibernate to log clob values it's going to insert. It is logging other value types, such as Integer etc.</p> <p>I have the following in my log4j co...
[ { "answer_id": 53419, "author": "Marcio Aguiar", "author_id": 4213, "author_profile": "https://Stackoverflow.com/users/4213", "pm_score": 2, "selected": true, "text": "<p>Try using:</p>\n\n<pre><code>log4j.logger.net.sf.hibernate=DEBUG\nlog4j.logger.org.hibernate=DEBUG\n</code></pre>\n\n...
2008/09/10
[ "https://Stackoverflow.com/questions/53365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1666/" ]
*(see [here](https://stackoverflow.com/questions/53316/hibernate-crops-clob-values-oddly) for the problem I'm trying to solve)* How do you get hibernate to log clob values it's going to insert. It is logging other value types, such as Integer etc. I have the following in my log4j config: ``` log4j.logger.net.sf.hibe...
Try using: ``` log4j.logger.net.sf.hibernate=DEBUG log4j.logger.org.hibernate=DEBUG ``` That's the finest level you'll get. If it does not show the information you want, then it's not possible.
53,379
<p>Does anyone have examples of how to use <a href="http://www.oracle-base.com/articles/8i/DBMS_APPLICATION_INFO.php" rel="nofollow noreferrer">DBMS_APPLICATION_INFO</a> package with JBOSS? </p> <p>We have a various applications which run within JBOSS and share db pools. I would like, at the start of each session thes...
[ { "answer_id": 53449, "author": "Tony BenBrahim", "author_id": 80075, "author_profile": "https://Stackoverflow.com/users/80075", "pm_score": 2, "selected": true, "text": "<p>yes, you can write a wrapper class around your connection pool, and a wraper around the connection\nso lets say yo...
2008/09/10
[ "https://Stackoverflow.com/questions/53379", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3839/" ]
Does anyone have examples of how to use [DBMS\_APPLICATION\_INFO](http://www.oracle-base.com/articles/8i/DBMS_APPLICATION_INFO.php) package with JBOSS? We have a various applications which run within JBOSS and share db pools. I would like, at the start of each session these applications to identify themselves to the ...
yes, you can write a wrapper class around your connection pool, and a wraper around the connection so lets say you have: ``` OracleConnection conn=connectionPool.getConnection("java:scott@mydb"); ``` Change it to: ``` public class LoggingConnectionPool extends ConnectionPool{ public OracleConnection getConnec...
53,395
<p>I know the answer is not going to be simple, and I already use a couple of (I think ugly) cludges. I am simply looking for some elegant answers.</p> <p>Abstract class:</p> <pre><code>public interface IOtherObjects; public abstract class MyObjects&lt;T&gt; where T : IOtherObjects { ... public List&lt;T&gt; ...
[ { "answer_id": 53402, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 2, "selected": false, "text": "<p>In your case MyObjectsA and MyObjectsB don't have common predecessor. Generic class is template for <em>different</em> classes...
2008/09/10
[ "https://Stackoverflow.com/questions/53395", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5302/" ]
I know the answer is not going to be simple, and I already use a couple of (I think ugly) cludges. I am simply looking for some elegant answers. Abstract class: ``` public interface IOtherObjects; public abstract class MyObjects<T> where T : IOtherObjects { ... public List<T> ToList() { ... } } ...
If you have ``` class B : A class C : A ``` And you have ``` List<B> listB; List<C> listC; ``` that you wish to treat as a List of the parent type Then you should use ``` List<A> listA = listB.Cast<A>().Concat(listC.Cast<A>()).ToList() ```
53,435
<p>I'm doing something bad in my ASP.NET app. It could be the any number of CTP libraries I'm using or I'm just not disposing something properly. But when I redeploy my ASP.NET to my Vista IIS7 install or my server's IIS6 install I crash an IIS worker process.</p> <p>I've narrowed the problem down to my HTTP crawler, ...
[ { "answer_id": 53457, "author": "Gareth Jenkins", "author_id": 1521, "author_profile": "https://Stackoverflow.com/users/1521", "pm_score": 1, "selected": false, "text": "<p>A quick search found <a href=\"http://www.iisfaq.com/default.aspx?view=P197\" rel=\"nofollow noreferrer\">IISState<...
2008/09/10
[ "https://Stackoverflow.com/questions/53435", "https://Stackoverflow.com", "https://Stackoverflow.com/users/209/" ]
I'm doing something bad in my ASP.NET app. It could be the any number of CTP libraries I'm using or I'm just not disposing something properly. But when I redeploy my ASP.NET to my Vista IIS7 install or my server's IIS6 install I crash an IIS worker process. I've narrowed the problem down to my HTTP crawler, which is a...
Download Debugging tools for Windows: <http://www.microsoft.com/whdc/DevTools/Debugging/default.mspx> Debugging Tools for Windows has has a script (ADPLUS) that allows you to create dumps when a process CRASHES: <http://support.microsoft.com/kb/286350> The command should be something like (if you are using IIS6): ``...
53,472
<p>I have some Ruby code which takes dates on the command line in the format:</p> <pre><code>-d 20080101,20080201..20080229,20080301 </code></pre> <p>I want to run for all dates between <code>20080201</code> and <code>20080229</code> inclusive and the other dates present in the list.</p> <p>I can get the string <cod...
[ { "answer_id": 53504, "author": "Purfideas", "author_id": 4615, "author_profile": "https://Stackoverflow.com/users/4615", "pm_score": 2, "selected": false, "text": "<p>assuming you want the range to iterate properly through months etc, try</p>\n\n<pre><code>require 'date'\n\nends = '2008...
2008/09/10
[ "https://Stackoverflow.com/questions/53472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4121/" ]
I have some Ruby code which takes dates on the command line in the format: ``` -d 20080101,20080201..20080229,20080301 ``` I want to run for all dates between `20080201` and `20080229` inclusive and the other dates present in the list. I can get the string `20080201..20080229`, so is the best way to convert this to...
But then just do ``` ends = '20080201..20080229'.split('..').map{|d| Integer(d)} ends[0]..ends[1] ``` anyway I don't recommend eval, for security reasons
53,473
<p>I am trying to apply styles to HTML tags dynamically by reading in the value of certain HTML attributes and applying a class name based on their values. For instance, if I have:</p> <pre><code>&lt;p height="30"&gt; </code></pre> <p>I want to apply a <code>class="h30"</code> to that paragraph so that I can style it...
[ { "answer_id": 53475, "author": "Frank Krueger", "author_id": 338, "author_profile": "https://Stackoverflow.com/users/338", "pm_score": 0, "selected": false, "text": "<p>Attributes are just properties (usually). So just try:</p>\n\n<pre><code>for (e in ...) {\n if (e.height == 30) {\n...
2008/09/10
[ "https://Stackoverflow.com/questions/53473", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5512/" ]
I am trying to apply styles to HTML tags dynamically by reading in the value of certain HTML attributes and applying a class name based on their values. For instance, if I have: ``` <p height="30"> ``` I want to apply a `class="h30"` to that paragraph so that I can style it in my style sheet. I can't find any inform...
I would highly recommend using something like jquery where adding classes is trivial: ``` $("#someId").addClass("newClass"); ``` so in your case: ``` $("p[height='30']").addClass("h30"); ``` so this selects all paragraph tags where the height attribute is 30 and adds the class h30 to it.
53,480
<p>Hey, I'm using <a href="http://en.wikipedia.org/wiki/Levenshtein_distance" rel="nofollow noreferrer">Levenshteins</a> algorithm to get distance between source and target string.</p> <p>also I have method which returns value from 0 to 1:</p> <pre><code>/// &lt;summary&gt; /// Gets the similarity between two strings...
[ { "answer_id": 53531, "author": "Greg", "author_id": 4123, "author_profile": "https://Stackoverflow.com/users/4123", "pm_score": 3, "selected": false, "text": "<p>It sounds like what you want may be a longest substring match. That is, in your example, two files like</p>\n\n<p>trash..thas...
2008/09/10
[ "https://Stackoverflow.com/questions/53480", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5369/" ]
Hey, I'm using [Levenshteins](http://en.wikipedia.org/wiki/Levenshtein_distance) algorithm to get distance between source and target string. also I have method which returns value from 0 to 1: ``` /// <summary> /// Gets the similarity between two strings. /// All relation scores are in the [0, 1] range, /// which me...
Your problem here may be distinguishing between noise words and useful data: * Rolling\_Stones.Best\_of\_2003.Wild\_Horses.mp3 * Super.Quality.Wild\_Horses.mp3 * Tori\_Amos.Wild\_Horses.mp3 You may need to produce a dictionary of noise words to ignore. That seems clunky, but I'm not sure there's an algorithm that can...
53,482
<p>I have long since forgotten the password for the root user on one of my boxes. Is there a way I can change it without having to log in to the instance, or will I have to reinstall?</p>
[ { "answer_id": 53483, "author": "Nick Stinemates", "author_id": 4960, "author_profile": "https://Stackoverflow.com/users/4960", "pm_score": 2, "selected": false, "text": "<p>A quick Google resulted in this answer. In the root shell type:</p>\n\n<pre><code>mysqladmin -u root password &lt;...
2008/09/10
[ "https://Stackoverflow.com/questions/53482", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4960/" ]
I have long since forgotten the password for the root user on one of my boxes. Is there a way I can change it without having to log in to the instance, or will I have to reinstall?
**Step 1** Stop database: ``` shell> /etc/init.d/mysql stop ``` **Step 2** Restart database * without password autentification * without connection to the network Access to database is only possible through it's sock file '/var/lib/mysql/mysql.sock'. ``` shell> mysqld --user=mysql --pid-file=/var/lib/mysql/mysq...
53,491
<p>How do I enable external access to MySQL Server? I can connect locally but I cannot connect from another box on the network.</p> <p>I just tried</p> <pre><code>grant all privileges on *.* to root@'%' identified by '*****' with grant option; </code></pre> <p>And restarted MySQL Server with no success.</p>
[ { "answer_id": 53512, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 6, "selected": true, "text": "<p>You probably have to edit the configuration file (usually my.cnf) to listen in the external interface instead of on...
2008/09/10
[ "https://Stackoverflow.com/questions/53491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4960/" ]
How do I enable external access to MySQL Server? I can connect locally but I cannot connect from another box on the network. I just tried ``` grant all privileges on *.* to root@'%' identified by '*****' with grant option; ``` And restarted MySQL Server with no success.
You probably have to edit the configuration file (usually my.cnf) to listen in the external interface instead of on localhost only. Change the `bind-address` parameter to your machine's IP address. If this is an old MySQL installation, you should comment out the skip-networking parameter. Afterwards, restart MySQL a...
53,497
<p>I'm having trouble writing a regular expression that matches valid IPv6 addresses, including those in their compressed form (with <code>::</code> or leading zeros omitted from each byte pair). </p> <p>Can someone suggest a regular expression that would fulfill the requirement?</p> <p>I'm considering expanding eac...
[ { "answer_id": 53499, "author": "Factor Mystic", "author_id": 1569, "author_profile": "https://Stackoverflow.com/users/1569", "pm_score": 5, "selected": false, "text": "<p>From \"<a href=\"http://vernon.mauery.com/content/projects/linux/ipv6_regex\" rel=\"noreferrer\">IPv6 regex</a>\": <...
2008/09/10
[ "https://Stackoverflow.com/questions/53497", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
I'm having trouble writing a regular expression that matches valid IPv6 addresses, including those in their compressed form (with `::` or leading zeros omitted from each byte pair). Can someone suggest a regular expression that would fulfill the requirement? I'm considering expanding each byte pair and matching the ...
I was unable to get @Factor Mystic's answer to work with POSIX regular expressions, so I wrote one that works with POSIX regular expressions and PERL regular expressions. It should match: * IPv6 addresses * zero compressed IPv6 addresses ([section 2.2 of rfc5952](https://www.rfc-editor.org/rfc/rfc5952#section-2.2)) *...
53,501
<p>I am developing console application in .Net and I want to change a behavior a little based on information that application was started from cmd.exe or from explorer.exe. Is it possible?</p>
[ { "answer_id": 53508, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 2, "selected": false, "text": "<p>The <a href=\"http://msdn.microsoft.com/en-us/library/ms682489(VS.85).aspx\" rel=\"nofollow noreferrer\">CreateToolhelp32Snap...
2008/09/10
[ "https://Stackoverflow.com/questions/53501", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2361/" ]
I am developing console application in .Net and I want to change a behavior a little based on information that application was started from cmd.exe or from explorer.exe. Is it possible?
``` Process this_process = Process.GetCurrentProcess(); int parent_pid = 0; using (ManagementObject MgmtObj = new ManagementObject("win32_process.handle='" + this_process.Id.ToString() + "'")) { MgmtObj.Get(); parent_pid = Convert.ToInt32(MgmtObj["ParentProcessId"]); } string parent_process_name = Process.GetPr...
53,513
<p>For example, if passed the following:</p> <pre><code>a = [] </code></pre> <p>How do I check to see if <code>a</code> is empty?</p>
[ { "answer_id": 53522, "author": "Patrick", "author_id": 429, "author_profile": "https://Stackoverflow.com/users/429", "pm_score": 14, "selected": true, "text": "<pre><code>if not a:\n print(&quot;List is empty&quot;)\n</code></pre>\n<p>Using the <a href=\"https://docs.python.org/libra...
2008/09/10
[ "https://Stackoverflow.com/questions/53513", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4872/" ]
For example, if passed the following: ``` a = [] ``` How do I check to see if `a` is empty?
``` if not a: print("List is empty") ``` Using the [implicit booleanness](https://docs.python.org/library/stdtypes.html#truth-value-testing) of the empty `list` is quite Pythonic.
53,543
<p>Having tries to target two of these environments at the same time I can safely say the if you have to use a database etc. you end up having to write unique code for that environment. Have you got a great way to handle this situation?</p>
[ { "answer_id": 53549, "author": "Daren Thomas", "author_id": 2260, "author_profile": "https://Stackoverflow.com/users/2260", "pm_score": 4, "selected": false, "text": "<p>If you <em>do</em> find you need to write unique code for an environment, use pythons </p>\n\n<pre><code>import mymod...
2008/09/10
[ "https://Stackoverflow.com/questions/53543", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4491/" ]
Having tries to target two of these environments at the same time I can safely say the if you have to use a database etc. you end up having to write unique code for that environment. Have you got a great way to handle this situation?
If you *do* find you need to write unique code for an environment, use pythons ``` import mymodule_jython as mymodule import mymodule_cpython as mymodule ``` have this stuff in a simple module (''module\_importer''?) and write your code like this: ``` from module_importer import mymodule ``` This way, all you n...
53,545
<p>I have an exe with an <code>App.Config</code> file. Now I want to create a wrapper dll around the exe in order to consume some of the functionalities.</p> <p>The question is how can I access the app.config property in the exe from the wrapper dll?</p> <p>Maybe I should be a little bit more in my questions, I have ...
[ { "answer_id": 53552, "author": "Gishu", "author_id": 1695, "author_profile": "https://Stackoverflow.com/users/1695", "pm_score": -1, "selected": false, "text": "<p>It's an xml file, you can use Linq-XML or DOM based approaches to parse out the relevant information.<br>\n(that said I'd q...
2008/09/10
[ "https://Stackoverflow.com/questions/53545", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3834/" ]
I have an exe with an `App.Config` file. Now I want to create a wrapper dll around the exe in order to consume some of the functionalities. The question is how can I access the app.config property in the exe from the wrapper dll? Maybe I should be a little bit more in my questions, I have the following app.config con...
After some testing, I found a way to do this. 1. Add the App.Config file to the test project. Use "Add as a link" option. 2. Use `System.Configuration.ConfigurationManager.AppSettings["myKey"]` to access the value.
53,562
<p>What are the steps required to enable Hibernate's second-level cache, when using the Java Persistence API (annotated entities)? How do I check that it's working? I'm using JBoss 4.2.2.GA.</p> <p>From the Hibernate documentation, it seems that I need to enable the cache and specify a cache provider in <em>persistenc...
[ { "answer_id": 53992, "author": "Tim Howland", "author_id": 4276, "author_profile": "https://Stackoverflow.com/users/4276", "pm_score": 3, "selected": true, "text": "<p>I believe you need to add the cache annotations to tell hibernate how to use the second-level cache (read-only, read-wr...
2008/09/10
[ "https://Stackoverflow.com/questions/53562", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2670/" ]
What are the steps required to enable Hibernate's second-level cache, when using the Java Persistence API (annotated entities)? How do I check that it's working? I'm using JBoss 4.2.2.GA. From the Hibernate documentation, it seems that I need to enable the cache and specify a cache provider in *persistence.xml*, like:...
I believe you need to add the cache annotations to tell hibernate how to use the second-level cache (read-only, read-write, etc). This was the case in my app (using spring / traditional hibernate and ehcache, so your mileage may vary). Once the caches were indicated, I started seeing messages that they were in use from...
53,569
<p>What is the best way to get a log of commits on a branch since the time it was branched from the current branch? My solution so far is:</p> <pre><code>git log $(git merge-base HEAD branch)..branch </code></pre> <p>The documentation for <a href="http://git-scm.com/docs/git-diff" rel="noreferrer">git-diff</a> indica...
[ { "answer_id": 53573, "author": "Lily Ballard", "author_id": 582, "author_profile": "https://Stackoverflow.com/users/582", "pm_score": 9, "selected": true, "text": "<p>In the context of a revision list, <code>A...B</code> is how <code>git-rev-parse</code> defines it. git-log takes a revi...
2008/09/10
[ "https://Stackoverflow.com/questions/53569", "https://Stackoverflow.com", "https://Stackoverflow.com/users/893/" ]
What is the best way to get a log of commits on a branch since the time it was branched from the current branch? My solution so far is: ``` git log $(git merge-base HEAD branch)..branch ``` The documentation for [git-diff](http://git-scm.com/docs/git-diff) indicates that `git diff A...B` is equivalent to `git diff $...
In the context of a revision list, `A...B` is how `git-rev-parse` defines it. git-log takes a revision list. `git-diff` does not take a list of revisions - it takes one or two revisions, and has defined the `A...B` syntax to mean how it's defined in the `git-diff` manpage. If `git-diff` did not explicitly define `A...B...
53,599
<p>Ulimately I just wanted to extract strings from the .rc file so I could translate them, but anything that goes with .rc files works for me.</p>
[ { "answer_id": 53697, "author": "Thomas", "author_id": 4980, "author_profile": "https://Stackoverflow.com/users/4980", "pm_score": 1, "selected": false, "text": "<p>Maybe this helps? (<a href=\"http://social.msdn.microsoft.com/forums/en-US/regexp/thread/5e87fce9-ec73-42eb-b2eb-c821e95e0d...
2008/09/10
[ "https://Stackoverflow.com/questions/53599", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4880/" ]
Ulimately I just wanted to extract strings from the .rc file so I could translate them, but anything that goes with .rc files works for me.
I'd consider usage of [gettext](http://en.wikipedia.org/wiki/Gettext) and [.PO files](http://gnu.cs.pu.edu.tw/software/gettext/manual/html_node/PO-Files.html), if your program fits GNU license 1) I'd suggest extracting from .rc files using state machine algorithm. ``` void ProcessLine(const char * str) { if (strst...
53,623
<p>I want to get whois information of a domain name from my c#/java programs. Is there a simple way to do this? </p>
[ { "answer_id": 53631, "author": "Thomas", "author_id": 4980, "author_profile": "https://Stackoverflow.com/users/4980", "pm_score": 2, "selected": false, "text": "<p>I think, the easiest way is a socket connection to a whois server on port 43. Send the domainname followed by a newline and...
2008/09/10
[ "https://Stackoverflow.com/questions/53623", "https://Stackoverflow.com", "https://Stackoverflow.com/users/184/" ]
I want to get whois information of a domain name from my c#/java programs. Is there a simple way to do this?
I found a perfect C# example on dotnet-snippets.com (*which doesn't exist anymore*). It's 11 lines of code to copy and paste straight into your own application. ``` /// <summary> /// Gets the whois information. /// </summary> /// <param name="whoisServer">The whois server.</param> /// <param name="url">The URL.</par...
53,629
<p>Is it possible to see the history of changes to a particular line of code in a Subversion repository?</p> <p>I'd like, for instance, to be able to see when a particular statement was added or when that statement was changed, even if its line number is not the same any more.</p>
[ { "answer_id": 53633, "author": "Maximilian", "author_id": 1733, "author_profile": "https://Stackoverflow.com/users/1733", "pm_score": 0, "selected": false, "text": "<p>svn blame shows you which checkin modified any line in a file the last time.</p>\n\n<p>This works on old revisions too....
2008/09/10
[ "https://Stackoverflow.com/questions/53629", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1428/" ]
Is it possible to see the history of changes to a particular line of code in a Subversion repository? I'd like, for instance, to be able to see when a particular statement was added or when that statement was changed, even if its line number is not the same any more.
I don't know a method for tracking statements through time in Subversion. It is simple however to see when any particular line in a file was last changed using `svn blame`. Check the SVNBook: [`svn blame` reference](http://svnbook.red-bean.com/en/1.7/svn.ref.svn.c.blame.html): **Synopsis** ``` svn blame TARGET[@REV]...
53,664
<p>I've started using Vim to develop Perl scripts and am starting to find it very powerful. </p> <p>One thing I like is to be able to open multiple files at once with:</p> <pre><code>vi main.pl maintenance.pl </code></pre> <p>and then hop between them with:</p> <pre><code>:n :prev </code></pre> <p>and see which fi...
[ { "answer_id": 53667, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 5, "selected": false, "text": "<p>Vim (but not the original Vi!) has tabs which I find (in many contexts) superior to buffers. You can say <code>:tab...
2008/09/10
[ "https://Stackoverflow.com/questions/53664", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4639/" ]
I've started using Vim to develop Perl scripts and am starting to find it very powerful. One thing I like is to be able to open multiple files at once with: ``` vi main.pl maintenance.pl ``` and then hop between them with: ``` :n :prev ``` and see which file are open with: ``` :args ``` And to add a file, I ...
Why not use tabs (introduced in Vim 7)? You can switch between tabs with `:tabn` and `:tabp`, With `:tabe <filepath>` you can add a new tab; and with a regular `:q` or `:wq` you close a tab. If you map `:tabn` and `:tabp` to your `F7`/`F8` keys you can easily switch between files. If there are not that many files or y...
53,676
<p>When trying to connect to an <code>ORACLE</code> user via TOAD (Quest Software) or any other means (<code>Oracle Enterprise Manager</code>) I get this error:</p> <blockquote> <p><code>ORA-011033: ORACLE initialization or shutdown in progress</code></p> </blockquote>
[ { "answer_id": 53684, "author": "rohancragg", "author_id": 5351, "author_profile": "https://Stackoverflow.com/users/5351", "pm_score": 8, "selected": true, "text": "<p>After some googling, I found the advice to do the following, and it worked:</p>\n\n<pre><code>SQL&gt; startup mount\n\nO...
2008/09/10
[ "https://Stackoverflow.com/questions/53676", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5351/" ]
When trying to connect to an `ORACLE` user via TOAD (Quest Software) or any other means (`Oracle Enterprise Manager`) I get this error: > > `ORA-011033: ORACLE initialization or shutdown in progress` > > >
After some googling, I found the advice to do the following, and it worked: ``` SQL> startup mount ORACLE Instance started SQL> recover database Media recovery complete SQL> alter database open; Database altered ```
53,728
<p>I am not concerned about other kinds of attacks. Just want to know whether HTML Encode can prevent all kinds of XSS attacks.</p> <p>Is there some way to do an XSS attack even if HTML Encode is used?</p>
[ { "answer_id": 53739, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": -1, "selected": false, "text": "<p>I don't believe so. Html Encode converts all functional characters (characters which could be interpreted by the browser...
2008/09/10
[ "https://Stackoverflow.com/questions/53728", "https://Stackoverflow.com", "https://Stackoverflow.com/users/184/" ]
I am not concerned about other kinds of attacks. Just want to know whether HTML Encode can prevent all kinds of XSS attacks. Is there some way to do an XSS attack even if HTML Encode is used?
No. Putting aside the subject of allowing some tags (not really the point of the question), HtmlEncode simply does NOT cover all XSS attacks. For instance, consider server-generated client-side javascript - the server dynamically outputs htmlencoded values directly into the client-side javascript, htmlencode will **n...
53,734
<p>If you're creating a temporary table within a stored procedure and want to add an index or two on it, to improve the performance of any additional statements made against it, what is the best approach? Sybase says <a href="http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc20020_1251/html/databases/data...
[ { "answer_id": 53814, "author": "Eric Z Beard", "author_id": 1219, "author_profile": "https://Stackoverflow.com/users/1219", "pm_score": 2, "selected": false, "text": "<p>What's the problem with adding the indexes after you put data into the temp table?</p>\n\n<p>One thing you need to be...
2008/09/10
[ "https://Stackoverflow.com/questions/53734", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1030/" ]
If you're creating a temporary table within a stored procedure and want to add an index or two on it, to improve the performance of any additional statements made against it, what is the best approach? Sybase says [this](http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc20020_1251/html/databases/databases...
A few thoughts: * If your temporary table is so big that you have to index it, then is there a better way to solve the problem? * You can force it to use the index (if you are sure that the index is the correct way to access the table) by giving an optimiser hint, of the form: ``` SELECT * FROM #table (index idI...
53,744
<p>I would like to know how can i escape a # in velocity. Backslash seems to escape it but it prints itself as well</p> <p>This: </p> <pre><code>\#\# </code></pre> <p>prints: </p> <pre><code>\#\# </code></pre> <p>I would like: </p> <pre><code>## </code></pre>
[ { "answer_id": 53747, "author": "Thomas", "author_id": 4980, "author_profile": "https://Stackoverflow.com/users/4980", "pm_score": 3, "selected": false, "text": "<p>Maybe, the following site helps? <a href=\"http://velocity.apache.org/tools/1.4/generic/EscapeTool.html\" rel=\"nofollow no...
2008/09/10
[ "https://Stackoverflow.com/questions/53744", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2138/" ]
I would like to know how can i escape a # in velocity. Backslash seems to escape it but it prints itself as well This: ``` \#\# ``` prints: ``` \#\# ``` I would like: ``` ## ```
If you don't want to bother with the EscapeTool, you can do this: ``` #set( $H = '#' ) $H$H ```
53,757
<p>Which compiles to faster code: "ans = n * 3" or "ans = n+(n*2)"?</p> <p>Assuming that n is either an int or a long, and it is is running on a modern Win32 Intel box.</p> <p>Would this be different if there was some dereferencing involved, that is, which of these would be faster?</p> <pre> long a; long *pn;...
[ { "answer_id": 53759, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 7, "selected": true, "text": "<p>IMO such micro-optimization is not necessary unless you work with some exotic compiler. I would put readability on the first pl...
2008/09/10
[ "https://Stackoverflow.com/questions/53757", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3137/" ]
Which compiles to faster code: "ans = n \* 3" or "ans = n+(n\*2)"? Assuming that n is either an int or a long, and it is is running on a modern Win32 Intel box. Would this be different if there was some dereferencing involved, that is, which of these would be faster? ``` long a; long *pn; long ans; ... *...
IMO such micro-optimization is not necessary unless you work with some exotic compiler. I would put readability on the first place.
53,786
<p>I am trying to automate functional testing of a server using a realistic frequency distribution of requests. (sort of load testing, sort of simulation)</p> <p>I've chosen the <a href="http://en.wikipedia.org/wiki/Weibull_distribution" rel="nofollow noreferrer">Weibull</a> distribution as it "sort of" matches the di...
[ { "answer_id": 53791, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 1, "selected": false, "text": "<p>Why don't you try <a href=\"http://grinder.sourceforge.net\" rel=\"nofollow noreferrer\">The Grinder 3</a> to load...
2008/09/10
[ "https://Stackoverflow.com/questions/53786", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5357/" ]
I am trying to automate functional testing of a server using a realistic frequency distribution of requests. (sort of load testing, sort of simulation) I've chosen the [Weibull](http://en.wikipedia.org/wiki/Weibull_distribution) distribution as it "sort of" matches the distribution I've observed (ramps up quickly, dro...
This is quick and probably not that accurate, but if you calculate the PDF yourself, then at least you make it easier to lay several smaller/larger ones on a single timeline. `dev` is the std deviation in the Guassian noise, which controls the roughness. Note that this is *not* the 'right' way to generate what you want...
53,811
<p>Do you normally set your compiler to optimize for maximum speed or smallest code size? or do you manually configure individual optimization settings? Why?</p> <p>I notice most of the time people tend to just leave compiler optimization settings to their default state, which with visual c++ means max speed. I've alw...
[ { "answer_id": 53819, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 0, "selected": false, "text": "<p>We always use maximize for optimal speed but then, all the code I write in C++ is somehow related to bioinformatics...
2008/09/10
[ "https://Stackoverflow.com/questions/53811", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4086/" ]
Do you normally set your compiler to optimize for maximum speed or smallest code size? or do you manually configure individual optimization settings? Why? I notice most of the time people tend to just leave compiler optimization settings to their default state, which with visual c++ means max speed. I've always felt t...
As a Gentoo user I have tried quite a few optimizations on the complete OS and there have been endless discussions on the [Gentoo forums](http://forums.gentoo.org/) about it. Some good flags for GCC can be found in the [wiki](http://gentoo-wiki.com/Safe_Cflags). In short, optimizing for size worked best on an old Pent...
53,820
<p>In the application I'm developping (in Java/swing), I have to show a full screen window on the <em>second</em> screen of the user. I did this using a code similar to the one you'll find below... Be, as soon as I click in a window opened by windows explorer, or as soon as I open windows explorer (i'm using windows XP...
[ { "answer_id": 53831, "author": "John Meagher", "author_id": 3535, "author_profile": "https://Stackoverflow.com/users/3535", "pm_score": 2, "selected": true, "text": "<p>Usually when an application is in \"full screen\" mode it will take over the entire desktop. For a user to get to ano...
2008/09/10
[ "https://Stackoverflow.com/questions/53820", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2965/" ]
In the application I'm developping (in Java/swing), I have to show a full screen window on the *second* screen of the user. I did this using a code similar to the one you'll find below... Be, as soon as I click in a window opened by windows explorer, or as soon as I open windows explorer (i'm using windows XP), the ful...
Usually when an application is in "full screen" mode it will take over the entire desktop. For a user to get to another window they would have to alt-tab to it. At that point windows would minimize the full screen app so that the other application could come to the front. This sounds like it may be a bug (undocumente...
53,824
<p>I am attempting to use the .Net System.Security.SslStream class to process the server side of a SSL/TLS stream with client authentication.</p> <p>To perform the handshake, I am using this code:</p> <pre><code>SslStream sslStream = new SslStream(innerStream, false, RemoteCertificateValidation, LocalCertificateSelec...
[ { "answer_id": 54321, "author": "Peter Ritchie", "author_id": 5620, "author_profile": "https://Stackoverflow.com/users/5620", "pm_score": 2, "selected": false, "text": "<p>What the certificate validation is doing is validating all certificates in the chain. In order to truely do that it...
2008/09/10
[ "https://Stackoverflow.com/questions/53824", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5542/" ]
I am attempting to use the .Net System.Security.SslStream class to process the server side of a SSL/TLS stream with client authentication. To perform the handshake, I am using this code: ``` SslStream sslStream = new SslStream(innerStream, false, RemoteCertificateValidation, LocalCertificateSelectionCallback); sslStr...
It does not look like this is currently possible using the .NET libraries. I solved it by using the Mono class library implementation of System.Security.SslStream, which gives better access to overriding the servers behavior during the handshake.
53,844
<p>I would like to do the equivalent of:</p> <pre><code>object result = Eval("1 + 3"); string now = Eval("System.DateTime.Now().ToString()") as string </code></pre> <p>Following Biri s <a href="http://www.codeproject.com/KB/cs/evalcscode.aspx" rel="noreferrer">link</a>, I got this snippet (modified to remove obsol...
[ { "answer_id": 54339, "author": "JJJ", "author_id": 5547, "author_profile": "https://Stackoverflow.com/users/5547", "pm_score": 1, "selected": false, "text": "<blockquote>\n <p>What are the performance implications of doing this?</p>\n</blockquote>\n\n<p>We use a system based on somethi...
2008/09/10
[ "https://Stackoverflow.com/questions/53844", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2260/" ]
I would like to do the equivalent of: ``` object result = Eval("1 + 3"); string now = Eval("System.DateTime.Now().ToString()") as string ``` Following Biri s [link](http://www.codeproject.com/KB/cs/evalcscode.aspx), I got this snippet (modified to remove obsolete method `ICodeCompiler.CreateCompiler()`: ``` priv...
I have written an open source project, [Dynamic Expresso](https://github.com/davideicardi/DynamicExpresso/), that can convert text expression written using a C# syntax into delegates (or expression tree). Text expressions are parsed and transformed into [Expression Trees](http://msdn.microsoft.com/en-us/library/bb39795...
53,849
<p>Java has a convenient split method:</p> <pre><code>String str = "The quick brown fox"; String[] results = str.split(" "); </code></pre> <p>Is there an easy way to do this in C++?</p>
[ { "answer_id": 53862, "author": "vzczc", "author_id": 224, "author_profile": "https://Stackoverflow.com/users/224", "pm_score": 5, "selected": false, "text": "<p>Here is a sample tokenizer class that might do what you want </p>\n\n<pre><code>//Header file\nclass Tokenizer \n{\n public...
2008/09/10
[ "https://Stackoverflow.com/questions/53849", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1288/" ]
Java has a convenient split method: ``` String str = "The quick brown fox"; String[] results = str.split(" "); ``` Is there an easy way to do this in C++?
C++ standard library algorithms are pretty universally based around iterators rather than concrete containers. Unfortunately this makes it hard to provide a Java-like `split` function in the C++ standard library, even though nobody argues that this would be convenient. But what would its return type be? `std::vector<st...
53,911
<p>Programming in vim I often go search for something, yank it, then go back to where I was, insert it, modify it.</p> <p>The problem is that after I search and find, I need to MANUALLY find my way back to where I was.</p> <p>Is there an automatic way to go back to where I was when I initiated my last search?</p>
[ { "answer_id": 53924, "author": "Mark Biek", "author_id": 305, "author_profile": "https://Stackoverflow.com/users/305", "pm_score": 6, "selected": false, "text": "<p>I've always done by it setting a mark.</p>\n\n<ol>\n<li><p>In command-mode, press <strong><kbd>m</kbd><em>[letter]</em></s...
2008/09/10
[ "https://Stackoverflow.com/questions/53911", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4639/" ]
Programming in vim I often go search for something, yank it, then go back to where I was, insert it, modify it. The problem is that after I search and find, I need to MANUALLY find my way back to where I was. Is there an automatic way to go back to where I was when I initiated my last search?
`Ctrl`+`O` takes me to the previous location. Don't know about location before the search. Edit: Also, ````.` will take you to the last change you made.
53,945
<p>I am currently loading a lightbox style popup that loads it's HTML from an XHR call. This content is then displayed in a 'modal' popup using <code>element.innerHTML = content</code> This works like a charm.</p> <p>In another section of this website I use a Flickr 'badge' (<a href="http://www.elliotswan.com/2006/08/...
[ { "answer_id": 54002, "author": "Jon Cram", "author_id": 5343, "author_profile": "https://Stackoverflow.com/users/5343", "pm_score": 0, "selected": false, "text": "<p>Can I get some clarification first to make sure I get the problem?</p>\n\n<p><code>document.write</code> calls will add c...
2008/09/10
[ "https://Stackoverflow.com/questions/53945", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4174/" ]
I am currently loading a lightbox style popup that loads it's HTML from an XHR call. This content is then displayed in a 'modal' popup using `element.innerHTML = content` This works like a charm. In another section of this website I use a Flickr 'badge' (<http://www.elliotswan.com/2006/08/06/custom-flickr-badge-api-do...
In general, script tags aren't executed when using innerHTML. In your case, this is good, because the `document.write` call would wipe out everything that's already in the page. However, that leaves you without whatever HTML document.write was supposed to add. jQuery's HTML manipulation methods will execute scripts in...
53,965
<pre><code>$output = preg_replace("|(/D)(/s+)(/d+)(;)|", "//1,//3;", $output); </code></pre> <p>I'm trying to replace all alphabetical character followed by one or more whitespace characters (tabs and/or spaces) followed by one or more numerical characters followed by a semicolon with the alphabetical character follow...
[ { "answer_id": 53988, "author": "T Percival", "author_id": 954, "author_profile": "https://Stackoverflow.com/users/954", "pm_score": 2, "selected": false, "text": "<p>Should those forward-slashes be backslashes? You'll need to escape them for PHP too unless you change your double-quotes ...
2008/09/10
[ "https://Stackoverflow.com/questions/53965", "https://Stackoverflow.com", "https://Stackoverflow.com/users/572/" ]
``` $output = preg_replace("|(/D)(/s+)(/d+)(;)|", "//1,//3;", $output); ``` I'm trying to replace all alphabetical character followed by one or more whitespace characters (tabs and/or spaces) followed by one or more numerical characters followed by a semicolon with the alphabetical character followed by a comma follo...
The two `|` at the start and end probably are incorrect - and should both be forward-slashes. All other forward slashes should be backward slashes (and need escaping). And since PHP 4.04 `$n` is the preferred way of referring to a capture group. ``` $output = preg_replace("/(\\D)\\s+(\\d+;)/", "$1,$2", $output); ``...
53,967
<p>I have a class that map objects to objects, but unlike dictionary it maps them both ways. I am now trying to implement a custom <code>IEnumerator</code> interface that iterates through the values.</p> <pre><code>public class Mapper&lt;K,T&gt; : IEnumerable&lt;T&gt;, IEnumerator&lt;T&gt; { C5.TreeDictionary&lt;K...
[ { "answer_id": 53986, "author": "Mendelt", "author_id": 3320, "author_profile": "https://Stackoverflow.com/users/3320", "pm_score": 2, "selected": false, "text": "<p>Use yield return.</p>\n\n<p><a href=\"https://stackoverflow.com/questions/39476/what-is-the-yield-keyword-used-for-in-c#39...
2008/09/10
[ "https://Stackoverflow.com/questions/53967", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4694/" ]
I have a class that map objects to objects, but unlike dictionary it maps them both ways. I am now trying to implement a custom `IEnumerator` interface that iterates through the values. ``` public class Mapper<K,T> : IEnumerable<T>, IEnumerator<T> { C5.TreeDictionary<K,T> KToTMap = new TreeDictionary<K,T>(); ...
First, don't make your collection object implement IEnumerator<>. This leads to bugs. (Consider the situation where two threads are iterating over the same collection). Implementing an enumerator correctly turns out to be non-trivial, so C# 2.0 added special language support for doing it, based on the 'yield return' ...
54,010
<p>I've recently been working on a beginner's project in Scala, and have a beginner question about Scala's Lists.</p> <p>Say I have a list of tuples ( <code>List[Tuple2[String, String]]</code>, for example). Is there a convenience method to return the first occurence of a specified tuple from the List, or is it necess...
[ { "answer_id": 54123, "author": "Tim Sullivan", "author_id": 722, "author_profile": "https://Stackoverflow.com/users/722", "pm_score": 3, "selected": false, "text": "<p>You could try using <a href=\"http://www.scala-lang.org/api/current/index.html#scala.collection.parallel.ParIterableLik...
2008/09/10
[ "https://Stackoverflow.com/questions/54010", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I've recently been working on a beginner's project in Scala, and have a beginner question about Scala's Lists. Say I have a list of tuples ( `List[Tuple2[String, String]]`, for example). Is there a convenience method to return the first occurence of a specified tuple from the List, or is it necessary to iterate throug...
``` scala> val list = List(("A", "B", 1), ("C", "D", 1), ("E", "F", 1), ("C", "D", 2), ("G", "H", 1)) list: List[(java.lang.String, java.lang.String, Int)] = List((A,B,1), (C,D,1), (E,F,1), (C,D,2), (G,H,1)) scala> list find {e => e._1 == "C" && e._2 == "D"} res0: Option[(java.lang.String, java.lang.String, Int)] = S...
54,043
<p>I would like to be able to do such things as</p> <pre><code>var m1 = new UnitOfMeasureQuantityPair(123.00, UnitOfMeasure.Pounds); var m2 = new UnitOfMeasureQuantityPair(123.00, UnitOfMeasure.Liters); m1.ToKilograms(); m2.ToPounds(new Density(7.0, DensityType.PoundsPerGallon); </code></pre> <p>If there isn't somet...
[ { "answer_id": 54049, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 3, "selected": true, "text": "<p>Check out the <a href=\"http://www.codeproject.com/KB/library/Measurement_Conversion.aspx\" rel=\"nofollow noreferr...
2008/09/10
[ "https://Stackoverflow.com/questions/54043", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056/" ]
I would like to be able to do such things as ``` var m1 = new UnitOfMeasureQuantityPair(123.00, UnitOfMeasure.Pounds); var m2 = new UnitOfMeasureQuantityPair(123.00, UnitOfMeasure.Liters); m1.ToKilograms(); m2.ToPounds(new Density(7.0, DensityType.PoundsPerGallon); ``` If there isn't something like this already, an...
Check out the [Measurement Unit Conversion Library](http://www.codeproject.com/KB/library/Measurement_Conversion.aspx) on The Code Project.
54,059
<p>Say I have a linked list of numbers of length <code>N</code>. <code>N</code> is very large and I don’t know in advance the exact value of <code>N</code>. </p> <p>How can I most efficiently write a function that will return <code>k</code> completely <em>random numbers</em> from the list?</p>
[ { "answer_id": 54070, "author": "Tom Hawtin - tackline", "author_id": 4725, "author_profile": "https://Stackoverflow.com/users/4725", "pm_score": 2, "selected": false, "text": "<p>I would suggest: First find your k random numbers. Sort them. Then traverse both the linked list and your ra...
2008/09/10
[ "https://Stackoverflow.com/questions/54059", "https://Stackoverflow.com", "https://Stackoverflow.com/users/797/" ]
Say I have a linked list of numbers of length `N`. `N` is very large and I don’t know in advance the exact value of `N`. How can I most efficiently write a function that will return `k` completely *random numbers* from the list?
There's a very nice and efficient algorithm for this using a method called **reservoir sampling**. Let me start by giving you its **history**: **Knuth** calls this Algorithm R on p. 144 of his 1997 edition of Seminumerical Algorithms (volume 2 of The Art of Computer Programming), and provides some code for it there. ...
54,068
<p>I'm looking at a new computer which will probably have vista on it. But there are so many editions of vista; are there any weird restrictions on what you can run on the various editions? For instance you couldn't run IIS on Windows ME. Can you still run IIS on the home editions of vista? </p>
[ { "answer_id": 54070, "author": "Tom Hawtin - tackline", "author_id": 4725, "author_profile": "https://Stackoverflow.com/users/4725", "pm_score": 2, "selected": false, "text": "<p>I would suggest: First find your k random numbers. Sort them. Then traverse both the linked list and your ra...
2008/09/10
[ "https://Stackoverflow.com/questions/54068", "https://Stackoverflow.com", "https://Stackoverflow.com/users/361/" ]
I'm looking at a new computer which will probably have vista on it. But there are so many editions of vista; are there any weird restrictions on what you can run on the various editions? For instance you couldn't run IIS on Windows ME. Can you still run IIS on the home editions of vista?
There's a very nice and efficient algorithm for this using a method called **reservoir sampling**. Let me start by giving you its **history**: **Knuth** calls this Algorithm R on p. 144 of his 1997 edition of Seminumerical Algorithms (volume 2 of The Art of Computer Programming), and provides some code for it there. ...
54,138
<p>I have a third-party app that creates HTML-based reports that I need to display. I have <em>some</em> control over how they look, but in general it's pretty primitive. I <em>can</em> inject some javascript, though. I'd like to try to inject some jQuery goodness into it to tidy it up some. One specific thing I wo...
[ { "answer_id": 54145, "author": "Ryan Lanciaux", "author_id": 1385358, "author_profile": "https://Stackoverflow.com/users/1385358", "pm_score": 0, "selected": false, "text": "<p>You could do this with jQuery but it may make additional maintenance a nightmare. I would recommend against do...
2008/09/10
[ "https://Stackoverflow.com/questions/54138", "https://Stackoverflow.com", "https://Stackoverflow.com/users/404/" ]
I have a third-party app that creates HTML-based reports that I need to display. I have *some* control over how they look, but in general it's pretty primitive. I *can* inject some javascript, though. I'd like to try to inject some jQuery goodness into it to tidy it up some. One specific thing I would like to do is to ...
Given a html page like this: ``` <body><br/> <table id="my-table">`<br/> <tr><br/> <td><div>This is the contents of Column One</div></td><br/> <td><div>This is the contents of Column Two</div></td><br/> <td><div>This is the contents of Column Three</div></td><br/> ...
54,142
<p>How does the comma operator work in C++?</p> <p>For instance, if I do:</p> <pre><code>a = b, c; </code></pre> <p>Does a end up equaling b or c? </p> <p>(Yes, I know this is easy to test - just documenting on here for someone to find the answer quickly.)</p> <p><strong>Update:</strong> This question has expos...
[ { "answer_id": 54146, "author": "Leon Timmermans", "author_id": 4727, "author_profile": "https://Stackoverflow.com/users/4727", "pm_score": 7, "selected": true, "text": "<p>It would be equal to <code>b</code>.</p>\n\n<p>The comma operator has a lower precedence than assignment.</p>\n" ...
2008/09/10
[ "https://Stackoverflow.com/questions/54142", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1541/" ]
How does the comma operator work in C++? For instance, if I do: ``` a = b, c; ``` Does a end up equaling b or c? (Yes, I know this is easy to test - just documenting on here for someone to find the answer quickly.) **Update:** This question has exposed a nuance when using the comma operator. Just to document t...
It would be equal to `b`. The comma operator has a lower precedence than assignment.
54,147
<p>I want to insert some special characters at the caret inside textboxes using javascript on a button. How can this be done?</p> <p>The script needs to find the active textbox and insert the character at the caret in that textbox. The script also needs to work in IE and Firefox.</p> <p><strong>EDIT:</strong> It is a...
[ { "answer_id": 54162, "author": "Jason Cohen", "author_id": 4926, "author_profile": "https://Stackoverflow.com/users/4926", "pm_score": 0, "selected": false, "text": "<p>Note that if the user pushes a button, focus on the textbox will be lost and there will be no caret position!</p>\n" ...
2008/09/10
[ "https://Stackoverflow.com/questions/54147", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1523/" ]
I want to insert some special characters at the caret inside textboxes using javascript on a button. How can this be done? The script needs to find the active textbox and insert the character at the caret in that textbox. The script also needs to work in IE and Firefox. **EDIT:** It is also ok to insert the character...
I think Jason Cohen is incorrect. The caret position is preserved when focus is lost. [**Edit**: Added code for FireFox that I didn't have originally.] [**Edit**: Added code to determine the most recent active text box.] First, you can use each text box's onBlur event to set a variable to "this" so you always know t...
54,219
<p>I'm working on an editor for files that are used by an important internal testing tool we use. The tool itself is large, complicated, and refactoring or rewriting would take more resources than we are able to devote to it for the forseeable future, so my hands are tied when it comes to large modifications. I must ...
[ { "answer_id": 54258, "author": "Mendelt", "author_id": 3320, "author_profile": "https://Stackoverflow.com/users/3320", "pm_score": 1, "selected": true, "text": "<p>If A, B, C and D have nothing in common then adding a base class won't really get you anything. It will just be an empty cl...
2008/09/10
[ "https://Stackoverflow.com/questions/54219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2547/" ]
I'm working on an editor for files that are used by an important internal testing tool we use. The tool itself is large, complicated, and refactoring or rewriting would take more resources than we are able to devote to it for the forseeable future, so my hands are tied when it comes to large modifications. I must use a...
If A, B, C and D have nothing in common then adding a base class won't really get you anything. It will just be an empty class and in effect will be the same as object. I'd just create an ErrorItem class without the generics, make Item an object and do some casting when you want to use the objects referenced. If you w...
54,227
<p>I have an asp.net url path which is being generated in a web form, and is coming out something like "/foo/bar/../bar/path.aspx", and is coming out in the generated html like this too. It should be shortened to "/foo/bar/path.aspx". </p> <p>Path.Combine didn't fix it. Is there a function to clean this path up? </p>
[ { "answer_id": 54273, "author": "Compile This", "author_id": 4048, "author_profile": "https://Stackoverflow.com/users/4048", "pm_score": 3, "selected": true, "text": "<p>You could create a helper class which wrapped the UriBuilder class in System.Net</p>\n\n<pre><code>public static class...
2008/09/10
[ "https://Stackoverflow.com/questions/54227", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5599/" ]
I have an asp.net url path which is being generated in a web form, and is coming out something like "/foo/bar/../bar/path.aspx", and is coming out in the generated html like this too. It should be shortened to "/foo/bar/path.aspx". Path.Combine didn't fix it. Is there a function to clean this path up?
You could create a helper class which wrapped the UriBuilder class in System.Net ``` public static class UriHelper { public static string NormalizeRelativePath(string path) { UriBuilder _builder = new UriBuilder("http://localhost"); builder.Path = path; return builder.Uri.Absolut...
54,237
<p>I want to link to bookmark on a page (mysite.com/mypage.htm#bookmark) AND visually highlight the item that was bookmarked (maybe having a red border). Naturally, there would be multiple items bookmarked. So that if someone clicked on #bookmark2 then <em>that</em> other area would be highlighted). </p> <p>I can s...
[ { "answer_id": 54257, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 0, "selected": false, "text": "<p>I guess if you could store this information with JavaScript and cookies for the functionality of remembering the bookmark...
2008/09/10
[ "https://Stackoverflow.com/questions/54237", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4906/" ]
I want to link to bookmark on a page (mysite.com/mypage.htm#bookmark) AND visually highlight the item that was bookmarked (maybe having a red border). Naturally, there would be multiple items bookmarked. So that if someone clicked on #bookmark2 then *that* other area would be highlighted). I can see how to do that wi...
In your css you need to define ```css a.highlight {border:1px solid red;} ``` or something similar Then using jQuery, ``` $(document).ready ( function () { //Work as soon as the DOM is ready for parsing var id = location.hash.substr(1); //Get the word after the hash from the url if (id) $('#'+id).addCla...
54,255
<p>Using Vim I often want to replace a block of code with a block that I just yanked.</p> <p>But when I delete the block of code that is to be replaced, that block itself goes into the register which erases the block I just yanked. So I've got in the habit of yanking, then inserting, then deleting what I didn't want, ...
[ { "answer_id": 54265, "author": "EBGreen", "author_id": 1358, "author_profile": "https://Stackoverflow.com/users/1358", "pm_score": 3, "selected": false, "text": "<p>Well, first do this command:</p>\n\n<pre><code>:h d\n</code></pre>\n\n<p>Then you will realize that you can delete into a ...
2008/09/10
[ "https://Stackoverflow.com/questions/54255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4639/" ]
Using Vim I often want to replace a block of code with a block that I just yanked. But when I delete the block of code that is to be replaced, that block itself goes into the register which erases the block I just yanked. So I've got in the habit of yanking, then inserting, then deleting what I didn't want, but with l...
To delete something without saving it in a register, you can use the "black hole register": ``` "_d ``` Of course you could also use any of the other registers that don't hold anything you are interested in.
54,295
<p>I'd like to store a properties file as XML. Is there a way to sort the keys when doing this so that the generated XML file will be in alphabetical order? </p> <pre><code>String propFile = "/path/to/file"; Properties props = new Properties(); /*set some properties here*/ try { FileOutputStream xmlStream = new ...
[ { "answer_id": 54303, "author": "samjudson", "author_id": 1908, "author_profile": "https://Stackoverflow.com/users/1908", "pm_score": 1, "selected": false, "text": "<p>java.util.Properties is based on Hashtable, which does not store its values in alphabetical order, but in order of the h...
2008/09/10
[ "https://Stackoverflow.com/questions/54295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5084/" ]
I'd like to store a properties file as XML. Is there a way to sort the keys when doing this so that the generated XML file will be in alphabetical order? ``` String propFile = "/path/to/file"; Properties props = new Properties(); /*set some properties here*/ try { FileOutputStream xmlStream = new FileOutputStream...
Here's a quick and dirty way to do it: ``` String propFile = "/path/to/file"; Properties props = new Properties(); /* Set some properties here */ Properties tmp = new Properties() { @Override public Set<Object> keySet() { return Collections.unmodifiableSet(new TreeSet<Object>(super.keySet())); } }; tmp.pu...
54,334
<p>The following SQL:</p> <pre><code>SELECT notes + 'SomeText' FROM NotesTable a </code></pre> <p>Give the error:</p> <blockquote> <p>The data types nvarchar and text are incompatible in the add operator.</p> </blockquote>
[ { "answer_id": 54343, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 7, "selected": true, "text": "<p>The only way would be to convert your text field into an nvarchar field.</p>\n\n<pre><code>Select Cast(notes as nvarchar(4...
2008/09/10
[ "https://Stackoverflow.com/questions/54334", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2017/" ]
The following SQL: ``` SELECT notes + 'SomeText' FROM NotesTable a ``` Give the error: > > The data types nvarchar and text are incompatible in the add operator. > > >
The only way would be to convert your text field into an nvarchar field. ``` Select Cast(notes as nvarchar(4000)) + 'SomeText' From NotesTable a ``` Otherwise, I suggest doing the concatenation in your application.
54,365
<p>This is probably <a href="http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/x13320.html" rel="noreferrer">a complex solution</a>.</p> <p>I am looking for a simple operator like ">>", but for prepending.</p> <p>I am afraid it does not exist. I'll have to do something like </p> <pre> mv myfile t...
[ { "answer_id": 54381, "author": "Jason Navarrete", "author_id": 3920, "author_profile": "https://Stackoverflow.com/users/3920", "pm_score": 7, "selected": false, "text": "<p>This still uses a temp file, but at least it is on one line:</p>\n\n<pre><code>echo \"text\" | cat - yourfile &gt;...
2008/09/10
[ "https://Stackoverflow.com/questions/54365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1277510/" ]
This is probably [a complex solution](http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/x13320.html). I am looking for a simple operator like ">>", but for prepending. I am afraid it does not exist. I'll have to do something like ``` mv myfile tmp cat myheader tmp > myfile ``` Anything smart...
The **hack** below was a quick off-the-cuff answer which worked and received lots of upvotes. Then, as the question became more popular and more time passed, people started reporting that it sorta worked but weird things could happen, or it just didn't work at all. Such fun. I recommend [the 'sponge' solution posted b...
54,380
<p>I am adding a ADO.Net Data Service lookup feature to an existing web page. Everything works great when running from visual studio, but when I roll it out to IIS, I get the following error:</p> <blockquote> <p><strong>Request Error</strong><br>The server encountered an error processing the request. See server log...
[ { "answer_id": 55557, "author": "Patrick Connelly", "author_id": 5431, "author_profile": "https://Stackoverflow.com/users/5431", "pm_score": 4, "selected": false, "text": "<p>Well I found the \"Server Logs\" mentioned in the error above.</p>\n\n<p>You need to turn on tracing in the web.c...
2008/09/10
[ "https://Stackoverflow.com/questions/54380", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5431/" ]
I am adding a ADO.Net Data Service lookup feature to an existing web page. Everything works great when running from visual studio, but when I roll it out to IIS, I get the following error: > > **Request Error** > The server encountered an error processing the request. See server logs for more details. > > > I g...
In order to verbosely display the errors resulting from your data service you can place the following tag above your dataservice definition: ``` [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)] ``` This will then display the error in your browser window as well as a stack trace. In add...
54,387
<p>I have a set of calculation methods sitting in a .Net DLL. I would like to make those methods available to Excel (2003+) users so they can use them in their spreadsheets.</p> <p>For example, my .net method:</p> <pre><code>public double CalculateSomethingReallyComplex(double a, double b) {...} </code></pre> <p>I ...
[ { "answer_id": 54429, "author": "samjudson", "author_id": 1908, "author_profile": "https://Stackoverflow.com/users/1908", "pm_score": 3, "selected": true, "text": "<p>There are two methods - you can used Visual Studio Tools for Office (VSTO):</p>\n\n<p><a href=\"http://blogs.msdn.com/pst...
2008/09/10
[ "https://Stackoverflow.com/questions/54387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1324220/" ]
I have a set of calculation methods sitting in a .Net DLL. I would like to make those methods available to Excel (2003+) users so they can use them in their spreadsheets. For example, my .net method: ``` public double CalculateSomethingReallyComplex(double a, double b) {...} ``` I would like enable them to call thi...
There are two methods - you can used Visual Studio Tools for Office (VSTO): <http://blogs.msdn.com/pstubbs/archive/2004/12/31/344964.aspx> or you can use COM: <http://blogs.msdn.com/eric_carter/archive/2004/12/01/273127.aspx> I'm not sure if the VSTO method would work in older versions of Excel, but the COM method ...
54,401
<p>As I develop more with vim, I find myself wanting to copy in blocks of useful code, similar to "templates" in Eclipse. </p> <p>I was thinking of making a separate file for each code chunk and just reading them in with</p> <pre><code>:r code-fornext </code></pre> <p>but that just seems kind of primitive. Googling ...
[ { "answer_id": 54527, "author": "brian newman", "author_id": 3210, "author_profile": "https://Stackoverflow.com/users/3210", "pm_score": 4, "selected": true, "text": "<p>To record macros in Vim, in the command mode, hit the <code>q</code> key and another key you want to assign the macro ...
2008/09/10
[ "https://Stackoverflow.com/questions/54401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4639/" ]
As I develop more with vim, I find myself wanting to copy in blocks of useful code, similar to "templates" in Eclipse. I was thinking of making a separate file for each code chunk and just reading them in with ``` :r code-fornext ``` but that just seems kind of primitive. Googling around I find vim macros mentione...
To record macros in Vim, in the command mode, hit the `q` key and another key you want to assign the macro to. For quick throw away macros I usually just hit `qq` and assign the macro to the `q` key. Once you are in recording mode, run through your key strokes. When you are done make sure you are back in command mode a...
54,418
<p>I need to retrieve all rows from a table where 2 columns combined are all different. So I want all the sales that do not have any other sales that happened on the same day for the same price. The sales that are unique based on day and price will get updated to an active status.</p> <p>So I'm thinking:</p> <pre><co...
[ { "answer_id": 54430, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 10, "selected": true, "text": "<pre><code>SELECT DISTINCT a,b,c FROM t\n</code></pre>\n\n<p>is <em>roughly</em> equivalent to: </p>\n\n<pre><code>SEL...
2008/09/10
[ "https://Stackoverflow.com/questions/54418", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4915/" ]
I need to retrieve all rows from a table where 2 columns combined are all different. So I want all the sales that do not have any other sales that happened on the same day for the same price. The sales that are unique based on day and price will get updated to an active status. So I'm thinking: ``` UPDATE sales SET s...
``` SELECT DISTINCT a,b,c FROM t ``` is *roughly* equivalent to: ``` SELECT a,b,c FROM t GROUP BY a,b,c ``` It's a good idea to get used to the GROUP BY syntax, as it's more powerful. For your query, I'd do it like this: ``` UPDATE sales SET status='ACTIVE' WHERE id IN ( SELECT id FROM sales S INNE...
54,419
<p>I have a WCF application that has two Services that I am trying to host in a single Windows Service using net.tcp. I can run either of the services just fine, but as soon as I try to put them both in the Windows Service only the first one loads up. I have determined that the second services ctor is being called but ...
[ { "answer_id": 54424, "author": "Darren Kopp", "author_id": 77, "author_profile": "https://Stackoverflow.com/users/77", "pm_score": 0, "selected": false, "text": "<p>you probably just need 2 service hosts.</p>\n\n<p>_host1 and _host2.</p>\n" }, { "answer_id": 77401, "author":...
2008/09/10
[ "https://Stackoverflow.com/questions/54419", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5408/" ]
I have a WCF application that has two Services that I am trying to host in a single Windows Service using net.tcp. I can run either of the services just fine, but as soon as I try to put them both in the Windows Service only the first one loads up. I have determined that the second services ctor is being called but the...
Base your service on this [MSDN article](http://msdn.microsoft.com/en-us/library/ms733069.aspx) and create two service hosts. But instead of actually calling each service host directly, you can break it out to as many classes as you want which defines each service you want to run: ``` internal class MyWCFService1 { ...
54,421
<p>If you are writing a program that is executable from the command line, you often want to offer the user several options or flags, along with possibly more than one argument. I have stumbled my way through this many times, but is there some sort of design pattern for looping through args and calling the appropriate h...
[ { "answer_id": 54457, "author": "Peter Ritchie", "author_id": 5620, "author_profile": "https://Stackoverflow.com/users/5620", "pm_score": 5, "selected": true, "text": "<p>I don't know of any documented \"patterns\" for processing.</p>\n\n<p>I believe one of the oldest libraries/APIs for ...
2008/09/10
[ "https://Stackoverflow.com/questions/54421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/577/" ]
If you are writing a program that is executable from the command line, you often want to offer the user several options or flags, along with possibly more than one argument. I have stumbled my way through this many times, but is there some sort of design pattern for looping through args and calling the appropriate hand...
I don't know of any documented "patterns" for processing. I believe one of the oldest libraries/APIs for handling arguments is getopt. Googling "getopt" shows lots of man pages and links to implementations. Generally, I have a preferences or settings service in my application that the argument processor knows how to ...
54,426
<p>Like the Delicious submission bookmark-let, I'd like to have some standard JavaScript I can use to submit any visited URL to a 3rd party site when that's possible by URL. Suggestions?</p> <p>For example, I've been using </p> <pre><code>javascript:void(location.href="http://www.yacktrack.com/home?query="+encodeURI...
[ { "answer_id": 54446, "author": "John Boker", "author_id": 2847, "author_profile": "https://Stackoverflow.com/users/2847", "pm_score": 1, "selected": false, "text": "<pre><code>document.location = \"http://url_submitting_to.com?query_string_param=\" + window.location;\n</code></pre>\n" ...
2008/09/10
[ "https://Stackoverflow.com/questions/54426", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5613/" ]
Like the Delicious submission bookmark-let, I'd like to have some standard JavaScript I can use to submit any visited URL to a 3rd party site when that's possible by URL. Suggestions? For example, I've been using ``` javascript:void(location.href="http://www.yacktrack.com/home?query="+encodeURI(location.href)) ```...
Do you want something exactly like the Delicious bookmarklet (as in, something the user actively clicks on to submit the URL)? If so, you could probably just copy their code and replace the target URL: ``` javascript:(function(){ location.href='http://example.com/your-script.php?url='+ encodeURIComponent(windo...
54,440
<p>I want to add the selected item from the <code>TreeView</code> to the <code>ListBox</code> control using <code>DataBinding</code> (If it can work with <code>DataBinding</code>). </p> <pre><code>&lt;TreeView HorizontalAlignment="Left" Margin="30,32,0,83" Name="treeView1" Width="133" ...
[ { "answer_id": 54665, "author": "Dillie-O", "author_id": 71, "author_profile": "https://Stackoverflow.com/users/71", "pm_score": 0, "selected": false, "text": "<p>I'm pretty sure it is possible, since WPF is really flexible with data binding, but I haven't done that specific scenario yet...
2008/09/10
[ "https://Stackoverflow.com/questions/54440", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3797/" ]
I want to add the selected item from the `TreeView` to the `ListBox` control using `DataBinding` (If it can work with `DataBinding`). ``` <TreeView HorizontalAlignment="Left" Margin="30,32,0,83" Name="treeView1" Width="133" > </TreeView> <ListBox VerticalAlignment="Top" Mar...
You can bind to an element using ElementName, so if you wanted to bind the selected tree item to the ItemsSource of a ListBox: ``` ItemsSource="{Binding SelectedItem, ElementName=treeView1}" ```
54,475
<p>I've run into a problem where I make changes to a few JavaScript files that are referenced in an HTML file, but the browser doesn't see the changes. It holds onto the copy cached in the browser, even though the web server has a newer version.</p> <p>Not until I force the browser to clear the cache do I see the chan...
[ { "answer_id": 54483, "author": "UnkwnTech", "author_id": 115, "author_profile": "https://Stackoverflow.com/users/115", "pm_score": 0, "selected": false, "text": "<p>I am also of the method of just renaming things. It never fails, and is fairly easy to do.</p>\n" }, { "answer_i...
2008/09/10
[ "https://Stackoverflow.com/questions/54475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5079/" ]
I've run into a problem where I make changes to a few JavaScript files that are referenced in an HTML file, but the browser doesn't see the changes. It holds onto the copy cached in the browser, even though the web server has a newer version. Not until I force the browser to clear the cache do I see the changes. Is t...
We append a product build number to the end of all Javascript (and CSS etc.) like so: ``` <script src="MyScript.js?4.0.8243"> ``` Browsers ignore everything after the question mark but upgrades cause a new URL which means cache-reload. This has the additional benefit that you can set HTTP headers that mean "never c...
54,482
<p>I need to enumerate all the user defined types created in a <code>SQL Server</code> database with <code>CREATE TYPE</code>, and/or find out whether they have already been defined.</p> <p>With tables or stored procedures I'd do something like this:</p> <pre><code>if exists (select * from dbo.sysobjects where name='...
[ { "answer_id": 54496, "author": "jwolly2", "author_id": 5202, "author_profile": "https://Stackoverflow.com/users/5202", "pm_score": 7, "selected": true, "text": "<p>Types and UDTs don't appear in sys.objects.\nYou should be able to get what you're looking for with the following:</p>\n\n<...
2008/09/10
[ "https://Stackoverflow.com/questions/54482", "https://Stackoverflow.com", "https://Stackoverflow.com/users/886/" ]
I need to enumerate all the user defined types created in a `SQL Server` database with `CREATE TYPE`, and/or find out whether they have already been defined. With tables or stored procedures I'd do something like this: ``` if exists (select * from dbo.sysobjects where name='foobar' and xtype='U') drop table fooba...
Types and UDTs don't appear in sys.objects. You should be able to get what you're looking for with the following: ``` select * from sys.types where is_user_defined = 1 ```
54,487
<p>How can I format Floats in Java so that the float component is displayed only if it's not zero? For example:</p> <pre> 123.45 -> 123.45 99.0 -> 99 23.2 -> 23.2 45.0 -> 45 </pre> <p>Edit: I forgot to mention - I'm still on Java 1.4 - sorry!</p>
[ { "answer_id": 54502, "author": "ScArcher2", "author_id": 1310, "author_profile": "https://Stackoverflow.com/users/1310", "pm_score": 4, "selected": true, "text": "<p>If you use <a href=\"http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html\" rel=\"nofollow noreferrer\">D...
2008/09/10
[ "https://Stackoverflow.com/questions/54487", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
How can I format Floats in Java so that the float component is displayed only if it's not zero? For example: ``` 123.45 -> 123.45 99.0 -> 99 23.2 -> 23.2 45.0 -> 45 ``` Edit: I forgot to mention - I'm still on Java 1.4 - sorry!
If you use [DecimalFormat](http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html) and specify # in the pattern it only displays the value if it is not zero. See my question [How do I format a number in java?](https://stackoverflow.com/questions/50532/how-do-i-format-a-number-in-java) Sample Code ``` ...
54,503
<p>I'm working on a .net post-commit hook to feed data into OnTime via their Soap SDK. My hook works on Windows fine, but on our production RHEL4 subversion server, it won't work when called from a shell script.</p> <pre> #!/bin/sh /usr/bin/mono $1/hooks/post-commit.exe "$@" </pre> <p>When I execute it with parameter...
[ { "answer_id": 54537, "author": "Herms", "author_id": 1409, "author_profile": "https://Stackoverflow.com/users/1409", "pm_score": 0, "selected": false, "text": "<p>Just a random thought that might help with debugging. Try changing your shell script to:</p>\n\n<pre><code>#!/bin/sh\necho ...
2008/09/10
[ "https://Stackoverflow.com/questions/54503", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1441/" ]
I'm working on a .net post-commit hook to feed data into OnTime via their Soap SDK. My hook works on Windows fine, but on our production RHEL4 subversion server, it won't work when called from a shell script. ``` #!/bin/sh /usr/bin/mono $1/hooks/post-commit.exe "$@" ``` When I execute it with parameters from the co...
It is normal for some processes to hang around for a while after they close their stdout (ie. you get an end-of-file reading from them). You need to call `proc.WaitForExit()` after reading all the data but before checking ExitCode.
54,536
<p>How do I create a windows application that does the following:</p> <ul> <li>it's a regular GUI app when invoked with no command line arguments</li> <li>specifying the optional "--help" command line argument causes the app to write usage text to stdout then terminate</li> <li>it must be a single executable. No chea...
[ { "answer_id": 113032, "author": "Hugh Allen", "author_id": 15069, "author_profile": "https://Stackoverflow.com/users/15069", "pm_score": 5, "selected": false, "text": "<p>Microsoft designed console and GUI apps to be mutually exclusive.\nThis bit of short-sightedness means that there is...
2008/09/10
[ "https://Stackoverflow.com/questions/54536", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5429/" ]
How do I create a windows application that does the following: * it's a regular GUI app when invoked with no command line arguments * specifying the optional "--help" command line argument causes the app to write usage text to stdout then terminate * it must be a single executable. No cheating by making a console app ...
Microsoft designed console and GUI apps to be mutually exclusive. This bit of short-sightedness means that there is no perfect solution. The most popular approach is to have two executables (eg. cscript / wscript, java / javaw, devenv.com / devenv.exe etc) however you've indicated that you consider this "cheating". Yo...