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
# | |
find app/models/ -name "*.rb" | xargs grep -h --color -e ^class | cut -d ' ' -f 2 | sort | uniq | while read k; do echo model class: "$k"; grep -r -l -w -m 1 --color "$k" ./app ./config ./lib ./script --exclude-dir=*assets* | head -n 2 | wc -l | grep 1; done |
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
class Blog | |
attr_writer :post_source | |
def new_post | |
post_source.call.tap do |p| | |
p.blog = self | |
end | |
end | |
private |
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
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
# IPC 1 - IO.pipe to set up the UNIX-pipe-based interprocess communication | |
in_r, in_w = IO.pipe; out_r, out_w = IO.pipe; err_r, err_w = IO.pipe | |
pid = spawn('cat -n', in: in_r, out: out_w, err: err_w) | |
[in_r, out_w, err_w].each(&:close) | |
in_w.puts("signal to process") | |
in_w.close |
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 |