Skip to content

Instantly share code, notes, and snippets.

@gmcclure
gmcclure / day_of_week_calc.py
Created November 12, 2012 00:43
Python routine for generating a 12-digit code that assists with determining the day of the week for any given date
#!/usr/bin/env python
import datetime, sys
try:
year = int(sys.argv[1])
except IndexError:
year = datetime.datetime.today().year
firstDayToFirstMonday = ['1st', '7th', '6th', '5th', '4th', '3rd', '2nd']
@gmcclure
gmcclure / glib.h
Created November 15, 2012 18:38
GLIB - Library of useful routines for C programming
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@gmcclure
gmcclure / list.h
Created November 15, 2012 18:40
Simple doubly linked list implementation, from the Linux kernel
#ifndef __LIST_H
#define __LIST_H
/* This file is from Linux Kernel (include/linux/list.h)
* and modified by simply removing hardware prefetching of list items.
* Here by copyright, credits attributed to wherever they belong.
* Kulesh Shanmugasundaram (kulesh [squiggly] isis.poly.edu)
*/
/*
@gmcclure
gmcclure / rpn.py
Created April 27, 2013 22:53
Programming Praxis, RPN
import sys
class RPN(object):
def __init__(self):
self._stack = []
self._expr = ''
self._operators = '+-*/'
def read_expr(self, out=sys.stdout):
@gmcclure
gmcclure / sieve.py
Created April 27, 2013 23:14
Praxis, Sieve of Eratosthenes
# sieve of eratosthenes
import math
import time
class Sieve(object):
def find_primes_to_max(self, n):
n += 1
primes_filter = [0] * n
@gmcclure
gmcclure / gist:5538047
Created May 8, 2013 03:49
an attempt to model a has_many :through with factory girl ...
# app/models/user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
class Parser
def initialize(output)
@output = output
end
def open_ged_file(file)
if file.strip.empty?
@output.puts "Can't parse without a GEDCOM file name"
exit
end
(defpackage :verbquiz
(:use :common-lisp))
(in-package :verbquiz)
(defparameter *dictionary* (make-hash-table :test #'equal))
(defun save-dictionary (&key (filename "dictionary.db"))
"Save the program *dictionary* in utf-8 format."
(with-open-file (out filename
import unittest
from StringIO import StringIO
import rpn_calc
class RPNTest(unittest.TestCase):
def setUp(self):
self.rpn = rpn_calc.RPN()
require 'spec_helper'
module GEDCOMParser
describe Parser do
let(:output) { double('output').as_null_object }
let(:parser) { Parser.new(output) }
describe '#open_ged_file' do
it "complains and stops whine when run without a filename" do