Skip to content

Instantly share code, notes, and snippets.

View greyblake's full-sized avatar
🇺🇦
#StandWithUkraine

Serhii Potapov greyblake

🇺🇦
#StandWithUkraine
View GitHub Profile
@greyblake
greyblake / rubocop-detect.sh
Created March 19, 2015 14:35
rubocop-detect
# Finds ruby files that was changed in HEAD against passed branch
# and run rubocop with them. It's supposed to help to detect
# rubocop offenses introduced by YOU.
#
# Examle:
# rubocop-detect develop
function rubocop-detect(){
local branch=${1:-master}
echo -e "\e[1mCOMPARING:\e[0m"
@greyblake
greyblake / method_visibility_declaration_proposal.rb
Last active August 29, 2015 14:15
Method visibility declaration
# Since ruby 2.1, method definition returns a name of a method as a symbol.
# Example:
def aaa; end # => :aaa
# How we do it currently
class SomeClass
def pub_meth
# ...
end
@greyblake
greyblake / json_benchmark.rb
Created September 19, 2014 08:50
JSON backends comparison
#
# user system total real
# json_gem 1.970000 0.000000 1.970000 ( 1.969385)
# yajl 2.090000 0.000000 2.090000 ( 2.096399)
# oj 1.240000 0.000000 1.240000 ( 1.234021)
# json_pure 23.400000 0.000000 23.400000 ( 23.432088)
#
require 'benchmark'
@greyblake
greyblake / xml_benchmarks.rb
Created September 19, 2014 07:49
XmlMini backend benchmarks
# Result
#
# user system total real
# REXML 8.190000 0.020000 8.210000 ( 8.211740)
# LibXML 1.140000 0.000000 1.140000 ( 1.141131)
# Nokogiri 1.600000 0.000000 1.600000 ( 1.604999)
#
require 'benchmark'
@greyblake
greyblake / show_page.rb
Created November 21, 2013 19:22
My tiny useful method for Capybara webkit driver to see screenshot in one command when I debug
def show_page
filename = "/tmp/shot.png"
driver = page.driver
driver.save_screenshot(filename)
system "eog #{filename}"
end
class SocialNotifier
include Celluloid
attr_reader :status
def intialize(&block)
@block = block
end
def run
# Override some stuff to detect FacotoryGirl usage out of `it`
module RSpec
module Core
class ExampleGroup
class << self
# redefine to do nothing
def it(*args)
end
@greyblake
greyblake / index.cgi
Created October 2, 2012 18:22
Serg server
#!/usr/bin/env ruby
require 'cgi'
# Refresh period
PERIOD = 1 # seconds
# Calculate random value from 1 to 10
value = rand(10) + 1
@greyblake
greyblake / bashrc
Created July 7, 2012 16:27
current repo in PS1
# git branch
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
export PS1='\u@\h \[\033[1;34m\]\w\[\033[0m\]\[\033[0;33m\]$(parse_git_branch)\[\033[0m\]$ '
@greyblake
greyblake / art.rb
Created April 27, 2012 14:12
art.rb
class Art
L = 2
MAX_EPOCH = 20
def initialize(n, m, p = 0.45)
@n = n
@m = m
@p = p
@w1 = Array.new(n) { Array.new(m) { 1.0 / (1+n) } }
@w2 = Array.new(m) { Array.new(n) { 1.0 } }