This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from BeautifulSoup import BeautifulSoup | |
body = "<p>Dear Everyone,</p><p>This is a test</p><h1>Test Complete</h1>" | |
plain_text = ' '.join(BeautifulSoup(body).findAll(text=True)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAMP: | |
/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot | |
set global net_buffer_length=1000000; | |
set global max_allowed_packet=1000000000; | |
/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot < ~/Downloads/DUMP | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Work out total and then round up to 2 decimal places WITHOUT dropping the final zero.... | |
from decimal import * | |
cost = "12.56896" | |
cost = Decimal(cost).quantize(Decimal('.01'), rounding=ROUND_UP) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import HttpResponse | |
from django.template.loader import render_to_string | |
from django.utils import simplejson | |
def myajax(request): | |
#Some logic | |
html = render_to_string(TEMPLATE, context) | |
return HttpResponse(simplejson.dumps({"html": html}), | |
content_type="application/json; charset=utf-8") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Convert Existing App | |
$ python manage.py convert_to_south APP_NAME --settings settings_debug | |
# Perform model change on development | |
$ python manage.py schemamigration APP_NAME --auto --settings settings_debug | |
$ python manage.py migrate APP_NAME --settings settings_debug.py | |
# Perform change on live server (assumes migration was applied and checked in on development) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Example File | |
AB101AA,394251,806376,57.1482995075,-2.09663094048 | |
Import file from command line: | |
$ mysqlimport -u root -p --local --fields-terminated-by=',' DATABASE FILENAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Connect to mysql command line... | |
$ mysql -u root -p | |
#Create user | |
$ create user USERNAME; | |
#Assign Permissions | |
$ grant PERMISSIONS on DATABASE.* to 'USERNAME'@'localhost' identified by 'PASSWORD'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils import simplejson | |
#Go to a url | |
response = self.client.get(self.url) | |
foobar = simplejson.loads(response.content) | |
print foorbar['item'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Very quick way to get some timing info... | |
import time | |
class Timer(): | |
def __enter__(self): self.start = time.time() | |
def __exit__(self, *args): print time.time() - self.start | |
with Timer(): | |
some_code() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Useful when creating lists in config files... | |
<%= my_list.join(',') %> |
OlderNewer