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
215,748
<p>I'm currently working on project with Haskell, and have found myself some trouble. I'm supposed to read and insert into a list each line in a "dictionary.txt" file, but I can't seem to do so. I've got this code:</p> <pre><code>main = do let list = [] loadNums "dictionary.txt" list loadNums location list = ...
[ { "answer_id": 215796, "author": "CesarB", "author_id": 28258, "author_profile": "https://Stackoverflow.com/users/28258", "pm_score": 5, "selected": true, "text": "<p>In the line where the error happens, Haskell is expecting \"IO a\", but you are giving it a []. Simplifying things a lot,...
2008/10/18
[ "https://Stackoverflow.com/questions/215748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9506/" ]
I'm currently working on project with Haskell, and have found myself some trouble. I'm supposed to read and insert into a list each line in a "dictionary.txt" file, but I can't seem to do so. I've got this code: ``` main = do let list = [] loadNums "dictionary.txt" list loadNums location list = do inh <- ...
In the line where the error happens, Haskell is expecting "IO a", but you are giving it a []. Simplifying things a lot, on a do block on the IO monad, every line is either: * Something which returns a value of the "IO a" type; the value of the "a" type within it is discarded (so the "a" is often "()") * A <- expressio...
215,752
<p>While working on a C++ project, I was looking for a third party library for something that is not my core business. I found a really good library, doing exactly what's needed, but it is written in Python. I decided to experiment with embedding Python code in C++, using the Boost.Python library.</p> <p>The C++ code ...
[ { "answer_id": 215772, "author": "Josh Segall", "author_id": 2659, "author_profile": "https://Stackoverflow.com/users/2659", "pm_score": 0, "selected": false, "text": "<p>You should be able to return the result from MyFunc, which would then end up in the variable you are currently callin...
2008/10/18
[ "https://Stackoverflow.com/questions/215752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25287/" ]
While working on a C++ project, I was looking for a third party library for something that is not my core business. I found a really good library, doing exactly what's needed, but it is written in Python. I decided to experiment with embedding Python code in C++, using the Boost.Python library. The C++ code looks some...
First of all, change your function to `return` the value. `print`ing it will complicate things since you want to get the value back. Suppose your `MyModule.py` looks like this: ``` import thirdparty def MyFunc(some_arg): result = thirdparty.go() return result ``` Now, to do what you want, you have to go bey...
215,753
<p>I was watching a tutorial on Rails and was very impressed that you could so easily create an editing system for a class just by defining it.</p> <p>Can this be done in ASP.NET?</p> <p>I know there are ORMs out there, but do they come with an editing system?</p> <p>To explain what I mean by an editing system, cons...
[ { "answer_id": 215772, "author": "Josh Segall", "author_id": 2659, "author_profile": "https://Stackoverflow.com/users/2659", "pm_score": 0, "selected": false, "text": "<p>You should be able to return the result from MyFunc, which would then end up in the variable you are currently callin...
2008/10/19
[ "https://Stackoverflow.com/questions/215753", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24696/" ]
I was watching a tutorial on Rails and was very impressed that you could so easily create an editing system for a class just by defining it. Can this be done in ASP.NET? I know there are ORMs out there, but do they come with an editing system? To explain what I mean by an editing system, consider a class for definin...
First of all, change your function to `return` the value. `print`ing it will complicate things since you want to get the value back. Suppose your `MyModule.py` looks like this: ``` import thirdparty def MyFunc(some_arg): result = thirdparty.go() return result ``` Now, to do what you want, you have to go bey...
215,767
<p>If you have something like:</p> <pre><code>val myStuff = Array(Person("joe",40), Person("mary", 35)) </code></pre> <p>How do you create an XML value with that data as nodes? I know how to use { braces } in an XML expression to put a value, but this is a collection of values. Do I need to iterate explicitly or is t...
[ { "answer_id": 215860, "author": "Aaron Maenpaa", "author_id": 2603, "author_profile": "https://Stackoverflow.com/users/2603", "pm_score": 5, "selected": true, "text": "<p>As it's a functional programming language Array.map is probably what you're looking for:</p>\n\n<pre><code>class Per...
2008/10/19
[ "https://Stackoverflow.com/questions/215767", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17138/" ]
If you have something like: ``` val myStuff = Array(Person("joe",40), Person("mary", 35)) ``` How do you create an XML value with that data as nodes? I know how to use { braces } in an XML expression to put a value, but this is a collection of values. Do I need to iterate explicitly or is there something better? ``...
As it's a functional programming language Array.map is probably what you're looking for: ``` class Person(name : String, age : Int){ def toXml() = <person><name>{ name }</name><age>{ age }</age></person> } object xml { val people = List( new Person("Alice", 16), new Person("Bob", 64) ) ...
215,770
<p>I'm a very novice OCaml programmer so please forgive me if this is a stupid/obvious question. There's <em>a lot</em> to absorb and I may have missed this in the documentation.</p> <p>I have a base of code that's starting to look like this:</p> <pre><code>let update_x p x = add_delta p; p.x &lt;- x; refresh ...
[ { "answer_id": 215884, "author": "Chris Conway", "author_id": 1412, "author_profile": "https://Stackoverflow.com/users/1412", "pm_score": 2, "selected": true, "text": "<p>No, you can't do what you want in plain OCaml. You could write a syntax extension with <a href=\"http://martin.jambon...
2008/10/19
[ "https://Stackoverflow.com/questions/215770", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18446/" ]
I'm a very novice OCaml programmer so please forgive me if this is a stupid/obvious question. There's *a lot* to absorb and I may have missed this in the documentation. I have a base of code that's starting to look like this: ``` let update_x p x = add_delta p; p.x <- x; refresh p let update_y p y = add_delt...
No, you can't do what you want in plain OCaml. You could write a syntax extension with [camlp4](http://martin.jambon.free.fr/extend-ocaml-syntax.htm) (which is a kind of a macro system, though a different kind than you're probably accustomed to) that would transform ``` UPDATE_FIELD x f y ``` into ``` x.f <- y ```...
215,820
<p>Years ago when I was working with C# I could easily create a temporary file and get its name with this function:</p> <pre><code>Path.GetTempFileName(); </code></pre> <p>This function would create a file with a unique name in the temporary directory and return the full path to that file. </p> <p>In the Cocoa API's...
[ { "answer_id": 215845, "author": "Giao", "author_id": 14099, "author_profile": "https://Stackoverflow.com/users/14099", "pm_score": 2, "selected": false, "text": "<p>You could use <a href=\"http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/mktemp.3.html\" rel=\"nofo...
2008/10/19
[ "https://Stackoverflow.com/questions/215820", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28106/" ]
Years ago when I was working with C# I could easily create a temporary file and get its name with this function: ``` Path.GetTempFileName(); ``` This function would create a file with a unique name in the temporary directory and return the full path to that file. In the Cocoa API's, the closest thing I can find is...
A safe way is to use [mkstemp(3)](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/mkstemp.3.html).
215,851
<p>I am developing a kernel for an operating system. In order to execute it, I've decided to use GRUB. Currently, I have a script attached to GRUB's <code>stage1</code>, <code>stage2</code>, a pad file and the kernel itself together which makes it bootable. The only problem is that when I run it, you have to let GRUB...
[ { "answer_id": 217507, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": true, "text": "<p>I would imagine you could just make your own menu.lst conf file, load that at the grub shell with \"configfile /path/to/menu...
2008/10/19
[ "https://Stackoverflow.com/questions/215851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1256/" ]
I am developing a kernel for an operating system. In order to execute it, I've decided to use GRUB. Currently, I have a script attached to GRUB's `stage1`, `stage2`, a pad file and the kernel itself together which makes it bootable. The only problem is that when I run it, you have to let GRUB know where the kernel is a...
I would imagine you could just make your own menu.lst conf file, load that at the grub shell with "configfile /path/to/menu.lst" and then do "setup (hd0)" replacing values as needed. I'm just guessing though.. no telling what the differences are on your custom setup.
215,854
<p>When using XmlDocument.Load , I am finding that if the document refers to a DTD, a connection is made to the provided URI. Is there any way to prevent this from happening?</p>
[ { "answer_id": 215892, "author": "muratgu", "author_id": 26224, "author_profile": "https://Stackoverflow.com/users/26224", "pm_score": 1, "selected": false, "text": "<p>Use an <code>XMLReader</code> to load the document and set the <code>ValidationType</code> property of the reader setti...
2008/10/19
[ "https://Stackoverflow.com/questions/215854", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14357/" ]
When using XmlDocument.Load , I am finding that if the document refers to a DTD, a connection is made to the provided URI. Is there any way to prevent this from happening?
After some more digging, maybe you should set the [XmlResolver](http://msdn.microsoft.com/en-us/library/system.xml.xmlreadersettings.xmlresolver.aspx) property of the XmlReaderSettings object to null. > > 'The XmlResolver is used to locate and > open an XML instance document, or to > locate and open any external re...
215,883
<p>I have an s-expression bound to a variable in Common Lisp:</p> <pre><code>(defvar x '(+ a 2)) </code></pre> <p>Now I want to create a function that when called, evaluates the expression in the scope in which it was defined. I've tried this:</p> <pre><code>(let ((a 4)) (lambda () (eval x))) </code></pre> <p>an...
[ { "answer_id": 215922, "author": "sanxiyn", "author_id": 18382, "author_profile": "https://Stackoverflow.com/users/18382", "pm_score": 2, "selected": false, "text": "<p>CLISP implements an extension to evaluate a form in the lexical environment. From the fact that it is an extension, I s...
2008/10/19
[ "https://Stackoverflow.com/questions/215883", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7492/" ]
I have an s-expression bound to a variable in Common Lisp: ``` (defvar x '(+ a 2)) ``` Now I want to create a function that when called, evaluates the expression in the scope in which it was defined. I've tried this: ``` (let ((a 4)) (lambda () (eval x))) ``` and ``` (let ((a 4)) (eval `(lambda () ,x))) ```...
You need to create code that has the necessary bindings. Wrap a LET around your code and bind every variable you want to make available in your code: ``` (defvar *x* '(+ a 2)) (let ((a 4)) (eval `(let ((a ,a)) ,*x*))) ```
215,896
<p>I'm writing a PHP script and the script outputs a simple text file log of the operations it performs. How would I use PHP to delete the first several lines from this file when it reaches a certain file size?</p> <p>Ideally, I would like it to keep the first two lines (date/time created and blank) and start deletin...
[ { "answer_id": 215898, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 0, "selected": false, "text": "<p>Typical operating systems don't provide the capability to insert or delete content of a file \"in-place\". What you wi...
2008/10/19
[ "https://Stackoverflow.com/questions/215896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27025/" ]
I'm writing a PHP script and the script outputs a simple text file log of the operations it performs. How would I use PHP to delete the first several lines from this file when it reaches a certain file size? Ideally, I would like it to keep the first two lines (date/time created and blank) and start deleting from line...
``` $x_amount_of_lines = 30; $log = 'path/to/log.txt'; if (filesize($log) >= $max_size)) { $file = file($log); $line = $file[0]; $file = array_splice($file, 2, $x_amount_of_lines); $file = array_splice($file, 0, 0, array($line, "\n")); // put the first line back in ... } ``` edit: with correction from by rc...
215,908
<h3>Note</h3> <p>This is not a REBOL-specific question. You can answer it in any language.</p> <h3>Background</h3> <p>The <a href="http://www.rebol.com" rel="nofollow noreferrer">REBOL</a> language supports the creation of domain-specific languages known as "dialects" in REBOL <em>parlance</em>. I've created such a ...
[ { "answer_id": 215952, "author": "Robert Gamble", "author_id": 25222, "author_profile": "https://Stackoverflow.com/users/25222", "pm_score": 4, "selected": true, "text": "<p>How about something like this:</p>\n\n<pre><code>#!/usr/bin/perl\n\nuse strict;\nuse warnings;\n\nmy @list1 = qw(1...
2008/10/19
[ "https://Stackoverflow.com/questions/215908", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27779/" ]
### Note This is not a REBOL-specific question. You can answer it in any language. ### Background The [REBOL](http://www.rebol.com) language supports the creation of domain-specific languages known as "dialects" in REBOL *parlance*. I've created such a dialect for list comprehensions, which aren't natively supported...
How about something like this: ``` #!/usr/bin/perl use strict; use warnings; my @list1 = qw(1 2); my @list2 = qw(3 4); my @list3 = qw(5 6); # Calculate the Cartesian Product my @cp = cart_prod(\@list1, \@list2, \@list3); # Print the result foreach my $elem (@cp) { print join(' ', @$elem), "\n"; } sub cart_prod ...
215,913
<p>I have ran into an odd problem with the ActionLink method in ASP.NET MVC Beta. When using the Lambda overload from the MVC futures I cannot seem to specify a parameter pulled from ViewData.</p> <p>When I try this:</p> <pre><code>&lt;%= Html.ActionLink&lt;PhotoController&gt;(p =&gt; p.Upload(((string)ViewData["grou...
[ { "answer_id": 216398, "author": "Schotime", "author_id": 29376, "author_profile": "https://Stackoverflow.com/users/29376", "pm_score": 2, "selected": false, "text": "<p>Have you updated your version of the Microsoft.Web.Mvc.dll where the Strongly typed actionlink resides. </p>\n\n<p>App...
2008/10/19
[ "https://Stackoverflow.com/questions/215913", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27860/" ]
I have ran into an odd problem with the ActionLink method in ASP.NET MVC Beta. When using the Lambda overload from the MVC futures I cannot seem to specify a parameter pulled from ViewData. When I try this: ``` <%= Html.ActionLink<PhotoController>(p => p.Upload(((string)ViewData["groupName"])), "upload new photo") %>...
Ok, I figured out what my problem was. Apparently I was not even setting the ViewData slot that I was trying to read from in the view, resulting in it being a null value. So effectually I was writing: ``` <%= Html.ActionLink<PhotoController>(p => p.Upload(null), "upload new photo") %> ``` I think the ultimate kick...
215,933
<p>I'm getting a totally bizzare error trying to compile a C program using GCC. Here is the batch file I am using:</p> <pre><code>echo Now compiling, assembling, and linking the core: nasm -f aout -o start.o start.asm gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./in...
[ { "answer_id": 215944, "author": "Paige Ruten", "author_id": 813, "author_profile": "https://Stackoverflow.com/users/813", "pm_score": 4, "selected": true, "text": "<p>The line that works is 126 characters long, the others are 130 and 136 characters long. The problem is that there is a 1...
2008/10/19
[ "https://Stackoverflow.com/questions/215933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19521/" ]
I'm getting a totally bizzare error trying to compile a C program using GCC. Here is the batch file I am using: ``` echo Now compiling, assembling, and linking the core: nasm -f aout -o start.o start.asm gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o co...
The line that works is 126 characters long, the others are 130 and 136 characters long. The problem is that there is a 127-character limit. I'm not sure how to get around this, but maybe **make** would get around it for you?...
215,959
<p>What's the best way to get a nice clean URL structure like stack overflow has? </p> <p>Do I need to use IIS for this? Or is there a way I can do it with some sort of mapping file in asp .net?</p> <p>The site I want this for has hundreds of pages, and is already deployed.<br> I would like a method that requires the...
[ { "answer_id": 215983, "author": "Gulzar Nazim", "author_id": 4337, "author_profile": "https://Stackoverflow.com/users/4337", "pm_score": 2, "selected": false, "text": "<p>from what I understand, you are looking for a tool to help you with mappings.</p>\n\n<p>If that is the case, you can...
2008/10/19
[ "https://Stackoverflow.com/questions/215959", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3153/" ]
What's the best way to get a nice clean URL structure like stack overflow has? Do I need to use IIS for this? Or is there a way I can do it with some sort of mapping file in asp .net? The site I want this for has hundreds of pages, and is already deployed. I would like a method that requires the least amount of c...
Perhaps [urlMappings](http://weblogs.asp.net/scottgu/archive/2005/11/14/430493.aspx) could work for you: ``` <system.web> <urlMappings enabled="true"> <add url="~/test/" mappedUrl="~/test.aspx"/> </urlMappings> ``` To make it work on IIS6 you to enable wildcard mappings.
215,961
<p>I am implementing a BFS, and what it is going to do is go through an ordered tree to find the shortest solution to a puzzle.</p> <p>What i will be doing is creating a Snapshot object that holds the current position of each piece in a puzzle. I will add this Snapshot object into the queue and check if it is the solu...
[ { "answer_id": 215970, "author": "Jeff Linahan", "author_id": 2222, "author_profile": "https://Stackoverflow.com/users/2222", "pm_score": 0, "selected": false, "text": "<p>You could use a queue from the standard template library, then create a function that creates a Snapshot object and ...
2008/10/19
[ "https://Stackoverflow.com/questions/215961", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29326/" ]
I am implementing a BFS, and what it is going to do is go through an ordered tree to find the shortest solution to a puzzle. What i will be doing is creating a Snapshot object that holds the current position of each piece in a puzzle. I will add this Snapshot object into the queue and check if it is the solution. Howe...
There is a way - you use the [Preprocessor's Token-Pasting Operator](http://msdn.microsoft.com/en-us/library/09dwwt6y(VS.80).aspx). This allows you to create a name based on a variable, so you'd specify: ``` #define S(variable) snapshot#variable ``` and you'd be able to create variables named snapshot1, snapshot2 et...
215,963
<p>I've read the documentation on <a href="http://msdn.microsoft.com/en-us/library/ms776420(VS.85).aspx" rel="noreferrer">WideCharToMultiByte</a>, but I'm stuck on this parameter:</p> <pre><code>lpMultiByteStr [out] Pointer to a buffer that receives the converted string. </code></pre> <p>I'm not quite sure how to pro...
[ { "answer_id": 215973, "author": "Brian R. Bondy", "author_id": 3153, "author_profile": "https://Stackoverflow.com/users/3153", "pm_score": 4, "selected": false, "text": "<p>You use the lpMultiByteStr [out] parameter by creating a new char array. You then pass this char array in to get ...
2008/10/19
[ "https://Stackoverflow.com/questions/215963", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23120/" ]
I've read the documentation on [WideCharToMultiByte](http://msdn.microsoft.com/en-us/library/ms776420(VS.85).aspx), but I'm stuck on this parameter: ``` lpMultiByteStr [out] Pointer to a buffer that receives the converted string. ``` I'm not quite sure how to properly initialize the variable and feed it into the fun...
Here's a couple of functions (based on Brian Bondy's example) that use WideCharToMultiByte and MultiByteToWideChar to convert between std::wstring and std::string using utf8 to not lose any data. ``` // Convert a wide Unicode string to an UTF8 string std::string utf8_encode(const std::wstring &wstr) { if( wstr.emp...
216,000
<p>I was trying to compile a program using an external compiled object coreset.o. I wrote the public01.c test file and my functions are in computation.c, both of which compiles. However its failing on linking it together. What might be the problem?</p> <pre><code>gcc -o public01.x public01.o computation.o coreset.o...
[ { "answer_id": 216009, "author": "zxcv", "author_id": 9628, "author_profile": "https://Stackoverflow.com/users/9628", "pm_score": 2, "selected": false, "text": "<p>It turns out the compiler version I was using did not match the compiled version done with the coreset.o. </p>\n\n<p>One wa...
2008/10/19
[ "https://Stackoverflow.com/questions/216000", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9628/" ]
I was trying to compile a program using an external compiled object coreset.o. I wrote the public01.c test file and my functions are in computation.c, both of which compiles. However its failing on linking it together. What might be the problem? ``` gcc -o public01.x public01.o computation.o coreset.o ld: fatal: file ...
I think that coreset.o was compiled for 64-bit, and you are linking it with a 32-bit computation.o. You can try to recompile computation.c with the '-m64' flag of [gcc(1)](http://www.manpagez.com/man/1/gcc-3.3/)
216,007
<p>My PHP/MS Sql Server 2005/win 2003 Application occasionally becomes very unresponsive, the memory/cpu usage does not spike. If i try to open any new connection from sql management studio, then the it just hangs at the open connection dialog box. how to deterime the total number of active connections ms sql server ...
[ { "answer_id": 216020, "author": "Mitch Wheat", "author_id": 16076, "author_profile": "https://Stackoverflow.com/users/16076", "pm_score": 9, "selected": true, "text": "<p>This shows the number of connections per each DB:</p>\n\n<pre><code>SELECT \n DB_NAME(dbid) as DBName, \n COUN...
2008/10/19
[ "https://Stackoverflow.com/questions/216007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
My PHP/MS Sql Server 2005/win 2003 Application occasionally becomes very unresponsive, the memory/cpu usage does not spike. If i try to open any new connection from sql management studio, then the it just hangs at the open connection dialog box. how to deterime the total number of active connections ms sql server 2005
This shows the number of connections per each DB: ``` SELECT DB_NAME(dbid) as DBName, COUNT(dbid) as NumberOfConnections, loginame as LoginName FROM sys.sysprocesses WHERE dbid > 0 GROUP BY dbid, loginame ``` And this gives the total: ``` SELECT COUNT(dbid) as TotalConnections FROM ...
216,008
<p>It just happens to me about one code design question. Say, I have one "template" method that invokes some functions that may "alter". A intuitive design is to follow "Template Design Pattern". Define the altering functions to be "virtual" functions to be overridden in subclasses. Or, I can just use delegate function...
[ { "answer_id": 216022, "author": "Daniel Plaisted", "author_id": 1509, "author_profile": "https://Stackoverflow.com/users/1509", "pm_score": 1, "selected": false, "text": "<p>It is possible that since you don't have any methods that override the virtual method that the JIT is able to rec...
2008/10/19
[ "https://Stackoverflow.com/questions/216008", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26349/" ]
It just happens to me about one code design question. Say, I have one "template" method that invokes some functions that may "alter". A intuitive design is to follow "Template Design Pattern". Define the altering functions to be "virtual" functions to be overridden in subclasses. Or, I can just use delegate functions w...
Think about what's required in each case: **Virtual call** * Check for nullity * Navigate from object pointer to type pointer * Look up method address in instruction table * (Not sure - even Richter doesn't cover this) Go to base type if method isn't overridden? Recurse until we find the right method address. (I do...
216,019
<p>I have a .ini file with sensitive information in my php wab app. I denied access to it using a .htaccess file:</p> <pre><code>&lt;files my.ini&gt; order deny,allow deny from all &lt;/files&gt; </code></pre> <p>I don't have access to folders outside of htdocs, so I can't move the .ini file out of browsable terr...
[ { "answer_id": 216059, "author": "Jeremy Cantrell", "author_id": 18866, "author_profile": "https://Stackoverflow.com/users/18866", "pm_score": 2, "selected": false, "text": "<p>The file will not be visible from apache. Obviously the best option is to put it outside of your site's root. I...
2008/10/19
[ "https://Stackoverflow.com/questions/216019", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3740/" ]
I have a .ini file with sensitive information in my php wab app. I denied access to it using a .htaccess file: ``` <files my.ini> order deny,allow deny from all </files> ``` I don't have access to folders outside of htdocs, so I can't move the .ini file out of browsable territory. Is my solution safe?
The .htaccess will block access from the web. However, if you're using a shared hosting environment, it might be possible for other users to access your ini. If its on a (virtual private) server and you're the only user for that server you're safe. In case of shared hosting it depends on server configuration. For more...
216,030
<p>Is there a better way to do the following:</p> <pre><code>$array = array('test1', 'test2', 'test3', 'test4', 'test5'); // do a bunch of other stuff, probably a loop $array[] = 'test6'; end($array); echo key($array); // gives me 6 </code></pre> <p>This will give the key of the most recently add array element.</p> ...
[ { "answer_id": 216039, "author": "Paolo Bergantino", "author_id": 16417, "author_profile": "https://Stackoverflow.com/users/16417", "pm_score": 4, "selected": true, "text": "<p>You could also do:</p>\n\n<pre><code>$end = end(array_keys($array));\n</code></pre>\n\n<p>But I think your way ...
2008/10/19
[ "https://Stackoverflow.com/questions/216030", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5441/" ]
Is there a better way to do the following: ``` $array = array('test1', 'test2', 'test3', 'test4', 'test5'); // do a bunch of other stuff, probably a loop $array[] = 'test6'; end($array); echo key($array); // gives me 6 ``` This will give the key of the most recently add array element. Is there a better way to do th...
You could also do: ``` $end = end(array_keys($array)); ``` But I think your way makes it clear what you want to do, so you could whip something up like: ``` function array_last_key($array) { end($array); return key($array); } ``` That's about it.
216,049
<p>Sometimes you're developing and you decide to commit, forgetting you created a few files on your project. Then a few days down the line your buddy gets your build out of Subversion and complains that some files appear to be missing. You realize, ah crap, I forgot to add those files!</p> <p>How can I get a list of t...
[ { "answer_id": 216052, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 8, "selected": true, "text": "<p>Use the <a href=\"http://svnbook.red-bean.com/en/1.0/re26.html\" rel=\"noreferrer\"><code>svn status</code></a> command...
2008/10/19
[ "https://Stackoverflow.com/questions/216049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8123/" ]
Sometimes you're developing and you decide to commit, forgetting you created a few files on your project. Then a few days down the line your buddy gets your build out of Subversion and complains that some files appear to be missing. You realize, ah crap, I forgot to add those files! How can I get a list of the files t...
Use the [`svn status`](http://svnbook.red-bean.com/en/1.0/re26.html) command: ``` svn status | grep ^? ``` Files that are not versioned are indicated with a ? at the start of the line. If you find that you always have some specific files that should not be added to the repository (for example, generated binaries), ...
216,068
<p>I am parsing an input text file. If I grab the input one line at a time using getline(), is there a way that I can search through the string to get an integer? I was thinking something similar to getNextInt() in Java. </p> <p>I know there has to be 2 numbers in that input line; however, these values will be separ...
[ { "answer_id": 216072, "author": "Eclipse", "author_id": 8701, "author_profile": "https://Stackoverflow.com/users/8701", "pm_score": 3, "selected": true, "text": "<p>If the only thing in there is whitespace and integers, just try something like this:</p>\n\n<pre><code>int i1, i2;\nstring...
2008/10/19
[ "https://Stackoverflow.com/questions/216068", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29326/" ]
I am parsing an input text file. If I grab the input one line at a time using getline(), is there a way that I can search through the string to get an integer? I was thinking something similar to getNextInt() in Java. I know there has to be 2 numbers in that input line; however, these values will be separated by one ...
If the only thing in there is whitespace and integers, just try something like this: ``` int i1, i2; stringstream ss(lineFromGetLine); ss >> i1 >> i2; ``` or easier: ``` int i1, i2; theFileStream >> i1 >> i2; ```
216,070
<p>I'm trying to create a POST request, unfortunately the body of the POST never seems to be sent.</p> <p>Below is the code that I'm using. The code is invoked when a user clicks on a link, not a form "submit" button. It runs without error, invokes the servlet that is being called but, as I mentioned earlier, the bo...
[ { "answer_id": 216074, "author": "Paolo Bergantino", "author_id": 16417, "author_profile": "https://Stackoverflow.com/users/16417", "pm_score": 4, "selected": true, "text": "<p>These are the kind of situations where Firebug and Firefox are really helpful. I suggest you install Firebug if...
2008/10/19
[ "https://Stackoverflow.com/questions/216070", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4962/" ]
I'm trying to create a POST request, unfortunately the body of the POST never seems to be sent. Below is the code that I'm using. The code is invoked when a user clicks on a link, not a form "submit" button. It runs without error, invokes the servlet that is being called but, as I mentioned earlier, the body of the PO...
These are the kind of situations where Firebug and Firefox are really helpful. I suggest you install Firebug if you don't have it and check the request that is being sent. You also definitely need to stick to `parameters` instead of `requestBody`. This: ``` new Ajax.Request(sURL, { method: 'POST', parameters...
216,076
<p>Is it possible to scale a UIView down to 0 (width and height is 0) using CGAffineTransformMakeScale?</p> <p>view.transform = CGAffineTransformMakeScale(0.0f, 0.0f);</p> <p>Why would this throw an error of &quot;<code>&lt;Error&gt;: CGAffineTransformInvert: singular matrix.</code>&quot; ?</p> <br /> <br /> <p><em>Upd...
[ { "answer_id": 216322, "author": "Ben Gottlieb", "author_id": 6694, "author_profile": "https://Stackoverflow.com/users/6694", "pm_score": 3, "selected": false, "text": "<p>I'm not sure it's possible to do this; you'll start running into divide-by-zero issues. If you try to do this, you'l...
2008/10/19
[ "https://Stackoverflow.com/questions/216076", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1987/" ]
Is it possible to scale a UIView down to 0 (width and height is 0) using CGAffineTransformMakeScale? view.transform = CGAffineTransformMakeScale(0.0f, 0.0f); Why would this throw an error of "`<Error>: CGAffineTransformInvert: singular matrix.`" ? *Update: There is another way of scaling down a UIView to 0* ``` [UI...
There are lots of times when the underlying frameworks need to invert your transform matrix. The inverse of a matrix is some matrix M' such that the product of your matrix M and the inverse matrix M' is the identify matrix 1. 1 = M \* M' The zero matrix does not have an inverse, hence the error message.
216,093
<p>I am working on a desktop application in PyGTK and seem to be bumping up against some limitations of my file organization. Thus far I've structured my project this way:</p> <ul> <li>application.py - holds the primary application class (most functional routines)</li> <li>gui.py - holds a loosely coupled GTK gui imp...
[ { "answer_id": 216098, "author": "JesperE", "author_id": 13051, "author_profile": "https://Stackoverflow.com/users/13051", "pm_score": 2, "selected": false, "text": "<p>This has likely nothing to do with PyGTK, but rather a general code organization issue. You would probably benefit from...
2008/10/19
[ "https://Stackoverflow.com/questions/216093", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24608/" ]
I am working on a desktop application in PyGTK and seem to be bumping up against some limitations of my file organization. Thus far I've structured my project this way: * application.py - holds the primary application class (most functional routines) * gui.py - holds a loosely coupled GTK gui implementation. Handles s...
In the project [Wader](http://wader-project.org) we use [python gtkmvc](http://pygtkmvc.sourceforge.net/), that makes much easier to apply the MVC patterns when using pygtk and glade, you can see the file organization of our project in the [svn repository](http://trac.wader-project.org/browser/trunk/wader): ``` wader/...
216,094
<p>I'm trying to get my head around SPL iterators and I've come up with 2 ways to handle it. I see the first version to be less complicated but the second version has composition feel to it (I think).</p> <p>What am I not seeing is which one is preferable over the other? Or am I just over complicating this?</p> <p>He...
[ { "answer_id": 216099, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>It depends on the situation. Is the box of chocolates going t0 contain multiple collections? If so you need to have the col...
2008/10/19
[ "https://Stackoverflow.com/questions/216094", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29230/" ]
I'm trying to get my head around SPL iterators and I've come up with 2 ways to handle it. I see the first version to be less complicated but the second version has composition feel to it (I think). What am I not seeing is which one is preferable over the other? Or am I just over complicating this? Here are my thought...
It depends on the situation. Is the box of chocolates going t0 contain multiple collections? If so you need to have the collections be members. Think of it this way. Is a box of chocolates a collection (i.e. PersonList) or something that owns a collection (i.e. a car may own a collection of it's last owners). I think...
216,109
<p>I get this message:</p> <blockquote> <p>Cannot find the X.509 certificate using the following search criteria: StoreName 'My', StoreLocation 'LocalMachine', FindType 'FindBySubjectDistinguishedName', FindValue 'CN=HighBall'.</p> </blockquote> <p>My web.config setup looks like this;</p> <p>Authentication is set ...
[ { "answer_id": 216148, "author": "VP.", "author_id": 18642, "author_profile": "https://Stackoverflow.com/users/18642", "pm_score": 3, "selected": true, "text": "<p>Check the other post about the tool that you asked about. Verify your \"my\" storage and check if the CN=\"HighBall\". I gue...
2008/10/19
[ "https://Stackoverflow.com/questions/216109", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29345/" ]
I get this message: > > Cannot find the X.509 certificate using the following search criteria: StoreName 'My', StoreLocation 'LocalMachine', FindType 'FindBySubjectDistinguishedName', FindValue 'CN=HighBall'. > > > My web.config setup looks like this; Authentication is set like... ``` <authentication mode="Wind...
Check the other post about the tool that you asked about. Verify your "my" storage and check if the CN="HighBall". I guess your CN is not just "HighBall", probably it has a top level domain. I think it's easier to look for the certificate serial number, i think it's faster than for it's canonical name and error prone. ...
216,119
<p>I want to have a function that will return the reverse of a list that it is given -- using recursion. How can I do that?</p>
[ { "answer_id": 216123, "author": "JesperE", "author_id": 13051, "author_profile": "https://Stackoverflow.com/users/13051", "pm_score": 0, "selected": false, "text": "<p>Take the first element, reverse the rest of the list recursively, and append the first element at the end of the list.<...
2008/10/19
[ "https://Stackoverflow.com/questions/216119", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11324/" ]
I want to have a function that will return the reverse of a list that it is given -- using recursion. How can I do that?
Append the first element of the list to a reversed sublist: ``` mylist = [1, 2, 3, 4, 5] backwards = lambda l: (backwards (l[1:]) + l[:1] if l else []) print backwards (mylist) ```
216,124
<p>Say I have a struct "s" with an int pointer member variable "i". I allocate memory on the heap for i in the default constructor of s. Later in some other part of the code I pass an instance of s by value to some function. Am I doing a shallow copy here? Assume I didn't implement any copy constructors or assignme...
[ { "answer_id": 216128, "author": "Don Neufeld", "author_id": 13097, "author_profile": "https://Stackoverflow.com/users/13097", "pm_score": 3, "selected": false, "text": "<p>Yes, that's a shallow copy. You now have two copies of s (one in the caller, one on the stack as a parameter), eac...
2008/10/19
[ "https://Stackoverflow.com/questions/216124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22471/" ]
Say I have a struct "s" with an int pointer member variable "i". I allocate memory on the heap for i in the default constructor of s. Later in some other part of the code I pass an instance of s by value to some function. Am I doing a shallow copy here? Assume I didn't implement any copy constructors or assignment oper...
To follow up on what @[don.neufeld.myopenid.com] said, it is not only a shallow copy, but it is either (take your pick) a memory leak or a dangling pointer. ``` // memory leak (note that the pointer is never deleted) class A { B *_b; public: A() : _b(new B) { } }; // dangling ptr (who deletes the instance...
216,138
<p>Are any of you aware of a library that helps you build/manipulate SQL queries, that supports JOIN's?</p> <p>It would give a lot of flexibility i'd think if you have something where you could return an object, that has some query set, and still be able to apply JOIN's to it, subqueries and such.</p> <p>I've search ...
[ { "answer_id": 216149, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 3, "selected": false, "text": "<p>Maybe you can try an <a href=\"http://en.wikipedia.org/wiki/Object-relational_mapping\" rel=\"noreferrer\">O...
2008/10/19
[ "https://Stackoverflow.com/questions/216138", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20538/" ]
Are any of you aware of a library that helps you build/manipulate SQL queries, that supports JOIN's? It would give a lot of flexibility i'd think if you have something where you could return an object, that has some query set, and still be able to apply JOIN's to it, subqueries and such. I've search around, and have ...
Maybe you can try an [ORM](http://en.wikipedia.org/wiki/Object-relational_mapping), like [Propel](http://propel.phpdb.org/trac/) or [Doctrine](http://www.doctrine-project.org/), they have a nice programmatic query language, and they return you arrays of objects that represent rows in your database... For example with ...
216,141
<p>The point of this question is to create the shortest <b>not abusively slow</b> Sudoku solver. This is defined as: <b>don't recurse when there are spots on the board which can only possibly be one digit</b>.</p> <p>Here is the shortest I have so far in python:</p> <pre><code>r=range(81) s=range(1,10) def R(A): ...
[ { "answer_id": 216603, "author": "Claudiu", "author_id": 15055, "author_profile": "https://Stackoverflow.com/users/15055", "pm_score": 2, "selected": false, "text": "<p>I've just trimmed the python a bit here:</p>\n\n<pre><code>r=range(81);s=range(1,10)\ndef R(A):\n z={}\n for i in...
2008/10/19
[ "https://Stackoverflow.com/questions/216141", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15055/" ]
The point of this question is to create the shortest **not abusively slow** Sudoku solver. This is defined as: **don't recurse when there are spots on the board which can only possibly be one digit**. Here is the shortest I have so far in python: ``` r=range(81) s=range(1,10) def R(A): bzt={} for i in r: ...
I haven't really made much of a change - the algorithm is identical, but here are a few further micro-optimisations you can make to your python code. * No need for !=0, 0 is false in a boolean context. * a if c else b is more expensive than using [a,b][c] if you don't need short-circuiting, hence you can use `h[ [0,A[...
216,150
<p>Where do you draw the line to stop making abstractions and to start writing sane code? There are tons of examples of 'enterprise code' such as the dozen-file "FizzBuzz" program... even something simple such as an RTS game can have something like:</p> <pre><code>class Player {} ;/// contains Weapons class Weapons{} ...
[ { "answer_id": 216169, "author": "Paweł Hajdan", "author_id": 9403, "author_profile": "https://Stackoverflow.com/users/9403", "pm_score": 5, "selected": true, "text": "<ol>\n<li><strong>YAGNI (You Ain't Gotta Need It).</strong> Don't create abstractions you don't see immediate use for or...
2008/10/19
[ "https://Stackoverflow.com/questions/216150", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15055/" ]
Where do you draw the line to stop making abstractions and to start writing sane code? There are tons of examples of 'enterprise code' such as the dozen-file "FizzBuzz" program... even something simple such as an RTS game can have something like: ``` class Player {} ;/// contains Weapons class Weapons{} ;/// contains ...
1. **YAGNI (You Ain't Gotta Need It).** Don't create abstractions you don't see immediate use for or a sensible reason. This way you have a simple thing that may become more complex, instead of a complicated things that you would strive to make simpler, but lose. 2. Make sure the abstractions make sense. If they're too...
216,155
<p>I want to allow users to paste <code>&lt;embed&gt;</code> and <code>&lt;object&gt;</code> HTML fragments (video players) via an HTML form. The server-side code is PHP. How can I protect against malicious pasted code, JavaScript, etc? I could parse the pasted code, but I'm not sure I could account for all variations....
[ { "answer_id": 216157, "author": "Paolo Bergantino", "author_id": 16417, "author_profile": "https://Stackoverflow.com/users/16417", "pm_score": 3, "selected": true, "text": "<p>I'm not really sure what parameters <code>EMBED</code> and <code>OBJECT</code> take as I've never really dealt ...
2008/10/19
[ "https://Stackoverflow.com/questions/216155", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17307/" ]
I want to allow users to paste `<embed>` and `<object>` HTML fragments (video players) via an HTML form. The server-side code is PHP. How can I protect against malicious pasted code, JavaScript, etc? I could parse the pasted code, but I'm not sure I could account for all variations. Is there a better way?
I'm not really sure what parameters `EMBED` and `OBJECT` take as I've never really dealt with putting media on a page (which is actually kind of shocking to think about) but I would take a BB Code approach to it and do something like `[embed url="http://www.whatever.com/myvideo.whatever" ...]` and then you can parse ou...
216,173
<p>Is there anything in the header of an HTTP request that would allow me to differentiate between an AJAX call and a direct browser request from a given client? Are the user agent strings usually the same regardless?</p>
[ { "answer_id": 216180, "author": "Wilco", "author_id": 5291, "author_profile": "https://Stackoverflow.com/users/5291", "pm_score": 0, "selected": false, "text": "<p>After some research, it looks like the best approach would be to simply specify a custom user agent string when making AJAX...
2008/10/19
[ "https://Stackoverflow.com/questions/216173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5291/" ]
Is there anything in the header of an HTTP request that would allow me to differentiate between an AJAX call and a direct browser request from a given client? Are the user agent strings usually the same regardless?
If you use Prototype, jQuery, Mootools or YUI you should find a **X-Requested-With:XMLHttpRequest** header which will do the trick for you. It should be possible to insert whatever header you like with other libraries. At the lowest level, given a [XMLHttpRequest](http://www.w3.org/TR/XMLHttpRequest) or XMLHTTP object...
216,182
<p>When should I continue to make derived classes, and when should I just add conditionals to my code? eg for a missile</p> <pre><code>class Object; class Projectile : public Object; class Missile : public Projectile; class MissileGuided : public Missile; </code></pre> <p>Or should I implement that last one in the m...
[ { "answer_id": 216194, "author": "Vlad Gudim", "author_id": 22088, "author_profile": "https://Stackoverflow.com/users/22088", "pm_score": 4, "selected": true, "text": "<p>You may want to consider using <strong>strategy pattern</strong> instead of both approaches and encapsulate behaviour...
2008/10/19
[ "https://Stackoverflow.com/questions/216182", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6266/" ]
When should I continue to make derived classes, and when should I just add conditionals to my code? eg for a missile ``` class Object; class Projectile : public Object; class Missile : public Projectile; class MissileGuided : public Missile; ``` Or should I implement that last one in the missile's code? ``` void M...
You may want to consider using **strategy pattern** instead of both approaches and encapsulate behaviours within external classes. Then the behaviours can be injected into the Missile class to make it GuidedMissile or SpaceRocket or whatever else you need. This way excessive branching of logic within the Missile clas...
216,185
<p>Suppose to have a code like this:</p> <pre><code>&lt;div class="notSelected"&gt; &lt;label&gt;Name &lt;input type="text" name="name" id="name" /&gt; &lt;/label&gt; &lt;div class="description"&gt; Tell us what's your name to make us able to fake to be your friend whe...
[ { "answer_id": 216214, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 4, "selected": true, "text": "<p>I would recommend a look at jQuery for your task. It is quite easy to learn and produces nice effects quickly. But your ...
2008/10/19
[ "https://Stackoverflow.com/questions/216185", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21384/" ]
Suppose to have a code like this: ``` <div class="notSelected"> <label>Name <input type="text" name="name" id="name" /> </label> <div class="description"> Tell us what's your name to make us able to fake to be your friend when sending you an email. </div> </div> ...
I would recommend a look at jQuery for your task. It is quite easy to learn and produces nice effects quickly. But your described effect alone, pure JavaScript would also be enough. Make your DIVs always have a class called "selectable". You can toggle other CSS classes later on. Create a CSS class named "selected" an...
216,202
<p>I have a command that runs fine if I ssh to a machine and run it, but fails when I try to run it using a remote ssh command like : </p> <pre><code>ssh user@IP &lt;command&gt; </code></pre> <p>Comparing the output of "env" using both methods resutls in different environments. When I manually login to the machine an...
[ { "answer_id": 216204, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 9, "selected": true, "text": "<p>There are different types of shells. The SSH command execution shell is a non-interactive shell, whereas your norm...
2008/10/19
[ "https://Stackoverflow.com/questions/216202", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13523/" ]
I have a command that runs fine if I ssh to a machine and run it, but fails when I try to run it using a remote ssh command like : ``` ssh user@IP <command> ``` Comparing the output of "env" using both methods resutls in different environments. When I manually login to the machine and run env, I get much more envir...
There are different types of shells. The SSH command execution shell is a non-interactive shell, whereas your normal shell is either a login shell or an interactive shell. Description follows, from man bash: ``` A login shell is one whose first character of argument zero is a -, or one started with ...
216,209
<p>I'm looking for the best way to tell if an <code>&lt;mx:Image&gt;</code> has already fired the 'Event.COMPLETE' event. I want to do something if it has shown, or attach an event handler if it hasnt yet.</p> <p>something like :</p> <pre><code>if (newBackground.percentLoaded &lt; 100) </code></pre> <p>or</p> <pre...
[ { "answer_id": 216260, "author": "REA_ANDREW", "author_id": 67959, "author_profile": "https://Stackoverflow.com/users/67959", "pm_score": 0, "selected": false, "text": "<p>Have you not subscribed to the Complete Event. Or the Progress Event? Are you using a Loader? I am sure in flex y...
2008/10/19
[ "https://Stackoverflow.com/questions/216209", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24727/" ]
I'm looking for the best way to tell if an `<mx:Image>` has already fired the 'Event.COMPLETE' event. I want to do something if it has shown, or attach an event handler if it hasnt yet. something like : ``` if (newBackground.percentLoaded < 100) ``` or ``` if (newBackground.content != null) ``` i was originally...
I'm assuming you for some reason can't attach an `Event.COMPLETE` event listener to the Image before it starts loading. If this is the case, you could always subclass `mx.controls.Image` and add your own property `"loadingCompleted"` or `"complete"` that is initially `false` but gets set to `true` when the `Event.COMPL...
216,233
<p>I wrote a program which includes writing and reading from database. When I run the app and try to perform writing I call the following method:</p> <pre><code>public static void AddMessage(string callID, string content) { string select = "INSERT INTO Sporocilo (oznaka_klica, smer, vsebina, pr...
[ { "answer_id": 216257, "author": "WW.", "author_id": 14663, "author_profile": "https://Stackoverflow.com/users/14663", "pm_score": 2, "selected": true, "text": "<p>Are you performing a commit after this? It might be running your statement but then not committing the changes and doing an...
2008/10/19
[ "https://Stackoverflow.com/questions/216233", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22996/" ]
I wrote a program which includes writing and reading from database. When I run the app and try to perform writing I call the following method: ``` public static void AddMessage(string callID, string content) { string select = "INSERT INTO Sporocilo (oznaka_klica, smer, vsebina, prebrano, cas_za...
Are you performing a commit after this? It might be running your statement but then not committing the changes and doing an implicit rollback. I think the exception handling looks dodgy. There is no point catching something unless you can actually handle it in some way. The top level of your framework is the place for...
216,255
<p>I am writing a small program. The interface I am writing to control each repository that is made defines a method of Save(IPublicObject). I am using LINQ for the SQL Version of the repository CRUD. My question is this. I would like to have only the one method which accepts the interface type. I want to think ho...
[ { "answer_id": 216388, "author": "Aleris", "author_id": 20417, "author_profile": "https://Stackoverflow.com/users/20417", "pm_score": 0, "selected": false, "text": "<p>What you wish to do is to have a:</p>\n\n<pre><code>Repository.Save(publicObject)\n</code></pre>\n\n<p>and the repositor...
2008/10/19
[ "https://Stackoverflow.com/questions/216255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/67959/" ]
I am writing a small program. The interface I am writing to control each repository that is made defines a method of Save(IPublicObject). I am using LINQ for the SQL Version of the repository CRUD. My question is this. I would like to have only the one method which accepts the interface type. I want to think how I can ...
For LINQ-to-SQL, the data-context already does a lot of the mapping for you. As such, I think generics might be the best way to achieve a save while still having some consideration of your interface (although I'm not quite sure what the interface is giving you in this scenario...). You can access the generic aspect of...
216,278
<p>Out style:</p> <pre><code>bool result; if(something.TryParse(val, out result)) { DoSomething(result); } </code></pre> <p>Nullable style:</p> <pre><code>bool? result = something.TryParse2(val); if(result.HasValue) { DoSomething(result.Value); } </code></pre>
[ { "answer_id": 216280, "author": "REA_ANDREW", "author_id": 67959, "author_profile": "https://Stackoverflow.com/users/67959", "pm_score": 0, "selected": false, "text": "<p>I would probably use the second example. Although I see both as perfectly acceptable.</p>\n" }, { "answer_i...
2008/10/19
[ "https://Stackoverflow.com/questions/216278", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16526/" ]
Out style: ``` bool result; if(something.TryParse(val, out result)) { DoSomething(result); } ``` Nullable style: ``` bool? result = something.TryParse2(val); if(result.HasValue) { DoSomething(result.Value); } ```
TryParse(val, out result) is a idiom established by the .NET framework in int.TryParse, DateTime.TryParse, etc. It is likely that people that read the code will be familiar with this idiom, so you should stick to it, unless you find a very good reason not to.
216,294
<p>I've been playing with some algorithms on the internet for a while and I can't seem to get them to work, so I'm tossing the question out here;</p> <p>I am attempting to render a velocity vector line from a point. Drawing the line isn't difficult: just insert a line with length <code>velocity.length</code> into the ...
[ { "answer_id": 216298, "author": "Simon", "author_id": 24039, "author_profile": "https://Stackoverflow.com/users/24039", "pm_score": 1, "selected": false, "text": "<p><a href=\"http://mathworld.wolfram.com/RotationMatrix.html\" rel=\"nofollow noreferrer\">This</a> should do you</p>\n" ...
2008/10/19
[ "https://Stackoverflow.com/questions/216294", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23845/" ]
I've been playing with some algorithms on the internet for a while and I can't seem to get them to work, so I'm tossing the question out here; I am attempting to render a velocity vector line from a point. Drawing the line isn't difficult: just insert a line with length `velocity.length` into the graph. This puts the ...
[Dupe.](https://stackoverflow.com/questions/193918/what-is-the-easiest-way-to-align-the-z-axis-with-a-vector) > > The question there involves getting a rotation to a certain axis, whereas I'm concerned with getting a rotation matrix. > > > Gee, I wonder if you could turn [convert one to the other](http://www.goog...
216,315
<p>As it was made clear in my <a href="https://stackoverflow.com/questions/212009/do-i-have-to-explicitly-call-systemexit-in-a-webstart-application">recent question</a>, Swing applications need to explicitly call System.exit() when they are ran using the Sun Webstart launcher (at least as of Java SE 6).</p> <p>I want ...
[ { "answer_id": 216337, "author": "Tom", "author_id": 22850, "author_profile": "https://Stackoverflow.com/users/22850", "pm_score": 3, "selected": false, "text": "<p>Use the javax.jnlp.ServiceManager to retrieve a webstart service.\nIf it is availabe, you are running under Webstart.</p>\n...
2008/10/19
[ "https://Stackoverflow.com/questions/216315", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18187/" ]
As it was made clear in my [recent question](https://stackoverflow.com/questions/212009/do-i-have-to-explicitly-call-systemexit-in-a-webstart-application), Swing applications need to explicitly call System.exit() when they are ran using the Sun Webstart launcher (at least as of Java SE 6). I want to restrict this hack...
When your code is launched via javaws, javaws.jar is loaded and the JNLP API classes that you don't want to depend on are available. Instead of testing for a system property that is not guaranteed to exist, you could instead see if a JNLP API class exists: ``` private boolean isRunningJavaWebStart() { boolean hasJ...
216,324
<p>I'm creating a site where the user unfortunately has to provide a regex to be used in a MySQL WHERE clause. And of course I have to validate the user input to prevent SQL injection. The site is made in PHP, and I use the following regex to check my regex:</p> <pre><code>/^([^\\\\\']|\\\.)*$/ </code></pre> <p>This ...
[ { "answer_id": 216336, "author": "REA_ANDREW", "author_id": 67959, "author_profile": "https://Stackoverflow.com/users/67959", "pm_score": -1, "selected": false, "text": "<p>If it is anly for the purposes of display this reg expression then most programs simply Html Encode the value and s...
2008/10/19
[ "https://Stackoverflow.com/questions/216324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29373/" ]
I'm creating a site where the user unfortunately has to provide a regex to be used in a MySQL WHERE clause. And of course I have to validate the user input to prevent SQL injection. The site is made in PHP, and I use the following regex to check my regex: ``` /^([^\\\\\']|\\\.)*$/ ``` This is double-escaped because ...
If you use prepared statements, SQL injection will be impossible. You should always use prepared statements. Roborg makes an excellent point though about expensive regexes.
216,329
<p>In a PHP project I'm working on we need to create some DAL extensions to support multiple database platforms. The main pitfall we have with this is that different platforms have different syntaxes - notable MySQL and MSSQL are quite different.</p> <h2>What would be the best solution to this?</h2> <p>Here are a cou...
[ { "answer_id": 216336, "author": "REA_ANDREW", "author_id": 67959, "author_profile": "https://Stackoverflow.com/users/67959", "pm_score": -1, "selected": false, "text": "<p>If it is anly for the purposes of display this reg expression then most programs simply Html Encode the value and s...
2008/10/19
[ "https://Stackoverflow.com/questions/216329", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2025/" ]
In a PHP project I'm working on we need to create some DAL extensions to support multiple database platforms. The main pitfall we have with this is that different platforms have different syntaxes - notable MySQL and MSSQL are quite different. What would be the best solution to this? ----------------------------------...
If you use prepared statements, SQL injection will be impossible. You should always use prepared statements. Roborg makes an excellent point though about expensive regexes.
216,333
<p>When i use any of the other strongly typed HTML helpers after typing for example </p> <pre><code>Html.Actionlink&lt;HomeController&gt;(x=&gt;x. </code></pre> <p>This pops up intellisense on the methods that the HomeController class has. However for the example above, this does not happen. Only after inserting the ...
[ { "answer_id": 216502, "author": "LBugnion", "author_id": 12233, "author_profile": "https://Stackoverflow.com/users/12233", "pm_score": 0, "selected": false, "text": "<p>In my experience, Intellisense in ASPX pages is flaky to say the least. I experienced the same as you described, as we...
2008/10/19
[ "https://Stackoverflow.com/questions/216333", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29376/" ]
When i use any of the other strongly typed HTML helpers after typing for example ``` Html.Actionlink<HomeController>(x=>x. ``` This pops up intellisense on the methods that the HomeController class has. However for the example above, this does not happen. Only after inserting the link text (second parameter) and go...
You migth forget the controller type generic parameter: ``` Html.Actionlink<YourControllerType>(x=>x. ``` The controller type is needed here because views are not coupled to the controller. Views are coupled to the model only.
216,341
<p>I want to apply a function to all columns in a matrix with MATLAB. For example, I'd like to be able to call smooth on every column of a matrix, instead of having smooth treat the matrix as a vector (which is the default behaviour if you call <code>smooth(matrix)</code>).</p> <p>I'm sure there must be a more idiomat...
[ { "answer_id": 216468, "author": "bastibe", "author_id": 1034, "author_profile": "https://Stackoverflow.com/users/1034", "pm_score": 0, "selected": false, "text": "<p>If this is a common use-case for your function, it would perhaps be a good idea to make the function iterate through the ...
2008/10/19
[ "https://Stackoverflow.com/questions/216341", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3829/" ]
I want to apply a function to all columns in a matrix with MATLAB. For example, I'd like to be able to call smooth on every column of a matrix, instead of having smooth treat the matrix as a vector (which is the default behaviour if you call `smooth(matrix)`). I'm sure there must be a more idiomatic way to do this, bu...
Your solution is fine. Note that horizcat exacts a substantial performance penalty for large matrices. It makes the code be O(N^2) instead of O(N). For a 100x10,000 matrix, your implementation takes 2.6s on my machine, the horizcat one takes 64.5s. For a 100x5000 matrix, the horizcat implementation takes 15.7s. If yo...
216,391
<p>I was just wondering, if by moving complex if else statements and the resulting html markup to the code behind violates some 'MVC' law?</p> <p>It seems like a great option when faced with inline if else statements that can become extremely unreadable.</p>
[ { "answer_id": 216451, "author": "mohammedn", "author_id": 29268, "author_profile": "https://Stackoverflow.com/users/29268", "pm_score": 0, "selected": false, "text": "<p>I believe as long as it's a rendering code and it's in a \"View\" not in a controller, then putting it on code behind...
2008/10/19
[ "https://Stackoverflow.com/questions/216391", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29376/" ]
I was just wondering, if by moving complex if else statements and the resulting html markup to the code behind violates some 'MVC' law? It seems like a great option when faced with inline if else statements that can become extremely unreadable.
I prefer not to use the code behind class in my views. This is not because it violates MVC by default, but because I found that the "natural" way (at least for me) is different. When I face complex HTML markup that relates to purely view concerns, I usually write an extension method for `HtmlHelper` class in order to...
216,409
<p>I have a very strange problem, when I try to <code>var_dump</code> (or <code>print_r</code>) a Doctrine Object, my Apache responses with an empty blank page (200 OK header). I can <code>var_dump</code> a normal php var like:</p> <pre><code>$dummy = array("a" =&gt; 1, "b" =&gt;2); </code></pre> <p>And it works fine...
[ { "answer_id": 216427, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": 2, "selected": true, "text": "<p>I've had that sometimes when trying to <code>print_r()</code> a self-referencing object - it gets into a loop and runs out ...
2008/10/19
[ "https://Stackoverflow.com/questions/216409", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a very strange problem, when I try to `var_dump` (or `print_r`) a Doctrine Object, my Apache responses with an empty blank page (200 OK header). I can `var_dump` a normal php var like: ``` $dummy = array("a" => 1, "b" =>2); ``` And it works fine. But I can't with any object from any Doctrine class, (like a re...
I've had that sometimes when trying to `print_r()` a self-referencing object - it gets into a loop and runs out of memory. Possibly that's what's happening to you. Try increasing the memory limit (`ini_set('memory_limit', '256M');`) and see if that fixes it. Edit: I don't think there's an actual fix for this - it's P...
216,426
<p>As I understand it, when asked to reserve a larger block of memory, the realloc() function will do one of three different things:</p> <p><code><pre> if free contiguous block exists grow current block else if sufficient memory allocate new memory copy old memory to new free old memory else return...
[ { "answer_id": 216435, "author": "Draemon", "author_id": 26334, "author_profile": "https://Stackoverflow.com/users/26334", "pm_score": 0, "selected": false, "text": "<p>No <strike>- and if you think about it, it can't work. Between you checking what it's going to do and actually doing it...
2008/10/19
[ "https://Stackoverflow.com/questions/216426", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2289/" ]
As I understand it, when asked to reserve a larger block of memory, the realloc() function will do one of three different things: ```` if free contiguous block exists grow current block else if sufficient memory allocate new memory copy old memory to new free old memory else return null ```` Gro...
`realloc()`'s behavior is likely dependent on its specific implementation. And basing your code on that would be a terrible hack which, to say the least, violates encapsulation. A better solution for your specific example is: 1. Find the size of the current buffer * Allocate a new buffer (with `malloc()`), greater t...
216,450
<p>I have a C++ library and a C++ application trying to use functions and classes exported from the library. The library builds fine and the application compiles but fails to link. The errors I get follow this form:</p> <blockquote> <p>app-source-file.cpp:(.text+0x2fdb): undefined reference to `lib-namespace::GetSta...
[ { "answer_id": 216464, "author": "PiedPiper", "author_id": 19315, "author_profile": "https://Stackoverflow.com/users/19315", "pm_score": 4, "selected": true, "text": "<p>the U before _ZN3lib-namespace12GetStatusStrEi in the nm output shows that the symbol is <strong>undefined</strong> in...
2008/10/19
[ "https://Stackoverflow.com/questions/216450", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16429/" ]
I have a C++ library and a C++ application trying to use functions and classes exported from the library. The library builds fine and the application compiles but fails to link. The errors I get follow this form: > > app-source-file.cpp:(.text+0x2fdb): undefined reference to `lib-namespace::GetStatusStr(int)' > > >...
the U before \_ZN3lib-namespace12GetStatusStrEi in the nm output shows that the symbol is **undefined** in the library. Maybe it's defined in the wrong namespace: it looks like you're calling it in lib-namepace but you might be defining it in another.
216,484
<p>I have a groovy script with an unknown number of variables in context at runtime, how do I find them all and print the name and value of each?</p>
[ { "answer_id": 216507, "author": "Ted Naleid", "author_id": 8912, "author_profile": "https://Stackoverflow.com/users/8912", "pm_score": 6, "selected": true, "text": "<p>Well, if you're using a simple script (where you don't use the \"def\" keyword), the variables you define will be store...
2008/10/19
[ "https://Stackoverflow.com/questions/216484", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2031/" ]
I have a groovy script with an unknown number of variables in context at runtime, how do I find them all and print the name and value of each?
Well, if you're using a simple script (where you don't use the "def" keyword), the variables you define will be stored in the binding and you can get at them like this: ``` foo = "abc" bar = "def" if (true) { baz = "ghi" this.binding.variables.each {k,v -> println "$k = $v"} } ``` Prints: ``` foo = abc...
216,513
<p>Just getting started with Linq to SQL so forgive the newbie question. I'm trying to reproduce the following (working) query in Linq to SQL (VB.NET):</p> <pre><code>Select f.Title, TotalArea = Sum(c.Area) From Firms f Left Join Concessions c on c.FirmID = f.FirmID Group By f.Title Order by Sum(c.Area) DESC <...
[ { "answer_id": 216527, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 3, "selected": false, "text": "<p><a href=\"http://msdn.microsoft.com/en-us/vbasic/bb737922.aspx\" rel=\"noreferrer\">Here</a> you can find ma...
2008/10/19
[ "https://Stackoverflow.com/questions/216513", "https://Stackoverflow.com", "https://Stackoverflow.com/users/239663/" ]
Just getting started with Linq to SQL so forgive the newbie question. I'm trying to reproduce the following (working) query in Linq to SQL (VB.NET): ``` Select f.Title, TotalArea = Sum(c.Area) From Firms f Left Join Concessions c on c.FirmID = f.FirmID Group By f.Title Order by Sum(c.Area) DESC ``` (A Firm h...
Answer ------ Here's the correct Linq to SQL equivalent ``` From c In Concessions _ Join f In Firms on f.FirmID equals c.FirmID _ Group by f.Title _ Into TotalArea = sum(c.OfficialArea) _ Order by TotalArea Descending _ Select Title, TotalArea ``` Thanks to @CMS for pointing me to [LinqPad](http://www.linqpad.net/...
216,523
<p>I want to ask a question about how you would approach a simple object-oriented design problem. I have a few ideas of my own about what the best way of tackling this scenario, but I would be interested in hearing some opinions from the Stack Overflow community. Links to relevant online articles are also appreciated. ...
[ { "answer_id": 216537, "author": "yfeldblum", "author_id": 12349, "author_profile": "https://Stackoverflow.com/users/12349", "pm_score": 3, "selected": false, "text": "<p>The pure approach would be: Make everything an interface. As implementation details, you may optionally use any of va...
2008/10/19
[ "https://Stackoverflow.com/questions/216523", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7532/" ]
I want to ask a question about how you would approach a simple object-oriented design problem. I have a few ideas of my own about what the best way of tackling this scenario, but I would be interested in hearing some opinions from the Stack Overflow community. Links to relevant online articles are also appreciated. I'm...
Mark, This is an interesting question. You will find as many opinions on this. I don't believe there is a 'right' answer. This is a great example of where a rigid heirarchial object design can really cause problems after a system is built. For example, lets say you went with the "Customer" and "Staff" classes. You dep...
216,536
<p>I'm relatively new to web application programming so I hope this question isn't too basic for everyone. </p> <p>I created a HTML page with a FORM containing a dojox datagrid (v1.2) filled with rows of descriptions for different grocery items. After the user selects the item he's interested in, he will click on th...
[ { "answer_id": 216540, "author": "vaske", "author_id": 16039, "author_profile": "https://Stackoverflow.com/users/16039", "pm_score": 2, "selected": false, "text": "<p>It's good one, but better is to use some script language such as JSP,PHP, ASP....and you can use simple POST and GET meth...
2008/10/19
[ "https://Stackoverflow.com/questions/216536", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27163/" ]
I'm relatively new to web application programming so I hope this question isn't too basic for everyone. I created a HTML page with a FORM containing a dojox datagrid (v1.2) filled with rows of descriptions for different grocery items. After the user selects the item he's interested in, he will click on the "Submit" b...
You could just use a hidden input field; that gets transmitted as part of the form. ``` <html> <head> </head> <body> <script type="text/javascript"> function updateSelectedItemId() { document.myForm.selectedItemId.value = 2; alert(document.myForm.selectedItemId.value); // For yo...
216,538
<p>What is the best way to format a decimal if I only want decimal displayed if it is not an integer.</p> <p>Eg:</p> <pre><code>decimal amount = 1000M decimal vat = 12.50M </code></pre> <p>When formatted I want:</p> <pre><code>Amount: 1000 (not 1000.0000) Vat: 12.5 (not 12.50) </code></pre>
[ { "answer_id": 216550, "author": "Richard Nienaber", "author_id": 9539, "author_profile": "https://Stackoverflow.com/users/9539", "pm_score": 6, "selected": true, "text": "<pre><code> decimal one = 1000M;\n decimal two = 12.5M;\n\n Console.WriteLine(one.ToString(\"0.##\"));\n ...
2008/10/19
[ "https://Stackoverflow.com/questions/216538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8547/" ]
What is the best way to format a decimal if I only want decimal displayed if it is not an integer. Eg: ``` decimal amount = 1000M decimal vat = 12.50M ``` When formatted I want: ``` Amount: 1000 (not 1000.0000) Vat: 12.5 (not 12.50) ```
``` decimal one = 1000M; decimal two = 12.5M; Console.WriteLine(one.ToString("0.##")); Console.WriteLine(two.ToString("0.##")); ```
216,542
<p>I need to figure out a way uniquely identify each computer which visits the web site I am creating. Does anybody have any advice on how to achieve this?</p> <p>Because i want the solution to work on all machines and all browsers (within reason) I am trying to create a solution using javascript.</p> <p>Cookies will n...
[ { "answer_id": 216548, "author": "Steve", "author_id": 27893, "author_profile": "https://Stackoverflow.com/users/27893", "pm_score": 1, "selected": false, "text": "<p>I think cookies might be what you are looking for; this is how most websites uniquely identify visitors. </p>\n" }, {...
2008/10/19
[ "https://Stackoverflow.com/questions/216542", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3746/" ]
I need to figure out a way uniquely identify each computer which visits the web site I am creating. Does anybody have any advice on how to achieve this? Because i want the solution to work on all machines and all browsers (within reason) I am trying to create a solution using javascript. Cookies will not do. I need ...
Introduction ============ I don't know if there is or ever will be a way to uniquely identify machines using a browser alone. The main reasons are: * You will need to save data on the users computer. This data can be deleted by the user any time. Unless you have a way to recreate this data which is unique for each an...
216,588
<p>I am displaying a scrolled data table in a web page. This table has several thousands of dynamic rows, so it is loaded from the server (via AJAX).</p> <p>The user can scroll up and down, so what I need is to <strong>detect when the user reaches the end of the scrollbar</strong> (that is, the last row at the bottom...
[ { "answer_id": 216607, "author": "Yuval Adam", "author_id": 24545, "author_profile": "https://Stackoverflow.com/users/24545", "pm_score": 2, "selected": false, "text": "<p>I'm not familiar with the specific element you are using, but in order \n to implement this on a full size window, y...
2008/10/19
[ "https://Stackoverflow.com/questions/216588", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12388/" ]
I am displaying a scrolled data table in a web page. This table has several thousands of dynamic rows, so it is loaded from the server (via AJAX). The user can scroll up and down, so what I need is to **detect when the user reaches the end of the scrollbar** (that is, the last row at the bottom of the table) in order ...
Thank you for your answers. That's my final working code (inspired by Greg and [ajaxian.com](http://ajaxian.com/archives/implementing-infinite-scrolling-with-jquery)), that uses some jQuery functions and works with the [YUI DataTable](http://developer.yahoo.com/yui/datatable/). ``` $(".yui-dt-bd").scroll(load_more); ...
216,600
<p>How would I go about adding <code>enctype="multipart/form-data"</code> to a form that is generated by using <code>&lt;% Html.BeginForm(); %&gt;</code>?</p>
[ { "answer_id": 216604, "author": "liggett78", "author_id": 19762, "author_profile": "https://Stackoverflow.com/users/19762", "pm_score": 9, "selected": true, "text": "<p>As part of htmlAttributes,e.g.</p>\n\n<pre><code>Html.BeginForm(\n action, controller, FormMethod.Post, new { encty...
2008/10/19
[ "https://Stackoverflow.com/questions/216600", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1469/" ]
How would I go about adding `enctype="multipart/form-data"` to a form that is generated by using `<% Html.BeginForm(); %>`?
As part of htmlAttributes,e.g. ``` Html.BeginForm( action, controller, FormMethod.Post, new { enctype="multipart/form-data"}) ``` Or you can pass `null` for action and controller to get the same default target as for BeginForm() without any parameters: ``` Html.BeginForm( null, null, FormMethod.Post, new { ...
216,616
<p>How can I construct the following string in an Excel formula:</p> <blockquote> <p>Maurice &quot;The Rocket&quot; Richard</p> </blockquote> <p>If I'm using single quotes, it's trivial: <code>=&quot;Maurice 'The Rocket' Richard&quot;</code> but what about double quotes?</p>
[ { "answer_id": 216623, "author": "YonahW", "author_id": 3821, "author_profile": "https://Stackoverflow.com/users/3821", "pm_score": 10, "selected": true, "text": "<p>Have you tried escaping with an additional double-quote? By escaping a character, you are telling Excel to treat the &quot...
2008/10/19
[ "https://Stackoverflow.com/questions/216616", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2443/" ]
How can I construct the following string in an Excel formula: > > Maurice "The Rocket" Richard > > > If I'm using single quotes, it's trivial: `="Maurice 'The Rocket' Richard"` but what about double quotes?
Have you tried escaping with an additional double-quote? By escaping a character, you are telling Excel to treat the " character as literal text. ```sql = "Maurice ""The Rocket"" Richard" ```
216,657
<p>I have a table called logs which has a datetime field. I want to select the date and count of rows based on a particular date format. </p> <p>How do I do this using SQLAlchemy?</p>
[ { "answer_id": 216730, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 0, "selected": false, "text": "<p>I don't know SQLAlchemy, so I could be off-target. However, I think that all you need is:</p>\n\n<pre><code>S...
2008/10/19
[ "https://Stackoverflow.com/questions/216657", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1448/" ]
I have a table called logs which has a datetime field. I want to select the date and count of rows based on a particular date format. How do I do this using SQLAlchemy?
I don't know of a generic SQLAlchemy answer. Most databases support some form of date formatting, typically via functions. SQLAlchemy supports calling functions via sqlalchemy.sql.func. So for example, using SQLAlchemy over a Postgres back end, and a table my\_table(foo varchar(30), when timestamp) I might do something...
216,664
<p>I have images being sent to my database from a remote video source at about 5 frames per second as JPEG images. I am trying to figure out how to get those images into a video format so I can stream a live video feed to Silverlight.</p> <p>It seems to make sense to create a MJPEG stream but I'm having a few problems...
[ { "answer_id": 216682, "author": "dicroce", "author_id": 3886, "author_profile": "https://Stackoverflow.com/users/3886", "pm_score": 0, "selected": false, "text": "<p>First, write your mjpeg frames out to separate files. You should then be able to open these in Phototshop (this will inde...
2008/10/19
[ "https://Stackoverflow.com/questions/216664", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13714/" ]
I have images being sent to my database from a remote video source at about 5 frames per second as JPEG images. I am trying to figure out how to get those images into a video format so I can stream a live video feed to Silverlight. It seems to make sense to create a MJPEG stream but I'm having a few problems. Firstly ...
I did MJPEG a long time ago (3-4 years ago) and I'm scratching my head trying to remember the details and I simply can't. But, if its possible, I would suggest finding some kind of web site that streams MJPEG content and fire up wireshark/ethereal and see what you get over the wire. My guess is you are missing some req...
216,673
<p>When I worked on the <a href="http://framework.zend.com/manual/en/zend.db.html" rel="noreferrer">Zend Framework's database component</a>, we tried to abstract the functionality of the <code>LIMIT</code> clause supported by MySQL, PostgreSQL, and SQLite. That is, creating a query could be done this way:</p> <pre><c...
[ { "answer_id": 720280, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "<pre><code>SELECT TOP n *\nFROM tablename\nWHERE key NOT IN (\n SELECT TOP x key\n FROM tablename\n ORDER BY key\n ...
2008/10/19
[ "https://Stackoverflow.com/questions/216673", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20860/" ]
When I worked on the [Zend Framework's database component](http://framework.zend.com/manual/en/zend.db.html), we tried to abstract the functionality of the `LIMIT` clause supported by MySQL, PostgreSQL, and SQLite. That is, creating a query could be done this way: ``` $select = $db->select(); $select->from('mytable');...
``` SELECT TOP n * FROM tablename WHERE key NOT IN ( SELECT TOP x key FROM tablename ORDER BY key DESC ); ```
216,710
<p>When I run the following, PowerShell hangs waiting for the dialog to close, even though the dialog is never displayed:</p> <pre><code>[void] [Reflection.Assembly]::LoadWithPartialName( 'System.Windows.Forms' ) $d = New-Object Windows.Forms.OpenFileDialog $d.ShowDialog( ) </code></pre> <p>Calling <code>ShowDialog</...
[ { "answer_id": 216738, "author": "Steven Murawski", "author_id": 1233, "author_profile": "https://Stackoverflow.com/users/1233", "pm_score": 5, "selected": true, "text": "<p>I was able to duplicate your problem and found a workaround. I don't know why this happens, but it has happened t...
2008/10/19
[ "https://Stackoverflow.com/questions/216710", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2495/" ]
When I run the following, PowerShell hangs waiting for the dialog to close, even though the dialog is never displayed: ``` [void] [Reflection.Assembly]::LoadWithPartialName( 'System.Windows.Forms' ) $d = New-Object Windows.Forms.OpenFileDialog $d.ShowDialog( ) ``` Calling `ShowDialog` on a `Windows.Forms.Form` works...
I was able to duplicate your problem and found a workaround. I don't know why this happens, but it has happened to others. If you set the ShowHelp property to $true, you will get the dialog to come up properly. Example: ``` [void] [Reflection.Assembly]::LoadWithPartialName( 'System.Windows.Forms' ) $d = New-Object W...
216,716
<p>In a <a href="https://stackoverflow.com/questions/215933/gcc-compiler-error-on-windows-xp">recent issue</a>, I've found that DJGPP can only accept the DOS command line character limit. To work around this limitation, I've decided to try to write a makefile to allow me to <a href="http://www.delorie.com/djgpp/v2faq/...
[ { "answer_id": 216767, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 2, "selected": false, "text": "<p>Let's try a non-comment answer...</p>\n\n<p>Possibility A:</p>\n\n<ul>\n<li>Your macro for SFILES is looking f...
2008/10/19
[ "https://Stackoverflow.com/questions/216716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1256/" ]
In a [recent issue](https://stackoverflow.com/questions/215933/gcc-compiler-error-on-windows-xp), I've found that DJGPP can only accept the DOS command line character limit. To work around this limitation, I've decided to try to write a makefile to allow me to [pass longer strings](http://www.delorie.com/djgpp/v2faq/fa...
What you are trying to do will not work without VPATH, and since you are still learning makefiles, I would avoid using VPATH. The rule is looking for "consoleio.c", which if I understood your makefile correctly does not exist; what exists is "source/consoleio.c". You probably should change it to something like "$(SOUR...
216,748
<p>What are the pros and cons of using nested public C++ classes and enumerations? For example, suppose you have a class called <code>printer</code>, and this class also stores information on output trays, you could have:</p> <pre><code>class printer { public: std::string name_; enum TYPE { TYPE_...
[ { "answer_id": 216754, "author": "Adam Rosenfield", "author_id": 9530, "author_profile": "https://Stackoverflow.com/users/9530", "pm_score": 3, "selected": false, "text": "<p>One con that can become a big deal for large projects is that it is impossible to make a forward declaration for ...
2008/10/19
[ "https://Stackoverflow.com/questions/216748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9236/" ]
What are the pros and cons of using nested public C++ classes and enumerations? For example, suppose you have a class called `printer`, and this class also stores information on output trays, you could have: ``` class printer { public: std::string name_; enum TYPE { TYPE_LOCAL, TYPE_NETWOR...
Nested classes -------------- There are several side effects to classes nested inside classes that I usually consider flaws (if not pure antipatterns). Let's imagine the following code : ``` class A { public : class B { /* etc. */ } ; // etc. } ; ``` Or even: ``` class A { public : class B ;...
216,749
<p>I have a WPF project defined like this:</p> <pre> MyApp.sln MyAppWPF MyApp.Domain </pre> <p>In one of my xaml files in the MyAppWPF project I'm trying to reference a class defined in MyApp.Domain project. I have a <strong>project reference</strong> in MyAppWPF to MyApp.Domain. I am trying to create the refer...
[ { "answer_id": 216759, "author": "Gishu", "author_id": 1695, "author_profile": "https://Stackoverflow.com/users/1695", "pm_score": 2, "selected": false, "text": "<p>Check if </p>\n\n<ol>\n<li>the fully qualified name for MyClass is MyApp.Domain.MyClass </li>\n<li>MyClass has a default pu...
2008/10/19
[ "https://Stackoverflow.com/questions/216749", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16501/" ]
I have a WPF project defined like this: ``` MyApp.sln MyAppWPF MyApp.Domain ``` In one of my xaml files in the MyAppWPF project I'm trying to reference a class defined in MyApp.Domain project. I have a **project reference** in MyAppWPF to MyApp.Domain. I am trying to create the reference like this: ``` <Windo...
Check if 1. the fully qualified name for MyClass is MyApp.Domain.MyClass 2. MyClass has a default public constructor (with no parameters) so that XAML can instantiate it.
216,766
<p>File formats I would like to play include .wav, .mp3, .midi.</p> <p>I have tried using the Wireless Toolkit classes with no success. I have also tried using the AudioClip class that is part of the Samsung SDK; again with</p>
[ { "answer_id": 223635, "author": "michael aubert", "author_id": 17867, "author_profile": "https://Stackoverflow.com/users/17867", "pm_score": 1, "selected": false, "text": "<p>Without source code to review, I would suggest using the wireles toolkit (from <a href=\"http://java.sun.com)fir...
2008/10/19
[ "https://Stackoverflow.com/questions/216766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9771/" ]
File formats I would like to play include .wav, .mp3, .midi. I have tried using the Wireless Toolkit classes with no success. I have also tried using the AudioClip class that is part of the Samsung SDK; again with
If this device supports audio/mpeg you should be able to play mp3 use this code inside your midlet... This works on my nokia symbian phones ``` // Code starts here put this into midlet run() method public void run() { try { InputStream is = getClass().getResourceAsStream("your_audio_file.mp3"); player = ...
216,771
<p>I know that this is a simple question for PHP guys but I don't know the language and just need to do a simple "get" from another web page when my page is hit. i.e. signal the other page that this page has been hit.</p> <p>EDIT: curl is not available to me.</p>
[ { "answer_id": 216774, "author": "troelskn", "author_id": 18180, "author_profile": "https://Stackoverflow.com/users/18180", "pm_score": 4, "selected": true, "text": "<p>If curl wrappers are on (they are per default), you can use:</p>\n\n<pre><code>file_get_contents('http://www.example.or...
2008/10/19
[ "https://Stackoverflow.com/questions/216771", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1463/" ]
I know that this is a simple question for PHP guys but I don't know the language and just need to do a simple "get" from another web page when my page is hit. i.e. signal the other page that this page has been hit. EDIT: curl is not available to me.
If curl wrappers are on (they are per default), you can use: ``` file_get_contents('http://www.example.org'); ``` Note that this happens synchronous, so before the request has completed, your page won't either. It would be better to log access to a logfile (or database) and export the data occasionally. Alternativel...
216,781
<p>I have a java webapp that has to be deployed on either Win or Linux machines. I now want to add log4j for logging and I'd like to use a relative path for the log file as I don't want to change the file path on every deployment. The container will most likely be Tomcat but not necessarily.</p> <p>What's the best way...
[ { "answer_id": 216805, "author": "Steve K", "author_id": 739, "author_profile": "https://Stackoverflow.com/users/739", "pm_score": 7, "selected": false, "text": "<p>Tomcat sets a catalina.home system property. You can use this in your log4j properties file. Something like this:</p>\n\n...
2008/10/19
[ "https://Stackoverflow.com/questions/216781", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2697/" ]
I have a java webapp that has to be deployed on either Win or Linux machines. I now want to add log4j for logging and I'd like to use a relative path for the log file as I don't want to change the file path on every deployment. The container will most likely be Tomcat but not necessarily. What's the best way of doing ...
I've finally done it in this way. Added a ServletContextListener that does the following: ``` public void contextInitialized(ServletContextEvent event) { ServletContext context = event.getServletContext(); System.setProperty("rootPath", context.getRealPath("/")); } ``` Then in the log4j.properties file: ``...
216,796
<p>For homework, I was given the following 8 code fragments to analyze and give a Big-Oh notation for the running time. Can anybody please tell me if I'm on the right track? </p> <pre><code>//Fragment 1 for(int i = 0; i &lt; n; i++) sum++; </code></pre> <p>I'm thinking O(N) for fragment 1</p> <pre><code>//Frag...
[ { "answer_id": 216801, "author": "Kyle Cronin", "author_id": 658, "author_profile": "https://Stackoverflow.com/users/658", "pm_score": 5, "selected": true, "text": "<p>I think fragment 5 is O(n^3), and similarly fragment 7 is O(n^5)*. It also looks like O(log(n)) for fragment 8.</p>\n\n<...
2008/10/19
[ "https://Stackoverflow.com/questions/216796", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14013/" ]
For homework, I was given the following 8 code fragments to analyze and give a Big-Oh notation for the running time. Can anybody please tell me if I'm on the right track? ``` //Fragment 1 for(int i = 0; i < n; i++) sum++; ``` I'm thinking O(N) for fragment 1 ``` //Fragment 2 for(int i = 0; i < n; i+=2) sum...
I think fragment 5 is O(n^3), and similarly fragment 7 is O(n^5)\*. It also looks like O(log(n)) for fragment 8. For the n \* n problems, you have to execute the body of the loop n \* n times, so it would be O(n^2), then you compound that with the order of the other code. Fragment 8 actually doubles the counter instea...
216,817
<p>Similar to <a href="https://stackoverflow.com/questions/216710/call-openfiledialog-from-powershell">this question</a>, after running the following code the browser dialog does appear with all the correct buttons, but the selection area that usally displays available folders is missing:</p> <pre><code>[void] [Reflec...
[ { "answer_id": 216880, "author": "Steven Murawski", "author_id": 1233, "author_profile": "https://Stackoverflow.com/users/1233", "pm_score": 2, "selected": false, "text": "<p>I believe it is a problem with PowerShell running in a MTA Thread. You can run the CTP of Version 2 in a STA (s...
2008/10/19
[ "https://Stackoverflow.com/questions/216817", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2495/" ]
Similar to [this question](https://stackoverflow.com/questions/216710/call-openfiledialog-from-powershell), after running the following code the browser dialog does appear with all the correct buttons, but the selection area that usally displays available folders is missing: ``` [void] [Reflection.Assembly]::LoadWithP...
I encountered this problem a while back and found the following COM workaround on the MSDN forums: ``` $app = new-object -com Shell.Application $folder = $app.BrowseForFolder(0, "Select Folder", 0, "C:\") if ($folder.Self.Path -ne "") {write-host "You selected " $folder.Self.Path} ``` <http://www.microsoft.com/commu...
216,822
<p>There are some cool and exciting features in .NET 3.5/C# 3.0, and with those features comes some darn interesting ways to write the exact same line of code.</p> <p>Using the above stated tool set (and by extension .NET 2.0 stuff), what are the different ways the below code snippet could reasonably be rewritten? </p...
[ { "answer_id": 216828, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 4, "selected": true, "text": "<p>Lambda:</p>\n\n<pre><code>if (Directory.Exists(uploadDirectory)) \n Directory.GetFiles(uploadDirectory)\n .Where...
2008/10/19
[ "https://Stackoverflow.com/questions/216822", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27860/" ]
There are some cool and exciting features in .NET 3.5/C# 3.0, and with those features comes some darn interesting ways to write the exact same line of code. Using the above stated tool set (and by extension .NET 2.0 stuff), what are the different ways the below code snippet could reasonably be rewritten? ``` ...
Lambda: ``` if (Directory.Exists(uploadDirectory)) Directory.GetFiles(uploadDirectory) .Where(f => File.GetLastWriteTime(file) < DateTime.Now.AddHours(-12)) .Each(f => File.Delete(f)); ``` Edit: On 2nd thought, you can avoid the security lookups on each File access by using DirectoryInfo and FileInfo inst...
216,823
<p>I'm currently using the following code to right-trim all the <code>std::strings</code> in my programs:</p> <pre><code>std::string s; s.erase(s.find_last_not_of(" \n\r\t")+1); </code></pre> <p>It works fine, but I wonder if there are some end-cases where it might fail?</p> <p>Of course, answers with elegant altern...
[ { "answer_id": 216829, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 4, "selected": false, "text": "<p>In the case of an empty string, your code assumes that adding 1 to <code>string::npos</code> gives 0. <code>string::np...
2008/10/19
[ "https://Stackoverflow.com/questions/216823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14690/" ]
I'm currently using the following code to right-trim all the `std::strings` in my programs: ``` std::string s; s.erase(s.find_last_not_of(" \n\r\t")+1); ``` It works fine, but I wonder if there are some end-cases where it might fail? Of course, answers with elegant alternatives and also left-trim solution are welco...
**EDIT** Since c++17, some parts of the standard library were removed. Fortunately, starting with c++11, we have lambdas which are a superior solution. ``` #include <algorithm> #include <cctype> #include <locale> // trim from start (in place) static inline void ltrim(std::string &s) { s.erase(s.begin(), std::fin...
216,833
<p>I have a ASP.NET <code>GridView</code> with a column mapped to a boolean. I want do display "Yes"/"No" instead of "True"/"False". Well actually I want "Ja"/"Nej" (in Danish).</p> <p>Is this possible? </p> <pre><code>&lt;asp:gridview id="GridView1" runat="server" autogeneratecolumns="false"&gt; &lt;columns&gt; ...
[ { "answer_id": 216851, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 3, "selected": false, "text": "<p>Nope - but you could use a template column:</p>\n\n<pre><code>&lt;script runat=\"server\"&gt;\n TResult Eval&lt;T,...
2008/10/19
[ "https://Stackoverflow.com/questions/216833", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8547/" ]
I have a ASP.NET `GridView` with a column mapped to a boolean. I want do display "Yes"/"No" instead of "True"/"False". Well actually I want "Ja"/"Nej" (in Danish). Is this possible? ``` <asp:gridview id="GridView1" runat="server" autogeneratecolumns="false"> <columns> ... <asp:boundfield headerte...
I use this code for VB: ``` <asp:TemplateField HeaderText="Active" SortExpression="Active"> <ItemTemplate><%#IIf(Boolean.Parse(Eval("Active").ToString()), "Yes", "No")%></ItemTemplate> </asp:TemplateField> ``` And this should work for C# (untested): ``` <asp:TemplateField HeaderText="Active" SortExpression="Act...
216,865
<p>I'm wondering about the practical use of #undef in C. I'm working through K&amp;R, and am up to the preprocessor. Most of this was material I (more or less) understood, but something on page 90 (second edition) stuck out at me:</p> <blockquote> <p>Names may be undefined with <code>#undef</code>, usually to ensu...
[ { "answer_id": 216874, "author": "mipadi", "author_id": 28804, "author_profile": "https://Stackoverflow.com/users/28804", "pm_score": 2, "selected": false, "text": "<p>I only use it when a macro in an <code>#included</code> file is interfering with one of my functions (e.g., it has the s...
2008/10/19
[ "https://Stackoverflow.com/questions/216865", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14048/" ]
I'm wondering about the practical use of #undef in C. I'm working through K&R, and am up to the preprocessor. Most of this was material I (more or less) understood, but something on page 90 (second edition) stuck out at me: > > Names may be undefined with `#undef`, > usually to ensure that a routine is > really a f...
### What it does If you read Plauger's [The Standard C Library](https://smile.amazon.com/dp/0131315099) (1992), you will see that the `<stdio.h>` header is allowed to provide `getchar()` and `getc()` as function-like macros (with special permission for `getc()` to evaluate its file pointer argument more than once!). H...
216,870
<p>I'm using the following regex to capture a fixed width "description" field that is always 50 characters long:</p> <pre><code>(?.{50}) </code></pre> <p>My problem is that the descriptions sometimes contain a <em>lot</em> of whitespace, e.g.</p> <pre><code>"FLUID COMPRESSOR " </code>...
[ { "answer_id": 216877, "author": "dmckee --- ex-moderator kitten", "author_id": 2509, "author_profile": "https://Stackoverflow.com/users/2509", "pm_score": 1, "selected": false, "text": "<p>Is there a particular reason you are asking for a regular expression? They may not be the best too...
2008/10/19
[ "https://Stackoverflow.com/questions/216870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2773/" ]
I'm using the following regex to capture a fixed width "description" field that is always 50 characters long: ``` (?.{50}) ``` My problem is that the descriptions sometimes contain a *lot* of whitespace, e.g. ``` "FLUID COMPRESSOR " ``` Can somebody provide a regex that: 1. Trims ...
Substitute two or more spaces for one space: ``` s/ +/ /g ``` Edit: for any white space (not just spaces) you can use \s if you're using a perl-compatible regex library, and the curly brace syntax for number of occurrences, e.g. ``` s/\s\s+/ /g ``` or ``` s/\s{2,}/ /g ``` Edit #2: forgot the /g global suffix,...
216,875
<p>As mentioned in many of my previous questions, I'm working through K&amp;R, and am currently into the preprocessor. One of the more interesting things &mdash; something I never knew before from any of my prior attempts to learn C &mdash; is the <code>##</code> preprocessor operator. According to K&amp;R:</p> <block...
[ { "answer_id": 216888, "author": "Brian R. Bondy", "author_id": 3153, "author_profile": "https://Stackoverflow.com/users/3153", "pm_score": 7, "selected": true, "text": "<p><strong>CrashRpt: Using ## to convert macro multi-byte strings to Unicode</strong></p>\n\n<p>An interesting usage i...
2008/10/19
[ "https://Stackoverflow.com/questions/216875", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14048/" ]
As mentioned in many of my previous questions, I'm working through K&R, and am currently into the preprocessor. One of the more interesting things — something I never knew before from any of my prior attempts to learn C — is the `##` preprocessor operator. According to K&R: > > The preprocessor operator `##` > provi...
**CrashRpt: Using ## to convert macro multi-byte strings to Unicode** An interesting usage in CrashRpt (crash reporting library) is the following: ``` #define WIDEN2(x) L ## x #define WIDEN(x) WIDEN2(x) //Note you need a WIDEN2 so that __DATE__ will evaluate first. ``` Here they want to use a two-byte string instea...
216,890
<p>One of our providers are sometimes sending XML feeds that are tagged as UTF-8 encoded documents but includes characters that are not included in the UTF-8 charset. This causes the parser to throw an exception and stop building the DOM object when these characters are encountered:</p> <pre><code>DocumentBuilder.pars...
[ { "answer_id": 216950, "author": "CesarB", "author_id": 28258, "author_profile": "https://Stackoverflow.com/users/28258", "pm_score": 2, "selected": false, "text": "<p>You should manually take a look at the invalid documents and see what is the common problem to them. It's quite probable...
2008/10/19
[ "https://Stackoverflow.com/questions/216890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29042/" ]
One of our providers are sometimes sending XML feeds that are tagged as UTF-8 encoded documents but includes characters that are not included in the UTF-8 charset. This causes the parser to throw an exception and stop building the DOM object when these characters are encountered: ``` DocumentBuilder.parse(ByteArrayInp...
if the problem truly is the wrong encoding (as opposed to a mixed encoding), you don't need to re-encode the document to parse it. just parse it as a Reader instead of an InputStream and the dom parser will ignore the header: ``` DocumentBuilder.parse(new InpputSource(new InputStreamReader(inputStream, "<real encoding...
216,894
<p>What's the best way to pipe the output from an java.io.OutputStream to a String in Java?</p> <p>Say I have the method:</p> <pre><code> writeToStream(Object o, OutputStream out) </code></pre> <p>Which writes certain data from the object to the given stream. However, I want to get this output into a String as easi...
[ { "answer_id": 216913, "author": "Horcrux7", "author_id": 12631, "author_profile": "https://Stackoverflow.com/users/12631", "pm_score": 10, "selected": true, "text": "<p>I would use a <code>ByteArrayOutputStream</code>. And on finish you can call:</p>\n\n<pre><code>new String( baos.toByt...
2008/10/19
[ "https://Stackoverflow.com/questions/216894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4332/" ]
What's the best way to pipe the output from an java.io.OutputStream to a String in Java? Say I have the method: ``` writeToStream(Object o, OutputStream out) ``` Which writes certain data from the object to the given stream. However, I want to get this output into a String as easily as possible. I'm considering ...
I would use a `ByteArrayOutputStream`. And on finish you can call: ``` new String( baos.toByteArray(), codepage ); ``` or better: ``` baos.toString( codepage ); ``` For the `String` constructor, the `codepage` can be a `String` or an instance of [java.nio.charset.Charset](http://docs.oracle.com/javase/7/docs/api/...
216,959
<p>I have a web application with users and their documents. Each user can have many documents:</p> <p>user.rb: </p> <pre><code>has_many :documents </code></pre> <p>document.rb:</p> <pre><code>belongs_to :user </code></pre> <p>document_controller.rb:</p> <pre><code>def index @documents = Document.find(:all) en...
[ { "answer_id": 217011, "author": "sock", "author_id": 4028, "author_profile": "https://Stackoverflow.com/users/4028", "pm_score": 3, "selected": false, "text": "<p>You set a relationship in your User class to your Document class. This will automatically add a method to your User objects ...
2008/10/19
[ "https://Stackoverflow.com/questions/216959", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29441/" ]
I have a web application with users and their documents. Each user can have many documents: user.rb: ``` has_many :documents ``` document.rb: ``` belongs_to :user ``` document\_controller.rb: ``` def index @documents = Document.find(:all) end ``` I am using the restful\_authentication plugin. Here is my ...
Take a look [here](http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#M000530) in the rails API in the Association Join Models section. However be aware Restful authentication won't control access in order to limit the users to only their own records particularly with restful routes. They c...
216,963
<p>Say you have a large PHP project and suddenly, when attempting to run it, you just end up with a blank page. The script terminates and you want to find exactly where that is with as little effort as possible.</p> <p>Is there a tool/program/command/IDE that can, on PHP script termination, tell you the location of a ...
[ { "answer_id": 216966, "author": "Paul Nathan", "author_id": 26227, "author_profile": "https://Stackoverflow.com/users/26227", "pm_score": 0, "selected": false, "text": "<pre><code>grep -n die filename\n</code></pre>\n" }, { "answer_id": 216969, "author": "Edward Z. Yang", ...
2008/10/19
[ "https://Stackoverflow.com/questions/216963", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29442/" ]
Say you have a large PHP project and suddenly, when attempting to run it, you just end up with a blank page. The script terminates and you want to find exactly where that is with as little effort as possible. Is there a tool/program/command/IDE that can, on PHP script termination, tell you the location of a script exi...
With some inspiration from the nonworking but still right-direction answer from RoBorg, I used the following code in the beginning: ``` function shutdown() { global $dbg_stack_a; print_r($dbg_stack_a); } register_shutdown_function('shutdown'); ``` And then I made a global conditional breakpoint (global = bre...
216,995
<p>Say I want to copy the contents of a directory excluding files and folders whose names contain the word 'Music'.</p> <pre><code>cp [exclude-matches] *Music* /target_directory </code></pre> <p>What should go in place of [exclude-matches] to accomplish this?</p>
[ { "answer_id": 217004, "author": "Daniel Bungert", "author_id": 21093, "author_profile": "https://Stackoverflow.com/users/21093", "pm_score": 2, "selected": false, "text": "<p>One solution for this can be found with find.</p>\n\n<pre><code>$ mkdir foo bar\n$ touch foo/a.txt foo/Music.txt...
2008/10/19
[ "https://Stackoverflow.com/questions/216995", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4812/" ]
Say I want to copy the contents of a directory excluding files and folders whose names contain the word 'Music'. ``` cp [exclude-matches] *Music* /target_directory ``` What should go in place of [exclude-matches] to accomplish this?
In Bash you can do it by enabling the `extglob` option, like this (replace `ls` with `cp` and add the target directory, of course) ``` ~/foobar> shopt extglob extglob off ~/foobar> ls abar afoo bbar bfoo ~/foobar> ls !(b*) -bash: !: event not found ~/foobar> shopt -s extglob # Enables extglob ~/foobar> ls !...
217,065
<p>I'm working on a sparse matrix class that <strong>needs</strong> to use an array of <code>LinkedList</code> to store the values of a matrix. Each element of the array (i.e. each <code>LinkedList</code>) represents a row of the matrix. And, each element in the <code>LinkedList</code> array represents a column and the...
[ { "answer_id": 217093, "author": "Fredrik", "author_id": 9191, "author_profile": "https://Stackoverflow.com/users/9191", "pm_score": 7, "selected": false, "text": "<p>For some reason you have to cast the type and make the declaration like this:</p>\n\n<pre><code>myMatrix = (LinkedList&lt...
2008/10/19
[ "https://Stackoverflow.com/questions/217065", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22371/" ]
I'm working on a sparse matrix class that **needs** to use an array of `LinkedList` to store the values of a matrix. Each element of the array (i.e. each `LinkedList`) represents a row of the matrix. And, each element in the `LinkedList` array represents a column and the stored value. In my class, I have a declaration...
You can't use generic array creation. It's a flaw/ feature of java generics. The ways without warnings are: 1. Using List of Lists instead of Array of Lists: ``` List< List<IntegerNode>> nodeLists = new LinkedList< List< IntegerNode >>(); ``` 2. Declaring the special class for Array of Lists: ``` class IntegerNo...
217,067
<p>I have a button on an ASP.Net page that will call Response.Redirect back to the same page after performing some processing in order to re-display the results of a query. However, for some reason, the page comes up blank. It seems that IsPostBack is returning true after the redirect. Anybody know why this would happe...
[ { "answer_id": 217134, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 2, "selected": false, "text": "<p>A Response.Redirect will trigger an HTTP <em>GET</em> from the browser. As no data is posted, IsPostBack is false. ...
2008/10/19
[ "https://Stackoverflow.com/questions/217067", "https://Stackoverflow.com", "https://Stackoverflow.com/users/320/" ]
I have a button on an ASP.Net page that will call Response.Redirect back to the same page after performing some processing in order to re-display the results of a query. However, for some reason, the page comes up blank. It seems that IsPostBack is returning true after the redirect. Anybody know why this would happen? ...
Sorry, it was an id-10-t error. My event handler wasn't getting called at all. The page had EnableViewState="false". Once I changed that to true it worked. I also took tvanfosson suggestion. This allows me to display a confirmation message. I can easily check to see if the action has already been taken and safely igno...
217,070
<p>Using Apache's commons-httpclient for Java, what's the best way to add query parameters to a GetMethod instance? If I'm using PostMethod, it's very straightforward:</p> <pre><code>PostMethod method = new PostMethod(); method.addParameter("key", "value"); </code></pre> <p>GetMethod doesn't have an "addParameter" me...
[ { "answer_id": 217102, "author": "Ryan Guest", "author_id": 1811, "author_profile": "https://Stackoverflow.com/users/1811", "pm_score": 6, "selected": true, "text": "<p>Post methods have post parameters, but <a href=\"http://www.cs.tut.fi/~jkorpela/forms/methods.html\" rel=\"noreferrer\"...
2008/10/19
[ "https://Stackoverflow.com/questions/217070", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29173/" ]
Using Apache's commons-httpclient for Java, what's the best way to add query parameters to a GetMethod instance? If I'm using PostMethod, it's very straightforward: ``` PostMethod method = new PostMethod(); method.addParameter("key", "value"); ``` GetMethod doesn't have an "addParameter" method, though. I've discove...
Post methods have post parameters, but [get methods do not](http://www.cs.tut.fi/~jkorpela/forms/methods.html). Query parameters are embedded in the URL. The current version of HttpClient accepts a string in the constructor. If you wanted to add the key, value pair above, you could use: ``` String url = "http://www.e...
217,073
<p>I have a linked list that I want to sort part of, eg:</p> <pre><code>std::sort(someIterator, otherIterator, predicate); </code></pre> <p>std::sort requires random-access iterators so this approach doesn't work. There is a specialisation std::list::sort, but that can only sort the entire list. I don't think I have ...
[ { "answer_id": 217083, "author": "Leon Timmermans", "author_id": 4727, "author_profile": "https://Stackoverflow.com/users/4727", "pm_score": 2, "selected": false, "text": "<p>Yes, but you will have to use a <a href=\"http://en.literateprograms.org/Merge_sort_(C_Plus_Plus)\" rel=\"nofollo...
2008/10/19
[ "https://Stackoverflow.com/questions/217073", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22517/" ]
I have a linked list that I want to sort part of, eg: ``` std::sort(someIterator, otherIterator, predicate); ``` std::sort requires random-access iterators so this approach doesn't work. There is a specialisation std::list::sort, but that can only sort the entire list. I don't think I have enough access to the list ...
How about unhooking the part of the list that you want sorted, into a standalone list, then use the specialized list sort, then hook it back into the original list?
217,074
<p>I've been having a lot of problems trying to figure out how to use <code>scanf()</code>. It seems to work fine with integers, being fairly straight forward <code>scanf("%d", &amp;i)</code>.</p> <p>Where I am running into issues is using <code>scanf()</code> in loops trying to read input. For example:</p> <pre><c...
[ { "answer_id": 217085, "author": "Andrew Edgecombe", "author_id": 11694, "author_profile": "https://Stackoverflow.com/users/11694", "pm_score": 1, "selected": false, "text": "<p>For question 1, I suspect that you've got a problem with your <code>printf()</code>, since there is no termina...
2008/10/19
[ "https://Stackoverflow.com/questions/217074", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9628/" ]
I've been having a lot of problems trying to figure out how to use `scanf()`. It seems to work fine with integers, being fairly straight forward `scanf("%d", &i)`. Where I am running into issues is using `scanf()` in loops trying to read input. For example: ``` do { printf("counter: %d: ", counter); scanf("%c %c%...
When you enter "`c P101`" the program actually receives "`c P101\n`". Most of the conversion specifiers skip leading whitespace including newlines but `%c` does not. The first time around everything up til the "`\n`" is read, the second time around the "\n" is read into `command`, "`c`" is read into `prefix`, and "`P`"...
217,113
<p>Long time ago, I saved a sentence from a Java reference book: <em>"Java has no mechanism to handle deadlock. it won't even know deadlock occurred." (Head First Java 2nd Edition, p.516)</em></p> <p>So, what is about it? Is there a way to catch deadlock case in Java? I mean, is there a way that our code understands a...
[ { "answer_id": 217127, "author": "Steve K", "author_id": 739, "author_profile": "https://Stackoverflow.com/users/739", "pm_score": 4, "selected": false, "text": "<p><a href=\"http://java.sun.com/javase/6/docs/technotes/guides/management/jconsole.html\" rel=\"noreferrer\">JConsole</a> is ...
2008/10/19
[ "https://Stackoverflow.com/questions/217113", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26379/" ]
Long time ago, I saved a sentence from a Java reference book: *"Java has no mechanism to handle deadlock. it won't even know deadlock occurred." (Head First Java 2nd Edition, p.516)* So, what is about it? Is there a way to catch deadlock case in Java? I mean, is there a way that our code understands a deadlock case oc...
Since JDK 1.5 there are very useful methods in the `java.lang.management` package to find and inspect deadlocks that occurs. See the `findMonitorDeadlockedThreads()` and `findDeadlockedThreads()` method of the `ThreadMXBean` class. A possible way to use this is to have a separate watchdog thread (or periodic task) tha...
217,132
<p>So I have an Access application, and I'd like some forms to be maximised when they are opened, and others to be medium-sized when they are opened. However, if I try something like this:</p> <pre><code>Private Sub Form_Activate() DoCmd.Maximize End Sub </code></pre> <p>or</p> <pre><code>Private Sub Form_Activat...
[ { "answer_id": 217137, "author": "tzot", "author_id": 6899, "author_profile": "https://Stackoverflow.com/users/6899", "pm_score": 2, "selected": false, "text": "<p>Access is an MDI (Multiple Document Interface) application, and this is how they work: either all sub-windows are maximized,...
2008/10/19
[ "https://Stackoverflow.com/questions/217132", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
So I have an Access application, and I'd like some forms to be maximised when they are opened, and others to be medium-sized when they are opened. However, if I try something like this: ``` Private Sub Form_Activate() DoCmd.Maximize End Sub ``` or ``` Private Sub Form_Activate() DoCmd.Restore End Sub ``` it h...
[ΤΖΩΤΖΙΟΥ](https://stackoverflow.com/questions/217132/controlling-size-of-forms-in-access#217137) is 100% right when saying that either all are maximised, or none. If you really want to manage this issue, you'll have to read a little bit [**here**](http://www.utteraccess.com/forums/printthread.php?Cat=&Board=84&main=64...
217,149
<p>In programming we face various situations where we are required to make use of intermediate STL containers as the following example depicts:</p> <pre><code>while(true) { set &lt; int &gt; tempSet; for (int i = 0; i &lt; n; i ++) { if (m.size() == min &amp;&amp; m.size() &lt;= max) { ...
[ { "answer_id": 217153, "author": "Head Geek", "author_id": 12193, "author_profile": "https://Stackoverflow.com/users/12193", "pm_score": 2, "selected": false, "text": "<p>The second may be slightly better time-wise, but the difference will be extremely minimal -- the code still has to go...
2008/10/19
[ "https://Stackoverflow.com/questions/217149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6561/" ]
In programming we face various situations where we are required to make use of intermediate STL containers as the following example depicts: ``` while(true) { set < int > tempSet; for (int i = 0; i < n; i ++) { if (m.size() == min && m.size() <= max) { tempSet.insert(i); ...
The first version is correct. It is simpler in almost every way. Easier to write, easier to read, easier to understand, easier to maintain, etc.... The second version *may* be faster, but then again it may not. You would need to show that it had a significant advantage before using it. In most non-trivial cases I woul...
217,177
<p>Problem : I have multiple projects checked out in my depot. I also have multiple pending numbered change lists, each change list containing checked out files specific to its project. When I check out a new file, it appears in the default change list instead of in the change list that is relevant to its project and I...
[ { "answer_id": 217194, "author": "Michael Burr", "author_id": 12711, "author_profile": "https://Stackoverflow.com/users/12711", "pm_score": 2, "selected": false, "text": "<p>The way I handle this is that each project I'm working on has a separate client workspace configuration.</p>\n\n<p...
2008/10/19
[ "https://Stackoverflow.com/questions/217177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13760/" ]
Problem : I have multiple projects checked out in my depot. I also have multiple pending numbered change lists, each change list containing checked out files specific to its project. When I check out a new file, it appears in the default change list instead of in the change list that is relevant to its project and I ne...
The graphical clients make this pretty easy. Dragging a file(s) or folder(s) onto a change list will check it out for you. Instead of checking them out with the context menu or Ctrl+E, which will put them in the default change list, just drag them onto the appropriate change list and they are automatically checked out ...
217,187
<p>I am new to the world of ASP.NET and SQL server, so please pardon my ignorance ...</p> <p>If I have a data structure in C# (for e.g. let's just say, a vector that stores some strings), is it possible to store the contents of the vector as is in SQL table? I want to do this so that it fast to convert that data back ...
[ { "answer_id": 217199, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 2, "selected": false, "text": "<p>If you're gonna do that (and I guess it's technically <em>possible</em>), you might just as well use a flat file: ...
2008/10/19
[ "https://Stackoverflow.com/questions/217187", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25205/" ]
I am new to the world of ASP.NET and SQL server, so please pardon my ignorance ... If I have a data structure in C# (for e.g. let's just say, a vector that stores some strings), is it possible to store the contents of the vector as is in SQL table? I want to do this so that it fast to convert that data back into vecto...
First, there is the obvious route of simply creating a relational structure and mapping the object to fields in the database. Second, if you have an object that is serializable, you can store it in SQL server. I have done this on occasion, and have used the Text data type in SQL Server to store the XML. ***Opinion: ...
217,213
<p>Is there a way to make <strong>awk</strong> (gawk) ignore or skip missing files? That is, files passed on the command line that no longer exist in the file system (e.g. rapidly appearing/disappearing files under /proc/[1-9]*).</p> <p>By default, a missing file is a fatal error :-(</p> <p>I would like to be able to...
[ { "answer_id": 217267, "author": "Schwern", "author_id": 14660, "author_profile": "https://Stackoverflow.com/users/14660", "pm_score": 0, "selected": false, "text": "<p>In the finest of traditions, I will answer your awk question with a Perl program.</p>\n\n<pre><code>#!/usr/bin/perl -w\...
2008/10/20
[ "https://Stackoverflow.com/questions/217213", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Is there a way to make **awk** (gawk) ignore or skip missing files? That is, files passed on the command line that no longer exist in the file system (e.g. rapidly appearing/disappearing files under /proc/[1-9]\*). By default, a missing file is a fatal error :-( I would like to be able to do the equivalent of somethi...
GAWK 4 has `BEGINFILE` in which you can test for `ERRNO` and do a `nextfile` if `ERRNO` is not empty (indicating that the file couldn't be opened).
217,219
<p>I am using the Entity Framework and Linq to Entities. I have created a small database pattern &amp; framework to implement versioning as well as localization. Every entity now consists of two or three tables, (ie Product, ProductBase &amp; ProductLocal). </p> <p>My linq always includes the following boilerplat...
[ { "answer_id": 217277, "author": "Paul Mendoza", "author_id": 29277, "author_profile": "https://Stackoverflow.com/users/29277", "pm_score": 0, "selected": false, "text": "<p>You need to use the DataLoadOptions class so that it automatically loads the foreign key relationships you specify...
2008/10/20
[ "https://Stackoverflow.com/questions/217219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29466/" ]
I am using the Entity Framework and Linq to Entities. I have created a small database pattern & framework to implement versioning as well as localization. Every entity now consists of two or three tables, (ie Product, ProductBase & ProductLocal). My linq always includes the following boilerplate code: ``` from o in ...
Yes. You can do this by defining an extension method named IsActive on IQueryable. There is a property on IQueryable called "Expression" that returns an expression tree representing the chain of LINQ method calls that was generated from your query. In your case that will look something like this: ``` DB.Product.Sele...
217,233
<p>I have multiple layers in an application and i find myself having to bubble up events to the GUI layer for doing status bar changes, etc . . I find myself having to write repeated coded where each layer simply subscribes to events from the lower layer and then in the call back simply raise an event up the chain. Is...
[ { "answer_id": 217303, "author": "Hapkido", "author_id": 27646, "author_profile": "https://Stackoverflow.com/users/27646", "pm_score": 0, "selected": false, "text": "<p>You can have a central channel that only support events. This channel must be independent so the layer only publish or...
2008/10/20
[ "https://Stackoverflow.com/questions/217233", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
I have multiple layers in an application and i find myself having to bubble up events to the GUI layer for doing status bar changes, etc . . I find myself having to write repeated coded where each layer simply subscribes to events from the lower layer and then in the call back simply raise an event up the chain. Is the...
If all you're doing is firing an event handler from another event handler, you can cut out the middle man and hook the event handlers directly in the add/remove blocks for the event. For example, if you have a UserControl with a "SaveButtonClick" event, and all you want to do when is call the event handler when the "S...
217,257
<p>I want to sort members by name in the source code. Is there any easy way to do it? </p> <p>I'm using NetBeans, but if there is another editor that can do that, just tell me the name of it.</p>
[ { "answer_id": 217272, "author": "Paul Croarkin", "author_id": 18995, "author_profile": "https://Stackoverflow.com/users/18995", "pm_score": 3, "selected": false, "text": "<p>Eclipse can do it.</p>\n" }, { "answer_id": 217289, "author": "Martin", "author_id": 24364, "...
2008/10/20
[ "https://Stackoverflow.com/questions/217257", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8418/" ]
I want to sort members by name in the source code. Is there any easy way to do it? I'm using NetBeans, but if there is another editor that can do that, just tell me the name of it.
In Netbeans 8.0.1: ``` Tools -> Options -> Editor -> Formatting -> Category: Ordering ``` ![Netbeans member sorting](https://i.stack.imgur.com/7BxRT.png) Then: ``` Source -> Organize Members ``` ![Netbeans member sorting](https://i.stack.imgur.com/MO7Dc.png)
217,259
<p>Often, programmers write code that generates other code.</p> <p>(The technical term is <a href="http://en.wikipedia.org/wiki/Metaprogramming" rel="nofollow noreferrer" title="Wikipedia article on metaprogramming">metaprogramming</a>, but it is more common than merely cross-compilers; think about every PHP web-page ...
[ { "answer_id": 217264, "author": "Oddthinking", "author_id": 8014, "author_profile": "https://Stackoverflow.com/users/8014", "pm_score": 2, "selected": false, "text": "<p>A technique that I use when the generating code dominates over the generated code is to pass an indent parameter arou...
2008/10/20
[ "https://Stackoverflow.com/questions/217259", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8014/" ]
Often, programmers write code that generates other code. (The technical term is [metaprogramming](http://en.wikipedia.org/wiki/Metaprogramming "Wikipedia article on metaprogramming"), but it is more common than merely cross-compilers; think about every PHP web-page that generates HTML or every XSLT file.) One area I ...
In the more general case, I have written XSLT code that generates C++ database interface code. Although at first I tried to output correctly indented code from the XSLT, this quickly became untenable. My solution was to completely ignore formatting in the XSLT output, and then run the resulting very long line of code t...
217,266
<p>If the C++ runtime msvcr80.dll is missing from a compiled library, is there any way to determine which version was used to create the library or to get it to run on a later version of msvcr80.dll?</p>
[ { "answer_id": 217279, "author": "David Segonds", "author_id": 13673, "author_profile": "https://Stackoverflow.com/users/13673", "pm_score": 3, "selected": false, "text": "<p><a href=\"http://www.dependencywalker.com/\" rel=\"noreferrer\">Dependency Walker</a> will help you answer this q...
2008/10/20
[ "https://Stackoverflow.com/questions/217266", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4670/" ]
If the C++ runtime msvcr80.dll is missing from a compiled library, is there any way to determine which version was used to create the library or to get it to run on a later version of msvcr80.dll?
The VC80 SP1 CRT redistributable package will install both the RTM and SP1 versions of the C runtime into `%SystemRoot%\WinSxS` (assuming you're using Windows XP or Vista; Windows 2000 doesn't support side-by-side assemblies). If you have VC8 installed, the CRT redistributable package is in `%ProgramFiles%\Microsoft Vi...