instruction
stringlengths
0
30k
[Ice][1] from ZeroC is a really high performance "enterprisey" interop layer that supports Java and .net amongst others. I think of it as an updated Corba - it even has its own object oriented interface definition language called [Slice][2] (like Corba's IDL, but actually quite readable). The feature set is extensive, with far more on offer than web services, but clearly it isn't an open standard, so not a decision to make lightly. The generated code it spits out is somewhat ugly too... [1]: http://www.zeroc.com/ice.html [2]: http://www.zeroc.com/doc/Ice-3.3.0/reference/
Usually you know where you are having problems, so you can set a breakpoint in your javascript code by placing the keyword "debugger;" on a line in your javascript code (obviously without the quotes) to set a breakpoint. When you get to it in IE, it will ask you if you want to debug and prompt you to choose a debugger from a list, hopefully you will see Visual Studio in that list (both a new instance as well as your currently-running instance) - if you are using FireFox with FireBug, it will automatically stop execution on that line and you will be within the FireBug debugger, not Visual Studio. You will want to do the following to setup IE for doing this - from within IE, follow this menu path: Tools > Internet Options > Advanced Tab > Uncheck the "Disable Script Debugging" options.
This one not only calculates n!, it is also O(n!). It may have problems if you want to calculate anything "big" though. long f(long n) { long r=1; for (long i=1; i<n; i++) r=r*i; return r; } long factorial(long n) { // iterative implementation should be efficient long result; for (long i=0; i<f(n); i++) result=result+1; return result; }
The best way to get back into C++ is to jump in. You can't learn a real language without spending any serious time in a country where they speak it. I wouldn't try to learn a programming language without spending time coding in it either. I wouldn't recommend learning C first though. That's a good way to pick up some bad habits in C++.
I haven't tried it myself but have heard from people and sources I trust that "Accelerated C++" by Koenig and Moo is a good book for people who want to pick up C++ quickly. Compared to the more traditional route of learning C first then C++ as a kind of C with classes the K+M approach helps you become productive quickly while avoiding pitfalls and bad habits associated with the legacy of the language.
iPhone App Minus App Store?
|iphone|
I've been looking into iPhone development, but I've been having problems coming up with the answer to a certain question. If I create an application on my Mac, is there any way I can get it to run on an iPhone without going through the app store? It doesn't matter if the iPhone has to be jailbroken, as long as I can still run an application created using the official SDK. For reasons I won't get into, I can't have this program going through the app store. Thanks for any help you can give!
@jjnguy: `-Xms` sets the *initial* size of the heap. Changing this will have no effect on `java.lang.OutOfMemory` errors. The option to use is `-Xmx` which sets the *maximum* size of the heap. [See here for details.][1] [1]: http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/java.html#nonstandard
**Nesting Using Statements** Usually we do it like this: StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter()) { using (IndentedTextWriter itw = new IndentedTextWriter(sw)) { ... } } But we can do it this way: StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter()) using (IndentedTextWriter itw = new IndentedTextWriter(sw)) { ... }
One way is to throw an exception in Page Load, but don't catch it. At the bottom of the page, you'll see the version number.
If you can profile, just Do it and profile. Datasets are heavier then a simple `Collection<T>` DataReaders are faster then using Adapters... Changing behavior in an objects is much easier than massaging a dataset Anyway: Just Do It, ask for forgiveness not permission.
Yes, Once you have joined the iPhone Developer Program,and paid Apple $99, you can transfer your application to up to 100 iPhones or iPod touches.
The Subversion book has [an appendix][1] that details important differences from CVS, which may help you make your decision. The two approaches are more or less the same idea but SVN was specifically designed to fix long standing flaws in CVS so, in theory at least, SVN will always be the better choice. [1]: http://svnbook.red-bean.com/en/1.4/svn.forcvs.html
CVS only tracks modification file by file while SVN tracks a whole commit as a new revision, which means that it is easier to follow the history of your project. Add the fact that all modern source control software use the concept of revision so it is far easier to migrate from SVN than it is from CVS. There is also the atomic commit problem. While I only encountered it once, it is possible that 2 people committing together in CVS conflicts each other loosing some data and putting your client in an inconsistent state. When detected early, these problem are not major because your data is still out there somewhere but it can be a pain in a stressful environment. And finally, not much tools are developed around CVS anymore. While the new and shiny new tools like Git or Mercurial definitely lack tools yet, SVN has a pretty large application base on any system.
When I needed to write an application with a client-server model where the clients could leave and enter whenever they want, (I assume that's also the case for your application as you use mobile devices) I made sure that the clients send an *online* message to the server, indicating they were connected and ready to do whatever they needed doing. at that time the server could send messages back to the client trough the same open connection. Also, but I don't know if that is applicable for you, I had some sort of *heartbeat* the clients sent to the server, letting it know it was still online. That way the server knows when a client was forcibly disconnected from the network and it could mark that client back as offline.
How big can a MySQL database get before performance starts to degrade.
|database|mysql|
At what point does a MySQL database start to loose performance? - Does physical database size matter? - Do number of records matter? - Is any performance degradation linear or exponential? Ive got (what I believe to be) a large database, almost 2GB and about 15M records. Should I be cleaning this out, or am I OK for another few years?
SVN has 3 main advantages over CVS - it's faster - supports versioning of binary files - and adds transactional commit (all or nothing)
You can use the artifact directory variable inside the MSBuild script itself. Here's an example of how I'm running FxCop right now from my CC.Net MSBuild script (this script is what CC.Net points to - there is also a "Build" target in the script that includes an MSBuild task against the SLN to do the actual compilation): <Exec Command='FxCopCmd.exe /project:"$(MSBuildProjectDirectory)\FXCopRules.FxCop" /out:"$(CCNetArtifactDirectory)\ProjectName.FxCop.xml"' WorkingDirectory="C:\Program Files\Microsoft FxCop 1.35" ContinueOnError="true" IgnoreExitCode="true" />
To get rid of the _AFXDLL error, have you tried changing to the settings to use MFC as a static lib instead of a DLL? This is similar to what you're already doing in changing the runtime libs to static instead of DLL.
It depends on your requirements. For instance, if you don't care about the searcher's properties (e.g. searcher strength, vision, etc.), then I would say haystack.find(needle) would be the cleanest solution. But, if you do care about the searcher's properties (or any other properties for that matter), I would inject an ISearcher interface into either the haystack constructor or the function to facilitate that. This supports both object oriented design (a haystack has needles) and inversion of control / dependency injection (makes it easier to unit test the "find" function).
If you are using Hibernate, take a look at [JBoss Envers][1]. From the project homepage: > The Envers project aims to enable easy versioning of persistent JPA classes. All that you have to do is annotate your persistent class or some of its properties, that you want to version, with @Versioned. For each versioned entity, a table will be created, which will hold the history of changes made to the entity. You can then retrieve and query historical data without much effort. This is somewhat similar to [Eric's approach][2], but probably much less effort. Don't know, what language/technology you use to access the database, though. [1]: http://www.jboss.org/envers/ [2]: http://stackoverflow.com/questions/23770/good-strategy-for-leaving-an-audit-trailchange-history-for-db-applications#23780
Try [Real World Haskell][1]. It's free online. [1]: http://book.realworldhaskell.org/beta/index.html
You can define multiple autoloading functions with spl\_autoload\_register: spl_autoload_register('load_controllers'); spl_autoload_register('load_models'); function load_models($class){ if( !file_exists("models/$class.php") ) return false; include "models/$class.php"; return true; } function load_controllers($class){ if( !file_exists("controllers/$class.php") ) return false; include "controllers/$class.php"; return true; }
Evidently the performance hit of anonymous delegates is pretty significant. Test code: static void Main(string[] args) { for (int kk = 0; kk < 10; kk++) { List<int> tmp = new List<int>(); for (int i = 0; i < 100; i++) tmp.Add(i); int sum = 0; long start = DateTime.Now.Ticks; for (int i = 0; i < 1000000; i++) sum += tmp.Find(delegate(int x) { return x == 3; }); Console.WriteLine("Anonymous delegates: " + (DateTime.Now.Ticks - start)); start = DateTime.Now.Ticks; sum = 0; for (int i = 0; i < 1000000; i++) { int match = 0; for (int j = 0; j < tmp.Count; j++) { if (tmp[j] == 3) { match = tmp[j]; break; } } sum += match; } Console.WriteLine("Classic C++ Style: " + (DateTime.Now.Ticks - start)); Console.WriteLine(); } } Results: Anonymous delegates: 710000 Classic C++ Style: 340000 Anonymous delegates: 630000 Classic C++ Style: 320000 Anonymous delegates: 630000 Classic C++ Style: 330000 Anonymous delegates: 630000 Classic C++ Style: 320000 Anonymous delegates: 610000 Classic C++ Style: 340000 Anonymous delegates: 630000 Classic C++ Style: 330000 Anonymous delegates: 650000 Classic C++ Style: 330000 Anonymous delegates: 620000 Classic C++ Style: 330000 Anonymous delegates: 620000 Classic C++ Style: 340000 Anonymous delegates: 620000 Classic C++ Style: 400000 In every case, using anonymous delegates is about 100% slower than the other way.
> HTTPS requests are not cached so sending an If-Modified-Since doesn't make any sense. The not caching is a security precaution. The not caching **on disk** is a security pre-caution, but it seems it indeed affects the **If-Modified-Since** behavior (glancing over the code). Try setting the Firefox preference (in about:config) **browser.cache.disk_cache_ssl** to **true**. If that helps, try sending **Cache-Control: public** header in your response.
> HTTPS requests are not cached so sending an If-Modified-Since doesn't make any sense. The not caching is a security precaution. The not caching **on disk** is a security pre-caution, but it seems it indeed affects the **If-Modified-Since** behavior (glancing over the code). Try setting the Firefox preference (in about:config) **browser.cache.disk\_cache\_ssl** to **true**. If that helps, try sending **Cache-Control: public** header in your response.
That used to be a problem in SQL 2000, but I thought that was fixed in 2005.
PHPs htmlspecialcharacters equivalent in .NET?
|c#|.net|asp.net|php|
PHP has a great function called [htmlspecialcharacters()][1] where you pass it a string and it replaces all of HTML's special characters with their safe equivalents, it's *almost* a one stop shop for sanitizing input. Very nice right? Well is there an equivalent in any of the .NET libraries? If not, can anyone link to any code samples or libraries that do this well? [1]: http://us2.php.net/manual/en/function.htmlspecialchars.php
8094 bytes. If you list some more information about what you are doing it might help us to figure out the actual cause.
System.Web.HttpUtility.HtmlEncode(string)
Try this. var encodedHtml = HttpContext.Current.Server.HtmlEncode(...);
Enterprise Reporting Solutions
|sql|reporting-services|reporting|
What options are there in the industry for enterprise reporting? I'm currently using SSRS 2005, and know that there is another version coming out with the new release of MSSQL. But, it seems like it might also be a good time to investigate the market to see what else is out there. What have you encountered? Do you like it/dislike it? Why? Thank you.
In SQL 2000, the row limit is 8K bytes, which is the same size as a page in memory. [Edit] In 2005, the page size is the same (8K), but the database uses pointers on the row in the page to point to other pages that contain larger fields. This allows 2005 to overcome the 8K row size limitation.
Don't know if there's an exact replacement, but there is a method HtmlUtility.HtmlEncode that replaces special characters with their HTML equivalents. A close cousin is HtmlUtility.UrlEncode for rendering URL's. You could also use validator controls like RegularExpressionValidator, RangeValidator, and System.Text.RegularExpression.Regex to make sure you're getting what you want.
Books by E.F. Codd and C.J. Date are the most obvious answers. I have not read this particular book but I am familiar with the authors, it is likely quite good. [Applied Mathmatics for Database Professionals][1] by Lexx de Haan and Toon Koppelaars. [1]: http://www.amazon.com/Applied-Mathematics-Database-Professionals-Experts/dp/1590597451/ref=pd_sxp_f_pt
If you want a colon delimited value converter then there is a 3rd party open source called [FileHelpers][1]. I'm not sure about what open-source license it is under, but it has helped me quite a lot. [1]: http://filehelpers.sourceforge.net/
It depends on what you actually want to do with the data. Given a large text file like that you typically only want a smaller subset of the data at any one time, so don't overlook tools like 'grep' for pulling out the pieces you want to look for and work with.
One point missed here: A List has a Count property, it internally keeps track of how many elements are in it. An IEnumerable DOES NOT. If you program to the interface IEnumerable and use the count extention method it will enumerate just to count the elements. A moot point though since in the IEnumerable you cannot refer to items by index. So if you want to lock in to Lists and Arrays you can get small performance increases. If you want flexability use foreach and program to IEnumerable. (allowing the use of linq and/or yield return).
I've got a lot faster developing SharePoint-Solutions in general (not only Workflows) when i started using [WSPBuilder][1]. WSPBuilder has a Visual Studio Addin called WSPBuilder Extensions and in my opinion the WSPBuilder Extensions do a better job than the infamous [Windows SharePoint Services 3.0 Tools: Visual Studio 2008 Extensions, Version 1.2][2]. Thanks to the WSPBuilder Menu deploy/upgrade/uninstall of a solution is just one click away! [1]: http://www.codeplex.com/wspbuilder [2]: http://www.microsoft.com/downloads/details.aspx?FamilyID=7bf65b28-06e2-4e87-9bad-086e32185e68&displaylang=en
Some image formats have headers where you can store arbitrary information as well. For example, the [PNG specification][1] has a chunk where you can store text data. This is similar to the answers above, but without adding random data to the image data itself. [1]: http://en.wikipedia.org/wiki/Portable_Network_Graphics#Ancillary_chunks
Actually, I think the rule of thumb is typically to use a natural key rather than a surrogate whenever possible... So if I have, for instance, an Invoice table and an InvoiceDetail table, we can probably use InvoiceNumber as our primary key on the first one. It already exists in our data and (I assume?) would be unique. For the second table, we are probably going to be stuck needing a surrogate key, however -- whether it's joined to Invoice number as composite or not. In any event, back to the original question... hometoast's link should get you started. -- Kevin Fairchild
preferred way to implement visitor pattern in dynamic languages?
|c#|ruby|design-patterns|dynamic-languages|
As an exercise for myself, I was translating a sample program into various languages. Starting in C#, I had a visitor-pattern interface like so: interface Visitor { void Accept(Bedroom x); void Accept(Bathroom x); void Accept(Kitchen x); void Accept(LivingRoom x); } Moving to ruby (or python, or whatever), I no longer get dispatch from the compiler based on type. Should I do the dispatch in the visitor itself? class Cleaner def accept(x) acceptBedroom(x) if Bedroom === x acceptBathroom(x) if Bathroom === x acceptKitchen(x) if Kitchen===x acceptLivingRoom(x) if LivingRoom===x end ... Or should I do the dispatch in the different specializaions of the room: class Bathroom<Room def initialize(name) super(name) end def accept(visitor) visitor.acceptBathroom(self) end end Or is there another preferred idiom that is used in dynamic languages? Full samples are at: <a>http://lostbearlabs.googlecode.com/svn/trunk/codex/Visitor/CSharp/Visitor/VisitorExample.cs</a> <a>http://lostbearlabs.googlecode.com/svn/trunk/codex/Visitor/Ruby/Visitor.rb</a>
What happens if two cycles overlap? Which one has its longest edge removed first? Does it matter if the longest edge of each is shared between the two cycles or not? For example: V = { a, b, c, d } E = { (a,b,1), (b,c,2), (c,a,4), (b,d,9), (d,a,3) } There's an a -> b -> c -> a cycle, and an a -> b -> d -> a
How to Determine the Installed ASP.NET Version of Host from a Web Page
|asp.net|
I have a site running in a Windows shared hosting environment. In their control panel for the shared hosting account I have it set to use ASP.NET version 3.0 but it doesn't say 3.5 SP1 specifically. How can I view the installed version running on the server where my website is hosted in an asp.net page?
|.net|asp.net|
It sounds like a GUI is not really what you were after, but maybe [HeidiSQL](http://en.wikipedia.org/wiki/HeidiSQL) would be worth a look. It's a GUI frontend for MySQL which I wouldn't say I quite _enjoyed_ using, but I've certainly come across worse ways to talk with a database.
Calculate Video Duration
|math|video|calculate|duration|
I suck at math. I need to figure out how to calculate a video duration with only a few examples of values. For example, a value of 70966 is displayed as 1:10 minutes. A value of 30533 displays as 30 seconds. A value of 7007 displays as 7 seconds.
Looks like the numbers are in milliseconds. So to convert to seconds, divide by 1000, then divide by 60 to find minutes etc.
Filter out HTML tags and resolve entities in python
|python|html|
Because regular expressions scare me, I'm trying to find a way to remove all HTML tags and resolve HTML entities from a string in Python.
I would **strongly** advise against putting unrelated data in a given Git repository. The overhead of creating new repositories is quite low, and that is a *feature* that makes it possible to keep different lineages completely separate. Fighting that idea means ending up with unnecessarily tangled history, which renders administration more difficult and--more importantly--"archeology" tools less useful because of the resulting dilution. Also, as you mentioned, Git assumes that the "unit of cloning" is the repository, and practically has to do so because of its distributed nature. A solution is to keep every project/package/etc. as its own *bare* repository (i.e., without working tree) under a blessed hierarchy, like: /repos/a.git /repos/b.git /repos/c.git Once a few conventions have been established, it becomes trivial to apply administrative operations (backup, packing, web publishing) to the complete hierarchy, which serves a role not entirely dissimilar to "monolithic" SVN repositories. Working with these repositories also becomes somewhat similar to SVN workflows, with the addition that one *can* use local commits and branches: svn checkout --> git clone svn update --> git pull svn commit --> git push (Cf. [this post](http://beta.stackoverflow.com/questions/6009/how-do-you-deal-with-configuration-files-in-source-control#36767) of mine for an example where local, throw-away commits & branches can be very useful). The easiest way to make an existing `~/dev/foo` in such a bare repository is probably: $ cd ~/dev $ git clone --bare foo /repos/foo.git $ mv foo foo.old $ git clone /repos/foo.git which is mostly equivalent to a `svn import`--but does not throw the existing, "local" history away!
After some experimentation, I've overcome my mental block. In retrospect, it's all obvious, but in the spirit of Stack Overflow, here's what I learned. As Sebastjan said, you first have to sort your data. This is important. The part I didn't get is that in the example construction groups = [] uniquekeys = [] for k, g in groupby(data, keyfunc): groups.append(list(g)) # Store group iterator as a list uniquekeys.append(k) "k" is the current grouping key, and "g" is an iterator that you can use to iterate over the group defined by that grouping key. In other words, the groupby iterator itself returns iterators. Here's an example of that, using clearer variable names: from itertools import groupby things = [("animal", "bear"), ("animal", "duck"), ("plant", "cactus"), ("vehicle", "speed boat"), ("vehicle", "school bus")] for key, group in groupby(things, lambda x: x[0]): for thing in group: print "A %s is a %s." % (thing[1], key) print " " This will give you the output: > A bear is a animal.<br> > A duck is a animal. > > A cactus is a plant. > >A speed boat is a vehicle. <br> >A school bus is a vehicle. In this example, "things" is a list of tuples where the first item in each tuple is the group the second item belongs to. The groupby() function takes two arguments: (1) the data to group and (2) the function to group it with. Here, "lambda x: x[0]" tells groupby() to use the first item in each tuple as the grouping key. In the above "for" statement, groupby returns three (key, group iterator) pairs - once for each unique key. You can use the returned iterator to iterate over each individual item in that group. Here's a slightly different example with the same data, using a list comprehension: for key, group in groupby(things, lambda x: x[0]): listOfThings = " and ".join(["%s" % thing[1] for thing in group]) print key + "s: " + listOfThings + "." This will give you the output: >animals: bear and duck.<br> >plants: cactus.<br> >vehicles: speed boat and school bus. Python's pretty cool, no?
From [wikipedia][1]: > Turing completeness, named after Alan > Turing, is significant in that every > plausible design for a computing > device so far advanced can be emulated > by a universal Turing machine — an > observation that has become known as > the Church-Turing thesis. Thus, a > machine that can act as a universal > Turing machine can, in principle, > perform any calculation that any other > programmable computer is capable of. > However, this has nothing to do with > the effort required to write a program > for the machine, the time it may take > for the machine to perform the > calculation, or any abilities the > machine may possess that are unrelated > to computation. > > While truly Turing-complete machines > are very likely physically impossible, > as they require unlimited storage, > Turing completeness is often loosely > attributed to physical machines or > programming languages that would be > universal if they had unlimited > storage. All modern computers are > Turing-complete in this sense. I don't know how you can be more non-technical than that except by saying "turing complete means 'able to answer computable problem given enough time and space'". [1]: http://en.wikipedia.org/wiki/Turing_completeness
It's generally considered bad practice to rely on linebreaks, since it's a fragile way to differentiate data. While most XML processors will preserve any whitespace you put in your XML, it's not guaranteed. The real problem is that most applications that output your XML into a readable format consider all whitespace in an XML interchangable, and might collapse those linebreaks into a single space. That's why your XSLT has to jump through such hoops to render the data properly. Using a "br" tag would vastly simplify the transform. Another potential problem is that if you open up your XML document in an XML editor and pretty-print it, you're likely to lose those line breaks. If you do keep using linebreaks, make sure add an xml:space="preserve" attribute to "address." (You can do this in your DTD, if you're using one.) **Some suggested reading** - An [article from XML.com][1] says the following: > XML applications often seem to take a > cavalier attitude toward whitespace > because the rules about the places in > an XML document where whitespace > doesn't matter sometimes give these > applications free rein to add or > remove whitespace in certain places. - [A collection of XSL-list posts regarding whitespace][2]. [1]: http://www.xml.com/pub/a/2001/11/07/whitespace.html [2]: http://www.dpawson.co.uk/xsl/sect2/N8321.html
One issue to consider is do you want a "makefile" creator or a replacement build system? The problem with replacement build systems is that you typically don't get good IDE integration for platforms whose users expect this (Visual C++). If you do want a makefile creator instead of a replacement build system, take a look at [MPC][1]. It's free and open source. [1]: http://ociweb.com/products/mpc
Firstly, you *really* want to be using sqlite. In my experience Access itself is a pile of [redacted], but the Jet database engine it uses is actually pretty fast and can handle some pretty complex SQL queries. If you can find a rails adapter that actually works I'd say you'll be fine. Just don't open the DB with the access frontend while your rails app is running :-) If your client is anal enough to only allow you to develop with an approved list of databases, they may be more concerned by the fact that [Jet is](http://aspalliance.com/14_Microsoft_Jet_database_engine_advice) [deprectated](http://en.wikipedia.org/wiki/Microsoft_Jet_Database_Engine) and will get no more support from MS. This might give you some ammunition in your quest to use a real database. Good luck
For loop and While loops are entry condition loops. They evaluate condition first, so the statement block associated with the loop won't run even once if the condition fails to meet The statements inside this for loop block will run 10 times, the value of $i will be 0 to 9; for ($i = 0; $i < 10; $i++) { # code... } Same thing done with while loop: $i = 0; while ($i < 10) { # code... $i++ } Do-while loop is exit-condition loop. It's guaranteed to execute once, then it will evaluate condition before repeating the block do { # code... } while ($flag == false); foreach is used to access array elements from start to end. At the beginning of foreach loop, the internal pointer of the array is set to the first element of the array, in next step it is set to the 2nd element of the array and so on till the array ends. In the loop block The value of current array item is available as $value and the key of current item is available as $index. foreach ($array as $index => $value) { # code... } You could do the same thing with while loop, like this while (current($array)) { $index = key($array); // to get key of the current element $value = $array[$index]; // to get value of current element # code ... next($array); // advance the internal array pointer of $array } And lastly: [The PHP Manual][1] is your friend :) [1]: http://www.php.net/download-docs.php
I used to use it a lot. This designer worked good for stubbing out prototype projects, but ultimately I found myself wasting a lot of time moving the mouse around when I could be typing. It seemed like an awesome idea to be able to print out the class diagrams to show APIs to other developers while I was prototyping, but it proved quite limiting and it looks awful on a non-color printer. Now I just use the text editor and some [AutoHotkey][1] macros to get everything done. [1]: http://www.autohotkey.com
I am with Brad on this one. The more I work on immensely complex systems, the more I see the need to truly decouple objects. He's right. It's obvious that a needle shouldn't know anything about haystack, so 1 is definitely out. But, a haystack should know nothing about a needle. If I were modeling a haystack, I might implement it as a collection -- but as a collection of *hay* or *straw* -- not a collection of needles! However, I would take into consideration that stuff does get lost in a haystack, but I know nothing about what exactly that stuff. I think it's better to not make the haystack look for items in itself (how *smart* is a haystack anyway). The right approach to me is to have the haystack present a collection of things that are in it, but are not straw or hay or whatever gives a haystack its essence. class Haystack : ISearchableThingsOnAFarm { ICollection<Hay> myHay; ICollection<IStuffSmallEnoughToBeLostInAHaystack> stuffLostInMe; public ICollection<Hay> Hay { get { return myHay; } } public ICollection<IStuffSmallEnoughToBeLostInAHayStack> LostAndFound { get { return stuffLostInMe; } } } class Needle : IStuffSmallEnoughToBeLostInAHaystack { } class Farmer { Search(Haystack haystack, IStuffSmallEnoughToBeLostInAHaystack itemToFind) } There's actually more I was going to type and abstract into interfaces and then I realized how crazy I was getting. Felt like I was in a CS class in college... :P You get the idea. I think going as loosely coupled as possible is a good thing, but maybe I was getting a bit carried away! :)
When to use lambda, when to use Proc.new?
|ruby|
In Ruby 1.8, there are subtle differences between proc/lambda on the one hand, and Proc.new on the other. - What are those differences? - Can you give guidelines on how to decide which one to choose? - In Ruby 1.9, proc and lambda are different. What's the deal?
In Ruby 1.8, there are subtle differences between proc/lambda on the one hand, and Proc.new on the other. - What are those differences? - Can you give guidelines on how to decide which one to choose? - In Ruby 1.9, proc and lambda are different. What's the deal? **Edit** @Mike Stone: there's no difference between 1.8 and 1.9 in this regard. @Accordeon Guy: that's the difference I had in mind, but I don't think it's the whole story. What about next/break/return in procs? What about Ruby 1.9? What about scopes, and returning procs from a method?
Wine is actually using gettimeofday() to implement QueryPerformanceCounter() and it is known to make many Windows games work on Linux and Mac. Starts <http://source.winehq.org/source/dlls/kernel32/cpu.c#L312> leads to <http://source.winehq.org/source/dlls/ntdll/time.c#L448>
Limit size of Queue<T> in .NET?
|.net|collections|queue|
I have a Queue&lt;T&gt; object that I have initialised to a capacity of 2, but obviously that is just the capacity and it keeps expanding as I add items. Is there already an object that automatically dequeues an item when the limit is reached, or is the best solution to create my own inherited class?
You should create your own class, a ringbuffer would probably fit your needs. The data structures in .NET that allows you to specify capacity, except for array, uses this to build the internal data structure used to hold the internal data. For instance, for a list, capacity is used to size an internal array. When you start adding elements to the list, it'll start filling this array from index 0 and up, and when it reaches your capacity, it increases the capacity to a new higher capacity, and continues filling it up.
I've knocked up a basic version of what I'm looking for, it's not perfect but it'll do the job until something better comes along. public class LimitedQueue<T> : Queue<T> { private int limit = -1; public int Limit { get { return limit; } set { limit = value; } } public LimitedQueue(int limit) : base(limit) { this.Limit = limit; } public new void Enqueue(T item) { if (this.Count >= this.Limit) { this.Dequeue(); } base.Enqueue(item); } }
Why wouldn't you just use an array with a size of 2? A Queue is supped to be able to dynamically grow and shrink.
Why wouldn't you just use an array with a size of 2? A Queue is supped to be able to dynamically grow and shrink. Or create a wrapper class around an instance of Queue<T> instance and each time one enqueues a <T> object, check the size of the queue. If larger than 2, dequeue the first item.
Unit testing with network-reliant code
|unit-testing|testing|wmi|
I'm trying to be better about unit testing my code, but right now I'm writing a lot of code that deals with remote systems. SNMP, WMI, that sort of thing. With most classes I can mock up objects to test them, but how do you deal with unit testing a real system? For example, if my class goes out and gets the Win32_LogicalDisk object for a server, how could I possibly unit test it?
Really good feedback is extremely important. Even simple things like making it obvious what can and cannot be clicked can be overlooked or too subtle. Feedback when something might happen in the background is great. In gmail, it's great that there's a status ribbon appearing at the top that let's you know if something is sending or loading, but it's even better that it lets you know that something has sent successfully or is _still_ loading. The "yellow fade" technique is something else made popular amongst the RoR crowd that accomplishes something similar. You never want the user to ask the question, "What just happened?" or "What will happen when I do this?". Another trick that has become more popular lately that I've been using a lot is editing in place. Instead of having a view of some data with a separate "edit" screen (or skipping the view and _only_ having an edit screen), it can often be more user friendly to have a nicely laid out view of some data and just click to edit parts of it. This technique is really only appropriate when reading the data happens more often than editing, and is not appropriate for serious data-entry.
So from the way you worded the question I'm inferring that you want to have an event handler which is invoked whenever focus switches between windows. You want to be notified, rather than having to poll. I actually don't think calling GetFocus from OnIdle is that much of a hack - sure it's polling, but it's low-overhead polling without side effects - but if you really want to track this, [Windows Hooks](http://msdn.microsoft.com/en-us/library/ms997537.aspx) are probably your best choice. Specifically you can install a CBT hook (WH_CBT) and listen for the HCBT_SETFOCUS notification. > Windows calls the WH_CBT hook with this hook code when Windows is about to set the focus to any window. In the case of thread-specific hooks, the window must belong to the thread. If the filter function returns TRUE, the focus does not change. You could also do with with a WH_CALLWNDPROC hook and listen for the WM_SETFOCUS message. Depending on whether you make it a global hook, or app-local, you can track focus across all windows on the system, or only the windows owned by your process.
You could monitor messages for the WM_[ACTIVATE][1] event. [ref][2] [1]: http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputmessages/wm_activate.asp?frame=true [2]: http://blogs.msdn.com/jfoscoding/archive/2006/08/02/686141.aspx
I would probably do something like this in your document class for(var i:int=0; i<numChildren; i++){ trace(getChildAt(i),"This is the child at position "+i); } I do this because I still code in the flash IDE and its debugger is so very painful to get working most of the time it's easier to just trace variables out, so you can either use that for loop to print the object names of the items currently on your stage, or use a debugger program to find the objects as well. Now that you have the children and at what index they actually are at within the stage, you can reference them by calling getChildAt(int), you can removeChildAt(int), you can addChildAt(displayObject, int) and swapChildrenAt(int, int). The int in these arguments would represent the index position that was returned by your trace statement and the displayObject would obviously just represent anything you wanted to add to the stage or parent DisplayObject. Using those 4 commands you should be able to freely re-arrange any movieclips you have on stage so that they will appear to transition seamlessly. @81bronco One should definitely name your assets on stage if you want to uniquely reference them specifically to avoid any confusion if there ends up being a lot of items on stage
Error viewing csproj property pages in VisualStudio2005
|visual-studio|
When I goto view the property page for my CSharp test application I get the following error. "An error occurred trying to load the page. COM object that has been seperated from its underlying RCW cannot be used." The only thing that seems to fix it is rebooting my PC!
We use FinalBuilder to automate a bunch of post build / pre build tasks. There's also a web interface so you can kick off builds (or push websites) by logging in to the web site and clicking a button. http://www.finalbuilder.com/
I found [Factor CSS][1] - complete with source code, but I think it does way more than I'd need. I really just want to combine CSS blocks that have the same selectors. I'll check out the source code and see if it can be converted to something usable as a TextMate bundle. That is, unless someone else manages to get to it before me. [1]: http://zamez.org/factorcss
I found [Factor CSS][1] - complete with source code, but I think it does way more than I'd need. I really just want to combine CSS blocks that have the same selectors. I'll check out the source code and see if it can be converted to something usable as a TextMate bundle. That is, unless someone else manages to get to it before me. EDIT: Even better - here's [a list of web-based tools for checking/formatting/optimizing css][2]. [1]: http://zamez.org/factorcss [2]: http://sixrevisions.com/css/css_code_optimization_formatting_validation/
This is usually caused by a 'rogue' add-in. Try disabling them all, and then re-enabling them checking for the error - so that you can narrow down the culprit.
Can't you edit the Web Deployment project's MSBuild file for it to do what you want?