Skip to content

Instantly share code, notes, and snippets.

View hyamamoto's full-sized avatar

Hiroshi Yamamoto hyamamoto

View GitHub Profile
@hyamamoto
hyamamoto / s3_to_netstorage.sh
Created June 3, 2016 02:32
Send file Amazon S3 bucket (aws sync) to Akamai NetStorage directory (secure rsync). Comment out 2 lines for --delete behavior.
#!/usr/bin/env bash
#
# Sync Amason S3 Bucket with Akamai NetStorage
#
# Dependency:
# "aws" command : AWS CLI
# "rsync" command :yeah, the one.
# .aws/credentials : AWS Credential file (for aws command)
# .ssj/netstorage.ppk : Private Key for your NetStorage account
@hyamamoto
hyamamoto / json2querystring.js
Created April 4, 2016 07:17
Snippet to convert a Json object to a query string for URL.
function json2querystring(json) {
return Object.keys(json).map(function(k) { return encodeURIComponent(k) + '=' + encodeURIComponent(json[k]) }).join('&');
}
var json = {param_1:'value1', param_2:'value2', param_3:3};
console.log(json2querystring(json));
@hyamamoto
hyamamoto / choochootrain.js
Created March 31, 2016 10:48
It gives a text of the choo choo train for your tweet. (Not really sure why I wrote it.)
DATA = {
ENGINES: ["🚂"],
CARS: ["🚃","🚋"],
SCENES: ['desert', 'forest', 'beach'],
ORBS: ["🌕","🌙","☀","☁"],
DESERT_TILES: ["🌵","🌵","🌴","🌴","🐪","🐢","🐎"],
FOREST_TILES: ["🌲","🌲","🌲","🌲","🐇","🌳","🌳"],
BEACH_TILES: ["🌴","🌴","🍍","🐢","🗿","🐚"],
SEA_TILES:["🐬","🐳","🐙"],
@hyamamoto
hyamamoto / jsonp.legacy.js
Created March 17, 2016 09:29
Legacy JSONP request maker. (Tested on > IE7, > Chrome21, > Firefox 17)
var $jsonp = (function () {
var that = {};
that.send = function (src, options) {
var options = options || {},
callback_name = options.callbackName || 'callback',
on_success = options.onSuccess || function () {
},
on_timeout = options.onTimeout || function () {
},
timeout = options.timeout || 10;
@hyamamoto
hyamamoto / calculating_floats.py
Last active September 19, 2016 10:27
Calculating float values in Python with builtins.
#!/usr/bin/env python
def p(t, v):
print('{:<40}-> {}'.format(t, v))
p('.1 + .1 + .1', .1 + .1 + .1)
p('round(.1 + .1 + .1, 10)', round(.1 + .1 + .1, 10))
p('(0.1).as_integer_ratio()', (0.1).as_integer_ratio())
@hyamamoto
hyamamoto / basic_op.sas
Created October 30, 2015 12:08
Self-study note: Playing with SAS.
d = {
0 1 0 0,
2 1 0 0,
0 1 0 4
};
e = d`;
e2 = t(d);
@hyamamoto
hyamamoto / multinomial1.m
Created October 16, 2015 12:04
Self-study note: Multivariate Analysis with Mathmatica. (Multinomial distribution)
n = 10;
p1 = 0.3;
p2 = 0.4;
ListPointPlot3D[
Table[
(
Factorial[n] /(Factorial[y1]*Factorial[y2]*Factorial[n - y1 - y2])
) * p1^y1* p2^y2* (1 - p1 - p2)^(n - y1 - y2),
{y1, 0, n},
{y2, 0, n}
@hyamamoto
hyamamoto / what-forces-layout.md
Last active September 20, 2015 02:06 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@hyamamoto
hyamamoto / ab_hammer.sh
Last active September 9, 2015 00:47
A little dirty HTTP benchmark script that was on my ancient disk. ab_hammer.sh uses ab (Apache Benchmark) to hammer the ${target_url} ${attempt} times with (${scale} * 10) concurrency requests, then spits the benchmark result to "${title}-X.csv" and "${title}.csv" .
#!/bin/bash
# A little dirty HTTP benchmark script
#
# ab_hammer.sh uses ab (Apache Benchmark) to hammer the ${target_url} ${attempt} times
# with (${scale} * 10) concurrency requests, then spits the benchmark result to
# "${title}-X.csv" and "${title}.csv" .
title=hammer
target_url="http://www.yourtarget_here.com/"
@hyamamoto
hyamamoto / pyenv-installer.sh
Created September 4, 2015 11:44
This script installs `pyenv` to your home directory. (you can set PYENV_ROOT to change the directory, tho.)
#!/usr/bin/env bash
if [ ! $(which git) ]; then
echo "Git is not installed, can't continue."
exit 1
fi
if [ -z "${PYENV_ROOT}" ]; then
PYENV_ROOT="$HOME/.pyenv"
fi