instruction stringlengths 21 27.8k | chosen stringlengths 18 28.2k | rejected stringlengths 18 33.6k | __index_level_0__ int64 0 50k |
|---|---|---|---|
<p>I want to call a c# function from my javascript function.</p>
<p>I have a link button in my ascx (please see the code below). The problem is that if you press enter in firefox is not working however it is working fine in internet explorer.</p>
<pre><code><li class="clearfix border_top">
<label for="title"... | <p>This can't be done with the normal <code>printf</code> format specifiers. The closest you could get would be:</p>
<pre><code>printf("%.6g", 359.013); // 359.013
printf("%.6g", 359.01); // 359.01
</code></pre>
<p>but the ".6" is the <em>total</em> numeric width so</p>
<pre><code>printf("%.6g", 3.01357); // 3.013... | <p>Your code rounds to three decimal places due to the ".3" before the f</p>
<pre><code>printf("%1.3f", 359.01335);
printf("%1.3f", 359.00999);
</code></pre>
<p>Thus if you the second line rounded to two decimal places, you should change it to this:</p>
<pre><code>printf("%1.3f", 359.01335);
printf("%1.2f", 359.0099... | 35,057 |
<p>I've been using MVC frameworks for a short while now and I really like how the concerns are separated out. I've got into a bad habit of letting the controllers do quite a bit of work. So I'm really looking for some advice.</p>
<p>When I first started using MVC I quite often had the controller doing manipulation o... | <p>First, there is no set of rules that's going to work in every situation. How you model you're application depends a lot on the type and complexity of the project. Having said that, here are some ideas:</p>
<ol>
<li>Nothing wrong with calling the repository from a controller. Just make sure the controller does not c... | <p>Ian Cooper has just written a blog post called <a href="http://codebetter.com/blogs/ian_cooper/archive/2008/12/03/the-fat-controller.aspx" rel="noreferrer">The Fat Controller</a> on just this subject.</p>
| 42,232 |
<p>When I am editing a cell in a <code>dataGrid</code>, the changes are not applied to the <code>dataProvider</code> until I finish editing. Is there a way that I can make the changes appear in the <code>dataProvider</code> whilst editing?</p>
<p>I would assume that the way of doing this would be to subclass the edit... | <p>A few notes:</p>
<ol>
<li><p>You will save yourself a lot of trouble by just using a <code><table></code> for this data, which is tabular. </p></li>
<li><p>Building this stuff via the DOM is insanely slow compared to letting the browser just render raw HTML. Just something to be aware of.</p></li>
</ol>
<p... | <p>I agree with Tpiptych but for arguments sake if I wanted to accomplish this I'd end up using different styles sheets for the defect browser (in this case IE6). </p>
<p>Be aware, that you may not be able to get 100% of the same look and you may need to design a slightly different look for IE6. </p>
<p>Even after I ... | 49,998 |
<p>The docs for <a href="http://msdn.microsoft.com/en-us/library/bb347013.aspx" rel="noreferrer">Dictionary.TryGetValue</a> say:</p>
<blockquote>
<p>When this method returns, [the value argument] contains the value associated with the specified key, if the key is found; otherwise, the <strong>default value for the t... | <p>You are looking for this:</p>
<pre><code>default(T);
</code></pre>
<p>so:</p>
<pre><code>public T Foo<T>(T Bar)
{
return default(T);
}
</code></pre>
| <p>Using the <a href="http://msdn.microsoft.com/en-us/library/xwth0h0d(VS.80).aspx" rel="noreferrer">default</a> keyword:</p>
<pre><code>T t = default(T)
</code></pre>
| 48,330 |
<p>When I write an app, I use the System.Data interfaces (IDbConnection, IDbCommand, IDataReader, IDbDataParameter, etc...). I do this to reduce vendor dependencies. Unless, I'm doing a simple test app, it just seems like the ethical thing to do when consulting.</p>
<p>However, it seems like all the code I see uses ... | <p>There are differences to the SQL you're going to have to give the classes, depending on the type of database engine you're talking to, so even if you manage to write all your code to use the interfaces, you still need to write multiple sets of SQL.</p>
<p>Or, you can do what we have done, write our own layer that t... | <p>Take a look at Microsoft's Patterns and Practices group's Enterprise library.
The data access code they have there shows some good implementations of provider independence.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/cc467894.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/cc4678... | 45,632 |
<p>I am in charge of providing a theme functionality for a site using a big CSS file (thousands of elements) I've just inherited.
Basically we want to allow the user to be able to change the colors on the screen.</p>
<p>Every CSS element, besides color definition also have lots of other attributes - size, font, float,... | <p>You only have to duplicate the color attributes so if you have </p>
<pre><code>a:hover
{
text-decoration:none;
color:Black;
display:block
}
</code></pre>
<p>in your css file in your theme you only need:</p>
<pre><code>a:hover
{
color:Red;
}
</code></pre>
<p>Now in your page you want to make sure... | <p>Remember: elements can have multiple style classes. Since the layout remains static and will be separate from the coloring, you want to define classes for layout and color separately, in completely different files.</p>
<p>So what you want to do for themes is define a few colors in a separate css file like this:</p... | 46,612 |
<p>What is current state of the art for enabling OpenID login in Ruby on Rails applications? This is a community wiki with up-to-date answers to this question.</p>
<h2>Authlogic</h2>
<p>The most advanced authentication solution seems to be <a href="http://github.com/binarylogic/authlogic" rel="noreferrer">Authlogic</a... | <p>Check out this <a href="http://railscasts.com/episodes/68-openid-authentication" rel="nofollow noreferrer">Railscast on OpenId</a> for more info. I'm not sure if/how it might work alongside restful_authentication, but might be a good resource. (I haven't watched it yet)</p>
| <p>Keep an eye on <a href="http://jimneath.org/2008/09/09/bort-base-rails-application/" rel="nofollow noreferrer">Bort</a>. It is a base rails application which already has restful_authentication setup among other things. The guy doing it is planning on adding OpenID.</p>
| 9,244 |
<p>I'd like to do some work with the nitty-gritties of computer imaging. I'm looking for a way to read single pixels of data, analyze them programatically, and change them. What is the best language to use for this (Python, c++, Java...)? What is the best fileformat?</p>
<p>I don't want any super fancy software/API... | <p>If you need speed (you'll probably always want speed with image processing) you definitely have to work with raw pixel data.
Java has some real disadvantages as you cannot access memory directly which makes pixel access quite slow compared to accessing the memory directly.
C++ is definitely the language of choice fo... | <p>Short answer? I'd say C++, you have far more flexibility in manipulating raw chunks of memory than Python or Java.</p>
| 17,269 |
<p>How do you measure the memory usage of an application or process in Linux?</p>
<p>From the blog article of <em><a href="http://virtualthreads.blogspot.com/2006/02/understanding-memory-usage-on-linux.html" rel="noreferrer">Understanding memory usage on Linux</a></em>, <code>ps</code> is not an accurate tool to use fo... | <p>With <code>ps</code> or similar tools you will only get the amount of memory pages allocated by that process. This number is correct, but:</p>
<ul>
<li><p>does not reflect the actual amount of memory used by the application, only the amount of memory reserved for it</p>
</li>
<li><p>can be misleading if pages are sh... | <p>Use the in-built <em>System Monitor</em> GUI tool available in Ubuntu.</p>
| 15,938 |
<p><strong>Duplicate of:</strong> <a href="https://stackoverflow.com/questions/203113/use-javascript-to-inject-script-references-as-needed">Use javascript to inject script references as needed?</a></p>
<p>Javascript doesn't have any directive to "include" or "import" another js file.
This means that if <code>script1.j... | <p>Use dynamic includes:</p>
<p><a href="https://stackoverflow.com/questions/203113/use-javascript-to-inject-script-references-as-needed">Use javascript to inject script references as needed?</a></p>
| <p>I guess you could use document.write in your JS files to make sure they include whatever dependencies they're dependent upon, though I wouldn't really recommend it...</p>
| 40,807 |
<p>It's rare that I hear someone using <a href="http://martinfowler.com/articles/injection.html" rel="nofollow noreferrer">Inversion of Control (Ioc)</a> principle with .Net. I have some friends that work with Java that use a lot more Ioc with Spring and PicoContainer.</p>
<p>I understand the principle of removing dep... | <p>Lots of people use IOC in .NET, and there are several frameworks available to assist with using IoC. You may see it less in the WinForms side of things, because it's harder to just let the container wire everything together when you are designing forms in Visual Studio, but I can say that for server-side .NET appli... | <p>I use it to allow my Unit tests to substitute Mock Classes (simulating actual production classes) for upstream dependant objects so that my unit tests truly only execute and test the code in the one class.method they are written to test.</p>
| 31,162 |
<p>If I have the following string:</p>
<pre><code>string s = "abcdefghab";
</code></pre>
<p>Then how do I get a string (or char[]) that has just the characters that are repeated in the original string using C# and LINQ. In my example I want to end up with "ab".</p>
<p>Although not necessary, I was trying to do this ... | <p>There isn't likely to be a foolproof method, as that's an intrusion into the privacy of the user. </p>
<p>One thing that comes to mind is checking for a referrer. If the user arrived at your page without following a link, they a) typed the url, b) followed a bookmark, or c) have your page set as their homepage. ... | <p>Simple solution, you shouldn't be checking if you or anyone else's site is set as the user's homepage. If they want it as their homepage, they'll make it so. </p>
<p>However, if you've got some Javascript that will check their email and see if they've sent links to your site to their friends or colleagues, I'd be... | 30,440 |
<p>On a page I want to dynamically list years and all the months in each year so an archive for each month can be viewed. I want to show the current year first but the current year may not be over yet so I only want to show the months that have passed, and the current month. Then I want all years and all months in the ... | <pre><code>$current_year = date('Y');
$months = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
$month_names = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
// Loop through all the months and create an array up to and including the curren... | <p>PHP has a Date() function and an mktime function, you can use these to compare dates and to create dates out of strings etc. Without providing code, i can give you an instruction to somehow make an iteration:</p>
<pre><code> -> Get current Year
-> Loop the current year untill the current month is reached
... | 43,821 |
<p>I am reading a .NET book, and in one of the code examples there is a class definition with this field:</p>
<pre><code>private DateTime? startdate
</code></pre>
<p>What does <code>DateTime?</code> mean?</p>
| <p>Since <code>DateTime</code> is a <code>struct</code>, not a <code>class</code>, you get a <code>DateTime</code> <em>object</em>, not a <em>reference</em>, when you declare a field or variable of that type. </p>
<p>And, in the same way as an <code>int</code> cannot be <code>null</code>, so this <code>DateTime</code>... | <pre><code>public class ReportsMapper : CommonMapper
{
public DateTime? cb_Bill_From_Date { get; set; }
public DateTime? cb_Bill_To_Date { get; set; }
public DateTime? tff_Bill_From_Date { get; set; }
public DateTime? tff_Bill_To_Date { get; set; }
}
</code></pre>
<p>If you declare DateTime As Null... | 13,512 |
<p>An integer's max value in Java is 2147483647, since Java integers are signed, right?</p>
<p>0xff000000 has a numeric value of 4278190080.</p>
<p>Yet I see Java code like this:</p>
<pre><code>int ALPHA_MASK = 0xff000000;
</code></pre>
<p>Can anyone enlighten me please?</p>
| <p>The high bit is a sign bit. Setting it denotes a negative number: -16777216. </p>
<p>Java, like most languages, stores signed numbers in <a href="http://en.wikipedia.org/wiki/Two%27s_complement" rel="noreferrer">2's complement</a> form. In this case, subtracting 2<sup>31</sup>, or 2147483648 from 0x7F000000, or 213... | <p>ints are signed in Java.</p>
| 41,266 |
<p>With ASP.NET 3.5 I can easily bind to an XML file by using an <code>XmlDataSource</code>.</p>
<p>How can I bind to an XML <em>string</em> instead of a <em>file</em>?</p>
| <p>Use the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.xmldatasource.data.aspx" rel="nofollow noreferrer">XmlDataSource.Data</a> property.</p>
<pre><code>XmlDataSource dataSource = new XmlDataSource();
dataSource.Data = "<root><element>Item #1</element>&l... | <p>From the XmlDataSource docs <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.xmldatasource.aspx" rel="nofollow noreferrer">here:</a> </p>
<blockquote>
<p><em>XML data can also be stored directly by the data source control in string form using the Data property</em>.</p>
</blockquote>
| 41,707 |
<p>I am adding a context menu using <code>QAction</code> for a widget.
Now, there is some white space beside the text of the action. I assume this is the space where the <code>QIcon</code> association with the <code>QAction</code> should have been there. Now how do I hide this space. I tried doing:</p>
<pre><code>acti... | <p>I don't know if there is a way specific to the action or the menu, but you could probably remove it using a style.</p>
| <p>You didn't mention the version of Qt you are using but version 4.4.3's QAction allows you to hide the icon:<br>
<a href="http://doc.trolltech.com/4.4/qaction.html#iconVisibleInMenu-prop" rel="nofollow noreferrer">http://doc.trolltech.com/4.4/qaction.html#iconVisibleInMenu-prop</a><br>
<br>
You can also try using the... | 25,568 |
<p>I need to migrate a large project from StarTeam 5 to Subversion, and I'd like to keep snapshots of (at least) 5-10 of the major releases. I've considered the following:</p>
<ul>
<li>Manual or scripted export/import of each snapshot. Advantages: straightforward, easy to select labeled/dated versions. Disadvantage... | <p>Having not used StarTeam I cannot speak to that -- but I think you've laid out some nice options. </p>
<ol>
<li>Scripted import seems like it could be time consuming, not really get you everything, but at the same time, be a reliable way to get into svn and still preserve your release history. </li>
<li>What is the... | <p>I'm struggling to migrate StarTeam 8 to SVN using the Polarion kit. I'm getting:</p>
<p>[main] DEBUG STProvider:80 - checkout ...relative/path/to/build.xml version:1.0
09:25:10,378</p>
<p>[main] INFO historyLogger:84 - EXCEPTION CAUGHT: java.lang.UnsatisfiedLinkError: com.starbase.util.NativeFileAccess.setLastMo... | 27,159 |
<p>I am working on a web app that uses Perl and I need to look into speeding up portions of the app. </p>
<p>I thought I'd start profiling the particular calls for the portion I wish to investigate. I've done some searching on profiling Perl code, but unfortunately most of what I find says that I should run my perl ... | <p>Have you tried <A href="http://search.cpan.org/dist/Devel-NYTProf" rel="nofollow noreferrer">Devel::NYTProf</a> (much better than Devel::DProf), which can work under Apache? Which webserver are you using? Is this a vanilla CGI script, a mod_perl thing, or something else?</p>
<p>If you're doing database stuff, the <... | <p>You can use the <a href="http://perldoc.perl.org/Benchmark.html" rel="nofollow noreferrer"><strong>Benchmark</strong></a> core module with the <strong>:hireswallclock</strong> option if you really want to time things internally. But really, you should be able to profile from the command line. You might have to wr... | 16,472 |
<p>As an example in pseudocode:</p>
<pre><code>if ((a mod 2) == 0)
{
isEven = true;
}
else
{
isEven = false;
}
</code></pre>
| <p>Instead of the modulo operator, which has slightly different semantics, for non-negative integers, you can use the <em>remainder</em> operator <code>%</code>. For your exact example:</p>
<pre><code>if ((a % 2) == 0)
{
isEven = true;
}
else
{
isEven = false;
}
</code></pre>
<p>This can be simplified to a on... | <p>The modulo operator is % (percent sign). To test for evenness or generally do modulo for a power of 2, you can also use & (the and operator) like isEven = !( a & 1 ).</p>
| 11,565 |
<p>How do I setup a class that represents an interface? Is this just an abstract base class?</p>
| <p>To expand on the answer by <a href="https://stackoverflow.com/questions/318064/how-do-you-declare-an-interface-in-c#318084">bradtgmurray</a>, you may want to make one exception to the pure virtual method list of your interface by adding a virtual destructor. This allows you to pass pointer ownership to another part... | <pre><code>class Shape
{
public:
// pure virtual function providing interface framework.
virtual int getArea() = 0;
void setWidth(int w)
{
width = w;
}
void setHeight(int h)
{
height = h;
}
protected:
int width;
int height;
};
class Rectangle: public Shape
{
public:
int... | 41,090 |
<p>Most developers and engineers that have experience writing software and deploying with the packaged Visual Studio Setup Project know about its many shortcomings. Usually in regards to installation customization, upgrade paths, etc. What are some good alternatives for software deployment? In particular I'm interested... | <ul>
<li><a href="http://wix.sourceforge.net/" rel="noreferrer">Windows Installer XML (Wix)</a></li>
<li><a href="http://nsis.sourceforge.net/Main_Page" rel="noreferrer">NullSoft Installer</a></li>
</ul>
| <p>NullSoft Installer (NSIS) is good, but building the scripts is painful - even with HM NIS Edit. You basically have to learn a whole different language to be able to work with their scripts. Example:</p>
<p>Plug-ins are necessary to do a lot of things as well, like check the .NET framework version or see if the appl... | 22,663 |
<p>I've been trying to encode a relational algebra in Scala (which to my knowlege has one of the most advanced type systems) and just don't seem to find a way to get where I want.</p>
<p>As I'm not that experienced with the academic field of programming language design I don't really know what feature to look for.</p>... | <p>What your asking for is to be able to structurally define a type as the <em>difference</em> of two other types (the original relation and the projection definition). I honestly can't think of any language which would allow you to do that. Types can be structurally cumulative (<code>A with B</code>) since <code>A w... | <p>I think I have settled on just using the normal facilities for mapping collection for the project part. The client just specify a function <code>[T<:Tuple](t:T) => P</code></p>
<p>With some java trickery to get to the class of P I should be able to use reflection to implement the query logic.</p>
<p>For the ... | 20,573 |
<p>How do you clear the IRB console screen?</p>
| <p>On <em>Mac OS X</em> or <em>Linux</em> you can use <kbd>Ctrl</kbd> + <kbd>L</kbd> to clear the <em>IRB</em> screen.</p>
| <p>The backtick operator captures the output of the command and returns it</p>
<pre><code>s = `cls`
puts s
</code></pre>
<p>would work better, I guess.</p>
| 14,204 |
<p>I'd like a C library that can serialize my data structures to disk, and then load them again later. It should accept arbitrarily nested structures, possibly with circular references.</p>
<p>I presume that this tool would need a configuration file describing my data structures. The library is allowed to use code gen... | <p>Check out <a href="http://troydhanson.github.io/tpl/" rel="nofollow noreferrer">tpl</a>. From the overview:</p>
<blockquote>
<p>Tpl is a library for serializing C
data. The data is stored in its
natural binary form. The API is small
and tries to stay "out of the way".
Compared to using XML, tpl is faster
... | <p>In theory YAML should do what you want <a href="http://code.google.com/p/yaml-cpp/" rel="nofollow noreferrer">http://code.google.com/p/yaml-cpp/</a> </p>
<p>Please let me know if it works for you.</p>
| 48,529 |
<p>I need to automate a process involving a website that is using a login form. I need to capture some data in the pages following the login page.</p>
<p>I know how to screen-scrape normal pages, but not those behind a secure site.</p>
<ol>
<li>Can this be done with the .NET WebClient class?
<ul>
<li>How would I au... | <p>One way would be through automating a browser -- you mentioned WebClient, so I'm guessing you might be referring to WebClient in .NET.<p>Two main points:<ul><li>There's nothing special about https related to WebClient - it just works</li><li>Cookies are typically used to carry authentication -- you'll need to captur... | <p>Can you please clarify? Is the WebClient class you speak of the one in HTTPUnit/Java?</p>
<p>If so, your session should be saved automatically.</p>
| 7,058 |
<p>I have a special url which I would want only few people to have access to. I have a list of super users stored as an array in the app.yml. How can I use this array in :requirements section of a specific route in the routes.rb file to allow only those super users access to this route? Thanks a lot.</p>
| <p>A more direct analogue to <code>dict.get(key, default)</code> than <code>hasattr</code> is <code>getattr</code>.</p>
<pre><code>val = getattr(obj, 'attr_to_check', default_value)
</code></pre>
<p>(Where <code>default_value</code> is optional, raising an exception on no attribute if not found.)</p>
<p>For your exa... | <p>For checking if a key is in a dictionary you can use <code>in</code>: <code>'key' in dictionary</code>.</p>
<p>For checking for attributes in object use the <code>hasattr()</code> function: <code>hasattr(obj, 'attribute')</code></p>
| 46,343 |
<p>HI All,</p>
<p>We have a .Net 2.0 application which has a MySQL backend. We want to be able to deploy MySQl and the DB when we install the application and im trying to find the best solution. The current setup is to copy the required files to a folder on the local machine and then perform a "NET START" commands to... | <p>Not sure where you're at in the project, but if it's a simple and small database you might consider converting it to <a href="http://www.sqlite.org/" rel="noreferrer">SQLite</a>. It's not ideal for Client/Server operations, but if it's low volume/transactions it might work.</p>
| <p>With a Client/Sever setup, you're allowed to require that whoever installs the server install it as an admin. That should solve most of your problems.</p>
<p>Again- that's the server. The clients might be another story.</p>
| 7,190 |
<p>Is it possible to create a final route that catches all .. and bounces the user to a 404 view in ASP.NET MVC?</p>
<p>NOTE: I don't want to set this up in my IIS settings.</p>
| <p>Found the answer myself.</p>
<p><a href="http://richarddingwall.name/2008/08/17/strategies-for-resource-based-404-errors-in-aspnet-mvc/" rel="noreferrer" title="Click to read Richard's MVC 404 strategies">Richard Dingwall</a> has an excellent post going through various strategies. I particularly like the Filter... | <p>If the route cannot be resolved, then MVC framework will through 404 error..
Best approach is to use Exception Filters ... Create a custom exceptionfilter and make like this.. </p>
<pre><code>public class RouteNotFoundAttribute : FilterAttribute, IExceptionFilter {
public void OnException(ExceptionContext filt... | 40,017 |
<p>I'm probably doing this all wrong. I have a text file full of data and I want to match and replace patterns of "item" and "catalog number" that are in the file. But the order of each element in the file is very important, so I want to match/replace starting from the top of the file and then work my way down.</p>
<p... | <p>.+ at start of your regex is "greedy". This means that it will match maximum chars.</p>
<p>You regex is better written (it would be more readable and faster) as</p>
<pre><code>my $re=qr/\sELEMENT\s(.+?)\s\(Item := "$item".+?CatalogNumber := "$catNum.+?END_ELEMENT/;
</code></pre>
<p>I think that you can simply rep... | <p>The best solution appears to be to grab each ELEMENT ... END_ELEMENT section from the data and regex only one section at a time rather than feeding the whole complete data set to a regular expression at once. Not exactly what I was trying to accomplish, but I rewrote my program to do this piecemeal processing and i... | 29,121 |
<p>I'm working on a WinCE 6.0 system with a touchscreen that stores its calibration data (x-y location, offset, etc.) in the system registry (HKLM\HARDWARE\TOUCH). Right now, I'm placing the cal values into registry keys that get put into the OS image at build time. That works fine for the monitor that I get the orig... | <p>I think what you're probably looking for is the Flush function of the RegistryKey class. This is normally not necessary (the registry is lazily-flushed by default), but if the power is turned off on the device before the system has a chance to do this, changes will be discarded:</p>
<p><a href="http://msdn.microsof... | <p>As I understood you need to know how to set a value to the registry during runtime. I hope the codes bellow can help you.</p>
<p>using Microsoft.Win32; </p>
<pre><code> /// <summary>
/// store a key value in registry. if it don't exist it will be created.
/// </summary>
/// <pa... | 8,195 |
<p>I have a script that has a part that looks like that:</p>
<pre><code>for file in `ls *.tar.gz`; do
echo encrypting $file
gpg --passphrase-file /home/$USER/.gnupg/backup-passphrase \
--simple-sk-checksum -c $file
done
</code></pre>
<p>For some reason if I run this script manually, works perfectly fine and ... | <p>It turns out that the answer was easier than I expected. There is a <code>--batch</code> parameter missing, gpg tries to read from /dev/tty that doesn't exist for cron jobs. To debug that I have used <code>--exit-on-status-write-error</code> param. But to use that I was inspired by exit status 2, reported by echoing... | <p>make sure the user that is running the cron job has the permissions needed to encrypt the file. </p>
| 6,102 |
<p>Is there a best way to turn an integer into its month name in .net?</p>
<p>Obviously I can spin up a datetime to string it and parse the month name out of there. That just seems like a gigantic waste of time.</p>
| <p>Try GetMonthName from DateTimeFormatInfo</p>
<p><a href="http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.getmonthname.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.getmonthname.aspx</a></p>
<p>You can do it by:</p>
<pre><code... | <p>To get abbreviated month value, you can use <code>Enum.Parse();</code></p>
<pre><code>Enum.Parse(typeof(Month), "0");
</code></pre>
<p>This will produce "Jan" as result.</p>
<p>Remember this is zero-based index.</p>
| 26,941 |
<p>I have some flexible PLA filament (<a href="https://rads.stackoverflow.com/amzn/click/com/B00VKSSA4E" rel="noreferrer" rel="nofollow noreferrer">https://www.amazon.com/dp/B00VKSSA4E/</a>, presumably a mix of PLA with some platicizer) that's supposed to be easy to print with settings similar to regular PLA. I've seen... | <p>You could enable <code>combing</code> in the slicer. Combing not only prevents retracts, it also uses already laid down paths for movement from one to the other location and as such reduces the amount of stringing.</p>
| <p>The right path seems to be enabling retraction, but tuning the retraction and print speed settings. I started out by dropping all speed settings to 30. With retraction disabled, this turned the stringing into solid walls between paths, with only a tiny gap at the very start of the wall, right after the extruder stop... | 1,254 |
<p>I need audio playback with these features: good performance (for game), pitch control, and ability to layer the same sample multiple times at the same time (polyphony). What would be a quick way to get this on the iphone sdk?</p>
<hr>
<p>Here's what I found out so far:</p>
<p>There's no available libraries or sam... | <p>FMOD (www.fmod.org) provides all these features. Check out their virtualvoices sample for polyphony and the pitch shift DSP effect in the docs.</p>
<p>I'm just a customer, not otherwise affiliated with them.</p>
| <p>The SoundEngine from CrashLanding is a mess, I’d stay away from it. Writing what you want around OpenAL is not hard, it’s a few hours of work. You can peek at <a href="http://github.com/zoul/Finch/" rel="nofollow noreferrer">Finch</a> or at the <a href="http://code.google.com/p/cocos2d-iphone/source/browse/trunk/exp... | 43,320 |
<p>I have to deal with text files in a motley selection of formats. Here's an example (Columns <strong>A</strong> and <strong>B</strong> are tab delimited):</p>
<pre><code>A B
a Name1=Val1, Name2=Val2, Name3=Val3
b Name1=Val4, Name3=Val5
c Name1=Val6, Name2=Val7, Name3=Val8
</code></pre>
<p>The files could ha... | <p>I don't like sed too much, but it works for such things:</p>
<pre><code>var="Name2";sed -n "1p;s/\([^ ]*\) .*$var=\([^ ,]*\).*/\1 \2/p" < filename
</code></pre>
<p>Gives you:</p>
<pre><code> A B
a Val2
c Val7
</code></pre>
| <p>From what I've seen I'd start with Awk for this sort of thing and then if you need something more complex, I'd progress to Python.</p>
| 10,796 |
<p>Ok, I have been working with Solaris for a 10+ years, and have never seen this...</p>
<p>I have a directory listing which includes both a file and subdirectory with the same name:</p>
<pre><code>-rw-r--r-- 1 root other 15922214 Nov 29 2006 msheehan
drwxrwxrwx 12 msheehan sysadmin 2048 Mar 25 15:39 ms... | <p>I would guess that these are in fact two different filenames that "look" the same, as the command file was able to distinguish them when the shell passed the expanded versions of the name in. Try piping ls into od or another hex/octal dump utility to see if they really have the same name, or if there are non-printi... | <p>And a quick answer to part 2 of my own question...</p>
<p>I would imagine I could rename the directory, delete the file, and rename the directory back to it's original again. </p>
<p>... I would still be interested to see what other people come up with.</p>
<p>JB</p>
| 10,887 |
<p>I have a custom program which preprocesses a C# file and generates a new C# file as output. I would like to invoke this from msbuild on each of the C# files in the project, then compile the output files instead of the original C# files. How would I go about this?</p>
| <p>I'm not sure if there is an easy way to perform it with default msbuild tasks. But you can create your own task to do whatever you want:</p>
<p><a href="http://blogs.msdn.com/msbuild/archive/2006/01/21/515834.aspx" rel="nofollow noreferrer">How To: Implementing Custom Tasks - Part I</a></p>
<p>Also you can search ... | <p>If your custom program is an executable the easiest way would be to call the executable with Exec:</p>
<pre><code><Exec Command="your executable" />
</code></pre>
<p>I would recommend writing a custom MSBuild task though. You can look at the <a href="http://www.codeplex.com/sdctasks" rel="nofollow noreferrer... | 14,407 |
<p>So I'm teaching myself Python, and I'm having an issue with lists. I want to pass my function a list and pop items off it while retaining the original list. How do I make python "instance" the passed list rather that passing a pointer to the original one?</p>
<p>Example:</p>
<pre><code>def burninate(b):
c = []... | <p>As other answers have suggested, you can provide your function with a copy of the list.</p>
<p>As an alternative, your function could take a copy of the argument:</p>
<pre><code>def burninate(b):
c = []
b = list(b)
for i in range(3):
c.append(b.pop())
return c
</code></pre>
<p>Basically, y... | <pre><code>burninate = lambda x: x[:-4:-1]</code></pre>
| 28,195 |
<p>While we try to set up as many unit tests as time allows for our applications, I always find the amount of UI-level tests lacking. There are many options out there, but I'm not sure what would be a good place to start. </p>
<p>What is your preferred unit testing tool for testing Swing applications? Why do you like ... | <p>On our side, we use to test SWING GUI with <a href="http://code.google.com/p/fest/" rel="noreferrer">FEST</a>. This is an adapter on the classical swing robot, but it ease dramatically its use. </p>
<p>Combined with TestNG, We found it an easy way to simulate "human" actions trough the GUI.</p>
| <p>try pounder : <a href="http://pounder.sourceforge.net/" rel="nofollow noreferrer">http://pounder.sourceforge.net/</a></p>
| 10,529 |
<p>Is there a way to get more useful information on validation error? XmlSchemaException provides the line number and position of the error which makes little sense to me. Xml document after all is not about its transient textual representation. I'd like to get an enumerated error (or an error code) specifying what whe... | <p>In my experience, you are lucky to get a line number and parse position.</p>
| <p>personally I'm not sure how to get a more detailed error, typcially f you open the document and go to the location mentioned you can easily find the error.</p>
<p>If the code isn't able to parse the file as valid XML, it is pretty hard for it to give an XPATH or other named XML detail.</p>
| 18,734 |
<p>I'm sorry I could not think of a better title.</p>
<p>The problem is the following:</p>
<p>For our customer we have created (as part of a larger application) a
graphical designer which they can use to build "scenario's".</p>
<p>These scenario's consist of "Composites" which in turn consist
of "Commands". These co... | <p>If you really just want a dirt simple language, you want a 'recursive descent parser'.</p>
<p>For example, a language like this:</p>
<pre><code>SCENARIO MyScenario
DELAY 1
COUNT 1 ADD 1
DIRECT_POWER 23, False, 150
WAIT 3
...
END_SCENARIO
</code></pre>
<p>You might have a grammar like:</p>
<pre><code>scenario :: ... | <p>While it might be great fun to create this mini-language and code it all up, the real questions you need to ask are:</p>
<ol>
<li>What is the business case for adding this feature / facility?</li>
<li>Who is going to pay for this feature?</li>
<li>Who is going to "sign off" on this feature if you build it?</li>
</o... | 32,997 |
<p>I've been writing PHP web applications for some time, and have come across very nice Javascript frameworks, such as JQuery, ExtJS, Scriptaculous, etc. I can't say the same about the PHP side - I always coded that part of the client-server dialog from scratch.</p>
<p>I've used CodeIgniter (<a href="http://codeignite... | <p>The <a href="http://framework.zend.com/" rel="nofollow noreferrer">Zend Framework</a> is integrated with <a href="http://dojotoolkit.org/" rel="nofollow noreferrer">Dojo Toolkit</a>. I haven't used the latest Zend Framework yet, but I do know that in the past, it has proven to be reliable.</p>
| <p>Yes, PHP can output XML and JSON for Ajax but not all PHP frameworks support JSON/XML equally well.</p>
<p>For example: I ran into an problem in Drupal (4.7) where the PHP sessions would be deleted after outputting a JSON response. (The HTML output code was explicitly closing the session, which was required or the ... | 20,638 |
<p>I'm attempting to install phpMyAdmin, but I constantly get errors.</p>
<p>When I type this in the terminal:</p>
<pre><code>sudo dpkg --configure -a
</code></pre>
<p>The following message appears:</p>
<pre>
Setting up mysql-server-5.0 (5.0.45-1ubuntu3) ...
* Stopping MySQL database server mysqld ... | <p>The installer error is related to the <code>mysql-server-5.0</code> package. You probably should do an <code>apt-get purge mysql-server-5.0</code> and then try reinstalling it. Once that has been installed, try and install phpmyadmin.</p>
| <p>You might also be able to get away with</p>
<pre><code>dpkg --configure mysql-server-5.0
</code></pre>
<p>since 'mysql-server' is a meta package. </p>
| 42,558 |
<p>I have an Asp.NET application (VS2008, Framework 2.0). When I try to set a property on one of the user controls like</p>
<pre><code>myUserControl.SomeProperty = someValue;
</code></pre>
<p>I get a <code>NullReferenceException</code>. When I debug, I found out that <code>myUserControl</code> is null. How is it poss... | <p>Where are you trying to access the property? If you are in onInit, the control may not be loaded yet.</p>
| <p>If you created the UserControl during runtime (through ControlCollection.Add), you need to create it on postback too.</p>
<p>Another case can be your UserControl does not match the designer.cs page</p>
| 5,015 |
<p>Does anyone know of a powershell cmdlet out there for automating task scheduler in XP/2003? If you've ever tried to work w/ schtasks you know it's pretty painful.</p>
| <p>Ok, Pablo has sparked my interest in saying that the scheduler is accessible via COM.</p>
<p>In PowerShell you can do this:</p>
<pre><code>$svc = new-object -com Schedule.Service
</code></pre>
<p>... and that gives you a handle to the task scheduler. You can see what members it has using:</p>
<pre><code>$svc | g... | <p>@slipsec: I don't have access to a 2003 server to try, but googling "2003 server" SCHTASKS there are links related to questions about it. Perhaps you misspell the command?
Like Matt says, you also can use AT, but in this case you don't have access to the scheduled tasks via the Control Panel, only via the AT command... | 5,388 |
<p>I'm having problems with Iterator.remove() called on a HashSet.</p>
<p>I've a Set of time stamped objects. Before adding a new item to the Set, I loop through the set, identify an old version of that data object and remove it (before adding the new object). the timestamp is included in hashCode and equals(), but ... | <p>I was very curious about this one still, and wrote the following test:</p>
<pre><code>import java.util.HashSet;
import java.util.Iterator;
import java.util.Random;
import java.util.Set;
public class HashCodeTest {
private int hashCode = 0;
@Override public int hashCode() {
return hashCode ++;
... | <p>If there are two entries with the same data, only one of them is replaced... have you accounted for that? And just in case, have you tried another collection data structure that doesn't use a hashcode, say a List?</p>
| 31,742 |
<p>Wrote the following in PowersHell as a quick iTunes demonstration:</p>
<pre><code>$iTunes = New-Object -ComObject iTunes.Application
$LibrarySource = $iTunes.LibrarySource
foreach ($PList in $LibrarySource.Playlists)
{
write-host $PList.name
}
</code></pre>
<p>This works well and pulls back a list of playlist na... | <p>Here is one thing that I did on my a Powershell script that adds podcasts to iTunes. I use Juice on a server to download all the podcasts that I listen to. The script uses .Net methods to release the COM objects. When I wrote my iTunes script I had read a couple of articles that stated you should release your COM ... | <p>You should be able to set $itunes to $null. Alternatively, $itunes should have a quit method you can call. $itunes.quit()</p>
| 7,551 |
<p>config file :</p>
<pre><code><system.net>
<mailSettings>
<smtp from="YYYYY@xxxxxx.com">
<network
host="mail.xxxxxx.com"
port="25"
password="password"
userName="user@xxxxxx.com"
defaultCredentials="false"
/>
</smtp>
</mailSettings>
</system.net>
</code></pre>
<p>I've alread... | <p>Set the deliveryMethod property on the smtp element to 'network'. </p>
| <p>Set the deliveryMethod property on the smtp element to 'network'. </p>
| 42,680 |
<p>This code</p>
<pre><code>select.select([sys.stdin], [], [], 1.0)
</code></pre>
<p>does exactly what I want on Linux, but not in Windows.</p>
<p>I've used <code>kbhit()</code> in <code>msvcrt</code> before to see if data is available on stdin for reading, but in this case it always returns <code>0</code>. Additio... | <p>In some rare situations, you might care what stdin is connected to. Mostly, you don't care -- you just read stdin.</p>
<p>In <code>someprocess | python myprogram.py</code>, stdin is connected to a pipe; in this case, the stdout of the previous process. You simply read from <code>sys.stdin</code> and you're readin... | <p>I run a thread that reads from stdin, then forward the data to a socket. The socket is selectable, so, stdin is selectable too.</p>
<blockquote>
<p>In a recent project, I must continuously read from one network socket, forward to another socket, until the user inputs <code>q</code> from the console. One may think to... | 41,926 |
<p>I've written a IE Toolbar in C# and everything is working fine except that when I open a child Windows Form from my toolbar, the tab key doesn't work on the child form to allow me to move from field to field.</p>
<p>The interesting part is that when I open my child form using form.showDialog() instead of form.show... | <p>Are you also implementing HasFocusIO? I believe your main toolbar class must also implement HasFocusIO and return true.</p>
<p>These types of problems with IE toolbars were the bane of my existence for a while. I think what I eventually ended up doing was creating separate UI threads and making my dialogs modal in ... | <p>Where are you implementing these? It's hard to tell from what you have there, are you implementing them in your Form or are you implementing them in your deskband class? </p>
<p>You need to implement them in your DeskBand implementation, and HasFocusIO needs to return true whenever one of your windows has focus (no... | 27,068 |
<p>I'm looking for suggestions for a PHP:</p>
<ol>
<li>calendar control/widget that I can embed on a web page to enable users to select dates. A datepicker.</li>
<li>calendar software that will provide weekly calendar view, similar to what Microsoft Outlook provides. It should display days of the week in columns and... | <p>You can use the JQuery's datepicker:</p>
<p>homepage: <a href="http://www.kelvinluck.com/assets/jquery/datePicker/" rel="nofollow noreferrer">http://www.kelvinluck.com/assets/jquery/datePicker/</a></p>
<p>demos: <a href="http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/" rel="nofollow noreferrer">http://... | <p>If you're willing to make a custom one take a look at the PHP <a href="http://docs.php.net/manual/en/book.calendar.php" rel="nofollow noreferrer">calendar book</a>. </p>
<p>Unfortunately I haven't used any of these myself.</p>
| 32,059 |
<p>Using sql server 2000, I would like to take my production data and put it in my test database, but I don't want to overwrite the schema of the test database as there are fields in it that I haven't added to production yet. Can this be done? I should add that these databases are on different servers.</p>
| <p>Use something like OmBelt's exportSQLServer to SQL tool.
(ombelt.com)</p>
<p>The inserts it makes specify fields so you should be okay. If not, mass-edit them.</p>
<p>I find it greatly simplifies SQLServer to have SQL dumps like other databases.</p>
| <p>If you use a tool to generate scripts that explicitly names columns (such as SSIS), it should work, as long as there aren't columns in your production database that don't exist in dev.</p>
| 12,435 |
<p>One of the things I like about coding "old skool" (web forms) is the AJAX Control Toolkit.</p>
<p>I saw on the <a href="http://www.asp.net/learn/mvc-videos/video-373.aspx" rel="nofollow noreferrer">Microsoft Storefront video 14</a>, <a href="http://blog.wekeroad.com/mvc-storefront/mvcstore-part-14/" rel="nofollow n... | <p><a href="http://ui.jquery.com/" rel="noreferrer">jQuery UI</a> has a calendar and other UI components. Also check out the vast number of <a href="http://plugins.jquery.com/" rel="noreferrer">jQuery plugins</a>.</p>
| <p>Most of the AJAX Control Toolkit is available in MVC-friendly javascript form off the <a href="http://www.asp.net/ajaxlibrary/CDNACT40412.ashx" rel="nofollow noreferrer">MS AJAX CDN</a>. These can be used using a jquery plug-in syntax as well.</p>
| 48,053 |
<p>I've been developing a simple website using asp.net MVC and I'm starting to add some JQuery\JSON goodness. </p>
<p>My problem is up until now all my 'Views' have been strongly typed and I've been building the view based on data from ViewData.Model.MyViewsData. Now once the view has been rendered and I do a Ajax s... | <p>I use jQuery and Monorail for an MVC framework - and we use both approaches.</p>
<p><a href="https://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/" rel="nofollow noreferrer">Here's an example for the jquery approach</a> - ignore the fact it's php. The approach is the same, namely in the p... | <p>If you use the Controller's JSON method to return data for your Ajax request, you can serialize your data to Json and then you have access to it from within your JavaScript. So as an example, If you had a comment form at the bottom of an Article/Blog Post page and you wanted to add the comment via a jQuery $.post ca... | 30,212 |
<p>In Java, say you have a class that wraps an <code>ArrayList</code> (or any collection) of objects. </p>
<p>How would you return one of those objects such that the caller will not see any future changes to the object made in the ArrayList? </p>
<p>i.e. you want to return a deep copy of the object, but you don't kno... | <p>Turn that into a spec:<br>
-that objects need to implement an interface in order to be allowed into the collection
Something like <code>ArrayList<ICloneable>()</code></p>
<p>Then you can be assured that you always do a deep copy - the interface should have a method that is guaranteed to return a deep copy. <... | <p>I suppose it is an ovbious answer:</p>
<p>Make a requisite for the classes stored in the collection to be cloneable. You could check that at insertion time or at retrieval time, whatever makes more sense, and throw an exception.</p>
<p>Or if the item is not cloneable, just fail back to the return by reference opti... | 4,962 |
<p>Are there any official naming conventions for tag names on Stack Exchange? And if not, how should tags be named?</p>
<p>From what I understand, one typically adds a <em>dash</em> (-) where you normally would leave a <em>space</em>, but how about tags that derive from words that are <em><a href="https://3dprinting.m... | <p>Looking at other SE sites, the most common approach seems to make everything lowercase (including names and trademarks) and using hyphens whenever there would be a space or hyphen in normal usage.</p>
<p>As such:</p>
<ul>
<li><p>MatterControl becomes mattercontrol</p></li>
<li><p>Makerbot becomes makerbot</p></li>... | <p>I would say we could use synonyms to stay with clear tag namespace.In this case we apply following pattern (especially for proper name (product name)):</p>
<pre><code>Topic | Existing tag | Synonym?
---------------+-----------------+--------------
MatterControl | mattercontrol | matter-control
</code... | 29 |
<p>What are the steps needed to successfully be able to remotely debug a stored procedure (SQL Server 2005) from within VS 2005? </p>
<p>Both client and server machines are on the same domain. I have never done this so step by step instructions would greatly be appreciated.</p>
| <p>Great Question! If I'm not mistaken I don't think debugging is possible inside of SQL Management Studio anymore (as it was back in the SQL Server 2000, Enterprise Studio days).</p>
<h2>Instructions to Remote Debug MS SQL Stored Procedures within Visual Studio 2005</h2>
<ol>
<li>Launch Visual Studio (If you're runnin... | <p>SQL Specifically</p>
<blockquote>
<p><a href="http://msdn.microsoft.com/en-us/library/s4sszxst(VS.71).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/s4sszxst(VS.71).aspx</a></p>
</blockquote>
<p>VS2005 in general</p>
<blockquote>
<p><a href="http://msdn.microsoft.com/en-us/library/y7f... | 17,205 |
<p>Ok, this is another one in the theory realm for the CS guys around.</p>
<p>In the 90's I did fairly well in implementing BST's. The only thing I could never get my head around was the intricacy of the algorithm to balance a Binary Tree (AVL).</p>
<p>Can you guys help me on this?</p>
| <p>A scapegoat tree possibly has the simplest balance-determination algorithm to understand. If any insertion causes the new node to be too deep, it finds a node around which to rebalance, by looking at weight balance rather than height balance. The rule for whether to rebalance on delete is also simple. It doesn't sto... | <p>The AVL tree is inefficient because you have to do potentially many rotations per insertion/deletion.</p>
<p>The Red-Black tree is probably a better alternative because insertions/deletions are much more efficient. This structure guarantees the longest path to a leaf is no more than twice the shortest path. So wh... | 16,172 |
<p>Apparently, they're "confusing". Is that seriously the reason? Can you think of any others?</p>
| <p>Have you seen how many developers don't really understand ref/out?</p>
<p>I use them where they're really necessary, but not otherwise. They're usually only useful if you want to effectively return two or more values - in which case it's worth at least <em>thinking</em> about whether there's a way of making the met... | <p>Isn't code complexity reason enough? Compare:</p>
<pre><code>int myValue;
ReadFromSomewhere(ref myValue);
</code></pre>
<p>To:</p>
<pre><code>int myValue = ReadFromSomewhere();
</code></pre>
| 26,387 |
<p>I have a webapp development problem that I've developed one solution for, but am trying to find other ideas that might get around some performance issues I'm seeing.</p>
<p>problem statement: </p>
<ul>
<li>a user enters several keywords/tokens</li>
<li>the application searches for matches to the tokens</li>
<li>ne... | <p>you could achive this in one query using 'UNION ALL' in MySQL.</p>
<p>Just loop through the tokens in PHP creating a UNION ALL for each token:</p>
<p>e.g if the tokens are 'x', 'y' and 'z' your query may look something like this</p>
<pre><code>SELECT * FROM `entries`
WHERE token like "%x%" union all
SELECT ... | <p>You'll probably get much better performance if you used a data structure designed for search tasks rather than a database. For example, you might try looking at building an <a href="http://en.wikipedia.org/wiki/Inverted_index" rel="nofollow noreferrer">inverted index</a>. Rather than writing it youself, however, you... | 7,002 |
<p>At work, we have one of those nasty communal urinals. There is no flush handle. Rather, it has a motion sensor that sometimes triggers when you stand in front of it and sometimes doesn't. When it triggers, a tank fills, which when full is used to flush the urinal.</p>
<p>In my many trips before this nastraption, I ... | <pre><code>OnUserEnter()
{
if (UsersDetected == 0)
{
FirstDetectionTime = Now();
}
UsersDetected++;
CurrentlyInUse = true;
}
OnUserExit()
{
CurrentlyInUse = false;
if (UsersDetected >= MaxUsersBetweenFlushes ||
Now() - FirstDetectionTime > StinkInterval)
{
Flush();
}
}... | <p>At the risk of sounding Ludditish, I think the best solution is a handle. But that isn't the question. I would assume the mechanism is very simple. Someone moves in front of it, a count starts. When the count is fulfilled, the urinal is "primed". When the person moves away, the trigger is pulled, and the sensor turn... | 29,365 |
<p>When I iterate over the values or keys are they going to correlate? Will the second key map to the second value?</p>
| <p>No, not necessarily. You should really use the entrySet().iterator() for this purpose. With this iterator, you will be walking through all Map.Entry objects in the Map and can access each key and associated value.</p>
| <p>The question confused me at first but @Matt cleared it up for me.</p>
<p>Consider using the entrySet() method that returns a set with the key-value pairs on the Map.</p>
<pre><code>Map<Integer, Integer> a = new HashMap<Integer, Integer>(2);
a.put(1, 2);
a.put(2, 3);
for (Map.Entry<Integer, Integer&g... | 15,577 |
<p>I have a problem with a string in C++ which has several words in Spanish. This means that I have a lot of words with accents and tildes. I want to replace them for their not accented counterparts. Example: I want to replace this word: "había" for habia. I tried replace it directly but with replace method of string c... | <p>First, this is a really bad idea: you’re mangling somebody’s language by removing letters. Although the extra dots in words like “naïve” seem superfluous to people who only speak English, there are literally thousands of writing systems in the world in which such distinctions are very important. Writing software to ... | <p>If you can (if you're running Unix), I suggest using the <a href="http://www.gnu.org/software/coreutils/manual/html_node/tr-invocation.html" rel="nofollow noreferrer"><code>tr</code></a> facility for this: it's custom-built for this purpose. Remember, no code == no buggy code. :-)</p>
<p>Edit: Sorry, you're right, ... | 17,460 |
<p>I'm trying to decode a WBXML encoded SyncML message from a Nokia N95.
My first attempt was to use the python pywbxml module which wraps calls to libwbxml. Decoding the message with this gave a lot of <unknown> tags and a big chunk of binary within a <Collection> tag. I tried running the contents of the &... | <p>I ended up writing a python parser myself. I managed to do it by following the spec here:
<a href="http://www.w3.org/TR/wbxml/" rel="nofollow noreferrer">http://www.w3.org/TR/wbxml/</a></p>
<p>And then taking the code tables from the horde.org cvs.</p>
<p>The open mobile alliance's site and documentation are terri... | <p>I used <a href="https://github.com/diegows/pywbxml/" rel="nofollow noreferrer">pywbxml</a> ,
Just needed one patch in pywbxml.pyx:</p>
<p><code>params.lang</code> in function <code>wbxml2xml</code> around <a href="https://github.com/diegows/pywbxml/blob/254030c8413ceab710838ff544c83bc343ddbd8c/0.1/src/pywbxml.pyx#L... | 27,971 |
<p>Is it possible to have a <code>MySQLi prepared statement</code> within the <code>fetch()</code> call of a previous statement? If not, what's the best way around it?</p>
<p>Example code:</p>
<pre><code>if($stmt = $link->prepare("SELECT item FROM data WHERE id = ?")) {
$stmt->bind_param("i", $id);
$stm... | <p>This is the single connection way:</p>
<pre><code>if($stmt = $link->prepare("SELECT item FROM data WHERE id = ?")) {
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->store_result(); // <-- this
$stmt->bind_result($item);
while( $stmt->fetch() ) {
/* Other code h... | <p>Or use <a href="http://php.net/manual/en/mysqli.store-result.php" rel="nofollow noreferrer"><code>store_result</code></a>.</p>
| 13,784 |
<p>I have a class hierarchy as such:</p>
<pre><code> +-- VirtualNode
|
INode --+ +-- SiteNode
| |
+-- AbstractNode --+
|
+-- SiteSubNode
</code></pre>
<p>And a corresponding <code>NodeCollection</cod... | <p>What you're after is the <a href="http://en.wikipedia.org/wiki/Visitor_pattern" rel="nofollow noreferrer">visitor pattern</a>, I think.</p>
| <p>If you can change the INode interface - add a virtual method that returns the "view" and override it in the inherited classes.</p>
<p>If you can't change the base interface - implement extension methods for each of the classes and have them return the "view" of for each particular class.</p>
| 22,593 |
<p>I have a subversion repository that contains a number so subfolders, corresponding to the various applications, configuration files, DLLs, etc (I'll call them 'modules') that make up my project. Now we are starting to "branch" into several related projects. That is, each high-level project will use a number of the... | <p>It would seem best to organize by <strong>Project</strong> at the top level, since you're going to want to checkout an entire branch and have a working copy for the project. If you organize by module, you'll have to do multiple checkouts (one for each module you're using) in order to build your project to a point w... | <p>I think that your use of "high-level" to describe what a project is suggests that you should have a Projects/modules setup.</p>
<p>However you could have a Modules and Projects set up - i.e., they are at the same level in the SVN repo. Your Projects can rely on Modules, and if possible the Projects can provide spec... | 16,191 |
<p>I have some jQuery/JavaScript code that I want to run only when there is a hash (<code>#</code>) anchor link in a URL. How can you check for this character using JavaScript? I need a simple catch-all test that would detect URLs like these:</p>
<ul>
<li><code>example.com/page.html#anchor</code></li>
<li><code>example... | <p>Simple use of <a href="https://developer.mozilla.org/en-US/docs/Web/API/Location/hash" rel="noreferrer">location hash</a>:</p>
<pre><code>if(window.location.hash) {
// Fragment exists
} else {
// Fragment doesn't exist
}
</code></pre>
| <p>sometimes you get the full query string such as "#anchorlink?firstname=mark"</p>
<p>this is my script to get the hash value:</p>
<pre><code>var hashId = window.location.hash;
hashId = hashId.match(/#[^?&\/]*/g);
returns -> #anchorlink
</code></pre>
| 38,212 |
<p>When would I implement IDispose on a class as opposed to a destructor? I read <a href="http://www.dotnetspider.com/resources/1382-Understanding-IDisposable-pattern.aspx" rel="noreferrer">this article</a>, but I'm still missing the point. </p>
<p>My assumption is that if I implement IDispose on an object, I can ex... | <p>A finalizer (aka destructor) is part of garbage collection (GC) - it is indeterminate when (or even if) this happens, as GC mainly happens as a result of memory pressure (i.e. need more space). Finalizers are usually only used for cleaning up <em>unmanaged</em> resources, since managed resources will have their own ... | <p>Here is another fine article which clears up some of the mist surrounding IDisposable, the GC and dispose.</p>
<p><a href="http://blogs.msdn.com/clyon/archive/2004/09/21/232445.aspx" rel="nofollow noreferrer">Chris Lyons WebLog Demystifying Dispose</a></p>
| 44,029 |
<p>Imagine we have a program trying to write to a particular file, but failing.</p>
<p>On the Windows platform, what are the possible things which might be causing the file to be un-writable, and what steps could be suggested to an end user/administrator to fix it.</p>
<hr />
<p>Please include steps which might require... | <p>Some suggestions:</p>
<ul>
<li>No write permission (get permission through Security tab on file Properties window; you must be the file owner or an Administrator)</li>
<li>File is locked (close any program that may have the file open, then reboot if that doesn't help)</li>
<li>File has the read-only DOS attribute s... | <p>On Vista could it also be that it's "marked" as unsafe because it's been downloaded from the internet and you have to click the unblock button on it's explorer properties dialog?</p>
| 5,824 |
<p>I've read the several discussions about storing code snippets but I did't find the info that I'm looking for, so let's define it:</p>
<ul>
<li>At home, I have several side projects, most of them quite small, one large, and numerous little examples that demonstrate a specific language feature (for example, some temp... | <p>I keep everything in a source control repository, indexed by language. As I learn new languages, I translate some of my old useful stuff into the new language to learn how to do things in the new language. </p>
| <p>I work in Visual Studio at home and at work.</p>
<p>I basically have all my code snippets in a folder that is synced to my <a href="https://www.mesh.com/Welcome/Default.aspx" rel="nofollow noreferrer">Live Mesh</a>. I then have each folder added to VS to enable it to auto-detect new snippets. Works like a charm for... | 42,059 |
<p>I've decided to reimplement the datetime picker, as a standard datetime picker isn't nullable. The user wants to start with a blank field and type (not select) the date.</p>
<p>I've created a user control to do just that, but if the user control is near the edge of the form, it will be cut off on the form boundry. ... | <p>The ToolStripDropDown control has this functionallity so by inheriting from it we can make a simple PopupWindow.</p>
<pre><code>/// <summary>
/// A simple popup window that can host any System.Windows.Forms.Control
/// </summary>
public class PopupWindow : System.Windows.Forms.ToolStripDropDown
{
pr... | <p>The reason that your control gets chopped off is because it is a child control of the form that you reside on. Any control on the form must be contained by the form, hence it gets chopped off.</p>
<p>I haven't done this in .Net, but had a similar problem in VB6. The solution then was to set the parent of the popup ... | 35,529 |
<p>I have code like this:</p>
<pre><code>class RetInterface {...}
class Ret1: public RetInterface {...}
class AInterface
{
public:
virtual boost::shared_ptr<RetInterface> get_r() const = 0;
...
};
class A1: public AInterface
{
public:
boost::shared_ptr<Ret1> get_r() const {...}
.... | <p>Firstly, this is indeed how it works in C++: the return type of a virtual function in a derived class must be the same as in the base class. There is the special exception that a function that returns a reference/pointer to some class X can be overridden by a function that returns a reference/pointer to a class that... | <p><a href="https://stackoverflow.com/questions/196733/smart-pointer-and-virtual#196744">Mr Fooz </a> answered part 1 of your question. Part 2, it works this way because the compiler doesn't know if it will be calling AInterface::get_r or A1::get_r at compile time - it needs to know what return value it's going to get,... | 23,904 |
<p>I am trying to display object data members in a generic way. I started by using PropertyGrid, which satisfies my needs as far as simple properties are concerned. However, it doesn't let the user drill-down into data members. It allows browsing into collections, but the interface is a bit awkward.</p>
<p>I'm basi... | <p>You can drill down into properties in the PropertyGrid of course. This is a vast subject, but maybe your properties simply need to have the ExpandableObjectConverter attached to them? Or if you are going more into details, the attached TypeConverter needs to override the GetPropertiesSupported and GetProperties meth... | <p>I would use a treeview control, styled to look like a 'grid'.
Then as you drill down, you can dynamically load any child items that you need to.</p>
| 28,437 |
<p>I'm trying to write rules for detecting some errors in <em>annotated</em> multi-threaded java programs. As a toy example, I'd like to detect if any method annotated with @ThreadSafe calls a method without such an annotation, without synchronization. I'm looking for a tool that would allow me to write such a test. ... | <p>Have you tried <a href="http://findbugs.sourceforge.net/" rel="nofollow noreferrer">FindBugs</a>? It actually supports a set of <a href="http://www.javaconcurrencyinpractice.com/annotations/doc/net/jcip/annotations/package-summary.html" rel="nofollow noreferrer">annotations for thread safety</a> (the same as those ... | <p>A simple tool to checkup on annotations is apt (<a href="http://java.sun.com/j2se/1.5.0/docs/guide/apt/" rel="nofollow noreferrer">http://java.sun.com/j2se/1.5.0/docs/guide/apt/</a> also part of Java 6 api in javax.annotation.processing) however this only has type information (ie I couldn't find a quick way to get a... | 34,862 |
<p>In the following table structure:</p>
<pre><code>Fruits
(
fruit_id,
fruitName
)
Vegetables
(
vegetable_id,
vegetableName
)
favoriteFoods
(
food_id,
foodName,
type_id (References either a fruit or a vegetable)
)
</code></pre>
<p>I realize that I could forgo using a foreign key co... | <p>I would only use 2 tables instead. Instead of having a separate Fruits and Vegetables table, why not have a table of Foods. Then have a foreign key constraint on fkfood_id to food_id. Then if for some reason you ever have to add meat, it would be much easier to maintain the application that uses this.</p>
<pre><... | <p>It depends on what you are going to do with the data.</p>
<p>If for some reason normalization is important to you, the following works quite well.</p>
<pre><code>Fruits (
fruit_id,
food_id references favoritefoods.food_id,
fruitName)
Vegetables(
vegetable_id,
food_id references favori... | 33,003 |
<p>How do I correct for floating point error in the following physical simulation:</p>
<ul>
<li>Original point (x, y, z),</li>
<li>Desired point (x', y', z') after forces are applied.</li>
<li>Two triangles (A, B, C) and (B, C, D), who share edge BC</li>
</ul>
<p>I am using this method for collision detection:</p>
<... | <p>This is an inevitable problem when shooting a single ray against some geometry with edges and vertices. It's amazing how physical simulations seem to seek out the smallest of numerical inaccuracies!</p>
<p>Some of the explanations and solutions proposed by other respondents will not work. In particular:</p>
<ul>
<... | <p>@Statement: I am indeed already using a "greater than or equal to" comparison in my code, thank you for the suggestion. +1</p>
<p>My current solution is to add a small nudge amount to the edge test. Basically when each triangle is tested, its edges are pushed out by a very small amount to counteract the error in f... | 12,475 |
<p>Looking for a <code>Linux application</code> <em>(or Firefox extension)</em> that will allow me to scrape an HTML mockup and keep the page's integrity.</p>
<p>Firefox does an almost perfect job but doesn't grab images referenced in the CSS.</p>
<p>The Scrapbook extension for Firefox gets everything, but flattens t... | <p>See <a href="http://www.devarticles.com/c/a/Web-Services/Website-Mirroring-With-wget/1/" rel="noreferrer">Website Mirroring With wget</a></p>
<pre><code>wget --mirror –w 2 –p --HTML-extension –-convert-links http://www.yourdomain.com
</code></pre>
| <p><a href="http://www.tenmax.com/teleport/pro/home.htm" rel="nofollow noreferrer">Teleport Pro</a> is great for this sort of thing. You can point it at complete websites and it will download a copy locally maintaining directory structure, and replacing absolute links with relative ones as necessary. You can also speci... | 10,503 |
<p>Here is new C# future in version 4.0 known as dynamic. Show me the way i can use it in my code and how this future can help me?</p>
<hr>
<p>Related questions:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/298277/does-the-new-dynamic-c-40-keyword-deprecate-the-var-keyword">Does the new ‘dynamic’ C# 4.0... | <p>One of the usages is interop between static and dynamic languages.</p>
<p>Say you want to invoke a JavaScript function fron silverlight:</p>
<pre><code>HtmlPage.Window.Invoke("HelloWorldFunction");
</code></pre>
<p>If the window was dynamic (and properly implemented) you would be able to use it like this:</p>
<p... | <p>One of the usages is interop between static and dynamic languages.</p>
<p>Say you want to invoke a JavaScript function fron silverlight:</p>
<pre><code>HtmlPage.Window.Invoke("HelloWorldFunction");
</code></pre>
<p>If the window was dynamic (and properly implemented) you would be able to use it like this:</p>
<p... | 38,680 |
<p>How do I convert a string into the corresponding code in PLT Scheme (which does not contain the <code>string->input-port</code> method)? For example, I want to convert this string:</p>
<pre><code>"(1 (0) 1 (0) 0)"
</code></pre>
<p>into this list:</p>
<pre><code>'(1 (0) 1 (0) 0)
</code></pre>
<p>Is it possibl... | <p>Scheme has procedure <code>read</code> for reading s-expressions from input port and you can convert a string to input stream with <code>string->input-port</code>. So, you can read a Scheme object from a string with</p>
<pre><code>(read (string->input-port "(1 (0) 1 (0) 0)"))
</code></pre>
<p>I don't have Sc... | <p>Many schemes have <code>with-input-from-string str thunk</code> that executes <code>thunk</code> in a context where <code>str</code> is the standard input port. For example in gambit scheme:</p>
<p><code>(with-input-from-string "(foo bar)"
(lambda () (read)))</code></p>
<p>evaluates to:</p>
<p><code>(foo bar)</... | 41,236 |
<p>For example to create a hierarchy of categories you use a column 'parent_id', which points to another category in the same table.</p>
<p>Should this be a foreign key? What would the dis/advantages be?</p>
| <p>Yes. Ensures that you don't have an orphan (entry with no parent), and depending on usage, if you define a cascading delete, when a parent is deleted, all its children will also be deleted.</p>
<p>Disadvantage would be a slight performance hit just like any other foreign key.</p>
| <p>Yes, you should make it a foreign key.</p>
<p>The benefits will be a better data model with less redundancy.</p>
| 30,593 |
<p>If I want to inject a globally scoped array variable into a page's client-side javascript during a full page postback, I can use:</p>
<pre><code>this.Page.ClientScript.RegisterArrayDeclaration("WorkCalendar", "\"" + date.ToShortDateString() + "\"");
</code></pre>
<p>to declare and populate a client-side javascript... | <p>Use the static method System.Web.UI.ScriptManager.AddStartupScript()</p>
<p>The script will run on all full and partial postbacks.</p>
| <p>You could also update a hidden label inside the update panel which allows you to write out any javascript you like. I would suggest though using web services or even page methods to fetch the data you need instead of using update panels.</p>
<p>Example: myLabel.Text = "...."; ... put your logic in this or you can a... | 12,061 |
<p>If I had a Canvas with n number of Visual objects of any shape or size, how would I highlight/outline a Visual object programmatically? </p>
<p>Is there something built into WPF to help me? </p>
| <p>Having read the comments in the other answer -- in which you state that you wish the outline to conform to the shape of the visual -- I can only suggest you take a look at the <code>BitmapEffects</code>. There is one for an Outer Glow effect.</p>
<p>Duplicating the visuals themselves would probably be less efficien... | <p>If you wrap those Visual objects in a Border ... and make the Opacity 0 by default ... then you could programmatically turn the Opacity to 1 whenever you need to.</p>
<p>Does that help?</p>
| 22,902 |
<p>I need to take a paragraph of text and extract from it a list of "tags". Most of this is quite straight forward. However I need some help now stemming the resulting word list to avoid duplicates. Example: Community / Communities</p>
<p>I've used an implementation of Porter Stemmer algorithm (I'm writing in PHP by ... | <p>If I understand correctly, then what you need is not a stemmer but a lemmatizer. Lemmatizer is a tool with knowledge about endings like <em>-ies</em>, <em>-ed</em>, etc., and exceptional wordforms like <em>written</em>, etc. Lemmatizer maps the input wordform to its lemma, which is guaranteed to be a "real" word.</p... | <p>Hey I don't know if that's perhaps too late, but there is only one PHP stemming script that produces real words: <a href="http://phpmorphy.sourceforge.net/">http://phpmorphy.sourceforge.net/</a> – it took me ages to find it. All other stemmers have to be compiled and even after that they only work according to Porte... | 23,158 |
<p>I am displaying a texture that I want to manipulate without out affecting the image data. I want to be able to clamp the texel values so that anything below the lower value becomes 0, anything above the upper value becomes 0, and anything between is linearly mapped from 0 to 1. </p>
<p>Originally, to display my ima... | <p>Unless you have a pretty old graphics-card, it's surprising that you don't have fragment-shader support. I'd suggest you try double-checking using <a href="http://www.realtech-vr.com/glview/" rel="nofollow noreferrer">this</a>.</p>
<p>Also, are you sure you want anything above the max value to be 0? Perhaps you mea... | <p>It's really unfortunate that you're using such an ancient version of OpenGL. Can you upgrade with your card?</p>
<p>For a more modern OGL 2.x, this is exactly the kind of program that GLSL is for. Great documentation can be found here:</p>
<p><a href="http://opengl.org/documentation/" rel="nofollow noreferrer">O... | 29,009 |
<p>How can I put up a "File Open" dialog from some VBA running in Excel? </p>
<p>I'm using Excel 2003. </p>
| <p>You want the <code>Application.GetOpenFilename</code> function. Copying from VBA Object Browser:</p>
<blockquote>
<p>Function GetOpenFilename([FileFilter], [FilterIndex], [Title], [ButtonText], [MultiSelect])<br>
Member of Excel.Application</p>
</blockquote>
| <p>Add a reference to ComDLG32.OCX and then something like...</p>
<pre><code>Sub PromptForFile()
Dim d As New MSComDlg.CommonDialog
d.Filter = "xls"
d.Filename = "*.xls"
d.ShowOpen
Excel.Workbooks.Open d.Filename
Set d = Nothing
End Sub
</code></pre>
| 27,295 |
<p>The title speaks for itself... I've tried to find another question like it but must have missed it if it exists. I'm looking for anything, from a core library replacing GAPI to a .net wrapper... It's for building a nice UI so no 3D needed...</p>
| <p>The System.Drawing classes in .NET are a lot more powerful than people realize. The only thing missing (which is actually really important in 2D graphics) is the ability to read and write individual pixels. This is technically possible using the GetPixel and SetPixel methods on the Bitmap object, but these methods... | <p>IMO I would suggest getting hold of the frame buffer somehow and drawing to it directly if possible or using D3DM or use the drawing services provided by the Native Platform (GDI) through APIs like DrawGradient() etc from coredll.dll and since you are on WM you might be able to leverage aygshell.dll to draw widgets.... | 45,230 |
<pre><code><form id="frm_1" name="frm_1" target="_self" method="GET" action="local_page.php" >
</form>
<form id="tgt_1" name="tgt_1" target="_blank" method="POST" action="http://stackoverflow.com/" >
</form>
<a onclick="test(event, '1'); " href="#" >Click Here</a>
<script>
... | <pre><code><form id="frm_1" name="frm_1" target="_self" method="POST" action="local_page.php" >
<input type="hidden" name="vital_param" value="<?= $something ?>">
</form>
<form id="tgt_1" name="tgt_1" target="_blank" method="POST" action="http://stackoverflow.com/" >
</form>
<bu... | <p>You should use the window.open to open the new page and then submit the tabchange e.g.</p>
<pre><code><form id="frm_1" name="frm_1" target="_self" method="GET" action="local_page.php" >
</form>
<a onclick="test(event, '1'); " href="#" >Click Here</a>
<script>
function test(event, i... | 33,692 |
<p>I need to communicate with an XML-RPC server from a .NET 2.0 client. Can you recommend any libraries?</p>
<p>EDIT: Having tried XML-RPC.Net, I like the way it generates dynamic proxies, it is very neat. Unfortunately, as always, things are not so simple. I am accessing an XML-RPC service which uses the unorthodox t... | <p>If the method name is all that is changing (i.e., the method signature is static) XML-RPC.NET can handle this for you. This is addressed <a href="http://xml-rpc.net/faq/xmlrpcnetfaq.html#2.23" rel="nofollow noreferrer">in the FAQ</a>, noting "However, there are some XML-RPC APIs which require the method name to be ... | <p>I had also tried to run <a href="http://www.xml-rpc.net/" rel="nofollow noreferrer">www.xml-rpc.net </a> with <a href="http://www.mono-project.com/Main_Page" rel="nofollow noreferrer">Mono </a> on Windows XP and it worked in Mono .NET Runtime also properly. Just for information for everybody. </p>
| 12,657 |
<p>I have been asking myself this question for a long time now. Thought of posting it. C# doesn't support Multiple Inheritance(this is the fact). All classes created in C# derive out of 'Object' class(again a fact).</p>
<p>So if C# does not support Multiple inheritance, then how are we able to extend a class even thou... | <p>Joel's answer is correct. There is a difference between multiple inheritance and an inhertance tree (or derivation chain). In your example, you actually show an inhertance tree: One object inherits (derives) from another object higher in the tree. Multiple inheritance allows one object to inherit from multiple base ... | <p>Given below.</p>
<pre><code>public class A : B
{
}
public class B : C
{
public int BProperty { get; set; }
}
public class C
{
public int CProperty { get; set; }
}
public class Test
{
public void TestStuff()
{
A a = new A();
// These are valid.
a.CProperty = 1;
a.... | 23,246 |
<p>What are the benefits of having a member variable declared as read only? Is it just protecting against someone changing its value during the lifecycle of the class or does using this keyword result in any speed or efficiency improvements?</p>
| <p>The <code>readonly</code> keyword is used to declare a member variable a constant, but allows the value to be calculated at runtime. This differs from a constant declared with the <code>const</code> modifier, which must have its value set at compile time. Using <code>readonly</code> you can set the value of the fi... | <p>There can be a performance benefit in WPF, as it removes the need for expensive DependencyProperties. This can be especially useful with collections</p>
| 34,946 |
<p>I was using jQuery plugins to create a rounded corner for my <code><li></code>, but it was not working on a lot of browsers and didn't support mouse over.</p>
<p>I am wondering what is the best way to use two images (left corner and right corner) as the left and right side with using <code><li></code>.<... | <p>The construct that I have seen used most for that is a span inside a link. </p>
<p>so something like: </p>
<pre><code><li><a><span>Your text here</span></a></li>
</code></pre>
<p>you can then target the span and the link using the hover state of the link: </p>
<pre><c... | <p>You could put Divs inside your li's like so:</p>
<pre><code><li>
<div class="lefcorner"></div>
<div class='liContent'>Foo</div>
<div class='rightcorner'></div>
</li>
</code></pre>
<p>That way you will both keep your semantics and will also have the cross-browse... | 41,202 |
<p>We're planning a browser application (xbap) which is going to talk to WCF services. These WCF services get information from a SQL database. Each of our clients has his own database on this server. The clients need to get reports from SQL Reporting Services. A client can have multiple instances of this application ru... | <p>With the full SQL Server 2008 products (Enterprise, Standard, Workgroup and Web Server), licensing you get a bunch of choices:</p>
<ul>
<li>There is a Webserver version that basically takes care of using SQL server within a web application.</li>
<li>Client Access Licenses (CALs) basically are not interesting if you... | <p>Per cpu licensing is probably your best best. But to answer your question, you can usually purchase "per device" or "per user" CALS for their software. This is just like it sounds. If you have one computer that will be accessing SQL Server with multiple users on that one comnputer, then "per device" CALS make sen... | 47,685 |
<p>I am using running a simple find all and paginating with willpaginate, but I'd also like to have the query sorted by the user. The first solution that came to mind was just use a params[:sort]</p>
<pre><code>http://localhost:3000/posts/?sort=created_at+DESC
@posts = Post.paginate :page => params[:page], :order ... | <p>I’d use a named scope for providing the default order (available since Rails 2.1).</p>
<p>You’d add the scope in your Post model:</p>
<pre><code>named_scope :ordered, lambda {|*args| {:order => (args.first || 'created_at DESC')} }
</code></pre>
<p>Then you can call:</p>
<pre><code>@posts = Post.ordered.pagina... | <p>I prefer this idiom:</p>
<pre><code>@posts = Post.paginate :page=>page, :order=>order
...
def page
params[:page] || 1
end
def order
params[:order] || 'created_at ASC'
end
</code></pre>
| 26,436 |
<p>I have a .NET 2.0 Windows Forms application. On this app there is a Form control with a Menu bar and a status bar. Also there's a ListView on this form.</p>
<p>If I add a context menu to this form, the context menu will open when the user right clicks any part of the form, including the menu bar and the status bar.... | <p>After you've placed your Statusbar at the bottom and MenuStrip at the top, </p>
<ol>
<li>Set ContextMenuStrip on your form to <em>None</em> </li>
<li>Place a standard Panel in the middle (between MenuStrip and StatusStrip) with the <em>Dock</em> property set to <em>Fill</em>. </li>
<li>Set the ContextMenuStrip prop... | <p>I found the answer:</p>
<pre><code>Point clientPos = this.PointToClient(Form.MousePosition);
Control control = this.GetChildAtPoint(clientPos);
</code></pre>
<p>This should give the underlying control that was clicked on the Form, or null if the click was on the gray area. So we just need to test for the type of t... | 13,453 |
<p>I am researching the feasibility of setting up a mapping tool for my alliance in an online game.
The game is not based in the real world so I am not interested in the content of the map tools available, just the functionality. </p>
<p>Minimally, I would like the map to display information about where allied cities... | <p>A List Apart has an <a href="http://www.alistapart.com/articles/takecontrolofyourmaps" rel="nofollow noreferrer">article from the creators of EveryBlock.com</a>. They use a full open-source stack (client side library, tile cache, map generator) as an alternative to Google Maps. That sounds like it has exactly what y... | <p>Wouldn't defining your own overlay with a KMZ file in Google Maps work?</p>
| 23,680 |
<p>I have values stored as strings in a <code>DataTable</code> where each value could really represent an <code>int</code>, <code>double</code>, or <code>string</code> (they were all converted to strings during an import process from an external data source). I need to test and see what type each value really is.</p>
... | <p>Would use double.TryParse, it has performance benefits.</p>
| <p>I'd personally use int.tryparse, then double.tryparse. Performance on those methods is quite fast. They both return a Boolean. If both fail then you have a string, per how you defined your data.</p>
| 2,422 |
<p>Here are my thoughts: The purpose of using MVC is seperation of concerns and testability of gui logic. View should be able to work with different models and model should be able to work with different views.
<p>I think controller class must implement an interface for mocking/testing reasons and view should call cont... | <h2>My "short" answer:</h2>
<hr>
<p>You may have noticed this already, but just in case:</p>
<p>First of all, even when you see that error, (assuming that you click past it and continue), then you should <strong>still be able to use 99% of the debugging features</strong> in Xcode. In other words, that error means t... | <p>Strange... Looking around my Mac, I see that library just fine, and it looks sane.</p>
<p>Have you tried using dtrace to see what Xcode and GDB are trying to do when the error happens?</p>
| 17,570 |
<p>Is there a complete list of Google Gears enabled sites? I'm aware of rememberthemilk.com, google docs and google calendar</p>
| <p>MySpace's message system is one of the <em>biggest</em> outside of Google. At least so I thought according to <a href="http://www.techcrunch.com/2008/05/28/myspace-shows-facebook-how-its-done-google-gears-to-power-messaging/" rel="noreferrer">this article</a>.</p>
<p>Other sites are:</p>
<ul>
<li><a href="http://w... | <p><a href="http://rememberthemilk.com" rel="nofollow noreferrer">Remember The Milk</a></p>
| 24,684 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.