Skip to content

Instantly share code, notes, and snippets.

@anthonynsimon
anthonynsimon / aiohttp_trace.py
Last active September 14, 2023 11:51
aiohttp tracing
import aiohttp
def request_tracer(results_collector):
"""
Provides request tracing to aiohttp client sessions.
:param results_collector: a dict to which the tracing results will be added.
:return: an aiohttp.TraceConfig object.
:example:
@anthonynsimon
anthonynsimon / _document.js
Last active October 31, 2020 11:33
Panelbear NextJS integration
// MIT License
// Copyright (c) 2020 Anthony N. Simon
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@anthonynsimon
anthonynsimon / TraduoaCLA
Last active March 12, 2019 13:06
Traduora's Contributor License Agreement
Contributor License Agreement (CLA)
This license is for your protection as a Contributor as well as the protection of the maintainers of the Traduora software; it does not change your rights to use your own Contributions for any other purpose. In the following, the maintainers of Traduora are referred to as Traduora.
You accept and agree to the following terms and conditions for Your present and future Contributions submitted to Traduora. Except for the license granted herein to Traduora and recipients of software distributed by Traduora, You reserve all right, title, and interest in and to Your Contributions.
1. Definitions.
“You” (or “Your”) shall mean the copyright owner or legal entity authorized by the copyright owner that is making this Agreement with Traduora. For legal entities, the entity making a Contribution and all other entities that control, are controlled by, or are under common control with that entity are considered to be a single Contributor. For the purposes of this definition, “con
@anthonynsimon
anthonynsimon / dsl.scala
Created March 1, 2019 10:00
Elastic Search DSL
import scala.collection.JavaConverters._
import com.fasterxml.jackson.databind.node._
import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper}
import scala.language.implicitConversions
object JacksonDSL {
object ObjectNode {
@anthonynsimon
anthonynsimon / Deferred.js
Last active November 12, 2018 15:16
Deferred, naive implementation of Promises
class Deferred {
constructor(resolver) {
this._result;
this._error;
this._ready = false;
this._callbacks = [];
if (resolver) {
resolver(this.resolve.bind(this), this.reject.bind(this));
}
@anthonynsimon
anthonynsimon / bf.ts
Last active October 19, 2018 11:54
Brainfuck interpreter + program generator
import chalk from 'chalk';
import * as fs from 'fs';
import * as term from 'terminal-kit';
function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
namespace BF2 {
type TraceId = { traceId: number };
@anthonynsimon
anthonynsimon / Observable.ts
Created August 13, 2018 15:48
Observables
type Callback<A> = (value: A) => void;
class Observable<A> {
private subscribers: Callback<A>[] = [];
next(value: A): void {
this.subscribers.forEach(fn => fn(value));
}
map<B>(mapper: (_: A) => B): Observable<B> {
@anthonynsimon
anthonynsimon / v1.rs
Created August 9, 2018 18:00
rust two ways
use std::collections::HashMap;
#[derive(Hash, Eq, PartialEq, Debug)]
struct Item {
rank: u32,
revision: u32,
}
fn should_insert(item: &Item, acc: &HashMap<u32, Item>) -> bool {
match acc.get(&item.rank) {
@anthonynsimon
anthonynsimon / Pipelines.scala
Created July 26, 2018 13:05
Pipelines.scala
import scala.collection.mutable
trait Source[+A] {
def output(): A
}
trait Flow[A, B] extends Sink[A] with Source[B]
trait Sink[-A] {
def input(a: A): Unit
package main
import (
"bufio"
"fmt"
"io"
"net"
"strings"
)