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 / asm.clj
Created August 30, 2011 18:41 — forked from hiredman/asm.clj
; generates a jar file in the pwd named cl.jar
; cl.jar contians a class file that contains a class named x.cl
; x.cl is a ClassLoader which is extended to have a method 'add'
; 'add' takes a ClassLoader or a URL
; in the case you call 'add' on a URL the URL is wrapped in a URLClassLoader
; x.cl searches the list of 'add'ed ClassLoaders for classes
;
; idea is to use it for developement, when dynamically adding classes from
; jars could be useful.
@fogus
fogus / Makefile
Created August 30, 2011 18:42 — forked from podhmo/Makefile
rr
default:
echo "(+ 1 2) (+ 10 3)" | ruby tlisp.rb
@fogus
fogus / HashLikeSmallTalkConditionals.rb
Created August 30, 2011 18:44 — forked from frogstarr78/HashLikeSmallTalkConditionals.rb
Ruby Hashes emulating Smalltalk Conditionals rr
#!/usr/bin/env ruby
module HashLikeSmalltalkConditionals
class ::Object
def nil? hash
hash[:if_false].call
self
end
end
@fogus
fogus / smalltalk_reference.st
Created August 30, 2011 18:45 — forked from sl4m/gist:712272
smalltalk_reference.st rr
"Chris Rathman / [email protected]
************************************************************************
* Allowable characters: *
* - a-z *
* - A-Z *
* - 0-9 *
* - .+/\*~<>@%|&? *
* - blank, tab, cr, ff, lf *
* *
* Variables: *
@fogus
fogus / foldr.clj
Created September 6, 2011 17:57 — forked from pjb3/foldr.clj
(defn foldr [f acc coll]
(if (first coll)
(f (first coll) (foldr f acc (rest coll)))
acc))
(defn neighbours [[x y]]
(for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])]
[(+ dx x) (+ dy y)]))
(defn step [cells]
(set (for [[loc n] (frequencies (mapcat neighbours cells))
:when (or (= n 3) (and (= n 2) (cells loc)))]
loc)))
(def board #{[2 1] [2 2] [2 3]})
@fogus
fogus / chess.feature
Created September 7, 2011 14:18 — forked from aslakhellesoy/chess.feature
Let's cuke some chess...
Feature: Validate moves
Scenario: Moving the knight illegally
Given the following board:
| | | | | | | | |8|
| | | | | | | | |7|
| | | | | | | | |6|
| | | | | | | | |5|
| | | |♞| | | | |4|
| | | | | | | | |3|
|♙| | | | | | | |2|
@fogus
fogus / fen_controller.rb
Created September 7, 2011 14:19 — forked from punund/fen_controller.rb
Dynamic creation of chess diagrams
#
# responds to requests with Forsyth-Edwards notation in URL with an image:
# http://dia-x.info/fen/2S5/1bQKpR2/4s3/2bkpP2/Sr1p2r1/1P1R3B/1B2s3/8
#
class FenController < ApplicationController
include Magick
#!/usr/bin/env ruby
if ARGV.size < 2
$stderr.puts 'usage: monitor <path> <command> [arg1 arg2 ...]'
exit 100
end
PATH = ARGV[0]
COMMAND = ARGV[1]
ARGS = ARGV[2..-1]
@fogus
fogus / Coder.scala
Created September 7, 2011 17:06 — forked from swannodette/Coder.scala
phone_code.clj
package demo
class Coder(words: List[String]) {
private val mnemonics = Map(
'2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL",
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ")
private val charCode: Map[Char, Char] =
for ((digit, str) <- mnemonics; letter <- str) yield letter -> digit