Create a dictionary with list comprehension in Python

Create a dictionary with list comprehension in Python

I like the Python list comprehension syntax.Can it be used to create dictionaries too? For example, by iterating over pairs of keys and values:mydict = {(k,v) for (k,v) in blah blah blah} # doesn't work 1:In Python 2.6 and earlier, the

Why is Java Vector class considered obsolete or deprecated?

Why is Java Vector class considered obsolete or deprecated?

Why is Java Vector considered a legacy class, obsolete or deprecated?Isn't its use valid when working with concurrency?And if I don't want to manually synchronize objects and just want to use a thread-safe collection without needing to make

How to validate an email address using a regular expression?

How to validate an email address using a regular expression?

Over the years I have slowly developed a regular expression that validates MOST email addresses correctly, assuming they don't use an IP address as the server part.I use it in several PHP programs, and it works most of the time. However, f

Is Loop Hoisting still a valid manual optimization for C code?

Is Loop Hoisting still a valid manual optimization for C code?

Using the latest gcc compiler, do I still have to think about these types of manual loop optimizations, or will the compiler take care of them for me well enough? 1:If your profiler tells you there is a problem with a loop, and only then

what is the purpose of the extra asterisks in php comments?

what is the purpose of the extra asterisks in php comments?

I've (finally) been reading up on PEAR (php) coding standards.What is the purpose of commenting like this:/** * Here is my comment* I Wrote this in a haiku* But why put the stars?*/As opposed to this:/* Here is a comment No haiku

Access to each separate channel in OpenCV

Access to each separate channel in OpenCV

I have an image with 3 channels (img) and another one with a single channel (ch1). Mat img(5,5,CV_64FC3); Mat ch1 (5,5,CV_64FC1);Is there any efficient way (not using for loop) to copy the first channel of img to ch1? 1:There is a

Avoiding HTML document reflows

Avoiding HTML document reflows

I have several hundred "row" elements like this: I need to get their clientHeight after they have been rendered on the page already. I know that the "clientHeight" property forces a reflow and this kills my performance since there are

What is the difference between these declarations in C?

What is the difference between these declarations in C?

In C and C++ what do the following declarations do?const int * i;int * const i;const volatile int ip;const int *i;Are any of the above declarations wrong?If not what is the meaning and differences between them?What are the useful uses of ab

Lvalues which do not designate objects in C++14

Lvalues which do not designate objects in C++14

I'm using N3936 as a reference here (please correct this question if any of the C++14 text differs).Under 3.10 Lvalues and rvalues we have: Every expression belongs to exactly one of the fundamental classifications in this taxonomy: lvalue

Options for real-time web notifications and updates using Comet/XMPP vs WebSocket technologies on a

Options for real-time web notifications and updates using Comet/XMPP vs WebSocket technologies on a

I am scoping out the architectural options for a project that will render live updates (like Facebook) of user activities - logins, photos, etc. Two main UI components of this are an auto-updating scrolling area where new notifications wil

How to switch subversion repository in Visual Studio using AnkhSVN?

How to switch subversion repository in Visual Studio using AnkhSVN?

I've been developing a project locally and using a local svn server for versioning in visual studio. I now want to switch to xp-dev hosted versioning but cannot seem to get rid of the svn bindings on my solution? Is there an easy way to dup

Limiting the number of threads executing a method at a single time

Limiting the number of threads executing a method at a single time

We have a situation where we want to limit the number of paralell requests our application can make to its application server. We have potentially 100+ background threads running that will want to at some point make a call to the applicati

How to get error result of unlink

How to get error result of unlink

If a call to unlink() returns false for the specified path, how do you find out what the reason for the failure was (i.e. EISDIR, ENOENT, ELOOP etc.)? PHP 5.x running on redhat linux. 1:here's one wayunlink("/path/that/does/not/exist");p

How to detect if windows is going to hibernate or suspend?

How to detect if windows is going to hibernate or suspend?

I am using SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler( SystemEvents_PowerModeChanged);to tell when Windows is suspending. But how do I know if it is going into hibernate or suspend?Is there a .Net or PInvoke method

How to replace nth character of a string with another

How to replace nth character of a string with another

How could I replace nth character of a String with another one?func replace(myString:String, index:Int, newCharac:Character) -> String { // Write correct code here return modifiedString}For example, replace("House", 2, "r") should be

How to have a fixed-size layout that also keeps the window from resizing?

How to have a fixed-size layout that also keeps the window from resizing?

I have a container widget. It's size policies are "Fixed" (both vertical and horizontal).it has setMaxmimumWidth and setMaximumHeight defined.I put an QHBoxLayout container there. adding widgets to it (with fixed width/height too).But when

Should users be allowed to entered a password with a space at the beginning or end? [closed]

Should users be allowed to entered a password with a space at the beginning or end? [closed]

Should users be able to enter a password such as " 12345" or "12345 " – a space at the beginning or end? Or would you trim the password to remove the leading or trailing spaces because it may just a typing error. 1:Yes, they should. It

How to get a Class Object from the Class Name in Java

How to get a Class Object from the Class Name in Java

I know the class name, say "MyClass" and want to retrieve the Class object, ie. MyClass.class for future references. Is there a way to do that?I've looked through the web but most of the things I found related to it were about the ClassLoad

Parameterized error messages for javax.validation.constraints.Pattern annotation?

Parameterized error messages for javax.validation.constraints.Pattern annotation?

I have an entity with a field of type String on which I defined a @Pattern annotation enforcing the content of the field matching a given regular expression. Now I wonder, whether it is possible to parameterize the constraint such as that t

Ninject Binding

Ninject Binding

How do bind my interface to a concrete class in a different assembly?I have the following projects in my solution:Foo.Data Foo.DomainIn Structure Map I add my two assembly names to the StructureMap.config file and a then using the PluginFam

Android, how to stop reading getView() function again, if the content is already downloaded in the L

Android, how to stop reading getView() function again, if the content is already downloaded in the L

I am a newbie Android guy. I have a ListView displaying images on every element of the ListView, It works fine... but when I start to scrolling I have realized my image is downloaded again if it is displayed in the screen of my phone device

How can I determine the statistical randomness of a binary string?

How can I determine the statistical randomness of a binary string?

How can I determine the statistical randomness of a binary string?Ergo, how can I code my own test, and return a single value that corresponds to the statistical randomness, a value between 0 and 1.0 (0 being not random, 1.0 being random)?T

Method Swizzling in Android using java

Method Swizzling in Android using java

Is it possible to do method swizzling in android using java? i would like to intercept a system method and log its parameters then process it normally 1:I think that technique could not be used using Java in any environment.Maybe you co

Can i force mysql to perform subquery first?

Can i force mysql to perform subquery first?

I have query like this:SELECT `table_1`.* from `table_1` INNER JOIN `table_2` [...] INNER JOIN `table_3` [...]WHERE `table_1`.`id` IN( SELECT `id` FROM [...])AND [more conditions]When I use EXPLAIN, there is 'DEPENDENT SUBQUERY' at the e

Simple SSH port forward in Golang

Simple SSH port forward in Golang

I'm trying to create (and later close) a simple TCP port forward over SSH with Go. I'm new to Golang and statically typed languages. (Coming from Ruby.)In a terminal I would simply run ssh -L 9000:localhost:9999 [email protected] and this acc