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 ActiveRecord | |
module QueryMethods | |
alias :old_where :where | |
def where(opts, *rest) | |
opts.merge!({:locale => :ru}) | |
old_where(opts, *rest) | |
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
require 'digest/sha1' | |
# | |
# servers -> [3, 5, 8] | |
# история количеств серверов | |
# | |
def fetch_server_no(acc, servers) | |
while server = servers.pop do | |
last = servers.last.to_i | |
# Для более равномерного размазывания по серверам | |
rest = Digest::SHA1.hexdigest("#{acc}_#{server}").to_i(16) % server |
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
# Govnokod | |
def update | |
if params[:user][:password].blank? | |
params[:user].delete :password | |
params[:user].delete :password_confirmation | |
end | |
if @user.update_attributes(params[:user]) | |
flash[:success] = "Edit Successful." |
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
# config.ru | |
module Server | |
def self.call(env) | |
body = File.read("index.html") | |
[200, { "Content-Type" => "text/html", "Content-Length" => body.bytesize.to_s }, [body]] | |
end | |
end | |
run Server |
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 Helpers | |
module Truncate | |
def teardown | |
teardown_couch | |
end | |
def teardown_couch | |
helpers = connection.design_docs["helpers"] | |
unless helpers && helpers.views.include?("truncate") | |
create_view |
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
# Ruby | |
module App | |
extend self | |
def call(env) | |
[ | |
200, | |
{ 'Content-Type' => 'application/json' }, | |
['{"message": "Hello World"}'] | |
] |
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 Foo | |
def Foo.bar | |
end | |
class << Foo | |
def baz | |
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
run proc{ | |
res = "Hello World" | |
[ | |
200, | |
{ | |
"Connection" => "close", | |
"Access-Control-Allow-Origin" => [ "http://domain1.com", "http://domain2.com" ] * "\n", | |
"Content-Length" => res.bytesize.to_s | |
}, | |
[res] |
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 'rack/utils' | |
run proc{ | |
res = "Hello World" | |
headers = Rack::Utils::HeaderHash.new | |
headers["Connection"] = "close" | |
headers["Content-Length"] = res.bytesize.to_s | |
headers["Access-Control-Allow-Origin"] = [ "http://mir.mail.ru", "http://my.mail.ru" ] | |
[200, headers, [res] ] |
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 TrieDict | |
attr_reader :dict | |
def initialize | |
@dict = {} | |
end | |
def put(str) | |
d = nil | |
str.chars.each do |c| |
OlderNewer