Skip to content

Instantly share code, notes, and snippets.

@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 / 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();