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

Use of the JavaScript 'bind' method

Use of the JavaScript 'bind' method

What is the use of bind() in JavaScript? 1:Bind creates a new function that will have this set to the first parameter passed to bind().Here's an example that shows how to use bind to pass a member method around that has the correct this:

How to center absolutely positioned element in div?

How to center absolutely positioned element in div?

I need to place a div (with position:absolute;) element in the center of my window. But I am having problems doing so, because the width is unknown.I tried this. But it needs to be adjusted as the width is responsive..center { left: 50%;

Why is this string reversal C code causing a segmentation fault? [duplicate]

Why is this string reversal C code causing a segmentation fault? [duplicate]

This question already has an answer here: Why do I get a segmentation fault when writing to a string initialized with “char *s” but not “char s[]”? 16 answers

Methods in ES6 objects: using arrow functions

Methods in ES6 objects: using arrow functions

In ES6, both of these are legal:var chopper = { owner: 'Zed', getOwner: function() { return this.owner; }};and, as shorthand:var chopper = { owner: 'Zed', getOwner() { return this.owner; }}Is it possible to use the new arrow fun

Read whole ASCII file into C++ std::string [duplicate]

Read whole ASCII file into C++ std::string [duplicate]

This question already has an answer here: What is the best way to read an entire file into a std::string in C++? 11 answers I need to read a whole file

Why doesn't the height of a container element increase if it contains floated elements?

Why doesn't the height of a container element increase if it contains floated elements?

I would like to ask how height and float work. I have an outer div and an inner div that has content in it. Its height may vary depending on the content of the inner div but it seems that my inner div will overflow its outside div. What wou

Replace preg_replace() e modifier with preg_replace_callback

Replace preg_replace() e modifier with preg_replace_callback

I'm terrible with regular expressions. I'm trying to replace this:public static function camelize($word) { return preg_replace('/(^|_)([a-z])/e', 'strtoupper("\\2")', $word);}with preg_replace_callback with an anonymous function. I don't

SQL Server: Examples of PIVOTing String data

SQL Server: Examples of PIVOTing String data

Trying to find some simple SQL Server PIVOT examples. Most of the examples that I have found involve counting or summing up numbers. I just want to pivot some string data. For example, I have a query returning the following.Action1 VIEW

Is there a CSS selector for elements containing certain text?

Is there a CSS selector for elements containing certain text?

I am looking for a CSS selector for the following table:Peter | male | 34Susanne | female | 12Is there any selector to match all TDs containing "male"? 1:If I read the specification correctly, no. You can match on an element, th

Absolute vs relative URLs

Absolute vs relative URLs

I would like to know the differences between these two types of URLs: relative URLs (for pictures, CSS files, JS files, etc.) and absolute URLs.In addition, which one is better to use? 1:In general, it is considered best-practice to use

MyISAM versus InnoDB

MyISAM versus InnoDB

I'm working on a projects which involves a lot of database writes, I'd say (70% inserts and 30% reads). This ratio would also include updates which I consider to be one read and one write. The reads can be dirty (e.g. I don't need 100% ac

How to dynamically add suggestions to autocompletetextview with preserving character status

How to dynamically add suggestions to autocompletetextview with preserving character status

Problem Description:I am facing some problem with AutoCompleteTextView where I have to show suggestions after each keypress.Thing is that, list of suggestion is dynamic like google's suggestion feature.It means the new suggestions should be

Improve INSERT-per-second performance of SQLite?

Improve INSERT-per-second performance of SQLite?

Optimizing SQLite is tricky. Bulk-insert performance of a C application can vary from 85 inserts per second to over 96,000 inserts per second!Background: We are using SQLite as part of a desktop application. We have large amounts of configu

What is the difference between a deep copy and a shallow copy?

What is the difference between a deep copy and a shallow copy?

What is the difference between a deep copy and a shallow copy? 1:Shallow copies duplicate as little as possible. A shallow copy of a collection is a copy of the collection structure, not the elements. With a shallow copy, two collectio

Generating random whole numbers in JavaScript in a specific range?

Generating random whole numbers in JavaScript in a specific range?

How can I generate a random whole number between two specified variables in Javascript, e.g. x = 4 and y = 8 would output any of 4, 5, 6, 7, 8? 1:There are some examples on the Mozilla Developer Network page:/** * Returns a random number

Are PHP short tags acceptable to use?

Are PHP short tags acceptable to use?

Here's the information according to the official documentation: There are four different pairs of opening and closing tags which can be used in PHP. Two of those, <?php ?> and <script language="php"> </script>, are always available. Th

Why does Date.parse give incorrect results?

Why does Date.parse give incorrect results?

Case One:new Date(Date.parse("Jul 8, 2005"));Output:Fri Jul 08 2005 00:00:00 GMT-0700 (PST)Case Two:new Date(Date.parse("2005-07-08"));Output:Thu Jul 07 2005 17:00:00 GMT-0700 (PST)Why is the second parse incorrect? 1:Until the 5th editi

What is the purpose of the var keyword and when should I use it (or omit it)?

What is the purpose of the var keyword and when should I use it (or omit it)?

NOTE: This question was asked from the viewpoint of ECMAScript version 3 or 5. The answers might become outdated with the introduction of new features in the release of ECMAScript 6.What exactly is the function of the var keyword in JavaScr

My regex is matching too much. How do I make it stop?

My regex is matching too much. How do I make it stop?

J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM J0000010: Project name: E:\foo.pf J0000011: Job name: MBiek Direct Mail Test J0000100: Machine name: DEV J0000100: Project file: E:\mbiek\foo.pf J0000100: Template file: E:

How to scroll the window automatically when mouse moves bottom of the page using jquery

How to scroll the window automatically when mouse moves bottom of the page using jquery

I have 50 divs,But in my window it shows only 25,I do drag and drop activity on these divs.So If i drag my first div near 25th div,It should scroll automatically to show the remaining divs.How do i do this in jquery? any idea?I am using Nes

Which HTTP code to use for an empty subresource in a REST API?

Which HTTP code to use for an empty subresource in a REST API?

Let's say I've a resource articles at /articles.These articles may have related articles, so I fetch them by GETting /articles/{id}/related.What should I return is there is no related articles?I can think of:404 Not Found, maybe with an emp

Number of commands in Dockerfile

Number of commands in Dockerfile

I noticed that each line in the Dockerfile creates a separate image. Is there any limit on the number of images that are created? Should we try to do a oneliner of RUN cmd1 && cmd2 && cmd3 instead?How would this differ if we use a service l

Get git current branch/tag name

Get git current branch/tag name

How can I get the current branch or tag name for my working copy? I have seen references that indicate rev-parse --abbrev-ref HEAD will give branch name, but this doesn't work if the checkout is of a tag, in which case it just returns 'HEA

~= operator in Swift

~= operator in Swift

I recently downloaded the Advanced NSOperations sample app from Apple and found this code...// Operators to use in the switch statement.private func ~=(lhs: (String, Int, String?), rhs: (String, Int, String?)) -> Bool { return lhs.0 ~= r