Skip to content

Instantly share code, notes, and snippets.

View cjgiridhar's full-sized avatar

Chetan Giridhar cjgiridhar

View GitHub Profile
@cjgiridhar
cjgiridhar / Null.py
Created May 24, 2011 09:27
Null Design Pattern
# Null Object Pattern
class AbstractLogging:
def Log(self, msg):
pass
from time import asctime, localtime
class RealLogging(AbstractLogging):
def Log(self, msg):
print 'Logged at', asctime(localtime()), msg
@cjgiridhar
cjgiridhar / lwp.c
Created June 13, 2011 07:13
LWP Code Implementation
#include <malloc.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <sched.h>
#include <stdio.h>
#include <fcntl.h>
// 64kB stack
#define STACK 1024*64
@cjgiridhar
cjgiridhar / ReviewBoard.pm
Created June 26, 2011 05:56
ReviewBoard2.0 Perl Package
package API::ReviewBoard;
use strict;
use warnings;
use LWP;
use HTTP::Cookies;
use Carp qw(croak);
use Params::Validate qw[validate OBJECT SCALAR ARRAYREF];
use Data::Dumper;
use vars qw( @EXPORT @ISA );
@cjgiridhar
cjgiridhar / mongoDB.py
Created July 24, 2012 03:20
CRUD for MongoDB with Pymongo
import pymongo
from pymongo import Connection
conn = Connection()
db = conn['myDB']
collection = db['language']
#Creating a collection
db.language.insert({"id": "1", "name": "C", "grade":"Boring"})
db.language.insert({"id": "2", "name":"Python", "grade":"Interesting"})
@cjgiridhar
cjgiridhar / tornadohelloworld.py
Created July 25, 2012 06:02
Tornado - Hello World
## Torando Web Server hello World
import tornado.ioloop
import tornado.web
class Hello(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
@cjgiridhar
cjgiridhar / TornadorequestHandler.py
Created July 26, 2012 04:56
Tornado - Request Handling
mport tornado.ioloop
import tornado.web
class Hello(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
class User(tornado.web.RequestHandler):
def get(self, username,designation):
self.get_arguments(username, strip=True)
@cjgiridhar
cjgiridhar / home.html
Created July 27, 2012 08:12
Tornado - Redirection
<html>
<body>
<FORM ACTION="/article" METHOD=POST>
<input type="submit" value="Home">
</FORM>
</body>
</html>
@cjgiridhar
cjgiridhar / mongotornado.py
Created July 27, 2012 10:21
Tornado - MongoDB
import tornado.ioloop
import tornado.web
import time
## MongoDB
import pymongo
from pymongo import Connection
conn = Connection()
db=conn['library']
collection = db['articles']
@cjgiridhar
cjgiridhar / articles.html
Created July 30, 2012 05:30
Tornado - Static File Handler
<html>
<title>
Articles
</title>
<body>
<h1>Articles page</h1>
<p><img src="images/images.jpg"/></p>
</body>
</html>
@cjgiridhar
cjgiridhar / template.html
Created August 1, 2012 08:14
Tornado - Templates
<html>
<head>
<title>{{ title }}</title>
</head>
<body>
<table border="1">
{% for key,value in dict.items() %}
<tr>
<td>{{ key }}</td>
<td>{{ value }}</td>