Skip to content

Instantly share code, notes, and snippets.

Avatar

Jessica McKellar jesstess

View GitHub Profile
View scrabble_cheater.py
import sys
scores = {"A": 1, "C": 3, "B": 3, "E": 1, "D": 2, "G": 2,
"F": 4, "I": 1, "H": 4, "K": 5, "J": 8, "M": 3,
"L": 1, "O": 1, "N": 1, "Q": 10, "P": 3, "S": 1,
"R": 1, "U": 1, "T": 1, "W": 4, "V": 4, "Y": 4,
"X": 8, "Z": 10}
# Get the Scrabble rack from the command line.
if len(sys.argv) < 2:
@jesstess
jesstess / ELF_strings
Created Feb 18, 2012
Where in an ELF executable do various types of strings live?
View ELF_strings
Where in an ELF executable do various types of strings live?
Inspired by "How to waste a lot of space without knowing": http://glandium.org/blog/?p=2361
Test file:
$ cat /tmp/test.c
char *ptr_global = "ptr_global_string";
char array_global[] = "array_global_string";
@jesstess
jesstess / find_prune_dir
Created Feb 1, 2012
Change all instances of foo to bar in this directory, excluding files in .git or its subdirectories
View find_prune_dir
find . -not \( -name .git -prune \) -type f -print0 | xargs -0 sed -i 's/foo/bar/g'
@jesstess
jesstess / alexa-top-10000.txt
Created Nov 25, 2011
How the Alexa top 10000 respond to unusual HTTP methods
View alexa-top-10000.txt
google.com
facebook.com
yahoo.com
youtube.com
live.com
wikipedia.org
blogger.com
baidu.com
msn.com
yahoo.co.jp
@jesstess
jesstess / NASA_images_png2yuv
Created Aug 12, 2011
Turning NASA images into movies: png2yuv | mpeg2enc
View NASA_images_png2yuv
Keith gave me the hook-up on turning NASA images into a high-quality movie. I had tried twiddling knobs starting from a basic ffmpeg incant:
ffmpeg -r 10 -i frame%03d.jpg frames.mov
but the movies looked terrible.
Keith said:
"""
Generally if you're making a movie out of separate frames, I prefer to use png2yuv and mpeg2enc from the mjpegtools package instead of ffmpeg -- it's pretty clean code designed for this task instead of an assemblage of random libraries.
@jesstess
jesstess / cpu_cache_info.txt
Created Jan 27, 2011
CPU cache level, type, size, cache line size, associativity.
View cpu_cache_info.txt
for path in /sys/devices/system/cpu/cpu*/cache/index*/
do
echo $path;
echo -n "Level: "; cat $path/level;
echo -n "Type: "; cat $path/type;
echo -n "Size: "; cat $path/size;
echo -n "Cache line size: "; cat $path/coherency_line_size;
echo -n "Associativity: "; cat $path/ways_of_associativity;
done
@jesstess
jesstess / tracer.c
Created Jan 24, 2011
A minimal tracer. Attach to a running process or run a process under it. Step through instructions or syscalls. Generate instruction and syscall summaries.
View tracer.c
/*
* A minimal tracer. You can:
* - attach to a running process or run a process under it.
* - step through instructions.
* - step through syscalls.
* - generate a syscall summary.
* - count and time the number of instructions executed.
*
* If you are generating a summary with 'ci' or 'cs', send SIGTSTP (Ctl-Z) to
* pause the traced process and dump a summary (useful if you've attached to a
@jesstess
jesstess / flash_cards.py
Created Jan 11, 2011
Growl-based flashcards
View flash_cards.py
#!/usr/bin/python
from Growl import GrowlNotifier
import time
import sys
import os
import optparse
"""
@jesstess
jesstess / genetic_rainbows.py
Created Dec 26, 2010
Use genetic algorithms to create graphical rainbows.
View genetic_rainbows.py
#!/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 Dec 22, 2010
Getting percentages with HAVING and CASE in SQL
View percentages_sql_having_case
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
You can’t perform that action at this time.