Skip to content

Instantly share code, notes, and snippets.

View micahlmartin's full-sized avatar

Micah Martin micahlmartin

View GitHub Profile
//Example of a basic bug that causes an infinite loop
public static IEnumerable<Filter> Create(IEnumerable<string> filters)
{
if (filters == null)
throw new ArgumentNullException("filters");
if (filters.Count() == 0)
throw new ArgumentException("At least 1 filter must be specified", "filters");
test
@micahlmartin
micahlmartin / .bash_profile
Created August 12, 2012 22:45
Micah's Bash profile for mac
export PATH+=/usr/local/bin
#list all and colorize
alias ls='ls -Ga'
#fix for gitk
alias gitk='gitk 2>/dev/null'
#list files only
alias lf='ls -l | grep -v ^d'
@micahlmartin
micahlmartin / CoffeeScript.sublime-build
Created August 23, 2012 14:05
CoffeeScript.sublime-build
{
"cmd": ["coffee", "-c", "$file"],
"selector": "source.coffee",
"path": "/usr/local/bin"
}
@micahlmartin
micahlmartin / gist:4261551
Created December 11, 2012 19:53
Convert anonymous object to dictionary
public static IDictionary<string, object> ToDictionary(this object values)
{
var dict = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
if (values != null)
{
foreach (PropertyDescriptor propertyDescriptor in TypeDescriptor.GetProperties(values))
{
object obj = propertyDescriptor.GetValue(values);
dict.Add(propertyDescriptor.Name, obj);
@micahlmartin
micahlmartin / Best2.cs
Last active December 15, 2015 04:08
Example of code that's easier to test and code that's harder to test. Instance vs. Static.
// Best 2
// Use of IoC is relegated only to the calling class.
// Injection of dependency is through an instance variable rather than through the constructor
public class UserService
{
public virtual User GetUserByID(long userID)
{
//Get user from database
@micahlmartin
micahlmartin / setup.py
Created May 20, 2013 21:54
Prevent multiple calls?
_hasBeenSetup = False
def setup():
global _hasBeenSetup
if _hasBeenSetup:
return
_hasBeenSetup = True
#!/bin/bash
#
# /etc/rc.d/init.d/
#
#
#
#
#
# Source function library.
@micahlmartin
micahlmartin / groups_and_users
Created July 3, 2013 01:54
List all users and their goups
#!/usr/bin/perl -T
#
# Lists members of all groups, or optionally just the group
# specified on the command line
#
# Copyright © 2010-2013 by Zed Pobre (zed@debian.org or zed@resonant.org)
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
@micahlmartin
micahlmartin / mass_sender
Created September 21, 2013 00:19
Send money on Venmo via CSV import
#!/usr/bin/env python
import sys
import os
import getopt
from decimal import Decimal
import csv
import locale
from subprocess import call
# Set the locale for currency formatting