instruction stringlengths 0 30k ⌀ |
|---|
When I am running the following statement:
@filtered = map {s/ //g} @outdata;
it is returning an empty list instead of the filtered list that I expected. What I am trying to do is remove every occurance of ` ` from an array of string (which is an XML file).
Obviously, I am not understanding some... |
|perl|maps| |
Mapping values from two array in Ruby |
|ruby|map|reduce| |
I'm wondering if there's a way to do what I can do below with Python, in Ruby:
sum = reduce(lambda x, y: x + y, map(lambda x, y: x * y, weights, data))
I have two arrays of equal sizes with the weights and data but I can't seem to find a function similar to map in Ruby, reduce I have working. |
|ruby|maps|reduce| |
LINQ, delete, IEntity interface |
|c#|linq|repository| |
I'm using repository pattern with LINQ, have IRepository.DeleteOnSubmit(T Entity). It works fine, but when my entity class has interface, like this:
public interface IEntity { int ID {get;set;} }
public partial class MyEntity: IEntity {
public int ID {
get { return this.IDfield;... |
LINQ, entity that implements Interface and exception in mapping |
|c#|linq|repository| |
How do I calculate distance between two latitude longitude points? |
|math|map|mapping|latitude|longitude| |
Here's an easy one for you:
How do I calculate the distance between two points points specified by latitude and longitude? |
Here's an easy one for you:
How do I calculate the distance between two points points specified by latitude and longitude?
EDIT: For clarification, I'd like the distance in kilometres |
Here's an easy one for you:
How do I calculate the distance between two points points specified by latitude and longitude?
EDIT: For clarification, I'd like the distance in kilometres, the points use the WGS84 system and I'd like to understand the relative accuracies of the approaches available. |
Help with aggressive JavaScript caching |
|javascript|caching| |
I've run into a problem where I make changes to a few JavaScript files that are referenced in an HTML file, but the browser doesn't see the changes. It holds onto the copy cached in the browser, even though the web server has a newer version.
Not until I force the browser to clear the cache do I see the changes.
... |
You don't mention a language for this but if you are looking for a really nice Objective-C wrapper around getopt then Dave Dribin's DDCLI framework is really nice.
<http://www.dribin.org/dave/blog/archives/2008/04/29/ddcli>
|
I use the [Getopts::std][1] and [Getopts::long][2] in perl and also the [Getopt][3] function in C. This standardises the parsing and format of parameters. Other languages have different mechanisms for handling these.
Hope this helps
[1]: http://perldoc.perl.org/Getopt/Std.html
[2]: http://perldoc.perl.or... |
The standard design usually follows what getopt does, there are getopt libraries for many languages, .NET, python, C, Perl, PHP, etc.
The basic design is to have a command line parser which returns part by part the arguments passed to be checked in a loop.
[This][1] article discusses it in some more detail.
... |
How do I list user defined types in a SQL Server database? |
|sql-server| |
I need to enumerate all the user defined types created in a SQL Server database with CREATE TYPE, and/or find out whether they have already been defined.
With tables or stored procedures I'd do something like this:
if exists (select * from dbo.sysobjects where name='foobar' and xtype='U')
drop table ... |
I am also of the method of just renaming things. It never fails, and is fairly easy to do. |
Paper prototyping baby - post-its on a whiteboard (so you can move them around and keep the relationships fluid without having to modify the page ideas themselves). Then of course, once you get down to the nitty-gritty of interface design, 'zoom in' on each of those post-its and use them to represent individual elemen... |
The problem is not with your delegate definition, it's that the parameter of the Do() method is of type System.Delegate, and the compiler generated delegate type (FakeSave) does not implicitly convert to System.Delegate.
Try adding a cast in front of your anonymous delegate:
Expect.Call(delegate { _dao.Save(t... |
lock should be used around the code that modifies shared state, state that is modified by other threads concurrently, and those other treads must take the same lock.
A lock is actually a memory access serializer, the threads (that take the lock) will wait on the lock to enter until the current thread exits the lock... |
Best way to extract data from a FileMaker Pro database in a script? |
|python|linux|perl|scripting|filemaker| |
My job would be easier, or at least less tedious if I could come up with an automated way (preferably in a Python script) to extract useful information from a FileMaker Pro database. I am working on Linux machine and the FileMaker database is on the same LAN running on an OS X machine. I can log into the webby interfac... |
My job would be easier, or at least less tedious if I could come up with an automated way (preferably in a Python script) to extract useful information from a FileMaker Pro database. I am working on Linux machine and the FileMaker database is on the same LAN running on an OS X machine. I can log into the webby interfac... |
My job would be easier, or at least less tedious if I could come up with an automated way (preferably in a Python script) to extract useful information from a FileMaker Pro database. I am working on Linux machine and the FileMaker database is on the same LAN running on an OS X machine. I can log into the webby interfac... |
SQL Query for size of a nvarchar(max) column |
|sql| |
I have a column which is of type nvarchar(max). How do I find the length of the string (or the number of bytes) for the column for each row in the table? |
If you really want to see all the gory details of how List<> and Dictionary<,> are implemented, use the wonderfully useful [.NET Reflector][1].
See also the documentation for the excellent [C5 Generic Collection Library][2], which has very good implementations of a number of collection types missing from the BCL.
... |
Check out [Frinika][1]. It's a full-featured music workstation implemented in Java (open source). Using the API, you can run midi events through the synthesizer, read the raw sound output, and write it to a WAV file (see source code link below).
Additional information:
- [Frinika Developer Area][2]
- [Source... |
CruiseControl.NET is your best option, in my opinion. It is fairly easy to extend with custom tasks if needed, works with both NAnt and MSBuild out of the box, and is very actively maintained. |
> SELECT LEN(columnName) AS MyLength
> FROM myTable |
This can happen if ASP.NET isn't installed. Go to Add/Remove Windows Components and look under IIS; make sure that ASP.NET is checked (meaning that it's installed.) That should clear up your problem! |
If you want to find out the max there should be a way for you to get the schema of the table. Normally you can do something like [SHOW COLUMNS](http://dev.mysql.com/doc/refman/5.0/en/show-columns.html) in SQL or a [DESCRIBE](http://dev.mysql.com/doc/refman/5.0/en/describe.html) style command. In a mysql shell that ca... |
If you want to find out the max there should be a way for you to get the schema of the table. Normally you can do something like [SHOW COLUMNS](http://dev.mysql.com/doc/refman/5.0/en/show-columns.html) in SQL or a [DESCRIBE](http://dev.mysql.com/doc/refman/5.0/en/describe.html) style command. In a mysql shell that ca... |
Eval and Bind both suck.
Why get the property through reflection? You can access it directly like this:
<pre>
((MyObject)Container.DataItem).MyProperty
</pre>
It's not like the object is unknown to you at runtime. That's my two cents, anyhow. |
As another option, you could use a monospace/terminal font like courier for printing the passwords. Similar characters should be a lot more distinguishable that way. |
I agree, but don't the cc if you don't need too. But if you really have too, make sure the file that have it is not accessible on the web. You can write a binary that would return the key. This way it's not store in clear text. But if your server is compromise it's still easy to get it. |
You also may want to check for circular project references. It was an issue for me once.
That is:
Project A references Project B
Project B references Project C
Project C references Project A |
How do you use FogBugz with an Agile methodology? |
|agile|fogbugz|schedule| |
"Evidence-based scheduling" in FogBugz is interesting, but how do I use it w/ an Agile methodology? |
In these situations when you have a public API, and you would like private and public methods/properties, I always use the Module Pattern. This pattern was made popular within the YUI library, and the details can be found here:
[http://yuiblog.com/blog/2007/06/12/module-pattern/][1]
[1]: http://yuiblog.com/bl... |
You can add folders to your solution for each namespace. While it'll still compile to a single executable, it organizes your source files and gives (what I think is) the desired effect?
I typically add a folder for each namespace in my project, and nest them according to the same hierarchy (MyApp.View.Dialogs for e... |
For the service to talk to the desktop, you're pretty much stuck with one of the RPC mechanisms. The .NET remoting mechanism ([IpcServerChannel][1]) isn't to hard to implement for this purpose.
Also with .NET a desktop application can send messages directly to the service with the [ServiceController.ExecuteCommand]... |
We append a product build number to the end of all Javascript (and CSS etc.) like so:
<script src="MyScript.js?4.0.8243">
Browsers ignore everything after the question mark but upgrades cause a new URL which means cache-reload.
This has the additional benefit that you can set HTTP headers that mean "never ... |
The NSTask and Unix domain socket approaches are both great suggestions. Something to keep an eye on is an Erlang FFI implementation that's in the works:
<a href="http://muvara.org/crs4/erlang/ffi/">http://muvara.org/crs4/erlang/ffi</a> |
is your webserver sending the right headers to tell the browser it has a new version? I've also added the date to the querystring before. ie myscripts.js?date=4/14/2008 12:45:03 (only the date would be encoded) |
Getopt is the only way to go.
http://sourceforge.net/projects/csharpoptparse |
Chromium supports [NPAPI](http://en.wikipedia.org/wiki/NPAPI) plugins which is harder to program compared to Firefox extensions. However NPAPI has better performance and is more versatile.
Checkout this [minimalistic example of an NPAPI plugin.](http://git.webvm.net/?p=npsimple) |
I think anything can be "overdone". This is true with nearly every best practice I can think of. I've seen inheritance chains so complex, the code was virtually unmanageable. |
SELECT DISTINCT a,b,c FROM t
is _roughly_ equivalent to:
SELECT a,b,c FROM t GROUP BY a,b,c
It's a good idea to get used to the GROUP BY syntax, as it's more powerful. |
SELECT DISTINCT a,b,c FROM t
is _roughly_ equivalent to:
SELECT a,b,c FROM t GROUP BY a,b,c
It's a good idea to get used to the GROUP BY syntax, as it's more powerful.
For your query, I'd do it like this:
UPDATE sales
SET status='ACTIVE'
WHERE in IN
(
SELECT id
... |
SELECT DISTINCT a,b,c FROM t
is _roughly_ equivalent to:
SELECT a,b,c FROM t GROUP BY a,b,c
It's a good idea to get used to the GROUP BY syntax, as it's more powerful.
For your query, I'd do it like this:
UPDATE sales
SET status='ACTIVE'
WHERE id IN
(
SELECT id
... |
Storing Images in PostgreSQL |
|postgresql|image| |
Alright, so I'm working on an application which will use a Linux back-end running PostgreSQL to serve up images to a Windows box with the front end written in C#.NET, though the front-end should hardly matter. My question is:
- **What is the best way to deal with storing images in Postgres?**
The images are ar... |
Would that there were, my friend -- TernaryOp is your only hope. |
> When should the lock be used?
A lock should be used to protect shared resources in multithreaded code. Not for anything else.
> But is it necessary when the application does not spin off any other threads?
Absolutely not. It's just a time waster. However do be sure that you're not implicitly using sy... |
No, you can add bits to the end of a jpg file, without reducing its usability. The heading of the jpg file tells how to read it, so the program reading it will stop at the end of the jpg data.
In fact, people have hidden zip files inside jpg files by appending the zip data to the end of the jpg data. Because of th... |
No, you can add bits to the end of a jpg file, without making it unusable. The heading of the jpg file tells how to read it, so the program reading it will stop at the end of the jpg data.
In fact, people have hidden zip files inside jpg files by appending the zip data to the end of the jpg data. Because of the wa... |
Bear in mind that there might be reasons why your application is not as single-threaded as you think. Async I/O in .NET may well call-back on a pool thread, for example, as do some of the various timer classes (not the Windows Forms Timer, though). |
It doesn't matter if captchas are broken or not now -- <a href="http://ddanchev.blogspot.com/2008/08/exposing-indias-captcha-solving-economy.html">there are Indian firms that do nothing but process captchas</a>. I'm with the rest of the group in saying that Captchas are on their way out. |
Most effective form of CAPTCHA? |
|captcha| |
Of all the forms of CAPTCHA available, which one is the "least crackable" while remaining fairly human readable? |
|captcha| |
If you look at the IL generated by the statement
public const ADate as Date = #12/31/04#
You'll see this:
.field public static initonly valuetype [mscorlib]System.DateTime ADate
.custom instance void [mscorlib]System.Runtime.CompilerServices.DateTimeConstantAttribute::.ctor(int64) = ( 01 00 00 C0 ... |
**If you're the perfectionist kind, roll your own**.
* It isn't that hard
* You learn something useful
* You'll get *exactly* what you want and need
Be warned that you may run into a quagmire fighting comment spam, fixing security holes, etc. But it'll probably be a fun project.
**If you are the practical ty... |
You could try increasing the indent size, but in general I would just say, relax, it will come with time. I don't think trying to make Python look like C is a very good idea. |
I would recommend JSON ... but since you already mentioned it maybe you should take a look at [Google protocol buffers](http://google-opensource.blogspot.com/2008/07/protocol-buffers-googles-data.html). |
I would recommend JSON ... but since you already mentioned it maybe you should take a look at [Google protocol buffers](http://google-opensource.blogspot.com/2008/07/protocol-buffers-googles-data.html).
Edit: Protocol buffers are made to be used programatically (there are bindings for c++, java, python ...) so they ... |
I'm no Django expert, so this answer is about session stores generally. Downvote if I'm wrong.
## Performance and Scalability
Choice of session store has an effect on performance and scalability. This should only be a big problem if you have a very popular application.
Both database and filesystem session stor... |
Version control of deliverables |
|version-control|deployment| |
We need to regularly synchronize many dozens of binary files (project executables and DLLs) between many developers at several different locations, so that every developer has an up to date environment to build and test at. Due to nature of the project, updates must be done often and on-demand (overnight updates are no... |
We need to regularly synchronize many dozens of binary files (project executables and DLLs) between many developers at several different locations, so that every developer has an up to date environment to build and test at. Due to nature of the project, updates must be done often and on-demand (overnight updates are no... |
If it's appropriate, having a blog is a good way of keeping content fresh, especially if you post often. A CMS would be handy too, as it reduces the friction of updating. The best way would be user-generated content, as other people make your site bigger and updated, and they may well link to their content from their o... |
`foo` is used as a place-holder name, usually in example code to signify that the object being named, or the choice of name, is not part of the crux of the example. `foo` is often followed by `bar`, `baz`, and even `bundy`, if more than one such name is needed. Wikipedia calls these names [Metasyntactic Variables][1]. ... |
It seems like the question is more about whether to use the server or client version *of the same OS*. So my answer is this: the client should be just fine. You can develop and test web applications of many flavors on client versions of Windows, OS X, and Linux. OS X and Linux obviously make Apache-based apps a little ... |
Namespaces are purely semantic. Whilst they usually do reflect a folder structure, at least when using Visual Studio IDE, they do not need to.
You can have the same namespace referenced in multiple libraries, ugly but true. |
I asked the FogBugz guys the same thing because in XP for example you'd provide the estimate in IET (ideal engineering time). Their answer was to be consistent in the way you provide the estimate. |
Unfortunately, the Groovy Eclipse plugin is pretty horrible at giving actual helpful information to let you know what is going wrong with your setup. I'm going to assume you already did the verification to make sure the plugin is actually building your Groovy files (i.e. doing a sample with no dependencies, checking t... |
What you are looking to do is called Single Sign On and Single Sign Off. There are differences based on how you have the applications set up. I will try to clarify where those differences come into play.
To implement single sign on and single sign off you need to make the cookie name, protection, and path attribut... |
What you are looking to do is called Single Sign On and Single Sign Off. There are differences based on how you have the applications set up. I will try to clarify where those differences come into play.
To implement single sign on and single sign off you need to make the cookie name, protection, and path attribut... |
What is the best practice for writing Registry calls/File Sytem calls/Process creation filter for WinXP, Vista? |
|winapi|drivers| |
We needed to monitor all processes Registry calls/File Sytem calls/Process creations in the system (for the antivirus hips module) .
Also time by time it will be needed to delay some calls or decline them.
|
Check out the [DecimalFormat][1] class, e.g. new DecimalFormat("0.##").format(99.0) will return "99".
[1]: http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormat.html |
new Formatter().format( "%f", myFloat ) |
If you will be supporting languages other than English, you will want to use nvarchar.
HTML should be okay as long as it contains standard ASCII characters. I've used nvarchar mainly in databases that were multi-lingual support. |