Skip to content

Instantly share code, notes, and snippets.

@kmtr
kmtr / handler.clj
Last active December 17, 2015 00:39
ring directoryindex middleware / -> /index.html /foo/ -> /foo/index.html /foo -> /foo
; clojure "1.5.1"
; compojure "1.1.5"
(ns app.handler
(:use compojure.core)
(:require [compojure.handler :as handler]
[compojure.route :as route]))
; middleware
(defn directoryindex [handler index]
(fn [request]
@kmtr
kmtr / Gruntfile.coffee
Last active December 17, 2015 03:08
Gruntfile.coffee jade, coffee, stylus
module.exports = (grunt)->
grunt.initConfig
jade:
compile:
files:[
expand: true
cwd: 'src/jade/'
src: '*.jade'
dest: 'build/'
ext: '.html']
@kmtr
kmtr / gist:5567921
Created May 13, 2013 12:20
remove .DS_Store
find . -name ".DS_Store" -print -exec rm {} \;

load and compile CoffeeScript

fs = require 'fs'
vm = require 'vm'
CoffeeScript = require 'coffee-script'
  
filePath = 'loader.litcoffee'
coffeeSource = fs.readFileSync filePath, {encoding: 'utf8'}
jsSource = CoffeeScript.compile coffeeSource, {literate: true}              
console.log jsSource
@kmtr
kmtr / hash.go
Created August 12, 2013 20:33
golang hash
package main
import (
"crypto/md5"
"crypto/sha512"
"fmt"
)
func main() {
hash := md5.New()
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github</groupId>
<artifactId>kmtr</artifactId>
<name>test</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
(defproject beaconlog "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [
[org.clojure/clojure "1.5.1"]
[compojure "1.1.6"]
[de.ubercode.clostache/clostache "1.3.1"]
[markdown-clj "0.9.35"]
@kmtr
kmtr / gist:7929809
Created December 12, 2013 15:31
insert a file object to blob
(ns beaconlog.db
(:use clojure.core)
(:require [clojure.java.jdbc :as j]))
(defn insert-file [file]
(j/db-transaction [db db-spec]
(let [buffer (byte-array (.length file))]
(j/insert! db :blob_table {:binary buffer}))))
@kmtr
kmtr / increment_rule.md
Last active January 18, 2016 15:13
トランプゲーム インクリメントのルール

インクリメント

この文書は?

トランプを使ったインクリメントというゲームのルールです。 神経衰弱に似ていますが、同じ数字のカードを探すのではなく、数字が増加する組み合わせを探します。

必要なもの

@kmtr
kmtr / file0.txt
Created January 19, 2016 16:14
VimでOCamlを書くためにmerlinとocp-indentを設定する ref: http://qiita.com/kmtr/items/25661e445278d6587de0
$ brew install ocaml --with-x11
$ brew install opam