Skip to content

Instantly share code, notes, and snippets.

View chakrit's full-sized avatar

Chakrit Wichian chakrit

View GitHub Profile
»» $ mocha --reporter nyan server.js
6 -_-_-_-_,------,
0 -_-_-_-_| /\_/\
0 -_-_-_-^|__( ^ .^)
-_-_-_- "" ""
✔ 6 tests complete (196ms)
@chakrit
chakrit / 1 - before.js
Created July 10, 2012 03:18
[refactor.io] entry/4ffb9f155eba35595d000011 - Inversed IF
function sample() {
if (condition1 === 'value1') {
if (condition2 === 'value2') {
if (condition3 === 'value3') {
throw 'wrong condition3';
} else {
do_actual_work();
and();
return value();
}
@chakrit
chakrit / 1 - before.js
Created July 10, 2012 04:51
[refactor.io] entry/4ffbb4c05eba35595d0000a8 - Decompose Conditional
if (date.before (SUMMER_START) || date.after(SUMMER_END))
charge = quantity * _winterRate + _winterServiceCharge;
else
charge = quantity * _summerRate;
»» $ jake cloc
http://cloc.sourceforge.net v 1.56 T=0.5 s (24.0 files/s, 1344.0 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code scale 3rd gen. equiv
-------------------------------------------------------------------------------
Javascript 11 139 76 438 x 1.48 = 648.24
Bourne Shell 1 5 1 13 x 3.81 = 49.53
-------------------------------------------------------------------------------
SUM: 12 144 77 451 x 1.55 = 697.77
07/10 12:59:20 GMT+0700] MongoError: E11000 duplicate key error index: nodejitsudb90023846573.users.$entries.gistId_1 dup key: { : null }
[07/10 12:59:20 GMT+0700] at Db.wrap (/opt/haibu/apps/chakrit/refactor.io/package/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1675:11)
[07/10 12:59:20 GMT+0700] at [object Object].<anonymous> (/opt/haibu/apps/chakrit/refactor.io/package/node_modules/mongoose/node_modules/mongodb/lib/mongodb/collection.js:297:26)
[07/10 12:59:20 GMT+0700] at [object Object].g (events.js:156:14)
[07/10 12:59:20 GMT+0700] at [object Object].emit (events.js:88:20)
[07/10 12:59:20 GMT+0700] at Db._callHandler (/opt/haibu/apps/chakrit/refactor.io/package/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1290:25)
[07/10 12:59:20 GMT+0700] at /opt/haibu/apps/chakrit/refactor.io/package/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:329:30
[07/10 12:59:20 GMT+0700] at [object Object].parseBody (/opt/haibu/apps/chak
@chakrit
chakrit / 1 - before.js
Created July 10, 2012 20:26
[refactor.io] entry/1 - Inversed IF
function sample() {
if (condition1 === 'value1') {
if (condition2 === 'value2') {
if (condition3 === 'value3') {
throw 'wrong condition3';
} else {
do_actual_work();
and();
return value();
}
@chakrit
chakrit / 1 - before.js
Created July 10, 2012 20:32
[refactor.io] entry/2 - Decomposed Conditional
if (date.before (SUMMER_START) || date.after(SUMMER_END))
charge = quantity * _winterRate + _winterServiceCharge;
else
charge = quantity * _summerRate;
@chakrit
chakrit / 1 - before.js
Created July 10, 2012 20:43
[refactor.io] entry/3 - test
asdfasdfaskl
info: Welcome to Nodejitsu chakrit
info: It worked if it ends with Nodejitsu ok
info: Executing command databases create redis refactor.io.db
info: Database refactor.io.db was created.
error: Database does not exist
info: Nodejitsu ok
@chakrit
chakrit / 1 - before.js
Created July 11, 2012 09:37
[refactor.io] entry/1 - Decomposed Conditional
if (date.before (SUMMER_START) || date.after(SUMMER_END))
charge = quantity * _winterRate + _winterServiceCharge;
else
charge = quantity * _summerRate;