Skip to content

Instantly share code, notes, and snippets.

View tianp's full-sized avatar

Tian Permana tianp

  • Jakarta, Indonesia
View GitHub Profile
@tianp
tianp / mongodbservice
Last active August 29, 2015 14:05
Start/Stop Homebrew installed MongoDB service on Mac OSX
// Start MongoDB service
launchctl start org.mongodb.mongod
// Stop MongoDB service
launchctl stop org.mongodb.mongod
// Make alias, for easier future
alias mongostart="launchctl start org.mongodb.mongod"
alias mongostop="launchctl stop org.mongodb.mongod"
@tianp
tianp / execute.js
Last active August 29, 2015 14:05
Execute Unix command using Node.js
// Minimal code to execute unix command using Node.js
// require the native `exec` module
var exec = require('child_process').exec
// run the exec command
exec("mkdir Musics");
scp -i /path/to/key.pem <username>@<server ip address>:/path/to/file /path/to/file.txt
@tianp
tianp / gist:90491f7792df1f9d4e58
Created January 16, 2015 09:22
Export MongoDB to CSV
mongoexport --host dbhost --port 27017 --collection coll --csv --fields field1,field2 --out filename.csv --db dbname --query '{}'
@tianp
tianp / Git Chekout Latest Tag
Created February 4, 2015 07:49
Git Chekout Latest Tag
# Get new tags from the remote
$ git fetch --tags
# Get the latest tag name
$ latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
# Checkout the latest tag
$ git checkout $latestTag
@tianp
tianp / server.js
Created February 27, 2015 09:21
Node Restify uncaughtException handler
// Extracted from https://gentlenode.com/journal/node-3-restify-cheatsheet/44
server.on( 'uncaughtException', function ( request, response, route, error ) {
// Emitted when some handler throws an uncaughtException somewhere in the chain.
// The default behavior is to just call res.send(error), and let the built-ins in restify handle transforming,
// but you can override to whatever you want here.
if ( process.env.NODE_ENV == 'production' ) {
var responseMessage = {
@tianp
tianp / today_interval.js
Created May 5, 2015 06:59
Moment.js Get Today (24 hours) Timeframe Interval
var moment = require('moment')
// get this midnight and next moment object and convert into unix timestamp
// this midnight (1 minute after last midnight)
var thisMidnight = moment( moment().format('YYYY-MM-DD') + ' 00:01:00' ).unix()
// next midnight (1 minute before next midnight)
var nextMidnight = moment( moment().format('YYYY-MM-DD') + ' 23:59:00' ).unix()