Skip to content

Instantly share code, notes, and snippets.


Thom Chiovoloni thomcc

View GitHub Profile
thomcc / snake.clj
Created Jan 2, 2012
Snake game in clojure
View snake.clj
(ns snake
(:import (java.awt Color Graphics Dimension Font)
(javax.swing JFrame JPanel)
(java.awt.event KeyEvent KeyAdapter)))
(def field [80 48]) ; [width height]
(def scale 10)
(def screen (Dimension. (* scale (field 0)) (* scale (field 1))))
(def on? true)
(def tick-speed 100)
View gist:1603487
(def sets
{:vowel #{:a :e :i :o :u}
:consonant #{:b :c :d :f :g :h :j} ; ... etc.
:other #{:y}})
(defn categorize [thing]
(condp #(% %2) thing
(sets :vowel) :vowel
(sets :consonant) :consonant
(sets :other) :other
package com.thomcc.nine.level.gen;
import java.awt.Image;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.ImageIcon;
thomcc / RPN.rb
Created Feb 8, 2012
Reverse Polish Notation Calculator
View RPN.rb
### Reverse Polish Notation (postfix) Calculator
class RPNCalculator
attr_accessor :stack
def initialize
# the stack, which will contain all the numbers this calculator
# can perform operations on
@stack = []
# the operations which this calculator supports. we store them as
# a hashtable which maps the symbol the user enters to a lambda of
# two values.
thomcc / core.clj
Created Feb 19, 2012
sending/receiving UDP messages
View core.clj
(ns chatty.core
(:import [ DatagramPacket InetAddress DatagramSocket]))
(defn send-data [socket ip port data]
(let [ipaddr (InetAddress/getByName ip)
pkt (DatagramPacket. (.getBytes data) (count data) ipaddr port)]
(.send socket pkt)))
(defn receive-data [socket]
(let [data (byte-array 1024), pkt (DatagramPacket. data 1024)]
thomcc / art.rkt
Created Feb 27, 2012
bitmap manip lib.
View art.rkt
#lang racket
;; -*- geiser-scheme-implementation: racket -*-
(require "utils.rkt")
;(provide struct:bitmap bitmap-width bitmap-height bitmap? make-bitmap bitmap-dimensions)
(provide (all-defined-out))
(struct bitmap (width height data) #:transparent
(λ (w h d type)
(if (and (= (vector-length d) h)
View gist:1952219
(ns clorth.core
(:require clojure.pprint))
(defn defword*
([dict word code] (defword* dict word code false))
([dict word code immediate]
(assoc dict word {:name word, :code code, :immediate immediate})))
(defmacro defword [dict name vars & code]
`(defword* ~dict (keyword '~name)
View gist:1963683
(defn splitup [ls]
(loop [rest ls, evens [], odds []]
(if-not rest
[evens odds]
(recur (nnext rest)
(conj evens (first rest))
(if (fnext rest)
(conj odds (fnext rest))
thomcc / levelgen.rkt
Created Mar 3, 2012
minecraft style level gen in racket
View levelgen.rkt
#lang racket/gui
(define (floor* n [v 1.0])
(inexact->exact (floor (/ n v))))
(define (offset n v)
(+ n (- (random v) (random v))))
(define (take-average lst)
(let ([n (exact->inexact (length lst))])
(for/sum ([e (in-list lst)]) (/ e n))))
thomcc /
Created Mar 4, 2012
old piece of 9 which never saw the light of day
package com.thomcc.nine.render;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
public class Radar {