Skip to content

Instantly share code, notes, and snippets.

View bizenn's full-sized avatar
🏠
Working from home

Tatsuya BIZENN bizenn

🏠
Working from home
  • Tokyo
View GitHub Profile
;; -*- Mode: Lisp; Syntax: Common-Lisp -*-
;;
;; 第1回 Scheme コードバトン (CL fork)
;;
;; ■ これは何か?
;; 「Scheme のコードをバトンのように回していき面白い物ができあがるのを楽しむ遊びです。」のCL版です。
;; 次回 Shibuya.lisp で成果を発表します。
;; Scheme 初心者のコードを書くきっかけに、中級者には他人のコードを読む機会になればと思います。
;;
;; ■ 2 つのルール
;; 第1回 Scheme コードバトン
;;
;; ■ これは何か?
;; Scheme のコードをバトンのように回していき面白い物ができあがるのを楽しむ遊びです。
;; 次回 Shibuya.lisp で成果を発表します。
;; Scheme 初心者のコードを書くきっかけに、中級者には他人のコードを読む機会になればと思います。
;;
;; ■ 2 つのルール
;;
;; (1)自分がこれだと思える変更をコードに加えて2日以内に次の人にまわしてください。
#!/usr/bin/env gosh
;;; -*- mode: scheme; coding: utf-8 -*-
(use srfi-1)
(use gauche.threads)
(define-class <thread-ring-element> ()
((thread)
(mutex)
(next :init-keyword :next)))
@bizenn
bizenn / swank-clojure.sh
Created September 6, 2011 08:51
swank-clojure easy wrapper script.
#!/bin/sh
# swank-clojure easy wrapper
# This requires lein deps or mvn deps.
DEST=$1
if [ -z ${DEST} ]; then
DEST=.
fi
cd ${DEST}
if [ -f project.clj ]; then
@bizenn
bizenn / core.clj
Created September 16, 2011 08:09
Simple script for inspection of clojure.contrib.http.agent
;; -*- mode: clojure; coding: utf-8-unix -*-
;; clojure.contrib.http.agentの動作検証用スクリプト
(ns http-agent-test.core
(:use [clojure.contrib.http.agent :as ha :only [http-agent stream status]]
[clojure.java.io :as io :only [output-stream copy]]))
(defn get-agent [url file]
(ha/http-agent url
:handler
(fn [this]
@bizenn
bizenn / janken.scm
Created November 2, 2011 05:04
Janken script supporting more than two hands
;;; -*- mode: scheme; coding: utf-8 -*-
(use util.match)
(define (which-win hand-left hand-right)
(match (list hand-left hand-right)
[(or ('g 'g) ('p 'p) ('c 'c)) #f]
[(or ('g 'p) ('p 'c) ('c 'g)) hand-right]
[(or ('p 'g) ('c 'p) ('g 'c)) hand-left]
[else (errorf "Unknown hand: left ~a, right ~a" hand-left hand-right)]))
;; gosh> (janken 'g 'p)
;; p
@bizenn
bizenn / with-connections.clj
Created December 22, 2011 07:34
with-connections -- Handling database multi-connection explicitly
(require '[clojure.java.jdbc :as sql])
(defmacro with-connections
""
[bindings & body]
(cond (empty? bindings) `(do ~@body)
(symbol? (bindings 0)) `(sql/with-connection ~(bindings 1)
(let [~(bindings 0) (sql/connection)]
(with-connections ~(subvec bindings 2) ~@body)))))
@bizenn
bizenn / rfc-http.diff
Created June 21, 2012 08:39
Authentication support on rfc.http, but only BASIC.
diff --git a/lib/rfc/http.scm b/lib/rfc/http.scm
index e9f3fa4..b7eb9a0 100644
--- a/lib/rfc/http.scm
+++ b/lib/rfc/http.scm
@@ -50,6 +50,7 @@
(use srfi-13)
(use rfc.822)
(use rfc.uri)
+ (use rfc.base64)
(use gauche.net)
@bizenn
bizenn / gist:3096144
Created July 12, 2012 05:55
Now this is not a memory eater
#!/usr/bin/env gosh
;;; -*- mode: scheme; coding: utf-8 -*-
(use srfi-13)
(use srfi-14)
(use parser.peg)
(use gauche.generator)
(use gauche.sequence)
;; Fetch a record each time
@bizenn
bizenn / echo.scm
Created October 11, 2012 10:08
echo server (prefork)
#!/usr/bin/env gosh
;;; -*- mode: scheme; coding: utf-8 -*-
(use srfi-1)
(use gauche.net)
(use gauche.uvector)
;; gosh echo.scm <num>
(define (main args)
(let* ((server (make-server-socket 'inet 9999 :reuse-addr? #t :backlog SOMAXCONN))
(procs (list-tabulate (x->integer (cadr args))