Skip to content

Instantly share code, notes, and snippets.

View aaronlelevier's full-sized avatar

Aaron Lelevier aaronlelevier

View GitHub Profile
@aaronlelevier
aaronlelevier / text_test_result.py
Created January 27, 2018 02:04
Has friendly test fail header formatting so the test header matches syntax for running a single test
from nose.result import TextTestResult as NoseTextTestResult
class TextTestResult(NoseTextTestResult):
def getDescription(self, test):
"""
Overrides the default test header, so the failed test name
can be copied as is and syntax works to be able to run the
single test "as copied" from this output.
@aaronlelevier
aaronlelevier / pullandpush.sh
Created January 26, 2018 23:21
Rebases the master branch and pushes up local synced branch to remote
pullandpush () {
if [ $# -eq 0 ]
then
echo "branch name not specified"
else
branch=$1
git checkout master
git pull --rebase
git checkout $branch
git rebase origin/master
@aaronlelevier
aaronlelevier / testuntilfail.sh
Created January 26, 2018 01:05
Run Django test until fail Bash function
testuntilfail () {
if [ $# -eq 0 ]
then
echo "Django test path must be specified"
else
RUNS_BEFORE_FAILURE=0
while [ $? = 0 ]; do
let RUNS_BEFORE_FAILURE=RUNS_BEFORE_FAILURE+1
echo "Beginning run number: $RUNS_BEFORE_FAILURE"
./manage.py test $1
@aaronlelevier
aaronlelevier / .gitshortcuts
Created January 10, 2018 18:10
Git Shortcuts
alias gitlog='git log --pretty=format:"%h%x09%an%x09%ad%x09%s"'
alias gs='git status'
alias gd='git diff'
alias gds='git diff --staged'
alias gl='git log'
alias ga='git add'
alias gb='git branch'
alias gc='git commit'
alias gco='git checkout'
alias gpr='git pull --rebase'
@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
@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:
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 / sublime-text-3-snippet-example.md
Created June 28, 2017 14:20
How to create a snippet example in Sublime Text 3
@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:

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.