instruction
stringlengths
0
30k
|c++|nintendods|user-interface|
I've made many different seperate parts of a GUI system for the Nintendo DS, like buttons and textboxes and select boxes, but I need a way of containing these classes in one Gui class, so that I can draw everything to the screen all at once, and check all the buttons at once to check if any are being pressed. My question is what is the best way organize all the classes (such as buttons and textboxes) into one GUI class? Here's one way I thought of but it doesn't seem right: **Edit:** I'm using C++. class Gui { public: void update_all(); void draw_all() const; int add_button(Button *button); // Returns button id void remove_button(int button_id); private: Button *buttons[10]; int num_buttons; } This code has a few problems, but I just wanted to give you an idea of what I want.
|c++|user-interface|
Java Time Zone is messed up
|java|timezone|
I am running a Tomcat application, and I need to display some time values. Unfortunately, the time is coming up an hour off. I looked into it and discovered that my default TimeZone is being set to: sun.util.calendar.ZoneInfo[id="GMT-08:00", offset=-28800000,dstSavings=0,useDaylight=false, transitions=0,lastRule=null] Rather than the Pacific time zone. This is further indicated when I try to print the default time zone's [display name][1], and it comes up "GMT-08:00", which seems to indicate to me that it is not correctly set to the US Pacific time zone. I am running on Ubuntu Hardy Heron, upgraded from Gutsy Gibbon. Is there a configuration file I can update to tell the JRE to use Pacific with all the associated daylight savings time information? The time on my machine shows correctly, so it doesn't seem to be an OS-wide misconfiguration. [1]: http://java.sun.com/j2se/1.5.0/docs/api/java/util/TimeZone.html#getDisplayName()
I am running a Tomcat application, and I need to display some time values. Unfortunately, the time is coming up an hour off. I looked into it and discovered that my default TimeZone is being set to: sun.util.calendar.ZoneInfo[id="GMT-08:00", offset=-28800000,dstSavings=0,useDaylight=false, transitions=0,lastRule=null] Rather than the Pacific time zone. This is further indicated when I try to print the default time zone's [display name](http://java.sun.com/j2se/1.5.0/docs/api/java/util/TimeZone.html#getDisplayName(\)), and it comes up "GMT-08:00", which seems to indicate to me that it is not correctly set to the US Pacific time zone. I am running on Ubuntu Hardy Heron, upgraded from Gutsy Gibbon. Is there a configuration file I can update to tell the JRE to use Pacific with all the associated daylight savings time information? The time on my machine shows correctly, so it doesn't seem to be an OS-wide misconfiguration.
I am running a Tomcat application, and I need to display some time values. Unfortunately, the time is coming up an hour off. I looked into it and discovered that my default TimeZone is being set to: sun.util.calendar.ZoneInfo[id="GMT-08:00", offset=-28800000,dstSavings=0,useDaylight=false, transitions=0,lastRule=null] Rather than the Pacific time zone. This is further indicated when I try to print the default time zone's <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/TimeZone.html#getDisplayName()">display name</a>, and it comes up "GMT-08:00", which seems to indicate to me that it is not correctly set to the US Pacific time zone. I am running on Ubuntu Hardy Heron, upgraded from Gutsy Gibbon. Is there a configuration file I can update to tell the JRE to use Pacific with all the associated daylight savings time information? The time on my machine shows correctly, so it doesn't seem to be an OS-wide misconfiguration.
There's many OS specific ways to force routing over specific interfaces. What OS are you using? XP? Vista? *nix? The simplest way is to configure your network card with a static IP and NO GATEWAY, the only gateway (ie. internet access) your laptop will find is then via the mobile. The disadvantage of this method is that you'll need to access your TFS server by IP address (or netbios name) as all DNS requests will be going out over the internet and not through your private LAN. EDIT: If you can't use the phone when the LAN is plugged in, that's because you've got it setup for DHCP and the DHCP server is advertising (incorrectly for you) that it will accept and route internet traffic. As previously mentioned, setup with a static IP and no gateway... if you insist on using DHCP you'll need to learn the ROUTE command in DOS, find the IP address of your phone (assuming it's acting as a router) set that as the default route, and remove whatever default route was assigned from the DHCP server. EDIT2: @dan - you can't use the internet from your phone directly (eg. mobile browser), or you can't make your laptop use your phone for internet when the cable is plugged in? (ie. routing issues) ... if it's the former, then your phone is probably configuring a PAN with your phone and trying to route internet back over the LAN EDIT @Jorge - IP routing is the responsibility of the network layer, not the application. Go review the [OSI model](http://en.wikipedia.org/wiki/OSI_model) ;)
Subversion, CVS and all other source control systems are not good for Word documents and other office files (such as Excel spread sheets), since the files themselves are stored in a binary format. That means that you can never go back and annotate (or blame, or whatever you want to call it), or do diffs between documents. There are revision control systems for Word documents out there, unfortunately I do not know any good ones. We use such control systems for Excel at my work, and unfortunately they all cost money. The good thing is that they make life a lot easier, especially if you ever have to do an audit or due diligence.
Have you tried using [Monitor.Pulse](http://msdn.microsoft.com/en-us/library/system.threading.monitor.pulse.aspx) (ensure your thread is using thread management before running this) to get the thread to do something? If that works, then you're going to have to look a bit more into your threading logic.
> We put the Thread.Sleep in after a couple of times when the database had gone away and we came back to 3Gb logs files full of database connection errors. I would think a better option would be to make it so that your logging system trapped duplicates, so that it could write something like, "The previous message was repeated N times". Assume I've written a standard note about how you should open your connection at the last possible moment and close it at the earliest opportunity, rather than spanning a potentially huge function in the way you've done it (but perhaps that is an artefact of your demonstrative code and your application is actually written properly). When you say that it's reporting the error you describe, do you mean that _this handler_ is reporting the error? The reason it's not clear to me is that in the code snippet you say "Something went wrong", but you didn't say that in your description; I wouldn't want this to be something so silly as the exception is being caught somewhere else, and the code is getting stuck somewhere other than the sleep.
Good question. These two operators work the same in PHP and C#. | is a bitwise OR. It will compare two values by their bits. E.g. 1101 | 0010 = 1111. This is extremely useful when using bit options. E.g. Read = 01 (0X01) Write = 10 (0X02) Read-Write = 11 (0X03). One useful example would be opening files. A simple example would be: File.Open(FileAccess.Read | FileAccess.Write); //Gives read/write access to the file || is a logical OR. This is the way most people think of OR and compares two values based on their truth. E.g. I am going to the store or I will go to the mall. This is the one used most often in code. E.g. if(Name == "Admin" || Name == "Developer) { //allow access } //checks if name equals Admin OR Name equals Developer PHP Resource: http://us3.php.net/language.operators.bitwise C# Resources: http://msdn.microsoft.com/en-us/library/kxszd0kx(VS.71).aspx http://msdn.microsoft.com/en-us/library/6373h346(VS.71).aspx
@Greg Hewgill Amusingly, 'git checkout foo' will not work if the working copy is in a directory named foo; however, both 'git checkout HEAD foo' and 'git checkout ./foo' will: $ pwd /Users/aaron/Documents/work/foo $ git checkout foo D foo Already on "foo" $ git checkout ./foo $ git checkout HEAD foo
The single pipe, |, is one of the [bitwise][1] operators. From Wikipedia: > In the C programming language family, the bitwise OR operator is "|" (pipe). Again, this operator must not be confused with its Boolean "logical or" counterpart, which treats its operands as Boolean values, and is written "||" (two pipes). [1]: http://en.wikipedia.org/wiki/Bitwise_operation#OR
TFS isn't just about Source Control. If you use the whole package that TFS offers, bug tracking, builds, reports, etc then TFS is a pretty solid choice (certainly better than Rational). TFS also integrates well with Active Directory. Though if you are just talking about SCM, then I prefer SubVersion. I don't really like IDE integration. I also like SVN's convention of Trunk/Tags/Branches structure, and relative ease of switching between branches. Merging seemed easier in TFS though. Tortoise's UI beats TFS's hands down though, especially in regards to adding a file to a repo.
I like stored procs, dont know how many times I was able to make a change to an application using a stored procedure which didn't produce any downtime to the application. Big fan of Transact SQL, tuning large queries have proven to be very useful for me. Haven't wrote any inline SQL in about 6 years!
I did some googling and this is what I came up with: <pre><code> HttpContext.Current.Response.StatusCode = 401; </code></pre> Not sure if it works or not, I haven't tested it. Either way, it's worth a try, right? :)
`cvs import` is not just for 3rd-party sources. In fact, directories are not versioned by CVS, so they are not a subject to branch policies. As long as you import empty directories, it is fine.
By the way, you can expand on this idea to very quickly find _two_ unique numbers among a list of duplicates. Let's call the unique numbers a and b. First take the XOR of everything, as Kyle suggested. What we get is a^b. We know a^b != 0, since a != b. Choose any 1 bit of a^b, and use that as a mask -- in more detail: choose x as a power of 2 so that x & (a^b) is nonzero. Now split the list into two sublists -- one sublist contains all numbers y with y&x == 0, and the rest go in the other sublist. By the way we chose x, we know that a and b are in different buckets. We also know that each pair of duplicates is still in the same bucket. So we can now apply ye olde "XOR-em-all" trick to each bucket independently, and discover what a and b are completely. Bam.
Use the global method std::remove with the begin and end iterator, and then use std::vector.erase to actually remove the elements. Documentation links std::remove http://www.cppreference.com/cppalgorithm/remove.html std::vector.erase http://www.cppreference.com/cppvector/erase.html std::vector<int> v; v.push_back(1); v.push_back(2); //Vector should contain the elements 1, 2 //Find new end iterator std::vector<int>::iterator newEnd = std::remove(v.begin(), v.end(), 1); //Erase the "removed" elements. v.erase(newEnd, v.end()); //Vector should now only contain 2 Thanks to Jim Buck for pointing out my error. I chose to update this answer rather than just up vote his because using the single argument version of erase will only remove a single vector entry, where std::remove removes every element that matches.
Use the global method std::remove with the begin and end iterator, and then use std::vector.erase to actually remove the elements. Documentation links std::remove http://www.cppreference.com/cppalgorithm/remove.html std::vector.erase http://www.cppreference.com/cppvector/erase.html std::vector<int> v; v.push_back(1); v.push_back(2); //Vector should contain the elements 1, 2 //Find new end iterator std::vector<int>::iterator newEnd = std::remove(v.begin(), v.end(), 1); //Erase the "removed" elements. v.erase(newEnd, v.end()); //Vector should now only contain 2 Thanks to Jim Buck for pointing out my error.
How do I install and use the ASP.NET AJAX Control Toolkit in my .NET 3.5 web applications?
|asp.net|ajax|.net-3.5|
How do I get it to work with my project? [http://ajax.asp.net/][1] [http://www.codeplex.com/AjaxControlToolkit/][2] [1]: http://ajax.asp.net/ [2]: http://www.codeplex.com/AjaxControlToolkit/
>Hmmmm, I talking about them as they are implemented here: >http://blog.benday.com/archive/2008/03/31/23176.aspx >(at least Context.Handler there) >I am still having trouble in VS making that reference. Context.Handler is an instance of an HttpContext. HttpContext exposes the CURRENT instance for the request under the HttpContext.Current property, however the current context can also be passed in HTTPHandlers in the ProcessRequest method: void ProcessRequest(HttpContext context)
OK, if you're trying to update a row with ID = 1, you'll do it like this: DataContext context = new DataContext(); LinqEntity item = (from le in context.LinqEntities where le.ID == 1 select le).Single(); item.Name = "John"; item.Surname = "Doe"; context.Submit(); You could also replace the Linq expression with a more concise lambda: LinqEntity item = context.LinqEntities.Single(le => le.ID == 1);
OK, if you're trying to update a row with ID = 1, you'll do it like this: DataContext context = new DataContext(); LinqEntity item = (from le in context.LinqEntities where le.ID == 1 select le).Single(); item.Name = "John"; item.Surname = "Doe"; context.Submit(); You could also replace the Linq expression with a more concise lambda: LinqEntity item = context.LinqEntities.Single(le => le.ID == 1); The most important thing the DataContext does is track any changes you make, so that when you call the Submit method it will autogenerate the Insert statements for the things you've changed.
Use [Array.Copy][1]. It has an overload that does what you need: > Array.Copy (Array, Int32, Array, > Int32, Int32) > *Copies a range of elements from an Array starting at the specified source > index and pastes them to another Array > starting at the specified destination > index.* [1]: http://msdn.microsoft.com/en-us/library/system.array.copy(VS.80).aspx
[Array.Copy Method](http://msdn.microsoft.com/en-us/library/system.array.copy.aspx) I guess something like: string[] less = new string[parts.Length - (x - 2)]; Array.Copy(parts, x - 2, less, 0, less.Length); (*sans* the off by 1 bug that I'm sure is in there.)
Here's a nice add-on for Visual Studio 2005/2008 by Mikhail Arkhipov of MSFT. A 'smart' spell checker for ASP.NET and HTML pages - smart in the fact it can ignore the script and only focus on the text for spell checking. * [Latest version][1] [1]: http://blogs.msdn.com/webdevtools/archive/2007/12/13/spell-checker-for-html-asp-net-jscript-vb-c-css-and-c-for-visual-studio-2005-and-2008.aspx
Here's a nice add-on for Visual Studio 2005/2008 by Mikhail Arkhipov of MSFT. * [Latest version][1] [1]: http://blogs.msdn.com/webdevtools/archive/2007/12/13/spell-checker-for-html-asp-net-jscript-vb-c-css-and-c-for-visual-studio-2005-and-2008.aspx
[FxCop ships with a spell check now][1] - have you tried that? [Here's a nice add-on][2] for Visual Studio 2005/2008 by Mikhail Arkhipov of MSFT. [1]: http://davesbox.com/archive/2008/06/08/fxcop-now-ships-with-the-spell-checker-libraries.aspx [2]: http://blogs.msdn.com/webdevtools/archive/2007/12/13/spell-checker-for-html-asp-net-jscript-vb-c-css-and-c-for-visual-studio-2005-and-2008.aspx
What's the best way to allow a user to browse for a file in C#?
|c#|
What's the best way to allow a user to browse for a file in C#?
One specific reason static data is bad, is that C++ makes no guarantees about initialization order of static objects in different translation units. In practice this can cause problems when one object depends on another in a different translation unit. Scott Meyers discusses this in Item 26 of his book More Effective C++.
using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Title = "Select a file"; if (dlg.ShowDialog()== DialogResult.OK) { //do something with dlg.FileName } }
I would say use the standard "Open File" dialog box ([OpenFileDialog](http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog.aspx)), this makes it less intimidating for new users and helps with a consistant UI.
Close, Ryan, but you never showed the dialog. it should be: if (dlg.ShowDialog() == DialogResult.OK)
@Juan Manuel Did you ever work in classic ASP? When you had to program all of your own events and "viewstatish" items (like a dropdown recalling its selected value after form submission)? If so, then ASP.NET MVC will not feel that awkward off the bat. I would check out Rob Conery's Awesome Series "[MVC Storefront][1]" where he has been walking through the framework and building each expected component for a storefront site. It's really impressive and easy to follow along (catching up is tough because Rob has been reall active and posted A LOT in that series). Personally, and quite contrary to Jeff Atwood's [feelings on the topic][2], I rather liked the webform's model. It was totally different than the vbscribt/classic ASP day's for sure but keeping viewstate in check and writing your own CSS friendly controls was enjoyable, actually. Then again, note that I said "liked". ASP.NET MVC is really awesome and more alike other web technologies out there. It certainly is easier to shift from ASP.NET to RAILS if you like to or need to work on multiple platforms. [1]: http://blog.wekeroad.com/mvc-storefront/ [2]: https://stackoverflow.fogbugz.com/default.asp?W24212
Dynamic reference to resource files in C#
|c#|localization|
I have an application on which I am implementing localization. I now need to dynamically reference a name in the resouce file. assume I have a resource file called Login.resx, an a number of strings: foo="hello", bar="cruel" and baz="world" normally, I will refer as: String result =Login.foo; and result=="hello"; my problem is, that at code time, I do not know if I want to refer to foo, bar or baz - I have a string that contains either "foo", "bar" or "baz". I need something like: Login["foo"]; Does anyone know if there is any way to dynamically reference a string in a resource file?
Assuming you have an identity column in the table... select top 1 <fields> from HistoryTable where BatchRef = @BatchRef order by <IdentityColumn> DESC
I have a tendency to stick with basic integers at first (1,2,3), moving onto rational numbers (2.1, 3.13) when things get bigger... Tried using fruit at one point, that works well for a small office. Oh, the 'banana' release? *looks over in the corner* "yea... thats getting pretty old now..." Unfortunately confusion started to set in when the development team grew, is it an Orange, or Mandarin, or Tangelo? It *looks* ok... what do you mean "rotten on the inside?" ... but in all honesty. Setup a separate repository as a master, development goes on in various repositories... for every scheduled release everything is checked in to the master repository so that you can quickly roll back when something goes wrong. (I'm assuming dev/test/production are all separate servers and dev is never allowed to touch production or the master repository....)
I maintain a system of web applications with various components that live in separate SVN repos. To be able to version track the system as a whole, I have another SVN repo which contains all other repos as external references. It also contains install / setup script(s) to deploy the whole thing. With that setup, the SVN revision number of the "metarepository" could possibly be used for versioning the complete system. In another case, I include the SVN revision via [SVN keywords][1] in a class file that serves no other purpose (to avoid the risk of keyword substitution breaking my code). The class in that file contains a string variable that is manipulated by SVN and parsed by a class method. An inconvenience with both approaches is that the revision number is not automatically updated by changes in the externals (approach 1) or the rest of the code (approach 2). [1]: http://svnbook.red-bean.com/en/1.2/svn.advanced.props.html#svn.advanced.props.special.keywords "SVN keywords"
It's a bit hard to decypher your data the way WMD has formatted it, but you can pull of the sort of trick you need with common table expressions on SQL 2005: with LastBatches as ( select Batch, max(Id) from HistoryTable group by Batch ) select * from HistoryTable h join LastBatches b on b.Batch = h.Batch and b.Id = h.Id Or a subquery (assuming the group by in the subquery works - off the top of my head I don't recall): select * from HistoryTable h join ( select Batch, max(Id) from HistoryTable group by Batch ) b on b.Batch = h.Batch and b.Id = h.Id Edit: I was assuming you wanted the last item for *every* batch. If you just need it for the one batch then the other answers (doing a top 1 and ordering descending) are the way to go.
How do I hide the input caret in a System.Windows.Forms.TextBox?
|winforms|textbox|
I need to display a variable-length message and allow the text to be selectable. The blinking input caret is confusing. How do I hide it?
I need to display a variable-length message and allow the text to be selectable. I have made the TextBox ReadOnly which does not allow the text to be edited, but the input caret is still shown. The blinking input caret is confusing. How do I hide it? <hr> [edit] First two answers are missing the primary question - how to hide the blinking input caret / cursor.
I need to display a variable-length message and allow the text to be selectable. I have made the TextBox ReadOnly which does not allow the text to be edited, but the input caret is still shown. The blinking input caret is confusing. How do I hide it?
I wanted something similar, but with the ability to specify how the values on duplicate keys were merged, so I hacked this out (not heavily tested!). Obviously this is not a single expression, but it is a single fn. call. def merge(d1, d2, merge=lambda x,y:y): """ Merges two dictionaries, non-destructively, combining values on duplicate keys as defined by the optional merge function. The default behavior replaces the values in d1 with corresponding values in d2. (There is no other generally applicable merge strategy, but often you'll have homogeneous types in your dicts, so specifying a merge technique can be valuable.) Examples: >>> d1 {'a': 1, 'c': 3, 'b': 2} >>> merge(d1, d1) {'a': 1, 'c': 3, 'b': 2} >>> merge(d1, d1, lambda x,y: x+y) {'a': 2, 'c': 6, 'b': 4} """ result = dict(d1) for k,v in d2.iteritems(): if k in result: result[k] = merge(result[k], v) else: result[k] = v return result
The main drawback of using ID, Name etc is that you have to qualify them with the table name if you are writing an SQL join which overlaps two tables. Despite that, I find it far more concise and readable to just use ID and Name - your code and tables will 'flow' much more easily past the eyes. Easier to type and less redundant. And typing SELECT Business.Name FROM ... in an SQL query is not really more troublesome than typing SELECT BusinessName FROM ... In general, if I find myself repeating semantic information it alerts me to look for ways to eliminate it or at least recognise why it repeats. This could be on the small scale (attribute names) or the large scale (behaviour patterns or common class structures).
Tools to convert asp.net dynamic site into static site
|asp.net|web-crawler|
Are there any tools that will spider an asp.net website and create a static site?
Unless I am misunderstanding you: you don't need to. If you connect to the server with another application (ie: PuTTY) and it has not seen the server before then you will be prompted to accept the key. I see why you might want to do this, but each application could have it's own way to store keys.
This can also be the result of using reflection. If you have code that reflects on a class and extracts a method by name (eg: with `Class.getDeclaredMethod("someMethodName", .....)`) then any time that method name changes, such as during a refactor, you will need to remember to update the parameters to the reflection method to match the new method signature, or the `getDeclaredMethod` call will throw a `NoSuchMethodException`. If this is the reason, then the stack trace should show the point that the reflection method is invoked, and you'll just need to update the parameters to match the actual method signature. In my experience, this comes up occasionally when unit testing private methods/fields, and using a `TestUtilities` class to extract fields for test verification. (Generally with legacy code that wasn't designed with unit testing in mind.)
Did you write your own FormsAuth attribute for the action? If so, in the OnActionExecuting method, you get passed the FilterExecutingContext. You can use this to pass back the 401 code. public class FormsAuth : ActionFilterAttribute { public override void OnActionExecuting(FilterExecutingContext filterContext) { filterContext.HttpContext.Response.StatusCode = 401; filterContext.Cancel = true; } } This should work. I am not sure if you wrote the FormsAuth attribute or if you got it from somewhere else.
Did you accidentally omit a semicolon on a previous line? If the previous line is an `#include`, you might have to look elsewhere for the missing semicolon.
Did you accidentally omit a semicolon on a previous line? If the previous line is an `#include`, you might have to look elsewhere for the missing semicolon. Edit: If the rest of your code is valid C++, then there probably isn't enough information to determine what the problem is. Perhaps you could post your code to a [pastebin](http://pastebin.ca) so we can see the whole thing. Ideally, in the process of making it smaller to post, it will suddenly start working and you'll then have discovered the problem!
> You can use Will Dean's suggestion [<code>#define arraysize(ar) (sizeof(ar) / sizeof(ar[0]))</code>] to replace the magic number 3 here with arraysize(str_array) -- although I remember there being some special case in which that particular version of arraysize might do Something Bad (sorry I can't remember the details immediately). But it very often works correctly. The case where it doesn't work is when the "array" is really just a pointer, not an actual array. Also, because of the way arrays are passed to functions (converted to a pointer to the first element), it doesn't work across function calls even if the signature looks like an array &mdash; <code>some_function(string parameter[])</code> is really <code>some_function(string *parameter)</code>.
Minimalistic Database Administration
|database|administration|task|
I am a developer. An architect on good days. Somehow I find myself also being the DBA for my small company. My background is fair in the DB arts but I have never been a full fledged DBA. My question is what do I have to do to ensure a realiable and reasonably functional database environment with as little actual effort as possible? I am sure that I need to make sure that backups are being preformed and that is being done. That is an easy one. What else should I be doing on a consistant basis?
I've used [The Grinder][1]. It's open source, pretty easy to use, and very configurable. It is Java based and uses Jython for the scripts. We ran it against a .NET web application, so don't think it's a Java only tool (by their nature, any web stress tool should not be tied to the platform it uses). We did some neat stuff with it... we were a web based telecom application, so one cool use I set up was to mimick dialing a number through our web application, then used an auto answer tool we had (which was basically a tutorial app from Microsoft to connect to their RTC LCS server... which is what Microsoft Office Communicator connects to on a local network... then modified to just pick up calls automatically). This then allowed us to use this instead of an expensive telephony tool called The Hammer (or something like that). Anyways, we also used the tool to see how our application held up under high load, and it was very effective in finding bottlenecks. The tool has built in reporting to show how long requests are taking, but we never used it. The logs can also store all the responses and whatnot, or custom logging. I highly recommend this tool, very useful for the price... but expect to do some custom setup with it (it has a built in proxy to record a script, but it may need customization for capturing something like sessions... I know I had to customize it to utilize a unique session per thread). [1]: http://grinder.sourceforge.net/
One more note, for our web application, I found that we had huge performance issues due to contention between threads over locks... so the moral was to think over the locking scheme very carefully. We ended up having worker threads to throttle too many requests using an asynchronous http handler, otherwise the application would just get overwhelmed and crash and burn. It meant a huge backlog could pile up, but at least the site would stay up.
I have done a great deal of work handling bounce emails and there different types. If you want to be absolutely sure that the email your looking at is indeed a bounce of a specific kind I highly recommend getting a good filter. I have worked with [Boogie Tools][1] and it has worked very well. It lets you know what kind of bounce it is, Hard, Soft, Transient or if its even someone trying to unsubscribe. It has a muliple API's including .Net and I found it quite easy to get working. [1]: http://www.boogietools.com/
We have been using [JSunit][1] for a while to do unit tests... it may not be the same kinds of tests you are talking about, but it is great for ensuring your JavaScript works as you expect. You run it in the browser, and it can be set in an Ant build to be automatically run against a bunch of browsers on a bunch of platforms remotely (so you can ensure your code is cross-browser as well as ensure the logic is correct). I don't think it replaces Selenium, but it complements it well. [1]: http://jsunit.net/
Linq to objects - select first object
|c#|linq|linq-to-objects|
I know almost nothing about linq. I'm doing this: var apps = from app in Process.GetProcesses() where app.ProcessName.Contains( "MyAppName" ) && app.MainWindowHandle != IntPtr.Zero select app; Which gets me all the running processes which match that criteria. But I don't know how to get the first one. The examples I can find on the net seem to imply I have to do this var matchedApp = (from app in Process.GetProcesses() where app.ProcessName.Contains( "MyAppName" ) && app.MainWindowHandle != IntPtr.Zero select app).First(); which strikes me as somewhat ugly, and also throws an exception if there are no matching processes. Is there a better way?
jQuery, action, return JSON. <http://devlicio.us/blogs/mike_nichols/archive/2008/05/25/jquery-cascade-cascading-values-from-forms.aspx>
Just to satisfy some curiosity: From [Why doesn't C# support default parameters?][1]: > In languages such as C++, a default value can be included as part of the method declaration: > void Process(Employee employee, bool bonus = false) > This method can be called either with: > a.Process(employee, true); > or > a.Process(employee); > in the second case, the parameter bonus is set to false. > C# doesn't have this feature. > One reason we don't have this feature is related to a specific implementation of the feature. In the C++ world, when the user writes: > a.Process(employee); > the compiler generates > a.process(employee, false); > In other words, the compiler takes the default value that is specified in the method prototype and puts it into the method call - it's just as if the user wrote 'false' as the second parameter. There's no way to change that default value without forcing the user of the class to recompile, which is unfortunate. > The overloading model works better in this respect. The framework author just defines two separate methods, and the single-parameter one calls the two-parameter method. This keeps the default value in the framework, where it can be modified if necessary. > It would be possible for a compiler to take something like the C++ definition and produce the overloads, but there are a few issues with that approach. > The first one is that the correlation between the code that the user writes and the code the compiler generates is less obvious. We generally try to limit magic when possible, as it makes it harder for programmers. The second issue has to do with things like XML doc comments and intellisense. The compiler would have to have special rules for how it generates doc comments for the overloaded methods, and intellisense would need to have smarts to collapse the overloaded methods into a single method. > Writing overloads yourself is a bit less convenient, but we think it's an acceptable solution. [1]: http://blogs.msdn.com/csharpfaq/archive/2004/03/07/85556.aspx
Exceptions in Web Services
|.net|web-services|wcf|exception|
My group is developing a service-based (.NET WCF) application and we're trying to decide how to handle exceptions in our internal services. Should we throw exceptions? Return exceptions serialized as XML? Just return an error code? Keep in mind that the user will never see these exceptions, it's only for other parts of the application.
Well, there's always the low tech solution of adding logging of the size of your maps when you modify them, then search the logs for which maps are growing beyond a reasonable size.
Reading from a http-get presenting in Firefox bookmarks
|javascript|firefox|plugin-development|xul|
I'm trying to get a Firefox plugin to read data from a HTTP get, parse the results and present them as links in a bookmark-like drop-down menu. My quesion then is: Does anyone have any sample code that will do this?
Install Python to match directory layout in OS X 10.5
|python|macos|64-bit|
The default Python install on OS X 10.5 is 2.5.1 with a fat 32 bit (Intel and PPC) client. I want to setup apache and mysql to run django. In the past I have run apache and mysql to match this install in 32 bit mode (even stripping out the 64 bit stuff from apache to make it work). I want to upgrade Python to 64 bit. I am completely comfortable with compiling it from source with one caveat. How to I match the way that the default install is laid out? Especially with regards to site-packages being in /Library/Python/2.5/ and not the one in buried at the top of the framework once I compile it.
Thinking out of the box, would migrating to a Wiki be out of the question? Since you consider it feasible to force your users into Subversion (or something similar), a larger change seem acceptable. Another migration target could be to use some kind of structured XML document format ([DocBook](http://www.docbook.org/) comes to mind). This would enable you to indeed use diffs and source control, while getting all sorts of document formats for free.
You can try [GTK+][1]. I believe wxWidgets implementation for linux is written in GTK+. [1]: http://www.gtk.org/
I tried Wireshark and Microsoft Network Monitor, but neither detected my (and the program I am trying to communicate with) transfer. If I had a day to sit and configure it I probably could get it working but I just wanted the bytes sent and, more specifically, bytes received. In the end I found [HHD Software's Accurate Network Monitor][1] software which did what I wanted it to, even if it was slight clunky. [1]: http://www.hhdsoftware.com/Products/home/accurate-network-monitor.html
As already suggested you probably want to reorder your query to sort it in the other direction so you actually fetch the first row. Then you'd probably want to use something like SELECT TOP 1 ... if you're using MSSQL 2k or earlier, or the SQL compliant variant SELECT * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY key ASC) AS rownumber, columns FROM tablename ) AS foo WHERE rownumber = n for any other version (or for other database systems that support the standard notation), or SELECT ... LIMIT 1 OFFSET 0 for some other variants without the standard SQL support. See also [this](http://stackoverflow.com/questions/16568/how-to-select-the-nth-row-in-a-sql-database-table) question for some additional discussion around selecting rows. Using the aggregate function max() might or might not be faster depending on whether calculating the value requires a table scan.
It's kind of hard to make sense of your table design - I think SO ate your delimiters. The basic way of handling this is to GROUP BY your fixed fields, and select a MAX (or MIN) for some unqiue value (a datetime usually works well). In your case, I *think* that the GROUP BY would be BatchRef and ItemCount, and Id will be your unique column. Then, join back to the table to get all columns. Something like: SELECT * FROM HistoryTable JOIN ( SELECT MAX(Id) as Id. BatchRef, ItemCount FROM HsitoryTable WHERE BacthRef = @batchRef GROUP BY BatchRef, ItemCount ) as Latest ON HistoryTable.Id = Latest.Id
Watch out with that quote-matching lookahead assertion. That'll only match if *Boolean* is the last part of a string, but not in the middle of the string. You'll need to match an even number of quote marks preceding the match if you want to be sure you're not in a string (assuming no multi-line strings and no escaped embedded quote marks).
How is your structure type defined? There are two ways to do it: // This will define a typedef for S1, in both C and in C++ typedef struct { int data; int text; } S1; // This will define a typedef for S2 ONLY in C++, will create error in C. struct S2 { int data; int text; };
I rather like this new (?) behavior because the XML document doesn't have any mention of Bar in it, so the deserializer should not even be attempting to set it.
Big fan of the UPSERT, really cuts down on the code to manage. Here is another way I do it: One of the input parameters is ID, if the ID is NULL or 0, you know it's an INSERT, otherwise it's an update. Assumes the application knows if there is an ID, so wont work in all situations, but will cut the executes in half if you do.
I've used Red Gate's SQL Packager for this in the past. The beauty of this tool is that it creates a C# project for you that actually does the work so if you need to you can extend the functionality of the default package to do other things like insert default values into new columns that have been added to the db etc. In the end you have a nice tool that you can hand to a technician and all they have to do to upgrade multiple DBs is point it to the database and click a button. Red Gate also has a product called SQL multi-script that allows you to run scripts against multiple servers/dbs at the same time. I've never used this tool but I imagine if you're looking for something to use internally that doesn't need to be packaged up you'd want to look at that.
If you have to use Rail's built-in Javascript generation, I would use Orion's solution, but with one small alteration to compensate for the return code. eval ('function(){' + code + '}()'); However, in my opinion you'd have an easier time in the long run by separating out the Javascript code into an external file or separate callable functions.
If you have to use Rail's built-in Javascript generation, I would use Orion's solution, but with one small alteration to compensate for the return code. eval ('(function(){' + code + '})()'); However, in my opinion you'd have an easier time in the long run by separating out the Javascript code into an external file or separate callable functions.
I would suggest: - A script to quickly restore the latest backup of a database, in case it gets corrupted - What kind of backups are you doing? Full backups each day, or incremental every hour, etc? - Some scripts to create new users and grant them basic access. However, the number one suggestion is to limit as much as possible the power other users have, this will greatly reduce the chance of stuff getting badly messed up. Servers that have everyone as an sa tend to get screwed up quicker than servers that are locked down.
@Juan Manuel Did you ever work in classic ASP? When you had to program all of your own events and "viewstatish" items (like a dropdown recalling its selected value after form submission)? If so, then ASP.NET MVC will not feel that awkward off the bat. I would check out Rob Conery's Awesome Series "[MVC Storefront][1]" where he has been walking through the framework and building each expected component for a storefront site. It's really impressive and easy to follow along (catching up is tough because Rob has been reall active and posted A LOT in that series). Personally, and quite contrary to Jeff Atwood's [feelings on the topic][2], I rather liked the webform model. It was totally different than the vbscribt/classic ASP day's for sure but keeping viewstate in check and writing your own CSS friendly controls was enjoyable, actually. Then again, note that I said "liked". ASP.NET MVC is really awesome and more alike other web technologies out there. It certainly is easier to shift from ASP.NET MVC to RAILS if you like to or need to work on multiple platforms. And while, yes, it is very stable obviously (this very site), if your company disallows "beta" software of any color; implementing it into production at the this time might be an issue. [1]: http://blog.wekeroad.com/mvc-storefront/ [2]: https://stackoverflow.fogbugz.com/default.asp?W24212