Skip to content

Instantly share code, notes, and snippets.

View shabda's full-sized avatar

Shabda Raaj shabda

View GitHub Profile
class DeclarativeFieldsMetaclass(type):
"""
Metaclass that converts Field attributes to a dictionary called
'base_fields', taking into account parent class 'base_fields' as well.
"""
def __new__(cls, name, bases, attrs):
attrs['base_fields'] = get_declared_fields(bases, attrs)
new_class = super(DeclarativeFieldsMetaclass,
cls).__new__(cls, name, bases, attrs)
if 'media' not in attrs:
#!/usr/bin/env python
import urllib, simplejson
def is_github_project(href):
"Quick and dirty way to find if a link is a github project"
if href.startswith("http://github.com") and len(href.split("/")) == 5:
return True
return False
def get_popular_projects():
shabda@jazzy ~> python repopular_project.py
set(['http://github.com/Sutto/barista', 'http://github.com/alunny/sleight', 'http://github.com/pypy/pypy', 'http://github.com/jacksonh/manos-spark', 'http://github.com/dysinger/apparatus', 'http://github.com/Yelp/mrjob', 'http://github.com/videlalvaro/Thumper'])
shabda@jazzy ~>
@shabda
shabda / default.coffee
Created December 12, 2011 09:07 — forked from dheerosaur/default.js
Hiding stuff, go directly to "My active tickets" in unfuddle
// Reusable extension for jQuery so that we can hide jQuery objects
// and hide them. We will show an arrow at the top-right corner which
// will toggle the display of these.
// Examples:
//
// For github.com.js:
// $("#header").toggleStuff();
//
// Some random site:
// $("#report_attachment").parent().next().toggleStuff()
$.fn.toggleStuff = ->
$this = $(this)
anchorCss =
position: 'fixed'
top: '30px'
right: '10px'
'z-index': '999'
'font-size': '30px'
'font-weight': 'bold'
'text-decoration': 'none'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'bpcle.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
'TEST NAME':'test_database.sqlite',
}
@shabda
shabda / binsearch.py
Created November 24, 2012 11:07 — forked from akshar-raaj/binsearch
Binary Search
not_found = -1
import unittest
class TestBinS(unittest.TestCase):
def test_empty(self):
lst = []
key = 0
self.assertEquals(binsearch(lst, 0,), -1)
def test_equal(self):
lst = [10, 10, 10, 10]
{
"metadata": {
"name": "Versioning"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@shabda
shabda / gist:5317134
Last active December 15, 2015 20:18
import random
import string
def random_word_from_seed(seed, len):
random.seed(seed)
letters = string.ascii_lowercase
return ''.join([random.choice(letters) for i in range(len)])
print random_word_from_seed(1944062, 5) +" "+random_word_from_seed(2068527, 5)
path = "./" #Override this
dropbox_dirs = set([el[:10] for el in os.listdir(".")
if os.path.join(path, el) and not el.startswith(".")])
for el in dropbox_dirs:
if not os.path.exists(os.path.join(path, el)):
os.mkdir(os.path.join(path, el))
os.system("mv %s*.* %s"%(os.path.join(path, el), os.path.join(path, el)))