Skip to content

Instantly share code, notes, and snippets.

@estebistec
estebistec / osx_geodjango_deps.sh
Created January 28, 2012 04:10
GeoDjango dependencies on OSX
# Freshen homebrew
brew update
brew upgrade
# The main stuff we need
brew install postgresql
brew install postgis
brew install gdal
# Switch to postgis version 1.5.3 - 2.0 not supported yet
@estebistec
estebistec / models.py
Created May 20, 2012 20:11
Base django model
# For anyone random finding this, yeah, I don't like Django performing the extra query to determine insert vs. update
class BaseModel(models.Model):
id = models.CharField(primary_key=True, max_length=512)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
version = models.IntegerField(default=1)
class Meta:
abstract = True
@estebistec
estebistec / gist:3092237
Created July 11, 2012 18:36
Distribute public key
# I always forget this command snippet and especially that ssh refuses if file privs aren't just so
cat ~/.ssh/id_rsa.pub | ssh user@remote-host "mkdir -p .ssh; chmod 700 .ssh; cat >> .ssh/authorized_keys2; chmod 600 .ssh/authorized_keys2"
@estebistec
estebistec / pipeline_settings.py
Created October 28, 2012 03:09
Automatically detect apps with less folders to setup lessc include-path
def get_less_static_dirs():
"""get static-directory paths for apps that have less files
Assumptions:
* You want any LESS files from apps in INSTALLED_APPS
* You don't have LESS files in any extra folders in STATIC_DIRS (maybe I should fix that... always thought static_dirs was dumb)
"""
app_modules = [import_module(app) for app in INSTALLED_APPS]
maybe_less_static_dirs = [
# For Django apps, __file__ should always be the path to __init__.pyc
@estebistec
estebistec / README.md
Last active February 3, 2021 23:16
This minimal setup allows you to run nginx using the current folder as the doc-root. NOTE: python's simplehttpserver may be good enough for you. This is just a nice simple nginx setup.
  1. Get all of these files into the target folder
  2. Run the following commands:
chmod +x *.sh
./nginx-start.sh
@estebistec
estebistec / requirements.txt
Last active December 23, 2015 03:29
development requirements
flake8
docformatter
pylint
cricket
bugjar
duvet
@estebistec
estebistec / gist:7324558
Created November 5, 2013 19:19
yes, parsing utc datetimes works (!??!)
$ pip freeze -l
python-dateutil==1.5
pytz==2013.8
$ python
...
>>> from dateutil.parser import parse
>>> import datetime
>>> import pytz
>>> d = datetime.datetime.now(pytz.UTC)
>>> d
@estebistec
estebistec / fields.py
Last active October 13, 2016 05:11
Django-REST-framework list serializer
def nested_from_native(nested_field, data):
if isinstance(nested_field, serializers.BaseSerializer):
return nested_field.from_native(data, None)
return nested_field.from_native(data)
class ListField(fields.WritableField):
def __init__(self, item_field, *args, **kwargs):
super(ListField, self).__init__(*args, **kwargs)
@estebistec
estebistec / memoized_property.py
Created December 23, 2013 16:06
I have written the if hasattr dance for properties that load once WAY too many times...
from functools import wraps
def memoized_property(fget):
"""
Return a property attribute for new-style classes that only calls
it's getter on the first property access. The result is stored
and on subsequent accesses is returned, preventing the need to call
the getter any more.
http://docs.python.org/2/library/functions.html#property
@estebistec
estebistec / intToBinStr.hs
Last active August 29, 2015 13:56
Haskell 4 Madhurima
intToBinStr :: Int -> String
intToBinStr n =
let _shiftBits 0 s = s ++ "0"
_shiftBits 1 s = s ++ "1"
_shiftBits x s = _shiftBits (div x 2) (s ++ show (mod x 2))
in _shiftBits n ""
main :: IO ()
main = print $ intToBinStr 19