Skip to content

Instantly share code, notes, and snippets.

View youz's full-sized avatar
🈳
kyomu

Yōsuke Ushiki youz

🈳
kyomu
View GitHub Profile
@youz
youz / bf-rec.lisp
Created January 8, 2009 07:33
brainf*ck interpreter (recursive)
(defun subnth (x n xs)
(let ((len (length xs)))
(if (<= len n) xs
(nconc (butlast xs (- len n)) `(,x) (cdr (nthcdr n xs))))))
(defun bf-rec (code pos tape ret jump)
(if (null code)
(values tape pos)
(flet ((_ (&key ((:tape e) tape) ((:code c) (cdr code)) ((:pos p) pos) ((:ret r) ret) ((:jump j) jump))
(bf-rec c p e r j)))
@youz
youz / bf.lisp
Created January 8, 2009 15:07
brainf*ck interpreter
(defun bf (src &optional (tape-length 100))
(let* ((code (remove-if-not (lambda (c) (find c "<>+-.,[]")) src))
(len (length code))
(jump (make-hash-table)))
(do* ((i 0 (1+ i)) (stack))
((= i len) (when stack (error (format nil "unmatch [ at ~A" (car stack)))))
(case (aref code i)
(#\[ (push i stack))
(#\] (unless stack (error (format nil "unmatch ] at ~A" i)))
@youz
youz / bf.js
Created January 9, 2009 06:19
brainf*ck interpreter for Javascript
/*@cc_on@*//*@if (@_jscript) var print=function(s){WScript.Echo(s)};@*//*@end@*/
var prompt=function(x,y){return'a'};
var alert = print;
(function(bf){j=s=[];o=p='';b=[m=0];bf=bf.split('');
for(i in bf)(c=bf[i])=='['?s.push(i):c==']'?j[j[i]=s.pop()]=i:0;
for(i=0;c=bf[i],i<bf.length;++i)
c=='>'?b[++m]=b[m]||0:
c=='<'?--m:c=='+'?++b[m]:
c=='-'?--b[m]:c=='['?b[m]||(i=j[i]):
@youz
youz / bf-reader.lisp
Created January 12, 2009 05:37
brainf*ck reader for CommonLisp
(defun read-bf (s &optional (d 0))
(let (code)
(loop
for p = nil then c
for c = #1=(read-char s nil) then #1#
while (and c (char/= c #\^))
do (case c
(#\[ (push `(loop while (< 0 #2=(aref tape pos))
do ,@(read-bf s (1+ d))) code))
(#\] (if (= d 0) (error "unmatch ]")
@youz
youz / outputz.barchart.user.js
Created January 17, 2009 04:53
Outputz.barchart.user.js
// ==UserScript==
// @name Outputz bar chart
// @namespace http://d.hatena.ne.jp/youz/
// @include http://outputz.com/*
// ==/UserScript==
(function(){
var make_uri = function (param) {
var q = '';
for (k in param) { q += '&' + k + '=' + param[k]; }
@youz
youz / list2xf.cs
Created February 16, 2009 03:33
convert filelist to X-Finder toolfolder.ini format
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
namespace list2xf
{
class list2xf
{
private const string usageText = "Usage: list2xf [-i filelist.txt] [-o output.ini] [-t typenum]";
@youz
youz / aobench.lisp
Created February 17, 2009 14:18
aobench CommonLisp ver.
(defparameter image-width 256)
(defparameter image-height 256)
(defparameter nsubsamples 2)
(defparameter nao-samples 8)
;; vector
(defmacro vx (v) `(svref ,v 0))
(defmacro vy (v) `(svref ,v 1))
(defmacro vz (v) `(svref ,v 2))
@youz
youz / aobench.lisp
Created February 19, 2009 14:44
aobench CommonLisp ver. (optimized)
(declaim (optimize (speed 3) (debug 0) (safety 0)))
(defparameter image-width 256)
(defparameter image-height 256)
(defparameter nsubsamples 2)
(defparameter nao-samples 8)
;; macros
(eval-when (:compile-toplevel :load-toplevel :execute)
@youz
youz / .sbclrc.lisp
Created February 26, 2009 16:04
ASDF settings for SBCL on Windows
(require :asdf)
(in-package :asdf)
(defvar *win-central-registry*
`((,(user-homedir-pathname) ".sbcl/site/")
(,(sb-ext:posix-getenv "SBCL_HOME") "site/")))
(defun win-sysdef-search (system)
(dolist (dir *win-central-registry*)
(let ((files (directory
@youz
youz / growl.l
Created March 23, 2009 13:21
Growl command for xyzzy
;;; growl.l --- Growl command for xyzzy
;;; Growl for Windows http://www.growlforwindows.com/gfw/default.aspx
;;; GNTP specification http://www.growlforwindows.com/gfw/help/gntp.aspx
(eval-when (:compile-toplevel :load-toplevel :execute)
(unless (find-package "growl")
(defpackage "growl"
(:use "lisp" "editor"))))