Skip to content

Instantly share code, notes, and snippets.

View theho's full-sized avatar

James Ho theho

View GitHub Profile
'use strict';
/**
* This module monitors angularFire's authentication and performs actions based on authentication state.
* directives/directive.ngcloakauth.js depends on this file
*
* Modify ng-cloak to hide content until FirebaseSimpleLogin resolves. Also
* provides ng-show-auth methods for displaying content only when certain login
* states are active.
*
# turn dict into an object that allows access to nested keys via dot notation
# from http://stackoverflow.com/questions/3797957/python-easily-access-deeply-nested-dict-get-and-set
# made three modifications:
# --added `get()` method
# --added `if not dict.__contains__...` to `__contains__()`
# --can now accept None as key
# JHO:
# --updated prints and Exceptions to be python3 friendly
# https://gist.github.com/einnocent/8854896
class dotdictify(dict):
/**
* Responsive mixin. The media breakpoints are as defined
* in the twitter bootstrap framework:
*
* - phone
* - tablet-portrait
* - tablet-landscape-desktop
* - large-desktop
*
* Additional parameters for tagetting retina and non-retina
// Add percentage of white to a color
@function tint($color, $percent){
@return mix(white, $color, $percent);
}
// Add percentage of black to a color
@function shade($color, $percent){
@return mix(black, $color, $percent);
}
@theho
theho / satellizer.User.py
Created May 18, 2015 10:29
satellizer User model using @hydbrid_property
# Original file https://github.com/jimmyho/satellizer/blob/master/examples/server/python/app.py
from sqlalchemy.ext.hybrid import hybrid_property
class User(db.Model):
_password = db.Column('password', db.String(120))
# ... etc ...
@hybrid_property
@theho
theho / FlaskAppFormatter.py
Last active August 29, 2015 14:21
Log Formatter for Flask to trim pathname relative to app_root
# app is flask app object
class FlaskAppFormatter(logging.Formatter):
def format(self, record):
if record.pathname and record.pathname.startswith(app.root_path):
record.pathname = record.pathname.lstrip(app.root_path)
return super(FlaskAppFormatter, self).format(record)
@theho
theho / q_chain.py
Created May 20, 2015 00:07
Methon chaining inspired by $q / Q in Javascript
# Inspired by $q/Q in javascript to chain methods
class Q:
def __init__(self, d):
self.d = d
self.error = None
def then(self, fn):
if not self.error:
try:
@theho
theho / backend-architectures.md
Created October 6, 2015 13:13 — forked from ragingwind/Backend Architectures Keywords and References.md
Backend Architectures Keywords and References. #wiki
"""
Single Node Cassandra/Spark using pySpark
"""
import os
import sys
SPARK_HOME = "/Users/jimmy/dev/spark"
os.environ['SPARK_HOME'] = SPARK_HOME
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
#
auth_provider = PlainTextAuthProvider(
username='jimmy', password='??????')
cluster = Cluster(contact_points=['dse1'], auth_provider=auth_provider)
session = cluster.connect()
#