Skip to content

Instantly share code, notes, and snippets.

Maksym Melnychok keymone

Block or report user

Report or block keymone

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:19393
% list of {type, flag} tuples
pack(List) -> pack(List, <<>>).
pack([], Ready) -> Ready;
pack([{Type, Flag}|Rest], Ready) ->
Bit = ?MODULE:Type(Flag) - 1,
Size = size(Ready) * 8,
io:format("switch bit ~p in ~p bits~n", [Bit, Size]),
switch(Bit, Size, Rest, Ready).
View gist:78790
-module(base32).
-export([encode/1, decode/1]).
encode(Binary) ->
encode(Binary, <<>>).
encode(<<>>, To) -> To;
encode(<<B:1>>, To) -> <<To/binary, (symbol(B)), "====">>;
encode(<<B:2>>, To) -> <<To/binary, (symbol(B)), "=">>;
encode(<<B:3>>, To) -> <<To/binary, (symbol(B)), "=======">>;
View upgrade.rb
#!/bin/env ruby
require 'fileutils'
DRUPAL_MAJOR = 6
puts "Scanning for available drupal versions"
available = Dir['*'].map do |file|
if file =~ /^drupal-#{DRUPAL_MAJOR}\.(\d+)$/
$1.to_i
@keymone
keymone / gist:1827669
Created Feb 14, 2012
File.each_lines_batch
View gist:1827669
class IO
def each_lines_batch(batch_size=1000, buffer_size=4096)
lines = []
chunk = ""
while data = file.read(buffer_size)
chunk << data
lines += chunk.lines.to_a
# last line might not be read until it's end
@keymone
keymone / tailor.rb
Created Jun 21, 2012
the realtime newrelic
View tailor.rb
# Usage, assuming that production.log is your rails log
#
# $ tail -f production.log | grep Completed | ruby tailor.rb <estimate> <size>
#
# * estimate is estimated number of requests per second (make it 50% larger)
# * size is length of every stat block(second, minute, hour)
# a line to print out
#
# @accept [Integer] num number of requests
@keymone
keymone / graph.rb
Created Jul 11, 2012
puppet repo graph
View graph.rb
# Generates infrastructure graph in DOT format
# Usage:
# $ find . -name '*.pp' | while read file; do cat $file; echo; done | \
# ruby graph.rb > puppet.dot
NODE = /^\s*(class|define|node)(\s+)([\w:]+)/
RELATION = /^\s*(require|inherits|include)(\s+)([\w:]+)/
USAGE = /^\s*([\w:]*[\w])(\s*)\{(\s*)/
IGNORE = %w{file package service cron exec Exec line plugin}
@keymone
keymone / speedtest.rb
Created Jul 16, 2012 — forked from equivalent/speedtest
ljust speed test
View speedtest.rb
# just speed test for http://stackoverflow.com/questions/11502629/how-to-do-number-to-string-suffix/11502715#11502715
# if we properly test int<->str conversion the log_10 method is about 30% faster
begin
int = 5
a = Time.now.to_f
10_000_000.times { int.to_s.ljust(3, "0").to_i }
puts Time.now.to_f - a # => 1.3s
View some.sql
create table mc (id int, member varchar(3));
insert into mc values (1, 'abc'), (1, 'pqr'), (2, 'xyz'), (2, 'pqr'), (3, 'pqr'), (3, 'abc');
Select id,count(*) as total from mc group by id having total=(Select count(*) from mc where id=1);
-- Result:
-- +------+-------+
-- | id | total |
-- +------+-------+
View graph.rb
# Generates infrastructure graph in DOT format
# Usage:
# $ find . -name '*.pp' | while read file; do cat $file; echo; done | \
# ruby graph.rb > puppet.dot
NODE = /^\s*(class|define|node)(\s+)([\w:]+)/
RELATION = /^\s*(inherits|include)(\s+)([\w:]+)/
RELATION2 = /^\s*class(\s+)\{\s*(['"]?)([\w:]+)/
USAGE = /^\s*([\w:]*[\w])(\s*)\{(\s*)/
IGNORE = %w{file package service cron exec Exec line plugin user group class
View puppet_autoload_patch.rb
require 'rubygems'
require 'puppet/util/autoload'
class Puppet::Util::Autoload
class << self
def search_directories(env=nil)
@search_directories ||= {}
# cache only after initialization
if Puppet.settings.app_defaults_initialized?
@search_directories[env] ||= search_directories_uncached(env)
You can’t perform that action at this time.