Skip to content

Instantly share code, notes, and snippets.

View ryanhanwu's full-sized avatar
🎯
Focusing

Ryan Wu ryanhanwu

🎯
Focusing
View GitHub Profile
//npm install b64url
//A signed_request for testing:
//WGvK-mUKB_Utg0l8gSPvf6smzacp46977pTtcRx0puE.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEyOTI4MjEyMDAsImlzc3VlZF9hdCI6MTI5MjgxNDgyMCwib2F1dGhfdG9rZW4iOiIxNTI1NDk2ODQ3NzczMDJ8Mi5ZV2NxV2k2T0k0U0h4Y2JwTWJRaDdBX18uMzYwMC4xMjkyODIxMjAwLTcyMTU5OTQ3NnxQaDRmb2t6S1IyamozQWlxVldqNXp2cTBmeFEiLCJ1c2VyIjp7ImxvY2FsZSI6ImVuX0dCIiwiY291bnRyeSI6ImF1In0sInVzZXJfaWQiOiI3MjE1OTk0NzYifQ
function parse_signed_request(signed_request, secret) {
encoded_data = signed_request.split('.',2);
// decode the data
sig = encoded_data[0];
json = base64url.decode(encoded_data[1]);
data = JSON.parse(json); // ERROR Occurs Here!
/**
* Module dependencies
*/
var express = require('express');
var fs = require('fs');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// img path
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
}
});
/**
* $.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) ) {
# 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
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;
@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>
@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 / 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 / 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 = '';