Skip to content

Instantly share code, notes, and snippets.

View koblas's full-sized avatar

David Koblas koblas

View GitHub Profile
@koblas
koblas / smtp.py
Created November 11, 2011 15:23
SMTP Client for Tornado
from tornado import ioloop
from tornado import iostream
import socket
class Envelope(object):
def __init__(self, sender, rcpt, body, callback):
self.sender = sender
self.rcpt = rcpt[:]
self.body = body
self.callback = callback
@koblas
koblas / gist:1436076
Created December 6, 2011 00:25
backbone portfolio
<!--
Looking for some code reviews and commentary on this backbonejs application.
-->
<div class="content">
<table class="portfolio">
<thead>
<tr><th></th><th>Symbol</th><th>Name</th><th>Shares</th><th>% of portfolio value</th></tr>
</thead>
@koblas
koblas / trie.py
Created June 4, 2012 18:40
Simple Priority Trie implementation in Python
class trie(object):
MAX_SUGGEST = 10
__slots__ = ('children', 'freq', 'name', '_top')
def __init__(self):
self.children = defaultdict(trie)
self.freq = 0
self.name = None
self._top = None
@koblas
koblas / backbone-filtered-collection.js
Created June 26, 2012 14:03
Filtered Collection Wrapper For Backbone
(function(_, Backbone) {
var defaultFilter = function() {return true;};
/**
* This represents a filtered collection. You can either pass a filter or
* invoke setFilter(filter) to give a filter. The filter is identical to
* that which is used for _.select(array, filter)
*
* false filter indicates no filtering.
*
@koblas
koblas / gist:3136961
Created July 18, 2012 15:35 — forked from zmaril/gist:3136483
Puma.com source code
(function (E, B) {
function ka(a, b, d) {
if (d === B && a.nodeType === 1) {
d = a.getAttribute("data-" + b);
if (typeof d === "string") {
try {
d = d === "true" ? true : d === "false" ? false : d === "null" ? null : !c.isNaN(d) ? parseFloat(d) : Ja.test(d) ? c.parseJSON(d) : d
} catch (e) {}
c.data(a, b, d)
} else d = B
@koblas
koblas / echo.cxx
Created August 15, 2012 22:46
libev c++ echo server
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <ev++.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <resolv.h>
#include <errno.h>
#include <list>
@koblas
koblas / aws.py
Created October 23, 2012 18:19
Not caching Exceptions
import logging
from addons.route import route
from .base import BaseHandler
from amazonproduct.api import API, NoExactMatchesFound, TooManyRequests
from tornado import httpclient
from tornado.web import asynchronous, HTTPError
from tornado import gen
from app.util.cache import LRUCache
from StringIO import StringIO
@koblas
koblas / openvpn.cf
Created March 28, 2017 12:08
OpenVPN Cloudformation template
{
"Description": "EC2 OpenVPN host for stage-railz",
"Mappings": {
"AmiMap": {
"us-east-1": {
"bastion": "ami-2757f631",
"ecs": "ami-b2df2ca4",
"ubuntu1604": "ami-2757f631"
},
"us-west-2": {
@koblas
koblas / user_service.go
Created July 30, 2018 18:30
GraphQL user_update code separation
// UpdateUser save user updates to the DB
func (svc *userService) UpdateUser(ctx context.Context, user *model.User, args UpdateUserInput) (*model.User, error) {
update := make(map[string]interface{})
if args.Password != nil {
user.HashPassword(*args.Password)
update["password"] = user.Password
}
if args.Name != nil && *args.Name != user.Name {
update["name"] = *args.Name
@koblas
koblas / wrap_graphql.go
Last active August 3, 2018 13:35
graphql-go/graphql wrapper for unmarshaling
package nresolver
import (
"reflect"
"strings"
"github.com/asaskevich/govalidator"
"github.com/graphql-go/graphql"
"github.com/mitchellh/mapstructure"
)