Skip to content

Instantly share code, notes, and snippets.

View funny-falcon's full-sized avatar

Sokolov Yura funny-falcon

View GitHub Profile
@funny-falcon
funny-falcon / genpas.rb
Created February 13, 2012 07:33
Password generator
class String
def randchar
self[(rand * size).to_i]
end
end
Vowels = 'aeiouy'
Consonants = 'bcdfghjklmnpqrstvwxz'
VowelsR, ConsonantsR = [Vowels, Consonants].map{|s| /[#{s}]/}
Chars = [Vowels, Consonants]
def gen_pass(len)
@funny-falcon
funny-falcon / rainbows_start.sh
Created March 7, 2012 17:13
rainbows restart with inotifywait
export NGINX_DIR=../nginx
export LOG_DIR=$NGINX_DIR/log
export SOCK_DIR=$NGINX_DIR/socks
export APP=`basename "$(realpath "$(dirname "$0")")"`
PID_FILE=$SOCK_DIR/$APP.pid
if [ -e "$PID_FILE" ] ; then
PID=`cat $PID_FILE`
if [ -n `ps aux | awk '/rainbows/ && /$PID/ && !/awk/ {print $0}'` ] ; then
echo "Action: " $@
@funny-falcon
funny-falcon / not_ugly_test.rb
Created March 12, 2012 05:53
uglier is sometimes faster
#!/usr/bin/env ruby
require 'yaml'
y=[]
(1..10000).each{|x|
#next unless x/2==(1.0*x)/2
z=x
divisors=[1]
_continue=true
@funny-falcon
funny-falcon / enumerator_patch.rb
Created March 12, 2012 17:00
Patch Enumemator to play well with EM::Sunchrony
class Enumerator
class Error < Struct.new(:error)
end
def feed(v)
@feed = v
end
class StopIteration < ::StopIteration
attr :result
def initialize(msg, result)
super(msg)
@funny-falcon
funny-falcon / test_mutex.rb
Created March 12, 2012 23:22
Fixed EM Mutexes
require 'eventmachine'
require 'fiber'
module EM
module Synchrony
class Mutex
def initialize
@waiters = []
end
def lock
@funny-falcon
funny-falcon / test_loop.rb
Created March 14, 2012 05:27
Test next_tick loop and timer
require 'eventmachine'
EM.run do
i = 0
myloop = ->{
puts i
i += 1
EM.next_tick(myloop)
}
EM.next_tick(myloop)
@funny-falcon
funny-falcon / test_queue.rb
Created March 16, 2012 20:59
Arrays magic number 16 and queue or when ruby can be faster than ruby
# This notebook is on Atom N270 1.33GHz, so that I use only 500000 iterations
~/tmp/ruby$ ruby test_queue.rb 500000
Rehearsal -------------------------------------------------------------
pure man queue 2 0.570000 0.000000 0.570000 ( 0.574775)
pure man queue 4 0.550000 0.000000 0.550000 ( 0.557201)
pure man queue 15 0.600000 0.000000 0.600000 ( 0.599789)
pure man queue 16 1.620000 0.000000 1.620000 ( 1.615062)
pure man queue 48 1.720000 0.000000 1.720000 ( 1.729971)
pure man queue 128 2.130000 0.000000 2.130000 ( 2.136135)
pure ruby smart queue 4 1.170000 0.000000 1.170000 ( 1.166562)
@funny-falcon
funny-falcon / primes.rb
Last active October 2, 2015 05:47
Primes in a range
class BitSet
def initialize
@bm = {}
end
def set(i)
n = i >> 4
@bm[n] = @bm[n].to_i | (1 << (i & 0xF))
end
def test(i)
@bm[i/16].to_i[i & 0xF] != 0
@funny-falcon
funny-falcon / remove disk
Created April 6, 2012 09:24
SATA hotswap
echo 1 > /sys/block/sd#/device/delete
@funny-falcon
funny-falcon / perf_and_gc.diff
Created May 4, 2012 08:47
Ruby-1.9.3-p194 performance patch
diff --git a/common.mk b/common.mk
index eb89a2b..59cdfe4 100644
--- a/common.mk
+++ b/common.mk
@@ -630,7 +630,8 @@ file.$(OBJEXT): {$(VPATH)}file.c $(RUBY_H_INCLUDES) {$(VPATH)}io.h \
gc.$(OBJEXT): {$(VPATH)}gc.c $(RUBY_H_INCLUDES) {$(VPATH)}re.h \
{$(VPATH)}regex.h $(ENCODING_H_INCLUDES) $(VM_CORE_H_INCLUDES) \
{$(VPATH)}gc.h {$(VPATH)}io.h {$(VPATH)}eval_intern.h {$(VPATH)}util.h \
- {$(VPATH)}debug.h {$(VPATH)}internal.h {$(VPATH)}constant.h
+ {$(VPATH)}debug.h {$(VPATH)}internal.h {$(VPATH)}constant.h \