Skip to content

Instantly share code, notes, and snippets.

View bankair's full-sized avatar
🦞

Alexandre Ignjatovic bankair

🦞
View GitHub Profile
ADD2 = ->(a) { a + 2 }
DIV3 = ->(a) { a / 3 }
(ADD2 + DIV3).call(4)
# == 3
(DIV3 + ADD2).call(4)
# == 2
# Note: the order is important here
class Proc
def +(other)
Proc.new { |args| self.call(other.call(arg)) }
end
end
add_2_div_3 = (add_2 . div_3)
def self.add_2_div_3(a)
div_3(add_2(a))
end
puts add_2_div_3(4)
# Print 2
def self.add_2(a)
a + 2
end
def self.div_3(a)
a / 3
end
require 'benchmark'
require 'benchmark/ips'
Benchmark.ips do |r|
r.report('merge!') do
(1..100).inject({}) do |h, e|
h.merge!(e => e)
end
end
ref = (1..100).to_a
r.report('Hash[]') do
@bankair
bankair / git-inspect.rb
Created February 20, 2015 13:17
Display the commit that last modified a specific line of a file
#! /usr/bin/ruby
file, line = (ARGV.shift || raise('Missing loc. Ex: /path/to/file:line')).split(/:/)
exec "git show $(git blame #{file} -L #{line},#{line} | awk '{print $1}')"
[NewRelic][11/26/14 15:26:13 +0000 XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX (2)] WARN : Timed out opening connection to collector after 120.003031938 seconds. If this problem persists, please see http://status.newrelic.com
function fuck() {
if killall -9 "$2" 2>/dev/null; then
echo ; echo " (╯°□°)╯︵$(echo "$2"|toilet -f term -F rotate)"; echo
fi
}
function get_free_port_starting_from() {
local PORT=$1
local QUIT=0
while [ "$QUIT" -ne 1 ]; do
lsof -i :$PORT> /dev/null
if [ $? -ne 0 ]
then
QUIT=1
else
PORT=`expr $PORT + 1`