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
43,778
<p><strong>Update:</strong> Check out this follow-up question: <a href="https://stackoverflow.com/questions/134581/gem-update-on-windows-is-it-broken"><strong>Gem Update on Windows - is it broken?</strong></a></p> <hr> <p>On Windows, when I do this:</p> <pre><code>gem install sqlite3-ruby </code></pre> <p>I get the...
[ { "answer_id": 43804, "author": "Nathan Fritz", "author_id": 4142, "author_profile": "https://Stackoverflow.com/users/4142", "pm_score": 2, "selected": false, "text": "<p>Is it possible that the newest version has not yet been ported to Win32 yet? Since this particular gem does have bind...
2008/09/04
[ "https://Stackoverflow.com/questions/43778", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1944/" ]
**Update:** Check out this follow-up question: [**Gem Update on Windows - is it broken?**](https://stackoverflow.com/questions/134581/gem-update-on-windows-is-it-broken) --- On Windows, when I do this: ``` gem install sqlite3-ruby ``` I get the following error: ``` Building native extensions. This could take a w...
As Nathan suggests, this does appear to be related to the fact that the latest versions of the sqlite3-ruby and hpricot gems don't appear to have Windows versions. Here's what to do when faced with this situation (note, the name of the gem is automatically wildcarded, so you can type just *sql* and get a list of all ge...
43,802
<p>I have a <code>String</code> representation of a date that I need to create a <code>Date</code> or <code>Calendar</code> object from. I've looked through <code>Date</code> and <code>Calendar</code> APIs but haven't found anything that can do this other than creating my own ugly parse method. I know there must be a w...
[ { "answer_id": 43806, "author": "Apocalisp", "author_id": 3434, "author_profile": "https://Stackoverflow.com/users/3434", "pm_score": 0, "selected": false, "text": "<p>Try this:</p>\n\n<pre><code>DateFormat.parse(String)\n</code></pre>\n" }, { "answer_id": 43807, "author": "M...
2008/09/04
[ "https://Stackoverflow.com/questions/43802", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2628/" ]
I have a `String` representation of a date that I need to create a `Date` or `Calendar` object from. I've looked through `Date` and `Calendar` APIs but haven't found anything that can do this other than creating my own ugly parse method. I know there must be a way, does anyone know of a solution?
In brief: ``` DateFormat formatter = new SimpleDateFormat("MM/dd/yy"); try { Date date = formatter.parse("01/29/02"); } catch (ParseException e) { e.printStackTrace(); } ``` See [`SimpleDateFormat` javadoc](http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) for more. And to turn it into a...
43,803
<p>This is what I've got. It works. But, is there a simpler or better way?</p> <p>ASPX Page&hellip;</p> <pre><code>&lt;asp:Repeater ID="RepeaterBooks" runat="server"&gt; &lt;HeaderTemplate&gt; &lt;table class="report"&gt; &lt;tr&gt; &lt;th&gt;Published&lt;/th&gt; ...
[ { "answer_id": 43818, "author": "Geoff", "author_id": 1097, "author_profile": "https://Stackoverflow.com/users/1097", "pm_score": 2, "selected": false, "text": "<p>In .Net 3.0+ you can replace your ItemDataBound to the asp:Literal by doing something like this:</p>\n\n<pre><code>&lt;ItemT...
2008/09/04
[ "https://Stackoverflow.com/questions/43803", "https://Stackoverflow.com", "https://Stackoverflow.com/users/83/" ]
This is what I've got. It works. But, is there a simpler or better way? ASPX Page… ``` <asp:Repeater ID="RepeaterBooks" runat="server"> <HeaderTemplate> <table class="report"> <tr> <th>Published</th> <th>Title</th> <th>Author</th> ...
@Geoff That sort of Eval statement was actually added in 2.0, but if performance is important Eval should be avoided since it uses Reflection. The repeater is a pretty good way of doing it, although it might be faster to generate the table in code: ASPX Page: ``` <table class="report" id="bookTable" runat="server">...
43,808
<p>I have a distributed Java application running on 5 application servers. The servers all use the same Oracle 9i database running on a 6th machine.</p> <p>The application need to prefetch a batch of 100 IDs from a sequence. It's relatively easy to do in a single-threaded, non-distributed environment, you can just iss...
[ { "answer_id": 43830, "author": "Matthew Watson", "author_id": 3839, "author_profile": "https://Stackoverflow.com/users/3839", "pm_score": 5, "selected": true, "text": "<p>Why not just have the sequence as increment by 100 all the time? each \"nextval\" gives you 100 sequence numbers to ...
2008/09/04
[ "https://Stackoverflow.com/questions/43808", "https://Stackoverflow.com", "https://Stackoverflow.com/users/686/" ]
I have a distributed Java application running on 5 application servers. The servers all use the same Oracle 9i database running on a 6th machine. The application need to prefetch a batch of 100 IDs from a sequence. It's relatively easy to do in a single-threaded, non-distributed environment, you can just issue these q...
Why not just have the sequence as increment by 100 all the time? each "nextval" gives you 100 sequence numbers to work with ``` SQL> create sequence so_test start with 100 increment by 100 nocache; Sequence created. SQL> select so_test.nextval - 99 as first_seq, so_test.currval as last_seq from dual; FIRST_SEQ L...
43,819
<p>We are now using NHibernate to connect to different database base on where our software is installed. So I am porting many SQL Procedures to Oracle.</p> <p>SQL Server has a nice function called DateDiff which takes a date part, startdate and enddate.</p> <p>Date parts examples are day, week, month, year, etc. . ....
[ { "answer_id": 44597, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "<p>Tom's article is very old. It only discusses the DATE type. If you use TIMESTAMP types then date arithmetic is built into ...
2008/09/04
[ "https://Stackoverflow.com/questions/43819", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2469/" ]
We are now using NHibernate to connect to different database base on where our software is installed. So I am porting many SQL Procedures to Oracle. SQL Server has a nice function called DateDiff which takes a date part, startdate and enddate. Date parts examples are day, week, month, year, etc. . . What is the Ora...
I stole most of this from an old tom article a few years ago, fixed some bugs from the article and cleaned it up. The demarcation lines for datediff are calculated differently between oracle and MSSQL so you have to be careful with some examples floating around out there that don't properly account for MSSQL/Sybase sty...
43,832
<p>I think I might be missing something here. Here is the relevant part of the trigger:</p> <pre><code> CURSOR columnNames (inTableName IN VARCHAR2) IS SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME = inTableName; /* Removed for brevity */ OPEN columnNames('TEMP'); </code></pre> <p>And her...
[ { "answer_id": 43859, "author": "Matthew Watson", "author_id": 3839, "author_profile": "https://Stackoverflow.com/users/3839", "pm_score": 1, "selected": false, "text": "<p>Works fine for me.</p>\n\n<pre><code>create or replace procedure so_test_procedure as \n CURSOR columnNames (inTabl...
2008/09/04
[ "https://Stackoverflow.com/questions/43832", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1185/" ]
I think I might be missing something here. Here is the relevant part of the trigger: ``` CURSOR columnNames (inTableName IN VARCHAR2) IS SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME = inTableName; /* Removed for brevity */ OPEN columnNames('TEMP'); ``` And here is the error message t...
To clarify the cause of the issue. As you state **OPEN columnNames('TEMP');** worked while **FOR columnName IN columnNames LOOP** did not. The FOR statement would work fine if it also included the parameter like so: **FOR columnName IN columnNames('TEMP') LOOP** You don't show the code where you fetch the rows...
43,842
<p>I have a string that contains the representation of a date. It looks like: </p> <p><strong>Thu Nov 30 19:00:00 EST 2006</strong></p> <p>I'm trying to create a Date object using SimpleDateFormat and have 2 problems. </p> <p>1.) I can't figure out the pattern to hard-code the solution into the SimpleDateFormat cons...
[ { "answer_id": 43849, "author": "alexmcchessers", "author_id": 998, "author_profile": "https://Stackoverflow.com/users/998", "pm_score": 2, "selected": false, "text": "<p>I'm not sure there's any easy way to parse a date and work out its pattern, but I would have thought that the pattern...
2008/09/04
[ "https://Stackoverflow.com/questions/43842", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2628/" ]
I have a string that contains the representation of a date. It looks like: **Thu Nov 30 19:00:00 EST 2006** I'm trying to create a Date object using SimpleDateFormat and have 2 problems. 1.) I can't figure out the pattern to hard-code the solution into the SimpleDateFormat constructor 2.) I can't find a way I cou...
The format to pass to SimpleDateFormat could be looked up at <http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html> ``` new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy") ``` As for your second question, I don't know of any Java library to figure out a date format and parse it without knowing in a...
43,870
<p>I am looking for a way to concatenate the strings of a field within a group by query. So for example, I have a table:</p> <pre><code>ID COMPANY_ID EMPLOYEE 1 1 Anna 2 1 Bill 3 2 Carol 4 2 Dave </code></pre> <p>and I wanted to group by company_id to get so...
[ { "answer_id": 43889, "author": "Guy C", "author_id": 4045, "author_profile": "https://Stackoverflow.com/users/4045", "pm_score": 4, "selected": false, "text": "<p>I claim no credit for the answer because I found it after some searching:</p>\n\n<p>What I didn't know is that PostgreSQL al...
2008/09/04
[ "https://Stackoverflow.com/questions/43870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4045/" ]
I am looking for a way to concatenate the strings of a field within a group by query. So for example, I have a table: ``` ID COMPANY_ID EMPLOYEE 1 1 Anna 2 1 Bill 3 2 Carol 4 2 Dave ``` and I wanted to group by company\_id to get something like: ``` COMPAN...
### PostgreSQL 9.0 or later: Modern Postgres (since 2010) has the [`string_agg(expression, delimiter)`](http://www.postgresql.org/docs/current/static/functions-aggregate.html#FUNCTIONS-AGGREGATE-TABLE) function which will do exactly what the asker was looking for: ``` SELECT company_id, string_agg(employee, ', ') FRO...
43,874
<p>I have a multiple selection SELECT field which I don't want the end user to be able to change the value of. </p> <p>For UI reasons, I would like to be able to do this without using the disabled="true" attribute. I've tried using onmousedown, onfocus, onclick and setting each to blur or return false but with no succ...
[ { "answer_id": 43880, "author": "ceejayoz", "author_id": 1902010, "author_profile": "https://Stackoverflow.com/users/1902010", "pm_score": 2, "selected": false, "text": "<p>Could you do it with an <code>onchange</code> event?</p>\n\n<pre><code>&lt;select onfocus=\"this.oldIndex=this.sele...
2008/09/04
[ "https://Stackoverflow.com/questions/43874", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1980/" ]
I have a multiple selection SELECT field which I don't want the end user to be able to change the value of. For UI reasons, I would like to be able to do this without using the disabled="true" attribute. I've tried using onmousedown, onfocus, onclick and setting each to blur or return false but with no success. Can ...
I know you mentioned that you don't want to, but I actually think that using the `disabled` attribute is a better solution: ``` <select multiple="multiple"> <option value="volvo" selected="true" disabled="disabled">Volvo</option> <option value="saab" disabled="disabled">Saab</option> <option value="opel" d...
43,890
<p><strong>Original Question</strong></p> <p>I want to be able to generate a new (fully valid) MP3 file from an existing MP3 file to be used as a preview -- try-before-you-buy style. The new file should only contain the first <em>n</em> seconds of the track.</p> <p>Now, I know I could just "chop the stream" at <em>n<...
[ { "answer_id": 43912, "author": "John Boker", "author_id": 2847, "author_profile": "https://Stackoverflow.com/users/2847", "pm_score": 4, "selected": false, "text": "<p>try:</p>\n\n<pre><code>ffmpeg -t 30 -i inputfile.mp3 outputfile.mp3\n</code></pre>\n" }, { "answer_id": 43914, ...
2008/09/04
[ "https://Stackoverflow.com/questions/43890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1820/" ]
**Original Question** I want to be able to generate a new (fully valid) MP3 file from an existing MP3 file to be used as a preview -- try-before-you-buy style. The new file should only contain the first *n* seconds of the track. Now, I know I could just "chop the stream" at *n* seconds (calculating from the bitrate a...
I also recommend ffmpeg, but the command line suggested by John Boker has an unintended side effect: it re-encodes the file to the default bitrate (which is 64 kb/s in the version I have here at least). This might give your customers a false impression of the quality of your sound files, and it also takes longer to do....
43,903
<p>In a stored procedure, when is #Temptable created in SQL Server 2005? When creating the query execution plan or when executing the stored procedure?</p> <pre><code>if (@x = 1) begin select 1 as Text into #Temptable end else begin select 2 as Text into #Temptable end </code></pre>
[ { "answer_id": 43910, "author": "Chris Miller", "author_id": 206, "author_profile": "https://Stackoverflow.com/users/206", "pm_score": 2, "selected": false, "text": "<p>It's created when it's executed and dropped when the session ends.</p>\n" }, { "answer_id": 43925, "author"...
2008/09/04
[ "https://Stackoverflow.com/questions/43903", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2184/" ]
In a stored procedure, when is #Temptable created in SQL Server 2005? When creating the query execution plan or when executing the stored procedure? ``` if (@x = 1) begin select 1 as Text into #Temptable end else begin select 2 as Text into #Temptable end ```
Interesting question. For the type of temporary table you're creating, I think it's when the stored procedure is executed. Tables created with the # prefix are accessible to the SQL Server session they're created in. Once the session ends, they're dropped. This url: <http://www.sql-server-performance.com/tips/query_e...
43,926
<p>A <code>.container</code> can contain many <code>.components</code>, and <code>.components</code> themselves can contain <code>.containers</code> (which in turn can contain .components etc. etc.)</p> <p>Given code like this:</p> <pre><code>$(".container .component").each(function(){ $(".container", this).css('bo...
[ { "answer_id": 43933, "author": "travis", "author_id": 1414, "author_profile": "https://Stackoverflow.com/users/1414", "pm_score": 2, "selected": false, "text": "<pre><code>$(\".container .component\").each(function() {\n if ($(\".container\", this).css('width') === \"auto\")\n ...
2008/09/04
[ "https://Stackoverflow.com/questions/43926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2268/" ]
A `.container` can contain many `.components`, and `.components` themselves can contain `.containers` (which in turn can contain .components etc. etc.) Given code like this: ``` $(".container .component").each(function(){ $(".container", this).css('border', '1px solid #f00'); }); ``` What do I need to add to the ...
``` $(".container .component").each(function() { $(".container", this).each(function() { if($(this).css('width') == 'auto') { $(this).css('border', '1px solid #f00'); } }); }); ``` Similar to the other answer but since components can also have multiple containers, also need...
43,955
<p>Is it possible to modify the title of the message box the confirm() function opens in JavaScript? </p> <p>I could create a modal popup box, but I would like to do this as minimalistic as possible. I would like to do something like this:</p> <pre><code>confirm("This is the content of the message box", "Modified tit...
[ { "answer_id": 43959, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 7, "selected": true, "text": "<p>This is not possible, as you say, from a security stand point. The only way you could simulate it, is by creating a modeless d...
2008/09/04
[ "https://Stackoverflow.com/questions/43955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2241/" ]
Is it possible to modify the title of the message box the confirm() function opens in JavaScript? I could create a modal popup box, but I would like to do this as minimalistic as possible. I would like to do something like this: ``` confirm("This is the content of the message box", "Modified title"); ``` The defau...
This is not possible, as you say, from a security stand point. The only way you could simulate it, is by creating a modeless dialog window. There are many third-party javascript-plugins that you could use to fake this effect so you do not have to write all that code.
43,970
<p>I'm setting up a server which is on a network behind a firewall and I want programs on this computer to be able to use sendmail to send emails to any email address. We have an SMTP server running on this network (let's call it mailrelay.example.com) which is how we're supposed to get outgoing emails through the fir...
[ { "answer_id": 43977, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 3, "selected": false, "text": "<p><a href=\"http://www.elandsys.com/resources/sendmail/smarthost.html\" rel=\"noreferrer\">http://www.elandsys.com/resources/se...
2008/09/04
[ "https://Stackoverflow.com/questions/43970", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1694/" ]
I'm setting up a server which is on a network behind a firewall and I want programs on this computer to be able to use sendmail to send emails to any email address. We have an SMTP server running on this network (let's call it mailrelay.example.com) which is how we're supposed to get outgoing emails through the firewal...
@eli: modifying sendmail.cf directly is not usually recommended, since it is generated by the macro compiler. Edit /etc/mail/sendmail.mc to include the line: ``` define(`SMART_HOST',`mailrelay.example.com')dnl ``` After changing the sendmail.mc macro configuration file, it must be recompiled to produce the send...
43,971
<p>Let's say I have a web site for hosting community generated content that targets a very specific set of users. Now, let's say in the interest of fostering a better community I have an off-topic area where community members can post or talk about anything they want, regardless of the site's main theme.</p> <p>Now, ...
[ { "answer_id": 43980, "author": "James Marshall", "author_id": 1025, "author_profile": "https://Stackoverflow.com/users/1025", "pm_score": 2, "selected": false, "text": "<p>If using Apache I'd use mod-rewrite to alias robots.txt to a script that could dynamically generate the necessary c...
2008/09/04
[ "https://Stackoverflow.com/questions/43971", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3043/" ]
Let's say I have a web site for hosting community generated content that targets a very specific set of users. Now, let's say in the interest of fostering a better community I have an off-topic area where community members can post or talk about anything they want, regardless of the site's main theme. Now, I *want* mo...
This will work for all well-behaving search engines, just add it to the `<head>`: ``` <meta name="robots" content="noindex, nofollow" /> ```
43,995
<p>Handling multiple merges onto branches in Subversion or CVS is just one of those things that has to be experienced. It is inordinately easier to keep track of branches and merges in Mercurial (and probably any other distributed system) but I don't know why. Does anyone else know?</p> <p>My question stems from the f...
[ { "answer_id": 44030, "author": "RedWolves", "author_id": 648, "author_profile": "https://Stackoverflow.com/users/648", "pm_score": 1, "selected": false, "text": "<p>I only have experience with Subversion but I can tell you that the merge screen in TortoiseSVN is horribly complicated. L...
2008/09/04
[ "https://Stackoverflow.com/questions/43995", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4003/" ]
Handling multiple merges onto branches in Subversion or CVS is just one of those things that has to be experienced. It is inordinately easier to keep track of branches and merges in Mercurial (and probably any other distributed system) but I don't know why. Does anyone else know? My question stems from the fact that w...
> > In Subversion (and CVS), the repository is first and foremost. In git > and mercurial there is not really the concept of a repository in the > same way; here changes are the central theme. > > > +1 The hassle in CVS/SVN comes from the fact that these systems do **not** remember the parenthood of changes. In...
44,007
<p>Is there any chance to get this work? I want my tests to be run by nunit2 task in NAnt. In addition I want to run NCover without running tests again. </p>
[ { "answer_id": 44037, "author": "Greg Hurlman", "author_id": 35, "author_profile": "https://Stackoverflow.com/users/35", "pm_score": 2, "selected": false, "text": "<p>Why not have NCover run NUnit? You get the exact same test results. Also, what exactly are you trying to measure when ru...
2008/09/04
[ "https://Stackoverflow.com/questions/44007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3182/" ]
Is there any chance to get this work? I want my tests to be run by nunit2 task in NAnt. In addition I want to run NCover without running tests again.
I figured it out. You change the path of the NUnit launcher to that of TeamCity's own. Here is an example: ``` <mkdir dir="${build}/coverage" failonerror="false"/> <!-- run the unit tests and generate code coverage --> <property name="tools.dir.tmp" value="${tools.dir}"/> <if test="${not path::is-path...
44,019
<p>I need to diff two log files but ignore the time stamp part of each line (the first 12 characters to be exact). Is there a good tool, or a clever awk command, that could help me out?</p>
[ { "answer_id": 44028, "author": "Blair Conrad", "author_id": 1199, "author_profile": "https://Stackoverflow.com/users/1199", "pm_score": 5, "selected": false, "text": "<p>@EbGreen said</p>\n\n<blockquote>\n <p>I would just take the log files and strip the timestamps off the start of eac...
2008/09/04
[ "https://Stackoverflow.com/questions/44019", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4061/" ]
I need to diff two log files but ignore the time stamp part of each line (the first 12 characters to be exact). Is there a good tool, or a clever awk command, that could help me out?
Depending on the shell you are using, you can turn the approach [@Blair](https://stackoverflow.com/questions/44019/an-easy-way-to-diff-log-files-ignoring-the-time-stamps#44028) suggested into a 1-liner ``` diff <(cut -b13- file1) <(cut -b13- file2) ``` (+1 to [@Blair](https://stackoverflow.com/questions/44019/an-eas...
44,046
<p>I'm trying to determine the best way to truncate or drop extra decimal places in SQL without rounding. For example:</p> <pre><code>declare @value decimal(18,2) set @value = 123.456 </code></pre> <p>This will automatically round <code>@value</code> to be <code>123.46</code>, which is good in most cases. However,...
[ { "answer_id": 44049, "author": "SQLMenace", "author_id": 740, "author_profile": "https://Stackoverflow.com/users/740", "pm_score": -1, "selected": false, "text": "<pre><code>select convert(int,@value)\n</code></pre>\n" }, { "answer_id": 44052, "author": "Jimmy", "author_...
2008/09/04
[ "https://Stackoverflow.com/questions/44046", "https://Stackoverflow.com", "https://Stackoverflow.com/users/105/" ]
I'm trying to determine the best way to truncate or drop extra decimal places in SQL without rounding. For example: ``` declare @value decimal(18,2) set @value = 123.456 ``` This will automatically round `@value` to be `123.46`, which is good in most cases. However, for this project, I don't need that. Is there a s...
``` select round(123.456, 2, 1) ```
44,066
<p>Is it possible to pass a reference to a function to another function in F#? Specifically, I'd like to pass lambda functions like</p> <p>foo(fun x -> x ** 3)</p> <p>More specifically, I need to know how I would refer to the passed function in a function that I wrote myself.</p>
[ { "answer_id": 44079, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 4, "selected": true, "text": "<p>Yes, it is possible. The <a href=\"http://research.microsoft.com/fsharp/manual/spec2.aspx#_Toc207785549\" rel=\"norefer...
2008/09/04
[ "https://Stackoverflow.com/questions/44066", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2270/" ]
Is it possible to pass a reference to a function to another function in F#? Specifically, I'd like to pass lambda functions like foo(fun x -> x \*\* 3) More specifically, I need to know how I would refer to the passed function in a function that I wrote myself.
Yes, it is possible. The [manual](http://research.microsoft.com/fsharp/manual/spec2.aspx#_Toc207785549) has this example: ``` > List.map (fun x -> x % 2 = 0) [1 .. 5];; val it : bool list = [false; true; false; true; false] ```
44,078
<p>I am trying to write a regular expression to strip all HTML with the exception of links (the <code>&lt;a href</code> and <code>&lt;/a&gt;</code> tags respectively. It does not have to be 100% secure (I am not worried about injection attacks or anything as I am parsing content that has already been approved and publi...
[ { "answer_id": 44088, "author": "Jimmy", "author_id": 4435, "author_profile": "https://Stackoverflow.com/users/4435", "pm_score": -1, "selected": false, "text": "<p>How about</p>\n\n<pre><code>&lt;[^a](.|\\n)+?&gt;\n</code></pre>\n\n<p>?</p>\n" }, { "answer_id": 44124, "autho...
2008/09/04
[ "https://Stackoverflow.com/questions/44078", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1306/" ]
I am trying to write a regular expression to strip all HTML with the exception of links (the `<a href` and `</a>` tags respectively. It does not have to be 100% secure (I am not worried about injection attacks or anything as I am parsing content that has already been approved and published into a [SWF](http://en.wikipe...
``` <(?!\/?a(?=>|\s.*>))\/?.*?> ``` Try this. Had something similar for p tags. Worked for them so don't see why not. Uses negative lookahead to check that it doesn't match a (prefixed with an optional / character) where (using positive lookahead) a (with optional / prefix) is followed by a > or a space, stuff and th...
44,084
<p>That's it. If you want to document a function or a class, you put a string just after the definition. For instance:</p> <pre><code>def foo(): """This function does nothing.""" pass </code></pre> <p>But what about a module? How can I document what a <em>file.py</em> does?</p>
[ { "answer_id": 44094, "author": "David Locke", "author_id": 1447, "author_profile": "https://Stackoverflow.com/users/1447", "pm_score": 2, "selected": false, "text": "<p>It's easy, you just add a docstring at the top of the module.</p>\n" }, { "answer_id": 44095, "author": "G...
2008/09/04
[ "https://Stackoverflow.com/questions/44084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1679/" ]
That's it. If you want to document a function or a class, you put a string just after the definition. For instance: ``` def foo(): """This function does nothing.""" pass ``` But what about a module? How can I document what a *file.py* does?
For the packages, you can document it in `__init__.py`. For the modules, you can add a docstring simply in the module file. All the information is here: <http://www.python.org/dev/peps/pep-0257/>
44,100
<p>This is a fairly trivial matter, but I'm curious to hear people's opinions on it.</p> <p>If I have a Dictionary which I'm access through properties, which of these formats would you prefer for the property?</p> <pre><code>/// &lt;summary&gt; /// This class's FirstProperty property /// &lt;/summary&gt; [DefaultValu...
[ { "answer_id": 44106, "author": "Glenn Slaven", "author_id": 2975, "author_profile": "https://Stackoverflow.com/users/2975", "pm_score": 3, "selected": true, "text": "<p>I like the second one purely because any avoidance of magic strings/numbers in code is a good thing. IMO if you need ...
2008/09/04
[ "https://Stackoverflow.com/questions/44100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1512/" ]
This is a fairly trivial matter, but I'm curious to hear people's opinions on it. If I have a Dictionary which I'm access through properties, which of these formats would you prefer for the property? ``` /// <summary> /// This class's FirstProperty property /// </summary> [DefaultValue("myValue")] public string First...
I like the second one purely because any avoidance of magic strings/numbers in code is a good thing. IMO if you need to reference a number or string literal in code more than once, it should be a constant. In most cases even if it's only used once it should be in a constant
44,131
<p>I need to display a variable-length message and allow the text to be selectable. I have made the TextBox ReadOnly which does not allow the text to be edited, but the input caret is still shown. </p> <p>The blinking input caret is confusing. How do I hide it?</p>
[ { "answer_id": 44146, "author": "Simon Gillbee", "author_id": 756, "author_profile": "https://Stackoverflow.com/users/756", "pm_score": 1, "selected": false, "text": "<p>If you disable the text box (set <code>Enable=false</code>), the text in it is still scrollable and selectable. If you...
2008/09/04
[ "https://Stackoverflow.com/questions/44131", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1042/" ]
I need to display a variable-length message and allow the text to be selectable. I have made the TextBox ReadOnly which does not allow the text to be edited, but the input caret is still shown. The blinking input caret is confusing. How do I hide it?
You can do through a win32 call ``` [DllImport("user32.dll")] static extern bool HideCaret(IntPtr hWnd); public void HideCaret() { HideCaret(someTextBox.Handle); } ```
44,153
<p>Like the title says: Can reflection give you the name of the currently executing method.</p> <p>I'm inclined to guess not, because of the Heisenberg problem. How do you call a method that will tell you the current method without changing what the current method is? But I'm hoping someone can prove me wrong there....
[ { "answer_id": 44158, "author": "bdukes", "author_id": 2688, "author_profile": "https://Stackoverflow.com/users/2688", "pm_score": 2, "selected": false, "text": "<p>I think you should be able to get that from creating a <a href=\"http://msdn.microsoft.com/en-us/library/6zh7csxz(VS.80).as...
2008/09/04
[ "https://Stackoverflow.com/questions/44153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3043/" ]
Like the title says: Can reflection give you the name of the currently executing method. I'm inclined to guess not, because of the Heisenberg problem. How do you call a method that will tell you the current method without changing what the current method is? But I'm hoping someone can prove me wrong there. **Update:*...
As of .NET 4.5, you can also use [[CallerMemberName]](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.callermembernameattribute). Example: a property setter (to answer part 2): ``` protected void SetProperty<T>(T value, [CallerMemberName] string property = null) { this.propertyValues[...
44,176
<p>Is there a way to perform a full text search of a subversion repository, including all the history?</p> <p>For example, I've written a feature that I used somewhere, but then it wasn't needed, so I svn rm'd the files, but now I need to find it again to use it for something else. The svn log probably says something ...
[ { "answer_id": 44185, "author": "dF.", "author_id": 3002, "author_profile": "https://Stackoverflow.com/users/3002", "pm_score": 2, "selected": false, "text": "<p>I don't have any experience with it, but <a href=\"http://supose.soebes.de/\" rel=\"nofollow noreferrer\">SupoSE</a> (open sou...
2008/09/04
[ "https://Stackoverflow.com/questions/44176", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3408/" ]
Is there a way to perform a full text search of a subversion repository, including all the history? For example, I've written a feature that I used somewhere, but then it wasn't needed, so I svn rm'd the files, but now I need to find it again to use it for something else. The svn log probably says something like "remo...
``` git svn clone <svn url> ``` ``` git log -G<some regex> ```
44,181
<p>I have a database with two tables (<code>Table1</code> and <code>Table2</code>). They both have a common column <code>[ColumnA]</code> which is an <code>nvarchar</code>. </p> <p>How can I select this column from both tables and return it as a single column in my result set?</p> <p>So I'm looking for something like...
[ { "answer_id": 44183, "author": "Kevin Fairchild", "author_id": 3743, "author_profile": "https://Stackoverflow.com/users/3743", "pm_score": 5, "selected": true, "text": "<pre><code>SELECT ColumnA FROM Table1 UNION Select ColumnB FROM Table2 ORDER BY 1\n</code></pre>\n\n<p>Also, if you kn...
2008/09/04
[ "https://Stackoverflow.com/questions/44181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1980/" ]
I have a database with two tables (`Table1` and `Table2`). They both have a common column `[ColumnA]` which is an `nvarchar`. How can I select this column from both tables and return it as a single column in my result set? So I'm looking for something like: ``` ColumnA in Table1: a b c ColumnA in Table2: d e f Re...
``` SELECT ColumnA FROM Table1 UNION Select ColumnB FROM Table2 ORDER BY 1 ``` Also, if you know the contents of Table1 and Table2 will **NEVER** overlap, you can use UNION ALL in place of UNION instead. Saves a little bit of resources that way. -- Kevin Fairchild
44,190
<p>I am looking for a simple JavaScript example that updates DOM.<br> Any suggestions?</p>
[ { "answer_id": 44198, "author": "Guy", "author_id": 1463, "author_profile": "https://Stackoverflow.com/users/1463", "pm_score": 0, "selected": false, "text": "<p>I believe that this tutorial on jQuery has an example that might help you: <a href=\"http://docs.jquery.com/Tutorials:Getting_...
2008/09/04
[ "https://Stackoverflow.com/questions/44190", "https://Stackoverflow.com", "https://Stackoverflow.com/users/370899/" ]
I am looking for a simple JavaScript example that updates DOM. Any suggestions?
Here is a short pure-javascript example. Assume you have a div with the id "maincontent". ``` var newnode = document.createTextNode('Here is some text.'); document.getElementById('maincontent').appendChild(newnode); ``` Of course, things are a lot easier (especially when you want to do more complicated things) with ...
44,194
<p>This is what I've got. It works. But, is there a simpler or better way?</p> <p>One an ASPX page, I've got the download link...</p> <pre><code>&lt;asp:HyperLink ID="HyperLinkDownload" runat="server" NavigateUrl="~/Download.aspx"&gt;Download as CSV file&lt;/asp:HyperLink&gt; </code></pre> <p>And then I've got the D...
[ { "answer_id": 44219, "author": "Simon Gillbee", "author_id": 756, "author_profile": "https://Stackoverflow.com/users/756", "pm_score": 6, "selected": true, "text": "<p>CSV formatting has some gotchas. Have you asked yourself these questions:</p>\n\n<ul>\n<li>Does any of my data have emb...
2008/09/04
[ "https://Stackoverflow.com/questions/44194", "https://Stackoverflow.com", "https://Stackoverflow.com/users/83/" ]
This is what I've got. It works. But, is there a simpler or better way? One an ASPX page, I've got the download link... ``` <asp:HyperLink ID="HyperLinkDownload" runat="server" NavigateUrl="~/Download.aspx">Download as CSV file</asp:HyperLink> ``` And then I've got the Download.aspx.vb Code Behind... ``` Public Pa...
CSV formatting has some gotchas. Have you asked yourself these questions: * Does any of my data have embedded commas? * Does any of my data have embedded double-quotes? * Does any of my data have have newlines? * Do I need to support Unicode strings? I see several problems in your code above. The comma thing first of...
44,220
<p>I have been told that there is a performance difference between the following code blocks.</p> <pre><code>foreach (Entity e in entityList) { .... } </code></pre> <p>and </p> <pre><code>for (int i=0; i&lt;entityList.Count; i++) { Entity e = (Entity)entityList[i]; ... } </code></pre> <p>where</p> <pre><cod...
[ { "answer_id": 44225, "author": "Daniel Jennings", "author_id": 3641, "author_profile": "https://Stackoverflow.com/users/3641", "pm_score": 4, "selected": true, "text": "<p>foreach creates an instance of an enumerator (returned from GetEnumerator) and that enumerator also keeps state thr...
2008/09/04
[ "https://Stackoverflow.com/questions/44220", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2894/" ]
I have been told that there is a performance difference between the following code blocks. ``` foreach (Entity e in entityList) { .... } ``` and ``` for (int i=0; i<entityList.Count; i++) { Entity e = (Entity)entityList[i]; ... } ``` where ``` List<Entity> entityList; ``` I am no CLR expect but from wh...
foreach creates an instance of an enumerator (returned from GetEnumerator) and that enumerator also keeps state throughout the course of the foreach loop. It then repeatedly calls for the Next() object on the enumerator and runs your code for each object it returns. They don't boil down to the same code in any way, re...
44,272
<p>This is a php example, but an algorithm for any language would do. What I specifically want to do is bubble up the United States and Canada to the top of the list. Here is an example of the array shortened for brevity. </p> <pre><code>array( 0 =&gt; '-- SELECT --', 1 =&gt; 'Afghanistan', 2 =&gt; 'Albania', ...
[ { "answer_id": 44292, "author": "Leigh Caldwell", "author_id": 3267, "author_profile": "https://Stackoverflow.com/users/3267", "pm_score": 1, "selected": false, "text": "<p>My shortcut in similar cases is to add a space at the start of Canada and two spaces at the start of United States....
2008/09/04
[ "https://Stackoverflow.com/questions/44272", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1797/" ]
This is a php example, but an algorithm for any language would do. What I specifically want to do is bubble up the United States and Canada to the top of the list. Here is an example of the array shortened for brevity. ``` array( 0 => '-- SELECT --', 1 => 'Afghanistan', 2 => 'Albania', 3 => 'Algeria', 4 => ...
What I usually do in these situations is to add a separate field called DisplayOrder or something similar. Everything defaults to, say, 1... You then sort by DisplayOrder and then the Name. If you want something higher or lower on the list, you can tweak the display order accordingly while keeping your normal IDs as-is...
44,288
<p>Comparing string in C# is pretty simple. In fact there are several ways to do it. I have listed some in the block below. What I am curious about are the differences between them and when one should be used over the others? Should one be avoided at all costs? Are there more I haven't listed? </p> <pre><code>st...
[ { "answer_id": 44301, "author": "Ed S.", "author_id": 1053, "author_profile": "https://Stackoverflow.com/users/1053", "pm_score": 6, "selected": false, "text": "<p>From MSDN:</p>\n\n<blockquote>\n <p>\"The CompareTo method was designed primarily for use in sorting or\n alphabetizing ...
2008/09/04
[ "https://Stackoverflow.com/questions/44288", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2894/" ]
Comparing string in C# is pretty simple. In fact there are several ways to do it. I have listed some in the block below. What I am curious about are the differences between them and when one should be used over the others? Should one be avoided at all costs? Are there more I haven't listed? ``` string testString = "T...
Here are the rules for how these functions work: **`stringValue.CompareTo(otherStringValue)`** 1. `null` comes before a string 2. it uses `CultureInfo.CurrentCulture.CompareInfo.Compare`, which means it will use a culture-dependent comparison. This might mean that `ß` will compare equal to `SS` in Germany, or similar...
44,298
<p>I have a databound TextBox in my application like so: (The type of <code>Height</code> is <code>decimal?</code>)</p> <pre class="lang-xml prettyprint-override"><code> &lt;TextBox Text=&quot;{Binding Height, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, ...
[ { "answer_id": 44362, "author": "Dillie-O", "author_id": 71, "author_profile": "https://Stackoverflow.com/users/71", "pm_score": 0, "selected": false, "text": "<p>It sounds to me that you'll want to handle two events:</p>\n\n<p>GotFocus: Will trigger when the textbox gains focus. You can...
2008/09/04
[ "https://Stackoverflow.com/questions/44298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/317/" ]
I have a databound TextBox in my application like so: (The type of `Height` is `decimal?`) ```xml <TextBox Text="{Binding Height, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, Converter={StaticResource NullConverter}}" /> ``` ```cs ...
You can force the keyboard focus to stay on the `TextBox` by handling the `PreviewLostKeyBoardFocus` event like this: ```xml <TextBox PreviewLostKeyboardFocus="TextBox_PreviewLostKeyboardFocus" /> ``` ```cs private void TextBox_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { ...
44,337
<p>As an exercise for myself, I was translating a sample program into various languages. Starting in C#, I had a visitor-pattern interface like so:</p> <pre><code>interface Visitor { void Accept(Bedroom x); void Accept(Bathroom x); void Accept(Kitchen x); void Accept(LivingRoom x)...
[ { "answer_id": 44362, "author": "Dillie-O", "author_id": 71, "author_profile": "https://Stackoverflow.com/users/71", "pm_score": 0, "selected": false, "text": "<p>It sounds to me that you'll want to handle two events:</p>\n\n<p>GotFocus: Will trigger when the textbox gains focus. You can...
2008/09/04
[ "https://Stackoverflow.com/questions/44337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4540/" ]
As an exercise for myself, I was translating a sample program into various languages. Starting in C#, I had a visitor-pattern interface like so: ``` interface Visitor { void Accept(Bedroom x); void Accept(Bathroom x); void Accept(Kitchen x); void Accept(LivingRoom x); } ``` Mo...
You can force the keyboard focus to stay on the `TextBox` by handling the `PreviewLostKeyBoardFocus` event like this: ```xml <TextBox PreviewLostKeyboardFocus="TextBox_PreviewLostKeyboardFocus" /> ``` ```cs private void TextBox_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { ...
44,338
<p>I'm trying to be better about unit testing my code, but right now I'm writing a lot of code that deals with remote systems. SNMP, WMI, that sort of thing. With most classes I can mock up objects to test them, but how do you deal with unit testing a real system? For example, if my class goes out and gets the Win32...
[ { "answer_id": 44525, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": true, "text": "<p>Assuming you meant \"How do I test against things that are hard/impossible to mock\":</p>\n\n<p>If you have a class that \"go...
2008/09/04
[ "https://Stackoverflow.com/questions/44338", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4550/" ]
I'm trying to be better about unit testing my code, but right now I'm writing a lot of code that deals with remote systems. SNMP, WMI, that sort of thing. With most classes I can mock up objects to test them, but how do you deal with unit testing a real system? For example, if my class goes out and gets the Win32\_Logi...
Assuming you meant "How do I test against things that are hard/impossible to mock": If you have a class that "goes out and gets the Win32\_LogicalDisk object for a server" AND does something else (consumes the 'Win32\_LogicalDisk' object in some way), assuming you want to test the pieces of the class that consume this...
44,352
<p>In Python, given a module X and a class Y, how can I iterate or generate a list of all subclasses of Y that exist in module X?</p>
[ { "answer_id": 44381, "author": "Chris AtLee", "author_id": 4558, "author_profile": "https://Stackoverflow.com/users/4558", "pm_score": 5, "selected": true, "text": "<p>Here's one way to do it:</p>\n\n<pre><code>import inspect\n\ndef get_subclasses(mod, cls):\n \"\"\"Yield the classes...
2008/09/04
[ "https://Stackoverflow.com/questions/44352", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
In Python, given a module X and a class Y, how can I iterate or generate a list of all subclasses of Y that exist in module X?
Here's one way to do it: ``` import inspect def get_subclasses(mod, cls): """Yield the classes in module ``mod`` that inherit from ``cls``""" for name, obj in inspect.getmembers(mod): if hasattr(obj, "__bases__") and cls in obj.__bases__: yield obj ```
44,359
<p>I have built a basic data entry application allowing users to browse external content in iframe and enter data quickly from the same page. One of the data variables is the URL. Ideally I would like to be able to load the iframes current url into a textbox with javascript. I realize now that this is not going to happ...
[ { "answer_id": 46361, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "<p>Does this help? </p>\n\n<p><a href=\"http://www.quirksmode.org/js/iframe.html\" rel=\"nofollow noreferrer\">http://www.quir...
2008/09/04
[ "https://Stackoverflow.com/questions/44359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4568/" ]
I have built a basic data entry application allowing users to browse external content in iframe and enter data quickly from the same page. One of the data variables is the URL. Ideally I would like to be able to load the iframes current url into a textbox with javascript. I realize now that this is not going to happen ...
I did some tests in Firefox 3 comparing the value of `.src` and `.documentWindow.location.href` in an `iframe`. (Note: The `documentWindow` is called `contentDocument` in Chrome, so instead of `.documentWindow.location.href` in Chrome it will be `.contentDocument.location.href`.) `src` is always the last URL that was ...
44,376
<p>How do you shade alternating rows in a SQL Server Reporting Services report?</p> <hr> <p><strong>Edit:</strong> There are a bunch of good answers listed below--from <a href="https://stackoverflow.com/questions/44376/add-alternating-row-color-to-sql-server-reporting-services-report#44378">quick</a> and <a href="htt...
[ { "answer_id": 44378, "author": "Michael Haren", "author_id": 29, "author_profile": "https://Stackoverflow.com/users/29", "pm_score": 9, "selected": true, "text": "<p>Go to the table row's BackgroundColor property and choose \"Expression...\"</p>\n\n<p>Use this expression: </p>\n\n<pre><...
2008/09/04
[ "https://Stackoverflow.com/questions/44376", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29/" ]
How do you shade alternating rows in a SQL Server Reporting Services report? --- **Edit:** There are a bunch of good answers listed below--from [quick](https://stackoverflow.com/questions/44376/add-alternating-row-color-to-sql-server-reporting-services-report#44378) and [simple](https://stackoverflow.com/questions/44...
Go to the table row's BackgroundColor property and choose "Expression..." Use this expression: ``` = IIf(RowNumber(Nothing) Mod 2 = 0, "Silver", "Transparent") ``` This trick can be applied to many areas of the report. And in .NET 3.5+ You could use: ``` = If(RowNumber(Nothing) Mod 2 = 0, "Silver", "Transparent"...
44,394
<p>I have a MemoryStream with the contents of a Font File (.ttf) and I would like to be able to create a FontFamily WPF object from that stream <strong>WITHOUT</strong> writing the contents of the stream to disk. I know this is possible with a System.Drawing.FontFamily but I cannot find out how to do it with System.Win...
[ { "answer_id": 7336238, "author": "kobi7", "author_id": 588613, "author_profile": "https://Stackoverflow.com/users/588613", "pm_score": 1, "selected": false, "text": "<p>The best approach I could think of, was to save the oldFont to a temp directory, and immediately load it using the new...
2008/09/04
[ "https://Stackoverflow.com/questions/44394", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4572/" ]
I have a MemoryStream with the contents of a Font File (.ttf) and I would like to be able to create a FontFamily WPF object from that stream **WITHOUT** writing the contents of the stream to disk. I know this is possible with a System.Drawing.FontFamily but I cannot find out how to do it with System.Windows.Media.FontF...
There is a similar question [here](https://stackoverflow.com/questions/44912480/c-sharp-wpf-how-to-load-a-fontfamily-from-a-byte-array), which contains a supposed solution by converting a System.Drawing.FontFamily to a WPF font family, all in memory without any file IO: ``` public static void Load(MemoryStream stream)...
44,401
<p>I've got a sign up form that requires the user to enter their email and password, both are in two separate text boxes. I want to provide a button that the user can click so that the password (which is masked) will appear in a popup when the user clicks the button.</p> <p>Currently my JavaScript code for this is as ...
[ { "answer_id": 44436, "author": "matt b", "author_id": 4249, "author_profile": "https://Stackoverflow.com/users/4249", "pm_score": 1, "selected": false, "text": "<p>I would assume that the browser has some issue with the script attempting to set the value of a password field:</p>\n\n<pre...
2008/09/04
[ "https://Stackoverflow.com/questions/44401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/750/" ]
I've got a sign up form that requires the user to enter their email and password, both are in two separate text boxes. I want to provide a button that the user can click so that the password (which is masked) will appear in a popup when the user clicks the button. Currently my JavaScript code for this is as follows: ...
I did a quick example up of a working version: ``` <html> <head> <script type="text/javascript" src="prototype.js"></script> <script type="text/javascript"> function toggleShowPassword() { var textBox = $('PasswordText'); if (textBox) ...
44,408
<p>I would like to generate a random floating point number between 2 values. What is the best way to do this in C#?</p>
[ { "answer_id": 44424, "author": "Ryan Farley", "author_id": 1627, "author_profile": "https://Stackoverflow.com/users/1627", "pm_score": 2, "selected": false, "text": "<pre><code>// generate a random number starting with 5 and less than 15\nRandom r = new Random();\nint num = r.Next(5, 15...
2008/09/04
[ "https://Stackoverflow.com/questions/44408", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2064/" ]
I would like to generate a random floating point number between 2 values. What is the best way to do this in C#?
The only thing I'd add to [Eric](https://stackoverflow.com/questions/44408/how-do-you-generate-a-random-number-in-c#44428)'s response is an explanation; I feel that knowledge of why code works is better than knowing what code works. The explanation is this: let's say you want a number between 2.5 and 4.5. The range is...
44,470
<p>Every time I publish the application in <a href="http://en.wikipedia.org/wiki/ClickOnce" rel="nofollow noreferrer">ClickOnce</a> I get get it to update the revision number by one. Is there a way to get this change automatically to change the version number in AssemblyInfo.cs file (all our error reporting looks at th...
[ { "answer_id": 44606, "author": "Judah Gabriel Himango", "author_id": 536, "author_profile": "https://Stackoverflow.com/users/536", "pm_score": 0, "selected": false, "text": "<p>You'll probably need to create a piece of code that updates AssemblyInfo.cs according to the version number st...
2008/09/04
[ "https://Stackoverflow.com/questions/44470", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3798/" ]
Every time I publish the application in [ClickOnce](http://en.wikipedia.org/wiki/ClickOnce) I get get it to update the revision number by one. Is there a way to get this change automatically to change the version number in AssemblyInfo.cs file (all our error reporting looks at the Assembly Version)?
We use Team Foundation Server Team Build and have added a block to the TFSBuild.proj's `AfterCompile` target to trigger the ClickOnce publish with our preferred version number: ```xml <MSBuild Projects="$(SolutionRoot)\MyProject\Myproject.csproj" Properties="PublishDir=$(OutDir)\myProjectPublish\; ...
44,481
<p>For this directory structure:</p> <pre><code>. |-- README.txt |-- firstlevel.rb `-- lib |-- models | |-- foo | | `-- fourthlevel.rb | `-- thirdlevel.rb `-- secondlevel.rb 3 directories, 5 files </code></pre> <p>The glob would match: </p> <pre><code>firstlevel.rb lib/secondlevel.rb l...
[ { "answer_id": 44486, "author": "James A. Rosen", "author_id": 1190, "author_profile": "https://Stackoverflow.com/users/1190", "pm_score": 1, "selected": false, "text": "<p>In Ruby itself:</p>\n\n<pre><code>Dir.glob('**/*.rb') perhaps?\n</code></pre>\n" }, { "answer_id": 44494, ...
2008/09/04
[ "https://Stackoverflow.com/questions/44481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3624/" ]
For this directory structure: ``` . |-- README.txt |-- firstlevel.rb `-- lib |-- models | |-- foo | | `-- fourthlevel.rb | `-- thirdlevel.rb `-- secondlevel.rb 3 directories, 5 files ``` The glob would match: ``` firstlevel.rb lib/secondlevel.rb lib/models/thirdlevel.rb lib/models/fo...
Apologies if I've missed the real point of the question but, if I was using sh/bash/etc., then I would probably use *find* to do the job: ``` find . -name '*.rb' -type f ``` Globs can get a bit nasty when used from within a script and *find* is much more flexible.
44,542
<p>Can someome provide code or pseudo-code for how the paging links on StackOverflow are generated?</p> <p>I keep racking my brain but can't think of a decent way to build the dynamic links that always show the 2 pages around the current, plus the first and last.</p> <p>Example: <code>1 ... 5 6 7 ... 593</code></p>
[ { "answer_id": 44560, "author": "Mike Stone", "author_id": 122, "author_profile": "https://Stackoverflow.com/users/122", "pm_score": 1, "selected": false, "text": "<p>Well, if you know the current page, it's pretty trivial to just subtract the number by 1, and add it by 1, then check tho...
2008/09/04
[ "https://Stackoverflow.com/questions/44542", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1097/" ]
Can someome provide code or pseudo-code for how the paging links on StackOverflow are generated? I keep racking my brain but can't think of a decent way to build the dynamic links that always show the 2 pages around the current, plus the first and last. Example: `1 ... 5 6 7 ... 593`
There are several other answers already, but I'd like to show you the approach I took to solve it: First, let's check out how Stack Overflow handles normal cases and edge cases. Each of my pages displays 10 results, so to find out what it does for 1 page, find a tag that has less than 11 entries: [usability](https://st...
44,569
<p>I have never used octal numbers in my code nor come across any code that used it (hexadecimal and bit twiddling notwithstanding).</p> <p>I started programming in C/C++ about 1994 so maybe I'm too young for this? Does older code use octal? C includes support for these by prepending a 0, but where is the code that us...
[ { "answer_id": 44575, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 3, "selected": false, "text": "<p>It's useful for the <code>chmod</code> and <code>mkdir</code> functions in Unix land, but aside from that I can't think...
2008/09/04
[ "https://Stackoverflow.com/questions/44569", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2543/" ]
I have never used octal numbers in my code nor come across any code that used it (hexadecimal and bit twiddling notwithstanding). I started programming in C/C++ about 1994 so maybe I'm too young for this? Does older code use octal? C includes support for these by prepending a 0, but where is the code that uses these b...
I recently had to write network protocol code that accesses 3-bit fields. Octal comes in handy when you want to debug that. Just for effect, can you tell me what the 3-bit fields of this are? ``` 0x492492 ``` On the other hand, this same number in octal: ``` 022222222 ``` Now, finally, in binary (in groups of 3...
44,617
<p>I would like to be able to add a "message" to a unit test, such that it actually appears within the TestResult.xml file generated by NUnit. For example, this is currently generated:</p> <pre><code>&lt;results&gt; &lt;test-case name="MyNamespace.Tests.MyTest" executed="True" success="True" time="0.203" asserts=...
[ { "answer_id": 44653, "author": "Blair Conrad", "author_id": 1199, "author_profile": "https://Stackoverflow.com/users/1199", "pm_score": 3, "selected": true, "text": "<p>This may be missing the point, but how about naming the tests so they indicate what they test - then you may not even ...
2008/09/04
[ "https://Stackoverflow.com/questions/44617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2696/" ]
I would like to be able to add a "message" to a unit test, such that it actually appears within the TestResult.xml file generated by NUnit. For example, this is currently generated: ``` <results> <test-case name="MyNamespace.Tests.MyTest" executed="True" success="True" time="0.203" asserts="4" /> </results> ``` ...
This may be missing the point, but how about naming the tests so they indicate what they test - then you may not even need the message. If it proves to be absolutely necessary, I think you'll need to produce your own testrunner that would (off the top of my head) read an additional attribute off the TestCase and atta...
44,656
<p>The code that I want to write is like this:</p> <pre><code>void MethodOnThreadA() { for (;;) { // Do stuff if (ErrorConditionMet) ThrowOnThread(threadB, new MyException(...)); } } void MethodOnThreadB() { try { for (;;) { // Do stuff ...
[ { "answer_id": 44661, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 3, "selected": false, "text": "<p>There are enough problems with exceptions that can be thrown on threads by other mechanisms, like aborting threads ...
2008/09/04
[ "https://Stackoverflow.com/questions/44656", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4592/" ]
The code that I want to write is like this: ``` void MethodOnThreadA() { for (;;) { // Do stuff if (ErrorConditionMet) ThrowOnThread(threadB, new MyException(...)); } } void MethodOnThreadB() { try { for (;;) { // Do stuff } } ...
This is NOT a good idea [This article talks about ruby's timeout library.](http://blog.headius.com/2008/02/rubys-threadraise-threadkill-timeoutrb.html) which throws exceptions across threads. It explains how doing such a thing is fundamentally broken. It's not just broken in ruby, it's broken anywhere that throws exc...
44,693
<p>In C++, what alternatives do I have for exposing a collection, from the point of view of performance and data integrity?</p> <p>My problem is that I want to return an internal list of data to the caller, but I don't want to generate a copy. Thant leaves me with either returning a reference to the list, or a pointer...
[ { "answer_id": 44697, "author": "Ben Collins", "author_id": 3279, "author_profile": "https://Stackoverflow.com/users/3279", "pm_score": 2, "selected": false, "text": "<p>Maybe something like this?</p>\n\n<pre><code>const std::vector&lt;mydata&gt;&amp; getData()\n{\n return _myPrivateDat...
2008/09/04
[ "https://Stackoverflow.com/questions/44693", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3081/" ]
In C++, what alternatives do I have for exposing a collection, from the point of view of performance and data integrity? My problem is that I want to return an internal list of data to the caller, but I don't want to generate a copy. Thant leaves me with either returning a reference to the list, or a pointer to the li...
[RichQ's answer](https://stackoverflow.com/questions/44693/in-c-what-alternatives-do-i-have-for-exposing-a-collection-from-the-point-of-vi#44734) is a reasonable technique, if you're using an array, vector, etc. If you're using a collection that isn't indexed by ordinal values... or think you *might need to* at some ...
44,715
<p>Ruby setters—whether created by <code>(c)attr_accessor</code> or manually—seem to be the only methods that need <code>self.</code> qualification when accessed within the class itself. This seems to put Ruby alone the world of languages:</p> <ul> <li>All methods need <code>self</code>/<code>this</code> (like Perl, ...
[ { "answer_id": 44779, "author": "Mike Stone", "author_id": 122, "author_profile": "https://Stackoverflow.com/users/122", "pm_score": 6, "selected": false, "text": "<p>Well, I think the reason this is the case is because <code>qwerty = 4</code> is ambiguous—are you defining a new variable...
2008/09/04
[ "https://Stackoverflow.com/questions/44715", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4615/" ]
Ruby setters—whether created by `(c)attr_accessor` or manually—seem to be the only methods that need `self.` qualification when accessed within the class itself. This seems to put Ruby alone the world of languages: * All methods need `self`/`this` (like Perl, and I think Javascript) * No methods require `self`/`this` ...
The important thing to remember here is that Ruby methods can be (un)defined at any point, so to intelligently resolve the ambiguity, every assignment would need to run code to check whether there is a method with the assigned-to name at the time of assignment.
44,771
<p>Ok, so my method in my webservice requires a type to be passed, it is called in the ServiceMethod property of the AutoCompleteExtender, I am fuzzy about how I should do that so I called it like this:</p> <pre><code>ServiceMethod="DropDownLoad&lt;&lt;%=(typeof)subCategory%&gt;&gt;" </code></pre> <p>where subCategor...
[ { "answer_id": 44923, "author": "bentford", "author_id": 946, "author_profile": "https://Stackoverflow.com/users/946", "pm_score": 2, "selected": true, "text": "<p>I dont' think calling a Generic Method on a webservice is possible.</p>\n\n<p>If you look at the service description of two ...
2008/09/04
[ "https://Stackoverflow.com/questions/44771", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4140/" ]
Ok, so my method in my webservice requires a type to be passed, it is called in the ServiceMethod property of the AutoCompleteExtender, I am fuzzy about how I should do that so I called it like this: ``` ServiceMethod="DropDownLoad<<%=(typeof)subCategory%>>" ``` where subCategory is a page property that looks like t...
I dont' think calling a Generic Method on a webservice is possible. If you look at the service description of two identical methods, one generic, one not: ``` [WebMethod] public string[] GetSearchList(string prefixText, int count) { } [WebMethod] public string[] GetSearchList2<T>(string prefixText, int count) { } `...
44,778
<p>What would be your preferred way to concatenate strings from a sequence such that between every two consecutive pairs a comma is added. That is, how do you map, for instance, <code>['a', 'b', 'c']</code> to <code>'a,b,c'</code>? (The cases <code>['s']</code> and <code>[]</code> should be mapped to <code>'s'</code> a...
[ { "answer_id": 44781, "author": "Mark Biek", "author_id": 305, "author_profile": "https://Stackoverflow.com/users/305", "pm_score": 11, "selected": true, "text": "<pre><code>my_list = ['a', 'b', 'c', 'd']\nmy_string = ','.join(my_list)\n</code></pre>\n\n<pre><code>'a,b,c,d'\n</code></pre...
2008/09/04
[ "https://Stackoverflow.com/questions/44778", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4285/" ]
What would be your preferred way to concatenate strings from a sequence such that between every two consecutive pairs a comma is added. That is, how do you map, for instance, `['a', 'b', 'c']` to `'a,b,c'`? (The cases `['s']` and `[]` should be mapped to `'s'` and `''`, respectively.) I usually end up using something ...
``` my_list = ['a', 'b', 'c', 'd'] my_string = ','.join(my_list) ``` ``` 'a,b,c,d' ``` This won't work if the list contains integers --- And if the list contains non-string types (such as integers, floats, bools, None) then do: ``` my_string = ','.join(map(str, my_list)) ```
44,780
<p>What's the best way to implement a SQL script that will grant select, references, insert, update, and delete permissions to a database role on all the user tables in a database?</p> <p>Ideally, this script could be run multiple times, as new tables were added to the database. SQL Server Management Studio generates ...
[ { "answer_id": 44841, "author": "Dr Zimmerman", "author_id": 4605, "author_profile": "https://Stackoverflow.com/users/4605", "pm_score": 2, "selected": false, "text": "<p>I'm sure there is an easier way, but you could loop through the sysobjects table in the database and grant permission...
2008/09/04
[ "https://Stackoverflow.com/questions/44780", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3475/" ]
What's the best way to implement a SQL script that will grant select, references, insert, update, and delete permissions to a database role on all the user tables in a database? Ideally, this script could be run multiple times, as new tables were added to the database. SQL Server Management Studio generates scripts fo...
Dr Zimmerman is on the right track here. I'd be looking to write a stored procedure that has a cursor looping through user objects using execute immediate to affect the grant. Something like this: ``` IF EXISTS ( SELECT 1 FROM sysobjects WHERE name = 'sp_grantastic' AND type = 'P' ) DROP PROCEDURE sp_gran...
44,787
<p>Scenario: You have an ASP.Net webpage that should display the next image in a series of images. If 1.jpg is currently loaded, the refresh should load 2.jpg.<br> Assuming I would use this code, where do you get the current images name.</p> <pre><code>string currImage = MainPic.ImageUrl.Replace(".jpg", ""); currIma...
[ { "answer_id": 44802, "author": "bdukes", "author_id": 2688, "author_profile": "https://Stackoverflow.com/users/2688", "pm_score": 0, "selected": false, "text": "<p>You'll have to hide the last value in a HiddenField or ViewState or somewhere like that...</p>\n" }, { "answer_id":...
2008/09/04
[ "https://Stackoverflow.com/questions/44787", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4298/" ]
Scenario: You have an ASP.Net webpage that should display the next image in a series of images. If 1.jpg is currently loaded, the refresh should load 2.jpg. Assuming I would use this code, where do you get the current images name. ``` string currImage = MainPic.ImageUrl.Replace(".jpg", ""); currImage = currImage....
``` int num = 1; if(Session["ImageNumber"] != null) { num = Convert.ToInt32(Session["ImageNumber"]) + 1; } Session["ImageNumber"] = num; ```
44,799
<p>We're currently building an application that executes a number of external tools. We often have to pass information entered into our system by users to these tools.</p> <p>Obviously, this is a big security nightmare waiting to happen.</p> <p>Unfortunately, we've not yet found any classes in the .NET Framework tha...
[ { "answer_id": 44807, "author": "Curt Hagenlocher", "author_id": 533, "author_profile": "https://Stackoverflow.com/users/533", "pm_score": 4, "selected": true, "text": "<p>Are you executing the programs directly or going through the shell? If you always launch an external program by giv...
2008/09/04
[ "https://Stackoverflow.com/questions/44799", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1931/" ]
We're currently building an application that executes a number of external tools. We often have to pass information entered into our system by users to these tools. Obviously, this is a big security nightmare waiting to happen. Unfortunately, we've not yet found any classes in the .NET Framework that execute command ...
Are you executing the programs directly or going through the shell? If you always launch an external program by giving the full path name to the executable and leaving the shell out of the equation, then you aren't really susceptible to any kind of command line injection. EDIT: DrFloyd, the shell is responsible for ev...
44,817
<p>Has anyone used ADO.NET Data Services as a data source for Adobe Flex applications? If so, any success stories or tragedies to avoid? If you did use it, how did you handle security?</p>
[ { "answer_id": 45891, "author": "Adam Cuzzort", "author_id": 4760, "author_profile": "https://Stackoverflow.com/users/4760", "pm_score": 3, "selected": true, "text": "<p>I use WebORB for .NET to do Flex remoting and then use DLINQ on the server. One tricky thing about using LINQ with Web...
2008/09/04
[ "https://Stackoverflow.com/questions/44817", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4541/" ]
Has anyone used ADO.NET Data Services as a data source for Adobe Flex applications? If so, any success stories or tragedies to avoid? If you did use it, how did you handle security?
I use WebORB for .NET to do Flex remoting and then use DLINQ on the server. One tricky thing about using LINQ with WebORB is that WebORB uses Reflection to automatically retrieve all the relationships of the object(s) you return to Flex. This causes severe time penalties as LINQ uses lazy loading to load relationships....
44,853
<p>I'm using ant to generate javadocs, but get this exception over and over - why?</p> <p>I'm using JDK version <strong>1.6.0_06</strong>.</p> <pre><code>[javadoc] java.lang.ClassCastException: com.sun.tools.javadoc.ClassDocImpl cannot be cast to com.sun.javadoc.AnnotationTypeDoc [javadoc] at com.sun.tools.java...
[ { "answer_id": 44870, "author": "John Meagher", "author_id": 3535, "author_profile": "https://Stackoverflow.com/users/3535", "pm_score": 7, "selected": true, "text": "<p>It looks like this has been reported as a <a href=\"http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6442982\" rel=\...
2008/09/04
[ "https://Stackoverflow.com/questions/44853", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1310/" ]
I'm using ant to generate javadocs, but get this exception over and over - why? I'm using JDK version **1.6.0\_06**. ``` [javadoc] java.lang.ClassCastException: com.sun.tools.javadoc.ClassDocImpl cannot be cast to com.sun.javadoc.AnnotationTypeDoc [javadoc] at com.sun.tools.javadoc.AnnotationDescImpl.annotation...
It looks like this has been reported as a [Java bug](http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6442982). It appears to be caused by using annotations from a 3rd party library (like JUnit) and not including the jar with that annotation in the javadoc invocation. If that is the case, just use the -classpath op...
44,864
<p>For example I have a situation where I have something like this (contrived) example:</p> <pre><code>&lt;div id="outer" style="margin: auto&gt; &lt;div id="inner1" style="float: left"&gt;content&lt;/div&gt; &lt;div id="inner2" style="float: left"&gt;content&lt;/div&gt; &lt;div id="inner3" style="float: l...
[ { "answer_id": 44872, "author": "Simon Young", "author_id": 4330, "author_profile": "https://Stackoverflow.com/users/4330", "pm_score": 2, "selected": false, "text": "<p>Try the <a href=\"https://addons.mozilla.org/en-US/firefox/addon/60\" rel=\"nofollow noreferrer\">Web Developer Plugin...
2008/09/04
[ "https://Stackoverflow.com/questions/44864", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2168/" ]
For example I have a situation where I have something like this (contrived) example: ``` <div id="outer" style="margin: auto> <div id="inner1" style="float: left">content</div> <div id="inner2" style="float: left">content</div> <div id="inner3" style="float: left">content</div> <br style="clear: both"/...
Try the [Web Developer Plugin](https://addons.mozilla.org/en-US/firefox/addon/60) for Firefox. Specifically, the **Information -> Display Block Size** and **Outline -> Outline Block Level Elements** options. This will allow to see the borders of your elements, and their size as Firefox sees them.
44,903
<p>I have multiple selects:</p> <pre><code>&lt;select id="one"&gt; &lt;option value="1"&gt;one&lt;/option&gt; &lt;option value="2"&gt;two&lt;/option&gt; &lt;option value="3"&gt;three&lt;/option&gt; &lt;/select&gt; &lt;select id="two"&gt; &lt;option value="1"&gt;one&lt;/option&gt; &lt;option value="2"&gt;two&...
[ { "answer_id": 44908, "author": "Jason Bunting", "author_id": 1790, "author_profile": "https://Stackoverflow.com/users/1790", "pm_score": 3, "selected": true, "text": "<p>I am not (currently) a user of jQuery, but I can tell you that you need to temporarily disconnect your event handler ...
2008/09/04
[ "https://Stackoverflow.com/questions/44903", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1414/" ]
I have multiple selects: ``` <select id="one"> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select> <select id="two"> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select> ``` What I want is to select "...
I am not (currently) a user of jQuery, but I can tell you that you need to temporarily disconnect your event handler while you repopulate the items or, at the least, set a flag that you then test for and based on its value, handle the change.
44,905
<p>When writing a switch statement, there appears to be two limitations on what you can switch on in case statements.</p> <p>For example (and yes, I know, if you're doing this sort of thing it probably means your <a href="https://en.wikipedia.org/wiki/Object-oriented_programming" rel="noreferrer">object-oriented</a> (...
[ { "answer_id": 44921, "author": "Brian Ensink", "author_id": 1254, "author_profile": "https://Stackoverflow.com/users/1254", "pm_score": 8, "selected": true, "text": "<p>This is my original post, which sparked some debate... <strong>because it is wrong</strong>:</p>\n\n<blockquote>\n <p...
2008/09/04
[ "https://Stackoverflow.com/questions/44905", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3394/" ]
When writing a switch statement, there appears to be two limitations on what you can switch on in case statements. For example (and yes, I know, if you're doing this sort of thing it probably means your [object-oriented](https://en.wikipedia.org/wiki/Object-oriented_programming) (OO) architecture is iffy - this is jus...
This is my original post, which sparked some debate... **because it is wrong**: > > The switch statement is not the same > thing as a big if-else statement. > Each case must be unique and evaluated > statically. The switch statement does > a constant time branch regardless of > how many cases you have. The if-e...
44,917
<p>Is there any efficiency difference in an explicit vs implicit inner join? For example:</p> <pre><code>SELECT * FROM table a INNER JOIN table b ON a.id = b.id; </code></pre> <p>vs.</p> <pre><code>SELECT a.*, b.* FROM table a, table b WHERE a.id = b.id; </code></pre>
[ { "answer_id": 44932, "author": "lomaxx", "author_id": 493, "author_profile": "https://Stackoverflow.com/users/493", "pm_score": 8, "selected": true, "text": "<p>Performance wise, they are exactly the same (at least in SQL Server).</p>\n\n<p>PS: Be aware that the <code>IMPLICIT OUTER JOI...
2008/09/04
[ "https://Stackoverflow.com/questions/44917", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4316/" ]
Is there any efficiency difference in an explicit vs implicit inner join? For example: ``` SELECT * FROM table a INNER JOIN table b ON a.id = b.id; ``` vs. ``` SELECT a.*, b.* FROM table a, table b WHERE a.id = b.id; ```
Performance wise, they are exactly the same (at least in SQL Server). PS: Be aware that the `IMPLICIT OUTER JOIN` syntax is deprecated since SQL Server 2005. (The `IMPLICIT INNER JOIN` syntax as used in the question is still supported) [Deprecation of "Old Style" JOIN Syntax: Only A Partial Thing](https://learn.micro...
44,937
<p>I want to make an etag that matches what Apache produces. How does apache create it's etags?</p>
[ { "answer_id": 44939, "author": "Chris Bartow", "author_id": 497, "author_profile": "https://Stackoverflow.com/users/497", "pm_score": 5, "selected": true, "text": "<p>Apache uses the standard format of inode-filesize-mtime. The only caveat to this is that the mtime must be epoch time a...
2008/09/04
[ "https://Stackoverflow.com/questions/44937", "https://Stackoverflow.com", "https://Stackoverflow.com/users/497/" ]
I want to make an etag that matches what Apache produces. How does apache create it's etags?
Apache uses the standard format of inode-filesize-mtime. The only caveat to this is that the mtime must be epoch time and padded with zeros so it is 16 digits. Here is how to do it in PHP: ``` $fs = stat($file); header("Etag: ".sprintf('"%x-%x-%s"', $fs['ino'], $fs['size'],base_convert(str_pad($fs['mtime'],16,"0"),10,...
44,942
<p>Can you cast a <code>List&lt;int&gt;</code> to <code>List&lt;string&gt;</code> somehow?</p> <p>I know I could loop through and .ToString() the thing, but a cast would be awesome.</p> <p>I'm in C# 2.0 (so no <a href="http://en.wikipedia.org/wiki/Language_Integrated_Query" rel="noreferrer">LINQ</a>).</p>
[ { "answer_id": 44949, "author": "Erik van Brakel", "author_id": 909, "author_profile": "https://Stackoverflow.com/users/909", "pm_score": 3, "selected": false, "text": "<p>Is C# 2.0 able to do <code>List&lt;T&gt;.Convert</code>? If so, I think your best guess would be to use that with a ...
2008/09/04
[ "https://Stackoverflow.com/questions/44942", "https://Stackoverflow.com", "https://Stackoverflow.com/users/493/" ]
Can you cast a `List<int>` to `List<string>` somehow? I know I could loop through and .ToString() the thing, but a cast would be awesome. I'm in C# 2.0 (so no [LINQ](http://en.wikipedia.org/wiki/Language_Integrated_Query)).
.NET 2.0 has the `ConvertAll` method where you can pass in a converter function: ``` List<int> l1 = new List<int>(new int[] { 1, 2, 3 } ); List<string> l2 = l1.ConvertAll<string>(delegate(int i) { return i.ToString(); }); ```
44,961
<p>I've searched on the Internet for comparisons between <a href="http://en.wikipedia.org/wiki/F_Sharp_%28programming_language%29" rel="noreferrer">F#</a> and <a href="http://en.wikipedia.org/wiki/Haskell_%28programming_language%29" rel="noreferrer">Haskell</a> but haven't found anything really definitive. What are the...
[ { "answer_id": 44969, "author": "Erik van Brakel", "author_id": 909, "author_profile": "https://Stackoverflow.com/users/909", "pm_score": 2, "selected": false, "text": "<p>Well, for one I'd say a main advantage is that F# compiles against the .NET platform which makes it easy to deploy o...
2008/09/04
[ "https://Stackoverflow.com/questions/44961", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3394/" ]
I've searched on the Internet for comparisons between [F#](http://en.wikipedia.org/wiki/F_Sharp_%28programming_language%29) and [Haskell](http://en.wikipedia.org/wiki/Haskell_%28programming_language%29) but haven't found anything really definitive. What are the primary differences and why would I want to choose one ove...
Haskell is a "pure" functional language, where as F# has aspects of both imperative/OO and functional languages. Haskell also has lazy evaluation, which is fairly rare amongst functional languages. What do these things mean? A pure functional language, means there are no side effects (or changes in shared state, when ...
44,965
<p>Having briefly looked at Haskell recently, what would be a <em>brief, succinct, practical</em> explanation as to what a monad essentially is?</p> <p>I have found most explanations I've come across to be fairly inaccessible and lacking in practical detail.</p>
[ { "answer_id": 2538, "author": "nlucaroni", "author_id": 157, "author_profile": "https://Stackoverflow.com/users/157", "pm_score": 7, "selected": false, "text": "<p>But, <a href=\"http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html\" rel=\"noreferrer\">You could have i...
2008/09/04
[ "https://Stackoverflow.com/questions/44965", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3394/" ]
Having briefly looked at Haskell recently, what would be a *brief, succinct, practical* explanation as to what a monad essentially is? I have found most explanations I've come across to be fairly inaccessible and lacking in practical detail.
First: The term **monad** is a bit vacuous if you are not a mathematician. An alternative term is **computation builder** which is a bit more descriptive of what they are actually useful for. They are a pattern for chaining operations. It looks a bit like method chaining in object-oriented languages, but the mechanism...
44,980
<p>How can one determine, in code, how long the machine is locked?</p> <p>Other ideas outside of C# are also welcome.</p> <hr> <p>I like the windows service idea (and have accepted it) for simplicity and cleanliness, but unfortunately I don't think it will work for me in this particular case. I wanted to run this on...
[ { "answer_id": 44987, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "<p>Below is the 100% working code to find if the PC is locked or not.</p>\n\n<p>Before using this use the namespace <code>Syst...
2008/09/04
[ "https://Stackoverflow.com/questions/44980", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1588/" ]
How can one determine, in code, how long the machine is locked? Other ideas outside of C# are also welcome. --- I like the windows service idea (and have accepted it) for simplicity and cleanliness, but unfortunately I don't think it will work for me in this particular case. I wanted to run this on my workstation at...
I hadn't found this before, but from any application you can hookup a SessionSwitchEventHandler. Obviously your application will need to be running, but so long as it is: ``` Microsoft.Win32.SystemEvents.SessionSwitch += new Microsoft.Win32.SessionSwitchEventHandler(SystemEvents_SessionSwitch); void SystemEvents_Sess...
44,989
<p>I'm trying to get the following bit of code to work in LINQPad but am unable to index into a var. Anybody know how to index into a var in LINQ?</p> <pre><code>string[] sa = {"one", "two", "three"}; sa[1].Dump(); var va = sa.Select( (a,i) =&gt; new {Line = a, Index = i}); va[1].Dump(); // Cannot apply indexing with...
[ { "answer_id": 44991, "author": "Joseph Daigle", "author_id": 507, "author_profile": "https://Stackoverflow.com/users/507", "pm_score": 5, "selected": true, "text": "<p>As the comment says, you cannot apply indexing with <code>[]</code> to an expression of type <code>System.Collections.G...
2008/09/04
[ "https://Stackoverflow.com/questions/44989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1463/" ]
I'm trying to get the following bit of code to work in LINQPad but am unable to index into a var. Anybody know how to index into a var in LINQ? ``` string[] sa = {"one", "two", "three"}; sa[1].Dump(); var va = sa.Select( (a,i) => new {Line = a, Index = i}); va[1].Dump(); // Cannot apply indexing with [] to an express...
As the comment says, you cannot apply indexing with `[]` to an expression of type `System.Collections.Generic.IEnumerable<T>`. The IEnumerable interface only supports the method `GetEnumerator()`. However with LINQ you can call the extension method `ElementAt(int)`.
44,999
<p>I have a "showall" query string parameter in the url, the parameter is being added dynamically when "Show All/Show Pages" button is clicked. </p> <p>I want the ability to toggle "showall" query string parameter value depending on user clicking the "Show All/Show Pages" button.</p> <p>I'm doing some nested "if's" a...
[ { "answer_id": 45003, "author": "Toran Billups", "author_id": 2701, "author_profile": "https://Stackoverflow.com/users/2701", "pm_score": 0, "selected": false, "text": "<p>Another dirty alternative could be just to use a hidden input and set that on/off instead of manipulating the url.</...
2008/09/04
[ "https://Stackoverflow.com/questions/44999", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3661/" ]
I have a "showall" query string parameter in the url, the parameter is being added dynamically when "Show All/Show Pages" button is clicked. I want the ability to toggle "showall" query string parameter value depending on user clicking the "Show All/Show Pages" button. I'm doing some nested "if's" and `string.Replac...
Just to elaborate on Toran's answer: Use: `<asp:HiddenField ID="ShowAll" Value="False" runat="server" />` To toggle your state: ``` protected void ToggleState(object sender, EventArgs e) { //parse string as boolean, invert, and convert back to string ShowAll.Value = (!Boolean.Parse(ShowAll.Value)).ToStrin...
45,004
<p>Is there a way to select a parent element based on the class of a child element in the class? The example that is relevant to me relating to HTML output by a nice menu plugin for <a href="http://drupal.org" rel="noreferrer">http://drupal.org</a>. The output renders like this: </p> <pre><code>&lt;ul class="menu"&...
[ { "answer_id": 45008, "author": "Dave Ward", "author_id": 60, "author_profile": "https://Stackoverflow.com/users/60", "pm_score": 8, "selected": true, "text": "<p>Unfortunately, there's no way to do that with CSS.</p>\n\n<p>It's not very difficult with JavaScript though:</p>\n\n<pre><cod...
2008/09/05
[ "https://Stackoverflow.com/questions/45004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4640/" ]
Is there a way to select a parent element based on the class of a child element in the class? The example that is relevant to me relating to HTML output by a nice menu plugin for <http://drupal.org>. The output renders like this: ``` <ul class="menu"> <li> <a class="active">Active Page</a> </li>...
Unfortunately, there's no way to do that with CSS. It's not very difficult with JavaScript though: ``` // JavaScript code: document.getElementsByClassName("active")[0].parentNode; // jQuery code: $('.active').parent().get(0); // This would be the <a>'s parent <li>. ```
45,015
<p>Given a string of JSON data, how can I safely turn that string into a JavaScript object?</p> <p>Obviously I can do this unsafely with something like:</p> <pre><code>var obj = eval("(" + json + ')'); </code></pre> <p>but that leaves me vulnerable to the JSON string containing other code, which it seems very danger...
[ { "answer_id": 45019, "author": "Mark Biek", "author_id": 305, "author_profile": "https://Stackoverflow.com/users/305", "pm_score": 5, "selected": false, "text": "<p>I'm not sure about other ways to do it but here's how you do it in <a href=\"http://www.prototypejs.org/learn/json\" rel=\...
2008/09/05
[ "https://Stackoverflow.com/questions/45015", "https://Stackoverflow.com", "https://Stackoverflow.com/users/797/" ]
Given a string of JSON data, how can I safely turn that string into a JavaScript object? Obviously I can do this unsafely with something like: ``` var obj = eval("(" + json + ')'); ``` but that leaves me vulnerable to the JSON string containing other code, which it seems very dangerous to simply eval.
[`JSON.parse(jsonString)`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) is a pure JavaScript approach so long as you can guarantee a reasonably modern browser.
45,030
<p>I'm wanting to parse a string into a nullable int in C#. ie. I want to get back either the int value of the string or null if it can't be parsed.</p> <p>I was kind of hoping that this would work</p> <pre><code>int? val = stringVal as int?; </code></pre> <p>But that won't work, so the way I'm doing it now is I've...
[ { "answer_id": 45037, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 10, "selected": true, "text": "<p><code>int.TryParse</code> is probably a tad easier:</p>\n\n<pre><code>public static int? ToNullableInt(this string s)\...
2008/09/05
[ "https://Stackoverflow.com/questions/45030", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2975/" ]
I'm wanting to parse a string into a nullable int in C#. ie. I want to get back either the int value of the string or null if it can't be parsed. I was kind of hoping that this would work ``` int? val = stringVal as int?; ``` But that won't work, so the way I'm doing it now is I've written this extension method ``...
`int.TryParse` is probably a tad easier: ``` public static int? ToNullableInt(this string s) { int i; if (int.TryParse(s, out i)) return i; return null; } ``` **Edit** @Glenn `int.TryParse` is "built into the framework". It and `int.Parse` are *the* way to parse strings to ints.
45,036
<p>The .NET <a href="http://msdn.microsoft.com/en-us/library/system.idisposable.aspx" rel="noreferrer">IDisposable Pattern</a> <em>implies</em> that if you write a finalizer, and implement IDisposable, that your finalizer needs to explicitly call Dispose. This is logical, and is what I've always done in the rare situat...
[ { "answer_id": 45043, "author": "Matt Bishop", "author_id": 4301, "author_profile": "https://Stackoverflow.com/users/4301", "pm_score": 3, "selected": false, "text": "<p>I don't think so. You have control over when Dispose is called, which means you could in theory write disposal code th...
2008/09/05
[ "https://Stackoverflow.com/questions/45036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/234/" ]
The .NET [IDisposable Pattern](http://msdn.microsoft.com/en-us/library/system.idisposable.aspx) *implies* that if you write a finalizer, and implement IDisposable, that your finalizer needs to explicitly call Dispose. This is logical, and is what I've always done in the rare situations where a finalizer is warranted. ...
The .Net Garbage Collector calls the Object.Finalize method of an object on garbage collection. By **default** this does **nothing** and must be overidden if you want to free additional resources. Dispose is NOT automatically called and must be **explicity** called if resources are to be released, such as within a 'us...
45,045
<p>When executing SubmitChanges to the DataContext after updating a couple properties with a LINQ to SQL connection (against SQL Server Compact Edition) I get a "Row not found or changed." ChangeConflictException.</p> <pre><code>var ctx = new Data.MobileServerDataDataContext(Common.DatabasePath); var deviceSessionReco...
[ { "answer_id": 83999, "author": "Sam", "author_id": 7021, "author_profile": "https://Stackoverflow.com/users/7021", "pm_score": 9, "selected": true, "text": "<p>Thats nasty, but simple:</p>\n\n<p>Check if the data types for all fields in the O/R-Designer match the data types in your SQL ...
2008/09/05
[ "https://Stackoverflow.com/questions/45045", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2723/" ]
When executing SubmitChanges to the DataContext after updating a couple properties with a LINQ to SQL connection (against SQL Server Compact Edition) I get a "Row not found or changed." ChangeConflictException. ``` var ctx = new Data.MobileServerDataDataContext(Common.DatabasePath); var deviceSessionRecord = ctx.Sessi...
Thats nasty, but simple: Check if the data types for all fields in the O/R-Designer match the data types in your SQL table. **Double check for nullable!** A column should be either nullable in both the O/R-Designer and SQL, or not nullable in both. For example, a NVARCHAR column "title" is marked as NULLable in your ...
45,062
<p>I am trying to link two fields of a given table to the same field in another table. I have done this before so I can't work out what is wrong this time.</p> <p>Anyway:</p> <pre><code>Table1 - Id (Primary) - FK-Table2a (Nullable, foreign key relationship in DB to Table2.Id) - FK-Table2b (Nullable, foreign key relat...
[ { "answer_id": 45065, "author": "Matt Mitchell", "author_id": 364, "author_profile": "https://Stackoverflow.com/users/364", "pm_score": 3, "selected": true, "text": "<p>No idea on the cause, but I just reconstructed my .dbml from scratch and it fixed itself.\nOh for a \"refresh\" feature...
2008/09/05
[ "https://Stackoverflow.com/questions/45062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/364/" ]
I am trying to link two fields of a given table to the same field in another table. I have done this before so I can't work out what is wrong this time. Anyway: ``` Table1 - Id (Primary) - FK-Table2a (Nullable, foreign key relationship in DB to Table2.Id) - FK-Table2b (Nullable, foreign key relationship in DB to Tabl...
No idea on the cause, but I just reconstructed my .dbml from scratch and it fixed itself. Oh for a "refresh" feature...
45,075
<p>Is there a better way to flash a window in Java than this:</p> <pre><code>public static void flashWindow(JFrame frame) throws InterruptedException { int sleepTime = 50; frame.setVisible(false); Thread.sleep(sleepTime); frame.setVisible(true); Thread.sleep(sleepTime); ...
[ { "answer_id": 45234, "author": "David Crow", "author_id": 2783, "author_profile": "https://Stackoverflow.com/users/2783", "pm_score": 1, "selected": false, "text": "<p>Well, there are a few minor improvements we could make. ;)</p>\n\n<p>I would use a Timer to make sure callers don't hav...
2008/09/05
[ "https://Stackoverflow.com/questions/45075", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2598/" ]
Is there a better way to flash a window in Java than this: ``` public static void flashWindow(JFrame frame) throws InterruptedException { int sleepTime = 50; frame.setVisible(false); Thread.sleep(sleepTime); frame.setVisible(true); Thread.sleep(sleepTime); frame.setVisib...
There are two common ways to do this: use JNI to set urgency hints on the taskbar's window, and create a notification icon/message. I prefer the second way, since it's cross-platform and less annoying. See [documentation on the `TrayIcon` class](http://java.sun.com/javase/6/docs/api/java/awt/TrayIcon.html), particular...
45,097
<p>I assume that you can't use a JavaScript code snippet to validate if the browser user has turned off JavaScript. So what can I use instead? Can someone offer a code sample?</p> <p>I'm looking to wrap an if/then statement around it.</p> <p>I often code in CFML, if that helps.</p>
[ { "answer_id": 45102, "author": "Daniel Jennings", "author_id": 3641, "author_profile": "https://Stackoverflow.com/users/3641", "pm_score": 3, "selected": false, "text": "<p>Use the &lt;noscript&gt; HTML tags.</p>\n" }, { "answer_id": 45104, "author": "Chris Marasti-Georg", ...
2008/09/05
[ "https://Stackoverflow.com/questions/45097", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I assume that you can't use a JavaScript code snippet to validate if the browser user has turned off JavaScript. So what can I use instead? Can someone offer a code sample? I'm looking to wrap an if/then statement around it. I often code in CFML, if that helps.
Are we talking about something like this: JavaScript: ``` <body> ... ... <script type="text/javascript"> <!-- document.write("Hello World!") //--> </script> <noscript>Your browser does not support JavaScript!</noscript> ... ... </body> ```
45,123
<p>I am designing a new System and I have a lot of Interfaces that will grow over time with the system. What is the best practice to name this interfaces</p> <pre><code>ISomethingV01 ISomethingV02 etc </code></pre> <p>and I do this</p> <pre><code>public interface ISomething{ void method(); } </code></pre> <p>...
[ { "answer_id": 45127, "author": "FlySwat", "author_id": 1965, "author_profile": "https://Stackoverflow.com/users/1965", "pm_score": 2, "selected": false, "text": "<p>The purpose of an interface is to define an abstract pattern that at type must implement.</p>\n\n<p>It would be better imp...
2008/09/05
[ "https://Stackoverflow.com/questions/45123", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1154/" ]
I am designing a new System and I have a lot of Interfaces that will grow over time with the system. What is the best practice to name this interfaces ``` ISomethingV01 ISomethingV02 etc ``` and I do this ``` public interface ISomething{ void method(); } ``` then I have to add method 2 so now what I do? ``...
Ideally, you shouldn't be changing your interfaces very often (if at all). If you do need to change an interface, you should reconsider its purpose and see if the original name still applies to it. If you still feel that the interfaces will change, and the interfaces changes are small (adding items) and you have contr...
45,132
<p>In particular, I have to extract all the messages and attachments from Lotus Notes files in the fastest and most reliable way. Another point that may be relevant is that I need to do this from a secondary thread.</p> <p><strong>Edit</strong></p> <p>Thanks for the answers - both of which are good. I should provide ...
[ { "answer_id": 45143, "author": "Joshua Turner", "author_id": 820, "author_profile": "https://Stackoverflow.com/users/820", "pm_score": 2, "selected": false, "text": "<p>Take a look at NotesSQL:<br/></p>\n\n<p><a href=\"http://www.ibm.com/developerworks/lotus/products/notesdomino/notessq...
2008/09/05
[ "https://Stackoverflow.com/questions/45132", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1899/" ]
In particular, I have to extract all the messages and attachments from Lotus Notes files in the fastest and most reliable way. Another point that may be relevant is that I need to do this from a secondary thread. **Edit** Thanks for the answers - both of which are good. I should provide more background information. ...
I really do hate that NotesSession COM object. You cannot use it in another thread than the thread it was initialized. Threads in .NET are fibers, the real underlying thread may change at any time. So I suggest using it this way, in a *using* block : ``` Imports Domino Imports System.Threading Public Class Affinite...
45,135
<p>Why does the order in which libraries are linked sometimes cause errors in GCC?</p>
[ { "answer_id": 45206, "author": "titanae", "author_id": 2387, "author_profile": "https://Stackoverflow.com/users/2387", "pm_score": 2, "selected": false, "text": "<p>I have seen this a lot, some of our modules link in excess of a 100 libraries of our code plus system &amp; 3rd party libs...
2008/09/05
[ "https://Stackoverflow.com/questions/45135", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1597/" ]
Why does the order in which libraries are linked sometimes cause errors in GCC?
(See the history on this answer to get the more elaborate text, but I now think it's easier for the reader to see real command lines). --- Common files shared by all below commands ``` // a depends on b, b depends on d $ cat a.cpp extern int a; int main() { return a; } $ cat b.cpp extern int b; int a = b; $ cat ...
45,163
<p>Given this HTML:</p> <pre><code>&lt;ul id="topnav"&gt; &lt;li id="topnav_galleries"&gt;&lt;a href="#"&gt;Galleries&lt;/a&gt;&lt;/li&gt; &lt;li id="topnav_information"&gt;&lt;a href="#"&gt;Information&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>And this CSS:</p> <pre class="lang-css prettyprint-overr...
[ { "answer_id": 45429, "author": "Ian Oxley", "author_id": 1904, "author_profile": "https://Stackoverflow.com/users/1904", "pm_score": 3, "selected": true, "text": "<p>Try this:</p>\n\n<pre class=\"lang-css prettyprint-override\"><code>#topnav {\n overflow:hidden;\n}\n#topnav li {\n ...
2008/09/05
[ "https://Stackoverflow.com/questions/45163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1306/" ]
Given this HTML: ``` <ul id="topnav"> <li id="topnav_galleries"><a href="#">Galleries</a></li> <li id="topnav_information"><a href="#">Information</a></li> </ul> ``` And this CSS: ```css #topnav_galleries a, #topnav_information a { background-repeat: no-repeat; text-indent: -9000px; padding: 0; ...
Try this: ```css #topnav { overflow:hidden; } #topnav li { float:left; } ``` And for IE you will need to add the following: ```css #topnav { zoom:1; } ``` Otherwise your floated < li > tags will spill out of the containing < ul >.
45,169
<p>I need to call into a Win32 API to get a series of strings, and I would like to return an array of those strings to JavaScript. This is for script that runs on local machine for administration scripts, not for the web browser.</p> <p>My IDL file for the COM object has the interface that I am calling into as:</p> <...
[ { "answer_id": 45211, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 4, "selected": true, "text": "<p>If i recall correctly, you'll need to wrap the <code>SAFEARRAY</code> in a <code>VARIANT</code> in order for it to get through,...
2008/09/05
[ "https://Stackoverflow.com/questions/45169", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1462171/" ]
I need to call into a Win32 API to get a series of strings, and I would like to return an array of those strings to JavaScript. This is for script that runs on local machine for administration scripts, not for the web browser. My IDL file for the COM object has the interface that I am calling into as: ``` HRESULT Ge...
If i recall correctly, you'll need to wrap the `SAFEARRAY` in a `VARIANT` in order for it to get through, and then use a [VBArray object](http://msdn.microsoft.com/en-us/library/y39d47w8(VS.85).aspx) to unpack it on the JS side of things: ``` HRESULT GetArrayOfStrings(/*[out, retval]*/ VARIANT* pvarBstrStringArray) { ...
45,176
<p>I have a rather complex page that dynamically builds user controls inside of a repeater. This repeater must be bound during the Init page event before <code>ViewState</code> is initialized or the dynamically created user controls will not retain their state.</p> <p>This creates an interesting Catch-22 because the o...
[ { "answer_id": 45181, "author": "Greg Hurlman", "author_id": 35, "author_profile": "https://Stackoverflow.com/users/35", "pm_score": 1, "selected": false, "text": "<blockquote>\n <p>This also has issues, because I have to explicitly null the session value during non postbacks in order t...
2008/09/05
[ "https://Stackoverflow.com/questions/45176", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1965/" ]
I have a rather complex page that dynamically builds user controls inside of a repeater. This repeater must be bound during the Init page event before `ViewState` is initialized or the dynamically created user controls will not retain their state. This creates an interesting Catch-22 because the object I bind the repe...
The LoadViewState method on the page is definitely the answer. Here's the general idea: ``` protected override void LoadViewState( object savedState ) { var savedStateArray = (object[])savedState; // Get repeaterData from view state before the normal view state restoration occurs. repeaterData = savedStateArray...
45,227
<p>I have been searching everywhere for the following functionality in Lisp, and have gotten nowhere:</p> <ol> <li><p>find the index of something in a list. example:</p> <pre><code>(index-of item InThisList) </code></pre></li> <li><p>replace something at a specific spot in a list. example:</p> <pre><code>(replace it...
[ { "answer_id": 45233, "author": "Jeremy", "author_id": 1114, "author_profile": "https://Stackoverflow.com/users/1114", "pm_score": 6, "selected": true, "text": "<p>You can use <code>setf</code> and <code>nth</code> to replace and retrieve values by index.</p>\n\n<pre><code>(let ((myList ...
2008/09/05
[ "https://Stackoverflow.com/questions/45227", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50/" ]
I have been searching everywhere for the following functionality in Lisp, and have gotten nowhere: 1. find the index of something in a list. example: ``` (index-of item InThisList) ``` 2. replace something at a specific spot in a list. example: ``` (replace item InThisList AtThisIndex) ;i think this can be done wit...
You can use `setf` and `nth` to replace and retrieve values by index. ``` (let ((myList '(1 2 3 4 5 6))) (setf (nth 4 myList) 101); <---- myList) (1 2 3 4 101 6) ``` To find by index you can use [the `position` function](http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/html/cltl/clm/node145.html). `...
45,230
<p>I have a small local network. Only one of the machines is available to the outside world (this is not easily changeable). I'd like to be able to set it up such that ssh requests that don't come in on the standard port go to another machine. Is this possible? If so, how?</p> <p>Oh and all of these machines are runni...
[ { "answer_id": 45231, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 0, "selected": false, "text": "<p>You can use Port Fowarding to do this. Take a look here:</p>\n\n<p><a href=\"http://portforward.com/help/portforwarding.htm\"...
2008/09/05
[ "https://Stackoverflow.com/questions/45230", "https://Stackoverflow.com", "https://Stackoverflow.com/users/85/" ]
I have a small local network. Only one of the machines is available to the outside world (this is not easily changeable). I'd like to be able to set it up such that ssh requests that don't come in on the standard port go to another machine. Is this possible? If so, how? Oh and all of these machines are running either ...
Another way to go would be to use ssh tunneling (which happens on the client side). You'd do an ssh command like this: ``` ssh -L 8022:myinsideserver:22 paul@myoutsideserver ``` That connects you to the machine that's accessible from the outside (myoutsideserver) and creates a tunnel through that ssh connection to ...
45,253
<p>I'm working on a Rails app and am looking to include some functionality from "<a href="https://stackoverflow.com/questions/42566/getting-the-hostname-or-ip-in-ruby-on-rails">Getting the Hostname or IP in Ruby on Rails</a>" that I asked.</p> <p>I'm having problems getting it to work. I was under the impression that ...
[ { "answer_id": 45261, "author": "Curt Hagenlocher", "author_id": 533, "author_profile": "https://Stackoverflow.com/users/533", "pm_score": 3, "selected": true, "text": "<p>You haven't described how you're trying to use the method, so I apologize in advance if this is stuff you already kn...
2008/09/05
[ "https://Stackoverflow.com/questions/45253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/422/" ]
I'm working on a Rails app and am looking to include some functionality from "[Getting the Hostname or IP in Ruby on Rails](https://stackoverflow.com/questions/42566/getting-the-hostname-or-ip-in-ruby-on-rails)" that I asked. I'm having problems getting it to work. I was under the impression that I should just make a ...
You haven't described how you're trying to use the method, so I apologize in advance if this is stuff you already know. The methods on a module never come into use unless the module is included into a class. Instance methods on a class require there to be an instance of the class. You probably want a class method inst...
45,267
<p>When an <code>AutoCompleteExtender</code> is displayed in IE6 it seems to ignore z-index and renders below any select controls (like <strong>dropdownlists</strong>) in IE6.</p> <pre><code>&lt;asp:TextBox ID="TextBox1" runat="server" /&gt; &lt;cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ...
[ { "answer_id": 45284, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 1, "selected": false, "text": "<p>Nothing renders below select controls in IE6. It's one of the many \"features\" microsoft bestowed upon us when they g...
2008/09/05
[ "https://Stackoverflow.com/questions/45267", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4582/" ]
When an `AutoCompleteExtender` is displayed in IE6 it seems to ignore z-index and renders below any select controls (like **dropdownlists**) in IE6. ``` <asp:TextBox ID="TextBox1" runat="server" /> <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1" EnableCaching="true"...
[**@Orion**](https://stackoverflow.com/questions/45267/how-do-i-make-autocompleteextender-render-above-select-controls-in-ie6#45284) has this *partially* correct - there is *one other way* to deal with these, and that is to cover the offending select lists with an iframe. This technique is used in [**Cody Lindley's Thi...
45,340
<p>Python frameworks always provide ways to handle URLs that convey the data of the request in an elegant way, like for example <a href="http://somewhere.overtherainbow.com/userid/123424/" rel="noreferrer">http://somewhere.overtherainbow.com/userid/123424/</a></p> <p>I want you to notice the ending path <strong>/useri...
[ { "answer_id": 45347, "author": "John Sheehan", "author_id": 1786, "author_profile": "https://Stackoverflow.com/users/1786", "pm_score": 0, "selected": false, "text": "<p>Also, check out ASP.NET MVC or if you're set on webforms, the new System.Web.Routing namespace in ASP.NET 3.5 SP1</p>...
2008/09/05
[ "https://Stackoverflow.com/questions/45340", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4491/" ]
Python frameworks always provide ways to handle URLs that convey the data of the request in an elegant way, like for example <http://somewhere.overtherainbow.com/userid/123424/> I want you to notice the ending path **/userid/123424/** How do you do this in ASP.NET?
This example uses ASP.NET Routing to implement friendly URLs. Examples of the mappings that the application handles are: <http://samplesite/userid/1234> - <http://samplesite/users.aspx?userid=1234> <http://samplesite/userid/1235> - <http://samplesite/users.aspx?userid=1235> This example uses querystrings and a...
45,372
<p>Let's say that I want to have a table that logs the date and the number of columns in some other table (or really any sort of math / string concat etc).</p> <pre><code>CREATE TABLE `log` ( `id` INTEGER NOT NULL AUTO_INCREMENT , `date` DATETIME NOT NULL , `count` INTEGER NOT NULL , PRIMARY KEY (`id`) ); </code></pre...
[ { "answer_id": 45382, "author": "Thomas Watnedal", "author_id": 4059, "author_profile": "https://Stackoverflow.com/users/4059", "pm_score": 0, "selected": false, "text": "<p>You definitly have to declare what to insert. This should be possible by using the <a href=\"http://dev.mysql.com/...
2008/09/05
[ "https://Stackoverflow.com/questions/45372", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1666/" ]
Let's say that I want to have a table that logs the date and the number of columns in some other table (or really any sort of math / string concat etc). ``` CREATE TABLE `log` ( `id` INTEGER NOT NULL AUTO_INCREMENT , `date` DATETIME NOT NULL , `count` INTEGER NOT NULL , PRIMARY KEY (`id`) ); ``` Is it possible to ha...
Triggers are the best tool for annotating data when a table is changed by insert, update or delete. To automatically set the date column of a new row in the log with the current date, you'd create a trigger that looked something like this: ``` create trigger log_date before insert on log for each row begin set ne...
45,414
<p>I'm using Eclipse 3.4 and have configured the Java code formatter with all of the options on the <em>Comments</em> tab enabled. The problem is that when I format a document comment that contains:</p> <pre><code>* @see &lt;a href="test.html"&gt;test&lt;/a&gt; </code></pre> <p>the code formatter inserts a space in t...
[ { "answer_id": 45550, "author": "Bart Schuller", "author_id": 4711, "author_profile": "https://Stackoverflow.com/users/4711", "pm_score": 3, "selected": true, "text": "<p>I can only assume it's a bug in Eclipse. It only happens with <em>@see</em> tags, it happens also for all 3 builtin c...
2008/09/05
[ "https://Stackoverflow.com/questions/45414", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2670/" ]
I'm using Eclipse 3.4 and have configured the Java code formatter with all of the options on the *Comments* tab enabled. The problem is that when I format a document comment that contains: ``` * @see <a href="test.html">test</a> ``` the code formatter inserts a space in the closing HTML, breaking it: ``` * @see <a ...
I can only assume it's a bug in Eclipse. It only happens with *@see* tags, it happens also for all 3 builtin code formatter settings. There are some interesting bugs reported already in the neighbourhood, but I couldn't find this specific one. See for example a search for *@see* in the [Eclipse Bugzilla](https://bugs....
45,424
<p>I'm using <b>Struts 2</b>.</p> <p>I'd like to return from an Action to the page which invoked it.</p> <p>Say I'm in page <strong>x.jsp</strong>, I invoke Visual action to change CSS preferences in the session; I want to return to <strong>x.jsp</strong> rather than to a fixed page (i.e. <strong>home.jsp</strong>)<b...
[ { "answer_id": 45595, "author": "nikhilbelsare", "author_id": 4705, "author_profile": "https://Stackoverflow.com/users/4705", "pm_score": 1, "selected": false, "text": "<pre><code>return INPUT;\n</code></pre>\n\n<p>will do the trick. INPUT constant is defined in Action interface itself. ...
2008/09/05
[ "https://Stackoverflow.com/questions/45424", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4690/" ]
I'm using **Struts 2**. I'd like to return from an Action to the page which invoked it. Say I'm in page **x.jsp**, I invoke Visual action to change CSS preferences in the session; I want to return to **x.jsp** rather than to a fixed page (i.e. **home.jsp**) Here's the relevant **struts.xml** fragment: ``` <actio...
You can use a dynamic result in struts.xml. For instance: ``` <action name="Visual" class="it.___.web.actions.VisualizationAction"> <result name="next">${next}</result> </action> ``` Then in your action, you create a field called next. So to invoke the action you will pass the name of the page that you want...
45,437
<p>I wondered whether anybody knows how to obtain membership of local groups on a remote server programmatically via C#. Would this require administrator permissions? And if so is there any way to confirm the currently logged in user's membership (or not) of these groups?</p>
[ { "answer_id": 45439, "author": "Patrik Svensson", "author_id": 936, "author_profile": "https://Stackoverflow.com/users/936", "pm_score": 0, "selected": false, "text": "<p>Perhaps this is something that can be done via WMI?</p>\n" }, { "answer_id": 45458, "author": "Espo", ...
2008/09/05
[ "https://Stackoverflow.com/questions/45437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3394/" ]
I wondered whether anybody knows how to obtain membership of local groups on a remote server programmatically via C#. Would this require administrator permissions? And if so is there any way to confirm the currently logged in user's membership (or not) of these groups?
[Howto: (Almost) Everything In Active Directory via C#](http://www.codeproject.com/KB/system/everythingInAD.aspx) is very helpfull and also includes instructions on how to iterate AD members in a group. ``` public ArrayList Groups(string userDn, bool recursive) { ArrayList groupMemberships = new ArrayList(); r...
45,453
<p>I'm generating ICalendar (.ics) files.</p> <p>Using the UID and SEQUENCE fields I can update existing events in Google Calendar and in Windows Calendar <strong><em>BUT NOT</em></strong> in MS Outlook 2007 - it just creates a second event</p> <p>How do I get them to work for Outlook ?</p> <p>Thanks</p> <p>Tom</p>...
[ { "answer_id": 45703, "author": "Hank Gay", "author_id": 4203, "author_profile": "https://Stackoverflow.com/users/4203", "pm_score": 0, "selected": false, "text": "<p>I'm using Entourage, so this may not match up exactly with the behavior you're seeing, but I hope it helps.</p>\n\n<p>Usi...
2008/09/05
[ "https://Stackoverflow.com/questions/45453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2839/" ]
I'm generating ICalendar (.ics) files. Using the UID and SEQUENCE fields I can update existing events in Google Calendar and in Windows Calendar ***BUT NOT*** in MS Outlook 2007 - it just creates a second event How do I get them to work for Outlook ? Thanks Tom
I've continued to do some testing and have now managed to get Outlook to update and cancel events based on the .cs file. Outlook in fact seems to respond to the rules defined in [RFC 2446](https://www.rfc-editor.org/rfc/rfc2446#page-19) In summary you have to specify `METHOD:REQUEST` and `ORGANIZER:xxxxxxxx` in add...
45,475
<p>I'm presenting information from a DataTable on my page and would like to add some sorting functionality which goes a bit beyond a straight forward column sort. As such I have been trying to place LinkButtons in the HeaderItems of my GridView which post-back to functions that change session information before reloadi...
[ { "answer_id": 45477, "author": "samjudson", "author_id": 1908, "author_profile": "https://Stackoverflow.com/users/1908", "pm_score": 0, "selected": false, "text": "<p>Two things to keep in mind when using events on dynamically generated controls in ASP.Net:</p>\n\n<ul>\n<li>Firstly, the...
2008/09/05
[ "https://Stackoverflow.com/questions/45475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4431/" ]
I'm presenting information from a DataTable on my page and would like to add some sorting functionality which goes a bit beyond a straight forward column sort. As such I have been trying to place LinkButtons in the HeaderItems of my GridView which post-back to functions that change session information before reloading ...
You're on the right track but try working with the Command Name/Argument of the LinkButton. Try something like this: In the HeaderTemplate of the the TemplateField, add a LinkButton and set the CommandName and CommandArgument ``` <HeaderTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CommandName="sort"...
45,481
<p>How can you do a streaming read on a large XML file that contains a xs:sequence just below root element, without loading the whole file into a XDocument instance in memory?</p>
[ { "answer_id": 45484, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 0, "selected": false, "text": "<p>I think it's not possible if you want to use object model (i.e. XElement\\XDocument) to query XML. Obviously, you can't build ...
2008/09/05
[ "https://Stackoverflow.com/questions/45481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4685/" ]
How can you do a streaming read on a large XML file that contains a xs:sequence just below root element, without loading the whole file into a XDocument instance in memory?
Going with a SAX-style element parser and the [XmlTextReader](http://msdn.microsoft.com/en-us/library/system.xml.xmltextreader.aspx) class created with [XmlReader.Create](http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.create.aspx) would be a good idea, yes. Here's a slightly-modified code example from [Co...
45,485
<p>Are there conventions for function names when using the Perl Test::More or Test::Simple modules?</p> <p>I'm specifically asking about the names of functions that are used to set up a test environment before the test and to tear down the environment after successful completion of the test(s).</p> <p>cheers,</p> <p...
[ { "answer_id": 45491, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 1, "selected": false, "text": "<p>I do not think there is a official set of conventions, so I would recommend looking at the examples at <a href=\"http://perld...
2008/09/05
[ "https://Stackoverflow.com/questions/45485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2974/" ]
Are there conventions for function names when using the Perl Test::More or Test::Simple modules? I'm specifically asking about the names of functions that are used to set up a test environment before the test and to tear down the environment after successful completion of the test(s). cheers, Rob
I dont think there are any such conventions out there. The only way you can do it is perhaps use BEGIN/END blocks, if the resources are to be used over the whole file. The general approach I take is to put related tests in one code block and then initialize the variables/resource etc there. You can perhaps keep an ea...
45,494
<p>I have a table <code>story_category</code> in my database with corrupt entries. The next query returns the corrupt entries:</p> <pre><code>SELECT * FROM story_category WHERE category_id NOT IN ( SELECT DISTINCT category.id FROM category INNER JOIN story_category ON category_id=category.id); </co...
[ { "answer_id": 45498, "author": "Cheekysoft", "author_id": 1820, "author_profile": "https://Stackoverflow.com/users/1820", "pm_score": 11, "selected": true, "text": "<p><em>Update: This answer covers the general error classification. For a more specific answer about how to best handle th...
2008/09/05
[ "https://Stackoverflow.com/questions/45494", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2138/" ]
I have a table `story_category` in my database with corrupt entries. The next query returns the corrupt entries: ``` SELECT * FROM story_category WHERE category_id NOT IN ( SELECT DISTINCT category.id FROM category INNER JOIN story_category ON category_id=category.id); ``` I tried to delete them ...
*Update: This answer covers the general error classification. For a more specific answer about how to best handle the OP's exact query, please see other answers to this question* In MySQL, you can't modify the same table which you use in the SELECT part. This behaviour is documented at: <http://dev.mysql.com/doc/re...
45,535
<p>I need the month+year from the datetime in SQL Server like 'Jan 2008'. I'm grouping the query by month, year. I've searched and found functions like datepart, convert, etc., but none of them seem useful for this. Am I missing something here? Is there a function for this?</p>
[ { "answer_id": 45543, "author": "SQLMenace", "author_id": 740, "author_profile": "https://Stackoverflow.com/users/740", "pm_score": 3, "selected": false, "text": "<p>That format doesn't exist. You need to do a combination of two things,</p>\n\n<pre><code>select convert(varchar(4),getdate...
2008/09/05
[ "https://Stackoverflow.com/questions/45535", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1688440/" ]
I need the month+year from the datetime in SQL Server like 'Jan 2008'. I'm grouping the query by month, year. I've searched and found functions like datepart, convert, etc., but none of them seem useful for this. Am I missing something here? Is there a function for this?
If you mean you want them back as a string, in that format; ``` SELECT CONVERT(CHAR(4), date_of_birth, 100) + CONVERT(CHAR(4), date_of_birth, 120) FROM customers ``` [Here are the other format options](http://msdn.microsoft.com/en-us/library/ms187928.aspx)
45,540
<p>I’ve writen a little python script that just pops up a message box containing the text passed on the command line. I want to pop it up only when the window —resulting from a previous call— is not open.</p> <pre><code>from Tkinter import * import tkMessageBox root = Tk() root.withdraw() # TODO not if a window wit...
[ { "answer_id": 46205, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>I believe you want:</p>\n\n<pre><code>if 'normal' != root.state():\n tkMessageBox.showinfo(\"Key you!\", \" \".join(sys.a...
2008/09/05
[ "https://Stackoverflow.com/questions/45540", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4717/" ]
I’ve writen a little python script that just pops up a message box containing the text passed on the command line. I want to pop it up only when the window —resulting from a previous call— is not open. ``` from Tkinter import * import tkMessageBox root = Tk() root.withdraw() # TODO not if a window with this title e...
I believe you want: ``` if 'normal' != root.state(): tkMessageBox.showinfo("Key you!", " ".join(sys.argv[1:])) ```
45,545
<p>How can I add horizontal scroll capabilities to the asp.net listbox control?</p>
[ { "answer_id": 45549, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 1, "selected": false, "text": "<p>If you really, really need it, one idea would be to create a custom\nListBox class whose HTML looks like this: sets the width...
2008/09/05
[ "https://Stackoverflow.com/questions/45545", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1360/" ]
How can I add horizontal scroll capabilities to the asp.net listbox control?
Example to add horizontal scroll: ``` <asp:ListBox ID="List" runat="server" Height="320px" Width="100%" style="overflow-x:auto;"SelectionMode="Multiple"> </asp:ListBox> ``` CSS3 overflow-x Property: <http://www.w3schools.com/cssref/css3_pr_overflow-x.asp>
45,546
<p>I want my controller to return the right HTTP response code when the user lacks permission to view a particular page.</p>
[ { "answer_id": 45568, "author": "John Boker", "author_id": 2847, "author_profile": "https://Stackoverflow.com/users/2847", "pm_score": 3, "selected": false, "text": "<p>Use this:\n<code>response.setStatus(403)</code>.</p>\n" }, { "answer_id": 45585, "author": "Cheekysoft", ...
2008/09/05
[ "https://Stackoverflow.com/questions/45546", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4702/" ]
I want my controller to return the right HTTP response code when the user lacks permission to view a particular page.
**Quickie** If you are using plain JSP views (as is most common), then simply add ``` <% response.setStatus( 403 ); %> ``` somewhere in your view file. At the top is a nice place. **Detail** In MVC, i would always set this in the view, and in most cases with Spring-MVC, use the `SimpleMappingExceptionResolver` to...
45,572
<p>I'm just wondering if it exists better solution for this.</p> <pre><code>BitConverter.ToInt32(sample_guid.ToByteArray(), 0) </code></pre>
[ { "answer_id": 45581, "author": "Ishmaeel", "author_id": 227, "author_profile": "https://Stackoverflow.com/users/227", "pm_score": 0, "selected": false, "text": "<p>Dunno about a better solution, but I hope you don't intend to use that Int32 as a random (or unique) value. </p>\n\n<p>You ...
2008/09/05
[ "https://Stackoverflow.com/questions/45572", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3182/" ]
I'm just wondering if it exists better solution for this. ``` BitConverter.ToInt32(sample_guid.ToByteArray(), 0) ```
I don't think there's a better solution than this.