Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
JakubOboza / loosedolar.js
Created October 20, 2011 21:05
jquery no conflicts
var $j = jQuery.noConflict();
// Use jQuery via $j(...)
$j(document).ready(function(){
$j("div").hide();
});
// Use Prototype with $(...), etc.
$('someid').hide();
before_filter :log_ram # or use after_filter
def log_ram
logger.warn 'RAM USAGE: ' + `pmap #{Process.pid} | tail -1`[10,40].strip
end
@JakubOboza
JakubOboza / hook.rb
Created October 6, 2011 13:55
Poor Mans Hook
module PoorManHook
module ClassMethods
private
def after(*syms, &block)
syms.each do |sym| # For each symbol
str_id = "__#{sym}__after__"
unless private_instance_methods.include?(str_id)
@JakubOboza
JakubOboza / wrap.sh
Created October 3, 2011 20:53
god.rc
#!/bin/sh
### BEGIN INIT INFO
# Provides: god
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: God
### END INIT INFO
#!/usr/bin/env ruby
['rubygems', 'eventmachine'].map{|x| require x}
module SelfServer; def receive_data(data); send_data(IO.readlines __FILE__); end; end;
EventMachine::run do
host = ARGV[1] || '0.0.0.0'
port = ARGV[2] || 8080
EventMachine::start_server host, port, SelfServer
puts "If you don't like defaults try chaging host or port"
puts "Open 2 terminal and try telnet #{host} #{port} and press enter"
end
@JakubOboza
JakubOboza / ab.txt
Created October 2, 2011 13:21
How Fat is libevent ;)
14:08 kuba@MacBook-Jakub-Oboza:~% ab -c 10 -n 15000 http://127.0.0.1:8081/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 1500 requests
Completed 3000 requests
Completed 4500 requests
Completed 6000 requests
@JakubOboza
JakubOboza / before_after.js
Created August 29, 2011 21:17
before filter for js functions
function sample(a, b){
return console.log(a + b);
}
function argless(){
console.log("Argless lol");
}
function before(foo, filter, args){
return function(){
@JakubOboza
JakubOboza / build-mongo.zsh
Created August 25, 2011 21:27
MongoDB build from source
#!/bin/zsh
# my personal everyday mongodb build script
# clean
scons --clean
# pull new changes
git pull
# build into prefixed directory
@JakubOboza
JakubOboza / run.sh
Created August 13, 2011 16:02
MongoDB Sample MapReduce in a file with usage
#!/bin/bash
mongo localhost:27017/data_gatherer test.js
@JakubOboza
JakubOboza / rque.rb
Created August 13, 2011 14:53
Redis Que
require 'redis'
class RQue
attr_reader :name, :connection
def initialize(name)
@name = name
@connection = Redis.new
end