Skip to content

Instantly share code, notes, and snippets.

@hiroaki
hiroaki / jquery-promise-problem.html
Created December 19, 2016 16:51
Promise - Error handling
<html><head><title>Promise - Error handling</title>
<script>
(function() {
var timeout, prepare, jquery_src;
prepare = function() {
jquery_src = {
'2': 'https://code.jquery.com/jquery-2.2.4.min.js',
'3': 'https://code.jquery.com/jquery-3.1.1.min.js'
}[location.search.substr(1, 1)];
@hiroaki
hiroaki / untitled.html
Last active December 18, 2016 05:31
invoke callbacks that contain async confirmation
<html><head><title>Promise</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script>
$(function() {
$('#start').show();
$('#prepare').hide();
$('#dialog').hide();
$('#contents').hide();
$('#goal').hide();
@hiroaki
hiroaki / install-ffmpeg-centos5.sh
Created April 20, 2016 16:31
Install ffmpeg on CentOS 5 automatically
#!/bin/sh
set -eu
# @(#)Install ffmpeg on CentOS 5
#
# Before execute this script, you have to install dependent packages:
# (There may be excess or deficiency)
#
# yum install zlib-devel bzip2 bzip2-devel sqlite sqlite-devel \
@hiroaki
hiroaki / install-ruby-2.3.0.sh
Last active March 18, 2016 18:23
Install ruby-2.3.0 on OS X (El Capitan)
#!/bin/sh
set -eu
WORKDIR=/path/to/build_dir
PREFIX=/path/to/install_dir
backdir=`pwd`
mkdir -p $WORKDIR
cd $WORKDIR
@hiroaki
hiroaki / zweitegps-json2gpx.rb
Created August 22, 2015 07:22
convert the data format of ZweiteGPS
#!/usr/bin/env ruby
# NOTE: currently, convert "trk" only. this does not consider "wpt" and "rte" yet.
require 'json'
require 'rexml/document'
require 'time'
json_file = ARGV[0]
@hiroaki
hiroaki / publish-dir.pl
Last active August 29, 2015 14:25
Publish directory via HTTP using plack
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Std;
my $opts = {
s => 'Standalone',
h => '0.0.0.0',
p => 5000,
@hiroaki
hiroaki / checksum-sha1.sh
Created July 18, 2015 16:50
Check SHA-1 digest
#!/bin/sh
exec -- openssl dgst -sha1 $1
@hiroaki
hiroaki / new_gist_file.rb
Created December 29, 2014 07:25
Get empty port
require 'socket'
class Util
def self.empty_port
s = TCPServer.open(0)
port = s.addr[1]
s.close
port
end
end
@hiroaki
hiroaki / install-shared-mime-info.sh
Created December 27, 2014 11:47
This script installs "shared-mime-info" on OS X Yosemite.
#!/bin/sh
# This script installs "shared-mime-info" to OS X Yosemite.
#
# Usage:
#
# $ sh this-script.sh [install-prefix]
#
# There is no need for you to modify the following.
@hiroaki
hiroaki / gist:ad55b38be8701f25eb93
Last active October 28, 2015 02:42
Real-time monitor (Server-Sent Events)
#!/usr/bin/env ruby
require 'sinatra/base'
SECONDS_INTERVAL = 1.0
URL_STREAM = '/stream'
NAME_EVENT = 'ldavg'
NUMBER_MAX_PLOT = 180
SEPARATOR_OF_DATA = ' '