This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// It is possible to add golang interfaces together. | |
// But did you know that you can also subtract them? | |
// Here are two arbitrary interfaces. They can have any | |
// methods. | |
type A interface { | |
Foo() string // This is the conflicting method signature. | |
Bar() int | |
} | |
type B interface { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> create table t ( | |
-> id integer primary key, | |
-> val json | |
-> ); | |
Query OK, 0 rows affected (0.04 sec) | |
mysql> insert into t(id, val) values (1, '{"a": 1}'), (2, '{"a": "two"}'); | |
Query OK, 2 rows affected (0.00 sec) | |
Records: 2 Duplicates: 0 Warnings: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
class NaryHeap(object): | |
"""implements an n-ary heap""" | |
def __init__(self, items=(), *, n=2, direction=min): | |
""" | |
create a new heap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// All arguments must be BigInts. Return value is a BigInt or a thrown RangeError | |
const bigH = (n, a, b) => { | |
let result = 0n | |
const stack = [{n, a, b}] | |
do { | |
const {n, a, b} = stack.pop() | |
if (n < 0n || a < 0n || b < 0n) { | |
throw Error('Can only hyperoperate on non-negative integers') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define ALIGNED __attribute__((aligned(32))) | |
// There are three structs, Foo, Bar, and Baz, each with a 20 byte field. | |
// Bar and Baz are annotated with an 'aligned' attribute of 32 bytes, but | |
// in slightly different ways. | |
typedef struct { | |
char a[20]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import Thread | |
import requests | |
from multithreading import Channel | |
def fetch_all_with_pool(iterable_of_urls, pool_size=20): | |
""" | |
Fetches URLs with a thread pool. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
"""Lazy hacks to enable easier usage of async functions, context managers, and iterators in the REPL.""" | |
from asyncio import set_event_loop | |
try: | |
import uvloop as loop_maker | |
except ImportError: | |
import asyncio as loop_maker | |
loop = loop_maker.new_event_loop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
from collections import Mapping, Iterable | |
from operator import attrgetter | |
from struct import pack, unpack | |
__doc__ = """ | |
Pure python tools for inspecting unknown protobuf data. Written for py3.6+. | |
Author: Kent Ross |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
from collections import deque | |
from queue import Empty, Full | |
from threading import Condition, RLock, Thread | |
from time import monotonic as now | |
from weakref import finalize | |
class ChannelClosed(Exception): | |
"""Exception raised when a channel has been closed.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* powers of 2 utility view for heap traversal */ | |
CREATE VIEW IF NOT EXISTS power2 AS | |
WITH RECURSIVE doubling(n) AS ( | |
VALUES (2) | |
UNION ALL | |
SELECT n*2 FROM doubling LIMIT 62 | |
) | |
SELECT n twos FROM doubling; | |
/* generates random floating point values in interval [0, 1) */ |
NewerOlder