qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
185,448 | <p>Imagine in the Global.asax.cs file I had an instance class as a private field. Let's say like this:</p>
<pre><code>private MyClass _myClass = new MyClass();
</code></pre>
<p>And I had a static method on Global called GetMyClass() that gets the current HttpApplication and returns that instance.</p>
<pre><code>public static MyClass GetMyClass()
{
return ((Global)HttpContext.Current.ApplicationInstance)._myClass;
}
</code></pre>
<p>So I could get the instance on the current requests httpapplication by calling Global.GetMyClass().</p>
<p>Keep in mind that there is more than one (Global) HttpApplication. There is an HttpApplication for each request and they are pooled/shared, so in the truest sense it is not a real <a href="http://en.wikipedia.org/wiki/Singleton_pattern" rel="nofollow noreferrer">singleton</a>. But it does follow the pattern to a degree.</p>
<p>So as the question asked, would you consider this at the very least the singleton pattern?</p>
<p>Would you say it should not be used? Would you discourage its use? Would you say it's a <strong><em>possibly</em></strong> bad practice like a true singleton.</p>
<p>Could you see any problems that may arise from this type of usage scenario?</p>
<p>Or would you say it's not a true singleton, so it's OK, and not bad practice. Would you recommend this as a semi-quasi singleton where an instance per request is required? If not what other pattern/suggestion would you use/give?</p>
<p>Have you ever used anything such as this?</p>
<p>I have used this on past projects, but I am unsure if it's a practice I should stay away from. I have never had any issues in the past though.</p>
<p>Please give me your thoughts and opinions on this.</p>
<p>I am not asking what a singleton is. And I consider a singleton bad practice when used improperly which is in many many many cases. That is me. However, that is not what I am trying to discuss. I am trying to discuss THIS scenario I gave.</p>
| [
{
"answer_id": 185670,
"author": "Kevin Dostalek",
"author_id": 22732,
"author_profile": "https://Stackoverflow.com/users/22732",
"pm_score": 2,
"selected": false,
"text": "public SomeClassType SomeProperty\n{\n get\n {\n if (HttpContext.Current.Cache[\"SomeKey\"] == null)\n... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185448",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14642/"
] |
185,451 | <p>What's a quick-and-dirty way to make sure that only one instance of a shell script is running at a given time?</p>
| [
{
"answer_id": 169969,
"author": "Alex B",
"author_id": 23643,
"author_profile": "https://Stackoverflow.com/users/23643",
"pm_score": 8,
"selected": false,
"text": "flock(1)"
},
{
"answer_id": 185466,
"author": "Aupajo",
"author_id": 10407,
"author_profile": "https://... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185451",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7598/"
] |
185,461 | <p>I would like MATLAB to tell me if I have an input file (.m file) that contains some variables with their numbers (i.e., <code>a = 5</code>, <code>b = 6</code>, <code>c = 7</code>) so that I can then use that .m file in another program (main .m file) that uses these variables to calculate <code>S = a + b + c</code>. How can I then read the input file from the main file? Assume the input file is called INP and the main MAIN.</p>
| [
{
"answer_id": 185469,
"author": "Scottie T",
"author_id": 6688,
"author_profile": "https://Stackoverflow.com/users/6688",
"pm_score": 2,
"selected": false,
"text": "% File: inputs.m\na = 5;\nb = 6;\nc = 7;\n"
},
{
"answer_id": 185660,
"author": "KennyMorton",
"author_id"... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
185,463 | <p>I have a view that supports landscape and portrait viewing, with the controls all moving around when you switch from one to the other. I'm currently doing this by setting the .center of each one of my controls when the user rotates the phone. The problem is that this is tedious, and requires a lot of code, and seems to defeat the purpose of using Interface Builder in the first place.</p>
<p>My question is: is there a way in Interface Builder for one view to support multiple looks (one for landscape one for portrait)? If not how do other people do this with IB? Do you set up 2 views?</p>
<p>Edit: Just to clarify my landscape and portrait views look different, I don't want a straight transform, I actually display the data differently in landscape mode</p>
| [
{
"answer_id": 401061,
"author": "Ed Marty",
"author_id": 36007,
"author_profile": "https://Stackoverflow.com/users/36007",
"pm_score": 1,
"selected": false,
"text": "UIView"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/185463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6044/"
] |
185,474 | <p>I have a connection string being passed to a function, and I need to create a DbConnection based object (i.e. SQLConnection, OracleConnection, OLEDbConnection etc) based on this string.</p>
<p>Is there any inbuilt functionality to do this, or any 3rd party libraries to assist. We are not necessarily building this connection string, so we cannot rely on a format the string is written in to determine its type, and I would <em>prefer</em> not to have to code up all combinations and permutations of possible connection strings</p>
| [
{
"answer_id": 185482,
"author": "Eric Tuttleman",
"author_id": 25677,
"author_profile": "https://Stackoverflow.com/users/25677",
"pm_score": 4,
"selected": false,
"text": "DbProviderFactory dbProviderFactory = DbProviderFactories.GetFactory(myDriverClass);\nDbConnection dbConnection = d... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185474",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5302/"
] |
185,483 | <p>How do I prevent my users from accessing directly pages meant for ajax calls only?</p>
<p>Passing a key during ajax call seems like a solution, whereas access without the key will not be processed. But it is also easy to fabricate the key, no? Curse of View Source...</p>
<p>p/s: Using Apache as webserver.</p>
<p>EDIT: To answer why, I have jQuery ui-tabs in my index.php, and inside those tabs are forms with scripts, which won't work if they're accessed directly. Why a user would want to do that, I don't know, I just figure I'd be more user friendly by preventing direct access to forms without validation scripts.</p>
| [
{
"answer_id": 185562,
"author": "Eran Galperin",
"author_id": 10585,
"author_profile": "https://Stackoverflow.com/users/10585",
"pm_score": 6,
"selected": true,
"text": " if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {\n //Request identified as ajax request\n }\n"
},
... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185483",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15345/"
] |
185,487 | <p>Assuming I have three tables :
TableA (key, value)
TableB (key, value)
TableC (key, value)</p>
<p>and I want to return a value for all keys. If the key exists in TableC return that value else if the key exists in B return that value else return the value from table A</p>
<p>The best I have come up with so far is</p>
<pre><code>SELECT key,Value
FROM TableA
WHERE key NOT IN (SELECT key FROM TableB)
AND key NOT IN (SELECT key FROM TableC)
UNION
SELECT key,Value
FROM TableB
WHERE key NOT IN (SELECT key FROM TableC)
UNION
SELECT key,Value
FROM TableC
</code></pre>
<p>But this seems pretty brute force. Anyone know a better way?</p>
<p>Edit: Here is a more concrete example. Consider TableA as a standard work schedule where the key is a date and the value is the assigned shift. Table B is a statutory holiday calendar that overrides the standard work week. Table C is an exception schedule that is used to override the other two schedules when someone is asked to come in and work either an extra shift or a different shift.</p>
| [
{
"answer_id": 185509,
"author": "Alexander Kojevnikov",
"author_id": 712,
"author_profile": "https://Stackoverflow.com/users/712",
"pm_score": 0,
"selected": false,
"text": "SELECT key, value, 2 AS priority\nFROM TableA\nUNION\nSELECT key, value, 1 AS priority\nFROM TableB\nUNION\nSELEC... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185487",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6819/"
] |
185,510 | <p>Is it possible to do something like this?</p>
<pre><code>var pattern = /some regex segment/ + /* comment here */
/another segment/;
</code></pre>
<p>Or do I have to use new <code>RegExp()</code> syntax and concatenate a string? I'd prefer to use the literal as the code is both more self-evident and concise.</p>
| [
{
"answer_id": 185529,
"author": "Jerub",
"author_id": 14648,
"author_profile": "https://Stackoverflow.com/users/14648",
"pm_score": 9,
"selected": true,
"text": "var segment_part = \"some bit of the regexp\";\nvar pattern = new RegExp(\"some regex segment\" + /*comment here */\n ... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185510",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17964/"
] |
185,520 | <p>I have months stored in SQL Server as 1,2,3,4,...12. I would like to display them as January,February etc. Is there a function in SQL Server like MonthName(1) = January? I am trying to avoid a CASE statement, if possible.</p>
| [
{
"answer_id": 185548,
"author": "Alexander Kojevnikov",
"author_id": 712,
"author_profile": "https://Stackoverflow.com/users/712",
"pm_score": 8,
"selected": true,
"text": "SELECT DATENAME(month, DATEADD(month, @mydate-1, CAST('2008-01-01' AS datetime)))\n"
},
{
"answer_id": 185... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185520",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23667/"
] |
185,521 | <p>I run into similar codes like this all the time in aspx pages:</p>
<pre><code><asp:CheckBox Runat="server" ID="myid" Checked='<%# DataBinder.Eval(Container.DataItem, "column").Equals(1) %>'>
</code></pre>
<p>I was wondering what other objects I have access to inside of that <%# %> tag. How come DataBinder.Eval() and Container.DataItem are not visible anywhere inside .CS code?</p>
| [
{
"answer_id": 185612,
"author": "Fung",
"author_id": 8280,
"author_profile": "https://Stackoverflow.com/users/8280",
"pm_score": 4,
"selected": true,
"text": "<%#DirectCast(Container.DataItem, DataRow)(\"some_column\")%>\n"
},
{
"answer_id": 1287615,
"author": "Community",
... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185521",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10088/"
] |
185,524 | <p>I'm trying to build the example described at <a href="http://support.microsoft.com/kb/178749/EN-US/" rel="nofollow noreferrer">http://support.microsoft.com/kb/178749/EN-US/</a> in order to build an application that programatically accesses Excel using Automation. I have Visual C++ 2005/Visual Studio 2005. Some of the instructions don't exactly match up (classwizard, mostly), but the general idea seems to be the same.</p>
<p>Problems: I don't end up with an excel.h file after using the "new class" to create my wrapper classes. So I can' t #include that file as it specifies in step 13. I do get a excel.tlh and an excel.tli in my windebug directory, but that doesn't seem to work. I tried all orders for </p>
<pre><code>#include "stdafx.h"
#include "debug/excel.tli"
#include "debug/excel.tlh"
</code></pre>
<p>... including leaving one of those files out of the compile, but I still end up with a ton of compile errors.</p>
<p>Here's the top 5 compile errors with the above #includes:</p>
<pre><code>1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2653: 'Adjustments' : is not a class or namespace name
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2146: syntax error : missing ';' before identifier 'GetParent'
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2433: 'IDispatchPtr' : 'inline' not permitted on data declarations
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(16) : error C3861: 'get_Parent': identifier not found
</code></pre>
<p>Here's the top 5 errors with these includes:</p>
<pre><code>#include "stdafx.h"
#include "debug/excel.tlh"
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tlh(550) : error C3121: cannot change GUID for class 'IFilter'
1> c:\program files\microsoft sdks\windows\v6.0\include\comdef.h(483) : see declaration of 'IFilter'
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tlh(1541) : error C2786: 'BOOL (__stdcall *)(HDC,int,int,int,int)' : invalid operand for __uuidof
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tlh(1541) : error C2923: '_com_IIID' : 'Rectangle' is not a valid template type argument for parameter '_Interface'
1> c:\program files\microsoft sdks\windows\v6.0\include\wingdi.h(3667) : see declaration of 'Rectangle'
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tlh(1541) : error C3203: '_com_IIID' : unspecialized class template can't be used as a template argument for template parameter '_IIID', expected a real type
</code></pre>
<p>Here's the top 5 errors with these includes:</p>
<pre><code>#include "stdafx.h"
#include "debug/excel.tli"
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2653: 'Adjustments' : is not a class or namespace name
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2146: syntax error : missing ';' before identifier 'GetParent'
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2433: 'IDispatchPtr' : 'inline' not permitted on data declarations
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
</code></pre>
<p>Thanks in advance.</p>
| [
{
"answer_id": 186009,
"author": "Nick",
"author_id": 26240,
"author_profile": "https://Stackoverflow.com/users/26240",
"pm_score": 1,
"selected": false,
"text": ".tlh"
},
{
"answer_id": 186029,
"author": "jmatthias",
"author_id": 2768,
"author_profile": "https://Stac... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185524",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1965047/"
] |
185,533 | <p>I've been looking at the <a href="http://www.getdropbox.com/install?os=mac" rel="noreferrer">DropBox</a> Mac client and I'm currently researching implementing a similar interface for a different service. </p>
<p>How exactly do they interface with finder like this? I highly doubt these objects represented in the folder are actual documents downloaded on every load? They must dynamically download as they are needed. So how can you display these items in finder without having actual file system objects? </p>
<p><strong>Does anyone know how this is achieved in Mac OS X?</strong> </p>
<p>Or any pointer's to Apple API's or other open source projects that have a similar integration with finder? </p>
| [
{
"answer_id": 7158576,
"author": "Wim Leers",
"author_id": 80305,
"author_profile": "https://Stackoverflow.com/users/80305",
"pm_score": 2,
"selected": false,
"text": "inotify"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/185533",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3415/"
] |
185,536 | <p>By default it seems that objects are drawn front to back. I am drawing a 2-D UI object and would like to create it back to front. For example I could create a white square first then create a slightly smaller black square on top of it thus creating a black pane with a white border. <a href="http://gpwiki.org/index.php/OpenGL:Tutorials:Tutorial_Framework:Ortho_and_Alpha" rel="noreferrer">This post</a> had some discussion on it and described this order as the "Painter's Algorithm" but ultimately the example they gave simply rendered the objects in reverse order to get the desired effect. I figure back to front (first objects go in back, subsequent objects get draw on top) rendering can be achieved via some transformation (gOrtho?) ?</p>
<p>I will also mention that I am not interested in a solution using a wrapper library such as GLUT. </p>
<p>I have also found that the default behavior on the Mac using the Cocoa NSOpenGLView appears to draw back to front, where as in windows I cannot get this behavior. The setup code in windows I am using is this:</p>
<pre><code>glViewport (0, 0, wd, ht);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho (0.0f, wd, ht, 0.0f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
</code></pre>
| [
{
"answer_id": 189915,
"author": "AlanKley",
"author_id": 8761,
"author_profile": "https://Stackoverflow.com/users/8761",
"pm_score": 6,
"selected": true,
"text": "glDepthFunc(GL_NEVER); // Ignore depth values (Z) to cause drawing bottom to top\n"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/185536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8761/"
] |
185,559 | <p>I would like to remove the domain/computer information from a login id in C#. So, I would like to make either "Domain\me" or "Domain\me" just "me". I could always check for the existence of either, and use that as the index to start the substring...but I am looking for something more elegant and compact.</p>
<p>Worse case scenario:</p>
<pre><code>int startIndex = 0;
int indexOfSlashesSingle = ResourceLoginName.IndexOf("\");
int indexOfSlashesDouble = ResourceLoginName.IndexOf("\\");
if (indexOfSlashesSingle != -1)
startIndex = indexOfSlashesSingle;
else
startIndex = indexOfSlashesDouble;
string shortName = ResourceLoginName.Substring(startIndex, ResourceLoginName.Length-1);
</code></pre>
| [
{
"answer_id": 185572,
"author": "BoltBait",
"author_id": 20848,
"author_profile": "https://Stackoverflow.com/users/20848",
"pm_score": 2,
"selected": false,
"text": " string[] domainuser;\n string Auth_User = Request.ServerVariables[\"AUTH_USER\"].ToString().ToLower(); \n domai... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185559",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18449/"
] |
185,569 | <p>This is an age-old question where given a table with attributes 'type', 'variety' and 'price', that you fetch the record with the minimum price for each type there is.</p>
<p>In SQL, we can do <a href="http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/" rel="noreferrer">this</a> by:</p>
<pre><code>select f.type, f.variety, f.price
from ( select type, min(price) as minprice from table group by type ) as x
inner join table as f on f.type = x.type and f.price = x.minprice;`
</code></pre>
<p>We could perhaps imitate this by:</p>
<pre><code>minprices = Table.minimum(:price, :group => type)
result = []
minprices.each_pair do |t, p|
result << Table.find(:first, :conditions => ["type = ? and price = ?", t, p])
end
</code></pre>
<p>Is there a better implementation than this?</p>
| [
{
"answer_id": 185647,
"author": "Avdi",
"author_id": 20487,
"author_profile": "https://Stackoverflow.com/users/20487",
"pm_score": 4,
"selected": false,
"text": "Table.minimum(:price, :group => :type)\n"
},
{
"answer_id": 186219,
"author": "François Beausoleil",
"author_... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
185,573 | <p>I couldn't really find this in Rails documentation but it seems like <strong>'mattr_accessor'</strong> is the <strong>Module</strong> corollary for <strong>'attr_accessor'</strong> (getter & setter) in a normal Ruby <strong>class</strong>.</p>
<p>Eg. in a class</p>
<pre><code>class User
attr_accessor :name
def set_fullname
@name = "#{self.first_name} #{self.last_name}"
end
end
</code></pre>
<p>Eg. in a module</p>
<pre><code>module Authentication
mattr_accessor :current_user
def login
@current_user = session[:user_id] || nil
end
end
</code></pre>
<p>This helper method is provided by <strong>ActiveSupport</strong>.</p>
| [
{
"answer_id": 185632,
"author": "Avdi",
"author_id": 20487,
"author_profile": "https://Stackoverflow.com/users/20487",
"pm_score": 9,
"selected": true,
"text": "mattr_accessor"
},
{
"answer_id": 188915,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185573",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6048/"
] |
185,575 | <p>In bash the ampersand (&) can be used to run a command in the background and return interactive control to the user before the command has finished running. Is there an equivalent method of doing this in Powershell?</p>
<p>Example of usage in bash:</p>
<pre><code> sleep 30 &
</code></pre>
| [
{
"answer_id": 6459716,
"author": "Dustin Getz",
"author_id": 20003,
"author_profile": "https://Stackoverflow.com/users/20003",
"pm_score": 5,
"selected": false,
"text": "ps2> start-job {start-sleep 20}\n"
},
{
"answer_id": 11372785,
"author": "Gian Marco",
"author_id": 6... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185575",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5769/"
] |
185,584 | <p>Does there exist a parser that generates an AST/parse tree at runtime? Kind of like a library that would accept a string of EBNF grammar or something analogous and spit out a data structure? </p>
<ul>
<li>I'm aware of antlr, jlex and their ilk. They generate source code which could do this. (like to skip the compile step)</li>
<li>I'm aware of Boost::Spirit, which uses some black magic with C++ syntax to generate such things at execution time (definitely much closer to what I want, but I'm a wuss when it comes to C++. And it's still somewhat limiting, because your grammar is hardcoded)</li>
<li>I'm not aware of anything in python or ruby, although a compiler compiler might very well be effective in such a language... </li>
</ul>
<p><p>Now I'm aware of parser combinators. (thanks, Jonas) And some libraries (thanks eliben)
<p> incidentally, I also noticed <a href="http://en.wikipedia.org/wiki/Parsing_expression_grammar" rel="noreferrer">Parsing Expression Grammars</a> lately, which sounds cool were someone to implement it (they say Perl 6 will have it, but Perl evades my understanding)</p>
| [
{
"answer_id": 185662,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 2,
"selected": false,
"text": "{syntax: while (condition) do code}\nwhile (condition, code) => // actual execution\n"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/185584",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23648/"
] |
185,594 | <p>What data structure does the following declaration specify?</p>
<pre><code> List<ArrayList>[] myArray;
</code></pre>
<p>I think it should declare an array where each element is a <code>List</code> (e.g., a <code>LinkedList</code> or an <code>ArrayList</code>) and require that each <code>List</code> contain <code>ArrayList</code> objects.</p>
<p>My reasoning:</p>
<pre><code> List<String> someList; // A List of String objects
List<ArrayList> someList; // A List of ArrayList objects
List<ArrayList>[] someListArray; // An array of List of ArrayList objects
</code></pre>
<p>After running some tests, I determined that it accepts an array where each element is an <code>LinkedList</code> object and does not specify what the LinkedList objects contain.</p>
<p>So <code>List<ArrayList></code> specifies what the <code>List</code> must contain, but <code>List<ArrayList>[]</code> specifies how the <code>List</code> must be implemented.</p>
<p>Am I missing something?</p>
<p>Here are my tests.</p>
<pre><code>import java.util.ArrayList;
import java.util.List;
import java.util.LinkedList;
public class Generics1 {
public static void main(String[] args) {
List<ArrayList>[] someListArray;
someListArray = getArrayWhereEachElementIsAnArrayListObject();
// Why does this satisfy the declaration?
//someListArray[0] => ArrayList object holding Strings
someListArray= getArrayWhereEachElementIsAListOfArrayListObjects();
//someListArray[0] => ArrayList object holding ArrayList objects
}
public static List[] getArrayWhereEachElementIsAnArrayListObject() {
List[] arrayOfLists = new ArrayList[2];
arrayOfLists[0] = getStringList();
arrayOfLists[1] = getIntegerList();
return arrayOfLists;
}
public static List[] getArrayWhereEachElementIsAListOfArrayListObjects() {
List list1 = new ArrayList();
list1.add(getArrayList());
List list2 = new ArrayList();
list2.add(getArrayList());
List[] arrayOfListsOfArrayLists = new ArrayList[2];
arrayOfListsOfArrayLists[0] = list1;
arrayOfListsOfArrayLists[1] = list2;
return arrayOfListsOfArrayLists;
}
public static List getStringList() {
List stringList= new ArrayList();
stringList.add("one");
stringList.add("two");
return stringList;
}
public static List getIntegerList() {
List intList= new ArrayList();
intList.add(new Integer(1));
intList.add(new Integer(2));
return intList;
}
public static ArrayList getArrayList() {
ArrayList arrayList = new ArrayList() ;
return arrayList;
}
}
</code></pre>
| [
{
"answer_id": 185619,
"author": "Mark",
"author_id": 26310,
"author_profile": "https://Stackoverflow.com/users/26310",
"pm_score": 3,
"selected": false,
"text": "List<List<ArrayList>> someListArray;\n"
},
{
"answer_id": 185627,
"author": "Draemon",
"author_id": 26334,
... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19685/"
] |
185,606 | <p>I wonder if this would be doable ? To insert an array into one field in the database.</p>
<p>For instance I have a title, I want to have that title with only one id, but it's going to be bilingually used on the website.</p>
<p>It feels a bit unnecessary to make another table to have their global ids and then another table with the actual titles linked to the table with the global id.</p>
<p>I just want to have something like this</p>
<pre><code>ID TITLE
1 Array("english title", "nederlandse titel");
</code></pre>
<p>I'm using PHP/MSYQL, so if it would be doable could you please explain in these languages.</p>
<p>Oh yeah I figured that I could format it funky and use the split function to turn it into an array again. But I wonder if I could just store it as an array right away, I case the user might type something with the same formatting (one out of a million)</p>
| [
{
"answer_id": 185625,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 5,
"selected": true,
"text": "$title = serialize($array);\n"
},
{
"answer_id": 185639,
"author": "Cade Roux",
"author_id": 18255,
"author_... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185606",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18671/"
] |
185,621 | <p>Has anybody been successful in integrating the Enterprise Library v4.0 with SharePoint WSS 3.0? I created a very simple .ASPX page. It's only purpose will to be to connect to an Oracle database and display some values in a DropDownList. But right now, all it does is displays Hello World. I've added the necessary references and everything compiles fine. When I test the page, it displays Hello World. But once I add the using Microsoft.Practices.EnterprisesLibrary.Data, the page no longer works. I just get the standard Unknown Error message. Is there a log file I can check? </p>
<p>I'm looking for any steps or tips that I can use to get this up and running. I use this Enterprise Library in all my ASP.NET applications and it works great. Trying to get this to work in SharePoint seems like a natural fit. But why does it seem so difficult? And why does there seem to be a lack of information?</p>
<p>Anyways, thank you so much for any information anybody can provide.</p>
| [
{
"answer_id": 189353,
"author": "Cruiser",
"author_id": 16971,
"author_profile": "https://Stackoverflow.com/users/16971",
"pm_score": 1,
"selected": false,
"text": "<SharePoint><SafeMode>"
},
{
"answer_id": 191055,
"author": "DrZ",
"author_id": 1082,
"author_profile"... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185621",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1082/"
] |
185,624 | <p>I have a function that is declared and defined in a header file. This is a problem all by itself. When that function is not inlined, every translation unit that uses that header gets a copy of the function, and when they are linked together there are duplicated. I "fixed" that by making the function inline, but I'm afraid that this is a fragile solution because as far as I know, the compiler doesn't guarantee inlining, even when you specify the "inline" keyword. If this is not true, please correct me.</p>
<p>Anyways, the real question is, what happens to static variables inside this function? How many copies do I end up with?</p>
| [
{
"answer_id": 189162,
"author": "paercebal",
"author_id": 14089,
"author_profile": "https://Stackoverflow.com/users/14089",
"pm_score": 8,
"selected": true,
"text": "void doSomething()\n{\n static int value ;\n}\n"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/185624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13562/"
] |
185,652 | <p>I have a UIImageView and the objective is to scale it down proportionally by giving it either a height or width. </p>
<pre><code>UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
//Add image view
[self.view addSubview:imageView];
//set contentMode to scale aspect to fit
imageView.contentMode = UIViewContentModeScaleAspectFit;
//change width of frame
CGRect frame = imageView.frame;
frame.size.width = 100;
imageView.frame = frame;
</code></pre>
<p>The image did get resized but the position is not at the top left. What is the best approach to scaling image/imageView and how do I correct the position?</p>
| [
{
"answer_id": 185788,
"author": "user26359",
"author_id": 26359,
"author_profile": "https://Stackoverflow.com/users/26359",
"pm_score": 0,
"selected": false,
"text": "image.center = [[imageView window] center];\n"
},
{
"answer_id": 185911,
"author": "Chris Lundie",
"auth... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185652",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1987/"
] |
185,661 | <p>I'd like to know if Flash/AS3 has any nice way to convert an AS3 'Date' object to/from rfc-850 timestamp format (as used by HTTP date and last-modified).</p>
<p>This question is very similar to <a href="https://stackoverflow.com/questions/17017/how-do-i-parse-and-convert-datetimes-to-the-rfc-3339-date-time-format">this question about rfc 3339</a>, except it's specific to AS3 and rfc-850.</p>
<p>RFC-850 is like: <code>Thu, 09 Oct 2008 01:09:43 GMT</code></p>
| [
{
"answer_id": 186080,
"author": "aaaidan",
"author_id": 26331,
"author_profile": "https://Stackoverflow.com/users/26331",
"pm_score": 3,
"selected": true,
"text": "Date"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/185661",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26331/"
] |
185,664 | <p>I'm trying to create a user control that allows users to make something like the following:</p>
<pre><code> <uc1:MyControl id="controlThing" runat="server">
<uc1:BoundColumn id="column1" Column="Name" runat="server" />
<uc1:CheckBoxBoundColumn id="column2" Column="Selector" runat="server" />
<uc1:BoundColumn id="column3" Column="Description" runat="server" />
...etc
</uc1:MyControl>
</code></pre>
<p>There are only certain controls I would allow, in addition to the fact that you can have many of any type. I can picture this in XSD, but I'm not entirely sure for ASP.NET.</p>
<p>My ASP.NET voodoo is drawing a blank right now.. any thoughts?</p>
| [
{
"answer_id": 185687,
"author": "nyxtom",
"author_id": 19753,
"author_profile": "https://Stackoverflow.com/users/19753",
"pm_score": 0,
"selected": false,
"text": "<mycontrol id=\"control1\" runat=\"server\">\n <templateitem id=\"bleh1\" runat=\"server\" />\n <templateitem id=\"bl... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19753/"
] |
185,680 | <p>How do I define nested class in Java Script. </p>
<p>Here is the code snippet I have:</p>
<pre><code>objA = new TestA();
function TestB ()
{
this.testPrint = function ()
{
print ( " Inside testPrint " );
}
}
function TestA ()
{
var myObjB = new TestB();
}
</code></pre>
<p>Now I am trying to access testPrint using objA</p>
<pre><code>objA.myObjB.testPrint();
</code></pre>
<p>But its giving error "objA has no properties"</p>
<p>How can I access testB method using objA handler?</p>
| [
{
"answer_id": 185695,
"author": "Aaron Maenpaa",
"author_id": 2603,
"author_profile": "https://Stackoverflow.com/users/2603",
"pm_score": 2,
"selected": false,
"text": "var objA = {\n myObjB: {\n testPrint: function(){\n print(\"Inside test print\");\n }\n }\n... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185680",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
185,681 | <p>How to parse the DOM and determine what row is selected in an ASP.NET <code>ListView</code>? I'm able to interact with the DOM via the <code>HtmlElement</code> in Silverlight, but I have not been able to locate a property indicating the row is selected.</p>
<p>For reference, this managed method works fine for an ASP.NET ListBox</p>
<pre><code>var elm = HtmlPage.Document.GetElementById(ListBoxId);
foreach (var childElm in elm.Children)
{
if (!((bool)childElm.GetProperty("Selected")))
{
continue;
}
}
</code></pre>
| [
{
"answer_id": 185897,
"author": "Bryant",
"author_id": 10893,
"author_profile": "https://Stackoverflow.com/users/10893",
"pm_score": 0,
"selected": false,
"text": "HtmlElement elem = HtmlPage.Document.GetElementById(\"testSelect\");\nint index = Convert.ToInt32(elem.GetProperty(\"select... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21410/"
] |
185,690 | <p>I'm using the <a href="http://www.componentace.com/zlib_.NET.htm" rel="noreferrer">zlib.NET</a> library to try and inflate files that are compressed by zlib (on a Linux box, perhaps). Here's what I'm doing:</p>
<pre><code>zlib.ZInputStream zinput =
new zlib.ZInputStream(File.Open(path, FileMode.Open, FileAccess.Read));
while (stopByte != (data = zinput.ReadByte()))
{
// check data here
}
zinput.Close();
</code></pre>
<p>The data bytes match the compressed data bytes, so I must be doing something wrong.</p>
| [
{
"answer_id": 185736,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": false,
"text": "int Read(buffer, offset, length)"
},
{
"answer_id": 185924,
"author": "Brendan Kowitz",
"author_id": 257... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3279/"
] |
185,697 | <p>Input: A positive integer K and a big text. The text can actually be viewed as word sequence. So we don't have to worry about how to break down it into word sequence.<br>
Output: The most frequent K words in the text.</p>
<p>My thinking is like this. </p>
<ol>
<li><p>use a Hash table to record all words' frequency while traverse the whole word sequence. In this phase, the key is "word" and the value is "word-frequency". This takes O(n) time. </p></li>
<li><p>sort the (word, word-frequency) pair; and the key is "word-frequency". This takes O(n*lg(n)) time with normal sorting algorithm. </p></li>
<li><p>After sorting, we just take the first K words. This takes O(K) time. </p></li>
</ol>
<p>To summarize, the total time is O(n+n<em>lg(n)+K), Since K is surely smaller than N, so it is actually O(n</em>lg(n)).</p>
<p>We can improve this. Actually, we just want top K words. Other words' frequency is not concern for us. So, we can use "partial Heap sorting". For step 2) and 3), we don't just do sorting. Instead, we change it to be</p>
<p>2') build a heap of (word, word-frequency) pair with "word-frequency" as key. It takes O(n) time to build a heap;</p>
<p>3') extract top K words from the heap. Each extraction is O(lg(n)). So, total time is O(k*lg(n)).</p>
<p>To summarize, this solution cost time O(n+k*lg(n)).</p>
<p>This is just my thought. I haven't find out way to improve step 1).<br>
I Hope some Information Retrieval experts can shed more light on this question.</p>
| [
{
"answer_id": 19460906,
"author": "Shawn",
"author_id": 165835,
"author_profile": "https://Stackoverflow.com/users/165835",
"pm_score": 0,
"selected": false,
"text": "List<Set<String>>"
},
{
"answer_id": 22341665,
"author": "Chihung Yu",
"author_id": 1320928,
"author... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185697",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26349/"
] |
185,698 | <p>I have a directory with several subdirectories with files.<br>
How can I copy all files in the subdirectories to a new location?<br></p>
<p><strong>Edit:</strong> I do not want to copy the directories, just the files...</p>
<p>As this is still on XP, I chose the below solution:</p>
<pre><code> for /D %S IN ("src\*.*") DO @COPY "%S\" "dest\"
</code></pre>
<p>Thanks!</p>
| [
{
"answer_id": 185703,
"author": "Eric Tuttleman",
"author_id": 25677,
"author_profile": "https://Stackoverflow.com/users/25677",
"pm_score": 2,
"selected": false,
"text": "XCOPY /E SrcDir\\*.* DestDir\\\n"
},
{
"answer_id": 185715,
"author": "Mark Cidade",
"author_id": 1... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185698",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14484/"
] |
185,747 | <p>I am trying to convert an <code>int</code> into three <code>bytes</code> representing that <code>int</code> (big endian).</p>
<p>I'm sure it has something to do with bit-wise and and bit shifting. But I have no idea how to go about doing it.</p>
<p>For example:</p>
<pre><code>int myInt;
// some code
byte b1, b2 , b3; // b1 is most significant, then b2 then b3.
</code></pre>
<p>*Note, I am aware that an int is 4 bytes and the three bytes have a chance of over/underflowing.</p>
| [
{
"answer_id": 185763,
"author": "Paul Tomblin",
"author_id": 3333,
"author_profile": "https://Stackoverflow.com/users/3333",
"pm_score": 2,
"selected": false,
"text": " byte b1 = (myInt & 0xff);\n myInt >>= 8;\n byte b2 = (myInt & 0xff);\n myInt >>= 8;\n byte b3 = (myInt & 0xf... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185747",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2598/"
] |
185,778 | <p>I am using trigger_error to "throw" errors in a custom class. My problem is that trigger_error prints out the line number where trigger_error was called. For example, given the following code:</p>
<pre><code>01 <?php
02 class Test {
03 function doAction() {
04 $this->doSubAction();
05 }
06
07 function doSubAction() {
08 if(true)
09 trigger_error('Custom error', E_USER_WARNING);
10 }
11 }
12
13 $var = new Test();
14 $var->doAction();
15 ?>
</code></pre>
<p>PHP will print out the following:</p>
<blockquote>
<p><strong>Warning:</strong> Custom error in <strong>test.php</strong> on line <strong>9</strong></p>
</blockquote>
<p>How would you make PHP return the line where the doAction() function was called (the method called outside the class, ignoring all calls made internally) as follows?</p>
<blockquote>
<p><strong>Warning:</strong> Custom error in <strong>test.php</strong> on line <strong>14</strong></p>
</blockquote>
<p><strong>Edit:</strong> Modified my example to be something a bit closer to what I'm trying to achieve.</p>
| [
{
"answer_id": 185817,
"author": "Rob Howard",
"author_id": 3528,
"author_profile": "https://Stackoverflow.com/users/3528",
"pm_score": 0,
"selected": false,
"text": "__LINE__"
},
{
"answer_id": 1145375,
"author": "Andrew Moore",
"author_id": 26210,
"author_profile": ... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185778",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26210/"
] |
185,780 | <p>I'm adding repeating events to a Cocoa app I'm working on. I have repeat every day and week fine because I can define these mathematically (3600*24*7 = 1 week). I use the following code to modify the date:</p>
<pre><code>[NSDate dateWithTimeIntervalSinceNow:(3600*24*7*(weeks))]
</code></pre>
<p>I know how many months have passed since the event was repeated but I can't figure out how to make an NSDate object that represents 1 month/3 months/6 months/9 months into the future. Ideally I want the user to say repeat monthly starting Oct. 14 and it will repeat the 14th of every month.</p>
| [
{
"answer_id": 186104,
"author": "mmalc",
"author_id": 23233,
"author_profile": "https://Stackoverflow.com/users/23233",
"pm_score": 6,
"selected": true,
"text": "NSDate *today = [NSDate date];\n\nNSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185780",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13069/"
] |
185,781 | <p>I read an interesting DailyWTF post today, <a href="http://thedailywtf.com/Articles/Out-of-All-the-Possible-Answers.aspx" rel="noreferrer">"Out of All The Possible Answers..."</a> and it interested me enough to dig up the original <a href="http://forums.thedailywtf.com/forums/t/10030.aspx" rel="noreferrer">forum post</a> where it was submitted. This got me thinking how I would solve this interesting problem - the original question is posed on <a href="http://projecteuler.net/index.php?section=problems&id=5" rel="noreferrer">Project Euler</a> as: </p>
<blockquote>
<p>2520 is the smallest number that can be divided by each of the
numbers from 1 to 10 without any remainder.</p>
<p>What is the smallest number that is evenly divisible by all of
the numbers from 1 to 20?</p>
</blockquote>
<p>To reform this as a programming question, <strong>how would you create a function that can find the Least Common Multiple for an arbitrary list of numbers?</strong></p>
<p>I'm incredibly bad with pure math, despite my interest in programming, but I was able to solve this after a little Googling and some experimenting. I'm curious what other approaches SO users might take. If you're so inclined, post some code below, hopefully along with an explanation. Note that while I'm sure libraries exist to compute the GCD and LCM in various languages, I'm more interested in something that displays the logic more directly than calling a library function :-) </p>
<p>I'm most familiar with Python, C, C++, and Perl, but any language you prefer is welcome. Bonus points for explaining the logic for other mathematically-challenged folks out there like myself.</p>
<p><strong>EDIT</strong>: After submitting I did find this similar question <a href="https://stackoverflow.com/questions/147515">Least common multiple for 3 or more numbers</a> but it was answered with the same basic code I already figured out and there's no real explanation, so I felt this was different enough to leave open.</p>
| [
{
"answer_id": 185920,
"author": "Mark Ransom",
"author_id": 5987,
"author_profile": "https://Stackoverflow.com/users/5987",
"pm_score": 5,
"selected": true,
"text": "def RangeLCM(first, last):\n factors = range(first, last+1)\n for i in range(0, len(factors)):\n if factors[... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185781",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20840/"
] |
185,804 | <p>I created an app for a small business. Some of the employees in the office can not see the form correctly. The reason is they have their DPI setting set to above 96dpi. Does anybody know of a way to control this?</p>
<p>For all of you who have experience with winforms apps, how do you control your form layout so that DPI does not affect the look of the application?</p>
| [
{
"answer_id": 202172,
"author": "Ian Boyd",
"author_id": 12597,
"author_profile": "https://Stackoverflow.com/users/12597",
"pm_score": 6,
"selected": false,
"text": "AutoScaleMode"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/185804",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21325/"
] |
185,836 | <p>Does anyone know if it possible to define the equivalent of a "java custom class loader" in .NET?</p>
<p><strong>To give a little background:</strong></p>
<p>I am in the process of developing a new programming language that targets the CLR, called "Liberty". One of the features of the language is its ability to define "type constructors", which are methods that are executed by the compiler at compile time and generate types as output. They are sort of a generalization of generics (the language does have normal generics in it), and allow code like this to be written (in "Liberty" syntax):</p>
<pre><code>var t as tuple<i as int, j as int, k as int>;
t.i = 2;
t.j = 4;
t.k = 5;
</code></pre>
<p>Where "tuple" is defined like so:</p>
<pre><code>public type tuple(params variables as VariableDeclaration[]) as TypeDeclaration
{
//...
}
</code></pre>
<p>In this particular example, the type constructor <code>tuple</code> provides something similar to anonymous types in VB and C#.</p>
<p>However, unlike anonymous types, "tuples" have names and can be used inside public method signatures.</p>
<p>This means that I need a way for the type that eventually ends up being emitted by the compiler to be shareable across multiple assemblies. For example, I want</p>
<p><code>tuple<x as int></code> defined in Assembly A to end up being the same type as <code>tuple<x as int></code> defined in Assembly B.</p>
<p>The problem with this, of course, is that Assembly A and Assembly B are going to be compiled at different times, which means they would both end up emitting their own incompatible versions of the tuple type.</p>
<p>I looked into using some sort of "type erasure" to do this, so that I would have a shared library with a bunch of types like this (this is "Liberty" syntax):</p>
<pre><code>class tuple<T>
{
public Field1 as T;
}
class tuple<T, R>
{
public Field2 as T;
public Field2 as R;
}
</code></pre>
<p>and then just redirect access from the i, j, and k tuple fields to <code>Field1</code>, <code>Field2</code>, and <code>Field3</code>.</p>
<p>However that is not really a viable option. This would mean that at compile time <code>tuple<x as int></code> and <code>tuple<y as int></code> would end up being different types, while at runtime time they would be treated as the same type. That would cause many problems for things like equality and type identity. That is too leaky of an abstraction for my tastes. </p>
<p>Other possible options would be to use "state bag objects". However, using a state bag would defeat the whole purpose of having support for "type constructors" in the language. The idea there is to enable "custom language extensions" to generate new types at compile time that the compiler can do static type checking with.</p>
<p>In Java, this could be done using custom class loaders. Basically the code that uses tuple types could be emitted without actually defining the type on disk. A custom "class loader" could then be defined that would dynamically generate the tuple type at runtime. That would allow static type checking inside the compiler, and would unify the tuple types across compilation boundaries.</p>
<p>Unfortunately, however, the CLR does not provide support for custom class loading. All loading in the CLR is done at the assembly level. It would be possible to define a separate assembly for each "constructed type", but that would very quickly lead to performance problems (having many assemblies with only one type in them would use too many resources).</p>
<p><strong>So, what I want to know is:</strong></p>
<p>Is it possible to simulate something like Java Class Loaders in .NET, where I can emit a reference to a non-existing type in and then dynamically generate a reference to that type at runtime before the code the needs to use it runs?</p>
<p><strong>NOTE:</strong></p>
<p>*I actually already know the answer to the question, which I provide as an answer below. However, it took me about 3 days of research, and quite a bit of IL hacking in order to come up with a solution. I figured it would be a good idea to document it here in case anyone else ran into the same problem. *</p>
| [
{
"answer_id": 185856,
"author": "Scott Wisniewski",
"author_id": 1737192,
"author_profile": "https://Stackoverflow.com/users/1737192",
"pm_score": 7,
"selected": true,
"text": "System.Reflection.Emit"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/185836",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1737192/"
] |
185,844 | <p>What is the best way to initialize a private, static data member in C++? I tried this in my header file, but it gives me weird linker errors:</p>
<pre><code>class foo
{
private:
static int i;
};
int foo::i = 0;
</code></pre>
<p>I'm guessing this is because I can't initialize a private member from outside the class. So what's the best way to do this?</p>
| [
{
"answer_id": 185848,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 10,
"selected": true,
"text": "class foo\n{\n private:\n static int i;\n};\n"
},
{
"answer_id": 185863,
"author": "Matt Curtis"... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] |
185,862 | <p>I am starting my first independent for profit venture. I am having a hard time deciding what language to use. I want to write my app in Perl, but I don't think it will be simple enough to compile. If I don't write it in Perl I will write it in C++.</p>
<p>The application will have many features, including <a href="http://www.wxwidgets.org/" rel="noreferrer">wxwidgets</a> interface, Deal with SDL, timers, some threading, and audio processing. The program itself will be somewhat complex, but not terribly large.</p>
<p>So my question's are:</p>
<ol>
<li>Can PAR, Perl2exe, or equivalent compile more than a basic test cases?</li>
<li>Speed, and compilation aside why should I use C++ over Perl?</li>
</ol>
<hr />
<p>Edit:
Some of my project specifications.</p>
<ul>
<li>Multi Platform. I am expecting 50% or more of my users to own macs, with Most of the rest being Windows users. If possible I also want to support Linux since It is my everyday operating system.</li>
<li>Since it's multi Platform I need a unified GUI creation tool. It needs to be able to use basic types, and allow me to create custom event handlers, and custom GUI objects.</li>
<li>It needs audio processing. Read and play, wav's and/or mp3's. Also I will be using some custom algorithms to determine special properties of the audio files; things like tempo, patterns, and so on.</li>
<li>I would like but don't require SDL/OpenGL support.</li>
</ul>
<p>Everything else is pretty mundane. Some different classes and containers. A few custom GUI controls.</p>
| [
{
"answer_id": 187707,
"author": "Axeman",
"author_id": 11289,
"author_profile": "https://Stackoverflow.com/users/11289",
"pm_score": 1,
"selected": false,
"text": "map"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/185862",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21204/"
] |
185,883 | <p>Using the Qt Visual studio integration, adding a new Qt class adds two separate moc.exe generated files - one for debug and one for release (and one for any other configuration currently existing). Yet the two eventual generated files seem to be identical.</p>
<p>On the other hand when adding a UI class, the uic.exe generated files don't have this separation and are the same file for all configurations.</p>
<p>Does anybody have an idea why there's a need for a separate moc file for every configuration? When is there a difference between the two?</p>
| [
{
"answer_id": 185925,
"author": "David Dibben",
"author_id": 5022,
"author_profile": "https://Stackoverflow.com/users/5022",
"pm_score": 3,
"selected": false,
"text": "class Test : public QObject\n{\n Q_OBJECT\npublic:\n Test(); \npublic slots:\n\n#ifndef DEBUG\n ... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185883",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9611/"
] |
185,893 | <p>I have a production server running with the following flag: -<strong>XX:+HeapDumpOnOutOfMemoryError</strong></p>
<p>Last night it generated a java-38942.hprof file when our server encountered a heap error. It turns out that the developers of the system knew of the flag but no way to get any useful information from it.</p>
<p>Any ideas?</p>
| [
{
"answer_id": 185926,
"author": "Christian C. Salvadó",
"author_id": 5445,
"author_profile": "https://Stackoverflow.com/users/5445",
"pm_score": 6,
"selected": false,
"text": "jhat -port 7401 -J-Xmx4G dump.hprof"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/185893",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4960/"
] |
185,899 | <p>Recently I was asked this during a job interview. I was honest and said I knew how a symbolic link behaves and how to create one, but do not understand the use of a hard link and how it differs from a symbolic one.</p>
| [
{
"answer_id": 1531795,
"author": "Adam Matan",
"author_id": 51197,
"author_profile": "https://Stackoverflow.com/users/51197",
"pm_score": 9,
"selected": false,
"text": "$ printf Cat > foo\n$ printf Dog > bar\n"
},
{
"answer_id": 8881100,
"author": "ChandanK",
"author_id"... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185899",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4960/"
] |
185,934 | <p>It appears that in PHP objects are passed by reference. Even assignment operators do not appear to be creating a copy of the Object.</p>
<p>Here's a simple, contrived proof:</p>
<pre><code><?php
class A {
public $b;
}
function set_b($obj) { $obj->b = "after"; }
$a = new A();
$a->b = "before";
$c = $a; //i would especially expect this to create a copy.
set_b($a);
print $a->b; //i would expect this to show 'before'
print $c->b; //i would ESPECIALLY expect this to show 'before'
?>
</code></pre>
<p>In both print cases I am getting 'after'</p>
<p>So, how do I pass <strong>$a</strong> to <strong><em>set_b()</em></strong> by value, not by reference?</p>
| [
{
"answer_id": 185938,
"author": "Leo",
"author_id": 20689,
"author_profile": "https://Stackoverflow.com/users/20689",
"pm_score": 4,
"selected": false,
"text": "$a = clone $b;\n"
},
{
"answer_id": 185939,
"author": "Eran Galperin",
"author_id": 10585,
"author_profile... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185934",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4960/"
] |
185,936 | <p>How can I delete the contents of a local folder in Python?</p>
<p>The current project is for Windows, but I would like to see *nix also.</p>
| [
{
"answer_id": 185941,
"author": "Nick Stinemates",
"author_id": 4960,
"author_profile": "https://Stackoverflow.com/users/4960",
"pm_score": 10,
"selected": true,
"text": "import os, shutil\nfolder = '/path/to/folder'\nfor filename in os.listdir(folder):\n file_path = os.path.join(fol... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185936",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/115/"
] |
185,937 | <p>I ran into an interesting (and very frustrating) issue with the <code>equals()</code> method today which caused what I thought to be a well tested class to crash and cause a bug that took me a very long time to track down. </p>
<p>Just for completeness, I wasn't using an IDE or debugger - just good old fashioned text editor and System.out's. Time was very limited and it was a school project.</p>
<p>Anyhow - </p>
<p>I was developing a basic shopping cart which could contain an <em><code>ArrayList</code> of <code>Book</code> objects</em>. In order to implement the <code>addBook()</code>, <code>removeBook()</code>, and <code>hasBook()</code> methods of the Cart, I wanted to check if the <code>Book</code> already existed in the <code>Cart</code>. So off I go -</p>
<pre><code>public boolean equals(Book b) {
... // More code here - null checks
if (b.getID() == this.getID()) return true;
else return false;
}
</code></pre>
<p>All works fine in testing. I create 6 objects and fill them with data. Do many adds, removes, has() operations on the <code>Cart</code> and everything works fine. I read that you can <em>either have <code>equals(TYPE var)</code> or <code>equals(Object o) { (CAST) var }</code></em> but assumed that since it was working, it didn't matter too much.</p>
<p>Then I ran into a problem - I needed to create a <code>Book</code> object with <em>only</em> the <code>ID</code> in it from within the Book class. No other data would be entered into it. Basically the following:</p>
<pre><code>public boolean hasBook(int i) {
Book b = new Book(i);
return hasBook(b);
}
public boolean hasBook(Book b) {
// .. more code here
return this.books.contains(b);
}
</code></pre>
<p>All of a sudden, the <code>equals(Book b)</code> method no longer works. This took a VERY long time to track down without a good debugger and assuming the <code>Cart</code> class was properly tested and correct. After swaapping the <code>equals()</code> method to the following:</p>
<pre><code>public boolean equals(Object o) {
Book b = (Book) o;
... // The rest goes here
}
</code></pre>
<p>Everything began to work again. Is there a reason the method decided not to take the Book parameter even though it clearly <b> was </b> a <code>Book</code> object? The only difference seemed to be it was instantiated from within the same class, and only filled with one data member. I'm very very confused. Please, shed some light?</p>
| [
{
"answer_id": 185942,
"author": "jjnguy",
"author_id": 2598,
"author_profile": "https://Stackoverflow.com/users/2598",
"pm_score": 9,
"selected": true,
"text": "equals()"
},
{
"answer_id": 186409,
"author": "Community",
"author_id": -1,
"author_profile": "https://Sta... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185937",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10583/"
] |
185,947 | <p>As a programming exercise, I've written a Ruby snippet that creates a class, instantiates two objects from that class, monkeypatches one object, and relies on method_missing to monkeypatch the other one.</p>
<p>Here's the deal. This works as intended:</p>
<pre><code>class Monkey
def chatter
puts "I am a chattering monkey!"
end
def method_missing(m)
puts "No #{m}, so I'll make one..."
def screech
puts "This is the new screech."
end
end
end
m1 = Monkey.new
m2 = Monkey.new
m1.chatter
m2.chatter
def m1.screech
puts "Aaaaaargh!"
end
m1.screech
m2.screech
m2.screech
m1.screech
m2.screech
</code></pre>
<p>You'll notice that I have a parameter for method_missing. I did this because I was hoping to use define_method to dynamically create missing methods with the appropriate name. However, it doesn't work. In fact, even using define_method with a static name like so:</p>
<pre><code>def method_missing(m)
puts "No #{m}, so I'll make one..."
define_method(:screech) do
puts "This is the new screech."
end
end
</code></pre>
<p>Ends with the following result: </p>
<pre><code>ArgumentError: wrong number of arguments (2 for 1)
method method_missing in untitled document at line 9
method method_missing in untitled document at line 9
at top level in untitled document at line 26
Program exited.
</code></pre>
<p>What makes the error message more bewildering is that I only have one argument for <code>method_missing</code>...</p>
| [
{
"answer_id": 185969,
"author": "Avdi",
"author_id": 20487,
"author_profile": "https://Stackoverflow.com/users/20487",
"pm_score": 8,
"selected": true,
"text": "define_method"
},
{
"answer_id": 242106,
"author": "Community",
"author_id": -1,
"author_profile": "https:... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21493/"
] |
185,952 | <p>I know this can be done in IE by creating an ActiveX object, but how do I do it in FF. The navigator.plugins['Adobe Acrobat'] object lets me know if it's installed or not, but it doesn't contain the version number. Any ideas?</p>
| [
{
"answer_id": 186312,
"author": "Allen Pike",
"author_id": 26398,
"author_profile": "https://Stackoverflow.com/users/26398",
"pm_score": 3,
"selected": false,
"text": "navigator.plugins[n].name"
},
{
"answer_id": 277084,
"author": "Community",
"author_id": -1,
"autho... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185952",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16319/"
] |
185,965 | <p>What is the best way to create a custom title for pages in a Rails app without using a plug-in?</p>
| [
{
"answer_id": 185973,
"author": "Avdi",
"author_id": 20487,
"author_profile": "https://Stackoverflow.com/users/20487",
"pm_score": 4,
"selected": false,
"text": "content_for"
},
{
"answer_id": 185978,
"author": "Alan",
"author_id": 17205,
"author_profile": "https://S... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185965",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1632/"
] |
185,966 | <pre><code><div id="myDiv">
<a>...</a>
<a>...</a>
<a>...</a>
<a>...</a>
<a>...</a>
<a>...</a>
</div>
</code></pre>
<p>If you wanted to select the 2nd, 3rd and 4th <code>a</code> tags in the above example, how would you do that? The only thing I can think of is:</p>
<pre><code>$("#myDiv a:eq(1), #myDiv a:eq(2), #myDiv a:eq(3)")
</code></pre>
<p>But that doesn't look to be very efficient or pretty. I guess you could also select ALL the <code>a</code>s and then do run <code>.each</code> over them, but that could get very inefficient if there were a lot more <code>a</code>s.</p>
| [
{
"answer_id": 186018,
"author": "Alexander Prokofyev",
"author_id": 11256,
"author_profile": "https://Stackoverflow.com/users/11256",
"pm_score": 8,
"selected": true,
"text": "$(\"#myDiv a\").slice(1, 4)\n"
},
{
"answer_id": 186034,
"author": "paxdiablo",
"author_id": 14... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9021/"
] |
185,967 | <p><em>Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost any database which has a JDBC driver that can detect foreign-key associations.</em> </p>
<hr>
<p>Querying PostgreSQL data dictionary for foreign-keys and relationship between tables is very straightforward, but how can I use that information to generate a graph of the relations between tables?</p>
<p>Any recommendations about tools that can do this?</p>
<p><strong>EDIT:</strong> I know GraphVIZ/DOT <em>can</em> be useful, however, I don't know have any idea regarding how to code an app that would generate the directed graph .DOT file.</p>
| [
{
"answer_id": 21501326,
"author": "Joe Pineda",
"author_id": 21258,
"author_profile": "https://Stackoverflow.com/users/21258",
"pm_score": 2,
"selected": false,
"text": "SELECT '\"' || Source.TABLE_NAME || '\" -> \"' \n || Destiny.TABLE_NAME || '\";' AS For_GraphViz\nFROM dba_... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185967",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/861/"
] |
185,972 | <p>In javascript, we can do:</p>
<pre><code>["a string", 10, {x : 1}, function() {}].push("another value");
</code></pre>
<p>What is the Scala equivalent?</p>
| [
{
"answer_id": 188235,
"author": "Daniel Spiewak",
"author_id": 9815,
"author_profile": "https://Stackoverflow.com/users/9815",
"pm_score": 6,
"selected": true,
"text": "List"
},
{
"answer_id": 6091792,
"author": "soc",
"author_id": 297776,
"author_profile": "https://... | 2008/10/09 | [
"https://Stackoverflow.com/questions/185972",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20689/"
] |
185,983 | <p>My friend accidentally bought a laptop with Windows Vista Home Basic Edition. He figured out how to install IIS on it, but it doesn't seem to have either the management console or the admin tools. Is there any way for him to configure a site or import an IIS 6 config file?</p>
<p>EDIT: "Windows Vista Home Edition" --> "Windows Vista Home Basic Edition".</p>
| [
{
"answer_id": 186163,
"author": "bugmagnet",
"author_id": 426,
"author_profile": "https://Stackoverflow.com/users/426",
"pm_score": 0,
"selected": false,
"text": "%SystemRoot%\\system32\\inetsrv\\iis.msc"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/185983",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5682/"
] |
186,004 | <p>Specifically, I want to listen to when programs are run and record information such as: timestamp, executable, windows name and user.</p>
| [
{
"answer_id": 186149,
"author": "bugmagnet",
"author_id": 426,
"author_profile": "https://Stackoverflow.com/users/426",
"pm_score": 1,
"selected": false,
"text": "Select * from Win32_Process"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186004",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24416/"
] |
186,015 | <p>I have had to do this several times, usually when trying to find in what files a variable or a function is used.</p>
<p>I remember using xargs with grep in the past to do this, but I am wondering if there are any easier ways.</p>
| [
{
"answer_id": 186020,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 6,
"selected": true,
"text": "grep -r REGEX .\n"
},
{
"answer_id": 186043,
"author": "Darren Greaves",
"author_id": 151,
"author_profil... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25910/"
] |
186,024 | <pre><code>(function()
{
//codehere
}
)();
</code></pre>
<p>What is special about this kind of syntax?
What does ()(); imply?</p>
| [
{
"answer_id": 186030,
"author": "Geoff",
"author_id": 10427,
"author_profile": "https://Stackoverflow.com/users/10427",
"pm_score": 5,
"selected": false,
"text": "function name (){...}\nname();\n"
},
{
"answer_id": 186186,
"author": "artificialidiot",
"author_id": 7988,
... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186024",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21572/"
] |
186,035 | <p>I have a simple "accordion" type page containing a list of H3 headers and DIV content boxes (each H3 is followed by a DIV). On this page I start with all DIVs hidden. When a H3 is clicked the DIV directly below (after) is revealed with jQuery's <a href="http://jquery.com/api/#slideDown" rel="nofollow noreferrer">"slideDown"</a> function while all other DIVs are hidden with the <a href="http://jquery.com/api/#slideUp" rel="nofollow noreferrer">"slideUp"</a> function.</p>
<p>The "slideUp" function inserts the following inline style into the specified DIVs:</p>
<pre><code>style="display: none;"
</code></pre>
<p>I am wondering if there is any way for me to show all the DIVs expanded when a user prints the page (as I do when a user has JavaScript disabled).</p>
<p>I am thinking it is impossible because the inline style will always take precedence over any other style declaration.</p>
<p>Is there another solution?</p>
<p><strong>Solution</strong></p>
<p><a href="https://stackoverflow.com/questions/186035/is-it-possible-to-print-a-div-that-is-hidden-by-jquerys-slideup-function#186189">Sugendran's solution</a> is great and works in the browsers (FF2, IE7 and IE6) I've tested so far. I wasn't aware there was any way to override inline styles which I'm pretty sure is something I've looked up before so this is great to find out. I also see there is <a href="https://stackoverflow.com/questions/104485/is-there-a-way-to-force-a-style-to-a-div-element-which-already-has-a-style-attr#104499">this answer here</a> regarding this. I wish search wasn't so difficult to navigate here :-).</p>
<p><a href="https://stackoverflow.com/questions/186035/is-it-possible-to-print-a-div-that-is-hidden-by-jquerys-slideup-function#186276">Lee Theobald's solution</a> would be great but the "slideUp" function adds the style="display:none;" bit. </p>
<p><a href="https://stackoverflow.com/questions/186035/is-it-possible-to-print-a-div-that-is-hidden-by-jquerys-slideup-function#186036">My solution</a> works fine, but is overkill when the !important declaration works.</p>
| [
{
"answer_id": 186036,
"author": "Matt Mitchell",
"author_id": 364,
"author_profile": "https://Stackoverflow.com/users/364",
"pm_score": 0,
"selected": false,
"text": "$('div#accordion> div').addClass('hideme');\n"
},
{
"answer_id": 186189,
"author": "Sugendran",
"author_... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186035",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/364/"
] |
186,037 | <p>Is there any way to validate the width and height of image when uploaded?
using javascript of server side ? like jsp, aspx etc?</p>
| [
{
"answer_id": 186067,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 2,
"selected": false,
"text": "getHeight"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186037",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25368/"
] |
186,044 | <p>I was developing a web page, where I was laying out a board for a Chess-like game, along with a couple of piece trays. It's all done using HTML (with jQuery for dynamic updating as the game is played). Somewhere I'd got the notion that using absolute positioning of elements within a page was considered a bad practice, and that it was preferable to use relative positioning.</p>
<p>After struggling with relative positioning for too long, I realized that absolute positioning of the board elements would be much, much easier to get right... and it was.</p>
<p>Is anyone aware of a reason that relative positioning is preferable over absolute? Are there any guidelines or rules of thumb that you apply when deciding which approach to take?</p>
| [
{
"answer_id": 186058,
"author": "Ash",
"author_id": 5023,
"author_profile": "https://Stackoverflow.com/users/5023",
"pm_score": 8,
"selected": true,
"text": "<div id=\"parentDIV\" style=\"position:relative\">\n <div id=\"childDIV\" style=\"position:absolute;left:20px;top:20px;\">\n ... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186044",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2193/"
] |
186,062 | <p>Can I create a Controller that simply returns an image asset?</p>
<p>I would like to route this logic through a controller, whenever a URL such as the following is requested:</p>
<pre><code>www.mywebsite.com/resource/image/topbanner
</code></pre>
<p>The controller will look up <code>topbanner.png</code> and send that image directly back to the client.</p>
<p>I've seen examples of this where you have to create a View - I don't want to use a View. I want to do it all with just the Controller.</p>
<p>Is this possible?</p>
| [
{
"answer_id": 186133,
"author": "Ian Suttle",
"author_id": 19421,
"author_profile": "https://Stackoverflow.com/users/19421",
"pm_score": 3,
"selected": false,
"text": "string pathToFile = @\"C:\\Documents and Settings\\some_path.jpg\";\nbyte[] imageData = File.ReadAllBytes(pathToFile);\... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186062",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23341/"
] |
186,071 | <p>I've been profiling some queries in an application I'm working on, and I came across a query that was retrieving more rows than necessary, the result set being trimmed down in the application code.</p>
<p>Changing a LEFT JOIN to an INNER JOIN trimmed the result set to just what was needed, and presumably would also be more performant (since less rows are selected). In reality, the LEFT JOIN'ed query was outperforming the INNER JOIN'ed, taking half the time to complete.</p>
<p>LEFT JOIN: (127 total rows, Query took 0.0011 sec)</p>
<p>INNER JOIN: (10 total rows, Query took 0.0024 sec)</p>
<p>(I ran the queries multiple times and those are averages).</p>
<p>Running EXPLAIN on both reveals nothing that explains the performance differences:</p>
<p>For the INNER JOIN:</p>
<pre><code>id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE contacts index NULL name 302 NULL 235 Using where
1 SIMPLE lists eq_ref PRIMARY PRIMARY 4 contacts.list_id 1
1 SIMPLE lists_to_users eq_ref PRIMARY PRIMARY 8 lists.id,const 1
1 SIMPLE tags eq_ref PRIMARY PRIMARY 4 lists_to_users.tag_id 1
1 SIMPLE users eq_ref email_2 email_2 302 contacts.email 1 Using where
</code></pre>
<p>For the LEFT JOIN:</p>
<pre><code>id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE contacts index NULL name 302 NULL 235 Using where
1 SIMPLE lists eq_ref PRIMARY PRIMARY 4 contacts.list_id 1
1 SIMPLE lists_to_users eq_ref PRIMARY PRIMARY 8 lists.id,const 1
1 SIMPLE tags eq_ref PRIMARY PRIMARY 4 lists_to_users.tag_id 1
1 SIMPLE users eq_ref email_2 email_2 302 contacts.email 1
</code></pre>
<p>And the query itself:</p>
<pre><code>SELECT `contacts`.*, `lists`.`name` AS `group`, `lists`.`id` AS `group_id`, `lists`.`shared_yn`, `tags`.`name` AS `context`, `tags`.`id` AS `context_id`, `tags`.`color` AS `context_color`, `users`.`id` AS `user_id`, `users`.`avatar`
FROM `contacts`
LEFT JOIN `lists` ON lists.id=contacts.list_id
LEFT JOIN `lists_to_users` ON lists_to_users.list_id=lists.id AND lists_to_users.user_id='1' AND lists_to_users.creator='1'
LEFT JOIN `tags` ON tags.id=lists_to_users.tag_id
INNER JOIN `users` ON users.email=contacts.email
WHERE (contacts.user_id='1')
ORDER BY `contacts`.`name` ASC
</code></pre>
<p>(The clause that I'm talking about is the last INNER JOIN on the 'users' table)</p>
<p>The query runs on a MySQL 5.1 database, if it makes a difference.</p>
<p>Does anyone has a clue on why the LEFT JOIN'ed query outperforms the INNER JOIN'ed on in this case?</p>
<p><strong>UPDATE:</strong> Due to Tomalak's suggestion that the small tables I'm using were making the INNER JOIN more complex, I'd created a test database with some mock data. The 'users' table is 5000 rows, and the contacts table is ~500,000 rows. The results are the same (also the timings haven't changed which is surprising when you consider that the tables are much bigger now).</p>
<p>I also ran ANALYZE and OPTIMIZE on the contacts table. Didn't make any discernible difference.</p>
| [
{
"answer_id": 186519,
"author": "mike",
"author_id": 19217,
"author_profile": "https://Stackoverflow.com/users/19217",
"pm_score": -1,
"selected": false,
"text": "SELECT SQL_NO_CACHE `contacts`.*, ...\n"
},
{
"answer_id": 188517,
"author": "Amy B",
"author_id": 8155,
... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186071",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10585/"
] |
186,077 | <p>I'd like to create a sparse file such that all-zero blocks don't take up actual disk space until I write data to them. Is it possible?</p>
| [
{
"answer_id": 193015,
"author": "titaniumdecoy",
"author_id": 18091,
"author_profile": "https://Stackoverflow.com/users/18091",
"pm_score": 4,
"selected": false,
"text": "#include <stdio.h>\n#include <string.h>\n#include <fcntl.h>\n#include <unistd.h>\n\nvoid create_file_with_hole(void)... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186077",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10184/"
] |
186,082 | <p>In my webapplication (C#, .Net 3.5), made up of a <em>core</em> class library (containing the business logic, data layer and a couple of utility classes), a windows service project, a webservice project and the website project, I have a couple of static classes in the <em>core</em> library used by all other projects. These classes (for example the <strong>Log</strong> class) require some initialization (They have an <strong>Initialize</strong> method) in order to set them up for usage. As an example, the <strong>Initialize</strong> method of the <strong>Log</strong> class has a directory path parameter which tells the <strong>Log</strong>, where to save the logfiles to. Alternativly I was thinking of loading the "settings" for the <strong>Log</strong> class from a configuration file in the static constructor. The drawback is, that I need different settings for unit-testing then in production code.</p>
<p>Is there a better way to design this? The drawback of this approach is, that all consumers of the static class will attempt to call Initialize. This is not really a problem because once initialized, the method will return immediately instead of executing the Initialize code again, but the design seems a bit weird to me. </p>
<p>I hope my english is sufficient to explain what I'm after. Do not hesitate to ask if the question is not clear enough.</p>
| [
{
"answer_id": 195763,
"author": "Cem Catikkas",
"author_id": 3087,
"author_profile": "https://Stackoverflow.com/users/3087",
"pm_score": 0,
"selected": false,
"text": "public class Log\n{\n public static void debug(Object o, String message)\n {\n System.out.println(o + \" [... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186082",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16440/"
] |
186,084 | <p>Just this - How do you add a timer to a C# console application? It would be great if you could supply some example coding.</p>
| [
{
"answer_id": 186086,
"author": "Ash",
"author_id": 5023,
"author_profile": "https://Stackoverflow.com/users/5023",
"pm_score": 6,
"selected": false,
"text": "using System; \nusing System.Threading; \npublic static class Program \n{ \n public static void Main() \n { \n Conso... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186084",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3535708/"
] |
186,094 | <p>I'm setting up a simple SQLite database to hold sensor readings. The tables will look something like this:</p>
<pre><code>sensors
- id (pk)
- name
- description
- units
sensor_readings
- id (pk)
- sensor_id (fk to sensors)
- value (actual sensor value stored here)
- time (date/time the sensor sample was taken)
</code></pre>
<p>The application will be capturing about 100,000 sensor readings per month from about 30 different sensors, and I'd like to keep all sensor readings in the DB as long as possible.</p>
<p>Most queries will be in the form</p>
<pre><code>SELECT * FROM sensor_readings WHERE sensor_id = x AND time > y AND time < z
</code></pre>
<p>This query will usually return about 100-1000 results.</p>
<p>So the question is, how big can the sensor_readings table get before the above query becomes too time consuming (more than a couple seconds on a standard PC).</p>
<p>I know that one fix might be to create a separate sensor_readings table for each sensor, but I'd like to avoid this if it is unnecessary. Are there any other ways to optimize this DB schema?</p>
| [
{
"answer_id": 186337,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 2,
"selected": false,
"text": "time"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186094",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10428/"
] |
186,096 | <p>Is there a simple and lightweight program to search over a text file and replace a string with regex?</p>
| [
{
"answer_id": 186116,
"author": "Paul Dixon",
"author_id": 6521,
"author_profile": "https://Stackoverflow.com/users/6521",
"pm_score": 2,
"selected": false,
"text": "sed -e 's/foo/bar/g' input.txt > output.txt\n"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/115/"
] |
186,099 | <p>I many times have to work with directories containing hundreds of thousands of files, doing text matching, replacing and so on. If I go the standard route of, say</p>
<pre><code>grep foo *
</code></pre>
<p>I get the too many files error message, so I end up doing</p>
<pre><code>for i in *; do grep foo $i; done
</code></pre>
<p>or</p>
<pre><code>find ../path/ | xargs -I{} grep foo "{}"
</code></pre>
<p>But these are less than optimal (create a new grep process per each file).</p>
<p>This looks like more of a limitation in the size of the arguments programs can receive, because the * in the for loop works alright. But, in any case, what's the proper way to handle this?</p>
<p>PS: Don't tell me to do grep -r instead, I know about that, I'm thinking about tools that do not have a recursive option.</p>
| [
{
"answer_id": 186167,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 0,
"selected": false,
"text": "for i in *; do\n grep foo $i\ndone\n"
},
{
"answer_id": 186171,
"author": "JesperE",
"author_id": 130... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5190/"
] |
186,106 | <p>I am new to web programming and have been exploring issues related to web security.</p>
<p>I have a form where the user can post two types of data - lets call them "safe" and "unsafe" (from the point of view of sql).</p>
<p>Most places recommend storing both parts of the data in database after sanitizing the "unsafe" part (to make it "safe").</p>
<p>I am wondering about a different approach - to store the "safe" data in database and "unsafe" data in files (outside the database). Ofcourse this approach creates its own set of problems related to maintaining association between files and DB entries. But are there any other major issues with this approach, especially related to security?</p>
<blockquote>
<p>UPDATE: Thanks for the responses! Apologies for not being clear regarding what I am
considering "safe" so some clarification is in order. I am using Django, and the form
data that I am considering "safe" is accessed through the form's "cleaned_data"
dictionary which does all the necessary escaping.</p>
<p>For the purpose of this question, let us consider a wiki page. The title of
wiki page does not need to have any styling attached with it. So, this can be accessed
through form's "cleaned_data" dictionary which will convert the user input to
"safe" format. But since I wish to provide the users the ability to arbitrarily style
their content, I can't perhaps access the content part using "cleaned_data" dictionary.</p>
<p>Does the file approach solve the security aspects of this problem? Or are there other
security issues that I am overlooking?</p>
</blockquote>
| [
{
"answer_id": 186184,
"author": "Paul Dixon",
"author_id": 6521,
"author_profile": "https://Stackoverflow.com/users/6521",
"pm_score": 1,
"selected": false,
"text": "$db->Execute(\"insert into foo(x,y,z) values (?,?,?)\", array($one, $two, $three));\n"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186106",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
186,108 | <p>In a vxWorks Real-Time process, you can pass environment variables as one of the parameter of the <strong>main</strong> routine.</p>
<p>How do you use the environment variables in the kernel context?</p>
| [
{
"answer_id": 186124,
"author": "LeopardSkinPillBoxHat",
"author_id": 22489,
"author_profile": "https://Stackoverflow.com/users/22489",
"pm_score": 3,
"selected": true,
"text": "putenv \"<VARIABLE NAME>=<VALUE>\"\n"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186108",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10703/"
] |
186,125 | <p>I would like to use a secure SSL login on my website! I have not used SSL before, so I am looking for some good reading. Can anyone tell me where I can find some sample code of SSL snippets or page code. (Not too technical)</p>
<ul>
<li>I do have a static IP</li>
<li>My host is set-up to handle SSL Pages. </li>
</ul>
<p>Interested in: Basic page code. / Tree structure. / Other </p>
<p>Paul </p>
| [
{
"answer_id": 186138,
"author": "Matt Mitchell",
"author_id": 364,
"author_profile": "https://Stackoverflow.com/users/364",
"pm_score": 2,
"selected": false,
"text": "if($requireSSL && $_SERVER['SERVER_PORT'] != 443) \n{\n header(\"HTTP/1.1 301 Moved Permanently\");\n header(\"Locat... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186125",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
186,131 | <p>He're an interesting problem that looks for the most Pythonic solution. Suppose I have a list of mappings <code>{'id': id, 'url': url}</code>. Some <code>id</code>s in the list are duplicate, and I want to create a new list, with all the duplicates removed. I came up with the following function:</p>
<pre><code>def unique_mapping(map):
d = {}
for res in map:
d[res['id']] = res['url']
return [{'id': id, 'url': d[id]} for id in d]
</code></pre>
<p>I suppose it's quite efficient. But is there a "more Pythonic" way ? Or perhaps a more efficient way ?</p>
| [
{
"answer_id": 186295,
"author": "DzinX",
"author_id": 18745,
"author_profile": "https://Stackoverflow.com/users/18745",
"pm_score": 3,
"selected": true,
"text": "def unique_mapping(mappings):\n return dict((m['id'], m) for m in mappings).values()\n"
},
{
"answer_id": 186317,
... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186131",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8206/"
] |
186,160 | <p>I have a table in the database that I'm retrieving using LINQ to SQL, and as a part of my processing I want to add to this list, then update the database with the new items + any changes I've made.</p>
<p>What I thought I could do was this:</p>
<pre><code>var list = (from item in db.Table
select item).ToList();
[do processing where I modify items & add to the list]
list = list.Distinct();
db.SubmitChanges();
</code></pre>
<p>What happens is that the modifications happed (ie. SQL updates) but any new items I add to the list don't get added.</p>
<p>Obviously I'm doing this wrong, what is the correct way to modify & add to a list of DB entities, then commit all the updates & inserts?</p>
| [
{
"answer_id": 186221,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 4,
"selected": true,
"text": "Item item;\nif (needNewOne)\n{\n item = new Item();\n db.InsertOnSubmit(item);\n}\nelse\n{\n item = list[i... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186160",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2975/"
] |
186,196 | <p>At the moment I check in all my files (including dll's, VS solution files, images, etc). I often need to checkout these files to a staging server or to a another developer and so having these files there means the project is setup there all ready to go.</p>
<p>Whats the best practice here?</p>
<p>EDIT: If I don't add the generated files like the dll files how do I ensure they are present when updating the staging server?</p>
| [
{
"answer_id": 186253,
"author": "Sietse",
"author_id": 6400,
"author_profile": "https://Stackoverflow.com/users/6400",
"pm_score": 1,
"selected": false,
"text": "mvn eclipse:eclipse"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23230/"
] |
186,202 | <p>What is the most elegant way to solve this:</p>
<ul>
<li>open a file for reading, but only if it is not already opened for writing</li>
<li>open a file for writing, but only if it is not already opened for reading or writing</li>
</ul>
<p>The built-in functions work like this</p>
<pre><code>>>> path = r"c:\scr.txt"
>>> file1 = open(path, "w")
>>> print file1
<open file 'c:\scr.txt', mode 'w' at 0x019F88D8>
>>> file2 = open(path, "w")
>>> print file2
<open file 'c:\scr.txt', mode 'w' at 0x02332188>
>>> file1.write("111")
>>> file2.write("222")
>>> file1.close()
</code></pre>
<p>scr.txt now contains '111'.</p>
<pre><code>>>> file2.close()
</code></pre>
<p>scr.txt was overwritten and now contains '222' (on Windows, Python 2.4).</p>
<p>The solution should work inside the same process (like in the example above) as well as when another process has opened the file.<br>
It is preferred, if a crashing program will not keep the lock open.</p>
| [
{
"answer_id": 186300,
"author": "kender",
"author_id": 4172,
"author_profile": "https://Stackoverflow.com/users/4172",
"pm_score": 0,
"selected": false,
"text": "import time\nclass ExclusiveFile(file):\n openFiles = {}\n fileLocks = []\n\n class FileNotExclusiveException(Except... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186202",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19166/"
] |
186,207 | <p>I've seen that a Processor Pack is available for Visual Studio 6, however it appears to only be available for users with SP5 and I am already using SP6:</p>
<p><em>In addition, the Visual C++ Processor Pack (VCPP) was removed from Service Pack 6. If you have the VCPP installed, installing SP6 will remove it from your machine. If you wish to continue using the VCPP, you will need to stay with SP5 or migrate to Visual Studio 2002 or 2003 (recommended).</em></p>
<p>Firstly, is this processor pack compatible with Visual Studio 6 SP6?</p>
<p>Secondly, would it actually help me? I'm concerned about getting the most from my application, but it needs to run on all flavours of Intel and AMD chips so I can't just target one platform.</p>
| [
{
"answer_id": 3918513,
"author": "b w",
"author_id": 4126,
"author_profile": "https://Stackoverflow.com/users/4126",
"pm_score": 2,
"selected": false,
"text": "latest"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186207",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15669/"
] |
186,208 | <p>What Latex styles do you use and where do you find them?</p>
<p>The reason I'm asking this is that it seems that some 99.9999% of all styles on the internet are copies of each other and of a <a href="http://www.tug.org/texshowcase/ps_s_1b.pdf" rel="noreferrer">physics exam paper</a></p>
<p>However, when you try to find a style for a paper like <a href="http://www.tug.org/texshowcase/en_gb_eclipse_114.pdf" rel="noreferrer">this one</a>... Good luck, you are never going to find it.</p>
<p>Creating your own style is often not really an option, because it requires you to dig quite deep into the very advanced features of TeX/LaTeX and fighting your way against possible incompatibilities with document classes/packages/whatnot.</p>
| [
{
"answer_id": 186452,
"author": "Will Robertson",
"author_id": 4161,
"author_profile": "https://Stackoverflow.com/users/4161",
"pm_score": 4,
"selected": true,
"text": "\\newcommand\\catalogueEntry[4]{%\n \\parbox[t]{0.23\\linewidth}{\\textbf{#1}}%\n \\hfill\n \\parbox[t]{0.23\\linew... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186208",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/445049/"
] |
186,211 | <p>I am using Windows 2003. I have mapped a web application into a virtual directory. This is built on framework 1.1 When i try to browse to the default page i get a error as </p>
<p>Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. </p>
<p>Parser Error Message: Access is denied: 'Interop.MSDASC'.</p>
<p>Source Error: </p>
<p>Line 196:
Line 197:
Line 198:
Line 199:
Line 200: </p>
<p>Source File: c:\windows\microsoft.net\framework\v1.1.4322\Config\machine.config Line: 198 </p>
<p>Assembly Load Trace: The following information can be helpful to determine why the assembly 'Interop.MSDASC' could not be loaded.</p>
| [
{
"answer_id": 186452,
"author": "Will Robertson",
"author_id": 4161,
"author_profile": "https://Stackoverflow.com/users/4161",
"pm_score": 4,
"selected": true,
"text": "\\newcommand\\catalogueEntry[4]{%\n \\parbox[t]{0.23\\linewidth}{\\textbf{#1}}%\n \\hfill\n \\parbox[t]{0.23\\linew... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186211",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20951/"
] |
186,232 | <p>I want to use implicit linking in my project , and nmake really wants a .def file . The problem is , that this is a class , and I don't know what to write in the exports section .
Could anyone point me in the right direction ?</p>
<p>The error message is the following :</p>
<p><strong>NMAKE : U1073: don't know how to make 'DLLCLASS.def'</strong></p>
<p>P.S: I'm trying to build using Windows CE Platform Builder .</p>
| [
{
"answer_id": 186240,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 3,
"selected": false,
"text": "__declspec(dllexport)"
},
{
"answer_id": 186834,
"author": "xtofl",
"author_id": 6610,
"author_profil... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186232",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11234/"
] |
186,237 | <p>I've got a "Schroedinger's Cat" type of problem here -- my program (actually the test suite for my program, but a program nonetheless) is crashing, but only when built in release mode, and only when launched from the command line. Through caveman debugging (ie, nasty printf() messages all over the place), I have determined the test method where the code is crashing, though unfortunately the actual crash seems to happen in some destructor, since the last trace messages I see are in other destructors which execute cleanly.</p>
<p>When I attempt to run this program inside of Visual Studio, it doesn't crash. Same goes when launching from WinDbg.exe. The crash only occurs when launching from the command line. This is happening under Windows Vista, btw, and unfortunately I don't have access to an XP machine right now to test on.</p>
<p>It would be really nice if I could get Windows to print out a stack trace, or <em>something</em> other than simply terminating the program as if it had exited cleanly. Does anyone have any advice as to how I could get some more meaningful information here and hopefully fix this bug?</p>
<p>Edit: The problem was indeed caused by an out-of-bounds array, <a href="https://stackoverflow.com/questions/186237/program-only-crashes-as-release-build-how-to-debug#187966">which I describe more in this post</a>. Thanks everybody for your help in finding this problem!</p>
| [
{
"answer_id": 186247,
"author": "David Dibben",
"author_id": 5022,
"author_profile": "https://Stackoverflow.com/users/5022",
"pm_score": 6,
"selected": false,
"text": "int* p;\n....\nif (p == 0) { // do stuff }\n"
},
{
"answer_id": 186269,
"author": "Franci Penov",
"auth... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186237",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14302/"
] |
186,244 | <p>One of the major advantages with Javascript is said to be that it is a prototype based language. </p>
<p>But what does it mean that Javascript is prototype based, and why is that an advantage?</p>
| [
{
"answer_id": 186368,
"author": "artificialidiot",
"author_id": 7988,
"author_profile": "https://Stackoverflow.com/users/7988",
"pm_score": 3,
"selected": false,
"text": "myobject.prototype=unkownobject;\nmyobject.newproperty=1;\n"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186244",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1918/"
] |
186,277 | <p>In the company where I work we have major releases twice every year. Extensive testing (automated and manual) is done the weeks before.
The automated tests produce logfiles, the results of the manual tests are written down in test plans (Word documents). As you can imagine this results in a lot of different files to be managed and interpreted by the test engineers. <br>
How do you <code>organize</code> your release tests? <br>
E.g. Do use a bug tracker? Do you use any other tools? How do you specify what has to be tested? Who does the testing? How is the ratio developers / testers?</p>
| [
{
"answer_id": 186532,
"author": "Ilya Kochetov",
"author_id": 15329,
"author_profile": "https://Stackoverflow.com/users/15329",
"pm_score": 2,
"selected": false,
"text": "1"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186277",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26395/"
] |
186,307 | <p>A project I'm working on will pull XML from a web-server and build a data store from it. The data will have certain core fields but needs to be extendable... for example I have a and later might want to have which adds extra fields.</p>
<p>In the Flex app, I don't want the central data store to be working on XML objects or simply putting the properties into Objects. I want to have strong types, e.g a Person class, which are created/populated from the XML.</p>
<p>How can this be done in a flexible way? Is Flex able to automatically build a Person from an XML if the attribute names match, or do I need to write conversion functionality for , , etc?</p>
| [
{
"answer_id": 186991,
"author": "Raleigh Buckner",
"author_id": 1153,
"author_profile": "https://Stackoverflow.com/users/1153",
"pm_score": 2,
"selected": false,
"text": "package {\n\n public class Foo{\n\n public function Foo(barparam1:String, barparam2:uint, barparam3:String, bar... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186307",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13220/"
] |
186,311 | <p>I have a list of Date objects, and a target Date. I want to find the date in the list that's nearest to the target date, but only dates that are before the target date.</p>
<p>Example:
2008-10-1
2008-10-2
2008-10-4</p>
<p>With a target date of 2008-10-3, I want to get 2008-10-2</p>
<p>What is the best way to do it?</p>
| [
{
"answer_id": 186318,
"author": "Sietse",
"author_id": 6400,
"author_profile": "https://Stackoverflow.com/users/6400",
"pm_score": 2,
"selected": false,
"text": "private Date getDateNearest(List<Date> dates, Date targetDate){\n for (Date date : dates) {\n if (date.compareTo(targetDa... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186311",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6400/"
] |
186,313 | <p>I'm using the Scriptaculous library to slap an appealing UI on an application which helps an enduser build lists. Let's say its for pizza creation.</p>
<p>To fill out an order, you drag a size of pizza from the pizza palette into the orders droppable. Once it is put in there, it gets replaced with a new div which is both draggable (because you can junk it by moving it back to the palette) and droppable (because you can add ingredients to it). </p>
<p>You can then add ingredients from your ingredients palette to any of the pizzas you have sitting in the group of orders. </p>
<p>I've successfully implemented these bits and everything works fine. The stickler: if I attempt to drag and drop the ingredient from a placed pizza, which is properly marked as draggable and which, for good measure, is z-positioned above the pizza, it instead grabs the pizza wholesale. This makes it impossible for me to undo ingredient selections, which is a key feature for this screen.</p>
<p>Any suggestions on how I can get this to do what I want? Ideally I'd like to keep the simple drag-on, drag-off UI as it is <em>worlds</em> more intuitive than what we were using previously. (A multi-stage HTML form... shudder...)</p>
| [
{
"answer_id": 187094,
"author": "Diodeus - James MacFarlane",
"author_id": 12579,
"author_profile": "https://Stackoverflow.com/users/12579",
"pm_score": 0,
"selected": false,
"text": "<table border=\"1\" cellpadding=\"5\">\n<tr>\n <td valign=\"top\">\n <ul id='fList' style='bo... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186313",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15046/"
] |
186,314 | <p>I am debugging a large, complex web page that has a lot of JavaScript, JQuery, Ajax and so on. Somewhere in that code I am getting a rouge request (I think it is an empty img) that calls the root of the server. I know it is not in the html or the css and am pretty convinced that somewhere in the JavaScript code the reqest is being made, but I can't track it down. I am used to using firebug, VS and other debugging tools but am looking for some way to find out where this is executed - so that I can find the offending line amongst about 150 .js files.</p>
<p>Apart from putting in a gazzillion console outputs of 'you are now here', does anyone have suggestions for a debugging tool that could highlight where in Javascript requests to external resources are made? Any other ideas?</p>
<p>Step by step debugging will take ages - I have to be careful what I step into (jQuery source - yuk!) and I may miss the crucial moment</p>
| [
{
"answer_id": 195652,
"author": "Vincent Robert",
"author_id": 268,
"author_profile": "https://Stackoverflow.com/users/268",
"pm_score": 1,
"selected": false,
"text": "$(document).bind('beforeSend', function(event, request, ajaxOptions)\n{\n // Will be called before every jQuery AJAX ... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3893/"
] |
186,316 | <p>I'm looking at creating a server in python that I can run, and will work as an SSH server. This will then let different users login, and act as if they'd logged in normally, but only had access to one command.</p>
<p>I want to do this so that I can have a system where I can add users to without having to create a system wide account, so that they can then, for example, commit to a VCS branch, or similar.</p>
<p>While I can work out how to do this with conch to get it to a "custom" shell... I can't figure out how to make it so that the SSH stream works as if it were a real one (I'm preferably wanting to limit to /bin/bzr so that bzr+ssh will work.</p>
<p>It needs to be in python (which i can get to do the authorisation) but don't know how to do the linking to the app. </p>
<p>This needs to be in python to work within the app its designed for, and to be able to be used for those without access to add new users</p>
| [
{
"answer_id": 189452,
"author": "Jean-Paul Calderone",
"author_id": 18243,
"author_profile": "https://Stackoverflow.com/users/18243",
"pm_score": 4,
"selected": true,
"text": "ISession.openShell"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186316",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20010/"
] |
186,328 | <p>Which is generally fastest when reading/comparing row info from a DataTable?</p>
<pre><code>'assume dt as datatable'
'method 1'
dim i as int32
for i = 0 to dt.rows.count - 1
....
next
'method 2'
dim row as datarow
for each row in dt.rows
....
next
</code></pre>
<p>And if there's a difference, in what circumstances does it pay to use one over the other? </p>
<p>Thanks in advance for any guidance!</p>
| [
{
"answer_id": 186363,
"author": "Matthew Scharley",
"author_id": 15537,
"author_profile": "https://Stackoverflow.com/users/15537",
"pm_score": 4,
"selected": true,
"text": "for each row in dt.rows\n// expands to:\nIEnumerator e = dt.rows.GetEnumerator()\nwhile e.MoveNext()\n row = e.... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186328",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17235/"
] |
186,338 | <p>Everything I read about better PHP coding practices keeps saying don't use <code>require_once</code> because of speed.</p>
<p>Why is this?</p>
<p>What is the proper/better way to do the same thing as <code>require_once</code>? If it matters, I'm using PHP 5.</p>
| [
{
"answer_id": 186386,
"author": "Oli",
"author_id": 12870,
"author_profile": "https://Stackoverflow.com/users/12870",
"pm_score": 8,
"selected": true,
"text": "require_once"
},
{
"answer_id": 186406,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://St... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/314/"
] |
186,345 | <p>I have a HTML select list with quite a few (1000+) names. I have a javascript in place which will select the first matching name if someone starts typing. This matching looks at the start of the item: </p>
<pre><code>var optionsLength = dropdownlist.options.length;
for (var n=0; n < optionsLength; n++)
{
var optionText = dropdownlist.options[n].text;
if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0)
{
dropdownlist.selectedIndex = n;
return false;
}
}
</code></pre>
<p>The customer would like to have a suggest or autofilter: typing part of a name should 'find' all names containing that part. I've seen a few Google Suggest like options, most using Ajax, but I'd like a pure javascript option, since the select list is already loaded anyway. Pointers anyone?</p>
| [
{
"answer_id": 186393,
"author": "MDCore",
"author_id": 1896,
"author_profile": "https://Stackoverflow.com/users/1896",
"pm_score": 2,
"selected": false,
"text": "if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0)\n"
},
{
"answer_id": 186551,
"author": "cllpse",
... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6399/"
] |
186,385 | <p>Which is the best timer approach for a C# console batch application that has to process as follows:</p>
<ol>
<li>Connect to datasources</li>
<li>process batch until timeout occurs or processing complete. "Do something with datasources"</li>
<li>stop console app gracefully.</li>
</ol>
<p>related question: <a href="https://stackoverflow.com/questions/186084/how-do-you-add-a-timer-to-a-c-console-application">How do you add a timer to a C# console application</a></p>
| [
{
"answer_id": 186439,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 2,
"selected": false,
"text": "List<DataSource> dataSources = ConnectToDataSources();\nTimeSpan timeout = GetTimeoutFromConfiguration(); // Or have it ... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186385",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3535708/"
] |
186,392 | <p>Many database systems don't allow comments or descriptions of tables and fields, so how do you go about documenting the purpose of a table/field apart from the obvious of having good naming conventions?</p>
<p>(Let's assume for now that "excellent" table and field names are not enough to document the full meaning of every table, field and relationship in the database.)</p>
<p>I know many people use UML diagrams to visualize the database, but I have rarely—if ever—seen a UML diagram including field comments. However, I have good experience with using comments inside <code>.sql</code> files. The downside to this approach is that it requires the <code>.sql</code> files to be manually kept up-to-date as the database structure changes over time—but if you do, you can also have it under version control.</p>
<p>Some other techniques I have seen are separate document describing database structure and relationships and manually maintained comments inside ORM code or other database-mapping code.</p>
<p>How have you solved this problem in the past? What methods exists and what are the various pros and cons associated with them? How you would you like this solved in "a perfect world"?</p>
<p><strong>Update</strong></p>
<p>As others have pointed out, most of the popular SQL engines do in fact allow comments, which is great. Oddly enough, people don't seem to be using these features much. At least not on the projects I have been involved with in the past.</p>
| [
{
"answer_id": 25296408,
"author": "hhh",
"author_id": 1853769,
"author_profile": "https://Stackoverflow.com/users/1853769",
"pm_score": 1,
"selected": false,
"text": ".sql"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186392",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1709/"
] |
186,403 | <p>When you create a procedure (or a function) in Oracle PL/SQL, you cannot specify the maximum length of the varchar2 arguments, only the datatype. For example</p>
<pre><code>create or replace procedure testproc(arg1 in varchar2) is
begin
null;
end;
</code></pre>
<p>Do you know the maximum length of a string that you can pass as the arg1 argument to this procedure in Oracle ?</p>
| [
{
"answer_id": 22060657,
"author": "user272735",
"author_id": 272735,
"author_profile": "https://Stackoverflow.com/users/272735",
"pm_score": 2,
"selected": false,
"text": "VARCHAR2"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186403",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20037/"
] |
186,405 | <p>This is a very basic problem that's frustrating me at the moment. Let's say within a single solution, I have two projects. Let's call the first project SimpleMath. It has one header file "Add.h" which has </p>
<pre><code>int add(int i, int j)
</code></pre>
<p>and the implementation "Add.cpp" which has</p>
<pre><code>int add(int i, int j) {
return i+j;
}
</code></pre>
<p>Now let's say in a second project I want to use the add function. However, this code:</p>
<blockquote>
<p><strong>#include "..\SimpleMath\Add.h"</strong></p>
</blockquote>
<pre><code>int main() {
add(1, 2);
}
</code></pre>
<p>results in "unresolved external symbol". How do I get the second program to "know" about the actual implementation in the .cpp file. As a side note all code is fictional this is not how I actually program.</p>
| [
{
"answer_id": 186430,
"author": "korona",
"author_id": 25731,
"author_profile": "https://Stackoverflow.com/users/25731",
"pm_score": 3,
"selected": false,
"text": "int add (int, int)\n"
},
{
"answer_id": 1207013,
"author": "Community",
"author_id": -1,
"author_profil... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186405",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23120/"
] |
186,413 | <p>I need to add a <code>xml:lang</code> attribute on the root xml node in the outbound document from BizTalk.</p>
<p>This is a fixed value, so it may be set in the schema or something.</p>
<p>This is what I want to get out:</p>
<pre><code><Catalog xml:lang="NB-NO">
...
</Catalog>
</code></pre>
<p>I've tried to define the attribute "xml:lang", but it doesn't allow me to use ":" in the schema. </p>
<p>This is the error message I get:</p>
<blockquote>
<p>Invalid 'name' attribute value
'xml:lang': The ':' character,
hexadecimal value 0x3A, at position 3
within the name, cannot be included in
a name.</p>
</blockquote>
<p>Is there another way to insert a ':' as part of the attribute name in BizTalk?</p>
<p>Can anyone tell me how to do this?</p>
<p>I'm using BizTalk 2006 and no orchestration.</p>
| [
{
"answer_id": 186435,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 1,
"selected": false,
"text": "xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" \n"
},
{
"answer_id": 8806322,
"author": "DanMan",
"aut... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
186,422 | <p>we're running in this issue. We're using a web service (using soap4r) to run some kind of searches and the problem appears when the webservice server is down and our aplication is trying to connect to it.
At that point the application is unreachable, and all the customers are blocked.</p>
<p>What can we do to avoid that? Is possibile to block the routing to a mongrel that it is blocked? (I suppose that the apache's proxy uses a round-robin algohritm)</p>
<p>Thanks
Roberto</p>
| [
{
"answer_id": 195681,
"author": "Otto",
"author_id": 9594,
"author_profile": "https://Stackoverflow.com/users/9594",
"pm_score": 0,
"selected": false,
"text": "maintence.html"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22083/"
] |
186,431 | <p>Given a week number, e.g. <code>date -u +%W</code>, how do you calculate the days in that week starting from Monday?</p>
<p>Example rfc-3339 output for week 40:</p>
<pre><code>2008-10-06
2008-10-07
2008-10-08
2008-10-09
2008-10-10
2008-10-11
2008-10-12
</code></pre>
| [
{
"answer_id": 186478,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 7,
"selected": true,
"text": "$week_number = 40;\n$year = 2008;\nfor($day=1; $day<=7; $day++)\n{\n echo date('m/d/Y', strtotime($year.\"W\".$week_number... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186431",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4534/"
] |
186,443 | <p>At the moment I pull data from remote MS SQL Server databases using custom-built JDBC connectors. This works fine but doesn't feel like the way to do it.</p>
<p>I feel I should be able to put a JDBC connection string into tnsnames on the server and have it "just work". I've looked around a little for this functionality but it doesn't seem to be there.</p>
<p>In this way I could connect to pretty much any database just using a database link.</p>
<p>Have I missed something?</p>
<hr>
<p>It looks like the two options are Generic Connectivity and Oracle Gateways but I'm surprised that's all there is. Generic Connectivity comes with the database license and Oracle Gateways is an add-on. For Generic Connectivity, if you're running on Linux (like me) you need to get hold of an ODBC driver as it isn't bundled with the database.</p>
<p>However... with Oracle being such keen Java fans, and with a JVM built-in to the database I'd have thought a JDBC-based linking technology would have been a no-brainer. It seems a natural extension to have a JDBC connection string in TNSNAMES and everything would "just work".</p>
<p>Anyone any ideas why this isn't available?</p>
| [
{
"answer_id": 186811,
"author": "Matthew Watson",
"author_id": 3839,
"author_profile": "https://Stackoverflow.com/users/3839",
"pm_score": 3,
"selected": true,
"text": "select * from mytable@my_ms_sql_server;\n"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186443",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4003/"
] |
186,456 | <p>How do you save data from ExtJS form? Load data from the business layer into form or grid?</p>
| [
{
"answer_id": 195118,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": " // Define the core service page to get the data (we use this when reloading)\n var url = '/pagedata/getbizzbox.ashx?dur... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24938/"
] |
186,472 | <p>I've seen some Python programmers use the following style fairly consistently (we'll call it style 1):</p>
<pre><code>import some_module
# Use some_module.some_identifier in various places.
</code></pre>
<p>For support of this style, you can cite the <a href="http://www.python.org/dev/peps/pep-0020/" rel="nofollow noreferrer">"explicit is better than implicit"</a> maxim. I've seen other programmers use this style (style 2):</p>
<pre><code>from some_module import some_identifier
# Use some_identifier in various places.
</code></pre>
<p>The primary benefit that I see in style 2 is maintainability -- especially with <a href="http://en.wikipedia.org/wiki/Duck_typing" rel="nofollow noreferrer">duck typing</a> ideals I may want to swap some_module for some_other_module. I also feel style 2 wins points with the <a href="http://www.python.org/dev/peps/pep-0020/" rel="nofollow noreferrer">"readability counts"</a> maxim. Although I tend to disagree, one can always argue that search-and-replace is just as good an option when using the first style.</p>
<p><strong>Addendum:</strong> It was noted that you could use <code>as</code> to solve the switch from <code>some_module</code> to <code>some_other_module</code> in style 1. I forgot to mention that it is also common to decide to implement <code>some_identifier</code> in your <em>current</em> module, which makes creation of an equivalent <code>some_module</code> container slightly awkward.</p>
| [
{
"answer_id": 186483,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 3,
"selected": false,
"text": "import some_other_module as some_module\n"
},
{
"answer_id": 186485,
"author": "paxdiablo",
"author_id": ... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186472",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3594/"
] |
186,475 | <p>I would like to use databinding when displaying data in a TextBox. I'm basically doing like:</p>
<pre><code> public void ShowRandomObject(IRandomObject randomObject) {
Binding binding = new Binding {Source = randomObject, Path = new PropertyPath("Name")};
txtName.SetBinding(TextBox.TextProperty, binding);
}
</code></pre>
<p>I can't seem to find a way to unset the binding. I will be calling this method with a lot of different objects but the TextBox will remain the same. Is there a way to remove the previous binding or is this done automatically when I set the new binding?</p>
| [
{
"answer_id": 186479,
"author": "Pop Catalin",
"author_id": 4685,
"author_profile": "https://Stackoverflow.com/users/4685",
"pm_score": 7,
"selected": true,
"text": "BindingOperations.ClearBinding(txtName, TextBox.TextProperty)\n"
},
{
"answer_id": 186877,
"author": "Arcturu... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186475",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/143/"
] |
186,477 | <p>I have a function which parses one string into two strings. In C# I would declare it like this:</p>
<pre><code>void ParseQuery(string toParse, out string search, out string sort)
{
...
}
</code></pre>
<p>and I'd call it like this:</p>
<pre><code>string searchOutput, sortOutput;
ParseQuery(userInput, out searchOutput, out sortOutput);
</code></pre>
<p>The current project has to be done in C++/CLI. I've tried</p>
<pre><code>using System::Runtime::InteropServices;
...
void ParseQuery(String ^ toParse, [Out] String^ search, [Out] String^ sort)
{
...
}
</code></pre>
<p>but if I call it like this:</p>
<pre><code>String ^ searchOutput, ^ sortOutput;
ParseQuery(userInput, [Out] searchOutput, [Out] sortOutput);
</code></pre>
<p>I get a compiler error, and if I call it like this:</p>
<pre><code>String ^ searchOutput, ^ sortOutput;
ParseQuery(userInput, searchOutput, sortOutput);
</code></pre>
<p>then I get an error at runtime. How should I declare and call my function?</p>
| [
{
"answer_id": 187577,
"author": "Bert Huijben",
"author_id": 2094,
"author_profile": "https://Stackoverflow.com/users/2094",
"pm_score": 8,
"selected": true,
"text": "void ReturnString([Out] String^% value)\n{\n value = \"Returned via out parameter\";\n}\n\n// Called as\nString^ resul... | 2008/10/09 | [
"https://Stackoverflow.com/questions/186477",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15371/"
] |
186,493 | <p>I'm trying to write a Mono C# daemon for linux.</p>
<p>I'd like to do a starts and stops of it when its done processing instead of just killing the process.</p>
<p>Does anyone have any examples of this?</p>
<p>Edit: I figured out how to use start-stop-daemon --background in debian, so I think I'll just use that for now.</p>
<p>Edit: I'm implementing this in java as well and they have this nice addShutdownHook that catches terminating the app. I need to spend a little more time sorting out the dependencies for mono service, or find a way to catch app termination. </p>
<p>There is the SessionEnd event, but thats only available for services and not console apps</p>
<p><strong>Answer:</strong>
<a href="https://stackoverflow.com/questions/351971/using-mono-service-to-wrap-a-windows-service-on-linux">using mono-service to wrap a windows service on linux</a></p>
| [
{
"answer_id": 187523,
"author": "David Schmitt",
"author_id": 4918,
"author_profile": "https://Stackoverflow.com/users/4918",
"pm_score": 4,
"selected": false,
"text": "ServiceProcess"
}
] | 2008/10/09 | [
"https://Stackoverflow.com/questions/186493",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/253/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.