Skip to content

Instantly share code, notes, and snippets.

View jessedhillon's full-sized avatar

Jesse Dhillon jessedhillon

View GitHub Profile
@jessedhillon
jessedhillon / formatter.py
Created November 15, 2020 20:22
TTY aware color formatting without duplication of stream definition
from colorlog import ColoredFormatter
class TogglingColoredFormatter(ColoredFormatter):
"""
Blanks all color codes if not running under a TTY.
This is useful when you want to be able to pipe colorlog output to a file.
"""
@jessedhillon
jessedhillon / histogram.sql
Created June 9, 2018 16:59
postgresql histogram
--- credit: https://tapoueh.org/blog/2014/02/postgresql-aggregates-and-histograms/
with drb_stats as (
select min(drb) as min,
max(drb) as max
from team_stats
),
histogram as (
select width_bucket(drb, min, max, 9) as bucket,
int4range(min(drb), max(drb), '[]') as range,
@jessedhillon
jessedhillon / async_unittest.py
Created December 30, 2017 23:49
Python3 unittest.TestCase with asyncio support
import asyncio
import unittest
def immediately(coro):
f = lambda self, *args, **kwargs: self.loop.run_until_complete(coro(self, *args, **kwargs))
f.__name__ = coro.__name__
return f
@jessedhillon
jessedhillon / makertime-calendar.html
Last active September 14, 2019 14:43
MakerTime visual calendar
<html>
<head>
<style type="text/css">
body {
font-family: -apple-system, BlinkMacSystemFont, San Francisco, Roboto, Segoe UI, Helvetica Neue, sans-serif
}
#clock {
display: flex;
flex-flow: column;
@jessedhillon
jessedhillon / twitch-transcript.html
Created August 27, 2016 08:19
Transcript of Twitch co-founder Emmett Shear's interview with Andrew Warner
<html><head><meta content="text/html; charset=UTF-8" http-equiv="content-type"><style type="text/css">ol{margin:0;padding:0}table td,table th{padding:0}.c3{background-color:#ffffff;max-width:468pt;padding:72pt 72pt 72pt 72pt}.c0{orphans:2;widows:2}.c1{height:11pt}.c2{font-weight:700}.title{padding-top:0pt;color:#000000;font-size:26pt;padding-bottom:3pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}.subtitle{padding-top:0pt;color:#666666;font-size:15pt;padding-bottom:16pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}li{color:#000000;font-size:11pt;font-family:"Arial"}p{margin:0;color:#000000;font-size:11pt;font-family:"Arial"}h1{padding-top:20pt;color:#000000;font-size:20pt;padding-bottom:6pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h2{padding-top:18pt;color:#000000;font-size:16pt;padding-bottom:6pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;o
@jessedhillon
jessedhillon / shift_float.c
Created February 1, 2016 22:03
FP bit manipulation
/*
* $ gcc shift_float.c
* $ a.out
*/
#include <stdio.h>
void main() {
float f = 3.0;
long l;
@jessedhillon
jessedhillon / main.js
Created January 14, 2015 03:52
Printing squares in a loop
// 1. Prompt user for a number, n
// 2. Print the square of every number between 0 and n
var number = parseInt(prompt("Give me a number")); // prompt is a built-in function
for(var i = 0; i <= number; i++) {
console.log(i * i);
}
@jessedhillon
jessedhillon / calc.js
Last active August 29, 2015 14:13
Calculator example
var number1 = parseFloat(prompt("Enter the first number"));
var number2 = parseFloat(prompt("Enter the second number"));
var operation = prompt("Choose one of +, -, *, /")
var result;
if(operation == "+") {
result = number1 + number2;
} else if(operation == "-") {
result = number1 - number2;
} else if(operation == "*") {
@jessedhillon
jessedhillon / iconbox.html
Created January 7, 2015 04:11
Images, icons and boxes
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="icon-box left-icon width-2">
<div class="icon">
<img src="http://placehold.it/48x48">
@jessedhillon
jessedhillon / style.css
Created January 7, 2015 04:08
Submenu example
#menubar {
position: absolute;
top: 300px;
left: 300px;
width: 500px;
background: #aaa;
}
.menu {
margin: 0;