question_id
int64
4
6.31M
answer_id
int64
7
6.31M
title
stringlengths
9
150
question_body
stringlengths
0
28.8k
answer_body
stringlengths
60
27.2k
question_text
stringlengths
40
28.9k
combined_text
stringlengths
124
39.6k
tags
listlengths
1
6
question_score
int64
0
26.3k
answer_score
int64
0
28.8k
view_count
int64
15
14M
answer_count
int64
0
182
favorite_count
int64
0
32
question_creation_date
stringdate
2008-07-31 21:42:52
2011-06-10 18:12:18
answer_creation_date
stringdate
2008-07-31 22:17:57
2011-06-10 18:14:17
4
7
How to convert Decimal to Double in C#?
I want to assign the decimal variable "trans" to the double variable "this.Opacity". decimal trans = trackBar1.Value / 5000; this.Opacity = trans; When I build the app it gives the following error: Cannot implicitly convert type decimal to double
An explicit cast to double like this isn't necessary: double trans = (double) trackBar1.Value / 5000.0; Identifying the constant as 5000.0 (or as 5000d ) is sufficient: double trans = trackBar1.Value / 5000.0; double trans = trackBar1.Value / 5000d;
How to convert Decimal to Double in C#? I want to assign the decimal variable "trans" to the double variable "this.Opacity". decimal trans = trackBar1.Value / 5000; this.Opacity = trans; When I build the app it gives the following error: Cannot implicitly convert type decimal to double
TITLE: How to convert Decimal to Double in C#? QUESTION: I want to assign the decimal variable "trans" to the double variable "this.Opacity". decimal trans = trackBar1.Value / 5000; this.Opacity = trans; When I build the app it gives the following error: Cannot implicitly convert type decimal to double ANSWER: An exp...
[ "c#", "floating-point", "type-conversion", "double", "decimal" ]
806
529
76,733
13
0
2008-07-31T21:42:52.667000
2008-07-31T22:17:57.883000
6
31
Why did the width collapse in the percentage width child element in an absolutely positioned parent on Internet Explorer 7?
I have an absolutely positioned div containing several children, one of which is a relatively positioned div. When I use a percentage-based width on the child div, it collapses to 0 width on IE7, but not on Firefox or Safari. If I use pixel width, it works. If the parent is relatively positioned, the percentage width o...
The parent div needs to have a defined width, either in pixels or as a percentage. In Internet Explorer 7, the parent div needs a defined width for child percentage div s to work correctly.
Why did the width collapse in the percentage width child element in an absolutely positioned parent on Internet Explorer 7? I have an absolutely positioned div containing several children, one of which is a relatively positioned div. When I use a percentage-based width on the child div, it collapses to 0 width on IE7, ...
TITLE: Why did the width collapse in the percentage width child element in an absolutely positioned parent on Internet Explorer 7? QUESTION: I have an absolutely positioned div containing several children, one of which is a relatively positioned div. When I use a percentage-based width on the child div, it collapses t...
[ "html", "css", "internet-explorer-7" ]
320
160
24,503
7
0
2008-07-31T22:08:08.620000
2008-08-01T12:22:51.593000
9
1,404
How do I calculate someone's age based on a DateTime type birthday?
Given a DateTime representing a person's birthday, how do I calculate their age in years?
An easy to understand and simple solution. // Save today's date. var today = DateTime.Today; // Calculate the age. var age = today.Year - birthdate.Year; // Go back to the year in which the person was born in case of a leap year if (birthdate.Date > today.AddYears(-age)) age--; However, this assumes you are looking f...
How do I calculate someone's age based on a DateTime type birthday? Given a DateTime representing a person's birthday, how do I calculate their age in years?
TITLE: How do I calculate someone's age based on a DateTime type birthday? QUESTION: Given a DateTime representing a person's birthday, how do I calculate their age in years? ANSWER: An easy to understand and simple solution. // Save today's date. var today = DateTime.Today; // Calculate the age. var age = today.Yea...
[ "c#", ".net", "datetime" ]
2,248
2,417
827,598
75
0
2008-07-31T23:40:59.743000
2008-08-04T16:50:06.170000
11
1,248
Calculate relative time in C#
Given a specific DateTime value, how do I display relative time, like: 2 hours ago 3 days ago a month ago
Jeff, your code is nice but could be clearer with constants (as suggested in Code Complete). const int SECOND = 1; const int MINUTE = 60 * SECOND; const int HOUR = 60 * MINUTE; const int DAY = 24 * HOUR; const int MONTH = 30 * DAY; var ts = new TimeSpan(DateTime.UtcNow.Ticks - yourDate.Ticks); double delta = Math.Abs(...
Calculate relative time in C# Given a specific DateTime value, how do I display relative time, like: 2 hours ago 3 days ago a month ago
TITLE: Calculate relative time in C# QUESTION: Given a specific DateTime value, how do I display relative time, like: 2 hours ago 3 days ago a month ago ANSWER: Jeff, your code is nice but could be clearer with constants (as suggested in Code Complete). const int SECOND = 1; const int MINUTE = 60 * SECOND; const int ...
[ "c#", "datetime", "time", "datediff", "relative-time-span" ]
1,653
1,070
202,800
42
0
2008-07-31T23:55:37.967000
2008-08-04T13:57:26.097000
16
12,446
Filling a DataSet or a DataTable from a LINQ query result set
How do you expose a LINQ query as an ASMX web service? Usually, from the business tier, I can return a typed DataSet or a DataTable which can be serialized for transport over ASMX. How can I do the same for a LINQ query? Is there a way to populate a typed DataSet or a DataTable via a LINQ query? public static MyDataTab...
As mentioned in the question, IEnumerable has a CopyToDataTable method: IEnumerable query = from order in orders.AsEnumerable() where order.Field ("OrderDate") > new DateTime(2001, 8, 1) select order; // Create a table from the query. DataTable boundTable = query.CopyToDataTable (); Why won't that work for you?
Filling a DataSet or a DataTable from a LINQ query result set How do you expose a LINQ query as an ASMX web service? Usually, from the business tier, I can return a typed DataSet or a DataTable which can be serialized for transport over ASMX. How can I do the same for a LINQ query? Is there a way to populate a typed Da...
TITLE: Filling a DataSet or a DataTable from a LINQ query result set QUESTION: How do you expose a LINQ query as an ASMX web service? Usually, from the business tier, I can return a typed DataSet or a DataTable which can be serialized for transport over ASMX. How can I do the same for a LINQ query? Is there a way to p...
[ "c#", "linq", "web-services", ".net-3.5" ]
159
99
88,393
7
0
2008-08-01T04:59:33.643000
2008-08-15T16:27:31.600000
17
26
Binary Data in MySQL
How do I store binary data in MySQL?
The answer by phpguy is correct but I think there is a lot of confusion in the additional details there. The basic answer is in a BLOB data type / attribute domain. BLOB is short for Binary Large Object and that column data type is specific for handling binary data. See the relevant manual page for MySQL.
Binary Data in MySQL How do I store binary data in MySQL?
TITLE: Binary Data in MySQL QUESTION: How do I store binary data in MySQL? ANSWER: The answer by phpguy is correct but I think there is a lot of confusion in the additional details there. The basic answer is in a BLOB data type / attribute domain. BLOB is short for Binary Large Object and that column data type is spe...
[ "mysql", "database", "binary-data", "data-storage" ]
199
143
87,599
9
0
2008-08-01T05:09:55.993000
2008-08-01T12:16:22.167000
19
531
What is the fastest way to get the value of π?
I'm looking for the fastest way to obtain the value of π, as a personal challenge. More specifically, I'm using ways that don't involve using #define constants like M_PI, or hard-coding the number in. The program below tests the various ways I know of. The inline assembly version is, in theory, the fastest option, thou...
The Monte Carlo method, as mentioned, applies some great concepts but it is, clearly, not the fastest, not by a long shot, not by any reasonable measure. Also, it all depends on what kind of accuracy you are looking for. The fastest π I know of is the one with the digits hard coded. Looking at Pi and Pi[PDF], there are...
What is the fastest way to get the value of π? I'm looking for the fastest way to obtain the value of π, as a personal challenge. More specifically, I'm using ways that don't involve using #define constants like M_PI, or hard-coding the number in. The program below tests the various ways I know of. The inline assembly ...
TITLE: What is the fastest way to get the value of π? QUESTION: I'm looking for the fastest way to obtain the value of π, as a personal challenge. More specifically, I'm using ways that don't involve using #define constants like M_PI, or hard-coding the number in. The program below tests the various ways I know of. Th...
[ "performance", "algorithm", "language-agnostic", "unix", "pi" ]
352
223
70,352
23
0
2008-08-01T05:21:22.257000
2008-08-02T18:22:52.690000
24
49
Throw an error preventing a table update in a MySQL trigger
If I have a trigger before the update on a table, how can I throw an error that prevents the update on that table?
Here is one hack that may work. It isn't clean, but it looks like it might work: Essentially, you just try to update a column that doesn't exist.
Throw an error preventing a table update in a MySQL trigger If I have a trigger before the update on a table, how can I throw an error that prevents the update on that table?
TITLE: Throw an error preventing a table update in a MySQL trigger QUESTION: If I have a trigger before the update on a table, how can I throw an error that prevents the update on that table? ANSWER: Here is one hack that may work. It isn't clean, but it looks like it might work: Essentially, you just try to update a...
[ "mysql", "database", "triggers" ]
195
67
105,586
7
0
2008-08-01T12:12:19.350000
2008-08-01T13:02:51.900000
25
1,443,907
How to use the C socket API in C++ on z/OS
I'm having issues getting the C sockets API to work properly in C++ on z/OS. Although I am including sys/socket.h, I still get compile time errors telling me that AF_INET is not defined. Am I missing something obvious, or is this related to the fact that being on z/OS makes my problems much more complicated? I discover...
Keep a copy of the IBM manuals handy: z/OS V1R11.0 XL C/C++ Programming Guide z/OS V1R11.0 XL C/C++ Run-Time Library Reference The IBM publications are generally very good, but you need to get used to their format, as well as knowing where to look for an answer. You'll find quite often that a feature that you want to u...
How to use the C socket API in C++ on z/OS I'm having issues getting the C sockets API to work properly in C++ on z/OS. Although I am including sys/socket.h, I still get compile time errors telling me that AF_INET is not defined. Am I missing something obvious, or is this related to the fact that being on z/OS makes my...
TITLE: How to use the C socket API in C++ on z/OS QUESTION: I'm having issues getting the C sockets API to work properly in C++ on z/OS. Although I am including sys/socket.h, I still get compile time errors telling me that AF_INET is not defined. Am I missing something obvious, or is this related to the fact that bein...
[ "c++", "c", "sockets", "mainframe", "zos" ]
176
97
16,412
9
0
2008-08-01T12:13:50.207000
2009-09-18T11:17:01.933000
36
352
Check for changes to an SQL Server table?
How can I monitor an SQL Server database for changes to a table without using triggers or modifying the structure of the database in any way? My preferred programming environment is.NET and C#. I'd like to be able to support any SQL Server 2000 SP4 or newer. My application is a bolt-on data visualization for another co...
Take a look at the CHECKSUM command: SELECT CHECKSUM_AGG(BINARY_CHECKSUM(*)) FROM sample_table WITH (NOLOCK); That will return the same number each time it's run as long as the table contents haven't changed. See my post on this for more information: CHECKSUM Here's how I used it to rebuild cache dependencies when tabl...
Check for changes to an SQL Server table? How can I monitor an SQL Server database for changes to a table without using triggers or modifying the structure of the database in any way? My preferred programming environment is.NET and C#. I'd like to be able to support any SQL Server 2000 SP4 or newer. My application is a...
TITLE: Check for changes to an SQL Server table? QUESTION: How can I monitor an SQL Server database for changes to a table without using triggers or modifying the structure of the database in any way? My preferred programming environment is.NET and C#. I'd like to be able to support any SQL Server 2000 SP4 or newer. M...
[ "sql", "sql-server", "datatable", "rdbms" ]
153
101
78,517
9
0
2008-08-01T12:35:56.917000
2008-08-02T05:20:22.397000
39
45
Reliable timer in a console application
I am aware that in.NET there are three timer types (see Comparing the Timer Classes in the.NET Framework Class Library ). I have chosen a threaded timer as the other types can drift if the main thread is busy, and I need this to be reliable. The way this timer works in the control of the timer is put on another thread ...
You can use something like Console.ReadLine() to block the main thread, so other background threads (like timer threads) will still work. You may also use an AutoResetEvent to block the execution, then (when you need to) you can call Set() method on that AutoResetEvent object to release the main thread. Also ensure tha...
Reliable timer in a console application I am aware that in.NET there are three timer types (see Comparing the Timer Classes in the.NET Framework Class Library ). I have chosen a threaded timer as the other types can drift if the main thread is busy, and I need this to be reliable. The way this timer works in the contro...
TITLE: Reliable timer in a console application QUESTION: I am aware that in.NET there are three timer types (see Comparing the Timer Classes in the.NET Framework Class Library ). I have chosen a threaded timer as the other types can drift if the main thread is busy, and I need this to be reliable. The way this timer w...
[ "c#", ".net", "vb.net", "timer" ]
114
63
8,237
3
0
2008-08-01T12:43:11.503000
2008-08-01T12:56:37.920000
42
77
Best way to allow plugins for a PHP application
I am starting a new web application in PHP and this time around I want to create something that people can extend by using a plugin interface. How does one go about writing 'hooks' into their code so that plugins can attach to specific events?
You could use an Observer pattern. A simple functional way to accomplish this: Output: This is my CRAZY application 4 + 5 = 9 4 * 5 = 20 Notes: For this example source code, you must declare all your plugins before the actual source code that you want to be extendable. I've included an example of how to handle single o...
Best way to allow plugins for a PHP application I am starting a new web application in PHP and this time around I want to create something that people can extend by using a plugin interface. How does one go about writing 'hooks' into their code so that plugins can attach to specific events?
TITLE: Best way to allow plugins for a PHP application QUESTION: I am starting a new web application in PHP and this time around I want to create something that people can extend by using a plugin interface. How does one go about writing 'hooks' into their code so that plugins can attach to specific events? ANSWER: Y...
[ "php", "plugins", "architecture", "hook" ]
293
168
40,824
8
0
2008-08-01T12:50:18.587000
2008-08-01T13:46:00.097000
48
31,910
Multiple submit buttons in an HTML form
Let's say you create a wizard in an HTML form. One button goes back, and one goes forward. Since the back button appears first in the markup when you press Enter, it will use that button to submit the form. Example: I would like to get to decide which button is used to submit the form when a user presses Enter. That wa...
I'm just doing the trick of float ing the buttons to the right. This way the Prev button is left of the Next button, but the Next comes first in the HTML structure:.f { float: right; }.clr { clear: both; } Benefits over other suggestions: no JavaScript code, accessible, and both buttons remain type="submit".
Multiple submit buttons in an HTML form Let's say you create a wizard in an HTML form. One button goes back, and one goes forward. Since the back button appears first in the markup when you press Enter, it will use that button to submit the form. Example: I would like to get to decide which button is used to submit the...
TITLE: Multiple submit buttons in an HTML form QUESTION: Let's say you create a wizard in an HTML form. One button goes back, and one goes forward. Since the back button appears first in the markup when you press Enter, it will use that button to submit the form. Example: I would like to get to decide which button is ...
[ "html", "forms", "form-submit", "submit-button" ]
291
152
257,419
28
0
2008-08-01T13:01:17.303000
2008-08-28T09:34:40.143000
59
43,110
How do I get a distinct, ordered list of names from a DataTable using LINQ?
I have a DataTable with a Name column. I want to generate a collection of the unique names ordered alphabetically. The following query ignores the order by clause. var names = (from DataRow dr in dataTable.Rows orderby (string)dr["Name"] select (string)dr["Name"]).Distinct(); Why does the orderby not get enforced?
To make it more readable and maintainable, you can also split it up into multiple LINQ statements. First, select your data into a new list, let's call it x1, do a projection if desired Next, create a distinct list, from x1 into x2, using whatever distinction you require Finally, create an ordered list, from x2 into x3,...
How do I get a distinct, ordered list of names from a DataTable using LINQ? I have a DataTable with a Name column. I want to generate a collection of the unique names ordered alphabetically. The following query ignores the order by clause. var names = (from DataRow dr in dataTable.Rows orderby (string)dr["Name"] select...
TITLE: How do I get a distinct, ordered list of names from a DataTable using LINQ? QUESTION: I have a DataTable with a Name column. I want to generate a collection of the unique names ordered alphabetically. The following query ignores the order by clause. var names = (from DataRow dr in dataTable.Rows orderby (string...
[ "c#", "linq", ".net-3.5" ]
117
40
27,375
7
0
2008-08-01T13:14:33.797000
2008-09-04T02:57:27.263000
66
4,521
Paging a collection with LINQ
How do you page through a collection in LINQ given that you have a startIndex and a count?
A few months back I wrote a blog post about Fluent Interfaces and LINQ which used an Extension Method on IQueryable and another class to provide the following natural way of paginating a LINQ collection. var query = from i in ideas select i; var pagedCollection = query.InPagesOf(10); var pageOfIdeas = pagedCollection.P...
Paging a collection with LINQ How do you page through a collection in LINQ given that you have a startIndex and a count?
TITLE: Paging a collection with LINQ QUESTION: How do you page through a collection in LINQ given that you have a startIndex and a count? ANSWER: A few months back I wrote a blog post about Fluent Interfaces and LINQ which used an Extension Method on IQueryable and another class to provide the following natural way o...
[ "linq", ".net-3.5" ]
89
45
6,204
4
0
2008-08-01T13:20:46.890000
2008-08-07T08:22:27.440000
79
62,853
Getting Subclipse in Aptana to work with the newest release of Subversion
The version of Subclipse (1.2.4) currently available through Aptana's automatic Plugins Manager does not work with the newest version of Subversion. I see on the Subclipse website however that they have 1.4.2 out for Eclipse. So I added a new remote update site to my Update manager. When I tried to install it, it told ...
Subclipse does not require Mylyn, but the update site includes a plugin that integrates Mylyn and Subclipse. This is intended for people that use Mylyn. In your case, you would want to just de-select Mylyn in the update dialog. Subclipse also requires Subversion 1.5 and the corresponding version of the JavaHL native li...
Getting Subclipse in Aptana to work with the newest release of Subversion The version of Subclipse (1.2.4) currently available through Aptana's automatic Plugins Manager does not work with the newest version of Subversion. I see on the Subclipse website however that they have 1.4.2 out for Eclipse. So I added a new rem...
TITLE: Getting Subclipse in Aptana to work with the newest release of Subversion QUESTION: The version of Subclipse (1.2.4) currently available through Aptana's automatic Plugins Manager does not work with the newest version of Subversion. I see on the Subclipse website however that they have 1.4.2 out for Eclipse. So...
[ "eclipse", "svn", "aptana", "subclipse" ]
50
18
11,457
4
0
2008-08-01T13:56:33.837000
2008-09-15T13:26:34.350000
80
124
SQLStatement.execute() - multiple queries in one statement
I've written a database generation script in SQL and want to execute it in my Adobe AIR application: Create Table tRole ( roleID integer Primary Key,roleName varchar(40) ); Create Table tFile ( fileID integer Primary Key,fileName varchar(50),fileDescription varchar(500),thumbnailID integer,fileFormatID integer,category...
I wound up using this. It is a kind of a hack, but it actually works pretty well. The only thing is you have to be very careful with your semicolons.: D var strSql:String = stream.readUTFBytes(stream.bytesAvailable); var i:Number = 0; var strSqlSplit:Array = strSql.split(";"); for (i = 0; i < strSqlSplit.length; i++){ ...
SQLStatement.execute() - multiple queries in one statement I've written a database generation script in SQL and want to execute it in my Adobe AIR application: Create Table tRole ( roleID integer Primary Key,roleName varchar(40) ); Create Table tFile ( fileID integer Primary Key,fileName varchar(50),fileDescription var...
TITLE: SQLStatement.execute() - multiple queries in one statement QUESTION: I've written a database generation script in SQL and want to execute it in my Adobe AIR application: Create Table tRole ( roleID integer Primary Key,roleName varchar(40) ); Create Table tFile ( fileID integer Primary Key,fileName varchar(50),f...
[ "apache-flex", "actionscript-3", "air" ]
54
20
6,683
3
0
2008-08-01T13:57:07.033000
2008-08-01T16:09:47.687000
85
154
Flat file databases
What are the best practices around creating flat file database structures in PHP? A lot of more matured PHP flat file frameworks out there which I attempt to implement SQL-like query syntax which is over the top for my purposes in most cases. (I would just use a database at that point). Are there any elegant tricks out...
Well, what is the nature of the flat databases. Are they large or small. Is it simple arrays with arrays in them? if its something simple say userprofiles built as such: $user = array("name" => "bob", "age" => 20, "websites" => array("example.com","bob.example.com","bob2.example.com"), "and_one" => "more"); and to save...
Flat file databases What are the best practices around creating flat file database structures in PHP? A lot of more matured PHP flat file frameworks out there which I attempt to implement SQL-like query syntax which is over the top for my purposes in most cases. (I would just use a database at that point). Are there an...
TITLE: Flat file databases QUESTION: What are the best practices around creating flat file database structures in PHP? A lot of more matured PHP flat file frameworks out there which I attempt to implement SQL-like query syntax which is over the top for my purposes in most cases. (I would just use a database at that po...
[ "php", "sql", "database", "flat-file" ]
132
81
69,859
11
0
2008-08-01T14:19:52.510000
2008-08-01T17:45:06.513000
88
98
Is gettimeofday() guaranteed to be of microsecond resolution?
I am porting a game, that was originally written for the Win32 API, to Linux (well, porting the OS X port of the Win32 port to Linux). I have implemented QueryPerformanceCounter by giving the uSeconds since the process start up: BOOL QueryPerformanceCounter(LARGE_INTEGER* performanceCount) { gettimeofday(&currentTimeVa...
Maybe. But you have bigger problems. gettimeofday() can result in incorrect timings if there are processes on your system that change the timer (ie, ntpd). On a "normal" Linux, though, I believe the resolution of gettimeofday() is 10us. It can jump forward and backward and time, consequently, based on the processes run...
Is gettimeofday() guaranteed to be of microsecond resolution? I am porting a game, that was originally written for the Win32 API, to Linux (well, porting the OS X port of the Win32 port to Linux). I have implemented QueryPerformanceCounter by giving the uSeconds since the process start up: BOOL QueryPerformanceCounter(...
TITLE: Is gettimeofday() guaranteed to be of microsecond resolution? QUESTION: I am porting a game, that was originally written for the Win32 API, to Linux (well, porting the OS X port of the Win32 port to Linux). I have implemented QueryPerformanceCounter by giving the uSeconds since the process start up: BOOL QueryP...
[ "linux", "winapi", "visual-c++", "unix", "timer" ]
106
63
45,129
10
0
2008-08-01T14:36:18.640000
2008-08-01T14:53:47.497000
90
1,466,832
How do you branch and merge with TortoiseSVN?
How do you branch and merge with Apache Subversion using the TortoiseSVN client?
My easy click-by-click instructions ( specific to TortoiseSVN ) are in Stack Overflow question What is the simplest way to do branching and merging using TortoiseSVN?.
How do you branch and merge with TortoiseSVN? How do you branch and merge with Apache Subversion using the TortoiseSVN client?
TITLE: How do you branch and merge with TortoiseSVN? QUESTION: How do you branch and merge with Apache Subversion using the TortoiseSVN client? ANSWER: My easy click-by-click instructions ( specific to TortoiseSVN ) are in Stack Overflow question What is the simplest way to do branching and merging using TortoiseSVN?...
[ "svn", "tortoisesvn", "branch", "branching-and-merging" ]
163
23
56,424
3
0
2008-08-01T14:41:24.277000
2009-09-23T15:40:46.943000
104
112
Anatomy of a "Memory Leak"
In.NET perspective: What is a memory leak? How can you determine whether your application leaks? What are the effects? How can you prevent a memory leak? If your application has memory leak, does it go away when the process exits or is killed? Or do memory leaks in your application affect other processes on the system ...
The best explanation I've seen is in Chapter 7 of the free Foundations of Programming e-book. Basically, in.NET a memory leak occurs when referenced objects are rooted and thus cannot be garbage collected. This occurs accidentally when you hold on to references beyond the intended scope. You'll know that you have leaks...
Anatomy of a "Memory Leak" In.NET perspective: What is a memory leak? How can you determine whether your application leaks? What are the effects? How can you prevent a memory leak? If your application has memory leak, does it go away when the process exits or is killed? Or do memory leaks in your application affect oth...
TITLE: Anatomy of a "Memory Leak" QUESTION: In.NET perspective: What is a memory leak? How can you determine whether your application leaks? What are the effects? How can you prevent a memory leak? If your application has memory leak, does it go away when the process exits or is killed? Or do memory leaks in your appl...
[ ".net", "performance", "memory-leaks", "com-interop" ]
181
112
15,291
15
0
2008-08-01T15:12:34.837000
2008-08-01T15:28:12.543000
108
111
Best Subversion clients for Windows Vista (64bit)
I've been using TortoiseSVN in a Windows environment for quite some time. It seems very feature-complete and nicely integrated into the Windows shell, and more importantly, it's fairly painless to teach to colleagues with little or no experience with source control. However, since we have moved to Windows Vista 64bit, ...
I have been using the 64Bit version of TortoiseSVN for ages and I have never had issues with it on Windows 64Bit or Vista 64Bit. I am currently not aware of any other similiar SVN clients that do work on Vista. Is it possible the problem could lie within the configuration of TortoiseSVN or even the installation of Vist...
Best Subversion clients for Windows Vista (64bit) I've been using TortoiseSVN in a Windows environment for quite some time. It seems very feature-complete and nicely integrated into the Windows shell, and more importantly, it's fairly painless to teach to colleagues with little or no experience with source control. How...
TITLE: Best Subversion clients for Windows Vista (64bit) QUESTION: I've been using TortoiseSVN in a Windows environment for quite some time. It seems very feature-complete and nicely integrated into the Windows shell, and more importantly, it's fairly painless to teach to colleagues with little or no experience with s...
[ "windows", "svn", "64-bit" ]
52
39
16,513
8
0
2008-08-01T15:22:29.467000
2008-08-01T15:27:23.093000
109
2,585
Decoding T-SQL CAST in C#/VB.NET
Recently our site has been deluged with the resurgence of the Asprox botnet SQL injection attack. Without going into details, the attack attempts to execute SQL code by encoding the T-SQL commands in an ASCII encoded BINARY string. It looks something like this: DECLARE%20@S%20NVARCHAR(4000);SET%20@S=CAST(0x44004500...0...
I went back to Michael's post, did some more poking and realized that I did need to do a double conversion, and eventually worked out this little nugget: Convert.ToString(Convert.ToChar(Int32.Parse(EncodedString.Substring(intParseIndex, 2), System.Globalization.NumberStyles.HexNumber))); From there I simply made a loop...
Decoding T-SQL CAST in C#/VB.NET Recently our site has been deluged with the resurgence of the Asprox botnet SQL injection attack. Without going into details, the attack attempts to execute SQL code by encoding the T-SQL commands in an ASCII encoded BINARY string. It looks something like this: DECLARE%20@S%20NVARCHAR(4...
TITLE: Decoding T-SQL CAST in C#/VB.NET QUESTION: Recently our site has been deluged with the resurgence of the Asprox botnet SQL injection attack. Without going into details, the attack attempts to execute SQL code by encoding the T-SQL commands in an ASCII encoded BINARY string. It looks something like this: DECLARE...
[ "c#", "sql", "vb.net", "ascii", "hex" ]
68
24
6,199
2
0
2008-08-01T15:23:05.190000
2008-08-05T17:02:30.870000
123
183
Java lib or app to convert CSV to XML file?
Is there an existing application or library in Java which will allow me to convert a CSV data file to XML file? The XML tags would be provided through possibly the first row containing column headings.
Maybe this might help: JSefa You can read CSV file with this tool and serialize it to XML.
Java lib or app to convert CSV to XML file? Is there an existing application or library in Java which will allow me to convert a CSV data file to XML file? The XML tags would be provided through possibly the first row containing column headings.
TITLE: Java lib or app to convert CSV to XML file? QUESTION: Is there an existing application or library in Java which will allow me to convert a CSV data file to XML file? The XML tags would be provided through possibly the first row containing column headings. ANSWER: Maybe this might help: JSefa You can read CSV f...
[ "java", "xml", "csv", "data-conversion" ]
121
70
81,172
16
0
2008-08-01T16:08:52.353000
2008-08-01T18:51:12.090000
126
127
How would you access Object properties from within an object method?
What is the "purist" or "correct" way to access an object's properties from within an object method that is not a getter/setter method? I know that from outside of the object you should use a getter/setter, but from within would you just do: Java: String property = this.property; PHP: $property = $this->property; or wo...
This has religious war potential, but it seems to me that if you're using a getter/setter, you should use it internally as well - using both will lead to maintenance problems down the road (e.g. somebody adds code to a setter that needs to run every time that property is set, and the property is being set internally w/...
How would you access Object properties from within an object method? What is the "purist" or "correct" way to access an object's properties from within an object method that is not a getter/setter method? I know that from outside of the object you should use a getter/setter, but from within would you just do: Java: Str...
TITLE: How would you access Object properties from within an object method? QUESTION: What is the "purist" or "correct" way to access an object's properties from within an object method that is not a getter/setter method? I know that from outside of the object you should use a getter/setter, but from within would you ...
[ "java", "php", "oop", "theory" ]
106
66
26,730
18
0
2008-08-01T16:10:30.337000
2008-08-01T16:13:47.600000
134
206
XSD DataSets and ignoring foreign keys
I have a pretty standard table set-up in a current application using the.NET XSD DataSet and TableAdapter features. My contracts table consists of some standard contract information, with a column for the primary department. This column is a foreign key to my Departments table, where I store the basic department name, ...
You can try turning Check-constraints off on the DataSet (it's in its properties), or altering the properties of that relationship, and change the key to a simple reference - up to you.
XSD DataSets and ignoring foreign keys I have a pretty standard table set-up in a current application using the.NET XSD DataSet and TableAdapter features. My contracts table consists of some standard contract information, with a column for the primary department. This column is a foreign key to my Departments table, wh...
TITLE: XSD DataSets and ignoring foreign keys QUESTION: I have a pretty standard table set-up in a current application using the.NET XSD DataSet and TableAdapter features. My contracts table consists of some standard contract information, with a column for the primary department. This column is a foreign key to my Dep...
[ ".net", "database", "xsd" ]
39
13
1,519
1
0
2008-08-01T16:33:38.183000
2008-08-01T19:52:14.227000
146
152
How do I track file downloads
I have a website that plays mp3s in a flash player. If a user clicks 'play' the flash player automatically downloads an mp3 and starts playing it. Is there an easy way to track how many times a particular song clip (or any binary file) has been downloaded? Is the play link a link to the actual mp3 file or to some javas...
The funny thing is I wrote a php media gallery for all my musics 2 days ago. I had a similar problem. I'm using http://musicplayer.sourceforge.net/ for the player. And the playlist is built via php. All music requests go to a script called xfer.php?file=WHATEVER $filename = base64_url_decode($_REQUEST['file']); header(...
How do I track file downloads I have a website that plays mp3s in a flash player. If a user clicks 'play' the flash player automatically downloads an mp3 and starts playing it. Is there an easy way to track how many times a particular song clip (or any binary file) has been downloaded? Is the play link a link to the ac...
TITLE: How do I track file downloads QUESTION: I have a website that plays mp3s in a flash player. If a user clicks 'play' the flash player automatically downloads an mp3 and starts playing it. Is there an easy way to track how many times a particular song clip (or any binary file) has been downloaded? Is the play lin...
[ "php", "apache", "logging", "download", "analytics" ]
90
42
21,872
8
0
2008-08-01T17:14:58.337000
2008-08-01T17:33:58.750000
163
170
How do I sync the SVN revision number with my ASP.NET web site?
Stack Overflow has a subversion version number at the bottom: svn revision: 679 I want to use such automatic versioning with my.NET Web Site/Application, Windows Forms, WPD projects/solutions. How do I implement this?
Looks like Jeff is using CruiseControl.NET based on some leafing through the podcast transcripts. This seems to have automated deployment capabilities from source control to production. Might this be where the insertion is happening?
How do I sync the SVN revision number with my ASP.NET web site? Stack Overflow has a subversion version number at the bottom: svn revision: 679 I want to use such automatic versioning with my.NET Web Site/Application, Windows Forms, WPD projects/solutions. How do I implement this?
TITLE: How do I sync the SVN revision number with my ASP.NET web site? QUESTION: Stack Overflow has a subversion version number at the bottom: svn revision: 679 I want to use such automatic versioning with my.NET Web Site/Application, Windows Forms, WPD projects/solutions. How do I implement this? ANSWER: Looks like ...
[ ".net", "asp.net", "svn", "versioning" ]
101
32
9,524
7
0
2008-08-01T18:00:13.830000
2008-08-01T18:24:30.550000
164
699
Embedding Windows Media Player for all browsers
Edit: This question was written in 2008, which was like 3 internet ages ago. If this question is still relevant to your environment, please accept my condolences. Everyone else should convert into a format supported by your browsers (That would be H.264 if Internet Explorer is needed, and probably AV1, VP8/VP9 if not) ...
The following works for me in Firefox and Internet Explorer:
Embedding Windows Media Player for all browsers Edit: This question was written in 2008, which was like 3 internet ages ago. If this question is still relevant to your environment, please accept my condolences. Everyone else should convert into a format supported by your browsers (That would be H.264 if Internet Explor...
TITLE: Embedding Windows Media Player for all browsers QUESTION: Edit: This question was written in 2008, which was like 3 internet ages ago. If this question is still relevant to your environment, please accept my condolences. Everyone else should convert into a format supported by your browsers (That would be H.264 ...
[ "windows", "embed", "media" ]
64
47
177,305
10
0
2008-08-01T18:02:22.797000
2008-08-03T14:27:20.967000
173
516
How to do version control for SQL Server database?
I want to get my databases under version control. I'll always want to have at least some data in there (as alumb mentions: user types and administrators). I'll also often want a large collection of generated test data for performance measurements. How would I apply version control to my database?
Martin Fowler wrote my favorite article on the subject, http://martinfowler.com/articles/evodb.html. I choose not to put schema dumps in under version control as alumb and others suggest because I want an easy way to upgrade my production database. For a web application where I'll have a single production database inst...
How to do version control for SQL Server database? I want to get my databases under version control. I'll always want to have at least some data in there (as alumb mentions: user types and administrators). I'll also often want a large collection of generated test data for performance measurements. How would I apply ver...
TITLE: How to do version control for SQL Server database? QUESTION: I want to get my databases under version control. I'll always want to have at least some data in there (as alumb mentions: user types and administrators). I'll also often want a large collection of generated test data for performance measurements. How...
[ "sql-server", "database", "svn", "version-control" ]
341
191
124,650
21
0
2008-08-01T18:33:08.333000
2008-08-02T17:33:54.927000
176
207
error_log per Virtual Host?
On one Linux Server running Apache and PHP 5, we have multiple Virtual Hosts with separate log files. We cannot seem to separate the php error_log between virtual hosts. Overriding this setting in the of the httpd.conf does not seem to do anything. Is there a way to have separate php error_logs for each Virtual Host?
To set the Apache ( not the PHP ) log, the easiest way to do this would be to do: # Stuff, # More Stuff, ErrorLog /path/where/you/want/the/error.log If there is no leading "/" it is assumed to be relative. Apache Error Log Page
error_log per Virtual Host? On one Linux Server running Apache and PHP 5, we have multiple Virtual Hosts with separate log files. We cannot seem to separate the php error_log between virtual hosts. Overriding this setting in the of the httpd.conf does not seem to do anything. Is there a way to have separate php error_l...
TITLE: error_log per Virtual Host? QUESTION: On one Linux Server running Apache and PHP 5, we have multiple Virtual Hosts with separate log files. We cannot seem to separate the php error_log between virtual hosts. Overriding this setting in the of the httpd.conf does not seem to do anything. Is there a way to have se...
[ "linux", "apache", "virtualhost" ]
124
89
120,269
11
0
2008-08-01T18:37:40.150000
2008-08-01T19:58:45.837000
180
539
Function for creating color wheels
This is something I've pseudo-solved many times and have never quite found a solution for. The problem is to come up with a way to generate N colors, that are as distinguishable as possible where N is a parameter.
My first thought on this is "how to generate N vectors in a space that maximize distance from each other." You can see that the RGB (or any other scale you use that forms a basis in color space) are just vectors. Take a look at Random Point Picking. Once you have a set of vectors that are maximized apart, you can save ...
Function for creating color wheels This is something I've pseudo-solved many times and have never quite found a solution for. The problem is to come up with a way to generate N colors, that are as distinguishable as possible where N is a parameter.
TITLE: Function for creating color wheels QUESTION: This is something I've pseudo-solved many times and have never quite found a solution for. The problem is to come up with a way to generate N colors, that are as distinguishable as possible where N is a parameter. ANSWER: My first thought on this is "how to generate...
[ "algorithm", "language-agnostic", "colors", "color-space" ]
71
28
19,598
8
0
2008-08-01T18:42:19.343000
2008-08-02T19:03:52.170000
192
258
Floating Point Number parsing: Is there a Catch All algorithm?
One of the fun parts of multi-cultural programming is number formats. Americans use 10,000.50 Germans use 10.000,50 French use 10 000,50 My first approach would be to take the string, parse it backwards until I encounter a separator and use this as my decimal separator. There is an obvious flaw with that: 10.000 would ...
I think the best you can do in this case is to take their input and then show them what you think they meant. If they disagree, show them the format you're expecting and get them to enter it again.
Floating Point Number parsing: Is there a Catch All algorithm? One of the fun parts of multi-cultural programming is number formats. Americans use 10,000.50 Germans use 10.000,50 French use 10 000,50 My first approach would be to take the string, parse it backwards until I encounter a separator and use this as my decim...
TITLE: Floating Point Number parsing: Is there a Catch All algorithm? QUESTION: One of the fun parts of multi-cultural programming is number formats. Americans use 10,000.50 Germans use 10.000,50 French use 10 000,50 My first approach would be to take the string, parse it backwards until I encounter a separator and us...
[ "c#", ".net", "asp.net", "internationalization", "globalization" ]
72
32
3,583
4
0
2008-08-01T19:23:13.117000
2008-08-01T23:17:53.657000
194
197
Upgrading SQL Server 6.5
Yes, I know. The existence of a running copy of SQL Server 6.5 in 2008 is absurd. That stipulated, what is the best way to migrate from 6.5 to 2005? Is there any direct path? Most of the documentation I've found deals with upgrading 6.5 to 7. Should I forget about the native SQL Server upgrade utilities, script out all...
Hey, I'm still stuck in that camp too. The third party application we have to support is FINALLY going to 2K5, so we're almost out of the wood. But I feel your pain 8^D That said, from everything I heard from our DBA, the key is to convert the database to 8.0 format first, and then go to 2005. I believe they used the b...
Upgrading SQL Server 6.5 Yes, I know. The existence of a running copy of SQL Server 6.5 in 2008 is absurd. That stipulated, what is the best way to migrate from 6.5 to 2005? Is there any direct path? Most of the documentation I've found deals with upgrading 6.5 to 7. Should I forget about the native SQL Server upgrade ...
TITLE: Upgrading SQL Server 6.5 QUESTION: Yes, I know. The existence of a running copy of SQL Server 6.5 in 2008 is absurd. That stipulated, what is the best way to migrate from 6.5 to 2005? Is there any direct path? Most of the documentation I've found deals with upgrading 6.5 to 7. Should I forget about the native S...
[ "sql-server", "migration" ]
40
11
4,760
4
0
2008-08-01T19:26:37.883000
2008-08-01T19:34:49.067000
227
2,943,318
Create a tag cloud by wrapping array values in h1 through h6 tags based on a mapping array of weights
I have the following arrays: $artist = ["the roots", "michael jackson", "billy idol", "more", "and more", "and_YET_MORE"]; $count = [5, 3, 9, 1, 1, 3]; I want to generate a tag cloud that will have artists with a higher number in $count enclosed in h6 tags and the lowest enclosed h1 tags.
You will want to add a logarithmic function to it too. (taken from tagadelic, my Drupal module to create tag clouds http://drupal.org/project/tagadelic ): db_query('SELECT COUNT(*) AS count, id, name FROM... ORDER BY count DESC'); $steps = 6; $tags = array(); $min = 1e9; $max = -1e9; while ($tag = db_fetch_object($re...
Create a tag cloud by wrapping array values in h1 through h6 tags based on a mapping array of weights I have the following arrays: $artist = ["the roots", "michael jackson", "billy idol", "more", "and more", "and_YET_MORE"]; $count = [5, 3, 9, 1, 1, 3]; I want to generate a tag cloud that will have artists with a highe...
TITLE: Create a tag cloud by wrapping array values in h1 through h6 tags based on a mapping array of weights QUESTION: I have the following arrays: $artist = ["the roots", "michael jackson", "billy idol", "more", "and more", "and_YET_MORE"]; $count = [5, 3, 9, 1, 1, 3]; I want to generate a tag cloud that will have ar...
[ "php", "arrays", "mapping", "tag-cloud" ]
79
43
9,776
9
0
2008-08-01T21:40:55.833000
2010-05-31T11:53:57.940000
231
1,812
Register Windows program with the mailto protocol programmatically
How do I make it so mailto: links will be registered with my program? How would I then handle that event in my program? Most of the solutions I found from a quick Google search are how to do this manually, but I need to do this automatically for users of my program if they click a button, such as "set as default email ...
@Dillie-O: Your answer put me in the right direction (I should have expected it to just be a registry change) and I got this working. But I'm going to mark this as the answer because I'm going to put some additional information that I found while working on this. The solution to this question really doesn't depend on w...
Register Windows program with the mailto protocol programmatically How do I make it so mailto: links will be registered with my program? How would I then handle that event in my program? Most of the solutions I found from a quick Google search are how to do this manually, but I need to do this automatically for users o...
TITLE: Register Windows program with the mailto protocol programmatically QUESTION: How do I make it so mailto: links will be registered with my program? How would I then handle that event in my program? Most of the solutions I found from a quick Google search are how to do this manually, but I need to do this automat...
[ "windows", "mailto" ]
43
19
31,416
2
0
2008-08-01T22:08:14.453000
2008-08-05T01:49:25.940000
234
12,202
SQL Server 2005 implementation of MySQL REPLACE INTO?
MySQL has this incredibly useful yet proprietary REPLACE INTO SQL Command. Can this easily be emulated in SQL Server 2005? Starting a new Transaction, doing a Select() and then either UPDATE or INSERT and COMMIT is always a little bit of a pain, especially when doing it in the application and therefore always keeping 2...
This is something that annoys me about MSSQL ( rant on my blog ). I wish MSSQL supported upsert. @Dillie-O's code is a good way in older SQL versions (+1 vote), but it still is basically two IO operations (the exists and then the update or insert ) There's a slightly better way on this post, basically: --try an update ...
SQL Server 2005 implementation of MySQL REPLACE INTO? MySQL has this incredibly useful yet proprietary REPLACE INTO SQL Command. Can this easily be emulated in SQL Server 2005? Starting a new Transaction, doing a Select() and then either UPDATE or INSERT and COMMIT is always a little bit of a pain, especially when doin...
TITLE: SQL Server 2005 implementation of MySQL REPLACE INTO? QUESTION: MySQL has this incredibly useful yet proprietary REPLACE INTO SQL Command. Can this easily be emulated in SQL Server 2005? Starting a new Transaction, doing a Select() and then either UPDATE or INSERT and COMMIT is always a little bit of a pain, es...
[ "mysql", "sql-server", "sql-server-2005" ]
89
63
51,546
4
0
2008-08-01T22:13:34.100000
2008-08-15T12:50:22.350000
246
176,741
Create a SQLite database based on an XSD Data Set
Does anybody know if there is a way to create an SQLite database based on an XSD DataSet? In the past, I've just used a basic SQLite manager, but I want to fuse things a bit more with my.NET development if possible.
I suspect in the general case this is hard; XML Schema allows for some quite bizarre type constructions. I'm not sure how you would do substitution groups, or extensions to restrictions of types for example. However it should be possible to knock something together quite quickly (especially mapping from the classes in ...
Create a SQLite database based on an XSD Data Set Does anybody know if there is a way to create an SQLite database based on an XSD DataSet? In the past, I've just used a basic SQLite manager, but I want to fuse things a bit more with my.NET development if possible.
TITLE: Create a SQLite database based on an XSD Data Set QUESTION: Does anybody know if there is a way to create an SQLite database based on an XSD DataSet? In the past, I've just used a basic SQLite manager, but I want to fuse things a bit more with my.NET development if possible. ANSWER: I suspect in the general ca...
[ ".net", "database", "sqlite" ]
45
19
3,283
3
0
2008-08-01T22:34:42.853000
2008-10-06T23:58:50.823000
260
307
Adding scripting functionality to .NET applications
I have a little game written in C#. It uses a database as back-end. It's a trading card game, and I wanted to implement the function of the cards as a script. What I mean is that I essentially have an interface, ICard, which a card class implements ( public class Card056: ICard ) and which contains a function that is c...
Oleg Shilo's C# Script solution (at The Code Project ) really is a great introduction to providing script abilities in your application. A different approach would be to consider a language that is specifically built for scripting, such as IronRuby, IronPython, or Lua. IronPython and IronRuby are both available today. ...
Adding scripting functionality to .NET applications I have a little game written in C#. It uses a database as back-end. It's a trading card game, and I wanted to implement the function of the cards as a script. What I mean is that I essentially have an interface, ICard, which a card class implements ( public class Card...
TITLE: Adding scripting functionality to .NET applications QUESTION: I have a little game written in C#. It uses a database as back-end. It's a trading card game, and I wanted to implement the function of the cards as a script. What I mean is that I essentially have an interface, ICard, which a card class implements (...
[ "c#", ".net", "scripting", "compiler-construction" ]
83
44
22,879
9
0
2008-08-01T23:22:08.983000
2008-08-02T01:49:46.220000
263
607
GTK implementation of MessageBox
I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL, so this isn't a GTK app. I handle the initialization ( gtk_init ) sort of stuff inside the MessageBox function as follows: int MessageBox(HWND hwnd, const char* text, const char* caption, UINT type) { GtkWidget *window = NULL; GtkWid...
Hmm, ok. I'd suggest code like this, then: typedef struct { int type; int result; } DialogData; static gboolean display_dialog(gpointer user_data) { DialogData *dialog_data = user_data; GtkWidget *dialog; if (dialog_data->type & MB_YESNO) dialog = gtk_message_dialog_new(...); else dialog = gtk_message_dialog_new(...)...
GTK implementation of MessageBox I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL, so this isn't a GTK app. I handle the initialization ( gtk_init ) sort of stuff inside the MessageBox function as follows: int MessageBox(HWND hwnd, const char* text, const char* caption, UINT type) {...
TITLE: GTK implementation of MessageBox QUESTION: I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL, so this isn't a GTK app. I handle the initialization ( gtk_init ) sort of stuff inside the MessageBox function as follows: int MessageBox(HWND hwnd, const char* text, const char* cap...
[ "c", "linux", "gtk", "x11" ]
42
18
11,832
3
0
2008-08-01T23:27:24.993000
2008-08-03T02:30:05.907000
265
266
Best Practice: Collaborative Environment, Bin Directory, SVN
What are the best practices for checking in BIN directories in a collaborative development environment using SVN? Should project level references be excluded from checkin? Is it easier to just add all bin directories? I develop a lot of DotNetNuke sites and it seems that in a multi-developer environment, it's always a ...
Any assemblies that are expected to be in the GAC should stay in the GAC. This includes System.web.dll or any other 3rd party dll that you'll deploy to the GAC in production. This means a new developer would have to install these assemblies. All other 3rd party assemblies should be references through a relative path. M...
Best Practice: Collaborative Environment, Bin Directory, SVN What are the best practices for checking in BIN directories in a collaborative development environment using SVN? Should project level references be excluded from checkin? Is it easier to just add all bin directories? I develop a lot of DotNetNuke sites and i...
TITLE: Best Practice: Collaborative Environment, Bin Directory, SVN QUESTION: What are the best practices for checking in BIN directories in a collaborative development environment using SVN? Should project level references be excluded from checkin? Is it easier to just add all bin directories? I develop a lot of DotN...
[ "svn", "collaboration" ]
38
19
3,296
5
0
2008-08-01T23:29:32.853000
2008-08-01T23:40:28.463000
289
298
How do you sort a dictionary by value?
I often have to sort a dictionary (consisting of keys & values) by value. For example, I have a hash of words and respective frequencies that I want to order by frequency. There is a SortedList which is good for a single value (say frequency), that I want to map back to the word. SortedDictionary orders by key, not val...
Use: using System.Linq.Enumerable;... List > myList = aDictionary.ToList(); myList.Sort( delegate(KeyValuePair pair1, KeyValuePair pair2) { return pair1.Value.CompareTo(pair2.Value); } ); Since you're targeting.NET 2.0 or above, you can simplify this into lambda syntax -- it's equivalent, but shorter. If you're target...
How do you sort a dictionary by value? I often have to sort a dictionary (consisting of keys & values) by value. For example, I have a hash of words and respective frequencies that I want to order by frequency. There is a SortedList which is good for a single value (say frequency), that I want to map back to the word. ...
TITLE: How do you sort a dictionary by value? QUESTION: I often have to sort a dictionary (consisting of keys & values) by value. For example, I have a hash of words and respective frequencies that I want to order by frequency. There is a SortedList which is good for a single value (say frequency), that I want to map ...
[ "c#", ".net", "sorting", "dictionary" ]
955
572
825,359
21
0
2008-08-02T00:40:58.200000
2008-08-02T01:15:42.123000
308
360
Is there a version control system for database structure changes?
I often run into the following problem. I work on some changes to a project that require new tables or columns in the database. I make the database modifications and continue my work. Usually, I remember to write down the changes so that they can be replicated on the live system. However, I don't always remember what I...
In Ruby on Rails, there's a concept of a migration -- a quick script to change the database. You generate a migration file, which has rules to increase the db version (such as adding a column) and rules to downgrade the version (such as removing a column). Each migration is numbered, and a table keeps track of your cur...
Is there a version control system for database structure changes? I often run into the following problem. I work on some changes to a project that require new tables or columns in the database. I make the database modifications and continue my work. Usually, I remember to write down the changes so that they can be repl...
TITLE: Is there a version control system for database structure changes? QUESTION: I often run into the following problem. I work on some changes to a project that require new tables or columns in the database. I make the database modifications and continue my work. Usually, I remember to write down the changes so tha...
[ "sql", "database", "oracle", "version-control" ]
133
66
38,383
22
0
2008-08-02T01:52:54.653000
2008-08-02T06:23:33.737000
328
7,488
PHP Session Security
What are some guidelines for maintaining responsible session security with PHP? There's information all over the web and it's about time it all landed in one place!
There are a couple of things to do in order to keep your session secure: Use SSL when authenticating users or performing sensitive operations. Regenerate the session id whenever the security level changes (such as logging in). You can even regenerate the session id every request if you wish. Have sessions time out Don'...
PHP Session Security What are some guidelines for maintaining responsible session security with PHP? There's information all over the web and it's about time it all landed in one place!
TITLE: PHP Session Security QUESTION: What are some guidelines for maintaining responsible session security with PHP? There's information all over the web and it's about time it all landed in one place! ANSWER: There are a couple of things to do in order to keep your session secure: Use SSL when authenticating users ...
[ "security", "php" ]
125
88
85,917
13
0
2008-08-02T02:41:34.493000
2008-08-11T02:38:06.737000
330
332
Should I use nested classes in this case?
I am working on a collection of classes used for video playback and recording. I have one main class which acts like the public interface, with methods like play(), stop(), pause(), record() etc... Then I have workhorse classes that do the video decoding and video encoding. I just learned about the existence of nested ...
I would be a bit reluctant to use nested classes here. What if you created an abstract base class for a "multimedia driver" to handle the back-end stuff (workhorse), and a separate class for the front-end work? The front-end class could take a pointer/reference to an implemented driver class (for the appropriate media ...
Should I use nested classes in this case? I am working on a collection of classes used for video playback and recording. I have one main class which acts like the public interface, with methods like play(), stop(), pause(), record() etc... Then I have workhorse classes that do the video decoding and video encoding. I j...
TITLE: Should I use nested classes in this case? QUESTION: I am working on a collection of classes used for video playback and recording. I have one main class which acts like the public interface, with methods like play(), stop(), pause(), record() etc... Then I have workhorse classes that do the video decoding and v...
[ "c++", "class", "oop", "inner-classes" ]
58
30
5,019
10
0
2008-08-02T02:51:36.470000
2008-08-02T03:00:24.613000
336
339
When to use unsigned values over signed ones?
When is it appropriate to use an unsigned variable over a signed one? What about in a for loop? I hear a lot of opinions about this and I wanted to see if there was anything resembling a consensus. for (unsigned int i = 0; i < someThing.length(); i++) { SomeThing var = someThing.at(i); // You get the idea. } I know Jav...
I was glad to find a good conversation on this subject, as I hadn't really given it much thought before. In summary, signed is a good general choice - even when you're dead sure all the numbers are positive - if you're going to do arithmetic on the variable (like in a typical for loop case). unsigned starts to make mor...
When to use unsigned values over signed ones? When is it appropriate to use an unsigned variable over a signed one? What about in a for loop? I hear a lot of opinions about this and I wanted to see if there was anything resembling a consensus. for (unsigned int i = 0; i < someThing.length(); i++) { SomeThing var = some...
TITLE: When to use unsigned values over signed ones? QUESTION: When is it appropriate to use an unsigned variable over a signed one? What about in a for loop? I hear a lot of opinions about this and I wanted to see if there was anything resembling a consensus. for (unsigned int i = 0; i < someThing.length(); i++) { So...
[ "language-agnostic", "types" ]
93
82
29,448
5
0
2008-08-02T03:34:44.763000
2008-08-02T03:49:21.987000
337
342
XML Processing in Python
I am about to build a piece of a project that will need to construct and post an XML document to a web service and I'd like to do it in Python, as a means to expand my skills in it. Unfortunately, whilst I know the XML model fairly well in.NET, I'm uncertain what the pros and cons are of the XML models in Python. Anyon...
Personally, I've played with several of the built-in options on an XML-heavy project and have settled on pulldom as the best choice for less complex documents. Especially for small simple stuff, I like the event-driven theory of parsing rather than setting up a whole slew of callbacks for a relatively simple structure....
XML Processing in Python I am about to build a piece of a project that will need to construct and post an XML document to a web service and I'd like to do it in Python, as a means to expand my skills in it. Unfortunately, whilst I know the XML model fairly well in.NET, I'm uncertain what the pros and cons are of the XM...
TITLE: XML Processing in Python QUESTION: I am about to build a piece of a project that will need to construct and post an XML document to a web service and I'd like to do it in Python, as a means to expand my skills in it. Unfortunately, whilst I know the XML model fairly well in.NET, I'm uncertain what the pros and ...
[ "python", "xml" ]
82
36
10,595
12
0
2008-08-02T03:35:55.697000
2008-08-02T04:01:34.600000
361
362
Generate list of all possible permutations of a string
How would I go about generating a list of all possible permutations of a string between x and y characters in length, containing a variable list of characters. Any language would work, but it should be portable.
There are several ways to do this. Common methods use recursion, memoization, or dynamic programming. The basic idea is that you produce a list of all strings of length 1, then in each iteration, for all strings produced in the last iteration, add that string concatenated with each character in the string individually....
Generate list of all possible permutations of a string How would I go about generating a list of all possible permutations of a string between x and y characters in length, containing a variable list of characters. Any language would work, but it should be portable.
TITLE: Generate list of all possible permutations of a string QUESTION: How would I go about generating a list of all possible permutations of a string between x and y characters in length, containing a variable list of characters. Any language would work, but it should be portable. ANSWER: There are several ways to ...
[ "string", "language-agnostic", "cross-platform", "permutation", "combinatorics" ]
166
69
214,067
36
0
2008-08-02T06:57:57.957000
2008-08-02T07:48:07.607000
371
396
How do you make sure email you send programmatically is not automatically marked as spam?
This is a tricky one and I've always relied on techniques, such as permission-based emails (i.e. only sending to people you have permission to send to) and not using blatantly spamish terminology. Of late, some of the emails I send out programmatically have started being shuffled into people's spam folder automatically...
Use email authentication methods, such as SPF, and DKIM to prove that your emails and your domain name belong together, and to prevent spoofing of your domain name. The SPF website includes a wizard to generate the DNS information for your site. Check your reverse DNS to make sure the IP address of your mail server poi...
How do you make sure email you send programmatically is not automatically marked as spam? This is a tricky one and I've always relied on techniques, such as permission-based emails (i.e. only sending to people you have permission to send to) and not using blatantly spamish terminology. Of late, some of the emails I sen...
TITLE: How do you make sure email you send programmatically is not automatically marked as spam? QUESTION: This is a tricky one and I've always relied on techniques, such as permission-based emails (i.e. only sending to people you have permission to send to) and not using blatantly spamish terminology. Of late, some o...
[ "email", "email-spam" ]
464
354
119,005
24
0
2008-08-02T08:19:18.260000
2008-08-02T10:21:54.300000
382
384
What is the meaning of the type safety warning in certain Java generics casts?
What is the meaning of the Java warning? Type safety: The cast from Object to List is actually checking against the erased type List I get this warning when I try to cast an Object to a type with generic information, such as in the following code: Object object = getMyList(); List list = (List ) object;
This warning is there because Java is not actually storing type information at run-time in an object that uses generics. Thus, if object is actually a List, there will be no ClassCastException at run-time except until an item is accessed from the list that doesn't match the generic type defined in the variable. This ca...
What is the meaning of the type safety warning in certain Java generics casts? What is the meaning of the Java warning? Type safety: The cast from Object to List is actually checking against the erased type List I get this warning when I try to cast an Object to a type with generic information, such as in the following...
TITLE: What is the meaning of the type safety warning in certain Java generics casts? QUESTION: What is the meaning of the Java warning? Type safety: The cast from Object to List is actually checking against the erased type List I get this warning when I try to cast an Object to a type with generic information, such a...
[ "java", "generics", "warnings", "casting", "type-safety" ]
81
53
10,291
1
0
2008-08-02T08:58:27.540000
2008-08-02T08:58:48.430000
402
2,530,953
iPhone app in landscape mode, 2008 systems
Please note that this question is from 2008 and now is of only historic interest. What's the best way to create an iPhone application that runs in landscape mode from the start, regardless of the position of the device? Both programmatically and using the Interface Builder.
Historic answer only. Spectacularly out of date. Please note that this answer is now hugely out of date/ This answer is only a historical curiosity. Exciting news! As discovered by Andrew below, this problem has been fixed by Apple in 4.0+. It would appear it is NO longer necessary to force the size of the view on ever...
iPhone app in landscape mode, 2008 systems Please note that this question is from 2008 and now is of only historic interest. What's the best way to create an iPhone application that runs in landscape mode from the start, regardless of the position of the device? Both programmatically and using the Interface Builder.
TITLE: iPhone app in landscape mode, 2008 systems QUESTION: Please note that this question is from 2008 and now is of only historic interest. What's the best way to create an iPhone application that runs in landscape mode from the start, regardless of the position of the device? Both programmatically and using the Int...
[ "ios", "objective-c", "landscape" ]
100
47
67,593
8
0
2008-08-02T10:47:08.460000
2010-03-27T21:13:17.970000
419
17,396
Unload a COM control when working in VB6 IDE
Part of my everyday work is maintaining and extending legacy VB6 applications. A common engine is written in C/C++ and VB6 uses these functions in order to improve performance. When it comes to asynchronous programming, a C interface is not enough and we rely on COM controls to fire events to VB6. My problem is that wh...
I'm pretty sure there's no good way to force VB6 to unload the control. Here's what I do... instead of running Visual C and Visual Basic side-by-side, run VB6 under VC: Load up VC Open the project containing your COM objects Edit, change, etc. In VC, set the Output Executable to be VB6.EXE with appropriate command-line...
Unload a COM control when working in VB6 IDE Part of my everyday work is maintaining and extending legacy VB6 applications. A common engine is written in C/C++ and VB6 uses these functions in order to improve performance. When it comes to asynchronous programming, a C interface is not enough and we rely on COM controls...
TITLE: Unload a COM control when working in VB6 IDE QUESTION: Part of my everyday work is maintaining and extending legacy VB6 applications. A common engine is written in C/C++ and VB6 uses these functions in order to improve performance. When it comes to asynchronous programming, a C interface is not enough and we re...
[ "com", "vb6" ]
37
27
3,067
1
0
2008-08-02T11:52:01.543000
2008-08-20T03:58:09.347000
438
77,397
Implementation of "Remember me" in a Rails application
My Rails-app has a sign in box with a "remember me" checkbox. Users who check that box should remain logged in even after closing their browser. I'm keeping track of whether users are logged in by storing their id in the user's session. But sessions are implemented in Rails as session cookies, which are not persistent....
I have spent a while thinking about this and came to some conclusions. Rails session cookies are tamper-proof by default, so you really don't have to worry about a cookie being modified on the client end. Here is what I've done: Session cookie is set to be long-lived (6 months or so) Inside the session store An 'expire...
Implementation of "Remember me" in a Rails application My Rails-app has a sign in box with a "remember me" checkbox. Users who check that box should remain logged in even after closing their browser. I'm keeping track of whether users are logged in by storing their id in the user's session. But sessions are implemented...
TITLE: Implementation of "Remember me" in a Rails application QUESTION: My Rails-app has a sign in box with a "remember me" checkbox. Users who check that box should remain logged in even after closing their browser. I'm keeping track of whether users are logged in by storing their id in the user's session. But sessio...
[ "ruby-on-rails", "ruby", "http" ]
57
13
12,127
7
0
2008-08-02T12:56:58.590000
2008-09-16T21:37:36.440000
469
3,040
How can I find the full path to a font from its display name on a Mac?
I am using the Photoshop's javascript API to find the fonts in a given PSD. Given a font name returned by the API, I want to find the actual physical font file that font name corresponds to on the disc. This is all happening in a python program running on OSX so I guess I'm looking for one of: Some Photoshop javascript...
Unfortunately the only API that isn't deprecated is located in the ApplicationServices framework, which doesn't have a bridge support file, and thus isn't available in the bridge. If you're wanting to use ctypes, you can use ATSFontGetFileReference after looking up the ATSFontRef. Cocoa doesn't have any native support,...
How can I find the full path to a font from its display name on a Mac? I am using the Photoshop's javascript API to find the fonts in a given PSD. Given a font name returned by the API, I want to find the actual physical font file that font name corresponds to on the disc. This is all happening in a python program runn...
TITLE: How can I find the full path to a font from its display name on a Mac? QUESTION: I am using the Photoshop's javascript API to find the fonts in a given PSD. Given a font name returned by the API, I want to find the actual physical font file that font name corresponds to on the disc. This is all happening in a p...
[ "python", "macos", "fonts", "photoshop" ]
48
22
5,094
6
0
2008-08-02T15:11:16.430000
2008-08-06T03:01:23.890000
470
473
Homegrown consumption of web services
I've been writing a few web services for a.net app, now I'm ready to consume them. I've seen numerous examples where there is homegrown code for consuming the service as opposed to using the auto generated methods that Visual Studio creates when adding the web reference. Is there some advantages to this?
No, what you're doing is fine. Don't let those people confuse you. If you've written the web services with.net then the reference proxies generated by.net are going to be quite suitable. The situation you describe (where you are both producer and consumer) is the ideal situation. If you need to connect to a web service...
Homegrown consumption of web services I've been writing a few web services for a.net app, now I'm ready to consume them. I've seen numerous examples where there is homegrown code for consuming the service as opposed to using the auto generated methods that Visual Studio creates when adding the web reference. Is there s...
TITLE: Homegrown consumption of web services QUESTION: I've been writing a few web services for a.net app, now I'm ready to consume them. I've seen numerous examples where there is homegrown code for consuming the service as opposed to using the auto generated methods that Visual Studio creates when adding the web ref...
[ ".net", "web-services" ]
24
11
789
1
0
2008-08-02T15:11:47.523000
2008-08-02T15:33:13.390000
482
509
WinForms ComboBox data binding gotcha
Assume you are doing something like the following List myitems = new List { "Item 1", "Item 2", "Item 3" }; ComboBox box = new ComboBox(); box.DataSource = myitems; ComboBox box2 = new ComboBox(); box2.DataSource = myitems So now we have 2 combo boxes bound to that array, and everything works fine. But when you chang...
This has to do with how data bindings are set up in the dotnet framework, especially the BindingContext. On a high level it means that if you haven't specified otherwise each form and all the controls of the form share the same BindingContext. When you are setting the DataSource property the ComboBox will use the Bindi...
WinForms ComboBox data binding gotcha Assume you are doing something like the following List myitems = new List { "Item 1", "Item 2", "Item 3" }; ComboBox box = new ComboBox(); box.DataSource = myitems; ComboBox box2 = new ComboBox(); box2.DataSource = myitems So now we have 2 combo boxes bound to that array, and eve...
TITLE: WinForms ComboBox data binding gotcha QUESTION: Assume you are doing something like the following List myitems = new List { "Item 1", "Item 2", "Item 3" }; ComboBox box = new ComboBox(); box.DataSource = myitems; ComboBox box2 = new ComboBox(); box2.DataSource = myitems So now we have 2 combo boxes bound to t...
[ "c#", "winforms", "data-binding" ]
57
39
20,990
2
0
2008-08-02T16:09:56.780000
2008-08-02T17:18:12.680000
502
7,090
Get a preview JPEG of a PDF on Windows?
I have a cross-platform (Python) application which needs to generate a JPEG preview of the first page of a PDF. On the Mac I am spawning sips. Is there something similarly simple I can do on Windows?
ImageMagick delegates the PDF->bitmap conversion to GhostScript anyway, so here's a command you can use (it's based on the actual command listed by the ps:alpha delegate in ImageMagick, just adjusted to use JPEG as output): gs -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT \ -dMaxBitmap=500000000 -dLastPage=1 ...
Get a preview JPEG of a PDF on Windows? I have a cross-platform (Python) application which needs to generate a JPEG preview of the first page of a PDF. On the Mac I am spawning sips. Is there something similarly simple I can do on Windows?
TITLE: Get a preview JPEG of a PDF on Windows? QUESTION: I have a cross-platform (Python) application which needs to generate a JPEG preview of the first page of a PDF. On the Mac I am spawning sips. Is there something similarly simple I can do on Windows? ANSWER: ImageMagick delegates the PDF->bitmap conversion to G...
[ "python", "windows", "image", "pdf" ]
59
44
18,039
3
0
2008-08-02T17:01:58.500000
2008-08-10T08:08:33.543000
514
519
Frequent SystemExit in Ruby when making HTTP calls
I have a Ruby on Rails Website that makes HTTP calls to an external Web Service. About once a day I get a SystemExit (stacktrace below) error email where a call to the service has failed. If I then try the exact same query on my site moments later it works fine. It's been happening since the site went live and I've had...
Using fcgi with Ruby is known to be very buggy. Practically everybody has moved to Mongrel for this reason, and I recommend you do the same.
Frequent SystemExit in Ruby when making HTTP calls I have a Ruby on Rails Website that makes HTTP calls to an external Web Service. About once a day I get a SystemExit (stacktrace below) error email where a call to the service has failed. If I then try the exact same query on my site moments later it works fine. It's b...
TITLE: Frequent SystemExit in Ruby when making HTTP calls QUESTION: I have a Ruby on Rails Website that makes HTTP calls to an external Web Service. About once a day I get a SystemExit (stacktrace below) error email where a call to the service has failed. If I then try the exact same query on my site moments later it ...
[ "ruby-on-rails", "ruby", "crash" ]
24
9
2,335
4
0
2008-08-02T17:26:39.793000
2008-08-02T17:50:34.987000
535
541
Continuous Integration System for a Python Codebase
I am starting to work on a hobby project with a Python codebase and I would like to set up some form of continuous integration (i.e. running a battery of test-cases each time a check-in is made and sending nag e-mails to responsible persons when the tests fail) similar to CruiseControl or TeamCity. I realize I could do...
We run Buildbot - Trac at work. I haven't used it too much since my codebase isn't part of the release cycle yet. But we run the tests on different environments (OSX/Linux/Win) and it sends emails — and it's written in Python.
Continuous Integration System for a Python Codebase I am starting to work on a hobby project with a Python codebase and I would like to set up some form of continuous integration (i.e. running a battery of test-cases each time a check-in is made and sending nag e-mails to responsible persons when the tests fail) simila...
TITLE: Continuous Integration System for a Python Codebase QUESTION: I am starting to work on a hobby project with a Python codebase and I would like to set up some form of continuous integration (i.e. running a battery of test-cases each time a check-in is made and sending nag e-mails to responsible persons when the ...
[ "python", "continuous-integration", "extreme-programming" ]
69
33
9,653
7
0
2008-08-02T18:43:54.787000
2008-08-02T19:06:40.667000
549
477,578
The definitive guide to form-based website authentication
Moderator note: This question is not a good fit for our question and answer format with the topicality rules which currently apply for Stack Overflow. We normally use a "historical lock" for such questions where the content still has value. However, the answers on this question are actively maintained and a historical ...
PART I: How To Log In We'll assume you already know how to build a login+password HTML form which POSTs the values to a script on the server side for authentication. The sections below will deal with patterns for sound practical auth, and how to avoid the most common security pitfalls. To HTTPS or not to HTTPS? Unless ...
The definitive guide to form-based website authentication Moderator note: This question is not a good fit for our question and answer format with the topicality rules which currently apply for Stack Overflow. We normally use a "historical lock" for such questions where the content still has value. However, the answers ...
TITLE: The definitive guide to form-based website authentication QUESTION: Moderator note: This question is not a good fit for our question and answer format with the topicality rules which currently apply for Stack Overflow. We normally use a "historical lock" for such questions where the content still has value. How...
[ "forms", "http", "security", "authentication", "language-agnostic" ]
5,518
3,962
685,030
11
0
2008-08-02T19:51:50.250000
2009-01-25T11:27:46.093000
561
794
How to use combinations of sets as test data
I would like to test a function with a tuple from a set of fringe cases and normal values. For example, while testing a function which returns true whenever given three lengths that form a valid triangle, I would have specific cases, negative / small / large numbers, values close-to being overflowed, etc.; what is more...
Absolutely, especially dealing with lots of these permutations/combinations I can definitely see that the first pass would be an issue. Interesting implementation in python, though I wrote a nice one in C and Ocaml based on "Algorithm 515" (see below). He wrote his in Fortran as it was common back then for all the "Alg...
How to use combinations of sets as test data I would like to test a function with a tuple from a set of fringe cases and normal values. For example, while testing a function which returns true whenever given three lengths that form a valid triangle, I would have specific cases, negative / small / large numbers, values ...
TITLE: How to use combinations of sets as test data QUESTION: I would like to test a function with a tuple from a set of fringe cases and normal values. For example, while testing a function which returns true whenever given three lengths that form a valid triangle, I would have specific cases, negative / small / larg...
[ "unit-testing", "language-agnostic", "testing" ]
29
18
11,470
5
0
2008-08-02T21:34:24.223000
2008-08-03T19:06:00.327000
564
566
What is the difference between an int and an Integer in Java and C#?
I was reading More Joel on Software when I came across Joel Spolsky saying something about a particular type of programmer knowing the difference between an int and an Integer in Java/C# (Object-Oriented Programming Languages). So, what is the difference?
In Java, the 'int' type is a primitive, whereas the 'Integer' type is an object. In C#, the 'int' type is the same as System.Int32 and is a value type (ie more like the java 'int'). An integer (just like any other value types) can be boxed ("wrapped") into an object. The differences between objects and primitives are s...
What is the difference between an int and an Integer in Java and C#? I was reading More Joel on Software when I came across Joel Spolsky saying something about a particular type of programmer knowing the difference between an int and an Integer in Java/C# (Object-Oriented Programming Languages). So, what is the differe...
TITLE: What is the difference between an int and an Integer in Java and C#? QUESTION: I was reading More Joel on Software when I came across Joel Spolsky saying something about a particular type of programmer knowing the difference between an int and an Integer in Java/C# (Object-Oriented Programming Languages). So, w...
[ "c#", "java", "integer", "int" ]
271
252
249,050
26
0
2008-08-02T21:47:34.820000
2008-08-02T21:55:45.477000
580
586
Deploying SQL Server Databases from Test to Live
I wonder how you guys manage deployment of a database between 2 SQL Servers, specifically SQL Server 2005. Now, there is a development and a live one. As this should be part of a buildscript (standard windows batch, even do with current complexity of those scripts, i might switch to PowerShell or so later), Enterprise ...
I've taken to hand-coding all of my DDL (creates/alter/delete) statements, adding them to my.sln as text files, and using normal versioning (using subversion, but any revision control should work). This way, I not only get the benefit of versioning, but updating live from dev/stage is the same process for code and data...
Deploying SQL Server Databases from Test to Live I wonder how you guys manage deployment of a database between 2 SQL Servers, specifically SQL Server 2005. Now, there is a development and a live one. As this should be part of a buildscript (standard windows batch, even do with current complexity of those scripts, i mig...
TITLE: Deploying SQL Server Databases from Test to Live QUESTION: I wonder how you guys manage deployment of a database between 2 SQL Servers, specifically SQL Server 2005. Now, there is a development and a live one. As this should be part of a buildscript (standard windows batch, even do with current complexity of th...
[ "sql-server", "sql-server-2005", "deployment", "release-management" ]
30
19
8,360
14
0
2008-08-02T23:30:59.090000
2008-08-02T23:51:09.410000
588
633
Best way to access Exchange using PHP?
I'm writing a CMS application in PHP and one of the requirements is that it must be able to interface with the customer's Exchange server. I've written up this functionality a few times before and have always used WebDAV to do it, but now I'm leaning away from that. I will be running the site on IIS OR Apache (no prefe...
Update as of 2020: Over a decade since this question and things have moved on. Microsft now has a Rest API that will allow you to easily access this data. Original Answer I have not used PHP to do this but have experience in using C# to achieve the same thing. The Outlook API is a way of automating Outlook rather than ...
Best way to access Exchange using PHP? I'm writing a CMS application in PHP and one of the requirements is that it must be able to interface with the customer's Exchange server. I've written up this functionality a few times before and have always used WebDAV to do it, but now I'm leaning away from that. I will be runn...
TITLE: Best way to access Exchange using PHP? QUESTION: I'm writing a CMS application in PHP and one of the requirements is that it must be able to interface with the customer's Exchange server. I've written up this functionality a few times before and have always used WebDAV to do it, but now I'm leaning away from th...
[ "php", "windows", "exchange-server", "webdav", "mapi" ]
58
24
60,403
9
0
2008-08-03T00:03:58.510000
2008-08-03T07:50:37.617000
594
595
cx_Oracle: How do I iterate over a result set?
There are several ways to iterate over a result set. What are the tradeoff of each?
The canonical way is to use the built-in cursor iterator. curs.execute('select * from people') for row in curs: print row You can use fetchall() to get all rows at once. for row in curs.fetchall(): print row It can be convenient to use this to create a Python list containing the values returned: curs.execute('select fi...
cx_Oracle: How do I iterate over a result set? There are several ways to iterate over a result set. What are the tradeoff of each?
TITLE: cx_Oracle: How do I iterate over a result set? QUESTION: There are several ways to iterate over a result set. What are the tradeoff of each? ANSWER: The canonical way is to use the built-in cursor iterator. curs.execute('select * from people') for row in curs: print row You can use fetchall() to get all rows a...
[ "python", "sql", "database", "oracle", "cx-oracle" ]
55
56
60,015
3
0
2008-08-03T01:15:08.507000
2008-08-03T01:17:36.393000
601
602
Robust Random Number Generation
I'm looking for a performant, reasonably robust RNG using no special hardware. It can use mathematical methods (Mersenne Twister, etc), it can "collect entropy" from the machine, whatever. On Linux/etc we have a drand48() which generates 48 random bits. I'd like a similar function/class for C++ or C# which can generate...
For C++, Boost.Random is probably what you're looking for. It has support for MT (among many other algorithms), and can collect entropy via the nondet_random class. Check it out!:-)
Robust Random Number Generation I'm looking for a performant, reasonably robust RNG using no special hardware. It can use mathematical methods (Mersenne Twister, etc), it can "collect entropy" from the machine, whatever. On Linux/etc we have a drand48() which generates 48 random bits. I'd like a similar function/class ...
TITLE: Robust Random Number Generation QUESTION: I'm looking for a performant, reasonably robust RNG using no special hardware. It can use mathematical methods (Mersenne Twister, etc), it can "collect entropy" from the machine, whatever. On Linux/etc we have a drand48() which generates 48 random bits. I'd like a simil...
[ "c#", "c++", "random", "mersenne-twister" ]
42
31
2,145
5
0
2008-08-03T02:05:59.620000
2008-08-03T02:18:57.987000
622
623
Most efficient code for the first 10000 prime numbers?
I want to print the first 10000 prime numbers. Can anyone give me the most efficient code for this? Clarifications: It does not matter if your code is inefficient for n >10000. The size of the code does not matter. You cannot just hard code the values in any manner.
The Sieve of Atkin is probably what you're looking for, its upper bound running time is O(N/log log N). If you only run the numbers 1 more and 1 less than the multiples of 6, it could be even faster, as all prime numbers above 3 are 1 away from some multiple of six. Resource for my statement
Most efficient code for the first 10000 prime numbers? I want to print the first 10000 prime numbers. Can anyone give me the most efficient code for this? Clarifications: It does not matter if your code is inefficient for n >10000. The size of the code does not matter. You cannot just hard code the values in any manner...
TITLE: Most efficient code for the first 10000 prime numbers? QUESTION: I want to print the first 10000 prime numbers. Can anyone give me the most efficient code for this? Clarifications: It does not matter if your code is inefficient for n >10000. The size of the code does not matter. You cannot just hard code the va...
[ "performance", "algorithm", "primes" ]
65
50
72,844
31
0
2008-08-03T05:45:21.423000
2008-08-03T06:03:35.973000
626
723
When to use lambda, when to use Proc.new?
In Ruby 1.8, there are subtle differences between proc/lambda on the one hand, and Proc.new on the other. What are those differences? Can you give guidelines on how to decide which one to choose? In Ruby 1.9, proc and lambda are different. What's the deal?
Another important but subtle difference between procs created with lambda and procs created with Proc.new is how they handle the return statement: In a lambda -created proc, the return statement returns only from the proc itself In a Proc.new -created proc, the return statement is a little more surprising: it returns c...
When to use lambda, when to use Proc.new? In Ruby 1.8, there are subtle differences between proc/lambda on the one hand, and Proc.new on the other. What are those differences? Can you give guidelines on how to decide which one to choose? In Ruby 1.9, proc and lambda are different. What's the deal?
TITLE: When to use lambda, when to use Proc.new? QUESTION: In Ruby 1.8, there are subtle differences between proc/lambda on the one hand, and Proc.new on the other. What are those differences? Can you give guidelines on how to decide which one to choose? In Ruby 1.9, proc and lambda are different. What's the deal? AN...
[ "ruby", "lambda", "proc" ]
345
384
83,758
14
0
2008-08-03T06:40:54.120000
2008-08-03T15:21:52.760000
644
665
Swap unique indexed column values in database
I have a database table and one of the fields (not the primary key) is having a unique index on it. Now I want to swap values under this column for two rows. How could this be done? Two hacks I know are: Delete both rows and re-insert them. Update rows with some other value and swap and then update to actual value. But...
I think you should go for solution 2. There is no 'swap' function in any SQL variant I know of. If you need to do this regularly, I suggest solution 1, depending on how other parts of the software are using this data. You can have locking issues if you're not careful. But in short: there is no other solution than the o...
Swap unique indexed column values in database I have a database table and one of the fields (not the primary key) is having a unique index on it. Now I want to swap values under this column for two rows. How could this be done? Two hacks I know are: Delete both rows and re-insert them. Update rows with some other value...
TITLE: Swap unique indexed column values in database QUESTION: I have a database table and one of the fields (not the primary key) is having a unique index on it. Now I want to swap values under this column for two rows. How could this be done? Two hacks I know are: Delete both rows and re-insert them. Update rows wit...
[ "sql", "database" ]
73
17
19,618
12
0
2008-08-03T09:55:26.257000
2008-08-03T12:26:35.843000
650
655
Automatically update version number
I would like the version property of my application to be incremented for each build but I'm not sure on how to enable this functionality in Visual Studio (2005/2008). I have tried to specify the AssemblyVersion as 1.0.* but it doesn't get me exactly what I want. I'm also using a settings file and in earlier attempts w...
With the "Built in" stuff, you can't, as using 1.0.* or 1.0.0.* will replace the revision and build numbers with a coded date/timestamp, which is usually also a good way. For more info, see the Assembly Linker Documentation in the /v tag. As for automatically incrementing numbers, use the AssemblyInfo Task: AssemblyInf...
Automatically update version number I would like the version property of my application to be incremented for each build but I'm not sure on how to enable this functionality in Visual Studio (2005/2008). I have tried to specify the AssemblyVersion as 1.0.* but it doesn't get me exactly what I want. I'm also using a set...
TITLE: Automatically update version number QUESTION: I would like the version property of my application to be incremented for each build but I'm not sure on how to enable this functionality in Visual Studio (2005/2008). I have tried to specify the AssemblyVersion as 1.0.* but it doesn't get me exactly what I want. I'...
[ "c#", "visual-studio", "versioning" ]
115
99
83,634
8
0
2008-08-03T11:12:52.463000
2008-08-03T11:41:38.490000
651
725
Checklist for IIS 6/ASP.NET Windows Authentication?
I've been having trouble getting my ASP.NET application to automatically log users into the Intranet site I'm building. No matter the googling or the experimentation I applied, there is always a login box displayed by IE7. I've got Windows authentication mode set in the Web.config, disabled anonymous access and configu...
It sounds like you've covered all the server-side bases--maybe it's a client issue? I assume your users have integrated authentication enabled in IE7? (Tools -> Internet Options -> Advanced -> Security). This is enabled by default. Also, is your site correctly recognized by IE7 as being in the Local Intranet zone? The ...
Checklist for IIS 6/ASP.NET Windows Authentication? I've been having trouble getting my ASP.NET application to automatically log users into the Intranet site I'm building. No matter the googling or the experimentation I applied, there is always a login box displayed by IE7. I've got Windows authentication mode set in t...
TITLE: Checklist for IIS 6/ASP.NET Windows Authentication? QUESTION: I've been having trouble getting my ASP.NET application to automatically log users into the Intranet site I'm building. No matter the googling or the experimentation I applied, there is always a login box displayed by IE7. I've got Windows authentica...
[ "asp.net", "iis", "authentication", "active-directory" ]
34
20
6,880
3
0
2008-08-03T11:21:54.520000
2008-08-03T15:24:38.290000
657
669
Encrypting Passwords
What is the fastest, yet secure way to encrypt passwords (in PHP preferably), and for whichever method you choose, is it portable? In other words, if I later migrate my website to a different server, will my passwords continue to work? The method I am using now, as I was told, is dependent on the exact versions of the ...
If you are choosing an encryption method for your login system then speed is not your friend, Jeff had a to-and-frow with Thomas Ptacek about passwords and the conclusion was that you should use the slowest, most secure encryption method you can afford to. From Thomas Ptacek's blog: Speed is exactly what you don’t want...
Encrypting Passwords What is the fastest, yet secure way to encrypt passwords (in PHP preferably), and for whichever method you choose, is it portable? In other words, if I later migrate my website to a different server, will my passwords continue to work? The method I am using now, as I was told, is dependent on the e...
TITLE: Encrypting Passwords QUESTION: What is the fastest, yet secure way to encrypt passwords (in PHP preferably), and for whichever method you choose, is it portable? In other words, if I later migrate my website to a different server, will my passwords continue to work? The method I am using now, as I was told, is ...
[ "php", "encryption", "passwords" ]
38
33
6,243
8
0
2008-08-03T11:50:33.137000
2008-08-03T12:48:36.657000
683
57,833
Using 'in' to match an attribute of Python objects in an array
I don't remember whether I was dreaming or not but I seem to recall there being a function which allowed something like, foo in iter_attr(array of python objects, attribute name) I've looked over the docs but this kind of thing doesn't fall under any obvious listed headers
Using a list comprehension would build a temporary list, which could eat all your memory if the sequence being searched is large. Even if the sequence is not large, building the list means iterating over the whole of the sequence before in could start its search. The temporary list can be avoiding by using a generator ...
Using 'in' to match an attribute of Python objects in an array I don't remember whether I was dreaming or not but I seem to recall there being a function which allowed something like, foo in iter_attr(array of python objects, attribute name) I've looked over the docs but this kind of thing doesn't fall under any obviou...
TITLE: Using 'in' to match an attribute of Python objects in an array QUESTION: I don't remember whether I was dreaming or not but I seem to recall there being a function which allowed something like, foo in iter_attr(array of python objects, attribute name) I've looked over the docs but this kind of thing doesn't fal...
[ "python", "arrays", "iteration" ]
58
49
15,131
8
0
2008-08-03T13:19:16.983000
2008-09-11T22:42:14.047000
696
704
Connect PHP to IBM i (AS/400)
I've got an upcoming project wherein I will need to connect our website ( PHP5/Apache 1.3/OpenBSD 4.1 ) to our back-end system running on an iSeries with OS400 V5R3 so that I can access some tables stored there. I've done some checking around but am running into some roadblocks. From what I've seen the DB2 extensions a...
Have you looked at connecting to the server using unixODBC? If I remember correctly it has support for IBM DB2 and compiles on OpenBSD. Check out http://www.php.net/odbc for more information regarding the PHP side. If you can't get that to work, the option to setup a web service on a Linux server may be all you can do.
Connect PHP to IBM i (AS/400) I've got an upcoming project wherein I will need to connect our website ( PHP5/Apache 1.3/OpenBSD 4.1 ) to our back-end system running on an iSeries with OS400 V5R3 so that I can access some tables stored there. I've done some checking around but am running into some roadblocks. From what ...
TITLE: Connect PHP to IBM i (AS/400) QUESTION: I've got an upcoming project wherein I will need to connect our website ( PHP5/Apache 1.3/OpenBSD 4.1 ) to our back-end system running on an iSeries with OS400 V5R3 so that I can access some tables stored there. I've done some checking around but am running into some road...
[ "php", "database", "odbc", "db2", "ibm-midrange" ]
37
18
9,109
8
0
2008-08-03T14:03:28.830000
2008-08-03T14:39:09.710000
709
713
.NET testing framework advice
I'm looking to introduce a unit testing framework into the mix at my job. We're using Visual Studio 2005 (though we may be moving to 2008 within the next six months) and work primarily in C#. If the framework has some kind of IDE integration that would be best, but I'm open to frameworks that don't have integration but...
I think NUnit is your best bet. With TestDriven.NET, you get great integration within Visual Studio. (ReSharper also has a unit test runner if you're using it). NUnit is simple to use and follows an established paradigm. You'll also find plenty of projects, tutorials, and guides using it which always helps. Your other ...
.NET testing framework advice I'm looking to introduce a unit testing framework into the mix at my job. We're using Visual Studio 2005 (though we may be moving to 2008 within the next six months) and work primarily in C#. If the framework has some kind of IDE integration that would be best, but I'm open to frameworks t...
TITLE: .NET testing framework advice QUESTION: I'm looking to introduce a unit testing framework into the mix at my job. We're using Visual Studio 2005 (though we may be moving to 2008 within the next six months) and work primarily in C#. If the framework has some kind of IDE integration that would be best, but I'm op...
[ "c#", ".net", "visual-studio", "unit-testing", "nunit" ]
55
44
6,777
10
0
2008-08-03T14:53:53.550000
2008-08-03T14:59:20.993000
717
799
Why doesn't VFP .NET OLEdb provider work in 64 bit Windows?
I wrote a windows service using VB that read some legacy data from Visual Foxpro Databases to be inserted in SQL 2005. The problem is this use to run fine in Windows server 2003 32-Bits, but the client recently moved to Windows 2003 64-Bits and now the service won't work. I'm getting a message the the VFP.NET OLEdb pro...
Have you tried changing the target CPU to x86 instead of "Any CPU" in the advanced compiler options? I know that this solves some problems with other OLEDB providers by forcing the use of the 32-bit version.
Why doesn't VFP .NET OLEdb provider work in 64 bit Windows? I wrote a windows service using VB that read some legacy data from Visual Foxpro Databases to be inserted in SQL 2005. The problem is this use to run fine in Windows server 2003 32-Bits, but the client recently moved to Windows 2003 64-Bits and now the service...
TITLE: Why doesn't VFP .NET OLEdb provider work in 64 bit Windows? QUESTION: I wrote a windows service using VB that read some legacy data from Visual Foxpro Databases to be inserted in SQL 2005. The problem is this use to run fine in Windows server 2003 32-Bits, but the client recently moved to Windows 2003 64-Bits a...
[ ".net", "sql-server-2005", "oledb", "legacy", "visual-foxpro" ]
31
15
11,995
3
0
2008-08-03T15:07:10.073000
2008-08-03T19:42:03.687000
742
33,957
Class views in Django
Django view points to a function, which can be a problem if you want to change only a bit of functionality. Yes, I could have million keyword arguments and even more if statements in the function, but I was thinking more of an object oriented approach. For example, I have a page that displays a user. This page is very ...
I've created and used my own generic view classes, defining __call__ so an instance of the class is callable. I really like it; while Django's generic views allow some customization through keyword arguments, OO generic views (if their behavior is split into a number of separate methods) can have much more fine-grained...
Class views in Django Django view points to a function, which can be a problem if you want to change only a bit of functionality. Yes, I could have million keyword arguments and even more if statements in the function, but I was thinking more of an object oriented approach. For example, I have a page that displays a us...
TITLE: Class views in Django QUESTION: Django view points to a function, which can be a problem if you want to change only a bit of functionality. Yes, I could have million keyword arguments and even more if statements in the function, but I was thinking more of an object oriented approach. For example, I have a page ...
[ "python", "django", "view", "oop" ]
62
46
15,428
9
0
2008-08-03T15:55:28.633000
2008-08-29T04:29:22.053000
752
755
How to create a new object instance from a Type
One may not always know the Type of an object at compile-time, but may need to create an instance of the Type. How do you get a new object instance from a Type?
The Activator class within the root System namespace is pretty powerful. There are a lot of overloads for passing parameters to the constructor and such. Check out the documentation at: http://msdn.microsoft.com/en-us/library/system.activator.createinstance.aspx or (new path) https://learn.microsoft.com/en-us/dotnet/ap...
How to create a new object instance from a Type One may not always know the Type of an object at compile-time, but may need to create an instance of the Type. How do you get a new object instance from a Type?
TITLE: How to create a new object instance from a Type QUESTION: One may not always know the Type of an object at compile-time, but may need to create an instance of the Type. How do you get a new object instance from a Type? ANSWER: The Activator class within the root System namespace is pretty powerful. There are a...
[ "c#", ".net", "performance", "reflection", "types" ]
926
1,057
744,888
11
0
2008-08-03T16:29:03.607000
2008-08-03T16:35:34.233000
761
762
Localising date format descriptors
What is the best way to localise a date format descriptor? As anyone from a culture which does not use the mm/dd/yyyy format knows, it is annoying to have to enter dates in this format. The.NET framework provides some very good localisation support, so it's trivial to parse dates according to the users culture, but you...
Here is my current method. Any suggestions? Regex singleMToDoubleRegex = new Regex("(?
Localising date format descriptors What is the best way to localise a date format descriptor? As anyone from a culture which does not use the mm/dd/yyyy format knows, it is annoying to have to enter dates in this format. The.NET framework provides some very good localisation support, so it's trivial to parse dates acco...
TITLE: Localising date format descriptors QUESTION: What is the best way to localise a date format descriptor? As anyone from a culture which does not use the mm/dd/yyyy format knows, it is annoying to have to enter dates in this format. The.NET framework provides some very good localisation support, so it's trivial t...
[ ".net", "internationalization", "date", "globalization" ]
22
2
1,340
7
0
2008-08-03T17:30:20.473000
2008-08-03T17:31:31.313000
766
1,619
Python and MySQL
I can get Python to work with Postgresql but I cannot get it to work with MySQL. The main problem is that on the shared hosting account I have I do not have the ability to install things such as Django or PySQL, I generally fail when installing them on my computer so maybe it's good I can't install on the host. I found...
MySQLdb is what I have used before. If you host is using Python version 2.5 or higher, support for sqlite3 databases is built in (sqlite allows you to have a relational database that is simply a file in your filesystem). But buyer beware, sqlite is not suited for production, so it may depend what you are trying to do w...
Python and MySQL I can get Python to work with Postgresql but I cannot get it to work with MySQL. The main problem is that on the shared hosting account I have I do not have the ability to install things such as Django or PySQL, I generally fail when installing them on my computer so maybe it's good I can't install on ...
TITLE: Python and MySQL QUESTION: I can get Python to work with Postgresql but I cannot get it to work with MySQL. The main problem is that on the shared hosting account I have I do not have the ability to install things such as Django or PySQL, I generally fail when installing them on my computer so maybe it's good I...
[ "python", "mysql", "postgresql", "bpgsql" ]
45
27
4,434
6
0
2008-08-03T17:44:07.450000
2008-08-04T21:54:11.857000
769
781
Solving a linear equation
I need to programmatically solve a system of linear equations in C, Objective C, or (if needed) C++. Here's an example of the equations: -44.3940 = a * 50.0 + b * 37.0 + tx -45.3049 = a * 43.0 + b * 39.0 + tx -44.9594 = a * 52.0 + b * 41.0 + tx From this, I'd like to get the best approximation for a, b, and tx.
Cramer's Rule and Gaussian Elimination are two good, general-purpose algorithms (also see Simultaneous Linear Equations ). If you're looking for code, check out GiNaC, Maxima, and SymbolicC++ (depending on your licensing requirements, of course). EDIT: I know you're working in C land, but I also have to put in a good w...
Solving a linear equation I need to programmatically solve a system of linear equations in C, Objective C, or (if needed) C++. Here's an example of the equations: -44.3940 = a * 50.0 + b * 37.0 + tx -45.3049 = a * 43.0 + b * 39.0 + tx -44.9594 = a * 52.0 + b * 41.0 + tx From this, I'd like to get the best approximation...
TITLE: Solving a linear equation QUESTION: I need to programmatically solve a system of linear equations in C, Objective C, or (if needed) C++. Here's an example of the equations: -44.3940 = a * 50.0 + b * 37.0 + tx -45.3049 = a * 43.0 + b * 39.0 + tx -44.9594 = a * 52.0 + b * 41.0 + tx From this, I'd like to get the ...
[ "math", "linear-algebra", "system", "linear-equation" ]
48
20
45,885
11
0
2008-08-03T18:14:24.267000
2008-08-03T18:37:24.003000
773
7,286
How do I use itertools.groupby()?
I haven't been able to find an understandable explanation of how to actually use Python's itertools.groupby() function. What I'm trying to do is this: Take a list - in this case, the children of an objectified lxml element Divide it into groups based on some criteria Then later iterate over each of these groups separat...
IMPORTANT NOTE: You may have to sort your data first. The part I didn't get is that in the example construction groups = [] uniquekeys = [] for k, g in groupby(data, keyfunc): groups.append(list(g)) # Store group iterator as a list uniquekeys.append(k) k is the current grouping key, and g is an iterator that you can us...
How do I use itertools.groupby()? I haven't been able to find an understandable explanation of how to actually use Python's itertools.groupby() function. What I'm trying to do is this: Take a list - in this case, the children of an objectified lxml element Divide it into groups based on some criteria Then later iterate...
TITLE: How do I use itertools.groupby()? QUESTION: I haven't been able to find an understandable explanation of how to actually use Python's itertools.groupby() function. What I'm trying to do is this: Take a list - in this case, the children of an objectified lxml element Divide it into groups based on some criteria ...
[ "python", "python-itertools" ]
694
867
462,776
15
0
2008-08-03T18:27:09.687000
2008-08-10T18:45:32.430000
805
894
ASP, need to use SFTP
This is ASP classic, not.Net. We have to get a way to SFTP into a server to upload and download a couple of files, kicked off by a user. What have other people used to do SFTP in ASP classic? Not necessarily opposed to purchasing a control.
If you have the ability to use WScript.Shell then you can just execute pscp.exe from the Putty package. Obviously this is less then ideal but it will get the job done and let you use SCP/SFTP in classic ASP.
ASP, need to use SFTP This is ASP classic, not.Net. We have to get a way to SFTP into a server to upload and download a couple of files, kicked off by a user. What have other people used to do SFTP in ASP classic? Not necessarily opposed to purchasing a control.
TITLE: ASP, need to use SFTP QUESTION: This is ASP classic, not.Net. We have to get a way to SFTP into a server to upload and download a couple of files, kicked off by a user. What have other people used to do SFTP in ASP classic? Not necessarily opposed to purchasing a control. ANSWER: If you have the ability to use...
[ "asp-classic", "sftp" ]
17
8
2,854
6
0
2008-08-03T20:11:26.043000
2008-08-03T23:52:47.360000
810
820
Visual Studio Setup Project - Per User Registry Settings
I'm trying to maintain a Setup Project in Visual Studio 2003 (yes, it's a legacy application). The problem we have at the moment is that we need to write registry entries to HKCU for every user on the computer. They need to be in the HKCU rather than HKLM because they are the default user settings, and they do change p...
First: Yes, this is something that belongs in the Application for the exact reson you specified: What happens after new user profiles are created? Sure, if you're using a domain it's possible to have some stuff put in the registry on creation, but this is not really a use case. The Application should check if there are...
Visual Studio Setup Project - Per User Registry Settings I'm trying to maintain a Setup Project in Visual Studio 2003 (yes, it's a legacy application). The problem we have at the moment is that we need to write registry entries to HKCU for every user on the computer. They need to be in the HKCU rather than HKLM because...
TITLE: Visual Studio Setup Project - Per User Registry Settings QUESTION: I'm trying to maintain a Setup Project in Visual Studio 2003 (yes, it's a legacy application). The problem we have at the moment is that we need to write registry entries to HKCU for every user on the computer. They need to be in the HKCU rather...
[ "windows", "visual-studio", "registry", "installation" ]
21
6
7,824
4
0
2008-08-03T20:35:01.987000
2008-08-03T20:48:47.263000
826
97,294
Efficiently get sorted sums of a sorted list
You have an ascending list of numbers, what is the most efficient algorithm you can think of to get the ascending list of sums of every two numbers in that list. Duplicates in the resulting list are irrelevant, you can remove them or avoid them if you like. To be clear, I'm interested in the algorithm. Feel free to pos...
Edit as of 2018: You should probably stop reading this. (But I can't delete it as it is accepted.) If you write out the sums like this: 1 4 5 6 8 9 --------------- 2 5 6 7 9 10 8 9 10 12 13 10 11 13 14 12 14 15 16 17 18 You'll notice that since M[i,j] <= M[i,j+1] and M[i,j] <= M[i+1,j], then you only need to examine th...
Efficiently get sorted sums of a sorted list You have an ascending list of numbers, what is the most efficient algorithm you can think of to get the ascending list of sums of every two numbers in that list. Duplicates in the resulting list are irrelevant, you can remove them or avoid them if you like. To be clear, I'm ...
TITLE: Efficiently get sorted sums of a sorted list QUESTION: You have an ascending list of numbers, what is the most efficient algorithm you can think of to get the ascending list of sums of every two numbers in that list. Duplicates in the resulting list are irrelevant, you can remove them or avoid them if you like....
[ "algorithm", "language-agnostic" ]
20
13
4,508
8
0
2008-08-03T21:08:54.977000
2008-09-18T21:41:13.387000
832
837
How do I most elegantly express left join with aggregate SQL as LINQ query
SQL: SELECT u.id, u.name, isnull(MAX(h.dateCol), '1900-01-01') dateColWithDefault FROM universe u LEFT JOIN history h ON u.id=h.id AND h.dateCol
A solution, albeit one that defers handling of the null value to the code, could be: DateTime yesterday = DateTime.Now.Date.AddDays(-1); var collection= from u in db.Universe select new { u.id, u.name, MaxDate =(DateTime?) ( from h in db.History where u.Id == h.Id && h.dateCol < yesterday select h.dateCol ).Max() }; Th...
How do I most elegantly express left join with aggregate SQL as LINQ query SQL: SELECT u.id, u.name, isnull(MAX(h.dateCol), '1900-01-01') dateColWithDefault FROM universe u LEFT JOIN history h ON u.id=h.id AND h.dateCol
TITLE: How do I most elegantly express left join with aggregate SQL as LINQ query QUESTION: SQL: SELECT u.id, u.name, isnull(MAX(h.dateCol), '1900-01-01') dateColWithDefault FROM universe u LEFT JOIN history h ON u.id=h.id AND h.dateCol ANSWER: A solution, albeit one that defers handling of the null value to the code...
[ "c#", "linq", "left-join" ]
24
10
1,912
4
0
2008-08-03T21:22:52.717000
2008-08-03T21:31:17.863000
833
838
Editing database records by multiple users
I have designed database tables (normalised, on an MS SQL server) and created a standalone windows front end for an application that will be used by a handful of users to add and edit information. We will add a web interface to allow searching accross our production area at a later date. I am concerned that if two user...
If you expect infrequent collisions, Optimistic Concurrency is probably your best bet. Scott Mitchell wrote a comprehensive tutorial on implementing that pattern: Implementing Optimistic Concurrency
Editing database records by multiple users I have designed database tables (normalised, on an MS SQL server) and created a standalone windows front end for an application that will be used by a handful of users to add and edit information. We will add a web interface to allow searching accross our production area at a ...
TITLE: Editing database records by multiple users QUESTION: I have designed database tables (normalised, on an MS SQL server) and created a standalone windows front end for an application that will be used by a handful of users to add and edit information. We will add a web interface to allow searching accross our pro...
[ "sql-server", "database" ]
34
16
28,606
8
0
2008-08-03T21:23:41.077000
2008-08-03T21:31:40.187000
835
1,023
CruiseControl.net, msbuild, /p:OutputPath and CCNetArtifactDirectory
I'm trying to setup CruiseControl.net at the moment. So far it works nice, but I have a Problem with the MSBuild Task. According to the Documentation, it passes CCNetArtifactDirectory to MSBuild. But how do I use it? I tried this: /noconsolelogger /p:OutputPath=$(CCNetArtifactDirectory)\test But that does not work. In ...
The CCNetArtifactDirectory is passed to the MSBuild by default, so you dont need to worry about it. MSBuild will place the build output in the "bin location" relevant to the working directory that you have specified. c:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe C:\data\projects\FooSolution\ FooSolution.sln /noco...
CruiseControl.net, msbuild, /p:OutputPath and CCNetArtifactDirectory I'm trying to setup CruiseControl.net at the moment. So far it works nice, but I have a Problem with the MSBuild Task. According to the Documentation, it passes CCNetArtifactDirectory to MSBuild. But how do I use it? I tried this: /noconsolelogger /p:...
TITLE: CruiseControl.net, msbuild, /p:OutputPath and CCNetArtifactDirectory QUESTION: I'm trying to setup CruiseControl.net at the moment. So far it works nice, but I have a Problem with the MSBuild Task. According to the Documentation, it passes CCNetArtifactDirectory to MSBuild. But how do I use it? I tried this: /n...
[ "msbuild", "cruisecontrol.net" ]
17
6
6,616
3
0
2008-08-03T21:25:09.763000
2008-08-04T04:45:12.497000
845
849
How to detect which one of the defined font was used in a web page?
Suppose I have the following CSS rule in my page: body { font-family: Calibri, Trebuchet MS, Helvetica, sans-serif; } How could I detect which one of the defined fonts were used in the user's browser? For people wondering why I want to do this is because the font I'm detecting contains glyphs that are not available in ...
I've seen it done in a kind of iffy, but pretty reliable way. Basically, an element is set to use a specific font and a string is set to that element. If the font set for the element does not exist, it takes the font of the parent element. So, what they do is measure the width of the rendered string. If it matches what...
How to detect which one of the defined font was used in a web page? Suppose I have the following CSS rule in my page: body { font-family: Calibri, Trebuchet MS, Helvetica, sans-serif; } How could I detect which one of the defined fonts were used in the user's browser? For people wondering why I want to do this is becau...
TITLE: How to detect which one of the defined font was used in a web page? QUESTION: Suppose I have the following CSS rule in my page: body { font-family: Calibri, Trebuchet MS, Helvetica, sans-serif; } How could I detect which one of the defined fonts were used in the user's browser? For people wondering why I want t...
[ "javascript", "html", "css", "fonts" ]
157
82
55,224
10
0
2008-08-03T21:42:37.903000
2008-08-03T21:51:44.360000
855
858
.Net XML comment into API Documentation
Is there an easy way to produce MSDN-style documentation from the Visual Studio XML output? I'm not patient enough to set up a good xslt for it because I know I'm not the first person to cross this bridge. Also, I tried setting up sandcastle recently, but it really made my eyes cross. Either I was missing something imp...
You're looking for Sandcastle Project Page: Sandcastle Releases Blog: Sandcastle Blog NDoc Code Documentation Generator for.NET used to be the tool of choice, but support has all but stopped.
.Net XML comment into API Documentation Is there an easy way to produce MSDN-style documentation from the Visual Studio XML output? I'm not patient enough to set up a good xslt for it because I know I'm not the first person to cross this bridge. Also, I tried setting up sandcastle recently, but it really made my eyes c...
TITLE: .Net XML comment into API Documentation QUESTION: Is there an easy way to produce MSDN-style documentation from the Visual Studio XML output? I'm not patient enough to set up a good xslt for it because I know I'm not the first person to cross this bridge. Also, I tried setting up sandcastle recently, but it rea...
[ "visual-studio", "xslt", "documentation", "sandcastle", "xml-comments" ]
21
12
3,497
6
0
2008-08-03T22:03:37.567000
2008-08-03T22:12:52.820000
871
875
Why is Git better than Subversion?
I've been using Subversion for a few years and after using SourceSafe, I just love Subversion. Combined with TortoiseSVN, I can't really imagine how it could be any better. Yet there's a growing number of developers claiming that Subversion has problems and that we should be moving to the new breed of distributed versi...
Git is not better than Subversion. But is also not worse. It's different. The key difference is that it is decentralized. Imagine you are a developer on the road, you develop on your laptop and you want to have source control so that you can go back 3 hours. With Subversion, you have a Problem: The SVN Repository may b...
Why is Git better than Subversion? I've been using Subversion for a few years and after using SourceSafe, I just love Subversion. Combined with TortoiseSVN, I can't really imagine how it could be any better. Yet there's a growing number of developers claiming that Subversion has problems and that we should be moving to...
TITLE: Why is Git better than Subversion? QUESTION: I've been using Subversion for a few years and after using SourceSafe, I just love Subversion. Combined with TortoiseSVN, I can't really imagine how it could be any better. Yet there's a growing number of developers claiming that Subversion has problems and that we s...
[ "svn", "git" ]
393
547
925,767
30
0
2008-08-03T22:38:29.040000
2008-08-03T22:45:44.533000
879
885
Are PHP Variables passed by value or by reference?
Are PHP variables passed by value or by reference?
It's by value according to the PHP Documentation. By default, function arguments are passed by value (so that if the value of the argument within the function is changed, it does not get changed outside of the function). To allow a function to modify its arguments, they must be passed by reference. To have an argument ...
Are PHP Variables passed by value or by reference? Are PHP variables passed by value or by reference?
TITLE: Are PHP Variables passed by value or by reference? QUESTION: Are PHP variables passed by value or by reference? ANSWER: It's by value according to the PHP Documentation. By default, function arguments are passed by value (so that if the value of the argument within the function is changed, it does not get chan...
[ "php", "variables", "pass-by-reference", "pass-by-value" ]
314
377
223,799
16
0
2008-08-03T22:51:41.447000
2008-08-03T23:06:56.423000
888
890
How do you debug PHP scripts?
How do you debug PHP scripts? I am aware of basic debugging such as using the Error Reporting. The breakpoint debugging in PHPEclipse is also quite useful. What is the best (in terms of fast and easy) way to debug in phpStorm or any other IDE?
Try Eclipse PDT to setup an Eclipse environment that has debugging features like you mentioned. The ability to step into the code is a much better way to debug then the old method of var_dump and print at various points to see where your flow goes wrong. When all else fails though and all I have is SSH and vim I still ...
How do you debug PHP scripts? How do you debug PHP scripts? I am aware of basic debugging such as using the Error Reporting. The breakpoint debugging in PHPEclipse is also quite useful. What is the best (in terms of fast and easy) way to debug in phpStorm or any other IDE?
TITLE: How do you debug PHP scripts? QUESTION: How do you debug PHP scripts? I am aware of basic debugging such as using the Error Reporting. The breakpoint debugging in PHPEclipse is also quite useful. What is the best (in terms of fast and easy) way to debug in phpStorm or any other IDE? ANSWER: Try Eclipse PDT to ...
[ "php", "eclipse", "debugging", "phpstorm", "xdebug" ]
402
145
357,674
30
0
2008-08-03T23:18:21.627000
2008-08-03T23:28:39.890000
904
911
How to break word after special character like Hyphens (-)
Given a relatively simple CSS: div { width: 150px; } 12333-2333-233-23339392-332332323 How do I make it so that the string stays constrained to the width of 150, and wraps to a new line on the hyphen?
Replace your hyphens with this: ­ It's called a "soft" hyphen. div { width: 150px; } 12333­2333­233­23339392­332332323
How to break word after special character like Hyphens (-) Given a relatively simple CSS: div { width: 150px; } 12333-2333-233-23339392-332332323 How do I make it so that the string stays constrained to the width of 150, and wraps to a new line on the hyphen?
TITLE: How to break word after special character like Hyphens (-) QUESTION: Given a relatively simple CSS: div { width: 150px; } 12333-2333-233-23339392-332332323 How do I make it so that the string stays constrained to the width of 150, and wraps to a new line on the hyphen? ANSWER: Replace your hyphens with this:...
[ "html", "css", "text" ]
79
75
22,538
11
0
2008-08-04T00:17:34.690000
2008-08-04T00:25:11.227000
905
942
Client collation and SQL Server 2005
We're upgrading an existing program from Win2k/SQL Server 2k to Windows 2003 and SQL Server 2005 as well as purchasing a new program that also uses 2k3/2k5. The vendor says that for us to host both databases we need to get the Enterprise version because the softwares clients use different collation for the connections ...
All editions of SQL Server 2000/2005/2008 support having multiple databases, each using their own collation sequence. You don't need the Enterprise version. When you have a database that uses a collation sequence that is different from default collation for the database server, you will need to take some extra precauti...
Client collation and SQL Server 2005 We're upgrading an existing program from Win2k/SQL Server 2k to Windows 2003 and SQL Server 2005 as well as purchasing a new program that also uses 2k3/2k5. The vendor says that for us to host both databases we need to get the Enterprise version because the softwares clients use dif...
TITLE: Client collation and SQL Server 2005 QUESTION: We're upgrading an existing program from Win2k/SQL Server 2k to Windows 2003 and SQL Server 2005 as well as purchasing a new program that also uses 2k3/2k5. The vendor says that for us to host both databases we need to get the Enterprise version because the softwar...
[ "sql-server", "sql-server-2005", "windows-server-2003" ]
15
7
868
1
0
2008-08-04T00:17:55.767000
2008-08-04T01:13:06.247000
930
951
How do I connect to a database and loop over a recordset in C#?
What's the simplest way to connect and query a database for a set of records in C#?
@Goyuix -- that's excellent for something written from memory. tested it here -- found the connection wasn't opened. Otherwise very nice. using System.Data.OleDb;... using (OleDbConnection conn = new OleDbConnection()) { conn.ConnectionString = "Provider=sqloledb;Data Source=yourServername\\yourInstance;Initial Catalo...
How do I connect to a database and loop over a recordset in C#? What's the simplest way to connect and query a database for a set of records in C#?
TITLE: How do I connect to a database and loop over a recordset in C#? QUESTION: What's the simplest way to connect and query a database for a set of records in C#? ANSWER: @Goyuix -- that's excellent for something written from memory. tested it here -- found the connection wasn't opened. Otherwise very nice. using S...
[ "c#", "database", "loops", "connection" ]
49
35
32,655
8
0
2008-08-04T00:47:25.143000
2008-08-04T01:31:31.157000
935
938
String literals and escape characters in postgresql
Attempting to insert an escape character into a table results in a warning. For example: create table EscapeTest (text varchar(50)); insert into EscapeTest (text) values ('This is the first part \n And this is the second'); Produces the warning: WARNING: nonstandard use of escape in a string literal ( Using PSQL 8.2 )...
Partially. The text is inserted, but the warning is still generated. I found a discussion that indicated the text needed to be preceded with 'E', as such: insert into EscapeTest (text) values (E'This is the first part \n And this is the second'); This suppressed the warning, but the text was still not being returned co...
String literals and escape characters in postgresql Attempting to insert an escape character into a table results in a warning. For example: create table EscapeTest (text varchar(50)); insert into EscapeTest (text) values ('This is the first part \n And this is the second'); Produces the warning: WARNING: nonstandard ...
TITLE: String literals and escape characters in postgresql QUESTION: Attempting to insert an escape character into a table results in a warning. For example: create table EscapeTest (text varchar(50)); insert into EscapeTest (text) values ('This is the first part \n And this is the second'); Produces the warning: WAR...
[ "string", "postgresql", "escaping" ]
142
158
383,391
5
0
2008-08-04T01:00:24.837000
2008-08-04T01:07:03.233000
944
1,016
Unhandled Exception Handler in .NET 1.1
I'm maintaining a.NET 1.1 application and one of the things I've been tasked with is making sure the user doesn't see any unfriendly error notifications. I've added handlers to Application.ThreadException and AppDomain.CurrentDomain.UnhandledException, which do get called. My problem is that the standard CLR error dial...
Oh, in Windows Forms you definitely should be able to get it to work. The only thing you have to watch out for is things happening on different threads. I have an old Code Project article here which should help: User Friendly Exception Handling
Unhandled Exception Handler in .NET 1.1 I'm maintaining a.NET 1.1 application and one of the things I've been tasked with is making sure the user doesn't see any unfriendly error notifications. I've added handlers to Application.ThreadException and AppDomain.CurrentDomain.UnhandledException, which do get called. My pro...
TITLE: Unhandled Exception Handler in .NET 1.1 QUESTION: I'm maintaining a.NET 1.1 application and one of the things I've been tasked with is making sure the user doesn't see any unfriendly error notifications. I've added handlers to Application.ThreadException and AppDomain.CurrentDomain.UnhandledException, which do ...
[ "c#", ".net", "exception" ]
31
13
5,152
6
0
2008-08-04T01:15:38.067000
2008-08-04T04:31:02.557000
947
1,028
How to use a mutex in Visual Basic
I have imported the kernel32 library. So, I have the createMutex function available but I am not quite sure of the various parameters and return values. This is classic Visual Basic, not Visual Basic.NET but I can probably work with either language in the form of an answer.
The VB code looks something like this: hMutex = CreateMutex(ByVal 0&, 1, ByVal 0&) The first parameter is a pointer to an SECURITY_ATTRIBUTES structure. If you don't know what it is, you don't need it. Pass NULL (0). The second parameter is TRUE (non-zero, or 1) if the calling thread should take ownership of the mutex....
How to use a mutex in Visual Basic I have imported the kernel32 library. So, I have the createMutex function available but I am not quite sure of the various parameters and return values. This is classic Visual Basic, not Visual Basic.NET but I can probably work with either language in the form of an answer.
TITLE: How to use a mutex in Visual Basic QUESTION: I have imported the kernel32 library. So, I have the createMutex function available but I am not quite sure of the various parameters and return values. This is classic Visual Basic, not Visual Basic.NET but I can probably work with either language in the form of an ...
[ "vb6", "mutex" ]
27
8
9,182
3
0
2008-08-04T01:22:49.830000
2008-08-04T04:58:40.300000
972
2,982
Adding a method to an existing object instance in Python
How do I add a method to an existing object (i.e., not in the class definition) in Python? I understand that it's not generally considered good practice to do so, except in some cases.
In Python, there is a difference between functions and bound methods. >>> def foo():... print "foo"... >>> class A:... def bar( self ):... print "bar"... >>> a = A() >>> foo >>> a.bar > >>> Bound methods have been "bound" (how descriptive) to an instance, and that instance will be passed as the first argument whenever ...
Adding a method to an existing object instance in Python How do I add a method to an existing object (i.e., not in the class definition) in Python? I understand that it's not generally considered good practice to do so, except in some cases.
TITLE: Adding a method to an existing object instance in Python QUESTION: How do I add a method to an existing object (i.e., not in the class definition) in Python? I understand that it's not generally considered good practice to do so, except in some cases. ANSWER: In Python, there is a difference between functions ...
[ "python", "oop", "methods", "monkeypatching" ]
855
1,171
385,254
19
0
2008-08-04T02:17:51.780000
2008-08-06T00:33:35.063000