Skip to content

Instantly share code, notes, and snippets.

View tranphuoctien's full-sized avatar
🎯
Focusing

Tien Tran tranphuoctien

🎯
Focusing
View GitHub Profile
@tranphuoctien
tranphuoctien / require-service.htm
Last active September 14, 2015 10:49 — forked from bennadel/require-service.htm
Creating A RequireJS Service For AngularJS Applications
<!doctype html>
<html ng-app="Demo">
<head>
<meta charset="utf-8" />
<title>
Creating A RequireJS Service For AngularJS
</title>
<style type="text/css">
@tranphuoctien
tranphuoctien / Linux Static IP
Created October 22, 2015 08:09 — forked from fernandoaleman/Linux Static IP
How To Configure Static IP On CentOS 6
## Configure eth0
#
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
HWADDR=A4:BA:DB:37:F1:04
TYPE=Ethernet
BOOTPROTO=static
@tranphuoctien
tranphuoctien / utf8-regex.js
Created November 3, 2015 06:42 — forked from chrisveness/utf8-regex.js
Utf8 string encode/decode using regular expressions
/**
* Encodes multi-byte Unicode string into utf-8 multiple single-byte characters
* (BMP / basic multilingual plane only).
*
* Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 - U+FFFF in 3 chars.
*
* Can be achieved in JavaScript by unescape(encodeURIComponent(str)),
* but this approach may be useful in other languages.
*
* @param {string} strUni Unicode string to be encoded as UTF-8.
@tranphuoctien
tranphuoctien / haproxy.cfg
Created November 27, 2015 08:35 — forked from roylines/haproxy.cfg
haproxy configuration for using with prerender.io
# Change YOUR_TOKEN to your prerender token
# Change http://example.com (server_name) to your website url
frontend my-frontend
mode http
bind :80
# prerender.io
acl user-agent-bot hdr_sub(User-Agent) -i baiduspider twitterbot facebookexternalhit rogerbot linkedinbot embedly showyoubot outbrain pinterest slackbot vkShare W3C_Validator
acl url-asset path_end js css xml less png jpg jpeg gif pdf doc txt ico rss zip mp3 rar exe wmv doc avi ppt mpg mpeg tif wav mov psd ai xls mp4 m4a swf dat dmg iso flv m4v torrent ttf woff
@tranphuoctien
tranphuoctien / using-raw-socket-io-in-sails.js
Created December 8, 2015 04:22 — forked from mikermcneil/using-raw-socket-io-in-sails.js
Using raw socket.io functionality in a Sails.js controller
module.exports = {
/**
*
* Using raw socket.io functionality from a Sails.js controller
*
*/
index: function (req,res) {
@tranphuoctien
tranphuoctien / NodeJscallbackPromise.js
Created March 21, 2016 10:08
If you're building your own NodeJS library and you like using Promises, chances are you'll want to implement your module API through promises.
// dual-module.js
var Q = require('q');
module.exports = {
getFullName: function (firstName, lastName, callback) {
var deferred = Q.defer();
if (firstName && lastName) {
var fullName = firstName + " " + lastName;
deferred.resolve(fullName);
// Pattern
//Usually, you call a callback as the last thing you do inside a function.
//You might consider it synonymous with return, only JavaScript does
//not halt function execution when it hits it. It can be easy to accidentally
//let execution continue after calling a callback, when you really expected it to end.
//In order to make this easy to spot, and make sure execution stops in the way you expect,
//I recommend returning the callback function call.
// wrong!
@tranphuoctien
tranphuoctien / exampleWaterfall.js
Created March 21, 2016 11:45
NodeJS Async WaterFall Example Raw
var async = require('async');
async.waterfall(
[
function(callback) {
callback(null, 'Yes', 'it');
},
function(arg1, arg2, callback) {
var caption = arg1 +' and '+ arg2;
callback(null, caption);
@tranphuoctien
tranphuoctien / wget.js
Created March 21, 2016 11:55 — forked from JacobHsu/wget.js
Downloading using wget #nodejs
//note: http://www.html-js.com/article/1961
// Function to download file using wget
var download_file_wget = function(file_url) {
// extract the file name
var file_name = url.parse(file_url).pathname.split('/').pop();
// compose the wget command
var wget = 'wget -P ' + DOWNLOAD_DIR + ' ' + file_url;
// excute wget using child_process' exec function
@tranphuoctien
tranphuoctien / FileController.js
Created March 28, 2016 06:55 — forked from tkh44/FileController.js
Simple file upload for sails.js
module.exports = {
get: function (req, res) {
res.sendfile(req.path.substr(1));
},
_config: {
rest: false,
shortcuts: false
}
};