Skip to content

Instantly share code, notes, and snippets.

@adambard
adambard / HLLField.py
Created July 25, 2018 19:20
A Django HLLField (HyperLogLog)
# Presented without warranty, but seems to work ok
from django.db import models
# From https://github.com/ascv/HyperLogLog
from HLL import HyperLogLog
def init_hll(m, seed, bytes=None):
hll = HyperLogLog(m, seed)
@adambard
adambard / grpc.ts
Created September 9, 2017 00:00
React GRPC HOC
import * as jspb from 'google-protobuf'
import { Code, grpc } from 'grpc-web-client'
import React from 'react'
export interface RPCResponseData<TResult, TOwnProps> {
ownProps: TOwnProps
loading: boolean
result: TResult | null
status: Code | null
statusMessage: string
@adambard
adambard / async.fs
Created August 10, 2017 05:28
map, bind, and unit for F# Async
type Microsoft.FSharp.Control.Async with
static member unit (t:'T) : Async<'T> = async { return t }
static member bind (fn:'T -> Async<'U>) (t: Async<'T>) : Async<'U> =
async {
let! input = t
return! fn(input)
}
static member map (fn:'T -> 'U) (t:Async<'T>) : Async<'U> =
async {
let! input = t
@adambard
adambard / stuff.py
Created November 6, 2016 17:38
Stats on new Hearthstone discover cards
import json
import random
import numpy
from collections import namedtuple
## LOAD CARDS
with open("cards.collectible.json") as f:
cards = json.load(f)
cards = [c for c in cards if 'cost' in c and 'text' in c]
@adambard
adambard / Blink.tsx
Last active November 4, 2016 21:17
Blink.tsx
calculatesum=function(html){
//! This function doesn't seem to do anything, since it's only ever called with an element's innerHTML.
var tmp = document.createElement("DIV")
tmp.innerHTML = html
return tmp.textContent||tmp.innerText
}
getColumnCount=function()
{
@adambard
adambard / table.html
Created April 27, 2016 19:57
Make and style an HTML table with column groups
<html>
<head>
<style>
table {
width: 900px;
margin: 0 auto;
border-collapse: collapse;
border: 1px solid;
}
th {
@adambard
adambard / Tapstream.md
Last active May 5, 2016 22:24
Instructions for Tapstream-Segment js integration

Getting Started

Tapstream integrates with Segment to simplify and consolidate tracking of user events.

Tapstream attempts to connect in-browser actions with in-app actions, to provide analytics that cross the browser-app border. So, for browser integrations, both track and page calls will be saved as Tapstream "hits" -- browser-side interactions. In the mobile SDK, track will instead send a Tapstream "event", specifying a mobile app interaction.

Browser Integration Instructions

@adambard
adambard / tapstream_logo.svg
Created April 26, 2016 22:02
Tapstream Logo SVG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
url = require('url')
http = require('http')
https = require('https')
r = require('readability-node')
jsdom = require('jsdom').jsdom
function handleRequest(request, response){
var uri = url.parse(request.url, true).query.url;
uri = url.parse(uri || "https://medium.com/@mbostock/what-makes-software-good-943557f8a488")
https.get(uri, function(res){