Skip to content

Instantly share code, notes, and snippets.

View gazay's full-sized avatar
🌐

Alex Gaziev gazay

🌐
View GitHub Profile
module A
# prefer when there are less than three class methods
# and there are instance methods
def self.boo
end
def self.soo
end
def fuuu
@barbuza
barbuza / microdns.py
Created May 20, 2012 16:21
fake python dns server for use with mac /etc/resolver system
# -*- coding: utf-8 -*-
import re
import socket
class UnsupportedQuery(BaseException):
pass
# eval with method definition is used to prevent warnings in some situations
DEFINEE = <<-CODE
eval 'def __; end'
it = method(:__).owner rescue instance_method(:__).owner
eval 'undef __'
it
CODE
self # => main

jitter.sh

For making your own jittergrams

Usage

Two files as input:

./jitter.sh file_01.jpg file_02.jpg
@brainopia
brainopia / gist:2215241
Created March 27, 2012 11:47
Set bom recursively to ruby files
#!/usr/bin/env ruby
require 'epath'
bom = "\xEF\xBB\xBF".force_encoding('binary')
Path.glob('**/*.rb') do |file|
next if file.binread(3) == bom
previous = file.binread
file.write bom + previous
end
# "python-like" import
load path, true # => will load new constants and methods under anonymous module
Module.nesting.first # => inside loaded file will return the current namespace
###
module PythonImport
def import(path)
load 'importer.rb', true
@burke
burke / 0-readme.md
Created January 27, 2012 13:44 — forked from funny-falcon/cumulative_performance.patch
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

class @SortableTable
constructor: (table, options) ->
@table = $(table).children('tbody')
@columnSelector = options.columnSelector || 'th'
@iconSelector = options.iconSelector
@rowMapper = options.rowMapper
@afterSort = options.afterSort
@enable()
getColumn: (element) ->
@brainopia
brainopia / gist:1379471
Created November 19, 2011 22:39
initial draft of capistrano benchmarker
require 'benchmark'
module Capistrano::Benchmark
def self.included(base)
base.class_eval do
alias execute_task_without_benchmark execute_task
alias execute_task execute_task_with_benchmark
end
end
module Lock
extend self
delegate :connection, :to => ActiveRecord::Base
def sync(*args)
lock = Zlib.crc32 args.join
obtain lock
yield
ensure
release lock