Skip to content

Instantly share code, notes, and snippets.

View graphbear's full-sized avatar

John Graber graphbear

  • Gray Bear, Inc.
  • USA • WI • MKE
  • 19:17 (UTC -05:00)
  • LinkedIn in/johngraber
View GitHub Profile
@graphbear
graphbear / keybase.md
Created November 13, 2014 03:35
keybase.md

Keybase proof

I hereby claim:

  • I am johngraber on github.
  • I am jgraber (https://keybase.io/jgraber) on keybase.
  • I have a public key whose fingerprint is F3EF D90C BA2C 6FC0 8C77 113B 3C70 C1E0 F10A F344

To claim this, I am signing this object:

@graphbear
graphbear / lowercase_the_filesystem.py
Last active August 29, 2015 14:09
lowercase names of all sub-directories and files
#!/usr/bin/python
# This script will rename in lower case every file and directory found in the
# current directory and below.
import os
for root, dirs, files in os.walk('.'):
for filename in files:
old_name = os.path.join(root, filename)
@graphbear
graphbear / clean_filenames.sh
Created July 24, 2015 12:47
clean special characters from file names
specChars () {
tr [:blank:] [_] | tr [/] [_] | tr -d [=~=][=!=][=@=][=#=][=$=][=%=][='('=][=')'=][=\'=][=,=][=.=][=:=][=';'=][=\\=]
}
IFS=$'\n'
files=$(ls -1)
for file in $files ; do
#! /bin/bash
# changeCase: a hack written to convert files from NDS upgrade CD to lowercase file names
# author: John Hamilton, john.hamilton@wiscdrapery.com
# date: 22-APR-02
#
# usage: This script assumes you have:
# *) copied all of the contents of the CD to your hard drive
# *) full read, write, execute permissions to the copied directories
# *) no hidden files ("dot" files) in or below your current directory
# requires mp3info be installed on system
specChars () {
tr [:blank:] [_] | tr [/] [_] | tr -d [=~=][=!=][=@=][=#=][=$=][=%=][='('=][=')'=][=\'=][=,=][=.=][=:=][=';'=][=\\=]
}
#check with user to see if the filenames look good
mp3info -p "File: %f\nTitle: %t\nArtist: %a\nAlbum: %l\nYear: %y\nGenre: %g\n" *.mp3
echo -n 'File names will be:' \n
@graphbear
graphbear / pg_logical_backup.sh
Created January 27, 2016 16:07
Postgres Logical Backup
#!/bin/bash
# a very basic script for logical backup of multiple databases in a postgres cluster
# get a list of database names, not including the default databases
DB_LIST=$(psql -qAt -c "SELECT datname FROM pg_database WHERE datname <> ALL ( ARRAY [ 'postgres' ::NAME, 'template0' ::NAME, 'template1' ::NAME, 'edb' ::NAME ] )")
# define and create location for backups
BASE_DIR="/path_to/backups/logical"
YMD=$(date "+%Y-%m-%d")
@graphbear
graphbear / pg_physical_backup.sh
Created January 27, 2016 16:10
Postgres Physical Backup
#!/bin/bash
# a very basic phyisical backup script, this will also
# clean up archived WAL that is no longer needed
# define and create location for backups
BASE_DIR="/path_to/backups/physical"
ARCHIVED_WAL_DIR=/path_to/archived_xlogs
YMD=$(date "+%Y-%m-%d")
DIR="$BASE_DIR/$YMD"
@graphbear
graphbear / trinum.py
Created February 6, 2016 19:55
triangular number
def trinum(n):
# calculates the "triangular number" of a number
# https://www.mathsisfun.com/algebra/triangular-numbers.html
return n*(n+1)/2
@graphbear
graphbear / wma.py
Last active April 2, 2024 22:22
weighted moving average
def wma(values, window):
# requires trinum.py
# using definition provided at
# http://www.oanda.com/forex-trading/learn/forex-indicators/weighted-moving-average
# create an array of weights
# use floats when creating array, or the result is integer division below
# and, note that they are reversed. why? read this:
@graphbear
graphbear / hma.py
Created February 6, 2016 19:57
hull moving average
def hma(values, window):
# requires wma.py
# HMA = WMA(2*WMA(PRICE, N/2) - WMA(PRICE, N), SQRT(N))
period = int(np.sqrt(window))
# created wma array with NaN values for indexes < window value
# hull_moving_averages = np.empty(window)