Skip to content

Instantly share code, notes, and snippets.

@nwjlyons
nwjlyons / styles.css
Last active January 4, 2016 20:59
Basic styles
* {
margin:0;
padding:0;
box-sizing:border-box;
}
html {
background:#eee;
font-family: Arial;
}
@nwjlyons
nwjlyons / post-checkout
Created May 15, 2014 15:15
Delete .pyc files and empty directories on git checkout
#! /bin/sh
# Start from the repository root.
cd ./$(git rev-parse --show-cdup)
# Delete .pyc files and empty directories.
find . -name "*.pyc" -delete
find . -type d -empty -delete
echo "$(tput bold).pyc files and empty directories deleted.$(tput sgr0)"
@nwjlyons
nwjlyons / euro-millions.py
Last active January 9, 2016 19:19
The National Lottery number generator
python -c "from random import sample; print 'EuroMillion numbers: %s %s' % (sample(range(1, 51), 5), sample(range(1, 12), 2))"
@nwjlyons
nwjlyons / end.sh
Last active August 29, 2015 14:01
Play sound after command has finished
# Play sound after command has finished.
#
# Usage:
# end ./manage.py test
end() {
"$@" && paplay /usr/share/sounds/alsa/Front_Left.wav
}
@nwjlyons
nwjlyons / laptop_fan.sh
Last active July 13, 2023 10:05
Manually control Mac Book Pro laptop fan from linux
# First su in as root
sudo su
# Then set fan control to manual mode
echo 1 > /sys/devices/platform/applesmc.768/fan1_manual
# Then set the fan speed to any value between fan1_min and fan1_max. To view these values
cat /sys/devices/platform/applesmc.768/fan1_min
cat /sys/devices/platform/applesmc.768/fan1_max
@nwjlyons
nwjlyons / back lit keyboard linux
Last active November 13, 2024 00:52
Turn Mac Book Pro backlit keyboard on and off under linux
# First su in as root
sudo su
# Then cd to backlight directory
cd /sys/class/leds/smc::kbd_backlight/
# Turn the backlight on
cat max_brightness > brightness
# Set to zero to turn off the backlight
@nwjlyons
nwjlyons / common.sh
Last active September 5, 2021 22:21
Instructions on how to wire up your MacBook Pro function keys to control your laptop hardware in Crunchbang
#! /bin/bash
case $1 in
up)
TOTAL=`expr $CURRENT + $INCREMENT`
if [ $TOTAL -gt $MAX ]; then
exit 1
fi
echo $TOTAL > $FILE
;;
javascript:(function() {
var adjectives = [
"Autumn", "Hidden", "Bitter", "Misty", "Silent", "Empty", "Dry", "Dark", "Summer", "Icy",
"Delicate", "Quiet", "White", "Cool", "Spring", "Winter", "Patient", "Twilight", "Dawn",
"Crimson", "Wispy", "Weathered", "Blue", "Billowing", "Broken", "Cold", "Damp", "Falling",
"Frosty", "Green", "Long", "Late", "Lingering", "Bold", "Little", "Morning", "Muddy", "Old",
"Red", "Rough", "Still", "Small", "Sparkling", "Wandering", "Withered", "Wild", "Black",
"Young", "Holy", "Solitary", "Fragrant", "Aged", "Snowy", "Proud", "Floral", "Restless",
"Divine", "Polished", "Ancient", "Purple", "Lively", "Nameless"];
var nouns = [
@nwjlyons
nwjlyons / runserver_quiet.py
Last active September 14, 2016 10:09
Don't log if path starts with /static/
from django.core.servers.basehttp import WSGIRequestHandler
# Grab the original log_message method.
_log_message = WSGIRequestHandler.log_message
def log_message(self, *args):
# Don't log if path starts with /static/
if self.path.startswith("/static/"):
return
else:
@nwjlyons
nwjlyons / lc.sh
Last active September 20, 2016 10:46
Sort local branches by line count.
#!/usr/bin/env bash
git branch | while read BRANCH ; do
git checkout $BRANCH &> /dev/null;
LINE_COUNT=`wc -l $(git ls-files | grep "\(.html\|.py\)$") | tail -n 1`
echo "$LINE_COUNT $BRANCH"
done | sort -r