instruction
stringlengths
0
30k
If it is an object then you should just be able to check to see if it is [null][1] or [undefined][2] and then load it if it is. if (myObject === null || myObject === undefined) { myObject = loadObject(); } Using the [typeof][3] function is also an option as it returns the type of the object provi...
if (new DateTime(5000) > new DateTime(1000)) { Console.WriteLine("i win"); }
Yes, however you will need to set your Binding flags to search for private fields (if your looking for the member outside of the class instance). The binding flag you will need is: System.Reflection.BindingFlags.NonPublic
I use IRC at work - it's almost a requirement for all of us who interact remotely (workign from home, different offices, and client sites) to be able to get help on problems fast.
It seems like this is a natural place to use pagination of your Hibernate results -- run the query at the Servlet level, and paginate results in a way similar to how this person describes: <http://blog.hibernate.org/Bloggers/Everyone/Year/2004/Month/08/Day/14#pagination> This is the easiest method of implementing...
How do I ignore files in subversion?
|command|svn|
Also, how do I find files which are not under version control?
You could also just go cheep: Run the files through [tidy][1] and then compare. This will result in similar structures, where new / deleted children will show up with traditional diff tools. It breaks down on removal / addition of surrounding nodes - good luck on soling that one... [1]: http://tidy.sourceforge.n...
You could also just go cheep: Run the files through [tidy][1] and then compare. This will result in similar structures, where new / deleted children will show up with traditional diff tools. It breaks down on removal / addition of surrounding nodes - good luck on solving that one... Also, the [XML Notepad][2] (sorry...
The web service is the best way, but there are some caveats: 1. You should always ask the user if it is ok to send error feedback information. 2. You should be prepared to fail gracefully if there are network errors. Don't let a failure to report a crash impede recovery! 3. You should avoid including user ident...
To ignore all files with the ending .jpg use: svn propset svn:ignore ''*.jpg'' . If you want to ignore multiple files or folders use: svn propedit svn:ignore . This will bring up your text editor so you can enter a list of files or directories to ignore. To find files that are not under version...
(imports System.IO) <pre>if Not Directory.Exists(Path) then Directory.CreateDirectory(Path) end if</pre>
You can use plugin for this, since you can call or even override private methods from within the plugin: var suggested_text_plugin = { init: function(o) { o.onTypeAhead = function() { // Original code from the sources goes here: if(this.st...
Turning on psychic debugging powers (as there's no actual question in your "question"). I' m assuming you're running Linux since it's tagged "bash" and you want a way to do it. After each command, the exit code can be found in the $? variable so you would have something like: ls -al file.ext rc=$? ...
The "w" command will do exactly what you want: <pre> NAME ENTRY TID STATUS DELAY OBJ_TYPE OBJ_ID OBJ_NAME ---------- ---------- ---------- ---------- ----- ---------- ---------- -------- tJobTask 0x1005a6e0 0x103bae00 PEND 0 SEM_B 0x10184088 N/A tExcTask 0x100599...
The best practices method of making this happen is to utilize drupal\_execute. drupal\_execute will run standard validation and basic node operations so that things behave the way the system expects. drupal_execute has its quirks and is slightly less intuitive than simply a node_save, but, in Drupal 6, you can utiliz...
Try [KeyCzar][1] [1]: http://code.google.com/p/keyczar/ Very easy to implement.
"`set -e`" is probably the easiest way to do this. Just put that before any commands in your program.
The best way to detect if they are unable to perform an action is to attempt it and catch the `UnauthorisedAccessException`. However as @<a href="http://stackoverflow.com/users/941/dannysmurf">DannySmurf</a> <a href="http://stackoverflow.com/questions/17533/request-vista-uac-elevation-if-path-is-protected#17544">cor...
When Microsoft got the security religion, DCOM (and the underlying RPC) got a lot of attention, and there definitely were changes made to close security holes that resulted in stricter marshaling. I'm suprised you see this in Vista but not in XP, but its possible that additional checks were added for Vista. Alternati...
Looking around a bit came up with the following... Private Declare Function IsCharAlphaA Lib "user32" Alias "IsCharAlphaA" (ByVal cChar As Byte) As Long I believe IsCharAlphaA tests ANSI character sets and IsCharAlpha tests ASCII. I may be wrong.
Ok, let's assume such an N exists. As onebyone pointed out, a malformed URL that is longer than N characters will be rejected by other input validation anyway. However, in my eyes, this opens up a whole new thing to think about: Using this constant, you can validate your other validation. If the other validations ha...
You might want to look at the SQL Server Management Objects (SMO). There are objects for scripting that will assist in generating T-SQL scripts from database objects. A good reference for this is ["Programming SQL Server 2005"][1] by Bill Hamilton. Chapter 12 in particular references the SMO utility classes. ...
Add a "nowrap" in your td tag...
I don't know MSSQL but would it not be: alter table company drop **constraint** Company_CountryID_FK;
This works pretty well... div.container { min-width: 760px; width:expression(document.body.clientWidth < 760? "760px": "auto" ); }
I also prefer ProGuard for both it's size reduction and breadth of obfuscation - see [http://proguard.sourceforge.net/][1]. I don't necessarily have size constraints other than download speeds, but haven't found anything that shrinks further. [1]: http://proguard.sourceforge.net/
I've always found looking at the unit test the best way to learn how to use an open source project. Castle has a fluent interface that will allow you to do everything in code. From the [WindsorDotNet2Tests][1] test case: [Test] public void ParentResolverIntercetorShouldNotAffectGenericComponentInterceptor()...
If you just want to see if layout is correct, just submit your website to <a href="http://browsershots.org/">BrowserShots.org</a> and visit later to see the screenshots. If you want to test the functionality (JavaScript, etc.) then you'll need to test manually.
It's not clear for me from your example what you're actually trying to achieve. Do you want to return a new XML with all the nodes stripped out except those that fulfill the condition? If yes, then this looks like the job for an XSLT transform which I don't think it's built-in in MSSQL 2005 (can be added as a UDF: [htt...
It's not clear for me from your example what you're actually trying to achieve. Do you want to return a new XML with all the nodes stripped out except those that fulfill the condition? If yes, then this looks like the job for an XSLT transform which I don't think it's built-in in MSSQL 2005 (can be added as a UDF: <htt...
Algorithm::Loops is really nice if you do much of this kind of thing. My own code: sub zip { @_[map $_&1 ? $_>>1 : ($_>>1)+($#_>>1), 1..@_] }
Sounds like you need to be using Sets.
It's just like a normal exception, and uses the same wrapping code as a normal exception would to marshal into a fault, including unwinding the stack. Like exceptions SOAP faults shouldn't, to my mind, be used for program flow, but to indicate errors.
What do you consider the best CMS in Java
|java|content-management-system|
Which CMS are you using in Java and what is your experience with it (in terms of extensibility, usage comfort, framework API, memory usage, performance etc.). I am looking for suggestions.
I believe you're talking about [FTP with SSL][ftps] when you say SFTP, and not the [SFTP protocol that goes along with SSH][sftp]. Use SFTP (the SSH version) as it doesn't require an encrypted control channel and will work fine over NAT. The SFTP page I linked to lists a number of graphical SFTP clients at the bottom o...
An alternative to the code from @Cody: Using the modulus operator: bool isEven = (a % 2) == 0; I think this is marginally better code than writing if/else, because there is less duplication & unused flexibility. It does require a bit more brain power to examine, but the good naming of `isEven` compensate...
Are you sure that response is correct? Parse error mean that there is sth wrong with data being evaluted in line `var t = eval( "(" + request + ")" ) ;`
Automated naming of local datagram sockets?
|datagram|sockets|unix|local|bind|
I'm implementing a simple service using datagrams over unix sockets. The server is bound to a public address, and it receives requests just fine. Unfortunately, when it comes to answering back, `sendto` fails unless the client is bound too. (the common error is `Transport endpoint is not connected`). Binding to s...
Automated naming of AF_UNIX local datagram sockets?
|unix|sockets|bind|datagram|local|
I'm implementing a simple service using datagrams over unix local sockets (AF_UNIX address family, i.e. **not UDP**). The server is bound to a public address, and it receives requests just fine. Unfortunately, when it comes to answering back, `sendto` fails unless the client is bound too. (the common error is `Trans...
Python reading Oracle path
|python|oracle-database|pylons|cx-oracle|
On my desktop I have written a small Pylons app that connects to Oracle. I'm now trying to deploy it to my server which is running Win2k3 x64. (My desktop is 32-bit XP) The Oracle installation on the server is also 64-bit. I was getting errors about loading the OCI dll, so I installed the 32 bit client into C:\ora...
You can use plugin for this, since you can call or even override private methods from within the plugin: var suggested_text_plugin = { init: function(o) { o.onTypeAhead = function() { // Original code from the sources goes here: if(this.st...
You can use plugin for this, since you can call or even override private methods from within the plugin: var suggested_text_plugin = { init: function(o) { o.onTypeAhead = function() { // Original code from the sources goes here: if(this.st...
There are a few factors involved in setting up multiplayer 1. The protocol, it's important that you decide whether you want TCP or UDP. UDP has less overhead but isn't guaranteed delivery. Conversely TCP is more trustworthy. Each game will have their preferred protocol. UDP for instance will work for a first pe...
It may not exactly fall into the 'grep' category, but I couldn't get by on Windows without a utility called [AgentRansack][1]. It's a gui-based "find in files" utility with regex support. It's dead simple to right-click on a folder, hit "ransack.." and find files containing what you're looking for. Extremely fast to...
If you just call exit in the bash with no parameters, it will return the exit code of the last command. Combined with OR the bash should only invoke exit, if the previous command fails. But I haven't tested this. <pre> command1 || exit; command2 || exit; </pre> The Bash will also store the exit code of the la...
Sure. Moving from Struts to an AJAX framework is a very liberating experience. (Though we used JSON rather than XML. Much easier to parse.) However, you need to be aware that it's effectively a full rewrite of your application. Instead of the classic Database/JSP/Actions scheme for MVC, you'll find yourself moving ...
In addition to `pprint.pprint`, `pprint.pformat` is really useful for making readable `__repr__`s. My complex `__repr__`s usually look like so: def __repr__(self): from pprint import pformat return "<ClassName %s>" % pformat({"attrs":self.attrs, ...
Does IBM WebSphere MQ support a 64 bit client on windows?
|c++|64-bit|ibm-mq|
Title says it all :) No, seriously, I'm porting a C++ 32 bit application to 64 bit on windows. The application is a client of IBM WebSphere MQ. It uses the MQ client API. Now, as the port progresses, I'm trying to find a 64 bit client. So far, no luck. Does anyone here happen to know if where I can find one, o...
alter table company drop constraint Company_CountryID_FK
Visual Studio ships with some features that can be helpful for you here: **Generate Method Stub**. When you write a call to a method that doesn't exist, you'll get a little smart tag on the method name, which you can use to generate a method stub based on the parameters you're passing. If you're a keyboard perso...
This will work: ALTER TABLE [dbo].[company] DROP CONSTRAINT [Company_CountryID_FK]
When the build is needed by the team on a regular basis, it's pretty easy. You appoint a team member (rotated periodically) to do the build. If the build process is complicated enough, the team will on its own come up with a way of at least partially automating the build. In the worst case, you'll have to automate the ...
If your program crashes, it's probably because it can't load the library it's dynamically linked with. (As you where saying, this happens when the system can't find a copy of the needed libaries anywhere in the search path). The problem is, that this happens at startup of an application, which the Windows OS does vi...
One use for metaclasses is adding new properties and methods to an instance automatically. For example, if you look at [Django models][1], their definition looks a bit confusing. It looks as if you are only defining class properties: class Person(models.Model): first_name = models.CharField(max_lengt...
May I recommend [browsershots][1] where you can submit pages and have them rendered out in a variety of browsers with various things set on or off such as Flash and JavaScript. I'd also recommend that you develop mainly in Firefox and regularly check it in IE6 as you work. IE6 is the one that will mostly screw up so...
May I recommend [browsershots][1] where you can submit pages and have them rendered out in a variety of browsers with various things set on or off such as Flash and JavaScript. At the end of the day you will still want to install FF, IE6-8, Opera and Safari/Chrome for testing manually. Also, if you've got a friend with...
public sealed class Singleton { private static readonly Singleton instance = new Singleton(); private Singleton(){} public static Singleton Instance { get { return instance; } } } There's [no ambigui...
There is an infinite number of things one could learn. Maybe a better approach would be to think of a project that interests you, or join an open source one, and then learn what you need to know to accomplish what is needed in that project. When you're done, pick a new project that might include new things not learned ...
Use VB.NET! No: really ;) using Microsoft.VisualBasic.ApplicationServices; The WindowsFormsApplicationBase from VB.Net provides you with a "SingleInstace" Property, which determines other Instances and let only one Instance run.
Are delegates not just shorthand interfaces?
|c#|interface|delegates|
Suppose we have: interface Foo { bool Func(int x); } class Bar: Foo { bool Func(int x) { return (x>0); } } class Baz: Foo { bool Func(int x) { return (x<0); } } Now we can toss around Bar and B...
I think the best you can do is set a threshold for "visiting a page." Have an automated task run every 60, 120, 300, or some number of seconds that clears out any entry that is older than a specified amount of time. There is no way to reliably detect (that I am aware of) when a user leaves a page. The best you can do i...
I'm not sure what you mean by "loaded"... does the variable `object` exist and simply doesn't have the type you want? In that case, you'll want something like: function isObjectType(obj, type) { return !!(obj && type && type.prototype && obj.constructor == type.prototype.constructor); } and then...
As far as free sources are concerned, as a .NET programmer I like www.asp.net, and there are many others, such as the ASP.NET quickstart tutorials at [http://quickstarts.asp.net/QuickStartv20/default.aspx][1], [C-SharpCorner][2] is good, too, if you don't mind C#. If you don't object to paying a little money, Lynda...
It turns out that rails uses something called Multi-parameter assignment to transmit dates and times in small parts that are reassembled when you assign params to the model instance. My problem was that I was using a datetime_select form field for a date model field. It apparently chokes when the multi-parameter mag...
The way to do this with random number generators is to integrate the probabiliity density function. With a set of discrete values you can calculate the prefix sum (sum of all values up to this one) and store it. With this you select the minumum prefix sum (aggregate to date) value greater than the random number. ...
Why not have an image for all possible outcomes for the pins? No Messing with layouts for browsers an image is an image
Why not have an image for all possible outcomes for the pins? No Messing with layouts for browsers an image is an image Generate them on the fly caching the created images for reuse.
What Does ActiveRecord::MultiparameterAssignmentErrors Mean?
|ruby-on-rails|datetime-select|forms|multiparameter|
I have a rails form with a datetime_select field. When I try to submit the form, I get the following exception: ActiveRecord::MultiparameterAssignmentErrors in WidgetsController#update 1 error(s) on assignment of multiparameter attributes If it's a validation error, why don't I see an error on the page?
|ruby-on-rails|forms|datetime-select|multiparameter|
I have a rails form with a datetime_select field. When I try to submit the form, I get the following exception: ActiveRecord::MultiparameterAssignmentErrors in WidgetsController#update 1 error(s) on assignment of multiparameter attributes If it's a validation error, why don't I see an error on the page?...
How can I initialize Zend_Form_Element_Select with a config array?
|php|html|zend-framework|
I tried: $form->addElement( 'select', 'salutation', array( 'required' => true, 'options' => array( 'Mr.' => 'Mr.', ...
It is possible that ReSharper is running its Test Runner as a separate process, and that separate process is not using your Windows identity but, instead, another one with lower privileges. You might be able to verify this opening Task Manager and checking Show processes from all users.
I think what he's asking here is how you wire up javascript functions to work hand in hand with your ASP.NET post back functionality. i.e. How can I trigger a control's event using my own Javascript. The ASP.NET class library contains a ClientScript class - Found in the System.Web.UI.Page class - which enables yo...
*What languages/environments have you used for developing scientific software, esp. data analysis? What libraries? (E.g., what do you use for plotting?)* I used to work for [Enthought][1], the primary corporate sponsor of [SciPy][2]. We collaborated with scientists from the companies that contracted Enthought for cu...
Reasons of getting a java.lang.VerifyError
|java|exception|deployment|
I'm investigating the following java.lang.VerifyError java.lang.VerifyError: (class: be/post/ehr/wfm/application/serviceorganization/report/DisplayReportServlet, method: getMonthData signature: (IILjava/util/Collection;Ljava/util/Collection;Ljava/util/HashMap;Ljava/util/Collection;Ljava/util/Locale;Lorg/apache/s...
Sure. Moving from Struts to an AJAX framework is a very liberating experience. (Though we used JSON rather than XML. Much easier to parse.) However, you need to be aware that it's effectively a full rewrite of your application. Instead of the classic Database/JSP/Actions scheme for MVC, you'll find yourself moving ...
Sure. Moving from Struts to an AJAX framework is a very liberating experience. (Though we used JSON rather than XML. Much easier to parse.) However, you need to be aware that it's effectively a full rewrite of your application. Instead of the classic Database/JSP/Actions scheme for MVC, you'll find yourself moving ...
Why would one use REST instead of Web services?
|web-services|rest|
Attended an interesting demo on REST today, however, I couldn't think of a single reason (nor was one presented) why REST is in anyway better or simpler to use and implement than a Web Services stack. What are some of the reasons Why anyone in the "real world" use REST instead of the Web Services?