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
preload_app true | |
worker_processes 2 | |
listen 3000 | |
before_fork do |server, worker| | |
ActiveRecord::Base.connection.disconnect! | |
end | |
after_fork do |server, worker| |
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 Example | |
attr_reader :value | |
def initialize(value) | |
@value = value | |
end | |
def truthy? | |
!!@value | |
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
module UTF8 | |
module Params | |
private | |
def normalize_parameters_with_encoding(value) | |
normalize_parameters_without_encoding(value).tap do |value| | |
value.force_encoding(Encoding.default_external) if value.respond_to?(:force_encoding) | |
end | |
end | |
end | |
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
module October | |
class Daemon | |
attr_reader :child, :root, :env | |
def initialize(root, env = nil) | |
@root = root | |
@env = env | |
end | |
def spawn! |
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 | |
console = File.expand_path(File.dirname(__FILE__), '.') + "/console" | |
exec console, *ARGV, '--irb=pry' |
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
array = 1_000_000.times.map{ rand(0..3) } | |
Benchmark.bm do |x| | |
x.report('check') { array.each_slice(2){|a,b| b == 0 ? 0 : a / b } } | |
x.report('rescue') { array.each_slice(2){|a,b| a / b rescue 0 } } | |
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
#!/Users/mikz/.rvm/rubies/macruby-0.12/bin/ruby | |
# coding: utf-8 | |
def colorize(text, color_code) | |
"\e[0;#{color_code}m#{text}" | |
end | |
def black(text=""); colorize(text, 30); end | |
def red(text=""); colorize(text, 31); end | |
def green(text=""); colorize(text, 32); 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
alias rt="ruby -Itest -I. -e \"alias rt="ruby -Itest -I. -e \"require'pathname';P=Pathname;ARGV.map{|a|p=P.new(a);next unless p.exist?;p.directory?? P.glob(p.join('**/*.rb')):p}.flatten.compact.uniq.each{|p|require p.expand_path}\""\"" |
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
# flat api params like: name=John&surnname=Doe | |
POST '/api/user', name: 'John', surname: 'Doe' | |
# nested api params like: user[name]=Jack&user[surname]=Xzbit | |
POST '/api/user', user: { name: 'Jack', surname: 'Xzbit' } | |
# how to get only params that are related to the model? | |
# imagine case: |
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
require 'open-uri' | |
class NamesGenerator | |
def self.load | |
go = open('https://raw.github.com/dotcloud/docker/master/pkg/namesgenerator/names-generator.go') | |
left, right = go.read.scan(/\[\.\.\.\]string{(?<strings>.+)}/) | |
left = left.first.scan(/"(.+?)"/) |