Skip to content

Instantly share code, notes, and snippets.

View chnbohwr's full-sized avatar
🐳
Enjoy development fun 享受開發樂趣

HsuChing(Hyman) chnbohwr

🐳
Enjoy development fun 享受開發樂趣
View GitHub Profile
@chnbohwr
chnbohwr / gist:959a2aacd9adf746ba66
Last active September 3, 2015 09:39
nodejs send gmail message
var fs = require('fs');
var readline = require('readline');
var google = require('googleapis');
var googleAuth = require('google-auth-library');
var SCOPES = ['https://mail.google.com/'];
var TOKEN_PATH = 'gmail-api-token.json';
// Load client secrets from a local file.
@chnbohwr
chnbohwr / gist:a482c6cea28b16e5b20c
Last active September 18, 2015 07:35
react render user list
function initialUserData(){
$.ajax({
url: 'https://randomuser.me/api/?results=10',
dataType: 'json',
success: function(data){
console.log('get ajax data success',data);
window.data = data.results;
initialReact();
}
});
/**
* game url : http://zzzscore.com/1to50/en/
* paste code in console , and happy to hack
*/
var Hacker = function () {
var self = this;
self.now_click_number = 1;
function getNextBox() {
if (self.now_click_number > 50) {
@chnbohwr
chnbohwr / gist:1c7388c4a9da41a9f481
Created October 6, 2015 13:38
express middleware
var express = require('express');
var app = express();
function showMessage(req,res){
console.log("server has send message");
res.send('Hello World!');
}
function checkSession(req,res,next){
@chnbohwr
chnbohwr / arduino note
Created November 14, 2015 04:40
IRremote & Ds3231 & crystal_I2c
#include <IRremote.h>
#include <Wire.h>
#include <Sodaq_DS3231.h>
#include <LiquidCrystal_I2C.h>
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
@chnbohwr
chnbohwr / react unit test rerender
Created December 17, 2015 02:37
react unit test component rerender
var output = TestUtils.renderIntoDocument(<Test value="123" />);
// rerender by React.render
React.render(<Test value="456" />, React.findDOMNode(output).parentNode);
@chnbohwr
chnbohwr / install-nodejs.sh
Last active December 29, 2015 08:34
install node and npm in ubuntu without sudo command
sudo apt-get update
sudo apt-get install g++ -y
sudo apt-get install build-essential -y
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
@chnbohwr
chnbohwr / download form data
Created January 8, 2016 02:42
XMLHttpRequest post form data and download file from response.
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
if (this.status === 200) {
var filename = "";
var disposition = xhr.getResponseHeader('Content-Disposition');
if (disposition && disposition.indexOf('attachment') !== -1) {
var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
var matches = filenameRegex.exec(disposition);
@chnbohwr
chnbohwr / clean_docker.sh
Created January 14, 2016 05:49
clean docker containers and volumes
echo 'kill all running container'
docker kill $(docker ps -q)
echo 'remove all container'
docker rm -v $(docker ps -a -q)
echo 'remove all volumes'
docker volume rm $(docker volume ls -q)
echo 'Delete all untagged/dangling (<none>) images'
docker rmi $(docker images -q -f dangling=true)
@chnbohwr
chnbohwr / gist:6d9dae6650d297620372eda01ea502b4
Created May 27, 2016 02:10 — forked from chad3814/gist:2924672
deleting array items in javascript with forEach() and splice()
// This is from my comment here: http://wolfram.kriesing.de/blog/index.php/2008/javascript-remove-element-from-array/comment-page-2#comment-466561
/*
* How to delete items from an Array in JavaScript, an exhaustive guide
*/
// DON'T use the delete operator, it leaves a hole in the array:
var arr = [4, 5, 6];
delete arr[1]; // arr now: [4, undefined, 6]