Skip to content

Instantly share code, notes, and snippets.

View jeonghwan-kim's full-sized avatar

김정환 jeonghwan-kim

View GitHub Profile
@jeonghwan-kim
jeonghwan-kim / decode-base64.js
Created March 6, 2014 13:23
encode image file by base64
var fs = require('fs');
if (process.argv.length < 3) {
throw new Error('Input file name');
}
var f = process.argv[2];
fs.readFile(f, 'utf8', function (err, data) {
if (err) {
@jeonghwan-kim
jeonghwan-kim / base64.js
Created March 6, 2014 14:32
usage base64 in nodejs
fs.readFile(image_origial, function(err, original_data){
fs.writeFile('image_orig.jpg', original_data, function(err) {});
var base64Image = original_data.toString('base64');
var decodedImage = new Buffer(base64Image, 'base64');
fs.writeFile('image_decoded.jpg', decodedImage, function(err) {});
});
@jeonghwan-kim
jeonghwan-kim / simple-http-server.js
Created March 13, 2014 04:55
http server only using http module.
var http = require('http');
// Create an HTTP server
var srv = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('okay');
throw 'Error';
});
srv.listen(9999, '127.0.0.1', function() {
describe('test my-moudle.js', function () {
describe('test foo() function', function () {
describe('Check parameter', function () {
it('Empty paramters', function () {
foo().should.be.an.instanceof(Array);
});
it('Throw test', function () {
(function () {
foo();
}).should.throw;
});
it('비동기 테스트', function (done) {
foo(function () {
done();
});
});
all: foo boo
foo:
mocha test_foo.js -R spec
boo:
mocha test_boo.js -R spec -t 5555
@jeonghwan-kim
jeonghwan-kim / angularjs-save-cookie.js
Created April 20, 2014 03:50
angularjs-save-cookie.js
app.filter('parseUrl', function() {
var //URLs starting with http://, https://, or ftp://
replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim,
//URLs starting with "www." (without // before it, or it'd re-link the ones done above).
replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim,
//Change email addresses to mailto:: links.
replacePattern3 = /(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim;
return function(text, target, otherProp) {
angular.forEach(text.match(replacePattern1), function(url) {
<!doctype html>
<html ng-app="Demo" ng-controller="AppController">
<head>
<meta charset="utf-8" />
<title>
Lazy Loading Images With AngularJS
</title>
<style type="text/css">