qid
int64
4
8.14M
question
stringlengths
20
48.3k
answers
list
date
stringlengths
10
10
metadata
list
input
stringlengths
12
45k
output
stringlengths
2
31.8k
431,391
<p>I have two tables in my database:</p> <p>NEWS table with columns:</p> <ul> <li><code>id</code> - the news id </li> <li><code>user</code> - the user id of the author)</li> </ul> <p>USERS table with columns:</p> <ul> <li><code>id</code> - the user id</li> </ul> <p>I want to execute this SQL: </p> <pre><code>SELE...
[ { "answer_id": 431397, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 8, "selected": true, "text": "<p>You can set aliases for the columns that you are selecting:</p>\n\n<pre><code>$query = 'SELECT news.id AS new...
2009/01/10
[ "https://Stackoverflow.com/questions/431391", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21613/" ]
I have two tables in my database: NEWS table with columns: * `id` - the news id * `user` - the user id of the author) USERS table with columns: * `id` - the user id I want to execute this SQL: ``` SELECT * FROM news JOIN users ON news.user = user.id ``` When I get the results in PHP I would like to get associ...
You can set aliases for the columns that you are selecting: ``` $query = 'SELECT news.id AS newsId, user.id AS userId, [OTHER FIELDS HERE] FROM news JOIN users ON news.user = user.id' ```
431,413
<p>I have extended the standard GridView control in ASP.NET. Basically it is just the same, but paging and sorting is done using callbacks.</p> <p>I have successfully created my own PagerTemplate, but it only works when PagerSettings.Position is set to Top. I want to have the pager at both the top and the bottom.</p> ...
[ { "answer_id": 476672, "author": "Glennular", "author_id": 14753, "author_profile": "https://Stackoverflow.com/users/14753", "pm_score": 0, "selected": false, "text": "<p>Giving it a quick look over, you want to make sure that your header and footer pagers are correctly set to TableRowSe...
2009/01/10
[ "https://Stackoverflow.com/questions/431413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2972/" ]
I have extended the standard GridView control in ASP.NET. Basically it is just the same, but paging and sorting is done using callbacks. I have successfully created my own PagerTemplate, but it only works when PagerSettings.Position is set to Top. I want to have the pager at both the top and the bottom. I get an Http...
This is what works for me.. the PagerRows must be set to their proper sections. I got this tip from <http://www.codeproject.com/Members/iguigova?msg=3153516> (search for MakeAccessible) ``` protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (Rows.Count > 0) { UseAccessible...
431,429
<p>Is there any advantage over using a class over a struct in cases such as these? (note: it will only hold variables, there will never be functions)</p> <pre><code>class Foo { private: struct Pos { int x, y, z }; public: Pos Position; }; </code></pre> <p>Versus:</p> <pre><code>struct Foo { struct...
[ { "answer_id": 431434, "author": "Evan Teran", "author_id": 13430, "author_profile": "https://Stackoverflow.com/users/13430", "pm_score": 6, "selected": true, "text": "<p>There is no real advantage of using one over the other, in c++, the only difference between a struct and a class is t...
2009/01/10
[ "https://Stackoverflow.com/questions/431429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51133/" ]
Is there any advantage over using a class over a struct in cases such as these? (note: it will only hold variables, there will never be functions) ``` class Foo { private: struct Pos { int x, y, z }; public: Pos Position; }; ``` Versus: ``` struct Foo { struct Pos { int x, y, z } Pos; }; ``` --...
There is no real advantage of using one over the other, in c++, the only difference between a struct and a class is the default visibility of it's members (structs default to public, classes default to private). Personally, I tend to prefer structs for POD types and use classes for everything else. EDIT: [litb](https...
431,432
<p>I have a python interpreter embedded inside an application. The application takes a long time to start up and I have no ability to restart the interpreter without restarting the whole application. What I would like to do is to essentially save the state of the interpreter and return to that state easily.</p> <p>I s...
[ { "answer_id": 431460, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<p>One very hacky and bug prone approach might be a c module that simply copies the memory to a file so it can be loaded back ...
2009/01/10
[ "https://Stackoverflow.com/questions/431432", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18909/" ]
I have a python interpreter embedded inside an application. The application takes a long time to start up and I have no ability to restart the interpreter without restarting the whole application. What I would like to do is to essentially save the state of the interpreter and return to that state easily. I started by ...
Try this code from ActiveState recipes: <http://code.activestate.com/recipes/572213/> It extends pickle so it supports pickling anything defined in the shell console. Theoretically you should just be able to pickle the **main** module, according to their documentation: ``` import savestate, pickle, __main__ pickle.du...
431,444
<p>Does anyone know how well F# measures with regards to performance, compared to C#. I have a C# raytracer with a lot of vector manipulations, ray-collission algorithms etc. and thought they might be more easily expressed in F#. I'm not asking for how well F# is at expressing math problems, something which has been an...
[ { "answer_id": 431468, "author": "Chris Smith", "author_id": 322, "author_profile": "https://Stackoverflow.com/users/322", "pm_score": 2, "selected": false, "text": "<p>F# will behave the same as C# for calculations (since it is all just IL). Just sure to represent your vector as a struc...
2009/01/10
[ "https://Stackoverflow.com/questions/431444", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4055/" ]
Does anyone know how well F# measures with regards to performance, compared to C#. I have a C# raytracer with a lot of vector manipulations, ray-collission algorithms etc. and thought they might be more easily expressed in F#. I'm not asking for how well F# is at expressing math problems, something which has been answe...
**Yes, F# will perform better.** Here are some performance results for a single-thread algorithm implemented in different languages (benchmarking activation function approaches for the neural networks): **C#:** ``` 10^7 iterations using Sigmoid1() took 3899,1979 ms 10^7 iterations using Sigmoid2() took 411,4441 ms ...
431,455
<p>I'm using the .NET framework version 6.0 on Windows Vista. I recently installed a program that displays charts. When I open it, I get an error message from the Microsoft .NET framework:</p> <blockquote> <p>Class not registered (exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).</p> </blockquote> <p>How d...
[ { "answer_id": 431468, "author": "Chris Smith", "author_id": 322, "author_profile": "https://Stackoverflow.com/users/322", "pm_score": 2, "selected": false, "text": "<p>F# will behave the same as C# for calculations (since it is all just IL). Just sure to represent your vector as a struc...
2009/01/10
[ "https://Stackoverflow.com/questions/431455", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53729/" ]
I'm using the .NET framework version 6.0 on Windows Vista. I recently installed a program that displays charts. When I open it, I get an error message from the Microsoft .NET framework: > > Class not registered (exception from HRESULT: 0x80040154 (REGDB\_E\_CLASSNOTREG)). > > > How do I fix the problem? Thanks.
**Yes, F# will perform better.** Here are some performance results for a single-thread algorithm implemented in different languages (benchmarking activation function approaches for the neural networks): **C#:** ``` 10^7 iterations using Sigmoid1() took 3899,1979 ms 10^7 iterations using Sigmoid2() took 411,4441 ms ...
431,469
<p>How expensive is it to perform the dereference operation on a pointer?</p> <p>I can imagine that the memory transfer is somehow proportional to the object size, but I want to know how expensive the dereference operation part is.</p>
[ { "answer_id": 431478, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 4, "selected": false, "text": "<p>Dereferencing can be expensive mostly because it costs an instruction to fetch data from memory which might be far away and...
2009/01/10
[ "https://Stackoverflow.com/questions/431469", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25418/" ]
How expensive is it to perform the dereference operation on a pointer? I can imagine that the memory transfer is somehow proportional to the object size, but I want to know how expensive the dereference operation part is.
Dereferencing, when translated into machine code, can mean different things depending on what you do with the dereferenced object. Accessing a single member of a class through a pointer is typically cheap. For example if c is a pointer to an instance of `class C` with an `int` member n then something like this: ``` in...
431,470
<pre> ::GetSystemMetrics (SM_CYBORDER) </pre> <p>...comes back with 1 and I know the title bar is taller than ONE pixel :/</p> <p>I also tried:</p> <pre> RECT r; r.left = r.top = 0; r.right = r.bottom = 400; ::AdjustWindowRect (& r, WS_OVERLAPPED, FALSE); _bdW = (uword)(r.right - r.lef...
[ { "answer_id": 431488, "author": "Head Geek", "author_id": 12193, "author_profile": "https://Stackoverflow.com/users/12193", "pm_score": 4, "selected": false, "text": "<p>I think what you're looking for is <code>SM_CYCAPTION</code> -- that's the height of the title bar. <code>SM_CYBORDER...
2009/01/10
[ "https://Stackoverflow.com/questions/431470", "https://Stackoverflow.com", "https://Stackoverflow.com/users/242756/" ]
``` ::GetSystemMetrics (SM_CYBORDER) ``` ...comes back with 1 and I know the title bar is taller than ONE pixel :/ I also tried: ``` RECT r; r.left = r.top = 0; r.right = r.bottom = 400; ::AdjustWindowRect (& r, WS_OVERLAPPED, FALSE); _bdW = (uword)(r.right - r.left - 400); _b...
The [GetWindowRect](http://msdn.microsoft.com/en-us/library/ms633519(VS.85).aspx) and [GetClientRect](http://msdn.microsoft.com/en-us/library/ms633503(VS.85).aspx) functions can be used calculate the size of all the window borders. Suite101 has a article on [resizing a window and the keeping client area at a know size...
431,485
<p>I need to record a video of a multitouch game I'm working on, and I'd like to record it from the simulator. My idea was to send touches from the device to the simulator (like <a href="http://code.google.com/p/accelerometer-simulator/wiki/Home" rel="nofollow noreferrer">this project</a> does with the accelerometer). ...
[ { "answer_id": 431488, "author": "Head Geek", "author_id": 12193, "author_profile": "https://Stackoverflow.com/users/12193", "pm_score": 4, "selected": false, "text": "<p>I think what you're looking for is <code>SM_CYCAPTION</code> -- that's the height of the title bar. <code>SM_CYBORDER...
2009/01/10
[ "https://Stackoverflow.com/questions/431485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36182/" ]
I need to record a video of a multitouch game I'm working on, and I'd like to record it from the simulator. My idea was to send touches from the device to the simulator (like [this project](http://code.google.com/p/accelerometer-simulator/wiki/Home) does with the accelerometer). Just by googling I haven't found anythin...
The [GetWindowRect](http://msdn.microsoft.com/en-us/library/ms633519(VS.85).aspx) and [GetClientRect](http://msdn.microsoft.com/en-us/library/ms633503(VS.85).aspx) functions can be used calculate the size of all the window borders. Suite101 has a article on [resizing a window and the keeping client area at a know size...
431,494
<p>A <strong>valid</strong> JSON Syntax is something of the kind:</p> <pre><code>{ "username": "admin", "password": "123" } </code></pre> <p>But what if I want to transmit an array of 'users' (<em>given the example</em>), instead of a single 'user' ?</p> <p>Is the code below Valid JSON, according to the specific...
[ { "answer_id": 431500, "author": "Andrew Hare", "author_id": 34211, "author_profile": "https://Stackoverflow.com/users/34211", "pm_score": 5, "selected": true, "text": "<p>Yes, your example is valid JSON - that is exactly how you want to use an array.</p>\n\n<p><strong>Edit</strong> : <a...
2009/01/10
[ "https://Stackoverflow.com/questions/431494", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44084/" ]
A **valid** JSON Syntax is something of the kind: ``` { "username": "admin", "password": "123" } ``` But what if I want to transmit an array of 'users' (*given the example*), instead of a single 'user' ? Is the code below Valid JSON, according to the specifications? ``` [{ "username": "admin", "password": ...
Yes, your example is valid JSON - that is exactly how you want to use an array. **Edit** : [Here is a good link on JSON and its usage.](http://www.json.org/fatfree.html)
431,509
<p>I have a many-to-many relationship between two classes: Tournament and Players</p> <p>I set Cascade.SaveUpdate in the mappings, but when saving a Tournament instance, the Players will not be saved to the Players table. Nhibernate only writes parent and child key columns in the linking table. The DB is SQLite.</p> ...
[ { "answer_id": 784428, "author": "Rob Scott", "author_id": 94707, "author_profile": "https://Stackoverflow.com/users/94707", "pm_score": 3, "selected": false, "text": "<p>Maybe a little (or a lot) late, but nonetheless,</p>\n\n<p>I simplified your example to look like this:</p>\n\n<pre><...
2009/01/10
[ "https://Stackoverflow.com/questions/431509", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53731/" ]
I have a many-to-many relationship between two classes: Tournament and Players I set Cascade.SaveUpdate in the mappings, but when saving a Tournament instance, the Players will not be saved to the Players table. Nhibernate only writes parent and child key columns in the linking table. The DB is SQLite. These are the ...
Maybe a little (or a lot) late, but nonetheless, I simplified your example to look like this: ``` public class Tournament { public virtual Guid Id { get; private set; } private readonly ISet<Player> players; public Tournament() { players = new HashedSet<Player>(); } public virtual I...
431,511
<p>I know this is similar to <a href="https://stackoverflow.com/questions/167576/sql-server-check-if-table-exists">this question</a>, but I'm using SQL Server CE 3.5 with a WinForms project in C#. How can I determine whether a table exists? I know the <code>IF</code> keyword is not supported, though <code>EXISTS</cod...
[ { "answer_id": 431532, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 6, "selected": true, "text": "<p>Yes, it does exist:</p>\n\n<pre><code>SELECT *\nFROM INFORMATION_SCHEMA.TABLES\nWHERE TABLE_NAME = 'TableName'\n</code></pre...
2009/01/10
[ "https://Stackoverflow.com/questions/431511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24566/" ]
I know this is similar to [this question](https://stackoverflow.com/questions/167576/sql-server-check-if-table-exists), but I'm using SQL Server CE 3.5 with a WinForms project in C#. How can I determine whether a table exists? I know the `IF` keyword is not supported, though `EXISTS` is. Does information\_schema exist ...
Yes, it does exist: ``` SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'TableName' ```
431,527
<p>I don't think it is a bug, but I am a bit puzzled as to why that doesn't work. A bonus question is why does it mention variable e? There is no variable e.</p> <pre> Prelude> :m +Control.Exception Prelude Control.Exception> handle (\_-> return "err") undefined &lt;interactive>:1:0: Ambiguous typ...
[ { "answer_id": 431553, "author": "Norman Ramsey", "author_id": 41661, "author_profile": "https://Stackoverflow.com/users/41661", "pm_score": 3, "selected": false, "text": "<p>This problem shows up only in GHC 6.10; it can't be duplicated in GHC 6.8 because the type of <code>handle</code>...
2009/01/10
[ "https://Stackoverflow.com/questions/431527", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5978/" ]
I don't think it is a bug, but I am a bit puzzled as to why that doesn't work. A bonus question is why does it mention variable e? There is no variable e. ``` Prelude> :m +Control.Exception Prelude Control.Exception> handle (\_-> return "err") undefined <interactive>:1:0: Ambiguous type variable ...
The type of `Control.Exception.handle` is: ``` handle :: Exception e => (e -> IO a) -> IO a -> IO a ``` The problem you are seeing is that the lambda expression `(\_ -> return "err")` is not of type `e -> IO a` where `e` is an instance of `Exception`. Clear as mud? Good. Now I'll provide a solution which should actu...
431,533
<p>For my current project I want to be able to load some classes from a dll (which is not always the same, and may not even exist when my app is compiled). There may also be several alternative dll's for a given class (eg an implementation for Direct3D9 and one for OpenGL), but only one of the dlls will be loaded/used ...
[ { "answer_id": 431573, "author": "Ana Betts", "author_id": 5728, "author_profile": "https://Stackoverflow.com/users/5728", "pm_score": 2, "selected": false, "text": "<p>Perhaps you want to look into DLL Delay-Loading (<a href=\"http://www.codeproject.com/KB/DLL/Delay_Loading_Dll.aspx\" r...
2009/01/10
[ "https://Stackoverflow.com/questions/431533", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6266/" ]
For my current project I want to be able to load some classes from a dll (which is not always the same, and may not even exist when my app is compiled). There may also be several alternative dll's for a given class (eg an implementation for Direct3D9 and one for OpenGL), but only one of the dlls will be loaded/used at ...
Easiest way to do this, IMHO, is to have a simple C function that returns a pointer to an interface described elsewhere. Then your app, can call all of the functions of that interface, without actually knowing what class it is using. Edit: Here's a simple example. In your main app code, you create a header for the in...
431,569
<p>Is there a difference or is one better than the other of the following:</p> <pre><code>$var = ''; ... $var .= 'blah blah'; $var .= $var2; $var .= 'blah blah'; </code></pre> <p>Or</p> <pre><code>$var = ''; ... $var .= 'blah blah' . $var2 . 'blah blah'; </code></pre> <p>Is there a speed difference or is there a re...
[ { "answer_id": 431582, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<p>I don't think you'll notice for such a short situation. I typically decide for readability reasons which I'm going to use. ...
2009/01/10
[ "https://Stackoverflow.com/questions/431569", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5441/" ]
Is there a difference or is one better than the other of the following: ``` $var = ''; ... $var .= 'blah blah'; $var .= $var2; $var .= 'blah blah'; ``` Or ``` $var = ''; ... $var .= 'blah blah' . $var2 . 'blah blah'; ``` Is there a speed difference or is there a reason why you'd pick one over the other?
There is a small difference if you echo the string. ``` echo $var1,$var2,$var3 // comma (echo with multiple arguments) ``` is slightly faster than ``` echo $var1.$var2.$var3 // dot (concat and echo) ```
431,579
<p>Does anybody know of a pure java (ar at least cross platform) open source component/library which displays HTML which can contain swing components inside it?</p> <p>All I could find were either abandoned or incomplete.</p> <p>I am asking because I'm thinking about trying out approach to do use this combination for...
[ { "answer_id": 431853, "author": "kenoa", "author_id": 53770, "author_profile": "https://Stackoverflow.com/users/53770", "pm_score": 2, "selected": false, "text": "<p>I think the question is the other way around or, better, goes further than using JTextPane. As I understand the question:...
2009/01/10
[ "https://Stackoverflow.com/questions/431579", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31141/" ]
Does anybody know of a pure java (ar at least cross platform) open source component/library which displays HTML which can contain swing components inside it? All I could find were either abandoned or incomplete. I am asking because I'm thinking about trying out approach to do use this combination for creating desktop...
I think the question is the other way around or, better, goes further than using JTextPane. As I understand the question: Marko needs a Java component that can display HTML and additionally is able to contain further Swing components. Say, there should be a new tag ``` <swing jclass="MySwingComponent" /> ``` which ...
431,616
<p>Trying to find an XML file I can use in lieu of a look-up database table until we get our web hosting switched over to the right DB.</p> <p>Can anyone refer me to an XML file with elements whose children have zipcodes, states, and cities? E.g.:</p> <pre><code>&lt;zip code="98117"&gt; &lt;state&gt;WA&lt;/state&...
[ { "answer_id": 431625, "author": "Tom Anderson", "author_id": 13502, "author_profile": "https://Stackoverflow.com/users/13502", "pm_score": 2, "selected": true, "text": "<p>Check out this one, it provides several different free ones.</p>\n\n<p><a href=\"https://stackoverflow.com/question...
2009/01/10
[ "https://Stackoverflow.com/questions/431616", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11574/" ]
Trying to find an XML file I can use in lieu of a look-up database table until we get our web hosting switched over to the right DB. Can anyone refer me to an XML file with elements whose children have zipcodes, states, and cities? E.g.: ``` <zip code="98117"> <state>WA</state> <city>Seattle</state> </zip> `...
Check out this one, it provides several different free ones. <https://stackoverflow.com/questions/24471/zip-code-database>
431,617
<p>Is there any way of overriding a model's id value on create? Something like:</p> <pre><code>Post.create(:id =&gt; 10, :title =&gt; 'Test') </code></pre> <p>would be ideal, but obviously won't work.</p>
[ { "answer_id": 431737, "author": "PJ Davis", "author_id": 39077, "author_profile": "https://Stackoverflow.com/users/39077", "pm_score": 5, "selected": false, "text": "<p>Try </p>\n\n<pre><code>a_post = Post.new do |p| \n p.id = 10\n p.title = 'Test'\n p.save\nend\n</code></pre>\n\n<p>...
2009/01/10
[ "https://Stackoverflow.com/questions/431617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12037/" ]
Is there any way of overriding a model's id value on create? Something like: ``` Post.create(:id => 10, :title => 'Test') ``` would be ideal, but obviously won't work.
id is just attr\_protected, which is why you can't use mass-assignment to set it. However, when setting it manually, it just works: ``` o = SomeObject.new o.id = 8888 o.save! o.reload.id # => 8888 ``` I'm not sure what the original motivation was, but I do this when converting ActiveHash models to ActiveRecord. Acti...
431,623
<p>I'm working on designing a multi-tiered app in Perl and I'm wondering about the pros and cons of the various IPC mechnisms available to me. I'm looking at handling moderately-sized data, typically a few dozen kilobytes but up to a couple of megabytes, and the load is pretty light, at most a couple of hundred reques...
[ { "answer_id": 431653, "author": "BobbyShaftoe", "author_id": 38426, "author_profile": "https://Stackoverflow.com/users/38426", "pm_score": 2, "selected": false, "text": "<p>Temporary files have other problems besides that. I think Internet socks are really the best choice. They are well...
2009/01/10
[ "https://Stackoverflow.com/questions/431623", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21632/" ]
I'm working on designing a multi-tiered app in Perl and I'm wondering about the pros and cons of the various IPC mechnisms available to me. I'm looking at handling moderately-sized data, typically a few dozen kilobytes but up to a couple of megabytes, and the load is pretty light, at most a couple of hundred requests p...
Temporary files (and related things, like a shared memory region), are probably a bad bet. If you ever want to run your server on one machine and your clients on another, you will need to rewrite your application. If you pick any of the other options, at least the semantics are the essentially the same, if you need to ...
431,628
<p>I am trying to build the search for a Django site I am building, and in that search, I am searching in three different models. And to get pagination on the search result list, I would like to use a generic object_list view to display the results. But to do that, I have to merge three querysets into one.</p> <p>How c...
[ { "answer_id": 431900, "author": "Carl Meyer", "author_id": 3207, "author_profile": "https://Stackoverflow.com/users/3207", "pm_score": 5, "selected": false, "text": "<p>The big downside of your current approach is its inefficiency with large search result sets, as you have to pull down ...
2009/01/10
[ "https://Stackoverflow.com/questions/431628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42546/" ]
I am trying to build the search for a Django site I am building, and in that search, I am searching in three different models. And to get pagination on the search result list, I would like to use a generic object\_list view to display the results. But to do that, I have to merge three querysets into one. How can I do ...
Concatenating the querysets into a list is the simplest approach. If the database will be hit for all querysets anyway (e.g. because the result needs to be sorted), this won't add further cost. ``` from itertools import chain result_list = list(chain(page_list, article_list, post_list)) ``` Using `itertools.chain` i...
431,635
<p>I'm using Grails 1.1 beta2. I need to import a large amount of data into my Grails application. If I repeatedly instantiate a grails domain class and then save it, the performance is unacceptably slow. Take for example importing people from a phone book:</p> <pre><code>for (each person in legacy phone book) { /...
[ { "answer_id": 431828, "author": "Gareth Davis", "author_id": 31480, "author_profile": "https://Stackoverflow.com/users/31480", "pm_score": 5, "selected": true, "text": "<p>This is a common issue with all hibernate applications and it is caused by the growth of the hibernate session. I'm...
2009/01/10
[ "https://Stackoverflow.com/questions/431635", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24396/" ]
I'm using Grails 1.1 beta2. I need to import a large amount of data into my Grails application. If I repeatedly instantiate a grails domain class and then save it, the performance is unacceptably slow. Take for example importing people from a phone book: ``` for (each person in legacy phone book) { // Construct ne...
This is a common issue with all hibernate applications and it is caused by the growth of the hibernate session. I'm guessing that the grails console holds a hibernate session open for you in a similar way to the 'open session in view' pattern that I know it uses in for normal web requests. The solution is to get hold...
431,642
<p>I'm trying to pass an instance of a class between two separate classes, like the following. </p> <pre><code>//classes public class A { public string name; public string data; } public class B : MarshalByRefObject { public A _a; } public class C : MarshalByRefObject { public A _a; } //main program static...
[ { "answer_id": 431671, "author": "leppie", "author_id": 15541, "author_profile": "https://Stackoverflow.com/users/15541", "pm_score": 2, "selected": true, "text": "<p>I recently had a similar issue (ensuring a singleton boxed valuetype after deserialization).</p>\n\n<p>To remedy my issue...
2009/01/10
[ "https://Stackoverflow.com/questions/431642", "https://Stackoverflow.com", "https://Stackoverflow.com/users/194/" ]
I'm trying to pass an instance of a class between two separate classes, like the following. ``` //classes public class A { public string name; public string data; } public class B : MarshalByRefObject { public A _a; } public class C : MarshalByRefObject { public A _a; } //main program static void Main(stri...
I recently had a similar issue (ensuring a singleton boxed valuetype after deserialization). To remedy my issue, I had to use ISerializationSurrogate and SurrogateSelector to fix up the reference and not let it get reboxed.
431,652
<p>I'm doing a project in seam that requires restful URLs. I have a view that is mapped to /group/{group}/{locale}. On that page I have a list of so called messages. Each message has a button to save changes to the message. This is linked to an action bean like this:</p> <pre><code>&lt;h:commandButton type="submit" va...
[ { "answer_id": 434857, "author": "Matthias van der Vlies", "author_id": 53702, "author_profile": "https://Stackoverflow.com/users/53702", "pm_score": 1, "selected": false, "text": "<p>OK, I managed to kill the redirect-filter by adding this to my compononents.xml:</p>\n\n<pre><code>&lt;w...
2009/01/10
[ "https://Stackoverflow.com/questions/431652", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53702/" ]
I'm doing a project in seam that requires restful URLs. I have a view that is mapped to /group/{group}/{locale}. On that page I have a list of so called messages. Each message has a button to save changes to the message. This is linked to an action bean like this: ``` <h:commandButton type="submit" value="Save Changes...
I've worked out where the unwanted `conversationId` query string parameter is coming from. The `<redirect/>` results in a call to `org.jboss.seam.faces.FacesManager.redirect(String viewId, Map<String, Object> parameters, boolean includeConversationId)` This is called from the following code in `org.jboss.seam.face...
431,658
<p>I'm still learning about REST and, in my test, came up with this scenario I don't know how to deal with.</p> <p>I have an existing sample WCF service which uses Linq-to-Sql. Its a tremendously simple database with a single table called "Tasks" which has four fields: Id, Description, IsCompleted, and EnteredDate. (...
[ { "answer_id": 431742, "author": "Tom", "author_id": 8969, "author_profile": "https://Stackoverflow.com/users/8969", "pm_score": 0, "selected": false, "text": "<p>I think <a href=\"https://stackoverflow.com/questions/430809/rest-interface-for-finding-average\">this</a> pretty much descri...
2009/01/10
[ "https://Stackoverflow.com/questions/431658", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42620/" ]
I'm still learning about REST and, in my test, came up with this scenario I don't know how to deal with. I have an existing sample WCF service which uses Linq-to-Sql. Its a tremendously simple database with a single table called "Tasks" which has four fields: Id, Description, IsCompleted, and EnteredDate. (I mentioned...
Results: I finally found a [nice blog post](http://blog.donnfelker.com/post/How-To-REST-Services-in-WCF-35-Part-2-The-POST.aspx) that helped me resolve this. It turns out I was pretty much doing things correctly but I was putting the test into Fiddler improperly. I also added a few more details to my attribute. ``` [...
431,672
<p>I have a project which I want to translate into multiple languages for the PHP Part I use Zend Frameworks Zend_Translate with GetText. Now I want to translate the JS part too.</p> <p>I am using the jQuery JS Framework and would love to hear your thoughts on translation for JS files</p>
[ { "answer_id": 431693, "author": "Thomaschaaf", "author_id": 19929, "author_profile": "https://Stackoverflow.com/users/19929", "pm_score": -1, "selected": false, "text": "<p><a href=\"http://plugins.jquery.com/project/jquery-localize\" rel=\"nofollow noreferrer\">http://plugins.jquery.co...
2009/01/10
[ "https://Stackoverflow.com/questions/431672", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19929/" ]
I have a project which I want to translate into multiple languages for the PHP Part I use Zend Frameworks Zend\_Translate with GetText. Now I want to translate the JS part too. I am using the jQuery JS Framework and would love to hear your thoughts on translation for JS files
I have successfully used GetText for translation of JavaScript files in three projects. Of course GetText natively doesn't support JavaScript and JavaScript also doesn't support GetText. My solution has been the following. * In JavaScript I surround translatable strings with `gettext("your text here")`. * Then I have...
431,684
<p><code>cd</code> is the shell command to change the working directory.</p> <p>How do I change the current working directory in Python?</p>
[ { "answer_id": 431694, "author": "PEZ", "author_id": 44639, "author_profile": "https://Stackoverflow.com/users/44639", "pm_score": 4, "selected": false, "text": "<p><code>os.chdir()</code> is the Pythonic version of <code>cd</code>.</p>\n" }, { "answer_id": 431695, "author": ...
2009/01/10
[ "https://Stackoverflow.com/questions/431684", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28835/" ]
`cd` is the shell command to change the working directory. How do I change the current working directory in Python?
You can change the working directory with: ```py import os os.chdir(path) ``` There are two best practices to follow when using this method: 1. Catch the exception (WindowsError, OSError) on invalid path. If the exception is thrown, do not perform any recursive operations, especially destructive ones. They will op...
431,714
<p>I am searching for a proof that all AVL trees can be colored like a red-black tree? Can anyone give the proof?</p>
[ { "answer_id": 679290, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "<p>I suspect the answer is no.</p>\n\n<p>AVL trees balance better than RB trees, which means they balance differently, which ...
2009/01/10
[ "https://Stackoverflow.com/questions/431714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am searching for a proof that all AVL trees can be colored like a red-black tree? Can anyone give the proof?
By definition R/B trees can be slightly less balanced then AVL-s, as |maxPath - minPath| must be <= 1 for AVLs and maxPath <= 2 \* minPath for R/Bs so that not every R/B is an AVL but on the other hand there is no need for the AVL-s To have Empty subTrees so ``` 4 / \ 3 6 /\ /\ 1 E 5 8 ``` is a...
431,719
<p>I was told by a rather smart person that you cannot implement garbage collection in C because of it's weakly typed. The basic idea seems to be that C gives you too much freedom. He mentioned casting pointers without type checking...</p> <p>I don't really grok the idea. Can someone give me an explanation and possibl...
[ { "answer_id": 431724, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 6, "selected": true, "text": "<p>He probably referred to the fact that you can cast a pointer to an int and back to the original pointer type. It's pretty mu...
2009/01/10
[ "https://Stackoverflow.com/questions/431719", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36706/" ]
I was told by a rather smart person that you cannot implement garbage collection in C because of it's weakly typed. The basic idea seems to be that C gives you too much freedom. He mentioned casting pointers without type checking... I don't really grok the idea. Can someone give me an explanation and possibly a code s...
He probably referred to the fact that you can cast a pointer to an int and back to the original pointer type. It's pretty much impossible for a GC to clean up correctly when you do that, consider: ``` char * p = (char *) malloc(16); int i = (int) p; p = 0; // GC runs and finds that the memory is no longer referenced p...
431,736
<p>i want to write a script to manipulate the dhcp.conf file. which in the sense, it has to read the file and it should ping all the lease IP and should give another text file, in which it should give the list of IPs, which devices are now existing.</p> <p>EDIT: thanks for your swift reply. dhcpd.conf file is like thi...
[ { "answer_id": 431855, "author": "derobert", "author_id": 27727, "author_profile": "https://Stackoverflow.com/users/27727", "pm_score": 1, "selected": false, "text": "<h1>Assumptions</h1>\n\n<p>First, there are two things you need to be aware of:</p>\n\n<ul>\n<li>Not all devices respond ...
2009/01/10
[ "https://Stackoverflow.com/questions/431736", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
i want to write a script to manipulate the dhcp.conf file. which in the sense, it has to read the file and it should ping all the lease IP and should give another text file, in which it should give the list of IPs, which devices are now existing. EDIT: thanks for your swift reply. dhcpd.conf file is like this ``` lea...
Assumptions =========== First, there are two things you need to be aware of: * Not all devices respond to ping. Quite a few PC firewalls disable ping replies. If you're on Ethernet, `arping` can be used instead and will even detect firewalled PCs. * dhcpd leaves leases in the file which it /knows/ are no longer valid...
431,738
<p>I am working on an django application that will return what historically was a table of information:</p> <pre><code>ISSUE DESCRIPTION INITIATOR INITIATEDDATE ASSIGNEE FORECASTDATE STATUS REMARKS </code></pre> <p>That will be the entrance point for users to sort / filter, etc the list of issues.<br> The colu...
[ { "answer_id": 431798, "author": "Jarrod Dixon", "author_id": 3, "author_profile": "https://Stackoverflow.com/users/3", "pm_score": 2, "selected": false, "text": "<p>If the information you're trying to display is tabular (as it appears to be), then go with tables.</p>\n\n<p>Also, see the...
2009/01/10
[ "https://Stackoverflow.com/questions/431738", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40529/" ]
I am working on an django application that will return what historically was a table of information: ``` ISSUE DESCRIPTION INITIATOR INITIATEDDATE ASSIGNEE FORECASTDATE STATUS REMARKS ``` That will be the entrance point for users to sort / filter, etc the list of issues. The columns like ISSUE, DATES, NAME...
The whole argument made by the CSS purists is that you need to keep your code semantically relevant to the information it contains. What you need to show is tabular data and you use the `<table>` tag to do that. The only "problem" with tables is when they are used to control the layout, like making your two column layo...
431,752
<p>When I'm moving through a file with a csv.reader, how do I return to the top of the file. If I were doing it with a normal file I could just do something like "file.seek(0)". Is there anything like that for the csv module?</p> <p>Thanks ahead of time ;)</p>
[ { "answer_id": 431767, "author": "Evan Fosmark", "author_id": 49701, "author_profile": "https://Stackoverflow.com/users/49701", "pm_score": 4, "selected": false, "text": "<p>You can still use file.seek(0). For instance, look at the following:</p>\n\n<pre><code>import csv\nfile_handle = o...
2009/01/10
[ "https://Stackoverflow.com/questions/431752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41718/" ]
When I'm moving through a file with a csv.reader, how do I return to the top of the file. If I were doing it with a normal file I could just do something like "file.seek(0)". Is there anything like that for the csv module? Thanks ahead of time ;)
You can seek the file directly. For example: ``` >>> f = open("csv.txt") >>> c = csv.reader(f) >>> for row in c: print row ['1', '2', '3'] ['4', '5', '6'] >>> f.seek(0) >>> for row in c: print row # again ['1', '2', '3'] ['4', '5', '6'] ```
431,755
<p>I'd like to know if there is any .Net class that allows me to know the SSID of the wireless network I'm connected to. So far I only found the library linked below. Is the best I can get or should I use something else? <a href="http://www.codeplex.com/managedwifi" rel="noreferrer">Managed WiFi</a> (<a href="http://ww...
[ { "answer_id": 431770, "author": "ine", "author_id": 4965, "author_profile": "https://Stackoverflow.com/users/4965", "pm_score": 2, "selected": false, "text": "<p>It looks like this will do what you want:</p>\n\n<pre><code>ManagementObjectSearcher searcher = new ManagementObjectSearcher(...
2009/01/10
[ "https://Stackoverflow.com/questions/431755", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53759/" ]
I'd like to know if there is any .Net class that allows me to know the SSID of the wireless network I'm connected to. So far I only found the library linked below. Is the best I can get or should I use something else? [Managed WiFi](http://www.codeplex.com/managedwifi) (<http://www.codeplex.com/managedwifi>) The metho...
I resolved using the library. It resulted to be quite easy to work with the classes provided: First I had to create a WlanClient object ``` wlan = new WlanClient(); ``` And then I can get the list of the SSIDs the PC is connected to with this code: ``` Collection<String> connectedSsids = new Collection<string>(); ...
431,759
<p>If you type <em>systeminfo</em> at the command prompt, there is a listing for <em>Product ID</em>. Can someone explain what this is exactly, and would it make a good seed for a registration code algorithm?</p>
[ { "answer_id": 431770, "author": "ine", "author_id": 4965, "author_profile": "https://Stackoverflow.com/users/4965", "pm_score": 2, "selected": false, "text": "<p>It looks like this will do what you want:</p>\n\n<pre><code>ManagementObjectSearcher searcher = new ManagementObjectSearcher(...
2009/01/10
[ "https://Stackoverflow.com/questions/431759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
If you type *systeminfo* at the command prompt, there is a listing for *Product ID*. Can someone explain what this is exactly, and would it make a good seed for a registration code algorithm?
I resolved using the library. It resulted to be quite easy to work with the classes provided: First I had to create a WlanClient object ``` wlan = new WlanClient(); ``` And then I can get the list of the SSIDs the PC is connected to with this code: ``` Collection<String> connectedSsids = new Collection<string>(); ...
431,785
<p>If all I want to do is throw the exception up a level when it occurs? </p> <pre><code>private void TryCatch() { try { foo(); } catch (Exception ex) { throw; } } private void NoTryCatch() { foo(); } </code></pre> <p>Aren't these two methods the same? </p> <p>If an exception occu...
[ { "answer_id": 431786, "author": "Otávio Décio", "author_id": 48684, "author_profile": "https://Stackoverflow.com/users/48684", "pm_score": 1, "selected": false, "text": "<p>These two methods are essentially the same. In this case ReSharper was correct with its suggestion.</p>\n" }, ...
2009/01/10
[ "https://Stackoverflow.com/questions/431785", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
If all I want to do is throw the exception up a level when it occurs? ``` private void TryCatch() { try { foo(); } catch (Exception ex) { throw; } } private void NoTryCatch() { foo(); } ``` Aren't these two methods the same? If an exception occurs in TryCatch it will be thrown ...
Yes, those methods are pretty much (\*) the same. The only difference is that it's easy to put a breakpoint in the first one. I'd always go with the second unless I really needed to break there and only there (as opposed to immediately any exceptions of that type were thrown, which would be easy). Even if I ever used t...
431,797
<p>I've looked through all the class documentation for Core Data and I can't find away to programmatically update values in a core data entity. For example, I have a structure similar to this:</p> <pre><code> id | title ============ 1 | Foo 2 | Bar 3 | FooFoo </code></pre> <p>Say that I want to update B...
[ { "answer_id": 431864, "author": "Evan DiBiase", "author_id": 2399475, "author_profile": "https://Stackoverflow.com/users/2399475", "pm_score": 6, "selected": true, "text": "<p>The <a href=\"http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CoreData/Articles/cdUsingMOs.html\" rel...
2009/01/10
[ "https://Stackoverflow.com/questions/431797", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46540/" ]
I've looked through all the class documentation for Core Data and I can't find away to programmatically update values in a core data entity. For example, I have a structure similar to this: ``` id | title ============ 1 | Foo 2 | Bar 3 | FooFoo ``` Say that I want to update Bar to BarBar, I can't find...
The [Apple documentation on using managed objects in Core Data](http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CoreData/Articles/cdUsingMOs.html) likely has your answer. In short, though, you should be able to do something like this: ``` NSError *saveError; [bookTwo setTitle:@"BarBar"]; if (![managedObjectC...
431,821
<p>I'm attempting to install a MYSQL driven .net application to a Windows XP sp2 machine. The development machine is the same OS. The application and all connectivity work fine on my machine (the developers mantra), but I receive the following error on the installation machine when attempting to connect to the database...
[ { "answer_id": 431859, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 1, "selected": false, "text": "<pre><code>Keyword not supported. Parameter name: command logging\n</code></pre>\n\n<p>This appears to be the relevant...
2009/01/10
[ "https://Stackoverflow.com/questions/431821", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm attempting to install a MYSQL driven .net application to a Windows XP sp2 machine. The development machine is the same OS. The application and all connectivity work fine on my machine (the developers mantra), but I receive the following error on the installation machine when attempting to connect to the database. ...
``` Keyword not supported. Parameter name: command logging ``` This appears to be the relevant part. The MySQL connection DSN is constructed from parameters which I guess are in your UDL file. Only certain parameters are meaningful to a MySQL DSN, and unrecognized parameters will cause errors like this. In this cas...
431,825
<p>For my university assignment I have to design some basic managment system for sicknesses and all for a school. I have decided to model some basic inheritance in the form of </p> <ul> <li>Person --> Student</li> <li>Person --> Staff</li> <li>Person --> Guardian</li> </ul> <p>Person (PersonID, FirstName, LastName)</...
[ { "answer_id": 431837, "author": "Otávio Décio", "author_id": 48684, "author_profile": "https://Stackoverflow.com/users/48684", "pm_score": 1, "selected": false, "text": "<p>This is not right. You should have a Person class, and other classes would determine that a certain Person is a St...
2009/01/10
[ "https://Stackoverflow.com/questions/431825", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50913/" ]
For my university assignment I have to design some basic managment system for sicknesses and all for a school. I have decided to model some basic inheritance in the form of * Person --> Student * Person --> Staff * Person --> Guardian Person (PersonID, FirstName, LastName) Student (StudentID (Which references the P...
I have no problem with the database design you've described. It's always a bit awkward to model inheritance in SQL, but you've used the least problematic solution. Here's a query to answer your question about retrieving the names of a student and staff member for a given incident: ``` SELECT ps.FirstName, ps.LastName...
431,826
<p>I'm following along with <a href="https://stackoverflow.com/questions/319463/can-i-make-post-or-get-requests-from-an-iphone-application#322573">this useful looking answer to my question</a>.</p> <p>It seems to be working, but here are two questions I have:</p> <ol> <li>How do I detect an HTTP error? The didFailWi...
[ { "answer_id": 431984, "author": "Adam Rosenfield", "author_id": 9530, "author_profile": "https://Stackoverflow.com/users/9530", "pm_score": 2, "selected": false, "text": "<p>Yes, you need to release that object. See the <a href=\"http://developer.apple.com/documentation/Cocoa/Conceptua...
2009/01/10
[ "https://Stackoverflow.com/questions/431826", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13009/" ]
I'm following along with [this useful looking answer to my question](https://stackoverflow.com/questions/319463/can-i-make-post-or-get-requests-from-an-iphone-application#322573). It seems to be working, but here are two questions I have: 1. How do I detect an HTTP error? The didFailWithError method doesn't seem to b...
You will get the status code returned in the didReceiveResponse ``` -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ NSHTTPURLResponse *httpResponse; httpResponse = (NSHTTPURLResponse *)response; int statusCode = [httpResponse statusCode]; //statusCode will ...
431,840
<p>I'm binding a GridView to an LINQ query. Some of the fields in the objects created by the LINQ statement are strings, and need to contain new lines.</p> <p>Apparently, GridView HTML-encodes everything in each cell, so I can't insert a &lt;br /&gt; to create a new line within a cell.</p> <p>How do I tell GridView n...
[ { "answer_id": 431857, "author": "Ray Booysen", "author_id": 42124, "author_profile": "https://Stackoverflow.com/users/42124", "pm_score": 7, "selected": true, "text": "<p>Can you subscribe to the RowDataBound event? If you can, you can run:</p>\n\n<pre><code>if (e.Row.RowType == DataCo...
2009/01/10
[ "https://Stackoverflow.com/questions/431840", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11574/" ]
I'm binding a GridView to an LINQ query. Some of the fields in the objects created by the LINQ statement are strings, and need to contain new lines. Apparently, GridView HTML-encodes everything in each cell, so I can't insert a <br /> to create a new line within a cell. How do I tell GridView not to HTML encode the c...
Can you subscribe to the RowDataBound event? If you can, you can run: ``` if (e.Row.RowType == DataControlRowType.DataRow) { string decodedText = HttpUtility.HtmlDecode(e.Row.Cells[0].Text); e.Row.Cells[0].Text = decodedText; } ```
431,861
<p>I have a snippet of code that I'm working with to filter rows in a table. It works perfectly in every browser other than Firefox v3.0.x (works fine with 3.1 beta 2). When I run the snippet in Firefox 3.0.x, it says that <code>children is undefined</code>. I am using jQuery v1.2.6 also.</p> <p>Code Snippet:</p> ...
[ { "answer_id": 431870, "author": "John Boker", "author_id": 2847, "author_profile": "https://Stackoverflow.com/users/2847", "pm_score": 0, "selected": false, "text": "<p>you might want to check the number of elements in children before trying to access the 3rd one.</p>\n" }, { "a...
2009/01/10
[ "https://Stackoverflow.com/questions/431861", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28540/" ]
I have a snippet of code that I'm working with to filter rows in a table. It works perfectly in every browser other than Firefox v3.0.x (works fine with 3.1 beta 2). When I run the snippet in Firefox 3.0.x, it says that `children is undefined`. I am using jQuery v1.2.6 also. Code Snippet: ``` var bodyRows = $("#resul...
Why not use jQuery to traverse the DOM elements instead. ``` var bodyRows = $("#resultsTable tbody tr"); bodyRows.each(function(){ var thirdCell = $(this).find('td').eq(2); if(!filterPattern.test($.trim(thirdCell.html()))){ this.style.display = 'none'; } else { this.style.display = ''; ...
431,866
<p>Say I have a Python function that returns multiple values in a tuple:</p> <pre><code>def func(): return 1, 2 </code></pre> <p>Is there a nice way to ignore one of the results rather than just assigning to a temporary variable? Say if I was only interested in the first value, is there a better way than this:</p...
[ { "answer_id": 431868, "author": "Luke Woodward", "author_id": 48503, "author_profile": "https://Stackoverflow.com/users/48503", "pm_score": 10, "selected": false, "text": "<p>You can use <code>x = func()[0]</code> to return the first value, <code>x = func()[1]</code> to return the secon...
2009/01/10
[ "https://Stackoverflow.com/questions/431866", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42974/" ]
Say I have a Python function that returns multiple values in a tuple: ``` def func(): return 1, 2 ``` Is there a nice way to ignore one of the results rather than just assigning to a temporary variable? Say if I was only interested in the first value, is there a better way than this: ``` x, temp = func() ```
One common convention is to use a "\_" as a variable name for the elements of the tuple you wish to ignore. For instance: ``` def f(): return 1, 2, 3 _, _, x = f() ```
431,884
<p>I have a numerical field called <code>category_id</code> in my table. I want to do something like this. </p> <pre><code>$ids=implode(',',$id_array); $sql="SELECT * FROM myTbl WHERE IN(category_id,'$ids')"; </code></pre> <p>Which should output something like:</p> <pre><code>SELECT * FROM myTbl WHERE IN(category_id...
[ { "answer_id": 431888, "author": "Paul Dixon", "author_id": 6521, "author_profile": "https://Stackoverflow.com/users/6521", "pm_score": 2, "selected": false, "text": "<p>Almost, but not quite - here is one way it could work</p>\n\n<pre><code>$ids=\"'\".implode(\"','\",$id_array).\"'\";\n...
2009/01/10
[ "https://Stackoverflow.com/questions/431884", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49153/" ]
I have a numerical field called `category_id` in my table. I want to do something like this. ``` $ids=implode(',',$id_array); $sql="SELECT * FROM myTbl WHERE IN(category_id,'$ids')"; ``` Which should output something like: ``` SELECT * FROM myTbl WHERE IN(category_id,'1,2,3,4,5,6'); ``` Is this possible and am I...
From where do you get the id array? If it's from the database you should consider doing it all there: ``` SELECT * FROM myTbl WHERE c_id IN (SELECT c_id FROM yourTable WHERE ...); ```
431,910
<p>In python it is easy to build a dictionary or array and pass it unpacked to a function with variable parameters</p> <p>I have this:</p> <pre><code>- (BOOL) executeUpdate:(NSString*)sql, ... { </code></pre> <p>And the manual way is this:</p> <pre><code>[db executeUpdate:@"insert into test (a, b, c, d, e) values (...
[ { "answer_id": 431962, "author": "mipadi", "author_id": 28804, "author_profile": "https://Stackoverflow.com/users/28804", "pm_score": 1, "selected": false, "text": "<p>To accomplish what you want, you have to use \"varargs\", as your method uses, or you can pass in an array of values, so...
2009/01/10
[ "https://Stackoverflow.com/questions/431910", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53185/" ]
In python it is easy to build a dictionary or array and pass it unpacked to a function with variable parameters I have this: ``` - (BOOL) executeUpdate:(NSString*)sql, ... { ``` And the manual way is this: ``` [db executeUpdate:@"insert into test (a, b, c, d, e) values (?, ?, ?, ?, ?)" , @"hi'", // look! I put ...
Unfortunately, no. Objective-C doesn't have argument unpacking like you get in a lot of modern languages. There isn't even a good way to work around it that I've ever found. Part of the problem is that Objective-C is essentially just C. It does multiple argument passing with C varargs, and there's no simple way to do ...
431,911
<p>Is there a general rule of thumb as to how many classes, interfaces etc should go in to a given name space before the items should be further classfied in to a new name space? Like a best practice or a community preference? Or is this all personal preference? </p> <pre><code>namespace: MyExample.Namespace interfac...
[ { "answer_id": 431927, "author": "Andrew Hare", "author_id": 34211, "author_profile": "https://Stackoverflow.com/users/34211", "pm_score": 0, "selected": false, "text": "<p>It is generally considered bad form to have a small number of classes in a namespace. I have always attributed thi...
2009/01/10
[ "https://Stackoverflow.com/questions/431911", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18196/" ]
Is there a general rule of thumb as to how many classes, interfaces etc should go in to a given name space before the items should be further classfied in to a new name space? Like a best practice or a community preference? Or is this all personal preference? ``` namespace: MyExample.Namespace interface1 interface2...
I have not seen any rule of thumb at any reliable source but there are a few common preferences that I haven seen while working with most developers. There are a few things that help you make the namespaces. 1. Domain of the class 2. Is it a class or an interface (I have seen some developers prefer namespaces like Sho...
431,912
<p>Is there a way to get all alphabetic chars (A-Z) in an array in PHP so I can loop through them and display them?</p>
[ { "answer_id": 431921, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "<pre><code>$alphabet = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','...
2009/01/10
[ "https://Stackoverflow.com/questions/431912", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49153/" ]
Is there a way to get all alphabetic chars (A-Z) in an array in PHP so I can loop through them and display them?
``` $alphas = range('A', 'Z'); ``` Documentation: <https://www.php.net/manual/en/function.range.php>
431,913
<p>I use RedGate SQL data compare and generated a .sql file, so I could run it on my local machine. But the problem is that the file is over 300mb, which means I can't do copy and paste because the clipboard won't be able to handle it, and when I try to open the file in SQL Server Management Studio I get an error about...
[ { "answer_id": 431914, "author": "BobbyShaftoe", "author_id": 38426, "author_profile": "https://Stackoverflow.com/users/38426", "pm_score": 2, "selected": false, "text": "<p>Run it at the command line with osql, see here:</p>\n\n<p><a href=\"http://metrix.fcny.org/wiki/display/dev/How+to...
2009/01/10
[ "https://Stackoverflow.com/questions/431913", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28647/" ]
I use RedGate SQL data compare and generated a .sql file, so I could run it on my local machine. But the problem is that the file is over 300mb, which means I can't do copy and paste because the clipboard won't be able to handle it, and when I try to open the file in SQL Server Management Studio I get an error about th...
From the command prompt, start up `sqlcmd`: ``` sqlcmd -S <server> -i C:\<your file here>.sql ``` Just replace `<server>` with the location of your SQL box and `<your file here>` with the name of your script. Don't forget, if you're using a SQL instance the syntax is: ``` sqlcmd -S <server>\instance. ``` Here is...
431,925
<p>I have a capistrano deployment recipe I've been using for some time to deploy my web app and then restart apache/nginx using the sudo command. Recently cap deploy is hanging when I try to execute these sudo commands. I see the output: "[sudo] password for " With my server name and the remote login, but this is no...
[ { "answer_id": 432042, "author": "wulong", "author_id": 52691, "author_profile": "https://Stackoverflow.com/users/52691", "pm_score": 6, "selected": true, "text": "<p>This seems to happen when connecting to CentOS machines as well. Add the following line in your capistrano deploy file:<...
2009/01/10
[ "https://Stackoverflow.com/questions/431925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36680/" ]
I have a capistrano deployment recipe I've been using for some time to deploy my web app and then restart apache/nginx using the sudo command. Recently cap deploy is hanging when I try to execute these sudo commands. I see the output: "[sudo] password for " With my server name and the remote login, but this is not a s...
This seems to happen when connecting to CentOS machines as well. Add the following line in your capistrano deploy file: ``` default_run_options[:pty] = true ``` Also make sure to use the `sudo` helper instead of executing `sudo` in your run commands directly. For example: ``` # not run "sudo chown root:root /etc/my...
431,940
<p>I am trying to set the default Style for every window in my WPF Windows application in my app.xaml. So far i have this in app.xaml:</p> <pre><code>&lt;Application.Resources&gt; &lt;ResourceDictionary&gt; &lt;Style x:Key=&quot;WindowStyle&quot; TargetType=&quot;{x:Type Window}&quot;&gt; &lt;Se...
[ { "answer_id": 431957, "author": "Ray Booysen", "author_id": 42124, "author_profile": "https://Stackoverflow.com/users/42124", "pm_score": 3, "selected": false, "text": "<p>The designer is not working because you're specifying a DynamicResource. Please change this to StaticResource and ...
2009/01/10
[ "https://Stackoverflow.com/questions/431940", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38438/" ]
I am trying to set the default Style for every window in my WPF Windows application in my app.xaml. So far i have this in app.xaml: ``` <Application.Resources> <ResourceDictionary> <Style x:Key="WindowStyle" TargetType="{x:Type Window}"> <Setter Property="Background" Value="Blue" /> </S...
To add on to what Ray says: For the Styles, you either need to supply a Key/ID or specify a TargetType. > > If a FrameworkElement does not have an > explicitly specified Style, it will > always look for a Style resource, > using its own type as the key > > - Programming WPF (Sells, Griffith) > > > If yo...
431,944
<p>How could I unpack a tuple of unknown to, say, a list?</p> <p>I have a number of columns of data and they get split up into a tuple by some function. I want to unpack this tuple to variables but I do not know how many columns I will have. Is there any way to dynamically unpack it to as many variables as I need?</p>
[ { "answer_id": 431947, "author": "PEZ", "author_id": 44639, "author_profile": "https://Stackoverflow.com/users/44639", "pm_score": 4, "selected": true, "text": "<p>Unpack the tuple to a list?</p>\n\n<pre><code>l = list(t)\n</code></pre>\n" }, { "answer_id": 431958, "author": ...
2009/01/10
[ "https://Stackoverflow.com/questions/431944", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41718/" ]
How could I unpack a tuple of unknown to, say, a list? I have a number of columns of data and they get split up into a tuple by some function. I want to unpack this tuple to variables but I do not know how many columns I will have. Is there any way to dynamically unpack it to as many variables as I need?
Unpack the tuple to a list? ``` l = list(t) ```
431,945
<p>I have very basic routing:</p> <pre><code>routes.MapRoute( "Default", "{controller}/{action}/{id}",parameters new { controller = "Home", action = "Index", id = "" } ); </code></pre> <p>The problem is that it...
[ { "answer_id": 434000, "author": "Charlino", "author_id": 10202, "author_profile": "https://Stackoverflow.com/users/10202", "pm_score": 2, "selected": false, "text": "<p>Have a look at this post: <a href=\"https://stackoverflow.com/questions/429963/the-resource-cannot-be-found-error-when...
2009/01/10
[ "https://Stackoverflow.com/questions/431945", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35643/" ]
I have very basic routing: ``` routes.MapRoute( "Default", "{controller}/{action}/{id}",parameters new { controller = "Home", action = "Index", id = "" } ); ``` The problem is that it works perfectly in all si...
Just add a slash "/" at the end of the URL: `www.xxx.yy/pages/filter/test./` See: [Dots in URL causes 404 with ASP.NET mvc and IIS](https://stackoverflow.com/questions/11728846/dots-in-url-causes-404-with-asp-net-mvc-and-iis).
431,955
<p><strong>(resolved: see bottom)</strong></p> <p>I have the following code snippet:</p> <pre><code>Protected Sub SqlDataSource1_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Inserted affected = CInt(DirectCast(e.Command.Parameters("@af...
[ { "answer_id": 431961, "author": "erikkallen", "author_id": 47161, "author_profile": "https://Stackoverflow.com/users/47161", "pm_score": 0, "selected": false, "text": "<p>What is the <code>query text...</code> part? An INSERT, I guess.\nCould it be an <code>insert ... select</code> whi...
2009/01/10
[ "https://Stackoverflow.com/questions/431955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4965/" ]
**(resolved: see bottom)** I have the following code snippet: ``` Protected Sub SqlDataSource1_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Inserted affected = CInt(DirectCast(e.Command.Parameters("@affected"), IDbDataParameter).Value)...
From [MSDN](http://msdn.microsoft.com/en-us/library/ms187342.aspx) > > After an INSERT, SELECT INTO, or bulk > copy statement is completed, > @@IDENTITY contains the last identity > value that is generated by the > statement. If the statement did not > affect any tables with identity > columns, @@IDENTITY retur...
431,956
<p>I am reading a tutorial that uses the following example (that I'll generalize somewhat):</p> <pre><code>f :: Foo -&gt; (Int, Foo) ... fList :: Foo -&gt; [Int] fList foo = x : fList bar where (x, bar) = f foo </code></pre> <p>My question lies in the fact that it seems you can refer to <code>x</code> and <code...
[ { "answer_id": 431970, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 2, "selected": false, "text": "<blockquote>\n <p>Am I right about this behavior?</p>\n</blockquote>\n\n<p>Yes. The names exist only in the block wh...
2009/01/10
[ "https://Stackoverflow.com/questions/431956", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38803/" ]
I am reading a tutorial that uses the following example (that I'll generalize somewhat): ``` f :: Foo -> (Int, Foo) ... fList :: Foo -> [Int] fList foo = x : fList bar where (x, bar) = f foo ``` My question lies in the fact that it seems you can refer to `x` and `bar`, by name, outside of the tuple where they ...
Seeing your edit, I think what your asking about is [Pattern matching](http://en.wikibooks.org/wiki/Haskell/Pattern_matching). And to answer your question: Yes, anything you can construct, you can also 'deconstruct' using the constructors. For example, you're probably familiar with this form of pattern matching: ``` ...
431,966
<p>Is there a way in iText to copy <em>just</em> the PDF acroform fields from one PDF document to another PDF document? I have the code to copy the entire PDF, but I would like to be able to overlay all my fields to a new/updated PDF document. </p>
[ { "answer_id": 432560, "author": "Deep Kapadia", "author_id": 48773, "author_profile": "https://Stackoverflow.com/users/48773", "pm_score": 1, "selected": false, "text": "<p>I don't quite remember very well if we were able to achieve this since I was not directly working on the implement...
2009/01/10
[ "https://Stackoverflow.com/questions/431966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17712/" ]
Is there a way in iText to copy *just* the PDF acroform fields from one PDF document to another PDF document? I have the code to copy the entire PDF, but I would like to be able to overlay all my fields to a new/updated PDF document.
``` public void replaceBackground(String newBackground, String CurrentForm, String newFile) throws Exception { PdfReader reader = new PdfReader(newBackground); PdfReader reader2 = new PdfReader(CurrentForm); PdfStamper stamp = new PdfStamper(reader2, new FileOutputStream(newF...
431,967
<p>I am attempting to write a .NET component. The component will be dropped onto a form/user control and needs to access attributes in assemblies referenced by the components parent form/user control at design-time. Is it possible to obtain these assemblies at design time?</p>
[ { "answer_id": 431980, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 0, "selected": false, "text": "<p>Have you tried using <a href=\"http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getreferencedassemb...
2009/01/10
[ "https://Stackoverflow.com/questions/431967", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53778/" ]
I am attempting to write a .NET component. The component will be dropped onto a form/user control and needs to access attributes in assemblies referenced by the components parent form/user control at design-time. Is it possible to obtain these assemblies at design time?
This is the proof of concept that I finally came up with for this question. It is not without flaws but I believe that with a little work it will function properly. ``` using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.Reflection; using System...
431,973
<p>How can I keep my WCF Service Client Connected with WinForm even if a Faulted State appened ?</p> <p>Thanks.</p>
[ { "answer_id": 431993, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 1, "selected": false, "text": "<p>As far as I know, a faulted state is usually terminal to a WCF proxy. So no, I don't think so.</p>\n" }, { ...
2009/01/10
[ "https://Stackoverflow.com/questions/431973", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50974/" ]
How can I keep my WCF Service Client Connected with WinForm even if a Faulted State appened ? Thanks.
Answer myself :) You might subscribe to InnerChannel Events ``` svc.InnerChannel.Closed += InnerChannel_Error; svc.InnerChannel.Closing += InnerChannel_Error; svc.InnerChannel.Faulted += InnerChannel_Error; ``` Then Handle Exceptions and Recreate the Service Proxy ``` private vo...
431,979
<p>I need to know how to set the very top left icon / image on a WPF page. I know how to do it in a WPF Window the page looks to be different.</p> <p>Thanks,</p> <p>Darren</p>
[ { "answer_id": 432071, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "<p>Are you referring to a WPF application deployed as an XBAP, if so the same rules apply as a normal website and you would ju...
2009/01/10
[ "https://Stackoverflow.com/questions/431979", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32339/" ]
I need to know how to set the very top left icon / image on a WPF page. I know how to do it in a WPF Window the page looks to be different. Thanks, Darren
I don't think there's any support for changing the host window's icon based on its current page in a navigation-style application. One workaround might be to introduce a property of type Image into your pages (perhaps derive all your pages from a base page, or introduce an IHasIcon interface and implement that), then ...
432,002
<p>An HTTP GET query string is a ordered sequence of key/value pairs:</p> <pre><code>?spam=eggs&amp;spam=ham&amp;foo=bar </code></pre> <p>Is, with certain semantics, equivalent to the following dictionary:</p> <pre><code>{'spam': ['eggs', 'ham'], 'foo': bar} </code></pre> <p>This happens to work well for boolean pr...
[ { "answer_id": 432021, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 4, "selected": true, "text": "<p>The usual way is to do it like this:</p>\n\n<pre><code>highlight_mode[7]=blue&amp;highlight_mode[9]=yellow\n</code>...
2009/01/11
[ "https://Stackoverflow.com/questions/432002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3594/" ]
An HTTP GET query string is a ordered sequence of key/value pairs: ``` ?spam=eggs&spam=ham&foo=bar ``` Is, with certain semantics, equivalent to the following dictionary: ``` {'spam': ['eggs', 'ham'], 'foo': bar} ``` This happens to work well for boolean properties of that page being requested: ``` ?expand=1&exp...
The usual way is to do it like this: ``` highlight_mode[7]=blue&highlight_mode[9]=yellow ``` AFAIR, quite a few server-side languages actually support this out of the box and will produce a nice dictionary for these values.
432,006
<p>I'm allocating an array of T, T extends Number inside a class. I can do it this way:</p> <pre><code>myClass test = new myClass(Double.class, 20); </code></pre> <p>Then the constructor itself:</p> <pre><code>myClass(Class&lt;T&gt; type, size) { array = (T[]) Array.newInstance(type, size); } </code></pre> <p>I...
[ { "answer_id": 432009, "author": "Jason Cohen", "author_id": 4926, "author_profile": "https://Stackoverflow.com/users/4926", "pm_score": 1, "selected": false, "text": "<p>You should use:</p>\n\n<pre><code>myClass test = new myClass( Double.class, 15 );\n</code></pre>\n\n<p>You were missi...
2009/01/11
[ "https://Stackoverflow.com/questions/432006", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm allocating an array of T, T extends Number inside a class. I can do it this way: ``` myClass test = new myClass(Double.class, 20); ``` Then the constructor itself: ``` myClass(Class<T> type, size) { array = (T[]) Array.newInstance(type, size); } ``` I'd like to know if it's possible to do it like this: `...
You can't use Class names as input parameters in Java. The `Object.class` was introduced to allow the passing of "Class names" So the answer is No, you can't pass `Number` as a parameter but you can pass `Number.class`. That is what it is for :) \*\* Update \*\* Also from you second constructor definition ``` myCla...
432,037
<p>How do I center the text horizontally and vertically in a <code>TextView</code>, so that it appears exactly in the middle of the <code>TextView</code> in <code>Android</code>?</p>
[ { "answer_id": 432155, "author": "Bill", "author_id": 51321, "author_profile": "https://Stackoverflow.com/users/51321", "pm_score": 13, "selected": true, "text": "<p>I'm assuming you're using XML layout.</p>\n<pre><code>&lt;TextView \n android:layout_width=&quot;match_parent&quot; \n...
2009/01/11
[ "https://Stackoverflow.com/questions/432037", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6068/" ]
How do I center the text horizontally and vertically in a `TextView`, so that it appears exactly in the middle of the `TextView` in `Android`?
I'm assuming you're using XML layout. ``` <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="@string/**yourtextstring**" /> ``` You can also use gravity `center_vertical` or `center_horizontal` according to your need. As @ste...
432,038
<p>I know the number of lines of code is completely arbitrary and a horrible metric. Even so, after a long day I like to click a little button and see that my <strong>pet project</strong> grew by 10%. (Or if I spent the day refactoring yet again it slimmed down by 10%, woohoo!)</p> <p>I've used two <a href="http://www...
[ { "answer_id": 432045, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 4, "selected": true, "text": "<p>Give a look to <a href=\"http://cloc.sourceforge.net/\" rel=\"nofollow noreferrer\">CLOC</a></p>\n\n<p>Check ...
2009/01/11
[ "https://Stackoverflow.com/questions/432038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40161/" ]
I know the number of lines of code is completely arbitrary and a horrible metric. Even so, after a long day I like to click a little button and see that my **pet project** grew by 10%. (Or if I spent the day refactoring yet again it slimmed down by 10%, woohoo!) I've used two [line](http://www.codeproject.com/KB/dotne...
Give a look to [CLOC](http://cloc.sourceforge.net/) Check the output: ``` ------------------------------------------------------------------------------- Language files blank comment code scale 3rd gen. equiv ------------------------------------------------------------------------------- ASP....
432,074
<p>What is difference to the controller that gets the return with repect to rendering the List?</p> <p>In Linq dataContext:</p> <pre><code>public IList&lt;Response&gt; GetResponses(int ID) { var responses = from r in this.Responses where r.ID == ID orderby r.Date select r; return responses.ToList...
[ { "answer_id": 432088, "author": "Andrew Kennan", "author_id": 22506, "author_profile": "https://Stackoverflow.com/users/22506", "pm_score": 4, "selected": true, "text": "<p>I doubt there's much difference to the controller but you should probably try to reveal as little information as p...
2009/01/11
[ "https://Stackoverflow.com/questions/432074", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49632/" ]
What is difference to the controller that gets the return with repect to rendering the List? In Linq dataContext: ``` public IList<Response> GetResponses(int ID) { var responses = from r in this.Responses where r.ID == ID orderby r.Date select r; return responses.ToList(); } ``` OR ``` pu...
I doubt there's much difference to the controller but you should probably try to reveal as little information as possible about the private data of your classes. This means exposing interfaces rather than concrete types and using the interface that exposes the minimum amount of information the client will need to opera...
432,086
<p>I have a few tables that I've defined like the below examples:</p> <pre><code>class TableA extends Zend_Db_Table_Abstract { protected $_schema = 'schema1'; protected $_name = 'tablea'; } class TableB extends Zend_Db_Table_Abstract { protected $_schema = 'schema2'; prote...
[ { "answer_id": 438055, "author": "farzad", "author_id": 9394, "author_profile": "https://Stackoverflow.com/users/9394", "pm_score": -1, "selected": false, "text": "<p>I think you can use a database view table to merge data from 2 schemas, and then use Zend Framework to fetch data from t...
2009/01/11
[ "https://Stackoverflow.com/questions/432086", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3765/" ]
I have a few tables that I've defined like the below examples: ``` class TableA extends Zend_Db_Table_Abstract { protected $_schema = 'schema1'; protected $_name = 'tablea'; } class TableB extends Zend_Db_Table_Abstract { protected $_schema = 'schema2'; protected $_name ...
I think this is related to this bug: <http://framework.zend.com/issues/browse/ZF-1838> It has been fixed in the upstream and should be available in the next release.
432,090
<p>Consider the following code:</p> <pre><code> private static void WriteProcesses(StreamWriter sw, DateTime d) { sw.WriteLine("List of processes @ " + d.ToString()); Process[] localAll = Process.GetProcesses().Where(o =&gt; o.ProcessName.ToLower() != "svchost"); i...
[ { "answer_id": 432101, "author": "John Sheehan", "author_id": 1786, "author_profile": "https://Stackoverflow.com/users/1786", "pm_score": 0, "selected": false, "text": "<p>If you don't want to use ToArray(), change Process[] to var then hover over it to see what type is being returned fr...
2009/01/11
[ "https://Stackoverflow.com/questions/432090", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50312/" ]
Consider the following code: ``` private static void WriteProcesses(StreamWriter sw, DateTime d) { sw.WriteLine("List of processes @ " + d.ToString()); Process[] localAll = Process.GetProcesses().Where(o => o.ProcessName.ToLower() != "svchost"); if(localAll.Length...
Change ``` Process[] localAll = Process.GetProcesses().Where(o => o.ProcessName.ToLower() != "svchost"); ``` to ``` Process[] localAll = Process.GetProcesses().Where(o => o.ProcessName.ToLower() != "svchost").ToArray(); ``` `Where` is returning an `IEnumerable<Process>` on which you can call `ToArray` to convert ...
432,112
<p>I know there is a method for a Python list to return the first index of something:</p> <pre><code>&gt;&gt;&gt; xs = [1, 2, 3] &gt;&gt;&gt; xs.index(2) 1 </code></pre> <p>Is there something like that for NumPy arrays?</p>
[ { "answer_id": 432146, "author": "Ned Batchelder", "author_id": 14343, "author_profile": "https://Stackoverflow.com/users/14343", "pm_score": 2, "selected": false, "text": "<p>There are lots of operations in NumPy that could perhaps be put together to accomplish this. This will return in...
2009/01/11
[ "https://Stackoverflow.com/questions/432112", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41718/" ]
I know there is a method for a Python list to return the first index of something: ``` >>> xs = [1, 2, 3] >>> xs.index(2) 1 ``` Is there something like that for NumPy arrays?
Yes, given an array, `array`, and a value, `item` to search for, you can use [`np.where`](http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html) as: ``` itemindex = numpy.where(array == item) ``` The result is a tuple with first all the row indices, then all the column indices. For example, if an arr...
432,118
<p>Is it possible to generate the database tables and c# classes from NHibernate config files? Afterwards, is it possible to change the config files and update the tables and config files non-destructively?</p> <p>Do you recommend any tools to do this? (preferably free...) </p>
[ { "answer_id": 432147, "author": "Shiva", "author_id": 50395, "author_profile": "https://Stackoverflow.com/users/50395", "pm_score": 2, "selected": false, "text": "<p>Yes it is possible to generate the database tables and C# classes from the NHibernate config files. Let me explain with t...
2009/01/11
[ "https://Stackoverflow.com/questions/432118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3291/" ]
Is it possible to generate the database tables and c# classes from NHibernate config files? Afterwards, is it possible to change the config files and update the tables and config files non-destructively? Do you recommend any tools to do this? (preferably free...)
As mentioned by Joachim, it's the "hbm2ddl.auto" setting that you're looking for. You can set it by code like this: ``` var cfg = new NHibernate.Cfg.Configuration(); cfg.SetProperty("hbm2ddl.auto", "create"); cfg.Configure(); ``` And you can also set it in your App.config file: ``` <hibernate-configuration xml...
432,127
<p>Is there an exact opposite action to "<strong>join</strong>" in linQ to SQL? I want to display just the results that do not fulfill the inner <strong>join</strong> constraint from a query. I wanna do it just in one query. Here's an example of it's use (<a href="http://img165.imageshack.us/img165/4940/liststj3.jpg" r...
[ { "answer_id": 432129, "author": "ccook", "author_id": 51275, "author_profile": "https://Stackoverflow.com/users/51275", "pm_score": 0, "selected": false, "text": "<p>Check out Zip here:</p>\n\n<p><a href=\"http://www.codeplex.com/nextension\" rel=\"nofollow noreferrer\">http://www.codep...
2009/01/11
[ "https://Stackoverflow.com/questions/432127", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53797/" ]
Is there an exact opposite action to "**join**" in linQ to SQL? I want to display just the results that do not fulfill the inner **join** constraint from a query. I wanna do it just in one query. Here's an example of it's use (<http://img165.imageshack.us/img165/4940/liststj3.jpg>).
Falvarez's roles: ``` Roles.Where(r => r.Users.Any(u => u.Name == "falvarez")); ``` Roles that falvarez doesn't have ``` Roles.Where(r => !r.Users.Any(u => u.Name == "falvarez")); ``` Project each role into an object that knows whether falvarez is in that role ``` Roles.Select(r => new { FalvarezInRole = r...
432,143
<p>In a C++ physics simulation, I have a class called Circle, and Square. These are Shapes, and have a method called push(), which applies force to it. There is then a special case of Circle, call it SpecialCircle, in which push() should exhibit slightly different properties. But in fact, there is also SpecialSquare(...
[ { "answer_id": 432166, "author": "Federico A. Ramponi", "author_id": 18770, "author_profile": "https://Stackoverflow.com/users/18770", "pm_score": 4, "selected": true, "text": "<p>Another solution (it may or may not fit your needs, it depends on the details of your implementation):</p>\n...
2009/01/11
[ "https://Stackoverflow.com/questions/432143", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
In a C++ physics simulation, I have a class called Circle, and Square. These are Shapes, and have a method called push(), which applies force to it. There is then a special case of Circle, call it SpecialCircle, in which push() should exhibit slightly different properties. But in fact, there is also SpecialSquare() whi...
Another solution (it may or may not fit your needs, it depends on the details of your implementation): * Have the class Behavior, and let NormalBehavior and SpecialBehavior inherit from it. * Have the class Shape, and let Square and Circle inherit from it. Let Shape be an aggregate type, with a Behavior member (i.e. y...
432,144
<p>I'm looking for an AJAX function to dynamically request an HTML page. I already found the following:</p> <pre><code>function ajaxinclude(url) { var page_request = false if (window.XMLHttpRequest) // if Mozilla, Safari etc page_request = new XMLHttpRequest() else if (window.ActiveXObject) // if IE ...
[ { "answer_id": 432158, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 3, "selected": false, "text": "<p>I would suggest using any of a number of different javascript frameworks for this functionality instead of reinventi...
2009/01/11
[ "https://Stackoverflow.com/questions/432144", "https://Stackoverflow.com", "https://Stackoverflow.com/users/194/" ]
I'm looking for an AJAX function to dynamically request an HTML page. I already found the following: ``` function ajaxinclude(url) { var page_request = false if (window.XMLHttpRequest) // if Mozilla, Safari etc page_request = new XMLHttpRequest() else if (window.ActiveXObject) // if IE { try...
I would have to agree, don't go reinventing the wheel, or in this case, AJAX. JQuery and Prototype do an excellent job of letting you NOT have to deal with cross-browser support, and greatly simplifying Javascript type programming. I fell into JQuery first so I'm biased towards it, and from what I've seen the library...
432,161
<p>Is it possible to have a switch in C# which checks if the value is null or empty not "" but <code>String.Empty</code>? I know i can do this:</p> <pre><code>switch (text) { case null: case "": break; } </code></pre> <p>Is there something better, because I don't want to have a large list of IF statem...
[ { "answer_id": 432177, "author": "JoshBerke", "author_id": 26160, "author_profile": "https://Stackoverflow.com/users/26160", "pm_score": 3, "selected": false, "text": "<p>how about</p>\n\n<pre><code>if (string.isNullOrEmpty(text))\n{\n //blah\n}\nelse\n{\n switch (text)\n {\n case ...
2009/01/11
[ "https://Stackoverflow.com/questions/432161", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51841/" ]
Is it possible to have a switch in C# which checks if the value is null or empty not "" but `String.Empty`? I know i can do this: ``` switch (text) { case null: case "": break; } ``` Is there something better, because I don't want to have a large list of IF statements? I'mm trying to replace: ``` i...
I would suggest something like the following: ``` switch(text ?? String.Empty) { case "": break; case "hi": break; } ``` Is that what you are looking for?
432,174
<p>I'm making a page which has some interaction provided by javascript. Just as an example: links which send an AJAX request to get the content of articles and then display that data in a div. Obviously in this example, I need each link to store an extra bit of information: the id of the article. The way I've been hand...
[ { "answer_id": 432196, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 3, "selected": false, "text": "<p>I know that you're currently using jQuery, but what if you defined the onclick handler inline. Then you could do:</...
2009/01/11
[ "https://Stackoverflow.com/questions/432174", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
I'm making a page which has some interaction provided by javascript. Just as an example: links which send an AJAX request to get the content of articles and then display that data in a div. Obviously in this example, I need each link to store an extra bit of information: the id of the article. The way I've been handlin...
Which version of HTML are you using? In HTML 5, it is totally valid to have [custom attributes prefixed with data-](https://www.w3schools.com/tags/att_global_data.asp), e.g. ``` <div data-internalid="1337"></div> ``` In XHTML, this is not really valid. If you are in XHTML 1.1 mode, the browser will probably complai...
432,211
<p>What I mean is, I'm looking for really short code that returns the lower value. for example:</p> <pre><code>a=[1,2,3,4,5,6,7,8,9,10] b=[1,2,3,4,5,6,7,8] len(a) = 10 len(b) = 8 if (fill-this-in): print(lesser-value) </code></pre> <p>And I forgot to add that if b is lower than a, I want b returned - not len(b) ...
[ { "answer_id": 432227, "author": "vili", "author_id": 53598, "author_profile": "https://Stackoverflow.com/users/53598", "pm_score": 2, "selected": false, "text": "<p><code>min()</code> should accomplish what you need</p>\n\n<pre><code>print(min(a,b))\n</code></pre>\n" }, { "answe...
2009/01/11
[ "https://Stackoverflow.com/questions/432211", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51518/" ]
What I mean is, I'm looking for really short code that returns the lower value. for example: ``` a=[1,2,3,4,5,6,7,8,9,10] b=[1,2,3,4,5,6,7,8] len(a) = 10 len(b) = 8 if (fill-this-in): print(lesser-value) ``` And I forgot to add that if b is lower than a, I want b returned - not len(b) - the variable b.
``` print(min(a, b)) ```
432,226
<p>I understand how to declaratively assign a method to be called when an Image receives a MouseMove event.</p> <blockquote> <pre><code> &lt;mx:Image id="oneCent" mouseMove="dragIt(event, 1);" /&gt; </code></pre> </blockquote> <p>How do I do this programmatically in Flex/AS3?</p> <p>EDIT: Tha...
[ { "answer_id": 432240, "author": "Scott Evernden", "author_id": 11397, "author_profile": "https://Stackoverflow.com/users/11397", "pm_score": 2, "selected": false, "text": "<pre><code>oneCent.addEventListener(MouseEvent.MOUSE_MOVE, dragIt);\n...\n\nfunction dragIt(event:MouseEvent):void\...
2009/01/11
[ "https://Stackoverflow.com/questions/432226", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24482/" ]
I understand how to declaratively assign a method to be called when an Image receives a MouseMove event. > > > ``` > <mx:Image > id="oneCent" > mouseMove="dragIt(event, 1);" > /> > > ``` > > How do I do this programmatically in Flex/AS3? EDIT: Thanks for the comments. Here's what I have...
You can't pass the second param directly - so add it to myImage: ``` myImage = new Image(); myImage.id = "oneCent"; myImage.num = 1; myImage.addEventListener(MouseEvent.MOUSE_MOVE, dragIt); ``` Then in the dragit function: ``` function dragIt(event:MouseEvent):void { trace("PARAM =", event.target.num, event.tar...
432,230
<p>Consider the following:</p> <pre><code>int ival = 1.01; int &amp;rval = 1.01; // error: non-const reference to a const value. int &amp;rval = ival; rval = 1.01; </code></pre> <p>The first assignment of &amp;rval to a literal value fails as expected. If I comment out that line the code compiles and runs. I under...
[ { "answer_id": 432236, "author": "casperOne", "author_id": 50776, "author_profile": "https://Stackoverflow.com/users/50776", "pm_score": 4, "selected": true, "text": "<p><code>ival</code> isn't a literal value, <code>1.01</code> is the literal value. It's been copied to <code>ival</code...
2009/01/11
[ "https://Stackoverflow.com/questions/432230", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1288/" ]
Consider the following: ``` int ival = 1.01; int &rval = 1.01; // error: non-const reference to a const value. int &rval = ival; rval = 1.01; ``` The first assignment of &rval to a literal value fails as expected. If I comment out that line the code compiles and runs. I understand why the initialization fails, but ...
`ival` isn't a literal value, `1.01` is the literal value. It's been copied to `ival` which is a variable, which most definitely can have it's references assigned to another variable.
432,245
<p>Given a path and filename how can I get the <code>Image</code> object:</p> <pre><code>Image image = ...(filename) </code></pre>
[ { "answer_id": 432251, "author": "casperOne", "author_id": 50776, "author_profile": "https://Stackoverflow.com/users/50776", "pm_score": 5, "selected": true, "text": "<p>You want to call the <a href=\"http://msdn.microsoft.com/en-us/library/e6ytk052.aspx\" rel=\"noreferrer\">static <code...
2009/01/11
[ "https://Stackoverflow.com/questions/432245", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
Given a path and filename how can I get the `Image` object: ``` Image image = ...(filename) ```
You want to call the [static `FromFile` method on the `Image` class](http://msdn.microsoft.com/en-us/library/e6ytk052.aspx).
432,257
<p>I have this:</p> <p>SolutionName: Foo.sln</p> <p>Assembly: Foo.Bar</p> <p>Namespaces are:</p> <p>Foo.Bar.Views<br> Foo.Bar.Model<br> Foo.Bar.BusinessObjects<br> Foo.Bar.Services </p> <p>Should the directory structure be like this?</p> <pre><code>__Foo/Foo.Bar/Foo.Bar.View__ or __Foo/Bar/View__ </code></pre>
[ { "answer_id": 432262, "author": "casperOne", "author_id": 50776, "author_profile": "https://Stackoverflow.com/users/50776", "pm_score": 0, "selected": false, "text": "<p>Well, it can be anything you wish. Either are valid, but the former might get a little redundant and lead to directo...
2009/01/11
[ "https://Stackoverflow.com/questions/432257", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
I have this: SolutionName: Foo.sln Assembly: Foo.Bar Namespaces are: Foo.Bar.Views Foo.Bar.Model Foo.Bar.BusinessObjects Foo.Bar.Services Should the directory structure be like this? ``` __Foo/Foo.Bar/Foo.Bar.View__ or __Foo/Bar/View__ ```
If you keep the Visual Studio option of "Automatic Namespaces" you would need to have Foo/Bar/Views. Since this is the default behavior of Visual Studio people will be most used to this. Plus it keeps your folder names/paths from getting excessively long.
432,283
<p>i'm trying to do a simple linq 2 sql many-to-many, insert some data, operation.</p> <p>here's the stock Northwind model representing a many to many:</p> <p><a href="http://www.iaingalloway.com/images/linq-detail.jpg" rel="nofollow noreferrer">alt text http://www.iaingalloway.com/images/linq-detail.jpg</a></p> <p>...
[ { "answer_id": 432427, "author": "John Farrell", "author_id": 25300, "author_profile": "https://Stackoverflow.com/users/25300", "pm_score": -1, "selected": false, "text": "<p>Many to Many relationships aren't supported in Linq2Sql. :(</p>\n\n<p>There are a couple of workarounds:</p>\n\n<...
2009/01/11
[ "https://Stackoverflow.com/questions/432283", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30674/" ]
i'm trying to do a simple linq 2 sql many-to-many, insert some data, operation. here's the stock Northwind model representing a many to many: [alt text http://www.iaingalloway.com/images/linq-detail.jpg](http://www.iaingalloway.com/images/linq-detail.jpg) Now what i'm trying to do is insert a new order and if the pr...
``` // Associate each product to the a new order_detail. orderDetailList.Add(new Order_Detail { Product = new SqlContext.Product { Foo = product.Foo } }); ``` One thing that is wrong here, is that you create a new product to set on your Order\_Detail.Product property. Instead , you should take the...
432,287
<p>I have a lingo script which runs some data processing for a Flash movie. I can call my Lingo functions from Flash by putting the following inside one of my methods:</p> <pre><code>getURL("Lingo: myMethod"); </code></pre> <p>and I can pass parameters from flash to lingo as follows:</p> <pre><code>getURL("Lingo: my...
[ { "answer_id": 432293, "author": "wulong", "author_id": 52691, "author_profile": "https://Stackoverflow.com/users/52691", "pm_score": 3, "selected": true, "text": "<p>You should be able to access Lingo via <code>ExternalInterface</code> assuming you're in Flash 8 or greater:</p>\n\n<pre>...
2009/01/11
[ "https://Stackoverflow.com/questions/432287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23249/" ]
I have a lingo script which runs some data processing for a Flash movie. I can call my Lingo functions from Flash by putting the following inside one of my methods: ``` getURL("Lingo: myMethod"); ``` and I can pass parameters from flash to lingo as follows: ``` getURL("Lingo: myMethod param"); ``` However, if myM...
You should be able to access Lingo via `ExternalInterface` assuming you're in Flash 8 or greater: ``` import flash.system.ExternalInterface; var valueFromLingo = ExternalInterface.call("myMethod"); trace(valueFromLingo); // -> 5 ```
432,320
<p>I have 2 tables: 1. Employees 2. Vouchers</p> <p>Employees table has a single primary key. Vouchers table has 3 foreign key constraints referencing the Employees table.</p> <p>The following is a sample T-SQL script (not the actual table script) to create both tables and their relationship in SQL Server:</p> <pre...
[ { "answer_id": 432329, "author": "dkretz", "author_id": 31641, "author_profile": "https://Stackoverflow.com/users/31641", "pm_score": 3, "selected": true, "text": "<p>Strictly from a relational design point of view, the Vouchers table as three Foreign Keys. Whether you choose to enforce ...
2009/01/11
[ "https://Stackoverflow.com/questions/432320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47610/" ]
I have 2 tables: 1. Employees 2. Vouchers Employees table has a single primary key. Vouchers table has 3 foreign key constraints referencing the Employees table. The following is a sample T-SQL script (not the actual table script) to create both tables and their relationship in SQL Server: ``` IF OBJECT_ID('dbo.Vou...
Strictly from a relational design point of view, the Vouchers table as three Foreign Keys. Whether you choose to enforce them, through CASCADE assertions or otherwise, is an implementation issue, but the relational design still exists. Presumably you want to enforce that, if one of the three fields is not NULL, then a ...
432,322
<p>I've seen it claimed that the following are "pretty much equivalent":</p> <pre><code>foo([NSString stringWithString:@"blah"]) # version 1 foo([[[NSString alloc] initWithString:@"blah"] autorelease]) # version 2 </code></pre> <p>Are the above in fact literally equivalent or are there any sub...
[ { "answer_id": 432330, "author": "Martin Cote", "author_id": 9936, "author_profile": "https://Stackoverflow.com/users/9936", "pm_score": 3, "selected": false, "text": "<p>They are equivalent, but I prefer \"stringWithString\" since it is more concise.</p>\n" }, { "answer_id": 432...
2009/01/11
[ "https://Stackoverflow.com/questions/432322", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4234/" ]
I've seen it claimed that the following are "pretty much equivalent": ``` foo([NSString stringWithString:@"blah"]) # version 1 foo([[[NSString alloc] initWithString:@"blah"] autorelease]) # version 2 ``` Are the above in fact literally equivalent or are there any subtle differences? What are ...
The two are functionally equivalent, but as rpetrich observes, may operate ever-so-slightly differently internally. This shouldn't matter to you, use whichever seems more convenient to you. Furthermore, while there is a minute performance difference, it is highly unlikely to matter to your application in practice. But...
432,347
<p>I have an object that is mapped to have a set of objects, very simple. However, what I really want to do is put some criteria on that mapping. Here's the current mapping:</p> <pre><code> &lt;set name="ops" inverse="true" cascade="all, delete-orphan"&gt; &lt;key column="cityblock_id" on-delete="cascade"/&...
[ { "answer_id": 432542, "author": "Deep Kapadia", "author_id": 48773, "author_profile": "https://Stackoverflow.com/users/48773", "pm_score": 0, "selected": false, "text": "<p>I am not sure if I understand your question clearly but it seems like you need to use a where clause in your SQL q...
2009/01/11
[ "https://Stackoverflow.com/questions/432347", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53813/" ]
I have an object that is mapped to have a set of objects, very simple. However, what I really want to do is put some criteria on that mapping. Here's the current mapping: ``` <set name="ops" inverse="true" cascade="all, delete-orphan"> <key column="cityblock_id" on-delete="cascade"/> <one-to-many c...
Under [6.2. Collection mappings](http://www.hibernate.org/hib_docs/v3/reference/en-US/html_single/#collections-mapping) in the Hibernate docs you will find that you can use a WHERE clause on any collection mapping: *where (optional) specify an arbitrary SQL WHERE condition to be used when retrieving or removing the c...
432,349
<p>I'm using <a href="http://www.latex-project.org/" rel="noreferrer">LaTeX</a>'s "<a href="http://en.wikibooks.org/wiki/LaTeX/Packages/Listings" rel="noreferrer">listings</a>" package to format source code. Unfortunately I get curly quotes instead of straight quotes. Since the curly quotes don't always point in the ri...
[ { "answer_id": 432387, "author": "dmckee --- ex-moderator kitten", "author_id": 2509, "author_profile": "https://Stackoverflow.com/users/2509", "pm_score": 5, "selected": false, "text": "<p>I see in the documentation (which should have been distributed with the packge, but is available a...
2009/01/11
[ "https://Stackoverflow.com/questions/432349", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49404/" ]
I'm using [LaTeX](http://www.latex-project.org/)'s "[listings](http://en.wikibooks.org/wiki/LaTeX/Packages/Listings)" package to format source code. Unfortunately I get curly quotes instead of straight quotes. Since the curly quotes don't always point in the right direction, it looks bad. How can I get straight quotes ...
Have you considered using a monospaced (typewriter) font for the listing? The following example works: ``` \documentclass{article} \usepackage{listings} \lstset{basicstyle=\ttfamily} % <<< This line added \begin{document} \begin{lstlisting} Fahrenheit=input("What is the Fahrenheit temperature?") Celsius=(5.0/9.0)*(Fah...
432,364
<p>When you create an instance of the cachefactory and then don’t use it anymore the memory that was used during the creation of the object is not released. This will have a substantial effect on all web apps or scenarios where a cachfactory might be created multiple times. The symptoms of this will be unusually high...
[ { "answer_id": 432362, "author": "U62", "author_id": 47612, "author_profile": "https://Stackoverflow.com/users/47612", "pm_score": 0, "selected": false, "text": "<p>Yes. Even if you use a framework like MFC or WTL, you still need to use Win32 calls for many things. </p>\n" }, { "...
2009/01/11
[ "https://Stackoverflow.com/questions/432364", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35331/" ]
When you create an instance of the cachefactory and then don’t use it anymore the memory that was used during the creation of the object is not released. This will have a substantial effect on all web apps or scenarios where a cachfactory might be created multiple times. The symptoms of this will be unusually high memo...
Well, I can't say it would hurt, but I think that it's better to remember how to quickly reference the API documentation instead of actually remebering the documentation itself. That mental currency (of which there is a limited amount, of course) could be better used remembering other things to make you a better develo...
432,379
<p>In my VB.net project I created a custom cursor (Window.cur). How can I assign that to the cursor without having to use the full file path to that file?</p> <p>VB.Net has My.Resources but it does not show the cursors that are embedded in the project.</p> <p>I found an example that used code like this:</p> <pre><code...
[ { "answer_id": 432390, "author": "Otávio Décio", "author_id": 48684, "author_profile": "https://Stackoverflow.com/users/48684", "pm_score": 0, "selected": false, "text": "<p>You are missing the namespace. You probably want to use:</p>\n\n<pre><code>MyNamespace.MySubfolder.Window.cur\n</c...
2009/01/11
[ "https://Stackoverflow.com/questions/432379", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53816/" ]
In my VB.net project I created a custom cursor (Window.cur). How can I assign that to the cursor without having to use the full file path to that file? VB.Net has My.Resources but it does not show the cursors that are embedded in the project. I found an example that used code like this: ``` New Cursor(Reflection.Ass...
Guessing the resource name can be difficult. To find out, run Ildasm.exe on your program. Double-click "Manifest" and look for the .mresource. Another way to do it that avoids guessing: Project + Properties, Resource tab. Click the arrow on the "Add Resource" button, Add Existing File and select your .cur file. Make y...
432,384
<p>I want to create some up and down buttons using the standard button background but with black arrows.</p> <p>What is the best way to accomplish this with WPF??</p> <p>Malcolm</p>
[ { "answer_id": 432394, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 8, "selected": true, "text": "<p>I find Marlett (a font built into Windows) handy for that sort of thing.</p>\n\n<pre><code>&lt;Button FontFamily=\"Mar...
2009/01/11
[ "https://Stackoverflow.com/questions/432384", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40568/" ]
I want to create some up and down buttons using the standard button background but with black arrows. What is the best way to accomplish this with WPF?? Malcolm
I find Marlett (a font built into Windows) handy for that sort of thing. ``` <Button FontFamily="Marlett" FontSize="20" Content="5"/> <Button FontFamily="Marlett" FontSize="20" Content="6"/> ``` Output: [![enter image description here](https://i.stack.imgur.com/gNHhp.png)](https://i.stack.imgur.com/gNHhp.png)
432,385
<p>I'm working on a simple tool that transfers files to a hard-coded location with the password also hard-coded. I'm a python novice, but thanks to ftplib, it was easy:</p> <pre><code>import ftplib info= ('someuser', 'password') #hard-coded def putfile(file, site, dir, user=(), verbose=True): """ upload ...
[ { "answer_id": 432391, "author": "Sergey Golovchenko", "author_id": 26592, "author_profile": "https://Stackoverflow.com/users/26592", "pm_score": 2, "selected": false, "text": "<p><a href=\"http://twistedmatrix.com/trac/\" rel=\"nofollow noreferrer\">Twisted</a> can help you with what yo...
2009/01/11
[ "https://Stackoverflow.com/questions/432385", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1464733/" ]
I'm working on a simple tool that transfers files to a hard-coded location with the password also hard-coded. I'm a python novice, but thanks to ftplib, it was easy: ``` import ftplib info= ('someuser', 'password') #hard-coded def putfile(file, site, dir, user=(), verbose=True): """ upload a file by ftp t...
[Paramiko](https://www.paramiko.org/) supports SFTP. I've used it, and I've used Twisted. Both have their place, but you might find it easier to start with Paramiko.
432,404
<p>I'm designing this forum layout where I come up with a nice design to draw the forum tables, however, I'm not sure that this can be easily done in HTML/CSS.</p> <p>Before I continue to draw the whole layout, I need to know if this is achievable and how, otherwise, I'll have to ditch this effect and rethink things.....
[ { "answer_id": 432409, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 1, "selected": false, "text": "<p>For the layout, the standard HTML <code>table</code> tag does all that, and is also an appropriate use for it.</p>\n\n<p>To...
2009/01/11
[ "https://Stackoverflow.com/questions/432404", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40480/" ]
I'm designing this forum layout where I come up with a nice design to draw the forum tables, however, I'm not sure that this can be easily done in HTML/CSS. Before I continue to draw the whole layout, I need to know if this is achievable and how, otherwise, I'll have to ditch this effect and rethink things... For ins...
CSS can do something like that very easily, provided you don't have to scale the gradient vertically as the table size increases. Below is an example you could use that would give you the effect you depicted above. **UPDATE:** I somehow didn't see the bevels (I guess I have to blame it being too late at night and my v...
432,423
<p>i have a listbox with a data template that contains a button.</p> <p>When the button is clicked I want to get in the button click handler the index of the listbox item that was current??</p> <p>How do I do this please?</p> <p>Malcolm</p>
[ { "answer_id": 432576, "author": "Jobi Joy", "author_id": 8091, "author_profile": "https://Stackoverflow.com/users/8091", "pm_score": 2, "selected": false, "text": "<p>Hope the bellow code will help you. </p>\n\n<pre><code>private void Button_Click(object sender, RoutedEventArgs e)\n{\n ...
2009/01/11
[ "https://Stackoverflow.com/questions/432423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40568/" ]
i have a listbox with a data template that contains a button. When the button is clicked I want to get in the button click handler the index of the listbox item that was current?? How do I do this please? Malcolm
More appropriate answer, ``` private void Button_Click(object sender, RoutedEventArgs e) { DependencyObject dep = (DependencyObject)e.OriginalSource; while ((dep != null) && !(dep is ListViewItem)) { dep = VisualTreeHelper.GetParent(dep); } if (dep == null) return; int index = lstBox.Item...
432,425
<p>I'm trying to integrate Autofac into an exsisting ASP.NET web application. </p> <p>The pages follow the MVP pattern. Each page implements a View and delegate functionality to a Presenter. The View is injected into the Presenter thru the constructor.</p> <p>I was able to register the Presenter and View and the p...
[ { "answer_id": 436623, "author": "mwissman", "author_id": 52632, "author_profile": "https://Stackoverflow.com/users/52632", "pm_score": 0, "selected": false, "text": "<p>I figured out a solution. Basically, you would register the page instance during the Page_PreInit event and then call...
2009/01/11
[ "https://Stackoverflow.com/questions/432425", "https://Stackoverflow.com", "https://Stackoverflow.com/users/52632/" ]
I'm trying to integrate Autofac into an exsisting ASP.NET web application. The pages follow the MVP pattern. Each page implements a View and delegate functionality to a Presenter. The View is injected into the Presenter thru the constructor. I was able to register the Presenter and View and the page loads fine but w...
There is a better way. First, enable [the Web integration module](http://code.google.com/p/autofac/wiki/AspNetIntegration). This will enable automatic property injection into the **Page** instance. Since your presenter needs the view in its constructor, your page should take a dependency on a presenter **factory** ins...
432,443
<p>I learned today that there are digraphs in C99 and C++. The following is a valid program:</p> <pre><code>%:include &lt;stdio.h&gt; %:ifndef BUFSIZE %:define BUFSIZE 512 %:endif void copy(char d&lt;::&gt;, const char s&lt;::&gt;, int len) &lt;% while (len-- &gt;= 0) &lt;% d&lt;:len:&gt; = s&lt;:...
[ { "answer_id": 432448, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 5, "selected": false, "text": "<p>I believe that their existence can be traced back to the <em>possibility</em> that somewhere, somebody is using a comp...
2009/01/11
[ "https://Stackoverflow.com/questions/432443", "https://Stackoverflow.com", "https://Stackoverflow.com/users/43496/" ]
I learned today that there are digraphs in C99 and C++. The following is a valid program: ``` %:include <stdio.h> %:ifndef BUFSIZE %:define BUFSIZE 512 %:endif void copy(char d<::>, const char s<::>, int len) <% while (len-- >= 0) <% d<:len:> = s<:len:>; %> %> ``` My question is: why do they ...
Digraphs were created for programmers that didn't have a keyboard which supported the ISO 646 character set. <http://en.wikipedia.org/wiki/C_trigraph>
432,454
<p>I'm writing a php app to access a MySQL database, and on a tutorial, it says something of the form</p> <pre><code>mysql_connect($host, $user, $pass) or die("could not connect"); </code></pre> <p>How does PHP know that the function failed so that it runs the die part? I guess I'm asking how the "or" part of it work...
[ { "answer_id": 432455, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 8, "selected": true, "text": "<p>If the first statement returns <code>true</code>, then the entire statement must be <code>true</code> therefore the second p...
2009/01/11
[ "https://Stackoverflow.com/questions/432454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24391/" ]
I'm writing a php app to access a MySQL database, and on a tutorial, it says something of the form ``` mysql_connect($host, $user, $pass) or die("could not connect"); ``` How does PHP know that the function failed so that it runs the die part? I guess I'm asking how the "or" part of it works. I don't think I've seen...
If the first statement returns `true`, then the entire statement must be `true` therefore the second part is never executed. For example: ``` $x = 5; true or $x++; echo $x; // 5 false or $x++; echo $x; // 6 ``` Therefore, if your query is unsuccessful, it will evaluate the `die()` statement and end the script.
432,462
<p>This is related to my last post.</p> <p>i want to have up and down buttons on listbox items so that they can moved up/down ie changed its index in the list. </p> <p>Any ideas how I would actualy do this?</p> <p>Malcolm</p>
[ { "answer_id": 432543, "author": "Wix", "author_id": 48378, "author_profile": "https://Stackoverflow.com/users/48378", "pm_score": 0, "selected": false, "text": "<p>I am pretty sure you can throw whatever you want into the ListBox. So you could just make your own control that has a label...
2009/01/11
[ "https://Stackoverflow.com/questions/432462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40568/" ]
This is related to my last post. i want to have up and down buttons on listbox items so that they can moved up/down ie changed its index in the list. Any ideas how I would actualy do this? Malcolm
I would make a button that is an up button, and in its OnClick event, do something like: ``` int location = listItems.SelectedIndex; if (location > 0) { object rememberMe = listItems.SelectedItem; listItems.Items.RemoveAt(location); listItems.Items.Insert(location - 1, rememberMe); listItems.SelectedIn...
432,463
<p>I would like to achieve <a href="http://en.wikipedia.org/wiki/Anti-aliasing#Full-scene_anti-aliasing" rel="noreferrer">FSAA</a> on my OpenGL ES app on the iPhone.</p> <p>Currently I do this by rendering the scene to a texture that is twice the width and height of the screen. I then use the nice function:</p> <pre>...
[ { "answer_id": 433295, "author": "NeARAZ", "author_id": 6799, "author_profile": "https://Stackoverflow.com/users/6799", "pm_score": 2, "selected": false, "text": "<p>Technically iPhone's GPU (PowerVR MBX Lite) should support anti-aliasing. However, it seems that current Apple's OpenGL ES...
2009/01/11
[ "https://Stackoverflow.com/questions/432463", "https://Stackoverflow.com", "https://Stackoverflow.com/users/338/" ]
I would like to achieve [FSAA](http://en.wikipedia.org/wiki/Anti-aliasing#Full-scene_anti-aliasing) on my OpenGL ES app on the iPhone. Currently I do this by rendering the scene to a texture that is twice the width and height of the screen. I then use the nice function: ``` void glDrawTexiOES(GLint x, GLint y, GLint ...
For Gran Turismo on the PSP, the developers achieved an effect similar to anti-aliasing by moving the image back and forth one pixel per frame (demonstration can be found here: <http://www.gtplanet.net/why-gran-turismo-psp-looks-so-good/>) so if the iPhone doesn't support what you're looking for that's an option.
432,464
<p>Im trying to get a value (IP address) from a W3C logfile (kinda like a text file). This is what I have so far but with no luck: </p> <pre><code>Set filename=ex%date:~-2,4%%date:~-10,2%%date:~-7,2%.log For /F "tokens=2 delims=: . " %%A in ('E:\WINDOWS\system32\LogFiles\MSFTPSVC6141885\%filename%') do (Set ip=%%A) ...
[ { "answer_id": 432471, "author": "Roger Lipscombe", "author_id": 8446, "author_profile": "https://Stackoverflow.com/users/8446", "pm_score": 2, "selected": false, "text": "<p>Have you tried <a href=\"http://www.microsoft.com/technet/scriptcenter/tools/logparser/default.mspx\" rel=\"nofol...
2009/01/11
[ "https://Stackoverflow.com/questions/432464", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53826/" ]
Im trying to get a value (IP address) from a W3C logfile (kinda like a text file). This is what I have so far but with no luck: ``` Set filename=ex%date:~-2,4%%date:~-10,2%%date:~-7,2%.log For /F "tokens=2 delims=: . " %%A in ('E:\WINDOWS\system32\LogFiles\MSFTPSVC6141885\%filename%') do (Set ip=%%A) ``` and the l...
Have you tried [Microsoft Log Parser](http://www.microsoft.com/technet/scriptcenter/tools/logparser/default.mspx)? Supposedly it supports W3C-style log files out-of-the-box. I don't know what you're trying to do, but it might be easier than hand-crafting a batch file. Alternatively, install AWK (e.g. from Cygwin). Or ...
432,491
<p>In C, something like the following would be a disaster (ie, a memory leak) because you're returning a pointer to memory that you will never be able to free:</p> <pre><code>NSString* foo() { return [NSString stringWithFormat:@"%i+%i=%i", 2, 2, 2+2]; } </code></pre> <p>Is that in fact totally fine in Objective-C s...
[ { "answer_id": 432511, "author": "Chris Hanson", "author_id": 714, "author_profile": "https://Stackoverflow.com/users/714", "pm_score": 3, "selected": true, "text": "<p>Functions in Cocoa obey the same memory management rules as everything else in Cocoa. Your first example is perfectly ...
2009/01/11
[ "https://Stackoverflow.com/questions/432491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4234/" ]
In C, something like the following would be a disaster (ie, a memory leak) because you're returning a pointer to memory that you will never be able to free: ``` NSString* foo() { return [NSString stringWithFormat:@"%i+%i=%i", 2, 2, 2+2]; } ``` Is that in fact totally fine in Objective-C since the memory that the r...
Functions in Cocoa obey the same memory management rules as everything else in Cocoa. Your first example is perfectly fine.
432,493
<p>I want to match a portion of a string using a <a href="https://en.wikipedia.org/wiki/Regular_expression" rel="noreferrer">regular expression</a> and then access that parenthesized substring:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code...
[ { "answer_id": 432503, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 12, "selected": true, "text": "<p>You can access capturing groups like this:</p>\n<p><div class=\"snippet\" data-lang=\"js\" data-hide=\"false...
2009/01/11
[ "https://Stackoverflow.com/questions/432493", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
I want to match a portion of a string using a [regular expression](https://en.wikipedia.org/wiki/Regular_expression) and then access that parenthesized substring: ```js var myString = "something format_abc"; // I want "abc" var arr = /(?:^|\s)format_(.*?)(?:\s|$)/.exec(myString); console.log(arr); //...
You can access capturing groups like this: ```js var myString = "something format_abc"; var myRegexp = /(?:^|\s)format_(.*?)(?:\s|$)/g; var myRegexp = new RegExp("(?:^|\s)format_(.*?)(?:\s|$)", "g"); var match = myRegexp.exec(myString); console.log(match[1]); // abc ``` And if there are multiple matches you can itera...
432,500
<p>I am looking for viewing the text of the system views and procedures in SQL Server 2005 using the object explorer or using sp_helptext.</p> <p>actually i am coming from the SQL Server 2000 background, where we have the feature of retreiving the code of the view and the stored procedure using SQL Server 2000 Enterpr...
[ { "answer_id": 432516, "author": "cmsjr", "author_id": 23114, "author_profile": "https://Stackoverflow.com/users/23114", "pm_score": 2, "selected": false, "text": "<p>Do you have access to SQL Server Management Studio? It is now sys.sp_helptext and can be browsed at master --> Programmab...
2009/01/11
[ "https://Stackoverflow.com/questions/432500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45972/" ]
I am looking for viewing the text of the system views and procedures in SQL Server 2005 using the object explorer or using sp\_helptext. actually i am coming from the SQL Server 2000 background, where we have the feature of retreiving the code of the view and the stored procedure using SQL Server 2000 Enterprise manag...
Do you have access to SQL Server Management Studio? It is now sys.sp\_helptext and can be browsed at master --> Programmability --> Stored Procedures --> System Stored Procedures in the object browser and executed with ``` exec sys.sp_helptext ObjectName ``` All the information you are looking for can be found in th...
432,510
<p>I'm trying to figure out the best way to save a simple one-to-many relationship in Linq2Sql.</p> <p>Lets assume we have the following POCO model (pseduo code btw):</p> <p><em>Person has zero to many Vechicles.</em></p> <pre><code>class Person { IList&lt;Vehicle&gt; Vehicle; } class Vehicle { string Name;...
[ { "answer_id": 432530, "author": "sirrocco", "author_id": 5246, "author_profile": "https://Stackoverflow.com/users/5246", "pm_score": 3, "selected": true, "text": "<pre><code>using (Db db = new Db())\n{\n var newPerson = db.People.SingleOrDefault(p =&gt; p.Id == person.Id) ?? new SqlC...
2009/01/11
[ "https://Stackoverflow.com/questions/432510", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30674/" ]
I'm trying to figure out the best way to save a simple one-to-many relationship in Linq2Sql. Lets assume we have the following POCO model (pseduo code btw): *Person has zero to many Vechicles.* ``` class Person { IList<Vehicle> Vehicle; } class Vehicle { string Name; string Colour; } ``` Now, when i s...
``` using (Db db = new Db()) { var newPerson = db.People.SingleOrDefault(p => p.Id == person.Id) ?? new SqlContext.Person(); // Left to right stuff. newPerson.Name = person.Name; newPerson.Age = person.Age; // add vehicles. Vehicle firstV = new Vehicle(); firstV.Name = "some name"; firs...
432,550
<p>In WPF 3.5 (with SP1), I have simply <strong>StackPanel that I would like to animate when I change the property Visibility</strong>. I have no idea of the height of this StackPanel since its content determines its height. So when I change the property of my StackPanel to Visible (progressPanel.Visibility = Visibilit...
[ { "answer_id": 432565, "author": "Jobi Joy", "author_id": 8091, "author_profile": "https://Stackoverflow.com/users/8091", "pm_score": 2, "selected": false, "text": "<p>If you need an expanding kind of effect with an animation which grows vertically. Do a double animation on the ScaleTran...
2009/01/11
[ "https://Stackoverflow.com/questions/432550", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42024/" ]
In WPF 3.5 (with SP1), I have simply **StackPanel that I would like to animate when I change the property Visibility**. I have no idea of the height of this StackPanel since its content determines its height. So when I change the property of my StackPanel to Visible (progressPanel.Visibility = Visibility.Visible;) I wo...
You can create and reuse custom StackPanel style that triggers animation when Visibility changes: ``` <Style x:Key="MyStyle" TargetType="{x:Type StackPanel}"> <Style.Triggers> <Trigger Property="Visibility" Value="Visible"> <Trigger.EnterActions> <BeginStoryboard> ...
432,553
<p>I need to use a custom prompt, just like the one shown in this <a href="http://abeautifulsite.net/notebook_files/87/demo" rel="noreferrer">jQuery plugin demo</a>. The problem is, all custom prompts depend on a callback, they are asynchronized, i need them to be synchronous.</p> <p>I need to do something like:</p> ...
[ { "answer_id": 432565, "author": "Jobi Joy", "author_id": 8091, "author_profile": "https://Stackoverflow.com/users/8091", "pm_score": 2, "selected": false, "text": "<p>If you need an expanding kind of effect with an animation which grows vertically. Do a double animation on the ScaleTran...
2009/01/11
[ "https://Stackoverflow.com/questions/432553", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I need to use a custom prompt, just like the one shown in this [jQuery plugin demo](http://abeautifulsite.net/notebook_files/87/demo). The problem is, all custom prompts depend on a callback, they are asynchronized, i need them to be synchronous. I need to do something like: ``` alert("Your name is " + myPrompt("What...
You can create and reuse custom StackPanel style that triggers animation when Visibility changes: ``` <Style x:Key="MyStyle" TargetType="{x:Type StackPanel}"> <Style.Triggers> <Trigger Property="Visibility" Value="Visible"> <Trigger.EnterActions> <BeginStoryboard> ...
432,556
<p>I would like to be able to start a second script (either PHP or Python) when a page is loaded and have it continue to run after the user cancels/navigates away is this possible?</p>
[ { "answer_id": 432561, "author": "Evan Fosmark", "author_id": 49701, "author_profile": "https://Stackoverflow.com/users/49701", "pm_score": 2, "selected": false, "text": "<p>Use <a href=\"http://www.electrictoolbox.com/article/php/process-forking/\" rel=\"nofollow noreferrer\">process fo...
2009/01/11
[ "https://Stackoverflow.com/questions/432556", "https://Stackoverflow.com", "https://Stackoverflow.com/users/115/" ]
I would like to be able to start a second script (either PHP or Python) when a page is loaded and have it continue to run after the user cancels/navigates away is this possible?
You can send Connection:Close headers, which finishes the page for your user, but enables you to execute things "after page loads". There is a simple way to ignore user abort (see [php manual](http://de3.php.net/ignore_user_abort) too): ``` ignore_user_abort(true); ```