INSTALLATION
echo "gem 'machinist_blueprint_with_method',\
git: 'git://gist.github.com/6204150.git',\
group: 'test'" >> GemfileEXAMPLE OF USAGE
| 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 |
| 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. |
| # 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` | |
| # 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 |
| ## | |
| # 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 | |
| # | |
| ## |
| #!/usr/bin/env ruby | |
| # encoding: utf-8 | |
| ## | |
| # @example | |
| # ruby -rubygems `__FILE__` `source_bucket_name` `target_bucket_name` | |
| # | |
| # @author @ipoval | |
| # | |
| # @see https://github.com/ipoval |
| 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) |
| $('#products').append('<%= j render(@products) %>'); | |
| <% if @products.next_page %> | |
| $('.pagination').replaceWith('<%= j will_paginate(@products) %>'); | |
| <% else %> | |
| $('.pagination').remove(); | |
| <% end %> |
| class Blog | |
| attr_writer :post_source | |
| def new_post | |
| post_source.call.tap do |p| | |
| p.blog = self | |
| end | |
| end | |
| private |
INSTALLATION
echo "gem 'machinist_blueprint_with_method',\
git: 'git://gist.github.com/6204150.git',\
group: 'test'" >> GemfileEXAMPLE OF USAGE