instruction
stringlengths
0
30k
|javascript|namespace|
I've got a JavaScript "object", built this way: function foo() { this.length = 0; } foo.prototype.getLength = function() { return this.length; } ... I know how to emulate namespaces with singleton JavaScript objects, but what is the best way to "namepace...
Return collection as read-only
|c#|.net|multithreading|collections|concurrency|
I have an object in a multi-threaded environment that maintains a collection of information, e.g.: public IList<string> Data { get { return data; } } I currently have `return data;` wrapped by a `ReaderWriterLockSlim` to protect the collection from sharing violations. Howe...
Seeing as it's SQL Server 2005, any reason not to use a CLR stored procedure? You could use your CLR language of choice then and it'd probably be a relatively direct port of your existing Delphi code.
If your underlying data is stored as list you can use [List(T).AsReadOnly][1] method. If your data can be enumerated, you can use [Enumerable.ToList][2] method to cast your collection to List and call AsReadOnly on it. [1]: http://msdn.microsoft.com/en-us/library/e78dcd75.aspx [2]: http://msdn.microsoft.co...
There are only 3 ways to generate unique values, rather they be passwords, user IDs, etc.: 1. Use an effective GUID generator - these are long and cannot be shrunk or only use part or **you FAIL**. 2. At least part of the number is sequentially generated off of a single sequence. You can add fluff to make it l...
There are only 3 ways to generate unique values, rather they be passwords, user IDs, etc.: 1. Use an effective GUID generator - these are long and cannot be shrunk. If you only use part or **you FAIL**. 2. At least part of the number is sequentially generated off of a single sequence. You can add fluff or enco...
If I'm using your site, "average" doesn't matter. All I care about is MY experience, and so you either need to make the site adaptive, design for a pretty low speed (iPhone 2G gets you 70-80 kbps if you're lucky, to take one common case), or be very clear about the requirements so I can decide whether or not my conne...
Wow! Big question! :) Correct me if I'm wrong. Your basic solution now is kind of an Observer pattern, where the data object (Account, etc) notifies about changes in their states. You think that the problem is that the subscribing plugin has to register in every object to be able to handle notifications. That's n...
It will have to get a hell of a lot simpler, with easier-to-remember IDs.
Or do a non-recursive checkout of /trunk, then just do a manual update on the 3 directories you need.
Not in any especially useful way, no. You can check out subtrees (as in Bobby Jack's suggestion), but then you lose the ability to update/commit them atomically; to do that, they need to be placed under their common parent, and as soon as you check out the common parent, you'll download everything under that parent. ...
Sort of. As Bobby says: svn co file:///.../trunk/foo file:///.../trunk/bar file:///.../trunk/hum will get the folders, but you will get separate folders from a subversion perspective. You will have to go separate commits and updates on each subfolder. I don't believe you can checkout a partial tree and t...
the FK_Contraints are set up like this: ALTER TABLE [dbo].[e2] WITH CHECK ADD CONSTRAINT [FK_e2_e1] FOREIGN KEY([E1Id]) REFERENCES [dbo].[e1] ([Id]) ALTER TABLE [dbo].[e3] WITH CHECK ADD CONSTRAINT [FK_e3_e2] FOREIGN KEY([E2Id]) REFERENCES [dbo].[e2] ([Id]) is this what you were asking for?
As someone who primarily programs web apps in Java, I can't/won't use OpenID because the library support isn't there. [JOID][1] and [openid4java][2] are the only two that I know of. JOID is apparently not actively maintained, not including really important patches that have been on the mailing list for months; and op...
For this type of tasks, I use my own [AutoIt](http://www.autoitscript.com/autoit3/) script (freeware, Windows only). The script redirects the standard output into a graphical window, displaying it with the ability to scroll back, etc (very useful in long processes like XCOPYs / PKZIPs to check if any error did happen)....
How can you find out where the style for a ASP .Net web page element came from?
|c#|asp.net|css|themes|
I have a quandary. My web application (C#, .Net 3.0, etc) has Themes, CSS sheets and, of course, inline style definitions. Now that's alot of chefs adding stuff to the soup. All of this results, not surprisingly, in my pages having bizarre styling on occasion. I am sure that all these styles are applied in a hier...
> What are the performance implications of doing this? We use a system based on something like the above mentioned, where each C# script is compiled to an in-memory assembly and executed in a seperate AppDomain. There's no caching system yet, so they scripts are recompiled every time they run. I've done some simple ...
You could create a helper class which wrapped the UriBuilder class in System.Net public static class UriHelper { private static readonly UriBuilder _builder = new UriBuilder("http://localhost"); public static string NormalizeRelativePath(string path) { _builder.Path = pat...
You could create a helper class which wrapped the UriBuilder class in System.Net public static class UriHelper { public static string NormalizeRelativePath(string path) { UriBuilder _builder = new UriBuilder("http://localhost"); builder.Path = path; return builder.Uri.A...
One website I use has a translation method the owner calls "wiki + machine translation". This is a community based site so is obviously different to the needs of companies. http://blog.bookmooch.com/2007/09/23/how-bookmooch-does-its-translations/
I haven't used Marlon's, but I have used [Kevin Moore's][1]. At the time I used it, there were a number of bugs I had to [work around][2]. Other than those issues, it did seem to work well enough. HTH, Kent [1]: http://j832.com/bagotricks/ [2]: http://kentb.blogspot.com/2007/07/wpf-and-date-entry.html
I'm not 100% sure if this can be accomplished without the stub, but this article may provide some insight: [How To: ClickOnce deployment for unmanaged app with COM component in managed assembly ][1] [1]: http://blogs.msdn.com/g/archive/2008/06/06/sample-demonstrating-clickonce-deployment-of-com-component-impl...
You can have a look at what Ayende is saying here : [MultiTable Entities][1]. But since you have separate tables , i don't think it will work. You can also check out [nhuser group][2] [1]: http://www.ayende.com/Blog/archive/2007/04/24/Multi-Table-Entities-in-NHibernate.aspx [2]: http://groups.google.co...
[This article][1] explain an technique of #include removing by using the parsing of Doxygen. That's just a perl script, so that's quite easy to use. [1]: http://www.gamesfromwithin.com/articles/0403/000011.html
[This article][1] explains a technique of #include removing by using the parsing of Doxygen. That's just a perl script, so it's quite easy to use. [1]: http://www.gamesfromwithin.com/articles/0403/000011.html
[Ghost Docs][1] > <summary> GhostDoc is a free add-in for Visual Studio that automatically generates XML documentation comments for C#. Either by using existing documentation inherited from base classes or implemented interfaces, or by deducing comments from name and type of e.g. methods, properties or parameter...
[Ghost Docs][1] > <summary> GhostDoc is a free add-in for Visual Studio that automatically generates XML documentation comments for C#. Either by using existing documentation inherited from base classes or implemented interfaces, or by deducing comments from name and type of e.g. methods, properties or parameter...
You might have some luck using [OpenEmbedded][1]. If there's no precompiled version you can use right away, setting up an OE-cross compile environment is not that hard. Another option could be to install gdb-server on the board, like described in [this blogpost][2]. [1]: http://wiki.openembedded.net/index.ph...
If you're using jQuery then you have loads of [CSS selectors and jQuery custome selectors][1] at your disposal to target elements on your page. So rather than picking out a submit button by it's id, you could do something like: $('fieldset > input[type="submit"]').click(function() {...}); [1]: http://docs...
XMLDataSource is designed to be used with data-bound controls. ASP.NET's TextBox is not a data-bound control. So to accomplish what you want you either have to find a textbox control with data binding or display the result in some other way. For example, you could use a [Repeater control][1] and create your own ren...
I think the best thing that extension methods replace are all those utility classes that you find in every project. At least for now, I feel that any other use of Extension methods would cause confusion in the workplace. My two bits.
I prefer to use the underscore prefix for private fields. I use lowercase first letter for the method parameters. I follow the guideline of having lowercase camelcase parameters for methods, which I regard as more important than the naming of private fields since it is part of the API for the class. . e.g. Pu...
Printing from a Windows service is really painful. It seems to work... sometimes... but finally it craches or throws an exception from time to time, without any clear reason. It's really hopeless. Officially, it's even [not supported][1], without any explanation, nor any proposal for an alternate solution. Recently,...
The `__doPostBack()` method works well. Another solution (very hackish) is to simply add an invisible ASP button in your markup and click it with a javascript method. <div style="display: none;"> <asp:Button runat="server" ... OnClick="ButtonClickHandlerMethod" /> </div> From your javascript, ...
Through a combination of the suggestions I got, I came up with this: private void DrawLetter() { Graphics g = this.CreateGraphics(); float width = ((float)this.ClientRectangle.Width); float height = ((float)this.ClientRectangle.Width); float em...
|javascript|namespaces|
How do you check in Python under Linux if a process is running?
|python|linux|process|
The only *nice* way I've found is: import sys import os try: os.kill(int(sys.argv[1]), 0) print "Running" except: print "Not running" ([Source](http://www.unix.com/unix-advanced-expert-users/79267-trick-bash-scripters-check-if-process-running.html)) ...
How do you check in Linux with Python if a process is still running?
|python|linux|processes|
Create DB in Sql Server based on Visio Data Model
|sql-server|database|script|visio|
I have created a database model in Visio Professional (2003). I know that the Enterprise version has the ability to create a DB in Sql Server based on the data in Visio. I do not have the option to install Enterprise. Aside from going through the entire thing one table and relationship at a time and creating the whole ...
|sql-server|database|scripting|visio|
How do you find the age of a long-running Linux process?
|linux|bash|process|
I have a problem with some zombie-like processes on a certain server that need to be killed every now and then. How can I best identify the ones that have run for longer than an hour or so?
|linux|bash|processes|
Passing switches to Xcode 3.1 user scripts
|script|xcode|arguments|
I have a user script that would be much more useful if it could dynamically change some of its execution dependent on what the user wanted. Passing simple switches would easily solve this problem but I don't see any way to do it. I also tried embedding a keyword in the script name, but Xcode copies the script to a ...
I have a user script that would be much more useful if it could dynamically change some of its execution dependent on what the user wanted. Passing simple switches would easily solve this problem but I don't see any way to do it. I also tried embedding a keyword in the script name, but Xcode copies the script to a ...
Automated testing keeps humans from doing a machine's job. Test-driven development maximizes the amount of automated testing. Beyond a certain point, of course, a human is still required. You reach diminishing returns when you try to apply TDD beyond that point.
TDD helps you design your software. The tests becomes the design. By writing the test first you think about your code from a consumer perspective, making a more user friendly and more compact software design. Also, by applying TDD you typically end up writing your code in a way where you can supply test mocks and st...
The real benefit of TDD is *supposed* to be that it allows you to modify/refactor/enhance your application without worrying about whether you've broken existing functionality. The fact that writing unit tests tends to result in loosely coupled code and better architecture isn't necessarily the *point* of TDD, but I th...
The real improvement is that it is a good way to force you to really think through the design and implementation. Then, once you've prepared the tests and written the code, solutions to unforeseen problems appear more easily. Something that usually happens to me that is a good analogy: When I'm going to post a quest...
It's early yet, but have you considered trying to use [MEF][1] instead of rolling your own? [1]: http://www.codeplex.com/MEF
Specifically, like this in C#: #if (DEBUG) Debug Stuff #endif C# has the following preprocessor directives: #if #else #elif // Else If #endif #define #undef // Undefine #warning // Causes the preprocessor to fire warning #error // Causes the preprocesso...
Making a lot of unwarranted assumptions, I think that the best approach would be to create a Factory that will receive the list of key value pairs and return the proper object or throw an exception if it's invalid (or create a dummy object, or whatever is better in the particular case). ` private class Factory { ...
The only way would be to convert your text field into an nvarchar field. Select Cast(notes as nvarchar(4000)) + 'SomeText' From NotesTable a Otherwise, I suggest doing the concatenation in your application.
If you think more objects is more object-oriented then yes. When doing object oriented design there are a couple of forces you have to balance. Most of OO design is about reducing and handling complexity. So if you get very complex solutions you're not doing too much OO but you're doing it wrong.
I like to sketch out a design with pen & paper. Seriously. No computer. Layout the home screen, including a navigation bar. From here, think about what you'd like 2nd and 3rd tier pages to look like. I've found that this process of writing things out on paper really helps me think about what I want out of the site. ...
Ctrl-P and Ctrl-N are kind of pseudo code completion. They basically search the file you are editing (and any open buffers, and if you are using TAGS anything in your TAG file) for words that start with what you are typing and add a drop down list. It works surprisingly well for variables and function names, even if ...
Ctrl-P (Get Previous Match) and Ctrl-N (Get Next Match) are kind of pseudo code completion. They basically search the file (Backwards for Ctrl-P, Forwards for Ctrl-N) you are editing (and any open buffers, and if you are using TAGS anything in your TAG file) for words that start with what you are typing and add a drop...
You can solve the Airspace problem by using .net 3.5 SP1: > These types of airspace restrictions > represent a huge limitation in a > framework, like WPF, where element > composition is used to create very > rich user experiences. With a D3DImage > solution, these restrictions are no > longer present! See [...
The way we work it is: There must be a good reason to refactor the code, otherwise why? If the reason is to allow another feature to use the same code, associate the changes with the other feature's request. If it's to make something faster, create a feature request for faster 'xyz' and associate the changes with...
The way we work it is: There must be a good reason to refactor the code, otherwise why? If the reason is to allow another feature to use the same code, associate the changes with the other feature's request. If it's to make something faster, create a feature request for faster 'xyz' and associate the changes with...
When do function-level static variables get allocated/initialized?
|c++|c|variables|
I'm quite confident that globally declared variables get allocated (and initialized, if applicable) at program start time. int globalgarbage; unsigned int anumber = 42; But what about static ones defined within a function? void doSomething() { static bool globalish = true; // .....
This is really ugly and there may be some issues with the string replacement, but it produces the expected results: public static class JSonify { public static string GetJsonTable<T>( this IQueryable<T> query, int pageNumber, int pageSize, string IDColumnName, string[] columnNames) { ...
I had the exact same experience from Day One working with Oracle stored procedures - "I have to use NOTEPAD?! Oh HELL no." So I hopped on the internets and what I found were people saying "Hey, I have to create stored procedures in Oracle, isn't there anything better than NOTEPAD?!" And the canonical answer was: ...
If you mean extends in the Base class sense, then in Java... no. But you can extend an enum value to have properties and methods if that's what you mean. For example, the following uses a Bracket enum: class Person { enum Bracket { Low(0, 12000), Middle(12000, 60000), ...
Making a lot of unwarranted assumptions, I think that the best approach would be to create a Factory that will receive the list of key value pairs and return the proper object or throw an exception if it's invalid (or create a dummy object, or whatever is better in the particular case). private class Factory {...
Making a lot of unwarranted assumptions, I think that the best approach would be to create a Factory that will receive the list of key value pairs and return the proper object or throw an exception if it's invalid (or create a dummy object, or whatever is better in the particular case). private class Factory {...
I'd use it if I could do it per-site and aggregate the identity later on my own time and terms. As it is, it's a giant pain in the ass to even find a decent OpenID provider; by decent I mean stackoverflow.com isn't one so I'm not going to bother. MSN
It will take all the popular sites supporting it an making it transparent to the user. "You can make a useraccount here, or if you use MySpace, Google Mail, Hotmail, etc then you can sign in using OpenID." Don't sell it as a new service, sell it as being able to sign in using a different ID from another site. ...
For a .NET component that will be used in both web applications and rich client applications, there seem to be two obvious options for caching: System.Web.Caching or the Ent. Lib. Caching Block. - What do you use? - Why? ## [System.Web.Caching](http://msdn.microsoft.com/en-us/library/system.web.caching.aspx) ...
Enterprise Library CacheFactory.GetCacheManager Throws Null Ref
|c#|configuration|enterpriselibrary|
I'm trying to convert an application using the 1.1 version of the Enterprise Library Caching block over to the 2.0 version. I think where I'm really having a problem is that the configuration for the different EntLib pieces was split out over several files. Apparently, this used to be handled by the **ConfigurationMa...
|c#|configuration|enterprise-library|
add preddefined data for typedef enums in c
|c|enum|typedef|
What is the best approach to define additional data for typedef enums in C? Example: typedef enum { kVizsla = 0, kTerrier = 3, kYellowLab = 10 } DogType; Now I would like to define names for each, for example kVizsla should be "vizsla". I currently use a function that returns a...
MySQL replication for fallback scenario
|mysql|replication|binary-log|fallback|
When I have two mysql servers that have different jobs (holding different databases) but want to be able to use one of them to slip in when the other one fails, what would you suggest how I keep the data on both of them equal "close to realtime"? Obviously it's not possible to make a full database dump every x minu...
Your HttpServletRequest object has a getParameter(String paramName) method that can be used to get parameter values. <http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getParameter(java.lang.String)> Edit: updated the link to the Java EE 5 docs
Your HttpServletRequest object has a getParameter(String paramName) method that can be used to get parameter values. <http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getParameter(java.lang.String)>
> I would focus first on your indexes, than have a server admin look at your OS, and if all that doesn't help it might be time for a master/slave configuration. That's true. Another thing that usually works is to just reduce the quantity of data that's repeadetly worked with. If you have "old data" and "new data" an...
Trust me, you will spend more money trying to search/develop a solution for this as compared to buying a third party component. Do not reinvent the wheel and go for the paid solution. Printing is a complex problem and I would love to see the day when better framework support is added for this.
Here is a good case for regular expressions. You can run a find and replace on the data either before you import (easier) or later on if the SQL import accepted those characters (not nearly as easy). But in either case, you have any number of methods to do a find and replace, be it editors, scripting languages, GUI p...
Binary log is definitely the way to go. However, you should be aware that with MySQL you can't just flip back and forth between servers like that. One server will be the master and the other will be the slave. You write/read to the master, but can only read from the slave server. If you ever write to the slave, they...