Forked from Sreekanth S's Pen groceries.
A Pen by Captain Anonymous on CodePen.
# fork it | |
# | |
# make it print all true with only ONE LINE OF CODE | |
class A | |
def A.foo | |
@foo ||= ( | |
if self == A | |
'42.0' | |
else |
Forked from Sreekanth S's Pen groceries.
A Pen by Captain Anonymous on CodePen.
$(document).ready(function(){ | |
$('.other_submit').click(function(){ | |
this.form.action = this.getAttribute('data-action') | |
}) | |
}) |
source :gemcutter | |
eval File.read(File.expand_path("../config/bundler/general.gemfile", __FILE__)) | |
unless RUBY_PLATFORM[/mswin/] || RUBY_PLATFORM[/mingw/] | |
eval File.read(File.expand_path("../config/bundler/unix.gemfile", __FILE__)) | |
end |
$ git clone github:lenary/guides.git | |
Cloning into guides... | |
remote: Counting objects: 255, done. | |
remote: Compressing objects: 100% (216/216), done. | |
remote: Total 255 (delta 111), reused 163 (delta 35) | |
Receiving objects: 100% (255/255), 1.49 MiB | 564 KiB/s, done. | |
Resolving deltas: 100% (111/111), done. | |
$ cd guides | |
$ git remote -v |
curl localhost:9200/_search -d '{ | |
"query" : { | |
"filtered" : { | |
"query" : {"match_all" : {}}, | |
"filter" : { | |
"and" : [ | |
{ | |
"range" : { | |
"file_size" : {"from" : 10, "to" : 10000} | |
} |
data = ["1", "11", "111", "2", "22", "222", "3", "4", "5"] | |
y = (1..9).inject({}) { |memo, data| memo[data.to_s] = 0; memo } | |
data.each { |z| y[z.chr] = y.fetch(z.chr, 0) + 1 } | |
puts y | |
y = {};(1..9).map { |x| y[x.to_s] = 0 } | |
data.each { |z| y[z.chr] = y.fetch(z.chr, 0) + 1 } | |
puts y |
# | |
# A basic, synthetic benchmark of the impact HTTP client has | |
# on the speed of talking to ElasticSearch in the Tire gem. | |
# | |
# In general, Curb seems to be more then two times faster the RestClient, in some cases it's three | |
# to five times faster. I wonder if keep-alive has anything to do with it, but it probably does. | |
# | |
# Run me with: | |
# $ git clone git://github.com/karmi/tire.git | |
# $ cd tire |
APIs are becoming an essential feature of modern web applications. Rails does a good job of helping your application provide an API using the same MVC structure you're accustomed to.
Let's work with the following example controller:
class ArticlesController < ApplicationController
jQuery has become the most popular JavaScript library both inside and outside the Rails community. Let's look at how to take advantage of the library with our applications.
The setup process differs depending on whether your app is running on a version of Rails before 3.1 or greater than 3.1.