Skip to content

Instantly share code, notes, and snippets.

View rudyhuynh's full-sized avatar

Rudy Huynh rudyhuynh

  • VN
View GitHub Profile
<form>
<label>Some label</label>
<input type="number"/>
<label>Some other label</label>
<textarea />
<MyCustomInput {...someProps} />
</form>
@rudyhuynh
rudyhuynh / multiple_ssh_setting.md
Last active October 19, 2020 03:02 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different git account

This instruction helps create multiple ssh keys for local machine to use multiple git remote repositories.

Step 1: Create different ssh keys

$ ssh-keygen -t rsa -C "your_email1@youremail.com"
$ ssh-keygen -t rsa -C "your_email2@youremail.com"
@rudyhuynh
rudyhuynh / polyline_decoder.js
Created April 3, 2017 06:26 — forked from ismaels/polyline_decoder.js
Javascript function to decode google maps api polyline
// source: http://doublespringlabs.blogspot.com.br/2012/11/decoding-polylines-from-google-maps.html
function decode(encoded){
// array that holds the points
var points=[ ]
var index = 0, len = encoded.length;
var lat = 0, lng = 0;
while (index < len) {
var b, shift = 0, result = 0;

From this answer: https://stackoverflow.com/a/17141512/6307412

git checkout my-branch
git branch -m my-branch-old # this will rename 'my-branch' to 'my-branch-old'
git checkout master
git checkout -b my-branch
git merge --squash my-branch-old
git commit -m "...your message..."
git push origin my-branch --force # add --force to rewrite history on remote if neccessary
import flowRight from 'lodash.flowright'
import {onErrorRetryHOF} from './onErrorRetryHOF'
import {bypassCacheHOF} from './bypassCacheHOF'
export const myAppFetch = flowRight([
onErrorRetryHOF,
bypassCacheHOF,
// more higher-order fetch here
])(fetch) // <--- the original fetch
@rudyhuynh
rudyhuynh / bypassCacheHOF.js
Last active May 19, 2018 04:28
A higher-order fetch that bypass cache
// A higher-order fetch that bypass cache:
export const bypassCacheHOF = (fetch) => (input, init) => {
let bypassCacheUrl
if (input.includes('?') {
bypassCacheUrl = input + '&_v=' + Math.random()
} else {
bypassCacheUrl = input + '?_v=' + Math.random()
}
return fetch(bypassCacheUrl, init)
@rudyhuynh
rudyhuynh / onErrorRetryHOF.js
Last active February 1, 2018 03:33
A higher-order fetch that retry on error
import Rx from "rxjs";
const MAX_RETRY = 3
const RETRY_DELAY = 500
export const onErrorRetryHOF = fetch => (input, init) => {
let count = 0;
return Rx.Observable.defer(() =>
Rx.Observable.fromPromise(
fetch(input, init).then(resp => {
if ((resp.status + "").startsWith("5")) throw resp;
@rudyhuynh
rudyhuynh / bypassCacheFetch-v1.js
Last active May 19, 2018 14:21
First abroach
// this function accepts the same input and returns the same output as window.fetch(),
// plus, it adds a ramdom param into the URL to bypass cache.
const bypassCacheFetch = (input, init) => {
let bypassCacheUrl
if (input.includes('?') {
bypassCacheUrl = input + '&_v=' + Math.random()
} else {
bypassCacheUrl = input + '?_v=' + Math.random()
}

Instruction to send a git commit to other machine when git server is down

Assume you are at a branch, which has 1 commit ahead of master. You want to send that commit to your friend's machine while the git server is down. Solution:

  1. At your machine, run git format-patch master --> 0001-mybranch.patch generated.
  2. Send 0001-mybranch.patch to your friend, at your friend's machine run git apply 0001-mybranch.patch
import React from "react";
/**
* Use just as the same as React.useReducer, but state and action are logged to the console.
* Example usage:
* ```
* const [state, dispatch] = useDebugReducer('MyComponent', reducer, initialState)
* // Console:
* // MyComponent dispatch: {...}
* // \t MyComponent state: {...}