Skip to content

Instantly share code, notes, and snippets.

View flada-auxv's full-sized avatar
🎯
Focusing

flada-auxv flada-auxv

🎯
Focusing
View GitHub Profile
@flada-auxv
flada-auxv / http.lisp
Created April 5, 2013 06:33
Land of Lisp 第13章 簡易webサーバの実装
;; CLISP特有のソケットコマンド・バイト/文字列変換コマンドを使っている
;; 日本語を利用するためのエンコーディング指定
(setf *terminal-encoding* charset:utf-8)
(setf *default-file-encoding* charset:utf-8)
;; 16進数で表されたASCIIコードをデコードする
(defun http-char (c1 c2 &optional (default #\space))
(let ((code (parse-integer
(coerce (list c1 c2) 'string)
@flada-auxv
flada-auxv / evolution.lisp
Created April 2, 2013 08:47
Land of Lisp 第10章
(defparameter *width* 100)
(defparameter *height* 30)
(defparameter *jungle* '(45 10 10 10))
(defparameter *plant-energy* 80)
;; key => (x座標 . y座標), value => t
;; コンスセルを比較するにはequalが必要となる為、:test #'equalとしている
(defparameter *plants* (make-hash-table :test #'equal))
(defparameter *reproduction-energy* 200)
(defstruct animal x y energy dir genes)
@flada-auxv
flada-auxv / robots.lisp
Last active December 15, 2015 16:39
Land of Lisp 第11章 loopとformatを悪用したジョークスクリプト 終盤のformatとかよく分かってない。。
(defparameter *robot-num* 10)
(defun robots ()
;; namedによって(return-from main とループを抜けれるように名前を持たせている
(loop named main
;; 幅64のゲーム盤におけるオフセット
;; withはループ内にローカル変数を作成する
with directions = '((q . -65) (w . -64) (e . -63)
(a . -1) (d . 1)
(z . 63) (x . 64) (c . 65))
@flada-auxv
flada-auxv / grand_theft_wumps.lisp
Created March 19, 2013 20:35
Land of Lisp 第8章
(load "graph_util")
(defparameter *congestion-city-nodes* nil)
(defparameter *congestion-city-edges* nil)
(defparameter *visited-nodes* nil)
(defparameter *node-num* 30)
(defparameter *edge-num* 45)
(defparameter *worm-num* 3)
(defparameter *cop-odds* 15)
@flada-auxv
flada-auxv / text_game.rb
Created March 17, 2013 12:48
usage追加してみた。一文字で打てるようにはしてない!
require 'yaml'
require 'hashie'
require 'readline'
@env = Hashie::Mash.new(YAML.load_file("./world.yml"))
@allowed_commands = %w(look walk pickup inventory)
@location = :living_room
def look
res = []
@flada-auxv
flada-auxv / graph.lisp
Created March 16, 2013 16:43
Land of Lisp 第7章
;; 使い方
;; 有向グラフ (graph->png "graph.dot" *wizard-nodes* *wizard-edges*)
;; 無向グラフ (ugraph->png "ugraph.dot" *wizard-nodes* *wizard-edges*)
(defparameter *wizard-nodes* '((living-room (you are in the living-room.
a wizrd is snoring loudly on the couch.))
(garden (you are in a beautiful garden.
there is a well infront of you.))
(attic (you are in the attic.
there is a giant welding torch in the corner.))))
#!/opt/local/bin/ruby1.9
#-*-encoding: utf-8-*-
class Env < Hash
def initialize(parms=[], args=[], outer=nil)
h = Hash[parms.zip(args)]
self.merge!(h)
@outer = outer
end
def find(key)
@flada-auxv
flada-auxv / game_repl.lisp
Created March 12, 2013 16:12
Land of Lisp 第5章
;; *** REPL ***
(defun game-repl ()
(let ((cmd (game-read)))
(unless (eq (car cmd) 'quit)
(game-print (game-eval cmd))
(game-repl))))
;; 入力に対して()を補い第二引数以降をシンボルとする
;; ex. walk east far => (WALK 'EAST 'FAR)
(defun game-read ()
# coding: utf-8
class Concern < ActiveRecord::Base
belongs_to :publication
end
@flada-auxv
flada-auxv / stack.rb
Created December 4, 2012 03:15 — forked from JoshCheek/stack.rb
The stack from my Pry screencast
# The stack I wrote for http://vimeo.com/26391171
# Note that there is an intentional bug in the each method :)
class Stack
Node = Struct.new :data, :next
def push(data)
@head = Node.new data, @head
end