Skip to content

Instantly share code, notes, and snippets.

@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 / 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
## 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 / 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"
### 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
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
local ltn12 = assert(require('ltn12'))
local cjson = assert(require('cjson'))
local http = assert(require('socket.http'))
-- local dbg = assert(require('debugger'))
-- local signal = require("posix.signal")
-- signal.signal(signal.SIGINT, function(signum)
-- io.write("\n")
-- -- put code to save some stuff here
-- os.exit(128 + signum)
## following is a simple cicruit breaker implementation with thread support.
## https://github.com/soundcloud/simple_circuit_breaker/blob/master/lib/simple_circuit_breaker.rb
class CircuitBreaker
class Error < StandardError
end
def initialize(retry_timeout=10, threshold=30)
@mutex = Mutex.new
@retry_timeout = retry_timeout
@threshold = threshold
@meetme2meat
meetme2meat / gist:ed1223b7f9675243b9e0da082726fe2e
Created February 3, 2019 05:07 — forked from pbailis/gist:5660980
Assorted distributed database readings

Context: I was asked for a list of interesting reading relating to "distributed databases, behavior under partitions and failures, failure detection." Here's what I came up with in about an hour.

For textbooks, "Introduction to Reliable and Secure Distributed Programming" is a superb introduction to distributed computing from a formal perspective; it's really not about "programming" or "engineering" but about distributed system fundamentals like consensus, distributed registers, and broadcast. Used in Berkeley's Distributed Computing course (and HT to @lalithsuresh) Book Site

Notes from courses like Lorenzo Alvisi's Distributed Computing class can be great.

There are a bunch of classics on causality, [Paxos](ht

@meetme2meat
meetme2meat / unmarshal_interface.go
Created September 23, 2019 14:06 — forked from tkrajina/unmarshal_interface.go
Unmarshal JSON to specific interface implementation
package main
import (
"encoding/json"
"fmt"
"reflect"
)
type Something interface{}