Skip to content

Instantly share code, notes, and snippets.

View redacted's full-sized avatar

Steven Tobin redacted

  • Ireland
View GitHub Profile
@redacted
redacted / battery_prompt.zsh
Last active October 29, 2015 10:26
parts of probably oh-my-zsh for battery monitoring on macs
function battery_pct() {
typeset -F maxcapacity=$(ioreg -rc "AppleSmartBattery"| grep '^.*"MaxCapacity"\ =\ ' | sed -e 's/^.*"MaxCapacity"\ =\ //')
typeset -F currentcapacity=$(ioreg -rc "AppleSmartBattery"| grep '^.*"CurrentCapacity"\ =\ ' | sed -e 's/^.*CurrentCapacity"\ =\ //')
integer i=$(((currentcapacity/maxcapacity) * 100))
echo $i
}
function battery_pct_remaining() {
if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then
battery_pct
@redacted
redacted / fix_whitespace.vim
Created April 7, 2015 11:21
no trailing whitespace
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
autocmd BufWrite *.py :call DeleteTrailingWS()
@redacted
redacted / gist:34de4ea384f87cfffbb2
Created February 26, 2015 11:54
PEP8 trailing whitespace: automatic nuking
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
autocmd BufWrite *.py :call DeleteTrailingWS()
@redacted
redacted / pipeline_auto.sh
Created January 29, 2015 17:11
Automating a processing pipeline
#!/bin/bash
get_insights() { python insights_lastNdays.py; }
build_reports() { python gen_weekly_plots.py; }
upload_reports() { python upload_all.py; }
# functions to call in order
declare -a functions=(get_insights build_reports upload_reports)
# make sure we are in the right directory for paths!
cd "$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
@redacted
redacted / Dangerous lazy object
Created January 29, 2015 11:31
Lazily initialise python object through horrible __getattr__ hacks
class State:
def __init__(self):
pass
def import_position(self):
self.position = {x: x * x for x in range(10)}
def __getattr__(self, s):
try:
return self.__getattribute__(s)
@redacted
redacted / random_capitals
Created September 8, 2014 01:49
Generate an xkcd-style password with randomly capitalised letters
import random
from xkcdpass.xkcd_password import *
def random_capitalisation(s, chance):
new_str = []
for i, c in enumerate(s):
new_str.append(c.upper() if random.random() < chance else c)
return "".join(new_str)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
@redacted
redacted / extract_latlngs.py
Created May 23, 2012 16:08
extract lat longs from localstorage db
import sqlite3
import sys
def get_latlngs(fname):
latlngs = []
conn = sqlite3.connect(fname)
c = conn.cursor()
@redacted
redacted / itunes100randomyoutube.py
Created May 4, 2012 10:16
Opens a song from the iTunes Top 100 in youtube (chosen at random)
'''
1) Gets top 100 songs from iTunes chart
2) Plays a random song from this list in YouTube
license: public domain
Dependancies:
1) BeautifulSoup http://www.crummy.com/software/BeautifulSoup/
'''
from urllib2 import urlopen
@redacted
redacted / sc2_scrape.py
Created April 5, 2012 15:27
Checks balance of StarCraft 2 races based on sc2-replays.net results
import urllib2
from collections import defaultdict, namedtuple
import BeautifulSoup
import sys
import time
import socket
Factions = ["protoss", "zerg", "terran"]