Skip to content

Instantly share code, notes, and snippets.

View chakrit's full-sized avatar

Chakrit Wichian chakrit

View GitHub Profile
@chakrit
chakrit / 1 - before.js
Created July 11, 2012 09:38
[refactor.io] entry/2 - 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 14, 2012 06:13
[refactor.io] entry/4 - testsetset
'BEFORE'
[07/18 17:29:46 GMT+0700] ld.so.1: node: fatal: relocation error: file /opt/haibu/apps/chakrit/refactor.io/package/node_modules/redis-url/node_modules/redis/node_modules/hiredis/build/Release/hiredis.node: symbol redisReaderCreate: referenced symbol not found
@chakrit
chakrit / 1 - before.js
Created July 21, 2012 18:47
[refactor.io] entry/5 - asdfasdf
What does the code looks like BEFORE
applying your refactoring technique.
Makes the flaw obvious.
@chakrit
chakrit / 1 - before.js
Created July 21, 2012 19:02
[refactor.io] entry/3 - Consolidated Conditional Expression
function disablityAmount() {
if (_seniority < 2) return 0;
if (_monthsDisabled > 12) return 0;
if (_isPartTime) return 0;
execute();
}
info: Welcome to Nodejitsu chakrit
info: It worked if it ends with Nodejitsu ok
info: Executing command deploy
info: Skipping require-analyzer because noanalyze option is set
info: Skipping require-analyzer because noanalyze option is set
info: Creating snapshot 0.1.1-1
info: Updating app niyai
info: Activating snapshot 0.1.1-1 for niyai
info: Starting app niyai
error: Error running command deploy
@chakrit
chakrit / 1 - before.js
Created August 1, 2012 07:24
[refactor.io] entry/4 - Remove Control Flag
function checkSecurity(people) {
var found = false;
for (var i = 0; i < people.length; i++) {
if (!found) {
if (people[i] === 'Don') {
alert('Don is here!');
found = true;
}
if (people[i] === 'John') {
[08/02 01:26:48 GMT+0700] [2012-08-01 18:26:48.686] [TRACE] NumberModel - add new number: { slug: 'king-chulalongkorn-memorial-hospital',
[08/02 01:26:48 GMT+0700] title: 'King Chulalongkorn Memorial Hospital',
[08/02 01:26:48 GMT+0700] 'title/th': '????????????????????????????????????????????????????????? ?????????????????????????????????',
[08/02 01:26:48 GMT+0700] tags: [ 'hospital', 'bangkok' ],
[08/02 01:26:48 GMT+0700] info: undefined,
[08/02 01:26:48 GMT+0700] number: '0-22564000' }
[08/01 23:08:06 GMT+0700] Error: Cannot find module 'icu-wordsplit'
[08/01 23:08:06 GMT+0700] at Function._resolveFilename (module.js:337:11)
[08/01 23:08:06 GMT+0700] at Function._load (module.js:279:25)
Express server listening on port 3000 in development mode
[2012-08-02 22:13:17.302] [TRACE] NumberModel - get number: 'asoke'
[2012-08-02 22:13:17.304] [TRACE] NumberModel - got number: null
[2012-08-02 22:13:17.304] [TRACE] IndexModel - get items from keyword: 'asoke'
[2012-08-02 22:13:17.305] [TRACE] IndexModel - got items: [ '1:asoke-skin-hospital' ]
[2012-08-02 22:13:17.305] [TRACE] NumberModel - get number: 'asoke-skin-hospital'
[2012-08-02 22:13:17.305] [TRACE] NumberModel - got number: '{"slug":"asoke-skin-hospital","title":"Asoke Skin Hospital","title/th":"โรงพยาบาลผิวหนัง อโศก โรงพยาบาลเฉพาะทางผิวหนัง","tags":["hospital","bangkok"],"info":{"facebook":"www.facebook.com/skinhospital/info","twitter":"twitter.com/skinhospital"},"number":"0-2246-5111"}'
[2012-08-02 22:13:17.306] [TRACE] Number - search for: 'asoke' ' result:' [ { slug: 'asoke-skin-hospital',
title: 'Asoke Skin Hospital',
'title/th': 'โรงพยาบาลผิวหนัง อโศก โรงพยาบาลเฉพาะทางผิวหนัง',
var assert = require('assert')
, N = 100000000
, STR = ''
, STR2 = 'very very long the quick brown fox jumps over the lazy dog.';
console.time('str.length == 0');
for (var i = 0; i < N; i++) {
assert(STR.length == 0);
assert(STR2.length != 0);