Skip to content

Instantly share code, notes, and snippets.

alias unzip-stream="python -c \"import zipfile,sys,StringIO;zipfile.ZipFile(StringIO.StringIO(sys.stdin.read())).extractall(sys.argv[1] if len(sys.argv) == 2 else '.')\""
@sungmin-park
sungmin-park / gist:4143172
Created November 25, 2012 11:23 — forked from mfenniak/gist:2978805
An extension of Flask that adds file hashes to static file URLs built by url_for("static"...)
import os.path
import contextlib
import hashlib
from flask import Flask
from flask.helpers import safe_join
# Injects an "h" parameter on the URLs of static files that contains a hash of
# the file. This allows the use of aggressive cache settings on static files,
# while ensuring that content changes are reflected immediately due to the
# changed URLs. Hashes are cached in-memory and only checked for updates when
@sungmin-park
sungmin-park / jquery.facebook.coffee
Last active December 10, 2015 03:08
Facebook Javascript SDK loader with jQuery
$.facebook = (id, {locale}={}, callback=->) ->
locale ?= 'en_US'
window.fbAsyncInit = ->
FB.init appId: id, status: true, cookie: true, xfbml: true
FB.Canvas.setAutoGrow()
FB.getLoginStatus callback
$('body').append $('<div>').attr('id', 'fb-root')
$('<script>').each ->
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
@sungmin-park
sungmin-park / hold_kernel_packages.sh
Last active December 14, 2015 03:49
hold kernel related pakges for ubuntu and debian
dpkg -l |egrep '^.. (linux|grub|initramfs)'| cut -d' ' -f3 | sed 's/$/ hold/' | sudo dpkg --set-selections
@sungmin-park
sungmin-park / ralias
Created May 21, 2013 12:48
source ralias
ruby ralias.rb > .ralias
source .ralias
@sungmin-park
sungmin-park / sqlalchemy_polymorphic_aliased.py
Created October 23, 2013 09:25
SQLAlchemy has wired problem of aliased.
#!/usr/bin/env python
from sqlalchemy import Column, Integer, create_engine, case, func, String, cast
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, aliased
engine = create_engine('sqlite://', echo=True)
Base = declarative_base()
class Number(Base):
@sungmin-park
sungmin-park / diconnectdb
Last active March 11, 2020 13:45
Disconnect all connection on target database for postgresql.
#!/usr/bin/env bash
if [ -z "$1" ]; then
echo "usage> $0 database"
exit 1
fi
cat <<-EOF | psql -d $1
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = '$1'
#!/bin/sh
if [ "$#" -ne 3 ]; then
echo "Usage: $0 host id pass"
exit 1
fi
openssl s_client -connect $1:993 -quiet << EOF
a1 LOGIN $2 $3
a5 LOGOUT
EOF
#!/bin/sh
if [ -z "$1" ]
then
echo "usage> $0 DATABASE" >&2
exit 1
fi
# Cannot use pipe. Pipe produces an empty backup file when pg_dump has errors.
FILE_NAME="$1-`date +"%Y%m%d-%H%M%S"`.sql"