Skip to content

Instantly share code, notes, and snippets.

View bruth's full-sized avatar

Byron Ruth bruth

View GitHub Profile
@bruth
bruth / jquery-ajax-queue.js
Last active May 3, 2018 06:08
jQuery override to Ajax method to support queuing requests. A deferred object is returned to act as a proxy when the request is actually sent. By default, GET requests are not queued unless the `queue` option is `true`.
(function(root, factory) {
if (typeof define == 'function' && define.amd) {
define(['jquery'], function(jQuery) {
factory(jQuery);
});
} else {
factory(root.jQuery);
}
})(this, function(jQuery) {
@bruth
bruth / gist:2865951
Last active November 19, 2017 20:11
Backbone Sync Queue
# Reference Backbone ajax function
_ajax = Backbone.ajax
requestQueue = []
requestPending = false
sendRequest = (options, promise, trigger=true) ->
options = _.clone options
if trigger
requestPending = true
@bruth
bruth / main.go
Last active November 1, 2017 18:18
package main
import (
"flag"
"fmt"
"log"
"math/rand"
"os"
"os/signal"
"sync"

Transport

This is a Go library that provides a thin, but opinionated abstraction over the go-nats API. The use case is for writing services that use NATS as a transport layer.

The NATS API expects a slice of bytes as the representation of a message. In general, it is often necessary to standardize on a serialization format to simplify designed and interacting with messages.

This library standardizes on Protocol Buffers as the message serialization format and it provides a few conveniences when working with Protobuf messages.

The two main value-add features this library provides are the Transport interface and implementation and the Message type.

package transport
import (
"errors"
"fmt"
"sync"
"time"
"github.com/golang/protobuf/proto"
"github.com/nats-io/go-nats"
@bruth
bruth / doc.md
Last active October 12, 2016 12:45
Concept dependence

Concept Dependence

Concept dependence is best understood using an example.

{
  "mrn": "001",
  "first_name": "John",
  "last_name": "Doe",
  "address": {

Keybase proof

I hereby claim:

  • I am bruth on github.
  • I am byronruth (https://keybase.io/byronruth) on keybase.
  • I have a public key whose fingerprint is 2346 07EB 7539 D135 6581 63F7 C873 29F9 01B2 88C1

To claim this, I am signing this object:

@bruth
bruth / email_based_user.py
Last active January 3, 2016 22:19
Email-based user
from random import choice
from string import ascii_lowercase, digits
from django.db import transaction
from django.db.models import User
USERNAME_CHARS = ascii_lowercase + digits
@transaction.commit_on_success
@bruth
bruth / gist:7467825
Created November 14, 2013 14:33
merge sorted
def merge_sorted(*iterables, **kwargs):
"""Returns a generator that merges N sorted iterables.
An optional `cmp` keyword argument may be supplied to customize the
comparison between values produced by the iterables.
"""
compare = kwargs.get('cmp', cmp)
direction = -1 if kwargs.get('reverse', False) else 1
@bruth
bruth / gist:7467784
Created November 14, 2013 14:30
UNION ALL + semantic graph idea

Notes

  • UNION removes duplicates from the set while UNION ALL does not which makes it much faster
    • Since this technique is being used for data integration, the UNION ALL is the
  • The number of columns must be the same for each select statement
    • A trick to fill in columns is to select a constant value such as null or ''

Example