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 / 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 / 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 / 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 / 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 / kairo.rb
Created August 23, 2013 18:22
抵抗の合計を求める
class Circuit
def initialize(circuit)
@circuit = analyze(circuit)
end
def calc
@circuit.inject(0) {|memo, item| memo + item.val}.truncate
end
def analyze(circuit)
#!/usr/bin/env ruby
LOG_ITEMS = %w(ip_address ident_user_name authenticate_user_name access_date request_line status_code forwarding_byte caller_url user_agent).each
class LogParser
def initialize(logs)
@logs = logs.chomp
@result = {}
@start_idx = 0
end
@flada-auxv
flada-auxv / gist:052f5dfff9b8a8b2aec5
Last active August 29, 2015 14:13
has_many :through な関連で accepts_nested_attributes_for を定義している時、親オブジェクトが保存されていない状態で子オブジェクトとの関連付けを行うと、外部キーが nil な中間テーブルの record を insert して死ぬ
# from http://guides.rubyonrails.org/association_basics.html#the-has-many-through-association
##### Model #####
class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, through: :appointments
accepts_nested_attributes_for :appointments
end
@flada-auxv
flada-auxv / Gemfile
Last active January 26, 2016 02:58
tegaki-jan sample
source "https://rubygems.org"
gem "sinatra"
@flada-auxv
flada-auxv / Gemfile
Last active February 12, 2016 01:59
hiyorime
source 'https://rubygems.org'
gem 'sinatra'
class Player
attr_reader :size
def initialize(senryaku)
@count = 0
@size = senryaku.size
@senryaku = senryaku
@senryaku_enum = senryaku.each_char.cycle
end