Skip to content

Instantly share code, notes, and snippets.

View iolloyd's full-sized avatar
💭
Busy bee

Lloyd Moore iolloyd

💭
Busy bee
View GitHub Profile
@iolloyd
iolloyd / BaseModel.py
Created January 30, 2013 16:41
Non-circular recursive json printer. It's naive since I am sure there are more type cases that it can't handle but it's good enough for the most cases and trivial to extend.
class ModelBase(object):
@declared_attr
def __tablename__(cls):
return cls.__name__.lower()
def get_fields(self, view):
"""Retrieves the fields list defined for the specified view.
"""
if view == 'list_view':
@iolloyd
iolloyd / run_virtual_env.sh
Created February 7, 2013 11:54
automatically activate virtualenv when you cd into a folder
function cd {
builtin cd "$@"
if [ -f "bin/activate" ] ; then
source bin/activate
fi
}
@iolloyd
iolloyd / SpotifyToAHP.scpt
Created February 13, 2013 18:51
update to spotify to audio hijack pro script
(* Script to record and tag spotify tracks, by Lloyd Moore *)
tell application "Spotify"
set currentTrack to (current track)
set trackName to (name of currentTrack)
tell application "Audio Hijack Pro"
set theSession to my getSession()
end tell
repeat
if trackName is not equal to (name of currentTrack) then
@iolloyd
iolloyd / auth.py
Created February 15, 2013 10:01
auth.py
def get_user_by_email(email):
user = g.db.query(User).filter_by(email=email).first()
return user
def check_auth(email, password):
"""This function is called to check if a username /
password combination is valid.
"""
user = get_user_by_email(email)
if not user:
@iolloyd
iolloyd / wiki.go
Created March 28, 2013 09:59
tutorial wiki project using the most awesome 'go' language from the golang site
package main
import (
"html/template"
"io/ioutil"
"net/http"
"regexp"
)
type Page struct {
@iolloyd
iolloyd / delegate_pain.py
Created April 10, 2013 16:28
delegate pain game
from __future__ import absolute_import
from flask import Blueprint, g, request, Response
from administrate.utils.jsonify import jsonify
from administrate.utils.create_filter import create_filter
from administrate.models.mapping import get_model_from_map
from administrate.models.crm.contact import Contact
from administrate.models.system.company import Company
@iolloyd
iolloyd / rebase fix workflow
Created April 10, 2013 16:56
accepting the remote file version during merge conflicts when rebasing
git pull --rebase origin <yourbranch>
... some merge conflict. Let's say the file is called foo/lika.py
git co --theirs foo/lika.py
git add foo/lika.py
git rebase --continue
That's it
@iolloyd
iolloyd / intersection.php
Created April 12, 2013 08:17
intersection finding
<?php
$a = array("a" => "one", "two", "three");
$b = array("b" => "two", "three", "four");
$c = array("c" => "three", "four", "five");
$result = array_intersect($a, $b, $c);
print_r($result);
?>
Array
(
[1] => three
@iolloyd
iolloyd / trace.py
Created August 12, 2013 09:35
trace of error in sqlalchemy
File "/project/s/lib/python2.6/site-packages/sqlalchemy/orm/query.py", line 115, in __init__
2 self._set_entities(entities)
3 File "/project/s/lib/python2.6/site-packages/sqlalchemy/orm/query.py", line 124, in _set_entities
4 self._set_entity_selectables(self._entities)
5 File "/project/s/lib/python2.6/site-packages/sqlalchemy/orm/query.py", line 157, in _set_entity_selectables
6 ent.setup_entity(*d[entity])
7 File "/project/s/lib/python2.6/site-packages/sqlalchemy/orm/query.py", line 2861, in setup_entity
8 self._with_polymorphic = ext_info.with_polymorphic_mappers
9 File "/project/s/lib/python2.6/site-packages/sqlalchemy/util/langhelpers.py", line 612, in __get__
10 obj.__dict__[self.__name__] = result = self.fget(obj)
@iolloyd
iolloyd / sqlParse.py
Last active December 25, 2015 12:49
parses sql dump file into structures containing table name, description and inserts
from pprint import pprint
from string import split, strip
def getMappings(x):
"""
add any tables which have a different name or different
column names in the new database.
Example:
the table 'foo' in the legacy database is called booyaka in