Skip to content

Instantly share code, notes, and snippets.

View oogali's full-sized avatar

Omachonu Ogali oogali

  • Ordinary Stack
  • Princeton, NJ
  • 08:20 (UTC -04:00)
View GitHub Profile
@oogali
oogali / makemodel.rb
Last active October 1, 2015 17:58
Dirty hax to make models from Hash 'documents'
!/usr/bin/env ruby
require 'rubygems'
require 'time'
require 'active_support/core_ext/string'
class ForeignKey
end
FOREIGN_KEY = ForeignKey.new
@oogali
oogali / d3-sample.html
Created March 18, 2012 05:14
sample d3 run
<html>
<head>
<title>latency!</title>
<style type = "text/css">
body { font-family: "Helvetica Neue"; font-size: 0.8em; font-weight: 300; }
#chart rect { stroke: #000; fill: #084c7d; }
text { fill: #000; }
</style>
<script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src = "https://raw.github.com/mbostock/d3/master/d3.v2.min.js"></script>
@oogali
oogali / etail.rb
Created March 22, 2012 04:53
eventmachine-tail test
#!/usr/bin/env ruby
require 'rubygems'
require 'eventmachine'
require 'eventmachine-tail'
class LogHandler < EventMachine::FileTail
def initialize(path, startpos = -1, *args)
super path, startpos
p args
@oogali
oogali / alternatives-jre16u30.sh
Created March 27, 2012 15:57
java alternatives (official sun jre)
alternatives --install /usr/bin/java java /usr/java/jre1.6.0_31/bin/java 2 \
--slave /usr/bin/keytool keytool /usr/java/jre1.6.0_31/bin/keytool \
--slave /usr/bin/orbd orbd /usr/java/jre1.6.0_31/bin/orbd \
--slave /usr/bin/pack200 pack200 /usr/java/jre1.6.0_31/bin/pack200 \
--slave /usr/bin/rmid rmid /usr/java/jre1.6.0_31/bin/rmid \
--slave /usr/bin/rmiregistry rmiregistry /usr/java/jre1.6.0_31/bin/rmiregistry \
--slave /usr/bin/servertool servertool /usr/java/jre1.6.0_31/bin/servertool \
--slave /usr/bin/tnameserv tnameserv /usr/java/jre1.6.0_31/bin/tnameserv \
--slave /usr/bin/unpack200 unpack200 /usr/java/jre1.6.0_31/bin/unpack200 \
--slave /usr/lib/jvm/jre jre /usr/java/jre1.6.0_31 \
@oogali
oogali / gist:2356389
Created April 11, 2012 02:10
Sinatra route examples
# http://host.com/path?query=1234
get '/path' do
# params['query'] will contain '1234'
end
# http://host.com/path/1234
get '/path/:number' do
# params['number'] will contain '1234'
end
@oogali
oogali / case-regex.rb
Created April 18, 2012 02:44
example on matching regex in a variable via case/when/end
#!/usr/bin/env ruby
line = "The quick brown fox jumped over the lazy dog"
r = {
:cat => /cat/,
:rabbit => /rabbit/,
:horse => /horse/,
:dog => /(\w+)\s+dog/
}
@oogali
oogali / McastReceiver.java
Created May 29, 2012 14:45
java + multicast testing
import java.net.*;
class McastReceiver {
final static String DEFAULT_MCAST_GROUP = "224.56.78.90";
final static int DEFAULT_MCAST_PORT = 12345;
final static String JOIN_MSG = "hello!";
MulticastSocket m_McastSock;
InetAddress m_Addr;
int m_Port;
@oogali
oogali / phaxio-sinatra.rb
Created August 1, 2012 02:47
Lightweight incoming fax handler via Phaxio
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
require 'json'
require 'active_support/core_ext/object'
require 'pony'
FROM_ADDRESS = '[email protected]'
@oogali
oogali / index-example.rb
Created August 17, 2012 15:24
indexes via AR migrations
class AddIndexesToAlertsTable < ActiveRecord::Migration
def self.up
add_index :alerts, [ :signature ]
end
def self.down
remove_index :alerts, [ :signature ]
end
end
@oogali
oogali / poll.rb
Created August 21, 2012 18:12
No, I don't want to install MRTG, RTG, RRDTool, MySQL, Cacti, Observium, PHP, Apache, Nginx, or FastCGI to get one-shot interface statistics.
#!/usr/bin/env ruby
require 'rubygems'
require 'snmp'
require 'time'
def mbps(bytes, duration)
((bytes / duration) * 8.to_f) / 1000000
end