Skip to content

Instantly share code, notes, and snippets.

View hyamamoto's full-sized avatar

Hiroshi Yamamoto hyamamoto

View GitHub Profile
@hyamamoto
hyamamoto / portable_zip.py
Created August 19, 2015 12:24
A utility class for the in-memory zip archive creation for Python 2.4, 2.5, 2.6, 2.7, 3.x. (The basic Idea is largely taken from http://stackoverflow.com/a/19722365.)
# -*- coding: utf-8 -*-
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
# Copyright (C) 2015 Hiroshi Yamamoto <[email protected]>
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
@hyamamoto
hyamamoto / utf8_to_sjis.go
Created February 7, 2015 17:05
ShiftJIS <=> UTF-8 conversion samples in Go language.
package main
import (
"fmt"
"strings"
"bytes"
"io"
"io/ioutil"
"golang.org/x/text/transform"
// "code.google.com/p/go.text/transform" // deprecated
@hyamamoto
hyamamoto / example.html
Last active August 29, 2015 14:14
HTML elements with css-class `imgs-onload` will enables `onload` function which is called after all the `<img>` inside the element actually finished loading images.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="jq_imgs_onload.js"></script>
</head>
<body>
<div class='imgs-onload' onload="window.alert('all resources loaded')">
<img src="http://i.imgur.com/PWSOy.jpg" />
<img src="http://i.imgur.com/PWSOy.jpg" />
@hyamamoto
hyamamoto / binarytree_printer.go
Created January 20, 2015 13:51
Binary-tree printer in Go language. This was a part of my answer for stackoverflow question ( http://ja.stackoverflow.com/questions/4739/ ), inspired by this answer ( http://stackoverflow.com/a/4973083 )
package main
import (
"time"
"math/rand"
"strconv"
)
// The main function
func main() {
@hyamamoto
hyamamoto / touch_NNNN.sh
Last active August 29, 2015 14:13
Sequentially Named File Generator. A bash shell script that creates a next 4-digit numbered file.
#!/bin/bash
# -------------------------------------------------------
# Sequentially Named File Generator.
#
# Create a new numbered file based on the given filename.
#
# Example:
#
# * "test.txt" -> "test####.txt"
# * "test" -> "test####"
@hyamamoto
hyamamoto / Readme.md
Created December 22, 2014 03:25
The script what greps terminfo entries and print the related information. It's useful to find a key corresponding to an unknown character sequence.

Reverse terminfo entry lookup

What's this

This script searches terminfo entries and print its information.

Technically, it does the same as the 1-liner below does.

@hyamamoto
hyamamoto / IntClassBug.scala
Last active August 29, 2015 14:11
I came across a compiler bug that involves a generics type with `scala.Int` . This can be one of the examples to show how they're handling primitive types internally. (Fixed in scala 2.10.1-RC1 by https://github.com/scala/scala/pull/1904 )
case class IntClassBug[A <: Int]() {
def test(init:A) = {
println("type=" + init.getClass)
}
}
@hyamamoto
hyamamoto / LENB.js
Last active October 13, 2021 08:46
Google Doc & Spreadsheets's LENB() function which is present in Microsoft Excel. LENB() returns a number of bytes, while LENH() returns a width of the given text. These functions are useful when you check if your translation resources can be fit inside original screens.
// To add these functions to your Google Doc documents,
// see https://developers.google.com/apps-script/guides/sheets/functions
/**
* @fileOverview Google Doc Apps Script: LENB() / LENH() functions for Spreadsheet.
* @author Hiroshi Yamamoto ([email protected])
* @license <a href="http://www.wtfpl.net/">WTFPL version 2.0</a>
* @version 0.2.0
*/
@hyamamoto
hyamamoto / reverser.sh
Last active August 29, 2015 14:10
A shell script to reverse lines in a file or stdin. This is needed because some environments lack "tac" or "tail-r" command. I used "sed" as a last resort which may have a performance problem if you are processing enormous text data. ( Install "tac" then! )
#!/bin/bash
#
# Reverse the order of lines in a file or stfin
#
# A tac-equivalent command for every environment.
# This script is needed because some environments
# like OS X and MingW lack tac command.
#
# Scriptd by Hiroshi Yamamoto ([email protected])
# Licensed under WTFPL version 2.0 (http://www.wtfpl.net/)
@hyamamoto
hyamamoto / keys_next_to_keys.dart
Created November 19, 2014 03:24
Getting a list of keys next to a given key according to a physical layout of the keyboard. Converted from zxcvbn code. Only to realize I can't use this for English Dvorak.
Map<String, List<String>> _DICT_KEYBOARD_KEY_CONNECTION = {
"!": ["`~", null, null, "2@", "qQ", null],
'"': [";:", "[{", "]}", null, null, "/?"],
"#": ["2@", null, null, "4\$", "eE", "wW"],
"\$": ["3#", null, null, "5%", "rR", "eE"],
"%": ["4\$", null, null, "6^", "tT", "rR"],
"&": ["6^", null, null, "8*", "uU", "yY"],
"'": [";:", "[{", "]}", null, null, "/?"],
"(": ["8*", null, null, "0)", "oO", "iI"],
")": ["9(", null, null, "-_", "pP", "oO"],