Skip to content

Instantly share code, notes, and snippets.


Sunny Chan sunnycmf

View GitHub Profile
sunnycmf / calc_file_checksum
Created Feb 18, 2014 — forked from guybrush/gist:721762
calculate a file sha1 checksum
View calc_file_checksum
#!/usr/bin/env node
require('fs').readFile('image.png',function(err, data){
View img2data.js
* Based on from
* Neither that gist nor this one work for me in 0.2.x or 0.3.x.
var request = require('request'),
BufferList = require('bufferlist').BufferList,
sys = require('sys'),
bl = new BufferList(),
url = ''
sunnycmf / node_image_resize_to_s3.js
Created Feb 17, 2014 — forked from simenbrekken/uploader.js
nodejs - image resize using magick to AWS S3
View node_image_resize_to_s3.js
var spawn = require('child_process').spawn,
aws2js = require('aws2js'),
http = require('http'),
urlutil = require('url')
mime = require('mime'),
Buffers = require('buffers');
var settings = {
s3: {
key: 'key',
zipstream = require "zipstream"
fs = require "fs"
async = require "async"
class StreamingResponse
filename: ""
files: []
streaming: true

High level style in javascript.

Opinions are like assholes, every one has got one.

This one is mine.

Punctuation: who cares?

Punctuation is a bikeshed. Put your semicolons, whitespace, and commas where you like them.

sunnycmf / escape.js
Last active Aug 29, 2015
trying to escape all chars from an input file
View escape.js
var fs = require('fs');
fs.readFile('testing.txt', {encoding:'utf8'}, function (err, data) {
if (err) throw err;
console.log('orig:\n' + data);
console.log('\n\n\nafter JSON.stringify:\n' + JSON.stringify(data));
console.log('\n\n\nafter JSON.stringify escapeSpecialChars() :\n' + JSON.stringify(data).escapeSpecialChars());
String.prototype.escapeSpecialChars = function() {
return this.replace(/\\n/g, "\\n").replace(/\\'/g, "\\'").replace(/\\"/g, '\\"').replace(/\\&/g, "\\&").replace(/\\r/g, "\\r").replace(/\\t/g, "\\t").replace(/\\b/g, "\\b").replace(/\\f/g, "\\f");
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl | sh
View index.js
// This module loads a config file in the current working directory matching the NODE_ENV variable.
// I.e. either './development.js' or './production.js' based on the process.env.NODE_ENV variable.
// If not set, it defaults to './development.js'.
// Can load custom environment files as well, as long as the NODE_ENV variable matches
// a file in the current directory. E.g. './staging.js'
// Usage: calling code can just require this module, e.g. "var config = require('./config')"
// assuming this file is named "index.js" and lives in a subdirectory named "config" of the app root.
var config
, config_file = './' + (process.env.NODE_ENV ? process.env.NODE_ENV : 'development') + '.js';
View passbook.rb
%w(pathname json openssl net/http digest/sha1 zip).each { |lib| require lib }
module Passbook
def self.wwdr_certificate <<-EOF.gsub /^\s+/, ""
You can’t perform that action at this time.