Ruby ampersand colon shortcut [duplicate]

Ruby ampersand colon shortcut [duplicate]

Possible Duplicate: What does map(&:name) mean in Ruby? In Ruby, I know that if I do:some_objects.each(&:foo)It's the same assome_objects.each { |obj| obj.foo }That is, &:foo creates the block { |obj| obj.foo }, turns it into a Proc, and

Unescape HTML entities in Javascript?

Unescape HTML entities in Javascript?

I have some Javascript code that communicates with an XML-RPC backend.The XML-RPC returns strings of the form:However, when I use the Javascript to insert the strings into HTML, they render literally. I don't see an i

Convert date format yyyy-mm-dd => dd-mm-yyyy [duplicate]

Convert date format yyyy-mm-dd => dd-mm-yyyy [duplicate]

This question already has an answer here: Convert one date format into another in PHP 14 answers I am trying to convert a date from yyyy-mm-dd to dd-mm

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

Find unique rows in numpy.array

Find unique rows in numpy.array

I need to find unique rows in a numpy.array.For example:>>> a # I havearray([[1, 1, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 0, 0], [1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 0]])>>> new_a # I want to get toarray([[1,

How do you read from stdin in Python?

How do you read from stdin in Python?

I'm trying to do some of the code golf challenges, but they all require the input to be taken from stdin. How do I get that in Python? 1:You could use the fileinput module:import fileinputfor line in fileinput.input(): passfileinput w

How to parse a string to an int in C++?

How to parse a string to an int in C++?

What's the C++ way of parsing a string (given as char *) into an int? Robust and clear error handling is a plus (instead of returning zero). 1:In the new C++11 there are functions for that: stoi, stol, stoll, stoul and so on.int myNr = s

How to force NSLocalizedString to use a specific language

How to force NSLocalizedString to use a specific language

On iPhone NSLocalizedString returns the string in the language of the iPhone.Is it possible to force NSLocalizedString to use a specific language to have the appin a different language than the device ? 1:NSLocalizedString() (and variant

Serializing to JSON in jQuery [duplicate]

Serializing to JSON in jQuery [duplicate]

This question already has an answer here: Serializing an object to JSON 3 answers I need to serialize an object to JSON. I'm using jQuery. Is there a "

How to count the occurrences of a list item?

How to count the occurrences of a list item?

Given an item, how can I count its occurrences in a list in Python? 1:If you only want one item's count, use the count method:>>> [1, 2, 3, 4, 1, 4, 1].count(1)3Don't use this if you want to count multiple items. Calling count in a loop

How to load an ImageView by URL in Android? [closed]

How to load an ImageView by URL in Android? [closed]

How do you use an image referenced by URL in an ImageView? 1:From Android developer:// show The Image in a ImageViewnew DownloadImageTask((ImageView) findViewById(R.id.imageView1)) .execute("http://java.sogeti.nl/JavaBlog/wp-c

How do I add a library project to Android Studio?

How do I add a library project to Android Studio?

How do I add a library project (such as Sherlock ABS) to Android Studio? (Not to the old ADT Eclipse-based bundle, but to the new Android Studio.) 1:Update for Android Studio 1.0Since Android Studio 1.0 was released (and a lot of version

How can I obfuscate (protect) JavaScript? [closed]

How can I obfuscate (protect) JavaScript? [closed]

I want to make a JavaScript application that's not open source, and thus I wish to learn how to can obfuscate my JS code? Is this possible? 1:Obfuscation:Try YUI Compressor. It's a very popular tool, built, enhanced and maintained by th

How do I make a list of data frames?

How do I make a list of data frames?

How do I make a list of data frames and how do I access each of those data frames from the list?For example, how can I put these data frames in a list ?d1 <- data.frame(y1 = c(1, 2, 3), y2 = c(4, 5, 6))d2 <- data.frame(y1 =

Daylight saving time and time zone best practices [closed]

Daylight saving time and time zone best practices [closed]

I am hoping to make this question and the answers to it the definitive guide to dealing with daylight saving time, in particular for dealing with the actual change overs. If you have anything to add, please doMany systems are dependent on k

Scanner is skipping nextLine() after using next() or nextFoo()?

Scanner is skipping nextLine() after using next() or nextFoo()?

I am using the Scanner methods nextInt() and nextLine() for reading input. It looks like this:System.out.println("Enter numerical value"); int option;option = input.nextInt(); // Read numerical value from inputSystem.out.println("Enter 1

What is the difference between client-side and server-side programming?

What is the difference between client-side and server-side programming?

I have this code:Why does this not write "bar" into my text file, b

Execute .sql schema in psycopg2 in Python

Execute .sql schema in psycopg2 in Python

I have a PostgreSQL schema stored in .sql file. It looks something like:CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY, facebook_id TEXT NOT NULL, name TEXT NOT NULL, access_token TEXT, created INTEGER NOT NULL);Ho

org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]A child cont

org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]A child cont

I am struggling for the past 6-7 hrs trying to figure out what went wrong with my Apache Tomcat Server. In all of my projects, the jdk version got switched to 1.6 from 1.8. To solve the version conflict, I verified whether compiled version

FileOutputStream: Does the “close” method calls also “flush”?

FileOutputStream: Does the “close” method calls also “flush”?

I'm really confused about flush and close method.In my code I always close my FileOutputStream object. But I want to know that if I have to use flush method here, and where can I use it?I will write a project that download 4 or 5 files repe

changing visibility using javascript

changing visibility using javascript

hii have web page which uses ajax to retrieving data from another pages and while doing that i want to show a loading gif in the page so i've create a div with my gif on it.

Python 2.5 dictionary 2 key sort

Python 2.5 dictionary 2 key sort

I have a dictionary of 200,000 items (the keys are strings and the values are integers).What is the best/most pythonic way to print the items sorted by descending value then ascending key (i.e. a 2 key sort)? a={ 'keyC':1, 'keyB':2, 'keyA':

Reloading model in laravel

Reloading model in laravel

In some of my tests, I have a user model I have created and I run some methods that need to save certain attributes. In rails, I would typically call something like user.reload which would repopulate the attributes from the database.Is ther

multiple “commands” in a single Sublime Text 2 user keymap shortcut

multiple “commands” in a single Sublime Text 2 user keymap shortcut

Is there a way to have multiple "commands" associated with one shortcut?I have these two shortcuts. First shortcut makes the window on the left larger than the right one (in a 2 column view) and the next shortcut puts the focus on the first

Android custom widget styles: how to put them into a namespace?

Android custom widget styles: how to put them into a namespace?

In the ApiDemos, there is a view example called Gallery1 which declares a custom style in attrs.xml, as such: now, I want to do the same thing for my widgets, but using a different namespace. However, as soon as I replace the android: na