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 / 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"}))
}

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 / 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 / test-delay.js
Created June 25, 2015 20:00
Q delay behavior
var Q = require('q');
function test() {
var d = Q.defer();
setTimeout(function() {
d.reject(new Error('failed'));
}, 500);
return d.promise;
@ghiden
ghiden / delay-test.js
Created June 25, 2015 19:56
Bluebird delay behaviors
var Promise = require('bluebird');
function test1() {
return new Promise(function(resolve) {
setTimeout(function() {
console.log('resolve');
resolve(100);
}, 500);
});
}
#!/usr/bin/env ruby
if ARGV.length != 3
puts 'Need 3 arguments'
puts ' calculate-email-distribution INITIAL_SIZE STEP AMOUNT'
puts 'e.g.'
puts ' calculate-email-distribution 100 20 65000'
exit 0
end
@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 / Venn.js-Experiment.markdown
Created August 11, 2014 09:38
A Pen by ghiden.