Skip to content

Instantly share code, notes, and snippets.

View mdippery's full-sized avatar
💭
Have you seen an older me go by in a time machine?

Michael Dippery mdippery

💭
Have you seen an older me go by in a time machine?
View GitHub Profile
@mdippery
mdippery / abilities.py
Last active October 21, 2020 22:36
Calculate expected value of D&D ability generation
#!/usr/bin/env python
import random
import sys
def d6():
return random.randrange(1, 7)
@mdippery
mdippery / Dockerfile
Created April 26, 2019 00:12
Dockerfile for jimmyless/space-web
FROM alpine:3.9 AS checkout
RUN apk add --update git
RUN git clone https://github.com/jimmylee/space-web.git /app
FROM alpine:3.9
RUN apk add --update npm
@mdippery
mdippery / singleton.py
Last active December 12, 2021 03:10
Creating a Singleton in Python
class Singleton(type):
def __init__(cls, name, bases, dict):
super(Singleton, cls).__init__(name, bases, dict)
cls.instance = None
def __call__(cls, *args, **kwargs):
if cls.instance is None:
cls.instance = super(Singleton, cls).__call__(*args, **kwargs)
return cls.instance
@mdippery
mdippery / byte.c
Created October 10, 2018 00:33
Read one byte at a time and print the value
#include <stdio.h>
int main(int argc, char **argv)
{
int i = 0;
int g = 0;
unsigned char ch;
if (argc > 1) {
@mdippery
mdippery / trees.py
Last active April 29, 2016 00:37
Demonstrating depth-first search and breadth-first-search in Python
import random
class TreeNode(object):
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def __hash__(self):
@mdippery
mdippery / group.m
Created June 30, 2015 06:20
Get file's group name in Cocoa
#import <Foundation/Foundation.h>
#include <grp.h>
#include <string.h>
#include <sys/stat.h>
@interface FileOwnerManager : NSObject
- (BOOL)isWheelPresent:(NSString *)path;
@end
@implementation FileOwnerManager
@mdippery
mdippery / Blood.hs
Created February 27, 2015 00:47
Blood pressure calculator
import System.Console.GetOpt (ArgOrder(..), getOpt)
import System.Environment (getArgs, getProgName)
data BloodPressureCategory = Normal
| Prehypertension
| Hypertension1
| Hypertension2
| HypertensiveCrisis
@mdippery
mdippery / Zodiac.hs
Last active August 29, 2015 14:16
Calculates Chinese zodiac sign for a given year
import System.Console.GetOpt (ArgOrder(..), getOpt)
import System.Environment (getArgs)
offset = (flip mod) 12
animal 4 = "Rat"
animal 5 = "Ox"
animal 6 = "Tiger"
animal 7 = "Rabbit"
animal 8 = "Dragon"
@mdippery
mdippery / evil_decorator.py
Created November 5, 2014 01:37
Python decorator that inserts variables into a function
import sys
from functools import wraps
from types import FunctionType
def is_python3():
return sys.version_info >= (3, 0)
def more_vars(**extras):
@mdippery
mdippery / scope.py
Created August 26, 2014 22:54
Python's scopes are weird
# This totally works, even though `i` isn't passed into the
# lambda, nor is it defined prior to the lambda declaration.
calculate_efp = lambda v: v - i
[calculate_efp(v) for i, v in enumerate([10,100,1000])]