Skip to content

Instantly share code, notes, and snippets.

require 'bundler'
Bundler.setup(:default)
require 'ffi-rzmq'
require 'celluloid/zmq'
require 'celluloid/current'
require 'securerandom'
Celluloid::ZMQ.init
class SockOne
include Celluloid::ZMQ
attr_reader :sock
### A quick dirty fix.
## Current version ActiveRecord 4.2.0
## Jruby 9.0.5.0
## Avoid some Mutex lock. Reference issue -> https://github.com/rails/rails/pull/14938.
## Why we need this.
## Since we cant upgrade to 5.2.stable because the JDBC driver support are still not mature and the 5.0.x is causing some strange
## error (which I seem is fixed only in 5.2.stable)
class Handler
@meetme2meat
meetme2meat / Gemfile
Created February 20, 2018 07:17 — forked from karmi/Gemfile
Sinatra + EventSource JavaScript Streaming
source "http://rubygems.org/"
gem "sinatra", "~> 1.3.0"
gem "thin"
## Tested under Jruby and Connection Pool 2.2.1
## jruby 9.0.5.0 (2.2.3) 2016-01-26 7bee00d Java HotSpot(TM) 64-Bit Server VM 25.144-b01 on 1.8.0_144-b01 +jit [darwin-x86_64]
require 'pg'
require 'colorize'
require 'connection_pool'
require 'securerandom'
$db_options = {user: 'postgres', dbname: 'postgres'}
class ScpLookup
attr_reader :pg_conn, :db_options
def initialize(db_options)
@meetme2meat
meetme2meat / requestor.awk
Created November 17, 2017 03:08 — forked from sinegar/requestor.awk
Combine tcpdump packets into requests and response times.
#!/usr/bin/awk -f
# #
#
# Inspired by http://www.percona.com/doc/percona-toolkit/2.1/pt-tcp-model.html
#
# Example usage:
# $ tcpdump -i any -s 0 -nnq -tt 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
# 1349692787.492311 IP X.X.X.X.XXXX > X.X.X.X.XXXX: tcp 1448
# $ ./requestor.awk dump.file
@meetme2meat
meetme2meat / call-apply-bind-proxy.js
Created September 26, 2016 07:42 — forked from branneman/call-apply-bind-proxy.js
JavaScript call() vs apply() vs bind() vs $.proxy()
var fn = function(arg1, arg2) {
var str = '<p>aap ' + this.noot + ' ' + arg1 + ' ' + arg2 + '</p>';
document.body.innerHTML += str;
};
var context = {
'noot': 'noot'
};
var args = ['mies', 'wim'];
// Calls a function with a given 'this' value and arguments provided individually.
@meetme2meat
meetme2meat / test-2.rb
Created July 29, 2016 06:56
Test-2 file
require 'rubygems'
$zone = "-06:00"
require 'pry'
#inspect.txt
#rinspect.txt
MONTH= {"Jan" => 1,"Feb" =>2,"Mar" => 3,"Apr" => 4,"May" => 5,"Jun" => 6,"Jul" => 7,"Aug" => 8,"Sep" => 9,"Oct" => 10,"Nov" => 11,"Dec" => 12}.freeze
def find_time(time)
day = time.match(/^\d{2}/)[0].to_i
month = MONTH[time.match(/[A-Z][a-z]{2}/)[0]]
@meetme2meat
meetme2meat / test.rb
Created July 29, 2016 06:55
Test rb file.
require 'rubygems'
$zone = "-06:00"
require 'pry'
#inspect.txt
#rinspect.txt
MONTH= {"Jan" => 1,"Feb" =>2,"Mar" => 3,"Apr" => 4,"May" => 5,"Jun" => 6,"Jul" => 7,"Aug" => 8,"Sep" => 9,"Oct" => 10,"Nov" => 11,"Dec" => 12}.freeze
def find_time(time)
day = time.match(/^\d{2}/)[0].to_i
month = MONTH[time.match(/[A-Z][a-z]{2}/)[0]]
year = time.match(/\d{4}/)[0].to_i
@meetme2meat
meetme2meat / gist:f22f0b62eeb314fb3c51eac96b059f1c
Created July 26, 2016 04:41
Ruby's performance tuning way
@meetme2meat
meetme2meat / logstash.conf
Last active June 24, 2016 13:30
The following is a logstash filter conf for zeromq
input {
stdin {
}
}
filter {
zeromq {
address => "tcp://127.0.0.1:8080"
mode => "client"
}