Skip to content

Instantly share code, notes, and snippets.

View ipoval's full-sized avatar

ipoval ipoval

  • Microsoft, Atlassian
  • Sydney, Australia
View GitHub Profile
@ipoval
ipoval / http_authentication
Created February 23, 2011 17:51
Http basic authentication for padrino
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
@ipoval
ipoval / overload_orm_methods_safely
Created April 20, 2011 06:41
Overload ORM safely or Black magic of metaprogramming
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.
@ipoval
ipoval / ruby_ipoval
Created June 20, 2011 07:40
ruby_ipoval
# 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`
@ipoval
ipoval / redis_ipoval
Created June 23, 2011 23:19
redis_ipoval
# 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
@ipoval
ipoval / file_column_ruby.rb
Last active September 26, 2015 19:07
File_column ruby legacy file-upload plugin
##
# 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
#
##
@ipoval
ipoval / sync_aws_buckets
Created November 6, 2011 01:23
sync_aws_buckets
#!/usr/bin/env ruby
# encoding: utf-8
##
# @example
# ruby -rubygems `__FILE__` `source_bucket_name` `target_bucket_name`
#
# @author @ipoval
#
# @see https://github.com/ipoval
@ipoval
ipoval / fibonacci_enumerator.rb
Last active September 28, 2015 03:08
fibonacci_enumerator
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)
@ipoval
ipoval / index.js.erb
Created December 16, 2011 23:37 — forked from ryanb/index.js.erb
Infinite scrolling solution covered in revised episode #114: http://railscasts.com/episodes/114-endless-page-revised
$('#products').append('<%= j render(@products) %>');
<% if @products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
$('.pagination').remove();
<% end %>
@ipoval
ipoval / ruby_fabric.rb
Last active October 2, 2015 02:47
DP: Fabric Class
class Blog
attr_writer :post_source
def new_post
post_source.call.tap do |p|
p.blog = self
end
end
private
@ipoval
ipoval / README.md
Last active December 20, 2015 22:19
Add a custom method definition to Test Blueprints in Machinist::Mongoid. It is very handy in the tests to have extra helper methods directly on the Test Blueprints without defining those in the corresponding Model class.

INSTALLATION

echo "gem 'machinist_blueprint_with_method',\
      git: 'git://gist.github.com/6204150.git',\
      group: 'test'" >> Gemfile

EXAMPLE OF USAGE