Skip to content

Instantly share code, notes, and snippets.

View tyano's full-sized avatar

Tsutomu YANO tyano

View GitHub Profile
@tyano
tyano / gist:8913549
Last active August 29, 2015 13:56
MD5ハッシュ突き合わせ
(ns mdsample.core
(:require [clojure.core.reducers :as r])
(:import [java.security MessageDigest]
[javax.xml.bind DatatypeConverter]
[java.util Arrays]))
(def ^MessageDigest digester (MessageDigest/getInstance "MD5"))
(defn- hexdigest
[^String s]
@tyano
tyano / core.clj
Created February 11, 2014 18:20
MD5ハッシュ突き合わせ(Clojure) - 単体でパフォーマンスチューニングしたものを、core.asyncを使って並列化。引数の末尾に :map をつけると、map/filterを使ったバージョンでもテスト可能。primitiveのloopのほうがちょっとだけ速い。並列化はcore数程度で頭打ち。100とかにしても遅くなるだけ。
(ns mdsample.core
(:require [clojure.core.reducers :as r]
[clojure.core.async :refer [chan >! <!! go close! alts!!]])
(:import [java.security MessageDigest]
[javax.xml.bind DatatypeConverter]
[java.util Arrays]
[java.util Queue]
[java.util.concurrent ConcurrentLinkedQueue]))
(defn- hexdigest
@tyano
tyano / killcoreaudio.sh
Created May 1, 2014 10:36
killcoreaudio.sh
#!/bin/bash
sudo kill `ps -ax | grep 'coreaudiod' | grep 'sbin' |awk '{print $1}'`
package jp.javelindev.snippets;
public class Java8Sample {
public static void main(String[] args) {
Laco laco = new Laco();
SampleClass sample = new SampleClass();
sample.func(laco); //ClassCastException SomeClassはLacoにキャストできません
}
@tyano
tyano / AnnotationEventDispatcher.java
Last active August 29, 2015 14:15
アノテーションによってイベントハンドラを定義できるWicketのIEventDispatcher実装
/*
* Copyright 2011 Tsutomu YANO.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@tyano
tyano / EventHandler.java
Last active August 29, 2015 14:15
EventHandlerアノテーション定義
/*
* Copyright 2011 Tsutomu YANO.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
object Factorial2 {
def fact(n: Int): Int = (1 /: (1 to n)) (_ * _)
def main(args: Array[String]) = {
val n = if(args.length == 0) 1 else Integer.parseInt(args(0))
1 to n foreach {i => println(i + "! = " + fact(i))}
}
}
object Factorial {
def fact(n: Int): Int = if(n == 0) 1 else n * fact(n - 1)
def main(args: Array[String]) = {
val n = if(args.length == 0) 1 else Integer.parseInt(args(0))
1 to n foreach {i => println(i + "! = " + fact(i))}
}
}
public class Factorial {
static int fact(int n) { return n == 0 ? 1 : n * fact(n - 1); }
public static void main(String[] args) {
int n = args.length == 0 ? 1 : Integer.parseInt(args[0]);
for(int i = 1; i <= n; i++) System.out.println(i + "! = " + fact(i));
}
}
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.DefaultCaret;
import javax.swing.SwingUtilities;