Skip to content

Instantly share code, notes, and snippets.

@anthonynsimon
anthonynsimon / _document.js
Last active Oct 31, 2020
Panelbear NextJS integration
View _document.js
// 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 Mar 12, 2019
Traduora's Contributor License Agreement
View TraduoaCLA
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 Mar 1, 2019
Elastic Search DSL
View dsl.scala
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 Nov 12, 2018
Deferred, naive implementation of Promises
View Deferred.js
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 Oct 19, 2018
Brainfuck interpreter + program generator
View bf.ts
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 };
View Observable.ts
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> {
View v1.rs
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) {
View 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
View streams.go
package main
import (
"bufio"
"fmt"
"io"
"net"
"strings"
)
View NettyExample.scala
import io.netty.bootstrap.ServerBootstrap
import io.netty.channel.{ChannelOption, ChannelHandlerContext, ChannelInitializer, ChannelInboundHandlerAdapter}
import io.netty.channel.nio.NioEventLoopGroup
import io.netty.channel.socket.SocketChannel
import io.netty.channel.socket.nio.NioServerSocketChannel
import io.netty.channel.group.{ChannelGroup, DefaultChannelGroup}
import io.netty.handler.codec.http.{HttpObjectAggregator, HttpServerCodec}
import io.netty.handler.logging.{LogLevel, LoggingHandler}
import io.netty.channel.ChannelHandler.Sharable
import io.netty.handler.codec.http._