Skip to content

Instantly share code, notes, and snippets.

@hongru
hongru / mkdir_p.js
Created May 28, 2012 07:49
mkdir -p for node
/* mkdir -p for node */
var fs = require('fs'),
path = require('path');
function mkdirpSync (pathes, mode) {
mode = mode || 0777;
var dirs = pathes.trim().split('/');
if (dirs[0] == '.') {
// ./aaa
dirs.shift();
@hongru
hongru / gist:2880416
Created June 6, 2012 07:24
base64Encode
function base64Encode(inputStr) {
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var outputStr = "";
var i = 0;
while (i < inputStr.length)
{
//all three "& 0xff" added below are there to fix a known bug
//with bytes returned by xhr.responseText
var byte1 = inputStr.charCodeAt(i++) & 0xff;
@hongru
hongru / imgRotate
Created August 12, 2012 08:38
imgRotate - canvas & DXTransform Matrix filter
var canvas = false;
var context = false;
var isCanvas = (document.createElement("canvas").getContext) ? true : false;
createCanvas = function(o) {
if (isCanvas) {
canvas = document.createElement("canvas");
canvas.style.position = "absolute";
canvas.style.width = nw + "px";
canvas.style.height = nh + "px";
@hongru
hongru / jstemplate.js
Created August 31, 2012 09:22
a light js template engine
/*!
* jstemplate: a light & fast js tamplate engine
* License MIT (c) 岑安
*/
;(function (name, definition) {
if (typeof define == 'function') define(definition);
else if (typeof module != 'undefined') module.exports = definition();
else this[name] = definition();
})('jstemplate', function () {
@hongru
hongru / Json Format
Created December 19, 2012 08:52
Json Format in document
//background js
console.log('JSON Page Format started!')
;(function () {
var txt = document.body.innerText.trim(),
easyReg = /^{.+}$|^(\w+)\(({.+})\)$/;
var gIndentStyle='&nbsp;&nbsp;&nbsp;&nbsp;';
var arr = txt.match(easyReg), jsonTxt;
if (!arr) return;
@hongru
hongru / spmbatch.js
Last active December 10, 2015 22:18
batch spm build|upload
#!/usr/bin/env node
// -*- js -*-
/**
* @example
* spmbat ./
*/
var fs = require('fs'),
util = require('util'),
path = require('path'),
@hongru
hongru / About Python&Django.md
Last active December 11, 2015 21:28
About Python&Django

Python27 install info for Windows

  • http://www.python.org/getit/releases/2.7.3/ 找到MSI installer 下载,建议用2.7的版本
  • 安装python后添加环境变量 PATH: ;C:\Python27
  • 安装python package包管理工具和常用package
  • 用pip安装各种需要的package,比如 pip install distribute ...
  • 安装 Django, pip install django
  • 安装 pil, pip install pil ,pil好像下载极其艰难 -_-#
function connect(scope, fnFrom, fnTo) {
"use strict"
var objFn = fnFrom.split('.');//处理传入的函数名
var deepth = objFn.length;
var scope = scope || window;
var j = deepth,i=j;
var _obj = scope,__obj=_obj ;
while (i > 0) {//以window.console.log为例,这里利用迭代最终拿到log
_obj = _obj[objFn[deepth - i]];
i -= 1;
@hongru
hongru / ejs2jst.js
Last active December 18, 2015 06:59
ejs2jst
// tasks
// ejs: {
// 'script/view.jst.js': 'view/**/*.ejs'
// },
grunt.registerMultiTask('ejs', 'Compile EJS templates into JST.', function() {
var options = {
client: true,
open: "<%",
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta content="yes" name="apple-mobile-web-app-capable">
<title>iOS Web App</title>
<!-- iPhone -->