Skip to content

Instantly share code, notes, and snippets.

View mikhailov's full-sized avatar

Anatoly Mikhaylov mikhailov

View GitHub Profile
@mikhailov
mikhailov / qu.rb
Last active September 20, 2015 19:47
quick union
class QU
attr_reader :array
def initialize(array)
@array = array
end
def union(p,q)
return if p == q
@array[root(p)] = root(q)
@mikhailov
mikhailov / gist:706275
Created November 19, 2010 09:09
nginx native ssl redirection without ssl_requirement
server {
listen 80;
server_name *.domain.com;
rewrite ^(.*) https://$host$1 permanent;
}
@mikhailov
mikhailov / capistrano_log_recipes.rb
Created March 25, 2011 06:24
Capistrano extra recipes
namespace :log do
desc "A pinch of tail"
task :tailf, :roles => :app do
run "tail -n 10000 -f #{shared_path}/log/#{rails_env}.log" do |channel, stream, data|
puts "#{data}"
break if stream == :err
end
end
@mikhailov
mikhailov / valid_parentheses.rb
Last active September 26, 2015 15:19
ValidParentheses
class ValidParentheses
SYMBOLS = {"(" => ")", "[" => "]", "{" => "}"}
def initialize(array)
@array = array.split("")
@stack = []
end
def process
@array.each do |i|
@mikhailov
mikhailov / decimal_mark.rb
Created September 26, 2015 16:23
DecimalMark
class DecimalMark
def initialize(data)
@array = data.split("")
@new_array = []
end
def process
i = 0
loop do
@mikhailov
mikhailov / fizz_buzz.rb
Created September 26, 2015 16:52
FizzBuzz
class FizzBuzz
def initialize(array)
@array = array
@new_array = []
end
def process
@array.each do |e|
value = \
if e % 3 == 0 && e % 5 == 0
@mikhailov
mikhailov / reverse_sentence.rb
Created September 26, 2015 20:09
ReverseSentence
class ReverseSentence
def initialize(string)
@array, @array_reversed = string.split(" "), []
end
def process
@array_reversed << @array.pop while @array.any?
@array_reversed.join(" ")
end
@mikhailov
mikhailov / mysql_strict.rb
Created July 2, 2012 08:32
Rails 3.2 monkey-patch to enable Mysql strict mode by default
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
private
alias_method :configure_connection_without_strict_mode, :configure_connection
def configure_connection
configure_connection_without_strict_mode
strict_mode = "SQL_MODE='STRICT_ALL_TABLES'"
execute("SET #{strict_mode}", :skip_logging)
end
@mikhailov
mikhailov / script.sh
Created October 13, 2012 09:22
Fight with TCP Slow Start
#!/bin/sh
ip route |grep default # default via 10.235.9.1 dev eth0
ip route change default via `ip route| awk '/^def/{print $3}'` dev eth0 initcwnd 16
ip route |grep default # default via 10.235.9.1 dev eth0 initcwnd 16
sysctl -w net.ipv4.tcp_slow_start_after_idle=0
sysctl -a |grep net.ipv4.tcp_slow_start_after_idle
@mikhailov
mikhailov / tests.rb
Created October 2, 2015 18:28
Basic testing framework
class Object
class UnitTestError < StandardError; end
def describe(description, &block)
if Object.class_eval(&block)
print '.'
else
puts 'FAIL ' + description
raise UnitTestError