Skip to content

Instantly share code, notes, and snippets.

View orther's full-sized avatar
🏠
Working from home

Brandon Orther orther

🏠
Working from home
View GitHub Profile
@orther
orther / MusicSearch.php
Created December 3, 2011 19:43
PHP example of using class constants for well defined and easily maintained options.
<?php
class MusicSearch {
// -----------------------------------------------------------------------------------------------------------------
// CONSTANTS
// -----------------------------------------------------------------------------------------------------------------
// categories options
const CATEGORY_ALBUM = 1;
diff --git a/lib/elements/model/database.py b/lib/elements/model/database.py
index a563906..87b9094 100644
--- a/lib/elements/model/database.py
+++ b/lib/elements/model/database.py
@@ -538,11 +538,16 @@ class DatabaseModel:
if key == meta.primary_key or key in meta.model.Meta.read_only:
continue
+ if key == "key":
+ key = "`key`"
server {
   listen      8118;
   server_name website.com www.website.com;
   root        /var/www/website/www;
   expires 1M;
   # route requests to front controller
   location / {
       rewrite ^(.+)$ /index.php?__rlquery=$uri last;
@orther
orther / fizzbuzz.py
Created April 11, 2012 17:02
FizzBuzz
def fuzz_bizz (start, finish, fizz_denominator=3, buzz_denominator=5):
for i in range(start, finish+1):
output = ''
if i % fizz_denominator is 0:
output += "Fizz"
if i % buzz_denominator is 0:
output += "Buzz"
if output is '':
@orther
orther / pip_with_pythonpath
Created March 8, 2013 05:49
-- `pip` for my restricted user This script runs `pip` located in $PYTHONPATH with -t (target dir) set as $PYTHONPATH
#!/bin/bash
PIP="$PYTHONPATH/pip $1"
# add target dir for install and uninstall
[[ "$1" = *install ]] && PIP="$PIP -t $PYTHONPATH"
# remove first arg since it is in $PIP
shift
"-------------------------------------------------------------------------------
" Vim Initial Setup
"-------------------------------------------------------------------------------
" init vim-pathogen
execute pathogen#infect()
set nocompatible
filetype off
@orther
orther / mad-jobs.sh
Created April 9, 2014 09:04
Linux jobs command for parallel processing
# Wait on all child jobs.
function wait_jobs () {
for PID in $(jobs -p); do
notice "Waiting on pid $PID"
wait $PID
done
}
#hdmi_group=2
#hdmi_mode=47
gpu_mem=128
#start_file=start_x.elf
#fixup_file=fixup_x.dat
start_x=1
@orther
orther / Makefile
Last active July 29, 2017 15:33
Example Makefile for Flask app using Chaussette
.PHONY: help db-gen-migration dev-rqworker dev-machine-api dev-frontend dev-api clean clean-pyc clean-build list test test-all test-aws coverage docs release sdist
help:
@echo "clean-build - remove build artifacts"
@echo "clean-pyc - remove Python file artifacts"
@echo "coverage - check code coverage quickly with the default Python"
@echo "db-gen-migration - autogenerate alembic migration"
@echo "dev-admin - start admin http server for development (uses chaussette)"
@echo "dev-api - start api http server for development (uses chaussette)"
@echo "dev-dashboard - start dashboard http server for development (uses chaussette)"
@orther
orther / gist:e305aa4a69f551c390a2
Created July 23, 2014 02:19
SQLAlchemy Argument and Example

This is from a facebood post Mehmet Ali 'mali' Akmanalp. These are two comments written by Mehmet Ali 'mali' Akmanalp:

Matt: so with SQLAlchemy the point is that the ORM is laid on top of this lower level SQL generator, so when the ORM is too specific and you need to fall back, you don't have to concatenate strings and you can generate syntactically correct and safe SQL through code. Check it: http://docs.sqlalchemy.org/en/rel_0_9/core/tutorial.html (scroll down for cooler examples).

Matt: let me give you an example from what I'm working on now. So let's say you have a generic query for fetching monthly aggregated import / export values between countries. Sometimes you want to filter by one country. Sometimes you want to filter by 10 countries. Sometimes you want to use the column containing the inflation-adjusted value instead of the regular column. Sometimes you want the average export instead of the total export.

With a low level abstraction layer, I can do stuff like already_complicated_query.fi