instruction stringlengths 0 30k ⌀ |
|---|
Mocking constructors in Ruby |
|ruby| |
I'm a Java-developer toying with Ruby, and loving it. I have understood that because of Ruby's metaprogramming facilities my unit-tests become much cleaner and I don't need nasty mocking frameworks. I have a class which needs the `File` class's services and in my test I don't want to touch my real filesystem. In Java I... |
Seems like you are going to have limited options since you want the check to occur before the upload. I think the best you are going to get is to use javascript to validate the extension of the file. You could build a hash of valid extensions and then look to see if the extension of the file being uploaded existed in... |
If you write a helper class with a simple public interface, that greatly reduces the practical tedium of implementation details like use of a `map<map<map<>>>`. The beauty of encapsulation!
That said, you might be able to rig a hashmap to do the trick nicely. Just hash the three doubles together to get the key for... |
It's a long shot but in the first insert the sql date format is valid for both uk/us, the second insert is invalid if the Oracle DB is setup for UK date format, I realise you have used the TO_DATE function but I don't see anything else ... |
You can also skip the hassle of writing .xls format files and use a more generic (but sufficiently Excel-friendly) format such as CSV:
#!/bin/bash
date=`date +%Y/%m/%d:%H:%M:%S`
size=$(ls -lah somefile | awk '{print $5}')
echo "$date,$size"
Then, in your crontab:
0 0 * * * /path/to/scri... |
yes and no.
You can't do:
insert into foo (c1, c2, c3)
values ("v1a", "v2a", "v3a"),
("v1b", "v2b", "v3b"),
("v1c", "v2c", "v3c")
but you can do
insert into foo (c1, c2, c3)
select (v1, v2, v3) from bar
What does that get you if you don't already have the dat... |
>>>>The parameter passing is handled in the online help Note: If you need to pass arguments to your scripts you need to pass -- as the first argument when using the -f switch. This seemed to be working under PHP4, but not under PHP5.
But PHP still doesn't parse those arguments. It just passes them to the script in ... |
Also, although it's bad practice, if there is a return statement within the finally block, it will trump any other return from the regular block. That is, the following block would return false:
try { return true; } finally { return false; }
Same thing with throwing exceptions from the finally block. |
CMMI isn't really about improving your software, it is about documenting what you have done. You can almost estimate a company's CMMI level by the weight of the documentation it produces.
Background: I have studied CMMI in my Software Engineering graduate program and have worked on a team that followed its guideline... |
How to publish wmi classes in .net? |
|c#|.net|.net-3.5|.net-2.0|wmi| |
I've created a seperate assembly with a class that is intended to be
published through wmi. Then I've created a windows forms app that
references that assembly and attempts to publish the class. When I try to
publish the class, I get an exception of type
System.Management.Instrumentation.WmiProviderInstallatio... |
|readdirectorychangesw|.net| |
|.net|windows|readdirectorychangesw| |
Also:
> The Cocotron is an open source project which aims to implement a cross-platform Objective-C API similar to that described by Apple Inc.'s Cocoa documentation. This includes the AppKit, Foundation, Objective-C runtime and support APIs such as CoreGraphics and CoreFoundation.
[http://www.cocotron.org/][1]
... |
How to solve call ambiguity between Generic.IList<T>.this[] and IList.this[]? |
|somebodytagthisplease| |
I've got a collection that implements an interface that extends both IList<T> and List.
public Interface IMySpecialCollection : IList<MyObject>, IList { ... }
That means I have two versions of the indexer.
I wish the generic implementation to be used, so I implement that one normally:
public MyOb... |
|.net|generics|explicit|interface|implementation| |
I've got a collection that implements an interface that extends both IList<T> and List.
public Interface IMySpecialCollection : IList<MyObject>, IList { ... }
That means I have two versions of the indexer.
I wish the generic implementation to be used, so I implement that one normally:
public MyOb... |
|.net|generics|interface|implementation|explicit| |
I've got a collection that implements an interface that extends both IList<T> and List.
public Interface IMySpecialCollection : IList<MyObject>, IList { ... }
That means I have two versions of the indexer.
I wish the generic implementation to be used, so I implement that one normally:
public MyOb... |
I think the answer is "it depends." Java runs on just about anything, but .NET/Mono are (IMHO) a better framework for the desktop. So I guess the answer really depends on what platforms you plan on targeting. |
You do alloc the label, in a sense, by creating it in IB.
What IB does, is look at your IBOutlets and how they are defined. If you have a class variable that IB is to assign a reference to some object, IB will send a retain message to that object for you.
If you are using properties, IB will make use of the prop... |
Sum of items in a collection |
|linq|sum| |
Using LINQ to SQL, I have an Order class with a collection of OrderDetails. The Order Details has a property called LineTotal which gets Qnty x ItemPrice.
I know how to do a new LINQ query of the database to find the order total, but as I already have the collection of OrderDetails from the DB, is there a simple m... |
Have you considered using the money-data type to store dollar-amounts?
Regarding the Con that decimal takes up one more byte, I would say don't care about it. In 1 million rows you will only use 1 more MB and storage is very cheap these days. |
Whatever you do, you need to be careful of rounding errors. Calculate using a greater degree of precision than you display in. |
The only reason to use Float for money is if you don't care about accurate answers. |
Is there a way to asynchronously filter an IList? |
|c#|javascript|ajax|.net-3.5| |
Ok, so there has to be a way to do this... no? If not I'd love some ideas.
I have two repeaters and an image inside an update panel along with some AJAX dropdowns with link buttons to the left. I want to update the data inside the update panel as fast as possible as values are selected from the dropdowns.
W... |
|c#|javascript|ajax|.net-3.5|repeater| |
Ok, so there has to be a way to do this... no? If not I'd love some ideas.
I have two repeaters and an image inside an update panel along with some AJAX dropdowns with link buttons to the left. I want to update the data inside the update panel as fast as possible as values are selected from the dropdowns.
Wha... |
You can't convert Adobe's ActiveX control to 64bit yourself, but you can force your application to run in 32bit mode by setting the platform target to x86.
For instructions for your version of Visual Studio, see section 1.44 of [Issues When Using Microsoft Visual Studio 2005](http://msdn.microsoft.com/en-gb/vstudio/... |
In his book great 'Effective Java' (Second Edition) Joshua Bloch explains what he calls the producer/consumer principle for using generics. Josh's explaination should tell you why your example does not work (compile) ...
Chapter 5 (Generics) is freely available here: <http://java.sun.com/docs/books/effective/generic... |
Many sites have a text box (for searching the site, or something) that is set to automatically take focus when the page loads (using javascript or something). In many browsers, the page will jump to that text box when it gets focus.
It really is very annoying :( |
Drawing a Web Graph |
|asp.net|api|visualization|graph| |
I'm trying to draw a graph on an ASP webpage. I'm hoping an API can be helpful, but so far I have not been able to find one.
The graph contains labeled nodes and unlabeled directional edges.
The ideal output would be something like [this][1].
Anybody know of anything pre-built than can help?
[1]: http:/... |
|asp.net|api|visualization|graph| |
how could I intercept linux sys calls? |
|c|linux| |
Besides the LD_PRELOAD trick , and Linux Kernel Modules that replace a certain syscall with one provided by you , is there any possibility to intercept a syscall ( open for example ) , so that it first goes through your function , before it reaches the actual open ? |
It's really a matter of taste. Factory classes can be abstracted/interfaced away as necessary, whereas factory methods are lighter weight (and also tend to be testable, since they don't have a defined type, but they will require a well-known registration point, akin to a service locator but for locating factory methods... |
There is a configuration property, [soapExtensionTypes][1] that does this, but affects all web services covered by the .config (all of them in the same directory or a sub-directory as the .config)
[1]: http://msdn.microsoft.com/en-us/library/b5e8e7kk(VS.71).aspx |
Also, if you decide to go the registry way, keep in mind that current user associations are under **HKEY_CURRENT_USER\Software\Classes**. It might be better to add your application there instead of local machine classes.
If your program will be run by limited users, you won't be able to modify CLASSES_ROOT anyway. |
Another good option is [FireDaemon][1]. It's used by some big shops like NASA, IBM, etc; see their web site for a full list.
[1]: http://www.firedaemon.com/ |
For Fun I had to look up the Motorolla HC11 Assembly:
org $100
Loop nop
jsr Loop
|
A strongly typed xml field in MSSQL has worked for us. |
It depends on what kind of reports you're talking about. For example... site stats... you could install google analytics and the client could export whatever format they wanted. |
(VB.NET) If you send an Object via a Property's Get accessor into a function with a ByRef keyword, it will actually attempt to update the object using the Set accessor for the Property.
Ex:
UpdateName(ByRef aName as String)
UpdateName(Employee.Name) will attempt to update the name by using the Set on the Name ... |
faster Math.exp() via JNI? |
|java|c|java-native-interface| |
I need to calculate Math.exp() from java very frequently, is it possible to get a native version to run faster than java's Math.exp()??
I tried just jni + C, but it's slower than just plain java. |
<pre><code>
select * from sys.syslogins l inner join sys.sysusers u on l.sid = u.sid
</code></pre>
Will get you going |
<pre><code>
select * from Master.dbo.syslogins l inner join sys.sysusers u on l.sid = u.sid
</code></pre>
This will get you what users are mapped to which logins within a single database.
|
When you have a problem like this, the best way of tracking down the problem is to reduce the page to the minimum necessary to reproduce the problem.
*"Ignore the [x] because I don't think that's the problem"* is no good, if you don't think that's the problem, save it to a temporary static page, delete the things yo... |
Use Java's.
Also, cache results of the exp and then you can look up the answer faster than calculating them again. |
When running a prefix query, Lucene searches for all terms in its "dictionary" that match the query. If more than 1024 (by default) match, the TooManyClauses-Exception is thrown.
You can call BooleanQuery.setMaxClauseCount to increase the maximum number of clauses permitted per BooleanQuery. |
How do you launch the javascript debugger in Google Chrome? |
|javascript|google-chrome|debugging| |
When using Google Chrome, I want to debug some javascript. How can I do that? |
These are the issues that in my opinion are quite controversial and hence prone to misunderstanding:
- In my experience the biggest advantage is producing far better code at the cost of a lot of time spent writing tests. So it's really worthwhile for projects that require high quality, but on some other, less qual... |
It depends on the language. In java you should use loops. Functional languages optimize recursion. S |
Getting ASN.1 Issuer strings from PEM files? |
|apache|openssl|asn.1|schannel| |
I recently came across an issue with Windows 2003 (apparently it also exists in other versions too), where if an SSL/TLS server is requesting client certificate authentication and it has more than 16KB of trusted certificate DNs, Internet Explorer (or any other app that uses schannel.dll) is unable to complete the SSL ... |
Probably the simplest way to speed up such processing is to store the already-processed points in <a href="http://en.wikipedia.org/wiki/Octree">Octree</a>. Checking for duplication will become close to logarithmic.
Also, make sure you tolerate round-off errors by checking the distance between the points, not the equ... |
For an example of why it might be desirable to suppress selection, see [SIMILE TImeline](http://simile.mit.edu/timeline/), which uses drag-and-drop to explore the timeline, during which accidental vertical mouse movement causes the labels to be highlighted unexpectedly, which looks weird. |
**Copying**:
If you frequently work with lines, you might want to make copy (`kill-ring-save`) and cut (`kill-region`) work on lines when no region is selected:
(defadvice kill-ring-save (before slickcopy activate compile)
"When called interactively with no active region, copy a single line instead."
... |
I've got a collection that implements an interface that extends both IList<T> and List.
public Interface IMySpecialCollection : IList<MyObject>, IList { ... }
That means I have two versions of the indexer.
I wish the generic implementation to be used, so I implement that one normally:
public M... |
@Vaibhav: Thanks a lot!
@Jay Bazuzi: I understand what you're saying, but for me it's very important that if a developer is working on a file, it be the lastest version of that file. Otherwise the check in introduces a lot of problems. If for some reason, as a result of the getting latest version, the project doesn'... |
Thanks, from another post someone recommended this [link][1]
[1]: http://www.microsoft.com/msj/0999/journal/journal.aspx |
I've found version 2.0 to be the easiest version to target and deploy since a lot of people have it installed already, If a sizable portion of your client base use Vista you might consider upgrading to 3.0.
Versions above that nearly always require an install which can be a pain for some users.
|
I've found version 2.0 to be the easiest version to target and deploy since a lot of people have it installed already, If a sizable portion of your client base use Vista you might consider upgrading to 3.0.
Versions above that nearly always require an install which can be a pain for some users.
Edit: The "framewor... |
ASP.Net RSS feed |
|asp.net|rss|webforms| |
How do I create an rss feed in ASP.Net? Is there anything built in to support it? If not, what third-party tools are available?
I'm thinking webforms, not MVC, though I suppose since this isn't a traditional page the difference may be minimal. |
Architecture for modeling |
|architecture|modeling|modularity| |
A common solution to building a model of a system which consists of many items of different types is to create a modular system, where each module is responsible for particular type. For example, there will be module for wombats WombatModule:IModule, where IModule interface has methods like GetCount() (to find number o... |
The key here is I need to script this. Is there a cleaner way to extract the service status from `psservice`/`sc query`? I'm able to pipe it to `findstr "RUNNING"`, but there's got to be a better way. |
You will need to be a member of the **db_ddladmin** or the **db_owner** role AFAIK |
Automated processing of an Email in Java |
|java|email|lotus-notes| |
Just got a request from my boss for an application I'm working on. Basically we're getting an email address setup for an external client to submit excel files to.
What I need is a way to automatically pick up any email sent to this address, so I can take the attachment, process it and save it to a folder.
Any in... |
Display blanks instead of 0 or 0.0 in a BIRT report |
|eclipse|reporting|birt| |
When using an aggregate control in some reports you would prefer to see a blank field instead of 0. There does not appear to be a way to do this automatically. Does anyone have a way that this can be done. Note, you want to maintain the '0' value for the field in cases when you export, but you want to show a blank w... |
I agree completely with [InSciTek Jeff][1]'s answer, I'll just add the following refinements:
- Information hiding and encapsulation: Critical for any maintainable code. Can be done by being careful in any programming language, doesn't require OO features, but doing it will make your code slightly OO-like.
- I... |
The [PyXPCOM extension][1] is one possibility.
But looking at what firewatir provides, I have to 2nd the suggestion for twill. It's based on [mechanize][2], which might also be useful in this context.
[1]: https://addons.mozilla.org/en-US/firefox/addon/7620
[2]: http://wwwsearch.sourceforge.net/mechanize/ |
osCommerce is one of those products that was badly designed from the beginning, and becomes basically unmaintainable as time moves forward. Addons are patches, and custom code modifies core. (Unless things have drastically changed since I last looked at it - judging by the version numbers, they have not).
While p... |
You changed to a new directory and want to move a file from the new directory to the old one. In one move: `mv file $OLDPWD` |
A script to svn update on an as needed basis.
SVN supports keywords. You can add which keywords you want to expand to the keywords property, and SVN will expand then. See $Id$ or $Revision$, or keywords in the SVN book.
|
A script to svn update on an as needed basis.
SVN supports keywords. You can add which keywords you want to expand to the keywords property, and SVN will expand then. See $Id$ or $Rev$, or keywords described in the SVN book.
|
I built my own unit testing software. Before executing the test, I store the continuation before executing the test, and then on failure, I (optionally) tell the scheme interpreter to drop into debug mode, and re-invoke the continuation. This way I can step through the problematic code really easily.
If your conti... |