Skip to content

Instantly share code, notes, and snippets.

View hanksudo's full-sized avatar
:octocat:
Follow your passion.

Hank Wang hanksudo

:octocat:
Follow your passion.
View GitHub Profile
@hanksudo
hanksudo / useful_sed.sh
Created June 4, 2013 18:33
Useful one-line scripts for sed
-------------------------------------------------------------------------
USEFUL ONE-LINE SCRIPTS FOR SED (Unix stream editor) Dec. 29, 2005
Compiled by Eric Pement - pemente[at]northpark[dot]edu version 5.5
Latest version of this file (in English) is usually at:
http://sed.sourceforge.net/sed1line.txt
http://www.pement.org/sed/sed1line.txt
This file will also available in other languages:
Chinese - http://sed.sourceforge.net/sed1line_zh-CN.html
@hanksudo
hanksudo / download_all_gists.sh
Created September 15, 2022 02:55
Download all public gists with gh command line
#!/bin/sh
gh api gists | jq -r '.[] | select(.public == true) | .files[].raw_url' | while read -r row ; do
curl -sO "$row"
done
@hanksudo
hanksudo / GetTweetId.py
Created May 19, 2011 08:52
Regex : Get Tweet Id by tweet
import re
s = 'https://twitter.com/#!/twitter/status/70943739882913792'
print re.search('/status/(\d+)', s).group(1)
@hanksudo
hanksudo / promise.race.js
Last active December 6, 2021 02:57
nodejs promise race
let promiseA = new Promise((resolve) => {
const timeout = 100 + Math.floor(Math.random() * 1900)
setTimeout(() => resolve('A'), timeout);
console.log('A timeout', timeout)
})
let promiseB = new Promise((resolve) => {
const timeout = 100 + Math.floor(Math.random() * 1900)
setTimeout(() => resolve('B'), timeout);
console.log('B timeout', timeout)
@hanksudo
hanksudo / stdev.js
Created July 18, 2013 10:02
Standard deviation(STDEV) with JavaScript
var stdev = function(arr) {
var n = arr.length;
var sum = 0;
arr.map(function(data) {
sum+=data;
});
var mean = sum / n;
@hanksudo
hanksudo / combineAndKeepOrder.go
Created August 18, 2021 13:26
(go) combine two array and keep order
package main
import "log"
func main() {
result := combineAndKeepOrder([]string{"a", "b", "c"}, []string{"c", "a", "d"})
log.Println(result, testEq(result, []string{"c", "b", "a", "d"}))
result = combineAndKeepOrder([]string{}, []string{"c", "a", "d"})
log.Println(result, testEq(result, []string{"c", "a", "d"}))
@hanksudo
hanksudo / remove-storyboard.md
Last active December 8, 2020 03:23
Initial iOS project without Storyboard (remove storyboard)
  1. Remove Main.storyboard file
  2. Remove Main interface in Deployment Info

Screen Shot 2020-12-08 at 12 11 07

  1. Remove UISceneStoryboardFile key in Info.plist
UISceneStoryboardFile
@hanksudo
hanksudo / loopback.md
Created November 4, 2020 13:28
Add/remove loopback alias IPs on macOS
# add 
sudo ifconfig lo0 alias 127.0.0.2

# revert
sudo ifconfig lo0 -alias 127.0.0.2
@hanksudo
hanksudo / aws-cli-note.md
Last active January 12, 2020 15:15
AWS CLI note

AWS CLI Note

aws-cli - examples

STS - AWS Security Token Service

# whoami
aws sts get-caller-identity