instruction stringlengths 0 30k ⌀ |
|---|
If you're using SQL Server, there's the HashBytes function:
[http://msdn.microsoft.com/en-us/library/ms174415.aspx][1]
[1]: http://msdn.microsoft.com/en-us/library/ms174415.aspx |
Register file extensions / mime types in Linux |
|mime|file-type|freedesktop|linux|installation| |
I'm developing a Linux application that has its own file format. I want my app to open when you double-click on those files.
How can I register a file extension and associate it with my application on Linux? I'm looking for a way that that is standard (works with GNOME and KDE based systems) and can be done automati... |
|linux|installation|mime|file-type| |
This is the web service to call.
http://developer.yahoo.com/search/local/V2/localSearch.html
This site has ok web services, but not exactly what you're asking for here.
http://www.usps.com/webtools/ |
I second the vote for MD5 or SHA with a salt. Any of the major web development languages have functions built-in for computing the hash (in PHP, for example, the mcrypt package contains the necessary functions). |
Regex to validate URIs |
|regex|.net| |
How do you produce a regex that matches only valid URI. The description for URIs can be found here: http://en.wikipedia.org/wiki/URI_scheme. It doesn't need to extract any parts, just test if a URI is valid.
(preferred format is .Net RegularExpression) |
How do you produce a regex that matches only valid URI. The description for URIs can be found here: http://en.wikipedia.org/wiki/URI_scheme. It doesn't need to extract any parts, just test if a URI is valid.
(preferred format is .Net RegularExpression) (.Net Version 1.1)
- Doesn't neet to check for a known proto... |
|.net|regex| |
How do you produce a regex that matches only valid URI. The description for URIs can be found here: http://en.wikipedia.org/wiki/URI_scheme. It doesn't need to extract any parts, just test if a URI is valid.
(preferred format is .Net RegularExpression) (.Net Version 1.1)
- Doesn't neet to check for a known proto... |
Is it really that bad to catch a general exception? |
|exception| |
Whilst analysing some legacy code with FXCop, it occurred to me is it really that bad to catch a general exception error within a try block or should you be looking for a specific exception. Thoughts on a postcard please. |
Well, I don't seen any difference between catching a general exception or a specific one, except that when having multiple catch blocks, you can react differently depending on what the exception is.
You will catch both IOException and NullPointerException with a generic Exception, but the way you program should reac... |
I think a good guideline is to catch only specific exceptions from within a framework (so that the host application can deal with edge cases like the disk filling up etc), but I don't see why we shouldn't be able to catch all exceptions from our application code. Quite simply there are times where you don't want the ap... |
Most of the time catching a general exception is not needed. Of course there are situations where you don't have a choice, but in this case I think it's better to check why you need to catch it. Maybe there's something wrong in your design. |
Unless you are doing some logging and clean up code in the front end of your application, then I think it is bad to catch all exceptions.
My basic rule of thumb is to catch all the exceptions you expect and anything else is a bug.
If you catch everything and continue on, it's a bit like putting a sticking plaster... |
The point is twofold I think.
Firstly, if you don't know what exception has occurred how can you hope to recover from it. If you expect that a user might type a filename in wrong then you can expect a FileNotFoundException and tell the user to try again. If that same code generated a NullReferenceException and you s... |
Obviously this is one of those questions where the only real answer is "it depends."
The main thing it depends on is where your are catching the exception. In general libraries should be more conservative with catching exceptions whereas at the top level of your program (e.g. in your main method or in the top of th... |
The *args and **kwargs ist a common idiom to allow arbitrary number of arguments to functions as described in the section [more on defining functions][1] in the the python documentation.
The *args will give you all funtion parameters a a list:
In [1]: def foo(*args):
...: for a in args:
.... |
The *args and **kwargs ist a common idiom to allow arbitrary number of arguments to functions as described in the section [more on defining functions][1] in the the python documentation.
The *args will give you all funtion parameters a a list:
In [1]: def foo(*args):
...: for a in args:
.... |
The *args and **kwargs ist a common idiom to allow arbitrary number of arguments to functions as described in the section [more on defining functions][1] in the the python documentation.
The *args will give you all funtion parameters a a list:
In [1]: def foo(*args):
...: for a in args:
.... |
One thing I would suggest ensure your build script (and installer project, if relevant in your case) is in source control. I tend to have a very simple script that just checks out\gets latest the "main" build script then launches it.
I say this b/c I see teams just running the latest version of the build script o... |
In most languages with decent optimization the former will work just fine. |
Calculating Distance Between 2 Cities |
|algorithm| |
How do you calculate the distance between 2 cities? |
|algorithm|mathematics|geography| |
|algorithm|mathematics|geography|trigonometry| |
|algorithm|mathematics|geography|trigonometry| |
|algorithm|math|trigonometry|geography| |
Easiest way for me to illustrate is using in-memory objects so it's clear what's happening. LINQ to SQL should be able to take that same LINQ query and translate it into appropriate SQL.
public class Site
{
static void Main()
{
List<Site> sites = new List<Site>()
... |
To determine what tags apply to a particular file use:
cvs log <filename>
This will output all the versions of the file and what tags have been applied to the version.
To determine what files are included in a single tag, the only thing I can think of is to check out using the tag and see what files come b... |
BODMAS |
|maths| |
What is BODMAS and why is it useful in programming? |
JavaScript and Threads |
|javascript| |
Is there some way to do multi-threading in JavaScript? |
|javascript|multithreading| |
@Mike: this kind of thinking makes me nervous. I've heard to many times "this should be infinitely portable", but when the question is asked: do you actually foresee that there will be any porting? the answer is: no.
Sticking to the lowest common denominator can really hurt performance, as can the introduction of ab... |
Can the same Adobe AIR app run more than once? |
|javascript|air|adobe| |
As the title says, is there a way to run the same Adobe AIR app more than once? I have a little widget I wrote that shows thumbnails from a couple of photo streams, and I'd like to fix it so I can look at more than one stream at a time. Thanks! |
I think Jeff complained about this recently. One common technique is to drag all the objects into the designer again...
I hope someone else chimes in with a better approach! |
How to find a normal vector pointing directly from virtual world to screen in Java3D? |
|java|graphics|java-3d| |
I think it can be done by applying the transformation matrix of the scenegraph to z-normal (0, 0, 1), but it doesn't work. My code goes like this:
Vector3f toScreenVector = new Vector3f(0, 0, 1);
Transform3D t3d = new Transform3D();
tg.getTransform(t3d); //tg is Transform Group of all objects in a scen... |
Theoretically, no, they are not unique. It's possible to generate an identical guid over and over. However, the chances of it happening are so low that you can assume they are unique.
I've read before that the chances are so low that you really should stress about something else--like your server spontaneously combu... |
I have a few lines of PowerShell code that I would like to use as an automated script. The way I would like it to be able to work is to be able to call it using one of the following options:
1. One command line that opens PowerShell, executes script and closes PowerShell (this would be used for a global build-rout... |
Set up PowerShell Script for Automatic Execution |
|command-line|scripting|powershell| |
Save your script as a .ps1 file and launch it using powershell.exe, like this:
powershell.exe .\foo.ps1
Make sure you specify the full path to the script, and make sure you have set your execution policy level to at least "RemoteSigned" so that unsigned local scripts can be run. |
Database - since you mentioned multiple threads. Synchronization as well as filtered retrieval are my reasons for my answer.
See if you have a performance problem before deciding to switch to files
*"Knuth: Premature optimization is the root of all evil" I didn't get any further in that book... :)* |
There are ways you can work around the limitations of file logging.
You can always start each log entry with a thread id of some kind, and grep out the individual thread ids. Or a different log file for each thread.
I've logged to database in the past, in a separate thread at a lower priority. I must say, que... |
Most of the memory overhead will come from the opcode cache size. Each opcode cacher has their own default(e.g. 30MB for APC) which you can change through the config file.
|
Most of the memory overhead will come from the opcode cache size. Each opcode cacher has their own default(e.g. 30MB for APC) which you can change through the config file.
Other than the cache size, the actual memory overhead of the cacher itself is negligible. |
I second the other answers here, **depends on what you are doing with the data**.
We have two scenarios here:
1. The majority of the logging is to a DB since admin users for the products we build need to be able to view them in their nice little app with all the bells and whistles.
2. We log all of our diagnos... |
How about logging to database-file, say a SQLite database? I think it can handle multi-threaded writes - although that may also have its own performance overheads. |
WinForms databinding and foreign key relationships |
If you can use some inline assembler and do the following (psuedo assembler):
PUSH A
A=B
POP B
You will save a lot of parameter passing and stack fix up code etc.
|
To help facilitate understanding of closures it might be useful to examine how they might be implemented in a procedural language. This explanation will follow a simplistic implementation of closures in Scheme.
To start, I must introduce the concept of a namespace. When you enter a command into a Scheme interpreter,... |
To help facilitate understanding of closures it might be useful to examine how they might be implemented in a procedural language. This explanation will follow a simplistic implementation of closures in Scheme.
To start, I must introduce the concept of a namespace. When you enter a command into a Scheme interpreter,... |
Yes! (except at the "top" of your application)
By catching an exception and allowing the code execution to continue, you are stating that you know how do deal with and circumvent, or fix a particular problem. You are stating that this is **a recoverable situation**. Catching Exception or SystemException means that y... |
How do I compare two arrays of DataRow objects in PowerShell? |
|arrays|powershell|comparison| |
I have two arrays of System.Data.DataRow objects which I want to compare. The rows have two columns A and B. Column A is a key and I want to find out which rows have had their B column changed and which rows have been added or deleted. How do I do this in PowerShell? |
Just a quick update on this, I have not forgotten!
Just doing some more research, looks like I am on to a winner, just need to get the code sorted.
So far, I have the following:
* The _XmlSeralizer_ is basically a class that does some nifty reflection on the classes it is serializing. It determines the propert... |
In my opinion you should catch all exceptions you **expect**, but this rule applies to anything but your interface logic. All the way down the call stack you should probably create a way to catch all exceptions, do some logging/give user feedback and, if needed and possible, shut down gracefully.
Nothing is worse th... |
Why does this python date/time conversion seem wrong? |
|python|datetime| |
>>> import time
>>> time.strptime("01-31-2009", "%m-%d-%Y")
(2009, 1, 31, 0, 0, 0, 5, 31, -1)
>>> time.mktime((2009, 1, 31, 0, 0, 0, 5, 31, -1))
1233378000.0
>>> 60*60*24 # seconds in a day
86400
>>> 1233378000.0 / 86400
14275.208333333334
time.mktime should return the num... |
Keep to the ideal of inbox zero in the actual inbox, then employ a decent search engine (Google Desktop or Xobni for example).
I have a handful of project- or filter-specific folders (e.g. for system generated status messages that go to a mailing list), but generally all archived email is dumped in one folder.
... |
My book recommendations:
**Essential C++** (Lippman)
**C++ Common Knowledge: Essential Intermediate Programming** (Dewhurst)
...and I second the **Effective C++** suggestion above.
A very handy alternative to buying books in meatspace is to subscribe to a service like [Safari Books Online][1]. For a not u... |
I strongly suggest using [VideoInput lib][1], it supports any DirectShow device (even multiple devices at the same time) and is more configurable. You'll spend five minutes make it play with OpenCV.
[1]: http://muonics.net/school/spring05/videoInput/ |
I don't think its possible to limit the number of words returned, however to limit the number of chars returned you could do something like
SELECT SUBSTRING(field_name, LOCATE('keyword', field_name) - chars_before, total_chars) FROM table_name WHERE field_name LIKE "%keyword%"
- chars_before - is the number... |
Change the message: just provide the primary key and the current date, not the key/value pairs. Your mdb fetches the entity by primary key and calls index(). After indexing you set a value "updated" in your index to the message date. You update your index only if the message date is after the "updated" field of the ind... |
A good starting place is "Thinking in C++" by Bruce Eckel, I've rarely had anyone complain about the book. Well written and also has a version available online. |
Determine if a ruby script is already running |
|ruby| |
Is there an easy way to tell if a ruby script is already running and then handle it appropriately? For example: I have a script called really_long_script.rb. I have it cronned to run every 5 minutes. When it runs, I want to see if the previous run is still running and then stop the execution of the second script. ... |
You can also [Uuencode][1] you original binary data. This format is a bit older but it does the same thing as base63 encoding.
[1]: http://en.wikipedia.org/wiki/Uuencode |
The recommendations for the accepted answer are a little out of date now.
- The windows forms implementation is pretty good now. (See [Paint-Mono][1] for a port of Paint.net which is a pretty involved Windows forms application. All that was required was an emulation layer for some of the P-Invoke and unsupported... |
Unless the data is truely random with a symmetric 1/0 distribution, this simply becomes a lossless data compression problem and is very analogous to CCITT Group 3 compression used for black and white (ie: Binary) FAX images. CCITT Group 3 uses a Huffman Coding scheme. In the case of FAX they are using a fixed set of Hu... |
Unless the data is truely random ***and*** has a symmetric 1/0 distribution, then this simply becomes a lossless data compression problem and is very analogous to CCITT Group 3 compression used for black and white (ie: Binary) FAX images. CCITT Group 3 uses a Huffman Coding scheme. In the case of FAX they are using a f... |
Unless the data is truely random ***and*** has a symmetric 1/0 distribution, then this simply becomes a lossless data compression problem and is very analogous to CCITT Group 3 compression used for black and white (ie: Binary) FAX images. CCITT Group 3 uses a Huffman Coding scheme. In the case of FAX they are using a f... |
|math| |
Since reddit's ranking algorithm rocks, it makes very much sense to have a look at it, if not copying it:
![alt text][1]
[1]: http://redflavor.com/reddit.cf.algorithm.png |
Since reddit's ranking algorithm rocks, it makes very much sense to have a look at it, if not copy it:
![alt text][1]
[1]: http://redflavor.com/reddit.cf.algorithm.png |
If all prisoners are killed when someone fails to find their number then you either save 100 or 0. There is no way to save 30 people. |
I've seen a lot of these types of questions lately--optimization to the nth degree.
I think it makes sense in certain circumstances:
1. Computing condition 2 is not a constant time operation
2. You are asking strictly for educational purposes--you want to know how the language works, not to save 3us.
In o... |
According to [this article][1] PHP does short circuit evaluation, which means that if the first condition is met the second is not even evaluated.
It's quite easy to test also (from the article):
<?php
/* ch06ex07 – shows no output because of short circuit evaluation */
if (true || $intVal = 5) ... |
You could iterate over the entire Workbook using vba:
Sub iterateOverWorkbook()
For Each i In Sheets
i.Select
Cells.Select
For Each j In Selection
If (j.Formula <> "") Then
j.Value = Replace(j.Formula, "INDIRECT(D4)", "INDIRECT(C4)")
... |
You could iterate over the entire Workbook using vba (i've included the code from @PabloG and @euro-micelli ):
Sub iterateOverWorkbook()
For Each i In ThisWorkbook.Worksheets
Set rRng = i.UsedRange
For Each j In rRng
If (Not IsEmpty(j)) Then
If (j.HasFormula) ... |
My suggestion would be an ASCII captcha it does not use an image, and it's programmer/geeky.
Here is a PHP implementation http://thephppro.com/products/captcha/ this one is a paid.
There is a free, also PHP implementation, however I could not find an example -> http://www.phpclasses.org/browse/package/4544.html
I ... |
There are drawbacks of using reference counting. One of the most mentioned is circular references: Suppose A references B, B references C and C references B. If A were to drop its reference to B, both B and C will still have a reference count of 1 and won't be deleted with traditional reference counting. CPython (refer... |
I finally got Multisampling working with my wxWidgets OpenGL program. It's a bit messy right now, but here's how:
**wxWidgets** doesn't have **Multisampling** support in their **stable releases** right now (latest version at this time is **2.8.8**). But, it's available as a patch and also through their daily snapsho... |