Skip to content

Instantly share code, notes, and snippets.

View fogus's full-sized avatar
💭
attempting to learn how to better learn

Fogus fogus

💭
attempting to learn how to better learn
View GitHub Profile
@fogus
fogus / zombies.lisp
Created December 31, 2008 19:08
zombies cl
(comment
Features:
- One monster type: Zombies!
- Teleporters
- Artificial Unintelligence technology for realistic zombie horde
behavior
- Full in-game documentation
- Trees
- Gold (because really, what's a roguelike without gold?)
- Each game is guaranteed to end in death by zombie
@fogus
fogus / gist:265107
Created December 29, 2009 02:32 — forked from agentcoops/gist:265069
(defn listify [orig-list]
"Turns (1 2 3 ...) into (1 (2 (3 (...)))) using continuation passing style."
(loop [lst orig-list cont identity]
(if (= () lst)
(cont ())
(recur (rest lst)
(fn [insert]
(cont (cons (first lst)
(list insert))))))))
@fogus
fogus / cells.clj
Created February 18, 2010 13:59 — forked from richhickey/cells.clj
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(set! *warn-on-reflection* true)
(ns com.wangdera.slideshow
(:use [clojure.contrib.test-is])
(:import (java.io File)
(javax.imageio ImageIO)
(javax.swing JFrame JPanel Timer)
(java.awt Dimension Frame Color)
(java.awt.event ActionListener WindowAdapter)))
(def imagelist (atom []))
(def current-image (atom nil))
import scala.xml.{Node, Elem, Group}
/**
* A path to a Node in a Node tree.
*/
sealed trait NodePath {
def depth: Int
}
object NodePath {
(ns joc
(:use [clojure.test]))
(defn rpn-orig
([tokens] (rpn-orig tokens []))
([[top & tail] stack]
(lazy-seq
(if top
(if (fn? top)
(let [l (peek stack)
;; stolen from http://cemerick.com/2010/08/02/defrecord-slot-defaults/
(defmacro defrecord+defaults
"Defines a new record, along with a new-RecordName factory function that
returns an instance of the record initialized with the default values
provided as part of the record's slot declarations. e.g.
(defrecord+ Foo [a 5 b \"hi\"])
(new-Foo)
=> #user.Foo{:a 5, :b \"hi\"}"
[name slots & etc]
@fogus
fogus / j.c
Created August 27, 2010 01:33
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
typedef char C;typedef long I;
typedef struct a{I t,r,d[3],p[2];}*A;
#define P printf
#define R return
#define V1(f) A f(w)A w;
#define V2(f) A f(a,w)A a,w;
@Chouser
Chouser / avoid-force-print.clj
Created September 21, 2010 13:38
Avoid forcing lazy seqs when printing
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
; modified by Chris Houser
(require '[clojure.contrib.reflect :as hack])
@fogus
fogus / rle.clj
Created March 8, 2011 19:47
Run-length encoding a seq
(defn mundane-pack
"Mundane recursive way to pack a sequence"
[[f & r :as S]]
(if (seq S)
(let [[packed tail] (split-with {f true} S)]
(if (seq tail)
(cons packed (mundane-pack tail))
[packed]))
[nil]))