Skip to content

Instantly share code, notes, and snippets.

Avatar

Trey Hunner treyhunner

View GitHub Profile
@treyhunner
treyhunner / models.py
Created Dec 10, 2010
Encrypt and decrypt Django model primary key values (useful for publicly viewable unique identifiers)
View models.py
# This code is under the MIT license.
# Inspired by this StackOverflow question:
http://stackoverflow.com/questions/3295405/creating-django-objects-with-a-random-primary-key
import struct
from Crypto.Cipher import DES
from django.db import models
def base36encode(number):
@treyhunner
treyhunner / screenshot.sh
Created Mar 29, 2011
Grab a screenshot, give it a public dropbox URL, shorten the URL, and copy it to the clipboard
View screenshot.sh
#!/bin/sh
# Ubuntu-specific modification of http://wiki.dropbox.com/TipsAndTricks/ShareScreenshots
# Change these
DB_USER_ID=YOURDBUSERID
BITLY_USERNAME=YOURBITLYUSERNAME
BITLY_API_KEY=YOURBITLYKEYHERE
DROPBOX_PUBLIC_DIR=~/Dropbox/Public
SCREENSHOT_DIR=screenshots
@treyhunner
treyhunner / catalina.out
Created Mar 31, 2011
tomcat log and haystack-generated solr schema.xml
View catalina.out
Mar 31, 2011 12:15:22 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/jvm/java-6-openjdk/jre/lib/i386/server:/usr/lib/jvm/java-6-openjdk/jre/lib/i386:/usr/lib/jvm/java-6-openjdk/jre/../lib/i386:/usr/java/packages/lib/i386:/usr/lib/jni:/lib:/usr/lib
Mar 31, 2011 12:15:22 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Mar 31, 2011 12:15:22 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 549 ms
Mar 31, 2011 12:15:22 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Mar 31, 2011 12:15:22 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.24
@treyhunner
treyhunner / pycco pull request 45 error
Created Jan 2, 2012
Error caused by running `pycco *.py -a -p` on main pycco directory with code from pull request 45.
View pycco pull request 45 error
bender:pycco(laginha|…)% pycco *.py -a -p
pycco = setup.py -> docs/docs/./setup.html
pycco = test.py -> docs/docs/./test.html
Traceback (most recent call last):
File "/usr/local/bin/pycco", line 9, in <module>
load_entry_point('Pycco==0.2.0', 'console_scripts', 'pycco')()
File "/usr/local/lib/python2.6/dist-packages/Pycco-0.2.0-py2.6.egg/pycco/main.py", line 508, in main
@treyhunner
treyhunner / remove sopa overlay.js
Created Jan 18, 2012
Bookmarklet to Temporarily remove SOPA overlay from Wikipedia page
View remove sopa overlay.js
javascript:(function(){$('body').children('[id^=mw], #content, #footer').show().filter('#mw-sopaOverlay').hide();})()
View approach 1: hal with _embedded.json
{
"queue_status": "running",
"_embedded": {
"jobs": [
{
"_links": {
"self": { "href": "/queue/job1" },
}
"status": "queued"
},
@treyhunner
treyhunner / test_path.py
Created Apr 26, 2012
Test file for OS path representation
View test_path.py
"""File for testing OS path separators in Python
Execute this file like this:
python test_path.py c:/path/to/a/file.txt
"""
import sys
import os
@treyhunner
treyhunner / Makefile
Created Jun 25, 2012
Generic Makefile for Django project
View Makefile
run:
python manage.py runserver_plus || python manage.py runserver
shell:
python manage.py shell_plus || python manage.py shell
@treyhunner
treyhunner / nbc
Created Oct 9, 2012
Instructions for installing pynxc on Ubuntu for use with Lego Mindstorm robots
View nbc
This file has been truncated, but you can view the full file.
@treyhunner
treyhunner / findpi
Created Dec 30, 2012
Script for finding Raspberry Pi computers on the network. The scripts searches for MAC addresses starting with `b8:27:eb:` (the Ethernet port on the Pi) and `80:1f:02` (Edimax wifi USB dongle).
View findpi
#!/bin/sh
if which nmap > /dev/null ; then
echo "Running nmap as root\n"
IP_RANGE=$(ip addr | grep "inet " | awk '{ print $2}' | grep -v 127.0.0)
sudo nmap -sP $IP_RANGE | grep -B2 -i 'b8:27:eb\|80:1f:02'
else
if which arp-scan > /dev/null ; then
echo "Running arp-scan as root\n"
sudo arp-scan --interface=eth0 --localnet | grep 'b8:27:eb\|80:1f:02'
else