Skip to content

Instantly share code, notes, and snippets.

View fl00r's full-sized avatar

Peter Yanovich fl00r

View GitHub Profile
# 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
# 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."
@fl00r
fl00r / server_balancing.rb
Created April 12, 2012 09:06
Server balancing by file ID
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
module ActiveRecord
module QueryMethods
alias :old_where :where
def where(opts, *rest)
opts.merge!({:locale => :ru})
old_where(opts, *rest)
end
end
end