Skip to content

Instantly share code, notes, and snippets.

View dominhhai's full-sized avatar
🏠
Working from home

Do Minh Hai dominhhai

🏠
Working from home
View GitHub Profile
@dominhhai
dominhhai / stop.js
Created January 31, 2016 02:42
Stop Nodejs server with cli. Finding server log by `log.endsWith('./bin/www')`.
const exec = require('child_process').exec
const SPACE = ' '
exec('ps aux | grep node', (err, stdout, stderr) => {
if (err !== null) {
return console.log(`exec error: ${err}`)
}
var data = stdout.toString().split('\n')
data.forEach((log) => {
if (log.endsWith('./bin/www')) {
@dominhhai
dominhhai / index.html
Created March 24, 2016 09:45
Bar/ Column combo Stacked Bar/Column Chart
<!DOCTYPE html>
<html>
<head>
<script src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1.0','packages':['corechart']}]}"></script>
<script>
var visual
google.setOnLoadCallback(function () {
visual = google.visualization
drawChart()
})
@dominhhai
dominhhai / n.sh
Created April 23, 2016 00:32
Update node & npm bash
#! /bin/bash
# node update
echo 'update node.js...'
echo 'current node version:'
node -v
echo 'clean npm cache...'
sudo npm cache clean -f
echo 'update n...'
sudo npm install -g n
@dominhhai
dominhhai / formatNumber.js
Last active May 27, 2016 08:10
Format integer number
function format (n) {
var str = n.toString()
for (var i = str.length - 3; i > 0; i -= 3) {
str = str.substring(0, i) + ',' + str.substring(i)
}
return str
}
var arr = [10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000]
arr.forEach(function (n) {
@dominhhai
dominhhai / 1-react-native-simulator-and-device.md
Created July 25, 2016 02:01 — forked from almost/1-react-native-simulator-and-device.md
Test React Native on the simulator and on a device without editing the code each time!

In the default React Native app scaffolding you have to edit AppDelegate.m to change where it loads the code if you want to test on your device. I use the following snippet to detect if it's being compiled for Debug or Production and for the Simulator or a device. For Production it uses a copy of the code included in the bundle, for Debug on the simualtor it loads from a server on localhost and for Debug on a device it loads from a server on a given IP address.

NOTE: You need to edit YOUR-IP-HERE and change it to the IP to load the code from when in Debug mode on a device. You could use a service like ngrok to make this work from anywhere.

  NSURL *jsCodeLocation;

  // Loading JavaScript code
  #if DEBUG
    // For Debug build load from development server. Start the server from the repository root:
@dominhhai
dominhhai / tor-install.txt
Last active September 7, 2021 09:04
MacOSでTorの簡単なインストール方法 ref: https://dominhhai.github.io/vi/2017/01/tor-on-mac/
# Brewの場合
$ brew install tor
# Macportsの場合
$ sudo port install tor
@dominhhai
dominhhai / letsencrypt.md
Last active February 14, 2017 02:07
Nginx vs Let's Encrypt

Check Python v2.7.x

$ python --version

Check open 443 port

$ sudo cat /etc/sysconfig/iptables

Get certbot from Github

@dominhhai
dominhhai / octave.md
Created June 24, 2017 11:37 — forked from obstschale/octave.md
An Octave introduction cheat sheet.

Octave CheatSheet

GNU Octave is a high-level interpreted language, primarily intended for numerical computations.
(via GNU Octave)

Basics

  • not equal ~=
  • logical AND &amp;&amp;
@dominhhai
dominhhai / gcolab-drive.py
Created September 27, 2018 01:44
Google Colab Code
# Connect with Google Drive
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import drive
drive.mount('/content/drive')