Skip to content

Instantly share code, notes, and snippets.

View tym-xqo's full-sized avatar
👾

Thomas Yager-Madden tym-xqo

👾
View GitHub Profile
@tym-xqo
tym-xqo / my.safety
Last active August 29, 2015 14:12
Little script for command-line SSH tunnel to MySQL
# Create this file and save in your home directory
# chmod 600 ~/my.safety (won't protect it from root, but better than nothing)
[client]
user=$USER
password=$PASSWD
# put your actual MySQL username and password in place of $USER and $PASSWD above.
@tym-xqo
tym-xqo / uninstall.sh
Created February 3, 2015 17:37
Removing boot2docker
#!/bin/bash
# Stop boot2docker processes
boot2docker stop
boot2docker delete
# Remove boot2docker executable
sudo rm /usr/local/bin/boot2docker
# Remove boot2docker ISO and socket files
@tym-xqo
tym-xqo / .gitignore
Last active August 29, 2015 14:14
gitignore for Sublime + Virtualenv
.pyc
# Virtualenv stuffs
.Python
[Bb]in
[Ii]nclude
[Ll]ib
[Ss]cripts
pyvenv.cfg
pip-selfcheck.json
@tym-xqo
tym-xqo / local-vs-remote-query-timing.md
Created April 22, 2015 19:01
local machine vs. qa database execution timing

Same query EXPLAIN plan run from my local machine vs. from shell on qa.iadops.com

My laptop:

oao_trial=> explain analyze insert into test values (7418880);
                                         QUERY PLAN
--------------------------------------------------------------------------------------------
 Insert on test  (cost=0.00..0.01 rows=1 width=0) (actual time=0.280..0.280 rows=0 loops=1)
   ->  Result  (cost=0.00..0.01 rows=1 width=0) (actual time=0.002..0.004 rows=1 loops=1)
@tym-xqo
tym-xqo / sha-1.sql
Last active August 29, 2015 14:19
pgsql SHA-1 function
BEGIN;
CREATE EXTENSION pgcrypto;
CREATE OR REPLACE FUNCTION sha1(text)
RETURNS character varying AS
$BODY$
BEGIN
RETURN ENCODE(public.DIGEST($1, 'sha1'), 'hex');
END;
@tym-xqo
tym-xqo / psql-client-install.sh
Last active August 29, 2015 14:20
Install CLI psql client
#!/bin/bash
# Add add a line for the Postgres repository
echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" >> /etc/apt/sources.list.d/pgdg.list
# Import the repository signing key
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | \
sudo apt-key add -
# Update the package lists, and install psql client
sudo apt-get update && apt-get install postgresql-client-9.4
@tym-xqo
tym-xqo / forecast.py
Last active August 29, 2015 14:21
Quick location and weather from Forecast.io - (I removed the location.py because of Whereami. This whole gist will be deleted eventually)
#!/usr/bin/env python
# coding: utf-8
import os
import forecastio
import json
from time import strftime
# Get an API key at https://developer.forecast.io
# and add to your local environment
@tym-xqo
tym-xqo / psql2json.sh
Last active August 29, 2015 14:24
Export table to json
psql -h qa.iadops.com -p 5433 -U<username> \
-c "select row_to_json(<table>) from <table>;" \
-d oao_trial -At > <table>.json
#!/bin/bash
# Standard `docker exec -t` doesn't create a full tty, and has no $TERM set.
# This creates problems for me sometimes (I like the `clear` command, and
# psql complains a bit if the client is not a functional terminal).
# I do the command below enough that I made this script.
# Pass it the name or ID of a running container, and Bob's your uncle.
while true;
@tym-xqo
tym-xqo / entry.sh
Last active October 9, 2015 19:53
env file to kubernetes conversion functions
#!/bin/bash
# Use this in Dockerfile ENTRYPOINT directive to source variables from /secret/env and export to the P1 environment
if [ -f /secret/env ]; then
set -a
. /secret/env
# Below keeps this idempotent if deployed to non-k8s environment (assuming the same env file is passed via --env-file at runtime)
else
mkdir -p /secret