Skip to content

Instantly share code, notes, and snippets.

@anhkind
anhkind / full_replicated_shards.yml
Last active April 27, 2017 07:37 — forked from eprothro/shards.yml
This has some minor changes from the original as `fully_replicated` is set to `true` and the key `followers` under `optopus/environments` is removed
<%
require 'cgi'
require 'uri'
def attribute(name, value, force_string = false)
if value
value_string =
if force_string
'"' + value + '"'
else
@anhkind
anhkind / reflect.py
Created November 21, 2016 15:51 — forked from huyng/reflect.py
A simple echo server to inspect http web requests
#!/usr/bin/env python
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE
# Written by Nathan Hamiel (2010)
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from optparse import OptionParser
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
@anhkind
anhkind / iterm2_keymap.txt
Created September 11, 2016 09:30
iTerm2 keymap for cursor
FOR ACTION SEND
⌘← "HEX CODE" 0x01
⌘→ "HEX CODE" 0x05
⌥← "SEND ESC SEQ" b
⌥→ "SEND ESC SEQ" f
@anhkind
anhkind / file.js
Last active July 14, 2016 14:47
Get AngularJS service in browser console
$http = angular.element(document.body).injector().get('$http')
@anhkind
anhkind / gdb_ruby_backtrace.py
Created June 15, 2016 15:40 — forked from csfrancis/gdb_ruby_backtrace.py
Dump an MRI call stack from gdb
string_t = None
def get_rstring(addr):
s = addr.cast(string_t.pointer())
if s['basic']['flags'] & (1 << 13):
return s['as']['heap']['ptr'].string()
else:
return s['as']['ary'].string()
def get_lineno(iseq, pos):
@anhkind
anhkind / open_ios_simulator.sh
Created May 11, 2016 08:52
Open iOS simulator
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
@anhkind
anhkind / curl_with_json.sh
Created April 14, 2016 19:14
Curl commands with json data
# GET
curl -v -H "Content-type: application/json" -H "Accept: application/json" -H "X-AUTH-TOKEN:123456" -X GET -d '{"q":"core"}' http://localhost:3000/search
@anhkind
anhkind / clear_redis.sh
Created April 11, 2016 19:00
Clear redis using redis-cli
#redis://redistogo:d20739cffb0c0a6fff719acc2728c236@catfish.redistogo.com:9402
redis-cli -h catfish.redistogo.com -p 9402 -a d20739cffb0c0a6fff719acc2728c236 flushall
@anhkind
anhkind / postgres_replication_cluster.sh
Last active February 22, 2016 17:42
Create a Postgres replication cluster using Docker image from sameersbn/postgresql
HOST=localhost
STORAGE_PATH=~/srv/docker/postgresql
DUMP_FILE_PATH=/path/to/dump/file
docker run --name postgresql-master -itd --restart always \
--publish 5433:5432 \
--volume $STORAGE_PATH/postgresql-master:/var/lib/postgresql \
--env 'PG_PASSWORD=passw0rd' \
--env 'DB_USER=dbuser' --env 'DB_PASS=dbuserpass' --env 'DB_NAME=dbname' \
--env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
-- check the last time tables were vacuumed and analyzed
-- Ref: https://lob.com/blog/supercharge-your-postgresql-performance/
SELECT relname, last_vacuum, last_autovacuum, last_analyze, last_autoanalyze
FROM pg_stat_all_tables
WHERE schemaname = 'public';