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
//================================================ Python code sample ================================================// | |
import urllib | |
# If your firewall blocks access to port 5567, you can fall back to port 80: | |
# url = "http://bulksms.2way.co.za/eapi/submission/send_sms/2/2.0" | |
# (See FAQ for more details.) | |
url = "http://bulksms.2way.co.za:5567/eapi/submission/send_sms/2/2.0" | |
params = urllib.urlencode({'username' : 'myusername', 'password' : 'xxxxxxxx', 'message' : 'Testing Python', 'msisdn' : 271231231234}) | |
f = urllib.urlopen(url, params) |
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
import boto | |
from boto.s3.key import Key | |
from django.conf import settings | |
#settings: | |
""" | |
AWS_ACCESS_KEY_ID | |
AWS_SECRET_ACCESS_KEY | |
DEFAULT_BUCKET |
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.dispatch import receiver | |
from django.db.models.signals import post_save | |
from django.contrib.contenttypes.models import ContentType | |
@receiver(post_save) | |
def model_saved(sender, instance, signal, *args, **kwargs): | |
app_label = sender._meta.app_label | |
model_name = sender._meta.module_name | |
content_type = ContentType.objects.get(app_label=app_label, model=model_name) |
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.contrib import admin | |
from more_with_admin.examples import models | |
class DocumentAdmin(admin.ModelAdmin): | |
def queryset(self, request): | |
qs = super(DocumentAdmin, self).queryset(request) | |
# If super-user, show all comments | |
if request.user.is_superuser: |
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
/* | |
It makes sense to use the built-in jquery dialog. But (IMO), the styling on them looks like it was done back a systems administrator. Here are a few lines of css to make them look a little less clunky | |
*/ | |
/** | |
Main colors: | |
dark: #545454 | |
light: #ccc | |
*/ | |
.ui-dialog {border: solid 4px #545454;border-radius:0px;padding:0px;-moz-box-shadow: 3px 3px 4px #545454;-webkit-box-shadow: 3px 3px 4px #545454;box-shadow: 3px 3px 4px #545454; | |
/* For IE 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
# given a list such as: | |
# list = [{'title':title, 'date': x.created_on}, ...] | |
# you can sort on a dict key like such | |
list.sort(key=lambda item:item['date'], reverse=True) | |
#source: http://stackoverflow.com/questions/652291/sorting-a-list-of-dictionary-values-by-date-in-python |
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
# hat-tip: Sven Marnach | |
# http://stackoverflow.com/questions/5817209/browse-files-and-subfolders-in-python | |
htmlfiles = [os.path.join(root, name) | |
for root, dirs, files in os.walk(path) | |
for name in files | |
if name.endswith((".html", ".htm"))] |
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
description "launch django app with gunicorn and new relic monitoring" | |
start on net-device-up | |
stop on shutdown | |
respawn | |
# this cd's into your app's base dir | |
chdir /var/www/<appname>/ | |
# this sets the path to your newrelic.ini file |
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.core.cache import cache | |
cache.clear() |
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
""" | |
DataFrame: | |
project_id hours overtime day | |
0 3 4 False 2015-10-07 | |
1 3 6 False 2015-10-07 | |
2 3 7 False 2015-10-07 | |
3 2 5 False 2015-10-07 | |
4 2 4 False 2015-10-07 | |
5 1 4 False 2015-10-07 |