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
def deep_get(dictionary, keys, default=None): | |
""" | |
Gets a value following the specified path, if it exists. | |
The keys are dot-separated. | |
Example: | |
deep_get({'most_visited': {'url': 'https://test.com/'}}, 'most_visited.url') | |
""" |
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 argparse | |
parser = argparse.ArgumentParser(description='Replace text nodes') | |
parser.add_argument('file', type=str) | |
args = parser.parse_args() | |
html = open(args.file).read() | |
def replace(content): |
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.db import models | |
from django import forms | |
class TextInputTextField(models.TextField): | |
def formfield(self, **kwargs): | |
kwargs.update({ | |
"widget": forms.TextInput | |
}) |
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 django.contrib.auth.admin import UserAdmin | |
from django.utils.translation import ugettext_lazy as _ | |
from .forms import UserChangeForm, UserCreationForm | |
from .models import User |
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
class CountIncrMethodMixin(models.Model): | |
def incr_count(self): | |
model = type(self) | |
model.objects.filter(id=self.id).update( | |
count=models.F("count")+1 | |
) |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<title>Coffee shop</title> | |
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script> | |
<script type="text/javascript" src="checkboxes.js"></script> | |
</head> | |
<body> | |
<p>What topping would you like?</p> |
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
i=1 ; for pnmfile in *.pnm ; do tifffile=$(printf %02d.tiff $i) ; convert -compress lzw $pnmfile $tifffile ; i=$((i+1)) ; done |
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
#!/bin/bash | |
DATABASES="cooldb nicedb epicdb" | |
LOCAL_PWD="Tr0ub4dor&3" | |
RDS_PWD="correcthorsebatterystaple" | |
RDS_HOST="blahblahblah.rds.amazonaws.com" | |
for DB in $DATABASES ; do | |
echo "Moving $DB" | |
echo "create database $DB;" | mysql --host=$RDS_HOST --user=root --password=$RDS_PWD |
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
location /maintenance/ { | |
alias /home/web/maintenance/; | |
} | |
if ($uri !~ ^/maintenance) { | |
return 302 http://mywebsite.com/maintenance/; | |
} |
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 sys | |
import httplib2 | |
import urllib | |
import hashlib | |
import re | |
import itertools | |
from BeautifulSoup import BeautifulSoup | |
import progressbar |
NewerOlder