Skip to content

Instantly share code, notes, and snippets.

Installation

npm install -g .

Run

$ sudo -E xfwd
@dhruvbaldawa
dhruvbaldawa / reload_db.sh
Created September 20, 2012 08:20
Bash script for automating some of django database cleanup
#### 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="admin"
DEFAULT_EMAIL="admin@mail.com"
DEFAULT_PASS="pass"
function usage
{
@dhruvbaldawa
dhruvbaldawa / pytransitions.py
Created January 27, 2018 19:50
pytransitions example
from transitions import Machine
class Payments(models.Model):
STATES = {
'started': 'Started',
'captured': 'Captured',
'completed': 'Completed',
}
class Payments(models.Model):
STATES = {
'started': 'Started',
'captured': 'Captured',
'completed': 'Completed',
'incomplete': 'Incomplete', # new incomplete state for us
}
def __init__(self, *args, **kwargs):
super(Payments, self).__init__(*args, **kwargs)
class Payments(models.Model):
STATES = {
'started': 'Started',
'captured': 'Captured',
'completed': 'Completed',
}
state = models.CharField(default='started', choices=STATES.items(), max_length=16)
def __init__(self, *args, **kwargs):
class Payment(models.Model):
STATE_CHOICES = (
('started', 'Started'),
('captured', 'Captured'),
('completed', 'Completed'),
# we introduce a new "incomplete" state
('incomplete', 'Incomplete'),
)
def can_complete(self):
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):
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
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
@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
{