Skip to content

Instantly share code, notes, and snippets.

View patrickbeeson's full-sized avatar

Patrick Beeson patrickbeeson

View GitHub Profile
@patrickbeeson
patrickbeeson / gist:e7b08b26b432e0a95686
Created September 23, 2014 14:59
Change field order of Django form (1.7+)
from collections import OrderedDict
class MyForm(forms.Form):
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
original_fields = self.fields
new_order = OrderedDict()
for key in ['first', 'second', ... 'last']:
new_order[key] = original_fields[key]
@patrickbeeson
patrickbeeson / postactivate
Created September 12, 2014 14:04
Set DJANGO_SETTINGS_MODULE for virtualenv
#!/bin/bash
# Set our local settings for this project
export DJANGO_SETTINGS_MODULE="myproject.settings.local"
@patrickbeeson
patrickbeeson / temp_convert.py
Created September 8, 2014 12:42
Convert F to C
# Converts temperature from F to C
far = input('Enter the temp in F:')
cel = input('Enter the temp in C:')
def convertC(far):
# Get the temp
# far = input('Enter the temp in F:')
@patrickbeeson
patrickbeeson / gist:5bb062bd6e80a00f864b
Created September 7, 2014 19:15
Integer check with exception
while True:
try:
userInput = int(input('Enter an integer: '))
print(str(userInput))
break
except ValueError:
print('Not an integer')
@patrickbeeson
patrickbeeson / gist:d6e6274c629c9a4a56f2
Created September 7, 2014 19:09
Type a command to quit loop
while True:
command = str(input('Close by typing q: '))
command = command.lower()
if command == 'q':
break
else:
command = str(input('Incorrect command. Close by typing q: '))
@patrickbeeson
patrickbeeson / gist:cefe76855554fafd3711
Last active August 29, 2015 14:06
Exclude multiples of a number
for i in range(1, 51):
if i % 3 == 0:
continue
print(str(i))
# Should result in a list of numbers from 1 to 50 excluding multiples of three
@patrickbeeson
patrickbeeson / factor.py
Created September 7, 2014 17:42
Find factors of a number
# factors.py
# Get integer input from user
userInteger = int(input('Enter a positive integer: '))
def findIntegers(userInteger):
"""
Find all factors of a number.
"""
@patrickbeeson
patrickbeeson / invest.py
Created September 7, 2014 17:41
Investment caculator
# invest.py
# Gather inputs from the user
amount = float(input('What is the amount you wish to invest? '))
rate = float(input('What is the current rate? '))
time = int(input('For what period of time would you like to hold your'
'investment (in years)? '))
def invest(amount, rate, time):
@patrickbeeson
patrickbeeson / gist:6b71b744148e8cde148f
Created September 1, 2014 16:45
Dump command line history to file
history > commands.log
@patrickbeeson
patrickbeeson / gist:2e9c1213efa529586e61
Created August 8, 2014 13:29
.htaccess change to redirect www to non-www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]