Skip to content

Instantly share code, notes, and snippets.

View varavut's full-sized avatar

Varavut Lormongkol varavut

View GitHub Profile
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 ตามด้านบน
{
a: '0',
leaf1: {
a: '1',
leaf1: {
a: '2',
leaf1: {
a: '3',
}
},
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]]++;
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);
}
function F(n){
if(n == 0 || n == 1)
return n;
return F(n-1) + F(n-2);
}
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;
#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);
#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;
@varavut
varavut / gist:3569306
Created September 1, 2012 10:40
mongostart
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);"
@varavut
varavut / a.sh
Created April 15, 2012 14:01
testmongo
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