Skip to content

Instantly share code, notes, and snippets.

View eculver's full-sized avatar
🧠
Braining

Evan Culver eculver

🧠
Braining
View GitHub Profile
@eculver
eculver / replace_apt_sources.sh
Created December 26, 2013 00:02
Replace default Ubuntu apt repository URLs w/ DigitalOcean's
sudo sed -i "s/archive\.ubuntu/mirrors.digitalocean/g" /etc/apt/sources.list
@eculver
eculver / invalidte_thumb.py
Last active December 29, 2015 07:29
Example of deleting a cached KVStore instance that sorl.thumbnail thumbnail templatetag creates. Pretty edge, but handy when thumbnails aren't being generated for whatever reason.
from sorl.thumbnail import default
from myapp.models import MyModel
# Get an model instance that has a File/ImageField associated with it. In this
# case the `thumb` attribute is an ImageField that we'd like to generate thumbnails for.
m = MyModel.objects.get(pk=10)
# Note the options passed to this method -- they are applied to the cache key so
# the ImageFile instance that is returned will be different for a different set
# of options kwargs provided here. In this case, the only option is `upscale=False`.
@eculver
eculver / test.py
Last active December 28, 2015 16:59
TestSettingsManager
# This should be in a global namespace shared across your entire project
from django.conf import settings
NO_SETTING = ('!', None)
class TestSettingsManager(object):
"""
A class which can modify some Django settings temporarily for a
test and then revert them to their original values later.
# create user
CREATE USER myuser WITH PASSWORD 'mypassword';
# create database
CREATE DATABASE mydatabase;
# grant access to user
GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;
# grant just create
#!/bin/bash
#
# This is a simple wrapper for generating commands for executables within a
# python virtualenv.
#
# Usage: virtenv env-name command [arg, arg, ...]
#
# env-name The name of the virtualenv for the command to be run in.
# command The command within the virtualenv's path to be run. The base path is usually $VIRTUALENV_HOME/$VIRTUALENV/bin.
# arg Any remaining arguments are passed to the command itself.
@eculver
eculver / app-config.js
Created November 4, 2013 22:24
This is an example of how we have set up our Ember.js application to use Require modules. The files below should be represented in this directory structure: https://dl.dropboxusercontent.com/u/1049965/require_example.png
// We generate this file with Grunt based on system/environment level configuration that is contained elsewhere... YAML file, build number, etc.
(function (exports) {
exports.config = {
"appVersion": "dev",
"cdnUrl": "http://cdn.example.com"
}
// this last bit allows the config to be used both in the browser and in Node (Grunt)
}(typeof exports === 'undefined' ? this['WD'] = {}: exports));
def get_meta_property(self, name):
if not self.has_property(name):
msg = "Invalid metadata field '{0}'".format(name)
raise InvalidMetadataField(msg)
try:
value_obj = self.meta_values.get(category__name=name)
except NodeMetadataValue.DoesNotExist:
return None
@eculver
eculver / m2m_example.py
Created September 30, 2013 23:13
Example of creating M2M records w/ Django ORM
from datetime import datetime, date, timedelta
from myproject.apps.events import Location, Event
start = date.today()
end = start + timedelta(days=3)
location = Location(place='Mountain View, CA', venue='Shoreline Amphitheatre',
address='1 Amphitheatre Pkwy, Mountain View, CA 94043',
latitude=37.423172, longitude=-122.078266)
location.save()
location /favicon.ico {
alias /wd/services/api/production/current/wdapi/static/wdapi/img/favicon.ico;
}
@eculver
eculver / prettify.sh
Created August 5, 2013 21:47
CLI pretty-print JSON w/ Python
echo '{"foo": "lorem", "bar": "ipsum"}' | python -mjson.tool