Skip to content

Instantly share code, notes, and snippets.

View ryanhanwu's full-sized avatar
🎯
Focusing

Ryan Wu ryanhanwu

🎯
Focusing
View GitHub Profile
@ryanhanwu
ryanhanwu / __stack.js
Created April 20, 2012 06:40 — forked from bmeck/__stack.js
stack trace api fun for the masses.
var stack_holder = new Error
function stackPrepare(e,stacks) {
var stack = stacks
for(var p in stack[0]) {
stack[p] = stack[0][p]
}
stack.find = function(fn) {
console.log(stack)
for(var i=0;i<stack.length;i++) {
if(stack[i].getFunction() === fn) {
@ryanhanwu
ryanhanwu / wget.js
Created August 6, 2012 02:28 — forked from xonecas/wget
simple wget for node.js
require('http');
function wget(host, path, https, callback) {
var port = (https) ? 443 : 80,
client = http.createClient(port, host, https),
request = client.request('get', path, {
'host': host
}),
response_body = '';
@ryanhanwu
ryanhanwu / snippet.js
Created September 12, 2012 11:48 — forked from christopherdebeer/snippet.js
Node.js Express - Mobile detection
app.get('/', function(req, res){
var ua = req.header('user-agent');
if(/mobile/i.test(ua)) {
res.render('mobile.html');
} else {
res.render('desktop.html');
}
});
@ryanhanwu
ryanhanwu / .gitignore
Created October 2, 2012 07:24
sina weibo OAuth with node-oauth for node.js+express
node_modules
config.js
@ryanhanwu
ryanhanwu / Javascript-base.sublime-snippet
Created November 21, 2012 03:58 — forked from LeZuse/Javascript-base.sublime-snippet
Sublime Javascript snippets
<snippet>
<content><![CDATA[base(this, '${1:method}'${2});${0}]]></content>
<tabTrigger>base</tabTrigger>
<scope>source.js</scope>
<description>Base method call</description>
</snippet>
http {
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
proxy_temp_path /var/tmp;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_comp_level 6;
# alias
alias ls='ls -la --col'
# JST time
sudo cp /usr/share/zoneinfo/Japan /etc/localtime
# package for build
sudo yum install -y git gcc-c++ openssl-devel make
# install nodebrew
wget https://raw.github.com/hokaccha/nodebrew/master/nodebrew
perl nodebrew setup
echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> .bashrc
/**
* $.parseParams - parse query string paramaters into an object.
*/
(function($) {
var re = /([^&=]+)=?([^&]*)/g;
var decodeRE = /\+/g; // Regex for replacing addition symbol with a space
var decode = function (str) {return decodeURIComponent( str.replace(decodeRE, " ") );};
$.parseParams = function(query) {
var params = {}, e;
while ( e = re.exec(query) ) {
var http = require('http'),
httpProxy = require('http-proxy');
// Create an instance of node-http-proxy
var proxy = new httpProxy.HttpProxy({
target: {
host: 'localhost',
port: 9001
}
});
/**
* Module dependencies
*/
var express = require('express');
var fs = require('fs');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// img path