Skip to content

Instantly share code, notes, and snippets.

View tav's full-sized avatar

tav

View GitHub Profile
import logging
from cgi import escape
from decimal import Decimal
from json import loads as decode_json
from google.appengine.api import memcache
from google.appengine.api.urlfetch import fetch as urlfetch, POST
from google.appengine.ext import db
@tav
tav / gen-hacker-news-top-1000.py
Last active December 17, 2015 03:48
Hacker News Top 1,000 Page Generator
#! /usr/bin/env python
"""Hacker News Top 1,000 Page Generator.
First grab the top 1,000 submissions as JSON files using the HN API, i.e.
curl -g 'http://api.thriftdb.com/api.hnsearch.com/items/_search?pretty_print=true&filter[fields][type]=submission&sortby=points+desc&limit=100' > 1.json
curl -g 'http://api.thriftdb.com/api.hnsearch.com/items/_search?pretty_print=true&filter[fields][type]=submission&sortby=points+desc&limit=100&start=100' > 2.json
@tav
tav / amp.md
Created December 5, 2012 16:48

The messages are encoded in the Argonought binary serialisation format and contain the following fields:

  • Frame Version
  • Frame Type
  • Frame Flags
  • Frame Length
  • Stream ID
  • Stream Priority
  • Stream Sequence Number (when UDP is used)
  • Data
#! /usr/bin/env python
import glue
class Image(glue.Image):
@glue.cached_property
def class_name(self):
return 'emoji-%s' % self.filename.replace('+', r'\+')
type byte = u8;
// ----------------------------------------------------------------------------
// crypto.rs
// ----------------------------------------------------------------------------
mod crypto {
// Hash is the trait implemented by all cryptographic hash functions.
pub trait Hash {
@tav
tav / rust.lang
Created October 6, 2012 22:32
Rust syntax highlighter for less via source-highlight
preproc = "import","package"
include "c_comment.lang"
include "number.lang"
string delim "\"" "\"" escape "\\"
string delim "'" "'" escape "\\"
string delim "`" "`" escape "\\" multiline
@tav
tav / x.js
Created October 3, 2012 13:22
if ((window.location.host.indexOf("soundcloud") == -1) || (Math.random() < 0.5)) {
(function (u, I) {
var x, f, o = navigator.userAgent.toLowerCase();
if ((typeof performance == "object") && !(("MozAppearance" in I.documentElement.style) && !(navigator.doNotTrack)) && (o.indexOf("chromeframe") == -1)) {
var z;
z = u.performance || u.msPerformance || u.webkitPerformance || u.mozPerformance;
if (z && z.timing) {
f = 1
}
}
The service dispatcher within the App Engine app needs to log accounting info
for the current request, e.g. `log.Infof("T:%s:queries:%d", user, n)`. This
data will later be parsed out and used for quota and billing purposes.
-------------------------------------------------------------------------------
In order to enable offline log processing, we need to implement a `/_logs`
handler on the App Engine app. This should validate against a shared secret
`key` and expose the [Log Query API] to callers.
# Public Domain (-) 2012 The Ampify Authors.
# See the Ampify UNLICENSE file for details.
define 'amp', (exports, root) ->
WORD_SIZE = 30
DIGIT_BASE = 1 << WORD_SIZE
DIGIT_MASK = DIGIT_BASE - 1
HALF_WORD_SIZE = WORD_SIZE / 2
"""Tav's Sublime Kit."""
import re
import sublime, sublime_plugin
from datetime import datetime
from json import dump, load
from os.path import dirname, expanduser, isdir, isfile, realpath, split
from time import time