Skip to content

Instantly share code, notes, and snippets.

# cf. https://html-preview.github.io/?url=https://github.com/hashids/hashids.github.io/blob/master/index.html
require "hashids"
puts "Default alphabet length: #{Hashids::DEFAULT_ALPHABET.length}"
hashids = Hashids.new("This is salt", 10)
puts <<MSG
Alphabet: #{hashids.alphabet}
Alphabet length: #{hashids.alphabet.length}
Seps: #{hashids.seps}
@abicky
abicky / gist:3052980
Created July 5, 2012 11:00
Create HTMLImageElement from HTMLCanvasElement and HTMLCanvasElement from HTMLImageElement
import "js/web.jsx";
class Util {
static function image2Canvas(image : HTMLImageElement) : HTMLCanvasElement {
var document = dom.window.document;
var canvas = document.createElement("canvas") as HTMLCanvasElement;
canvas.width = image.width;
canvas.height = image.height;
var ctx = canvas.getContext("2d") as CanvasRenderingContext2D;
ctx.drawImage(image, 0, 0);
#!/bin/bash
set -eu
PANE_MINIMUM=2
usage() {
cat <<USAGE
Usage: $(basename $0) [-c COL] [-r ROW] [--ssh-option SSH_OPTIONS] HOST [HOST2 ...]
@abicky
abicky / KNB.R
Created June 2, 2013 11:20
KNB corpus parser for R
# Parser for KNB corpus (http://nlp.ist.i.kyoto-u.ac.jp/kuntt/#ga739fe2)
#
# Copyright 2012- Takeshi Arabiki
# License: MIT License (http://opensource.org/licenses/MIT)
#
# Example:
#
# # KNB コーパスを data ディレクトリ下にダウンロードして解凍
# # 返り値は解凍後のファイル名
# dir <- KNB$downloadCorpus("data")
@abicky
abicky / bigquery_benchmark.rb
Last active September 9, 2019 07:30
Extract data from JSON using keys in the first level
require 'csv'
require 'faker'
require 'google/cloud/bigquery'
PROJECT_ID = ENV['PROJECT_ID']
DATASET_ID = ENV['DATASET_ID']
TABLE_ID = 'json_extract_benchmark'
bigquery = Google::Cloud::Bigquery.new(project_id: PROJECT_ID)
require 'test/unit/ui/console/testrunner'
class TestUnitProfiler
Record = Struct.new(:test_name, :test_class, :start_time, :self_time, :total_time, :children, keyword_init: true) do
def to_h
{
name: test_name,
class: test_class,
self: self_time,
total: total_time,
#!/bin/bash
set -eo pipefail
image_id=$1
if [ -z "$image_id" ]; then
echo "Usage: $(basename $0) IMAGE_ID"
exit 1
fi
@abicky
abicky / wc_hdfs
Created August 7, 2011 05:25
execute a command like wc to data on HDFS
#!/bin/bash
condition=""
fs="\t"
while getopts c:F: OPT; do
case $OPT in
c ) condition=$OPTARG;;
F ) fs=$OPTARG;;
esac
@abicky
abicky / id3conv.py
Created January 22, 2013 22:02
convert ID3 tags of MP3 files from Latin-1 to UTF-16
#!/usr/bin/env python
# -* - coding: utf-8 -*-
import argparse
import inspect
import eyed3
import eyed3.id3
def convertID3Encoding(audiofile, backup = False):
tag = audiofile.tag
if not tag:
# Copyright 2015- Takeshi Arabiki
# License: MIT License (http://opensource.org/licenses/MIT)
library(data.table)
access_logs <- (function() {
set.seed(0)
USER_COUNT <- 10000
PAGES <- c("page1", "page2", "page3")