Skip to content

Instantly share code, notes, and snippets.

View sasaki-shigeo's full-sized avatar

SASAKI Shigeo sasaki-shigeo

View GitHub Profile
@sasaki-shigeo
sasaki-shigeo / zip.scala
Last active April 9, 2019 15:24
A sample program of ZipOutputStream and ZipInputStream. This code is ported from Hishidama's Java Zip File Memo. See http://www.ne.jp/asahi/hishidama/home/tech/java/zip.html
import java.io._
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
import java.util.zip.ZipInputStream
def encode(zos: ZipOutputStream, files: Seq[File]) {
for (f <- files) {
if (f.isDirectory) {
encode(zos, f.listFiles)
} else {
@sasaki-shigeo
sasaki-shigeo / gzip-sample.scala
Last active August 26, 2019 14:06
A sample code of gzip in Scala. The API of gzip is defined in the package java.util.zip that provides GZIPOutputStream and GZIPInputStream, the subclasses of DeflatterOutputStream and InflatterInputStream, respectively. GZIPOutputStream compresses data into a given output stream and GZIPInputStream decompresses data from an input one.
import java.io._
import java.util.zip._
val pi = new PipedInputStream
val po = new PipedOutputStream(pi)
val zo = new GZIPOutputStream(po)
val zi = new GZIPInputStream(pi)
val w = new PrintWriter(zo)
val r = new BufferedReader(new InputStreamReader(zi))
@sasaki-shigeo
sasaki-shigeo / parse-xml.scala
Created January 30, 2014 01:23
incomplete XML parser / Scala の parser combinator で XML の構文解析器を作ったが,まだ不完全
import scala.util.parsing.combinator._
abstract class XML
case class Element(name: String, attributes: Map[String, String], contents: Seq[XML]) extends XML
case class Letter(c: Char) extends XML
case class CDATA(text: String) extends XML
case class CharEntity(c: Char) extends XML
case class Entity(c: Char) extends XML
case class Comment(text: String) extends XML
@sasaki-shigeo
sasaki-shigeo / TurtleGraphics.pde
Last active May 3, 2020 08:00
Turtle Graphics class in Processing / Processingによるタートルグラフィックスクラス(簡易版)
class Turtle {
float x = 0;
float y = 0;
float dir = 0;
boolean pen_down = false;
int weight = 1;
color pen_color = #000000;
Turtle(float x, float y, float dir) {
this.x = x;
@sasaki-shigeo
sasaki-shigeo / analog-clock.pde
Last active February 9, 2016 05:32
analogue clock / アナログ時計
float r;
void setup() {
size(500, 500);
r = min(width, height) * 7 / 16;
frameRate(1);
smooth();
}
void draw() {
@sasaki-shigeo
sasaki-shigeo / clock-face1.pde
Created February 6, 2016 13:47
A clock face / 時計の文字盤
size(500, 500);
float r = min(width, height) / 2;
translate(width / 2, height / 2);
strokeCap(SQUARE);
strokeWeight(10);
for (int i = 0; i < 12; i++) {
line(0.88 * r * cos(radians(30 * i)), 0.88 * r * sin(radians(30 * i)),
0.98 * r * cos(radians(30 * i)), 0.98 * r * sin(radians(30 * i)));
}
@sasaki-shigeo
sasaki-shigeo / clock-face2.pde
Last active February 7, 2016 14:04
A Clock Face in Arabic Numerals / 算用数字の時計の文字盤
size(500, 500);
int font_px = min(width, height) / 16;
float r = min(width, height) / 2 - font_px;
textSize(font_px);
textAlign(CENTER, CENTER);
translate(width / 2, height / 2);
fill(0);
for (int i = 1; i <= 12; i++) {
@sasaki-shigeo
sasaki-shigeo / clock-face3.pde
Created February 7, 2016 14:00
A Clock Face in Roman Numerals / ローマ数字の時計の文字盤
size(500, 500);
int font_px = min(width, height) / 16;
float r = min(width, height) / 2 - font_px;
String[] hs = { "XII", "I", "II", "III", "IIII", "V", "VI", "VII", "VIII", "IX", "X", "XI" };
PFont font = createFont("Serif", font_px);
textFont(font);
textSize(font_px);
textAlign(CENTER, CENTER);
#
# zsh login script
# (c) 2016 sasaki-shigeo@acm.org
#
# Setting Terminal
eval `tset -s`
stty -istrip
bindkey -em
@sasaki-shigeo
sasaki-shigeo / snowfalling3.pde
Last active January 30, 2017 06:26
a tree, stars, snow
float angle = radians(20);
PGraphics aTree;
class Snow {
float x;
float y;
float z;
float sz;
Snow(float x0, float y0, float z0, float sz0) {