Skip to content

Instantly share code, notes, and snippets.

View blaix's full-sized avatar

Justin Blake blaix

View GitHub Profile
@blaix
blaix / log.py
Last active November 4, 2016 19:05
# in importer/logging.py
import logging as log
log.basicConfig(filename='importer.log', level=log.WARNING, format='%(message)s')
# everywhere else:
from importer.logging import log
log.warning('used warning so i could look at the log without clutter from other projects')
@blaix
blaix / auth.py
Last active February 23, 2016 21:17
def validate_token(secret, auth_token):
# do the token check logic... (using settings.PARTNER_ID)
def validate_token_from_yola(auth_token):
yola = Yola()
partner = yola.get_partner(settings.PARTNER_ID)
validate_token(partner['shared_secret_key'], auth_token)
@blaix
blaix / gist:669eda5fb305d1cf3cd0
Created January 14, 2016 21:35
service interview questions
Can you describe some of the APIs you've worked on / built?
- why did you make the choices you did?
- how is it tested?
If you had multiple legacy services that you wanted to combine into one new service, can you describe at a high-level how you'd do that?
@blaix
blaix / gist:e87da44be33d8b518470
Last active December 4, 2015 20:14
An argument against an argument against DI

In this article, DHH uses this example:

def publish!
  self.update published_at: Time.now
end

saying DI folks would shiver at hard-coding Time.now and that they would inject a clock or something to more easily test it.

# dumb example object with no dependencies:
class Printer(object):
def println(self, message):
print message
# dumb example object with dependencies:
class Greeter(object):
# can't use it without deciding on a printer
def write(msg):
print msg
class Plugins(object):
plugins = {
'writer': write,
}
@classmethod
def register(cls, name, plugin):
require "liquid"
require "school/great_lesson/page_controller"
require "school/great_lesson/page_repository"
require "school/great_lesson/page_view"
require "school/great_lesson/page_template"
require "school/great_lesson/page_file_db"
require "school/great_lesson/paginator"
require "school/great_lesson/locates_pages_file"
require "school/great_lesson/locates_page_template"
nav = SiteNavigation(site)
nav.as_dict()
nav = SiteNavigation.for_site_id(site_id)
nav.as_dict()
# If this is the interface:
SiteNavigation(site).as_dict()
# that means we have to have a site object to build a site nav object.
# That's fine within the Site object.
# My point was that if (someday in the future) we need to build a nav object but we only have a site id,
# instead of doing this:
@blaix
blaix / models.py
Last active August 29, 2015 14:27
class Site(models.model):
# ...
def get_navigation(self):
return SiteNavigation(self.pages).as_dict()
class SiteNavigation(object):
# ...