qid int64 4 19.1M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
426,221 | <p>I have a query like this:</p>
<pre><code>SELECT t1.id,
(SELECT COUNT(t2.id)
FROM t2
WHERE t2.id = t1.id
) as num_things
FROM t1
WHERE num_things = 5;
</code></pre>
<p>The goal is to get the id of all the elements that appear 5 times in the other table. However, I get this error:</p>
<pre><code>ERROR: column "num_things" does not exist
SQL state: 42703
</code></pre>
<p>I'm probably doing something silly here, as I'm somewhat new to databases. Is there a way to fix this query so I can access <code>num_things</code>? Or, if not, is there any other way of achieving this result?</p>
| [
{
"answer_id": 426237,
"author": "Brian Fisher",
"author_id": 43816,
"author_profile": "https://Stackoverflow.com/users/43816",
"pm_score": 2,
"selected": true,
"text": "SELECT t1.id\nFROM t1\nWHERE (SELECT COUNT(t2.id)\n FROM t2\n WHERE t2.id = t1.id\n ) = 5;\n"
},
... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15055/"
] |
426,224 | <p>Consider the following:</p>
<pre><code>typedef struct
{
float m00, m01, m02, m03;
float m10, m11, m12, m13;
float m20, m21, m22, m23;
float m30, m31, m32, m33;
} Matrix;
@interface TestClass : NSObject
{
Matrix matrix;
}
- (TestClass *) init;
@end
</code></pre>
<hr>
<pre><code>@implementation TestClass
- (TestClass *) init
{
self = [super init];
matrix = (Matrix) {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
return self;
}
@end
</code></pre>
<p>How to ensure that the 64 bytes allocated with the struct are properly released whenever the "matrix" variable is not relevant anymore (or whenever the whole object is released)?</p>
| [
{
"answer_id": 426336,
"author": "Stefan Tannenbaum",
"author_id": 50511,
"author_profile": "https://Stackoverflow.com/users/50511",
"pm_score": 4,
"selected": true,
"text": "TestClass* testAddress = [[TestClass alloc] init];\nMatrix* matrixAddress = &(testAddress->matrix);\n\nint rawTes... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426224",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50335/"
] |
426,230 | <p>I came across a reference to it recently on <a href="http://www.reddit.com/r/programming/comments/7o8d9/tcmalloca_faster_malloc_than_glibcs_open_sourced/c06wjka" rel="noreferrer">proggit</a> and (as of now) it is not explained.</p>
<p>I suspect <a href="https://stackoverflow.com/questions/335108/hide-symbols-in-shared-object-from-ld#335253">this</a> might be it, but I don't know for sure.</p>
| [
{
"answer_id": 426244,
"author": "Joshua",
"author_id": 14768,
"author_profile": "https://Stackoverflow.com/users/14768",
"pm_score": 6,
"selected": false,
"text": "LD_PRELOAD LD_LIBRARY_PATH"
},
{
"answer_id": 426252,
"author": "Ronny Brendel",
"author_id": 14114,
"a... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426230",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4203/"
] |
426,239 | <p>This is a good <a href="https://stackoverflow.com/questions/41785/learning-resources-on-parsers-interpreters-and-compilers">listing</a>, but what is the best one for a complete newb in this area. One for someone coming from a higher level background (VB6,C#,Java,Python) - not to familiar with C or C++. I'm much more interested in hand-written parsing versus Lex/Yacc at this stage.</p>
<p>If I had just majored in Computer Science instead of Psychology I might have taken a class on this in college. Oh well.</p>
| [
{
"answer_id": 426308,
"author": "Toon Krijthe",
"author_id": 18061,
"author_profile": "https://Stackoverflow.com/users/18061",
"pm_score": 5,
"selected": true,
"text": "addOp = '+' | '-';\nmulOp = '*' | '/';\nparLeft = '(';\nparRight = ')';\nnumber = digit, {digit};\ndigit = '0'..'9';\n... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426239",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36590/"
] |
426,245 | <p>How can I share/link App.config or Web.config between multiple projects in a visual studio solution ?</p>
| [
{
"answer_id": 10932954,
"author": "nawfal",
"author_id": 661933,
"author_profile": "https://Stackoverflow.com/users/661933",
"pm_score": 4,
"selected": false,
"text": "<appSettings> <appSettings> <appSettings> <configuration> <appSettings> <appSettings> <add> <appSettings> <configuratio... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426245",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50974/"
] |
426,247 | <p>I'm putting together a bookmarklet that inserts jquery into pages it is invoked on. On many pages it works just fine, but on pages like <a href="http://www.cnn.com" rel="nofollow noreferrer">http://www.cnn.com</a> (which includes both prototype and scriptaculous) it behaves a bit strangely.</p>
<p><code>$(blah..).appendTo("body")</code> does not work whereas <code>$(blah..).appendTo(document.getElementsByTagName("body")[0])</code> works</p>
<p><code>$("#id").hide()</code> , <code>.show()</code> and <code>.css()</code> don't work.</p>
<p>I've tried changing the variable from <code>$</code> to <code>jQuery</code> to <code>$k = jQuery.noConflict()</code> but the results are the same. </p>
<p>Note: On many web pages it works fine, only on cnn.com and a few others it does not.</p>
<p>Has anyone come across this, do you have any pointers?? </p>
| [
{
"answer_id": 10932954,
"author": "nawfal",
"author_id": 661933,
"author_profile": "https://Stackoverflow.com/users/661933",
"pm_score": 4,
"selected": false,
"text": "<appSettings> <appSettings> <appSettings> <configuration> <appSettings> <appSettings> <add> <appSettings> <configuratio... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426247",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
426,253 | <p>Looking at the source code for Stack Overflow, I noticed they have used tables and inline CSS quite a bit, also something I found odd was use of inline table attribute formatting. </p>
<p><code><table width="100%"></code></p>
<p>I'm just curious if there was any specific reason(s) to why they used tables to structure their template instead of the popular (or used to be popular) DIVs.</p>
<p>As well...the purpose of using CSS includes and using inline CSS on the same page (I know there is probably a great answer/solution(s) for this...I'm just curious to what they are) </p>
<p>I understand there is nothing wrong with using tables for tabular data...but in this case Stack Overflows tables are used for structure.</p>
| [
{
"answer_id": 426264,
"author": "Michael Haren",
"author_id": 29,
"author_profile": "https://Stackoverflow.com/users/29",
"pm_score": 5,
"selected": false,
"text": "tables CSS CSS"
},
{
"answer_id": 426282,
"author": "hasen",
"author_id": 35364,
"author_profile": "ht... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426253",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12564/"
] |
426,258 | <p>I'd like to do something like this to tick a <code>checkbox</code> using <strong>jQuery</strong>:</p>
<pre><code>$(".myCheckBox").checked(true);
</code></pre>
<p>or</p>
<pre><code>$(".myCheckBox").selected(true);
</code></pre>
<p>Does such a thing exist?</p>
| [
{
"answer_id": 426273,
"author": "Micah",
"author_id": 17744,
"author_profile": "https://Stackoverflow.com/users/17744",
"pm_score": 7,
"selected": false,
"text": "$('.myCheckbox').attr('checked',true) //Standards compliant\n $(\"form #mycheckbox\").attr('checked', true)\n $(\"#mycheckbo... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18107/"
] |
426,298 | <p>I need to write some python ftp code that uses a ftp proxy. The proxy doesn't require authentication but the ftp server I am connecting to does. I have the following code but I am getting a "I/O error(ftp error): 501 USER format: proxy-user:auth-method@destination. Closing connection." error. My code is:</p>
<pre><code>import urllib2
proxies = {'ftp':'ftp://proxy_server:21'}
ftp_server = ' ftp.somecompany.com '
ftp_port='21'
username = 'aaaa'
password = 'secretPW'
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm( )
top_level_url = ftp_server
password_mgr.add_password(None , top_level_url, username, password)
proxy_support = urllib2.ProxyHandler(proxies )
handler = urllib2.HTTPBasicAuthHandler(password_mgr )
opener = urllib2.build_opener(proxy_support )
opener = urllib2.build_opener(handler )
a_url = 'ftp://' + ftp_server + ':' + ftp_port + '/'
print a_url
try:
data = opener.open(a_url )
print data
except IOError, (errno, strerror):
print "I/O error(%s): %s" % (errno, strerror)
</code></pre>
<p>I would be grateful for any assistance I can get. </p>
| [
{
"answer_id": 426331,
"author": "Jehiah",
"author_id": 51022,
"author_profile": "https://Stackoverflow.com/users/51022",
"pm_score": 2,
"selected": false,
"text": "top_level_url install_opener build_opener urllib2.urlopen auth_handler = urllib2.HTTPBasicAuthHandler()\nauth_handler.add_p... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426298",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
426,310 | <p>I have a database which holds the residents of each house in a certain street. I have a 'house view' php web page which can display an individual house and residents when given the house number using 'post'. I also have a 'street view' web page which gives a list of houses. What I want to know is if you can have links on the street view which will link to the house view and post the house number at the same time without setting up a form for each?</p>
<p>Regards</p>
| [
{
"answer_id": 426328,
"author": "Ali",
"author_id": 49153,
"author_profile": "https://Stackoverflow.com/users/49153",
"pm_score": 5,
"selected": true,
"text": "<a href=\"house.php?id=<?php echo $house_id;?>\">\n <?php echo $house_name;?>\n</a>\n $_GET['id'] is_numeric()"
},
{
"... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426310",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23435/"
] |
426,346 | <p>I am currently doing a code review and the following code made me jump. I see multiple issues with this code. Do you agree with me? If so, how do I explain to my colleague that this is wrong (stubborn type...)?</p>
<ul>
<li>Catch a generic exception (Exception ex)</li>
<li>The use of "if (ex is something)" instead of having another catch block</li>
<li>We eat SoapException, HttpException and WebException. But if the Web Service failed, there not much to do.</li>
</ul>
<p>Code:</p>
<pre><code>try
{
// Call to a WebService
}
catch (Exception ex)
{
if (ex is SoapException || ex is HttpException || ex is WebException)
{
// Log Error and eat it.
}
else
{
throw;
}
}
</code></pre>
| [
{
"answer_id": 426356,
"author": "Michael Haren",
"author_id": 29,
"author_profile": "https://Stackoverflow.com/users/29",
"pm_score": 5,
"selected": true,
"text": "throw throw throw ex try\n{\n // Call to a WebService\n}\ncatch (SoapException ex)\n{\n // Log Error and eat it\n}\nc... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42024/"
] |
426,353 | <p>If I use /clr:oldSyntax the following should work:</p>
<pre><code>public __value enum IceCreamFlavors
{
Vanilla,
Chocolate,
Sardine,
};
</code></pre>
<p>what is the equivalent in non-oldSyntax? How do I declare a "managed" enum in Managed C++ for .NET 2.0?</p>
<p><strong>Edit:</strong>
when I follow JaredPar's <a href="https://stackoverflow.com/questions/426353/proper-way-to-declare-an-enum-in-managed-c-2005#426362">advice</a>, then if I try to pass an IceCreamFlavor to a function with the signature: </p>
<pre><code>OrderFlavor(IceCreamFlavors flav)
</code></pre>
<p>by running </p>
<pre><code>OrderFlavor(IceCreamFlavors::Sardine)
</code></pre>
<p>I get the error: </p>
<pre><code>'IceCreamFlavors Sardine' : member function redeclaration not allowed
</code></pre>
| [
{
"answer_id": 426362,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 3,
"selected": true,
"text": "enum class IceCreamFlavors {\n Vanilla,\n Chocolate,\n Sardine,\n};\n"
},
{
"answer_id": 4318139,
"author":... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426353",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2831/"
] |
426,378 | <p>I quite like Rails' database migration management system. It is not 100% perfect, but it does the trick. Django does not ship with such a database migration system (yet?) but there are a number of open source projects to do just that, such as django-evolution and south for example.</p>
<p>So I am wondering, what database migration management solution for django do you prefer? (one option per answer please)</p>
| [
{
"answer_id": 431901,
"author": "Brian Clapper",
"author_id": 53495,
"author_profile": "https://Stackoverflow.com/users/53495",
"pm_score": 2,
"selected": false,
"text": "manage.py"
}
] | 2009/01/08 | [
"https://Stackoverflow.com/questions/426378",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38626/"
] |
426,384 | <p>I have a script that forces a download and I make a call to this via Javascript. However, the dialog box doesn't pop up, here is the download.php script:</p>
<pre><code>header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
// change, added quotes to allow spaces in filenames, by Rajkumar Singh
header("Content-Disposition: attachment; filename=\"".basename($properFilename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
</code></pre>
<p>Here is the Javascript (using JQuery):</p>
<pre><code>///force download
$.ajax({
type: "GET",
url: "download.php",
data: 'file=' + msg + '&properFilename=' + properFileName,
success: function(msg){
window.location.href = msg;
});//ajax
</code></pre>
<p>This redirects my browser to another page rather than showing the down dialog box.</p>
<p>I know the JS variable msg contains the file with the right headers but I don't know what to do with it to get it to display the download dialog box.</p>
<p>Thanks all</p>
<p>p.s. Didn't know where to put this thread JS or PHP.</p>
<h2>EDIT:</h2>
<p>I have the right approach I am sure of that :) - A user comes to my site, they fill in a form and they press submit. After a few seconds their fle should show up in a dialog box that they can download. To do this:</p>
<p>I make an AJAX call to get the file and download it. I use the PHP script to send the headers. Now all I need is a way to get the dowload dialog box to show up!!</p>
| [
{
"answer_id": 426392,
"author": "Luca Matteis",
"author_id": 50394,
"author_profile": "https://Stackoverflow.com/users/50394",
"pm_score": 3,
"selected": true,
"text": "window.location.href = msg;\n <script>\nfunction showDialogBox(form) {\n form.submit();\n window.location.href =... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426384",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51649/"
] |
426,393 | <p>I'm using the table class that auto-generates a table for me from an array of data pulled from my database.</p>
<p><strong>Model</strong>:</p>
<pre><code>function get_reports_by_user_id($userid)
{
return $this->db->get_where('ss2_report',array('userid' => $userid))->result_array();
}
</code></pre>
<p><strong>Controller</strong>:</p>
<pre><code>function index()
{
echo $this->table->generate($this->mymodel->get_reports_by_user_id('1234'));
}
</code></pre>
<p>The controller will eventually be moved to a view when I have it working. This generates the table just fine, but I'd like to add a link to a field. For example, the <code>id</code> column that would allow me to link to a page of data for just that report's id. I know I can just output the table the old fashioned way by hand. I can then add whatever links I want, but I'd love to be able to use the auto-generation as much as possible. There's got to be a way to do something as common as linking a table cell. Does anyone have any ideas?</p>
<p><strong>EDIT</strong>:</p>
<p>User <strong>Java PHP</strong> has it mostly right below. Here's the code that makes it work:</p>
<pre><code>function get_reports_by_user_id($userid)
{
$rows = $this->db->get_where('ss2_report',array('userid' => $userid))->result_array();
foreach ($rows as $count => $row)
{
$rows[$count]['id'] = anchor('report/'.$row['id'],$row['id']);
}
return $rows;
}
</code></pre>
<p>I just needed to replace the value in the original array with the anchor text version.</p>
| [
{
"answer_id": 426408,
"author": "FryGuy",
"author_id": 28776,
"author_profile": "https://Stackoverflow.com/users/28776",
"pm_score": 1,
"selected": false,
"text": "foreach ($row in $this->mymodel->get_reports_by_user_id('1234'))\n{\n $row->id = anchor(site_url(array('report', 'user',... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39539/"
] |
426,396 | <p>I'm developing an application which currently have hundreds of objects created. </p>
<p>Is it possible to determine (or approximate) the memory allocated by an object (class instance)? </p>
| [
{
"answer_id": 426757,
"author": "Sean",
"author_id": 25640,
"author_profile": "https://Stackoverflow.com/users/25640",
"pm_score": 3,
"selected": false,
"text": "!dumpheap -stat\n"
},
{
"answer_id": 789065,
"author": "varun",
"author_id": 95967,
"author_profile": "ht... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426396",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40441/"
] |
426,397 | <p>I am trying to parse the Linux <code>/etc/passwd</code> file in Java. I'm currently reading each line through the <a href="https://docs.oracle.com/javase/9/docs/api/java/util/Scanner.html" rel="noreferrer"><code>java.util.Scanner</code></a> class and then using <a href="https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#split-java.lang.String-" rel="noreferrer"><code>java.lang.String.split(String)</code></a> to delimit each line.</p>
<p>The problem is that the line:</p>
<pre><code>list:x:38:38:Mailing List Manager:/var/list:/bin/sh"
</code></pre>
<p>is treated by the scanner as 3 different lines:</p>
<ol>
<li><code>list:x:38:38:Mailing</code></li>
<li><code>List</code></li>
<li><code>Manager...</code></li>
</ol>
<p>When I type this out into a new file that I didn't get from Linux, <code>Scanner</code> parses it properly.</p>
<p>Is there something I'm not understanding about new lines in Linux?</p>
<p>Obviously a work around is to parse it without using scanner, but it wouldn't be elegant. Does anyone know of an elegant way to do it?</p>
<p>Is there a way to convert the file into one that would work with <code>Scanner</code>?</p>
<hr />
<p>Not even two days ago: <a href="https://stackoverflow.com/questions/419291/historical-reason-behind-different-line-ending-at-different-platforms">Historical reason behind different line ending at different platforms</a></p>
<p><strong>EDIT</strong></p>
<p>Note from the original author:</p>
<blockquote>
<p><em>"I figured out I have a different error that is causing the problem. Disregard question"</em></p>
</blockquote>
| [
{
"answer_id": 426404,
"author": "Michael Haren",
"author_id": 29,
"author_profile": "https://Stackoverflow.com/users/29",
"pm_score": 6,
"selected": false,
"text": "'\\r\\n' '\\r' '\\n' '\\n'"
},
{
"answer_id": 426416,
"author": "davetron5000",
"author_id": 3029,
"au... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426397",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38663/"
] |
426,398 | <p>I have an HTML table that looks like this:</p>
<pre><code>-------------------------------------------------
|Column 1 |Column 2 |
-------------------------------------------------
|this is the text in column |this is the column |
|one which wraps |two test |
-------------------------------------------------
</code></pre>
<p>But I want it to hide the overflow. The reason here is that the text contains a link to more details, and having the "wrapping" wastes lots of space in my layout. It should like this (without increasing the widths of the columns or the table, because they'll go off the screen/create a horizontal scrollbar otherwise):</p>
<pre><code>-------------------------------------------------
|Column 1 |Column 2 |
-------------------------------------------------
|this is the text in column |this is the column |
-------------------------------------------------
</code></pre>
<p>I've tried lots of different CSS techniques to try to get this, but I can't get it to turn out right. Mootables is the only thing I've found that does this: <a href="http://joomlicious.com/mootable/" rel="noreferrer">http://joomlicious.com/mootable/</a>, but I can't figure out how they do it. Does anyone know how I can do this with my own table using CSS and/or Javascript, or how Mootables does it?</p>
<p>Sample HTML:</p>
<pre><code><html><body>
<table width="300px">
<tr>
<td>Column 1</td><td>Column 2</td>
</tr>
<tr>
<td>this is the text in column one which wraps</td>
<td>this is the column two test</td>
</tr>
</table></body></html>
</code></pre>
| [
{
"answer_id": 426405,
"author": "DavGarcia",
"author_id": 40161,
"author_profile": "https://Stackoverflow.com/users/40161",
"pm_score": 8,
"selected": true,
"text": "<html>\n<head>\n<style>\n.hideextra { white-space: nowrap; overflow: hidden; text-overflow:ellipsis; }\n</style>\n</head>... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426398",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4965/"
] |
426,420 | <p>I'd like to call a .net webservice from another domain using only jquery.</p>
<p>What is the best way to do this? and are there any configuration changes I need to be aware of on the web site hosting the web page?</p>
<p>The reason I ask this, is that I am only marginally in control of that area.
So I can only make limited changes.</p>
| [
{
"answer_id": 426574,
"author": "Andreas Grech",
"author_id": 44084,
"author_profile": "https://Stackoverflow.com/users/44084",
"pm_score": 0,
"selected": false,
"text": "$.post(\"CodersWS.asmx/DeleteBook\", { id_book: parseInt(currBookID, 10) }, function(res) {\n///do something with re... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13911/"
] |
426,421 | <p>I am trying to create a WPF application that takes command line arguments. If no arguments are given, the main window should pop up. In cases of some specific command line arguments, code should be run with no GUI and exit when finished. Any suggestions on how this should properly be done would be appreciated.</p>
| [
{
"answer_id": 426436,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 8,
"selected": true,
"text": "StartupUri=\"Window1.xaml\"\n protected override void OnStartup(StartupEventArgs e)\n{\n base.OnStartup(e);\n\n if ... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426421",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20489/"
] |
426,463 | <p>I try to encrypt simple text with RSA algorithm. I have a problem with my code.</p>
<pre><code>RSA *_RSA ;
unsigned char text[2560] = "A";
unsigned char sectext[2560];
unsigned char decrypttext[2560];
int i = 0;
_RSA = RSA_generate_key ( 1024, 65537, NULL, NULL );
i = RSA_public_encrypt ( 1, text, sectext, _RSA, RSA_PKCS1_OAEP_PADDING );
i = RSA_private_decrypt( 1, sectext, decrypttext, _RSA, RSA_PKCS1_OAEP_PADDING);
RSA_free ( _RSA );
</code></pre>
<p>The return value of <code>RSA_public_encrypt</code> is 128, which is the size of the ciphertext. <code>RSA_private_decrypt</code> returns -1, which is an error. If I try to display the recovered text then I get nothing.</p>
<p>Why is <code>RSA_private_decrypt</code> returning -1?</p>
| [
{
"answer_id": 426608,
"author": "Andreas Magnusson",
"author_id": 5811,
"author_profile": "https://Stackoverflow.com/users/5811",
"pm_score": 0,
"selected": false,
"text": "ERR_error_string()"
},
{
"answer_id": 428348,
"author": "Tuminoid",
"author_id": 40657,
"autho... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
426,483 | <p>I'm not familiar with ASP, but am helping someone out with their website as a side project. I am trying to call Apache FOP (a java application) from ASP using VB. I have seen simple examples using the GetObject('java:...') constuct, but I don't know how to pass and retrieve binary data from a java object.</p>
<p>Ideally, I would do this all in memory--I would prefer to not have to write my data to disk, call FOP on that file (which will read, and then write a new file), and then re-read the data off of disk. The site isn't <em>that</em> busy so I could do this, but it just doesn't seem efficient.</p>
| [
{
"answer_id": 467082,
"author": "molson",
"author_id": 53130,
"author_profile": "https://Stackoverflow.com/users/53130",
"pm_score": 3,
"selected": true,
"text": "Dim shell, foppath, workpath\nSet shell = Server.CreateObject(\"WScript.Shell\")\n\nfoppath = Server.MapPath(\"/fop/\")\nwor... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426483",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53130/"
] |
426,484 | <p>I'm guessing there's something really basic about C# inheritance that I don't understand. Would someone please enlighten me?</p>
| [
{
"answer_id": 426521,
"author": "toad",
"author_id": 48759,
"author_profile": "https://Stackoverflow.com/users/48759",
"pm_score": 0,
"selected": false,
"text": "class Bar : Foo { }\n class Foo {\n public Foo(int someVar) {}\n}\n\nclass Bar : Foo {\n public Bar() : base(42) {}\n}\... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/781/"
] |
426,495 | <p>How do you rename a table in <a href="http://en.wikipedia.org/wiki/SQLite" rel="noreferrer">SQLite</a> 3.0?</p>
| [
{
"answer_id": 426512,
"author": "John Sheehan",
"author_id": 1786,
"author_profile": "https://Stackoverflow.com/users/1786",
"pm_score": 9,
"selected": true,
"text": "ALTER TABLE `foo` RENAME TO `bar`\n"
},
{
"answer_id": 61398025,
"author": "ftrotter",
"author_id": 1443... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4883/"
] |
426,497 | <p>I get the following compilation error with the following source code:</p>
<p>Compilation Error:</p>
<p>Type of conditional expression cannot be determined because there is no implicit conversion between '' and 'MyEnum'</p>
<p>Source Code</p>
<pre><code>public enum MyEnum
{
Value1, Value2, Value3
}
public class MyClass
{
public MyClass() {}
public MyEnum? MyClassEnum { get; set; }
}
public class Main()
{
object x = new object();
MyClass mc = new MyClass()
{
MyClassEnum = Convert.IsDBNull(x) : null ?
(MyEnum) Enum.Parse(typeof(MyEnum), x.ToString(), true)
};
}
</code></pre>
<p>How can I resolve this error?</p>
| [
{
"answer_id": 426517,
"author": "M4N",
"author_id": 19635,
"author_profile": "https://Stackoverflow.com/users/19635",
"pm_score": 4,
"selected": false,
"text": "MyClassEnum = Convert.IsDBNull(x) ? null : \n (MyEnum) Enum.Parse(typeof(MyEnum), x.ToString(), true)\n public enum... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26327/"
] |
426,500 | <p>I'm trying to unit test some code that looks like this:</p>
<pre><code>def main():
parser = optparse.OptionParser(description='This tool is cool', prog='cool-tool')
parser.add_option('--foo', action='store', help='The foo option is self-explanatory')
options, arguments = parser.parse_args()
if not options.foo:
parser.error('--foo option is required')
print "Your foo is %s." % options.foo
return 0
if __name__ == '__main__':
sys.exit(main())
</code></pre>
<p>With code that looks like this:</p>
<pre><code>@patch('optparse.OptionParser')
def test_main_with_missing_p4clientsdir_option(self, mock_optionparser):
#
# setup
#
optionparser_mock = Mock()
mock_optionparser.return_value = optionparser_mock
options_stub = Mock()
options_stub.foo = None
optionparser_mock.parse_args.return_value = (options_stub, sentinel.arguments)
def parser_error_mock(message):
self.assertEquals(message, '--foo option is required')
sys.exit(2)
optionparser_mock.error = parser_error_mock
#
# exercise & verify
#
self.assertEquals(sut.main(), 2)
</code></pre>
<p>I'm using <a href="http://www.voidspace.org.uk/python/mock.html" rel="nofollow noreferrer">Michael Foord's Mock</a>, and nose to run the tests.</p>
<p>When I run the test, I get:</p>
<pre><code> File "/Users/dspitzer/Programming/Python/test-optparse-error/tests/sut_tests.py", line 27, in parser_error_mock
sys.exit(2)
SystemExit: 2
----------------------------------------------------------------------
Ran 1 test in 0.012s
FAILED (errors=1)
</code></pre>
<p>The problem is that OptionParser.error does a sys.exit(2), and so main() naturally relies on that. But nose or unittest detects the (expected) sys.exit(2) and fails the test.</p>
<p>I can make the test pass by adding "return 2" under the parser.error() call in main() and removing the sys.exit() call from parser_error_mock(), but I find it distasteful to modify the code under test to allow a test to pass. Is there a better solution?</p>
<p><strong>Update</strong>: <a href="https://stackoverflow.com/users/3002/df">df</a>'s answer works, although the correct call is "self.assertRaises(SystemExit, sut.main)".</p>
<p>Which means the test passes whatever the number is in the sys.exit() in parser_error_mock(). Is there any way to test for the exit code?</p>
<p>BTW, the test is more robust if I add:</p>
<pre><code>self.assertEquals(optionparser_mock.method_calls, [('add_option', ('--foo',), {'action': 'store', 'help': 'The foo option is self-explanatory'}), ('parse_args', (), {})])
</code></pre>
<p>at the end.</p>
<p><strong>Update 2</strong>: I can test for the exit code by replacing "self.assertRaises(SystemExit, sut.main)" with:</p>
<pre><code>try:
sut.main()
except SystemExit, e:
self.assertEquals(type(e), type(SystemExit()))
self.assertEquals(e.code, 2)
except Exception, e:
self.fail('unexpected exception: %s' % e)
else:
self.fail('SystemExit exception expected')
</code></pre>
| [
{
"answer_id": 426624,
"author": "dF.",
"author_id": 3002,
"author_profile": "https://Stackoverflow.com/users/3002",
"pm_score": 4,
"selected": false,
"text": "assertEquals self.assertRaises(SystemExit, sut.main, 2)\n SystemExit"
},
{
"answer_id": 455576,
"author": "Daryl Spi... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426500",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4766/"
] |
426,505 | <p>I have been struggling for some time trying to define a generic interface, but I fail to
achieve what I want. The following is a simplified example of the problem.</p>
<p>Let's say I have a generic <em>Message</em> class</p>
<pre><code>public class Message<T> {
private T content;
public void setContent(T content) {
this.content = content;
}
public T getContent() {
return content;
}
}
</code></pre>
<p>and then I want to define an interface for transfering things:</p>
<pre><code>public interface Transfer<Message<T>> {
public void send(Message message);
}
</code></pre>
<p>The problem is that the compiler does not accept this, and always complains about
the second '<' character, no matter what variations I try.
How do I specify this interface so that it is bound to a generic type (based on Message)
and also have access to the parameterized type?</p>
<p>My plan was to use this interface like the following:</p>
<pre><code>public class Carrier<Message<T>> implements Transfer<Message<T>> {
public void send(Message message) {
T content = message.getContent();
print(content);
}
public static void print(String s) {
System.out.println("The string equals '" + s + "'");
}
public static void print(Integer i) {
System.out.println("The integer equals " + i);
}
public static void main(String[] args) {
Carrier<Message<String>> stringCarrier = new Carrier<Message<String>>();
Message<String> stringMessage = new Message<String>("test");
stringCarrier.send(stringMessage);
Carrier<Message<Integer>> integerCarrier = new Carrier<Message<Integer>>();
Message<Integer> integerMessage = new Message<Integer>(123);
integerCarrier.send(integerMessage);
}
}
</code></pre>
<p>I have done some searching and reading (among other things <a href="http://www.angelikalanger.com/GenericsFAQ/" rel="nofollow noreferrer">Angelika's generics faq</a>), but I am not able to tell if this is not possible or if I am doing it wrong.</p>
<p><strong>Update 2009-01-16</strong>: Removed the original usage of "Thing" instead of "Message< T >" (which was used because with that I was able to compile without getting syntax errors on the interface).</p>
| [
{
"answer_id": 426529,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": false,
"text": "public class Carrier<Thing extends Message<Foo>, Foo>\n implements Transfer<Thing>\n thing Message<Foo> Carrier<Messa... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23118/"
] |
426,513 | <p>My problem is that I have a user that is having a problem displaying a portion of website I am creating, but I am unable to reproduce it on any of my browsers, even with the same version of the browser.</p>
<p>What I'm looking for is probably a website that I can send the user to which will tell me what version of the browser they are running along with the plugs installed and any other information that might affect the display of a page.</p>
<p>Any one know of anything like this?</p>
<p><strong>Edit:</strong> The problem is related to CSS. They want some special image around all the text inputs, but on the users computer the text input displays partially outside of the image which is setup as a background.</p>
<p>I need more user specific information than Google Analytics as you can't separate out a specific user. I also suspect that it's more complicated than just the user agent.</p>
<p>I also can put the website out there publicly because they want to keep their idea private until it's released...grr.</p>
| [
{
"answer_id": 426522,
"author": "Andy Webb",
"author_id": 10931,
"author_profile": "https://Stackoverflow.com/users/10931",
"pm_score": 1,
"selected": false,
"text": "function TestAcro()\n{\nvar acrobat=new Object();\nacrobat.installed=false;\nacrobat.version='0.0';\nif (navigator.plugi... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426513",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5441/"
] |
426,540 | <p>This question doesn't relate only to MouseEvent.CLICK event type but to all event types that already exist in AS3. I read a lot about custom events but until now I couldn't figure it out how to do what I want to do. I'm going to try to explain, I hope you understand:</p>
<p>Here is a illustration of my situation:</p>
<pre><code>for(var i:Number; i < 10; i++){
var someVar = i;
myClips[i].addEventListener(MouseEvent.CLICK, doSomething);
}
function doSomething(e:MouseEvent){ /* */ }
</code></pre>
<p>But I want to be able to pass <em>someVar</em> as a parameter to <em>doSomething</em>. So I tried this:</p>
<pre><code>for(var i:Number; i < 10; i++){
var someVar = i;
myClips[i].addEventListener(MouseEvent.CLICK, function(){
doSomething(someVar);
});
}
function doSomething(index){ trace(index); }
</code></pre>
<p>This kind of works but not as I expect. Due to the function closures, when the MouseEvent.CLICK events are actually fired the <em>for</em> loop is already over and <em>someVar</em> is holding the last value, the number <em>9</em> in the example. So every click in each movie clip will call <em>doSomething</em> passing <em>9</em> as the parameter. And it's not what I want.</p>
<p>I thought that creating a custom event should work, but then I couldn't find a way to fire a custom event when the MouseEvent.CLICK event is fired and pass the parameter to it. Now I don't know if it is the right answer.</p>
<p>What should I do and how?</p>
| [
{
"answer_id": 426743,
"author": "fenomas",
"author_id": 10651,
"author_profile": "https://Stackoverflow.com/users/10651",
"pm_score": 2,
"selected": false,
"text": "for (var i=0; i<5; i++) {\n myClips[i].addEventListener( MouseEvent.CLICK, getHandler(i) );\n}\n\nfunction getHandler(i... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426540",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/47883/"
] |
426,544 | <p>I am concentrating this question on 'reporting-type' queries (count, avg etc. i.e. ones that don't return the domain model itself) and I was just wondering if there is any inherent performance benefit in using HQL, as it may be able to leverage the second level cache. Or perhaps even better - cache the entire query.</p>
<p>The obvious implied benefit is that NHibernate knows what the column names are as it already knows about the model mapping.</p>
<p>Any other benefits I should be aware of?</p>
<p><em>[I am using NHibernate but I assume that in this instance what applies to Hibernate will be equally applicable to NHibernate]</em></p>
| [
{
"answer_id": 426763,
"author": "Brian",
"author_id": 700,
"author_profile": "https://Stackoverflow.com/users/700",
"pm_score": 2,
"selected": false,
"text": "Select count(*), dept from employees group by dept\n"
}
] | 2009/01/08 | [
"https://Stackoverflow.com/questions/426544",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4884/"
] |
426,551 | <ol>
<li><p>Header div on top of the 3 columns</p></li>
<li><p>Height of all columns must fill at least the height of viewport. So if a column has a different bgcolor, the color is all the way to bottom of viewport even if column has no content.</p></li>
<li><p>Second and 3rd columns have variable width. If 3rd column width is 0, 3rd column collapses and template turns into a 2 column one. (not that important requirement)</p></li>
<li><p>A sticky footer in 2nd column which always stays at bottom of viewport even if 2nd column has no content however footer should not be below bottom border of 1st and 3rd columns.</p></li>
<li><p>Works in FF & IE 6+</p></li>
</ol>
<p>Example: (the two dashed lines are viewport edges)</p>
<pre><code>-----------------------------------------
HEADER full width of viewport
column 1 column 2 column 3
| |
| |
| |
\ / my footer \ /
-----------------------------------------
</code></pre>
| [
{
"answer_id": 426654,
"author": "hasen",
"author_id": 35364,
"author_profile": "https://Stackoverflow.com/users/35364",
"pm_score": 2,
"selected": true,
"text": "<table id=\"layout\"><tr>\n <td id=\"left-column\"> {{ NAV MENU }} </td>\n <td>\n <table id=\"middle-table\"><tr... | 2009/01/08 | [
"https://Stackoverflow.com/questions/426551",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5232/"
] |
426,561 | <p>I have an ascii file and in there somewhere is the line:
BEGIN
and later on the line:
END</p>
<p>I'd like to be able to remove those two lines and everything in between from a command line call in windows. This needs to be completely automated. </p>
<p>EDIT: See <a href="https://stackoverflow.com/questions/425864/sed-in-vista-how-to-delete-all-symbols-between">sed in Vista - how to delete all symbols between?</a> for details on how to use sed to do this (cygwin has sed).</p>
<p>EDIT: I am finding that SED could be working but when I pipe the output to a file, the carriage returns have been removed. How can I keep these? Using this sed regex:</p>
<p>/^GlobalSection(TeamFoundationVersionControl) = preSolution$/,/^EndGlobalSection$/{
/^GlobalSection(TeamFoundationVersionControl) = preSolution$/!{
/^EndGlobalSection$/!d
}
}</p>
<p>.. where the start section is 'GlobalSection(TeamFoundationVersionControl) = preSolution' and the end section is 'EndGlobalSection'. I'd also like to delete these lines as well. </p>
<p>EDIT: I am now using something simpler for sed:</p>
<p>/^GlobalSection(TeamFoundationVersionControl) = preSolution$/,/^EndGlobalSection$/d</p>
<p>The line feeds are still an issue though</p>
| [
{
"answer_id": 426695,
"author": "danieltalsky",
"author_id": 22452,
"author_profile": "https://Stackoverflow.com/users/22452",
"pm_score": 1,
"selected": false,
"text": "sourcefile = File.open(ARGV[0])\n\n# Get the string and do a multiline replace\nfileString = sourceFile.read()\nslice... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51948/"
] |
426,563 | <p>I created a local subversion directory and I'm having problems. I tried checking in my first file with the following command:</p>
<pre><code>svn ci TestCommenterParseFilter.java
</code></pre>
<p>and I got the following error message</p>
<pre><code>svn: Commit failed (details follow):
svn: Can't create directory '/export/svn/db/transactions/1-1.txn': Permission denied
svn: Your commit message was left in a temporary file:
svn: '/export/speedplane/nutch-0.9/src/plugin/commenter/src/test/org/commenter/nutch/svn-commit.tmp'
</code></pre>
<p>Any suggestions?</p>
| [
{
"answer_id": 426581,
"author": "Jonathan Lonowski",
"author_id": 15031,
"author_profile": "https://Stackoverflow.com/users/15031",
"pm_score": 0,
"selected": false,
"text": "-m -F $ svn ci TestCommenterParseFilter.java -m \"Commit message.\"\n\n$ svn ci TestCommenterParseFilter.java -F... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426563",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51189/"
] |
426,569 | <p>I've been a software developer for over twenty years, programming in C, Perl, SQL, Java, PHP, JavaScript, and recently Python. I've never had a problem I could not debug using some careful thought, and well-placed debugging <code>print</code> statements.</p>
<p>I respect that many people say that my techniques are primitive, and using a real debugger in an IDE is much better. Yet from my observation, IDE users don't appear to debug faster or more successfully than I can, using my stone knives and bear skins. I'm sincerely open to learning the right tools, I've just never been shown a compelling advantage to using visual debuggers.</p>
<p>Moreover, I have never read a tutorial or book that showed how to debug effectively using an IDE, beyond the basics of how to set breakpoints and display the contents of variables.</p>
<p>What am I missing? What makes IDE debugging tools so much more effective than thoughtful use of diagnostic <code>print</code> statements?</p>
<p>Can you suggest resources (tutorials, books, screencasts) that show the finer techniques of IDE debugging?</p>
<hr>
<p>Sweet answers! Thanks much to everyone for taking the time. Very illuminating. I voted up many, and voted none down. </p>
<p>Some notable points:</p>
<ul>
<li>Debuggers can help me do <em>ad hoc</em> inspection or alteration of variables, code, or any other aspect of the runtime environment, whereas manual debugging requires me to stop, edit, and re-execute the application (possibly requiring recompilation).</li>
<li>Debuggers can attach to a running process or use a crash dump, whereas with manual debugging, "steps to reproduce" a defect are necessary.</li>
<li>Debuggers can display complex data structures, multi-threaded environments, or full runtime stacks easily and in a more readable manner.</li>
<li>Debuggers offer many ways to reduce the time and repetitive work to do almost any debugging tasks. </li>
<li>Visual debuggers and console debuggers are both useful, and have many features in common.</li>
<li>A visual debugger integrated into an IDE also gives you convenient access to smart editing and all the other features of the IDE, in a single integrated development environment (hence the name).</li>
</ul>
| [
{
"answer_id": 426680,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 2,
"selected": false,
"text": "printf"
},
{
"answer_id": 2780342,
"author": "newtover",
"author_id": 68998,
"author_profile": "h... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20860/"
] |
426,573 | <p>I work off of a multi-user Windows Server, and the rdpclip bug bites us all daily. We usually just open task manager and kill then restart rdpclip, but that's a pain in the butt. I wrote a powershell script for killing then restarting rdpclip, but no one's using it because it's a script (not to mention the execution policy is restricted for the box). I'm trying to write a quick and dirty windows app where you click a button to kill rdpclip and restart it. But I want to restrict it to the current user, and can't find a method for the Process class that does this. So far, here's what I have:</p>
<pre><code>Process[] processlist = Process.GetProcesses();
foreach(Process theprocess in processlist)
{
if (theprocess.ProcessName == "rdpclip")
{
theprocess.Kill();
Process.Start("rdpclip");
}
}
</code></pre>
<p>I'm not certain, but I think that's going to kill all the rdpclip processes. I'd like to select by user, like my powershell script does:</p>
<pre><code>taskkill /fi "username eq $env:username" /im rdpclip.exe
& rdpclip.ex
</code></pre>
<p>I suppose I could just invoke the powershell script from my executable, but that seems fairly kludgy.</p>
<p>Apologies in advance for any formatting issues, this is my first time here.</p>
<p>UPDATE: I also need to know how to get the current user and select only those processes. The WMI solution proposed below doesn't help me get that. </p>
<p>UPDATE2: Ok, I've figured out how to get the current user, but it doesn't match the process user over Remote Desktop. Anyone know how to get username instead of the SID?</p>
<p>Cheers,
fr0man</p>
| [
{
"answer_id": 429248,
"author": "fr0man",
"author_id": 53159,
"author_profile": "https://Stackoverflow.com/users/53159",
"pm_score": 4,
"selected": true,
"text": " Process[] processlist = Process.GetProcesses();\n bool rdpclipFound = false;\n\n foreach (P... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426573",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53159/"
] |
426,579 | <p>I've become interested in algorithms lately, and the fibonacci sequence grabbed my attention due to its simplicity.</p>
<p>I've managed to put something together in javascript that calculates the nth term in the fibonacci sequence in less than 15 milliseconds after reading lots of information on the web. It goes up to 1476...1477 is infinity and 1478 is NaN (according to javascript!)</p>
<p>I'm quite proud of the code itself, except it's an utter monster. </p>
<p>So here's my question:
A) is there a faster way to calculate the sequence?
B) is there a faster/smaller way to multiply two matrices?</p>
<p>Here's the code:</p>
<pre><code>//Fibonacci sequence generator in JS
//Cobbled together by Salty
m = [[1,0],[0,1]];
odd = [[1,1],[1,0]];
function matrix(a,b) {
/*
Matrix multiplication
Strassen Algorithm
Only works with 2x2 matrices.
*/
c=[[0,0],[0,0]];
c[0][0]=(a[0][0]*b[0][0])+(a[0][1]*b[1][0]);
c[0][1]=(a[0][0]*b[0][1])+(a[0][1]*b[1][1]);
c[1][0]=(a[1][0]*b[0][0])+(a[1][1]*b[1][0]);
c[1][1]=(a[1][0]*b[0][1])+(a[1][1]*b[1][1]);
m1=(a[0][0]+a[1][1])*(b[0][0]+b[1][1]);
m2=(a[1][0]+a[1][1])*b[0][0];
m3=a[0][0]*(b[0][1]-b[1][1]);
m4=a[1][1]*(b[1][0]-b[0][0]);
m5=(a[0][0]+a[0][1])*b[1][1];
m6=(a[1][0]-a[0][0])*(b[0][0]+b[0][1]);
m7=(a[0][1]-a[1][1])*(b[1][0]+b[1][1]);
c[0][0]=m1+m4-m5+m7;
c[0][1]=m3+m5;
c[1][0]=m2+m4;
c[1][1]=m1-m2+m3+m6;
return c;
}
function fib(n) {
mat(n-1);
return m[0][0];
}
function mat(n) {
if(n > 1) {
mat(n/2);
m = matrix(m,m);
}
m = (n%2<1) ? m : matrix(m,odd);
}
alert(fib(1476)); //Alerts 1.3069892237633993e+308
</code></pre>
<p>The matrix function takes two arguments: a and b, and returns a*b where a and b are 2x2 arrays.
Oh, and on a side note, a magical thing happened...I was converting the Strassen algorithm into JS array notation and it worked on my first try! Fantastic, right? :P</p>
<p>Thanks in advance if you manage to find an easier way to do this.</p>
| [
{
"answer_id": 426596,
"author": "Andreas Grech",
"author_id": 44084,
"author_profile": "https://Stackoverflow.com/users/44084",
"pm_score": 1,
"selected": false,
"text": "var IterMemoFib = function() {\n var cache = [1, 1];\n var fib = function(n) {\n if (n >= cache.length)... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426579",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50548/"
] |
426,584 | <p>What is the easiest way to programmatically force capitalization of keywords in Visual Studio 2008?</p>
<p>We work with a proprietary command delimited language (like HTML). We are attempting to migrate from an older editor to Visual Studio 2008. Our coding standards are to capitalize the commands. The old editor is customized to recognize the command begin delimiter and to force capitalization until the end delimiter is typed or the escape key is pressed.</p>
<p>What's the best way to do that in Visual Studio 2008? Can it be done with a macro or an add-in?</p>
<p>(Edited 1-12-2009)</p>
<p>Thank you for the suggestions so far. I don't think they answer my question.</p>
<p>Clarifications: </p>
<ul>
<li>The previous editor was CodeWright so the customizations there are not portable to visual studio.</li>
<li>The source code is not C#. StyleCop seems to be specifically for C#. Our language is similar to markup languages like HTML but with different delimiter characters and commands.</li>
<li>I am trying to actually capitalize as the developer types, not remind them about proper capitalization. Since the commands are all delimited our current editor actually turns the Caps Lock on when the beginning delimiter is typed. When the end delimiter or the escape key is pressed the caps lock is turned back off. This is independent of the state of the Caps Lock on the keyboard.</li>
</ul>
| [
{
"answer_id": 448658,
"author": "BubbleSort",
"author_id": 8366,
"author_profile": "https://Stackoverflow.com/users/8366",
"pm_score": 2,
"selected": true,
"text": "Private My_AutoCaps As Boolean = False\nPrivate Sub TextDocumentKeyPressEvents_BeforeKeyPress(ByVal Keypress _\n As Strin... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426584",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8366/"
] |
426,599 | <p>I am using asp.net and I am trying to save checkbox values into a database. Multiple checkboxes may be entered into the same field in the database. So for instance I have two checkboxes with names "Comma" and "Hyphen" and if the user checks both of these then the database will store the values ',','-'. How do you do this?</p>
<p>thanks</p>
| [
{
"answer_id": 426621,
"author": "DavGarcia",
"author_id": 40161,
"author_profile": "https://Stackoverflow.com/users/40161",
"pm_score": 2,
"selected": true,
"text": "List<string> values = new List<string>();\nif (cbComma.Checked) {\n values.Add(\"','\");\n}\n...\nstring result = value... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426599",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45429/"
] |
426,609 | <p>I don't know what I am missing, but I added Profile properties in the Web.config file but cannot access Profile.<em>Item</em> in the code or create a new profile.</p>
| [
{
"answer_id": 1111714,
"author": "Joel Spolsky",
"author_id": 4,
"author_profile": "https://Stackoverflow.com/users/4",
"pm_score": 8,
"selected": true,
"text": "<profile> Web.config Profile. ProfileBase <profile defaultProvider=\"SqlProvider\" inherits=\"YourNamespace.AccountProfile\">... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426609",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49632/"
] |
426,620 | <p>Ever stumbled on a tutorial that you feel is of great value but not quite explained properly? That's my dilemma. I know <a href="http://www.tonymarston.net/php-mysql/backbuttonblues.html" rel="nofollow noreferrer">THIS TUTORIAL</a> has some value but I just can't get it. </p>
<ol>
<li>Where do you call each function?</li>
<li>Which function should be called
first and which next, and which
third?</li>
<li>Will all functions be called in all files in an application?</li>
<li>Does anyone know of a better way cure the "Back Button Blues"?</li>
</ol>
<p>I'm wondering if this will stir some good conversation that includes the author of the article. The part I'm particularly interested in is controlling the back button in order to prevent form duplicate entries into a database when the back button is pressed. Basically, you want to control the back button by calling the following three functions during the execution of the scripts in your application. In what order exactly to call the functions (see questions above) is not clear from the tutorial.</p>
<blockquote>
<p>All forwards movement is performed by
using my scriptNext function. This is
called within the current script in
order to activate the new script.</p>
<pre><code>function scriptNext($script_id)
// proceed forwards to a new script
{
if (empty($script_id)) {
trigger_error("script id is not defined", E_USER_ERROR);
} // if
// get list of screens used in this session
$page_stack = $_SESSION['page_stack'];
if (in_array($script_id, $page_stack)) {
// remove this item and any following items from the stack array
do {
$last = array_pop($page_stack);
} while ($last != $script_id);
} // if
// add next script to end of array and update session data
$page_stack[] = $script_id;
$_SESSION['page_stack'] = $page_stack;
// now pass control to the designated script
$location = 'http://' .$_SERVER['HTTP_HOST'] .$script_id;
header('Location: ' .$location);
exit;
} // scriptNext
</code></pre>
<p>When any script has finished its
processing it terminates by calling my
scriptPrevious function. This will
drop the current script from the end
of the stack array and reactivate the
previous script in the array.</p>
<pre><code>function scriptPrevious()
// go back to the previous script (as defined in PAGE_STACK)
{
// get id of current script
$script_id = $_SERVER['PHP_SELF'];
// get list of screens used in this session
$page_stack = $_SESSION['page_stack'];
if (in_array($script_id, $page_stack)) {
// remove this item and any following items from the stack array
do {
$last = array_pop($page_stack);
} while ($last != $script_id);
// update session data
$_SESSION['page_stack'] = $page_stack;
} // if
if (count($page_stack) > 0) {
$previous = array_pop($page_stack);
// reactivate previous script
$location = 'http://' .$_SERVER['HTTP_HOST'] .$previous;
} else {
// no previous scripts, so terminate session
session_unset();
session_destroy();
// revert to default start page
$location = 'http://' .$_SERVER['HTTP_HOST'] .'/index.php';
} // if
header('Location: ' .$location);
exit;
} // scriptPrevious
</code></pre>
<p>Whenever a script is activated, which
can be either through the scriptNext
or scriptPrevious functions, or
because of the BACK button in the
browser, it will call the following
function to verify that it is the
current script according to the
contents of the program stack and take
appropriate action if it is not.</p>
<pre><code>function initSession()
// initialise session data
{
// get program stack
if (isset($_SESSION['page_stack'])) {
// use existing stack
$page_stack = $_SESSION['page_stack'];
} else {
// create new stack which starts with current script
$page_stack[] = $_SERVER['PHP_SELF'];
$_SESSION['page_stack'] = $page_stack;
} // if
// check that this script is at the end of the current stack
$actual = $_SERVER['PHP_SELF'];
$expected = $page_stack[count($page_stack)-1];
if ($expected != $actual) {
if (in_array($actual, $page_stack)) {// script is within current stack, so remove anything which follows
while ($page_stack[count($page_stack)-1] != $actual ) {
$null = array_pop($page_stack);
} // while
$_SESSION['page_stack'] = $page_stack;
} // if
// set script id to last entry in program stack
$actual = $page_stack[count($page_stack)-1];
$location = 'http://' .$_SERVER['HTTP_HOST'] .$actual;
header('Location: ' .$location);
exit;
} // if
... // continue processing
} // initSession
</code></pre>
<p>The action taken depends on whether
the current script exists within the
program stack or not. There are three
possibilities:</p>
<ul>
<li>The current script is not in the $page_stack array, in which case it is
not allowed to continue. Instead it is
replaced by the script which is at the
end of the array.</li>
<li>The current script is in the
$page_stack array, but it is not the
last entry. In this case all
following entries in the array are
removed.</li>
<li>The current script is the last entry
in the $page_stack array. This is
the expected situation. Drinks all
round!</li>
</ul>
</blockquote>
| [
{
"answer_id": 430769,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "if ($_POST) {\n process_input($_POST);\n header(\"Location: $_SERVER[HTTP_REFERER]\");\n exit;\n}\n"
}
] | 2009/01/09 | [
"https://Stackoverflow.com/questions/426620",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40376/"
] |
426,622 | <p>After going through the Appendix A, "C# Coding Style Conventions" of the great book "Framework Design Guidelines" (2nd edition from November 2008), I am quite confused as to what coding style is Microsoft using internally / recommending.</p>
<p>The blog entry <a href="http://blogs.msdn.com/sourceanalysis/archive/2008/05/25/a-difference-of-style.aspx" rel="noreferrer">A Brief History Of C# Style</a> claims:</p>
<blockquote>
<p>In fact, the differences between the "StyleCop style" and the "Framework Design Guidelines style" are relatively minor</p>
</blockquote>
<p>As I see it, the differences are quite pronounced. StyleCop says opening brace should be on a separate line, Framework Design Guidelines say it should be after the opening statement. StyleCop says all keywords are to be followed by a space, Framework Design Guidelines say 'get rid of all spaces' (even around binary operators).</p>
<p>I find this rule from the Framework Design Guidelines book especially ironic (page 366, 6th rule from the top):</p>
<blockquote>
<p><b>Do not</b> use spaces before flow control statements</p>
<pre><code>Right: while(x==y)
Wrong: while (x == y)
</code></pre>
</blockquote>
<p>This is explicitely stating that the StyleCop style is <strong>wrong</strong> (space after the while keyword, spaces before and after the equality binary operator).</p>
<p>In the end, code formatted using the StyleCop style has quite a different "feel" from the one formatted using the Framework Design Guidelines style. By following the Framework Design Guidelines style, one would have to disable a bunch of the rules (AND there are no rules that check adherence to the Framework Design Guidelines style...).</p>
<p>Could somebody (MSFT insiders perhaps?) shed some light on this divergence?</p>
<p>How is your team dealing with this? Following StyleCop? Framework Design Guidelines? Ignoring style altogether? Baking your own style?</p>
| [
{
"answer_id": 426686,
"author": "Greg Beech",
"author_id": 13552,
"author_profile": "https://Stackoverflow.com/users/13552",
"pm_score": 2,
"selected": false,
"text": "public int Prop\n{\n get;\n set;\n}\n"
}
] | 2009/01/09 | [
"https://Stackoverflow.com/questions/426622",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23843/"
] |
426,647 | <p>I have a huge tab separated file which I want to sort on its 2nd column. I need to use the tab character as the field delimiter in cygwin sort. So I need something like this:</p>
<pre><code>sort -t \t -k 2,2 in.txt > out.txt
</code></pre>
<p>But the command prompt evaluates '\t' literally and not as the tab character. Note that I need to do this on a Windows machine running Cygwin. Variations such as </p>
<pre><code>sort -t "\t"
sort -t \"\t\"
</code></pre>
<p>don't work, neither does putting this in a cmd file with an actual tab in place of the \t above.</p>
<p>Edit: A solution using either the DOS shell or the Cygwin bash shell is fine.</p>
| [
{
"answer_id": 426699,
"author": "PEZ",
"author_id": 44639,
"author_profile": "https://Stackoverflow.com/users/44639",
"pm_score": 5,
"selected": true,
"text": "sort -t ' ' -k 2,2 in.txt > out.txt\n"
},
{
"answer_id": 1142918,
"author": "Joakim Lundborg",
"author_id": 5... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426647",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5734/"
] |
426,649 | <p>I am constantly forgetting what the special little codes are for formatting .NET strings. Either through ToString() or using String.Format(). Alignment, padding, month vs. minute (month is uppercase M?), abbreviation vs. full word, etc. I can never remember.</p>
<p>I have the same problem with regexes, but luckily there's <a href="http://www.ultrapico.com/Expresso.htm" rel="noreferrer">Expresso</a> to help me out. It's awesome.</p>
<p>Is there a tool like Expresso for experimenting with formatted strings on standard types like DateTime and float and so on?</p>
| [
{
"answer_id": 426681,
"author": "Steven Murawski",
"author_id": 1233,
"author_profile": "https://Stackoverflow.com/users/1233",
"pm_score": 5,
"selected": true,
"text": "$teststring = 'Currency - {0:c}. And a date - {1:ddd d MMM}. And a plain string - {2}'\n[string]::Format($teststrin... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14582/"
] |
426,650 | <p>When I create a constructor with parameters using Resharper's 'Generate code' feature, I get something like this:</p>
<pre><code>public class Example{
private int _x;
private int _y;
public Example(int _x, int _y){
this._x = _x;
this._y = _y;
}
}
</code></pre>
<p>I would like to use this naming convention instead:</p>
<pre><code>public class Example{
private int _x;
private int _y;
public Example(int x, int y){
_x = x;
_y = y;
}
}
</code></pre>
<p>but I don't know if it's possible to edit this constructor template and where.</p>
| [
{
"answer_id": 426756,
"author": "Andre Gallo",
"author_id": 14401,
"author_profile": "https://Stackoverflow.com/users/14401",
"pm_score": 0,
"selected": false,
"text": " public MyClass(string myField)\n {\n this.myField = myField;\n }\n}\n"
}
] | 2009/01/09 | [
"https://Stackoverflow.com/questions/426650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1560/"
] |
426,655 | <p>Or, in other words, what is wrong with something like -</p>
<pre><code>new Method[] {Vector.add(), Vector.remove()}
</code></pre>
<p>Eclipse keeps telling me that I need arguments. But I obviously don't want to call the methods, I just want to use them as objects! What to do?</p>
| [
{
"answer_id": 426660,
"author": "Allain Lalonde",
"author_id": 2443,
"author_profile": "https://Stackoverflow.com/users/2443",
"pm_score": 4,
"selected": true,
"text": "new Method[] { \n Vector.class.getMethod(\"add\", Object.class), \n Vector.class.getMethod(\"remove\", Object.class)... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51792/"
] |
426,668 | <p>I am building a website but I started with a template and gutted it, changed a lot and got rid of the entire center section and now I have to start over with the body but whenever I try to insert the navigation menu, which is a javascript code that is inserted from another program I used to build it. Well, every time I try to insert the menu on the left side of the page, it falls outside the alignment of the header and footer, so instead of it being straight aligned with the header and footer on the left side, it is on the outside of where it should be. I'm absolutely retarded when it comes to this stuff so if someone could tell me the trick here and for building the content of the body. Just simple stuff like what html code and tags to use for making the boxes that you can insert things into, not image placeholders but boxes to input content like navigation menu or anything really? </p>
<p>HELP PLEASE. </p>
<p>here is the site.
Retairacket.thexdt.com</p>
| [
{
"answer_id": 825579,
"author": "Travis",
"author_id": 307338,
"author_profile": "https://Stackoverflow.com/users/307338",
"pm_score": 1,
"selected": false,
"text": "<p> <div>"
}
] | 2009/01/09 | [
"https://Stackoverflow.com/questions/426668",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
426,694 | <p>I am currently putting together a rails-based web application which will only serve and receive data via json and xml. However, some requirements contain the ability to upload binary data (images).</p>
<p>Now to my understanding JSON is not entirely meant for that... but how do you in general tackle the problem of receiving binary files/data over those two entrypoints to your application? </p>
| [
{
"answer_id": 1291187,
"author": "John Franklin",
"author_id": 157986,
"author_profile": "https://Stackoverflow.com/users/157986",
"pm_score": 2,
"selected": false,
"text": ":binary <object type=\"binary\" encoding=\"base64\">...</object> def show\n @myobject = MyObject.find(:id)\n re... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426694",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2591/"
] |
426,717 | <p>Is there an easy way to compile c code in visual studio 2005? Its been a while(2-3 years) since I've done any coding in either c or c++, but I remember that you used to be able ti, in vs 2003, compile c code in visual studio. I thought it was just a matter of using an empty project(rather than, say a c++ project or a C# project) and giving your file s a *.c extension. However, doing that, I can't seem to figure out how to compile. I'm sure I'm just doing something stupid or missing something obvious. </p>
<p>Ah, really makes me appreciate eclipse's auto compile that much more, which is my normal IDE since I use java for work on the day to day basis.</p>
| [
{
"answer_id": 426762,
"author": "ChrisW",
"author_id": 49942,
"author_profile": "https://Stackoverflow.com/users/49942",
"pm_score": 0,
"selected": false,
"text": "main WinMain"
}
] | 2009/01/09 | [
"https://Stackoverflow.com/questions/426717",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/292/"
] |
426,723 | <p>Why would someone use a group by versus distinct when there are no aggregations done in the query?</p>
<p>Also, does someone know the group by versus distinct performance considerations in MySQL and SQL Server. I'm guessing that SQL Server has a better optimizer and they might be close to equivalent there, but in MySQL, I expect a significant performance advantage to distinct.</p>
<p>I'm interested in dba answers.</p>
<p>EDIT:</p>
<p>Bill's post is interesting, but not applicable. Let me be more specific...</p>
<pre><code>select a, b, c
from table x
group by a, b,c
</code></pre>
<p>versus</p>
<pre><code>select distinct a,b,c
from table x
</code></pre>
| [
{
"answer_id": 426899,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 5,
"selected": false,
"text": "GROUP BY SELECT b, c, d FROM table1 GROUP BY a;\n b c d a GROUP BY DISTINCT DISTINCT SELECT DISTINCT(a), b, c FROM tab... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426723",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36902/"
] |
426,731 | <p>Out of the following queries, which method would you consider the better one? What are your reasons (code efficiency, better maintainability, less WTFery)...</p>
<pre><code>SELECT MIN(`field`)
FROM `tbl`;
SELECT `field`
FROM `tbl`
ORDER BY `field`
LIMIT 1;
</code></pre>
| [
{
"answer_id": 426738,
"author": "Otávio Décio",
"author_id": 48684,
"author_profile": "https://Stackoverflow.com/users/48684",
"pm_score": 4,
"selected": false,
"text": "SELECT MIN(`field`)\nFROM `tbl`;\n"
},
{
"answer_id": 426785,
"author": "Sean McSomething",
"author_i... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426731",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9021/"
] |
426,736 | <p>I have the source code of an application written in C++ and I just want to comment something using:</p>
<pre><code>#ifdef 0
...
#endif
</code></pre>
<p>And I get this error</p>
<blockquote>
<p>error: macro names must be identifiers</p>
</blockquote>
<p>Why is this happening?</p>
| [
{
"answer_id": 426754,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 4,
"selected": false,
"text": "#if 0\n ...\n#endif\n"
},
{
"answer_id": 426767,
"author": "paxdiablo",
"author_id": 14860,
"author... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426736",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39160/"
] |
426,737 | <p>In the context of C++ (not that it matters):</p>
<pre><code>class Foo{
private:
int x[100];
public:
Foo();
}
</code></pre>
<p>What I've learnt tells me that if you create an instance of Foo like so:</p>
<pre><code>Foo bar = new Foo();
</code></pre>
<p>Then the array x is allocated on the heap, but if you created an instance of Foo like so:</p>
<pre><code>Foo bar;
</code></pre>
<p>Then it's created on the stack.</p>
<p>I can't find resources online to confirm this.</p>
| [
{
"answer_id": 426750,
"author": "Otávio Décio",
"author_id": 48684,
"author_profile": "https://Stackoverflow.com/users/48684",
"pm_score": 1,
"selected": false,
"text": "Foo* bar = new Foo(); \n"
},
{
"answer_id": 426764,
"author": "wilhelmtell",
"author_id": 456,
"a... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46555/"
] |
426,740 | <p>Is there any way to select a subset from a large set based on a property or predicate in less than <code>O(n)</code> time?</p>
<p>For a simple example, say I have a large set of authors. Each author has a one-to-many relationship with a set of books, and a one-to-one relationship with a city of birth.</p>
<p>Is there a way to efficiently do a query like "get all books by authors who were born in Chicago"? The only way I can think of is to first select all authors from the city (fast with a good index), then iterate through them and accumulate all their books (<code>O(n)</code> where <code>n</code> is the number of authors from Chicago).</p>
<p>I know databases do something like this in certain joins, and Endeca claims to be able to do this "fast" using what they call "Record Relationship Navigation", but I haven't been able to find anything about the actual algorithms used or even their computational complexity.</p>
<p>I'm not particularly concerned with the exact data structure... I'd be jazzed to learn about how to do this in a <a href="https://en.wikipedia.org/wiki/Relational_database_management_system" rel="nofollow noreferrer">RDBMS</a>, or a key/value repository, or just about anything.</p>
<p>Also, what about third or fourth degree requests of this nature? (Get me all the books written by authors living in cities with immigrant populations greater than 10,000...) Is there a generalized n-degree algorithm, and what is its performance characteristics?</p>
<p><strong>Edit:</strong></p>
<p>I am probably just really dense, but I don't see how the inverted index suggestion helps. For example, say I had the following data:</p>
<pre><code>DATA
1. Milton England
2. Shakespeare England
3. Twain USA
4. Milton Paridise Lost
5. Shakespeare Hamlet
6. Shakespeare Othello
7. Twain Tom Sawyer
8. Twain Huck Finn
INDEX
"Milton" (1, 4)
"Shakespeare" (2, 5, 6)
"Twain" (3, 7, 8)
"Paridise Lost" (4)
"Hamlet" (5)
"Othello" (6)
"Tom Sawyer" (7)
"Huck Finn" (8)
"England" (1, 2)
"USA" (3)
</code></pre>
<p>Say I did my query on "books by authors from England". Very quickly, in <code>O(1)</code> time via a hashtable, I could get my list of authors from England: <code>(1, 2)</code>. But then, for the next step, in order retrieve the books, I'd have to, for EACH of the set <code>{1, 2}</code>, do ANOTHER <code>O(1)</code> lookup: <code>1 -> {4}, 2 -> {5, 6}</code> then do a union of the results <code>{4, 5, 6}</code>.</p>
<p>Or am I missing something? Perhaps you meant I should explicitly store an index entry linking Book to Country. That works for very small data sets. But for a large data set, the number of indexes required to match any possible combination of queries would make the index grow exponentially. </p>
| [
{
"answer_id": 426804,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 1,
"selected": false,
"text": "from collections import defaultdict\n\ncountry = [ \"England\", \"USA\" ]\n\nauthor= [ (\"Milton\", \"England\"), (\"Shake... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3044/"
] |
426,758 | <p>I have a thread that needs to be executed every 10 seconds. This thread contains several calls (12 - 15) to a database on another server. Additionally, it also accesses around 3 files. Consequently, there will be quite a lot of IO and network overhead. </p>
<p>What is the best strategy to perform the above? </p>
<p>One way would be to use the sleep method along with a while loop, but that would be a bad design. </p>
<p>Will a class similar to Timer be helpful in this case? Also, would it be better to create a couple of more threads (one for IO and one for JDBC), instead of having them run in one thread?</p>
| [
{
"answer_id": 426766,
"author": "jjnguy",
"author_id": 2598,
"author_profile": "https://Stackoverflow.com/users/2598",
"pm_score": 2,
"selected": false,
"text": "// Perhaps something like this\nTimer t = new Timer();\nt.scheduleAtFixedRate(yourTimerTask, 0, 10 * 1000);\n// Hopefully you... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426758",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48725/"
] |
426,765 | <p>I have an erlang server that will be communicating via tcp sockets with a client written in C. Are there any C libraries for parsing erlang binary terms to C structs?</p>
<p>I realize this is not absolutely necessary, but it would be very convenient.</p>
| [
{
"answer_id": 1452494,
"author": "jldupont",
"author_id": 171461,
"author_profile": "https://Stackoverflow.com/users/171461",
"pm_score": 3,
"selected": true,
"text": " PktHandler *ph = new PktHandler();\n MsgHandler *mh = new MsgHandler(ph);\n\n //Register a message type\n // {echo, {C... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426765",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49695/"
] |
426,779 | <p>I'm building a app that need manage money datatype.</p>
<p>I'm new on Obj-c, so I can't see the ligth in the use of NSDecimalNumber.</p>
<p>For example, in my unit test I do this:</p>
<pre><code>@interface SamplePerson : NSObject {
NSString *name;
NSDate *birthDate;
NSInteger size;
NSNumber *phone;
NSDecimal balance;
BOOL *isOk;
}
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSDate *birthDate;
@property (nonatomic) NSInteger size;
@property (nonatomic, retain) NSNumber *phone;
@property (nonatomic) NSDecimal balance;
@property (nonatomic) BOOL *isOk;
--
o.balance = [NSDecimalNumber decimalNumberWithDecimal: [[NSNumber numberWithLong: 12.5] decimalValue]];
</code></pre>
<p>But get a warning:</p>
<blockquote>
<p>warning: passing argument 1 of 'save:' from distinct Objective-C type</p>
</blockquote>
<p>Overally, I dound this issue more complex than expected. I could hack using integers but I never do that in my 10+ years coding in Foxpro, Delphi, .NET, Python... never have issue for doing this kind of work.</p>
<p>Anyway, I wanna know how do this. I read the web but only found the same code as above and info like "Use NSDecimalNumber or get killed!".</p>
<p>I wanna know how:</p>
<ul>
<li>Assing simple values, like 12.5</li>
<li>Simple math</li>
<li>How store & load from sqlite.</li>
</ul>
<p>Thank you.</p>
<p>(btw: exist a library or utility that solve this? this sound like a common headache, rigth?)</p>
| [
{
"answer_id": 427144,
"author": "rustyshelf",
"author_id": 6044,
"author_profile": "https://Stackoverflow.com/users/6044",
"pm_score": 1,
"selected": false,
"text": "[NSNumber numberWithLong: 12.5]\n"
}
] | 2009/01/09 | [
"https://Stackoverflow.com/questions/426779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53185/"
] |
426,781 | <p>I am just a beginner in Perl and need some help in filtering columns using a Perl script.
I have about 10 columns separated by comma in a file and I need to keep 5 columns in that file and get rid of every other columns from that file. How do we achieve this? </p>
<p>Thanks a lot for anybody's assistance. </p>
<p>cheers,
Neel</p>
| [
{
"answer_id": 426792,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 3,
"selected": false,
"text": "while(<STDIN>) {\n chomp;\n @fields = split (\",\",$_);\n print \"$fields[1],$fields[3],$fields[5],$fields[7],$... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426781",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53121/"
] |
426,805 | <p>I'm calling a javascript function that sets the opacity of an iframe an unknown amount of times in rapid succession. Basically this tweens the alpha from 0 to 100.
here is the code</p>
<pre><code>
function setAlpha(value)
{
iframe.style.opacity = value * .01;
iframe.style.filter = 'alpha(opacity =' + val + ')';
}
</code></pre>
<p>My problem is that for the first time it is working in ie (7) and not in firefox (3.02). in Firefox I get a delay and then the contentdocument appears with an opacity of 100. If I stick an alert in it works, so I'm guessing it is a race condition (although I thought javascript was single threaded) and that the setAlpha function is being called before the last function has finished executing.
Any help would be greatly appreciated. I've read the 'avoiding a javascript race condition post' but I think this qualifies as something different (plus I can't figure out how to apply that example to this one).</p>
| [
{
"answer_id": 426842,
"author": "olliej",
"author_id": 784,
"author_profile": "https://Stackoverflow.com/users/784",
"pm_score": 1,
"selected": false,
"text": "while(...) setAlpha(...)\n"
},
{
"answer_id": 426855,
"author": "Kenan Banks",
"author_id": 43089,
"author_... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426805",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
426,809 | <p>Is there a way to tell when a file was moved to a certain directory?</p>
<p>I'm being asked why a script of mine did not find a file in a certain directory. The file was created last January but I suspect it was placed in the directory after the script was run. Is there a way for me to confirm my suspicion?</p>
<p>Viewing the file properties gives me the created, modified, and accessed times, and the first two do not change when moving files from one directory to another.</p>
<hr>
<p>EDIT: I have cygwin installed, if that helps at all. Is there a unix way of determining when a directory entry was created?</p>
| [
{
"answer_id": 20881885,
"author": "jonretting",
"author_id": 2083509,
"author_profile": "https://Stackoverflow.com/users/2083509",
"pm_score": 0,
"selected": false,
"text": "finfo() { [[ -f \"$(cygpath \"$@\")\" ]] || { echo \"bad-file\";return 1;}; echo \"$(wmic datafile where name=\\\... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426809",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1094969/"
] |
426,820 | <p>I'm especially interested in solutions with source code available (Django independency is a plus, but I'm willing to hack my way through)</p>
| [
{
"answer_id": 435901,
"author": "sastanin",
"author_id": 25450,
"author_profile": "https://Stackoverflow.com/users/25450",
"pm_score": 2,
"selected": false,
"text": "upload_data download_data appcfg.py class XmlExport(webapp.RequestHandler):\n def get(self):\n objects=MyModel.... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426820",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9440/"
] |
426,825 | <p>Is it possible to check who is entering your website in PHP. I have a web application ( written in PHP) that should only allow users entering from some particular websites. Is it possible to get the referral websites by examining the <code>_Request</code> object? If yes, how?</p>
| [
{
"answer_id": 426841,
"author": "alex",
"author_id": 31671,
"author_profile": "https://Stackoverflow.com/users/31671",
"pm_score": 6,
"selected": true,
"text": "$referringSite = $_SERVER['HTTP_REFERER']; // is that spelt wrong in PHP ?\n"
},
{
"answer_id": 427132,
"author": ... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426825",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3834/"
] |
426,860 | <p>Does anyone know of a tool that will analyse a C++ codebase and display a graphical representation of which files include which header files and highlight redundant includes? I've used Understand C++ but it's expensive and became very unwieldy very quickly on a large (and poorly encapsulated) codebase.</p>
| [
{
"answer_id": 428855,
"author": "Mr.Ree",
"author_id": 37946,
"author_profile": "https://Stackoverflow.com/users/37946",
"pm_score": 2,
"selected": false,
"text": "'-H'\n Print the name of each header file used, in addition to other\n normal activities. Each name is indented to... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426860",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/52719/"
] |
426,878 | <p>In other words, can I do something like</p>
<pre><code>for() {
for {
for {
}
}
}
</code></pre>
<p>Except N times? In other words, when the method creating the loops is called, it is given some parameter N, and the method would then create N of these loops nested one in another?</p>
<p>Of course, the idea is that there should be an "easy" or "the usual" way of doing it. I already have an idea for a very complicated one.</p>
| [
{
"answer_id": 426903,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 3,
"selected": false,
"text": "for for for for (x = 0; x < 10; ++x) {\n for (y = 0; y < 5; ++y) {\n for (z = 0; z < 20; ++z) {\n DoSomethin... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426878",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51792/"
] |
426,888 | <p>Is it possible to control the format of the password that is automatically generated by a call to MembershipUser.ResetPassword()?</p>
<p>I want to be able to allow or not allow certain special characters in the generated password.</p>
<p>I am using the SqlMembershipProvider with a password format of Hashed.</p>
<p>Thanks.</p>
| [
{
"answer_id": 734428,
"author": "Oskar Austegard",
"author_id": 27938,
"author_profile": "https://Stackoverflow.com/users/27938",
"pm_score": 4,
"selected": false,
"text": "user.ChangePassword(user.ResetPassword(), MyMethodToGenerateRandomPassword());\n"
},
{
"answer_id": 109903... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15937/"
] |
426,889 | <p>I recently found LINQ and love it. I find lots of occasions where use of it is so much more expressive than the longhand version but a colleague passed a comment about me abusing this technology which now has me second guessing myself. It is my perspective that if a technology works efficiently and the code is elegant then why not use it? Is that wrong? I could spend extra time writing out processes "longhand" and while the resulting code may be a few ms faster, it's 2-3 times more code and therefore 2-3 times more chance that there may be bugs.</p>
<p>Is my view wrong? <em>Should</em> I be writing my code out longhand rather than using LINQ? Isn't this what LINQ was designed for?</p>
<p>Edit: I was speaking about LINQ to objects, I don't use LINQ to XML so much and I have used LINQ to SQL but I'm not so enamoured with those flavours as LINQ to objects.</p>
| [
{
"answer_id": 426905,
"author": "Steve",
"author_id": 48552,
"author_profile": "https://Stackoverflow.com/users/48552",
"pm_score": 3,
"selected": false,
"text": "var v = List.Where(...);\nfor(int i = 0; i < v.Count(); i++)\n{...}\n List.IndexedForEach( (p,i) => \n {\n if(i != 3)\n ... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426889",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53119/"
] |
426,896 | <p>I am using VIM in Windows. The problem is that I want to use <kbd>Ctrl</kbd><kbd>V</kbd> as a visual mode. However, this key has conflict with Windows paste. How can I reset this key back to VIM visual mode instead of pasting. I prefer to set this in my _vimrc configuration file.</p>
| [
{
"answer_id": 426978,
"author": "Windows programmer",
"author_id": 23705,
"author_profile": "https://Stackoverflow.com/users/23705",
"pm_score": 4,
"selected": false,
"text": "behave mswin\n"
},
{
"answer_id": 7932159,
"author": "dannysauer",
"author_id": 65589,
"aut... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426896",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/62776/"
] |
426,932 | <p>The other day, I tweaked a script for a friend's World of Warcraft addon. He was surprised that you could edit the addons—that they were "open source." (Word of Warcraft addons are written in the Lua scripting language) I found myself wanting to say "Sure you can—all scripts are 'open source'."</p>
<p>Is that true? Sure, some scripts can be compiled to bytecode, but aren't almost all scripts interpreted? That is to say, doesn't the device interpreting the script need the "source," by definition?</p>
| [
{
"answer_id": 427119,
"author": "Norman Ramsey",
"author_id": 41661,
"author_profile": "https://Stackoverflow.com/users/41661",
"pm_score": 1,
"selected": false,
"text": "luac"
}
] | 2009/01/09 | [
"https://Stackoverflow.com/questions/426932",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26237/"
] |
426,941 | <p>I want do this:<br>
<strong>func(conditionA ? pa1 : pa2, conditionB ? pb1 : pb2, conditionC ? pc1 : pc2);</strong></p>
<p>In C style function, there is no problem. But if func() is a template function, compiler will report errors.
Here pa1 and pa2, ... are different class and have a <strong>static</strong> method - "convert()". convert() is also declared as <strong>inline</strong> for performance consideration.</p>
<p>If template cannot solve this problem, there will be a very looooooooooong if-else like below.</p>
<pre>
if (conditionA)
{
typeA1 a;
if (conditionB)
{
typeB1 b;
if (conditonC)
{
C1 c;
Function(a, b, c);
}
else
{
C2 c;
Function(a, b, c);
}
}
else
{
typeB2 b;
if (conditonC)
{
C1 c;
Function(a, b, c);
}
else
{
C2 c;
Function(a, b, c);
}
}
}
else
{
typeA2 a;
if (conditionB)
{
typeB1 b;
if (conditonC)
{
C1 c;
Function(a, b, c);
}
else
{
C2 c;
Function(a, b, c);
}
}
else
{
typeB2 b;
if (conditonC)
{
C1 c;
Function(a, b, c);
}
else
{
C2 c;
Function(a, b, c);
}
}
}
</pre>
| [
{
"answer_id": 426958,
"author": "Frank Krueger",
"author_id": 338,
"author_profile": "https://Stackoverflow.com/users/338",
"pm_score": 2,
"selected": false,
"text": "a b p ? a : b predicate() ? 3.14 : \"sdfsd\"\n pa1 pa2 convert conditionA ? pa1.convert() : pa2.convert()\n"
},
{
... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53200/"
] |
426,953 | <p>I'm just curious about the efficiency of pattern matching in Haskell. What is a simple case of where pattern matching would be better than nested <code>if</code>/<code>case</code> statements and then the converse? </p>
<p>Thanks for your help.</p>
| [
{
"answer_id": 427159,
"author": "Norman Ramsey",
"author_id": 41661,
"author_profile": "https://Stackoverflow.com/users/41661",
"pm_score": 5,
"selected": true,
"text": "case if p then e1 else e2 case p of { True -> e1; False -> e2 } case case if"
}
] | 2009/01/09 | [
"https://Stackoverflow.com/questions/426953",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41718/"
] |
426,963 | <p>I would like to convert tab to spaces in gVim. I added the following line to my <code>_vimrc</code>:</p>
<pre><code>set tabstop=2
</code></pre>
<p>It works to stop at two spaces but it still looks like one tab key is inserted (I tried to use the h key to count spaces afterwards).</p>
<p>I'm not sure what should I do to make gVim convert tabs to spaces?</p>
| [
{
"answer_id": 426966,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 7,
"selected": false,
"text": "set expandtab\n :%s/\\t/ /g\n"
},
{
"answer_id": 426970,
"author": "D.Shawley",
"author_id": 41747,
"a... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426963",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/62776/"
] |
426,965 | <p>I was wondering if it was possible to change the my Shoes app's icon? I imagine its style-oriented, but I haven't been able to find anything on it.</p>
<p>Is this possible?</p>
| [
{
"answer_id": 427275,
"author": "A. Rex",
"author_id": 3508,
"author_profile": "https://Stackoverflow.com/users/3508",
"pm_score": 3,
"selected": true,
"text": "#{DIR}/static/shoes-icon.png libshoes.so"
},
{
"answer_id": 7465920,
"author": "Translunar",
"author_id": 1703... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426965",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45615/"
] |
426,979 | <p>My UI designer gives me great UI mockups created in Photoshop. I want to exactly match the colors in the mockup, but every time I create a color using the <code>-colorWithCalibratedRed:green:blue:alpha:</code> method of NSColor, the colors do not match.</p>
<p>I have tried sampling the colors from the Photoshop mockup using the Pixie app in /Developer/Applications/Graphics Tools/ and it copies an NSColor definition to the clipboard, but these colors are not correct when I build and run the app.</p>
<p>If I use the values that the Photoshop color picker provides, they are not correct either.</p>
<p>I suspect this must be something to do with the fact that I'm sampling a calibrated color from the screen and so the values are incorrect, but I am not sure how to work around this.</p>
<p>If I use <code>-colorWithDeviceRed:green:blue:alpha:</code> and pass through the values it looks correct, but then the color is not consistent on other systems.</p>
<p>Is there a way to do this reliably?</p>
| [
{
"answer_id": 427188,
"author": "Rob Keniger",
"author_id": 50122,
"author_profile": "https://Stackoverflow.com/users/50122",
"pm_score": 0,
"selected": false,
"text": "[NSColor colorWithCalibratedRed:1.0 green:1.0 blue:1.0 alpha:1.0]"
},
{
"answer_id": 427381,
"author": "Ch... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426979",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50122/"
] |
426,991 | <p>Im learning lisp and im pretty new at this so i was wondering...</p>
<p>if i do this:</p>
<pre><code>(defparameter *list-1* (list 1 2))
(defparameter *list-2* (list 2 3))
(defparameter *list-3* (append *list-1* *list-2*))
</code></pre>
<p>And then</p>
<pre><code>(setf (first *list-2*) 1)
*list-3*
</code></pre>
<p>I will get (1 2 1 4)</p>
<p>I know this is because the append is going to "save resources" and create a new list for the first chunk, but will actually just point to the second chunk, coz if i do:</p>
<pre><code>(setf (first *list-1*) 0)
*list-3*
</code></pre>
<p>I will get (1 2 1 4) instade of the more logical (0 2 1 4)</p>
<p>So my question is, what other cases are like this in lisp, how do you black belt lispers know how to deal with this stuff that is not intuitive or consistent?</p>
| [
{
"answer_id": 427002,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "append (1 2 ...)"
},
{
"answer_id": 427008,
"author": "Charlie Martin",
"author_id": 35092,
"author_profil... | 2009/01/09 | [
"https://Stackoverflow.com/questions/426991",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/47846/"
] |
427,009 | <p>I'd prefer my primary key field weren't visible in my edit page. If I make it an AutoField, it isn't rendered in the HTML form. But then the primary key value isn't in my POST data either. Is there a simple way to render the AutoField as a hidden field?</p>
| [
{
"answer_id": 430050,
"author": "Daniel Naab",
"author_id": 32638,
"author_profile": "https://Stackoverflow.com/users/32638",
"pm_score": 3,
"selected": false,
"text": "(r'^edit/?P<my_id>[\\d]+)/$', views.edit),\n from django.shortcuts import render_to_response, get_object_or_404\nfrom ... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10077/"
] |
427,033 | <p>My Client Application Receives data through WebService from a Remote Server. The Application is basically written in 1.1 Framework Windows Form.</p>
<p>All I want to do is to set my Client App TimeZone equal to Server TimeZone so that any Date Time related discrepancies can be avoided.</p>
<p>For this I would like to know How to retrieve Server Time Zone and How to Set Client Time Zone equal to Server.</p>
| [
{
"answer_id": 1840459,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "// Get time in local time zone \nDateTime thisTime = DateTime.Now;\nConsole.WriteLine(\"Time in {0} zone: {1}\", TimeZoneInfo... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427033",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
427,039 | <p>I am currently trying to justify text in a textarea, unfortunately the CSS:</p>
<pre><code>text-align: justify;
</code></pre>
<p>Doesn't work on the text like center, left and right do. I've tried this in both Firefox 3 and IE 7 with no luck.</p>
<p>Is there any way around this?</p>
| [
{
"answer_id": 427056,
"author": "Ken Paul",
"author_id": 26671,
"author_profile": "https://Stackoverflow.com/users/26671",
"pm_score": 2,
"selected": false,
"text": "TEXTAREA FORM TEXTAREA P SPAN TD text-align: justify;"
},
{
"answer_id": 5251532,
"author": "shweta",
"au... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427039",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17020/"
] |
427,040 | <p>I've been mulling over creating a language that would be extremely well suited to creation of DSLs, by allowing definitions of functions that are infix, postfix, prefix, or even consist of multiple words. For example, you could define an infix multiplication operator as follows (where multiply(X,Y) is already defined):</p>
<pre><code>a * b => multiply(a,b)
</code></pre>
<p>Or a postfix "squared" operator:</p>
<pre><code>a squared => a * a
</code></pre>
<p>Or a C or Java-style ternary operator, which involves two keywords interspersed with variables:</p>
<pre><code>a ? b : c => if a==true then b else c
</code></pre>
<p>Clearly there is plenty of scope for ambiguities in such a language, but if it is statically typed (with type inference), then most ambiguities could be eliminated, and those that remain could be considered a syntax error (to be corrected by adding brackets where appropriate).</p>
<p>Is there some reason I'm not seeing that would make this extremely difficult, impossible, or just a plain bad idea?</p>
<p><em>Edit:</em> A number of people have pointed me to languages that may do this or something like this, but I'm actually interested in pointers to how I could implement my own parser for it, or problems I might encounter if doing so. </p>
| [
{
"answer_id": 427073,
"author": "WW.",
"author_id": 14663,
"author_profile": "https://Stackoverflow.com/users/14663",
"pm_score": 2,
"selected": false,
"text": "a * b squared\n"
},
{
"answer_id": 427146,
"author": "Norman Ramsey",
"author_id": 41661,
"author_profile"... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427040",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16050/"
] |
427,051 | <p>I am writing a web app for a client. Users will have a one-time key that they will use to initially identify themselves to the app. Once the app verifies that the key is valid it will take them to a page where they can create a normal account to use for all subsequent logins. The create-account page should only be accessible after entering the key and shouldn't be accessible otherwise. I.e, it shouldn't be accessible to users logged in with a normal account.
This is asp.net 3.0 using a custom membership provider.</p>
<p>My plan is to create a temporary account based on the key and authenticate the user with that account. This allows them access to the create-user page (which is protected with a location tag ) where they can create the formal account. I then authenticate them with their new account and delete the temporary account.
The flow is: the user goes to a page where they enter the key. If the key is valid I create the temporary account, call FormsAuthentication.SetAuthCookie, and redirect to the create-account page. This all works, although it seems a little complicated.</p>
<p>The problem is that the create-user page is available to any authenticated user; I only want it available during the time between entering the key and creating the formal account. So I thought I'd create a special role for the temporary account and make the create-user page accessible only to that role and none other. I created my own Principal object with a special role and tried setting it when I authenticate the temporary account but I can't get that to work.</p>
<p>I'm really hoping I don't have to write a custom role provider just to do this.</p>
<p>How can I make this work? There's gotta be a simpler way!</p>
| [
{
"answer_id": 427073,
"author": "WW.",
"author_id": 14663,
"author_profile": "https://Stackoverflow.com/users/14663",
"pm_score": 2,
"selected": false,
"text": "a * b squared\n"
},
{
"answer_id": 427146,
"author": "Norman Ramsey",
"author_id": 41661,
"author_profile"... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427051",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44394/"
] |
427,070 | <p>I've got unformatted html in a string.</p>
<p>I am trying to format it nicely and output the formatted html back into a string.
I've been trying to use The System.Web.UI.HtmlTextWriter to no avail:</p>
<pre><code>System.IO.StringWriter wString = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter wHtml = new System.Web.UI.HtmlTextWriter(wString);
wHtml.Write(sMyUnformattedHtml);
string sMyFormattedHtml = wString.ToString();
</code></pre>
<p>All I get is the unformatted html, is it possible to achieve what I'm trying to do here?</p>
| [
{
"answer_id": 427638,
"author": "lotsoffreetime",
"author_id": 18248,
"author_profile": "https://Stackoverflow.com/users/18248",
"pm_score": 3,
"selected": true,
"text": " // Attractively format the XML with consistant indentation.\n\n public static String PrettyPrint(String XML)\... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427070",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9266/"
] |
427,075 | <p>I started getting this error when posting the form back with Model Binder. To test the problem I reduced the postback to one string property of the model but i still get the overflow error. Can anyone suggest what would cause this? </p>
<p>UPDATE
The problem appears to be related to the property in the model that is a foreign key. If this key is removed, the binding works. How can I do the binding and include the foreign key relationship?</p>
| [
{
"answer_id": 427197,
"author": "Chad Moran",
"author_id": 25416,
"author_profile": "https://Stackoverflow.com/users/25416",
"pm_score": 2,
"selected": true,
"text": "public ActionResult AddProduct([Bind(Exclude = \"Category\")]Product product) { }\n"
}
] | 2009/01/09 | [
"https://Stackoverflow.com/questions/427075",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49632/"
] |
427,080 | <p>I'm defining a datagrid's RowDetailsTemplate in the following way:</p>
<p>RowDetailsTemplate="{StaticResource defaultTemplate}"</p>
<p>where</p>
<pre><code><UserControl.Resources>
<DataTemplate x:Key="defaultTemplate">
<StackPanel>
<TextBlock Text="default" x:Name="_txt" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="otherTemplate">
<StackPanel>
<TextBlock Text="other" x:Name="_txt" />
</StackPanel>
</DataTemplate>
</UserControl.Resources>
</code></pre>
<p>Is there a way to programatically define which of the two above DataTemplates a given row is to use (perhaps in the LoadingRowDetails() event)?</p>
| [
{
"answer_id": 427197,
"author": "Chad Moran",
"author_id": 25416,
"author_profile": "https://Stackoverflow.com/users/25416",
"pm_score": 2,
"selected": true,
"text": "public ActionResult AddProduct([Bind(Exclude = \"Category\")]Product product) { }\n"
}
] | 2009/01/09 | [
"https://Stackoverflow.com/questions/427080",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51900/"
] |
427,095 | <p>Does anyone know of a Python equivalent for <a href="http://fmpp.sourceforge.net/" rel="noreferrer">FMPP</a> the text file preprocessor?</p>
<p>Follow up: I am reading the docs and looking at the examples for the suggestions given. Just to expand. My usage of FMPP is to read in a data file (csv) and use multiple templates depending on that data to create multi page reports in html all linked to a main index.</p>
| [
{
"answer_id": 427827,
"author": "Mekk",
"author_id": 48167,
"author_profile": "https://Stackoverflow.com/users/48167",
"pm_score": 3,
"selected": true,
"text": "<div py:if=\"variable\"> ... </div>"
},
{
"answer_id": 427870,
"author": "hasen",
"author_id": 35364,
"aut... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427095",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53195/"
] |
427,097 | <p>i am trying to use this code to bind my asp.net menu control to a collection..
but its giving me an error that my collection is now IHierarchyEnumerable.. which I understand why too.. </p>
<pre><code> StringCollection sc = pos.getAllmembers();
Menu1.DataSource = pos.getAllmembers().GetEnumerator();
</code></pre>
<p>is there a way around this..</p>
| [
{
"answer_id": 427154,
"author": "JoshBerke",
"author_id": 26160,
"author_profile": "https://Stackoverflow.com/users/26160",
"pm_score": 0,
"selected": false,
"text": "public class StringHeirarchy : StringCollection,IHierarchyEnumerable\n{\n public IHierarchyData GetHierarchyData(objec... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427097",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43838/"
] |
427,102 | <p>When I read Django code I often see in models what is called a "slug". I am not quite sure what this is, but I do know it has something to do with URLs. How and when is this slug-thing supposed to be used?</p>
<p>(I have read its definition in <a href="http://docs.djangoproject.com/en/dev/glossary/" rel="noreferrer">this glossary</a>.)</p>
<blockquote>
<p><strong>Slug</strong><br />
A short label for something, containing only letters, numbers,
underscores or hyphens. They’re generally used in URLs. For example,
in a typical blog entry URL:</p>
<p><a href="https://www.djangoproject.com/weblog/2008/apr/12/spring/" rel="noreferrer">https://www.djangoproject.com/weblog/2008/apr/12/spring/</a> the last bit
(spring) is the slug.</p>
</blockquote>
| [
{
"answer_id": 427160,
"author": "Josh Smeaton",
"author_id": 10583,
"author_profile": "https://Stackoverflow.com/users/10583",
"pm_score": 11,
"selected": true,
"text": "<title> The 46 Year Old Virgin </title>\n<content> A silly comedy movie </content>\n<slug> the-46-year-old-virgin </s... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427102",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24946/"
] |
427,151 | <p>I've got a game idea that requires some semi-realistic simulation of a fluid flowing around various objects. Think of a pool of mercury on an irregular surface that is being tilted in various directions.</p>
<p>This is for a game, so 100% physical realism is not necessary. What is most important is that the calculations can be done in real time on a device with the horsepower of an iPhone.</p>
<p>I'm thinking that some sort of cellular automaton or particle system is the way to go, but I don't know where to start.</p>
<p>Any suggestions?</p>
| [
{
"answer_id": 37348635,
"author": "OB1",
"author_id": 6341361,
"author_profile": "https://Stackoverflow.com/users/6341361",
"pm_score": 1,
"selected": false,
"text": "1 0"
}
] | 2009/01/09 | [
"https://Stackoverflow.com/questions/427151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1175/"
] |
427,152 | <p>I have a read function in a module.</p>
<p>If I perform that function simultaneously I need to timestamp it.</p>
<p>How do I do this?</p>
| [
{
"answer_id": 427234,
"author": "Swaroop C H",
"author_id": 4869,
"author_profile": "https://Stackoverflow.com/users/4869",
"pm_score": 2,
"selected": false,
"text": "#!/usr/bin/env python\n\nimport datetime\n\ndef timestampit(func):\n def decorate(*args, **kwargs):\n print da... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427152",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46646/"
] |
427,180 | <p>I want to be able to create a GUID/UUID on the iPhone and iPad. </p>
<p>The intention is to be able to create keys for distributed data that are all unique. Is there a way to do this with the iOS SDK?</p>
| [
{
"answer_id": 427521,
"author": "Stephan Burlot",
"author_id": 53071,
"author_profile": "https://Stackoverflow.com/users/53071",
"pm_score": 9,
"selected": true,
"text": "[[UIDevice currentDevice] uniqueIdentifier]\n -[UIDevice uniqueIdentifier] + (NSString *)GetUUID\n{\n CFUUIDRef the... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6044/"
] |
427,192 | <p>I’m quite new to jquery and trying to figure out how to preload images for the jQuery Cycle Plugin.</p>
<p>I have 5+ large size images and I need those to be preloaded before starting the slideshow with Cycle plugin. Also I need to display a loading gif wile it preloads the images.</p>
<p>I have tried to implement the technique here <a href="http://jqueryfordesigners.com/image-loading/" rel="nofollow noreferrer">http://jqueryfordesigners.com/image-loading/</a></p>
<p>but still couldn’t figure out how to make it work with the Cycle plugin.</p>
<p>Can anyone please help me with this?</p>
<p>Thanks</p>
| [
{
"answer_id": 13790297,
"author": "ecume des jours",
"author_id": 1272234,
"author_profile": "https://Stackoverflow.com/users/1272234",
"pm_score": 1,
"selected": false,
"text": "jQuery('.imageslideshow').cycle({\n slideExpr: 'img',\n // other options\n});\n"
}
] | 2009/01/09 | [
"https://Stackoverflow.com/questions/427192",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
427,200 | <p>I've been hacking together some basic Joomla 1.5 components and modules recently and always every time I get into it, I end up tearing my hair out because I simply do not understand how the MVC pattern works. Some examples of the problems I run into:</p>
<ul>
<li>How does the view get access the model?</li>
<li>How do you switch to a different view?</li>
<li>How do you even include the correct file which defines the model?</li>
<li>etc.</li>
</ul>
<p>I'm sure that there are very simple answers to all my questions: my main problem is that overall I don't feel the "documentation" is useful at all and definitely doesn't provide enough information about how to develop components/modules in the new MVC style. The API website is almost worse-than-useless since all it provides are class trees of the functions with virtually no comments at all. The docs website is targetted to administrators and core developers only.</p>
<p><strong>Is there any useful source of information for web developers using Joomla 1.5?</strong></p>
| [
{
"answer_id": 428220,
"author": "jlleblanc",
"author_id": 586,
"author_profile": "https://Stackoverflow.com/users/586",
"pm_score": 2,
"selected": false,
"text": "display() view view display() view parent::display() mylist function display()\n{\n $view = JRequest::getVar('view', '');... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427200",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9021/"
] |
427,203 | <p>I saw someone ask a question about detecting if a URL redirects from groovy and perl but couldn't find anything on PHP.</p>
<p>Anyone know of somewhere I could find that code that does this?</p>
| [
{
"answer_id": 427216,
"author": "Brian Fisher",
"author_id": 43816,
"author_profile": "https://Stackoverflow.com/users/43816",
"pm_score": 4,
"selected": false,
"text": "$ch = curl_init('http://www.yahoo.com/');\ncurl_exec($ch);\n$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);\nif (($cod... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427203",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46782/"
] |
427,207 | <p>We'd like to make a few basic hook scripts that we can all share -- for things like pre-formatting commit messages. Git has hook scripts for that that are normally stored under <code><project>/.git/hooks/</code>. However, those scripts are not propagated when people do a clone and they are not version controlled. </p>
<p>Is there a good way to help everyone get the right hook scripts? Can I just make those hook scripts point to version controlled scripts in my repo?</p>
| [
{
"answer_id": 427269,
"author": "mipadi",
"author_id": 28804,
"author_profile": "https://Stackoverflow.com/users/28804",
"pm_score": 8,
"selected": true,
"text": "hooks .git/hooks root=\"$(pwd)\"\nln -s \"$root/hooks\" \"$root/.git/hooks\"\n ln -sf .git/hooks"
},
{
"answer_id": ... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427207",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/825/"
] |
427,209 | <p>There are certain conditions that can cause stack overflows on an x86 Linux system:</p>
<ul>
<li><code>struct my_big_object[HUGE_NUMBER]</code> on the stack. Walking through it eventually causes <code>SIGSEGV</code>.</li>
<li>The <code>alloca()</code> routine (like <code>malloc()</code>, but uses the stack, automatically frees itself, and also blows up with <code>SIGSEGV</code> if it's too big). <b>Update: alloca() isn't formally deprecated as I originally stated; it is merely discouraged</b>.</li>
</ul>
<p>Is there a way to programmatically detect if the local stack is big enough for a given object? I know the stack size is adjustable via <code>ulimit</code>, so I have hope there is a way (however non-portable it may be). Ideally, I would like to be able to do something like this:</p>
<pre><code>int min_stack_space_available = /* ??? */;
if (object_size < min_stack_space_available)
{
char *foo = alloca(object_size);
do_stuff(foo);
}
else
{
char *foo = malloc(object_size);
do_stuff(foo);
free(foo);
}
</code></pre>
| [
{
"answer_id": 427281,
"author": "Nick",
"author_id": 26240,
"author_profile": "https://Stackoverflow.com/users/26240",
"pm_score": -1,
"selected": false,
"text": "bool CanFitOnStack( size_t num_bytes )\n{\n int stack_offset_for_function = 4; // <- Determine this\n try\n {\n ... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427209",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40620/"
] |
427,210 | <p>I have a CGFloat value which I want to round to 3 digits after the decimal point. How should I do this?</p>
<p>Thanks.</p>
| [
{
"answer_id": 427225,
"author": "Lily Ballard",
"author_id": 582,
"author_profile": "https://Stackoverflow.com/users/582",
"pm_score": 2,
"selected": false,
"text": "myFloat = round(myfloat * 1000) / 1000.0;\n"
},
{
"answer_id": 428288,
"author": "Zach Langley",
"author_... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46297/"
] |
427,217 | <p>I noticed some people declare a private variable and then a public variable with the get and set statements:</p>
<pre><code>private string myvariable = string.Empty;
public string MyVariable
{
get { return myvariable; }
set { myvariable = value ?? string.Empty; }
}
</code></pre>
<p>and then some people just do the following:</p>
<pre><code>public string MyVariable
{
get { return value; }
set { MyVariable = value; }
}
</code></pre>
<p>Being a bear of little intelligence (yes, I have kids... why do you ask?) I can't figure out why you would choose one over the other. Isn't it just as effective in using a public variable that you can set any time using the set method of the variable?</p>
<p>Can anyone shed some light on this for me?</p>
<p>UPDATE: I corrected the second example after several people pointed out it wouldn't compile. Sorry about that, but the question still remains...</p>
| [
{
"answer_id": 427231,
"author": "Jarrod Dixon",
"author_id": 3,
"author_profile": "https://Stackoverflow.com/users/3",
"pm_score": 4,
"selected": false,
"text": "public string MyVariable { get; set; }\n"
}
] | 2009/01/09 | [
"https://Stackoverflow.com/questions/427217",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51949/"
] |
427,219 | <p>Given the existence of other divs on a page, how would one create a div that acts as if it's fixed-width within a certain domain of a web page? Example: the commenting system on Slashdot, which acts like a fixed-width div for purposes of scrolling along a screen but will remain within a certain length? I want a block of text to appear alongside the screen for a certain part of the page, but I want it to <i>stay</i> within that piece of the page, rather than have it move entirely along the page like a fixed block would move.</p>
| [
{
"answer_id": 427445,
"author": "Marcin Gil",
"author_id": 5731,
"author_profile": "https://Stackoverflow.com/users/5731",
"pm_score": 0,
"selected": false,
"text": "<div style=\"width xx; height xx; overflow: scroll;\">?\n"
},
{
"answer_id": 485599,
"author": "Nate Cook",
... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427219",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
427,220 | <p>For instance, is the following possible:</p>
<pre><code>#define definer(x) #define #x?
</code></pre>
| [
{
"answer_id": 427228,
"author": "shoosh",
"author_id": 9611,
"author_profile": "https://Stackoverflow.com/users/9611",
"pm_score": 3,
"selected": false,
"text": "#"
},
{
"answer_id": 427404,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackover... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427220",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/47937/"
] |
427,221 | <p>The last question I asked concerned how to bin data by x co-ordinate. The solution was simple and elegant, and I'm ashamed I didn't see it. This question may be harder (or I may just be blind).</p>
<p>I started out with about 140000 data points and split them into 70 groups equally spaced along the x axis I then took the average position (x_avg, y_avg) of each group and plotted them; a nice curve appeared. Unfortunately there are two problems. First of all, the edges are much less populated than the center of the graph; Second of all, some areas change more than others and thus need a better resolution.</p>
<p>I thus have two specific questions and a general invitation to throw suggestions:</p>
<p>Does matlab have a builtin way of splitting a matrix into either a fixed number of smaller matricies or smaller matricies of a fixed size?</p>
<p>Is there an algorithm (or a matlab function, but I find that unlikely) to determine the boundaries required to bin regions of interest more finely?</p>
<p>More generally, is there a better way of condensing tens of thousands of data points into a neat trend?</p>
| [
{
"answer_id": 427247,
"author": "Kevin Loney",
"author_id": 13834,
"author_profile": "https://Stackoverflow.com/users/13834",
"pm_score": 1,
"selected": false,
"text": "// Some of this shamelessly borrowed from the wikipedia article\nfunction kdtree(points, lower_bound, upper_bound) {\n... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/52310/"
] |
427,226 | <p>This is somewhat asp.net MVC related only for example purposes but I was hoping to achieve something like this:</p>
<pre><code>new SelectList(ViewData.Model.Formats.ToList().ForEach(x => index + " - " + x.Name), "ID", "Name");
</code></pre>
<p>Basically trying to be smart and return "index" as a number 1 - <em>n</em> where <em>n</em> is the number of items in the list <code>ViewData.Model.Formats</code> so my select list has a # prefixed on each entry. Any simple way to do this, or am I looking at making a new list with that append and ditching the lambda trick?</p>
| [
{
"answer_id": 427236,
"author": "Hosam Aly",
"author_id": 41283,
"author_profile": "https://Stackoverflow.com/users/41283",
"pm_score": 1,
"selected": false,
"text": "int index = 0;\nnew SelectList(ViewData.Model.Formats.ForEach(x => ++index + \" - \" + x.Name), \"ID\", \"Name\");\n ind... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41211/"
] |
427,235 | <p>say I have this</p>
<pre><code>$result = mysql_query('SELECT views FROM post ORDER BY views ASC');
</code></pre>
<p>and I want to use the value at index 30 I assumed I would use</p>
<pre><code>mysql_data_seek($result, 30);
$useableResult = mysql_fetch_row($result);
echo $useableResult . '<br/>';
</code></pre>
<p>But that is returning my whole table</p>
<p>What have I got wrong?</p>
<p>Edit: Woops, I actually have</p>
<pre><code>mysql_data_seek($result, 30);
while($row = mysql_fetch_row($result)){
echo $row['views'] . '<br/>';
}
</code></pre>
| [
{
"answer_id": 427245,
"author": "Soviut",
"author_id": 46914,
"author_profile": "https://Stackoverflow.com/users/46914",
"pm_score": 4,
"selected": true,
"text": "$result = mysql_query('SELECT views FROM post WHERE ID=30')\n $result = mysql_query('SELECT views FROM post LIMIT 30, 1')\n"... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427235",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36076/"
] |
427,249 | <p>If I have a fileset like this:</p>
<pre><code><fileset dir=".">
<exclude name="classes/*"/>
<include name="**/zar.class"/>
</fileset>
</code></pre>
<p>The exclude takes precedence over the include and I don't end up with any classes. [since for this hypothetical example, zar.class is in the classes dir] I would like to include the zar file, even though it is in the classes dir.</p>
<p>I banged my head against this one for a while, reading about selectors, patternsets, filesets, trying to combine filesets, etc. but could not get it working.</p>
<p>Anyone know how to do this?</p>
| [
{
"answer_id": 427277,
"author": "Brian Fisher",
"author_id": 43816,
"author_profile": "https://Stackoverflow.com/users/43816",
"pm_score": 2,
"selected": false,
"text": "<patternset id=\"a\">\n <exclude name=\"classes/*\"/>\n</patternset>\n\n<patternset id=\"b\">\n <include name=\"**/... | 2009/01/09 | [
"https://Stackoverflow.com/questions/427249",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41762/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.