Skip to content

Instantly share code, notes, and snippets.

View ghiden's full-sized avatar

Hidenari Nozaki ghiden

View GitHub Profile
@ghiden
ghiden / job-completion-estimate.js
Last active October 30, 2023 19:49
estimate job completion time in JS
// To run: node job-completion-estimate
function sleep() {
return new Promise((resolve) => {
// add a random jitter of +-0.5 seconds
setTimeout(() => resolve(), 1000 - (Math.random() - 0.5) * 1000);
});
}
function humanReadableTime(duration) {
@ghiden
ghiden / config.toml
Last active August 17, 2023 07:59
Load TOML config and pick environment from a environmental variable in Go
[dev]
url = "http://dev.example.com"
username = "dev.account"
password = "devdev"
[test]
url = "http://test.example.com"
username = "test.account"
password = "testtest"
@ghiden
ghiden / nodejs_decode_sample.js
Created June 29, 2011 05:11
decode a base64 encoded image file with node.js
var fs = require('fs'),
decode64 = require('base64').decode;
var data = fs.readFileSync('./encode.png', 'base64');
var buffer = new Buffer(data, 'base64');
fs.writeFileSync('./decode.png', decode64(buffer), 'binary')
@ghiden
ghiden / scala_grouped_and_sliding
Created February 6, 2013 10:11
Scala grouped and sliding
scala> val a = (1 to 10).toList
a: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scala> for (x <- a.grouped(2)) println(x)
List(1, 2)
List(3, 4)
List(5, 6)
List(7, 8)
List(9, 10)
@ghiden
ghiden / bluebird-csv.js
Created June 15, 2015 09:07
To promisify csv-parse using Bluebird
"use strict";
var fs= require('fs');
var Promise = require('bluebird');
var parse= Promise.promisify(require('csv-parse'));
var file = fs.readFileSync('test.csv', 'utf8');
var headerKeys;
var options ={
trim: true,
@ghiden
ghiden / open-firefox-page-in-safari.lua
Created July 21, 2018 01:27
Because github pages cannot open a bookmarklet from firefox, I can't bookmark pages to pinboard. So I've created this Hammerspoon script to open a firefox page on safari.
getUrl = [[
tell application "System Events"
tell application "Firefox" to activate
delay .5
tell application "System Events"
keystroke "l" using command down
keystroke "c" using command down
end tell
delay .5
set u to the clipboard
@ghiden
ghiden / reflect.js
Last active February 9, 2017 21:34
A utility function to wait all promises to settle
/*
Promise.all(arr.map(reflect)).then(function(results){
var success = results.filter(x => x.status === "resolved");
});
*/
module.exports = function reflect(promise){
return promise.then(v => ({v:v, status: "resolved"}), e => ({e:e, status: "rejected"}))
}
@ghiden
ghiden / bargraph.css
Last active January 13, 2017 00:33
D3.js bar graph example
.chart {
background: #b0e0f8;
margin: 5px;
}
.chart rect {
stroke: white;
fill: steelblue;
}

Keybase proof

I hereby claim:

  • I am ghiden on github.
  • I am hidenari (https://keybase.io/hidenari) on keybase.
  • I have a public key whose fingerprint is 8A2E 98CD BB28 C287 B43E 8104 2C1A 5D84 CC80 8F5D

To claim this, I am signing this object:

@ghiden
ghiden / D3-Grouping-Elements:-Part-2.markdown
Created September 18, 2013 09:17
A Pen by Hidenari Nozaki.

D3 Grouping Elements: Part 2

This time, sort function is cleaner than the previous one. It doesn't need to update rect and text position, just the container g. And, by using 'transform', appending rect and text becomes easier.

A Pen by Hidenari Nozaki on CodePen.

License.