Skip to content

Instantly share code, notes, and snippets.

@squirly
squirly / 1.machine_services.yml
Last active July 22, 2016 23:11
Using docker with CircleCI
machine:
services:
- docker
@squirly
squirly / 1a. Bucket structure
Created July 21, 2016 18:17
Code samples for blogpost
|- dist
| |- branch
| |- commit
| |- production
|- files
@squirly
squirly / 1a. Initial Middleware.go
Last active July 20, 2016 01:07
post: golang context and di
func AddMessageMiddleware(message string, next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
oldCtx := nil // Get context from request
newCtx := oldCtx // modify context
next.ServeHTTP(w, r) // pass request to child handler
})
}
@squirly
squirly / user-server.go
Last active July 15, 2016 18:48
Mock dependency implementations for blog post example. Copy and paste from the blog post to complete
package main
import (
"net/http"
"fmt"
"errors"
"context"
)
// mock implementations
@squirly
squirly / using-context.go
Created July 11, 2016 23:32
Golang net/http Context and Dependency Injection
package main
import (
"context"
"net/http"
)
func main() {
helloHandler := AddMessageMiddleware("Hello!", http.HandlerFunc(RespondWithMessage))
goodbyeHandler := AddMessageMiddleware("Goodbye!", http.HandlerFunc(RespondWithMessage))
@squirly
squirly / 1Factory.js
Last active August 29, 2015 14:19
Van AngularJs April Presentation Demos
"use strict";
angular.module('myModule', []).
factory('User', [function () {
function User (data) {
angular.extend(this, data);
}
User.prototype.getFullName = function () {
@squirly
squirly / gist:4716577
Last active December 12, 2015 04:48
A Python decorators example
from functools import wraps
def cache(func):
func.cache = None
@wraps(func)
def inner(*a, **k):
if func.cache is None:
func.cache = func(*a, **k)
return func.cache
return inner
@squirly
squirly / lazy_class.py
Created November 28, 2012 02:44
An inheritable lazy class with argument attachment.
def import_class(import_string, *a, **k):
module, klass = import_string.rsplit('.', 1)
def combine_args_kwargs(args, kwargs):
new_args = a + args
new_kwargs = k.copy()
new_kwargs.update(kwargs)
return new_args, new_kwargs
def load_class():
@squirly
squirly / An Intro.rst
Last active October 12, 2015 22:38
Sailbot Workshop

I will be using this Gist throughout the presentation as a paste bin and to document some important notes.

After the presentation and throughout the workshop I will add additional content as questions are asked.

@squirly
squirly / repl.py
Created November 14, 2012 16:38
REPL
print('Tyler\'s python implementation of REPL.\n')
while True:
# Read - Get user input
read_value = raw_input('Ty\'s PyREPL >>> ')
# Eval - Run user input
try:
try:
out = eval(read_value)
except SyntaxError: