Skip to content

Instantly share code, notes, and snippets.

View Mause's full-sized avatar
:shipit:
Still trying to figure out what I'm doing

Elliana May Mause

:shipit:
Still trying to figure out what I'm doing
View GitHub Profile
@Mause
Mause / gol.py
Created July 6, 2012 05:20
A silly implementation of conways game of life
"an implementation of conways game of life"
# File: gol.py
#
# Project: Conways game of life
# Component:
#
# Authors: Dominic May;
# Lord_DeathMatch;
# Mause
@Mause
Mause / sample.c
Last active October 12, 2015 10:07
Code sample for blog.
int main()
{
system("chown www-data:www-data /var/www/docs;");
system("chmod go+rx -R /var/www/docs");
system("chmod go+rw -R /var/www/builds");
return 0;
}
@Mause
Mause / csv_kml.py
Created November 4, 2012 14:53
Requires unidecode, can be got from the python package index
#!/usr/bin/env python
# -*- coding: LATIN-1 -*-
import sys
import csv
from xml.dom import minidom
from unidecode import unidecode
from xml.etree import ElementTree
from xml.etree.ElementTree import Element, SubElement, Comment
@Mause
Mause / Pretty Colour generator.py
Last active June 3, 2022 22:32
Uses golden ratio to create pleasant/pretty colours returns in rgb form. The theory for this colour generator was taken from; http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
import math
import random
# the colorsys module is required for color conversion
from colorsys import hsv_to_rgb
# the theory for this colour generator was taken from;
# http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
def pretty_colours(how_many):
"""uses golden ratio to create pleasant/pretty colours
@Mause
Mause / Pipeline.py
Created April 7, 2013 04:32
Python generator pipelines demo
import types
class Pipeline(object):
def __init__(self, source):
if type(source) == types.FunctionType:
self.pipe = source()
else:
self.pipe = source
@Mause
Mause / decorator.py
Last active December 15, 2015 21:50
Decorator demo
def decorator(*arguments):
# this function recieves arguments passed to the decorator
def real_decorator(function):
# this function recieves the function we are decorating
def wrapper(*args, **kwargs):
# this function recieves the arguments intended for the function we are decorating
# print(args, kwargs)
# print(inspect.getargspec(function))
# print('args', arguments)
@Mause
Mause / gist:7559046
Created November 20, 2013 07:21
A simple inheriting dictionary implementation written in Python, with some inspiration taken from EmberJS' internals.
import collections
class InheritDict(collections.UserDict):
def __init__(self, data, parent=None):
for k, v in data.items():
if isinstance(data[k], dict):
data[k] = InheritDict(data[k], self)
super().__init__(data)
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@Mause
Mause / gist:8884395
Last active August 29, 2015 13:56
simple example of type specialisation with Python
from functools import wraps
def specific_magic(f):
@wraps(f)
def wrapper(self, *args, **kwargs):
for arg in args:
if type(arg) != self.__class__:
raise TypeError('{} not of type {}'.format(
arg, self.__class__.__name__
files = {
'unique_filename': 'file_data',
'unique_filename': ('filename', 'file_data'),
'unique_filename': ('filename', 'file_data', 'custom file content type'),
'unique_filename': (
'filename',
'file_data',
'custom file content type',
<custom headers in tuple or dict>
)