Skip to content

Instantly share code, notes, and snippets.

View thomcc's full-sized avatar
🦀

Thom Chiovoloni thomcc

🦀
View GitHub Profile
@thomcc
thomcc / VoronoiNose.java
Created January 21, 2012 17:31
voronoi nose
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
thomcc / RPN.rb
Created February 8, 2012 01:51
Reverse Polish Notation Calculator
### 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
thomcc / core.clj
Created February 19, 2012 18:52
sending/receiving UDP messages
(ns chatty.core
(:import [java.net 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
thomcc / art.rkt
Created February 27, 2012 06:22
bitmap manip lib.
#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
#:guard
(λ (w h d type)
(if (and (= (vector-length d) h)
(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)
(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))
odds)))))
@thomcc
thomcc / levelgen.rkt
Created March 3, 2012 06:27
minecraft style level gen in racket
#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
thomcc / Radar.java
Created March 4, 2012 15:59
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 {
(statements
(compile
'((define (factorial n)
(if (= n 0)
1
(* n (factorial (- n 1)))))
(factorial 1000))
'val
'return))
; =>
@thomcc
thomcc / quine.rb
Created March 13, 2012 14:44
quine in ruby
x = [
%q{puts "x = ["},
%q{x.each_with_index {|s,i| puts "%q{" << s << "}" << (i == x.length-1 ? "" : ",") }},
%q{puts "]"},
%q{puts "x.map {|s| eval s}"}
]
x.map {|s| eval s}