Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hideaki-t
hideaki-t / send_to_kindle.py
Created July 4, 2014 05:12
send to kindle
import sys
from outbox import Outbox, Email, Attachment
from pathlib import Path
if sys.version_info.major < 3:
d = sys.getfilesystemencoding()
def u(s):
return unicode(s, d)
@hideaki-t
hideaki-t / normalize_neologd.py
Last active August 29, 2015 14:18
normalize_neologd.py
# encoding: utf8
from __future__ import unicode_literals
import re
import unicodedata
def unicode_normalize(cls, s):
pt = re.compile('([{}]+)'.format(cls))
def norm(c):
@hideaki-t
hideaki-t / mmap_memoryview.ipynb
Created April 12, 2015 11:35
wrapping mmap object with memoryview
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hideaki-t
hideaki-t / levenshtein_distance.rs
Last active August 29, 2015 14:21
Unicode-aware Levenshtein distance by Rust
fn main() {
fn f(a:&str, b:&str) {
println!("{}:{} => {}", a, b, levenshtein_distance(a, b));
}
f("こんにちは", "こんばんは");
f("hello", "ell0");
f("hello", "hello");
f("こんにちは", "hello");
f("ABC", "ABC");
f("\u{1F369}", "\u{1F36A}");
@hideaki-t
hideaki-t / javafx20_custombrowser.groovy
Created June 29, 2011 23:01
JavaFX 2.0 and Groovy
import javafx.animation.Interpolator
import javafx.animation.TranslateTransition
import javafx.application.Application
import javafx.event.Event
import javafx.event.EventHandler
import javafx.geometry.Pos
import javafx.scene.Group
import javafx.scene.Scene
import javafx.scene.control.Button
import javafx.scene.control.TextBox
@hideaki-t
hideaki-t / groovyfx_custombrowser.groovy
Created July 3, 2011 01:04
a custom browser using GroovyFX.
import groovyx.javafx.ClosureEventHandler
import groovyx.javafx.GroovyFX
import groovyx.javafx.SceneGraphBuilder
import javafx.animation.Interpolator
import javafx.animation.TranslateTransition
import javafx.util.Duration
GroovyFX.start({
def loadAction = { view.engine.load(new URI(urlBox.getText()).toString()) }
def stage = new SceneGraphBuilder().stage(title: "GroovyFXのテスト") {
@hideaki-t
hideaki-t / compositing1.js
Created July 16, 2011 17:22
compositing multiple non-transparent images(graphs of munin)
var imgs = document.querySelectorAll('img[src*="netstat"]');
var c = document.createElement('canvas');
var c2 = document.createElement('canvas');
c.width = c2.width = imgs[0].width;
c.height = c2.height = imgs[0].height;
document.body.appendChild(c);
var ctx = c.getContext('2d');
var ctx2 = c2.getContext('2d');
var i = 0, n = imgs.length;
@hideaki-t
hideaki-t / gist:1088268
Created July 18, 2011 00:04
sleepsort with barrier(python3.2+)
import threading
import time
import random
from sys import argv
from queue import Queue
class T(threading.Thread):
def __init__(self, num, barrier, queue):
self.barrier = barrier
@hideaki-t
hideaki-t / gist:1090953
Created July 18, 2011 23:33
check performance and consistency of several counter implementations.
import java.util.concurrent.atomic.AtomicInteger;
public class test {
static final int n = 500_000_000;
int i = 0;
int si = 0;
volatile int vi = 0;
AtomicInteger ai = new AtomicInteger(0);
AtomicInteger ai2 = new AtomicInteger(0);