Skip to content

Instantly share code, notes, and snippets.

@kzkn
kzkn / BitStream.java
Last active November 11, 2019 23:35
import java.nio.ByteBuffer;
public class BitStream {
private final byte[] bytes;
private final int numOfBits;
private int pos;
public BitStream(ByteBuffer buf) {
bytes = new byte[buf.remaining()];
@kzkn
kzkn / md5.lisp
Last active November 10, 2016 14:57
(defpackage :md5
(:use :cl)
(:shadow :cl
:count
:block)
(:export :init
:update
:digest
:hexdigest))
(in-package :md5)
@kzkn
kzkn / sha1.lisp
Last active January 14, 2016 12:04
(defpackage :sha1
(:use :cl)
(:shadow :block)
(:export :init
:update
:digest
:hexdigest))
(in-package :sha1)
(deftype u8 () '(unsigned-byte 8))
(in-package :cl)
(defpackage piecetable
(:use :cl)
(:shadow :cl :delete))
(in-package :piecetable)
(defstruct span
in-add-buffer
start
end)
@kzkn
kzkn / Child.java
Last active April 28, 2016 15:29
子プロセスで開いているポートに親プロセスからconnectする
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
public class Child {
public static void main(String[] args) throws Exception {
try (ServerSocket sock = new ServerSocket()) {
;;;; http://bford.info/pub/lang/packrat-icfp02.pdf
;;;; Section 2.1 Recursive Dscent Parsing
;;;; 再帰下降パーサー
;;;;
;;;; Additive <- Multitive '+' Additive | Multitive
;;;; Multitive <- Primary '*' Multitive | Primary
;;;; Primary <- '(' Additive ')' | Decimal
;;;; Decimal <- '0' | ... | '9'
;;;; http://bford.info/pub/lang/packrat-icfp02.pdf
;;;; Section 2.4 Packrat Parser
;;;;
;;;; Additive <- Multitive '+' Additive | Multitive
;;;; Multitive <- Primary '*' Multitive | Primary
;;;; Primary <- '(' Additive ')' | Decimal
;;;; Decimal <- '0' | ... | '9'
(defpackage pp1
#!/bin/sh
while read f
do
echo "$f"
# ffmpeg -loglevel error -i "${f}" -f image2 -vcodec png -r 1 "%03d.png"
# https://unix.stackexchange.com/a/36411
ffmpeg -loglevel error -i "${f}" -f image2 -vcodec png -r 1 "%03d.png" </dev/null
done <<EOF
a.mp4
@kzkn
kzkn / line_wrap_ext.rb
Created November 14, 2017 15:41
日本語の禁則文字を意識して tokenize する prawn への monkey patch
module Prawn
module Text
module Formatted #:nodoc:
# @private
class LineWrap #:nodoc:
def scan_pattern(encoding = ::Encoding::UTF_8)
ebc = break_chars(encoding)
eshy = soft_hyphen(encoding)
ehy = hyphen(encoding)
ews = whitespace(encoding)
@kzkn
kzkn / rbctags
Last active March 27, 2018 14:12
#!/bin/sh
clean=0
rails=0
while getopts rc OPT
do
case $OPT in
r) rails=1 ;;
c) clean=1 ;;