Skip to content

Instantly share code, notes, and snippets.

@kendru
kendru / configure-gcloud-profile.md
Created August 27, 2019 15:52
Configuring a gcloud profile

Configuring a gcloud profile

  1. Create a new profile:
luther:~ ameredith$ gcloud config configurations create my-profile
Created [my-profile].
Activated [my-profile].
  1. Authenticate with Google
@kendru
kendru / visitor.rs
Created July 15, 2019 03:55
Example implementation of the visitor pattern in Rust
pub trait Visitable {
fn accept<V: Visitor>(&self, visitor: &mut V) -> V::Result;
}
pub trait Visitor {
type Result;
fn visit_num(&mut self, num: &Num) -> Self::Result;
fn visit_add<T, U>(&mut self, add: &Add<T, U>) -> Self::Result
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
.editor {
position: absolute;
min-height: 100%;
@kendru
kendru / name-scrubber.js
Last active May 9, 2019 03:58
Removes names from the DOM
// XXHash
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.XXH=r():t.XXH=r()}(this,function(){return function(t){function r(e){if(i[e])return i[e].exports;var o=i[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}var i={};return r.m=t,r.c=i,r.d=function(t,i,e){r.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:e})},r.n=function(t){var i=t&&t.__esModule?function(){return t["default"]}:function(){return t};return r.d(i,"a",i),i},r.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},r.p="",r(r.s=2)}([function(t,r,i){"use strict";(function(t){function e(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(r){return!1}}function o(){return n.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function h(t,r
@kendru
kendru / actix_dispatch_test.rs
Last active October 12, 2018 20:27
Test dispatching command to an Actix actor system
extern crate actix;
extern crate actix_web;
extern crate futures;
use std::thread;
use std::io::{self, Write};
use actix::prelude::*;
use actix_web::{Error as ActixWebError, HttpMessage};
use actix_web::client;
use futures::future::{self, Future};
@kendru
kendru / db.js
Created August 30, 2018 22:59
Simple database that packs records into contiguous memory
const POOL_SIZE = 4 * 1024;
let mySchema = ['int32', 'char(32)', 'int32'];
let bufferPool = new ArrayBuffer(POOL_SIZE);
let dir = {
tbl: {
people: { offset: 0, size: 0 }
}
};
@kendru
kendru / Bucket.js
Created February 23, 2018 15:49
Simple token bucket implementation
class Bucket {
constructor(size, per) {
this.per = per;
this.size = size;
this.lastFilled = Math.floor(Date.now() / 1000);
this.tokens = size;
}
take() {
@kendru
kendru / async-work-queue.js
Created February 9, 2018 23:35
Asynchronous work queue
const promise_ = Symbol('promise');
class Deferred {
constructor() {
this[promise_] = new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
});
}
@kendru
kendru / mysql-sandbox.sh
Last active December 27, 2018 00:40
Set up a throw-away mysql server in docker and a client to connect to it
#!/bin/bash
cleanup_db() {
docker stop mysql_sandbox &>/dev/null
docker rm mysql_sandbox &>/dev/null
docker network inspect mysql_sandbox > /dev/null 2>&1
if [[ "$?" == "0" ]]; then
docker network rm mysql_sandbox
fi
@kendru
kendru / findNode.js
Last active October 31, 2017 22:42
Find a node matching a predicate in a generic JS tree
function findNode(node, pred) {
if (pred(node)) {
return node;
}
if (typeof node == 'object' && node.constructor == Object) {
for (var prop in node) {
if (node.hasOwnProperty(prop)) {
let foundNode = findNode(node[prop], pred);