Skip to content

Instantly share code, notes, and snippets.

View michaelsproul's full-sized avatar

Michael Sproul michaelsproul

View GitHub Profile

GNU GENERAL PUBLIC LICENSE

Version 3, 29 June 2007

Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>

Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

@michaelsproul
michaelsproul / unsw-curl
Created July 26, 2013 23:36
Logon to myUNSW with curl
#!/bin/bash
# A filthy bash script to fetch a timetable from myUNSW
# Add your credentials here
USERNAME=""
PASSWORD=""
MYUNSW="https://ssologin.unsw.edu.au/cas/login?service=https%3A%2F%2Fmy.unsw.edu.au%2Famserver%2FUI%2FLogin%3Fmodule%3DISISWSSO%26IDToken1%3D"
TIMETABLE="https://my.unsw.edu.au/active/studentTimetable/timetable.xml"
@michaelsproul
michaelsproul / python_wtf.py
Last active January 3, 2016 17:49
Python WTF
# This is the weirdest shit I have ever seen in Python.
# If you call this on a list of directories containing only .cpp files, it's fine.
# If any of the directories contain .c files, there are instant errors!!
# E.g:
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# File "python_wtf.py", line 18, in get_objects
# objects.extend([c_filter(x) for x in c_files])
# File "python_wtf.py", line 18, in <listcomp>
# objects.extend([c_filter(x) for x in c_files])
@michaelsproul
michaelsproul / quine.py
Last active August 29, 2015 13:55
Python Quine
#!/usr/bin/env python
x = """#!/usr/bin/env python
x = {0}
# These comments make up 40% of this quine.
print(x.format('"'*3 + x + '"'*3))"""
# These comments make up 40% of this quine.
print(x.format('"'*3 + x + '"'*3))
@michaelsproul
michaelsproul / owned_ll.rs
Created April 15, 2014 23:57
Rust Linked List (with owned pointers)
enum LinkedList
{
Node(int, ~LinkedList),
Nil
}
impl LinkedList
{
fn push_front(&mut self, x: int)
{
@michaelsproul
michaelsproul / keybase.md
Created September 2, 2014 05:48
keybase.md

Keybase proof

I hereby claim:

  • I am michaelsproul on github.
  • I am michaelsproul (https://keybase.io/michaelsproul) on keybase.
  • I have a public key whose fingerprint is CAA9 A268 5516 A030 F66A 0AD8 77B1 309D 2E54 E914

To claim this, I am signing this object:

@michaelsproul
michaelsproul / overflow.c
Created October 16, 2014 00:18
scanf buffer overflow
// Enter a string of the form:
// # 1 "filenameiswaytoolong.cpp"
// You should get a segfault.
#include <stdio.h>
int main() {
int num;
char buffer[16];
char trailing[16];
@michaelsproul
michaelsproul / haskell_dp.hs
Created October 22, 2014 23:50
Haskell Dynamic Programming
-- Recursive and Dynamic Programming solutions to the recurrence N(k) = 2N(k - 3) + N(k - 2)
compute_rec :: Int -> Int
compute_rec 0 = 0
compute_rec 1 = 0
compute_rec 2 = 2
compute_rec k = 2 * (compute_rec (k - 3)) + (compute_rec (k - 2))
compute :: Int -> Int
compute k = cache !! k
where
@michaelsproul
michaelsproul / conditional_closure.rs
Created December 22, 2014 05:54
Rust Closure Variables
fn stuff() {
// Split the path into its components, and make each component a path.
let simple_map = |comp: &str| -> Pattern {
Pattern::simple_pattern(comp)
};
let glob_map = |comp: &str| -> Pattern {
Pattern::glob_pattern(comp)
};
let map_fn = match prelude {
@michaelsproul
michaelsproul / Authors.md
Last active August 29, 2015 14:18
Rust Contributors