instruction stringlengths 0 30k ⌀ |
|---|
I also like project euler, but I would like to point out that the questions get really tricky really fast. After the first 20 questions or so, they start to be problems most people won't be able to figure out in 1/2 an hour. Another problem is that a lot of them deal with math with really large numbers, that don't fi... |
There is a way.
The JarJar project does this AFAIR. The first goal of the JarJar project is to allow one to embed third party libraries in your own jar, changing the package structure if necessary. Doing so it can strip out the classes that are not needed.
Check it out at <http://code.google.com/p/jarjar/>.
He... |
There are a couple ways you can do this. First, and probably most easily, you can do it recursively.
(defun remove-low-words (word-list)
(if (good-enough-score-p (car word-list))
(list word (remove-low-words (cdr word-list)))
(remove-low-words (cdr word-list))))
You could also do... |
You're talking about network sockets, not UNIX sockets I assume?
I'm not sure this suits your needs, but the way I would do it is by seperating the networking and logic part, and only restart the logic part, then reconnect the logic part to the networking part. |
This program gets Google's homepage and then when you pass it SIG_INT via ctrl-c it restarts the program and reads the output of the homepage from the open socket with Google.
#!/usr/bin/ruby
#simple_connector.rb
require 'socket'
puts "Started."
if ARGV[0] == "restart"
sock... |
The "automatic" keyword also allows you to write recursive functions (since verilog 2001). I believe they should be synthesisable if they bottom out, but I'm not sure if they have tool support.
I too, do verilog! |
Best way to display/format SQL 2005 money data type in ASP.Net |
|asp.net| |
I am attempting to set an asp.net textbox to a SQL 2005 money data type field, the initial result displayed to the user is 40.0000 instead of 40.00.
In my asp.net textbox control I would like to only display the first 2 numbers after the decimal point e.g. 40.00
What would be the best way to do this?
My code is be... |
For lots of different runs over the same logic but with different data you can use CSV, as many columns as you like for the input and the last for the output etc. |
If you _really_ want to do this, you can use the GCHandle.Alloc method to specify that a pointer should be pinned without being automatically released at the end of the scope like the fixed statement.
But, as other people have been saying, doing this is putting undue pressure on the garbage collector. What about ju... |
Regarding the [excerpt from the csharp faq][1]:
Most of the problems listed there were solved for VB.Net (specifically the intellisense and xml comments issues), meaning they're really red herrings-- _there is code available to the C# team that will solve the problem._
Another reason has to do with forcing a ... |
Maybe tcl/tk would provide what you want http://www.tcl.tk/ |
A semaphore is an object containing a natural number (i.e. a integer greater or equal to zero) on which two modifying operations are defined. One operation, `V`, adds 1 to the natural. The other operation, `P`, decreases the natural number by 1. Both activities are atomic (i.e. no other operation can be executed at the... |
If indeed an audit trail is all you need, I'd lean toward the audit table solution (complete with denormalized copies of the important column on other tables, e.g., `UserName`). Keep in mind, though, that bitter experience indicates that a single audit table will be a huge bottleneck down the road; it's probably worth... |
How to traverse a maze programatically when you've hit a dead end. |
|c#|ai| |
Moving through the maze forward is pretty easy, but I can't seem to figure out how to back up through the maze to try a new route once you hit a dead end without going back too far? |
PowerBuilder in particular has a nice trick you can do to incorporate the build number from an ini file into the compiled application.
Details here: <http://www.pbdr.com/pbtips/ex/autorev.htm>
We have ini file inside source control that stores the build number and its value is used in our build scripts to determi... |
**Using attributes, child config sections and constraints**
There is also the possibility to use attributes which automatically takes care of the plumbing, as well as providing the ability to easily add constraints.
I here present an example from code I use myself in one of my sites. With a constraint I dictate t... |
Getting started with a custom JXTA PeerGroup |
|java|jxta| |
I have been working with JXTA 2.3 for the last year or so for a peer-to-peer computing platform I am developing. I am migrating to JXTA 2.5 and in the process I am trying to clean up a lot of my use of JXTA. For the most part, I approached JXTA with a "just make it work" attitude. I used it to jumpstart creating and ma... |
Joey, I believe anything is lighter than Eclipse! :o) |
> Just to check, if you use just this part you get an error?
>
>If so, do you still get an error if you copy and paste one of those Inserts into this >page, I am trying to see if it's local to the page or that actual line.
>
>Also, can you post a copy of the connection calls (minus passwords), unless the inserts >u... |
I liked the idea of trying to use MonoDevelop mostly just to make sure my stuff would work against the Mono runtimes. I guess it would also be possible to get crazy with msbuild and write some custom targets that tried to build against Mono, but that's basically emulating the now-defunct plug-in's functionality which ... |
A couple of observations:
* Don't create simple delegates explicitly in code like that unless you're pre-2.0 so you could use:
BeginInvoke(new EventHandler<CoolObjectEventArgs>(mCoolObject_CoolEvent), sender, args);
Also you don't need to create and populate the object array because the args paramet... |
I think what you're looking for is the select() call in c/c++. I found a copy of the man page here: <http://www.opengroup.org/onlinepubs/007908775/xsh/select.html>. Select takes file descriptors as arguments and tells you when one of them has changed and is ready for reading. |
<?php
/*
Resizes an image and converts it to PNG returning the PNG data as a string
*/
function imageToPng($srcFile, $maxSize = 100) {
list($width_orig, $height_orig, $type) = getimagesize($srcFile);
// Get the aspect ra... |
Just as an update in case anyone else has this problem, I installed the .Net 3.5 SP1 update separately. Now I'm down to "only" 5045MB required. |
PHP has arrays which are actually associative arrays and can also be used as sets. Like many interpreted languages, PHP offers all this under one hood instead of providing different explicit data types.
E.g.
$lst = array(1, 2, 3);
$hsh = array(1 => "This", 2 => "is a", 3 => "test");
/Edit: Also, take ... |
How to have to remote orgins for Git? |
|git| |
My company is a small one where we would be using Git for version control. The main server will be local. But we do want an server where our local repo is kept online to give access to our clients so that they can have assurance that we are doing the right thing and to allow them to check out from there if needed.
... |
How to have two remote orgins for Git? |
Err... `tmp_obj_a07724` suspiciously looks like a leftover temporary
file :)
What happens if you simply move it away from the `.git` directory
(after a backup of the whole thing)?
|
You can add remotes with `git remote add <name> <url>`
You can then push to a remote <name> with `git push <name> master:master` to push your local master branch to the remote master branch.
When you create a repo with `git clone` the remote is named `origin` but you can create a `public` repository for your onli... |
The JavaFX API just supports media playback at the moment (see [javafx.scene.media.MediaView][1]). There might very well be mere Java APIs for encoding, however.
[1]: http://javafx.com/releases/preview1/docs/api/javafx.scene.media/javafx.scene.media.MediaView.html# |
From what I know, you can hack the build files to target the 1.1 runtime instead.
Google for your question and you should turn up pages like [this one](http://devlicio.us/blogs/ziemowit_skowronski/archive/2008/08/22/working-with-net-1-1-in-visual-studio-2008-and-team-server.aspx). |
If you're asking in the perspective of a DSL, [Guile Scheme](http://www.gnu.org/software/guile/guile.html) could help, as already suggested with the S-expressions.
Personally I also use JSON for AJAX transactions.
|
Merge early, merge often, and make sure that QA on the mainline knows and regresses/verifies the defects fixed in each patch of the maintenance releases.
It's really easy to let something slip out and "unfix" a bug in a subsequent release, and let me tell you, customers don't care about how complicated it can get ... |
[**According to Scott Guthrie**][1], the reason VS 2008 does not support 1.0 or 1.1...
> "...is that there were significant CLR engine changes between .NET 1.x and 2.x that make debugging very difficult to support. In the end the costing of the work to support that was so large and impacted so many parts of Visual ... |
@steveth45: I think you mean:
unsigned long n;
printf("%lu", n); // unsigned long
or
long n;
printf("%ld", n); // signed long
Am I right? |
If you can't use the (proper) init structure to do this (you're on shared hosting, etc.), use cron to run a script (it can be written in whatever language you like) every few minutes that checks to see if they're running, and restarts them if necessary. |
You could also set a cookie on the user-side and then check for the presence of that cookie directly after redirecting, which if you're bothered about friendly URLs would mean that you don't have to pass around a PHPSESSID in the query string. |
this.txtPayment.Text = string.Format("{0:c}", dr[Payment"].ToString()); |
asp:DropDownList Error: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items. |
|asp.net| |
I have a asp.net 2.0 web site with numerous asp:DropDownList controls.
The DropDownList control contains the standard info city, state, county etc... info.
In addition to the standard codes the site also has custom codes that the users can configure themselves.
For example a animal dropdown may contain the values Do... |
Use the *ToString* method with "c" to format it as currency.
this.txtPayment.Text = dr["Payment"].ToString("c");
[Standard Numeric Format Strings][1]
[1]: http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx |
Does the "c" format string work on ASP.NET the same way as it does in, say, Windows Forms? Because in WinForms I'm fairly certain it obeys the *client's* currency settings. So even if the value is stored in US Dollars, if the client PC is set up to display Yen then that's the currency symbol that'll be displayed. That ... |
Per [John](#38471), I don't see what the problem with a classic normalised schema would be. You haven't given much information to go on, but you say that there's a one-to-many relationship between users and addresses, so I'd plump for a bog standard solution with a foreign key to the user in the address relation. |
I liked the idea of trying to use MonoDevelop mostly just to make sure my stuff would work against the Mono runtimes. I guess it would also be possible to get crazy with msbuild and write some custom targets that tried to build against Mono, but that's basically emulating the now-defunct plug-in's functionality which ... |
I'd recommend getting VMWare Player and using the free Mono development platform image that is provided on the website.
<http://www.go-mono.com/mono-downloads/download.html>
Setup time for this will be minimal, and it will also allow you to get your code working in .NET and then focus on porting issues without a ... |
> I guess in a managed environment, a
> leak would be you keeping an
> unnecessary reference to a large chunk
> of memory around.
Absolutely. Also, not using the .Dispose() method on disposable objects when appropriate can cause mem leaks. The easiest way to do it is with a using block because it automatically ex... |
Yaakov,
I'd been wrangling over the same question whilst retro fitting LINQ to SQL over a legacy DB. Our database is a bit of a whopper (150 tables) and after some thought and experimentation I elected to use multiple DataContexts. Whether this is considered an anti-pattern remains to be seen, but for now it makes l... |
Python's [Tk/Tcl][1] widget library works very well, and I believe is sufficiently cross platform.
[Tkinter][2] is the python interface to Tk/Tcl
[1]: http://www.tcl.tk/
[2]: http://docs.python.org/lib/module-Tkinter.html |
You don't need to *compile* python for Mac/Windows/Linux. It is an interpreted language, so you simply need to have the Python interpreter installed on the system of your choice (it is available for all three platforms).
As for a GUI library that works cross platform, Python's [Tk/Tcl][1] widget library works very ... |
Create one Message table, containing a unique MessageId and the various properties you need to store for a message.
Table: Message
Fields: Id, TimeReceived, MessageDetails, WhateverElse...
Create two link tables - QuoteMessage and JobMessage. These will just contain two fields each, foreign keys to the... |
Create one Message table, containing a unique MessageId and the various properties you need to store for a message.
Table: Message
Fields: Id, TimeReceived, MessageDetails, WhateverElse...
Create two link tables - QuoteMessage and JobMessage. These will just contain two fields each, foreign keys to the... |
Create one Message table, containing a unique MessageId and the various properties you need to store for a message.
Table: Message
Fields: Id, TimeReceived, MessageDetails, WhateverElse...
Create two link tables - QuoteMessage and JobMessage. These will just contain two fields each, foreign keys to the... |
Create one Message table, containing a unique MessageId and the various properties you need to store for a message.
Table: Message
Fields: Id, TimeReceived, MessageDetails, WhateverElse...
Create two link tables - QuoteMessage and JobMessage. These will just contain two fields each, foreign keys to the... |
The only native data structure in PHP is array. Fortunately, array are quite flexible and can be used as hash tables as well.
[http://www.php.net/array][1]
However, there is SPL which is sort of a clone of C++ STL.
[http://www.php.net/manual/en/book.spl.php][2]
[1]: http://www.php.net/array
[2]: http... |
Wikipedia:
* [High-pass filter](http://en.wikipedia.org/wiki/High-pass_filter)
* [Low-pass filter](http://en.wikipedia.org/wiki/Low-pass_filter)
* [Band-pass filter](http://en.wikipedia.org/wiki/Band-pass_filter)
These "high", "low", and "band" terms refer to *frequencies*. In high-pass, you try to remove low f... |
They are generally Electrical circuits that tend to pass parts of analog signals. High pass tends to transmit more of the high frequency parts and low pass tends to pass more of the low frequency parts.
They can be simulated in software. A walking average can act as a low pass filter for instance and the difference ... |
You can probably find the best in an algorithms textbook like [Introduction to Algorithms][1]. Though I've never read that particular book, it's quite renowned for being thorough and would probably contain most of the problems you're likely to encounter.
[1]: http://www.amazon.com/Introduction-Algorithms-Thomas-... |
"Computers and Intractability: A guide to the theory of NP-Completeness" by Garey and Johnson[1] is a great reference for this sort of thing, although the "solved" problems (in P) are obviously not given much attention in the book.
I'm not aware of any good on-line resources, but Karp's seminal paper Reducibility am... |
Validate (X)HTML in Python |
|python|html|validation|xhtml| |
What's the best way to go about validating that a document follows some version of HTML (prefereably that I can specify)? I'd like to be able to know where the failures occur, as in a web-based validator, except in a native Python app. |
Try using a Rails distribution like: http://instantrails.rubyforge.org/wiki/wiki.pl
One download install for rails+ruby+mysql on Windows. |
Are there any good programs for actionscript/flex that'll count lines of code, number of functions, files, packages,etc... |
|apache-flex|actionscript-3|code-analysis| |
Doug McCune had created something that was exactly what I needed ([http://dougmccune.com/blog/2007/05/10/analyze-your-actionscript-code-with-this-apollo-app/][1]) but alas - it was for AIR beta 2. I just would like some tool that I can run that would provide some decent metrics...any idea's?
[1]: http://dougmcc... |
Like what so many people have already indicated, the answer here is "it depends". There are some things like *repeating operations* that are much simpler and cleaner in NAnt. See [the MSDN forums][1] for a discussion about this.
[1]: http://forums.msdn.microsoft.com/en-US/msbuild/thread/417329cb-a6f6-45dd-9a56-9... |
The way we handle this at my work is to keep the trunk branch as the most cutting-edge code (ie, 2.0 in this case). You create a branch for the 1.x code, and make all your fixes there. Any changes to 1.x should be merged (manually, if need be) into the trunk (2.0) branch.
I would then insist that 1.x developers ma... |
How to cache ASP.NET user controls? |
|asp.net|caching|user-controls| |
I heard on a recent podcast (Polymorphic) that it is possible to cache a user control as opposed to the entire page.
I think my header control which displays static content and my footer control could benefit from being cached.
How can I go about caching just those controls? |
If you are getting one of DNN's error pages, there is a chance it may have logged the error to the eventlog table. |
Although I have tinkered with LEGO Mindstorms (and enjoyed it) in the past I would thoroughly recommend [XNA Game Studio][1] for the following reasons:
- It involves creating something many children will be interested in (games).
- It's free.
- It's a real language (C#) and a real IDE (Visual Studio).
- Y... |
Eclipse "Share Project" by hand? |
|svn|eclipse|subclipse| |
What actually happens to the file system when you do a Subclipse Share Project on an Eclipse project that was externally checked out from Subversion? All the .svn folders are already in place. I get an error when I try to Share Project the right way, and I'd rather not delete and re-checkout the projects from the SVN... |
Won't the answer depend on what cleanup has to happen as a result of a throw? If an excpetion is thrown that causes a whole load of objects to go out of scope up the stack, then that will add to the overhead.
In other words, I'm not sure if there is a an answer to the 3rd question that is independent of the specific... |
If you need to authenticate against the second site, you may need to spawn a new thread and call the windows LogonUser API. Once you have the security token, assign it to the new thread and do your connection via that thread.
LogonUser requires enhanced privileges, and isn't Managed code, so there are some pretty s... |
Use [backtracking](http://www.cs.bu.edu/teaching/alg/maze/) by keeping a stack of previous direction decisions. |
In management studio:
- Right-click the database, choose properties, then options.
- Make sure "Recovery model" is set to "Simple", not "Full"
- Click Ok
- Right-click the database again, choose tasks -> shrink files
- Change file type to "log"
- Click ok.
Alternatively, the SQL to do it:
ALTER DATAB... |
backup log logname with truncate_only followed by a dbcc shrinkfile command |
Autocomplete Dropdown with Linkbuttons - or "AJAX gone wild" |
|ajax|.net-3.5| |
Ok, so I want an autocomplete dropdown with linkbuttons as selections. So, the user puts the cursor in the "text box" and is greated with a list of options. They can either start typing to narrow down the list, or select one of the options on the list. As soon as they click (or press enter) the dataset this is link... |
The simplest (to implement) algorithm would be to just keep a stack of locations you've been at, and the route you took from each, unless backtracking gives you that information.
To go back, just pop off old locations from the stack and check for more exits from that location until you find an old location with an u... |
if I remember well... in query analyzer or equivalent:
BACKUP LOG databasename WITH TRUNCATE_ONLY
DBCC SHRINKFILE ( databasename_Log, 1)
|
@Simon,
You raise very good points. I was already thinking about the "temporary" "human-readable" numbers i'd generate while offline, that i'd recreate on sync. But i wanted to avoid doing with with foreign keys, etc. |
You should provide information about what operating system and the type of filesystem you are using. On certain flavours of UNIX and certain filesystems you might be able to use the commands "ff" and "ncheck" as alternatives. |
How do I convert images between CMYK and RGB in ColdFusion (java)? |
|java|image|coldfusion| |
I have a need to convert images from CMYK to RGB - not necessarily back again, but hey, if it can be done...
With the release of ColdFusion 8, we got the [CFImage][1] tag, but it doesn't support this conversion; and nor does [Image.cfc][2], or [Alagad's Image Component][3].
However, it should be possible in Java;... |
PHP's [array][1] doubles as both a list and a dictionary.
$myArray = array("Apples", "Oranges", "Pears");
$myScalar = $myArray[0] // == "Apples"
Or to use it as an associative array:
$myArray = array("a"=>"Apples", "b"=>"Oranges", "c"=>"Pears");
$myScalar = $myArray["a"] // == "Apples"
... |