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 'logger' | |
require 'rubygems' | |
require 'wirble' | |
require 'pp' | |
Wirble.init | |
Wirble.colorize | |
# require 'utility_belt' | |
if ENV.include?('RAILS_ENV')&& !Object.const_defined?('RAILS_DEFAULT_LOGGER') | |
Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT)) |
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
def kata(digits = [], has_pair = false) | |
if digits.inject {|sum, digit| sum + digit } == 15 | |
has_pair ? [digits] : [] | |
else | |
start = (digits.last || 0) + 1 | |
(start..9).inject([]) do |result, digit| | |
result + kata(digits + [digit], has_pair) + kata(digits + [digit, digit], true) | |
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
def kata(digits = [], sum = 0, has_pair = false) | |
if sum < 15 | |
start = (digits.last || 0) + 1 | |
(start..9).inject([]) do |result, digit| | |
result + | |
kata(digits + [digit], sum + digit, has_pair) + | |
kata(digits + [digit, digit], sum + digit + digit, true) | |
end | |
elsif sum == 15 && has_pair | |
[digits] |
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
server { | |
access_log /opt/nginx/logs/test_server.access.log main buffer=32k; | |
error_log /opt/nginx/logs/test_server.error.log info; | |
expires 6h; | |
listen 2300 default rcvbuf=64k backlog=128; | |
root /opt/apps/test_server/current/public; | |
server_name test_server.com www.test_server.com; | |
passenger_enabled on; | |
} |
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
pid /opt/nginx/logs/nginx.pid; | |
# Run as the nginx user | |
user nginx nginx; | |
worker_processes 2; | |
error_log /opt/nginx/logs/error.log notice; | |
events { | |
worker_connections 1024; | |
use epoll; |
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 'rubygems' | |
require 'rack' | |
class Object | |
def webapp | |
class << self | |
define_method :call do |env| | |
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?) | |
[200, {}, send(func, *attrs)] | |
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 RuleBook | |
def RuleBook.add_rules(object, instance_or_class, rules) | |
instance_or_class = instance_or_class.to_s.downcase.strip.to_sym | |
raise(ArgumentError, "'instance_or_class' must equal :instance or :class") unless [:instance, :class].include?(instance_or_class) | |
raise(ArgumentError, "'rules' must be a Hash") unless rules.is_a?(Hash) | |
unless object.instance_variable_get(:@_rulebook_initiated) # Class instance variable. Not class variable. Not instance variable. Is confusing. | |
object.instance_variable_set(:@_rulebook_initiated, true) | |
object.instance_variable_set(:@_rulebook, {:instance=>{}, :class=>{}}) # @_rulebook is actually two rulebooks, instance and class | |
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
# Rake task to launch multiple Resque workers in development/production with simple management included | |
require 'resque/tasks' # Require Resque tasks | |
namespace :workers do | |
# = $ rake workers:start | |
# | |
# Launch multiple Resque workers with the Rails environment loaded, | |
# so they have access to your models, etc. |
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
# Usage: | |
respond_to :rss, :only => [:index] | |
def index | |
@deals = Deal.by_city(@city).limit(15) | |
respond_with(@deals) do |format| | |
format.rss { render :rss => @deals, :title => "KupiKon", :item => { :title => :title, :description => :description }} | |
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
ActiveRecord::Base.connection.increment_open_transactions | |
ActiveRecord::Base.connection.begin_db_transaction | |
at_exit do | |
ActiveRecord::Base.connection.rollback_db_transaction | |
ActiveRecord::Base.connection.decrement_open_transactions | |
end |
OlderNewer