qid
int64
4
8.14M
question
stringlengths
20
48.3k
answers
list
date
stringlengths
10
10
metadata
list
input
stringlengths
12
45k
output
stringlengths
2
31.8k
475,984
<p>My Sql Query in Vb.net is like this:</p> <pre><code>Dim TableName As String ="City" Dim Str As String="Select * from "+TableName+"" </code></pre> <p>I got TableName from another Form .how we can do this in linq? can we use TableName in Linq query dynamically?</p> <p>please help me?</p>
[ { "answer_id": 476002, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 1, "selected": false, "text": "<p>Sorry for my example being in C#, but my Vb is rusty. I can read it, but not write it very well off the top of my h...
2009/01/24
[ "https://Stackoverflow.com/questions/475984", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
My Sql Query in Vb.net is like this: ``` Dim TableName As String ="City" Dim Str As String="Select * from "+TableName+"" ``` I got TableName from another Form .how we can do this in linq? can we use TableName in Linq query dynamically? please help me?
Sorry for my example being in C#, but my Vb is rusty. I can read it, but not write it very well off the top of my head. The best way I can think to do this is to use reflection and extension methods rather than LINQ syntax. ``` PropertyInfo info = dataContext.GetType().GetProperty( "City" ); IQueryable table = info...
475,986
<p>I'm building a dynamic ExtJS form based on JSON data loaded from an ASP.NET web service. The problem I find is that ExtJS expects the JSON in a specific format, ie. </p> <pre><code>{ "metaData": { "title": "Testing" }, "data": [], "success": true } </code></pre> <p>When using an ASP.NET web service to return an ob...
[ { "answer_id": 477455, "author": "Mark Clancy", "author_id": 57083, "author_profile": "https://Stackoverflow.com/users/57083", "pm_score": 3, "selected": true, "text": "<p>After some more testing I've found that the ExtJS form does load the JSON from my web service but because the respon...
2009/01/24
[ "https://Stackoverflow.com/questions/475986", "https://Stackoverflow.com", "https://Stackoverflow.com/users/57083/" ]
I'm building a dynamic ExtJS form based on JSON data loaded from an ASP.NET web service. The problem I find is that ExtJS expects the JSON in a specific format, ie. ``` { "metaData": { "title": "Testing" }, "data": [], "success": true } ``` When using an ASP.NET web service to return an object as JSON it returns wi...
After some more testing I've found that the ExtJS form does load the JSON from my web service but because the response text doesn't have "success": true in the root it is handled by the 'failed' handler. Fortunately this handler accepts the same parameters as the 'success' handler so can be manipulated the same. Here...
475,988
<p>after a bit speedtracing I found a piece of code (called very very often) which converts values of one enum to values of another enum, like this:</p> <pre><code>public Enum2 ConvertToEnum2(Enum1 enum1) { switch(enum1) { case Enum1.One: return Enum2.One; break; case Enum1.Two: ...
[ { "answer_id": 475993, "author": "AnthonyWJones", "author_id": 17516, "author_profile": "https://Stackoverflow.com/users/17516", "pm_score": 4, "selected": true, "text": "<p>A dictionary definitely would not be faster.</p>\n\n<p>If the enums in the Enum1 are sequential then an array of E...
2009/01/24
[ "https://Stackoverflow.com/questions/475988", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31985/" ]
after a bit speedtracing I found a piece of code (called very very often) which converts values of one enum to values of another enum, like this: ``` public Enum2 ConvertToEnum2(Enum1 enum1) { switch(enum1) { case Enum1.One: return Enum2.One; break; case Enum1.Two: return E...
A dictionary definitely would not be faster. If the enums in the Enum1 are sequential then an array of Enum2 would likely be faster (but that could be marginal). IF the Enum1 is close to sequential so that the array isn't too spares it may still be useful approach. For an enum with the [Flags] attribute then the swit...
475,990
<p>Can someone please explain what the "&amp;" does in the following:</p> <pre><code>class TEST { } $abc =&amp; new TEST(); </code></pre> <p>I know it is by reference. But can someone illustrate why and when I would need such a thing? Or point me to a url where this is explained well. I am unable to grasp the conce...
[ { "answer_id": 475998, "author": "Sam Cogan", "author_id": 8768, "author_profile": "https://Stackoverflow.com/users/8768", "pm_score": 1, "selected": false, "text": "<p>Firstly, you don't really need to use it if you are using PHP 5, in PHP 5 all objects are passed by reference by defaul...
2009/01/24
[ "https://Stackoverflow.com/questions/475990", "https://Stackoverflow.com", "https://Stackoverflow.com/users/426996/" ]
Can someone please explain what the "&" does in the following: ``` class TEST { } $abc =& new TEST(); ``` I know it is by reference. But can someone illustrate why and when I would need such a thing? Or point me to a url where this is explained well. I am unable to grasp the concept. Thank you very much.
As I understand it, you're not asking about PHP references in general, but about the `$foo =& new Bar();` construction idiom. This is only seen in PHP4 as the usual `$foo = new Bar()` stores a *copy* of the object. This generally goes unnoticed unless the class stored a reference to $this in the constructor. When call...
476,016
<p>I have the following table containing the winning numbers of 6/49 lottery. </p> <pre><code>+-----+------------+----+----+----+----+----+----+-------+ | id | draw | n1 | n2 | n3 | n4 | n5 | n6 | bonus | +-----+------------+----+----+----+----+----+----+-------+ | 1 | 1982-06-12 | 3 | 11 | 12 | 14 | 41 | 4...
[ { "answer_id": 476019, "author": "karlis", "author_id": 49034, "author_profile": "https://Stackoverflow.com/users/49034", "pm_score": 0, "selected": false, "text": "<p>make a union:\nselect n1 from lottery \nunion select n2 from lottery \n....\nand then make your aggregate!</p>\n" }, ...
2009/01/24
[ "https://Stackoverflow.com/questions/476016", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45066/" ]
I have the following table containing the winning numbers of 6/49 lottery. ``` +-----+------------+----+----+----+----+----+----+-------+ | id | draw | n1 | n2 | n3 | n4 | n5 | n6 | bonus | +-----+------------+----+----+----+----+----+----+-------+ | 1 | 1982-06-12 | 3 | 11 | 12 | 14 | 41 | 43 | 13 | | ...
Given your table layout, you can't combine the queries into a single one by any other means than to union your queries, or to union your base table into a transposed version: ``` SELECT n, COUNT(*) as freq FROM ( SELECT n1 AS n FROM lottery UNION ALL SELECT n2 FROM lottery UNION ALL SELECT n3 FROM lottery ...
476,017
<p>Let's say I have the following model:</p> <pre><code>class Contest: title = models.CharField( max_length = 200 ) description = models.TextField() class Image: title = models.CharField( max_length = 200 ) description = models.TextField() contest = models.ForeignKey( Contest ) user = models.F...
[ { "answer_id": 476024, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 3, "selected": false, "text": "<p>You can write your own sort in Python very simply.</p>\n\n<pre><code>def getScore( anObject ):\n return anObject.scor...
2009/01/24
[ "https://Stackoverflow.com/questions/476017", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35903/" ]
Let's say I have the following model: ``` class Contest: title = models.CharField( max_length = 200 ) description = models.TextField() class Image: title = models.CharField( max_length = 200 ) description = models.TextField() contest = models.ForeignKey( Contest ) user = models.ForeignKey( Use...
Oh, of course I forget about new aggregation support in Django and its `annotate` functionality. So query may look like this: ``` Contest.objects.get(pk=id).image_set.annotate(score=Sum('vote__value')).order_by( 'score' ) ```
476,020
<p>I'm trying to create this:</p> <p>Tag1 has the ordered list of objects: O1, O3, O2. Tag2 has the ordered list of objects: O1, O4.</p> <p>Every time I click a tag, I want to see the list of objects. So clicking Tag1 would show in a listbox:</p> <ul> <li>O1</li> <li>O3</li> <li>O2</li> </ul> <p>But I would like to...
[ { "answer_id": 476024, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 3, "selected": false, "text": "<p>You can write your own sort in Python very simply.</p>\n\n<pre><code>def getScore( anObject ):\n return anObject.scor...
2009/01/24
[ "https://Stackoverflow.com/questions/476020", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1013/" ]
I'm trying to create this: Tag1 has the ordered list of objects: O1, O3, O2. Tag2 has the ordered list of objects: O1, O4. Every time I click a tag, I want to see the list of objects. So clicking Tag1 would show in a listbox: * O1 * O3 * O2 But I would like to **keep the auto update so every time I edit or add/dele...
Oh, of course I forget about new aggregation support in Django and its `annotate` functionality. So query may look like this: ``` Contest.objects.get(pk=id).image_set.annotate(score=Sum('vote__value')).order_by( 'score' ) ```
476,039
<p>I'm fairly new to C# but I will <strong>try</strong> to make this quick! ;)</p> <p>This is just a theoretical situation, but imagine that:</p> <p><strong>I)</strong> One have a class 'ClassA' with a 'ClassB' inside it and a 'ClassC' inside of 'ClassB'.</p> <p><strong>II)</strong> ClassA have a method which gets c...
[ { "answer_id": 476053, "author": "Quassnoi", "author_id": 55159, "author_profile": "https://Stackoverflow.com/users/55159", "pm_score": 4, "selected": true, "text": "<p>I'll rewrite it a little:</p>\n\n<pre><code>ClassA()\n{\n memberB = new ClassB();\n}\n\nMethodA()\n{\n memberB = new ...
2009/01/24
[ "https://Stackoverflow.com/questions/476039", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58589/" ]
I'm fairly new to C# but I will **try** to make this quick! ;) This is just a theoretical situation, but imagine that: **I)** One have a class 'ClassA' with a 'ClassB' inside it and a 'ClassC' inside of 'ClassB'. **II)** ClassA have a method which gets called. The method itself is (don't know the name for this) 'con...
I'll rewrite it a little: ``` ClassA() { memberB = new ClassB(); } MethodA() { memberB = new ClassB(); } ``` In this case, `memberB` holds a reference to an instance of `classB`. In the constructor for `classA`, new instance of `classB` is created (call it `instance 1`) and reference to this instance is assign...
476,043
<p>Is there a way to use (reference) a DLL written in an unmanaged C++ (not a COM library) in my C# application?</p> <p>When I try to reference it from within Visual Studio, I get 'not a COM object' error message.</p> <p>Maybe there is some kind of translator\router that would COMify my DLL reference? I have no clue ...
[ { "answer_id": 476045, "author": "petr k.", "author_id": 15497, "author_profile": "https://Stackoverflow.com/users/15497", "pm_score": 3, "selected": false, "text": "<p>See \"<strong>Consuming unmanaged DLL functions</strong>\" topic on MSDN:</p>\n\n<p><a href=\"http://msdn.microsoft.com...
2009/01/24
[ "https://Stackoverflow.com/questions/476043", "https://Stackoverflow.com", "https://Stackoverflow.com/users/430254/" ]
Is there a way to use (reference) a DLL written in an unmanaged C++ (not a COM library) in my C# application? When I try to reference it from within Visual Studio, I get 'not a COM object' error message. Maybe there is some kind of translator\router that would COMify my DLL reference? I have no clue how COM and COM i...
You need to use the DllImport attribute. Here's an example for the Win32 PostMessage function: ``` [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool PostMessage(IntPtr handle, int message, IntPtr wparam, IntPtr lparam); ```
476,049
<p>I'm very new to ASP.NET, help me please understand MasterPages conception more.</p> <p>I have Site.master with common header data (css, meta, etc), center form (blank) and footer (copyright info, contact us link, etc).</p> <pre><code>&lt;%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inhe...
[ { "answer_id": 476063, "author": "Chris Roberts", "author_id": 475, "author_profile": "https://Stackoverflow.com/users/475", "pm_score": 0, "selected": false, "text": "<p>I may be misunderstanding your problem - but from the code you've posted, there isn't anything <em>in</em> the footer...
2009/01/24
[ "https://Stackoverflow.com/questions/476049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41956/" ]
I'm very new to ASP.NET, help me please understand MasterPages conception more. I have Site.master with common header data (css, meta, etc), center form (blank) and footer (copyright info, contact us link, etc). ``` <%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="_SiteMaster" %> <!...
I've been working with nested master pages and have run in to something similar. From what I see where you have "Some footer here" in the Site.Master is where the problem lies and I've had similar problems with having content with-in a contentplaceholder tag. if you try this instead ``` <asp:ContentPlaceHolder ID="hol...
476,070
<p>Of course both F# and C# compile to IL and the CLR JITter does most of the hard work, however I wanted to know whether there's anything implicit in the F# language or its core libraries which result in lesser performance compared to C#?</p> <p>Additionally, is there anything in the use of functional programming in t...
[ { "answer_id": 476075, "author": "Ian P", "author_id": 10853, "author_profile": "https://Stackoverflow.com/users/10853", "pm_score": 3, "selected": false, "text": "<p>A good example is the sieve of eratosthenes.</p>\n\n<p>A co-worker and I wrote similar sieves in C# and F#. The performan...
2009/01/24
[ "https://Stackoverflow.com/questions/476070", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3394/" ]
Of course both F# and C# compile to IL and the CLR JITter does most of the hard work, however I wanted to know whether there's anything implicit in the F# language or its core libraries which result in lesser performance compared to C#? Additionally, is there anything in the use of functional programming in the .net f...
A good example is the sieve of eratosthenes. A co-worker and I wrote similar sieves in C# and F#. The performance of the C# version was almost 10 times slower than it's functional counterpart written by my co-worker. There were probably some inefficiencies in the C# version that could have been cleaned up, but the F#...
476,084
<p>I'm trying to set up a C# application which uses TWAIN <a href="http://www.codeproject.com/KB/dotnet/twaindotnet.aspx" rel="nofollow noreferrer">example from code project</a></p> <p>This works fine except that I need to cast <code>Form</code> to <code>IMessageFilter</code> and call <code>IMessageFilter.PreFilterMe...
[ { "answer_id": 476161, "author": "driAn", "author_id": 50430, "author_profile": "https://Stackoverflow.com/users/50430", "pm_score": 0, "selected": false, "text": "<p>I thought TWAIN is considered obsolete. Maybe take a look at <a href=\"http://www.microsoft.com/whdc/device/stillimage/WI...
2009/01/24
[ "https://Stackoverflow.com/questions/476084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/430254/" ]
I'm trying to set up a C# application which uses TWAIN [example from code project](http://www.codeproject.com/KB/dotnet/twaindotnet.aspx) This works fine except that I need to cast `Form` to `IMessageFilter` and call `IMessageFilter.PreFilterMessage()` to catch TWAIN callbacks. Also I need to start this filtering...
You could try it with the `ComponentDispatcher.ThreadFilterMessage` event. As far as I understand, it serves the same purpose in *WPF* as `Application.AddMessageFilter()` in *WinForms*.
476,101
<p>I'm using Visual Basic 9 (VS2008) and TagLib.</p> <p>The following code extracts the album art from an MP3 file and displays it in a PictureBox.</p> <p>Is there a better way to write this code?</p> <pre><code> Dim file As TagLib.File = TagLib.File.Create(filepath) If file.Tag.Pictures.Length &gt;= 1 Then Di...
[ { "answer_id": 476113, "author": "splattne", "author_id": 6461, "author_profile": "https://Stackoverflow.com/users/6461", "pm_score": 2, "selected": false, "text": "<p>At first glance it looks okay to me.</p>\n\n<p>You could add some error handling, for example if <code>TagLib.File.Creat...
2009/01/24
[ "https://Stackoverflow.com/questions/476101", "https://Stackoverflow.com", "https://Stackoverflow.com/users/57175/" ]
I'm using Visual Basic 9 (VS2008) and TagLib. The following code extracts the album art from an MP3 file and displays it in a PictureBox. Is there a better way to write this code? ``` Dim file As TagLib.File = TagLib.File.Create(filepath) If file.Tag.Pictures.Length >= 1 Then Dim bin As Byte() = DirectCast(fi...
I'm not intimately familiar with TagLib but it doesn't look like there is much of a better way to write this. The only suggestion I can give is that you could reduce the amount of code by taking advantage of type inference. The two variable declarations don't need an explicit type if "Option Infer" is currently on. Thi...
476,105
<p>How can I convert a string to a date time object in javascript by specifying a format string?</p> <p>I am looking for something like:</p> <pre><code>var dateTime = convertToDateTime("23.11.2009 12:34:56", "dd.MM.yyyy HH:mm:ss"); </code></pre>
[ { "answer_id": 476117, "author": "Christoph", "author_id": 48015, "author_profile": "https://Stackoverflow.com/users/48015", "pm_score": 7, "selected": false, "text": "<p>Use <code>new Date(<i>dateString</i>)</code> if your string is compatible with <a href=\"https://developer.mozilla.or...
2009/01/24
[ "https://Stackoverflow.com/questions/476105", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31505/" ]
How can I convert a string to a date time object in javascript by specifying a format string? I am looking for something like: ``` var dateTime = convertToDateTime("23.11.2009 12:34:56", "dd.MM.yyyy HH:mm:ss"); ```
I think this can help you: [http://www.mattkruse.com/javascript/date/](https://web.archive.org/web/20090114044719/http://www.mattkruse.com/javascript/date/) There's a `getDateFromFormat()` function that you can tweak a little to solve your problem. Update: there's an updated version of the samples available at [javas...
476,112
<p>I'd like to call Update ... Set ... Where ... to update a field as soon as that evil ERP process is changing the value of another.</p> <p>I'm running MS SQL.</p>
[ { "answer_id": 476115, "author": "William T Wild", "author_id": 58314, "author_profile": "https://Stackoverflow.com/users/58314", "pm_score": 2, "selected": false, "text": "<p>You could use a trigger to update the other field. </p>\n\n<p>Edit: I guess that may depend on what SQLesque dat...
2009/01/24
[ "https://Stackoverflow.com/questions/476112", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4085/" ]
I'd like to call Update ... Set ... Where ... to update a field as soon as that evil ERP process is changing the value of another. I'm running MS SQL.
I can't test, but i guess its a trigger like this ``` CREATE TRIGGER TriggerName ON TableName FOR UPDATE AS IF UPDATE(ColumnUpdatedByERP) BEGIN UPDATE ... END ``` -- Edit - a better version, thanks for comment Tomalak ``` CREATE TRIGGER TriggerName ON TableName FOR UPDATE AS DECLARE @oldValue VARCHAR(...
476,128
<p>I'm currently working on a wcf service that does some lookups in a database and return the data to the client. The user has entered an id of something he wants to see in a textbox. This could be a client-id, a product-id, an order-id or whatever. The lookup method on the server tries to find the id in the client tab...
[ { "answer_id": 476115, "author": "William T Wild", "author_id": 58314, "author_profile": "https://Stackoverflow.com/users/58314", "pm_score": 2, "selected": false, "text": "<p>You could use a trigger to update the other field. </p>\n\n<p>Edit: I guess that may depend on what SQLesque dat...
2009/01/24
[ "https://Stackoverflow.com/questions/476128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31722/" ]
I'm currently working on a wcf service that does some lookups in a database and return the data to the client. The user has entered an id of something he wants to see in a textbox. This could be a client-id, a product-id, an order-id or whatever. The lookup method on the server tries to find the id in the client table....
I can't test, but i guess its a trigger like this ``` CREATE TRIGGER TriggerName ON TableName FOR UPDATE AS IF UPDATE(ColumnUpdatedByERP) BEGIN UPDATE ... END ``` -- Edit - a better version, thanks for comment Tomalak ``` CREATE TRIGGER TriggerName ON TableName FOR UPDATE AS DECLARE @oldValue VARCHAR(...
476,168
<p>In Yahoo or Google and in many websites when you fill up a form and if your form has any errors it gets redirected to the same page. Note that the data in the form remains as it is. I mean the data in the text fields remains the same. I tried &lsaquo;form action="(same page here)" method="post or get"&rsaquo;. It ge...
[ { "answer_id": 476169, "author": "Ólafur Waage", "author_id": 22459, "author_profile": "https://Stackoverflow.com/users/22459", "pm_score": 0, "selected": false, "text": "<p>You'll have to check the data within the same file, and if it is correct, then you redirect to the correct locatio...
2009/01/24
[ "https://Stackoverflow.com/questions/476168", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53467/" ]
In Yahoo or Google and in many websites when you fill up a form and if your form has any errors it gets redirected to the same page. Note that the data in the form remains as it is. I mean the data in the text fields remains the same. I tried ‹form action="(same page here)" method="post or get"›. It gets redirected to ...
Here is a modified version of what I use for *very* simple websites where I don't want/need an entire framework to get the job done. ``` function input($name, $options = array()) { if(!isset($options['type'])) $options['type'] = 'text'; $options['name'] = $name; if(isset($_POST[$name]) && $options['type'...
476,186
<p>I am a PHP programmer and I want to develop a website using visual web developer .net I knew that asp.net has many different approaches in dealing with database. However, I am familer with PHP way in programming for example:</p> <pre><code>$query = "select * from table where user_id &gt; 2" $result = mysql_query($q...
[ { "answer_id": 476191, "author": "Sampson", "author_id": 54680, "author_profile": "https://Stackoverflow.com/users/54680", "pm_score": 2, "selected": false, "text": "<p>Sure...learn C# (somewhat similar syntax) Or develop using one of the following:</p>\n\n<ul>\n<li><a href=\"http://php4...
2009/01/24
[ "https://Stackoverflow.com/questions/476186", "https://Stackoverflow.com", "https://Stackoverflow.com/users/459737/" ]
I am a PHP programmer and I want to develop a website using visual web developer .net I knew that asp.net has many different approaches in dealing with database. However, I am familer with PHP way in programming for example: ``` $query = "select * from table where user_id > 2" $result = mysql_query($query); while($ro...
Sure...learn C# (somewhat similar syntax) Or develop using one of the following: * [PHP4Mono](http://php4mono.sourceforge.net/) * [PHP4Apps](http://www.codeproject.com/csharp/php4apps.asp) * [PHP Sharp](http://www.akbkhome.com/wiki.php/Projects/PHP_Sharp) * [PHP Mono Extensions](http://www.php.net/~sterling/mono/) * [...
476,188
<p>Usually, when using Windows Authentication, the software (eg Internet Explorer) tries to use Windows Authentication, and if it doesn't succeed (because the domain is untrusted, or because the credentials are not ok for example), it just popups a login window so that you can input your domain, login and password.</p>...
[ { "answer_id": 476193, "author": "Sam Cogan", "author_id": 8768, "author_profile": "https://Stackoverflow.com/users/8768", "pm_score": 1, "selected": false, "text": "<p>Trusted Authentication will use the credentials that you are logged into the machine with to try and connect, there’s n...
2009/01/24
[ "https://Stackoverflow.com/questions/476188", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47341/" ]
Usually, when using Windows Authentication, the software (eg Internet Explorer) tries to use Windows Authentication, and if it doesn't succeed (because the domain is untrusted, or because the credentials are not ok for example), it just popups a login window so that you can input your domain, login and password. With ...
try this: [Use RUNAS to set your Windows Auth domain for database connections](http://weblogs.asp.net/jgalloway/archive/2007/09/07/tip-use-runas-to-set-your-windows-auth-domain-for-database-connections.aspx) ``` runas /user:domain\user “C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\ssmsee.exe...
476,212
<p>Does anyone know how to find out the precision of <code>long double</code> on a specific platform? I appear to be losing precision after 17 decimal digits, which is the same as when I just use <code>double</code>. I would expect to get more, since <code>double</code> is represented with 8 bytes on my platform, wh...
[ { "answer_id": 476225, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 6, "selected": true, "text": "<p>You can find out with <code>std::numeric_limits</code>:</p>\n\n<pre><code>#include &lt;iostream&gt; /...
2009/01/24
[ "https://Stackoverflow.com/questions/476212", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1288/" ]
Does anyone know how to find out the precision of `long double` on a specific platform? I appear to be losing precision after 17 decimal digits, which is the same as when I just use `double`. I would expect to get more, since `double` is represented with 8 bytes on my platform, while `long double` is 12 bytes. Before ...
You can find out with `std::numeric_limits`: ``` #include <iostream> // std::cout #include <limits> // std::numeric_limits int main(){ std::cout << std::numeric_limits<long double>::digits10 << std::endl; } ```
476,214
<p>What is the linq equivalent of the following statement ?</p> <pre><code>IF NOT EXISTS(SELECT UserName FROM Users WHERE UserName='michael') BEGIN INSERT INTO Users (UserName) values ('michael'); END </code></pre> <p>also can you suggest any sql-to-linq converters? I am currently using LINQPad which does a great job...
[ { "answer_id": 476252, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 6, "selected": true, "text": "<p>It can't be done in LINQ2SQL with a single statement as the LINQ syntax and extension methods don't support inserts. ...
2009/01/24
[ "https://Stackoverflow.com/questions/476214", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49742/" ]
What is the linq equivalent of the following statement ? ``` IF NOT EXISTS(SELECT UserName FROM Users WHERE UserName='michael') BEGIN INSERT INTO Users (UserName) values ('michael'); END ``` also can you suggest any sql-to-linq converters? I am currently using LINQPad which does a great job in terms of writing linq ...
It can't be done in LINQ2SQL with a single statement as the LINQ syntax and extension methods don't support inserts. The following (assuming a datacontext named `db`) should do the trick. ``` if (!db.Users.Any( u => u.UserName == "michael" )) { db.Users.InsertOnSubmit( new User { UserName = "michael" } ); ...
476,217
<p>I usually do something like the example below when I need to return error messages from a function, if no errors occur I just return an empyty string. Is this best practice, or are there alternatve ways of returning error messages from functions?</p> <pre><code>Function Test() as String ' Do something If error ...
[ { "answer_id": 476228, "author": "Erik Engbrecht", "author_id": 18973, "author_profile": "https://Stackoverflow.com/users/18973", "pm_score": 4, "selected": true, "text": "<p>Instead of returning an error message you should throw an exception that contains the error message.</p>\n\n<p>He...
2009/01/24
[ "https://Stackoverflow.com/questions/476217", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47212/" ]
I usually do something like the example below when I need to return error messages from a function, if no errors occur I just return an empyty string. Is this best practice, or are there alternatve ways of returning error messages from functions? ``` Function Test() as String ' Do something If error occured Then ...
Instead of returning an error message you should throw an exception that contains the error message. Here's a quick overview: <http://www.vbdotnetheaven.com/UploadFile/rajeshvs/dotnetException04162005022135AM/dotnetException.aspx>
476,218
<p>Yesterday I found this function:</p> <pre><code>function clone(obj) { return typeof obj === 'undefined' ? this : (clone.prototype = Object(obj), new clone); } </code></pre> <p>I though that i saw alot in Javascript, but this syntax is unknown for me:</p> <pre><code> clone.prototype = Object(obj), new ...
[ { "answer_id": 476235, "author": "sth", "author_id": 56338, "author_profile": "https://Stackoverflow.com/users/56338", "pm_score": 3, "selected": false, "text": "<p><a href=\"https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Expressions_and_Operators#Comma_operator\" rel=\"nofol...
2009/01/24
[ "https://Stackoverflow.com/questions/476218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58260/" ]
Yesterday I found this function: ``` function clone(obj) { return typeof obj === 'undefined' ? this : (clone.prototype = Object(obj), new clone); } ``` I though that i saw alot in Javascript, but this syntax is unknown for me: ``` clone.prototype = Object(obj), new clone ``` Can someone explain me ho...
Your 'final solution' gives unexpected results because of operator precedence. The following example might help to clarify the issue: ``` var a, b, c; a = 1, 2; // a is 1 (b = 1), 2; // b is 1 - same as above! c = (1, 2); // c is 2 ``` Also notice that ``` var a = 1, 2; ``` produces a syntax error!
476,222
<p>I need a solution where a user could enter the URL of a web page in my system. The page would load, and then the user could click a certain section that he wants to change. So basically what I need is, a way to display a web page inside my app (could possibly be done with frames but I'd prefer not to have a horizont...
[ { "answer_id": 476370, "author": "troelskn", "author_id": 18180, "author_profile": "https://Stackoverflow.com/users/18180", "pm_score": 0, "selected": false, "text": "<p>This is a <em>very</em> general question. There are lots of content management systems around, that provides something...
2009/01/24
[ "https://Stackoverflow.com/questions/476222", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49153/" ]
I need a solution where a user could enter the URL of a web page in my system. The page would load, and then the user could click a certain section that he wants to change. So basically what I need is, a way to display a web page inside my app (could possibly be done with frames but I'd prefer not to have a horizontal ...
You could use `<iframe>` tags, then set `contentEditable = on`. This way, the browser supplies the WYSIWYG features. The borders, etc. may not work, though. Some code: ``` var idno = 0; function addEditor(parent, url) { parent.innerHTML += '<iframe src="' + url + '" id="edit' + idno + '"></iframe>'; var el = ...
476,231
<p>I'm developing a Desktop Search Engine in Visual Basic 9 (VS2008) using Lucene.NET (v2.0).</p> <p>I use the following code to initialize the IndexWriter</p> <pre><code>Private writer As IndexWriter writer = New IndexWriter(indexDirectory, New StandardAnalyzer(), False) writer.SetUseCompoundFile(True) </code></pr...
[ { "answer_id": 476260, "author": "Steve Severance", "author_id": 41717, "author_profile": "https://Stackoverflow.com/users/41717", "pm_score": 4, "selected": true, "text": "<p>To update a lucene index you need to delete the old entry and write in the new entry. So you need to use an Inde...
2009/01/24
[ "https://Stackoverflow.com/questions/476231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/57175/" ]
I'm developing a Desktop Search Engine in Visual Basic 9 (VS2008) using Lucene.NET (v2.0). I use the following code to initialize the IndexWriter ``` Private writer As IndexWriter writer = New IndexWriter(indexDirectory, New StandardAnalyzer(), False) writer.SetUseCompoundFile(True) ``` If I select the same docum...
To update a lucene index you need to delete the old entry and write in the new entry. So you need to use an IndexReader to find the current item, use writer to delete it and then add your new item. The same will be true for multiple entries which I think is what you are trying to do.Just find all the entries, delete th...
476,272
<p>I am writing a small matrix library in C++ for matrix operations. However my compiler complains, where before it did not. This code was left on a shelf for 6 months and in between I upgraded my computer from debian etch to lenny (g++ (Debian 4.3.2-1.1) 4.3.2 ) however I have the same problem on a Ubuntu system with ...
[ { "answer_id": 476279, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 8, "selected": true, "text": "<p>You have declared your function as <code>friend</code>. It's not a member of the class. You should remove <code>Matrix::</co...
2009/01/24
[ "https://Stackoverflow.com/questions/476272", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53702/" ]
I am writing a small matrix library in C++ for matrix operations. However my compiler complains, where before it did not. This code was left on a shelf for 6 months and in between I upgraded my computer from debian etch to lenny (g++ (Debian 4.3.2-1.1) 4.3.2 ) however I have the same problem on a Ubuntu system with the...
You have declared your function as `friend`. It's not a member of the class. You should remove `Matrix::` from the implementation. `friend` means that the specified function (which is not a member of the class) can access private member variables. The way you implemented the function is like an instance method for `Mat...
476,276
<p>Is it possible to use Javascript inside CSS?</p> <p>If it is, can you give a simple example?</p>
[ { "answer_id": 476283, "author": "Hank Gay", "author_id": 4203, "author_profile": "https://Stackoverflow.com/users/4203", "pm_score": 2, "selected": false, "text": "<p>Not in any conventional sense of the phrase \"inside CSS.\"</p>\n" }, { "answer_id": 476289, "author": "Paol...
2009/01/24
[ "https://Stackoverflow.com/questions/476276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Is it possible to use Javascript inside CSS? If it is, can you give a simple example?
IE and Firefox both contain ways to execute JavaScript from CSS. As Paolo mentions, one way in IE is the `expression` technique, but there's also the more obscure **HTC behavior**, in which a seperate XML that contains your script is loaded via CSS. A similar technique for Firefox exists, using **XBL**. These technique...
476,290
<p>is it possible to make beep in WinCE ?</p> <p>i try and i get an error</p>
[ { "answer_id": 476317, "author": "ctacke", "author_id": 13154, "author_profile": "https://Stackoverflow.com/users/13154", "pm_score": 3, "selected": false, "text": "<p>Yes. P/Invoke <a href=\"http://msdn.microsoft.com/en-us/library/aa909766.aspx\" rel=\"noreferrer\">PlaySound</a> or <a ...
2009/01/24
[ "https://Stackoverflow.com/questions/476290", "https://Stackoverflow.com", "https://Stackoverflow.com/users/43907/" ]
is it possible to make beep in WinCE ? i try and i get an error
The .net framework methods for beeing are not available in the CF version of the framework. The best way to get a beep sound is to PInvoke into the MessageBeep function. The PInvoke signature for this method is pretty straight forward ``` [DllImport("CoreDll.dll")] public static extern void MessageBeep(int code); pub...
476,291
<p>Are there any reasons why the simulator will display UIImageViews properly, but incorrectly on the iPhone?</p> <p>My Process: An image in a PNG file Start a UIGraphicsBeginImageContext() Draw the PNG in a CGrect Draw text in the CGRect Create an UIImage from the context Set the image of a UIImaveView to the UIImag...
[ { "answer_id": 476463, "author": "August", "author_id": 30966, "author_profile": "https://Stackoverflow.com/users/30966", "pm_score": 0, "selected": false, "text": "<p>Have you checked the scaling/resize options for the UIImageView?</p>\n" }, { "answer_id": 484507, "author": ...
2009/01/24
[ "https://Stackoverflow.com/questions/476291", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48311/" ]
Are there any reasons why the simulator will display UIImageViews properly, but incorrectly on the iPhone? My Process: An image in a PNG file Start a UIGraphicsBeginImageContext() Draw the PNG in a CGrect Draw text in the CGRect Create an UIImage from the context Set the image of a UIImaveView to the UIImage Set the ...
Got IT! Here is how I beat the SDK. For some reason, A UIImageView does not like the image produced by the UIGraphicsBeginImageContext. So instead, I changed my class as a subclass of a standard UIView (not UIImageView). Then I implemented the drawRect method. Inside the drawRect method, i put the same code I had in ...
476,296
<p>Hai Techies,</p> <p>I have some stored procedure which was written in SQL server.Now i want to migrate this to mysql.Is there any freeware tools which can do this for me.</p>
[ { "answer_id": 476318, "author": "Lucas Jones", "author_id": 41981, "author_profile": "https://Stackoverflow.com/users/41981", "pm_score": 3, "selected": true, "text": "<p>I don't think so. You could just execute the query to create the procedure, ie:</p>\n\n<pre><code>CREATE PROCEDURE B...
2009/01/24
[ "https://Stackoverflow.com/questions/476296", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40521/" ]
Hai Techies, I have some stored procedure which was written in SQL server.Now i want to migrate this to mysql.Is there any freeware tools which can do this for me.
I don't think so. You could just execute the query to create the procedure, ie: ``` CREATE PROCEDURE Blah(foo int, bar text) END; ``` (I think) and then ask questions or Google any problems that occur.
476,328
<p>I needed a Low-Pass-Filter in one of my Scala projects and came up with this:</p> <pre><code>def filter(numbers: Seq[Double], filterSize: Int): Seq[Double] = { assert(filterSize &gt; 0) val ringBuffer = new Array[Double](filterSize) var ringBufferIndex = 0 numbers.map(x =&gt; { // update ring buffer ...
[ { "answer_id": 476349, "author": "Lemmy", "author_id": 58598, "author_profile": "https://Stackoverflow.com/users/58598", "pm_score": 0, "selected": false, "text": "<p>Here is a shorter version that I have come up with to tackle the first problem:</p>\n\n<pre><code> def filter(numbers: S...
2009/01/24
[ "https://Stackoverflow.com/questions/476328", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58598/" ]
I needed a Low-Pass-Filter in one of my Scala projects and came up with this: ``` def filter(numbers: Seq[Double], filterSize: Int): Seq[Double] = { assert(filterSize > 0) val ringBuffer = new Array[Double](filterSize) var ringBufferIndex = 0 numbers.map(x => { // update ring buffer ringBuffer(ringBuf...
To have your method take a generic collection type and return the same type, I believe you would need Higher Kinded types, as described in the [Generics of a Higher Kind](http://www.cs.kuleuven.be/~adriaan/files/genericshk/tcpoly-oopsla.pdf) paper. Unfortunately the current collections library predates this feature in ...
476,354
<p>I want to write a simple, dumb, X terminal emulator in C on a Linux system. </p> <p>At first, I just thought I would have to popen a shell and display its output. I checked xterm and rxvt code, and it looks a bit more complicated.</p> <p>First, I have to open a pseudo-terminal with openpty. So I look at the man pa...
[ { "answer_id": 476994, "author": "Dave C", "author_id": 55504, "author_profile": "https://Stackoverflow.com/users/55504", "pm_score": 6, "selected": true, "text": "<p>With respect to the master/slave part of your question, from the <a href=\"http://www.freebsd.org/cgi/man.cgi?query=pty&a...
2009/01/24
[ "https://Stackoverflow.com/questions/476354", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58624/" ]
I want to write a simple, dumb, X terminal emulator in C on a Linux system. At first, I just thought I would have to popen a shell and display its output. I checked xterm and rxvt code, and it looks a bit more complicated. First, I have to open a pseudo-terminal with openpty. So I look at the man page and see that o...
With respect to the master/slave part of your question, from the [pty(4)](http://www.freebsd.org/cgi/man.cgi?query=pty&apropos=0&sektion=4&manpath=FreeBSD+7.1-RELEASE&format=html "pty(4) man page") man page (which is referenced from the openpty(3) man page on my system): > > A pseudo terminal is a pair of > characte...
476,356
<p>I am bringing out a separate question from <a href="https://stackoverflow.com/questions/471952/-parameter-of-ruby-block">here</a>. It really confused me. Here is the definition of add_mapping method:</p> <pre><code>def add_mapping(regexp, &amp;proc) @test_mappings &lt;&lt; [regexp, proc] end </code></pre> <p>How...
[ { "answer_id": 476372, "author": "geowa4", "author_id": 50214, "author_profile": "https://Stackoverflow.com/users/50214", "pm_score": 0, "selected": false, "text": "<p>Yep, according to the <a href=\"http://www.rubycentral.com/book/ref_c_proc.html\" rel=\"nofollow noreferrer\">documentat...
2009/01/24
[ "https://Stackoverflow.com/questions/476356", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44512/" ]
I am bringing out a separate question from [here](https://stackoverflow.com/questions/471952/-parameter-of-ruby-block). It really confused me. Here is the definition of add\_mapping method: ``` def add_mapping(regexp, &proc) @test_mappings << [regexp, proc] end ``` How could `proc` here get executed and return res...
Eric, what add\_mapping does is just adding a regular expresion + proc tuple to an array called @test\_mappings. add\_mappings does not execute the proc. I don't know how ZenTest works but it should be executing the procs after reading all add\_mapping calls. Check out the code for ZenTest and look out for @test\_map...
476,359
<p>I have checked 100% I am closing all handles on a file I recently created. But when I call "opendialog.execute;" the dialog pop up as usual but on the mouse over hint of a recently created file the entire thing crashes with a out of bounds error.</p> <p>I know this is not any of my out of bounds as if I open the fi...
[ { "answer_id": 476575, "author": "Cesar Romero", "author_id": 36875, "author_profile": "https://Stackoverflow.com/users/36875", "pm_score": 2, "selected": false, "text": "<p>Are you sure an instance of form1 is created?</p>\n\n<p>if yes:</p>\n\n<p>Why dont you use like this:</p>\n\n<pre>...
2009/01/24
[ "https://Stackoverflow.com/questions/476359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53915/" ]
I have checked 100% I am closing all handles on a file I recently created. But when I call "opendialog.execute;" the dialog pop up as usual but on the mouse over hint of a recently created file the entire thing crashes with a out of bounds error. I know this is not any of my out of bounds as if I open the file without...
The solution for this was to use activeX, it appears there was a bug intorduced after SP2 uses ActiveX; initialization OleInitialize(nil); finalization OleUninitialize end. oringinaly posted by the fox [here](https://stackoverflow.com/questions/586482/is-there-a-way-to-disable-the-hint-for-a-topendialog-in-delph...
476,364
<p>I'm having some issues validating some XML against a Schema, using .net and C#.</p> <p>I am using XmlReaderSettings with the ValidationEventHandler.</p> <p>However, this seems to stop catching errors after it has encountered the first error at a particular level within the XML file, instead of checking the next ta...
[ { "answer_id": 493054, "author": "Steen", "author_id": 1448983, "author_profile": "https://Stackoverflow.com/users/1448983", "pm_score": 0, "selected": false, "text": "<p>The XMLReader is described as a</p>\n\n<blockquote>\n <p>reader that provides fast, non-cached, forward-only access ...
2009/01/24
[ "https://Stackoverflow.com/questions/476364", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm having some issues validating some XML against a Schema, using .net and C#. I am using XmlReaderSettings with the ValidationEventHandler. However, this seems to stop catching errors after it has encountered the first error at a particular level within the XML file, instead of checking the next tag at the same lev...
This sounds like you have a `xsd:sequence` defined in your schema and the error occurs when the order of elements in your document does not match the order of the elements defined in the schema. Given this schema: ``` <?xml version="1.0" encoding="utf-8"?> <xsd:schema attributeFormDefault="unqualified" elem...
476,390
<p>How can I ask to <em>display</em> multiple vars in one line? So I want to get output like:</p> <pre><code>30 if(s[i] != '\0') 5: s[i] = 101 'e' 4: exp = 14 3: val = 123.45 2: sign = 1 1: i = 6 </code></pre> <p>I've been typing in disp s[i] ENTER disp exp ENTER (etc, etc) and I just know there's got to be a be...
[ { "answer_id": 477394, "author": "Employed Russian", "author_id": 50617, "author_profile": "https://Stackoverflow.com/users/50617", "pm_score": 4, "selected": true, "text": "<p>To establish multiple active \"variable displays\" without re-typing each of <code>display i</code>, <code>disp...
2009/01/24
[ "https://Stackoverflow.com/questions/476390", "https://Stackoverflow.com", "https://Stackoverflow.com/users/386102/" ]
How can I ask to *display* multiple vars in one line? So I want to get output like: ``` 30 if(s[i] != '\0') 5: s[i] = 101 'e' 4: exp = 14 3: val = 123.45 2: sign = 1 1: i = 6 ``` I've been typing in disp s[i] ENTER disp exp ENTER (etc, etc) and I just know there's got to be a better way to do this in one line o...
To establish multiple active "variable displays" without re-typing each of `display i`, `display s[i]`, etc. every time you restart GDB, use a GDB "canned command sequence". For example, add this to your `~/.gdbinit`: ``` define disp_vars disp i disp sign disp val disp exp disp s[i] end ``` Now you can ad...
476,394
<p>I am writing a fairly simple Django application where users can enter string queries. The application will the search through the database for this string.</p> <pre><code>Entry.objects.filter(headline__contains=query) </code></pre> <p>This query is pretty strait forward but not really helpful to someone who isn't ...
[ { "answer_id": 476420, "author": "nosklo", "author_id": 17160, "author_profile": "https://Stackoverflow.com/users/17160", "pm_score": 4, "selected": false, "text": "<p>You could try using python's <a href=\"http://docs.python.org/library/difflib\" rel=\"noreferrer\">difflib</a> module.</...
2009/01/24
[ "https://Stackoverflow.com/questions/476394", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41895/" ]
I am writing a fairly simple Django application where users can enter string queries. The application will the search through the database for this string. ``` Entry.objects.filter(headline__contains=query) ``` This query is pretty strait forward but not really helpful to someone who isn't 100% sure what they are lo...
djangos orm doesn't have this behavior out-of-box, but there are several projects that integrate django w/ search services like: * sphinx ([django-sphinx](http://github.com/dcramer/django-sphinx/tree/master)) * solr, a lightweight version of lucene ([djangosearch](https://code.google.com/p/django-solr-search/)) * luc...
476,402
<p>I have xml containing:</p> <pre><code>&lt;day p="d"&gt; &lt;day p="n"&gt; </code></pre> <p>What attributes do I need to add to Day class in order to deserialize the xml with XmlSerializer?</p>
[ { "answer_id": 476421, "author": "leppie", "author_id": 15541, "author_profile": "https://Stackoverflow.com/users/15541", "pm_score": 0, "selected": false, "text": "<pre><code>[XmlElement(\"day\")]\npublic class Day\n{\n [XmlAttribute(\"p\")]\n public string P {get;set;}\n}\n</code></p...
2009/01/24
[ "https://Stackoverflow.com/questions/476402", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have xml containing: ``` <day p="d"> <day p="n"> ``` What attributes do I need to add to Day class in order to deserialize the xml with XmlSerializer?
The following decorations - ``` [XmlType(TypeName="day")] public class Day { [XmlAttribute("p")] public string P { get; set; } } [XmlRoot("someObject")] public class SomeObject { [XmlArray("days")] public List<Day> Days { get; set; } } ``` Would serialise to: ``` <someObject xmlns:xsi="http://www.w...
476,426
<p>I have an HTML form - with PHP, I am sending the data of the form into a MySQL database. Some of the answers to the questions on the form have checkboxes. Obviously, the user does not have to tick all checkboxes for one question. I also want to make the other questions (including radio groups) optional.</p> <p>Howe...
[ { "answer_id": 476437, "author": "Gumbo", "author_id": 53114, "author_profile": "https://Stackoverflow.com/users/53114", "pm_score": 6, "selected": true, "text": "<p>Unchecked radio or checkbox elements are not submitted as they are not considered as <a href=\"http://www.w3.org/TR/REC-ht...
2009/01/24
[ "https://Stackoverflow.com/questions/476426", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58433/" ]
I have an HTML form - with PHP, I am sending the data of the form into a MySQL database. Some of the answers to the questions on the form have checkboxes. Obviously, the user does not have to tick all checkboxes for one question. I also want to make the other questions (including radio groups) optional. However, if I ...
Unchecked radio or checkbox elements are not submitted as they are not considered as [successful](http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.2). So you have to check if they are sent using the `isset` or `empty` function. ``` if (isset($_POST['checkbox'])) { // checkbox has been checked } ```
476,432
<p>I have a windows service listening to messages from a queue but the messages are not read from the queue.I created an event log to check for logs during service startup and shutdown but the logs are not written. I do not want to debug the service since it is a painful process.Is there a way to solve this issue.The m...
[ { "answer_id": 476444, "author": "DOK", "author_id": 27637, "author_profile": "https://Stackoverflow.com/users/27637", "pm_score": 0, "selected": false, "text": "<p>In my experience, the most common problem in writing to event logs is that the user does not have sufficient permission to ...
2009/01/24
[ "https://Stackoverflow.com/questions/476432", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49424/" ]
I have a windows service listening to messages from a queue but the messages are not read from the queue.I created an event log to check for logs during service startup and shutdown but the logs are not written. I do not want to debug the service since it is a painful process.Is there a way to solve this issue.The mess...
This certainly sounds as if the account that your windows service is running under doesn't have enough rights to write to the event log in question. Setting event log permissions for non-admin accounts can be a bit of a black art because you need to configure custom security descriptors using SDDL etc. However there's...
476,436
<p>Is there a null coalescing operator in Javascript?</p> <p>For example, in C#, I can do this:</p> <pre><code>String someString = null; var whatIWant = someString ?? "Cookies!"; </code></pre> <p>The best approximation I can figure out for Javascript is using the conditional operator:</p> <pre><code>var someString ...
[ { "answer_id": 476442, "author": "Tom", "author_id": 20, "author_profile": "https://Stackoverflow.com/users/20", "pm_score": 3, "selected": false, "text": "<p>After reading your clarification, @Ates Goral's answer provides how to perform the same operation you're doing in C# in JavaScrip...
2009/01/24
[ "https://Stackoverflow.com/questions/476436", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2596/" ]
Is there a null coalescing operator in Javascript? For example, in C#, I can do this: ``` String someString = null; var whatIWant = someString ?? "Cookies!"; ``` The best approximation I can figure out for Javascript is using the conditional operator: ``` var someString = null; var whatIWant = someString ? someStr...
**Update** JavaScript now supports the [nullish coalescing operator (??)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_Coalescing_Operator). It returns its right-hand-side operand when its left-hand-side operand is `null` or `undefined`, and otherwise returns its left-hand-side o...
476,443
<p>I have a collection of people that is paginated with will_paginate </p> <pre><code>@people = Person.paginate :page =&gt; params[:page], :limit =&gt; 10, :conditions =&gt; ['company_id = ? ' , @company.id ] </code></pre> <p>The people are shown on the company/view page and ren...
[ { "answer_id": 476482, "author": "geowa4", "author_id": 50214, "author_profile": "https://Stackoverflow.com/users/50214", "pm_score": 3, "selected": true, "text": "<p>Are you missing <code>per_page</code>?</p>\n" }, { "answer_id": 477433, "author": "Community", "author_id...
2009/01/24
[ "https://Stackoverflow.com/questions/476443", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58353/" ]
I have a collection of people that is paginated with will\_paginate ``` @people = Person.paginate :page => params[:page], :limit => 10, :conditions => ['company_id = ? ' , @company.id ] ``` The people are shown on the company/view page and rendered with a partial. Note that th...
Are you missing `per_page`?
476,455
<p>For all operation with Amazon services(S3, EC2, SimpleDB) You need to sign all resquest with HMAC-SHA-1 Signature(<a href="http://en.wikipedia.org/wiki/HMAC" rel="noreferrer">http://en.wikipedia.org/wiki/HMAC</a> , <a href="http://docs.amazonwebservices.com/AWSFWS/latest/DeveloperGuide/index.html?SummaryOfAuthentica...
[ { "answer_id": 476484, "author": "Fredrik Jansson", "author_id": 58237, "author_profile": "https://Stackoverflow.com/users/58237", "pm_score": 0, "selected": false, "text": "<p>I don't know if this is the case anymore, but there used to be restrictions on encryption algorithms and your r...
2009/01/24
[ "https://Stackoverflow.com/questions/476455", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41483/" ]
For all operation with Amazon services(S3, EC2, SimpleDB) You need to sign all resquest with HMAC-SHA-1 Signature(<http://en.wikipedia.org/wiki/HMAC> , <http://docs.amazonwebservices.com/AWSFWS/latest/DeveloperGuide/index.html?SummaryOfAuthentication.html>). I'm working under asp.net backend and there is no problems. ...
CommonCrypto does the trick. ``` #import <CommonCrypto/CommonHMAC.h> ``` then later ``` /* inputs: NSData *keyData; NSData *clearTextData */ uint8_t digest[CC_SHA1_DIGEST_LENGTH] = {0}; CCHmacContext hmacContext; CCHmacInit(&hmacContext, kCCHmacAlgSHA1, keyData.bytes, keyData.length); CCHmacUpdate(&hmacCont...
476,485
<p>I'm stuck at not being able to map texture to a square in openGLES. I'm trying to display a jpg image on the screen, and in order for me to do that, I draw a square that I want to then map image onto. However all I get as an output is a white square. I don't know what am I doing wrong. And this problem is preventing...
[ { "answer_id": 476520, "author": "codelogic", "author_id": 43427, "author_profile": "https://Stackoverflow.com/users/43427", "pm_score": 3, "selected": true, "text": "<p>You need to enable texturing:</p>\n\n<pre><code>glEnable( GL_TEXTURE_2D );\n</code></pre>\n\n<p>before rendering the s...
2009/01/24
[ "https://Stackoverflow.com/questions/476485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58145/" ]
I'm stuck at not being able to map texture to a square in openGLES. I'm trying to display a jpg image on the screen, and in order for me to do that, I draw a square that I want to then map image onto. However all I get as an output is a white square. I don't know what am I doing wrong. And this problem is preventing me...
You need to enable texturing: ``` glEnable( GL_TEXTURE_2D ); ``` before rendering the square.
476,488
<p>I've found myself writing</p> <pre><code>for(int i=0;i&lt;myvec.size();i++) myvec[i]-&gt;DoWhatever(param); </code></pre> <p>a lot, and I'd like to compress this into a <code>foreach</code> statement, but I'm not sure how to get <code>param</code> in there without going super-verbose. I've also got things like<...
[ { "answer_id": 476507, "author": "Martin York", "author_id": 14065, "author_profile": "https://Stackoverflow.com/users/14065", "pm_score": 5, "selected": true, "text": "<pre><code>#include &lt;vector&gt;\n#include &lt;algorithm&gt;\n#include &lt;functional&gt;\n\nclass X\n{\n public:\...
2009/01/24
[ "https://Stackoverflow.com/questions/476488", "https://Stackoverflow.com", "https://Stackoverflow.com/users/112/" ]
I've found myself writing ``` for(int i=0;i<myvec.size();i++) myvec[i]->DoWhatever(param); ``` a lot, and I'd like to compress this into a `foreach` statement, but I'm not sure how to get `param` in there without going super-verbose. I've also got things like ``` for(int i=0;i<myvec.size();i++) if(myvec[i]->I...
``` #include <vector> #include <algorithm> #include <functional> class X { public: void doWhat(int x) {} bool IsOK() const {return true;} }; class CallWhatIfOk { public: CallWhatIfOk(int p): param(p) {} void operator()(X& x) const { if (x.IsOK()) {x.doWhat(param);}...
476,499
<p>The standard naming convention in the Java world is to name packages, classes and methods according to:</p> <pre><code>com.domainname.productname (package) com.domainname.productname.ClassName (class) com.domainname.productname.ClassName.isUpperCase(String str) (method) </code></pre> <p>What is the C#/.NET standa...
[ { "answer_id": 476504, "author": "Kev", "author_id": 419, "author_profile": "https://Stackoverflow.com/users/419", "pm_score": 4, "selected": true, "text": "<p>AKU's answer should help you out:</p>\n\n<p><a href=\"https://stackoverflow.com/questions/55692/-net-namespaces#55700\">.NET nam...
2009/01/24
[ "https://Stackoverflow.com/questions/476499", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58394/" ]
The standard naming convention in the Java world is to name packages, classes and methods according to: ``` com.domainname.productname (package) com.domainname.productname.ClassName (class) com.domainname.productname.ClassName.isUpperCase(String str) (method) ``` What is the C#/.NET standard naming convention for th...
AKU's answer should help you out: [.NET namespaces](https://stackoverflow.com/questions/55692/-net-namespaces#55700) He links to Microsoft's guidelines: <http://msdn.microsoft.com/en-us/library/893ke618(VS.71).aspx> You should consider reading the the rest of the guidelines starting here: <http://msdn.microsoft.c...
476,511
<p>Is there a library in python that works like this?</p> <pre><code>&gt;&gt;&gt; resolvePath("http://www.asite.com/folder/currentpage.html", "anotherpage.html") 'http://www.asite.com/folder/anotherpage.html' &gt;&gt;&gt; resolvePath("http://www.asite.com/folder/currentpage.html", "folder2/anotherpage.html") 'http://w...
[ { "answer_id": 476521, "author": "James Brady", "author_id": 29903, "author_profile": "https://Stackoverflow.com/users/29903", "pm_score": 8, "selected": true, "text": "<p>Yes, there is <a href=\"https://docs.python.org/2/library/urlparse.html#urlparse.urljoin\" rel=\"noreferrer\"><code>...
2009/01/24
[ "https://Stackoverflow.com/questions/476511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/52509/" ]
Is there a library in python that works like this? ``` >>> resolvePath("http://www.asite.com/folder/currentpage.html", "anotherpage.html") 'http://www.asite.com/folder/anotherpage.html' >>> resolvePath("http://www.asite.com/folder/currentpage.html", "folder2/anotherpage.html") 'http://www.asite.com/folder/folder2/anot...
Yes, there is [`urlparse.urljoin`](https://docs.python.org/2/library/urlparse.html#urlparse.urljoin), or [`urllib.parse.urljoin`](https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urljoin) for Python 3. ``` >>> try: from urlparse import urljoin # Python2 ... except ImportError: from urllib.parse import ...
476,522
<p>Are any of the .NET generic collections marked as IXmlSerializable? I've tried List&lt;T&gt; and Collection&lt;T&gt; but neither work out of the box.</p> <p>Before I roll my own collection&lt;T&gt;, list&lt;T&gt;, or dictionary&lt;T&gt; class, I thought I'd check to see whether Microsoft had included something that...
[ { "answer_id": 476528, "author": "Mike", "author_id": 52068, "author_profile": "https://Stackoverflow.com/users/52068", "pm_score": 3, "selected": true, "text": "<p>As far as I know, there aren't any. You could take a look at the attached link, though. I think you'll find it useful.</p>\...
2009/01/24
[ "https://Stackoverflow.com/questions/476522", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19112/" ]
Are any of the .NET generic collections marked as IXmlSerializable? I've tried List<T> and Collection<T> but neither work out of the box. Before I roll my own collection<T>, list<T>, or dictionary<T> class, I thought I'd check to see whether Microsoft had included something that does this already. It seems like basic ...
As far as I know, there aren't any. You could take a look at the attached link, though. I think you'll find it useful. [Serialize and deserialize objects as Xml using generic types in C# 2.0](https://web.archive.org/web/20200204000600/http://geekswithblogs.net:80/paulwhitblog/archive/2007/07/20/114076.aspx)
476,529
<p>How do I do a Case WHEN in Linq to SQL (vb.net please).</p> <p>In SQL it would be like this:</p> <pre><code>SELECT CASE WHEN condition THEN trueresult [...n] [ELSE elseresult] END </code></pre> <p>How would I do this in Linq to SQL?</p>
[ { "answer_id": 476670, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 2, "selected": false, "text": "<p>I haven't tried this but you may be able to do something like:</p>\n\n<pre><code>Dim query = From tbl In db.Table _\...
2009/01/24
[ "https://Stackoverflow.com/questions/476529", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47167/" ]
How do I do a Case WHEN in Linq to SQL (vb.net please). In SQL it would be like this: ``` SELECT CASE WHEN condition THEN trueresult [...n] [ELSE elseresult] END ``` How would I do this in Linq to SQL?
Check This Out ``` var data = from d in db.tb select new { CaseResult = ( d.Col1 == “Case1” ? "Case 1 Rised" : d.Col1 == “Case2” ? "Case 2 Rised" : "Unknown Case") }; ``` Please Note that [ ? Symbol = then] , [ : Symbol = Or].
476,534
<p>I know that C# supports covariance in arrays like this :</p> <pre><code>object[] array = new string[3]; </code></pre> <p>But I'm getting an error when it tries to compile the below code</p> <pre><code>class Dummy&lt;K,T&gt; where T:K { public void foo() { K[] arr = new T[4]; } } </code></pre> ...
[ { "answer_id": 476536, "author": "Fredrik Jansson", "author_id": 58237, "author_profile": "https://Stackoverflow.com/users/58237", "pm_score": -1, "selected": false, "text": "<p>type T has to support implicit convertion to K. E.g.</p>\n\n<p>T a = new T();\nK b = a;</p>\n\n<p>has to be va...
2009/01/24
[ "https://Stackoverflow.com/questions/476534", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I know that C# supports covariance in arrays like this : ``` object[] array = new string[3]; ``` But I'm getting an error when it tries to compile the below code ``` class Dummy<K,T> where T:K { public void foo() { K[] arr = new T[4]; } } ``` It says "Cannot implicitly convert type 'T[]' to 'K...
You have to specify that both T and K are reference types. Array covariance only works with reference types. Change the declaration to: ``` class Dummy<K,T> where T : class, K ``` and it works fine. You don't have to specify that K is a reference type, because if T is a reference type and it derives from or implemen...
476,540
<p>I'm basically trying to teach myself how to code and I want to follow good practices. There are obvious benefits to unit testing. There is also much zealotry when it comes to unit-testing and I prefer a much more pragmatic approach to coding and life in general. As context, I'm currently writing my first "real" appl...
[ { "answer_id": 476590, "author": "Rasmus Faber", "author_id": 5542, "author_profile": "https://Stackoverflow.com/users/5542", "pm_score": 3, "selected": false, "text": "<p>You are right: the simplicity of the service makes these tests uninteresting. It is not until you get more business ...
2009/01/24
[ "https://Stackoverflow.com/questions/476540", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1880/" ]
I'm basically trying to teach myself how to code and I want to follow good practices. There are obvious benefits to unit testing. There is also much zealotry when it comes to unit-testing and I prefer a much more pragmatic approach to coding and life in general. As context, I'm currently writing my first "real" applica...
Essentially what you are testing here is that the methods are getting called, not whether or not they actually work. Which is what mocks are supposed to do. Instead of calling the method, they just check to see if the method got called, and return whatever is in the Return() statement. So in your assertion here: ``` A...
476,555
<p>I've got a gridview that is bound to a dataview in the codebehind. The datasource is actually powershell, so I'm processing the data myself. This works fine and displays the result how I want. However, when I try to enable paging, I get this error when opening the page:</p> <p>The table must contain row sections ...
[ { "answer_id": 485723, "author": "Sam Cogan", "author_id": 8768, "author_profile": "https://Stackoverflow.com/users/8768", "pm_score": 3, "selected": true, "text": "<p>There were 2 issues here for anyone that comes across this issue. Firstly, for some reason, setting the paging settings ...
2009/01/24
[ "https://Stackoverflow.com/questions/476555", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8768/" ]
I've got a gridview that is bound to a dataview in the codebehind. The datasource is actually powershell, so I'm processing the data myself. This works fine and displays the result how I want. However, when I try to enable paging, I get this error when opening the page: The table must contain row sections in order of...
There were 2 issues here for anyone that comes across this issue. Firstly, for some reason, setting the paging settings in the aspx page, rather than the code behind fixed the first error, not really sure why. I then recieved another error, because the datasource I'm using is not a sql datasource, its a custom one, so ...
476,557
<p>Given an operation contract such as:</p> <pre><code>[OperationContract] void Operation(string param1, string param2, int param3); </code></pre> <p>This could be redesigned to:</p> <pre><code>[MessageContract] public class OperationRequest { [MessageBodyMember] public string Param1 { get; set; } [Mess...
[ { "answer_id": 478649, "author": "Keith Fitzgerald", "author_id": 49611, "author_profile": "https://Stackoverflow.com/users/49611", "pm_score": 0, "selected": false, "text": "<p>I think it honestly depends on the scenario. If you're just exchanging simple types [i.e. string], OperationCo...
2009/01/24
[ "https://Stackoverflow.com/questions/476557", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58644/" ]
Given an operation contract such as: ``` [OperationContract] void Operation(string param1, string param2, int param3); ``` This could be redesigned to: ``` [MessageContract] public class OperationRequest { [MessageBodyMember] public string Param1 { get; set; } [MessageBodyMember] public string Para...
`XML` usually tends to be camelCased. `WSDL` and `XML` Schema use camelCasing for both elements and attributes, for example check out the [syntax](http://www.w3schools.com/wsdl/wsdl_syntax.asp) and [schema](http://www.w3schools.com/Schema/schema_howto.asp). Why `SOAP` was defined differently, I do not know, but it use...
476,573
<p>Hi I need to create a module in drupal to display some data, not being a drupal developer and after reading a couple of tutorials, i cant seem to display anything.</p> <p>I have the next code:</p> <pre><code>&lt;?php function helloworld_perm() { return array('access helloworld content'); } function helloworld_...
[ { "answer_id": 476631, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": true, "text": "<p>From the way that your menu array is structured in <code>helloworld_menu()</code>, I'm assuming that this is Drupal 6. If so...
2009/01/24
[ "https://Stackoverflow.com/questions/476573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47846/" ]
Hi I need to create a module in drupal to display some data, not being a drupal developer and after reading a couple of tutorials, i cant seem to display anything. I have the next code: ``` <?php function helloworld_perm() { return array('access helloworld content'); } function helloworld_listado(){ return "yea"...
From the way that your menu array is structured in `helloworld_menu()`, I'm assuming that this is Drupal 6. If so, you need to rename 'access' to 'access arguments'. See <http://api.drupal.org/api/function/hook_menu/6>. The Drupal API documentation also includes a heavily-commented page\_example.module that's doing ba...
476,576
<p>I'm a German student and for computer classes I need to implement the DES-encryption in Java (by myself, not by using the Java-API) and explain it in detail. I didn't find any Java-code-examples using google, however <a href="http://cppgm.blogspot.com/2008/01/data-encryption-standard.html" rel="nofollow noreferrer">...
[ { "answer_id": 476770, "author": "Lawrence Dol", "author_id": 8946, "author_profile": "https://Stackoverflow.com/users/8946", "pm_score": 1, "selected": false, "text": "<p>Or, more concisely:</p>\n\n<pre><code>output.print((char)M);\n</code></pre>\n\n<p>This assumes M is a numeric value ...
2009/01/24
[ "https://Stackoverflow.com/questions/476576", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58386/" ]
I'm a German student and for computer classes I need to implement the DES-encryption in Java (by myself, not by using the Java-API) and explain it in detail. I didn't find any Java-code-examples using google, however [I did find an easy implementation in C](http://cppgm.blogspot.com/2008/01/data-encryption-standard.htm...
Its late and I'm tired but this isn't a DES implementation, is it? It looks more like [RSA](http://en.wikipedia.org/wiki/RSA#Key_Generation). Yeah the link on your post is an asymmetrical cryptosystem. DES is symmetrical.
476,589
<p>My particular problem:</p> <p>I have a string which specifies an aribitrary type in a configuration class</p> <p><code>Config.numberType = "System.Foo";</code></p> <p>where <code>Foo</code> is a type like <code>Decimal</code> or <code>Double</code></p> <p>I use <code>Type.GetType(Config.numberType)</code> to ret...
[ { "answer_id": 476601, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 3, "selected": false, "text": "<blockquote>\n <p>How do I get from that type to being\n able to use, System.Foo.TryParse() ?</p>\n</blockquote>\n\n<p>You'll ...
2009/01/24
[ "https://Stackoverflow.com/questions/476589", "https://Stackoverflow.com", "https://Stackoverflow.com/users/199/" ]
My particular problem: I have a string which specifies an aribitrary type in a configuration class `Config.numberType = "System.Foo";` where `Foo` is a type like `Decimal` or `Double` I use `Type.GetType(Config.numberType)` to return the corresponding type. How do I get from that type to being able to use, `System...
As many have said - there isn't a direct route. I expect one close option is `TypeConverter`: ``` Type type = typeof(double); string text = "123.45"; object value = TypeDescriptor.GetConverter(type) .ConvertFromInvariantString(text); ``` Of course, you may need `try`/`catch` to handle exceptions...
476,615
<p>Can anyone explain to me the purpose of ungetch? This is from K&amp;R chapter 4 where you create a Reverse Polish Calculator. </p> <p>I've ran the program without the call to ungetch and in my tests it still works the same.</p> <pre><code> int getch(void) /* get a (possibly pushed back) character */ { ...
[ { "answer_id": 476619, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 3, "selected": false, "text": "<p>Try running the program without spaces around operators. I don't recall precisely the format of that example and I don...
2009/01/24
[ "https://Stackoverflow.com/questions/476615", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58657/" ]
Can anyone explain to me the purpose of ungetch? This is from K&R chapter 4 where you create a Reverse Polish Calculator. I've ran the program without the call to ungetch and in my tests it still works the same. ``` int getch(void) /* get a (possibly pushed back) character */ { if (bufp > 0) { ...
I don't know about the specific example you're referring to (It's probaby 23 years since I read K&R, and that was the first edition.), but often when parsing it's convenient to 'peek' at the next character to see if it is part of what you're currently parsing. For instance, if you're reading a number you want to keep r...
476,623
<p>I have got an UITableView. How to <em>simply</em> fill it with three elements, for example "e1", "e2", "e3" ?</p>
[ { "answer_id": 476922, "author": "Igor", "author_id": 174644, "author_profile": "https://Stackoverflow.com/users/174644", "pm_score": 4, "selected": true, "text": "<p>set DataSource of your table to your class and define in your class 3 methods:</p>\n\n<pre><code>- (NSInteger)numberOfSec...
2009/01/24
[ "https://Stackoverflow.com/questions/476623", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have got an UITableView. How to *simply* fill it with three elements, for example "e1", "e2", "e3" ?
set DataSource of your table to your class and define in your class 3 methods: ``` - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section { return 3; } - (UITableViewCell *)tableView:(UITableView ...
476,630
<p>How do a I create a validator, which has these simple rules. An expression is valid if </p> <p>it must start with a letter<br> it must end with a letter<br> it can contain a dash (minus sign), but not at start or end of the expression </p>
[ { "answer_id": 476637, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "<pre><code>^[a-zA-Z]+-?[a-zA-Z]+$\n</code></pre>\n\n<p>E.g.</p>\n\n<pre><code>def validate(whatever)\n reg = /^[a-zA-Z]+-?[a-...
2009/01/24
[ "https://Stackoverflow.com/questions/476630", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
How do a I create a validator, which has these simple rules. An expression is valid if it must start with a letter it must end with a letter it can contain a dash (minus sign), but not at start or end of the expression
``` /^[A-Za-z]+(-?[A-Za-z]+)?$/ ``` this seems like what you want. ^ = match the start position ^[A-Za-z]+ = start position is followed by any at least one or more letters. -? = is there zero or one hyphens (use "\*" if there can be multiple hyphens in a row). [A-Za-z]+ = hyphen is followed by one or more l...
476,647
<p>My problem is with understanding the finer point of mixed langage programming and accessing API's in external libraries. My skills at C++ are nonexistent and at VB, mediocre.</p> <p>I have a c++ dll compiled (portaudio library), and am trying to access it from VB (Visual Studio 2005). I am getting MarshallDirect...
[ { "answer_id": 476807, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 2, "selected": false, "text": "<p>Your API function declaration is wrong. The function returns a pointer which is not reflected in your code. The si...
2009/01/24
[ "https://Stackoverflow.com/questions/476647", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2135219/" ]
My problem is with understanding the finer point of mixed langage programming and accessing API's in external libraries. My skills at C++ are nonexistent and at VB, mediocre. I have a c++ dll compiled (portaudio library), and am trying to access it from VB (Visual Studio 2005). I am getting MarshallDirectiveExcepti...
Your API function declaration is wrong. The function returns a pointer which is not reflected in your code. The signature translates to VB as follows: ``` Private Declare Function Pa_GetDeviceInfo Lib "portaudio_x86.dll" ( _ ByVal dindex As Integer _ ) As IntPtr ``` Of course, using an `IntPtr` directly is not e...
476,663
<p>I am a somewhat experienced Rails developer and I thought I would try out ASP.NET's version of MVC. In doing so I also decided to try Linq->Sql...</p> <p>I am a bit confused about the way Linq->Sql handles joins.</p> <p>A trivial example of my schema is :</p> <p><strong>books</strong>:<br> id<br> title </p> <p>...
[ { "answer_id": 476669, "author": "Bramha Ghosh", "author_id": 3268, "author_profile": "https://Stackoverflow.com/users/3268", "pm_score": 0, "selected": false, "text": "<p>I don't think your expected result is supported in Linq to Sql.</p>\n\n<p>What you're doing may feel wrong, but I th...
2009/01/24
[ "https://Stackoverflow.com/questions/476663", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36285/" ]
I am a somewhat experienced Rails developer and I thought I would try out ASP.NET's version of MVC. In doing so I also decided to try Linq->Sql... I am a bit confused about the way Linq->Sql handles joins. A trivial example of my schema is : **books**: id title **categories**: id name **books\_categor...
Use a partial class implementation for Book and add appropriate methods for categories and their properties. Have the properties front-end the Books\_Categories property (you can make this have private visibility to force implementation through your Categories property). ``` public partial class Books { public IEn...
476,678
<p>I'm trying to get a <code>JTabbedPane</code> where all tabs (the actual tabs, not the components) have the same width (either the minimum width needed for the widest label or a constant width). </p> <p>I've tried to override <code>BasicTabbedPaneUI.getTabBounds(int tabIndex, Rectangle dest)</code>, but apparently t...
[ { "answer_id": 476756, "author": "Lawrence Dol", "author_id": 8946, "author_profile": "https://Stackoverflow.com/users/8946", "pm_score": 2, "selected": false, "text": "<p>I think it's not as complicated as you've done. Just use setTabComponentAt() with a JLabel on which you've set prefe...
2009/01/24
[ "https://Stackoverflow.com/questions/476678", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49540/" ]
I'm trying to get a `JTabbedPane` where all tabs (the actual tabs, not the components) have the same width (either the minimum width needed for the widest label or a constant width). I've tried to override `BasicTabbedPaneUI.getTabBounds(int tabIndex, Rectangle dest)`, but apparently this method isn't used by the pai...
The answer is simple. When we put the name for the tab, just format the name using html. say tp - JTabbedPane object ``` tp.addTab("<html><body><table width='150'>Name</table></body></html>",Componentobject) ```
476,679
<p>I'm looking for a quick and easy way to preload images with JavaScript. I'm using jQuery if that's important.</p> <p>I saw this here (<a href="http://nettuts.com/tutorials/javascript-ajax/the-definitive-guide-to-creating-a-practical-jquery-plugin/" rel="noreferrer">http://nettuts.com...</a>):</p> <pre><code>functi...
[ { "answer_id": 476681, "author": "James", "author_id": 21677, "author_profile": "https://Stackoverflow.com/users/21677", "pm_score": 11, "selected": true, "text": "<p>Quick <em>and</em> easy:</p>\n\n<pre><code>function preload(arrayOfImages) {\n $(arrayOfImages).each(function(){\n ...
2009/01/24
[ "https://Stackoverflow.com/questions/476679", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm looking for a quick and easy way to preload images with JavaScript. I'm using jQuery if that's important. I saw this here ([http://nettuts.com...](http://nettuts.com/tutorials/javascript-ajax/the-definitive-guide-to-creating-a-practical-jquery-plugin/)): ``` function complexLoad(config, fileNames) { for (var x ...
Quick *and* easy: ``` function preload(arrayOfImages) { $(arrayOfImages).each(function(){ $('<img/>')[0].src = this; // Alternatively you could use: // (new Image()).src = this; }); } // Usage: preload([ 'img/imageName.jpg', 'img/anotherOne.jpg', 'img/blahblahblah.jpg' ]);...
476,726
<p>I have a CSV of file of data that I can load in R using <code>read.csv()</code></p> <p>Some of the data is missing, so I want to reduce the data frame down to set that consists entirely of non-missing data, i.e. if a <code>NULL</code> appears anywhere, I want to exclude that column and row from the filtered data se...
[ { "answer_id": 476739, "author": "rguha", "author_id": 58681, "author_profile": "https://Stackoverflow.com/users/58681", "pm_score": 4, "selected": true, "text": "<p>If <code>x</code> is your <code>data.frame</code> (or <code>matrix</code>) then</p>\n\n<pre><code>x[ ,apply(x, 2, function...
2009/01/24
[ "https://Stackoverflow.com/questions/476726", "https://Stackoverflow.com", "https://Stackoverflow.com/users/277/" ]
I have a CSV of file of data that I can load in R using `read.csv()` Some of the data is missing, so I want to reduce the data frame down to set that consists entirely of non-missing data, i.e. if a `NULL` appears anywhere, I want to exclude that column and row from the filtered data set. I know I can probably do thi...
If `x` is your `data.frame` (or `matrix`) then ``` x[ ,apply(x, 2, function(z) !any(is.na(z)))] ``` Since your example uses `NULL`, `is.na(·)` will be replaced by `is.null(·)` Alternatively you can look at `subset(·)`.
476,730
<p>I'd like to know if it's possible to determine what <strong>inline styling</strong> has been attributed to an HTML element. I do not need to retrieve the value, but rather just detect if it's been set inline or not.</p> <p>For instance, if the HTML were:</p> <pre><code>&lt;div id="foo" style="width: 100px; height...
[ { "answer_id": 476744, "author": "AnthonyWJones", "author_id": 17516, "author_profile": "https://Stackoverflow.com/users/17516", "pm_score": 1, "selected": false, "text": "<p>The style property of an HTML Element returns a style object which lists all the properties. Any that have a val...
2009/01/24
[ "https://Stackoverflow.com/questions/476730", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58249/" ]
I'd like to know if it's possible to determine what **inline styling** has been attributed to an HTML element. I do not need to retrieve the value, but rather just detect if it's been set inline or not. For instance, if the HTML were: ``` <div id="foo" style="width: 100px; height: 100px; background: green;"></div> `...
**Updated to work with IE** You could try something like this ``` function hasInlineStyle(obj, style) { var attrs = obj.getAttribute('style'); if(attrs === null) return false; if(typeof attrs == 'object') attrs = attrs.cssText; var styles = attrs.split(';'); for(var x = 0; x < styles.length; x++) ...
476,731
<p>I have a model Foo which have a ForeignKey to the User model.</p> <p>Later, I need to grab all the User's id and put then on a list</p> <pre><code>foos = Foo.objects.filter(...) l = [ f.user.id for f in foos ] </code></pre> <p>But when I do that, django grabs the whole User instance from the DB instead of giving...
[ { "answer_id": 476805, "author": "Tiago", "author_id": 55283, "author_profile": "https://Stackoverflow.com/users/55283", "pm_score": 0, "selected": false, "text": "<p>Nevermind... I´m not sure why this didn´t work before when I tried, but this is how to do:</p>\n\n<pre><code>l = [ f.user...
2009/01/24
[ "https://Stackoverflow.com/questions/476731", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55283/" ]
I have a model Foo which have a ForeignKey to the User model. Later, I need to grab all the User's id and put then on a list ``` foos = Foo.objects.filter(...) l = [ f.user.id for f in foos ] ``` But when I do that, django grabs the whole User instance from the DB instead of giving me just the numeric user's id, w...
Use [queryset's values() function](http://docs.djangoproject.com/en/dev/ref/models/querysets/#values-fields), which will return a list of dictionaries containing name/value pairs for each attribute passed as parameters: ``` >>> Foo.objects.all().values('user__id') [{'user__id': 1}, {'user__id' 2}, {'user__id': 3}] ``...
476,736
<p>Here's a simple method with a <code>foreach</code> loop:</p> <pre><code>IEnumerable&lt;XElement&gt; FieldsToXElements(object instance) { var fieldElements = new List&lt;XElement&gt;(); foreach (var field in instance.GetType().GetFields(instance)) { fieldElements.Add(new XElement(field.Name, fie...
[ { "answer_id": 476742, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 5, "selected": true, "text": "<p>No, I don't expect any direct <strong>language</strong> suport (i.e. inside the query syntax) any time soon.</p>\n\...
2009/01/24
[ "https://Stackoverflow.com/questions/476736", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11574/" ]
Here's a simple method with a `foreach` loop: ``` IEnumerable<XElement> FieldsToXElements(object instance) { var fieldElements = new List<XElement>(); foreach (var field in instance.GetType().GetFields(instance)) { fieldElements.Add(new XElement(field.Name, field.GetValue(instance))); } r...
No, I don't expect any direct **language** suport (i.e. inside the query syntax) any time soon. It sounds like you mean the mythical `ForEach` extension method; trivial to add, but Eric Lippert has commented numerous times about the cross between side-effect-free functional code and `Action<T>` with side-effects. In p...
476,763
<p>I know you can use get_class($this) normally but I need to get the name of the class in a static function where the object hasn't been instantiated.</p> <p>See the following code:</p> <pre><code>class ExampleClass { static function getClassName() { echo get_class($this); // doesn't work unless the ...
[ { "answer_id": 476778, "author": "Andrew G. Johnson", "author_id": 428190, "author_profile": "https://Stackoverflow.com/users/428190", "pm_score": 2, "selected": false, "text": "<p>I figured out you can use __CLASS__ to get the class name. Example:</p>\n\n<pre><code>class ExampleClass\n...
2009/01/24
[ "https://Stackoverflow.com/questions/476763", "https://Stackoverflow.com", "https://Stackoverflow.com/users/428190/" ]
I know you can use get\_class($this) normally but I need to get the name of the class in a static function where the object hasn't been instantiated. See the following code: ``` class ExampleClass { static function getClassName() { echo get_class($this); // doesn't work unless the object is instantiat...
I think you're looking for the get\_called\_class() function, if you wish to get the class name from a static method. See [get\_called\_class documentation](http://php.net/manual/en/function.get-called-class.php) for more information.
476,772
<p>There are a lot of articles around the web concerning Python performance. The first thing you read is concatenating strings should not be done using '+'; avoid s1 + s2 + s3, and instead use <em>str.join</em></p> <p>I tried the following: concatenating two strings as part of a directory path: three approaches:</p> <o...
[ { "answer_id": 476787, "author": "RSabet", "author_id": 49219, "author_profile": "https://Stackoverflow.com/users/49219", "pm_score": 4, "selected": true, "text": "<p>It is true you should not use '+'. Your example is quite special. Try the same code with:</p>\n<pre><code>s1 = '*' * 1000...
2009/01/24
[ "https://Stackoverflow.com/questions/476772", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58683/" ]
There are a lot of articles around the web concerning Python performance. The first thing you read is concatenating strings should not be done using '+'; avoid s1 + s2 + s3, and instead use *str.join* I tried the following: concatenating two strings as part of a directory path: three approaches: 1. '+' which I should...
It is true you should not use '+'. Your example is quite special. Try the same code with: ``` s1 = '*' * 100000 s2 = '+' * 100000 ``` Then the second version (str.join) is much faster.
476,774
<p>I currently have following two tables:</p> <pre><code>CREATE TABLE files_list ( 'listid' INT, 'name' VARCHAR(25), 'synonym' VARCHAR(25), 'description' VARCHAR(25) ); CREATE TABLE files_tags ( 'tag_name' VARCHAR(25), 'listid' INT ); </code></pre> <p>If someone uses the keyword "dragon b...
[ { "answer_id": 478854, "author": "ysth", "author_id": 17389, "author_profile": "https://Stackoverflow.com/users/17389", "pm_score": 0, "selected": false, "text": "<p>Be careful when using union to actually get the columns you want for each unioned query. And this case, a subquery seems ...
2009/01/24
[ "https://Stackoverflow.com/questions/476774", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58670/" ]
I currently have following two tables: ``` CREATE TABLE files_list ( 'listid' INT, 'name' VARCHAR(25), 'synonym' VARCHAR(25), 'description' VARCHAR(25) ); CREATE TABLE files_tags ( 'tag_name' VARCHAR(25), 'listid' INT ); ``` If someone uses the keyword "dragon ball", at the moment, I use...
It would make more sense to join the tables. ``` SELECT name, synonym, description, tag_name FROM `files_list` WHERE ( name LIKE '%dragon%' OR synonym LIKE '%dragon%' OR description LIKE '%dragon%' OR name LIKE '%ball%' OR synonym LIKE '%ball%' OR description LIKE '%ball%' ) OUTER JOIN files_tags on files_tags.listid ...
476,793
<p>I'm running PHP 5.2.8 on Apache 2.2.11 on Windows XP SP 3. In php.ini,</p> <pre><code>extension_dir = "C:\Program Files\PHP\ext" extension=php_mysql.dll </code></pre> <p>In error.log:</p> <pre><code>PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\Program Files\\PHP\\ext\\php_mysql.dll' - The specif...
[ { "answer_id": 476799, "author": "Erik", "author_id": 6733, "author_profile": "https://Stackoverflow.com/users/6733", "pm_score": 1, "selected": false, "text": "<p>You could try</p>\n\n<p>extension_dir = \"C:/Program Files/PHP/ext\"</p>\n\n<p>Edit: No, not that. Seems you need to add it ...
2009/01/24
[ "https://Stackoverflow.com/questions/476793", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23107/" ]
I'm running PHP 5.2.8 on Apache 2.2.11 on Windows XP SP 3. In php.ini, ``` extension_dir = "C:\Program Files\PHP\ext" extension=php_mysql.dll ``` In error.log: ``` PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\Program Files\\PHP\\ext\\php_mysql.dll' - The specified module could not be found.\r\n in...
Try adding a **trailing slash** to your `extension_dir` path. This is what I am using in my WAMP setup: ``` extension_dir = "D:\php\ext\" ; ...snip... extension=php_gd2.dll ```
476,797
<p>I am having an odd problem with my SQL Server express 2005 DB. It is running on a 2003 server. With VS2005 I can access the db without any problem. But when I try and run the application I get:</p> <pre><code> Cannot open user default database. Login failed. Login failed for user 'NT AUTHORITY\NETWORK SERVICE'....
[ { "answer_id": 476828, "author": "AnthonyWJones", "author_id": 17516, "author_profile": "https://Stackoverflow.com/users/17516", "pm_score": 1, "selected": true, "text": "<p>The difference isn't related to ACLs on the folder but to that fact that the security context is mapped to a user ...
2009/01/24
[ "https://Stackoverflow.com/questions/476797", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6486/" ]
I am having an odd problem with my SQL Server express 2005 DB. It is running on a 2003 server. With VS2005 I can access the db without any problem. But when I try and run the application I get: ``` Cannot open user default database. Login failed. Login failed for user 'NT AUTHORITY\NETWORK SERVICE'......... .ldf may...
The difference isn't related to ACLs on the folder but to that fact that the security context is mapped to a user in the DB. Your DB will have a mapping for your user account probably to dbo. If the Network Service account is going to use the DB you need to create a user in the db to map to Machine account.
476,800
<p>Is it possible to find the greatest of two integers without any comparison? I found some solutions: </p> <pre><code>if(!(a/b)) // if a is less than b then division result will be zero. { cout &lt;&lt; " b is greater than a"; } else if (!(a-b)) // we know a is greater than or equal to b now. check whether they...
[ { "answer_id": 476806, "author": "fmsf", "author_id": 26004, "author_profile": "https://Stackoverflow.com/users/26004", "pm_score": 0, "selected": false, "text": "<pre><code>(!(a/b) ? cout &lt;&lt; \" b is greater than a\" : (!(b-a) ? cout &lt;&lt; \"a and b are equal\" : cout &lt;&lt;...
2009/01/24
[ "https://Stackoverflow.com/questions/476800", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48911/" ]
Is it possible to find the greatest of two integers without any comparison? I found some solutions: ``` if(!(a/b)) // if a is less than b then division result will be zero. { cout << " b is greater than a"; } else if (!(a-b)) // we know a is greater than or equal to b now. check whether they are equal. { cou...
Subtract them and check the sign using nasty bit twiddling hacks <http://graphics.stanford.edu/~seander/bithacks.html> Don't do this in production code if the other programmers know where you live.
476,810
<p>I thought that I'll be clever and use subquery to get my <a href="https://stackoverflow.com/questions/470992/how-to-count-number-of-different-items-in-sql#471152">report</a> in one go. But after running into problems and reading documentation I saw that my approach does not work in MySQL. My inner query returns ~100...
[ { "answer_id": 476975, "author": "Noah Goodrich", "author_id": 20178, "author_profile": "https://Stackoverflow.com/users/20178", "pm_score": 4, "selected": true, "text": "<p>Try using an INNER JOIN (something like this):</p>\n\n<pre><code>SELECT p1.surname ,p1.name,p1.id,r1.start_date,r1...
2009/01/24
[ "https://Stackoverflow.com/questions/476810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44715/" ]
I thought that I'll be clever and use subquery to get my [report](https://stackoverflow.com/questions/470992/how-to-count-number-of-different-items-in-sql#471152) in one go. But after running into problems and reading documentation I saw that my approach does not work in MySQL. My inner query returns ~100 records and o...
Try using an INNER JOIN (something like this): ``` SELECT p1.surname ,p1.name,p1.id,r1.start_date,r1.end_date,c1.short_name FROM ejl_players p1 INNER JOIN ( SELECT p.id FROM ejl_players p LEFT JOIN ejl_registration r ON (r.player_id = p.id) LEFT JOIN ejl_teams t ON (r.team_id = t.id) LEFT JOIN e...
476,813
<p>I have an array of FileReference objects which have several listeners attached to each of them, should I be removing each listener in it's handler method, or should I remove them all in the complete handler?</p> <p>I read somewhere to use weak references for listeners, but I would think it would be better to explic...
[ { "answer_id": 476841, "author": "Christian Nunciato", "author_id": 32129, "author_profile": "https://Stackoverflow.com/users/32129", "pm_score": 4, "selected": true, "text": "<p>It's always a good idea to remove your listeners explicitly when you no longer need them, yeah, and the way y...
2009/01/24
[ "https://Stackoverflow.com/questions/476813", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49684/" ]
I have an array of FileReference objects which have several listeners attached to each of them, should I be removing each listener in it's handler method, or should I remove them all in the complete handler? I read somewhere to use weak references for listeners, but I would think it would be better to explicitly remov...
It's always a good idea to remove your listeners explicitly when you no longer need them, yeah, and the way you're doing it is fine. It might seem a little verbose, but it's still good practice, and it keeps you in the habit of knowing where your listeners are, since not knowing leads so often to leaks and unexpected b...
476,831
<p>A while ago I was trying to figure out a way of doing this without using a table layout:</p> <pre><code>&lt;table&gt; &lt;tr&gt;&lt;td rowspan="2"&gt;Left column&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Right Top&lt;/td&gt;&lt;td&gt;Right bottom&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; </code></pre> <p>Eventually...
[ { "answer_id": 476839, "author": "Evan Fosmark", "author_id": 49701, "author_profile": "https://Stackoverflow.com/users/49701", "pm_score": 1, "selected": false, "text": "<pre><code>&lt;div style='float:left;width:200px;height:300px;'&gt;Left column&lt;/div&gt;\n&lt;div style='margin-lef...
2009/01/24
[ "https://Stackoverflow.com/questions/476831", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
A while ago I was trying to figure out a way of doing this without using a table layout: ``` <table> <tr><td rowspan="2">Left column</td></tr> <tr><td>Right Top</td><td>Right bottom</td></tr> </table> ``` Eventually I gave up and decided that it's impossible to do without tables (okay, CSS 3 might be able to, bu...
To answer the question in the title, things which are awkward, very hard, or impossible to do: * variables and calculations (expression doesn't count, and vars would be handy for things like colour sanitising) * vertical centring * setting dimensions to "space remaining" (like "\*" in tables) * mixing relative and abs...
476,843
<p>I'm having troubles creating a property of an array of integers in Objective-C. I'm not sure whether this is even possible to do in Obj-C so I'm hoping someone can help me in finding out either how to do it correctly or provide an alternative solution.</p> <p>myclass.h</p> <pre><code>@interface myClass : NSObject ...
[ { "answer_id": 476851, "author": "Georg Schölly", "author_id": 24587, "author_profile": "https://Stackoverflow.com/users/24587", "pm_score": 4, "selected": false, "text": "<p>I'm just speculating:</p>\n\n<p>I think that the variable defined in the ivars allocates the space right in the o...
2009/01/24
[ "https://Stackoverflow.com/questions/476843", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58677/" ]
I'm having troubles creating a property of an array of integers in Objective-C. I'm not sure whether this is even possible to do in Obj-C so I'm hoping someone can help me in finding out either how to do it correctly or provide an alternative solution. myclass.h ``` @interface myClass : NSObject { @private int doubl...
This should work: ``` @interface MyClass { int _doubleDigits[10]; } @property(readonly) int *doubleDigits; @end @implementation MyClass - (int *)doubleDigits { return _doubleDigits; } @end ```
476,865
<p>I'm using timer queues in my application, and pass a pointer to one of my own C++ Timer objects as the 'parameter' to the callback (in CreateTimerQueueTimer). I then call a virtual method on the object in the callback.</p> <p>The destructor of the Timer object will make sure to cancel the timer using DeleteTimerQue...
[ { "answer_id": 476929, "author": "jpalecek", "author_id": 51831, "author_profile": "https://Stackoverflow.com/users/51831", "pm_score": 2, "selected": false, "text": "<p>The concept of using the object pointer as callback function parameter is not bad by itself. However, you obviously ne...
2009/01/24
[ "https://Stackoverflow.com/questions/476865", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48659/" ]
I'm using timer queues in my application, and pass a pointer to one of my own C++ Timer objects as the 'parameter' to the callback (in CreateTimerQueueTimer). I then call a virtual method on the object in the callback. The destructor of the Timer object will make sure to cancel the timer using DeleteTimerQueueTimer()....
The concept of using the object pointer as callback function parameter is not bad by itself. However, you obviously need to start the destruction after the last callback has exited. So, I wouldn't make Timer abstract and derive from it at all. I would use another abstract class `TimerImpl` and make the `Timer` class u...
476,887
<p>Is it possible to use ido-mode completion to find definitions in a TAGS file? I suspect that ido-completing-read is part of the answer. Here's my non-working code, which shows an unpopulated ido-mode minibuffer:</p> <pre><code>(defun ido-choose-from-tags () "Use ido to select tags " (interactive) (etags-t...
[ { "answer_id": 476899, "author": "Charlie Martin", "author_id": 35092, "author_profile": "https://Stackoverflow.com/users/35092", "pm_score": 0, "selected": false, "text": "<p>Of course it's possible, this is EMACS. What does the non-working code do that tells you it isn't working?</p>\...
2009/01/24
[ "https://Stackoverflow.com/questions/476887", "https://Stackoverflow.com", "https://Stackoverflow.com/users/207/" ]
Is it possible to use ido-mode completion to find definitions in a TAGS file? I suspect that ido-completing-read is part of the answer. Here's my non-working code, which shows an unpopulated ido-mode minibuffer: ``` (defun ido-choose-from-tags () "Use ido to select tags " (interactive) (etags-tags-apropos ...
Kind of inefficient, but how about: ``` (defun my-ido-find-tag () "Find a tag using ido" (interactive) (tags-completion-table) (let (tag-names) (mapc (lambda (x) (unless (integerp x) (push (prin1-to-string x t) tag-names))) tags-completion-table) (find-tag (ido-compl...
476,931
<p>How do I do a simple compare of an enum value and a string that should match the enums name?</p> <p>How do I parse the string into it's appropriate enum value.</p> <p>For example,</p> <pre><code>Enum A B=0 C=1 D=2 End Enum </code></pre> <p>How do I check if String = A.C and how do I convert string...
[ { "answer_id": 476938, "author": "JoshBerke", "author_id": 26160, "author_profile": "https://Stackoverflow.com/users/26160", "pm_score": 3, "selected": false, "text": "<p><code>Enum.GetName(typeof(A),enumValue)==stringValue</code></p>\n" }, { "answer_id": 476940, "author": "M...
2009/01/25
[ "https://Stackoverflow.com/questions/476931", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35331/" ]
How do I do a simple compare of an enum value and a string that should match the enums name? How do I parse the string into it's appropriate enum value. For example, ``` Enum A B=0 C=1 D=2 End Enum ``` How do I check if String = A.C and how do I convert string into its corresponding A value without ...
There are several different methods that are related: ``` Enum.GetName(typeof(A), A.C) == "C" A.C.ToString() == "C" ((A)Enum.Parse(typeof(A), "C")) == A.C ``` The first two convert the value of `A.C` to a string representation (`"C"`) and then compare it to a string. The last one converts the string `"C"` to a type ...
476,942
<p>I understand that one can raise an event in the class that the implementation declaration occurs, but I wish to raise the event at the base class level and have the derived class's event be raised:</p> <pre><code>public interface IFoo { event EventHandler&lt;FooEventArgs&gt; FooValueChanged; void RaiseFooV...
[ { "answer_id": 476947, "author": "Mitch Wheat", "author_id": 16076, "author_profile": "https://Stackoverflow.com/users/16076", "pm_score": 1, "selected": false, "text": "<p>Why do you need to use an event? Can't you just use an overridden method. The base calls the overridable method, wh...
2009/01/25
[ "https://Stackoverflow.com/questions/476942", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27765/" ]
I understand that one can raise an event in the class that the implementation declaration occurs, but I wish to raise the event at the base class level and have the derived class's event be raised: ``` public interface IFoo { event EventHandler<FooEventArgs> FooValueChanged; void RaiseFooValueChanged(IFooView ...
Note first, the event declaration that you are using is a short-hand notation in C#: ``` public event EventHandler Event; public void RaiseEvent() { this.Event(this, new EventArgs()); } ``` Is equivalent to: ``` private EventHandler backEndStorage; public event EventHandler Event { add { this.backEndStorage...
476,951
<p>I have a Perl script that I'd like to run on Windows, using either <a href="http://www.strawberry.com" rel="nofollow noreferrer">Strawberry Perl</a> or <a href="http://www.activestate.com" rel="nofollow noreferrer">ActivePerl</a>; I don't care which. This script however, uses <code>flock()</code> calls, which does n...
[ { "answer_id": 477031, "author": "Paul Beckingham", "author_id": 14356, "author_profile": "https://Stackoverflow.com/users/14356", "pm_score": 4, "selected": true, "text": "<p>Is the Fcntl module installed? Try this:</p>\n\n<pre><code>perl.exe -MFcntl -e 1\n</code></pre>\n\n<p>If it com...
2009/01/25
[ "https://Stackoverflow.com/questions/476951", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13744/" ]
I have a Perl script that I'd like to run on Windows, using either [Strawberry Perl](http://www.strawberry.com) or [ActivePerl](http://www.activestate.com); I don't care which. This script however, uses `flock()` calls, which does not seem to be included in either of those versions of Perl. Can anyone help get this up...
Is the Fcntl module installed? Try this: ``` perl.exe -MFcntl -e 1 ``` If it complains, you don't have the Fcntl module installed. If it doesn't complain, then you have access to Fcntl::flock, so put this in your script: ``` use Fcntl qw(:DEFAULT :flock); ``` and off you go.
476,953
<p>I'm looking for a way to map some hot-keys to "delete the line that my cursor is on" in Xcode. I found "delete to end of line" and "delete to beginning of line" in the text key bindings, but I am missing how to completely delete the line no matter what I have selected. TextMate has this functionality mapped to Ctrl+...
[ { "answer_id": 477961, "author": "Ashley Clark", "author_id": 4556, "author_profile": "https://Stackoverflow.com/users/4556", "pm_score": 5, "selected": true, "text": "<p>You can set up a system-wide key binding file that will apply to all Cocoa apps.</p>\n\n<p>To do what you want it sho...
2009/01/25
[ "https://Stackoverflow.com/questions/476953", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53653/" ]
I'm looking for a way to map some hot-keys to "delete the line that my cursor is on" in Xcode. I found "delete to end of line" and "delete to beginning of line" in the text key bindings, but I am missing how to completely delete the line no matter what I have selected. TextMate has this functionality mapped to Ctrl+Shi...
You can set up a system-wide key binding file that will apply to all Cocoa apps. To do what you want it should like like this: In your home folder, Library/KeyBindings/DefaultKeyBinding.dict ``` { "^D" = ( "moveToBeginningOfLine:", "deleteToEndOfLine:", ); } ``` I believe if you only want i...
476,961
<p>Given this piece of code:</p> <pre><code>(void)someFunction(void) { int array[] = {1,2,3,4,5,6,7,8,9,10}; } </code></pre> <p>Where are the values of the array stored?</p> <ul> <li>Stack?</li> <li>Heap?</li> <li>Together with those string literals. (Is it called High Frequency Heap?)</li> <li>Somewhere else?</...
[ { "answer_id": 476970, "author": "Michael Burr", "author_id": 12711, "author_profile": "https://Stackoverflow.com/users/12711", "pm_score": 4, "selected": true, "text": "<p>The array itself will be on the stack. There will be a bit of code on entry to the function that copies the values...
2009/01/25
[ "https://Stackoverflow.com/questions/476961", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24587/" ]
Given this piece of code: ``` (void)someFunction(void) { int array[] = {1,2,3,4,5,6,7,8,9,10}; } ``` Where are the values of the array stored? * Stack? * Heap? * Together with those string literals. (Is it called High Frequency Heap?) * Somewhere else? I'm asking because I'm unsure regarding this question: [C...
The array itself will be on the stack. There will be a bit of code on entry to the function that copies the values which are stored in some unnamed array in a global/static memory area into the local array on the stack. It's likely that the unnamed global/static array with the initial values is in the same general memo...
476,966
<p><strong>Homework question:</strong></p> <ul> <li>Cygwin GNU <strong>GDB</strong></li> <li>Cygwin GNU <strong>GCC</strong> </li> </ul> <p>Attempting to establish the length of the <b>hypotenuse</b> C from the square root of <strong>A</strong> power of 2 and <strong>B</strong> power of 2.</p> <p><strong>Example</st...
[ { "answer_id": 476976, "author": "gkrogers", "author_id": 54501, "author_profile": "https://Stackoverflow.com/users/54501", "pm_score": 0, "selected": false, "text": "<p>I make the answer 8.628522469, i.e. 8.628522.</p>\n" }, { "answer_id": 476980, "author": "cletus", "au...
2009/01/25
[ "https://Stackoverflow.com/questions/476966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
**Homework question:** * Cygwin GNU **GDB** * Cygwin GNU **GCC** Attempting to establish the length of the **hypotenuse** C from the square root of **A** power of 2 and **B** power of 2. **Example** input: Enter the length of two sides of a right-angled triangle: 2.25 8.33 **Answer:** The length of the hypotenuse...
The square root algorithm you're (supposed to be?) using is called [Newton's method](http://en.wikipedia.org/wiki/Newton%27s_method). Your if statement should be a while loop. Replace ``` if (e*e > 0.001) { nx = (cx +*s/cx)/2; return nx; } else { return nx; } ``` with a while loop that itera...
476,968
<p>I have a python app and java app. The python app generates input for the java app and invokes it on the command line.</p> <p>I'm sure there must be a more elegant solution to this; just like using JNI to invoke C code from Java.</p> <p>Any pointers? (FYI I'm v. new to Python) </p> <p><strong>Clarification</stron...
[ { "answer_id": 476977, "author": "Dave Ray", "author_id": 40310, "author_profile": "https://Stackoverflow.com/users/40310", "pm_score": 4, "selected": false, "text": "<p>Take a look at <a href=\"http://www.jython.org/\" rel=\"noreferrer\">Jython</a>. It's kind of like JNI, but replace C ...
2009/01/25
[ "https://Stackoverflow.com/questions/476968", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48891/" ]
I have a python app and java app. The python app generates input for the java app and invokes it on the command line. I'm sure there must be a more elegant solution to this; just like using JNI to invoke C code from Java. Any pointers? (FYI I'm v. new to Python) **Clarification** (at the cost of a long question: ap...
Sorry to ressurect the thread, but there was no accepted answer... You could also use [Py4J](http://py4j.sourceforge.net/index.html). There is an example on the frontpage and lots of documentation, but essentially, you just call Java methods from your python code as if they were python methods: ``` >>> from py4j.java...
476,979
<p>Ive been playing around with the Google Calendar API and am getting stuck on something. When i call this below to <strong>delete a calendar event</strong> it works fine on the first pass and usually the second. However, around the 2nd or 3rd time I call this method I get a <strong>(401) Unauthorized error</strong>...
[ { "answer_id": 476977, "author": "Dave Ray", "author_id": 40310, "author_profile": "https://Stackoverflow.com/users/40310", "pm_score": 4, "selected": false, "text": "<p>Take a look at <a href=\"http://www.jython.org/\" rel=\"noreferrer\">Jython</a>. It's kind of like JNI, but replace C ...
2009/01/25
[ "https://Stackoverflow.com/questions/476979", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47576/" ]
Ive been playing around with the Google Calendar API and am getting stuck on something. When i call this below to **delete a calendar event** it works fine on the first pass and usually the second. However, around the 2nd or 3rd time I call this method I get a **(401) Unauthorized error**. It uses the same credentials ...
Sorry to ressurect the thread, but there was no accepted answer... You could also use [Py4J](http://py4j.sourceforge.net/index.html). There is an example on the frontpage and lots of documentation, but essentially, you just call Java methods from your python code as if they were python methods: ``` >>> from py4j.java...
477,006
<p>This is a very basic query I can't figure out....</p> <p>Let's say I have a two column table like this:</p> <pre><code>userid | roleid --------|-------- 1 | 1 1 | 2 1 | 3 2 | 1 </code></pre> <p>I want to get all distinct userids that have <code>roleids</code> 1, 2 AND 3. Usi...
[ { "answer_id": 477013, "author": "cletus", "author_id": 18393, "author_profile": "https://Stackoverflow.com/users/18393", "pm_score": 7, "selected": false, "text": "<p>Ok, I got downvoted on this so I decided to test it:</p>\n\n<pre><code>CREATE TABLE userrole (\n userid INT,\n roleid ...
2009/01/25
[ "https://Stackoverflow.com/questions/477006", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27305/" ]
This is a very basic query I can't figure out.... Let's say I have a two column table like this: ``` userid | roleid --------|-------- 1 | 1 1 | 2 1 | 3 2 | 1 ``` I want to get all distinct userids that have `roleids` 1, 2 AND 3. Using the above example, the only result I want ...
``` SELECT userid FROM UserRole WHERE roleid IN (1, 2, 3) GROUP BY userid HAVING COUNT(DISTINCT roleid) = 3; ``` --- To anyone reading this: my answer is simple and straightforward, and got the 'accepted' status, but please do go read the [answer](https://stackoverflow.com/questions/477006/sql-statement-join-vs-grou...
477,042
<p>Can I test if a type has been registered in a Unity container without calling for a Resolve and trapping the exception?</p>
[ { "answer_id": 477052, "author": "Mitch Wheat", "author_id": 16076, "author_profile": "https://Stackoverflow.com/users/16076", "pm_score": 2, "selected": false, "text": "<p>Your only other option (currently) is to use <code>ResolveAll&lt;T&gt;()</code> and enumerate the results. </p>\n" ...
2009/01/25
[ "https://Stackoverflow.com/questions/477042", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5302/" ]
Can I test if a type has been registered in a Unity container without calling for a Resolve and trapping the exception?
Unity 2.0 will have an `IsRegistered` method that you can use to find out if a type has been registered in the container. The Beta1 of Unity 2.0 is available on Codeplex as of Feb 10th. See the release notes and download it here; <http://unity.codeplex.com/wikipage?title=Unity2%20Beta1> UPDATE: Downloaded and test...
477,050
<p>My mac has folders Shared and Public folders. Their permissions are drwxr-xr-x+ for Public and drwxrwxrwt@ for Shared. What do the signs + and @ mean?</p>
[ { "answer_id": 477054, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": true, "text": "<p>@ means there are \"extended attributes\". Type</p>\n\n<pre><code>ls -l@\n</code></pre>\n\n<p>to see what they are. With tha...
2009/01/25
[ "https://Stackoverflow.com/questions/477050", "https://Stackoverflow.com", "https://Stackoverflow.com/users/54964/" ]
My mac has folders Shared and Public folders. Their permissions are drwxr-xr-x+ for Public and drwxrwxrwt@ for Shared. What do the signs + and @ mean?
@ means there are "extended attributes". Type ``` ls -l@ ``` to see what they are. With that command, everything with a @ after it will have some extra lines explaining why it has a @. In my experience, the @ usually means a file is going to be opened with an application other than the default (i.e. it might open wi...
477,061
<p>I work in Python and would like to read user input (from command line) in Unicode format, ie a Unicode equivalent of <code>raw_input</code>?</p> <p>Also, I would like to test Unicode strings for equality and it looks like a standard <code>==</code> does not work.</p>
[ { "answer_id": 477084, "author": "dF.", "author_id": 3002, "author_profile": "https://Stackoverflow.com/users/3002", "pm_score": 4, "selected": false, "text": "<p>It should work. <code>raw_input</code> returns a byte string which you must decode using the correct encoding to get your <co...
2009/01/25
[ "https://Stackoverflow.com/questions/477061", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58713/" ]
I work in Python and would like to read user input (from command line) in Unicode format, ie a Unicode equivalent of `raw_input`? Also, I would like to test Unicode strings for equality and it looks like a standard `==` does not work.
[`raw_input()`](https://docs.python.org/2/library/functions.html#raw_input "raw_input()") returns strings as encoded by the OS or UI facilities. The difficulty is knowing which is that decoding. You might attempt the following: ``` import sys, locale text= raw_input().decode(sys.stdin.encoding or locale.getpreferreden...
477,064
<p>I would like to execute a stored procedure over each row in a set without using a cursor with something like this: <br/><br/> <code>SELECT EXEC dbo.Sproc @Param1 = Table1.id<br/> FROM Table1 </code> <br/><br/> I am using T-SQL in SQL Server 2005. I think this might be possible using a function, but I'd like to use ...
[ { "answer_id": 477072, "author": "Josef", "author_id": 5581, "author_profile": "https://Stackoverflow.com/users/5581", "pm_score": 5, "selected": false, "text": "<p>Yes. If you have a column you can use within the table to mark the ones processed, you can use WHILE EXISTS:</p>\n\n<pre><c...
2009/01/25
[ "https://Stackoverflow.com/questions/477064", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58714/" ]
I would like to execute a stored procedure over each row in a set without using a cursor with something like this: `SELECT EXEC dbo.Sproc @Param1 = Table1.id FROM Table1` I am using T-SQL in SQL Server 2005. I think this might be possible using a function, but I'd like to use a stored procedure if possible (compa...
9 out of 10 times you can do what you want without a cursor or a while loop. However, if you must use one, I have found that while loops tend to be faster. Also if you do not want to delete or update the table, you can use something like this: ``` DECLARE @id [type] SELECT @id = MIN([id]) FROM [table] WHILE @id IS N...
477,066
<p>I want to do this:</p> <pre><code>class MyClass { var $array1 = array(3,4); var $array2 = self::$array1; } </code></pre> <p>and <code>$array2</code> doesn't work.</p> <p>Do you have a solution/trick to make a class property equal to another class property?</p>
[ { "answer_id": 477073, "author": "Paolo Bergantino", "author_id": 16417, "author_profile": "https://Stackoverflow.com/users/16417", "pm_score": 3, "selected": false, "text": "<p>According to the <a href=\"http://us.php.net/manual/en/language.oop5.basic.php\" rel=\"nofollow noreferrer\"><...
2009/01/25
[ "https://Stackoverflow.com/questions/477066", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I want to do this: ``` class MyClass { var $array1 = array(3,4); var $array2 = self::$array1; } ``` and `$array2` doesn't work. Do you have a solution/trick to make a class property equal to another class property?
According to the [`PHP Manual`](http://us.php.net/manual/en/language.oop5.basic.php): > > The default value must be a constant expression, not (for example) a **variable**, a class member or a function call. > > > What you COULD do is: ``` class MyClass { var $array1 = array(3,4); var $array2 = array(); ...
477,075
<p>I have some existing code that retrieves data from a database using ADO.NET that I want to convert to linq.</p> <p>What the code does is receives an SQL query via command line, executes it, returns the rows and their column names, then prints them to the screen. I would like to know how to write this code in linq....
[ { "answer_id": 477089, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 2, "selected": true, "text": "<p>I don't see the value in moving to LINQ here. The beauty of LINQ is that you can write your query in the language of...
2009/01/25
[ "https://Stackoverflow.com/questions/477075", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58444/" ]
I have some existing code that retrieves data from a database using ADO.NET that I want to convert to linq. What the code does is receives an SQL query via command line, executes it, returns the rows and their column names, then prints them to the screen. I would like to know how to write this code in linq. The ENTI...
I don't see the value in moving to LINQ here. The beauty of LINQ is that you can write your query in the language of your domain objects, rather than in T-SQL. In your case you only want to accept actual SQL commands. It seems like it would be more work to deconstruct the command, turn it into LINQ -- using reflection ...
477,085
<p>When I use an import such as</p> <pre><code>&lt;script type="text/javascript" src="http://o.aolcdn.com/dojo/1.2.3/dojo/dojo.xd.js" djConfig="parseOnLoad:true, isDebug: true"&gt;&lt;/script&gt; </code></pre> <p>I get the error</p> <pre><code>dojox.data.CsvStore is not a constructor </code></pre> <p>for lin...
[ { "answer_id": 477190, "author": "pierdeux", "author_id": 53747, "author_profile": "https://Stackoverflow.com/users/53747", "pm_score": 1, "selected": false, "text": "<p>Are you running that code inside <code>dojo.addOnLoad()</code>? As in:</p>\n\n<pre><code>dojo.addOnLoad(function(){\n...
2009/01/25
[ "https://Stackoverflow.com/questions/477085", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20386/" ]
When I use an import such as ``` <script type="text/javascript" src="http://o.aolcdn.com/dojo/1.2.3/dojo/dojo.xd.js" djConfig="parseOnLoad:true, isDebug: true"></script> ``` I get the error ``` dojox.data.CsvStore is not a constructor ``` for lines such as ``` var stateStore = new dojox.data.CsvStore({url...
Reacting to your update: I strongly think you should try with `dojo.addOnLoad()`. Together, the last two `<script>` sections of your `<head>` would become: ``` <script> dojo.addOnLoad(function(){ dojo.require("dojox.data.CsvStore"); dojo.require("dijit.Tree"); dojo.require("dojo.parser"); /* I d...
477,092
<p>I am writing an app which - similarly to many apps out there - is 90% regular CRUD things and 10% "juice", where we need nasty business logic and more flexibility and customization.</p> <p>Regarding this 90%, I was trying to stick to the DRY principle as much as I can. As long as controllers go, I have found resour...
[ { "answer_id": 477190, "author": "pierdeux", "author_id": 53747, "author_profile": "https://Stackoverflow.com/users/53747", "pm_score": 1, "selected": false, "text": "<p>Are you running that code inside <code>dojo.addOnLoad()</code>? As in:</p>\n\n<pre><code>dojo.addOnLoad(function(){\n...
2009/01/25
[ "https://Stackoverflow.com/questions/477092", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14540/" ]
I am writing an app which - similarly to many apps out there - is 90% regular CRUD things and 10% "juice", where we need nasty business logic and more flexibility and customization. Regarding this 90%, I was trying to stick to the DRY principle as much as I can. As long as controllers go, I have found resource\_contro...
Reacting to your update: I strongly think you should try with `dojo.addOnLoad()`. Together, the last two `<script>` sections of your `<head>` would become: ``` <script> dojo.addOnLoad(function(){ dojo.require("dojox.data.CsvStore"); dojo.require("dijit.Tree"); dojo.require("dojo.parser"); /* I d...
477,095
<p>I am trying to go through the <a href="http://www.asp.net/learn/mvc/tutorial-11-cs.aspx" rel="nofollow noreferrer">following tutorial</a> on asp.net. When I get down to this code:</p> <pre><code> &lt;%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Index.aspx....
[ { "answer_id": 477100, "author": "thaBadDawg", "author_id": 48832, "author_profile": "https://Stackoverflow.com/users/48832", "pm_score": 3, "selected": true, "text": "<p>Try doing a Build on your MVC project. Until the code behind has been compiled for the first time the intellisense wo...
2009/01/25
[ "https://Stackoverflow.com/questions/477095", "https://Stackoverflow.com", "https://Stackoverflow.com/users/648/" ]
I am trying to go through the [following tutorial](http://www.asp.net/learn/mvc/tutorial-11-cs.aspx) on asp.net. When I get down to this code: ``` <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="MvcApplication1.Views.Home.Index" %> <%@...
Try doing a Build on your MVC project. Until the code behind has been compiled for the first time the intellisense won't work.
477,096
<p>I've discovered a new pattern. Is this pattern well known or what is the opinion about it?</p> <p>Basically, I have a hard time scrubbing up and down source files to figure out what module imports are available and so forth, so now, instead of</p> <pre><code>import foo from bar.baz import quux def myFunction(): ...
[ { "answer_id": 477103, "author": "dF.", "author_id": 3002, "author_profile": "https://Stackoverflow.com/users/3002", "pm_score": 5, "selected": false, "text": "<p>A few problems with this approach:</p>\n\n<ul>\n<li>It's not immediately obvious when opening the file which modules it depen...
2009/01/25
[ "https://Stackoverflow.com/questions/477096", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49287/" ]
I've discovered a new pattern. Is this pattern well known or what is the opinion about it? Basically, I have a hard time scrubbing up and down source files to figure out what module imports are available and so forth, so now, instead of ``` import foo from bar.baz import quux def myFunction(): foo.this.that(quux...
The (previously) [top-voted answer](https://stackoverflow.com/questions/477096/python-import-coding-style/477107#477107) to this question is nicely formatted but absolutely wrong about performance. Let me demonstrate Performance =========== Top Import ---------- ``` import random def f(): L = [] for i in xr...
477,114
<p>I'm attempting to post a random testimonial on each page of a site. </p> <p>I started off by using an application helper like this:</p> <pre><code>module ApplicationHelper def random_testimonial @random_testimonial = Testimonial.find(:first, :offset =&gt; rand(Testimonial.count)) end end </code></pre> ...
[ { "answer_id": 477127, "author": "Milan Novota", "author_id": 26123, "author_profile": "https://Stackoverflow.com/users/26123", "pm_score": 3, "selected": false, "text": "<p>If I understand you correctly, you want a method that returns the same object every time it is referenced in one r...
2009/01/25
[ "https://Stackoverflow.com/questions/477114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56461/" ]
I'm attempting to post a random testimonial on each page of a site. I started off by using an application helper like this: ``` module ApplicationHelper def random_testimonial @random_testimonial = Testimonial.find(:first, :offset => rand(Testimonial.count)) end end ``` In my view I can reference the met...
While that works, and I have certainly been known to do this, it violates the MVC separation of concerns. View helpers are not supposed to contain controller/model type logic, which this does. You might consider refactoring this back into the application controller. Helpers are supposed to be for view formatting and s...
477,115
<p>I've embarked on a project which is encouraging me to expand my knowledge of SQL. I've already learned quite a bit, but I've gotten myself to a point where I can see a problem, but I don't know enough to properly research a solution. I've hit SO, Google, and the MySQL docs, but either I'm asking the wrong question...
[ { "answer_id": 477123, "author": "Hank Gay", "author_id": 4203, "author_profile": "https://Stackoverflow.com/users/4203", "pm_score": 2, "selected": false, "text": "<p>What do you think <em>should</em> come back? You can't have lists inside a tuple coming back from a query, so your curre...
2009/01/25
[ "https://Stackoverflow.com/questions/477115", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46387/" ]
I've embarked on a project which is encouraging me to expand my knowledge of SQL. I've already learned quite a bit, but I've gotten myself to a point where I can see a problem, but I don't know enough to properly research a solution. I've hit SO, Google, and the MySQL docs, but either I'm asking the wrong questions or ...
What do you think *should* come back? You can't have lists inside a tuple coming back from a query, so your current results seems like the only way to get back all the data in one query. UPDATE: SQL doesn't support hierarchical structures, so you'll have to build that yourself (assuming you aren't using an ORM tool th...