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 fit into standard integer or even long variable types.
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/>. Here is a link about shrinking jars: <http://sixlegs.com/blog/java/jarjar-keep.html>
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 it with `mapcar` and `reduce`, where the former can construct you a list with failing elements replaced by `nil` and the latter can be used to filter out the `nil`. Either would be a good candidate for a "filter" macro or function that takes a list and returns the list filtered by some predicate.
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 = IO.open(ARGV[1].to_i) puts sock.read exit else sock = TCPSocket.new('google.com', 80) sock.write("GET /\n") end Signal.trap("INT") do puts "Restarting..." exec("ruby simple_connector.rb restart #{sock.fileno}") end while true sleep 1 end
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 below: this.txtPayment.Text = dr["Payment"].ToString();
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 just creating a struct that holds onto a pair of your nodes and then managing an array of NodePairs rather than an array of nodes? If you really do want to have completely unmanaged access to a chunk of memory, you would probably be better off allocating the memory directly from the unmanaged heap rather than permanently pinning a part of the managed heap (this prevents the heap from being able to properly compact itself). One quick and simple way to do this would be to use Marshal.AllocHGlobal method.
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 user of a class to re-compile, but that's a bit of a red herring, too. If you _change_ a default value in your framework class and the user does _not_ have to recompile, you risk the user _not knowing that the default value changed._ Now you have a potential bug in the code that doesn't show up until runtime. In other words, the alternative of overloading the function is at least as bad. Of course, this also presumes a specific implementation of the feature, but it's the implementation suggested in the faq. Therefore you have to weigh the remaining reason ("try to limit the magic") vs the fact (which they acknowledge) that writing the overloads is "a bit less convenient". Personally, I say put the feature in, and let the programmer decide whether or not to use it. [1]: http://blogs.msdn.com/csharpfaq/archive/2004/03/07/85556.aspx
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 same time as a `V` or a `P`). Because the natural number 0 cannot be decreased, calling `P` on a semaphore containing a 0 will block the execution of the calling process(/thread) until some moment at which the number is no longer 0 and `P` can be successfully (and atomically) executed. As mentioned in other answers, semaphores can be used to restrict access to a certain resource to a maximum (but variable) number of processes.
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 the effort to create individual audit tables for all your audited tables. If you need to track the actual historical (and/or future) versions, then the standard solution is to track the same entity with multiple rows using some combination of start, end, and duration values. You can use a view to make accessing current values convenient. If this is the approach you take, you can run into problems if your versioned data references mutable but unversioned data.
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 determine what label to apply to the source tree after a successful build. Works very nicely for our needs. When we branch, we do have to manually kick the file to increment the proper number though.
**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 the maximum amount of disk space any one user is allowed to use. MailCenterConfiguration.cs: namespace Ani { public sealed class MailCenterConfiguration : ConfigurationSection { [ConfigurationProperty("userDiskSpace", IsRequired = true)] [IntegerValidator(MinValue = 0, MaxValue = 1000000)] public int UserDiskSpace { get { return (int)base["userDiskSpace"]; } set { base["userDiskSpace"] = value; } } } } This is set up in web.config like so <configSections> <!-- Mailcenter configuration file --> <section name="mailCenter" type="Ani.MailCenterConfiguration" requirePermission="false"/> </configSections> ... <mailCenter userDiskSpace="25000"> <mail host="my.hostname.com" port="366" /> </mailCenter> **Child elements** The child xml element _mail_ is created created in the same .cs file as the one above. Here I've added constraints on the port. If the port is assigned a value not in this range the runtime will complain when the config is loaded. MailCenterConfiguration.cs: public sealed class MailCenterConfiguration : ConfigurationSection { [ConfigurationProperty("mail", IsRequired=true)] public MailElement Mail { get { return (MailElement)base["mail"]; } set { base["mail"] = value; } } public class MailElement : ConfigurationElement { [ConfigurationProperty("host", IsRequired = true)] public string Host { get { return (string)base["host"]; } set { base["host"] = value; } } [ConfigurationProperty("port", IsRequired = true)] [IntegerValidator(MinValue = 0, MaxValue = 65535)] public int Port { get { return (int)base["port"]; } set { base["port"] = value; } } **Use** To then use it practically in code, all you have to do is instantiate the MailCenterConfigurationObject, this will **automatically** read the relevant sections from web.config. MailCenterConfiguration.cs private static MailCenterConfiguration instance = null; public static MailCenterConfiguration Instance { get { if (instance == null) { instance = (MailCenterConfiguration)WebConfigurationManager .GetSection("mailCenter"); } return instance; } } AnotherFile.cs public void SendMail() { MailCenterConfiguration conf = MailCenterConfiguration.Instance; SmtpClient smtpClient = new SmtpClient(conf.Mail.Host, conf.Mail.Port); } **Check for validity** I previously mentioned that the runtime will complain when the configuration is loaded and some data does not comply to the rules you have set up (e.g. in MailCenterConfiguration.cs). I tend to want to know these things as soon as possible when my site fires up. One way to solve this is load the configuration in _Global.asax.cx.Application_Start_ , if the configuration is invalid you will be notified of this with the means of an exception. Your site won't start and instead you will be presented detailed exception information in the [Yellow screen of death][1]. Global.asax.cs protected void Application_ Start(object sender, EventArgs e) { MailCenterConfiguration.Instance; } [1]: http://www.codinghorror.com/blog/images/yellow-screen-of-death-large.png
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 managing my peer-to-peer overlay network and providing basic communication services. I would like to use it in a more "JXTA" way since I am making changes to move to 2.5 anyway. My first step would be a basic creation of a custom PeerGroup. I see some new new mechanisms that are using the META-INF.services infrastructure of Java. Should I be listing a related PeerGroup implementing object here with a GUID in net.jxta.platform.Module? As I understand it, if I do this, when a group with a spec ID matching the GUID is encountered and joined or created it should automatically use the matching object. I should be able to just manually tie a PeerGroup object to the group but this new method using META-INF seems to be a lot easier to manage. Does anyone have any pointers or examples of using this infrastructure for PeerGroup implementation? Also, some general information on the META-INF.services mechanism in Java would be helpful. Stephen
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 >use exactly the same syntax as this example. Here is what is in the connection.php file. I linked to the file through an include in the same fashion as where I execute the INSERT queries elsewhere in the code. $conn = mysql_connect("localhost", ******, ******) or die("Could not connect"); mysql_select_db("adbay_com_-_cms") or die("Could not select database"); I will try the working INSERT query in this area to check that out. Thanks for the suggestion! As to the others posting about the password access. I did, as stated in my first posting, check permissions. I used phpMyAdmin to verify that the permissions for the user account I was using were correct. And if it matters at all, apache@localhost is not the name of the user account that I use to get into the database. I don't have any user accounts with the name apache in them at all for that matter.
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 assume was non-trivial to build. I do have minor experience with cygwin, and I am happy typing "configure" and "make" all day long, but when a problem occurs in that process, I'm virtually screwed. I'll probably try to play with all this again, but if it takes me more than a couple hours to come up with a way to build comfortably against the Mono runtimes, I'll probably just bail. Thanks for the advice, anyway!
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 parameter is a "params" type so you can just pass in the list. * Secondly, I would probably favour Invoke over BeginInvoke as the latter will result in the code being called asynchronously which may or may not be what you're after but would make handling subsequent exceptions difficult to propagate without a call to EndInvoke. What would happen is that your app will end up getting a TargetInvocationException instead.
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 ratio $ratio_orig = $width_orig / $height_orig; $width = $maxSize; $height = $maxSize; // resize to height (orig is portrait) if ($ratio_orig < 1) { $width = $height * $ratio_orig; } // resize to width (orig is landscape) else { $height = $width / $ratio_orig; } // Temporarily increase the memory limit to allow for larger images ini_set('memory_limit', '32M'); switch ($type) { case IMAGETYPE_GIF: $image = imagecreatefromgif($srcFile); break; case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($srcFile); break; case IMAGETYPE_PNG: $image = imagecreatefrompng($srcFile); break; default: throw new Exception('Unrecognized image type ' . $type); } // create a new blank image $newImage = imagecreatetruecolor($width, $height); // Copy the old image to the new image imagecopyresampled($newImage, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // Output to a temp file $destFile = tempnam(); imagepng($newImage, $destFile); // Free memory imagedestroy($newImage); if ( is_file($destFile) ) { $f = fopen($destFile, 'rb'); $data = fread($f); fclose($f); // Remove the tempfile unlink($destFile); return $data; } throw new Exception('Image conversion failed.'); }
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 a look [in the manual](http://www.php.net/manual/en/language.types.array.php).
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. So if I simply wish to push only to the one outside, and will never pull from it, what is the best Git way to do this?
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 online server and push to it with `git push public master:master`
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 to manage multiple branches -- that's your job. Make sure you're using a source control system that supports branching and merging (I've had experience with Perforce and SVN, and while Perforce is better, SVN is free). I also believe that having a single person responsible for performing the merges in a consistent manner helps ensure that they happen regularly. It's generally been me or one of the senior people on our team.
[**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 Studio that we weren't able to add 1.1 support in this release." Sounds like it would be difficult to really create such a plugin. The only hope you might find in his statement is that they "weren't able to add 1.1 support *in this release*" (emphasis mine). i.e. maybe they will add it down the road. I wouldn't hold my breath though. ---------- EDIT: Looks like the link [**@lassevk**][2] provided shows some promise for those people that can't accept running VS 2003 side-by-side with VS 2008. Looks like a lot of work though. :) [1]: http://weblogs.asp.net/scottgu/archive/2007/06/20/vs-2008-multi-targeting-support.aspx [2]: http://stackoverflow.com/questions/44737/is-there-a-plugin-for-targetting-net-11-with-vs-2008#44748
@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 Dog, Cat, Fish, ect... I am popluating the DropDownList from a SQL 2005 table that I created e.g. tblCodes Everything works great and users are able to add orders using the numerous DropDownList controls to choose items from the list. The problem occurrs if a user wants to change one of their custom dropdowns. For example a user would like to change the verbage on a animal type control from Dog to K9. This is where the problem starts. For all new orders the drop down works fine. When the user retrieved an old order I get the following error in the C# codebehind "'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items." What's happening is the old order has a database field value of Dog and the DropDownList no longer has Dog in its list since the user changed it to K9. Any ideas on a workaround? Is there a way to make the asp:DropDownList accept items not seeded in its list? Is there another control I could use?
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 may not be what you want. It may be wiser if that's the case to use: txtPayment.Text = dr["Payment"].ToString("00.00")
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 assume was non-trivial to build. I do have minor experience with cygwin, and I am happy typing "configure" and "make" all day long, but when a problem occurs in that process, I'm virtually screwed. I'll probably try to play with all this again, but if it takes me more than a couple hours to come up with a way to build comfortably against the Mono runtimes, I'll probably just bail. I will try the Eclipse idea. I use that for Java, so I might be able to get the c# stuff to work. We shall see... Thanks for the advice, anyway!
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 massive hassle of switching machines and the like. the VMWare Player tools will allow you to simply drag and drop the files over to copy them. I'm looking to take a couple of my .NET apps and make them Mono compliant, and this is the path I'm going to take here shortly.
> 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 executes .Dispose() at the end: StreamReader sr; using(sr = new StreamReader("somefile.txt")) { //do some stuff } And if you create a class that is using unmanaged objects, if you're not implementing IDisposable correctly, you could be causing memory leaks for your class's users.
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 life manageable.
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 well, and I believe is sufficiently cross platform. [Tkinter][2] is the python interface to Tk/Tcl From the python project webpage: <pre> Tkinter is not the only GuiProgramming toolkit for Python. It is however the most commonly used one, and almost the only one that is portable between Unix, Mac and Windows </pre> [1]: http://www.tcl.tk/ [2]: http://docs.python.org/lib/module-Tkinter.html
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 Quote/Job and the Message. Table: QuoteMessage Fields: QuoteId, MessageId Table: JobMessage Fields: QuoteId, JobId
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 Quote/Job and the Message. Table: QuoteMessage Fields: QuoteId, MessageId Table: JobMessage Fields: QuoteId, JobId In this way you have defined the data properties of a Message in one place only (making it easy to extend, and to query across all messages), but you also have the referential integrity linking Quotes and Jobs to any number of messages. Indeed, both a Quote and Job could be linked to the *same* message (I'm not sure if that is appropriate to your business model, but at least the data model gives you the option).
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 Quote/Job and the Message. Table: QuoteMessage Fields: QuoteId, MessageId Table: JobMessage Fields: JobId, MessageId In this way you have defined the data properties of a Message in one place only (making it easy to extend, and to query across all messages), but you also have the referential integrity linking Quotes and Jobs to any number of messages. Indeed, both a Quote and Job could be linked to the *same* message (I'm not sure if that is appropriate to your business model, but at least the data model gives you the option).
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 Quote/Job and the Message. Table: QuoteMessage Fields: QuoteId, MessageId Table: JobMessage Fields: JobId, MessageId In this way you have defined the data properties of a Message in one place only (making it easy to extend, and to query across all messages), but you also have the referential integrity linking Quotes and Jobs to any number of messages. Indeed, both a Quote and Job could be linked to the *same* message (I'm not sure if that is appropriate to your business model, but at least the data model gives you the option). @Guy - thanks, typo corrected.
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://www.php.net/manual/en/book.spl.php
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 frequencies. In low-pass, you try to remove high. In band pass, you only allow a continuous frequency range to remain. Choosing the cut-off frequency depends upon your application. Coding these filters can either be done by simulating RC circuits or by playing around with Fourier transforms of your time-based data. See the wikipedia articles for code examples.
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 between a walking average and it's input can work as a high pass filter.
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-H-Cormen/dp/0262032937
"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 among Combinatorial Problems (1972)[2] on reductions and complexity is probably the "canonical" reference for Hard Problems. Links (markdown seems to having issues with this post): 1: http://portal.acm.org/citation.cfm?id=578533 2: http://en.wikipedia.org/wiki/Karp's_21_NP-complete_problems
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://dougmccune.com/blog/2007/05/10/analyze-your-actionscript-code-with-this-apollo-app/
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-98bb4aee74f9
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 make note of both the revision number for the 1.x commit and the revision number for the 2.0 merge in the ticket for that bug. That way, it will be easier to notice if anyone forgets to merge their changes, and the fact that they have to keep track of it will help them remember.
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). - You get to learn OOP. - It's something the parents are going to find as much fun as the kids are. [1]: http://creators.xna.com/
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 Repository browser.
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 specifics of the code.
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 severe hiccups to using it. But that's been the only work around I've been able to find to get a Forms authenticated site talking to a Windows Authenticated Service/Site. Hope this helps.
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 DATABASE mydatabase SET RECOVERY SIMPLE DBCC SHRINKFILE (mydatabase_Log, 1) Ref: <http://msdn.microsoft.com/en-us/library/ms189493.aspx>
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 linked to will be filtered by the selection. Ok, is this as easy as wrapping an AJAX autocomplete around a dropdown? No? (Please?)
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 untested exit. By consistently testing the exits in the same order each time, if you know that backtracking to a location comes from down (ie. last time you were at the old location you went down), then you simply pick the next direction after *down*. I am not entirely sure what you mean by *going back too far* though, I would assume you would want to go back to the previous place you have untested routes, is that not what you want? Note that unless you try to keep track of the path from the starting point to your current location, and avoiding those squares when you try to find new routes, you might end up going in circle, which would eventually make the stack too large. A simple recursive method which marks the path it takes and never enters areas that are marked can easily do this. Also, if your *thing* that moves through the maze is slightly smarter than just being able to move, and hit (stop at) walls, in that it can see from its current point in all directions, I have other algorithms that might help.
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; which we can leverage through CF. For example here's how you might create a java thread to sleep a process: [1]:http://cfquickdocs.com/cf8/?getDoc=cfimage [2]:http://x.com [3]:http://x.com <cfset jthread = createObject("java", "java.lang.thread")/> <cfset jthread.sleep(5000)/> I would guess a similar method could be used to leverage java to do this image conversion, but not being a java developer, I don't have a clue where to start. Can anyone lend a hand here?
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" [1]: http://hudzilla.org/phpwiki/index.php?title=Arrays