Skip to content

Instantly share code, notes, and snippets.

@hyone
hyone / hyone-4clojure-solution97.clj
Created July 3, 2011 18:46 — forked from anonymous/hyone-4clojure-solution97.clj
4clojure #97 - Pascal's Triangle
;; hyone's solution to Pascal's Triangle
;; https://4clojure.com/problem/97
(fn [n] (nth (iterate #(vec (map + (conj % 0) (cons 0 %))) '[1]) (dec n)))
@hyone
hyone / gist:1065043
Created July 5, 2011 15:21
100 doors by ruby
# 安直にやる
doors1 = (1..100).inject([false] * 100) {|a,p|
a.each_with_index.map {|st,i| (i+1) % p == 0 ? !st : st }
}.map {|b| b ? :open : :close }
# 平方数だけが最終的 open になる、という性質を使う
doors2 = (1..100).map {|i|
root = Math.sqrt(i)
root == root.to_i ? :open : :close
}
@hyone
hyone / gist:1309608
Created October 24, 2011 17:42
elscreen-next, elscreen-previous を引数を受けとれるように改良。
(require 'elscreen)
(defun elscreen-cycle (count &optional previous)
"Switch the next/previous screen cyclically by count."
(cond
((elscreen-one-screen-p)
(elscreen-message
(format "You cannot escape from screen %d!"
(elscreen-get-current-screen))))
(t
@hyone
hyone / gist:1331070
Created November 1, 2011 16:38
中心点の座標を持つ二つの図形(点、正方形、長方形、円)が重なりを持つかどうか判定する
type figure =
Point
| Circle of float
| Rectangle of float * float
| Square of float;;
type 'a with_location = { loc_x: float; loc_y: float; body: 'a };;
let diff x y = abs_float (x -. y)
@hyone
hyone / gist:1645612
Created January 20, 2012 06:04
Fix syntax to work with slime repl (clojure) with paredit
;; From https://github.com/overtone/live-coding-emacs/blob/master/lib/durendal/durendal.el
(defun clojure-slime-repl-fix-syntax ()
(modify-syntax-entry ?\{ "(}")
(modify-syntax-entry ?\} "){")
(modify-syntax-entry ?\[ "(]")
(modify-syntax-entry ?\] ")[")
(modify-syntax-entry ?~ "' ")
(modify-syntax-entry ?, " ")
(modify-syntax-entry ?^ "'")
@hyone
hyone / gist:1689488
Created January 27, 2012 16:03
Run prove command on *.t file in quickrun.el
;; use prove on *.t file
(quickrun-add-command "perl/test"
'((:command . "prove")
(:exec . "%c -v %s")
(:description . "Run Perl Test script")))
(add-to-list 'quickrun-file-alist '("\\.t$" . "perl/test"))
@hyone
hyone / gist:1689469
Created January 27, 2012 16:00
Fix the problem output don't display in quickrun.el
(defadvice quickrun/apply-outputter (after quickrun/fix-scroll-buffer activate)
(recenter))
@hyone
hyone / gist:1705182
Created January 30, 2012 16:10
Check expression context
use v5.14;
use warnings;
sub hoge {
say do {
given (wantarray) {
when (undef) { "void" }
when (0) { "scalar" }
when (1) { "list" }
}
@hyone
hyone / gist:1711460
Created January 31, 2012 16:33
Multiple async HTTP requests by http.async.client
;; (defproject async-test1 "1.0.0-SNAPSHOT"
;; :description "FIXME: write description"
;; :dependencies [[org.clojure/clojure "1.3.0"]
;; [http.async.client "0.4.0"]]
;; :dev-dependencies [[swank-clojure "1.3.4"]])
(ns async-test1.core
(:require [http.async.client :as client]
[http.async.client.request :as request]))
@hyone
hyone / gist:1835356
Created February 15, 2012 12:24
Multiple async HTTP requests by aleph
;; (defproject async-test2 "1.0.0-SNAPSHOT"
;; :description "FIXME: write description"
;; :dependencies [[org.clojure/clojure "1.3.0"]
;; [aleph "0.2.1-alpha1"]])
(ns async-test2.core
(:use lamina.core
aleph.http))