Skip to content

Instantly share code, notes, and snippets.

View jesstess's full-sized avatar

Jessica McKellar jesstess

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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