Skip to content

Instantly share code, notes, and snippets.

View twopoint718's full-sized avatar
yo

Christopher Wilson twopoint718

yo
View GitHub Profile
@twopoint718
twopoint718 / multtab.py
Created June 20, 2009 01:47
multiplication table in python
import math
def multtab(n):
width = 1 + int(math.ceil(math.log(n)/math.log(10)))
format_str = '%' + str(width) + "d"
for row in range(1,n+1):
for col in range(1,n+1):
print format_str % (row * col),
print
def lower_text(text):
return " ".join(map(lambda w: str.lower(w), text.split()))
if __name__ == "__main__":
print "Enter some text in mixed-case"
input = raw_input()
print lower_text(input)
(defn thanks [name reason]
(println (format "Hey %s, thanks for %s!" name reason)))
(thanks "Posterous" "github gist auto-expands")
import java.io.*;
import java.util.*;
public class LineBreaker
{
public static void main(String[] args)
{
if (args.length < 1) {
System.err.println("Give the name of the file as an argument.");
System.exit(1);
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double CostOfItem;
double NumberYears;
double Inflation;
double Result;
@twopoint718
twopoint718 / secret_santa.hs
Created December 27, 2011 21:35
Choosing a secret santa with "discouraged" pairings
import Data.List (delete, permutations, intercalate)
import System.Random
type Person = String
type SantaSuggestion = [(Person, Person)]
people :: [Person]
people = ["Chris", "Sarah", "Matt", "Jimmy", "Colin", "Kelsey", "Peter"]
-- main function chooses from the lowest-scoring (least bad)
@twopoint718
twopoint718 / TrueOf.rb
Created February 17, 2012 18:18
george boole ate my brain
class Hash
def true_of?(subject_key, &block)
TrueOf.new(self).instance_eval(&block)
end
end
class TrueOf
attr_reader :value, :key
def initialize(hash, key, &block)
@twopoint718
twopoint718 / login.opa
Created August 31, 2012 19:54
Opa CLogin example
function login_page() {
login = CLogin.make("", CLogin.default_config("test", function(_, _){some(true)}));
xml = CLogin.html(login);
Resource.page("Login page", page_template(xml))
}
@twopoint718
twopoint718 / request.1
Created October 6, 2012 22:01
Troff source file
.TL
Request for Funds In Support of An Expedition to the Antarctic
Continent
.AU
William Dyer Ph.D.
.AI
Professor of Geology, Miskatonic University
.AB
Being a request for funds necessary to support a lively expedition
to the southernmost continent of the world. Reasons for the outlays
@twopoint718
twopoint718 / with_reader.hs
Created November 9, 2012 22:36
Using the Reader Monad
import Control.Monad.Reader
import Prelude hiding (last)
import Text.Printf
import qualified Data.Map as M
type PersonInfo = Reader (M.Map String String) String
gimmie :: String -> PersonInfo
gimmie key = asks (M.findWithDefault "" key)