Skip to content

Instantly share code, notes, and snippets.

View saxbophone's full-sized avatar
🏳️‍⚧️

saxbophone

🏳️‍⚧️
View GitHub Profile
@saxbophone
saxbophone / patch_requests.py
Created September 21, 2015 21:49
An experiment into monkey-patching the rather excellent Requests library
import __main__
import types
# patch_requests by Joshua Saxby
# An experiment into monkey-patching the rather excellent Requests
# library so the module can be hooked on a global level with minimal
# code having to be written by the end-user.
try:
@saxbophone
saxbophone / classes.js
Created November 7, 2015 17:42
Trying out ES6 classes, I think I made a mistake somewhere...
class Animal {
constructor(name="Unnamed", age=0, height=0) {
this.name = name;
this.age = age;
this.height = height;
}
describe() {
return `Species:\t${this.constructor.name}\nName:\t${this.name}\nAge:\t${this.age}\nHeight:\t${this.height}`;
}
}
@saxbophone
saxbophone / fibonacci.js
Created November 26, 2015 14:56
Fibonacci sequence generator in ES6
function* fibonacci(a=0, b=1) {
`This is a fibonacci sequence generator.`
yield a;
yield b;
let current = b;
let previous = a;
while (true) {
let next = previous + current;
previous = current;
current = next;
@saxbophone
saxbophone / currency_converter.py
Last active November 27, 2015 21:29
Python Currency Conversion
from decimal import Decimal
from functools import reduce
def average(*items):
"""
Returns mean average of a list (expects Decimal objects).
"""
return reduce(lambda x, y: x+y, items) / Decimal(len(items))
@saxbophone
saxbophone / main.c
Last active January 2, 2016 15:39
My own attempt at implementing the PID algorithm in some (hopefully) clean, understandable C
/*
* PID Controller Implementation in C
*
* Created by Joshua Saxby (aka @saxbophone) on 1 Jan, 2016
*
* My own attempt at implementing the PID algorithm in some (hopefully) clean, understandable C.
* No warranty, no patenting (LOL!), free use, yadda yadda etc, hope you find this useful and don't be evil!
*/
@saxbophone
saxbophone / control.c
Last active January 2, 2016 21:27
Quadcopter algorithm
#include <stdio.h>
typedef struct {
/*
* A struct used for storing the configured state of a Quadcopter's motors,
* such as the maximmum power output per motor and the other tuning paramters
* that effect how the quad will calculate the thrust ratios of the motors
*/
@saxbophone
saxbophone / exception.py
Created February 11, 2016 12:30
The one exception handler
import urllib
import webbrowser
try:
thing()
except Exception as E:
webbrowser.open(
'http://stackoverflow.com/search?q={}'.format(
urllib.quote_plus('{} {}'.format(E.__class__.__name__, E.message))
)
@saxbophone
saxbophone / meme.sh
Last active August 31, 2016 17:05
A very annoying shell function - Prints out a stupid message from fortune via cowsay, to all terminals, then waits a number of seconds in the fibonacci scale before spawning itself into the background
function meme() {
if [ "$1" -eq "1" ] && [ "$2" -eq "1" ]
then
wall <<< `cowsay "Hello! I am Cow, and I like to SAY things"`
else
wall <<< `fortune | cowsay`
fi
a=$1
b=$2
temp=$((a + b))
@saxbophone
saxbophone / Saxbotheme.tmTheme
Last active March 29, 2016 14:08
My own Text editor theme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- Generated by: TmTheme-Editor -->
<!-- ============================================ -->
<!-- app: http://tmtheme-editor.herokuapp.com -->
<!-- code: https://github.com/aziz/tmTheme-Editor -->
<plist version="1.0">
<dict>
<key>name</key>
<string>Saxbotheme</string>
@saxbophone
saxbophone / Noblue_Night.tmTheme
Created March 28, 2016 21:59
Noblue Night - A Text editor theme completely devoid of blue, for help with sleep
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- Generated by: TmTheme-Editor -->
<!-- ============================================ -->
<!-- app: http://tmtheme-editor.herokuapp.com -->
<!-- code: https://github.com/aziz/tmTheme-Editor -->
<plist version="1.0">
<dict>
<key>name</key>
<string>Noblue Night</string>