Skip to content

Instantly share code, notes, and snippets.

View jamiltron's full-sized avatar

Justin Hamilton jamiltron

View GitHub Profile
@jamiltron
jamiltron / jamiltron lein swank error
Created January 17, 2011 18:17
lein swank error (Clojure 1.3.0)
Var *classpath* not marked :dynamic true, setting to :dynamic. You should fix this before next release!
Exception in thread "main" java.io.FileNotFoundException: Could not locate mire/server__init.class or mire/server.clj on classpath:
at clojure.lang.RT.load(RT.java:412)
at clojure.lang.RT.load(RT.java:381)
at clojure.core$load$fn__4389.invoke(core.clj:5308)
at clojure.core$load.doInvoke(core.clj:5307)
at clojure.lang.RestFn.invoke(RestFn.java:409)
at clojure.core$load_one.invoke(core.clj:5132)
at clojure.core$compile$fn__4394.invoke(core.clj:5319)
at clojure.core$compile.invoke(core.clj:5318)
#include <stdio.h>
displayword(char *word1)
{
printf("the man will %s",word1);
}
int main(void)
{
char verb1[100];
@jamiltron
jamiltron / image_idea.py
Created April 20, 2011 15:53
image idea
def Unit(pygame.sprite.Sprite):
images = None
def __init__(self, sprite_map):
if Unit.images == None:
Unit.images = load_images(sprite_map)
self.images = Unit.image.convert(Unit.images)
def load_assests(self, sprite_map):
@jamiltron
jamiltron / basic_curry_ex.py
Created April 26, 2011 17:17
Very basic curry example in Python
# This is meant to show trivial examples of currying.
# I know there are way more effective methods of doing this
# but this is meant to be illustrative, I also want to add
# a few non-trivial examples to show how its useful.
import operator
def curry(func, var):
y = var
def f(x):
return func(x, y)
;;; forsight.scm
;;; by Justin Hamilton
;;; last updated May 20th 2011 (currently not done)
;;; released under BSD 2-clause license
;;; Global variables
(define *prompt* "forsight> ")
(define *dictionary* '((+ add-f) (- sub-f) (* mul-f) (/ div-f) (mod mod-f)
(/mod mod-div-f) (and and-f) (or or-f) (= eq-f)
(> gt-f) (< lt-f) (swap swap-f) (dup dup-f)
@jamiltron
jamiltron / tinyforsight.ss
Created June 18, 2011 18:00
Tiny Forsight, trying to figure out error
#lang racket
(define *prompt* "> ")
(define *dictionary* '(("+" add-f)))
(define (push item stack)
(cons item stack))
(define (pop stack)
(rest stack))
@jamiltron
jamiltron / pack.clj
Created July 14, 2011 03:46
Pack a Sequence
; Write a function which packs consecutive duplicates into a list
; (pack [1 1 2 1 1 1 3 3]) => '((1 1) (2) (1 1 1) (3 3)))
; (pack [[1 2] [1 2] [3 4]]) => '(([1 2] [1 2]) ([3 4])))
(defn pack [n]
(letfn [(pack-iter [seen col curr out]
(cond
(empty? curr) (reverse (cons col out))
(= seen (first curr)) (pack-iter seen (cons (first curr) col) (rest curr) out)
:else (pack-iter (first curr) '() curr (cons col out))))]
@jamiltron
jamiltron / dropnth.clj
Created July 14, 2011 04:55
Drop every nth-item
; Write a function that drops every nth item from a sequence
(fn drop-nth [lat n]
(flatten (map #(if (= (count %) n) (drop-last %) %)
(partition-all n lat))))
@jamiltron
jamiltron / flat.clj
Created July 15, 2011 00:00
Flatten a List
;; Flatten a Sequence: Write a function which flattens a sequence.
(defn flat [n]
(let [x (first n)
xs (rest n)]
(cond
(empty? n) '()
(coll? x) (concat (flat x) (flat xs))
:else (cons x (flat xs)))))
@jamiltron
jamiltron / compseq.clj
Created July 15, 2011 00:23
Compress a Sequence
;; Compress a sequence: Write a function which removes consecutive duplicates from a sequence.
;; old way
(defn comp-seq-old [n]
(cond
(empty? (rest n)) n
(= (first n) (first (rest n))) (comp-seq-old (cons (first n) (rest (rest n))))
:else (cons (first n) (comp-seq-old (rest n)))))
;; new way