Skip to content

Instantly share code, notes, and snippets.

View 0atman's full-sized avatar
🦀
Oxidising

Tristram Oaten 0atman

🦀
Oxidising
View GitHub Profile
@0atman
0atman / generate_titles.py
Last active August 29, 2015 13:56
Grab titles for all django templates in this directory. (Used to test ubuntu.com)
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 June 24, 2014 23:48
A micropython dice roller, output in binary!
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 August 29, 2015 14:04
An alias to get round bzr's inability to auto-merge
commit () {
bzr pull && bzr commit -m "$1" && bzr push
}
@0atman
0atman / cwd_listener.sh
Last active August 29, 2015 14:07
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")
function chpwd() { │
emulate -L zsh │
tree --dirsfirst -L 1 `pwd` > ~/.current_tree │
}
@0atman
0atman / settings.py
Last active August 29, 2015 14:08
Nice default logging options for Django
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
{
"metadata": {
"name": "",
"signature": "sha256:fccf17e183ef75a5b0b1c58e43cf8dec8aeeb1ee0fb3f6745ba8111fd173b7ea"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@0atman
0atman / open_servers.py
Last active August 29, 2015 14:08
A locally-hosted web page listing all open http servers.
"""
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 December 16, 2014 17:06
A python script to do google speech API transcription
"""
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 August 29, 2015 14:14
juju status prettifier
#!/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 February 6, 2015 16:43
A shell function `todo` that uses jq (http://stedolan.github.io/jq/) to give you a list of all your assigned trello tasks.
todo() {
curl -s https://trello.com/1/members/my/cards/\?key\=your-application-key\&token\=your-user-token | jq '.[] | .name'
}