Skip to content

Instantly share code, notes, and snippets.

View letoh's full-sized avatar
💭
I may be slow to respond.

letoh letoh

💭
I may be slow to respond.
View GitHub Profile
@letoh
letoh / interpreter.js
Created June 19, 2017 07:51 — forked from be5invis/interpreter.js
A CPS-style S-exp interpreter (with call/cc)
function interpret(form, env, k){
if(form instanceof Array){
switch(form[0]){
case 'lambda': {
var params = form[1];
var body = form[2];
return k(function(k){ return function() {
var e = Object.create(env);
for(var j = 0; j < params.length; j++)
e[params[j]] = arguments[j];
@letoh
letoh / fizzBuzz.c
Last active February 14, 2017 06:08 — forked from lancetw/fizzBuzz.c
char** fizzBuzz(int n, int* returnSize) {
struct _ {
char *rets[n + 1];
char data[0];
} * ret = calloc(sizeof(struct _) + n * 9 + 1, sizeof(char));
*returnSize = n;
char * sp = ret->data;
for (int i = 1; i <= n; ++i, sp += 9) {
ret->rets[i - 1] = sp;
https://dtwnuis9ywd79.cloudfront.net/paijo/images/paijo_vol28.png
「語言不分貴賤」
@letoh
letoh / Makefile
Last active October 25, 2016 02:55
Common Lisp package
BIN = test-app
all: $(BIN)
test-app: a.lisp b.lisp
ccl64 -l build.lisp
clean:
rm -f $(BIN)
@letoh
letoh / org-emphasis-hack.el
Created July 21, 2015 18:14
some tweaks on org-emphasis syntax
;;; 只在 Org 8.2.10 測試過
;;; 應該可以放到 org-load-hook 之類的地方吧...
;; 允許中文全形標點緊接在 emphasis marker 前後 (i.e. pre-, post-match)
;; 例: ,*中文* 或 +測試+。
(setcar (nthcdr 0 org-emphasis-regexp-components) " \t('\"{、,。:;?「」『』〈〉《》>【】﹝﹞")
(setcar (nthcdr 1 org-emphasis-regexp-components) "- \t.,:!?;'\")}\\、,。:;?「」『』〈〉《》【】﹝﹞")
;; 允許 , ' " 這三個標點出現在緊臨 emmphasis marker 內側的位置
;; 例: ="= 或 =123"=
(setcar (nthcdr 2 org-emphasis-regexp-components) " \t\r\n")
// modified from b****'s implementation https://gist.github.com/anonymous/aaafa4bd4de9d1a8ffa0
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdarg.h>
enum {n, y, d, o, r, e, m, s, _};
int to_num(char hash[], ...) {
@letoh
letoh / dbobj.c
Last active August 29, 2015 14:18
#include <stdio.h>
#include <string.h>
#include <db.h>
#define F_NUM(name) \
long name
#define F_TEXT(name,n) \
struct { int len; char data[n]; } name
#define REC(name) struct Rec_##name
@letoh
letoh / gitconfig
Created March 17, 2015 04:19
gitconfig
[alias]
st = status
ci = commit
co = checkout
up = checkout
br = branch -v
cia = commit -a
di = diff --color
gr = grep -n
log1 = log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
@letoh
letoh / randpw
Created February 25, 2015 02:33
#!/bin/sh
date | md5sum
date +%s | sha256sum | base64 | head -c 32; echo
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;
openssl rand -base64 32
openssl rand -base64 37 | cut -c1-37
tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1
strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6
;; goal in elisp
;; emacs -batch -Q -l goal.el
(defmacro g (&rest al)
`(concat "g"
(apply 'concat
(mapcar (lambda (o)
(if (null o) "o"
(if (listp o) (car o)