Skip to content

Instantly share code, notes, and snippets.

@anhkind
anhkind / date_stub.js
Last active August 29, 2015 14:18
Stub JS Date
var lastNow = new Date();
var lastStubbedNow = new Date(1421224206 * 1000);
var oldDate = Date;
// stub with new Date function
Date = function () {
var args = arguments.length > 0 ? Array.prototype.slice.call(arguments) : [getStubbedNow().getTime()];
args.unshift(null)
return new ( Function.prototype.bind.apply( oldDate, args ) ) // http://stackoverflow.com/a/8843181/1036829
@anhkind
anhkind / active_admin.rb
Created May 21, 2015 13:04
Monkey patching to ActiveAdmin (v0.6.0) to have multiple column sorting (config.sort_order = "column1_desc, column2_asc")
# initializers/active_admin.rb
module ActiveAdmin
class ResourceController
module DataAccess
# monkey patch to have multiple column sorting as "column1_asc, column2_desc"
def apply_sorting(chain)
params[:order] ||= active_admin_config.sort_order
orders = []
params[:order].present? && params[:order].split(/\s*,\s*/).each do |fragment|
@anhkind
anhkind / color_util.rb
Created May 30, 2015 07:31
Use SASS functions to lighten/ darken a (hex) color Rails
class ColorUtil
class << self
def lighten hex_color, percent
adjust :lightness, hex_color, percent
end
def darken hex_color, percent
adjust :lightness, hex_color, percent * -1
end
@anhkind
anhkind / gist:45447fa8347e491c3a0a
Created December 12, 2015 10:19 — forked from nicdev/gist:7282303
Some nmap scans I need to keep notes for
# Discover live hosts on a subnet
# nmap -sP -PE -PP -n [subnet in CIDR notation]
nmap -sP -PE -PP -n 192.168.1.0/24
# Scan for installed software and versions
# nmap -sV --version-all [CIDR or IP]
nmap -sV --version-all 192.168.1.0/24
-- 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';
@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' \
@anhkind
anhkind / clear_redis.sh
Created April 11, 2016 19:00
Clear redis using redis-cli
#redis://redistogo:[email protected]:9402
redis-cli -h catfish.redistogo.com -p 9402 -a d20739cffb0c0a6fff719acc2728c236 flushall
@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 / open_ios_simulator.sh
Created May 11, 2016 08:52
Open iOS simulator
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
@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):