Skip to content

Instantly share code, notes, and snippets.

View jesstess's full-sized avatar

Jessica McKellar jesstess

View GitHub Profile
@jesstess
jesstess / music_through_dev_dsp.py
Created November 15, 2010 02:11
Construct tones yourself and play them through /dev/dsp
#!/usr/bin/python
# Play music without any external files (ie you create the notes yourself)
# through /dev/dsp! Inspired by
# http://www.tldp.org/LDP/abs/html/devref1.html#MUSICSCR
def generate_notes():
# See http://www.phy.mtu.edu/~suits/NoteFreqCalcs.html for details on
# calculating the frequencies
@jesstess
jesstess / growl_ticket_notifier
Created November 18, 2010 03:41
Check ticket trackers for new tickets and generate notifications for them through Growl.
#!/usr/bin/python
import pycurl
import re
import urlparse
from StringIO import StringIO
from Growl import GrowlNotifier
"""
Check ticket trackers for new tickets and generate notifications for them
@jesstess
jesstess / cycle_bash_color
Created November 25, 2010 03:11
cycle through colors with each new shell prompt
export colorvar=31; export PROMPT_COMMAND='export PS1="\e[""$colorvar"";40m\w> "; colorvar=$(((colorvar + 1) % 7 + 31));'
@jesstess
jesstess / wget_spider_https
Created November 27, 2010 20:02
Use wget to spider a site as a logged-in user.
http://addictivecode.org/FrequentlyAskedQuestions
To spider a site as a logged-in user:
1. post the form data (_every_ input with a name in the form, even if it doesn't have a value) required to log in (--post-data).
2. save the cookies that get generated (--save-cookies), including session cookies (--keep-session-cookies), which are not saved when --save-cookies alone is specified.
2. load the cookies, continue saving the session cookies, and recursively (-r) spider (--spider) the site, ignoring (-R) /logout.
# log in and save the cookies
wget --post-data='username=my_username&password=my_password&next=' --save-cookies=cookies.txt --keep-session-cookies https://foobar.com/login
@jesstess
jesstess / password_gen_dev_urandom
Created November 27, 2010 20:24
N-character password generation out of /dev/urandom
# alphanumeric
</dev/urandom tr -dc [:alnum:] | head -c10
# all printable characters, excluding whitespace
</dev/urandom tr -dc [:graph:] | head -c10
@jesstess
jesstess / DIY_bandwidth_summaries
Created December 19, 2010 03:42
DIY bandwidth summaries
DIY bandwidth summaries
1. ifconfig
ifconfig -a will give you transmitted and received bytes by interface since last boot.
Gets its info from /proc/net/dev
2. iptables
@jesstess
jesstess / mysql_time_frequency_tables
Created December 22, 2010 04:04
Quick frequency tables bucketing on time in MySQL
# date field is of type 'date'
mysql> SELECT YEAR(date) AS year, MONTH(date) AS month, count(*) AS count FROM my_table GROUP BY year, month ORDER BY year, month;
+------+-------+-------+
| year | month | count |
+------+-------+-------+
| 2008 | 6 | 1 |
| 2009 | 3 | 1 |
| 2009 | 5 | 2 |
| 2009 | 6 | 1 |
| 2009 | 7 | 1 |
@jesstess
jesstess / percentages_sql_having_case
Created December 22, 2010 19:25
Getting percentages with HAVING and CASE in SQL
I have a table of accounts and a table of transactions. There's a
one-to-many relationship between accounts and transactions;
transactions.account_id is a foreign key into accounts. For all
accounts where < 50% of transactions are authorized, I want to
get the account id and that percentage:
SELECT a.id, SUM(t.authorized=1)/COUNT(*) AS percentage
FROM accounts a, transaction_info t
WHERE a.id=t.account_id
GROUP BY a.id
@jesstess
jesstess / genetic_rainbows.py
Created December 26, 2010 20:37
Use genetic algorithms to create graphical rainbows.
#!/usr/bin/env python
from Tkinter import *
import colorsys
import optparse
import random
"""
Use genetic algorithms to create graphical rainbows.
@jesstess
jesstess / flash_cards.py
Created January 11, 2011 03:09
Growl-based flashcards
#!/usr/bin/python
from Growl import GrowlNotifier
import time
import sys
import os
import optparse
"""