input
stringlengths
51
42.3k
output
stringlengths
18
55k
Django - uploaded images can not be retrieved <p>I am exploring file/images uploads in Django. I have a model with Photo class which has thumb ImageField. I uploaded thumb with admin panel and I made template which just gives <code>&lt;img src='{{photo.thumb.url}}' /&gt;</code>. Unfortunately I don't get any images and...
<p>The development server by default doesn't serve static files (see the <a href="http://docs.djangoproject.com/en/dev/howto/static-files/?from=olddocs">documentation</a>). You'll need to add the following code to the bottom of your <code>urls.py</code> to enable static file serving:</p> <pre><code>from django.conf im...
Alter all values in a Python list of lists? <p>Let's say I have a list like:</p> <pre><code>my_list = [[1,2,3],[4,5,6],[7,8,9]] </code></pre> <p>How do I alter every value in the list without doing?:</p> <pre><code>for x in range(0, 3): for y in range(0, 3): my_list[x][y] = -my_list[x][y] </code></pre> ...
<p>Another option is to use the built-in <code>map</code> function:</p> <pre><code>&gt;&gt;&gt; my_list = [[1,2,3],[4,5,6],[7,8,9]] &gt;&gt;&gt; neg = lambda x: -x &gt;&gt;&gt; f = lambda x: map(neg, x) &gt;&gt;&gt; map(f, my_list) [[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]] </code></pre>
asp.net designer how to get the designed page type <p>I want to find out inside a webcontrol the real type of the page that is designed in Visual Studio 2008.</p> <p>I can obtain the WebFormsRootDesigner, and somehow i know it is possible to get the</p> <p>file path of the aspx page.</p> <p>I would like rather to ge...
<p>That's a really bad design. It's always bad to have the "inner" behave differently based on the "outer", or the "child" to be based on the "parent".</p> <p>Instead, have the page tell the control how to behave, by setting a property. Different pages will tell the same control to behave in different ways. This way, ...
IoC/DI framworks with Smart Client Winform apps: How should I approach this? <p>I'm starting a new Winforms app, and I intend to use an IoC/DI framework (probably Ninject, but i'm also thinking about StructureMap and LinFu).</p> <p>It seems like nearly everyone who is using IoC/DI is doing so in a web based environmen...
<p>The Microsoft patterns and practices team which maintains the <a href="http://www.codeplex.com/unity">Unity</a> injection container also created the <a href="http://msdn.microsoft.com/en-us/library/aa480450.aspx">Smart Client - Composite UI Application Block</a> for winforms, which I believe uses Unity. I know the ...
How to assign byte[] as a pointer in C# <p>I have a function that generates a CRC check byte based on the content of any packet.The problem is in translating the function from C++ to C#</p> <p>C++ code:</p> <pre><code>unsigned char GenerateCheckByte( char* packet, int length, unsigned long seed ) { if( !packet ) retu...
<p>You could make the method accept a byte array:</p> <pre><code>public static unsafe byte GenerateCheckByte(byte[] packetArray, int length, UInt32 seed) { fixed(byte *packet = packetArray) { ... etc } } </code></pre> <p>It's better to keep the unsafe stuff hidden away as much as possible behind m...
MySql Insert doesn't work when the website deployed on the host! <p>I'm using XAPP under windows and my website just working well!</p> <p>when I deployed it on the host server, it seems to be working normally, but the insert requests to MySql doesn't have any effect, nothing is changing on the database!</p> <p>Does a...
<p>check the permissions on the database server for the username and password that you are using. It can also be restricted by IP address, among others.</p>
Create Random Number Sequence with No Repeats <h3>Duplicate:</h3> <blockquote> <p><a href="http://stackoverflow.com/questions/196017/unique-random-numbers-in-o1">Unique random numbers in O(1)?</a></p> </blockquote> <p>I want an pseudo random number generator that can generate numbers with no repeats in a random ord...
<p>You may be interested in a linear feedback shift register. We used to build these out of hardware, but I've also done them in software. It uses a shift register with some of the bits xor'ed and fed back to the input, and if you pick just the right "taps" you can get a sequence that's as long as the register size. T...
Passing a function object: Error <p>What's wrong with the following little program that passes a function object?</p> <pre><code>#include &lt;iostream&gt; #include &lt;functional&gt; void foo(const std::unary_function&lt;const std::string&amp;, void&gt;&amp; fct) { const std::string str = "test"; fct(str); // err...
<p>A common mistake. <code>unary_function</code> and <code>binary_function</code> are just two structs that add typedefs</p> <pre><code>argument_type result_type </code></pre> <p>and respectively</p> <pre><code>first_argument_type second_argument_type result_type </code></pre> <p>Not more. They are for convenience ...
SIlverlight VSM State change to target items in ItemsControl <p>I have an ItemsControl with Items being added through databinding to an observable collection. Each item has a data template that defines its look. </p> <p>I am trying to figure out if it is possible to apply/trigger animations to/on each of the Items in ...
<p>This is possible using a ObjectAnimationUsingKeyFrames, however it's stupidly hard to do, will cause you to rip your hair out, crash your visual studio regularly and gives you very little over doing it the simple way.</p> <p>The simple way:</p> <pre><code>public class TestSwapContentControl : ContentControl { ...
why doesn't subprocess.Popen(...) always return? <p>I hope this is a simple python question.</p> <p>When I try the following in the python interpreter:</p> <pre><code>&gt;&gt;&gt; import process &gt;&gt;&gt; def test(cmd): ... p = subprocess.Popen(cmd) ... &gt;&gt;&gt; test(['ls', '-l']) </code></pre> <p>It will r...
<p>In the first variation, <code>test()</code> returns immediately after starting the process, but before its output is sent to the console.</p> <p>If you look at the output you <em>do</em> get the prompt, immediately before the output of <code>ls</code>. </p> <pre><code>&gt;&gt;&gt; test(['ls', '-l']) &gt;&gt;&gt; t...
Vista Recycle Bin Maximum Size <p>Does anyone know how to set the Maximum Size of the Recycle Bin via script? Whether its written in batch or vbs or just a reg file? I've been exploring this idea for the last few days, and can't get an answer. Maybe someone here knows how. I'm wanting to add it to my Vista Cleanup Scri...
<p>The maximum size of the Recycle Bin for each drive is stored under this key:</p> <pre><code>HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\Volume\ </code></pre> <p>There's a subkey with the GUID of each mounted volume. This GUID can be found with the MOUNTVOL command, or programmatically with Ge...
screencasts like dimecasts.net for spring framework <p>Does anybody know of a series of screencasts for spring framework like on this webpage www.dimecasts.net</p>
<p>Try <a href="http://www.parleys.com/display/PARLEYS/Home" rel="nofollow">http://www.parleys.com/display/PARLEYS/Home</a> </p>
How do I read JPEG and PNG pixels in C++ on Linux? <p>I'm doing some image processing, and I'd like to individually read each pixel value in a JPEG and PNG images.</p> <p>In my deployment scenario, it would be awkward for me to use a 3rd party library (as I have restricted access on the target computer), but I'm assum...
<p>This is a small routine I digged from 10 year old source code (using libjpeg):</p> <pre><code>#include &lt;jpeglib.h&gt; int loadJpg(const char* Name) { unsigned char a, r, g, b; int width, height; struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; FILE * infile; /* source file */ ...
Gray NSTableView à la iTunes <p>How can I achieve the dark gray <code>NSTableView</code> look (used in iTunes, Delicious Library, etc.) in my own application?</p> <p><img src="http://i41.tinypic.com/nvcmmr.png" alt="iTunes NSTableHeaderView" /></p> <p>I always thought this was an option in <code>NSTableView</code> (...
<p>A good friend of mine created a whole control kit called <a href="http://binarymethod.com/" rel="nofollow">BGHUDAppKit</a>. It's for the new HUD stuff that Apple introduced a while ago. I believe his controls are themable, and they come with source. I personally haven't done anything with Cocoa, but he has and I kno...
Calendar Syncronization in Android Application <p>I am working on project a in which i have to sync my program with google <code>Calendar</code> using Android application.</p> <p>for that i am using <code>eclipse</code> and i got some code online but i dont know wht .jar file i need to add for support below importss.....
<p>com.google.android.gdata and com.google.wireless are not part of the public SDK so you won't be able to use them.</p> <p>I haven't tried to use the gdata-java-client library on android yet, but you should see if you can download it and include it in your project and see if you can compile and run it on android.</p>...
Hanging VBScript on query <p>I inherited a piece of code from a recently-retired colleague that gets the total physical memory on a box and, when I perform the following on Windows XP and Server 2003, it works fine:</p> <pre><code>memSize = 0 set colItems = wmi.execQuery("select * from Win32_LogicalMemoryConfiguration...
<p>The <code>Win32_LogicalMemoryConfiguration</code> class has been deprecated. Try the <a href="http://msdn.microsoft.com/en-us/library/aa394239%28VS.85%29.aspx" rel="nofollow">Win32_OperatingSystem</a> class instead. It should give the proper results on Server 2008.</p> <p>I believe the property you're interested in...
String with Double quoted and Single quoted <p>i have a string with double quote like this</p> <pre><code>$count = 5; $str = "result: $count"; echo $str; //result: 5 </code></pre> <p>variable parsing work well, and my problem is $count var must be define later than $str </p> <pre><code>$str = "result: $count"; $coun...
<p>For this type of thing, I'd probably use string formatting. In PHP, that'd be <a href="http://us.php.net/sprintf" rel="nofollow">printf</a>.</p> <pre><code> ?php $str="result: %d" ....dostuff.....define $count..... printf($str,$count) ? </code></pre> <p>edit: although, the best way to do this probably depends part...
linq aggregate <pre><code>class Category { public string Name { get; set; } public int Count { get; set;} } Name Count AA 2 BB 3 AA 4 </code></pre> <p>I have an <code>IEnumerable&lt;Category&gt;</code></p> <p>and would like to get a list of Categories with unique names and the sum of multiple ...
<p>Your updated question isn't entirely clear in terms of the phone number, but I suspect you want something like:</p> <pre><code> var query = from category in list group category by category.Name into grouped select new { Name = grouped.Key, SumA = group...
what is the difference b/w Layer and Tier? <p><strong>Duplicate</strong>: <a href="http://stackoverflow.com/questions/120438/whats-the-difference-between-layers-and-tiers">What’s the difference between “Layers” and “Tiers”?</a></p> <p>HI , i am having confusion about these two terms what does these two terms...
<p>Sometimes people use them interchangeably but in my mind a layer is a logical separation (GUI, data access, business logic etc)and a tier is a physical separation (separate servers...ie web server, database server etc).</p> <p>See the entries in Wikipedia: <a href="http://en.wikipedia.org/wiki/Multitier%5Farchitect...
How do you implement simple website redirects? <p>If you go to <a href="http://www.codinghorror.com" rel="nofollow">www.codinghorror.com</a>, it is automatically redirected to <a href="http://www.codinghorror.com/blog" rel="nofollow">www.codinghorror.com/blog</a></p> <p>How does one re-direct to the "/blog/"?</p> <p>...
<p>This would be a good opportunity to teach yourself about HTTP status codes. Read the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10">status code definitions section</a> of the HTTP 1.1 spec; section 10.3, "Redirection 3xx," covers the status codes pertinent to your question. Knowing the HTTP ...
Hacking/cracking deontology <p>Let's say you recently discovered some major vulnerabilities in a couple of websites that activate mainly in your country and are very powerful in their market. The vulnerabilities I'm talking about are as worse as letting me browse the admin interface with super admin privileges.</p> <p...
<p><strong>Talk. To. A. Lawyer.</strong></p> <p>This could get sticky depending on the company. By saying "you have xx days to fix this before I announce the exploit", you are basically saying "do what I expect, or I will cause you lots of grief".</p> <p>The other issue is, how did you discover this? Were you using t...
IP adresses of B Class: broadcast <p>Are the following IP adresses - 168.94.254.255 &amp; 168.94.255.254 - used for broadcast, if they belong to B Class? (The adresses were randomly chosen). I suppose 168.94.255.255 would rather be a broadcast adress, but I'm not sure. Thanks in advance!</p>
<p>A class B network in CIDR notation is a /16 network. A broadcast address is where all of the host bits are 1. In your case, the last 16 bits would need to be 1 to be a broadcast address.</p> <p>168.94.254.255 and 168.94.255.254 each have a zero bit in the last 16 bits, so they are not broadcast addresses.</p> <p>I...
Using WatiN, how can I access the head part of the page, specifically the meta tags? <p>WatIn provides great functionality for programmatic access to the displayed parts of a Web page.</p> <p>I want to access the head part of the page, spedifically the META tags. Watin allows me access to the TITLE, but AFAICT nothin...
<p>This will give you a collection of meta tags in your page.</p> <p>Syntax in WatiN 2.0 beta 1:</p> <pre><code>var metaTags = browser.ElementsWithTag("meta"); </code></pre> <p>Syntax in WatiN 2.0 CTPs and earlier:</p> <pre><code>var metaTags = browser.Elements.Filter(Find.By("tagName", "META")); </code></pre> <p...
Date range from weeknumber + year <p>I have 2 dropdowns 1 with weeknumbers 1 with years. I want to extract the date range from this data. </p> <p>So:</p> <p>Weeknumber 13 year 2009 would give:</p> <p>monday 23 march 2009 tuesday 24 march 2009 ...</p> <p>VB.Net preferred but C# sollution is also ok. </p> <p>Edit:...
<pre><code>CultureInfo curCulture = CultureInfo.CurrentCulture; DateTime targetDate = curCulture.Calendar.AddWeeks(new DateTime([year], 1, 1), [Week]); DayOfWeek targetWeekDay = curCulture.Calendar.GetDayOfWeek(targetDate); DateTime targetBeginningOfWeek = targetDate.AddDays(-1*Convert.ToInt16(targetWeekDay)); <...
C# 3 dimensional array definition issue <p>My following code has compile error,</p> <p>Error 1 Cannot implicitly convert type 'TestArray1.Foo[<em>,</em>,*]' to 'TestArray1.Foo[][][]' C:\Users\lma\Documents\Visual Studio 2008\Projects\TestArray1\TestArray1\Program.cs 17 30 TestArray1</p> <p>Does anyone have any idea...
<p>Regarding version 2 of your code - unfortunately you can't specify jagged arrays in that way. Instead, you need to do:</p> <pre><code>Foo[][][] foos = new Foo[1][][]; foos[0] = new Foo[1][]; foos[0][0] = new Foo[1]; </code></pre> <p>You have to populate each array separately, basically. <code>Foo[][][]</code> mean...
How is it possible that kill -9 for a process on Linux has no effect? <p>I'm writing a plugin to highlight text strings automatically as you visit a web site. It's like the highlight search results but automatic and for many words; it could be used for people with allergies to make words really stand out, for example, ...
<p>As noted in comments to the OP, a process status (<code>STAT</code>) of <code>D</code> indicates that the process is in an "uninterruptible sleep" state. In real-world terms, this generally means that it's waiting on I/O and can't/won't do anything - including dying - until that I/O operation completes.</p> <p>Pro...
Why is "Set as Startup" option stored in the suo file and not the sln file? <p>It seems like this setting should be stored in the solution file so it's shared across all users and part of source code control. Since we don't check in the suo file, each user has to set this separately which seems strange.</p>
<p>It is absolutely necessary that everyone can define their StartUp Project themselves, as <a href="http://stackoverflow.com/a/694742">Jon has already said</a>. But to have a dedicated default one would be great, and as I can tell, it is possible!</p> <p><strong>If you don’t have a .suo file in your solution direct...
how do you copy an CALayer? <p>How to you make an NSArray full of multiple instances of a CALayer (all with the same frame, contents etc)?</p> <p>Background: CALayer takes a bit of overhead to create, so I would like to create a number of CALayers (all sharing the same properties) in the init method of a class (to be ...
<p>I haven't tried this with <code>CALayer</code> specifically, but I know you can perform a deep-copy by taking advantage of <code>NSCoding</code>:</p> <p><code>CALayer *layer = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:layer]];</code></p> <p>I'm not sure how copying them...
APC for windows alternative download <p>I am trying to install APC on windows but the site <a href="http://pecl4win.php.net/" rel="nofollow">http://pecl4win.php.net/</a> is down for a while now with the message:</p> <blockquote> <p>The pecl4win build box is temporarily out of service. We're preparing a new build sys...
<p><strong>Update:</strong></p> <p>My answer below is outdated, and the <code>pierre</code> folder seems to be offline. You can now use <a href="https://pecl.php.net/packages.php" rel="nofollow">PECL :: Package Browser</a>, for example: <a href="https://pecl.php.net/package/APC" rel="nofollow">PECL :: Package :: APC</...
Screen capture and event with Vista UAC <p>I'ved developed a c# application that captures screens using bitblt and sends keyboard and mouse events using calls to keybd_event and mouse_event.</p> <p>According to Microsoft I needed to modify the app.manifest with: requestedExecutionLevel level="highestAvailable" uiA...
<p>UAC runs on the secure desktop, only trusted processes running on the system account are allowed to run in that context.</p> <p>This is to prevent exactly what you are trying to achieve - processes spoofing or capturing user input.</p>
What is the format of /dev/input/by-path/pci-xxx-kbd output? <p>after doing</p> <pre><code>$ cat /dev/input/by-path/pci-0000:00:02.0-usb-0:2:1.0-event-kbd &gt; ~/test_kbd </code></pre> <p>as root, I got a bunch of binary codes (which was expected). Now, I wanted to know how can I interpret this binary code to figure...
<p>I would guess that they are scan codes. <a href="http://www.computer-engineering.org/ps2keyboard/scancodes2.html" rel="nofollow">This page</a> lists the make and break codes of keys used by modern keyboards. For more information on PS/2 keyboard programming, see <a href="http://www.computer-engineering.org/index.h...
Help with Python loop weirdness? <p>I'm learning Python as my second programming language (my first real one if you don't count HTML/CSS/Javascript). I'm trying to build something useful as my first real application - an IRC bot that alerts people via SMS when certain things happen in the channel. Per a request by so...
<p>If this is a regular CSV file you should not try to parse it yourself. Use the standard library <a href="http://docs.python.org/library/csv.html" rel="nofollow">csv module</a>.</p> <p>Here is a short example from the docs:</p> <pre><code>import csv reader = csv.reader(open("some.csv", "rb")) for row in reader: ...
How do I add a property to a JavaScript Object using a variable as the name? <p>I'm pulling items out of the DOM with jQuery and want to set a property on an object using the id of the DOM element. For example:</p> <pre><code>obj = {}; jQuery(itemsFromDom).each(function() { element = jQuery(this); name = element.a...
<p>You can use this equivalent syntax:</p> <pre><code>obj[name] = value; </code></pre>
How do I rotate an image? <blockquote> <p>See also: <a href="http://stackoverflow.com/questions/697520/why-is-my-image-rotation-algorithm-not-working">Why is my image rotation algorithm not working?</a></p> </blockquote> <p>This question isn't language specific, and is a math problem. I will however use some C++ cod...
<p>The usual way to solve this is by doing it backwards. Instead of calculating where each pixel in the input image ends up in the output image, you calculate where each pixel in the output image is located in the input image (by rotationg the same amount <b>in the other direction</b>. This way you can be sure that all...
two tone background in html? <p>So I want to make the background of my website two tone. What I mean is have a dark gray in the center, going all the way down, but then have a lighter gray on just the sides. Maybe 80-85% of the pages width. Do would I go about doing this?</p> <p>So what I want is the middle to be on...
<p>You'd be much better off using a background image, mate; assuming you know your target audience's primary monitor size, you could just make, say, a 1024x1 image with the parameters you require. If, however (and this is more likely the case), you are trying to get this to be dynamic, why not just use a <code>div</cod...
How to return a part of an array in Ruby? <p>With a list in Python I can return a part of it using the following code:</p> <pre><code>foo = [1,2,3,4,5,6] bar = [10,20,30,40,50,60] half = len(foo) / 2 foobar = foo[:half] + bar[half:] </code></pre> <p>Since Ruby does everything in arrays I wonder if there is something ...
<p>Yes, Ruby has very similar array-slicing syntax to Python. Here is the <code>ri</code> documentation for the array index method:</p> <pre><code>--------------------------------------------------------------- Array#[] array[index] -&gt; obj or nil array[start, length] -&gt; an_ar...
ASP.NET: Managing Users and Roles (CMS, Portal, etc?) <p>I am not sure how to phrase a good question, so I will just say what I am after!</p> <p>I have to retool a web application for our vendors and part of that requires restricting content on a vendor by vendor basis. Looking at ASP.NET (MVC) this seems easy enough...
<p>ASP.NET provides extensive membership and role management APIs that are pretty easy to work with since version 2.0. They are available in ASP.NET MVC. Probably they do not require much more work than you would do anyway for styling or other stuff. But since you don't want to do it anyway, you can use a simple Web fo...
Running Ant with JDK 1.6 on Mac OS X <p>I am having a problem running Ant with JDK 1.6 on Mac OS X. Even though Java application versions is set to Java SE 6 in OS X's Java Preference, executing <code>java -version</code> in Terminal also shows <code>java version "1.6.0_07"</code>, Ant still seems to use JDK 1.5 to be ...
<p>The JAVA_HOME environment variable is set in your home directory's .profile file. (/Users/ejel/.profile ?) Edit it and set it to what you want it to be. E.g.:</p> <pre><code>export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home </code></pre> <p>From this point onward, every time you open ...
Why does TCP work, when UDP does not? <p>The code:</p> <pre><code>&lt;?php error_reporting(E_ALL); /* Allow the script to hang around waiting for connections. */ set_time_limit(0); /* Turn on implicit output flushing so we see what we're getting * as it comes in. */ ob_implicit_flush(); $address = '127.0.0.1'; $po...
<p>Because TCP is connection oriented and UDP is not, and there are different APIs for UDP sockets. Have a look at <a href="http://www.php.net/manual/en/function.socket-recvfrom.php" rel="nofollow">socket_recvfrom</a> and <a href="http://www.php.net/manual/en/function.socket-sendto.php" rel="nofollow">socket_sendto</a>...
What is LLVM and How is replacing Python VM with LLVM increasing speeds 5x? <p>Google is sponsoring an Open Source project to increase the speed of Python by 5x.</p> <p><a href="http://code.google.com/p/unladen-swallow/">Unladen-Swallow</a> seems to have a <a href="http://code.google.com/p/unladen-swallow/wiki/Project...
<p><a href="http://llvm.org/">LLVM</a> is several things together - kind of a virtual machine/optimizing compiler, combined with different frontends that take the input in a particular language and output the result in an intermediate language. This intermediate output can be run with the virtual machine, or can be use...
Mature standard library for C <p>I'm looking for a library for C that gives me at least some of the things I really miss from C++ and the STL/Boost. (I have to use C, so please no "use C++" posts)</p> <p>I need</p> <ol> <li>dynamic strings (that grow and shrink automatically)</li> <li>some sort of list (std::vector r...
<p>What about the <a href="http://library.gnome.org/devel/glib/" rel="nofollow">GLib</a> from GTK?</p>
Getting started with Web Services <p>I want to start developing some web services, I've had some courses that talked about them and read about them on my own. However I can't seem to know exactly where or how to begin with them. I mean, I've done some tutorials and the excercises from class but that still left me kind ...
<p>I think that <a href="http://cxf.apache.org/" rel="nofollow">CXF</a> makes the developement of a webservice really easy.</p>
Using the repository pattern with Entity Framework (mvc storefront) <p>Can anyone give a helping hand? I've been watching the videos for the MVC storefront and have created my own website using these techniques i.e. DDD, Repository pattern but I wish to use Entity Framework.</p> <p>In the Interfaces it returns IQuerya...
<p>Let me answer your questions one at a time:</p> <p>Your repositories <em>should</em> return IQueryable&lt;T&gt;, <em>not</em> ObjectQuery. The reason is that the whole purpose of the repository pattern is to abstract away the specifics of your data store. This allows you to do things like substitute a mock reposito...
Why do I have to define LD_LIBRARY_PATH with an export every time I run my application? <p>I have some code that uses some shared libraries (c code on gcc). When compiling I have to explicitly define the include and library directories using -I and -L, since they aren't in the standard places. When I try to run the cod...
<p>You should avoid setting <code>LD_LIBRARY_PATH</code> in your <code>.bashrc</code>. See <a href="http://xahlee.info/UnixResource_dir/_/ldpath.html">"<code>Why LD_LIBRARY_PATH is bad</code>"</a> for more information.</p> <p>Use the linker option <a href="http://sourceware.org/binutils/docs-2.22/ld/Options.html#Opti...
Make multiple monitors go to sleep with Windows API? <p>How exactly would I make both of my monitors go to sleep, I want to write an application myself because I'd like to add certain functionality, and so far I can't find anything on MSDN relating to making your display go to sleep.</p>
<p>You want something like:</p> <p>SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2);</p> <p>It should work on dual monitors.</p> <p>Although it <a href="http://blogs.msdn.com/oldnewthing/archive/2006/06/13/629451.aspx" rel="nofollow">might be best not to use HWND_BROADCAST, but instead to use ...
How can I perform a command line uninstall of Firebird? <p>I've used the command-line switches for installing a Firebird database from within the install package for my application. But now I'd like to uninstall Firebird in the same way. </p> <p>The problem is that the Windows install executable for Firebird was built...
<p>HKLM\Software\Microsoft\Windows\Currentversion\Uninstall\ with example like {350C97B0-3D7C-4EE8-BAA9-00BCB3D54227} Under that you will find a key named "UninstallString" you should be able to just execute that and uninstall.</p> <p>Some programs are listed by name and not GUID as well so double check</p>
Best method of post processing Nginx reverse proxy response <p>I'm doing some researching on switching from Apache to Nginx as a reverse proxy in front of a Grails application on the backend. I'm playing around with some URL rewriting and have run into an issue with the response being sent back from my back end. I can ...
<p>You can use the Lua module to capture the response and manipulate it like a Lua string. Silly example to upper case the output:</p> <pre><code>res = ngx.location.capture('/some/path') ngx.print(string.upper(res.body)) </code></pre> <p>see <a href="http://wiki.nginx.org/HttpLuaModule#ngx.location.capture" rel="nofo...
UITableView scrolls to far and causes weird things <p>I have a UITableView that when scrolled to far bounces bag. This also means the user can drag the table so that only half of it is visible and the other half of the main view is white. This causes some weird behavior in my app. I create an array in the AppDelegat...
<p>This is on the device but looks as though I've figured it out.</p> <p>In didSelectRowAtIndexPath of RootViewController, I get one of the objects out of delegate.thearray. Just before 2nd View is pushed, I release this object. That's wrong since I didn't alloc the object. Removed that line and no more weirdness i...
How to access the Description attribute on either a property or a const in C#? <p>How do you access the Description property on either a const or a property, i.e.,</p> <pre><code>public static class Group { [Description( "Specified parent-child relationship already exists." )] public const int ParentChildRela...
<p>Try the following</p> <pre><code>var property = typeof(Group).GetProperty("UserExistsInGroup"); var attribute = property.GetCustomAttributes(typeof(DescriptionAttribute), true)[0]; var description = (DescriptionAttribute)attribute; var text = description.Description; </code></pre>
Existing tool or code to identify quoted text in emails <p>I am looking for a way to identify quoted text in emails. The goal is to add something along the lines of Gmails "show quoted text" feature to my web app which involves a mail handler bot.</p> <p>There are similar questions on stackoverflow, but they are askin...
<p>Just following up on an email I received regarding this question.</p> <p>Sup has a pretty easy to understand/extract/translate bit of logic for accomplishing this. I ported the relevant functions to Python and tweaked it for my purposes.</p> <p>Sup is terminal-based mail client written in Ruby: <a href="http://sup...
c++ exit loop based on keyboard input <p>Is it possible to exit a C++ loop based on keyboard input without actually having to input something each iteration?</p> <p>For instance</p> <pre><code>while(checkkeyboardinput != 'q') { do work } </code></pre> <p>I feel that this is very easy, but google isn't hel...
<p>Try _kbhit(). As far as I know it checks if there is any keyboard input waiting in the buffer.</p> <p><a href="http://msdn.microsoft.com/en-us/library/58w7c94c%28VS.80%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/58w7c94c%28VS.80%29.aspx</a></p> <blockquote> <p>_kbhit </p> <p>Checks the c...
Is there a way other than with JS to accomplish table row highlighting with CSS in IE? <p>I'd like to add row highlighting on hover using on CSS that will work in Internet Explorer. I have tried the following:</p> <pre><code>#tableId tr:hover td { background-color:#f00; } </code></pre> <p>This seems to work in Opera,...
<p>Some versions of IE (specifically, IE6, though :hover is buggy in IE7) do not support :hover, which means there's simply no way to accomplish row highlighting without JavaScript.</p> <p>Just to be technically correct - IE6 does support :hover, but only on anchor tags, so you can't target table rows.</p>
How do I declare class-level properties in Objective-C? <p>Maybe this is obvious, but I don't know how to declare class properties in Objective-C.</p> <p>I need to cache per-class a dictionary and wonder how put it in the class.</p>
<p>properties have a specific meaning in Objective-C, but I think you mean something that's equivalent to a static variable? E.g. only one instance for all types of Foo?</p> <p>To declare class functions in Objective-C you use the + prefix instead of - so your implementation would look something like:</p> <pre><code>...
RouteTable.Routes RouteCollection? <p>The example I see everywhere for MVC-style routing is something like this:</p> <pre><code>void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); } public static void RegisterRoutes(RouteCollection routes) { routes.Add(new Route ( ...
<p>Unit testing.</p> <p>By decoupling (through argument passing) registration from RouteTable.Routes you can choose which RouteCollection is used for registration in unit testing.</p> <p>IMHO, it's also nicer to write routes.Add() instead of RouteTable.Routes.Add() everywhere.</p> <p>"Is there a reason that Map() sh...
Should we create objects if we need them only once in our code? <p>This is a coding style questions:-</p> <p>Here is the case</p> <pre><code>Dim obj1 as new ClassA ' Some lines of code which does not uses obj1 Something.Pass(obj1) ' Only line we are using obj1 </code></pre> <p>Or should we directly initiaize the o...
<p>If you're only using the object in that method call, it's probably better to just pass in "new ClassA()" directly into the call. This way, you won't have an extra variable lying around, that someone might mistakenly try to use in the future.</p> <p>However, for readability, and debugging it's often useful to creat...
Java Keylistener without window being open? <p>I'm trying to create an auto-clicker in Java(only language I know and I just learned Threads). I want to have the applet open in it's own window(not on a webpage), and I want to be able to start and stop the program with the spacebar without the window being selected so th...
<p>Late answer but hopefully helpful :)</p> <p>You can using JNA, it's a cakewalk!!</p> <ol> <li>get JNA (jna.jar)</li> <li><p>create your own mapping for User32 (User32.dll) in the form</p> <pre> public interface User32 extends StdCallLibrary { User32 INSTANCE = (User32) Native.loadLibrary("User32", User32.class, ...
What's the best tool for generating a parser in Java for my own language grammar? <p>I'm developing a small programming language based mostly of the C99 standard and I've already written a fairly decent lexer in java and now I'm looking to generate a Java Parser from the grammar. I know there's <a href="http://www.gnu....
<p>Another couple to look at are <a href="https://javacc.dev.java.net/" rel="nofollow">JavaCC</a> and <a href="http://sablecc.org/" rel="nofollow">SableCC</a> (it has been a long time since I looked at SableCC).</p>
Create if an entry doesn't exist, otherwise update? <p>Kinda strange to put it into words that short, heh.</p> <p>Anyway, what I want is basically to update an entry in a table if it does exist, otherwise to create a new one filling it with the same data.</p> <p>I know that's easy, but I'm relatively new to MySQL in ...
<p>A lot of developers still execute a query to check if a field is present in a table and then execute an insert or update query according to the result of the first query. Try using the ON DUPLICATE KEY syntax, this is a lot faster and better then executing 2 queries. More info can be found <a href="http://dev.mysql....
What's the PostgreSQL equivalent of MSSQL's CONTEXT_INFO? <p>In relation to my other question <a href="http://stackoverflow.com/questions/695817/whats-the-best-way-to-audit-log-deletes">"What’s the best way to audit log DELETEs?"</a>. What's the PostgreSQL equivalent of CONTEXT_INFO?</p> <p>[EDIT]</p> <p>I want to...
<p><a href="http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks_II#Any_other_session_variables" rel="nofollow">http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks_II#Any_other_session_variables</a></p> <p>PostgreSQL provides more variants, please, look to this site.</p>
To use OpenID or not to use? <p>I'm new to this site but I've read the rules and also searched the questions section but not found any related question answered well.<br /> anyway, the question: what's the Pros. &amp; Cons. of using OpenID on a website instead of a regular login system? My customer wants me to use thi...
<p>OpenId is implemented by Stackoverflow. Since you just signed up you may have experienced the benefits yourself.</p> <p>Basically, it can be used to allow users to log into the website without creating an account or sending you any of their personal information. As long as they have an account with an OpenId provid...
jQuery portlet and dialog box problem <p>I create sortable element and attach an on-click event on every portlet to open dialog box, but when i open (drag more portlet to the main dashboard), and click the setup link (on the header of the portlet) the alert() (i setup for testing purpose) always fire for every portlet ...
<p>I'm not really sure I totally understand your problem, but, what I think you are trying to say is that when you drag a portlet, it's supposed to be binding a click event listener to the 'setup' (wrench) button on your portlet so that when it's clicked a dialog pops up. And, you are saying that when you click on that...
Updating MySQL TIMESTAMP field using time()? <p>Here is the table of interest when exported via phpMyAdmin:</p> <pre><code>CREATE TABLE IF NOT EXISTS `users` ( `ip` varchar(20) NOT NULL, `lastcheck` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, UNIQUE KEY `ip` (`ip`) ) ENGINE=MyISAM D...
<p>I am not sure if maybe I understand your problem, looking at column lastcheck declaration CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP that means when ever you update (ip = '$uip') this column an automatic date update will also happen lastcheck. Which mean you can write you update statment as follows :</p> <pre><c...
Overloading C++ STL methods <p>How can I overload the STL implementation for methods like find, erase and insert to take varying parameters? I tried to look up the overloading of STL methods but couldn't find any help.</p>
<p>You can't overload the methods of a class without editing the code of that class.</p> <p>Write your own free functions that act as helpers; they would take the relevant container class as the first parameter.</p> <p>You can inherit from a class and add methods that way, but the std container classes are not design...
Avoiding parallel inheritance hierarchies <p>I have two parallel inheritance chains:</p> <pre><code>Vehicle &lt;- Car &lt;- Truck &lt;- etc. VehicleXMLFormatter &lt;- CarXMLFormatter &lt;- TruckXMLFormatter &lt;- etc. </code></pre> <p>My experience has been that parallel inheritance hiera...
<p>I am thinking of using the Visitor pattern.</p> <pre><code>public class Car : Vehicle { public void Accept( IVehicleFormatter v ) { v.Visit (this); } } public class Truck : Vehicle { public void Accept( IVehicleFormatter v ) { v.Visit (this); } } public interface IVehicleFormatter ...
Accessing data member of RootViewController in another class <p>I am developing an iPhone application using Objective-C. I want to access a data member which is of type NSMutableArray of the RootViewController class in another class. I tried making the array static. But I would like to have a non static array. How do I...
<p>You need two things:</p> <ol> <li>a reference to the <code>RootViewController</code></li> <li>a means of getting your variable out of <code>RootViewController</code>.</li> </ol> <p>In a situation where you have (most likely) one <code>RootViewController</code> per application, it makes sense to keep a reference to...
what is tunnelling (ssh tunneling and ppp tunneling) <p>what is tunnelling (ssh tunneling and ppp tunneling)? I searched in google but it is confusing.. can anyone provide some good material on this tunneling topic?</p>
<p>Well, basically you have 3 machines:</p> <ul> <li><strong>A</strong> your machine</li> <li><strong>B</strong> server</li> <li><strong>C</strong> remote machine</li> </ul> <p>Basic tunnel would be any communication on port X of <strong>A</strong> gets forwarded to port Y of <strong>C</strong> by <strong>B</strong>....
For loop with onRollOver problem <p>I can't get this For loop with onRollOver to work.</p> <pre><code>for (var i:Number = 1; i&lt;=4; i++) { this['videobutton'+i].onRollOver = function() { trace(i); this['stream'+i].pause(false); this['video'+i].attachVideo(this['stream'+i]); fadeIn(this['video'+i]); }...
<p>I haven't done anything with Flash before, but it looks like the variable <code>i</code> is being <a href="http://en.wikipedia.org/wiki/Closure%5F%28computer%5Fscience%29" rel="nofollow">closed over</a>. The code inside the rollover handler is only executed on rollover, and <code>i</code> is evaluated at that time;...
Getting a dump of a process that crashes on startup <p>On a customer machine (WinXP SP2) to which I have no access, I have a Win32 EXE (unmanaged C++) that crashes on startup. I guess the best way to troubleshoot this is to obtain a (mini-)dump and analyze it later with windbg or similar.</p> <p>Now, I would normally ...
<p>Alternatively you may set up your own dump generation framework which automatically creates a process dump when any Unhandled exception is encountered. This would avoid clients having to install Windbg.</p> <p>Use SetUnhandledExceptionFilter Win32 API to register the application level exception handler at the appli...
Macbook Security Alarm Task <p>I intend to put my macbook on my landing/hallway for when the people downstairs come up to rummage through my bedroom/rooms, such that when an intruder is detected a set of scripted events occur, such as a countdown from 10 followed by very loud music, but the existing software is either ...
<p>You should check out <a href="http://sourceforge.net/projects/opencvlibrary/" rel="nofollow">OpenCV</a>.</p> <p>It is for C++ though, I am not sure if there is a version for Java. </p> <p>It is the best API to handle webcams. If you can switch to C++ to use it then I would strongly suggest you do that.</p>
Are Enterprise Java Beans still useful when compared to Spring? <p>I have an upcoming project in a class that will allow me to work with either EJBs or Spring, and I was wondering what would be more applicable for "real world" situations.</p>
<p>The two technologies aren't mutually exclusive. And when you say EJBs it depends on if you're talking about session beans or entity beans (or message driven beans for completeness).</p> <p>Stateless session beans are and always have been quite useful if for no other reason than they provide a reasonably consistent ...
Default fields available in a Search Server web content source? <p>I'm using the search web service on a Search Server 2008 Express install in a web application.</p> <p>I have created the content source and scope and can successfully query the web service if I specify the fields I wish to return.</p> <p>What I cannot...
<p>There are some good tools available to help you debug this, here are some suggestion:</p> <ol> <li>My <a href="http://www.codeplex.com/MOSSSearchCoder" rel="nofollow">SearchCoder</a> will help you right SQL Correctly</li> <li>The <a href="http://sharepointsearchserv.codeplex.com/" rel="nofollow">Search Service tool...
Opportunities to use Func<> to improve code readability <p>Today I finally "got" the <a href="http://msdn.microsoft.com/en-us/library/bb549151.aspx" rel="nofollow"><code>Func&lt;&gt;</code></a> delegate and saw how I could use it to make some of my less readable LINQ queries (hopefully) more readable.</p> <p>Here's a ...
<p>I guess there would only be a point in doing this if you were going to be reusing the Func in question in a number of places (and it involved more than trivial logic). Otherwise using the standard way seems much better and perfectly readable.</p>
How can I control the lifetime of an email (time of transmission) with PHP Simple Mail? <p>I am using Simple Mail from PHP. Now I have the intention of knowing the life time of an email.</p> <p>If a user wishes to send email one day after submitting the form, how can I achieve this in PHP?</p> <pre><code>$headers = ...
<p>What you would do is specify the time to send the email. Save that with the email to, subject, message and headers in a database.</p> <p>Then create a cronjob that checks the database every few minutes to see if any emails are supposed to be sent. If so, that PHP file (that the cronjob executes) will send the email...
Need help understanding C# generics <p>I am self-studying a C# reference and it gives the following information:</p> <p>1.21.4. Declaring Generic Parameters Generic parameters can be introduced in the declaration of classes, structs, interfaces, delegates (see the upcoming "Delegates" section), and methods. Other cons...
<p>That is just showing the API of <code>Nullable&lt;T&gt;</code> rather than the implementation. It's not meant to be compiled - <code>System.Nullable&lt;T&gt;</code> is part of the framework, you don't have to implement it yourself.</p>
My Tomcat re-deploy fails when using Teamcity <p>I'm using Teamcity to run CI which works great, apart from one thing: when my webapp is deployed to the web container (Tomcat 5.5) after a few times Tomcat runs out of memory. This is something that you see in development as well, but it's not such a huge problem since t...
<p>It's an issue with tomcat, the classloader and the classes are not being garbage collected properly. Every time you reload the webapp context, more copies of these classes are loaded, and as these are stored in the permanent heap generation, it will eventually run out of memory. </p> <p>You can <a href="http://st...
For what reasons do people choose Ruby over Java? <p>I am a beginner to Ruby. I've heard the following complaints about Ruby, and was hoping the Stack Overflow community could address each point raised. </p> <p>Common complaints about Ruby that I've heard:</p> <ul> <li>Ruby is slower than Java</li> <li>Ruby is not st...
<p>Ruby is slower than Java to run but faster to write, or read. Which is more important to you? I don't know any company in the world who'd pass if given the opportunity to (say) cut their dev time in half at the cost of doubling their hardware.</p> <p>Ruby is not statically typed, but neither are Python, Perl, Lis...
WPF 3D - Why does my ImageBrush not render? <p>I have a 3D plane which I'm trying to render with an ImageBrush as it's DiffuseMaterial.Brush. If i use a SolidColorBrush then the plane appears fine but I get nothing at all with either an ImageBrush or a VisualBrush.</p> <p>Can anyone tell me why? Here's the code.</p>...
<p>Got it,</p> <p>I needed to provide mapping coordinates for the brush to render. The MeshhGeometry3D now looks like this - </p> <pre><code>&lt;MeshGeometry3D x:Name="frontmesh" TriangleIndices=" 0 1 2 2 3 0" ...
Anyone have more details on a XBox 360 Console History Export Project? <p>Recently, at the Charlotte 2009 Code Camp someone was telling me about a project/product that would export the history of a XBox 360 Console and then create some kind of diary or journal for the XBox.</p> <p>He didn't really know the details, bu...
<p>Something like what <a href="http://360voice.gamerdna.com/" rel="nofollow">the 360 voice</a> is doing?</p>
ActionLink pointing to route not affected by current route <p>I have am problem because I have a menu where the links always should point to MyController/MyAction, but the site has other routes that go to the same action, but with more parameters.</p> <p>&lt;%= Html.ActionLink("MyLink", "MyAction", "MyController")%></...
<p>Ahh found out that I could use RouteLink instead...</p>
Setting XML Namepaces <p>I want create an xml document with the namepace attributes along the lines of this:</p> <pre><code>&lt;MyXmlDoC xmlns="http://abc" xmlns:brk="http://123"&gt; </code></pre> <p>Using the System.Xml.Linq xml library, iv done this:</p> <pre><code> public static XAttribute XmlNamepace() ...
<p>(From your answer) you need to add the ChildNode with the rt namespace, this should work:</p> <pre><code>rootNode.Add(new XElement(rt + "ChildNode", "Hello")); </code></pre>
How can I search an array in VB.NET? <p>I want to be able to effectively search an array for the contents of a string.<br /> Example: </p> <pre><code>dim arr() as string={"ravi","Kumar","Ravi","Ramesh"} </code></pre> <p>I pass the value is "ra" and I want it to return the index of 2 and 3.</p> <p>How can I do this ...
<p>It's not exactly clear how you want to search the array. Here are some alternatives:</p> <p>Find all items containing the exact string "Ra" (returns items 2 and 3):</p> <pre><code>Dim result As String() = Array.FindAll(arr, Function(s) s.Contains("Ra")) </code></pre> <p>Find all items starting with the exact stri...
How do I get the filepath for a class in Python? <p>Given a class C in Python, how can I determine which file the class was defined in? I need something that can work from either the class C, or from an instance off C.</p> <p>The reason I am doing this, is because I am generally a fan off putting files that belong tog...
<p>You can use the <a href="http://docs.python.org/library/inspect.html#inspect.getfile">inspect</a> module, like this:</p> <pre><code>import inspect inspect.getfile(C.__class__) </code></pre>
Synchronizing time, but ignoring time zones <p>I have an application that I want to have a feature where it synchronizes the Windows system clock, but only setting the minutes, unless for example the system time is 13:58 and the time server is 14:02, in which case the hour should be changed too. The thing is, I don't ...
<p>It sounds like what you really want is just to synchronize the client machine's UTC time to be the same as the server's UTC time, regardless of the time zones of either the server or the client.</p> <p>You'll want to find the APIs to get and set the time based on UTC.</p> <p>That <em>may</em> not be what you want,...
How do I perform certain actions in InstallShield in all situations other than a repair? <p>I've configured an InstallShield setup to delete certain VDs from IIS right before the InstallFiles action. The code is being called within the "OnInstallFilesActionBefore" event. This works fine, except that I don't want the VD...
<p>Yes, just add a condition, nothing wrong with that. Try <code>REMOVE~="ALL" OR NOT Installed</code>.</p>
DCOM server debug <p>I'm learning DCOM and I need to debug a class that I have created, how can I do this?</p>
<p>Write a simplest client that does CoInitialize(), then CoCreateInstance().</p> <p>Insert delays (call to Sleep() for example) into DllGetClassObject() of your server - with ATL you have the full source.</p> <p>After the client calls CoCreateInstance() attach the debugger to the server host process.</p>
Why is my image rotation algorithm not working? <h3>Attempts 1 &amp; 2:</h3> <p><em>Note:</em> Removed first attempts to cut down on question size. See community wiki for previous attempts.</p> <h3>Attempt 3:</h3> <p>As per fuzzy-waffle's example, I have implemented the following, which doesn't appear to work correc...
<p>The algorithm, unless I read it wrong, seems to rotate around the point 0,0 which is not what you want. Maybe you need to add height/2 and width/2 to your row and column values before you plug them in.</p> <pre><code>for (int y = 0; y &lt; 10; y++) { for (int x = 0; x &lt; 10; x++) { VUInt32 newX = (cos...
How to copy directory from source tree to binary tree? <p>Copying directory from source tree to binary tree. For example: How to copy www to bin folder.</p> <pre><code>work ├─bin └─src ├─doing │ └─www ├─include └─lib </code></pre> <p>Thanks.</p>
<p>Since version 2.8, the <a href="https://cmake.org/cmake/help/v3.6/command/file.html">file command</a> has a copy argument:</p> <pre><code>file(COPY yourDir DESTINATION yourDestination) </code></pre> <p>Note that:</p> <blockquote> <p>Relative input paths are evaluated with respect to the current source directo...
How to get information from VS_VERSION_INFO inside ActiveX control <p>Is there a way to extract information from VS_VERSION_INFO (e.g. FILEVERSION) inside the same application? I know, you probably thinking in a path of:<br> 1. GetModuleFileName(...)<br> 2. GetFileVersionInfoSize(...)<br> 3. GetFileVersionInfo...
<p>Here is the code which eventiuly worked for me (and Yes, it is for MFC ActiveX control):</p> <pre><code>CString modFilename; if(GetModuleFileName(AfxGetInstanceHandle(), modFilename.GetBuffer(MAX_PATH), MAX_PATH) &gt; 0) { modFilename.ReleaseBuffer(MAX_PATH); DWORD dwHandle = 0; DWORD dwSize = GetFileVe...
ASP.Net Master Page and File path issues <p>I'm trying to add a script reference to jQuery in my master page so that it will work for any page. It currently looks like this</p> <pre><code>&lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt; </code></pre> <p>The problem is that the path is always relat...
<p>You could use a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.aspx"><code>ScriptManager</code></a>:</p> <pre><code>&lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt; &lt;Scripts&gt; &lt;asp:ScriptReference Path="~/jquery.js" /&gt; &lt;/Scripts&gt; &lt;/asp:Sc...
WCF client in ASP.net Page <p>Can anyone advise of a good pattern for using a WCF Service from an ASP.net Page? It seems that if the lifetime of the Client(:ServiceModel.ClientBase) is not properly controlled that we get PipeException thrown. It currently exists as a field of the Page class, but is being reinstantiated...
<p>I agree with Michael, abstract it out into another layer if possible.</p> <p>However, if you are going to call it from your aspx page, I would just create a separate method to call it, return its results and cleanup. Keeps the code clean by having it all in one place. Just remember to dispose in your finally bloc...
Polymorphic Associations in Rails <p>How do polymorphic associations work in Rails? What are their advantages? Is there a way to add <code>belongs_to</code> method just by running a migration?</p>
<p>Ryan has a <a href="http://railscasts.com/episodes/154-polymorphic-association" rel="nofollow">railscast</a> about this that is pretty good.</p> <p>Belongs_to isn't something you add to a migration, you add it to the model. In the migration, you have to add the foreign key column. For example if you have a post m...
PHP upload code problem with permitted MIME file types <p>I have a file (image) upload script in PHP that I use to upload and resize images... It uses a simple MIME type and size validation so only jpg images are allowed and 1MB max file size.</p> <p>I recently discovered a problem. When I try tu upload a .avi file us...
<p><a href="http://us3.php.net/manual/en/features.file-upload.common-pitfalls.php" rel="nofollow">http://us3.php.net/manual/en/features.file-upload.common-pitfalls.php</a></p> <p>It looks like your <code>upload_max_filesize</code> ini-setting is too low. This would cause no error to be displayed when you upload a very...
String concatenation using C# <p>I've a input string:</p> <p>"risk management, portfolio management, investment planning"</p> <p>How do I convert this string into:</p> <p>"risk management" + "portfolio management" + "investment planning"</p> <p>Thanks.</p>
<h2>Split and Trim</h2> <pre><code> // include linq library like this: // using System.Linq; // then "test1, test2".Split(',').Select(o =&gt; o.Trim()); </code></pre> <p>or</p> <pre><code>"test1, test2".Split(',').Select(o =&gt; o.Trim()).ToArray(); // returns array </code></pre> <p>and</p> <pre><code>"test1, t...
Factory class knows too much <p><strong>UPDATED</strong> I've updated the example to better illustrate my problem. I realised it was missing one specific point - namely the fact that the <code>CreateLabel()</code> method always takes a label type so the factory can decide what type of label to create. Thing is, it mi...
<p>Well, how do you want to <em>call</em> the factory method?</p> <p>Concentrate on how you want to be able to use your API, and the implementation will usually make itself fairly clear. This is made even easier if you write the desired results of your API as unit tests.</p> <p>An overload may well be the right thing...
How can I reset a asp.net form after postback? <p>I am trying after the btnCreate_OnClick event to reset the form to it's default value just like the first page_load. The problem is after PostBack, every textbox and other controls, reloads the ViewState value. I cannot deactivate viewstate because of server event on Dr...
<p>If workable, I usually just use Response.Redirect to reload the same page from scratch.</p> <p>An initial GET request to a page usually costs less than subsequent POSTs anyway, so there's not much reason to avoid it.</p>
changing sorting criteria after the first result <p>I am selecting from a database of news articles, and I'd prefer to do it all in one query if possible. In the results, I need a sorting criteria that applies ONLY to the first result.</p> <p>In my case, the first result must have an image, but the others should be so...
<p>Even if you manage to find a query that looks like one query, it is going to be logicaly two queries. Have a look at <a href="http://dev.mysql.com/doc/refman/5.0/en/union.html" rel="nofollow">MySQL UNION</a> if you really must make it one query (but it will still be 2 logical queries). You can union the image in the...
MVC Vs n-tier architecture <p>I was wondering what exactly is the difference between MVC(which is an architectural pattern) and an n-tier architecture for an application. I searched for it but couldn't find a simple explanation. May be I am a bit naive on MVC concepts, so if anyone can explain the difference then it wo...
<p>N-tier architecture usually has each layer separated by the network. I.E. the presentation layer is on some web servers, then that talks to backend app servers over the network for business logic, then that talks to a database server, again over the network, and maybe the app server also calls out to some remote se...
Avoid null pointer checks in C++ <p>Use case:</p> <pre><code>class B { int b; public: int getB() { return b; } }; class A { B *b; public: int getB() { if (b ) { //How can I avoid the null check for b here ...
<p>What do you expect to happen if B is null then in getB()? If it's not a valid state for your program, just assert(b != NULL). If it is a valid state, you need the check.</p> <p>Some languages support contracts so you wouldn't need to manually write the checking code, but unfortunately C++ doesn't.</p>
How can I initialize a module's instance variables in Ruby? <p>I have some modules where I would like to use instance variables in. I'm currently initializing them like this:</p> <pre><code>module MyModule def self.method_a(param) @var ||= 0 # other logic goes here end end </code></pre> <p>I also could ca...
<p>Initialize them in the module definition.</p> <pre><code>module MyModule # self here is MyModule @species = "frog" @color = "red polka-dotted" @log = [] def self.log(msg) # self here is still MyModule, so the instance variables are still available @log &lt;&lt; msg end def self.show_log p...
HP Quality Center API + ASP.NET <p>Has anyone ever used ASP or ASP.NET to connect to HPQC via the API? Where can I find some examples of this interaction? Any direction on the matter would be greatly appreciated.</p>
<p>I guess by looking into the QC Open Test Architecture API documentation will do. There are lots of examples based in VB. The only difference when implementing it on ASP is that you will need to install the QC API where you web server will be executing the Active Server Pages.</p>