Skip to content

Instantly share code, notes, and snippets.

Avatar

Tristram Oaten 0atman

View GitHub Profile
@0atman
0atman / generate_titles.py
Last active Aug 29, 2015
Grab titles for all django templates in this directory. (Used to test ubuntu.com)
View generate_titles.py
import os
import urllib2
import string
def clean_path(p):
cleaned = p[1:-1].split(".html")[0].split("index")[0]
return cleaned if cleaned[-1] == "/" else "%s/" % cleaned
@0atman
0atman / roll.py
Created Jun 24, 2014
A micropython dice roller, output in binary!
View roll.py
import pyb
def set_state():
n = int(pyb.rng() / 2**30 * 6) + 1
[pyb.LED(l).off() for l in range(1,4)]
byte_list = list(str(bin(n))[2:])
byte_list.reverse()
for led, byte in enumerate(byte_list):
if int(byte):
pyb.LED(int(led) + 1).on()
@0atman
0atman / bashrc
Last active Aug 29, 2015
An alias to get round bzr's inability to auto-merge
View bashrc
commit () {
bzr pull && bzr commit -m "$1" && bzr push
}
@0atman
0atman / cwd_listener.sh
Last active Aug 29, 2015
A ZSH function to output the shell user's cwd tree to a file (with a view to printing it in an always-visible window, perhaps with "tail -n 20 .current_tree")
View cwd_listener.sh
function chpwd() { │
emulate -L zsh │
tree --dirsfirst -L 1 `pwd` > ~/.current_tree │
}
@0atman
0atman / settings.py
Last active Aug 29, 2015
Nice default logging options for Django
View settings.py
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'error_file': {
'level': 'WARNING',
'filename': os.path.join(BASE_DIR, 'django-error.log'),
'class':'logging.handlers.RotatingFileHandler',
'maxBytes': 1 * 1024 * 1024,
'backupCount': 2
View gist:8e9c5406c9083074b9cc
{
"metadata": {
"name": "",
"signature": "sha256:fccf17e183ef75a5b0b1c58e43cf8dec8aeeb1ee0fb3f6745ba8111fd173b7ea"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@0atman
0atman / open_servers.py
Last active Aug 29, 2015
A locally-hosted web page listing all open http servers.
View open_servers.py
"""
A locally-hosted web page listing all open http servers.
Requirements:
nmap (apt-get install nmap)
sh, werkzeug (pip install sh, werkzeug)
"""
from werkzeug.wrappers import Request, Response
from sh import nmap
print " * Running nmap..."
@0atman
0atman / transcribe.py
Created Dec 16, 2014
A python script to do google speech API transcription
View transcribe.py
"""
Requires the pip package `SpeechRecognition`
The google api seems to only like 15s chuncks
"""
import speech_recognition as sr
import sys
r = sr.Recognizer()
with sr.WavFile(sys.argv[1]) as source:
audio = r.record(source)
@0atman
0atman / juju-status.py
Last active Aug 29, 2015
juju status prettifier
View juju-status.py
#!/usr/bin/env python
"""
concicely prints the output of `juju status`.
Good for `watch`ing. i.e. `watch -d juju-status`
"""
import json
from subprocess import Popen, PIPE, STDOUT
import argparse
import sys
@0atman
0atman / trello_todo.sh
Created Feb 6, 2015
A shell function `todo` that uses jq (http://stedolan.github.io/jq/) to give you a list of all your assigned trello tasks.
View trello_todo.sh
todo() {
curl -s https://trello.com/1/members/my/cards/\?key\=your-application-key\&token\=your-user-token | jq '.[] | .name'
}
You can’t perform that action at this time.