Skip to content

Instantly share code, notes, and snippets.

View aaronlelevier's full-sized avatar

Aaron Lelevier aaronlelevier

View GitHub Profile
@aaronlelevier
aaronlelevier / planned_django_screencast_tips.md
Last active September 12, 2015 12:52
Django tips I'd like to screencast

Django tips I'd like to screencast

  1. ipython / django-extensions
  2. model_mommy
  3. Learn a single text-editor well
  • learning a few extra commands in Sublime-text has made a huge difference
@aaronlelevier
aaronlelevier / postgres.sls
Last active November 5, 2015 23:07
salt postgres state
run-postgresql:
service.running:
- enable: true
- name: postgresql-93
- require:
- pkg: postgresql93
# I keep getting this error ->
@aaronlelevier
aaronlelevier / python_install.sls
Created December 3, 2015 14:34
Trying to install Python 2.7.10 in a Salt State
### previous SLS
install-python-2.7.10-from-tarball:
cmd.run:
- names:
- cd /usr/src
- wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
- tar xzf Python-2.7.10.tgz
- cd Python-2.7.10
- ./configure
- make altinstall
@aaronlelevier
aaronlelevier / charge.py
Last active January 16, 2016 14:19
This python function has a bug, can you find it?
def charge(self, account):
"""
Charge account for the monthly amount. This is triggered by
a monthly cron job.
"""
self.check_balance(account)
amount = settings.MONTHLY_CHARGE
return self.create(account=account, amount=amount)

Got this error when changing a ManyToMany 'through' table name

(django19)[~/Documents/bsrs/bsrs-django/bigsky]$ ./manage.py migrate
Operations to perform:
  Apply all migrations: accounting, category, flatpages, contenttypes, admin, sites, person, ticket, auth, work_request, dtd, third_party, work_order, location, contact, generic, setting, translation, sessions, utils
Running migrations:
  No migrations to apply.
  Your models have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
@aaronlelevier
aaronlelevier / python-example-docstring.md
Created April 21, 2017 17:48
Eample Python docstring from Google's guidlines
def func(x, y, *args, **kwargs):
    """Summary
    
    Parameters:
      x (int) : first parameter
      y: second parameter
        with longer description
        
 Raises:
@aaronlelevier
aaronlelevier / sublime-text-3-snippet-example.md
Created June 28, 2017 14:20
How to create a snippet example in Sublime Text 3
drop database ci_copy;
create database ci_copy with template ci;
\q
drop database ci;
create database ci with template ci_copy;
\q
drop database persistent_copy;
create database persistent_copy with template persistent;
@aaronlelevier
aaronlelevier / la_jolla_tides.py
Created August 15, 2017 14:37
Sample code for requesting La Jolla, CA tide predictions from www.tidesandcurrents.noaa.gov
import requests
import json
url = "https://tidesandcurrents.noaa.gov/api/datagetter?begin_date=20170816&end_date=20170816&station=9410230&datum=MLLW&product=predictions&units=english&time_zone=lst&format=json"
r = requests.get(url, headers=headers)
content = r.content.decode('utf8')
if 'wrong' not in content.lower():
try:
data = json.loads(content)
except Exception:
@aaronlelevier
aaronlelevier / backup-restore-db-functions.sh
Created January 10, 2018 18:08
Bash functions for backing up and restoring any database in PostgreSQL by name
backupdb () {
if [ $# -eq 0 ]
then
echo "db_name not specified"
else
db_name=$1
db_name_copy=${db_name}_copy
psql -c "DROP DATABASE $db_name_copy;"
psql -c "CREATE DATABASE $db_name_copy WITH TEMPLATE $db_name;"
fi