Skip to content

Instantly share code, notes, and snippets.

View 0atman's full-sized avatar
🦀
Oxidising

Tristram Oaten 0atman

🦀
Oxidising
View GitHub Profile
from feedparser import parse
def refresh_every(number_of_connections, url):
"""
This is an iterator that caches the result of the feed for
self.number_of_connections number of calls, before refreshing url.
"""
count = 0
data = parse(url).entries
while True:
def memoize(obj):
"""
Usage:
@memoize
def my_func():
...
"""
cache = obj.cache = {}
@functools.wraps(obj)
@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 / set-gnome-shell-hotkeys.sh
Created September 29, 2014 10:19
i3 gnome-shell keyboard bindings
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-1 "['<alt>1']"
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-2 "['<alt>2']"
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-3 "['<alt>3']"
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-4 "['<alt>4']"
gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-1 "['<alt><shift>1']"
gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-2 "['<alt><shift>2']"
gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-3 "['<alt><shift>3']"
gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-4 "['<alt><shift>4']"
@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..."