qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
282,226 | <p>I'm working on a time sheet application, where I'd like the user to be able to enter times in TextBoxes, e.g.: 8 a or 8:00 a or the like, just like you can in Excel.</p>
<p>Now if you enter a <em>date</em> in a TextBox and then use DateTime.TryParse, you can enter it in several formats (Jan 31, 2007; 1/31/2007; 31/1/2007; January 31, 2007; etc.) and .NET will figure it out and turn it into a DateTime.</p>
<p>But when I use DateTime.TryParse on a string like "8 a" or "8:00 a", it doesn't understand it.</p>
<p>I know I can use ParseExact, but I'm wondering if there's a more flexible solution. I want .NET to get 8:00a from "8 a" or "8:00 a", and to leave the date component at the default 1/1/0001.</p>
| [
{
"answer_id": 282296,
"author": "Timothy Khouri",
"author_id": 11917,
"author_profile": "https://Stackoverflow.com/users/11917",
"pm_score": 2,
"selected": false,
"text": "DateTime blah = DateTime.Parse(\"1/1/0001 \" + myTimeString);\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5486/"
] |
282,228 | <p>We have encountered a very strange situation when we deployed an application at a customer site. This application is implemented as a service using C# on .NET 3. The application communicates with a web service that is written using gSOAP. In our .NET application, the classes that wrap the web service were created by performing "Add Service" in Visual Studio and referencing the WSDL. Communication is performed using HTTPS, but using port 35000.</p>
<p>What we are seeing is that when our application runs as "Local Administrator account" everything works well. However when our application runs as any other account, including "Local System account" and even a user account with network admin privileges, web service method calls sometimes time out. Other times they succeed but after a very, very long time, e.g. 100 seconds instead of less than 1 second as expected.</p>
<p>This customer is using Cisco switches in their network.</p>
<p>We have not encountered this behavior at other sites. Any insights or suggestions would be greatly appreciated.</p>
| [
{
"answer_id": 282296,
"author": "Timothy Khouri",
"author_id": 11917,
"author_profile": "https://Stackoverflow.com/users/11917",
"pm_score": 2,
"selected": false,
"text": "DateTime blah = DateTime.Parse(\"1/1/0001 \" + myTimeString);\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282228",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
282,245 | <p>What order of precedence are events handled in JavaScript?</p>
<p>Here are the events in alphabetical order...</p>
<ol>
<li>onabort - Loading of an image is
interrupted</li>
<li>onblur - An element loses focus</li>
<li>onchange - The user changes the
content of a field</li>
<li>onclick - Mouse clicks an object</li>
<li>ondblclick - Mouse double-clicks an
object</li>
<li>onerror - An error occurs when
loading a document or an image</li>
<li>onfocus - An element gets focus</li>
<li>onkeydown - A keyboard key is
pressed</li>
<li>onkeypress - A keyboard key is
pressed or held down</li>
<li>onkeyup - A keyboard key is
released</li>
<li>onload - A page or an image is
finished loading</li>
<li>onmousedown - A mouse button is
pressed</li>
<li>onmousemove - The mouse is moved</li>
<li>onmouseout - The mouse is moved off
an element</li>
<li>onmouseover - The mouse is moved
over an element</li>
<li>onmouseup - A mouse button is
released</li>
<li>onreset - The reset button is
clicked</li>
<li>onresize - A window or frame is
resized</li>
<li>onselect - Text is selected</li>
<li>onsubmit - The submit button is
clicked</li>
<li>onunload - The user exits the page</li>
</ol>
<p>What order are they handled out of the event queue?</p>
<p>The precedence is not first-in-first-out (FIFO) or so I believe.</p>
| [
{
"answer_id": 69429589,
"author": "Friedrich",
"author_id": 11769765,
"author_profile": "https://Stackoverflow.com/users/11769765",
"pm_score": 2,
"selected": false,
"text": "<input onclick=\"console.log('onclick - Mouse clicks an object')\" \n ondblclick=\"console.log('ondblclick - Mouse double-clicks an object')\"\n onmousedown=\"console.log('onmousedown - A mouse button is pressed')\"\n onmouseup=\"console.log('onmouseup - A mouse button is released')\"\n onmousemove=\"console.log('onmousemove - The mouse is moved')\"\n onmouseenter=\"console.log('onmousenter - The mouse is moved over an element (not bubbling)')\"\n onmouseover=\"console.log('onmouseover - The mouse is moved over an element')\"\n onmouseout=\"console.log('onmouseout - The mouse is moved off an element')\"\n onmouseleave=\"console.log('onmouseout - The mouse is moved off an element (not bubbling)')\"\n onchange=\"console.log('onchange - The user changes the content of a field')\"\n onfocusin=\"console.log('onfocusin - An element gets focus')\"\n onfocus=\"console.log('onfocus - An element gets focus (not bubbling)')\"\n onkeydown=\"console.log('onkeydown - A keyboard key is pressed')\"\n onkeypress=\"console.log('onkeypress - A keyboard key is pressed or held down')\"\nonselectionchange=\"console.log('onselectionchange - The caret position changed')\"\n onkeyup=\"console.log('onkeyup - A keyboard key is released')\"\n onselect=\"console.log('onselect - Text is selected')\"\n onfocusout=\"console.log('onfocusout - Loosing focus')\"\n onblur=\"console.log('onblur - Loosing focus (not bubbling)')\"\n ontouchstart=\"console.log('ontouchstart')\"\n ontouchmove=\"console.log('ontouchmove')\"\n ontouchend=\"console.log('ontouchend')\"\n ontouchcancel=\"console.log('ontouchcancel')\"\n placeholder=\"edit me\"\n/>"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282245",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13930/"
] |
282,252 | <p>I have multiple ordered lists. Unfortunately, the order of the items isn't a simple alpha or numeric comparison, otherwise this is trivial. So what I have is something like:</p>
<pre><code>List #1 List #2 List #3
groundhog groundhog easter
mothersday mayday mothersday
midsummer laborday halloween
christmas
</code></pre>
<p>And from this I can gather than groundhog < mothersday, but the relationship of groundhog and easter is unknown. I am guaranteed that the order of the items from list-to-list is self consistent. (i.e. that no matter which list it occurs in, easter is always before halloween)</p>
<p>But what I need is a new ordered list that represents each item in the other lists only once, that preserves all of the known relationships above:</p>
<pre><code>groundhog
easter
mayday
mothersday
midsummer
laborday
halloween
christmas
</code></pre>
<p>However, the following list is also perfectly valid:</p>
<pre><code>easter
groundhog
mothersday
mayday
midsummer
laborday
halloween
christmas
</code></pre>
<p>I'm looking for a fairly quick, general-purpose algorithm I can use to order N lists in this way. (Working C# code a plus, for sure, but not necessary.) </p>
<p>I have solution that works, but its O(N^2) and a dog with even modest data sets.</p>
| [
{
"answer_id": 297198,
"author": "Phil",
"author_id": 38343,
"author_profile": "https://Stackoverflow.com/users/38343",
"pm_score": 1,
"selected": false,
"text": "groundhog"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282252",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8173/"
] |
282,280 | <p>Is there a way to force the flash garbage collector to clean up freed memory? I've seen that it takes a lot of time for flash to clean up not referenced memory...</p>
| [
{
"answer_id": 31196731,
"author": "user5075924",
"author_id": 5075924,
"author_profile": "https://Stackoverflow.com/users/5075924",
"pm_score": 0,
"selected": false,
"text": "var antiGC:Dictionary = new Dictionary(false);\n\nvar loaderwidth:Tween = new Tween(maskbox, \"width\", Regular.easeIn, 1, 1000, 25, false);\n\n\nantiGC[loaderwidth] = loaderwidth;\n\nloaderwidth.addEventListener(TweenEvent.MOTION_FINISH, lwfinished);\n\nfunction lwfinished(e:TweenEvent){\n\n loaderwidth.removeEventListener(TweenEvent.MOTION_FINISH, lwfinished);\n antiGC[e.currentTarget] = null;\n delete antiGC[e.currentTarget];\n}\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282280",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26521/"
] |
282,298 | <p>I have an htaccess file that uses mod_rewrite to redirect /controller to /index.php?controller=%controller%</p>
<p>Like this:</p>
<pre><code># Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
# Rewrite current-style URLs of the form 'index.php?controller=x&action=y'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?controller=$1 [L,QSA]
</IfModule>
</code></pre>
<p>Now, what I need to be able to do is make ONE of the controllers work with HTTP Authentication. I'm not asking if this is the best way to do things, I'm simply asking how to do it.</p>
<p>Example:</p>
<pre><code>http://www.example.com/ - It requires no auth
http://www.example.com/secret - requires auth
</code></pre>
| [
{
"answer_id": 282364,
"author": "Mark S.",
"author_id": 13968,
"author_profile": "https://Stackoverflow.com/users/13968",
"pm_score": 1,
"selected": false,
"text": "if (in_array($controllerString, $configuration['protected']))\n{\n $authenticated = false;\n if (!isset($_SERVER['PHP_AUTH_USER'])) {\n header('WWW-Authenticate: Basic realm=\"My Realm\"');\n header('HTTP/1.0 401 Unauthorized');\n echo 'You are unatuhorized to access this section of the website.';\n } else if ($_SERVER['PHP_AUTH_USER'] == 'admin' && $_SERVER['PHP_AUTH_PW'] == 'admin'){\n $authenticated = true;\n }\n\n if (!$authenticated)\n {\n unset($_SERVER['PHP_AUTH_USER']);\n die();\n }\n} \n"
},
{
"answer_id": 282384,
"author": "ken",
"author_id": 20300,
"author_profile": "https://Stackoverflow.com/users/20300",
"pm_score": 3,
"selected": true,
"text": "<Location /secret>\n AuthName localhost\n AuthType Basic\n AuthUserFile <file>\n Require valid-user\n</Location>\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282298",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13968/"
] |
282,308 | <p>I'm working with an ASP.net 2.0 GridView control that is bound to the results of a sql query, so it looks something like this:</p>
<pre><code><asp:GridView ID="MySitesGridView" runat="server" AutoGenerateColumns="False" DataSourceID="InventoryDB" AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowCommand="GridView1_RowCommand" OnRowDataBound="siteRowDataBound">
<Columns>
<asp:BoundField DataField="Server" HeaderText="Server"/>
<asp:BoundField DataField="Customer" HeaderText="Customer" SortExpression="Customer" />
<asp:BoundField DataField="PublicIP" HeaderText="Site Address" DataFormatString="&lt;a href='http://{0}/foo'&gt;Go To Site&lt;/a&gt;" />
</Columns>
</asp:GridView>
</code></pre>
<p>As you can see, I'm displaying links with addresses in one of the columns (the one bound to the PublicIP field) using the format string:</p>
<pre><code>&lt;a href='http://{0}/foo'&gt;Go To Site&lt;/a&gt;
</code></pre>
<p>Here's the problem: I need to use one of the <em>other</em> columns from the result set as well as the PublicIP column in my links, but I don't know how to make that available to my format string. I essentially need that column bound to two columns from the result set. To clarify, I need something like:</p>
<pre><code>&lt;a href='http://{0}/{1}'&gt;Go To Site&lt;/a&gt;
</code></pre>
<p>Where {1} is the value of my other column. Is there any way to accomplish this cleanly (even if it doesn't use format strings)? I've looked into using TemplateFields as well, but can see no easy way to do it with them either.</p>
| [
{
"answer_id": 282324,
"author": "Cristian Libardo",
"author_id": 16526,
"author_profile": "https://Stackoverflow.com/users/16526",
"pm_score": 1,
"selected": false,
"text": "<asp:TemplateField>\n <ItemTemplate>\n <a href='<%#Eval(\"PublicIP\")/<%# Eval(\"Customer\") %>'>Go to site</a>\n </ItemTemplate>\n</asp:TemplateField>\n"
},
{
"answer_id": 282345,
"author": "devio",
"author_id": 21336,
"author_profile": "https://Stackoverflow.com/users/21336",
"pm_score": 3,
"selected": true,
"text": "<a href=\"<%# CalculateUrl(Eval(\"PublicIP\"), Eval(\"Customer\")) %>\">site</a>\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282308",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2327/"
] |
282,317 | <p>In C# I sometimes wish I could make special methods for certain "instantiations" of generic classes.</p>
<p><strong>UPDATE: The following code is just a dumb example of a more abstract problem - don't focus too much on time series, just the principles of "adding extra methods" for certain T</strong>.</p>
<p>Example:</p>
<pre><code>class Timeseries<T>
{
...
TimeSeries<T> Slice(...) { ... }
}
</code></pre>
<p>In the case where T is double, I would like some extra methods, like <code>Integrate()</code>, <code>Interpolate()</code> and so on that make only sense for <code>double</code>, because I need to do arithmetic on them.</p>
<p>There are several ways to do this, but I cannot find one that I'm satisfied with.</p>
<p><strong>1. Inherit into a special class</strong></p>
<pre><code>class TimeseriesDouble : Timeseries<double>
{
double Interpolate(...) { ... }
...
}
</code></pre>
<p><strong>cons:</strong> <code>TimeseriesDouble.Slice()</code> will return a new <code>Timeseries<double></code> object, now missing my special methods.</p>
<p><strong>2. External methods</strong></p>
<pre><code>public static double Interpolate(Timeseries<double> ts, ...) { ... }
</code></pre>
<p><strong>cons:</strong> Breaks with OO principles. And I don't want to put my methods away. Also, the methods might need private/protected state.</p>
<p><strong>3. Extension methods</strong></p>
<p>Same as 2, just with a nicer calling syntax.</p>
<p><strong>4. Common base class</strong></p>
<pre><code>class TimeSeries_base { ... }
class TimeSeries<T> : TimeSeries_base { .. typesafe versions of methods .. }
class TimeSeriesDouble : TimeSeries_base { .. typesafe versions of methods .. }
</code></pre>
<p><strong>cons:</strong> too much duplication of things from <code>TimeSeries_base</code> into the two subclasses. The base class might become just a place holder for utility functions for the sub classes.</p>
<p><strong>pro:</strong> I can now do things like <code>List<TimeSeries_base></code> dynamically.</p>
<p><strong>5. Just forget about a common class</strong></p>
<p>I.e., keep <code>Timeseries<T></code> and <code>TimeseriesDouble</code> separate in the code.</p>
<p><strong>cons:</strong> Then I don't get all the benefit of treating a <code>TimeseriesDouble</code> like a <code>TimeSeries<T></code>, e.g. combining two timeseries with ZIP(A,B), where one happens to be of doubles.</p>
<hr>
<p><strong>Any other ideas?</strong>
Currently, I think I like the design (1) best.</p>
| [
{
"answer_id": 282506,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 1,
"selected": false,
"text": " TimeSeriesDouble tsD = new TimeSeriesDouble();\n TimeSeriesDouble subTSD = tsD.Slice(...) as TimeSeriesDouble;\n"
},
{
"answer_id": 282548,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 5,
"selected": true,
"text": "public class TimeSeries<T, U> where U : TimeSeries<T, U>\n{\n U Slice(...)\n}\n\npublic class TimeSeriesDouble : TimeSeries<double, TimeSeriesDouble>\n{\n ...\n}\n"
},
{
"answer_id": 282588,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 3,
"selected": false,
"text": "interface ITimeSeries<T> { ... }\n\nabstract class TimeSeriesBase<TS> where TS : TimeSeriesBase<TS> \n { public TS Slice() { ... } \n }\n\nclass TimeSeries<T>:TimeSeriesBase<TimeSeries<T>>,ITimeSeries<T> {}\n\nclass TimeSeriesDouble:TimeSeriesBase<TimeSeriesDouble>,ITimeSeries<double>\n { public double Interpolate() { ... }\n }\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282317",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31890/"
] |
282,322 | <p>Suppose I have a SELECT statement that returns some set of results. Is there some way I can number my results in the following way:</p>
<blockquote>
<p>SELECT TOP 3 Name FROM PuppyNames ORDER BY NumberOfVotes</p>
</blockquote>
<p>would give me...</p>
<blockquote>
<p>Fido</p>
<p>Rover</p>
<p>Freddy Krueger</p>
</blockquote>
<p>...but I want...</p>
<blockquote>
<p>1, Fido</p>
<p>2, Rover</p>
<p>3, Freddy Krueger</p>
</blockquote>
<p>where of course the commas signify that the numbers are in their own column. [I am using SQL Server 2000.]</p>
| [
{
"answer_id": 282350,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 4,
"selected": true,
"text": "ROW_NUMBER()"
},
{
"answer_id": 282358,
"author": "Eric Sabine",
"author_id": 1493157,
"author_profile": "https://Stackoverflow.com/users/1493157",
"pm_score": 2,
"selected": false,
"text": " SELECT (\n SELECT COUNT(*)\n FROM PuppyNames b\n WHERE b.Popularity <= a.Popularity\n ) AS Ranking\n , a.Name\n FROM PuppyNames a\n ORDER BY a.Popularity\n"
},
{
"answer_id": 282374,
"author": "BoltBait",
"author_id": 20848,
"author_profile": "https://Stackoverflow.com/users/20848",
"pm_score": 2,
"selected": false,
"text": "SELECT TOP 3 Name FROM PuppyNames ORDER BY NumberOfVotes DESC\n"
},
{
"answer_id": 282430,
"author": "Panos",
"author_id": 8049,
"author_profile": "https://Stackoverflow.com/users/8049",
"pm_score": 1,
"selected": false,
"text": "SELECT TOP 3 COUNT(*) AS Number, p1.Name\nFROM PuppyNames AS p1 INNER JOIN PuppyNames AS p2 \n ON p1.NumberOfVotes < p2.NumberOfVotes OR (p1.NumberOfVotes = p2.NumberOfVotes AND p1.ID >= p2.ID)\nGROUP BY p1.Name\nORDER BY Number\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10675/"
] |
282,329 | <p>There's been a cluster of Perl-hate on Stack Overflow lately, so I thought I'd bring my "<a href="http://use.perl.org/~brian_d_foy/journal/32556" rel="nofollow noreferrer">Five things you hate about your favorite language</a>" question to Stack Overflow. Take your favorite language and tell me five things you hate about it. Those might be things that just annoy you, admitted design flaws, recognized performance problems, or any other category. You just have to hate it, and it has to be your favorite language.</p>
<p>Don't compare it to another language, and don't talk about languages that you already hate. Don't talk about the things you like in your favorite language. I just want to hear the things that you hate but tolerate so you can use all of the other stuff, and I want to hear it about the language you wished other people would use.</p>
<p>I ask this whenever someone tries to push their favorite language on me, and sometimes as an interview question. If someone can't find five things to hate about his favorite tool, he doesn't know it well enough to either advocate it or pull in the big dollars using it. He hasn't used it in enough different situations to fully explore it. He's advocating it as a culture or religion, which means that if I don't choose his favorite technology, I'm wrong.</p>
<p>I don't care that much which language you use. Don't want to use a particular language? Then don't. You go through due diligence to make an informed choice and still don't use it? Fine. Sometimes the right answer is "You have a strong programming team with good practices and a lot of experience in Bar. Changing to Foo would be stupid."</p>
<hr />
<p>This is a good question for code reviews too. People who really know a codebase will have all sorts of suggestions for it, and those who don't know it so well have non-specific complaints. I ask things like "If you could start over on this project, what would you do differently?" In this fantasy land, users and programmers get to complain about anything and everything they don't like. "I want a better interface", "I want to separate the model from the view", "I'd use this module instead of this other one", "I'd rename this set of methods", or whatever they really don't like about the current situation. That's how I get a handle on how much a particular developer knows about the codebase. It's also a clue about how much of the programmer's ego is tied up in what he's telling me.</p>
<p>Hate isn't the only dimension of figuring out how much people know, but I've found it to be a pretty good one. The things that they hate also give me a clue how well they are thinking about the subject.</p>
| [
{
"answer_id": 282342,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 7,
"selected": false,
"text": "lock"
},
{
"answer_id": 282356,
"author": "zmf",
"author_id": 13285,
"author_profile": "https://Stackoverflow.com/users/13285",
"pm_score": 3,
"selected": false,
"text": "Boolean"
},
{
"answer_id": 282366,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 5,
"selected": false,
"text": "__init__"
},
{
"answer_id": 282436,
"author": "I GIVE TERRIBLE ADVICE",
"author_id": 35344,
"author_profile": "https://Stackoverflow.com/users/35344",
"pm_score": 6,
"selected": false,
"text": "$var = preg_match_all('/regexp/', $str, $ret);\necho $var; //outputs the number of matches \nprint_r($ret); //outputs the matches as an array\n"
},
{
"answer_id": 282445,
"author": "staticsan",
"author_id": 28832,
"author_profile": "https://Stackoverflow.com/users/28832",
"pm_score": 3,
"selected": false,
"text": "explode()"
},
{
"answer_id": 282505,
"author": "Myrddin Emrys",
"author_id": 9084,
"author_profile": "https://Stackoverflow.com/users/9084",
"pm_score": 6,
"selected": false,
"text": "object.method(1, {|a| a.bar}, \"blah\")\n"
},
{
"answer_id": 282574,
"author": "too much php",
"author_id": 28835,
"author_profile": "https://Stackoverflow.com/users/28835",
"pm_score": 7,
"selected": false,
"text": "$parts = explode('|', $string);\n$first = $parts[0];\n"
},
{
"answer_id": 282686,
"author": "Brad Gilbert",
"author_id": 1337,
"author_profile": "https://Stackoverflow.com/users/1337",
"pm_score": 6,
"selected": false,
"text": "my @array = ( 1, 2, 3 );\nmy $array = [ 4, 5, 6 ];\n\nmy $one = $array[0]; # not @array[0], you would get the length instead\nmy $four = $array->[0]; # definitely not $array[0]\n\nmy( $two, $three ) = @array[1,2];\nmy( $five, $six ) = @$array[1,2]; # coerce to array first\n\nmy $length_a = @array;\nmy $length_s = @$array;\n\nmy $ref_a = \\@array;\nmy $ref_s = $array;\n"
},
{
"answer_id": 282714,
"author": "wnoise",
"author_id": 15464,
"author_profile": "https://Stackoverflow.com/users/15464",
"pm_score": 4,
"selected": false,
"text": "($)"
},
{
"answer_id": 286856,
"author": "StingyJack",
"author_id": 16391,
"author_profile": "https://Stackoverflow.com/users/16391",
"pm_score": 4,
"selected": false,
"text": "AndAlso"
},
{
"answer_id": 288931,
"author": "utku_karatas",
"author_id": 14716,
"author_profile": "https://Stackoverflow.com/users/14716",
"pm_score": 3,
"selected": false,
"text": "try except finally end;"
},
{
"answer_id": 313395,
"author": "Demur Rumed",
"author_id": 40172,
"author_profile": "https://Stackoverflow.com/users/40172",
"pm_score": 1,
"selected": false,
"text": "::value"
},
{
"answer_id": 321863,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 4,
"selected": false,
"text": "cpan"
},
{
"answer_id": 321966,
"author": "kristina",
"author_id": 4243,
"author_profile": "https://Stackoverflow.com/users/4243",
"pm_score": 3,
"selected": false,
"text": "f = new Function( \"foo\", \"bar\", \"return foo+bar;\" );\n"
},
{
"answer_id": 344716,
"author": "hasen",
"author_id": 35364,
"author_profile": "https://Stackoverflow.com/users/35364",
"pm_score": 3,
"selected": false,
"text": "__init__"
},
{
"answer_id": 347124,
"author": "Daniel Cassidy",
"author_id": 31662,
"author_profile": "https://Stackoverflow.com/users/31662",
"pm_score": 5,
"selected": false,
"text": "Object"
},
{
"answer_id": 347134,
"author": "Tetha",
"author_id": 17663,
"author_profile": "https://Stackoverflow.com/users/17663",
"pm_score": 1,
"selected": false,
"text": "l = [l1, l2, ..., ln]"
},
{
"answer_id": 347672,
"author": "Andreas Grech",
"author_id": 44084,
"author_profile": "https://Stackoverflow.com/users/44084",
"pm_score": 4,
"selected": false,
"text": "hasOwnProperty"
},
{
"answer_id": 385617,
"author": "Jay Bazuzi",
"author_id": 5314,
"author_profile": "https://Stackoverflow.com/users/5314",
"pm_score": 2,
"selected": false,
"text": "MessageBoxButton"
},
{
"answer_id": 385625,
"author": "Jay Bazuzi",
"author_id": 5314,
"author_profile": "https://Stackoverflow.com/users/5314",
"pm_score": 5,
"selected": false,
"text": "switch()"
},
{
"answer_id": 410238,
"author": "EMP",
"author_id": 20336,
"author_profile": "https://Stackoverflow.com/users/20336",
"pm_score": 3,
"selected": false,
"text": "static T Parse(string s)"
},
{
"answer_id": 410260,
"author": "Logan Serman",
"author_id": 29595,
"author_profile": "https://Stackoverflow.com/users/29595",
"pm_score": 3,
"selected": false,
"text": "<?php\nif($x == NULL)\n{\n?>\n <p><?= $x . ' is null' ?></p>\n<?php\n}\n?>\n"
},
{
"answer_id": 424664,
"author": "SpoonMeiser",
"author_id": 1577190,
"author_profile": "https://Stackoverflow.com/users/1577190",
"pm_score": 3,
"selected": false,
"text": "import random\n\ndef myFunction():\n\n if random.choice(True, False):\n myString = \"blah blah blah\"\n\n print myString\n"
},
{
"answer_id": 425557,
"author": "peSHIr",
"author_id": 50846,
"author_profile": "https://Stackoverflow.com/users/50846",
"pm_score": 2,
"selected": false,
"text": "Class<D>"
},
{
"answer_id": 434132,
"author": "Sean Edwards",
"author_id": 53315,
"author_profile": "https://Stackoverflow.com/users/53315",
"pm_score": 3,
"selected": false,
"text": "global"
},
{
"answer_id": 564273,
"author": "Chris Lutz",
"author_id": 60777,
"author_profile": "https://Stackoverflow.com/users/60777",
"pm_score": 2,
"selected": false,
"text": "write()"
},
{
"answer_id": 564388,
"author": "Jon Ericson",
"author_id": 1438,
"author_profile": "https://Stackoverflow.com/users/1438",
"pm_score": 2,
"selected": false,
"text": "DUAL"
},
{
"answer_id": 567742,
"author": "Ellery Newcomer",
"author_id": 23648,
"author_profile": "https://Stackoverflow.com/users/23648",
"pm_score": 2,
"selected": false,
"text": "array.length += 512;"
},
{
"answer_id": 737519,
"author": "SingleNegationElimination",
"author_id": 65696,
"author_profile": "https://Stackoverflow.com/users/65696",
"pm_score": 2,
"selected": false,
"text": "lambda"
},
{
"answer_id": 919957,
"author": "Jonas Kölker",
"author_id": 58668,
"author_profile": "https://Stackoverflow.com/users/58668",
"pm_score": 3,
"selected": false,
"text": "snprintf"
},
{
"answer_id": 989478,
"author": "Gregory Higley",
"author_id": 27779,
"author_profile": "https://Stackoverflow.com/users/27779",
"pm_score": 1,
"selected": false,
"text": "; A small DSL that sends email to people about URLs.\nrules: [\n some [\n into [\n set email email!\n set url url!\n (send/subject email url reform [ \"Check Out\" url ])\n ]\n ]\n]\n\n; Global context\nnotify: func [ [catch] dsl [block!] ] [\n unless parse dsl rules [\n throw make error! \"You screwed up somehow.\"\n ]\n]\n"
},
{
"answer_id": 999207,
"author": "Rado",
"author_id": 123376,
"author_profile": "https://Stackoverflow.com/users/123376",
"pm_score": 2,
"selected": false,
"text": "finally\n{\n if(par1 != null)\n par1.Dispose();\n if(comm != null)\n comm.Dispose();\n if(conn != null)\n conn.Dispose();\n}\n"
},
{
"answer_id": 1005241,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 7,
"selected": false,
"text": "int a[10];\nfor (int idx = 0; idx < 15; idx++) a[idx] = 10;\n"
},
{
"answer_id": 1090890,
"author": "Paul Delhanty",
"author_id": 94338,
"author_profile": "https://Stackoverflow.com/users/94338",
"pm_score": 3,
"selected": false,
"text": "head"
},
{
"answer_id": 1117951,
"author": "quant_dev",
"author_id": 59557,
"author_profile": "https://Stackoverflow.com/users/59557",
"pm_score": 2,
"selected": false,
"text": "const"
},
{
"answer_id": 1650025,
"author": "kaleissin",
"author_id": 30368,
"author_profile": "https://Stackoverflow.com/users/30368",
"pm_score": 2,
"selected": false,
"text": "import foo\n"
},
{
"answer_id": 1795175,
"author": "tster",
"author_id": 175308,
"author_profile": "https://Stackoverflow.com/users/175308",
"pm_score": 0,
"selected": false,
"text": "x = y ?? z;\n"
},
{
"answer_id": 1967710,
"author": "Aaronaught",
"author_id": 38360,
"author_profile": "https://Stackoverflow.com/users/38360",
"pm_score": 2,
"selected": false,
"text": "GO"
},
{
"answer_id": 1968109,
"author": "slebetman",
"author_id": 167735,
"author_profile": "https://Stackoverflow.com/users/167735",
"pm_score": 2,
"selected": false,
"text": "$array($foo)"
},
{
"answer_id": 1990972,
"author": "John Stewien",
"author_id": 242220,
"author_profile": "https://Stackoverflow.com/users/242220",
"pm_score": 1,
"selected": false,
"text": "public class MyClass {\n private int someInt;\n\n public int SomeInt {\n get {\n return someInt;\n }\n set {\n someInt = value;\n }\n }\n}\n"
},
{
"answer_id": 2093310,
"author": "Bobby",
"author_id": 180239,
"author_profile": "https://Stackoverflow.com/users/180239",
"pm_score": -1,
"selected": false,
"text": "On Error"
},
{
"answer_id": 2218394,
"author": "Brendan",
"author_id": 199,
"author_profile": "https://Stackoverflow.com/users/199",
"pm_score": 1,
"selected": false,
"text": "math.ceil()"
},
{
"answer_id": 2494578,
"author": "Robert Davis",
"author_id": 265627,
"author_profile": "https://Stackoverflow.com/users/265627",
"pm_score": 2,
"selected": false,
"text": "dynamic"
},
{
"answer_id": 2763684,
"author": "Joey Adams",
"author_id": 149391,
"author_profile": "https://Stackoverflow.com/users/149391",
"pm_score": 0,
"selected": false,
"text": "a := 3"
},
{
"answer_id": 2763792,
"author": "o0'.",
"author_id": 207655,
"author_profile": "https://Stackoverflow.com/users/207655",
"pm_score": -1,
"selected": false,
"text": "(self,"
},
{
"answer_id": 2763939,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "path"
},
{
"answer_id": 2764399,
"author": "Midhat",
"author_id": 9425,
"author_profile": "https://Stackoverflow.com/users/9425",
"pm_score": 0,
"selected": false,
"text": "public static T MyFunc<T>(string arg) where T:Enum //wont work :(\n"
},
{
"answer_id": 2795725,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "Item o()"
},
{
"answer_id": 2891643,
"author": "Eamon Nerbonne",
"author_id": 42921,
"author_profile": "https://Stackoverflow.com/users/42921",
"pm_score": 2,
"selected": false,
"text": "IComparable"
},
{
"answer_id": 2891883,
"author": "e-satis",
"author_id": 9951,
"author_profile": "https://Stackoverflow.com/users/9951",
"pm_score": 2,
"selected": false,
"text": "elif"
},
{
"answer_id": 2892209,
"author": "Sedat Kapanoglu",
"author_id": 54937,
"author_profile": "https://Stackoverflow.com/users/54937",
"pm_score": 1,
"selected": false,
"text": "switch"
},
{
"answer_id": 2892388,
"author": "YasirA",
"author_id": 298282,
"author_profile": "https://Stackoverflow.com/users/298282",
"pm_score": 2,
"selected": false,
"text": "dialyzer(1)"
},
{
"answer_id": 2907479,
"author": "Sir Graystar",
"author_id": 349266,
"author_profile": "https://Stackoverflow.com/users/349266",
"pm_score": 2,
"selected": false,
"text": "(int)"
},
{
"answer_id": 2908194,
"author": "pablo.meier",
"author_id": 196469,
"author_profile": "https://Stackoverflow.com/users/196469",
"pm_score": 2,
"selected": false,
"text": "fun my_function/1"
},
{
"answer_id": 2908247,
"author": "Vorlauf",
"author_id": 350300,
"author_profile": "https://Stackoverflow.com/users/350300",
"pm_score": 2,
"selected": false,
"text": "#define STR_LINE2(x) #x"
},
{
"answer_id": 2908547,
"author": "DrewConway",
"author_id": 144537,
"author_profile": "https://Stackoverflow.com/users/144537",
"pm_score": 2,
"selected": false,
"text": "lists"
},
{
"answer_id": 2908877,
"author": "Tomas Sedovic",
"author_id": 2239,
"author_profile": "https://Stackoverflow.com/users/2239",
"pm_score": 1,
"selected": false,
"text": "list.empty?"
},
{
"answer_id": 2909896,
"author": "Arnold deVos",
"author_id": 319053,
"author_profile": "https://Stackoverflow.com/users/319053",
"pm_score": 2,
"selected": false,
"text": "def f(x: Int) = x*x"
},
{
"answer_id": 2949743,
"author": "Bastien Léonard",
"author_id": 88851,
"author_profile": "https://Stackoverflow.com/users/88851",
"pm_score": 3,
"selected": false,
"text": "main.py"
},
{
"answer_id": 2955202,
"author": "RCIX",
"author_id": 117069,
"author_profile": "https://Stackoverflow.com/users/117069",
"pm_score": 2,
"selected": false,
"text": "a += 20"
},
{
"answer_id": 3261769,
"author": "xenoterracide",
"author_id": 206466,
"author_profile": "https://Stackoverflow.com/users/206466",
"pm_score": 3,
"selected": false,
"text": "say"
},
{
"answer_id": 3528183,
"author": "dan04",
"author_id": 287586,
"author_profile": "https://Stackoverflow.com/users/287586",
"pm_score": 3,
"selected": false,
"text": "T if C else F"
},
{
"answer_id": 3678835,
"author": "Thorbjørn Ravn Andersen",
"author_id": 53897,
"author_profile": "https://Stackoverflow.com/users/53897",
"pm_score": 2,
"selected": false,
"text": "${...}"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282329",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2766176/"
] |
282,332 | <p>Background: we have a system that was written in an older CMS based on Java back during the 2002-2003 days. We want to keep moving forward with our new stuff, using tomcat, stripes, and sitemesh. We have navigation, layouts, "pods", js, css, etc, that we've taken out of the old CMS and into a few of our new apps so we have consistent look and feel.</p>
<p>We now need some sort of solution to get rid of all the code duplication going on. Our apps are running on the same VM at the moment, but that might change. We need a way for all of our tomcat instances to access some common elements (and those elements may/may not need to do some server side stuff). </p>
<p>The best we've come up with so far is making a fairly standard sitemesh decorator, that uses c:import to get what it needs, and plugs it right in. This solution has some network overhead which could bog it down and introduce a fail point. We've looked at <%@ include file="/something.jsp" %> as well but that seems to be only context relative. We could use c:import and point it at localhost, which seems to be the best solution so far. </p>
<p>Are there other templating/decorating frameworks out there (Tiles?) that could make this simpler? What are we missing?</p>
| [
{
"answer_id": 282342,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 7,
"selected": false,
"text": "lock"
},
{
"answer_id": 282356,
"author": "zmf",
"author_id": 13285,
"author_profile": "https://Stackoverflow.com/users/13285",
"pm_score": 3,
"selected": false,
"text": "Boolean"
},
{
"answer_id": 282366,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 5,
"selected": false,
"text": "__init__"
},
{
"answer_id": 282436,
"author": "I GIVE TERRIBLE ADVICE",
"author_id": 35344,
"author_profile": "https://Stackoverflow.com/users/35344",
"pm_score": 6,
"selected": false,
"text": "$var = preg_match_all('/regexp/', $str, $ret);\necho $var; //outputs the number of matches \nprint_r($ret); //outputs the matches as an array\n"
},
{
"answer_id": 282445,
"author": "staticsan",
"author_id": 28832,
"author_profile": "https://Stackoverflow.com/users/28832",
"pm_score": 3,
"selected": false,
"text": "explode()"
},
{
"answer_id": 282505,
"author": "Myrddin Emrys",
"author_id": 9084,
"author_profile": "https://Stackoverflow.com/users/9084",
"pm_score": 6,
"selected": false,
"text": "object.method(1, {|a| a.bar}, \"blah\")\n"
},
{
"answer_id": 282574,
"author": "too much php",
"author_id": 28835,
"author_profile": "https://Stackoverflow.com/users/28835",
"pm_score": 7,
"selected": false,
"text": "$parts = explode('|', $string);\n$first = $parts[0];\n"
},
{
"answer_id": 282686,
"author": "Brad Gilbert",
"author_id": 1337,
"author_profile": "https://Stackoverflow.com/users/1337",
"pm_score": 6,
"selected": false,
"text": "my @array = ( 1, 2, 3 );\nmy $array = [ 4, 5, 6 ];\n\nmy $one = $array[0]; # not @array[0], you would get the length instead\nmy $four = $array->[0]; # definitely not $array[0]\n\nmy( $two, $three ) = @array[1,2];\nmy( $five, $six ) = @$array[1,2]; # coerce to array first\n\nmy $length_a = @array;\nmy $length_s = @$array;\n\nmy $ref_a = \\@array;\nmy $ref_s = $array;\n"
},
{
"answer_id": 282714,
"author": "wnoise",
"author_id": 15464,
"author_profile": "https://Stackoverflow.com/users/15464",
"pm_score": 4,
"selected": false,
"text": "($)"
},
{
"answer_id": 286856,
"author": "StingyJack",
"author_id": 16391,
"author_profile": "https://Stackoverflow.com/users/16391",
"pm_score": 4,
"selected": false,
"text": "AndAlso"
},
{
"answer_id": 288931,
"author": "utku_karatas",
"author_id": 14716,
"author_profile": "https://Stackoverflow.com/users/14716",
"pm_score": 3,
"selected": false,
"text": "try except finally end;"
},
{
"answer_id": 313395,
"author": "Demur Rumed",
"author_id": 40172,
"author_profile": "https://Stackoverflow.com/users/40172",
"pm_score": 1,
"selected": false,
"text": "::value"
},
{
"answer_id": 321863,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 4,
"selected": false,
"text": "cpan"
},
{
"answer_id": 321966,
"author": "kristina",
"author_id": 4243,
"author_profile": "https://Stackoverflow.com/users/4243",
"pm_score": 3,
"selected": false,
"text": "f = new Function( \"foo\", \"bar\", \"return foo+bar;\" );\n"
},
{
"answer_id": 344716,
"author": "hasen",
"author_id": 35364,
"author_profile": "https://Stackoverflow.com/users/35364",
"pm_score": 3,
"selected": false,
"text": "__init__"
},
{
"answer_id": 347124,
"author": "Daniel Cassidy",
"author_id": 31662,
"author_profile": "https://Stackoverflow.com/users/31662",
"pm_score": 5,
"selected": false,
"text": "Object"
},
{
"answer_id": 347134,
"author": "Tetha",
"author_id": 17663,
"author_profile": "https://Stackoverflow.com/users/17663",
"pm_score": 1,
"selected": false,
"text": "l = [l1, l2, ..., ln]"
},
{
"answer_id": 347672,
"author": "Andreas Grech",
"author_id": 44084,
"author_profile": "https://Stackoverflow.com/users/44084",
"pm_score": 4,
"selected": false,
"text": "hasOwnProperty"
},
{
"answer_id": 385617,
"author": "Jay Bazuzi",
"author_id": 5314,
"author_profile": "https://Stackoverflow.com/users/5314",
"pm_score": 2,
"selected": false,
"text": "MessageBoxButton"
},
{
"answer_id": 385625,
"author": "Jay Bazuzi",
"author_id": 5314,
"author_profile": "https://Stackoverflow.com/users/5314",
"pm_score": 5,
"selected": false,
"text": "switch()"
},
{
"answer_id": 410238,
"author": "EMP",
"author_id": 20336,
"author_profile": "https://Stackoverflow.com/users/20336",
"pm_score": 3,
"selected": false,
"text": "static T Parse(string s)"
},
{
"answer_id": 410260,
"author": "Logan Serman",
"author_id": 29595,
"author_profile": "https://Stackoverflow.com/users/29595",
"pm_score": 3,
"selected": false,
"text": "<?php\nif($x == NULL)\n{\n?>\n <p><?= $x . ' is null' ?></p>\n<?php\n}\n?>\n"
},
{
"answer_id": 424664,
"author": "SpoonMeiser",
"author_id": 1577190,
"author_profile": "https://Stackoverflow.com/users/1577190",
"pm_score": 3,
"selected": false,
"text": "import random\n\ndef myFunction():\n\n if random.choice(True, False):\n myString = \"blah blah blah\"\n\n print myString\n"
},
{
"answer_id": 425557,
"author": "peSHIr",
"author_id": 50846,
"author_profile": "https://Stackoverflow.com/users/50846",
"pm_score": 2,
"selected": false,
"text": "Class<D>"
},
{
"answer_id": 434132,
"author": "Sean Edwards",
"author_id": 53315,
"author_profile": "https://Stackoverflow.com/users/53315",
"pm_score": 3,
"selected": false,
"text": "global"
},
{
"answer_id": 564273,
"author": "Chris Lutz",
"author_id": 60777,
"author_profile": "https://Stackoverflow.com/users/60777",
"pm_score": 2,
"selected": false,
"text": "write()"
},
{
"answer_id": 564388,
"author": "Jon Ericson",
"author_id": 1438,
"author_profile": "https://Stackoverflow.com/users/1438",
"pm_score": 2,
"selected": false,
"text": "DUAL"
},
{
"answer_id": 567742,
"author": "Ellery Newcomer",
"author_id": 23648,
"author_profile": "https://Stackoverflow.com/users/23648",
"pm_score": 2,
"selected": false,
"text": "array.length += 512;"
},
{
"answer_id": 737519,
"author": "SingleNegationElimination",
"author_id": 65696,
"author_profile": "https://Stackoverflow.com/users/65696",
"pm_score": 2,
"selected": false,
"text": "lambda"
},
{
"answer_id": 919957,
"author": "Jonas Kölker",
"author_id": 58668,
"author_profile": "https://Stackoverflow.com/users/58668",
"pm_score": 3,
"selected": false,
"text": "snprintf"
},
{
"answer_id": 989478,
"author": "Gregory Higley",
"author_id": 27779,
"author_profile": "https://Stackoverflow.com/users/27779",
"pm_score": 1,
"selected": false,
"text": "; A small DSL that sends email to people about URLs.\nrules: [\n some [\n into [\n set email email!\n set url url!\n (send/subject email url reform [ \"Check Out\" url ])\n ]\n ]\n]\n\n; Global context\nnotify: func [ [catch] dsl [block!] ] [\n unless parse dsl rules [\n throw make error! \"You screwed up somehow.\"\n ]\n]\n"
},
{
"answer_id": 999207,
"author": "Rado",
"author_id": 123376,
"author_profile": "https://Stackoverflow.com/users/123376",
"pm_score": 2,
"selected": false,
"text": "finally\n{\n if(par1 != null)\n par1.Dispose();\n if(comm != null)\n comm.Dispose();\n if(conn != null)\n conn.Dispose();\n}\n"
},
{
"answer_id": 1005241,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 7,
"selected": false,
"text": "int a[10];\nfor (int idx = 0; idx < 15; idx++) a[idx] = 10;\n"
},
{
"answer_id": 1090890,
"author": "Paul Delhanty",
"author_id": 94338,
"author_profile": "https://Stackoverflow.com/users/94338",
"pm_score": 3,
"selected": false,
"text": "head"
},
{
"answer_id": 1117951,
"author": "quant_dev",
"author_id": 59557,
"author_profile": "https://Stackoverflow.com/users/59557",
"pm_score": 2,
"selected": false,
"text": "const"
},
{
"answer_id": 1650025,
"author": "kaleissin",
"author_id": 30368,
"author_profile": "https://Stackoverflow.com/users/30368",
"pm_score": 2,
"selected": false,
"text": "import foo\n"
},
{
"answer_id": 1795175,
"author": "tster",
"author_id": 175308,
"author_profile": "https://Stackoverflow.com/users/175308",
"pm_score": 0,
"selected": false,
"text": "x = y ?? z;\n"
},
{
"answer_id": 1967710,
"author": "Aaronaught",
"author_id": 38360,
"author_profile": "https://Stackoverflow.com/users/38360",
"pm_score": 2,
"selected": false,
"text": "GO"
},
{
"answer_id": 1968109,
"author": "slebetman",
"author_id": 167735,
"author_profile": "https://Stackoverflow.com/users/167735",
"pm_score": 2,
"selected": false,
"text": "$array($foo)"
},
{
"answer_id": 1990972,
"author": "John Stewien",
"author_id": 242220,
"author_profile": "https://Stackoverflow.com/users/242220",
"pm_score": 1,
"selected": false,
"text": "public class MyClass {\n private int someInt;\n\n public int SomeInt {\n get {\n return someInt;\n }\n set {\n someInt = value;\n }\n }\n}\n"
},
{
"answer_id": 2093310,
"author": "Bobby",
"author_id": 180239,
"author_profile": "https://Stackoverflow.com/users/180239",
"pm_score": -1,
"selected": false,
"text": "On Error"
},
{
"answer_id": 2218394,
"author": "Brendan",
"author_id": 199,
"author_profile": "https://Stackoverflow.com/users/199",
"pm_score": 1,
"selected": false,
"text": "math.ceil()"
},
{
"answer_id": 2494578,
"author": "Robert Davis",
"author_id": 265627,
"author_profile": "https://Stackoverflow.com/users/265627",
"pm_score": 2,
"selected": false,
"text": "dynamic"
},
{
"answer_id": 2763684,
"author": "Joey Adams",
"author_id": 149391,
"author_profile": "https://Stackoverflow.com/users/149391",
"pm_score": 0,
"selected": false,
"text": "a := 3"
},
{
"answer_id": 2763792,
"author": "o0'.",
"author_id": 207655,
"author_profile": "https://Stackoverflow.com/users/207655",
"pm_score": -1,
"selected": false,
"text": "(self,"
},
{
"answer_id": 2763939,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "path"
},
{
"answer_id": 2764399,
"author": "Midhat",
"author_id": 9425,
"author_profile": "https://Stackoverflow.com/users/9425",
"pm_score": 0,
"selected": false,
"text": "public static T MyFunc<T>(string arg) where T:Enum //wont work :(\n"
},
{
"answer_id": 2795725,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "Item o()"
},
{
"answer_id": 2891643,
"author": "Eamon Nerbonne",
"author_id": 42921,
"author_profile": "https://Stackoverflow.com/users/42921",
"pm_score": 2,
"selected": false,
"text": "IComparable"
},
{
"answer_id": 2891883,
"author": "e-satis",
"author_id": 9951,
"author_profile": "https://Stackoverflow.com/users/9951",
"pm_score": 2,
"selected": false,
"text": "elif"
},
{
"answer_id": 2892209,
"author": "Sedat Kapanoglu",
"author_id": 54937,
"author_profile": "https://Stackoverflow.com/users/54937",
"pm_score": 1,
"selected": false,
"text": "switch"
},
{
"answer_id": 2892388,
"author": "YasirA",
"author_id": 298282,
"author_profile": "https://Stackoverflow.com/users/298282",
"pm_score": 2,
"selected": false,
"text": "dialyzer(1)"
},
{
"answer_id": 2907479,
"author": "Sir Graystar",
"author_id": 349266,
"author_profile": "https://Stackoverflow.com/users/349266",
"pm_score": 2,
"selected": false,
"text": "(int)"
},
{
"answer_id": 2908194,
"author": "pablo.meier",
"author_id": 196469,
"author_profile": "https://Stackoverflow.com/users/196469",
"pm_score": 2,
"selected": false,
"text": "fun my_function/1"
},
{
"answer_id": 2908247,
"author": "Vorlauf",
"author_id": 350300,
"author_profile": "https://Stackoverflow.com/users/350300",
"pm_score": 2,
"selected": false,
"text": "#define STR_LINE2(x) #x"
},
{
"answer_id": 2908547,
"author": "DrewConway",
"author_id": 144537,
"author_profile": "https://Stackoverflow.com/users/144537",
"pm_score": 2,
"selected": false,
"text": "lists"
},
{
"answer_id": 2908877,
"author": "Tomas Sedovic",
"author_id": 2239,
"author_profile": "https://Stackoverflow.com/users/2239",
"pm_score": 1,
"selected": false,
"text": "list.empty?"
},
{
"answer_id": 2909896,
"author": "Arnold deVos",
"author_id": 319053,
"author_profile": "https://Stackoverflow.com/users/319053",
"pm_score": 2,
"selected": false,
"text": "def f(x: Int) = x*x"
},
{
"answer_id": 2949743,
"author": "Bastien Léonard",
"author_id": 88851,
"author_profile": "https://Stackoverflow.com/users/88851",
"pm_score": 3,
"selected": false,
"text": "main.py"
},
{
"answer_id": 2955202,
"author": "RCIX",
"author_id": 117069,
"author_profile": "https://Stackoverflow.com/users/117069",
"pm_score": 2,
"selected": false,
"text": "a += 20"
},
{
"answer_id": 3261769,
"author": "xenoterracide",
"author_id": 206466,
"author_profile": "https://Stackoverflow.com/users/206466",
"pm_score": 3,
"selected": false,
"text": "say"
},
{
"answer_id": 3528183,
"author": "dan04",
"author_id": 287586,
"author_profile": "https://Stackoverflow.com/users/287586",
"pm_score": 3,
"selected": false,
"text": "T if C else F"
},
{
"answer_id": 3678835,
"author": "Thorbjørn Ravn Andersen",
"author_id": 53897,
"author_profile": "https://Stackoverflow.com/users/53897",
"pm_score": 2,
"selected": false,
"text": "${...}"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282332",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31172/"
] |
282,363 | <p>I run a series of time consuming operations on a background worker thread. At various stages I update a (windows form) progress bar by invoking a delegate. However, one of the more time operations occurs on a single line of code.</p>
<p>Is it possible to :</p>
<p>a) Update the UI while that single line of code is being executed, or at least display an animated icon that shows the user that work is being done.</p>
<p>b) Let the user cancel the background worker thread while that single line of code is being executed</p>
| [
{
"answer_id": 282380,
"author": "jons911",
"author_id": 34375,
"author_profile": "https://Stackoverflow.com/users/34375",
"pm_score": 3,
"selected": true,
"text": "public void DoWork() {\n System.Threading.Thread.Sleep(10000);\n\n // won't execute until the sleep is over\n bgWorker.ReportProgress(100);\n}\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282363",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2680373/"
] |
282,369 | <p>Recently I had to move one of my web applications to a new hosting provider. The mail and web service is still held on the old hosting site however, when I try to send an email from the new server,I get an error; </p>
<p>"The server rejected one or more recipient addresses. The server response was:</p>
<pre><code>450 <email_address>: Recipient address rejected: Greylisted for 5 minutes
</code></pre>
<p>I asked my old hosting provider what I need to do to fix this and they replied with</p>
<blockquote>
<p>The mail server operates on POP before
SMTP. If a valid POP login is not
received before sending mail through
the server, then the mail is
greylisted and held for 5 minutes
before a retry. </p>
<p>To prevent this, simply do a Receive
before sending mail</p>
</blockquote>
<p>Does anyone have any idea how I do a POP before SMTP in C#? </p>
| [
{
"answer_id": 282387,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 2,
"selected": false,
"text": "$ telnet new-pop-server.com 110\nConnected to new-pop-server.com.\nEscape character is '^]'.\n+OK\nUSER <username>\n+OK \nPASS <password>\n+OK // you're authenticated at this point \nLIST\n+OK \n. // no new messages!\nQUIT\n+OK \n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282369",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26300/"
] |
282,372 | <p>want to pass boost::bind to a method expecting a plain function pointer (same signature).</p>
<pre><code>typedef void TriggerProc_type(Variable*,void*);
void InitVariable(TriggerProc_type *proc);
boost::function<void (Variable*, void*)> triggerProc ...
InitVariable(triggerProc);
error C2664: 'InitVariable' : cannot convert parameter 1 from
'boost::function<Signature>' to 'void (__cdecl *)(type *,void *)'
</code></pre>
<p>I can avoid storing a boost::function and just pass the bound functor directly, but then I get similar error:</p>
<pre><code>error C2664: 'blah(void (__cdecl *)(type *,void *))' : cannot convert parameter
1 from 'boost::_bi::bind_t<R,F,L>' to 'void (__cdecl *)(type *,void *)'
</code></pre>
| [
{
"answer_id": 282433,
"author": "coryan",
"author_id": 33325,
"author_profile": "https://Stackoverflow.com/users/33325",
"pm_score": 4,
"selected": false,
"text": "#include <boost/function.hpp>\n#include <iostream>\n\nint f(int x)\n{\n return x + x;\n}\n\ntypedef int (*pointer_to_func)(int);\n\nint\nmain()\n{\n boost::function<int(int x)> g(f);\n\n if(*g.target<pointer_to_func>() == f) {\n std::cout << \"g contains f\" << std::endl;\n } else {\n std::cout << \"g does not contain f\" << std::endl;\n }\n\n return 0;\n}\n"
},
{
"answer_id": 512189,
"author": "Dustin Getz",
"author_id": 20003,
"author_profile": "https://Stackoverflow.com/users/20003",
"pm_score": 0,
"selected": false,
"text": "#include <boost/function.hpp>\n#include <boost/bind.hpp>\n\nvoid f(int x)\n{\n (void) x;\n _asm int 3;\n}\n\ntypedef void (*cb_t)(int);\n\nint main()\n{\n boost::function<void (int x)> g = boost::bind(f, 3);\n cb_t cb = *g.target<cb_t>(); //target returns null\n cb(1);\n\n return 0;\n}\n"
},
{
"answer_id": 512233,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 2,
"selected": false,
"text": "cb_t cb = *g.target<cb_t>(); //target returns null\n"
},
{
"answer_id": 3453616,
"author": "Ian Ni-Lewis",
"author_id": 416621,
"author_profile": "https://Stackoverflow.com/users/416621",
"pm_score": 6,
"selected": true,
"text": "typedef void (*CallbackType)(int x, void* user_data);\nvoid RegisterCallback(CallbackType cb, void* user_data);\n\nvoid MyCallback(int x, void* userData) {\n boost::function<void(int)> pfn = static_cast<boost::function<void(int)> >(userData);\n pfn(x);\n}\n\nboost::function<void(int)> fn = boost::bind(myFunction(5));\nRegisterCallback(MyCallback, &fn);\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20003/"
] |
282,377 | <p>In Visual Studio, How do I show all classes inherited from a base class? </p>
<p><strong>For example</strong>, in ASP.NET MVC there are several '<a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.actionresult.aspx" rel="noreferrer">ActionResult</a>' types -- and they all inherit from / implement the base class <code>ActionResult</code>. </p>
<p>It looks like unless you just 'know' that <code>View</code> and <code>Json</code> are valid <code>ActionResult</code> types, there is no way you can easily find this information out. </p>
<p><em>Please prove me wrong.</em></p>
<p>Is there something in the object browser that makes this easy to find out?</p>
<p>I'm even up for suggestions of tools outside of Visual Studio to discover this information about various classes. For example: is there something in Resharper that will help me out?</p>
| [
{
"answer_id": 11210689,
"author": "Lzh",
"author_id": 1041631,
"author_profile": "https://Stackoverflow.com/users/1041631",
"pm_score": 4,
"selected": false,
"text": "//Go through all the types and either add them to a tree node, or add a tree\n//node or more to them depending whether the type is a base or derived class.\n//If neither base or derived, just add them to the dictionary so that they be\n//checked in the next iterations for being a parent a child or just remain a\n//root level node.\n\nvar types = typeof(TYPEOFASSEMBLY).Assembly.GetExportedTypes().ToList();\nDictionary<Type, TreeNode> typeTreeDictionary = new Dictionary<Type, TreeNode>();\nforeach (var t in types)\n{\n var tTreeNode = FromType(t);\n typeTreeDictionary.Add(t, tTreeNode);\n\n //either a parent or a child, never in between\n bool foundPlaceAsParent = false;\n bool foundPlaceAsChild = false;\n foreach (var d in typeTreeDictionary.Keys)\n {\n if (d.BaseType.Equals(t))\n {\n //t is parent to d\n foundPlaceAsParent = true;\n tTreeNode.Nodes.Add(typeTreeDictionary[d]);\n //typeTreeDictionary.Remove(d);\n }\n else if (t.BaseType.Equals(d))\n {\n //t is child to d\n foundPlaceAsChild = true;\n typeTreeDictionary[d].Nodes.Add(tTreeNode);\n }\n }\n\n if (!foundPlaceAsParent && !foundPlaceAsChild)\n {\n //classHierarchyTreeView.Nodes.Add(tn);\n }\n}\n\nforeach (var t in typeTreeDictionary.Keys)\n{\n if (typeTreeDictionary[t].Level == 0)\n {\n classHierarchyTreeView.Nodes.Add(typeTreeDictionary[t]);\n }\n}\n\nStringBuilder sb = new StringBuilder();\nforeach (TreeNode t in classHierarchyTreeView.Nodes)\n{\n sb.Append(GetStringRepresentation(t, 0));\n}\ntextBox2.Text = sb.ToString();\n"
},
{
"answer_id": 11849238,
"author": "Dan Esparza",
"author_id": 19020,
"author_profile": "https://Stackoverflow.com/users/19020",
"pm_score": 3,
"selected": false,
"text": "ActionResult"
},
{
"answer_id": 11867488,
"author": "Mehmet Ataş",
"author_id": 554397,
"author_profile": "https://Stackoverflow.com/users/554397",
"pm_score": 0,
"selected": false,
"text": "Assembly asm = Assembly.LoadFrom(PATH_TO_PROJECT_OUTPUT);\n\nvar types = from t in asm.GetTypes()\n where t.BaseType != null && t.BaseType.ToString() == \"System.Web.UI.Page\"\n // if you want to add reference - where typeof (System.Web.UI.Page).Equals(t.BaseType) \n select t;\n\nforeach (var type in types)\n{\n Console.WriteLine(type);\n}\n"
},
{
"answer_id": 29966495,
"author": "Richard",
"author_id": 4850494,
"author_profile": "https://Stackoverflow.com/users/4850494",
"pm_score": -1,
"selected": false,
"text": ": Classname"
},
{
"answer_id": 61248908,
"author": "Just Shadow",
"author_id": 5935112,
"author_profile": "https://Stackoverflow.com/users/5935112",
"pm_score": 0,
"selected": false,
"text": "Code Map"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282377",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19020/"
] |
282,391 | <p>.NET 3.5, C#</p>
<p>I have a web app with a "search" feature. Some of the fields that are searchable are first-class columns in the table, but some of them are in fact nested fields inside an XML data type. </p>
<p>Previously, I built a system for dynamically constructing the SQL for my search. I had a nice class hierarchy that built SQL expressions and conditional statements. The only problem was it was not safe from SQL injection attacks.</p>
<p>I was reading <a href="http://blog.wekeroad.com/2008/02/27/creating-in-queries-with-linq-to-sql/" rel="nofollow noreferrer">Rob Conery's excellent article</a> which pointed out that multiple queries can combined into a single TSQL query for the server if the IQueryable result is never enumerated. This got me to thinking that my dynamic search construction was much too complicated - I just needed to combine multiple LINQ expressions.</p>
<p>For example (contrived):</p>
<pre><code>Author:
ID (int),
LastName (varchar(32)),
FirstName (varchar(32))
context.Author.Where(xx => xx.LastName == "Smith").Where(xx => xx.FirstName == "John")
</code></pre>
<p>Results in the following query:</p>
<pre><code>SELECT [t0].[ID], [t0].[LastName], [t0].[FirstName]
FROM [dbo].[Author] AS [t0]
WHERE ([t0].[LastName] = Smith) AND ([t0].[FirstName] = John)
</code></pre>
<p>I realized this might be the perfect solution for a simple dynamic query generation that's safe from SQL injection - I'd just loop over my IQueryable result and execute additional conditionals expressions to get my final single-execution expression.</p>
<p>However, I can't find any support for evaluation of XML data. In TSQL, to get a value from an XML node, we would do something like</p>
<pre><code>XMLField.value('(*:Root/*:CreatedAt)[1]', 'datetime') = getdate()
</code></pre>
<p>But I can't find the LINQ to SQL equivalent of creating this evaluation. Does one exist? I know I can evaluate all non-XML conditions DB side, and then do my XML evaluations code side, but my data are large enough that A) that's a lot of network traffic to drag on performance and B) I'll get out-of-memory exceptions if I can't evaluate the XML first DB side to exclude certain result sets.</p>
<p>Ideas? Suggestions? </p>
<p>Bonus question - If XML evaluation is in fact possible DB side, what about FLWOR support?</p>
| [
{
"answer_id": 282514,
"author": "Daniel M",
"author_id": 36559,
"author_profile": "https://Stackoverflow.com/users/36559",
"pm_score": 5,
"selected": true,
"text": "xmlColumn.value"
},
{
"answer_id": 23779525,
"author": "user1620076",
"author_id": 1620076,
"author_profile": "https://Stackoverflow.com/users/1620076",
"pm_score": -1,
"selected": false,
"text": "Dim txt as String = \"<File>3</File>\"\nReturn (From P In DC.LPlanningRefs Where P.Details.ToString.Contains(txt) Select P).FirstOrDefault\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282391",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17803/"
] |
282,393 | <p>I have a rather complex decorator written by someone else. What I want to do is call a decorated version of the function one time based on a descision or call the original function (not decorated) another time. Is this possible?</p>
| [
{
"answer_id": 282399,
"author": "Ali Afshar",
"author_id": 28380,
"author_profile": "https://Stackoverflow.com/users/28380",
"pm_score": 6,
"selected": true,
"text": "decorator(original_function)()\n"
},
{
"answer_id": 282816,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 2,
"selected": false,
"text": "def original_function():\n pass\n\ndecorated_function= decorator(original_function)\n\nif use_decorated:\n decorated_function()\nelse:\n original_function()\n"
},
{
"answer_id": 812743,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "# http://www.phyast.pitt.edu/~micheles/python/decorator-2.0.1.zip\nfrom decorator import decorator, update_wrapper\n\nclass mustbe : pass\n\ndef wrapper ( interface_ ) :\n print \"inside hhh\"\n def call ( func, self, *args, **kwargs ) :\n print \"decorated\"\n print \"calling %s.%s with args %s, %s\" % (self, func.__name__, args, kwargs)\n return interface_ ( self, *args, **kwargs )\n def original ( instance , *args, **kwargs ) :\n if not isinstance ( instance, mustbe ) :\n raise TypeError, \"Only use this decorator on children of mustbe\"\n return interface_ ( instance, *args, **kwargs )\n call = decorator ( call, interface_ )\n call.original = update_wrapper ( original, call )\n return call\n\nclass CCC ( mustbe ):\n var = \"class var\"\n @wrapper\n def foo ( self, param ) :\n \"\"\"foo\"\"\"\n print self.var, param\n\nclass SSS ( CCC ) :\n @wrapper ( hidden_=True )\n def bar ( self, a, b, c ) :\n print a, b, c\n\nif __name__ == \"__main__\" :\n from inspect import getargspec\n\n print \">>> i=CCC()\"\n i=CCC()\n\n print \">>> i.var = 'parrot'\"\n i.var = 'parrot'\n\n print \">>> i.foo.__doc__\"\n print i.foo.__doc__\n\n print \">>> getargspec(i.foo)\"\n print getargspec(i.foo)\n\n print \">>> i.foo(99)\"\n i.foo(99)\n\n print \">>> i.foo.original.__doc__\"\n print i.foo.original.__doc__\n\n print \">>> getargspec(i.foo.original)\"\n print getargspec(i.foo.original)\n\n print \">>> i.foo.original(i,42)\"\n i.foo.original(i,42)\n\n print \">>> j=SSS()\"\n j=SSS()\n\n print \">>> j.bar(1,2,3)\"\n j.bar(1,2,3)\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7883/"
] |
282,406 | <p>I am just getting started with IoC containers so apologies if this is a stupid question.</p>
<p>I have code like the following in an app</p>
<pre><code>internal static class StaticDataHandlerFactory
{
public static IStaticDataHandler CreateHandler(StaticDataUpdate staticDataUpdate)
{
if (staticDataUpdate.Item is StaticDataUpdateOffice)
{
return new OfficeUpdateHandler();
}
if (staticDataUpdate.Item is StaticDataUpdateEmployee)
{
return new EmployeeUpdateHandler();
}
if (staticDataUpdate.Item == null)
{
throw new NotImplementedException(
string.Format("No static data provided"));
}
else
{
throw new NotImplementedException(
string.Format("Unimplemented static data type of {0}", staticDataUpdate.Item.GetType().FullName));
}
}
}
</code></pre>
<p>It is basically a simple factory that returns the correct strategy for handling the input data.</p>
<p>Would an IoC container allow me to eliminate code like this? That is to say : would it allow me to dynamically choose a concrete implementation to load based on the type of an input parameter?</p>
<p>Or am I way off course here?</p>
| [
{
"answer_id": 282481,
"author": "Paul Sonier",
"author_id": 28053,
"author_profile": "https://Stackoverflow.com/users/28053",
"pm_score": 2,
"selected": false,
"text": "m_officeUpdateHandler"
},
{
"answer_id": 284685,
"author": "dviljoen",
"author_id": 29021,
"author_profile": "https://Stackoverflow.com/users/29021",
"pm_score": 1,
"selected": false,
"text": "public static IStaticDataHandler CreateHandler<T>( params object[] args )\n{...\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282406",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17194/"
] |
282,422 | <p>I have a Flash application that is hosted from within a Drupal page. Some parts of the Flash application should be available to all users, but some should only be available to a logged-in user. (The specific role doesn't matter, just that they are any authorized user of the site).</p>
<p>From within Flash, I can detect whether the user is logged on by screen-scraping the "?q=user" page, but this is very brittle. What is the "right" way to do this? I can install additional Modules if necessary, but they need to be compatible with Drupal 6, not 5.</p>
<p>Similarly, if there is no user currently logged in, how can I take a username and password that they provide to me and log them in (or determine that the password is bad)?</p>
| [
{
"answer_id": 282462,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 2,
"selected": false,
"text": "<?php\n// myservices.info\n name = My Services\n description = Expose basic services\n core = 6.x\n\n<?php\n// myservices.module\n\n function myservices_menu() {\n $items['myservices/user'] = array(\n 'title' => 'Get auth',\n 'page callback' => 'myservices_get_user',\n 'access arguments' => array('access content'),\n );\n return $items;\n }\n\n function myservices_get_user() {\n global $user;\n if (in_array('authenticated user', $user->roles) ) {\n print 'yes';\n } else {\n print 'no';\n }\n }\n"
},
{
"answer_id": 291600,
"author": "Eric",
"author_id": 4540,
"author_profile": "https://Stackoverflow.com/users/4540",
"pm_score": 3,
"selected": true,
"text": "package\n{\n import com.ak33m.rpc.xmlrpc.XMLRPCObject;\n\n import flash.events.*;\n import flash.net.*;\n\n import mx.collections.ItemResponder;\n import mx.rpc.AsyncToken;\n import mx.rpc.events.FaultEvent;\n import mx.rpc.events.ResultEvent;\n\n\n public class DrupalLogin\n {\n private var _api:XMLRPCObject;\n\n public function DrupalLogin( url:String )\n {\n _api = new XMLRPCObject();\n _api.endpoint = url;\n _api.destination = \"\";\n }\n\n public function set LoginResult( fn:Function ):void {_handleLoginResult = fn; }\n public function set CheckResult( fn:Function ):void {_handleCheckResult = fn; }\n public function set LogoutResult( fn:Function ):void {_handleLogoutResult = fn; }\n public function get User():String { return _user; }\n public function set TraceResult( fn:Function ):void {_handleTrace = fn; }\n\n private var _handleLoginResult:Function;\n private var _handleCheckResult:Function;\n private var _handleLogoutResult:Function;\n private var _handleTrace:Function;\n\n private function onTrace( st:String ):void\n {\n _handleTrace(st);\n }\n\n private var _firstCheckDone:Boolean = false;\n private var _loggedIn:Boolean = false;\n\n\n // The logged-in user's ID (if any)\n private var _user:String = \"\";\n\n\n\n // *****************************************\n // doLogin\n // *****************************************\n\n // Function doLogin kicks off the process.\n public function doLogin( user:String, pwd:String ):void\n {\n onTrace( \"******************* doLogin ********************\" );\n\n if( !_firstCheckDone )\n {\n _handleLoginResult( false, \"ALWAYS CALL doCheck() FIRST TO SEE IF YOU NEED TO LOG IN OR NOT\" );\n return;\n }\n if( _loggedIn )\n {\n _handleLoginResult( true, \"YOU ARE ALREADY LOGGED IN\" );\n return;\n }\n\n var token:AsyncToken = _api.call( \"user.login\", _sid, user, pwd );\n var tresponder:ItemResponder = new ItemResponder(this.onLoginInfo,this.onLoginFault);\n token.addResponder(tresponder);\n }\n\n\n private function onLoginInfo (event:ResultEvent,token:Object = null):void\n {\n onTrace( \"... got onLoginInfo\" );\n\n _user = event.result.user.name;\n _loggedIn = true;\n _handleLoginResult( true, \"logged in ok\" ); \n }\n\n private function onLoginFault (event:FaultEvent, token:Object=null):void\n {\n onTrace( \" got onLoginFault\" );\n\n _loggedIn = false;\n _handleLoginResult( false, \"Fault: \" + event.fault.faultString + \" -- \" + event.fault.faultCode);\n }\n\n\n // *****************************************\n // doLogout\n // *****************************************\n\n public function doLogout():void\n {\n onTrace( \"******************* doLogout ********************\" );\n\n if( !_firstCheckDone )\n {\n _handleLogoutResult( false, \"ALWAYS CALL doCheck() FIRST TO SEE IF YOU ARE ABLE TO LOG OUT OR NOT\" );\n return;\n }\n if( !_loggedIn )\n {\n _handleLogoutResult( true, \"YOU ARE ALREADY LOGGED OUT\" );\n return;\n }\n\n var token:AsyncToken = _api.call( \"user.logout\", _sid );\n var tresponder:ItemResponder = new ItemResponder(this.onLogoutInfo,this.onLogoutFault);\n token.addResponder(tresponder);\n }\n\n private function onLogoutInfo (event:ResultEvent,token:Object = null):void\n {\n onTrace( \"got onLogoutInfo\" );\n\n _loggedIn = false;\n _handleLogoutResult( true, \"logged out ok\" ); \n }\n\n private function onLogoutFault (event:FaultEvent, token:Object=null):void\n {\n onTrace( \"got onLogoutFault\" );\n\n _loggedIn = false;\n _handleLogoutResult( false, \"Fault: \" + event.fault.faultString + \" -- \" + event.fault.faultCode);\n }\n\n\n // *****************************************\n // doCheckLogin\n // *****************************************\n\n private var _sid:String;\n\n public function doCheckLogin():void\n {\n onTrace( \"******************* doCheckLogin ********************\" );\n\n var token:AsyncToken = _api.call( \"system.connect\" );\n var tresponder:ItemResponder = new ItemResponder(this.onCheckInfo,this.onCheckFault);\n token.addResponder(tresponder);\n\n }\n\n private function onCheckInfo (event:ResultEvent,token:Object = null):void\n {\n onTrace( \"got onCheckInfo\" );\n\n _user = event.result.user.name;\n _sid = event.result.user.sid;\n var roles:Object = event.result.user.roles;\n _loggedIn = false;\n for( var i:int=0; i<10; i++ )\n {\n var tmp:String = roles[i.toString()];\n if( tmp == \"authenticated user\" )\n _loggedIn = true;\n }\n\n trace( \"user = \" + _user + \", sid=\" + _sid + \", loggedIn=\" + _loggedIn );\n _firstCheckDone = true;\n\n _handleCheckResult( _loggedIn, _loggedIn?(\"Currently logged in as \" + _user):\"Not logged in yet\" );\n }\n\n private function onCheckFault (event:FaultEvent, token:Object=null):void\n {\n onTrace( \"got onCheckFault\" );\n\n _handleCheckResult( false, \"Fault: \" + event.fault.faultString + \" -- \" + event.fault.faultCode);\n }\n\n }\n}\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4540/"
] |
282,429 | <p>What happens if the browser receives a redirect response to an ajax request?</p>
| [
{
"answer_id": 282450,
"author": "jishi",
"author_id": 33663,
"author_profile": "https://Stackoverflow.com/users/33663",
"pm_score": 3,
"selected": false,
"text": "ajax-request"
},
{
"answer_id": 65227261,
"author": "kissu",
"author_id": 8816585,
"author_profile": "https://Stackoverflow.com/users/8816585",
"pm_score": 2,
"selected": false,
"text": "fetch"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282429",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7883/"
] |
282,444 | <p>Is it possible to detect, on the client side, whether the user is using an encrypted page or not?</p>
<p>Put another way -- I want to know if the URL of the current page starts with http or https.</p>
| [
{
"answer_id": 282454,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 7,
"selected": true,
"text": "window.location.protocol"
},
{
"answer_id": 2473245,
"author": "Rod",
"author_id": 163882,
"author_profile": "https://Stackoverflow.com/users/163882",
"pm_score": 4,
"selected": false,
"text": "if (\"https:\" == document.location.protocol) {\n /* secure */\n} else {\n /* unsecure */\n}\n"
},
{
"answer_id": 52011220,
"author": "Chris Zalcman",
"author_id": 10271298,
"author_profile": "https://Stackoverflow.com/users/10271298",
"pm_score": 2,
"selected": false,
"text": "var secure = window.isSecureContext;\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282444",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
282,448 | <p>I'm developing a SOAP application that integrates with a 3rd party. I think the WSDL of this third party is very strange. I'm pretty new to SOAP, so I don't want to go asking them to fix it if it isn't broken. Here's some things I've noticed that I consider wrong about it, though I'm sure it's technically a valid document (hence the reason I wrote "best practices" in the title). Also, I'm using gSOAP as my SOAP library, which may be why I think some of these things are weird (I'm even newer to gSOAP than I am to SOAP in general).</p>
<ol>
<li><p>they have interfaces specified for both SOAP 1.1 and SOAP 1.2 in the same WSDL. This causes gSOAP to generate twice as many classes as it needs to, since I'm only going to use 1.2.</p></li>
<li><p>all of their namespaces are <code>http://tempuri.org</code>. That shouldn't be like that, right?</p></li>
<li><p>despite defining a bunch of RPC calls, their WSDL uses the document format. I'm thinking of asking them to switch to RPC format because it seems that gSOAP won't generate methods that take C++ typed parameters for document format. Instead, it creates a new class for every API function's input and response data. I'll have to write another layer of wrapping around the gSOAP stuff to provide a reasonable API to the rest of my app if I can't fix that. Also, AFAICT, the XML that will be going back and forth would be exactly the same as it is now if they switched to RPC, so I don't think it would be difficult.</p></li>
<li><p>elements have minOccurs = 0 yet when I submit requests without them, I get errors returned back indicating they're required (sometimes even stack traces of null pointer exceptions). They should specify them as minOccurs = 1 if they're required, right?</p></li>
<li><p>nearly all of the web service functions specify a response that includes an integer to indicate success (really a boolean) and an error message string. Should they be using SOAP faults for this? I think it would be easier for my application to handle if it was a fault since gSOAP will let me figure that out really easily (and print the error message trivially).</p></li>
</ol>
<p>Of course, I don't have high hopes that this 3rd party company will change their WSDL just because I've asked them to. At least I'll learn something... for all I know, none of these are wrong or even questionable. Thanks for your help.</p>
| [
{
"answer_id": 5268619,
"author": "chenhong ",
"author_id": 654676,
"author_profile": "https://Stackoverflow.com/users/654676",
"pm_score": 1,
"selected": false,
"text": "typedef double xsd_double;\nint ns__add(xsd_double a, xsd_double b, xsd_double &result);\nint ns__sub(xsd_double a, xsd_double b, xsd_double &result);\nint myns__sqrt(xsd_double a, xsd_double &result);\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282448",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10861/"
] |
282,451 | <p>I have a .net transaction with a SQL insert to a SQL Server 2005 database. The table has an identity primary key. </p>
<p>When an error occurs within the transaction, <code>Rollback()</code> is called. The row inserts are rolled back correctly, however the next time I insert data to the table, the identity is incremented as if the rollback never occurred. So essentially there are gaps in the identity sequence. Is there any way to have the <code>Rollback()</code> method reclaim the missing identity? </p>
<p>Am I not approaching this the right way?</p>
| [
{
"answer_id": 282495,
"author": "Jason Jackson",
"author_id": 13103,
"author_profile": "https://Stackoverflow.com/users/13103",
"pm_score": 8,
"selected": true,
"text": "User 1\n------------\nbegin transaction\ninsert into A ...\ninsert into B ...\nupdate C ...\ninsert into D ...\ncommit\n\n\nUser 2\n-----------\nbegin transaction\ninsert into A ...\ninsert into B ...\ncommit\n"
},
{
"answer_id": 282510,
"author": "Brian",
"author_id": 700,
"author_profile": "https://Stackoverflow.com/users/700",
"pm_score": 1,
"selected": false,
"text": "PRAGMA AUTONOMOUS_TRANSACTION;' \n"
},
{
"answer_id": 282569,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 4,
"selected": false,
"text": "DELETE"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282451",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19763/"
] |
282,457 | <p>I am working on a small project to take a CSV file and then insert its data into a HTML table (I would use datagrid and dataset or datatable, but the system I will be talking to does not support ASP.NET uploads for sending newsletters).</p>
<p>Anyway, I will use the file.readalllines method to return the contents of the csv file into a string array.</p>
<p>But for each string member of the array, I will be using the string.split function to split up the string into the char array. Problem is (and the csv file is generated by the system I talk to btw - I get data from this system and feed data into it), the csv contents are makes of cars. This means that I could have:</p>
<p>Nissan Almera</p>
<p>Nissan Almera 1.4 TDi</p>
<p>VW Golf 1.9 SE</p>
<p>And so forth...</p>
<p>Is there a robust way I could ensure that where I have Almera 1.4 TDi, for example, it is one member in the char array I split each string into, rather than seperate members.</p>
| [
{
"answer_id": 282488,
"author": "Gary Willoughby",
"author_id": 13227,
"author_profile": "https://Stackoverflow.com/users/13227",
"pm_score": -1,
"selected": false,
"text": "String.Split(Convert.ToChar(\",\"));\n"
},
{
"answer_id": 282497,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 2,
"selected": false,
"text": "string.Split()"
},
{
"answer_id": 282625,
"author": "Robert Paulson",
"author_id": 14033,
"author_profile": "https://Stackoverflow.com/users/14033",
"pm_score": 0,
"selected": false,
"text": "regex csv"
},
{
"answer_id": 282764,
"author": "richardtallent",
"author_id": 16306,
"author_profile": "https://Stackoverflow.com/users/16306",
"pm_score": 0,
"selected": false,
"text": "int numFields = 4;\nstring[] myFields = myLine.Split(' ');\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282457",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32484/"
] |
282,459 | <p>I know of <code>is</code> and <code>as</code> for <code>instanceof</code>, but what about the reflective <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html#isInstance(java.lang.Object)" rel="noreferrer">isInstance()</a> method?</p>
| [
{
"answer_id": 282469,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 7,
"selected": true,
"text": "obj.getClass().isInstance(otherObj)"
},
{
"answer_id": 282685,
"author": "CodingWithSpike",
"author_id": 28278,
"author_profile": "https://Stackoverflow.com/users/28278",
"pm_score": 2,
"selected": false,
"text": "bool result = ((obj as MyClass) != null)\n"
},
{
"answer_id": 283111,
"author": "Ana Betts",
"author_id": 5728,
"author_profile": "https://Stackoverflow.com/users/5728",
"pm_score": 8,
"selected": false,
"text": "bool result = (obj is MyClass); // Better than using 'as'\n"
},
{
"answer_id": 283122,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": "is"
},
{
"answer_id": 34493891,
"author": "Youngjae",
"author_id": 361100,
"author_profile": "https://Stackoverflow.com/users/361100",
"pm_score": 2,
"selected": false,
"text": "IsAssignableFrom"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282459",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36744/"
] |
282,460 | <p>How can I determine current version of my repository to see if I need to upgrade it (svnadmin upgrade)?</p>
<p>In reality I'm hosting SVN with 3rd party and I want to find out if I need to ask them to upgrade my repos or not.</p>
<p>I'm asking since 1.5 server will keep repo version at 1.4, unless I miss something?</p>
| [
{
"answer_id": 282484,
"author": "bdumitriu",
"author_id": 35415,
"author_profile": "https://Stackoverflow.com/users/35415",
"pm_score": 6,
"selected": false,
"text": "<REPO>/db/format"
},
{
"answer_id": 282496,
"author": "Ken Gentle",
"author_id": 8709,
"author_profile": "https://Stackoverflow.com/users/8709",
"pm_score": 5,
"selected": false,
"text": "http"
},
{
"answer_id": 44720766,
"author": "user7457877",
"author_id": 7457877,
"author_profile": "https://Stackoverflow.com/users/7457877",
"pm_score": 3,
"selected": false,
"text": "SUBVERSION VERSION NUMBER SCHEMA VERSION\n------------------------- --------------\nUp to and including 0.27 1\n0.28 - 0.33.1 2\n0.34 - 1.3 3\n(no released version used this) 4\n1.4 - 5\n"
},
{
"answer_id": 60815542,
"author": "bahrep",
"author_id": 761095,
"author_profile": "https://Stackoverflow.com/users/761095",
"pm_score": 0,
"selected": false,
"text": "Get-SvnRepository MyRepo | Format-List"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282460",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19124/"
] |
282,468 | <p>The following C# code takes 5 minutes to run:</p>
<pre><code>int i = 1;
string fraction = "";
while (fraction.Length < 1000000)
{
fraction += i.ToString();
i++;
}
</code></pre>
<p>"Optimising it" like this causes it to run in 1.5 seconds:</p>
<pre><code>int i = 1;
string fraction = "";
while (fraction.Length < 1000000)
{
// concatenating strings is much faster for small strings
string tmp = "";
for (int j = 0; j < 1000; j++)
{
tmp += i.ToString();
i++;
}
fraction += tmp;
}
</code></pre>
<p><strong>EDIT:</strong> Some people suggested using <code>StringBuilder</code>, which is an excellent suggestion also, and this comes out at 0.06s:</p>
<pre><code>int i = 1;
StringBuilder fraction = new StringBuilder();
while (fraction.Length < 1000000)
{
fraction.Append(i);
i++;
}
</code></pre>
<p>Playing around to find the optimum value of <code>j</code> is a topic for another time, but why exactly does this non-obvious optimisation work so well? Also, on a related topic, I've heard it said that you should never use the <code>+</code> operator with strings, in favour of <code>string.Format()</code>, is this true?</p>
| [
{
"answer_id": 282476,
"author": "Mitch Wheat",
"author_id": 16076,
"author_profile": "https://Stackoverflow.com/users/16076",
"pm_score": 3,
"selected": false,
"text": "StringBuilder"
},
{
"answer_id": 282477,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 2,
"selected": false,
"text": "Format"
},
{
"answer_id": 282480,
"author": "Zote",
"author_id": 20683,
"author_profile": "https://Stackoverflow.com/users/20683",
"pm_score": 2,
"selected": false,
"text": "int i = 1;\n StringBuilder fraction = new StringBuilder();\n while (fraction.Length < 1000000)\n {\n fraction.Append(i);\n i++;\n }\nreturn sb.ToString();\n"
},
{
"answer_id": 282525,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": false,
"text": "using System;\nusing System.Diagnostics;\nusing System.Text;\n\npublic class Test\n{\n const int Limit = 4000000;\n\n static void Main()\n {\n Time(Concatenation, \"Concat\");\n Time(SimpleStringBuilder, \"StringBuilder as in post\");\n Time(SimpleStringBuilderNoToString, \"StringBuilder calling Append(i)\");\n Time(CapacityStringBuilder, \"StringBuilder with appropriate capacity\");\n }\n\n static void Time(Action action, string name)\n {\n Stopwatch sw = Stopwatch.StartNew();\n action();\n sw.Stop();\n Console.WriteLine(\"{0}: {1}ms\", name, sw.ElapsedMilliseconds);\n GC.Collect();\n GC.WaitForPendingFinalizers();\n }\n\n static void Concatenation()\n {\n int i = 1;\n string fraction = \"\";\n while (fraction.Length < Limit)\n {\n // concatenating strings is much faster for small strings\n string tmp = \"\";\n for (int j = 0; j < 1000; j++)\n {\n tmp += i.ToString();\n i++;\n }\n fraction += tmp; \n }\n }\n\n static void SimpleStringBuilder()\n {\n int i = 1;\n StringBuilder fraction = new StringBuilder();\n while (fraction.Length < Limit)\n {\n fraction.Append(i.ToString());\n i++;\n }\n }\n\n static void SimpleStringBuilderNoToString()\n {\n int i = 1;\n StringBuilder fraction = new StringBuilder();\n while (fraction.Length < Limit)\n {\n fraction.Append(i);\n i++;\n }\n }\n\n static void CapacityStringBuilder()\n {\n int i = 1;\n StringBuilder fraction = new StringBuilder(Limit + 10);\n while (fraction.Length < Limit)\n {\n fraction.Append(i);\n i++;\n }\n }\n}\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282468",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15537/"
] |
282,475 | <p>Consider the following trivial HTML page that throws an error:</p>
<pre><code><html><head><script>
throw new Error('oops');
alert('should not reach here');
</script></head></html>
</code></pre>
<p>The user I am logged into Vista with is a member of both the Administrators and Debugger Users groups.</p>
<p>If I run Internet Explorer on Vista as an administrator (right click → <strong>Run as administrator</strong>) and load the page I get the following error prompt:</p>
<p><a href="https://i.stack.imgur.com/pIdR1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pIdR1.png" alt="alt text"></a></p>
<p>Clicking Yes displays the following prompt from which I can successfully open Visual Studio 2008 and debug the problem:</p>
<p><a href="http://img227.imageshack.us/img227/9751/debuguy3.png" rel="nofollow noreferrer">alt text http://img227.imageshack.us/img227/9751/debuguy3.png</a></p>
<p>If I instead launch Internet Explorer normally and load the page no error prompt is displayed (or any indication of the error for that matter) and I can't jump in and debug the problem.</p>
<p>I've tried making the site the page is served from a trusted site in Internet Explorer. This causes the error prompt to be displayed for the page, but clicking yes doesn't do anything and the browser just sits and hangs.</p>
<p>Similarly I can only successfully attach to an existing Internet Explorer process from Visual Studio to debug JavaScript if Internet Explorer was run as an administrator.</p>
<p><strong>How can I successfully debug JavaScript with Visual Studio when running Internet Explorer with UAC enabled?</strong></p>
| [
{
"answer_id": 282476,
"author": "Mitch Wheat",
"author_id": 16076,
"author_profile": "https://Stackoverflow.com/users/16076",
"pm_score": 3,
"selected": false,
"text": "StringBuilder"
},
{
"answer_id": 282477,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 2,
"selected": false,
"text": "Format"
},
{
"answer_id": 282480,
"author": "Zote",
"author_id": 20683,
"author_profile": "https://Stackoverflow.com/users/20683",
"pm_score": 2,
"selected": false,
"text": "int i = 1;\n StringBuilder fraction = new StringBuilder();\n while (fraction.Length < 1000000)\n {\n fraction.Append(i);\n i++;\n }\nreturn sb.ToString();\n"
},
{
"answer_id": 282525,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": false,
"text": "using System;\nusing System.Diagnostics;\nusing System.Text;\n\npublic class Test\n{\n const int Limit = 4000000;\n\n static void Main()\n {\n Time(Concatenation, \"Concat\");\n Time(SimpleStringBuilder, \"StringBuilder as in post\");\n Time(SimpleStringBuilderNoToString, \"StringBuilder calling Append(i)\");\n Time(CapacityStringBuilder, \"StringBuilder with appropriate capacity\");\n }\n\n static void Time(Action action, string name)\n {\n Stopwatch sw = Stopwatch.StartNew();\n action();\n sw.Stop();\n Console.WriteLine(\"{0}: {1}ms\", name, sw.ElapsedMilliseconds);\n GC.Collect();\n GC.WaitForPendingFinalizers();\n }\n\n static void Concatenation()\n {\n int i = 1;\n string fraction = \"\";\n while (fraction.Length < Limit)\n {\n // concatenating strings is much faster for small strings\n string tmp = \"\";\n for (int j = 0; j < 1000; j++)\n {\n tmp += i.ToString();\n i++;\n }\n fraction += tmp; \n }\n }\n\n static void SimpleStringBuilder()\n {\n int i = 1;\n StringBuilder fraction = new StringBuilder();\n while (fraction.Length < Limit)\n {\n fraction.Append(i.ToString());\n i++;\n }\n }\n\n static void SimpleStringBuilderNoToString()\n {\n int i = 1;\n StringBuilder fraction = new StringBuilder();\n while (fraction.Length < Limit)\n {\n fraction.Append(i);\n i++;\n }\n }\n\n static void CapacityStringBuilder()\n {\n int i = 1;\n StringBuilder fraction = new StringBuilder(Limit + 10);\n while (fraction.Length < Limit)\n {\n fraction.Append(i);\n i++;\n }\n }\n}\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282475",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2766/"
] |
282,489 | <p>What is a good way to set up a single container div with some border images surrounding it (in my case only on the left, bottom, and right sides)? I have it centered at the top of the page, overlapping everything else (so like that OSX-style slide-down dialog).</p>
<p>Here's the basic layout:</p>
<p><img src="https://i.stack.imgur.com/HoGAj.jpg" alt="alt text"></p>
<p>Here's what I've got so far (can I avoid a static width/height for the content?):</p>
<p><strong>HTML:</strong></p>
<pre><code><div class="contentbox">
<div class="contentbox-wrapper" style="width: 400px">
<div class="contentbox-mid" style="height: 200px">
<div class="contentbox-w"></div>
<div class="contentbox-content">
Content Box Test
</div>
<div class="contentbox-e"></div>
</div>
<div class="contentbox-bottom">
<div class="contentbox-sw"></div>
<div class="contentbox-s"></div>
<div class="contentbox-se"></div>
</div>
</div>
</div>
</code></pre>
<p><strong>CSS:</strong></p>
<pre><code>.contentbox {
width: 100%;
position: fixed;
z-index: 2;
}
.contentbox-wrapper {
width: 300px;
margin-left: auto;
margin-right: auto;
}
.contentbox-mid {
height: 100px;
}
.contentbox-w {
width: 30px;
height: 100%;
background: transparent url("../../images/contentbox_w.png");
float: left;
}
.contentbox-content {
width: auto;
height: 100%;
background: #e8e8e8;
float: left;
}
.contentbox-e {
width: 30px;
height: 100%;
background: transparent url("../../images/contentbox_e.png");
float: left;
}
.contentbox-bottom {
width: 300px;
height: 30px;
}
.contentbox-sw {
width: 30px;
height: 30px;
background: transparent url("../../images/contentbox_sw.png");
float: left;
}
.contentbox-s {
height: 30px;
background: transparent url("../../images/contentbox_s.png");
margin-left: 30px;
margin-right: 30px;
}
.contentbox-se {
width: 30px;
height: 30px;
background: transparent url("../../images/contentbox_se.png");
float: right;
position: relative;
bottom: 30px;
}
</code></pre>
| [
{
"answer_id": 282476,
"author": "Mitch Wheat",
"author_id": 16076,
"author_profile": "https://Stackoverflow.com/users/16076",
"pm_score": 3,
"selected": false,
"text": "StringBuilder"
},
{
"answer_id": 282477,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 2,
"selected": false,
"text": "Format"
},
{
"answer_id": 282480,
"author": "Zote",
"author_id": 20683,
"author_profile": "https://Stackoverflow.com/users/20683",
"pm_score": 2,
"selected": false,
"text": "int i = 1;\n StringBuilder fraction = new StringBuilder();\n while (fraction.Length < 1000000)\n {\n fraction.Append(i);\n i++;\n }\nreturn sb.ToString();\n"
},
{
"answer_id": 282525,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": false,
"text": "using System;\nusing System.Diagnostics;\nusing System.Text;\n\npublic class Test\n{\n const int Limit = 4000000;\n\n static void Main()\n {\n Time(Concatenation, \"Concat\");\n Time(SimpleStringBuilder, \"StringBuilder as in post\");\n Time(SimpleStringBuilderNoToString, \"StringBuilder calling Append(i)\");\n Time(CapacityStringBuilder, \"StringBuilder with appropriate capacity\");\n }\n\n static void Time(Action action, string name)\n {\n Stopwatch sw = Stopwatch.StartNew();\n action();\n sw.Stop();\n Console.WriteLine(\"{0}: {1}ms\", name, sw.ElapsedMilliseconds);\n GC.Collect();\n GC.WaitForPendingFinalizers();\n }\n\n static void Concatenation()\n {\n int i = 1;\n string fraction = \"\";\n while (fraction.Length < Limit)\n {\n // concatenating strings is much faster for small strings\n string tmp = \"\";\n for (int j = 0; j < 1000; j++)\n {\n tmp += i.ToString();\n i++;\n }\n fraction += tmp; \n }\n }\n\n static void SimpleStringBuilder()\n {\n int i = 1;\n StringBuilder fraction = new StringBuilder();\n while (fraction.Length < Limit)\n {\n fraction.Append(i.ToString());\n i++;\n }\n }\n\n static void SimpleStringBuilderNoToString()\n {\n int i = 1;\n StringBuilder fraction = new StringBuilder();\n while (fraction.Length < Limit)\n {\n fraction.Append(i);\n i++;\n }\n }\n\n static void CapacityStringBuilder()\n {\n int i = 1;\n StringBuilder fraction = new StringBuilder(Limit + 10);\n while (fraction.Length < Limit)\n {\n fraction.Append(i);\n i++;\n }\n }\n}\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282489",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5291/"
] |
282,499 | <p>Does this pattern:</p>
<pre><code>setTimeout(function(){
// do stuff
}, 0);
</code></pre>
<p>Actually return control to the UI from within a loop? When are you supposed to use it? Does it work equally well in all browsers?</p>
| [
{
"answer_id": 282544,
"author": "Kornel",
"author_id": 27009,
"author_profile": "https://Stackoverflow.com/users/27009",
"pm_score": 3,
"selected": true,
"text": "<script>"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282499",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1169746/"
] |
282,503 | <p>The <code>PropertyGrid</code> control is very useful for editing objects at run-time. I'm using it as follows:</p>
<pre><code>Form form = new Form();
form.Parent = this;
form.Text = "Editing MyMemberVariable";
PropertyGrid p = new PropertyGrid();
p.Parent = form;
p.Dock = DockStyle.Fill;
p.SelectedObject = _MyMemberVariable;
p.PropertyValueChanged += delegate(object s, PropertyValueChangedEventArgs args)
{
_MyMemberVariable.Invalidate();
};
form.Show();
</code></pre>
<p>As you can see, I'm using the <code>PropertyValueChanged</code> notification to figure out when to update <code>_MyMemberVariable</code>. However, <code>_MyMemberVariable</code> is a class that I didn't write, and one of its members is a <code>Collection</code> type. The <code>PropertyGrid</code> calls the Collection Editor to edit this type. However, when the Collection Editor is closed, I do not get a <code>PropertyValueChanged</code> notification.</p>
<p>Obviously, I could work around this problem by using <code>ShowDialog()</code> and invalidating <code>_MyMemberVariable</code> after the dialog is closed. </p>
<p>But I'd like to actually get <code>PropertyValueChanged</code> events to fire when collections have been edited. Is there a way to do that without modifying <code>_MyMemberVariable</code> (I don't have access to its source code)? </p>
| [
{
"answer_id": 282863,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "//designer code excluded\npublic partial class Form1 : Form\n{\n public Form1()\n {\n InitializeComponent();\n\n propertyGrid1.SelectedObject = listBox1;\n\n propertyGrid1.PropertyValueChanged += delegate(object s, PropertyValueChangedEventArgs args)\n {\n MessageBox.Show(\"Invalidate Me!\");\n };\n\n }\n}\n"
},
{
"answer_id": 18075711,
"author": "mkaj",
"author_id": 765326,
"author_profile": "https://Stackoverflow.com/users/765326",
"pm_score": 3,
"selected": true,
"text": "propertyGrid1.PropertyValueChanged += (o, args) => PropertyGridValueChanged();\npropertyGrid1.LostFocus += (sender, args) => PropertyGridValueChanged();\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282503",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2683/"
] |
282,522 | <p>In Ant is there any way to do something like this:</p>
<pre><code><arguments id="arg-list">
<arg value="arg1" />
<arg value="arg2" />
</arguments>
<property name="prop1" refid="arg-list" />
</code></pre>
<p>I'm trying to write a macro for psexec and I'm looking for a nice way to pass in the argument list.</p>
<p>I know that you can do something similar with classpaths...</p>
<p>Thanks!</p>
| [
{
"answer_id": 282583,
"author": "Richard A",
"author_id": 24355,
"author_profile": "https://Stackoverflow.com/users/24355",
"pm_score": 4,
"selected": true,
"text": "<macrodef name=\"example\">\n <attribute name=\"args\"/>\n <sequential>\n <exec executable=\"example.exe\">\n <arg value=\"somearg\" />\n <arg line=\"@{args}\"/>\n </exec>\n </sequential>\n</macrodef>\n\n<example args=\"somearg arg1 arg2\"/>\n"
},
{
"answer_id": 8312201,
"author": "Jean-Rémy Revy",
"author_id": 1047365,
"author_profile": "https://Stackoverflow.com/users/1047365",
"pm_score": 0,
"selected": false,
"text": "<find ... delimiter=\"\"/> ... </find>"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282522",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18437/"
] |
282,526 | <p>I've noticed, using visual studio 2003, that I can "comment out" my comments to make them no longer be comments. This one needs an example:</p>
<p>If I have:</p>
<pre><code>/*
int commented_out = 0;
*/
</code></pre>
<p>I can comment out the /* and */ with // and code within the /* and */ is no longer "commented out" (the text changes to non-comment color <strong>and</strong> the compiler treats it as code once again). Like so:</p>
<pre><code>///*
int commented_out = 0;
//*/
</code></pre>
<p>I've found this is true for msvc 2003, is this normal C++ behavior or is it just a fluke that works with this compiler?</p>
| [
{
"answer_id": 282533,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 3,
"selected": false,
"text": "//"
},
{
"answer_id": 282553,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 5,
"selected": true,
"text": "/*"
},
{
"answer_id": 699565,
"author": "GameFreak",
"author_id": 26659,
"author_profile": "https://Stackoverflow.com/users/26659",
"pm_score": 1,
"selected": false,
"text": "/*\nint foo = 0;\n/*/\nint foo = 1;\n//*/\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282526",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29703/"
] |
282,531 | <p>I'm looking for a .NET library that will allow creation of a Word document. I need to export HTML based content to a Word doc (97-2003 format, not docx).</p>
<p>I know that there are the Microsoft Office Automation libraries and Office interop, but as far as I can tell, they require that you have office actually installed and they do the conversion by opening word itself. But I don't want to have the requirement of having office installed for the conversion to work.</p>
<p>Edit: Converting to RTF may even work, if possible.</p>
| [
{
"answer_id": 283932,
"author": "Fionnuala",
"author_id": 2548,
"author_profile": "https://Stackoverflow.com/users/2548",
"pm_score": 4,
"selected": true,
"text": "<html>\n<head>\n<STYLE type=\"text/css\">\n h1 {text-align:center; font-size:12.0pt; font-family:Arial; font-weight:bold;}\n\n p {margin:0in; margin-bottom:0pt; font-size: 10.0pt;font-family: Arial;}\n p.Address {text-align:center;font-family:Times; margin-bottom: 10px;}\n</style></head>\n<body>\n<p class=\"Address\">The Street</p>\n<h1>Head</h1>\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/194/"
] |
282,539 | <p>I was wondering if there is a way to implement an action listener for a Jbutton without a name. For example, I have the following for loop that creates a button for each letter of the alphabet.</p>
<pre><code>for (int i = 65; i < 91; i++){
alphabetPanel.add(new JButton("<html><center>" + (char)i));
}
</code></pre>
<p>Is there a way that I can add an action listener for each of those buttons without getting rid of my for loop and hard coding each JButton and then creating an action listener for each? </p>
<p>Thanks in advance,</p>
<p>Tomek</p>
| [
{
"answer_id": 282558,
"author": "John Gardner",
"author_id": 13687,
"author_profile": "https://Stackoverflow.com/users/13687",
"pm_score": 3,
"selected": true,
"text": "ActionListener listener = something;\n\nfor (int i = 65; i < 91; i++){\n JButton button = new JButton(\"<html><center>\" + (char)i);\n button.addActionListener( listener );\n alphabetPanel.add(button);\n}\n"
},
{
"answer_id": 282563,
"author": "bruno conde",
"author_id": 31136,
"author_profile": "https://Stackoverflow.com/users/31136",
"pm_score": 2,
"selected": false,
"text": "for (int i = 65; i < 91; i++){\n JButton button = new JButton(\"<html><center>\" + (char)i));\n button.addActionListener( new ButtonListener());\n alphabetPanel.add(button);\n}\n"
},
{
"answer_id": 282871,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "new JButton().addActionListener(new ActionListener(){\n @Override\n public void actionPerformed(ActionEvent arg0) {\n // TODO your action \n } \n });\n"
},
{
"answer_id": 284095,
"author": "Tom Hawtin - tackline",
"author_id": 4725,
"author_profile": "https://Stackoverflow.com/users/4725",
"pm_score": 1,
"selected": false,
"text": "alphabetPanel.add(new JButton(\"<html><center>\" + (char)i) {{\n addActionListener(new ActionListener() {\n public void actionPerformed(ActionEvent event) {\n ...\n }\n });\n}});\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282539",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29326/"
] |
282,545 | <p>I'm writing my first Windows CE app using the .NET Compact Framework v3.5.<br>
I need the app to be able to do an HTTP POST to a URL.<br>
It appears that the .NET CF does not have System.Web.<br>
So, I could use some guidence on how to accomplish and HTTP Posts using the .Net CF.
Thanks,
Greg</p>
| [
{
"answer_id": 282749,
"author": "Craig Norton",
"author_id": 24804,
"author_profile": "https://Stackoverflow.com/users/24804",
"pm_score": 2,
"selected": true,
"text": "Try\n Dim Request As HttpWebRequest = CType(WebRequest.Create(\"<The server>\"), HttpWebRequest)\n\n Request.AllowWriteStreamBuffering = True\n Request.KeepAlive = False\n Request.Credentials = CredentialCache.DefaultCredentials\n Request.ContentType = \"text/html\"\n Request.Method = \"POST\"\n\n 'If required\n 'Dim proxyURI As New Uri(\"193.129.241.46\", UriKind.Absolute)\n 'Dim webProxy As New WebProxy\n 'webProxy.Address = proxyURI\n 'webProxy.Credentials = New NetworkCredential(\"\", \"\")\n 'Request.Proxy = webProxy\n\n Dim requestStream As Stream = Request.GetRequestStream\n Dim Writer As New IO.BinaryWriter(requestStream)\n Writer.Close()\n\n Dim Reader As New BinaryReader(Request.GetResponse.GetResponseStream)\n Reader.Close()\nCatch ex As Exception\n Throw ex\nEnd Try\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282545",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23823/"
] |
282,570 | <p>Simple question, hopefully an easy way and just want to verify I'm doing it the correct / efficient way.</p>
<p>I have a class T object, which is typically put into a vector that is created in my main() function. It can be any kind of data, string, int, float.. etc. I'm reading from a file... which is inputted from the user and passed onto the function. Here is my basic read in function:</p>
<pre><code>template <class T, class U>
void get_list(vector<T>& v, const char *inputFile, U)
{
ifstream myFile;
T object;
myFile.open("inputFile")
while(!myFile.eof())
{
myFile >> object;
insert(v, object, U)
}
}
</code></pre>
<p>insert is just another function that will go through and insert the data into my data structure. I just want to make sure this is the best way to pass that data on if it will even work.</p>
| [
{
"answer_id": 282596,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 1,
"selected": false,
"text": ".eof()"
},
{
"answer_id": 282598,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 2,
"selected": false,
"text": "template <class T, class U>\nvoid get_list(vector<T>& v, const char *inputFile, U)\n{\n ifstream myFile(\"inputFile\"); // Why hard code this?\n // When you pass inputFile as a parameter? \n T object;\n\n\n while(myFile >> object) // Get the object here.\n // If it fails because of eof() or other\n // It will not get inserted.\n {\n insert(v, object, U)\n }\n}\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282570",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28392/"
] |
282,571 | <p>I'm trying to design a homepage for an MVC site that has two different views, based on if the user is logged in or not.</p>
<p>So image the default (not logged in) view is showing general, nonspecific info. If i'm logged in, the view is showing mostly personal stuff instead.</p>
<p>What's the best practice to handling this? Don't forget, we also need to unit test this.</p>
<p>Thanks heaps!</p>
| [
{
"answer_id": 282585,
"author": "Adrian Clark",
"author_id": 148,
"author_profile": "https://Stackoverflow.com/users/148",
"pm_score": 5,
"selected": true,
"text": "public ActionResult Index()\n\n If (User.IsLoggedOn)\n {\n // Do user-specific controller stuff here...\n\n return View(\"LoggedOnIndex\");\n }\n else\n {\n // Do anon controller stuff here...\n\n return View(\"AnonymousIndex\");\n }\n"
},
{
"answer_id": 679080,
"author": "taelor",
"author_id": 78404,
"author_profile": "https://Stackoverflow.com/users/78404",
"pm_score": 2,
"selected": false,
"text": "User.IsloggedOn"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282571",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30674/"
] |
282,575 | <p>I have a system which sits on a web server and generates files on the fly in response to HTTP requests. This is currently implemented as an HTTPHandler.</p>
<p>Once the files are generated, they don't change very often, so I'd like to implement a cache.</p>
<p>Ideally, I'd like the web server to look at the cache folder and serve the files directly from there without <strong>any</strong> of my code having to execute (web servers are designed to be good at serving files after all, so if I can keep out of the way of that so much the better!).</p>
<p>What I'd like to then do is hook into the server's "file not found" event as an opportunity to create the file, drop a copy in the cache folder for the next time it's requested and also return it to the user instead of the "file not found" message.</p>
<p>This way, repeat requests for files will be lightening fast and my code will only get called in 'exceptional' cases.</p>
<p>So - the question is - how do I wire my code into the "file not found" event in as unobtrusive and lightweight way as possible?</p>
<p>Thanks</p>
| [
{
"answer_id": 282617,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 1,
"selected": false,
"text": "<customErrors mode=\"On\">\n <error statusCode=\"404\" redirect=\"FileGeneratorHandler.ashx\" />\n</customErrors>\n"
},
{
"answer_id": 282620,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 3,
"selected": true,
"text": "http://yourdomain.com/yourhandler.ashx;originally/requested/url\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282575",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/475/"
] |
282,576 | <p>How does one do namespaced controllers in Merb, for instance to create an admin section to the site? In Rails one would use Admin::CategoriesController, is this similar in Merb or is this another recommended way of doing it?</p>
| [
{
"answer_id": 283197,
"author": "Laz",
"author_id": 34991,
"author_profile": "https://Stackoverflow.com/users/34991",
"pm_score": 3,
"selected": true,
"text": "namespace :admin do\n resources :categories\nend\n"
},
{
"answer_id": 476571,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<%= link_to(\"Categories Admin\", resource(:admin, :categories) %>\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/282576",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34991/"
] |
282,600 | <p>For large <code>n</code> (see below for how to determine what's large enough), it's safe to treat, by the central limit theorem, the distribution of the sample mean as normal (gaussian) but I'd like a procedure that gives a confidence interval for any <code>n</code>. The way to do that is to use a Student T distribution with <code>n-1</code> degrees of freedom.</p>
<p>So the question is, given a stream of data points that you collect or encounter one at a time, how do you compute a <code>c</code> (eg, <code>c=.95</code>) confidence interval on the mean of the data points (without storing all of the previously encountered data)?</p>
<p>Another way to ask this is: How do you keep track of the first and second moments for a stream of data without storing the whole stream?</p>
<p>BONUS QUESTION: Can you keep track of higher moments without storing the whole stream?</p>
| [
{
"answer_id": 282634,
"author": "John D. Cook",
"author_id": 25188,
"author_profile": "https://Stackoverflow.com/users/25188",
"pm_score": 3,
"selected": false,
"text": "[mean - 1.96*stdev, mean + 1.96*stdev]"
},
{
"answer_id": 282639,
"author": "David Nehme",
"author_id": 14167,
"author_profile": "https://Stackoverflow.com/users/14167",
"pm_score": 2,
"selected": false,
"text": " sigma = sqrt( (q - (s*s/n)) / (n-1) )\n delta = t(1-c/2,n-1) * sigma / sqrt(n)\n"
},
{
"answer_id": 283167,
"author": "dreeves",
"author_id": 4234,
"author_profile": "https://Stackoverflow.com/users/4234",
"pm_score": 3,
"selected": true,
"text": "n = u = s = 0"
},
{
"answer_id": 2209251,
"author": "George Dontas",
"author_id": 170792,
"author_profile": "https://Stackoverflow.com/users/170792",
"pm_score": 1,
"selected": false,
"text": "n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282600",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4234/"
] |
282,603 | <p>I'm using a logging module that can have reporting enabled/disabled at runtime. Calls generally go something like:</p>
<pre><code>WARN(
"Danger Will Robinson! There are "
+ boost::lexical_cast<string>(minutes)
+ " minutes of oxygen left!"
);
</code></pre>
<p>I'm using an inline function for WARN, but I'm curious as to how much optimization is going on behind the scenes -- evaluation of the arguments throughout the entire program would be costly. The <code>WARN</code> function goes something like this:</p>
<pre><code>bool WARNINGS_ENABLED = false;
inline void WARN(const string &message) {
if (!WARNINGS_ENABLED) {
return;
}
// ...
}
</code></pre>
<p>Given that constructing the string argument has no side-effects, will the compiler optimize it out? Is a certain level of optimization required (<code>-Ox</code> in <code>g++</code> for some <code>x</code>)?</p>
| [
{
"answer_id": 282611,
"author": "Mr Fooz",
"author_id": 25050,
"author_profile": "https://Stackoverflow.com/users/25050",
"pm_score": 1,
"selected": false,
"text": "inline void warnFunc(some_boost_lambda &message_generator) {\n if (WARNINGS_ENABLED) {\n cerr << message_generator() << endl;\n }\n}\n\n#define WARN(msg) warnFunc(...insert boost magic here to turn msg into a lambda...)\n"
},
{
"answer_id": 282635,
"author": "Benedikt Waldvogel",
"author_id": 4308,
"author_profile": "https://Stackoverflow.com/users/4308",
"pm_score": 3,
"selected": false,
"text": "char WARNINGS_ENABLED = 0;\n\ninline void WARN(const char* message) {\n if (!WARNINGS_ENABLED) {\n return;\n }\n puts(message);\n}\n\nint main() {\n WARN(\"foo\");\n return 0;\n}\n"
},
{
"answer_id": 282648,
"author": "Tom Leys",
"author_id": 11440,
"author_profile": "https://Stackoverflow.com/users/11440",
"pm_score": 0,
"selected": false,
"text": "void inline void LogWarning(const string &message) \n{\n //Warning\n}\n\n#ifdef WARNINGS_ENABLED\n#define WARN(a) LogWarning(a)\n#else\n#define WARN(a)\n#endif\n"
},
{
"answer_id": 282658,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 5,
"selected": true,
"text": "WARN2"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282603",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3594/"
] |
282,615 | <p>I'm a new to MSBuild and wanted to play around with it a bit, but I just cannot figure out why this isn't working.</p>
<p>So my solution has two projects: "Model" and "BuildTasks". BuildTasks just has a single class:</p>
<pre><code>using Microsoft.Build.Utilities;
namespace BuildTasks
{
public class Test : Task
{
public override bool Execute()
{
Log.LogMessage( "FASDfasdf" );
return true;
}
}
}
</code></pre>
<p>And then in the Model.csproj I've added this:</p>
<pre><code> <UsingTask TaskName="BuildTasks.Test" AssemblyFile="$(SolutionDir)src\BuildTasks\bin\BuildTasks.dll" />
<Target Name="AfterBuild">
<Test />
</Target>
</code></pre>
<p>I've set up the build order so "BuildTasks" gets built before "Model". But when I try to build Model I get this error:</p>
<blockquote>
<p>The "BuildTasks.Test" task could not
be loaded from the assembly
C:\WIP\TestSolution\src\BuildTasks\bin\BuildTasks.dll.
Could not load file or assembly
'file:///C:\WIP\TestSolution\src\BuildTasks\bin\BuildTasks.dll'
or one of its dependencies. The system
cannot find the file specified.
Confirm that the <UsingTask>
declaration is correct, and that the
assembly and all its dependencies are
available.</p>
</blockquote>
<p>This file definitely exists, so why can't MSBuild find it?</p>
<p>I've even tried hard-coding "C:\WIP\TestSolution" in place of "$(SolutionDir)" and get the same error. However, if I copy that .dll to my desktop and hard-code the path to my desktop, it <em>DOES</em> work, which I can't figure out why.</p>
<p><strong>EDIT</strong>: I don't have the path wrong. I modified the Debug/Release builds for BuildTasks to output the .dll to just the bin folder since I didn't want Debug/Release to have different paths.</p>
| [
{
"answer_id": 282626,
"author": "Aaron Powell",
"author_id": 11388,
"author_profile": "https://Stackoverflow.com/users/11388",
"pm_score": 0,
"selected": false,
"text": "bin\\Configuration Type\\BuildTasks.dll"
},
{
"answer_id": 282777,
"author": "Todd",
"author_id": 31940,
"author_profile": "https://Stackoverflow.com/users/31940",
"pm_score": 1,
"selected": false,
"text": "<UsingTask \n TaskName=\"BuildTasks.Test\" \n AssemblyFile=\"$(SolutionDir)src\\BuildTasks\\bin\\$(Configuration)\\BuildTasks.dll\" />\n\n<Target Name=\"AfterBuild\">\n <Test />\n</Target>\n"
},
{
"answer_id": 3208281,
"author": "Gareth Farrington",
"author_id": 2021,
"author_profile": "https://Stackoverflow.com/users/2021",
"pm_score": 4,
"selected": false,
"text": "<Target Name=\"AfterBuild\">\n <Exec Command=\"$(MSBuildBinPath)\\MSBuild.exe \n "$(MSBuildProjectDirectory)\\PostBuild.msbuild" \n /property:SomeProperty=$(SomeProperty)\" />\n</Target>\n"
},
{
"answer_id": 37343912,
"author": "user400144",
"author_id": 400144,
"author_profile": "https://Stackoverflow.com/users/400144",
"pm_score": 1,
"selected": false,
"text": "/nr:false"
},
{
"answer_id": 37344692,
"author": "user400144",
"author_id": 400144,
"author_profile": "https://Stackoverflow.com/users/400144",
"pm_score": 2,
"selected": false,
"text": "MSBUILDDISABLENODEREUSE = 1"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282615",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34715/"
] |
282,619 | <p>We have a My_list class that has a list of pointers to Abstract_things. To optimize on memory usage, all derived Things use one memory pool that is established with the "new and delete" stereotype. In order to size the pool properly during the initization of the application, the builder figures out which Thing is the biggest and sizes the pool based on that. </p>
<p>The design dilemma is that if a new Thing is added to the model, (represented with the red Thing_4), the designer has to know to go over to Builder to adjust the logic. I have observed that it was hard enough for our team to remember to do this (about half our Things weren’t considered in the Builder). I’m very concerned that future generations will overlook this.</p>
<p>My question is how can I improve this? It would be wonderful if in the act of creating a Thing_4 class, all that max_size stuff automagically got handled. I can’t think of a way though.</p>
<p>Note: Reviewing my picture I realize there's a mistake. The last line in the code-box should read Abstract_thing::set_max_pool_size(max_size, max_number).</p>
<p>Edit: I can't figure out how to display a picture. Everything looks good in the preview window, but when published it's not there. Any help?</p>
<p>Edit: To give a little bit more background, this is part of a design for an embedded application in a safety-critical system. We are allowed to allocate memory off the heap when the application is initializing, but after we exit that initialization phase, NO dynamic memory can be allocated. Attempting to do so crashes the application. Therefore, we program to the largest sizes and the maximum number of instances we use. Having one pool that contains enough space for all derived objects is the better approach over having a pool for each derived object.</p>
<p><a href="http://img262.imageshack.us/img262/4470/designproblemof1.png" rel="nofollow noreferrer">alt text http://img262.imageshack.us/img262/4470/designproblemof1.png</a></p>
| [
{
"answer_id": 282640,
"author": "Rob Walker",
"author_id": 3631,
"author_profile": "https://Stackoverflow.com/users/3631",
"pm_score": 2,
"selected": false,
"text": "template<class T>\nclass RegisterPoolClass\n{\npublic:\n RegisterPoolClass() { init_pool.Register(sizeof(T)); }\n};\n\nclass Thing_1 : public Abstract_Thing\n{\n static RegisterPoolClass<Thing_1> sInitializer;\n ...\n};\n\nRegisterPoolClass<Thing_1> Thing_1::sInitializer;\n"
},
{
"answer_id": 282642,
"author": "BCS",
"author_id": 1343,
"author_profile": "https://Stackoverflow.com/users/1343",
"pm_score": 0,
"selected": false,
"text": "echo '#include\"head\"' > out.cpp\ngrep \"class \\w+ : TheClass\" *.cpp | sed \"s/.*class \\(\\w\\)+ : TheClass.*/assert(sizeof($1) <= MAX_SIZE); >> out.cpp\necho '#include\"tail\"' >> out.cpp\ngcc out.cpp\n./a.out\n"
},
{
"answer_id": 282646,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 0,
"selected": false,
"text": "#ifndef ABSTRACT_THING\n#define ABSTRACT_THING\nclass AbstractThing\n{\nprivate:\n static size_t maxChildSize;\n static bool maxChildLock;\n static std::vector<type_info> validChildren;\n\n static size_t getMaxChildSize()\n {\n maxChildLock = true;\n return maxChildSize;\n }\npublic:\n template<typename T>\n static void setChildSize()\n {\n // This is to stop registering things after getMaxChildSize()\n // has been called. This check is only needed during testing\n if (maxChildLocked)\n {\n exit(1);\n }\n maxChildSize = std::max(maxChildSize,sizeof(T));\n validChildren.push_back(typeid T);\n }\n template<typename T>\n static bool testValidType()\n {\n // While testing call this method.\n // Don't call in production to speed things up.\n\n // Only registered children will be allowed to get memory.\n // Or maybe generate a warning in the log if it fails.\n return validChildren.find(typeid T) != validChildren.end();\n }\n};\ntemplate<typename T>\nclass RegisterAbsoluteThing\n{\npublic:\n RegisterAbsoluteThing()\n {\n AbstractThing::setChildSize<T>();\n }\n};\n#endif\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282619",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36756/"
] |
282,622 | <p>It seems that everybody knows you're supposed to have a clear distinction between the GUI, the business logic, and the data access. I recently talked to a programmer who bragged about always having a clean data access layer. I looked at this code, and it turns out his data access layer is just a small class wrapping a few SQL methods (like ExecuteNonQuery and ExecuteReader). It turns out that in his ASP.NET code behind pages, he has tons of SQL hard coded into the page_load and other events. But he swears he's using a data access layer.</p>
<p>So, I throw the question out. How would you define a data access layer?</p>
| [
{
"answer_id": 10088435,
"author": "AD - Stop Putin -",
"author_id": 494775,
"author_profile": "https://Stackoverflow.com/users/494775",
"pm_score": 0,
"selected": false,
"text": "DRO"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282622",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/681/"
] |
282,627 | <p>I'm attempting to utilize <a href="http://en.wikipedia.org/wiki/VBScript" rel="nofollow noreferrer">VBScript</a> to connect pull the <code>physicalDeliveryOfficeName</code> attribute in <a href="http://en.wikipedia.org/wiki/Active_Directory" rel="nofollow noreferrer">Active Directory</a> by providing the email address. </p>
<p>I know how to do it with a common name like the following:</p>
<pre><code>Set MyUser = GetObject ("LDAP://cn=" & uname & ",ou=" & strname & ",DC=bobdom,DC=net")
</code></pre>
<p>However only the email address is available. How to do this? I've even tried </p>
<pre><code>Set MyUser = GetObject ("LDAP://mail=" & uname & ",ou=" & strname & ",DC=bobdom,DC=net")
</code></pre>
<p>and that doesn't work. </p>
| [
{
"answer_id": 288873,
"author": "Otus",
"author_id": 36613,
"author_profile": "https://Stackoverflow.com/users/36613",
"pm_score": 2,
"selected": false,
"text": "<LDAP://SERVERNAME/DC=bobdom,DC=net>;(&(objectClass=user)(mail=mike.spencer@kenblanchard.com));\n"
},
{
"answer_id": 309598,
"author": "phill",
"author_id": 18853,
"author_profile": "https://Stackoverflow.com/users/18853",
"pm_score": 3,
"selected": true,
"text": "Function getOffice (strname, uname) \n\nstrEmail = uname\nWScript.Echo \"email: \" & strEmail \nDim objRoot : Set objRoot = GetObject(\"LDAP://RootDSE\")\nDim objDomain : Set objDomain = GetObject(\"LDAP://\" & objRoot.Get(\"defaultNamingContext\"))\nDim cn : Set cn = CreateObject(\"ADODB.Connection\")\nDim cmd : Set cmd = CreateObject(\"ADODB.Command\")\ncn.Provider = \"ADsDSOObject\"\ncn.Open \"Active Directory Provider\"\nSet cmd.ActiveConnection = cn\n\ncmd.CommandText = \"SELECT physicalDeliveryOfficeName FROM '\" & objDomain.ADsPath & \"' WHERE mail='\" & strEmail & \"'\"\ncmd.Properties(\"Page Size\") = 1\ncmd.Properties(\"Timeout\") = 300\ncmd.Properties(\"Searchscope\") = ADS_SCOPE_SUBTREE\n\nDim objRS : Set objRS = cmd.Execute\n If IsNull(objRS.Fields(0)) = TRUE Then \n getOffice = \"BLANK\"\n Else \n getOffice = objRS.Fields(0)\n WScript.Echo getOffice \n End If \n\n\nSet objRS = Nothing\nSet cmd = Nothing\nSet cn = Nothing\nSet objDomain = Nothing\nSet objRoot = Nothing\nEnd Function \n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282627",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18853/"
] |
282,644 | <p>What is the correct way to convert ASP.NET SOAP-based web services to JSON-based responses?
...And then call these from jQuery?</p>
<p>What are "best practices" when integrating jQuery based AJAX and ASP.NET?
Articles? Books?</p>
| [
{
"answer_id": 282695,
"author": "Frank Schwieterman",
"author_id": 32203,
"author_profile": "https://Stackoverflow.com/users/32203",
"pm_score": 3,
"selected": true,
"text": "using System.Runtime.Serialization;\nusing System.Runtime.Serialization.Json;\n\npublic class JsonSerializer\n{\n // To make a type serializeable, mark it with DataContractAttribute\n // To make a member of such types serializeable, mark them with DataMemberAttribute\n // All types marked for serialization then need to be passed to JsonSerialize as\n // parameter 'types'\n\n static public string JsonSerialize(object objectToSerialize, params Type[] types)\n {\n DataContractJsonSerializer serializer = new DataContractJsonSerializer(\n types[0], types.Skip(1));\n\n MemoryStream ms = new MemoryStream();\n serializer.WriteObject(ms, objectToSerialize);\n ms.Seek(0, SeekOrigin.Begin);\n StreamReader sr = new StreamReader(ms);\n return sr.ReadToEnd();\n }\n}\n"
},
{
"answer_id": 282873,
"author": "Cyril Gupta",
"author_id": 33052,
"author_profile": "https://Stackoverflow.com/users/33052",
"pm_score": 0,
"selected": false,
"text": "//Webmethod returns some HTML content\nMyservice.DoSomething(myParam, callBackFunction);\n\n//Content is set on the webpage\nfunction callBackFunction(result){\n document.getElementById('myElemID').innerHTML = result;\n}\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36590/"
] |
282,647 | <p>In PHP, I can write:</p>
<pre><code>$vname = 'phone';
$$vname = '555-1234';
print $phone;
</code></pre>
<p>... And the script will output "555-1234".</p>
<p>Is there any equivalent in Perl?</p>
<p>Is there any way to constrain <code>$phone</code> to the scope of the local block, as if I'd written <code>my $phone</code>? Using <code>my $$vname</code> gives me "Can't declare scalar dereference in my at ..." errors.</p>
| [
{
"answer_id": 282668,
"author": "Christian C. Salvadó",
"author_id": 5445,
"author_profile": "https://Stackoverflow.com/users/5445",
"pm_score": 3,
"selected": false,
"text": "$vname = \"phone\";\n$$vname = \"555-1234\";\nprint $phone;\n"
},
{
"answer_id": 282689,
"author": "gpojd",
"author_id": 28071,
"author_profile": "https://Stackoverflow.com/users/28071",
"pm_score": 3,
"selected": false,
"text": "perl -le 'my $vname = \"phone\"; ${ $vname } = \"555-1234\"; print $phone'\n"
},
{
"answer_id": 282814,
"author": "Michael Carman",
"author_id": 8233,
"author_profile": "https://Stackoverflow.com/users/8233",
"pm_score": 7,
"selected": true,
"text": "my"
},
{
"answer_id": 283287,
"author": "ysth",
"author_id": 17389,
"author_profile": "https://Stackoverflow.com/users/17389",
"pm_score": 4,
"selected": false,
"text": "local $phone;\n"
},
{
"answer_id": 1156864,
"author": "Brad Gilbert",
"author_id": 1337,
"author_profile": "https://Stackoverflow.com/users/1337",
"pm_score": 0,
"selected": false,
"text": "use strict;\nuse warnings;\nuse 5.010;\n\nour $test=1;\n\n# Access $test through the special hash %::\nsay ${$::{test}}++;\n\n# This is essentially what the previous line did.\nsay ${\\$test}++\n\n# Same as $test\nsay ${test}++;\n\n{\n # PHP's simple symbolic ref\n my $ref = \"test\";\n no strict 'refs';\n say $$ref++;\n say ${\"test\"}++;\n}\n{\n package d;\n say ${$main::{test}}++;\n\n my $ref = $main::{\"test\"};\n say $$ref++;\n\n $ref = \\$main::test;\n say $$ref++;\n}\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282647",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3528/"
] |
282,650 | <p>You can set the HcDynamicCompressionLevel anywhere from 0-10. I've heard 10 is bad (high CPU usage), but what's the magic number that works the best? </p>
| [
{
"answer_id": 10051876,
"author": "Kevin P. Rice",
"author_id": 733805,
"author_profile": "https://Stackoverflow.com/users/733805",
"pm_score": 2,
"selected": false,
"text": "httpCompression"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36400/"
] |
282,653 | <p>Something that confuses me, but has never caused any problems... the recommended way to dispatch an event is as follows:</p>
<pre><code>public event EventHandler SomeEvent;
...
{
....
if(SomeEvent!=null)SomeEvent();
}
</code></pre>
<p>In a multi-threaded environment, how does this code guarantee that another thread will not alter the invocation list of <code>SomeEvent</code> between the check for null and the invocation of the event?</p>
| [
{
"answer_id": 282661,
"author": "denis phillips",
"author_id": 748,
"author_profile": "https://Stackoverflow.com/users/748",
"pm_score": 2,
"selected": false,
"text": "EventHandler tmpEvent = SomeEvent;\nif (tmpEvent != null)\n{\n tmpEvent();\n}\n"
},
{
"answer_id": 282741,
"author": "HTTP 410",
"author_id": 13118,
"author_profile": "https://Stackoverflow.com/users/13118",
"pm_score": 6,
"selected": false,
"text": "SomeEvent"
},
{
"answer_id": 282861,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "\npublic class Test\n{\n private EventHandler myEvent;\n private object eventLock = new object();\n\n private void OnMyEvent()\n {\n EventHandler handler;\n\n lock(this.eventLock)\n {\n handler = this.myEvent;\n }\n if (handler != null)\n {\n handler(this, EventArgs.Empty);\n }\n }\n\n public event MyEvent\n {\n add\n {\n lock(this.eventLock)\n {\n this.myEvent += value;\n }\n }\n remove\n {\n lock(this.eventLock)\n {\n this.myEvent -= value;\n }\n }\n\n }\n}\n"
},
{
"answer_id": 283149,
"author": "Cherian",
"author_id": 22039,
"author_profile": "https://Stackoverflow.com/users/22039",
"pm_score": 5,
"selected": false,
"text": "public event EventHandler SomeEvent = delegate {};"
},
{
"answer_id": 27356941,
"author": "Gidi Baum",
"author_id": 2830334,
"author_profile": "https://Stackoverflow.com/users/2830334",
"pm_score": 0,
"selected": false,
"text": "public static class Extensions\n{\n public static void Raise(this EventHandler e, object sender, EventArgs args = null)\n {\n var e1 = e;\n\n if (e1 != null)\n {\n if (args == null)\n args = new EventArgs();\n\n e1(sender, args);\n } \n }\n }\n"
},
{
"answer_id": 32421409,
"author": "Krzysztof Branicki",
"author_id": 5297231,
"author_profile": "https://Stackoverflow.com/users/5297231",
"pm_score": 6,
"selected": true,
"text": "?."
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282653",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14357/"
] |
282,667 | <p>I'm relatively new to programming and I have to write a function that reads in input from the user and to fill two arrays then compare them. I guess what I'm confused on is how to read in both arrays.</p>
<p>This is what I'm supposed to do,</p>
<p>Write a table_diff function that compares two arrays of integers and returns the subscript of the first place they differ. If the arrays are the same, the function should return -1 ex:</p>
<p>345 & 345 --> -1 (same)</p>
<p>345 & 346 --> 2 (differ at index 2)</p>
<p>1234 & 123 --> 3 (differ at index 3)</p>
<p>This is what I have, any help is appreciated! </p>
<pre><code>while((r = scanf("%i", &value)) != 1 && ptra < endptra)
{
*ptra ++ = value;
if (r==1)
printf("No room after reading values\n\n");
else if(r != EOF)
printf("invalid char");
}
while((r = scanf("%i\n", &value))!= 1 && ptrb < endptrb){
*ptrb ++ = value;
if (r==1)
printf("No room after reading values\n\n");
else if(r != EOF)
printf("invalid char");
}
</code></pre>
| [
{
"answer_id": 282754,
"author": "Daniel Spiewak",
"author_id": 9815,
"author_profile": "https://Stackoverflow.com/users/9815",
"pm_score": 1,
"selected": false,
"text": "while((r = scanf(\"%i\", &value)) != 1 && ptra < endptra)\n{\n *(ptra++) = value; \n\n if (r==1)\n printf(\"No room after reading values\\n\\n\");\n else if(r != EOF)\n printf(\"invalid char\");\n} \n\nwhile((r = scanf(\"%i\\n\", &value))!= 1 && ptrb < endptrb){\n *(ptrb++) = value;\n\n if (r==1)\n printf(\"No room after reading values\\n\\n\"); \n else if(r != EOF)\n printf(\"invalid char\"); \n}\n"
},
{
"answer_id": 282767,
"author": "Svante",
"author_id": 31615,
"author_profile": "https://Stackoverflow.com/users/31615",
"pm_score": 0,
"selected": false,
"text": "copy - paste"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
282,670 | <p>If I have a list like this:</p>
<pre><code><ul id="mylist">
<li id="list-item1">text 1</li>
<li id="list-item2">text 2</li>
<li id="list-item3">text 3</li>
<li id="list-item4">text 4</li>
</ul>
</code></pre>
<p>What's the easiest way to re-arrange the DOM nodes to my preference? (This needs to happen automatically when the page loads, the list-order preference is gained from a cookie)</p>
<p>E.g.</p>
<pre><code><ul id="mylist">
<li id="list-item3">text 3</li>
<li id="list-item4">text 4</li>
<li id="list-item2">text 2</li>
<li id="list-item1">text 1</li>
</ul>
</code></pre>
| [
{
"answer_id": 282711,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 8,
"selected": true,
"text": "var list = document.getElementById('mylist');\n\nvar items = list.childNodes;\nvar itemsArr = [];\nfor (var i in items) {\n if (items[i].nodeType == 1) { // get rid of the whitespace text nodes\n itemsArr.push(items[i]);\n }\n}\n\nitemsArr.sort(function(a, b) {\n return a.innerHTML == b.innerHTML\n ? 0\n : (a.innerHTML > b.innerHTML ? 1 : -1);\n});\n\nfor (i = 0; i < itemsArr.length; ++i) {\n list.appendChild(itemsArr[i]);\n}\n"
},
{
"answer_id": 8732114,
"author": "Jay",
"author_id": 304711,
"author_profile": "https://Stackoverflow.com/users/304711",
"pm_score": 3,
"selected": false,
"text": "$(\"li\").tsort({order:\"asc\"});\n$(\"li\").tsort({order:\"desc\"});\n"
},
{
"answer_id": 9141303,
"author": "peter",
"author_id": 356293,
"author_profile": "https://Stackoverflow.com/users/356293",
"pm_score": 1,
"selected": false,
"text": "function forEach(ar, func){ if(ar){for(var i=ar.length; i--; ){ func(ar[i], i); }} }\nfunction removeElement(node){ return node.parentNode.removeChild(node); }\nfunction insertBefore(ref){ return function(node){ return ref.parentNode.insertBefore(node, ref); }; }\n\nfunction sort(items, greater){ \n var marker = insertBefore(items[0])(document.createElement(\"div\")); //in case there is stuff before/after the sortees\n forEach(items, removeElement);\n items.sort(greater); \n items.reverse(); //because the last will be first when reappending\n forEach(items, insertBefore(marker));\n removeElement(marker);\n} \n"
},
{
"answer_id": 11052468,
"author": "Michal Stefanow",
"author_id": 775359,
"author_profile": "https://Stackoverflow.com/users/775359",
"pm_score": 4,
"selected": false,
"text": " jQuery.fn.sortDomElements = (function() {\n return function(comparator) {\n return Array.prototype.sort.call(this, comparator).each(function(i) {\n this.parentNode.appendChild(this);\n });\n };\n })();\n"
},
{
"answer_id": 39569822,
"author": "Ebrahim Byagowi",
"author_id": 1414809,
"author_profile": "https://Stackoverflow.com/users/1414809",
"pm_score": 4,
"selected": false,
"text": "var p = document.getElementById('mylist');\nArray.prototype.slice.call(p.children)\n .map(function (x) { return p.removeChild(x); })\n .sort(function (x, y) { return /* your sort logic, compare x and y here */; })\n .forEach(function (x) { p.appendChild(x); });\n"
},
{
"answer_id": 45985978,
"author": "cgenco",
"author_id": 1298553,
"author_profile": "https://Stackoverflow.com/users/1298553",
"pm_score": 3,
"selected": false,
"text": "const sortChildren = ({ container, childSelector, getScore }) => {\n const items = [...container.querySelectorAll(childSelector)];\n\n items\n .sort((a, b) => getScore(b) - getScore(a))\n .forEach(item => container.appendChild(item));\n};\n"
},
{
"answer_id": 50127768,
"author": "ahuigo",
"author_id": 2140757,
"author_profile": "https://Stackoverflow.com/users/2140757",
"pm_score": 6,
"selected": false,
"text": "var list = document.querySelector('#test-list');\n\n[...list.children]\n .sort((a,b)=>a.innerText>b.innerText?1:-1)\n .forEach(node=>list.appendChild(node));\n"
},
{
"answer_id": 63746236,
"author": "Leedehai",
"author_id": 8385554,
"author_profile": "https://Stackoverflow.com/users/8385554",
"pm_score": 0,
"selected": false,
"text": "compare"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21677/"
] |
282,676 | <p>I have some shapefile (demographic/heat map data in the USA, such as crime in New York) data imported into a sql server 2008 database, field data type: <em>Geography</em>.</p>
<p>How can i get this data, from a <em>select</em> query, in a format which i can then display on google maps or microsoft virtual earth?</p>
<p>thanks!</p>
<p>Edit 1: So far, the best solution has been to use a (free) 3rd Party dll (<a href="http://www.codeplex.com/SharpMap" rel="nofollow noreferrer">SharpMap</a>). I'm hoping someone might suggest some sql tricks in sql2008 to return it in a compatible format ...</p>
| [
{
"answer_id": 577600,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": true,
"text": "select SHAPE.STX as X\n ,SHAPE.STY as Y\n ,SHAPE.STAsText() as WKT\n ,SHAPE.AsGml() as GML\nfrom dpu.SW_SERVICE_LOCATIONS\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30674/"
] |
282,692 | <p>How can you express X of Y are true, in boolean logic? a rule like 2 of the following must be true (A, B, C, D, E, F)
is it a form of multiplcation or set operations?<br>
the end result is all the permutations like AB OR AC OR AD, if you said 3 of following it is like ABC, ABD, ABE, etc.. so it is like (A,B,C)^2?</p>
<p>thanks!</p>
| [
{
"answer_id": 282728,
"author": "Charlie Martin",
"author_id": 35092,
"author_profile": "https://Stackoverflow.com/users/35092",
"pm_score": 2,
"selected": false,
"text": "(A & B & C & ~D & ~E) |\n(A & B & ~C & D & ~E) |\n(A & B & ~C & ~D & E) | ...\n(~A & ~B & C & D & E)\n"
},
{
"answer_id": 282731,
"author": "BCS",
"author_id": 1343,
"author_profile": "https://Stackoverflow.com/users/1343",
"pm_score": 0,
"selected": false,
"text": "2 : a&(b|c|d|e|f) | b&(c|d|e|f) | c&(d|e|f) | d&(e|f) | e*f\n3 : a&(b&(c|d|e|f) | c&(d|e|f) | d&(e|f) | e*f) | b&(c&(d|e|f) | d&(e|f) | e*f) | c&(d&(e|f) | e*f) | d&e&f\n"
},
{
"answer_id": 282734,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 3,
"selected": true,
"text": "A B C'D'E'F' v\nA B'C'D'E'F v\nA'B C'D'E'F' v\n: : : : : :\n<absolute bucketload of boolean expressions>\n: : : : : :\nA'B'C'D'E F\n"
},
{
"answer_id": 282753,
"author": "Patrick",
"author_id": 429,
"author_profile": "https://Stackoverflow.com/users/429",
"pm_score": 2,
"selected": false,
"text": "bool nOf(int n, bool[] bs)\n{\n foreach(bool b in bs)\n {\n if((n -= b ? 1 : 0) <= 0) break;\n }\n return n == 0;\n}\n"
},
{
"answer_id": 282820,
"author": "too much php",
"author_id": 28835,
"author_profile": "https://Stackoverflow.com/users/28835",
"pm_score": 2,
"selected": false,
"text": "expressions = [A, B, C, D, E, F, G ]\nnumTrue = len(filter(None, expressions)\n"
},
{
"answer_id": 291458,
"author": "waynecolvin",
"author_id": 35658,
"author_profile": "https://Stackoverflow.com/users/35658",
"pm_score": 0,
"selected": false,
"text": "Basic Half-Adder\n\nA, B : 1st 2nd bits\nO, C : unit output and carry to next unit\n\nO := A xor B;\nC := A and B;\n"
},
{
"answer_id": 365681,
"author": "joel.neely",
"author_id": 3525,
"author_profile": "https://Stackoverflow.com/users/3525",
"pm_score": 0,
"selected": false,
"text": "(A && B) || (A && C) || ... || (D && E) || (D && F) || (E && F)\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282692",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5111/"
] |
282,700 | <p>I'm working on a school project and I'm getting some weird errors from Xcode. I'm using TextMate's Command+R function to compile the project. Compilation seems to work okay but linking fails with an error message I don't understand. </p>
<p>ld output:</p>
<blockquote>
<p>ld: duplicate symbol text_field(std::basic_istream >&)in /path/final/build/final.build/Release/final.build/Objects-normal/ppc/generics.o and /path/final/build/final.build/Release/final.build/Objects-normal/ppc/main.o
collect2: ld returned 1 exit status</p>
</blockquote>
<p>Below is my file io_functions.cpp This is the only declaration of text_field in the entire project. </p>
<pre><code>#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
#ifndef ENDF
#define ENDF '|'
#define ENDR '\n'
/**
reads one field from a given input stream
Usage: var = text_field(in)
*/
string text_field(istream &in){
string s;
getline(in, s, ENDF);
return s;
}
long long_field(istream &in){
return atol(text_field(in).c_str());
}
int int_field(istream &in){
return atoi(text_field(in).c_str());
}
double double_field(istream &in){
return atof(text_field(in).c_str());
}
#endif
</code></pre>
<p>What is going wrong? For a number of reasons I don't want to post my project's entire source. </p>
| [
{
"answer_id": 282717,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 6,
"selected": true,
"text": "main.o"
},
{
"answer_id": 59873749,
"author": "Snow Albert",
"author_id": 4123418,
"author_profile": "https://Stackoverflow.com/users/4123418",
"pm_score": 0,
"selected": false,
"text": "inline string text_field(istream &in)\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282700",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16204/"
] |
282,712 | <p>I'm quite confused about the basic concepts of a Hash table. If I were to code a hash how would I even begin? What is the difference between a Hash table and just a normal array? </p>
<p>Basically if someone answered this question I think all my questions would be answered:
If I had 100 randomly generated numbers (as keys), how would I implement a hash table and why would that be advantageous over an array?</p>
<p>Psuedo-code or Java would be appreciated as a learning tool...</p>
| [
{
"answer_id": 282722,
"author": "Daniel Spiewak",
"author_id": 9815,
"author_profile": "https://Stackoverflow.com/users/9815",
"pm_score": 4,
"selected": false,
"text": "int[] arr = ...\nfor (int i = 0; i < arr.length; i++) {\n System.out.println(arr[i] + 1);\n}\n"
},
{
"answer_id": 282835,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 3,
"selected": false,
"text": "mod( hash, table size )"
},
{
"answer_id": 282836,
"author": "gnud",
"author_id": 27204,
"author_profile": "https://Stackoverflow.com/users/27204",
"pm_score": 6,
"selected": false,
"text": "public int stringHash(String s) {\n int h = s.length();\n for(char c : s.toCharArray()) {\n h ^= c;\n }\n return h;\n}\n"
},
{
"answer_id": 282867,
"author": "Adam Liss",
"author_id": 29157,
"author_profile": "https://Stackoverflow.com/users/29157",
"pm_score": 7,
"selected": true,
"text": "N"
},
{
"answer_id": 2897041,
"author": "Omer Akhter",
"author_id": 327493,
"author_profile": "https://Stackoverflow.com/users/327493",
"pm_score": 0,
"selected": false,
"text": "startAddress"
},
{
"answer_id": 18417551,
"author": "Durai Amuthan.H",
"author_id": 730807,
"author_profile": "https://Stackoverflow.com/users/730807",
"pm_score": 0,
"selected": false,
"text": " import java.util.Collection;\n import java.util.Enumeration;\n import java.util.Hashtable;\n import java.util.Set;\n\n public class HashtableDemo {\n\n public static void main(String args[]) {\n\n// Creating Hashtable for example\n\n Hashtable companies = new Hashtable();\n\n\n// Java Hashtable example to put object into Hashtable\n// put(key, value) is used to insert object into map\n\n companies.put(\"Google\", \"United States\");\n companies.put(\"Nokia\", \"Finland\");\n companies.put(\"Sony\", \"Japan\");\n\n\n// Java Hashtable example to get Object from Hashtable\n// get(key) method is used to retrieve Objects from Hashtable\n\n companies.get(\"Google\");\n\n\n// Hashtable containsKey Example\n// Use containsKey(Object) method to check if an Object exits as key in\n// hashtable\n\n System.out.println(\"Does hashtable contains Google as key: \"+companies.containsKey(\"Google\"));\n\n\n// Hashtable containsValue Example\n// just like containsKey(), containsValue returns true if hashtable\n// contains specified object as value\n\n System.out.println(\"Does hashtable contains Japan as value: \"+companies.containsValue(\"Japan\"));\n\n\n// Hashtable enumeration Example\n// hashtabl.elements() return enumeration of all hashtable values\n\n Enumeration enumeration = companies.elements();\n\n while (enumeration.hasMoreElements()) {\n System.out.println(\"hashtable values: \"+enumeration.nextElement());\n }\n\n\n// How to check if Hashtable is empty in Java\n// use isEmpty method of hashtable to check emptiness of hashtable in\n// Java\n\n System.out.println(\"Is companies hashtable empty: \"+companies.isEmpty());\n\n\n// How to find size of Hashtable in Java\n// use hashtable.size() method to find size of hashtable in Java\n\n System.out.println(\"Size of hashtable in Java: \" + companies.size());\n\n\n// How to get all values form hashtable in Java\n// you can use keySet() method to get a Set of all the keys of hashtable\n// in Java\n\n Set hashtableKeys = companies.keySet();\n\n\n// you can also get enumeration of all keys by using method keys()\n\n Enumeration hashtableKeysEnum = companies.keys();\n\n\n// How to get all keys from hashtable in Java\n// There are two ways to get all values form hashtalbe first by using\n// Enumeration and second getting values ad Collection\n\n Enumeration hashtableValuesEnum = companies.elements();\n\n\n Collection hashtableValues = companies.values();\n\n\n// Hashtable clear example\n// by using clear() we can reuse an existing hashtable, it clears all\n// mappings.\n\n companies.clear();\n }\n }\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282712",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36545/"
] |
282,729 | <p>I was wondering if someone would be able to help me write a CQL query for NDepend that will show me all the methods in my form class that handle the form events. So I would like to be able to find all the methods that look like this:</p>
<pre><code>Private Sub AddFolderButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddFolderButton.Click
</code></pre>
<p>I have had a look through some of the options but I can't really find anything that does what I need.</p>
<p>I have only just started using NDepend, so I haven't really got used to it yet, but I do know one thing how the hell did I live without it all this time.</p>
| [
{
"answer_id": 282931,
"author": "Nathan W",
"author_id": 6335,
"author_profile": "https://Stackoverflow.com/users/6335",
"pm_score": 0,
"selected": false,
"text": "SELECT METHODS WHERE NameLike \"_\" OR NameLike \"EventArgs\" AND !IsSpecialName AND IsPrivate \n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6335/"
] |
282,740 | <p>Currently we have a DLL that checks whether a username/password is a valid Windows user using the Windows API LogonUser method. We need to enhance it so it checks whether the user belongs to a specified group as well. Is there a Windows method that does that?</p>
<p>Given a Windows username and password, find out whether the user belongs to a specified group.</p>
| [
{
"answer_id": 282914,
"author": "Robo",
"author_id": 26305,
"author_profile": "https://Stackoverflow.com/users/26305",
"pm_score": 1,
"selected": true,
"text": "unit GetGroupsForUserUnit;\n\ninterface\n\nuses\n Windows, SysUtils, Classes, ShellAPI;\n\ntype\n {$EXTERNALSYM NET_API_STATUS}\n NET_API_STATUS = DWORD;\n LPLOCALGROUP_USERS_INFO_0 = ^LOCALGROUP_USERS_INFO_0;\n {$EXTERNALSYM LPLOCALGROUP_USERS_INFO_0}\n PLOCALGROUP_USERS_INFO_0 = ^LOCALGROUP_USERS_INFO_0;\n {$EXTERNALSYM PLOCALGROUP_USERS_INFO_0}\n _LOCALGROUP_USERS_INFO_0 = record\n lgrui0_name: LPWSTR;\n end;\n {$EXTERNALSYM _LOCALGROUP_USERS_INFO_0}\n LOCALGROUP_USERS_INFO_0 = _LOCALGROUP_USERS_INFO_0;\n {$EXTERNALSYM LOCALGROUP_USERS_INFO_0}\n TLocalGroupUsersInfo0 = LOCALGROUP_USERS_INFO_0;\n PLocalGroupUsersInfo0 = PLOCALGROUP_USERS_INFO_0;\n\nconst\n {$EXTERNALSYM MAX_PREFERRED_LENGTH}\n MAX_PREFERRED_LENGTH = DWORD(-1);\n {$EXTERNALSYM NERR_Success}\n NERR_Success = 0;\n {$EXTERNALSYM NERR_BASE}\n NERR_BASE = 2100;\n {$EXTERNALSYM NERR_UserNotFound}\n NERR_UserNotFound = (NERR_BASE+121);\n {$EXTERNALSYM NERR_InvalidComputer}\n NERR_InvalidComputer = (NERR_BASE+251);\n {$EXTERNALSYM LG_INCLUDE_INDIRECT}\n LG_INCLUDE_INDIRECT = $0001;\n\n\n{$EXTERNALSYM NetUserGetLocalGroups}\nfunction NetUserGetLocalGroups(servername: PWideChar; username: PWideChar;\n level: DWORD; flags: DWORD; var bufptr: Pointer; prefmaxlen: DWORD;\n var entriesread: DWORD; var totalentries: DWORD): NET_API_STATUS; stdcall;\n{$EXTERNALSYM NetApiBufferFree}\nfunction NetApiBufferFree(Buffer: Pointer): NET_API_STATUS; stdcall;\n\nfunction GetGroupsForNetUser(uname: widestring): string;\n\nimplementation\n\nfunction NetUserGetLocalGroups; external 'netapi32.dll' name\n'NetUserGetLocalGroups';\nfunction NetApiBufferFree; external 'netapi32.dll' name 'NetApiBufferFree';\n\nfunction GetGroupsForNetUser(uname: widestring): string;\n// NetUserGetLocalGroups - returns semi-colon delim string of groups.\n// Pass in user value returned by GetUserName to get current user.\nvar\n bufptr: Pointer;\n Status: NET_API_STATUS;\n PrefMaxLen, EntriesRead, TotalEntries: DWord;\n i: integer;\n pTmpBuf: LPLOCALGROUP_USERS_INFO_0;\nbegin\n PrefMaxLen := MAX_PREFERRED_LENGTH;\n Status := NetUserGetLocalGroups(nil, PWideChar(uname), 0 ,\n LG_INCLUDE_INDIRECT, bufptr, PrefMaxLen,\n EntriesRead, TotalEntries);\n case Status of\n NERR_Success: begin\n result := 'success, but no groups';\n pTmpBuf := bufptr;\n if pTmpBuf <> nil then\n begin\n result := '';\n for i := 0 to EntriesRead - 1 do\n begin\n if pTmpBuf <> nil then\n begin\n if result = '' then\n begin\n result := pTmpBuf.lgrui0_name\n else\n result := result + ';' + pTmpBuf.lgrui0_name;\n end;\n Inc(pTmpBuf);\n end;\n end;\n end;\n ERROR_ACCESS_DENIED: begin\n result := 'The user does not have access.';\n end;\n NERR_InvalidComputer: begin\n result := 'The computer name is invalid.';\n end;\n NERR_UserNotFound: begin\n result := 'The user name could not be found. (' + uname + ')';\n end;\n else begin\n result := 'Unknown error.';\n end;\n end;\n if bufptr <> nil then\n NetApiBufferFree(bufptr);\nend;\n\nend.\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26305/"
] |
282,746 | <p>I'm writing C# code that needs to connect to COM events. I implemented the use of
IConnectionPointContainer and IConnectionPoint thus:</p>
<pre><code> IConnectionPointContainer connectionPointContainer = internalGenerator as IConnectionPointContainer;
if (connectionPointContainer == null)
{
Debug.Fail("The script generator doesn't support the required interface - IConnectionPointContainer");
throw new InvalidCastException("The script generator doesn't support the required interface - IConnectionPointContainer");
}
Guid IID_IScriptGeneratorEvents = typeof(IScriptGeneratorCallback).GUID;
connectionPointContainer.FindConnectionPoint(ref IID_IScriptGeneratorEvents, out m_connectionPoint);
m_connectionPoint.Advise(this, out m_cookie);
</code></pre>
<p>The problem is that when the COM server is actually implemented in .Net (say, C#), after .Net creates it, it handles it as a .Net object, not a COM object. Since the .Net object doesn't implement the IConnectionPointContainer interface, I get null when trying to cast the object to that interface.</p>
<p>Any idea how can i workaround this?
I can of course implement IConnectionPointContainer by myself in the C# COM server, however I would like a simpler solution, which I can easily explain to other developers which need to implement the COM server.</p>
<p>P.S I must use IConnectionPointContainer as the COM server may be implemented in non-.Net (C++, Java).</p>
<p>Thanks,
Inbar</p>
| [
{
"answer_id": 1333190,
"author": "SPARQLGuy",
"author_id": 162598,
"author_profile": "https://Stackoverflow.com/users/162598",
"pm_score": 0,
"selected": false,
"text": "internal void QuickActivate(UnsafeNativeMethods.tagQACONTAINER pQaContainer, UnsafeNativeMethods.tagQACONTROL pQaControl)\n{\n int num;\n this.LookupAmbient(-701).Value = ColorTranslator.FromOle((int) pQaContainer.colorBack);\n this.LookupAmbient(-704).Value = ColorTranslator.FromOle((int) pQaContainer.colorFore);\n if (pQaContainer.pFont != null)\n {\n Control.AmbientProperty ambient = this.LookupAmbient(-703);\n IntSecurity.UnmanagedCode.Assert();\n try\n {\n Font font2 = Font.FromHfont(((UnsafeNativeMethods.IFont) pQaContainer.pFont).GetHFont());\n ambient.Value = font2;\n }\n catch (Exception exception)\n {\n if (ClientUtils.IsSecurityOrCriticalException(exception))\n {\n throw;\n }\n ambient.Value = null;\n }\n finally\n {\n CodeAccessPermission.RevertAssert();\n }\n }\n pQaControl.cbSize = UnsafeNativeMethods.SizeOf(typeof(UnsafeNativeMethods.tagQACONTROL));\n this.SetClientSite(pQaContainer.pClientSite);\n if (pQaContainer.pAdviseSink != null)\n {\n this.SetAdvise(1, 0, (IAdviseSink) pQaContainer.pAdviseSink);\n }\n IntSecurity.UnmanagedCode.Assert();\n try\n {\n ((UnsafeNativeMethods.IOleObject) this.control).GetMiscStatus(1, out num);\n }\n finally\n {\n CodeAccessPermission.RevertAssert();\n }\n pQaControl.dwMiscStatus = num;\n if ((pQaContainer.pUnkEventSink != null) && (this.control is UserControl))\n {\n Type defaultEventsInterface = GetDefaultEventsInterface(this.control.GetType());\n if (defaultEventsInterface != null)\n {\n IntSecurity.UnmanagedCode.Assert();\n try\n {\n **AdviseHelper.AdviseConnectionPoint(this.control, pQaContainer.pUnkEventSink, defaultEventsInterface, out pQaControl.dwEventCookie);**\n }\n catch (Exception exception2)\n {\n if (ClientUtils.IsSecurityOrCriticalException(exception2))\n {\n throw;\n }\n }\n finally\n {\n CodeAccessPermission.RevertAssert();\n }\n }\n }\n if ((pQaContainer.pPropertyNotifySink != null) && UnsafeNativeMethods.IsComObject(pQaContainer.pPropertyNotifySink))\n {\n UnsafeNativeMethods.ReleaseComObject(pQaContainer.pPropertyNotifySink);\n }\n if ((pQaContainer.pUnkEventSink != null) && UnsafeNativeMethods.IsComObject(pQaContainer.pUnkEventSink))\n {\n UnsafeNativeMethods.ReleaseComObject(pQaContainer.pUnkEventSink);\n }\n}\n"
},
{
"answer_id": 16342698,
"author": "MarkB42",
"author_id": 351028,
"author_profile": "https://Stackoverflow.com/users/351028",
"pm_score": 0,
"selected": false,
"text": "MyAppDotNetWrapper"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36694/"
] |
282,758 | <p>Sometimes you have strings that must fit within a certain pixel width. This function attempts to do so efficiently. Please post your suggestions or refactorings below :)</p>
<pre><code>function fitStringToSize(str,len) {
var shortStr = str;
var f = document.createElement("span");
f.style.display = 'hidden';
f.style.padding = '0px';
document.body.appendChild(f);
// on first run, check if string fits into the length already.
f.innerHTML = str;
diff = f.offsetWidth - len;
// if string is too long, shorten it by the approximate
// difference in characters (to make for fewer iterations).
while(diff > 0)
{
shortStr = substring(str,0,(str.length - Math.ceil(diff / 5))) + '&hellip;';
f.innerHTML = shortStr;
diff = f.offsetWidth - len;
}
while(f.lastChild) {
f.removeChild(f.lastChild);
}
document.body.removeChild(f);
// if the string was too long, put the original string
// in the title element of the abbr, and append an ellipsis
if(shortStr.length < str.length)
{
return '<abbr title="' + str + '">' + shortStr + '</abbr>';
}
// if the string was short enough in the first place, just return it.
else
{
return str;
}
}
</code></pre>
<p>UPDATE:
@some's solution below is much better; please use that. </p>
<p>Update 2:
Code now posted as a <a href="https://gist.github.com/24261/7fdb113f1e26111bd78c0c6fe515f6c0bf418af5" rel="noreferrer">gist</a>; feel free to fork and submit patches :)</p>
| [
{
"answer_id": 283994,
"author": "some",
"author_id": 36866,
"author_profile": "https://Stackoverflow.com/users/36866",
"pm_score": 6,
"selected": true,
"text": "/ 5"
},
{
"answer_id": 1251574,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "<p id=\"truncateMe\">Lorem ipsum dolor sit amet, consectetuer adipiscing\nelit. Aenean consectetuer. Etiam venenatis. Sed ultricies, pede sit\namet aliquet lobortis, nisi ante sagittis sapien, in rhoncus lectus\nmauris quis massa. Integer porttitor, mi sit amet viverra faucibus,\nurna libero viverra nibh, sed dictum nisi mi et diam. Nulla nunc eros,\nconvallis sed, varius ac, commodo et, magna. Proin vel\nrisus. Vestibulum eu urna. Maecenas lobortis, pede ac dictum pulvinar,\nnibh ante vestibulum tortor, eget fermentum urna ipsum ac neque. Nam\nurna nulla, mollis blandit, pretium id, tristique vitae, neque. Etiam\nid tellus. Sed pharetra enim non nisl.</p>\n\n<script type=\"text/javascript\">\n\nvar len = 100;\nvar p = document.getElementById('truncateMe');\nif (p) {\n\n var trunc = p.innerHTML;\n if (trunc.length > len) {\n\n /* Truncate the content of the P, then go back to the end of the\n previous word to ensure that we don't truncate in the middle of\n a word */\n trunc = trunc.substring(0, len);\n trunc = trunc.replace(/\\w+$/, '');\n\n /* Add an ellipses to the end and make it a link that expands\n the paragraph back to its original size */\n trunc += '<a href=\"#\" ' +\n 'onclick=\"this.parentNode.innerHTML=' +\n 'unescape(\\''+escape(p.innerHTML)+'\\');return false;\">' +\n '...<\\/a>';\n p.innerHTML = trunc;\n }\n}\n\n</script>\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282758",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13289/"
] |
282,779 | <p>I was wondering if there was some kind of J tool in the java swing library that opens up a file browser window and allows a user to choose a file. Then the ouput of the file would be the absolute path of the chosen file.</p>
<p>Thanks in advance,</p>
| [
{
"answer_id": 282793,
"author": "Tomek",
"author_id": 29326,
"author_profile": "https://Stackoverflow.com/users/29326",
"pm_score": 4,
"selected": false,
"text": "final JFileChooser fc = new JFileChooser();\nfc.showOpenDialog(this);\n\ntry {\n // Open an input stream\n Scanner reader = new Scanner(fc.getSelectedFile());\n}\n"
},
{
"answer_id": 282902,
"author": "iberck",
"author_id": 34768,
"author_profile": "https://Stackoverflow.com/users/34768",
"pm_score": 3,
"selected": false,
"text": "String filename = File.separator+\"tmp\";\nJFileChooser fc = new JFileChooser(new File(filename));\n\n// Show open dialog; this method does not return until the dialog is closed\nfc.showOpenDialog(frame);\nFile selFile = fc.getSelectedFile();\n\n// Show save dialog; this method does not return until the dialog is closed\nfc.showSaveDialog(frame);\nselFile = fc.getSelectedFile();\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29326/"
] |
282,791 | <ul>
<li><p>How do I utilize a ?: operator in the SELECT clause of a LINQ query? If this can't be done, how can I emulate one? The goal is to get a CASE block in my select clause. As you might suspect, I'm getting an error: <em>Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.</em></p></li>
<li><p>Is this the proper way, or a sufficient way, to say "from a inner join i on a.ipid=i.id inner join u on i.uid=u.id"? If not, please provide one. Thanks.</p>
<pre><code>var query =
from a in db.tblActivities
from i in db.tblIPs
from u in db.tblUsers
select new {
u.UserName == null
? i.Address
: u.UserName,
a.Request,
a.DateTime };
</code></pre></li>
</ul>
| [
{
"answer_id": 282806,
"author": "LeppyR64",
"author_id": 16592,
"author_profile": "https://Stackoverflow.com/users/16592",
"pm_score": 0,
"selected": false,
"text": "var query =\n from a in db.tblActivities\n from i in a.tblIPs\n from u in i.tblUsers \n select new\n {\n userName = (u.UserName == null)\n ? i.Address\n : u.UserName,\n a.Request,\n a.DateTime\n };\n"
},
{
"answer_id": 282822,
"author": "hugoware",
"author_id": 17091,
"author_profile": "https://Stackoverflow.com/users/17091",
"pm_score": 0,
"selected": false,
"text": "string something = null;\nstring somethingElse = something ?? \"default value\";\n"
},
{
"answer_id": 282875,
"author": "GalacticCowboy",
"author_id": 29638,
"author_profile": "https://Stackoverflow.com/users/29638",
"pm_score": 5,
"selected": true,
"text": "var query = from a in db.tblActivities\n join i in db.tblIPs on a.ipid equals i.id\n join u in db.tblUsers on i.uid equals u.id\n select new {\n UserName = (u.UserName ?? i.Address),\n Request = a.Request,\n Date = a.DateTime\n };\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282791",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11112/"
] |
282,800 | <p>I don't even know where to go with this. Google wasn't very helpful. As with my previous question. I'm using TextMate's Command+R to compile the project.</p>
<blockquote>
<p>game.h:16:error: declaration of ‘Player* HalfSet::Player() const’</p>
<p>players.h:11:error: changes meaning of ‘Player’ from ‘class Player’</p>
<p>game.h:21:error: ‘Player’ is not a type</p>
</blockquote>
<p>player.h file (partial)</p>
<pre><code>#ifndef PLAYERS_H
#define PLAYERS_H
using namespace std;
#include <string>
#include <vector>
#include <istream>
#include <iomanip>
#include "generics.h"
class Player{ //Line 11
public:
//getters
long Id() const;
string FirstName() const;
string LastName() const;
string Country() const;
//setters
void setId(long id);
void setFirstName(string s);
void setLastName(string s);
void setCountry(string s);
//serializing functions
void display(ostream &out);
void read(istream &in);
void write(ostream &out);
//Initalizers
Player();
Player(istream &in);
Player(string firstName, string lastName);
Player(string firstName, string lastName, string country);
Player(long id, string firstName, string lastName, string country);
~Player();
private:
long _id;
string _firstName;
string _lastName;
string _country;
};
</code></pre>
<p>game.h file (partial)</p>
<pre><code>#ifndef GAME_H
#define GAME_H
#include "generics.h"
#include "players.h"
#include <string>
#include <vector>
#include <istream>
#include <iomanip>
using namespace std;
class HalfSet{
public:
//getters
Player* Player() const; //Line 16
int GamesWon() const;
int TotalPoints() const;
int Errors() const;
//setters
void setPlayer(Player* p);
void setGamesWon(int games);
void setTotalPoints(int points);
void setErrors(int errors);
//Serialization
void display(ostream &out) const;
void read(istream &in) const;
void write(ostream &out) const;
//Initalizers
HalfSet();
~HalfSet();
private:
Player* _player;
int _gamesWon;
int _points;
int _errors;
};
</code></pre>
<p>What is going on here?</p>
| [
{
"answer_id": 283463,
"author": "MSalters",
"author_id": 15416,
"author_profile": "https://Stackoverflow.com/users/15416",
"pm_score": 3,
"selected": false,
"text": "HalfSet::setPlayer(Player*)"
},
{
"answer_id": 26695750,
"author": "Shafik Yaghmour",
"author_id": 1708801,
"author_profile": "https://Stackoverflow.com/users/1708801",
"pm_score": 3,
"selected": false,
"text": "3.3.7"
},
{
"answer_id": 71200825,
"author": "Cyphonvoid",
"author_id": 18264398,
"author_profile": "https://Stackoverflow.com/users/18264398",
"pm_score": 0,
"selected": false,
"text": "#include \"a.h\"\n\nclass System {\n public:\n car car; /*This line is problem, Can't declare object with same name as \n class*/\n};\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282800",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16204/"
] |
282,802 | <p>I know that I can <code> svn diff -r a:b repo </code> to view the changes between the two specified revisions. What I'd like is a diff for every revision that changed the file. Is such a command available?</p>
| [
{
"answer_id": 282887,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 5,
"selected": false,
"text": "git-svn"
},
{
"answer_id": 282956,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "svn log -q file | grep '^r' | cut -f1 -d' '\n"
},
{
"answer_id": 283168,
"author": "bendin",
"author_id": 33412,
"author_profile": "https://Stackoverflow.com/users/33412",
"pm_score": 9,
"selected": true,
"text": "#!/bin/bash\n\n# history_of_file\n#\n# Outputs the full history of a given file as a sequence of\n# logentry/diff pairs. The first revision of the file is emitted as\n# full text since there's not previous version to compare it to.\n\nfunction history_of_file() {\n url=$1 # current url of file\n svn log -q $url | grep -E -e \"^r[[:digit:]]+\" -o | cut -c2- | sort -n | {\n\n# first revision as full text\n echo\n read r\n svn log -r$r $url@HEAD\n svn cat -r$r $url@HEAD\n echo\n\n# remaining revisions as differences to previous revision\n while read r\n do\n echo\n svn log -r$r $url@HEAD\n svn diff -c$r $url@HEAD\n echo\n done\n }\n}\n"
},
{
"answer_id": 283181,
"author": "ngn",
"author_id": 23109,
"author_profile": "https://Stackoverflow.com/users/23109",
"pm_score": 7,
"selected": false,
"text": "svn blame filename\n"
},
{
"answer_id": 18211953,
"author": "dlink",
"author_id": 1574587,
"author_profile": "https://Stackoverflow.com/users/1574587",
"pm_score": 2,
"selected": false,
"text": "svnhistory elements.py |more\n"
},
{
"answer_id": 24938573,
"author": "emilie zawadzki",
"author_id": 1879453,
"author_profile": "https://Stackoverflow.com/users/1879453",
"pm_score": 7,
"selected": false,
"text": "svn log --diff [path_to_file] > log.txt\n"
},
{
"answer_id": 54064368,
"author": "alamba",
"author_id": 5483458,
"author_profile": "https://Stackoverflow.com/users/5483458",
"pm_score": 1,
"selected": false,
"text": "svn blame -v <filename>\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23071/"
] |
282,831 | <p>I am trying to see what are the gotchas in using XmlHttpWebRequest such that it works for Safari, Firefox and IE?</p>
| [
{
"answer_id": 282842,
"author": "Corey Trager",
"author_id": 9328,
"author_profile": "https://Stackoverflow.com/users/9328",
"pm_score": 1,
"selected": false,
"text": " // Create the request object; Microsoft failed to properly\n // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available\n var xhr = window.ActiveXObject ? new ActiveXObject(\"Microsoft.XMLHTTP\") : new XMLHttpRequest();\n\n // Open the socket\n // Passing null username, generates a login popup on Opera (#2865)\n if( s.username )\n xhr.open(type, s.url, s.async, s.username, s.password);\n else\n xhr.open(type, s.url, s.async);\n\n // Need an extra try/catch for cross domain requests in Firefox 3\n try {\n"
},
{
"answer_id": 282844,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 2,
"selected": false,
"text": "var xhr;\nif (window.XMLHttpRequest) {\n xhr = new XMLHttpRequest(); // Mozilla/Webkit/Opera\n} else if (window.ActiveXObject) {\n xhr = new ActiveXObject('Msxml2.XMLHTTP'); // IE\n} else {\n throw new Error('Ajax likely not supported');\n}\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282831",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
282,832 | <p>I am trying to do something like this</p>
<pre><code>public void GetData(ref Dictionary<T,V> dataDictionary)
{
}
</code></pre>
<p>Where T can be GUID, string, or int and V is custom user or item object.</p>
| [
{
"answer_id": 282846,
"author": "jons911",
"author_id": 34375,
"author_profile": "https://Stackoverflow.com/users/34375",
"pm_score": 0,
"selected": false,
"text": "public void GetData<T, V>(ref Dictionary<T, V> dataDictionary) {\n if (typeof(T) == typeof(string) || typeof(T) == typeof(int) || typeof(T) == typeof(Guid)) {\n ...\n } else {\n throw new ArgumentException();\n }\n}\n"
},
{
"answer_id": 282848,
"author": "Robert Paulson",
"author_id": 14033,
"author_profile": "https://Stackoverflow.com/users/14033",
"pm_score": 2,
"selected": false,
"text": "public Dictionary<T,V> GetData<T,V>()\n"
},
{
"answer_id": 283254,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 0,
"selected": false,
"text": "string"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282832",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
282,838 | <p>I know this question had been asked more than a few times, but so far I haven't been able to find a good solution for it.</p>
<p>I've got a panel with other control on it.<br>
I want to draw a line on it and on top of all the controls in the panel</p>
<p>I came across 3 types of solutions (non of them worked the way I wanted) :</p>
<ol>
<li><p>Get the desktop DC and Draw on the screen.<br>
This will draw on other applications if they overlap the form.</p></li>
<li><p>Overriding the panel's "CreateParams":</p></li>
</ol>
<p>=</p>
<pre><code>protected override CreateParams CreateParams {
get {
CreateParams cp;
cp = base.CreateParams;
cp.Style &= ~0x04000000; //WS_CLIPSIBLINGS
cp.Style &= ~0x02000000; //WS_CLIPCHILDREN
return cp;
}
}
</code></pre>
<p>//NOTE I've also tried disabling WS_CLIPSIBLINGS</p>
<p>and then drawing the line OnPaint().
But... Since the panel's OnPaint is called before the OnPaint of the controls in it,
the drawing of the controls inside simply paints on top of the line.<br>
I've seen someone suggest using a message filter to listen to WM_PAINT mesages, and use a timer, but I don't think this solution is either "good practice" or effective.<br>
What would you do ? Decide that the controls inside have finished drawing after X ms, and set the timer to X ms ?</p>
<hr>
<p>This screen shot shows the panel with WS_CLIPSIBLINGS and WS_CLIPCHILDREN turned off.<br>
The Blue line is painted at the Panel's OnPaint, and simply being painted on by the textboxes and label.<br>
The Red line is painted on top only because it's not being painted from the panel's OnPaint (It's actually painted as a result of a Button being clicked)<br>
<img src="https://i73.photobucket.com/albums/i201/sdjc1/temp/screen3.png" alt="alt text"></p>
<hr>
<p>3rd: Creating a transparent layer and drawing on top of that layer.<br>
I've created a transparent control using:</p>
<pre><code>protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}
</code></pre>
<p>The problem is still, putting the transparent control on top of the Panel and all its controls.<br>
I've tried bringing it to the front using: "BringToFront()" , but it didn't seem to help.<br>
I've put it in the Line control's OnPaint() handler.<br>
Should I try putting it somewhere else ??<br>
- This also creates issue with having another control on top of the panel. (catching the mouse clicks etc..) </p>
<p><strong>Any help would be greatly appreciated!</strong></p>
<p>**EDIT:
The black line is a sample of what I was trying to do. (used windows paint to paint it)</p>
<p><img src="https://i73.photobucket.com/albums/i201/sdjc1/temp/screen2.jpg" alt="alt text"></p>
| [
{
"answer_id": 282891,
"author": "asponge",
"author_id": 19449,
"author_profile": "https://Stackoverflow.com/users/19449",
"pm_score": 2,
"selected": false,
"text": "panel.Paint += new PaintEventHandler(panel_Paint);\nbutton.Paint += new PaintEventHandler(button_Paint);\n\nprotected void panel_Paint(object sender, PaintEventArgs e)\n{\n //draw the full line which will then be partially obscured by child controls\n}\n\nprotected void button_Paint(object sender, PaintEventArgs e)\n{\n //draw the obscured line portions on the button\n}\n"
},
{
"answer_id": 283037,
"author": "Matt Brunell",
"author_id": 24970,
"author_profile": "https://Stackoverflow.com/users/24970",
"pm_score": 3,
"selected": false,
"text": "private void label1_Paint(object sender, PaintEventArgs e)\n{\n System.Drawing.Drawing2D.GraphicsPath myGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath();\n myGraphicsPath.AddEllipse(new Rectangle(0, 0, 125, 125));\n myGraphicsPath.AddEllipse(new Rectangle(75, 75, 20, 20));\n myGraphicsPath.AddEllipse(new Rectangle(120, 0, 125, 125));\n myGraphicsPath.AddEllipse(new Rectangle(145, 75, 20, 20));\n //Change the button's background color so that it is easy\n //to see.\n label1.BackColor = Color.ForestGreen;\n label1.Size = new System.Drawing.Size(256, 256);\n label1.Region = new Region(myGraphicsPath);\n}\n"
},
{
"answer_id": 295452,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": " protected override CreateParams CreateParams\n {\n get\n {\n CreateParams cp;\n cp = base.CreateParams;\n cp.Style &= 0x7DFFFFFF; //WS_CLIPCHILDREN\n return cp;\n }\n }\n"
},
{
"answer_id": 297594,
"author": "MusiGenesis",
"author_id": 14606,
"author_profile": "https://Stackoverflow.com/users/14606",
"pm_score": 3,
"selected": false,
"text": "panel1.Paint += PaintPanelOrButton;\nbutton1.Paint += PaintPanelOrButton;\nbutton2.Paint += PaintPanelOrButton;\n"
},
{
"answer_id": 298452,
"author": "Hath",
"author_id": 5186,
"author_profile": "https://Stackoverflow.com/users/5186",
"pm_score": 2,
"selected": false,
"text": "public partial class MainForm : Form\n {\n public MainForm()\n {\n InitializeComponent();\n this.simpleLine1.BringToFront();\n }\n }\n\n\n\nusing System;\nusing System.Windows.Forms;\nusing System.Drawing;\nusing System.Collections.Generic;\n\npublic class SimpleLine : Control\n{\n private Control parentHooked; \n private List<Control> controlsHooked;\n\n public enum LineType\n {\n Horizontal,\n Vertical,\n ForwardsDiagonal,\n BackwardsDiagonal\n }\n\n public event EventHandler AppearanceChanged;\n private LineType appearance;\n public virtual LineType Appearance\n {\n get\n {\n return appearance;\n }\n set\n {\n if (appearance != value)\n {\n this.SuspendLayout();\n switch (appearance)\n {\n case LineType.Horizontal:\n if (value == LineType.Vertical)\n {\n this.Height = this.Width;\n }\n\n break;\n case LineType.Vertical:\n if (value == LineType.Horizontal)\n {\n this.Width = this.Height;\n }\n break;\n }\n this.ResumeLayout(false);\n\n appearance = value;\n this.PerformLayout();\n this.Invalidate();\n }\n }\n }\n protected virtual void OnAppearanceChanged(EventArgs e)\n {\n if (AppearanceChanged != null) AppearanceChanged(this, e);\n }\n\n public event EventHandler LineColorChanged;\n private Color lineColor;\n public virtual Color LineColor\n {\n get\n {\n return lineColor;\n }\n set\n {\n if (lineColor != value)\n {\n lineColor = value;\n this.Invalidate();\n }\n }\n }\n protected virtual void OnLineColorChanged(EventArgs e)\n {\n if (LineColorChanged != null) LineColorChanged(this, e);\n }\n\n public event EventHandler LineWidthChanged;\n private float lineWidth;\n public virtual float LineWidth\n {\n get\n {\n return lineWidth;\n }\n set\n {\n if (lineWidth != value)\n {\n if (0 >= value)\n {\n lineWidth = 1;\n }\n lineWidth = value;\n this.PerformLayout();\n }\n }\n }\n protected virtual void OnLineWidthChanged(EventArgs e)\n {\n if (LineWidthChanged != null) LineWidthChanged(this, e);\n }\n\n public SimpleLine()\n {\n base.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Selectable, false);\n base.SetStyle(ControlStyles.SupportsTransparentBackColor, true);\n base.BackColor = Color.Transparent;\n\n InitializeComponent();\n\n appearance = LineType.Vertical;\n LineColor = Color.Black;\n LineWidth = 1;\n controlsHooked = new List<Control>();\n\n this.ParentChanged += new EventHandler(OnSimpleLineParentChanged);\n }\n\n private void RemoveControl(Control control)\n {\n if (controlsHooked.Contains(control))\n {\n control.Paint -= new PaintEventHandler(OnControlPaint);\n if (control is TextboxX)\n {\n TextboxX text = (TextboxX)control;\n text.DoingAPaint -= new EventHandler(text_DoingAPaint);\n }\n controlsHooked.Remove(control);\n }\n }\n\n void text_DoingAPaint(object sender, EventArgs e)\n {\n this.Invalidate();\n }\n\n private void AddControl(Control control)\n {\n if (!controlsHooked.Contains(control))\n {\n control.Paint += new PaintEventHandler(OnControlPaint);\n if (control is TextboxX)\n {\n TextboxX text = (TextboxX)control;\n text.DoingAPaint += new EventHandler(text_DoingAPaint);\n }\n controlsHooked.Add(control);\n }\n }\n\n private void OnSimpleLineParentChanged(object sender, EventArgs e)\n {\n UnhookParent();\n\n if (Parent != null)\n {\n\n foreach (Control c in Parent.Controls)\n {\n AddControl(c);\n }\n Parent.ControlAdded += new ControlEventHandler(OnParentControlAdded);\n Parent.ControlRemoved += new ControlEventHandler(OnParentControlRemoved);\n parentHooked = this.Parent;\n }\n }\n\n private void UnhookParent()\n {\n if (parentHooked != null)\n {\n foreach (Control c in parentHooked.Controls)\n {\n RemoveControl(c);\n }\n parentHooked.ControlAdded -= new ControlEventHandler(OnParentControlAdded);\n parentHooked.ControlRemoved -= new ControlEventHandler(OnParentControlRemoved);\n parentHooked = null;\n }\n }\n\n private void OnParentControlRemoved(object sender, ControlEventArgs e)\n {\n RemoveControl(e.Control);\n } \n\n private void OnControlPaint(object sender, PaintEventArgs e)\n {\n int indexa =Parent.Controls.IndexOf(this) , indexb = Parent.Controls.IndexOf((Control)sender);\n //if above invalidate on paint\n if(indexa < indexb)\n {\n Invalidate();\n }\n }\n\n private void OnParentControlAdded(object sender, ControlEventArgs e)\n {\n AddControl(e.Control);\n }\n\n private System.ComponentModel.IContainer components = null;\n private void InitializeComponent()\n {\n components = new System.ComponentModel.Container();\n }\n protected override void Dispose(bool disposing)\n {\n if (disposing && (components != null))\n {\n components.Dispose();\n }\n base.Dispose(disposing);\n }\n\n protected override CreateParams CreateParams\n {\n get\n {\n CreateParams cp = base.CreateParams;\n cp.ExStyle |= 0x20; // Turn on WS_EX_TRANSPARENT\n return cp;\n }\n }\n\n protected override void OnLayout(LayoutEventArgs levent)\n {\n switch (this.Appearance)\n {\n case LineType.Horizontal:\n this.Height = (int)LineWidth;\n this.Invalidate();\n break;\n case LineType.Vertical:\n this.Width = (int)LineWidth;\n this.Invalidate();\n break;\n }\n\n base.OnLayout(levent);\n }\n\n protected override void OnPaintBackground(PaintEventArgs pevent)\n {\n //disable background paint\n }\n\n protected override void OnPaint(PaintEventArgs pe)\n {\n switch (Appearance)\n {\n case LineType.Horizontal:\n DrawHorizontalLine(pe);\n break;\n case LineType.Vertical:\n DrawVerticalLine(pe);\n break;\n case LineType.ForwardsDiagonal:\n DrawFDiagonalLine(pe);\n break;\n case LineType.BackwardsDiagonal:\n DrawBDiagonalLine(pe);\n break;\n }\n }\n\n private void DrawFDiagonalLine(PaintEventArgs pe)\n {\n using (Pen p = new Pen(this.LineColor, this.LineWidth))\n {\n pe.Graphics.DrawLine(p, this.ClientRectangle.X, this.ClientRectangle.Bottom,\n this.ClientRectangle.Right, this.ClientRectangle.Y);\n }\n }\n\n private void DrawBDiagonalLine(PaintEventArgs pe)\n {\n using (Pen p = new Pen(this.LineColor, this.LineWidth))\n {\n pe.Graphics.DrawLine(p, this.ClientRectangle.X, this.ClientRectangle.Y,\n this.ClientRectangle.Right, this.ClientRectangle.Bottom);\n }\n }\n\n private void DrawHorizontalLine(PaintEventArgs pe)\n {\n int y = this.ClientRectangle.Height / 2;\n using (Pen p = new Pen(this.LineColor, this.LineWidth))\n {\n pe.Graphics.DrawLine(p, this.ClientRectangle.X, y,\n this.ClientRectangle.Width, y);\n }\n }\n\n private void DrawVerticalLine(PaintEventArgs pe)\n {\n int x = this.ClientRectangle.Width / 2;\n using (Pen p = new Pen(this.LineColor, this.LineWidth))\n {\n pe.Graphics.DrawLine(p,x, this.ClientRectangle.Y,\n x, this.ClientRectangle.Height);\n }\n }\n}\n"
},
{
"answer_id": 316526,
"author": "MusiGenesis",
"author_id": 14606,
"author_profile": "https://Stackoverflow.com/users/14606",
"pm_score": 4,
"selected": false,
"text": "using System.Drawing.Drawing2D;\n"
},
{
"answer_id": 6031104,
"author": "takrl",
"author_id": 520044,
"author_profile": "https://Stackoverflow.com/users/520044",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing System.ComponentModel;\nusing System.ComponentModel.Design;\nusing System.Drawing;\nusing System.Windows.Forms;\nusing System.Windows.Forms.Design;\n\nnamespace WindowsFormsApplication3\n{\n [Designer(\"WindowsFormsApplication3.DecoratedPanelDesigner\")]\n public class DecoratedPanel : Panel\n {\n #region decorationcanvas\n\n // this is an internal transparent panel.\n // This is our canvas we'll draw the lines on ...\n private class DecorationCanvas : Panel\n {\n public DecorationCanvas()\n {\n // don't paint the background\n SetStyle(ControlStyles.Opaque, true);\n }\n\n protected override CreateParams CreateParams\n {\n get\n {\n // use transparency\n CreateParams cp = base.CreateParams;\n cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT\n return cp;\n }\n }\n }\n\n #endregion\n\n private DecorationCanvas _decorationCanvas;\n\n public DecoratedPanel()\n {\n // add our DecorationCanvas to our panel control\n _decorationCanvas = new DecorationCanvas();\n _decorationCanvas.Name = \"myInternalOverlayPanel\";\n _decorationCanvas.Size = ClientSize;\n _decorationCanvas.Location = new Point(0, 0);\n // this prevents the DecorationCanvas to catch clicks and the like\n _decorationCanvas.Enabled = false;\n _decorationCanvas.Paint += new PaintEventHandler(decoration_Paint);\n Controls.Add(_decorationCanvas);\n }\n\n protected override void Dispose(bool disposing)\n {\n if (disposing && _decorationCanvas != null)\n {\n // be a good citizen and clean up after yourself\n\n _decorationCanvas.Paint -= new PaintEventHandler(decoration_Paint);\n Controls.Remove(_decorationCanvas);\n _decorationCanvas = null;\n }\n\n base.Dispose(disposing);\n }\n\n void decoration_Paint(object sender, PaintEventArgs e)\n {\n // --- PAINT HERE ---\n e.Graphics.DrawLine(Pens.Red, 0, 0, ClientSize.Width, ClientSize.Height);\n }\n\n protected override void OnControlAdded(ControlEventArgs e)\n {\n base.OnControlAdded(e);\n\n if (IsInDesignMode)\n return;\n\n // Hook paint event and make sure we stay on top\n if (!_decorationCanvas.Equals(e.Control))\n e.Control.Paint += new PaintEventHandler(containedControl_Paint);\n\n ResetDecorationZOrder();\n }\n\n protected override void OnControlRemoved(ControlEventArgs e)\n {\n base.OnControlRemoved(e);\n\n if (IsInDesignMode)\n return;\n\n // Unhook paint event\n if (!_decorationCanvas.Equals(e.Control))\n e.Control.Paint -= new PaintEventHandler(containedControl_Paint);\n }\n\n /// <summary>\n /// If contained controls are updated, invalidate the corresponding DecorationCanvas area\n /// </summary>\n /// <param name=\"sender\"></param>\n /// <param name=\"e\"></param>\n void containedControl_Paint(object sender, PaintEventArgs e)\n {\n Control c = sender as Control;\n\n if (c == null)\n return;\n\n _decorationCanvas.Invalidate(new Rectangle(c.Left, c.Top, c.Width, c.Height));\n }\n\n protected override void OnResize(EventArgs eventargs)\n {\n base.OnResize(eventargs);\n // make sure we're covering the panel control\n _decorationCanvas.Size = ClientSize;\n }\n\n protected override void OnSizeChanged(EventArgs e)\n {\n base.OnSizeChanged(e);\n // make sure we're covering the panel control\n _decorationCanvas.Size = ClientSize;\n }\n\n /// <summary>\n /// This is marked internal because it gets called from the designer\n /// to make sure our DecorationCanvas stays on top of the ZOrder.\n /// </summary>\n internal void ResetDecorationZOrder()\n {\n if (Controls.GetChildIndex(_decorationCanvas) != 0)\n Controls.SetChildIndex(_decorationCanvas, 0);\n }\n\n private bool IsInDesignMode\n {\n get\n {\n return DesignMode || LicenseManager.UsageMode == LicenseUsageMode.Designtime;\n }\n }\n }\n\n /// <summary>\n /// Unfortunately, the default designer of the standard panel is not a public class\n /// So we'll have to build a new designer out of another one. Since Panel inherits from\n /// ScrollableControl, let's try a ScrollableControlDesigner ...\n /// </summary>\n public class DecoratedPanelDesigner : ScrollableControlDesigner\n {\n private IComponentChangeService _changeService;\n\n public override void Initialize(IComponent component)\n {\n base.Initialize(component);\n\n // Acquire a reference to IComponentChangeService.\n this._changeService = GetService(typeof(IComponentChangeService)) as IComponentChangeService;\n\n // Hook the IComponentChangeService event\n if (this._changeService != null)\n this._changeService.ComponentChanged += new ComponentChangedEventHandler(_changeService_ComponentChanged);\n }\n\n /// <summary>\n /// Try and handle ZOrder changes at design time\n /// </summary>\n /// <param name=\"sender\"></param>\n /// <param name=\"e\"></param>\n void _changeService_ComponentChanged(object sender, ComponentChangedEventArgs e)\n {\n Control changedControl = e.Component as Control;\n if (changedControl == null)\n return;\n\n DecoratedPanel panelPaint = Control as DecoratedPanel;\n\n if (panelPaint == null)\n return;\n\n // if the ZOrder of controls contained within our panel changes, the\n // changed control is our control\n if (Control.Equals(panelPaint))\n panelPaint.ResetDecorationZOrder();\n }\n\n protected override void Dispose(bool disposing)\n {\n if (disposing)\n {\n if (this._changeService != null)\n {\n // Unhook the event handler\n this._changeService.ComponentChanged -= new ComponentChangedEventHandler(_changeService_ComponentChanged);\n this._changeService = null;\n }\n }\n\n base.Dispose(disposing);\n }\n\n /// <summary>\n /// If the panel has BorderStyle.None, a dashed border needs to be drawn around it\n /// </summary>\n /// <param name=\"pe\"></param>\n protected override void OnPaintAdornments(PaintEventArgs pe)\n {\n base.OnPaintAdornments(pe);\n\n Panel panel = Control as Panel;\n if (panel == null)\n return;\n\n if (panel.BorderStyle == BorderStyle.None)\n {\n using (Pen p = new Pen(SystemColors.ControlDark))\n {\n p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;\n pe.Graphics.DrawRectangle(p, 0, 0, Control.Width - 1, Control.Height - 1);\n }\n }\n }\n }\n}\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282838",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36777/"
] |
282,851 | <p>I just read <a href="https://stackoverflow.com/questions/72271/no-newline-at-end-of-file-compiler-warning">this post</a> about why new-line warnings exist, but to be honest my team has people working on several different platforms and with several different editors (everyone uses what bests suites them), so the warning has become ubiquitous, and since its not really a warning worth taking care of it's become noise and makes finding serious warnings a hassle. </p>
<p>Many times important warnings have gone unnoticed because, people got used to having a gazillion useless warnings pass by, so they obviously just stop looking at them carefully, and with reason IMHO. One could say in our case GCC is crying wolf too much for anyone to take it seriously anymore, which is a bad attitude but its just human nature. </p>
<p>Right now we compile with <code>-Wall</code>, because we want warnings, but is there a counter flag to avoid the new-line warnings?</p>
<p><strong>Note:</strong> I Looked through the manual a bit but didn't find the answer in any place obvious so I gave up.</p>
<p><strong>Note:</strong> In response to Robert Gamble's totally reasonable solution, our code is cross-platform and we have people and builds on Linux, Solaris and Windows, so the new-line... is not under consensus. And Somebody's compiler is always going to cry-wolf. Because there are over 40 developers, and other non programmer staff as well.</p>
| [
{
"answer_id": 21864095,
"author": "bames53",
"author_id": 365496,
"author_profile": "https://Stackoverflow.com/users/365496",
"pm_score": 2,
"selected": false,
"text": "-Wno-eof-newline\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282851",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15124/"
] |
282,858 | <p>In standard php or source code based projects we easily keep all of the code in SVN and each developer can checkout their own copy and collaborate on the same code. </p>
<p>When developing a Drupal site however, much of the work is in "setup". Besides the theme and modules you don't really have any "source code". How do you run multiple instances of the same site so developers can all work at the same time yet share their work?</p>
<p>Example Scenario:</p>
<p>We launch an initial version of a Drupal site with content type "X" created. We also initially launch a view on the site that lists all the nodes of type "X" in chronological order. The client starts using the site, add content, menu items etc.</p>
<p>The next release is planned to add user search ability to that view. The setup for that is contained in the database though. We can copy down the production database to our development version to get the latest data while we work on changing the view. During that time however the client can still be updating the site, making our dev database out of sync. When we are ready to push the new view to production, is there an easier way to do it other than manually repeat the steps to set it up on the production install?</p>
| [
{
"answer_id": 414442,
"author": "Stewart Robinson",
"author_id": 47424,
"author_profile": "https://Stackoverflow.com/users/47424",
"pm_score": 5,
"selected": true,
"text": "function ec_install() {\n $ret = array();\n $num = 0;\n while (1) {\n $version = 6000 + $num;\n $funcname = 'ec_update_' . $version;\n if (function_exists($funcname)) {\n $ret[] = $funcname();\n $num++;\n } else {\n break;\n }\n }\nreturn $ret;\n}\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282858",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36780/"
] |
282,859 | <p>I remember from way back at university using a switch with 'binary search' or 'binary switch'. Something like that, My google foo is broken today. Anyway it goes down like this: You define an array of possible options (Strings usually), some magic happens, and those options in the array become the cases in the switch happens. I do remember that they had to be in alphabetical order for this to work. Can you help me remember the magic? Even a name of what I should be looking at would be fantastic.</p>
| [
{
"answer_id": 282869,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 4,
"selected": true,
"text": "public enum Day {\n SUNDAY, MONDAY, TUESDAY, WEDNESDAY, \n THURSDAY, FRIDAY, SATURDAY \n}\n\npublic class EnumTest {\n\n Day day;\n\n public EnumTest(Day day) {\n this.day = day;\n }\n\n public void tellItLikeItIs() {\n switch (day) {\n case MONDAY:\n System.out.println(\"Mondays are bad.\");\n break;\n\n case FRIDAY:\n System.out.println(\"Fridays are better.\");\n break;\n\n case SATURDAY:\n case SUNDAY:\n System.out.println(\"Weekends are best.\");\n break;\n\n default:\n System.out.println(\"Midweek days are so-so.\");\n break;\n }\n }\n\n ....\n}\n"
},
{
"answer_id": 282895,
"author": "Elijah",
"author_id": 33611,
"author_profile": "https://Stackoverflow.com/users/33611",
"pm_score": 0,
"selected": false,
"text": "final int RED = 0;\nfinal int YELLOW = 1;\nfinal int BLUE = 2;\nfinal int GREEN = 3;\n\nString[] colors = new String[] { \"red\", \"yellow\", \"blue\", \"green\" };\n\nswitch (color) {\n case RED:\n System.out.println(colors[RED]);\n break;\n case YELLOW:\n System.out.println(colors[YELLOW]);\n break;\n ...the rest\n}\n"
},
{
"answer_id": 592135,
"author": "Peter Lawrey",
"author_id": 57695,
"author_profile": "https://Stackoverflow.com/users/57695",
"pm_score": 0,
"selected": false,
"text": "public enum Day {\n SUNDAY {\n public String tellItLikeItIs() {\n return \"Weekends are best.\";\n }\n },\n MONDAY {\n public String tellItLikeItIs() {\n return \"Mondays are bad.\";\n }\n }, \n TUESDAY, \n WEDNESDAY, \n THURSDAY, \n FRIDAY {\n public String tellItLikeItIs() {\n return \"TGI Friday.\";\n }\n }, \n SATURDAY {\n public String tellItLikeItIs() {\n return \"Weekends are best.\";\n }\n }\n\n public String tellItLikeItIs() {\n return \"Midweek days are so-so.\";\n }\n}\n\npublic class TodayIs{\n public static void main(String... args) {\n Day day = Day.valueOf(args[0].toUppercase());\n System.out.println(day.tellItLikeItIs());\n }\n}\n"
},
{
"answer_id": 592274,
"author": "XenF",
"author_id": 63972,
"author_profile": "https://Stackoverflow.com/users/63972",
"pm_score": 0,
"selected": false,
"text": "public enum Day {\n SUNDAY (\"sundays are this\"),\n MONDAY (\"mondays are that\"), \n TUESDAY (\"blah\"), \n WEDNESDAY (\"blah\"), \n THURSDAY (\"blah\"), \n FRIDAY (\"blah\"), \n SATURDAY (\"more blah\");\n\n private final String tell;\n\n public Day(String tell){\n this.tell = tell;\n }\n public String tellItLikeItIs() {\n return this.tell;\n }\n}\n\npublic class TodayIs{\n public static void main(String... args) {\n Day day = Day.valueOf(args[0].toUppercase());\n System.out.println(day.tellItLikeItIs());\n"
},
{
"answer_id": 9702319,
"author": "GingerHead",
"author_id": 1358722,
"author_profile": "https://Stackoverflow.com/users/1358722",
"pm_score": 0,
"selected": false,
"text": "switch (day) {\n}\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282859",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3431280/"
] |
282,862 | <p>Is there a way to have a function return a editable reference to some internal data. Here's an example I hope helps show what I mean.</p>
<pre><code>class foo
{
public int value;
}
class bar
{
bar()
{
m_foo = new foo();
m_foo.value = 42;
}
private m_foo;
foo getFoo(){return m_foo;}
}
class main
{
int main()
{
bar b = new bar();
b.getFoo().value = 37;
}
}
</code></pre>
<p>The return of getFoo() according to "==" is the same as the internal m_foo until I try to edit it. In c/c++ I'd return a reference or pointer.</p>
| [
{
"answer_id": 282878,
"author": "jpoh",
"author_id": 4368,
"author_profile": "https://Stackoverflow.com/users/4368",
"pm_score": 0,
"selected": false,
"text": "foo"
},
{
"answer_id": 282880,
"author": "Corey Trager",
"author_id": 9328,
"author_profile": "https://Stackoverflow.com/users/9328",
"pm_score": 3,
"selected": true,
"text": "using System;\n\nnamespace ConsoleApplication1\n{\n public class foo\n {\n public int value;\n };\n\n public class bar\n {\n public bar()\n {\n m_foo = new foo();\n m_foo.value = 42;\n }\n\n private foo m_foo;\n public foo getFoo() { return m_foo; }\n };\n\n public class Program\n {\n public static int Main()\n {\n bar b = new bar();\n b.getFoo().value = 37;\n return 0;\n }\n };\n}\n"
},
{
"answer_id": 282881,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "class bar\n{\n private m_foo;\n bar()\n {\n m_foo = new foo();\n m_foo.value = 42;\n }\n\n\n foo Foo\n {\n get { return m_foo;}\n }\n}\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282862",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36782/"
] |
282,876 | <p>Ok, this is driving me nuts.</p>
<p>I've done just about everything I can to enable step through debugging of stored procedures of a sql server 2005 database.</p>
<p><a href="http://arjunachith.blogspot.com/2007/05/debugging-stored-procedures-debug.html" rel="noreferrer">http://arjunachith.blogspot.com/2007/05/debugging-stored-procedures-debug.html</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/zefbf0t6(vs.71).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/zefbf0t6(vs.71).aspx</a></p>
<p>My currents setup:</p>
<ol>
<li>visual studio 2008 SP1</li>
<li>SQL server 2005 express database (yes you can debug on this)</li>
<li>DEV database on my localmachine with "root" login as sysadmin</li>
</ol>
<p>All I want to do is right click on a stored proc in my server explorer in VS 2008 and see "step into stored procedure". I've done all I can and I can't see that.
I'm just trying to access a local database on my local machine, I've created an account</p>
| [
{
"answer_id": 2385462,
"author": "Sethupathi",
"author_id": 286949,
"author_profile": "https://Stackoverflow.com/users/286949",
"pm_score": 1,
"selected": false,
"text": "Allow SQL/CLR Debugging"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282876",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/750/"
] |
282,883 | <p>We need to start adding internationalisation to our program. Thankfully not the whole thing yet, just a few bits, but I want the way we do it to scale up to potentially cover the whole program. The thing is, our program is based on plugins, so not all strings belong in the same place.</p>
<p>As far as I understand it, Java's <code>ResourceBundle</code> work like this. You create a class that extends <code>ResourceBundle</code>, called something like <code>MyProgramStrings</code>, and also language-specific classes called <code>MyProgramStrings_fr</code>, <code>MyProgramStrings_es</code> etc. Each of these classes maps keys (strings) to values (any object). It's up to each of these classes where to get its data from, but a common place for them is a properties file.</p>
<p>You look up values in two stages: first you get the correct bundle, then you query it for the string you want.</p>
<pre><code>Locale locale = Locale.getDefault(); // or = new Locale("en", "GB");
ResourceBundle rb = ResourceBundle.getBundle("MyProgramStrings", locale);
String wotsitName = rb.getString("wotsit.name");
</code></pre>
<p>However, what we need is to combine the results of several locales into a single resource space. For example, a plugin needs to be able to override a string that's already defined, and have that new value returned whenever code looks up the string.</p>
<p>I'm a little lost in all this. Can anybody help?</p>
<hr>
<p><strong>Update:</strong> David Waters asked:</p>
<blockquote>
<p>I have put my answer at the bottom but I would be interested in hearing how you solved this problem.</p>
</blockquote>
<p>Well, we haven't got very far yet - long term WIBNIs always fall victim to the latest crisis - but we're basing it on the interface that a plugin implements, with the convention that resources have the same fully qualified name as the interface.</p>
<p>So an interface <code>UsersAPI</code> may have various different implementations. A method <code>getBundle()</code> on that interface by default returns the equivalent of <code>ResourceBundle.get("...UsersAPI", locale)</code>. That file can be replaced, or implementations of UsersAPI can override the method if they need something more complicated.</p>
<p>So far that does what we need, but we're still looking at more flexible solutions based on the plugins.</p>
| [
{
"answer_id": 282919,
"author": "matt b",
"author_id": 4249,
"author_profile": "https://Stackoverflow.com/users/4249",
"pm_score": 2,
"selected": false,
"text": "MyProgramStrings"
},
{
"answer_id": 282948,
"author": "Chris Morley",
"author_id": 36034,
"author_profile": "https://Stackoverflow.com/users/36034",
"pm_score": 1,
"selected": false,
"text": "en_US"
},
{
"answer_id": 657553,
"author": "David Waters",
"author_id": 12148,
"author_profile": "https://Stackoverflow.com/users/12148",
"pm_score": 1,
"selected": false,
"text": "package com.example;\n\npublic class UILabels extends ResourceBundle{\n // plugins call this method to register there own resource bundles to override\n public static void addPluginResourceBundle(String bundleName){\n extensionBundles.add(bundleName);\n }\n\n // Find the base Resources via standard Resource loading\n private ResourceBundle getFileResources(){\n return ResourceBundle.getBundle(\"com.example.UILabelsFile\", this.getLocale());\n }\n private ResourceBundle getExtensionResources(String bundleName){\n return ResourceBundle.getBundle(bundleName, this.getLocale());\n }\n\n ...\n protected Object handleGetObject(String key){\n // If there is an extension value use that\n Object extensionValue = getValueFromExtensionBundles(key);\n if(extensionValues != null)\n return extensionValues;\n // otherwise use the one defined in the property files\n return getFileResources().getObject(key);\n }\n\n //Returns the first extension value found for this key, \n //will return null if not found \n //will return the first added if there are multiple.\n private Object getValueFromExtensionBundles(String key){\n for(String bundleName : extensionBundles){\n ResourceBundle rb = getExtensionResources(bundleName);\n Object o = rb.getObject(key);\n if(o != null) return o;\n }\n return null;\n } \n\n}\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282883",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1000/"
] |
282,899 | <p>If you have a particular line of C code in mind to examine in the machine output, how would you locate it in objdump output. Here is an example</p>
<pre><code>if (cond)
foo;
bar();
</code></pre>
<p>and I want to see if bar was inlined as I'd like.
Or would you use some alternative tool instead of objdump?</p>
| [
{
"answer_id": 282934,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 4,
"selected": true,
"text": "-S"
},
{
"answer_id": 3596594,
"author": "rurban",
"author_id": 414279,
"author_profile": "https://Stackoverflow.com/users/414279",
"pm_score": 0,
"selected": false,
"text": " 55 push %ebp\n 89 e5 mov %esp, %ebp\n ...\n c9 leave # optional\n c3 ret\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282899",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30636/"
] |
282,904 | <p>I have this PHP script that I wrote to automatically follow users that post messages with certain terms. It works 100% of the time on a bunch of test accounts but then does not work on the account I'd like to use it with. </p>
<p>I've checked the account's API rate limit and it's well within the boundaries. I've also verified that the username and password are correct. If I change nothing else but the username and password to another account it will work, but when changed back (correctly) to the main account nothing happens. I am totally baffled. Has anyone ever come across this?</p>
<p>I'm including the two files used below. If there's any other info that would be helpful, let me know and I'll provide it if I can. Thanks!</p>
<p>Index.php </p>
<pre><code><?php
$url = "http://search.twitter.com/search.atom?q=SEARCHTERM&show_user=true&rpp=100";
$search = file_get_contents($url);
$regex_name = '/\<name\>(.+?) \(/';
preg_match_all($regex_name,$search,$user);
for($i=0;$user[1][$i];$i++)
{
$follow = $user[1][$i];
include("follow.php");
}
?>
</code></pre>
<p>Follow.php</p>
<pre><code><?php
define('TWITTER_CREDENTIALS', 'username:password');
$url = "http://twitter.com/friendships/create/".$follow.".xml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, TWITTER_CREDENTIALS);
$result= curl_exec ($ch);
curl_close ($ch);
?>
</code></pre>
<p>Quick update on this: Turns out the problem was on Twitter's end--the account in question had tighter than normal API limits imposed for some reason. I'm not marking any responses as the answer since it was a rather idiosyncratic instance.</p>
| [
{
"answer_id": 284875,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "curl_setopt($ch, CURLOPT_VERBOSE, 1);\n"
},
{
"answer_id": 286961,
"author": "Till",
"author_id": 2859,
"author_profile": "https://Stackoverflow.com/users/2859",
"pm_score": 2,
"selected": false,
"text": "<?php\n$url = \"http://search.twitter.com/search.json?q=SEARCHTERM&show_user=true&rpp=100\";\n$search = file_get_contents($url);\nif ($search === false) {\n die('Error occurred.');\n}\n$hits = json_decode($search);\nvar_dump($hits);\n?>\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282904",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30098/"
] |
282,905 | <p>I'm looking for an alternative, since I find emacs difficult to use. I'd rather use an editor that supports all the usual shortcuts I'm used to, such as arrow keys to move the cursor around, CTRL+SHIFT+RightArrow to select the next word, etc.</p>
<p>Basically, I don't want to have to relearn all my familiar shortcuts just so I can use emacs.</p>
<p>Can anyone recommend a suitable editor?</p>
<p>Another thing - Notepad++ supports LISP syntax coloring, but it doesn't have an integrated LISP console like emacs does. Would it be fine to just have a Notepad++ window and a Command Line window open, side-by-side, and use the command-line whenever I want to run my program?</p>
| [
{
"answer_id": 293255,
"author": "Charlie Martin",
"author_id": 35092,
"author_profile": "https://Stackoverflow.com/users/35092",
"pm_score": 1,
"selected": false,
"text": ":set ai lisp aw\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282905",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23341/"
] |
282,907 | <p>I'm going to try out turbogears however I'm on windows vista.
however due to firewall proxy problems, it seems i can't download .egg files which is required for setup turbogears to get installed in my windows environment.
I do have a bootable, or I can make a bootable Linux USB, I can try cygwin but I am not sure where to start with cygwin, so I was wondering what would solve my firewall / proxy problem of installing something like turbogears.</p>
<p>if it's possible, is there some non-online version of turbogears that i could just download from visiting a site and then somehow importing that non-online version into my python environment?</p>
<p>thanks so much!:)</p>
| [
{
"answer_id": 283174,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://Stackoverflow.com/users/6491",
"pm_score": 2,
"selected": false,
"text": "tgsetup.py"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1345527/"
] |
282,916 | <p>I am extremely new at php and I was wondering if someone could help me use either a <code>for()</code> or <code>while()</code> loop to create an array of 10 elements.</p>
| [
{
"answer_id": 282917,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 5,
"selected": false,
"text": "$array = array();\n$array2 = array();\n\n// for example\nfor ($i = 0; $i < 10; ++$i) {\n $array[] = 'new element';\n}\n\n// while example\nwhile (count($array2) < 10 ) {\n $array2[] = 'new element';\n}\n\nprint \"For: \".count($array).\"<br />\";\nprint \"While: \".count($array2).\"<br />\";\n"
},
{
"answer_id": 282951,
"author": "alex",
"author_id": 31671,
"author_profile": "https://Stackoverflow.com/users/31671",
"pm_score": 4,
"selected": false,
"text": "for"
},
{
"answer_id": 282964,
"author": "John T",
"author_id": 36457,
"author_profile": "https://Stackoverflow.com/users/36457",
"pm_score": 3,
"selected": false,
"text": "<?php\n\n\n// for loop\nfor ($i = 0; $i < 10; $i++) {\n\n$myArray[$i] = \"This is element \".$i.\" in the array\";\n\necho $myArray[$i];\n\n}\n\n\n//while loop\n$x = 0;\n\nwhile ($x < 10) {\n\n$someArray[$x] = \"This is element \".$x.\" in the array\";\n\necho $someArray[$x];\n\n$x++;\n}\n\n?>\n"
},
{
"answer_id": 373721,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 2,
"selected": false,
"text": "$arr = array();\nfor ($i = 0; $i < 10; ++$i) {\n $arr[] = \"Element $i\";\n}\n"
},
{
"answer_id": 373722,
"author": "too much php",
"author_id": 28835,
"author_profile": "https://Stackoverflow.com/users/28835",
"pm_score": 1,
"selected": false,
"text": "array_fill()"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282916",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
282,938 | <p>What is the best way to give the user feedback for a color selection?<br>
I have a dialog with a "Select Color" push button which pops a <code>QColorDialog</code>. After the selection is made I want to show the user the color selected.<br>
Usually I do this using a <code>QLabel</code> and changing it's background color in the palette. This method is cumbersome and I think not very portable. </p>
<p>Is there a standard way of doing this?</p>
| [
{
"answer_id": 283262,
"author": "Jérôme",
"author_id": 2796,
"author_profile": "https://Stackoverflow.com/users/2796",
"pm_score": 3,
"selected": false,
"text": "const QString COLOR_STYLE(\"QPushButton { background-color : %1; color : %2; }\");\n\nQColor ChosenColor; // Color chosen by the user with QColorDialog\nQColor IdealTextColor = getIdealTextColor(ChosenColor);\nbtnChooseColor->setStyleSheet(COLOR_STYLE.arg(ChosenColor.name()).arg(IdealTextColor.name()));\n"
},
{
"answer_id": 9770748,
"author": "Shihe Zhang",
"author_id": 1278112,
"author_profile": "https://Stackoverflow.com/users/1278112",
"pm_score": 2,
"selected": false,
"text": "QColor chosenColor = QColorDialog::getColor(); //return the color chosen by user\nsetColorButton->setBackgroundColor(chosenColor);\nsetColorButton->setAutoFillBackground(true);\nsetColorButton->setFlat(true);\n"
},
{
"answer_id": 13147946,
"author": "Tim MB",
"author_id": 794283,
"author_profile": "https://Stackoverflow.com/users/794283",
"pm_score": 0,
"selected": false,
"text": "QPalette p;\np.setColor(QPalette::Button, color);\ngColorButton->setPalette(p);\n"
},
{
"answer_id": 17033643,
"author": "Ben Gates",
"author_id": 1546639,
"author_profile": "https://Stackoverflow.com/users/1546639",
"pm_score": 2,
"selected": false,
"text": "paintEvent"
},
{
"answer_id": 17039760,
"author": "Pavel Strakhov",
"author_id": 344347,
"author_profile": "https://Stackoverflow.com/users/344347",
"pm_score": 2,
"selected": false,
"text": "QPixmap pixmap(16, 16);\npixmap.fill(color);\nlabel->setPixmap(pixmap);\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282938",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9611/"
] |
282,943 | <p>Does anyone have a good way of implementing something like a sequence in SQL server?</p>
<p>Sometimes you just don't want to use a GUID, besides the fact that they are ugly as heck. Maybe the sequence you want isn't numeric? Besides, inserting a row and then asking the DB what the number is just seems so hackish.</p>
| [
{
"answer_id": 282958,
"author": "Corey Trager",
"author_id": 9328,
"author_profile": "https://Stackoverflow.com/users/9328",
"pm_score": 3,
"selected": false,
"text": "BEGIN TRANSACTION \nSELECT number from plain old table.. \nUPDATE plain old table, set the number to be the next number \nINSERT your row \nCOMMIT \n"
},
{
"answer_id": 283013,
"author": "MusiGenesis",
"author_id": 14606,
"author_profile": "https://Stackoverflow.com/users/14606",
"pm_score": 0,
"selected": false,
"text": "row[\"ID\"] = Guid.NewGuid();\n"
},
{
"answer_id": 8465306,
"author": "sqljunkieshare",
"author_id": 1092386,
"author_profile": "https://Stackoverflow.com/users/1092386",
"pm_score": 6,
"selected": false,
"text": "SEQUENCE"
},
{
"answer_id": 12784166,
"author": "Trident D'Gao",
"author_id": 139667,
"author_profile": "https://Stackoverflow.com/users/139667",
"pm_score": 2,
"selected": false,
"text": "CREATE TABLE [SEQUENCE](\n [NAME] [varchar](100) NOT NULL,\n [NEXT_AVAILABLE_ID] [int] NOT NULL,\n CONSTRAINT [PK_SEQUENCES] PRIMARY KEY CLUSTERED \n(\n [NAME] ASC\n)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]\n) ON [PRIMARY]\nGO\n\nCREATE PROCEDURE CLAIM_IDS (@sequenceName varchar(100), @howMany int)\nAS\nBEGIN\n DECLARE @result int\n update SEQUENCE\n set\n @result = NEXT_AVAILABLE_ID,\n NEXT_AVAILABLE_ID = NEXT_AVAILABLE_ID + @howMany\n where Name = @sequenceName\n Select @result as AVAILABLE_ID\nEND\nGO\n"
},
{
"answer_id": 14483178,
"author": "James Cane",
"author_id": 2004450,
"author_profile": "https://Stackoverflow.com/users/2004450",
"pm_score": 2,
"selected": false,
"text": "CREATE SEQUENCE\n"
},
{
"answer_id": 18496977,
"author": "Georgios Syngouroglou",
"author_id": 1123501,
"author_profile": "https://Stackoverflow.com/users/1123501",
"pm_score": 2,
"selected": false,
"text": "CREATE TABLE Sequences ( \n name VARCHAR(30) NOT NULL, \n value BIGINT DEFAULT 0 NOT NULL, \n CONSTRAINT PK_Sequences PRIMARY KEY (name) \n);\n"
},
{
"answer_id": 27392196,
"author": "Vladimir Baranov",
"author_id": 4116017,
"author_profile": "https://Stackoverflow.com/users/4116017",
"pm_score": 4,
"selected": false,
"text": "SEQUENCE"
},
{
"answer_id": 39758519,
"author": "Tony L.",
"author_id": 3347858,
"author_profile": "https://Stackoverflow.com/users/3347858",
"pm_score": 2,
"selected": false,
"text": "CREATE SEQUENCE Schema.SequenceName\nAS int\nINCREMENT BY 1 ;\n"
},
{
"answer_id": 46861232,
"author": "daniele3004",
"author_id": 3467532,
"author_profile": "https://Stackoverflow.com/users/3467532",
"pm_score": 0,
"selected": false,
"text": "CREATE SEQUENCE [dbo].[SequenceFile]\nAS int\nSTART WITH 1\nINCREMENT BY 1 ;\n"
},
{
"answer_id": 48432763,
"author": "mike",
"author_id": 3175487,
"author_profile": "https://Stackoverflow.com/users/3175487",
"pm_score": 0,
"selected": false,
"text": "--it is used like this:\n-- use the sequence in either insert or select:\nInsert into MyTable Values (NextVal('MySequence'), 'Foo');\n\nSELECT NextVal('MySequence');\n\n--you can make as many sequences as you want, by name:\nSELECT NextVal('Mikes Other Sequence');\n\n--or a blank sequence identifier\nSELECT NextVal('');\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282943",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3453/"
] |
282,968 | <p>I need to write some Prolog programs for a class.</p>
<p>Any recommendations?</p>
| [
{
"answer_id": 10800170,
"author": "Karl Adler",
"author_id": 1059828,
"author_profile": "https://Stackoverflow.com/users/1059828",
"pm_score": 2,
"selected": false,
"text": "% swipl\n?- emacs.\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282968",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30626/"
] |
282,977 | <p>Suppose that I have a Java class with a static method, like so:</p>
<pre>
class A
{
static void foo()
{
// Which class invoked me?
}
}
</pre>
<p>And suppose further that class A has an arbitrary number of subclasses:</p>
<pre>
class B extends A { }
class C extends A { }
class D extends A { }
...
</pre>
<p>Now consider the following method invocations:</p>
<pre>
A.foo();
B.foo();
C.foo();
D.foo();
...
</pre>
<p>My question is, how can method <code>foo()</code> tell which class is invoking it?</p>
| [
{
"answer_id": 283008,
"author": "Daniel Spiewak",
"author_id": 9815,
"author_profile": "https://Stackoverflow.com/users/9815",
"pm_score": 4,
"selected": true,
"text": "A.foo()"
},
{
"answer_id": 283518,
"author": "Georgy Bolyuba",
"author_id": 4052,
"author_profile": "https://Stackoverflow.com/users/4052",
"pm_score": 2,
"selected": false,
"text": "class A\n{\n static void foo(A whoIsCalingMe)\n {\n // Which class invoked me?\n }\n}\n"
},
{
"answer_id": 283823,
"author": "alasdairg",
"author_id": 15768,
"author_profile": "https://Stackoverflow.com/users/15768",
"pm_score": 2,
"selected": false,
"text": "static void foo()\n{\n Throwable t = new Throwable();\n StackTraceElement[] trace = t.getStackTrace();\n String className = trace[1].getClassName();\n Class whoCalledMe = null;\n try\n {\n whoCalledMe = Class.forName( className );\n }\n catch( Exception e )\n {\n }\n}\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282977",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36794/"
] |
282,983 | <p>I'm following several tutorials and references trying to get my kernel set up. I've come across some unfamiliar code in a tutorial that isn't explaining it at all. It's code that I'm told maps the <code>16 IRQs (0-15)</code> to ISR locations <code>32-47</code>:</p>
<pre><code>void irq_remap(void)
{
outportb(0x20, 0x11);
outportb(0xA0, 0x11);
outportb(0x21, 0x20);
outportb(0xA1, 0x28);
outportb(0x21, 0x04);
outportb(0xA1, 0x02);
outportb(0x21, 0x01);
outportb(0xA1, 0x01);
outportb(0x21, 0x0);
outportb(0xA1, 0x0);
}
</code></pre>
<p>The code for <code>outportb()</code> is as follows, but I already have a clear grasp of what its doing:</p>
<pre><code>void outPortB(unsigned short port, unsigned char data)
{
__asm__ __volatile__ ("outb %1, %0" : : "dN" (port), "a" (data));
}
</code></pre>
<p>I should mention that this is on x86 architecture in protected mode. This source code works fine and I understand what it does, but I don't understand how it does it. Can someone explain to me what's going on here, so that in case I need to expand on this I will know what I'm doing?</p>
| [
{
"answer_id": 283033,
"author": "Evan Teran",
"author_id": 13430,
"author_profile": "https://Stackoverflow.com/users/13430",
"pm_score": 5,
"selected": true,
"text": "outb"
},
{
"answer_id": 3604425,
"author": "Mike Gonta",
"author_id": 430125,
"author_profile": "https://Stackoverflow.com/users/430125",
"pm_score": 1,
"selected": false,
"text": "PIC"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282983",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19521/"
] |
282,984 | <p>Consider two tables transaction and category each having their own ID and information.</p>
<p>A transaction can have more than one category, I have read creating a 3rd table to link transaction and category using their IDs is best. But what would you call this table, assuming you would have many like it?</p>
<p>transactionCategories is the best I'm coming up with, is there anything better?</p>
| [
{
"answer_id": 282994,
"author": "WW.",
"author_id": 14663,
"author_profile": "https://Stackoverflow.com/users/14663",
"pm_score": 3,
"selected": true,
"text": "student_class"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282984",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34435/"
] |
282,992 | <p>Of course, the immediate answer for most situations is <strong>"yes"</strong>, and I am a firm believer that a process should correctly cleanup any resources it has allocated, but what I have in my situation is a long-running system daemon that opens a fixed number of file descriptors at the startup, and closes them all before exiting.</p>
<p>This is an embedded platform, and I'm trying to make the code as compact as possible, while not introducing any bad style. But since file descriptors are closed before exit anyway, does this file descriptor cleanup code serve any purpose? Do you always close all your file descriptors?</p>
| [
{
"answer_id": 283002,
"author": "Evan Teran",
"author_id": 13430,
"author_profile": "https://Stackoverflow.com/users/13430",
"pm_score": 2,
"selected": false,
"text": "....\nAll open stdio(3) streams are flushed and closed. Files created by tmpfile(3) are removed.\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282992",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23643/"
] |
282,993 | <p>I'd like to give customers a choice of the database engine, but also want to minimize my troubles of such a decision.<br>
The engines in question are MySQL (5 or later) and SQL Server (2005 or later).</p>
| [
{
"answer_id": 283074,
"author": "MusiGenesis",
"author_id": 14606,
"author_profile": "https://Stackoverflow.com/users/14606",
"pm_score": 2,
"selected": false,
"text": "SELECT [ORDER], [Why This Name] FROM [Table From Hell]\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/282993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28098/"
] |
283,004 | <p>I'm building an ORM library with reuse and simplicity in mind; everything goes fine except that I got stuck by a stupid inheritance limitation. Please consider the code below:</p>
<pre><code>class BaseModel {
/*
* Return an instance of a Model from the database.
*/
static public function get (/* varargs */) {
// 1. Notice we want an instance of User
$class = get_class(parent); // value: bool(false)
$class = get_class(self); // value: bool(false)
$class = get_class(); // value: string(9) "BaseModel"
$class = __CLASS__; // value: string(9) "BaseModel"
// 2. Query the database with id
$row = get_row_from_db_as_array(func_get_args());
// 3. Return the filled instance
$obj = new $class();
$obj->data = $row;
return $obj;
}
}
class User extends BaseModel {
protected $table = 'users';
protected $fields = array('id', 'name');
protected $primary_keys = array('id');
}
class Section extends BaseModel {
// [...]
}
$my_user = User::get(3);
$my_user->name = 'Jean';
$other_user = User::get(24);
$other_user->name = 'Paul';
$my_user->save();
$other_user->save();
$my_section = Section::get('apropos');
$my_section->delete();
</code></pre>
<p>Obviously, this is not the behavior I was expecting (although the actual behavior also makes sense).. So my question is if you guys know of a mean to get, in the parent class, the name of child class.</p>
| [
{
"answer_id": 283094,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 8,
"selected": true,
"text": "debug_backtrace()"
},
{
"answer_id": 283148,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "class BaseModel\n{\n\n public function get () {\n echo get_class($this);\n\n }\n\n public static function instance () {\n static $Instance;\n if ($Instance === null) {\n $Instance = new self;\n\n }\n return $Instance;\n }\n}\n\nclass User\nextends BaseModel\n{\n public static function instance () {\n static $Instance;\n if ($Instance === null) {\n $Instance = new self;\n\n }\n return $Instance;\n }\n}\n\nclass SpecialUser\nextends User\n{\n public static function instance () {\n static $Instance;\n if ($Instance === null) {\n $Instance = new self;\n\n }\n return $Instance;\n }\n}\n\n\nBaseModel::instance()->get(); // value: BaseModel\nUser::instance()->get(); // value: User\nSpecialUser::instance()->get(); // value: SpecialUser\n"
},
{
"answer_id": 283698,
"author": "Tom Haigh",
"author_id": 22224,
"author_profile": "https://Stackoverflow.com/users/22224",
"pm_score": 2,
"selected": false,
"text": "BaseModel::get('User', 1);\n"
},
{
"answer_id": 292268,
"author": "Preston",
"author_id": 25213,
"author_profile": "https://Stackoverflow.com/users/25213",
"pm_score": 0,
"selected": false,
"text": "get_row_from_db_as_array()"
},
{
"answer_id": 1166592,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 8,
"selected": false,
"text": "get_class($this);\n"
},
{
"answer_id": 3033031,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "<?php\n\nclass Base \n{\n public static function find($id)\n {\n $table = static::$_table;\n $class = static::getClass();\n // $data = find_row_data_somehow($table, $id);\n $data = array('table' => $table, 'id' => $id);\n return new $class($data);\n }\n\n public function __construct($data)\n {\n echo get_class($this) . ': ' . print_r($data, true) . PHP_EOL;\n }\n}\n\nclass User extends Base\n{\n protected static $_table = 'users';\n\n public static function getClass()\n {\n return __CLASS__;\n }\n}\n\nclass Image extends Base\n{\n protected static $_table = 'images';\n\n public static function getClass()\n {\n return __CLASS__;\n }\n}\n\n$user = User::find(1); // User: Array ([table] => users [id] => 1) \n$image = Image::find(5); // Image: Array ([table] => images [id] => 5)\n"
},
{
"answer_id": 4728770,
"author": "lo_fye",
"author_id": 3407,
"author_profile": "https://Stackoverflow.com/users/3407",
"pm_score": 0,
"selected": false,
"text": "class Base \n{\n public static function find($id)\n {\n $table = static::$_table;\n $class = static::$_class;\n $data = array('table' => $table, 'id' => $id);\n return new $class($data);\n }\n}\n\nclass User extends Base\n{\n public static $_class = 'User';\n}\n"
},
{
"answer_id": 49847054,
"author": "Joas",
"author_id": 8837781,
"author_profile": "https://Stackoverflow.com/users/8837781",
"pm_score": 5,
"selected": false,
"text": "static"
},
{
"answer_id": 53981934,
"author": "Engr Syed Rowshan Ali",
"author_id": 10270165,
"author_profile": "https://Stackoverflow.com/users/10270165",
"pm_score": 4,
"selected": false,
"text": "get_class()"
},
{
"answer_id": 72047605,
"author": "Syamlal",
"author_id": 6176681,
"author_profile": "https://Stackoverflow.com/users/6176681",
"pm_score": 0,
"selected": false,
"text": "class_basename($this)"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/283004",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36797/"
] |
283,024 | <p>Is it possible to free memory allocated by C's alloca() explicitly, before the current function exits? If so,how?</p>
| [
{
"answer_id": 283039,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 4,
"selected": false,
"text": "alloca"
},
{
"answer_id": 29658582,
"author": "Michael",
"author_id": 543873,
"author_profile": "https://Stackoverflow.com/users/543873",
"pm_score": 2,
"selected": false,
"text": "int some_function(int n) {\n // n has the desired length of the array\n ...\n { // new scope\n int arr[n]; // instead of int *arr = alloca(n*sizeof(int));\n // do stuff with array\n }\n // function continues with arr deallocated\n ...\n}\n"
},
{
"answer_id": 38216454,
"author": "Luke Lee",
"author_id": 3818556,
"author_profile": "https://Stackoverflow.com/users/3818556",
"pm_score": 1,
"selected": false,
"text": "#include <stdio.h>\n#include <alloca.h>\n\nint main()\n{\n unsigned long p0, p1, p2;\n p0=(unsigned long)alloca(0);\n p1=(unsigned long)alloca((size_t) 0x1000);\n p2=(unsigned long)alloca((size_t)-0x1000);\n printf( \"p0=%lX, p1=%lX, p2=%lX\\n\", p0, p1, p2 );\n return 0;\n}\n"
},
{
"answer_id": 65277398,
"author": "MuAlphaOmegaEpsilon",
"author_id": 14346683,
"author_profile": "https://Stackoverflow.com/users/14346683",
"pm_score": -1,
"selected": false,
"text": "freea(...)"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/283024",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23903/"
] |
283,027 | <p>I am working on a WPF application that opens and displays XPS documents. When the application closes, the specification is the application should delete the opened XPS document for clean up. However, when opening a certain XPS document, the application throws an exception that the file is still in use when it tries to delete it. It is a little weird because it only happens when opening a particular XPS document and only when you have moved beyond the first page. </p>
<p>Some of the codes I used are shown below:</p>
<p>For opening the XPS Document:</p>
<pre><code>DocumentViewer m_documentViewer = new DocumentViewer();
XpsDocument m_xpsDocument = new XpsDocument(xpsfilename, fileaccess);
m_documentViewer.Document = m_xpsDocument.GetFixedDocumentSequence();
m_xpsDocument.Close();
</code></pre>
<p>For navigating the XPS document:</p>
<pre><code>m_documentViewer.FirstPage();
m_documentViewer.LastPage();
m_documentViewer.PreviousPage();
m_documentViewer.NextPage();
</code></pre>
<p>For closing the DocumentViewer object and deleting the file:</p>
<pre><code>m_documentViewer.Document = null;
m_documentViewer = null;
File.Delete(xpsfilename);
</code></pre>
<p>It's all pretty basic and it works with the other documents that we tested. But with the particular XPS document, an exception pops up saying that the file to be deleted is still being used. </p>
<p>Is there something wrong or missing from my code? </p>
<p>Thanks!</p>
| [
{
"answer_id": 1370213,
"author": "Tim Erickson",
"author_id": 8787,
"author_profile": "https://Stackoverflow.com/users/8787",
"pm_score": 3,
"selected": false,
"text": "var myXpsFile = @\"c:\\path\\to\\My XPS File.xps\";\nvar myXpsDocument = new XpsDocument(myXpsFile);\nMyDocumentViewer.Document = myXpsDocument;\n\n//open MyDocumentViwer's Window and then close it\n//NOTE: at this point your DocumentViewer still has a lock on your XPS file\n//even if you Close() it\n//but we need to do something else instead\n\n//Get the Uri from which the system opened the XpsPackage and so your XpsDocument\nvar myXpsUri = myXpsDocument.Uri; //should point to the same file as myXpsFile\n\n//Get the XpsPackage itself\nvar theXpsPackage = System.IO.Packaging.PackageStore.GetPackage(myXpsUri);\n\n//THIS IS THE KEY!!!! close it and make it let go of it's file locks\ntheXpsPackage.Close();\n\nFile.Delete(myXpsFile); //this should work now\n\n//if you don't remove the package from the PackageStore, you won't be able to\n//re-open the same file again later (due to System.IO.Packaging's Package store/caching\n//rather than because of any file locks)\nSystem.IO.Packaging.PackageStore.RemovePackage(myXpsUri);\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/283027",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
283,032 | <p>I am using UIActivityIndicatorView to showing user that there is something going on, let them wait. But UIActivityIndicatorView looks small, do not have background color, and not very obvious to the user. While in iPhone SDK's UIImagePickerController, it uses the similar mechanism, but with the black background as well as some text besides the indicator.</p>
<p>I am wondering whether there is any existing component to do that task, or I have to implement my own class to perform that task.</p>
<p>Any suggestion are highly welcome, thanks in advance.</p>
| [
{
"answer_id": 283119,
"author": "leonho",
"author_id": 30883,
"author_profile": "https://Stackoverflow.com/users/30883",
"pm_score": 4,
"selected": false,
"text": "[activityIndicator setBackgroundColor:[UIColor blackColor]];\n"
},
{
"answer_id": 20995452,
"author": "Rajesh Loganathan",
"author_id": 2611413,
"author_profile": "https://Stackoverflow.com/users/2611413",
"pm_score": 3,
"selected": false,
"text": "UIActivityIndicatorView *activityIndicator= [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];\nactivityIndicator.layer.cornerRadius = 05;\nactivityIndicator.opaque = NO;\nactivityIndicator.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.6f];\nactivityIndicator.center = self.view.center;\nactivityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;\n[activityIndicator setColor:[UIColor colorWithRed:0.6 green:0.8 blue:1.0 alpha:1.0]];\n[self.view addSubview: activityIndicator];\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/283032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32096/"
] |
283,035 | <p>I have a Windows application (VS2005/C#) which comes in two versions, Enterprise and Pro. In the Pro version, some of the features and menus are disabled. Currently, I'm doing this by commenting out the disabling code to create the Enterprise version, then I copy each executable file to another location. Obviously this process is fraught with peril... :)</p>
<p>I would like to have two folders for my two executable files, and visual studio should put the code to disable the features in the pro version, and put each in their correct folders. I have installer projects that would pick up the files from there and make the installers for the two versions. That part is already working, but I'm manually copying the two executables into the right folders before I build the installers. So it sucks...</p>
<p>What I'd like to do is something like this:</p>
<pre><code>#ifdef PROVERSION
part1.disable();
part2.disable();
#endif
</code></pre>
<p>Is this possible with Visual studio???</p>
<p>Note, my overall goal is to automate the process of creating the two installers.</p>
| [
{
"answer_id": 283097,
"author": "Jeff Donnici",
"author_id": 821,
"author_profile": "https://Stackoverflow.com/users/821",
"pm_score": 0,
"selected": false,
"text": "enum LicenseLevel {\n Eval = 0,\n Pro = 1,\n Enterprise = 2\n}\n\n// later... \n\nfor(i=0; i < widgets.Count; i++) {\n if (i == 100 && CurrentUser.LicenseLevel < LicenseLevel.Enterprise)\n break;\n // do stuff\n}\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/283035",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5255/"
] |
283,045 | <p>I need help writing the following method:</p>
<pre><code>def get_new_location(current_location, target_location, distance_travelled):
...
...
return new_location
</code></pre>
<p>where all locations are (lat,long)</p>
<p>I realize that there are different models for the earth (WGS-84, GRS-80, ...) which take into account the fact that the earth is an ellipsoid. For my purposes, this level of precision is not necessary, assuming a perfect sphere is good enough.</p>
<p><strong>UPDATE</strong></p>
<p>I'm fine tuning my question taking into account some of the responses.</p>
<p><code>benjismith</code> argues that my question cannot be answered because there is more than one shortest path between points on the globe. He has a lot of backing in the form of votes, so I guess there's something I don't understand, because I disagree.</p>
<blockquote>
<p>The midpoint between any two locations
on a sphere is a circular arc.</p>
</blockquote>
<p>I concede that this is true when two points are at complete opposites. By this I mean that both points, while remaining on the surface of the sphere, could not be any further away from each other. In this case there are infinite number of equidistant paths joining both points. This, however, is an edge case, not the rule. In all other cases, the vast majority of cases, there is a single shortest path.</p>
<p>To illustrate: if you were to hold a string which passed through two points, and pulled it tight, would there not be only one possible path on which the string would settle (except the edge case already discussed)?</p>
<p>Now, prior to asking the question, obtaining the distance between two points and the heading was not a problem.</p>
<p>I guess what I should have asked is if the following is valid:</p>
<pre><code>def get_new_location(current_location, target_location, percent_traveled):
new_location.lon = (1-percent_traveled)*current_location.lon+percent_traveled*target_location.lon
new_location.lat = (1-percent_traveled)*current_location.lat+percent_traveled*target_location.lat
return new_location
</code></pre>
<p>If I were to follow this path, would I be following the great-circle, the rhumb line, ... or would I be completely off?
(I know these terms now because of Drew Hall's answer.)</p>
| [
{
"answer_id": 290674,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 2,
"selected": false,
"text": "def get_new_location(current_location, target_location, percent_traveled):\n # convert locations into cartiesian co-ordinates\n current_vector = location_to_vector(current_location)\n target_vector = location_to_vector(target_location)\n # compute the angle between current_vector and target_vector\n complete_angle = acos(vector_dot_product(current_vector, target_vector))\n # determine the current partial angle, based on percent_traveled\n partial_angle = percent_traveled*complete_angle\n # compute a temporary vector to simplify calculation\n temporary_vector = vector_cross_product(current_vector, target_vector)\n temporary_vector = vector_cross_product(current_vector, temporary_vector)\n # calculate new_vector\n scalar_one = cos(partial_angle)\n scalar_two = -sin(partial_angle)/sin(complete_angle)\n vector_one = vector_multiply_by_scalar(scalar_one, current_vector)\n vector_two = vector_multiply_by_scalar(scalar_two, temporary_vector)\n new_vector = vector_sum(vector_one, vector_two)\n # convert new_vector back into latitude & longitude and return\n new_location = vector_to_location(new_vector)\n return new_location"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/283045",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20498/"
] |
283,061 | <p>My installation of APEX has come pear shaped on a Oracle 9.2.0.5.0 instance, all the packages are invalid.</p>
<p>I've tried recompiling everything with DBMS_UTILITY.compile_schema, but still all the packages are invalid. So, tried recompiling individual packages,</p>
<pre><code>SQL> ALTER PACKAGE FLOWS_020000.WWV_FLOW_QUERY COMPILE BODY;
Warning: Package Body altered with compilation errors.
SQL> show err
No errors.
SQL>
SQL> ALTER PACKAGE FLOWS_020000.WWV_FLOW_QUERY COMPILE;
Warning: Package altered with compilation errors.
SQL> show err
No errors.
SQL>
</code></pre>
<p>nothing in the alter log for it..</p>
<p>How can I find what the error is? shouldn't "show err" give it to me?</p>
| [
{
"answer_id": 283085,
"author": "Gary Myers",
"author_id": 25714,
"author_profile": "https://Stackoverflow.com/users/25714",
"pm_score": 2,
"selected": false,
"text": "SHOW ERRORS PACKAGE BODY FLOWS_020000.WWV_FLOW_QUERY\n"
},
{
"answer_id": 283118,
"author": "WW.",
"author_id": 14663,
"author_profile": "https://Stackoverflow.com/users/14663",
"pm_score": 2,
"selected": false,
"text": "SHOW ERRORS PACKAGE FLOWS_020000.WWV_FLOW_QUERY\n"
},
{
"answer_id": 283288,
"author": "cagcowboy",
"author_id": 19629,
"author_profile": "https://Stackoverflow.com/users/19629",
"pm_score": 3,
"selected": false,
"text": "SELECT *\nFROM ALL_ERRORS\nWHERE OWNER = USER;\n"
},
{
"answer_id": 885872,
"author": "Jamie Love",
"author_id": 27308,
"author_profile": "https://Stackoverflow.com/users/27308",
"pm_score": 0,
"selected": false,
"text": "alter package XXX.my_package compile body;\n"
},
{
"answer_id": 16692963,
"author": "yellowvamp04",
"author_id": 2409724,
"author_profile": "https://Stackoverflow.com/users/2409724",
"pm_score": 4,
"selected": false,
"text": "ALTER PACKAGE your_package_name_here COMPILE PACKAGE;\n\nALTER PACKAGE your_package_name_here COMPILE BODY;\n"
},
{
"answer_id": 72813414,
"author": "Rahulkumar",
"author_id": 9107405,
"author_profile": "https://Stackoverflow.com/users/9107405",
"pm_score": 2,
"selected": false,
"text": "SQL> ALTER PACKAGE OWNER.PACKAGE COMPILE BODY;\n\nWarning: Package Body altered with compilation errors.\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/283061",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3839/"
] |
283,063 | <p>Given the following simple example:</p>
<pre><code> List<string> list = new List<string>() { "One", "Two", "Three", "three", "Four", "Five" };
CaseInsensitiveComparer ignoreCaseComparer = new CaseInsensitiveComparer();
var distinctList = list.Distinct(ignoreCaseComparer as IEqualityComparer<string>).ToList();
</code></pre>
<p>It appears the CaseInsensitiveComparer is not actually being used to do a case-insensitive comparison. </p>
<p>In other words <strong>distinctList</strong> contains the same number of items as <strong>list</strong>. Instead I would expect, for example, "Three" and "three" be considered equal.</p>
<p>Am I missing something or is this an issue with the Distinct operator?</p>
| [
{
"answer_id": 283188,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 9,
"selected": true,
"text": "StringComparer"
},
{
"answer_id": 283189,
"author": "Ash",
"author_id": 5023,
"author_profile": "https://Stackoverflow.com/users/5023",
"pm_score": 3,
"selected": false,
"text": "class IgnoreCaseComparer : IEqualityComparer<string>\n{\n public CaseInsensitiveComparer myComparer;\n\n public IgnoreCaseComparer()\n {\n myComparer = CaseInsensitiveComparer.DefaultInvariant;\n }\n\n public IgnoreCaseComparer(CultureInfo myCulture)\n {\n myComparer = new CaseInsensitiveComparer(myCulture);\n }\n\n #region IEqualityComparer<string> Members\n\n public bool Equals(string x, string y)\n {\n if (myComparer.Compare(x, y) == 0)\n {\n return true;\n }\n else\n {\n return false;\n }\n }\n\n public int GetHashCode(string obj)\n {\n return obj.ToLower().GetHashCode();\n }\n\n #endregion\n}\n"
},
{
"answer_id": 440075,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "List<string> list = new List<string>() { \"One\", \"Two\", \"Three\", \"three\", \"Four\", \"Five\" };\n\nvar z = (from x in list select new { item = x.ToLower()}).Distinct();\n\nz.Dump();\n"
},
{
"answer_id": 43678808,
"author": "Javed Ahmad",
"author_id": 7936234,
"author_profile": "https://Stackoverflow.com/users/7936234",
"pm_score": 2,
"selected": false,
"text": " ## Distinct Operator( Ignoring Case) ##\n string[] countries = {\"USA\",\"usa\",\"INDIA\",\"UK\",\"UK\" };\n\n var result = countries.Distinct(StringComparer.OrdinalIgnoreCase);\n\n foreach (var v in result) \n { \n Console.WriteLine(v);\n }\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/283063",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5023/"
] |
283,087 | <p>I am looking to parse INSERT and UPDATE MySQL SQL queries in PHP to determine what changes where made from what original data. Now this would be pretty easy to create, but I want to see if there are any existing libraries in PHP to do this.</p>
<p>Basically what I have is a table with all of the above queries that have been run on a database. I have already separated out the table name and type of query. I am looking to create a full change log for user viewing based on this data, so I need to get the values of the original INSERT and then changes that are made in each UPDATE. In the end I need field name and new value and with the record id(s). I'll do the rest of the checking/beautifying, including the column name to human readable and if a field value hasn't actually changed.</p>
<p>At the moment, I probably don't need to do multiple table UPDATE's, but it would be useful.</p>
<p>What libraries are there to do this?</p>
| [
{
"answer_id": 414671,
"author": "Dan Soap",
"author_id": 25253,
"author_profile": "https://Stackoverflow.com/users/25253",
"pm_score": 2,
"selected": false,
"text": "timestamp, user, field, old_value, new_value\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/283087",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5441/"
] |
283,090 | <p>I'd like to popup a simple dialog with an editor box, to let user enter some value then just return. I am wondering whether iPhone SDK has that kind of support.</p>
<p>Thanks.</p>
| [
{
"answer_id": 286049,
"author": "BlueDolphin",
"author_id": 32096,
"author_profile": "https://Stackoverflow.com/users/32096",
"pm_score": 4,
"selected": true,
"text": "UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@\"Your title here\" message:@\"this gets covered\" delegate:self cancelButtonTitle:@\"Cancel\" otherButtonTitles:@\"OK\", nil];\nUITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];\n\nCGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 130.0);\n[myAlertView setTransform:myTransform];\n\n[myTextField setBackgroundColor:[UIColor whiteColor]];\n[myAlertView addSubview:myTextField];\n[myAlertView show];\n[myAlertView release];\n"
},
{
"answer_id": 849537,
"author": "JobJob",
"author_id": 104264,
"author_profile": "https://Stackoverflow.com/users/104264",
"pm_score": 1,
"selected": false,
"text": "UIAlertView* theAlert = [[UIAlertView alloc] initWithTitle:@\"Lah\"\n message:@\"dee dah\"\n delegate:self\n cancelButtonTitle:nil\n otherButtonTitles:nil];\n//NSLog(@\"Pre Show: alert frame x,y: %f,%f, alert frame width,height: %f,%f\", theAlert.frame.origin.x,theAlert.frame.origin.y, theAlert.frame.size.width, theAlert.frame.size.height);\n[retrievingListAlert show];\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/283090",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32096/"
] |
283,103 | <p>DDL for Database Tables:</p>
<pre><code> Users:
id - int - identity
name - varchar - unique
PCs:
id - int - idnetity
name - varchar - unique
userid - FK to Users
Apps:
id - int - identity
name - varchar
pcid - FK to PCs
</code></pre>
<p>I created a DataContext using the Linq To SQL designer in Visual Studio 2008.</p>
<p>I want to perform this query:</p>
<pre><code>select
users.name,
pcs.name,
apps.name
from
users u
join pcs p on p.userid = u.id
join apps a on a.pcid = p.id
</code></pre>
<p>I was told in another thread where I posted an answer that the following was incorrect and that it created a cross-join.</p>
<pre><code>var query = from u in db.Users // gets all users
from p in u.PCs // gets all pcs for user
from a in p.Apps // gets all apps for pc
select new
{
username = u.Name,
pcname = p.Name,
appname = a.Name
};
</code></pre>
<p>When I execute this query I get the correct results. A cross-join with two records in each table should return 8 records but my query correctly returns the two records.</p>
<p>Am I lucky, or is the person telling me that I'm wrong confused?</p>
| [
{
"answer_id": 283157,
"author": "Ali Ersöz",
"author_id": 4215,
"author_profile": "https://Stackoverflow.com/users/4215",
"pm_score": 3,
"selected": true,
"text": "var query = from u in db.Users\n join p in db.PCs on p.UserId == u.Id\n join a in db.Apps on a.PCId == p.Id\n select new\n {\n username = u.Name,\n pcname = p.Name,\n appname = a.Name\n };\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/283103",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16592/"
] |
283,120 | <p>I want to assign default values to a column in my select sql query so that if the value of that column is null I get that default value in my recordset. Is there anyway to do this?</p>
<p>Example:</p>
<pre><code>select col1 (some default value) from tblname;
</code></pre>
| [
{
"answer_id": 283129,
"author": "LeppyR64",
"author_id": 16592,
"author_profile": "https://Stackoverflow.com/users/16592",
"pm_score": 3,
"selected": false,
"text": "select\n isnull(col1, defaultvalue)\nfrom\n tblname;\n"
},
{
"answer_id": 283151,
"author": "Alexander Prokofyev",
"author_id": 11256,
"author_profile": "https://Stackoverflow.com/users/11256",
"pm_score": 4,
"selected": false,
"text": "SELECT COALESCE(column_name, default_value) FROM table_name;\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/283120",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
283,128 | <p>I'm writing a wrapper class for a command line executable. This exe accepts input from <code>stdin</code> until I hit <code>Ctrl+C</code> in the command prompt shell, in which case it prints output to <code>stdout</code> based on the input. I want to simulate that <code>Ctrl+C</code> press in C# code, sending the kill command to a .NET <code>Process</code> object. I've tried calling <code>Process.Kill()</code>, but that doesn't seem to give me anything in the process's <code>StandardOutput</code> <code>StreamReader</code>. Might there be anything I'm not doing right? Here's the code I'm trying to use:</p>
<pre><code>ProcessStartInfo info = new ProcessStartInfo(exe, args);
info.RedirectStandardError = true;
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
Process p = Process.Start(info);
p.StandardInput.AutoFlush = true;
p.StandardInput.WriteLine(scriptcode);
p.Kill();
string error = p.StandardError.ReadToEnd();
if (!String.IsNullOrEmpty(error))
{
throw new Exception(error);
}
string output = p.StandardOutput.ReadToEnd();
</code></pre>
<p>The output is always empty, even though I get data back from <code>stdout</code> when I run the exe manually.</p>
<p><strong>Edit</strong>: This is C# 2.0 by the way.</p>
| [
{
"answer_id": 283137,
"author": "Alon L",
"author_id": 30884,
"author_profile": "https://Stackoverflow.com/users/30884",
"pm_score": -1,
"selected": false,
"text": " [DllImport(\"user32.dll\")]\n public static extern int SendMessage(\n int hWnd, // handle to destination window\n uint Msg, // message\n long wParam, // first message parameter\n long lParam // second message parameter\n );\n"
},
{
"answer_id": 283357,
"author": "Rob",
"author_id": 34224,
"author_profile": "https://Stackoverflow.com/users/34224",
"pm_score": 5,
"selected": false,
"text": "Console.ReadLine()"
},
{
"answer_id": 285041,
"author": "Kevlar",
"author_id": 19252,
"author_profile": "https://Stackoverflow.com/users/19252",
"pm_score": 6,
"selected": true,
"text": "p.StandardInput.Close()\n"
},
{
"answer_id": 7323673,
"author": "James Schopp",
"author_id": 931216,
"author_profile": "https://Stackoverflow.com/users/931216",
"pm_score": 4,
"selected": false,
"text": "//import in the declaration for GenerateConsoleCtrlEvent\n[DllImport(\"kernel32.dll\", SetLastError=true)] \nstatic extern bool GenerateConsoleCtrlEvent(ConsoleCtrlEvent sigevent, int dwProcessGroupId);\npublic enum ConsoleCtrlEvent \n{ \n CTRL_C = 0, \n CTRL_BREAK = 1, \n CTRL_CLOSE = 2, \n CTRL_LOGOFF = 5, \n CTRL_SHUTDOWN = 6 \n}\n\n//set up the parents CtrlC event handler, so we can ignore the event while sending to the child\npublic static volatile bool SENDING_CTRL_C_TO_CHILD = false;\nstatic void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)\n{\n e.Cancel = SENDING_CTRL_C_TO_CHILD;\n}\n\n//the main method..\nstatic int Main(string[] args)\n{\n //hook up the event handler in the parent\n Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);\n\n //spawn some child process\n System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();\n psi.Arguments = \"childProcess.exe\";\n Process p = new Process();\n p.StartInfo = psi;\n p.Start();\n\n //sned the ctrl-c to the process group (the parent will get it too!)\n SENDING_CTRL_C_TO_CHILD = true;\n GenerateConsoleCtrlEvent(ConsoleCtrlEvent.CTRL_C, p.SessionId); \n p.WaitForExit();\n SENDING_CTRL_C_TO_CHILD = false;\n\n //note that the ctrl-c event will get called on the parent on background thread\n //so you need to be sure the parent has handled and checked SENDING_CTRL_C_TO_CHILD\n already before setting it to false. 1000 ways to do this, obviously.\n\n\n\n //get out....\n return 0;\n}\n"
},
{
"answer_id": 29274238,
"author": "Vitaliy Fedorchenko",
"author_id": 2756471,
"author_profile": "https://Stackoverflow.com/users/2756471",
"pm_score": 6,
"selected": false,
"text": "GenerateConsoleCtrlEvent()"
},
{
"answer_id": 58890546,
"author": "Simon Mourier",
"author_id": 403671,
"author_profile": "https://Stackoverflow.com/users/403671",
"pm_score": 2,
"selected": false,
"text": " static void RunFFMpeg(string arguments)\n {\n var startup = new STARTUPINFO();\n startup.cb = Marshal.SizeOf<STARTUPINFO>();\n if (!CreateProcess(null, \"ffmpeg.exe \" + arguments, IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref startup, out var info))\n throw new Win32Exception(Marshal.GetLastWin32Error());\n\n CloseHandle(info.hProcess);\n CloseHandle(info.hThread);\n\n var process = Process.GetProcessById(info.dwProcessId);\n Console.CancelKeyPress += (s, e) =>\n {\n process.WaitForExit();\n Console.WriteLine(\"Abort.\");\n // end of program is here\n };\n\n process.WaitForExit();\n Console.WriteLine(\"Exit.\");\n }\n\n [StructLayout(LayoutKind.Sequential)]\n private struct PROCESS_INFORMATION\n {\n public IntPtr hProcess;\n public IntPtr hThread;\n public int dwProcessId;\n public int dwThreadId;\n }\n\n [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]\n private struct STARTUPINFO\n {\n public int cb;\n public string lpReserved;\n public string lpDesktop;\n public string lpTitle;\n public int dwX;\n public int dwY;\n public int dwXSize;\n public int dwYSize;\n public int dwXCountChars;\n public int dwYCountChars;\n public int dwFillAttribute;\n public int dwFlags;\n public short wShowWindow;\n public short cbReserved2;\n public IntPtr lpReserved2;\n public IntPtr hStdInput;\n public IntPtr hStdOutput;\n public IntPtr hStdError;\n }\n\n [DllImport(\"kernel32\")]\n private static extern bool CloseHandle(IntPtr hObject);\n\n [DllImport(\"kernel32\", SetLastError = true, CharSet = CharSet.Unicode)]\n private static extern bool CreateProcess(\n string lpApplicationName,\n string lpCommandLine,\n IntPtr lpProcessAttributes,\n IntPtr lpThreadAttributes,\n bool bInheritHandles,\n int dwCreationFlags,\n IntPtr lpEnvironment,\n string lpCurrentDirectory,\n ref STARTUPINFO lpStartupInfo,\n out PROCESS_INFORMATION lpProcessInformation);\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/283128",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19252/"
] |
283,131 | <p>Can anyone help me to put a vertical scroll bar for an <code><asp:CheckBoxList></code>?</p>
| [
{
"answer_id": 283137,
"author": "Alon L",
"author_id": 30884,
"author_profile": "https://Stackoverflow.com/users/30884",
"pm_score": -1,
"selected": false,
"text": " [DllImport(\"user32.dll\")]\n public static extern int SendMessage(\n int hWnd, // handle to destination window\n uint Msg, // message\n long wParam, // first message parameter\n long lParam // second message parameter\n );\n"
},
{
"answer_id": 283357,
"author": "Rob",
"author_id": 34224,
"author_profile": "https://Stackoverflow.com/users/34224",
"pm_score": 5,
"selected": false,
"text": "Console.ReadLine()"
},
{
"answer_id": 285041,
"author": "Kevlar",
"author_id": 19252,
"author_profile": "https://Stackoverflow.com/users/19252",
"pm_score": 6,
"selected": true,
"text": "p.StandardInput.Close()\n"
},
{
"answer_id": 7323673,
"author": "James Schopp",
"author_id": 931216,
"author_profile": "https://Stackoverflow.com/users/931216",
"pm_score": 4,
"selected": false,
"text": "//import in the declaration for GenerateConsoleCtrlEvent\n[DllImport(\"kernel32.dll\", SetLastError=true)] \nstatic extern bool GenerateConsoleCtrlEvent(ConsoleCtrlEvent sigevent, int dwProcessGroupId);\npublic enum ConsoleCtrlEvent \n{ \n CTRL_C = 0, \n CTRL_BREAK = 1, \n CTRL_CLOSE = 2, \n CTRL_LOGOFF = 5, \n CTRL_SHUTDOWN = 6 \n}\n\n//set up the parents CtrlC event handler, so we can ignore the event while sending to the child\npublic static volatile bool SENDING_CTRL_C_TO_CHILD = false;\nstatic void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)\n{\n e.Cancel = SENDING_CTRL_C_TO_CHILD;\n}\n\n//the main method..\nstatic int Main(string[] args)\n{\n //hook up the event handler in the parent\n Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);\n\n //spawn some child process\n System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();\n psi.Arguments = \"childProcess.exe\";\n Process p = new Process();\n p.StartInfo = psi;\n p.Start();\n\n //sned the ctrl-c to the process group (the parent will get it too!)\n SENDING_CTRL_C_TO_CHILD = true;\n GenerateConsoleCtrlEvent(ConsoleCtrlEvent.CTRL_C, p.SessionId); \n p.WaitForExit();\n SENDING_CTRL_C_TO_CHILD = false;\n\n //note that the ctrl-c event will get called on the parent on background thread\n //so you need to be sure the parent has handled and checked SENDING_CTRL_C_TO_CHILD\n already before setting it to false. 1000 ways to do this, obviously.\n\n\n\n //get out....\n return 0;\n}\n"
},
{
"answer_id": 29274238,
"author": "Vitaliy Fedorchenko",
"author_id": 2756471,
"author_profile": "https://Stackoverflow.com/users/2756471",
"pm_score": 6,
"selected": false,
"text": "GenerateConsoleCtrlEvent()"
},
{
"answer_id": 58890546,
"author": "Simon Mourier",
"author_id": 403671,
"author_profile": "https://Stackoverflow.com/users/403671",
"pm_score": 2,
"selected": false,
"text": " static void RunFFMpeg(string arguments)\n {\n var startup = new STARTUPINFO();\n startup.cb = Marshal.SizeOf<STARTUPINFO>();\n if (!CreateProcess(null, \"ffmpeg.exe \" + arguments, IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref startup, out var info))\n throw new Win32Exception(Marshal.GetLastWin32Error());\n\n CloseHandle(info.hProcess);\n CloseHandle(info.hThread);\n\n var process = Process.GetProcessById(info.dwProcessId);\n Console.CancelKeyPress += (s, e) =>\n {\n process.WaitForExit();\n Console.WriteLine(\"Abort.\");\n // end of program is here\n };\n\n process.WaitForExit();\n Console.WriteLine(\"Exit.\");\n }\n\n [StructLayout(LayoutKind.Sequential)]\n private struct PROCESS_INFORMATION\n {\n public IntPtr hProcess;\n public IntPtr hThread;\n public int dwProcessId;\n public int dwThreadId;\n }\n\n [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]\n private struct STARTUPINFO\n {\n public int cb;\n public string lpReserved;\n public string lpDesktop;\n public string lpTitle;\n public int dwX;\n public int dwY;\n public int dwXSize;\n public int dwYSize;\n public int dwXCountChars;\n public int dwYCountChars;\n public int dwFillAttribute;\n public int dwFlags;\n public short wShowWindow;\n public short cbReserved2;\n public IntPtr lpReserved2;\n public IntPtr hStdInput;\n public IntPtr hStdOutput;\n public IntPtr hStdError;\n }\n\n [DllImport(\"kernel32\")]\n private static extern bool CloseHandle(IntPtr hObject);\n\n [DllImport(\"kernel32\", SetLastError = true, CharSet = CharSet.Unicode)]\n private static extern bool CreateProcess(\n string lpApplicationName,\n string lpCommandLine,\n IntPtr lpProcessAttributes,\n IntPtr lpThreadAttributes,\n bool bInheritHandles,\n int dwCreationFlags,\n IntPtr lpEnvironment,\n string lpCurrentDirectory,\n ref STARTUPINFO lpStartupInfo,\n out PROCESS_INFORMATION lpProcessInformation);\n"
}
] | 2008/11/12 | [
"https://Stackoverflow.com/questions/283131",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29867/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.