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 / 00 environment
Created February 2, 2012 19:13
Error on rake with rvm and default gemset
$ uname -a
Linux yura-desktop 2.6.38-13-generic #54-Ubuntu SMP Tue Jan 3 13:44:52 UTC 2012 i686 athlon i386 GNU/Linux
$ rvm -v
rvm 1.10.2 by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.beginrescueend.com/]
$ bash --version
GNU bash, версия 4.2.8(1)-release (i686-pc-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
@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 / performance_and_backport_gc.patch
Created February 18, 2012 12:26
Union of backport GC and performance patches for ruby-1.9.3-p125
diff --git a/Changelog.backport_gc b/Changelog.backport_gc
new file mode 100644
index 0000000..b617fc8
--- /dev/null
+++ b/Changelog.backport_gc
@@ -0,0 +1,128 @@
+Tue Jan 17 12:32:46 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * gc.c (aligned_malloc, aligned_free): covered missing defined
+ operators and fixes for cygwin.
@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