Skip to content

Instantly share code, notes, and snippets.

View sasaki-shigeo's full-sized avatar

SASAKI Shigeo sasaki-shigeo

View GitHub Profile
class StopWatch {
public static void main(String[] args)
throws InterruptedException // thrown by Thread.sleep()
{
for (int h = 0; h < 24; h++) {
for (int m = 0; m < 60; m++) {
for (int s = 0; s < 60; s++) {
System.out.printf("%2d:%02d:%02d\n", h, m, s);
Thread.sleep(1000); // 1000 ms = 1.0 sec
}
@sasaki-shigeo
sasaki-shigeo / fizzbuzz.hs
Created August 27, 2013 08:52
FizzBuzz in Haskell
-- FizzBuzz in Haskell
fizzBuzz n | n `mod` 15 == 0 = "FizzBuzz"
| n `mod` 3 == 0 = "Fizz"
| n `mod` 5 == 0 = "Buzz"
| otherwise = show n
main = do
putStr $ show $ map fizzBuzz [1..100]
@sasaki-shigeo
sasaki-shigeo / comprehension-example.scm
Last active December 21, 2015 19:09
Example code of SRFI 42 (eager comprehension) / 先行評価的内包表記のプログラム例
(cond-expand
(guile (use-modules (srfi srfi-42)))
(gauche (use srfi-42))
(racket (require srfi/42))
(plt (require (lib "42.ss" "srfi")))
(srfi-42 #t))
(list-ec (: k 10) k) ; 0 から始まり,10 の直前まで
(list-ec (: k 10) (* k k)) ; 0 から始まり,10 の直前まで k の 2乗
(list-ec (: k 1 10) k) ; 1 から始まり,10 の直前まで
@sasaki-shigeo
sasaki-shigeo / snowfalling1.pde
Last active December 12, 2016 17:16
Demonstration of snow falling (the number of crystals is fixed) /雪の降下アニメーション (雪の結晶の個数固定)
class Crystal {
float x, y, phi;
Crystal(float x0, float y0, float phi0) {
x = x0;
y = y0;
phi = phi0;
}
void fall() {
@sasaki-shigeo
sasaki-shigeo / snowfalling2.pde
Last active January 10, 2017 04:26
Demonstration of snow falling /Processing による雪の降下デモ
class Crystal {
float x, y, phi;
Crystal(float x0, float y0, float phi0) {
x = x0;
y = y0;
phi = phi0;
}
void fall() {
@sasaki-shigeo
sasaki-shigeo / SecureHashSample.scala
Created December 6, 2013 10:19
Sample code for Message Digest (Secure Hash Function) in Scala 一方向ハッシュ関数のプログラム例
import java.security.MessageDigest
def hexBytes(bs: Array[Byte]):String =
bs.map("%02X".format(_)).mkString(" ")
val md2 = MessageDigest.getInstance("MD2")
val md5 = MessageDigest.getInstance("MD5")
val sha1 = MessageDigest.getInstance("SHA-1")
val sha256 = MessageDigest.getInstance("SHA-256")
val sha384 = MessageDigest.getInstance("SHA-384")
@sasaki-shigeo
sasaki-shigeo / pentagon.pde
Last active March 11, 2019 04:57
drawing a pentagon in Processing / Processing で正5角形を描く
void setup() {
size(500, 500);
fill(255, 255, 0); // YELLOW
pentagon(250, 250, 100);
}
/** drawing a pantagon inscribed a circle as radius r ans its center is placed at (x, y).
*/
void pentagon(float x, float y, float r) {
pushMatrix();
@sasaki-shigeo
sasaki-shigeo / stars.pde
Last active December 30, 2015 12:09
Drawing stars / Processing で星形(5芒星)を描く
void setup() {
size(500, 500);
noStroke();
fill(255, 255, 0);
for (int i = 0; i < 10; i++) {
star(random(width), random(height), 30);
}
}
void star(float x, float y, float r) {
@sasaki-shigeo
sasaki-shigeo / hexagons.pde
Last active December 30, 2015 12:18
Drawing hexagons in Processing / Processing で正6角形を描く
void setup() {
size(500, 500);
for (int i = 0; i < 20; i++) {
hexagon(random(width), random(height), 20);
}
}
/** drawing a hexagon inscribed a circle as radius r and its center is placed at (x, y).
*/
void hexagon(float x, float y, float r) {
@sasaki-shigeo
sasaki-shigeo / snow-crystal.pde
Last active December 30, 2015 18:49
A kind of snow crystal /Processing で雪の結晶を描く
void setup() {
size(500, 500);
crystal(250, 250, 100);
}
void hexagon(float x, float y, float r) {
pushMatrix();
translate(x, y);
beginShape();
for (int i = 0; i < 6; i++) {