Skip to content

Instantly share code, notes, and snippets.

View EmmanuelOga's full-sized avatar
🕹️

Emmanuel Oga EmmanuelOga

🕹️
View GitHub Profile
@EmmanuelOga
EmmanuelOga / gist:165867
Created August 11, 2009 14:41
/usr/bin/escapepath utility: escape spaces on file names.
#!/usr/bin/ruby
# /usr/bin/escapepath utility: escape spaces on file names.
require 'shellwords'
puts(STDIN.gets.chomp.shellescape) while not STDIN.eof?
@EmmanuelOga
EmmanuelOga / Programator2000.rb
Created October 12, 2009 19:55
Programator2000
require 'singleton'
set_trace_func proc { |event, file, line, id, binding, classname|
if event == "line" && file == "Programator2000"
puts Programator2000.instance.to_lines[line - 1]
print "[NEXT]"
gets
end
# Taken from passenger_memory_stats script
# Returns the private dirty RSS for the given process, in KB.
def determine_private_dirty_rss(pid)
total = 0
File.read("/proc/#{pid}/smaps").split("\n").each do |line|
line =~ /^(Private)_Dirty: +(\d+)/
if $2
total += $2.to_i
end
# rack-httperflog
# httperf wsesslog generator middleware.
# http://github.com/EmmanuelOga/rack-httperflog/
require "net/http"
require "nokogiri"
require "rack"
module Rack
class Httperflog < Struct.new(:app, :ping_urls, :log_path, :flag_path)
def call(env)
@EmmanuelOga
EmmanuelOga / Dirty Qick Campfirenotifications on linux
Created December 22, 2009 02:47
Qick & Dirty Campfire notifications on linux
require "rubygems"
require "uri"
require "yajl/http_stream"
require 'shellwords'
require 'open-uri'
require 'term/ansicolor'
$domain = "broadspire"
$token = '90454e67ebe1e202034a49266cc0abf0de7e538e'
$room_id = 177718
@EmmanuelOga
EmmanuelOga / r191.txt
Created December 26, 2009 22:42
curb, typhoeus, net:http, em-http quick benchmark
ruby 1.9.1p243 (2009-07-16 revision 24175) [x86_64-linux]
curb (0.6.2.1)
em-http-request (0.2.5)
eventmachine (0.12.10)
typhoeus (0.1.13)
user system total real Memory (Kb)
4kb std
0.000000 0.000000 3.010000 ( 22.408594) 24,484
@EmmanuelOga
EmmanuelOga / gist:264690
Created December 28, 2009 14:17
Model model
class Model < AR::Base
named_scope :my_grandma, lambda { blah! }
belongs_to :something
CONSTANT = "K"
attr_wicked :column
attr_accessible :col2
attr_protected :col3
@EmmanuelOga
EmmanuelOga / gist:264718
Created December 28, 2009 15:17
Hash vs Struct allocations test
# Use with ree.
# http://blog.evanweaver.com/articles/2009/10/21/object-allocations-on-the-web/
GC.enable_stats
def sizeof(obj)
GC.clear_stats
obj.clone
puts "#{GC.num_allocations} allocations"
GC.clear_stats
obj.clone
puts "#{GC.allocated_size} bytes"
@EmmanuelOga
EmmanuelOga / the_horror.rb
Created January 4, 2010 22:56
A piece of crap.
# This is crap. :o
# Why did I code this? I should have know better.
# only in ruby 1.9
class Stringificator < BasicObject
Signature = " > a hidden method < "
define_method(Signature) { ::Kernel.binding }
def method_missing(x)
x.to_s
@EmmanuelOga
EmmanuelOga / hello_world.cairo.c
Created January 6, 2010 03:29
gcc hello_world.cairo.c -lcairo -ohello_world
#include <cairo/cairo.h>
int
main (int argc, char *argv[])
{
cairo_surface_t *surface =
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 240, 80);
cairo_t *cr =
cairo_create (surface);