Skip to content

Instantly share code, notes, and snippets.

@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'
@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 / ralias
Created May 21, 2013 12:48
source ralias
ruby ralias.rb > .ralias
source .ralias
@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
/* 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 / 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 ->
@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
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 '.')\""
#!/bin/sh
# Shell script to install your public key on a remote machine
# Takes the remote machine name as an argument.
# Obviously, the remote machine must accept password authentication,
# or one of the other keys in your ssh-agent, for this to work.
#
# http://www.devthought.com/2009/09/19/get-ssh-copy-id-in-mac-os-x/
#
@sungmin-park
sungmin-park / os_system_vs_subprocess_call.py
Created January 10, 2012 20:08
os.system vs subprocess.call
import os
os.system()
# http://bugs.python.org/issue1524
os.system(
'call "c:\\Program Files\\ImageMagick-6.7.4-Q16\\convert.exe" ' + \
'"c:\\Users\\Public\\Pictures\\Sample Pictures\\Chrysanthemum.jpg"' + \
' ' + '"c:\\Users\\Public\\Pictures\\Sample Pictures\\Chrysanthemum.gif"'
)
from subprocess import call