Skip to content

Instantly share code, notes, and snippets.

DEPARTMENT OF PUBLIC HEALTH AND HUMAN SERVICES 4041439825.4495
DEPARTMENT OF ADMINISTRATION 2305045669.05002
DEPARTMENT OF REVENUE 1437437534.65
DEPARTMENT OF TRANSPORTATION 1263305003.25008
OFFICE OF PUBLIC INSTRUCTION 451130738.55
MONTANA STATE FUND 420293464.210003
DEPARTMENT OF LABOR AND INDUSTRY 404242881.190003
DEPARTMENT OF COMMERCE 365923960.079999
COMMISSIONER OF HIGHER EDUCATION 311434469.469999
DEPARTMENT OF CORRECTIONS 288275698.659999
@kathawala
kathawala / zip-only.sh
Created May 24, 2015 01:33
one-liner to zip all .c and .h files in a directory
find . | grep -E '\.(c|h)$' | zip six.zip -@
@kathawala
kathawala / cleanpkg.sh
Created May 18, 2015 05:23
Removes cached packages which have 2+ more recent package versions cached
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
x="zzzzz"
copies=()
CLEAN_DIR="/var/cache/pacman/pkg"
@kathawala
kathawala / bigpkg.sh
Created January 17, 2015 20:41
Prints out a list of all pacman packages sorted by size from largest to smallest
#!/bin/bash
( echo "PACKAGE SIZE(K)";
for A in /var/lib/pacman/local/*/desc; do
egrep -A1 '%(NAME|SIZE)' $A \
| gawk '/^[a-z]/ { printf "%s ", $1 }; /^[0-9]/ { printf "%.0f\n", $1/1024 }'
done | sort -nrk2 ) | column -t
@kathawala
kathawala / getpath.py
Created December 22, 2014 09:49
Python script getting its own directory
#!/bin/env python
import inspect
import os
import sys
def get_script_dir(follow_symlinks=True):
if getattr(sys, 'frozen', False): # py2exe, PyInstaller, cx_Freeze
path = os.path.abspath(sys.executable)
else:
@kathawala
kathawala / randomwords.py
Created December 15, 2014 05:47
Prints and erases 5 random lines from a file
# Reads out 5 random lines from a file and erases them
import os.path
import random
dictionary = open("/home/farhan/bin/words", "r")
words = set()
last_pos = dictionary.tell()
rand_words = list(dictionary)
@kathawala
kathawala / gmail.py
Created December 12, 2014 00:46
A simple parser for GMail's Atom feed xml. Prints out the Title and Summary and Email address of sender
import xml.etree.ElementTree as etree
tree = etree.parse('/home/farhan/bin/email.xml')
root = tree.getroot()
for entry in root.iter('{http://purl.org/atom/ns#}entry'):
for title in entry.findall('{http://purl.org/atom/ns#}title'):
print ('TITLE: ', title.text)
for author in entry.findall('{http://purl.org/atom/ns#}author'):
for email in author.findall('{http://purl.org/atom/ns#}email'):
@kathawala
kathawala / play.sh
Created December 8, 2014 08:59
A script to download a youtube video and play it in smplayer, good for flash-only videos or long videos which buffer
#!/bin/bash
#utility to play a youtube video after the url has been cut using ctrl-x
youtube-dl -o "/home/farhan/Downloads/frmyoutube.%(ext)s" "$(xclip -o)" | tee /home/farhan/bin/play.log
#make sure we don't have any errors
if [ $(grep -i "error" ~/bin/play.log) ]; then
echo "Error downloading video. Try again :("
exit 1
fi
@kathawala
kathawala / undecorate.ds
Created November 29, 2014 19:40
1-line window undecoration rule for devilspie
(undecorate)
@kathawala
kathawala / ram.sh
Created November 28, 2014 23:06
Little script to print out your memory usage
#!/bin/bash
# free is a utility which provides statistics about memory in use
# -m flag provides memory in Mb
# awk takes all the arguments from grep and can print them
USED=`free -m | grep cache: | awk '{print $3}'`
TOTAL=`free -m | grep Mem: | awk '{print $2}'`
# bc is a linux calculator which can print floating point
# scale determines number of decimals (ex: 0.00)