Skip to content

Instantly share code, notes, and snippets.

View tyano's full-sized avatar

Tsutomu YANO tyano

View GitHub Profile
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));
}
}
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))}
}
}
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;
var fs = require('fs');
var sys = require('sys');
var stream = fs.createReadStream('./sample.txt', { 'flags': 'r',
'encoding': 'UTF-8',
'bufferSize': 4 * 1024});
var stream2 = fs.createReadStream('./sample2.txt', { 'flags': 'r',
'encoding': 'UTF-8',
'bufferSize': 4 * 1024});
@tyano
tyano / gist:1429205
Created December 4, 2011 04:48
List(1, 2, 3, 1) を Map(1 -> 2, 2 -> 1, 3 -> 1)
List(1,2,3,1).zip(List(1,1,1,1)).foldLeft(Map[Int,Int]()) { (x, y) => x.get(y._1) match { case Some(v) => x + Pair(y._1, (v + y._2)) case None => x + y }}
@tyano
tyano / gist:1429218
Created December 4, 2011 04:54
List(1, 2, 3, 1) を Map(1 -> 2, 2 -> 1, 3 -> 1) No.2
List(1,2,3,1).foldLeft(Map[Int,Int]()) { (x, y) => x.get(y) match { case Some(v) => x + Pair(y, (v + 1)) case None => x + Pair(y, 1) }}
@tyano
tyano / gist:2497774
Created April 26, 2012 08:51
errors on easy_install subvertpy
Searching for subvertpy
Reading http://pypi.python.org/simple/subvertpy/
Reading http://samba.org/~jelmer/subvertpy
Reading http://launchpad.net/subvertpy
Best match: subvertpy 0.8.10
Downloading http://samba.org/~jelmer/subvertpy/subvertpy-0.8.10.tar.gz
Processing subvertpy-0.8.10.tar.gz
Running subvertpy-0.8.10/setup.py -q bdist_egg --dist-dir /tmp/easy_install-NDoICr/subvertpy-0.8.10/egg-dist-tmp-GLfV9D
Traceback (most recent call last):
File "/usr/bin/easy_install-2.7", line 10, in <module>
@tyano
tyano / build.xml
Created February 4, 2013 11:12
apache riverのインストールスクリプト
<target name="install-artifacts" depends="jars">
<macrodef name="install">
<attribute name="file" />
<attribute name="pom" />
<sequential>
<artifact:install file="@{file}" >
<pom refid="@{pom}"/>
</artifact:install>
</sequential>
</macrodef>
@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]