Skip to content

Instantly share code, notes, and snippets.

View jeonghwan-kim's full-sized avatar

김정환 jeonghwan-kim

View GitHub Profile
it('비동기 테스트', function (done) {
foo(function () {
done();
});
});
it('Throw test', function () {
(function () {
foo();
}).should.throw;
});
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);
});
@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() {
@jeonghwan-kim
jeonghwan-kim / my-winston.js
Last active May 2, 2018 09:59
usage of winston
// set timezone
process.env.TZ = 'Asia/Seoul';
// winston object
var winston = require('winston');
var logger = new (winston.Logger)({
transports: [
new (winston.transports.File)({
filename: 'error.log',
json: false,
@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 / 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 / my-test-widget.php
Created October 25, 2013 07:40
Add a custom widget as wordpress plugin.
<?php
/*
Plugin Name: My Test Widget
Plugin URI: http://wordpress.org/plugins/???
Description: Test widget.
Author: Jeonghwan Kim
Version: 1.0
Author URI: mailto:ej88ej@gmail.com
*/
@jeonghwan-kim
jeonghwan-kim / merge-sort.c
Created October 25, 2013 01:38
merge sort
// a, b, 두 배열을 정렬하며 merge하는 함수
void merge(int a[], int n, int b[], int m) {
int *c = (int *)calloc(sizeof(int), (n + m));
int i = 0, j = 0, k = 0;
while (k < n + m) {
// 두 배열중 1개가 종료되면 루프에서 벗어남.
if (i >= n || j >= m) break;
// 두 배열의 값을 비교하여 순서대로 합침.
// Heap 구조에 따라 출력 로직도 변경되어야 함 (1 ~ n까지만 출력)
void print_array(int a[], int n) {
for (int i = 1; i <= n; i++) {
printf("%3d", a[i]);
}
}
void foo(int a[], int n) {
printf("[Before] ");
print_array(a, n);