Skip to content

Instantly share code, notes, and snippets.

View osa1's full-sized avatar

Ömer Sinan Ağacan osa1

View GitHub Profile
@osa1
osa1 / sprite_parse.py
Created September 8, 2011 18:45
simple script to locate sprites in a sprite sheet
import pygame
import pygame.locals as locals
def check_adjacency(rect, px):
test_rect = pygame.Rect(rect.left-1, rect.top-1, rect.width+2, rect.height+2)
return test_rect.collidepoint(px[0], px[1])
def find_groups(groups, px):
return [grp for grp in groups if check_adjacency(grp, px)]
@osa1
osa1 / grid.py
Created November 12, 2011 08:46
A simple grid class and some helper functions which I wrote to visualize some algorithms
import threading
import pygame
class Grid(object):
def __init__(self, size_x, size_y=None):
if not size_y:
self.size_x = size_x[0]
self.size_y = size_y[1]
else:
self.size_x = size_x
@osa1
osa1 / astroid.py
Created December 3, 2011 18:38
Generate randomly shaped polygons(namely, astroids)
import math
import random
import pygame
class Astroid:
def __init__(self, points=5, radius=50,
radius_range=10, angle_range=20):
self.points = points
self.radius = radius
@osa1
osa1 / gist:1541028
Created December 30, 2011 19:00
my first try for HAMT
(defpackage hamt
(:use :common-lisp)
(:export amt-base-node
amt-node
make-amt-base-node
get-entry
put-entry))
(in-package :hamt)
@osa1
osa1 / gist:1551743
Created January 2, 2012 19:08
persistent HAMT!!
(in-package :cl-user)
;; TODO: maybe I should use CLOS
(defpackage hamt
(:use :common-lisp)
(:export put get make-hamt)
(:shadow put get))
(in-package :hamt)
@osa1
osa1 / gist:1566862
Created January 5, 2012 19:46
first working version of zebot (web interface with hunchentoot is on the way)
(in-package :cl-user)
(ql:quickload '("usocket" "cl-who"))
(defpackage zebot
(:use :cl :usocket :cl-who))
(in-package zebot)
(defvar *NICK* "botnick")
@osa1
osa1 / gist:1570375
Created January 6, 2012 12:27
web interface generator for zebot
(in-package :cl-user)
(ql:quickload '("hunchentoot" "cl-who"))
(defpackage zebot-web
(:use :cl :hunchentoot :cl-who))
(in-package zebot-web)
;; TODO: find a way to use symbols from other packages
@osa1
osa1 / gist:1590973
Created January 10, 2012 20:23
persistent set data structure built on top of persistent hamt
(in-package :cl-user)
(defpackage pset
(:use :cl :hamt)
(:export put get make-pset)
(:shadow put get))
(in-package pset)
(defstruct (pset
@osa1
osa1 / gist:1694247
Created January 28, 2012 13:07
case-eval
(defmacro case-eval (testform &body clauses)
"Like case, but the keys are evaluated. (They're still compared with EQL)."
(let ((value (gensym)))
`(let ((,value ,testform))
(cond
,@(mapcar (lambda (clause)
(destructuring-bind (keys &body body) clause
(if (atom keys)
`((eql ,value ,keys) ,@body)
`((or ,@(mapcar (lambda (key) `(eql ,value ,key)) keys)) ,@body))))
@osa1
osa1 / gist:1704351
Created January 30, 2012 13:18
defbinstruct first try
(defun read-bytes (n &optional (in *standard-input*))
(apply #'+ (loop for i from 0 to (1- n)
collect (ash (read-byte in) (* 8 (- n (1+ i)))))))
(defmacro remove-keywords (form)
(cond ((null form) '())
((integerp form)
`(read-bytes ,form stream))
((and (consp form) (keywordp (first form)))
(case (first form)