Skip to content

Instantly share code, notes, and snippets.

View sunnycmf's full-sized avatar
🎯
Focusing

Sunny Chan sunnycmf

🎯
Focusing
  • Carousell
  • Hong Kong
View GitHub Profile
@sunnycmf
sunnycmf / img2data.js
Created February 17, 2014 15:50 — forked from jfsiii/img2data.js
/*
* Based on https://gist.github.com/583836 from http://stackoverflow.com/questions/3709391/node-js-base64-encode-a-downloaded-image-for-use-in-data-uri.
* 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 = 'http://nodejs.org/logo.png'
;
@sunnycmf
sunnycmf / node_image_resize_to_s3.js
Created February 17, 2014 16:29 — forked from simenbrekken/uploader.js
nodejs - image resize using magick to AWS S3
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',
@sunnycmf
sunnycmf / calc_file_checksum
Created February 18, 2014 02:25 — forked from guybrush/gist:721762
calculate a file sha1 checksum
#!/usr/bin/env node
require('fs').readFile('image.png',function(err, data){
console.log(require('crypto').createHash('sha1').update(data).digest('hex'))
})
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
sunnycmf / escape.js
Last active August 29, 2015 13:56
trying to escape all chars from an input file
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");
@sunnycmf
sunnycmf / apache-useful-online.md
Last active August 29, 2015 13:57
apache useful online tool
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://npmjs.org/install.sh | sh
// 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';
%w(pathname json openssl net/http digest/sha1 zip).each { |lib| require lib }
module Passbook
def self.wwdr_certificate
OpenSSL::X509::Certificate.new <<-EOF.gsub /^\s+/, ""
-----BEGIN CERTIFICATE-----
MIIEIzCCAwugAwIBAgIBGTANBgkqhkiG9w0BAQUFADBiMQswCQYDVQQGEwJVUzET
MBEGA1UEChMKQXBwbGUgSW5jLjEmMCQGA1UECxMdQXBwbGUgQ2VydGlmaWNhdGlv
biBBdXRob3JpdHkxFjAUBgNVBAMTDUFwcGxlIFJvb3QgQ0EwHhcNMDgwMjE0MTg1
NjM1WhcNMTYwMjE0MTg1NjM1WjCBljELMAkGA1UEBhMCVVMxEzARBgNVBAoMCkFw