Skip to content

Instantly share code, notes, and snippets.

View hyamamoto's full-sized avatar

Hiroshi Yamamoto hyamamoto

View GitHub Profile
#
# Ledger Nano S
#
# USB connection fix for Ubuntu 18.04.5
# This script will create "/etc/udev/rules.d/20-hw1.rules" and restart udev.
#
# @reference https://support.ledger.com/hc/en-us/articles/115005165269-Fix-connection-issues
#
wget -q -O - https://raw.githubusercontent.com/LedgerHQ/udev-rules/master/add_udev_rules.sh | sudo bash
@hyamamoto
hyamamoto / Makefile.ask_passwd
Created August 1, 2018 00:03
asking a password in a makefile.
ask_password:
@$(eval PASSWORD=$(shell stty -echo; read -p "Password: " pwd; stty echo; echo $$pwd))
echo $(PASSWORD)
ask_password_twice:
while true; do \
read -s -p "Password: " password; \
echo; \
read -s -p "Password (again): " password2; \
@hyamamoto
hyamamoto / colNameToNum.js
Created September 21, 2017 07:26
Converts an Excel-style column name to a number. (JavaScript / Python)
//
// Convert an Excel-style column name to a number.
//
// Code: Hiroshi Yamamoto
function colNameToNum(name) {
var colNum = 0;
var pow = 1;
var i = name.length;
while(i--) {
@hyamamoto
hyamamoto / 0-vagrant-centos7-postgresql9.4.md
Last active September 5, 2017 11:35
Vagrant box: CentOS 7 + PostgreSQL9.4, The port 5432 of a guest os will be mapped to a host's 5432.

vagrant: centos7 + postgres9.4

Spin up the VM with

$vagrant up

then,

$psql -U postgres -W -h 127.0.0.1

@hyamamoto
hyamamoto / string.hashcode.js
Created September 30, 2016 07:19
JavaScript Implementation of String.hashCode() .
/**
* Returns a hash code for a string.
* (Compatible to Java's String.hashCode())
*
* The hash code for a string object is computed as
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
* using number arithmetic, where s[i] is the i th character
* of the given string, n is the length of the string,
* and ^ indicates exponentiation.
* (The hash value of the empty string is zero.)
@hyamamoto
hyamamoto / smooth-scroll.js
Created September 14, 2016 02:40
Enable smooth scroll jumping inside a web page to any given element, position or anchor(id). Written in plain JavaScript without jQuery. (tested on Chrome > 21, Firefox > 28, IE >= 8) https://jsfiddle.net/6xfd9dr8/
var scroll = {
iterr: 30, // miliseconds
tm: null,
reset_timer: function () { // reset
if (this.tm) {
clearTimeout(this.tm);
this.tm = null;
}
this.iterr = 30;
},
@hyamamoto
hyamamoto / mul_tbl.c
Last active August 1, 2016 09:23
Prints a complete multiplication-table in C language, which came out of nowhere under the strong sunlight in a summer day when all those Pokemon servers Go down.
#include <stdio.h>
#define N 9
main(k){for(k--;k<N*N;k++)printf("%2d%c",(k/N+1)*(k%N+1),(k+1)%N?32:10);}
@hyamamoto
hyamamoto / boot_every_60min.bat
Created July 29, 2016 01:46
A little Windows batch script that restarts THE THING every 60 min.
@echo off
:loop
evil_substance.exe
timeout /t 3600 >null
Taskkill /F /IM evil_substance.exe >null
goto loop
@hyamamoto
hyamamoto / ack_2_html.sh
Created July 13, 2016 08:27
A script to obtain HTML document from the `ack` search result. (just a proof of concept)
#!/bin/sh
##############################
# ack_2_html (script example)
##############################
# Description:
# Perform an ack search then create a colorized HTML document.
# Usage:
# ack_2_html.sh OUTPUTFILE_NAME PART_OF_FILEPATH PART_OF_TEXT
# Dependency:
@hyamamoto
hyamamoto / string.levenstein.js
Created June 22, 2016 08:14
The string.levenstein() function will get you an edit distance between 2 string values.
if (!String.prototype.levenstein) {
String.prototype.levenstein = (function(string) {
// source originated from https://gist.github.com/andrei-m/982927#gistcomment-1797205
var a = this, b = string + "", m = [], i, j, min = Math.min;
if (!(a && b)) return (b || a).length;
for (i = 0; i <= b.length; m[i] = [i++]);
for (j = 0; j <= a.length; m[0][j] = j++);