Skip to content

Instantly share code, notes, and snippets.

@eungju
eungju / Pic.hs
Created August 8, 2011 15:40
PIC plugin for Gitit
module Pic (plugin) where
-- This plugin allows you to include a PIC diagram
-- in a page like this:
--
-- ~~~ {.pic name="diagram1"}
-- box "box"
-- ~~~
--
-- The "pic2png" executable must be in the path.
@eungju
eungju / run.clj
Created September 6, 2011 14:07
stdio test runner
(ns markup.test
(:use (clojure.java shell)))
(defn run-test [name input expected dut]
(let [actual (:out (sh dut :in input))]
(if (= actual expected)
:pass
:fail)))
(defn print-plan [tests]
@eungju
eungju / look-and-say.clj
Created September 21, 2011 04:42
Look-and-say sequence
(defn look-and-say [input]
((fn [input acc]
(if (empty? input)
(reverse acc)
(let [[x & xs] input [i n & as] acc]
(if (= x i)
(recur xs (list* x (inc n) as))
(recur xs (list* x 1 acc))))))
(rest input) [(first input) 1]))
@eungju
eungju / JsonPropertiesPersister.java
Created October 5, 2011 02:48
JsonPropertiesPersister for Spring
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
@eungju
eungju / binary-response.patch
Created October 31, 2011 02:56
A patch for the binary response body decoding problem
diff --git a/basis/http/client/client.factor b/basis/http/client/client.factor
index 7f99c62..8d1b996 100644
--- a/basis/http/client/client.factor
+++ b/basis/http/client/client.factor
@@ -162,7 +162,8 @@ ERROR: download-failed response ;
: http-request ( request -- response data )
[ [ % ] with-http-request ] B{ } make
- over content-encoding>> decode check-response-with-body ;
+ over content-encoding>> dup binary = [ drop ] [ decode ] if
@eungju
eungju / gist:1789606
Created February 10, 2012 13:13
test.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<body id="container">
<script type="text/javascript">
function drawPaths(canvas) {
var ctx = canvas.getContext('2d');
ctx.rect(0, 0, 256, 256);
ctx.fillStyle = "#FFFFFF";
ctx.fill();
ctx.strokeStyle = "#FF0000";
@eungju
eungju / skia-macosx-x86_64.patch
Created March 16, 2012 10:56
Skia Mac OS X 64 patch
Index: src/ports/SkFontHost_mac_coretext.cpp
===================================================================
--- src/ports/SkFontHost_mac_coretext.cpp (revision 3410)
+++ src/ports/SkFontHost_mac_coretext.cpp (working copy)
@@ -1948,7 +1948,7 @@
int count = CFArrayGetCount(cfArray);
if (tags) {
for (int i = 0; i < count; ++i) {
- tags[i] = (SkFontTableTag)CFArrayGetValueAtIndex(cfArray, i);
+ tags[i] = (SkFontTableTag)(uintptr_t)CFArrayGetValueAtIndex(cfArray, i);
@eungju
eungju / gist:2352121
Created April 10, 2012 15:26
수익율계산
: standard-deposit ( a r t -- a ) swap 1 + swap ^ * ;
: regular-deposit ( a r n t -- a ) over [ / ] [ * ] 2bi* iota [ 2over rot 1 + standard-deposit ] map sum 2nip ;
@eungju
eungju / p1_2.erl
Created August 31, 2012 07:31
문제로 풀어보는 알고리즘 149쪽 문제 3.c 풀이
-module(p1_2).
-compile(export_all).
s([_]=L) ->
[[L]];
s([A|L]) ->
S = s(L),
lists:append([lists:map(fun(X) -> [[A]|X] end, S)|lists:map(fun(X) -> each_append(A,X) end, S)]).
each_append(_, [], _, Acc) ->
@eungju
eungju / p1_3.erl
Created September 5, 2012 10:55
코딩 인터뷰 완전 분석 210쪽 17.3 변형 문제 풀이
-module(p1_3).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
% 주어진 자연수 n의 팩토리얼을 구해서 마지막에 붙은 연속된 0의 개수와 연속된 0 바로 앞에 나오는 숫자를 구하는 문제이다. 우선 문제 설명대로 팩토리얼을 구하고 마지막 연속된 0의 갯수를 세고, 마지막 연속된 0을 제외한 마지막 자리수를 구한다.
% 팩토리얼을 구한다.
factorial(1, Acc) ->
Acc;