Skip to content

Instantly share code, notes, and snippets.

@dhruvbaldawa
dhruvbaldawa / answer.py
Created April 24, 2014 22:14
finally_always_guaranteed
def foo():
try:
return True
except:
pass
else:
return False
@dhruvbaldawa
dhruvbaldawa / check_mu.py
Created April 24, 2014 23:57
few interesting python scripts
import urllib2
import time
import os
msg_string = 'Result for %s %s declared.'
url = 'http://results.mu.ac.in/choose_nob.php?exam_id=%s&exam_year=2012&exam_month=MAY'
# some exam_id to start looking from
id_start = 2765
### Keybase proof
I hereby claim:
* I am dhruvbaldawa on github.
* I am dhruvbaldawa (https://keybase.io/dhruvbaldawa) on keybase.
* I have a public key whose fingerprint is 7C20 B07E 23F3 2875 0BD1 FC85 3825 385A 7C27 34C1
To claim this, I am signing this object:
<HTML>
<HEAD>
<TITLE>TEST</TITLE>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
function run() {
link = 'http://ajay-pc/nisarg/my_ajay/node/1.json';
$.ajax({
url: link,
dataType: 'json',
@dhruvbaldawa
dhruvbaldawa / mu_result.py
Created July 15, 2012 13:50
MU Result Checking Script
import urllib2
import time
import tweepy
import os
# Twitter Bot Credentials
# Refer on https://dev.twitter.com
consumer_key = ''
consumer_secret = ''
access_token = ''
@dhruvbaldawa
dhruvbaldawa / json_decode.py
Created September 8, 2012 18:00
JSON decoding
request_dict = {}
for key, value in json_decoded_dict.iteritems():
try:
request_dict[key] = json.loads(value)
except:
request_dict[key] = value
return request_dict
@dhruvbaldawa
dhruvbaldawa / reload_db.sh
Created February 12, 2013 10:56
Reload database script for Flask
#### I am no Bash expert, I just googled and put this script together
#### Be free to fork and post updates to this gist
#### Also, you can change the username and email below for the django superuser
DEFAULT_USER="dhruv"
DEFAULT_EMAIL="dbaldawa@enthought.com"
DEFAULT_PASS="d"
function usage
{
import sys
from urllib import urlencode
import requests
from urlparse import urlparse, parse_qs
from random import choice
import re
self_id = None # your facebook id here
utc_bday = None # utc timestamp of your birthday
class Payment(models.Model):
is_started = models.BooleanField(default=True)
is_captured = models.BooleanField(default=False)
is_completed = models.BooleanField(default=False)
def can_capture(self):
return self.is_started and not self.is_captured and not self.is_completed
def can_complete(self):
return self.is_captured
class Payment(models.Model):
STATE_CHOICES = (
('started', 'Started'),
('captured', 'Captured'),
('completed', 'Completed'),
)
state = models.CharField(choices=STATE_CHOICES, default='started', max_length=16)
def can_capture(self):