This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function printTree(n){ | |
| if(n.leaf1) | |
| printTree(n.leaf1); | |
| if(n.leaf2) | |
| printTree(n.leaf2); | |
| if(n.a) | |
| console.log(n.a); | |
| } | |
| printTree(n); // n คือ tree ตามด้านบน |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| a: '0', | |
| leaf1: { | |
| a: '1', | |
| leaf1: { | |
| a: '2', | |
| leaf1: { | |
| a: '3', | |
| } | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function countElement(array, i, acc){ | |
| if(!i) | |
| i = 0; | |
| if(!acc) | |
| acc = {}; | |
| if(array.length<=i) | |
| return acc; | |
| if(!acc[array[i]]) | |
| acc[array[i]] = 0; | |
| acc[array[i]]++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function F(n, a, b){ | |
| if(!a) | |
| a = 0; | |
| if(!b) | |
| b = 1; | |
| if(n == 0) | |
| return a; | |
| return F(n-1, b, a+b); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function F(n){ | |
| if(n == 0 || n == 1) | |
| return n; | |
| return F(n-1) + F(n-2); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function F(n){ | |
| var a = 0; | |
| var b = 1; | |
| var result = 0; | |
| for(var i=2; i<=n; i++){ | |
| result = a + b; | |
| a = b; | |
| b = result; | |
| } | |
| return result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "stdafx.h" | |
| #include <conio.h> | |
| int _tmain(int argc, _TCHAR* argv[]) | |
| { | |
| int a[10], i; | |
| for (i = 9; i >= -1; i--) { | |
| printf("before: i = %d\t", i); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "stdafx.h" | |
| #include <conio.h> | |
| int _tmain(int argc, _TCHAR* argv[]) | |
| { | |
| int a[10], i; | |
| for (i = 0; i <= 10; i++) { | |
| printf("before: i = %d\t", i); | |
| a[i] = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sudo /usr/bin/mongod --replSet foo --port 27017 -fork --quiet --dbpath /data/r0 --logpath /var/log/mongodb0.log | |
| sudo /usr/bin/mongod --replSet foo --port 27018 -fork --quiet --dbpath /data/r1 --logpath /var/log/mongodb1.log | |
| sudo /usr/bin/mongod --replSet foo --port 27019 -fork --quiet --dbpath /data/r2 --logpath /var/log/mongodb2.log | |
| sudo mongo localhost:27017 --eval "config = {_id: 'foo', members: [{_id: 0, host: 'localhost:27017'},{_id: 1, host: 'localhost:27018'},{_id: 2, host: 'localhost:27019'}]};rs.initiate(config);" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sudo apt-get update | |
| sudo apt-get install openjdk-6-jre-headless -f | |
| sudo apt-get install curl | |
| sudo apt-get install unzip | |
| sudo apt-get install openssh-server | |
| sudo curl -OL http://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.8.zip | |
| sudo unzip elasticsearch-* && rm elasticsearch-*.zip | |
| cd elasticsearch-0.19.8 | |
| sudo mkdir /usr/local/elasticsearch |