Skip to content

Instantly share code, notes, and snippets.

View nick-brady's full-sized avatar
🎯
Focusing

Nick Brady nick-brady

🎯
Focusing
View GitHub Profile
@nick-brady
nick-brady / reset_migrations.sh
Last active July 28, 2020 18:44
Blow away all Django migrations in Postgres and start over - the easy way
# This file is not meant to be executed. Merely a reference for doing this step by step.
# dump the postgres database (DATA ONLY)
pg_dump --data-only dbname > dump.sql
# Create a new database that will replace your old one
psql -U pguser --password
=# CREATE DATABASE newdb;
@nick-brady
nick-brady / battleship.py
Created April 1, 2018 00:44
A terminal battleship implementation to practice object oriented concepts
from random import randint
from time import sleep
# ALG_DEBUG = True
ALG_DEBUG = False
def blue(string):
return '\x1b[0;34;40m' + string + '\x1b[0m'
def green(string):
@nick-brady
nick-brady / console.py
Last active March 20, 2018 17:51
dumb script for writing the boilerplate javascript to log out the arguments in a function
# python console.py arg1, arg2, arg3, arg4
import sys
def cleanString(string):
if string[-1] == ',':
return string[:-1]
else:
return string
@nick-brady
nick-brady / query-string-parser.js
Created December 20, 2017 19:27
query string parser
/**
* modified code of gist - https://gist.github.com/Manc/9409355
* - newer syntax
* - decodeURIComponent instead of generic decoding function (unescape)
* keys with name name defined after will take priority
*/
export function parseQueryString(location) {
const query = decodeURIComponent(location).trim();
const obj = {};
const qPos = query.indexOf('?');
@nick-brady
nick-brady / python-dijkstras.py
Last active July 17, 2017 19:01
simple Python implementation of Dijkstra's Algorithm
from collections import defaultdict
import math
class DirectedGraph(dict):
"""Create a directed Graph. Root keys contain a dictionary of other nodes they are directed to with
corresponding weight"""
def __missing__(self, key):
value = self[key] = {key: 0} # A keys distance to itself is always 0
return value