Skip to content

Instantly share code, notes, and snippets.

-- postgres snippets
-- show databases owned by a specific user
psql -d postgres -c "SELECT datname FROM pg_database JOIN pg_authid ON pg_database.datdba = pg_authid.oid WHERE rolname = 'rolename'"
-- see all active sessions
SELECT * FROM pg_stat_activity;
-- kill sessions
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'dbname' AND pid <> pg_backend_pid();
# get external ip
wget -q -O - checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
# javafy regex
echo '/^\d{5}\\(?:[-\s]\d{4})?$/' | sed 's/\\/\\\\/g'
# loop to make dirs
for i in {1..5}; do mkdir unit$i; done
@meganlkm
meganlkm / laravel_shared_hosting_project.sh
Last active May 19, 2019 23:14
setup a laravel 4.2 project to deploy to a shared hosting provider
#!/bin/bash
myproject='myproject'
mywwwdir='public_html'
# initialize project
composer create-project laravel/laravel $myproject 4.2.*
cd $myproject
perl -pi -e "s|/public|/../${mywwwdir}|" bootstrap/paths.php
@meganlkm
meganlkm / laravel_deploy_shared_host.sh
Last active April 17, 2016 23:45
deploy laravel project to a shared hosting provider
#!/bin/bash
PRJ_HOME=$(pwd)
REPO_URL='git@github.com:username/repo.git'
BUILD_DIR=${PRJ_HOME}/project-build
APP_DIR=${BUILD_DIR}/my-app
RSYNC_CMD='rsync -avz -e ssh --exclude-from ./.build-exclude'
COMPOSER_CMD='composer install'
@meganlkm
meganlkm / laravel5_shared_hosting_project.sh
Last active January 3, 2019 19:49
setup a laravel5 project to deploy to a shared hosting provider
#!/bin/bash
myproject='myproject'
mywww='public_html'
# initialize project
composer create-project laravel/laravel $myproject --prefer-dist
cd $myproject
# fix paths to public
#!/bin/bash
#
# installs node into a python virtualenv
# dependencies: pip, virtualenv, virtualenvwrapper
#
# install dependencies:
# sudo easy_install pip
# sudo pip install virtualenv virtualenvwrapper
#
# Usage: mknodeenv myproject
#!/bin/bash
#
# Source this from .bash_profile
#
# TODO py-ify and ansible-fy this
# append source .mypystuff to .bash_profile
#
# Usage: mkpy projectname
function get_st3_prj_file() {
@meganlkm
meganlkm / sqlplus
Created October 14, 2015 17:55
This is how I got the sublime text SQLExec plugin to connect to oracle
#!/bin/bash
# this file should be in your path before
# instantclient/sqlplus is picked up.
# make sure to chmod +x
source /path/to/your/env/settings/.bash_profile
/path/to/instantclient/sqlplus $@
@meganlkm
meganlkm / release
Created July 15, 2016 05:13
bump VERSION and tag
#!/bin/bash
VERSION=$(<VERSION)
echo "Current VERSION: ${VERSION}"
V_LIST=(`echo $VERSION | tr '.' ' '`)
V_MAJOR=${V_LIST[0]}
V_MINOR=${V_LIST[1]}
V_PATCH=${V_LIST[2]}
@meganlkm
meganlkm / boto3-client.py
Created October 9, 2017 17:40
function and decorator that returns a boto3 client or resource
import os
from functools import wraps
from inspect import getargspec
import boto3
AWS_REGION = os.getenv('AWS_REGION', 'us-east-1')
def get_client(name, client_type='client', region=None, *args, **kwargs):