This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#products').append('<%= j render(@products) %>'); | |
<% if @products.next_page %> | |
$('.pagination').replaceWith('<%= j will_paginate(@products) %>'); | |
<% else %> | |
$('.pagination').remove(); | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fibonacci = Enumerator.new do |yielder| | |
n1, n2 = 0, 1 | |
loop do | |
yielder.yield n1 | |
n1, n2 = n2, n1 + n2 | |
end | |
end | |
p fibonacci.first(20) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
## | |
# @example | |
# ruby -rubygems `__FILE__` `source_bucket_name` `target_bucket_name` | |
# | |
# @author @ipoval | |
# | |
# @see https://github.com/ipoval |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# If you encountered a problem like this: | |
# Errno::EMLINK: Too many links ...releases/20110811111351/public/document/file/51159 | |
# Most likely it is caused by the limitations of your Linux filesystem - | |
# a directory can only have a certain number of sub-directories. | |
# | |
# http://blog.zachwaugh.com/post/309921185/ext3-filesystem-sub-directory-limit | |
# | |
## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Docs | |
http://redis.io | |
http://www.infoq.com/presentations/newport-evolving-key-value-programming-model | |
http://rediscookbook.org | |
http://www.paperplanes.de/2010/2/16/a_collection_of_redis_use_cases.html | |
http://thechangelog.com/post/2801342864/episode-0-4-5-redis-with-salvatore-sanfilippo | |
http://www.slideshare.net/pauldix/indexing-thousands-of-writes-per-second-with-redis | |
http://ai.mee.nu/is_couchdb_the_anti-redis | |
http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis | |
http://antirez.com/post/take-advantage-of-redis-adding-it-to-your-stack.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://hyperpolyglot.org/scripting | |
$? # global Process::Status object; system('date'); $?.exitstatus; | |
$ ruby -cw filename.rb # checks the code in the file for syntax errors | |
$ ruby -e '1/0' # one-liner ruby executable | |
`gem environment gemdir` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Overload your ORM safely or Black magic of metaprogramming | |
========================================================== | |
Introduction | |
------------ | |
Ruby provides the great set of metaprogramming features. | |
Metaprogramming is a bit like magic, which makes something astonishing possible. | |
But there are two kinds of magic: white magic, which does good things, and black magic, which can do nasty things. | |
And unfortunately sometimes it is so easy to fall into the dark side of metaprogramming. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HttpAuthentication | |
module Basic | |
def authenticate_or_request_with_http_basic(realm = 'Application') | |
authenticate_with_http_basic || request_http_basic_authentication(realm) | |
end | |
def authenticate_with_http_basic | |
if auth_str = request.env['HTTP_AUTHORIZATION'] | |
return 'login:password' == ActiveSupport::Base64.decode64(auth_str.sub(/^Basic\s+/, '')) | |
end |
NewerOlder