Skip to content

Instantly share code, notes, and snippets.

View cjgiridhar's full-sized avatar

Chetan Giridhar cjgiridhar

View GitHub Profile
// defining a function
var async_factorial = function(n, callback){
console.log("step1");
var fact = 1;
process.nextTick(function(){
for(var i=1; i<n; i++) {
fact = fact*i;
}
console.log("step2");
callback(fact);
@cjgiridhar
cjgiridhar / helloworld.js
Last active December 11, 2015 02:09
node.js - Hello world
var http = require('http');
var server = http.createServer(function(request, response) {
response.write("Hello World");
response.end();
})
server.listen(8888);
console.log("Server Started")
@cjgiridhar
cjgiridhar / test.py
Created October 11, 2012 05:00
Lettuce Example Python BDD
from lettuce import *
@step('I have the number (\d+)')
def have_the_number(step, number):
world.number = int(number)
@step('I compute its fibonacci')
def compute_its_fibonacci(step):
world.number = fibonacci(world.number)
@cjgiridhar
cjgiridhar / fib.feature
Created October 11, 2012 05:00
Lettuce Example Python BDD
Feature: Compute fibonacci
In order to play with Lettuce
As beginners
We'll implement fibonacci
Scenario: Fibonacci of 0
Given I have the number 0
When I compute its fibonacci
Then I see the number 1
@cjgiridhar
cjgiridhar / morelikethis.html
Created September 26, 2012 08:08
Torando - Whoosh - MoreLike HTML
<html>
<head>
<title> More Like </title>
</head>
<body>
<FORM action="/morelikethis" method="POST">
Document:<input type=text name=path>
<input type="submit" name="submit">
</FORM>
</body>
@cjgiridhar
cjgiridhar / tornadowhoosh_morelike.py
Created September 26, 2012 08:07
Torando - Whoosh - MoreLike
import whoosh,os
from whoosh import index
import whoosh.index
import whoosh.fields
import whoosh.qparser
import tornado.ioloop
import tornado.web
class Search(object):
def __init__(self, indexdir, searchstr=None):
@cjgiridhar
cjgiridhar / searchform.html
Created September 21, 2012 11:16
Tornado - Search form
<html>
<head>
<title> Search </title>
</head>
<body>
<FORM action="/search" method="get">
<input type=text name=q>
<input type="submit" name="submit">
</FORM>
</body>
@cjgiridhar
cjgiridhar / tornadowhoosh.py
Created September 21, 2012 11:15
Tornado - Whoosh
import whoosh,os
from whoosh import index
import whoosh.index
import whoosh.qparser
import tornado.ioloop
import tornado.web
class Search(object):
def __init__(self, indexdir, searchstr):
self.indexdir = indexdir
@cjgiridhar
cjgiridhar / fileuploadform.html
Created September 17, 2012 04:29
Tornado - File Uploads - Form
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Upload Form</title>
</head>
<body>
<p><h1>Select & Upload</h1></p>
<form enctype="multipart/form-data" action="/upload" method="post">
File: <input type="file" name="filearg" />
<br />
@cjgiridhar
cjgiridhar / tornadofileupload.py
Created September 17, 2012 04:29
Tornado - File Uploads
import tornado
import tornado.ioloop
import tornado.web
import os, uuid
__UPLOADS__ = "uploads/"
class Userform(tornado.web.RequestHandler):
def get(self):
self.render("fileuploadform.html")