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 / bmi.hs
Created August 15, 2012 19:15
A BMI calculator in Haskell
{-
N.B.: This is just a simple example of a Haskell program. Don't
take BMI seriously. You're fine just the way you are!
-}
import Data.Char (isDigit)
import Data.List (isInfixOf, isSuffixOf)
import Data.List.Split (splitOn)
import System.Console.GetOpt (ArgOrder(..), getOpt)
import System.Environment (getArgs, getProgName)
@mdippery
mdippery / book.m
Created October 28, 2010 18:11
An example of using @dynamic properties in Objective-C
#import <Foundation/Foundation.h>
@interface Book : NSObject
{
NSMutableDictionary *data;
}
@property (retain) NSString *title;
@property (retain) NSString *author;
@end
@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 / 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 / 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 / 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 / NSString+Random.h
Created February 8, 2011 15:34
Generate random strings in Objective-C
/*
* Copyright (C) 2011 Michael Dippery <mdippery@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@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 / .bash_logout
Created November 10, 2013 00:10
Removes the crap that SSH puts in your console title bar when SSH'ing into a machine. Drop this in the ~/.bash_logout file on the remote machine.
# ~/.bash_logout
printf '\e]0;\a'