Skip to content

Instantly share code, notes, and snippets.

View aaronlelevier's full-sized avatar

Aaron Lelevier aaronlelevier

View GitHub Profile
@aaronlelevier
aaronlelevier / docker-cheatsheet.rst
Last active August 29, 2015 14:18
Docker Cheatsheet

Docker Command Line Cheatsheet

# Build image
# -t : tag
# . : current dir
docker build -t username/image_name:tag_name .

# start image in bash
@aaronlelevier
aaronlelevier / textress_example_models.py
Created April 6, 2015 20:24
Example of data models in one of Textress' Apps
import re
from django.db import models
from django.conf import settings
from django.utils.translation import ugettext, ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User
from django.utils.text import slugify
@aaronlelevier
aaronlelevier / yahoo_weather.py
Created April 6, 2015 20:17
Make Yahoo! Weather API call for the weather in Las Vegas
def get_weather(url="http://weather.yahooapis.com/forecastrss?w=12795483&u=f"):
try:
r = requests.get(url)
# parse bytes into a text string
text = r.content.decode("utf-8")
#convert xml text to OrderedDict
doc = xmltodict.parse(text)
# item contains all the main temp info
title = doc['rss']['channel']['title']
condition = doc['rss']['channel']['item']['yweather:condition']
@aaronlelevier
aaronlelevier / Dockerfile-django-postgres
Created April 6, 2015 14:37
Dockerfile for django-postgres-nginx-uswgi
### Docker Commands ###
FROM ubuntu:trusty
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential git python libpq-dev python-dev python-setuptools nginx supervisor
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql postgresql-contrib
RUN easy_install pip
RUN pip install django==1.7.7 pyscopg2 uwsgi
@aaronlelevier
aaronlelevier / split_list.py
Created March 30, 2015 22:16
Split a list using python and reformat it in a single column fomat
'''
To convert zipcodes
-------------------
From the output on: http://www.freemaptools.com/find-zip-codes-inside-radius.htm
to a list of strings to use as a filter in SQL.
Change data initially in this format:
1111,2222,3333
To this format:
@aaronlelevier
aaronlelevier / django_celery_howto.txt
Created December 23, 2014 15:07
Basic setup and install need to get Celery running in Django with Redis
#pip
pip install redis
pip install celery[redis]
pip install django-celery
# redis server
# download here
http://download.redis.io/redis-stable.tar.gz
# follow install instructions here
http://redis.io/topics/quickstart
@aaronlelevier
aaronlelevier / las_vegas_weather.py
Last active August 29, 2015 14:05
Get the current weather for Las Vegas using Yahoo!'s Weather API
import requests
import xmltodict
def get_weather(url="http://weather.yahooapis.com/forecastrss?w=12795483&u=f"):
"""
Get the current weather for Las Vegas using Yahoo!'s Weather API
"""
try:
r = requests.get(url)
# parse bytes into a text string
# ---------------------------- None View Helper Functions ------------------------------------
# Place to save image upload file
def handle_uploaded_file(f):
with open(content_file_name(f), 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
# Attempt Imagefield
def content_file_name(instance, filename):
@aaronlelevier
aaronlelevier / mysql_answer.text
Created August 13, 2014 14:08
MySQL Django settings and config
I currently use Postgres and a Mac for my Django Dev environment. However, when I first started I was using a Windows machine with MySQL. When I looked through my notes just now, it was pretty easy to set up. (I didn't use xampp however). What I installed was:
1. MySQL workbench: http://dev.mysql.com/downloads/workbench/
2. MySQL-python connector - I used pip install for this. So if you have "pip" then it's just:
pip install mysql-python
3. And, this is what my database settings looked like in my settings.py:
DATABASES = {
@aaronlelevier
aaronlelevier / length_validator.py
Created July 22, 2014 16:56
zip code length custom django validator
from django.db import models
from django.core.exceptions import ValidationError
def validate_length(value):
if len(value) != 5:
raise ValidationError('%s is not five digits.' % value)
class MyModel(models.Model):