Skip to content

Instantly share code, notes, and snippets.

proxy_cache_path /var/cache/nginx/sub.example.com levels=1:2 keys_zone=media-cache:8m max_size=100m inactive=600m;
proxy_temp_path /var/cache/nginx/tmp/media;
server {
listen 80;
server_name sub.example.com;
client_max_body_size 20m;
access_log /var/log/nginx/sub.example.com.access.log;
error_log /var/log/nginx/sub.example.com.error.log;
@vojd
vojd / gist:4284560
Last active October 14, 2015 01:08
local.py
from settings import *
DATABASES = {
"default" : {
"ENGINE" : "django.db.backends.sqlite3",
"NAME" : "db/dev.db"
}
}
# add johnny's middleware
LOCAL_MIDDLEWARE_CLASSES = (
@vojd
vojd / simple_django_test.py
Created December 6, 2012 14:58
simple_django_test
def add_to_cart(product):
resp = self.client.post(reverse('add_to_cart_view', {'product' : product.pk}
return resp
def test_add_to_cart():
# add all products to cart
for product in Product.objects.all():
resp = add_to_cart(product)
self.assertEqual(resp.status_code, 302)
@vojd
vojd / ups_selections.py
Created December 3, 2012 09:56
ups_selections
SHIPPING_SERVICES = (
('11', 'Standard'),
('07', 'Worldwide Express'),
('54', 'Worldwide Express Plus'),
('08', 'Worldwide Expedited'),
('65', 'Saver. Required for Rating and Ignored for Shopping'),
)
SHIPPING_SERVICES_LOOKUP = dict(SHIPPING_SERVICES)
# 07 - Worldwide Express
@vojd
vojd / xml_multiple_root.xml
Created November 27, 2012 10:56
Multiple root element oddity
<?xml version="1.0" ?>
<AccessRequest xml:lang='en-US'>
<AccessLicenceNumber>secret</AccessLicenceNumber>
<UserId>secret</UserId>
<Password>secret</Password>
</AccessRequest>
<?xml version="1.0" ?>
<RatingServiceSelectionRequest>
<Request>
@vojd
vojd / git_remote_branch_list
Created November 25, 2012 19:09
Git - list remote branches by revision date
for k in `git branch -r | perl -pe 's/^..(.*?)( ->.*)?$/\1/'`; do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k -- | head -n 1`\\t$k; done | sort -r
# http://stackoverflow.com/questions/2514172/listing-each-branch-and-its-last-revisions-date-in-git
@vojd
vojd / selenium_wait_unti.py
Created November 22, 2012 14:53
selenium_wait
try:
WebDriverWait(self.browser, 10).until(
lambda driver : self.assertEqual(
"1", driver.browser.find_element_by_xpath("//*[@id='cart-amount']").text)
)
except Exception as e:
print e
@vojd
vojd / gunicorn-django-debug
Created October 9, 2012 13:50
Gunicorn run in debug mode
---- starting ----
#!/bin/bash
python ./manage.py run_gunicorn -b 0.0.0.0:8001 -p /tmp/gunicorn.pid --daemon --access-logfile /var/log/gunicorn.log
echo "Server started, \n using PID /tmp/gunicorn.pid"
----- stopping ----
#!/bin/bash
kill `cat /tmp/gunicorn.pid`
@vojd
vojd / mobiscroll_setup.js
Created October 2, 2012 11:12
mobiscroll Formats date like [day date shortMonth] [hour] [minute]
/**
* Mobiscroll setup with swedish translation
* Formats date like [day date shortMonth] [hour] [minute]
*/
$(document).ready(function(){
(function ($) {
$.scroller.i18n.sv = $.extend($.scroller.i18n.sv, {
setText: 'Klar',
cancelText: 'Avbryt'
@vojd
vojd / contact_form_view.py
Created May 29, 2012 20:49
Django contact form view
from django.views.generic.edit import ProcessFormView
class ContactView(ProcessFormView):
form_class = ContactForm
template_name = 'contact.html'
success_url = '/thanks/'
def form_valid(self, form):
send_contact_message(form.cleaned_data['email'],
form.cleaned_data['message'])