Skip to content

Instantly share code, notes, and snippets.

@marinbek
marinbek / redshift_unload_copy.sql
Created May 21, 2014 08:37
unload & copy redshift data
SELECT 'UNLOAD (\'select * from '||n.nspname ||'.'|| c.relname||'\') TO \'s3://bucket/' || c.relname || '_\';' as "Name"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v','S','')
AND n.nspname LIKE 'nu_alibris';
SELECT 'COPY ' || n.nspname ||'.'|| c.relname ||' from \'s3://bucket/' || c.relname || '_\';' as "Name"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
@marinbek
marinbek / import_schema_to_schema.sql
Created June 2, 2014 09:46
Import all tables from one schema to another schema - Redshift
SELECT 'drop table '||n.nspname ||'.'|| c.relname||' CASCADE;' as "Name"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v','S','')
AND n.nspname = 'destination_schema';
SELECT 'create table '||n.nspname ||'.'|| c.relname||' as select * from source_schema.' || c.relname||';' as "Name"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v','S','')
@marinbek
marinbek / aws.js
Created April 15, 2015 06:43
AWS ip range parser
var https = require('https'),
regions = {
"ap-northeast-1": "Tokyo, JP",
"ap-southeast-1": "SG",
"ap-southeast-2": "Sydney, AU",
"eu-central-1": "Frankfurt, DE",
"eu-west-1": "IE",
"sa-east-1": "Sao Paulo, BR",
"us-east-1": "VA, US",
"us-west-1": "CA, US",
@marinbek
marinbek / rump debugging.md
Created February 19, 2016 13:48
rumpkernel debugging

Generally speaking, use rumprun -D [port] and target remote:[port] in gdb.

Common gdb commands

  • disas or disas startaddr endaddr - disassembles around current PC or specific address
  • info locals/args/variables - prints out local variables, function arguments, all variables...
  • info registers - prints out all registers and their values
  • break file:linenr - sets a breakpoint on specific file/line
  • c - continue execution
  • n - step to next command in current stack frame
  • si - step by single instruction
@marinbek
marinbek / jenkins-go.sh
Created November 28, 2016 15:37
jenkins golang setup
export GOROOT=/usr/local/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH:$WORKSPACE/bin
export GOPATH=$WORKSPACE
git config url."git@github.com:".insteadOf "https://github.com/"
go get github.com/AlekSi/gocov-xml
go get github.com/axw/gocov/gocov
mkdir -p $GOPATH/src/github.com/NextUserSF/

Keybase proof

I hereby claim:

  • I am marinbek on github.
  • I am mbek (https://keybase.io/mbek) on keybase.
  • I have a public key ASDTZnlrv7nKLbuojoT2ybXNJIZl8dK-uHzTOxQyO3l3zQo

To claim this, I am signing this object:

@marinbek
marinbek / mongo.md
Last active October 12, 2017 16:33
useful mongo scripts

Deleting duplicates

 var count=0;
 var coll = [];
 
 db.getCollection('some_collection').aggregate([
    { "$group": {
        "_id": { "id": "$id" },
 "dups": { "$push": "$_id" },
@marinbek
marinbek / hexfile.py
Created September 26, 2018 14:28
Save a string of HEXs into a bin file and curl it away
import binascii
data = '4b4344'
with open('bla.bin', 'wb') as fout:
for hex in [data[i:i+2] for i in range(0, len(data), 2)]:
fout.write(binascii.unhexlify(hex))
# now send it with curl -X POST --data-binary @bla.bin http://foo.com

git verify-pack -v .git/objects/pack/pack-f5ac2e2d5f7e3c247be0ec6eff02d303ab7ddffd.idx | sort -k 3 -n | tail -10 git rev-list --objects --all | grep c58053e7cc22579a2abacc8c85219117b5252718

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch -rf releases' --prune-empty --tag-name-filter cat -- --all

git gc --aggressive --prune=now