Skip to content

Instantly share code, notes, and snippets.

View treyhunner's full-sized avatar
🐍
💖

Trey Hunner treyhunner

🐍
💖
View GitHub Profile
@treyhunner
treyhunner / models.py
Created December 10, 2010 06:16
Encrypt and decrypt Django model primary key values (useful for publicly viewable unique identifiers)
# 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 March 29, 2011 14:59
Grab a screenshot, give it a public dropbox URL, shorten the URL, and copy it to the clipboard
#!/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 March 31, 2011 19:12
tomcat log and haystack-generated solr schema.xml
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 January 2, 2012 18:48
Error caused by running `pycco *.py -a -p` on main pycco directory with code from pull request 45.
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 January 18, 2012 06:02
Bookmarklet to Temporarily remove SOPA overlay from Wikipedia page
javascript:(function(){$('body').children('[id^=mw], #content, #footer').show().filter('#mw-sopaOverlay').hide();})()
@treyhunner
treyhunner / approach 1: hal with _embedded.json
Created February 18, 2012 02:19
Embedding links in HAL+JSON
{
"queue_status": "running",
"_embedded": {
"jobs": [
{
"_links": {
"self": { "href": "/queue/job1" },
}
"status": "queued"
},
@treyhunner
treyhunner / test_path.py
Created April 26, 2012 07:37
Test file for OS path representation
"""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 June 25, 2012 07:04
Generic Makefile for Django project
run:
python manage.py runserver_plus || python manage.py runserver
shell:
python manage.py shell_plus || python manage.py shell
@treyhunner
treyhunner / nbc
Created October 9, 2012 20:20
Instructions for installing pynxc on Ubuntu for use with Lego Mindstorm robots
This file has been truncated, but you can view the full file.
@treyhunner
treyhunner / findpi
Created December 30, 2012 19:28
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).
#!/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