Skip to content

Instantly share code, notes, and snippets.

Install

Install dependencies:

sudo apt install clang build-essential git

Install the UASM assembler from source:

@kwarrick
kwarrick / enum_statemachine.rs
Created April 16, 2019 20:40
State machine using enums in Rust
#[derive(Debug)]
enum State {
New(Option<String>),
Running(String),
Failure(Box<State>),
}
enum Event {
Open(String),
Run,
@kwarrick
kwarrick / benchmark.yml
Created January 22, 2019 21:30
mmo-rust-server artillery script
config:
target: "ws://127.0.0.1:8080/"
phases:
- duration: 30
arrivalRate: 5
name: "Easy start"
- duration: 60
arrivalRate: 5
rampTo: 100
name: "Ramping up"
@kwarrick
kwarrick / lib.rs
Last active August 25, 2018 03:04
Neon example of shared state.
use std::sync::Arc;
use std::sync::RwLock;
use std::collections::HashMap;
#[macro_use]
extern crate neon;
use neon::prelude::*;
pub struct Increment {
key: String,
@kwarrick
kwarrick / tmux_local_install.sh
Created November 13, 2017 03:54 — forked from ryin/tmux_local_install.sh
bash script for installing tmux without root access
#!/bin/bash
# Script for installing tmux on systems where you don't have root access.
# tmux will be installed in $HOME/local/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# exit on error
set -e
TMUX_VERSION=1.8
@kwarrick
kwarrick / coalesce.ml
Last active August 29, 2015 14:06
Coalesce a list of overlapping and adjacent start/end tuples.
open Core.Std
(**
* Coalesce a list of overlapping and adjacent start/end tuples.
*
* let ranges = [(2,3); (1,2); (5,11); (4,10); (3,3)];;
* coalesce_ranges ranges;;
* - : (int * int) list = [(1, 11)]
**)
let coalesce_ranges ?(cmp=compare) ranges =
@kwarrick
kwarrick / timesink-calendar.html
Last active December 25, 2015 07:59
Create a d3 'Calendar View' display of hours spent on the computer from a Time Sink CSV export.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Time Sink Calendar View</title>
<script src="moment.min.js"></script>
<script src="d3.v3.min.js"></script>
<style>
body {
@kwarrick
kwarrick / map-reduce-csv.py
Last active December 18, 2015 05:59
Map-reduce a CSV file using UNIX sort utility in just 24 lines of code.
#!/usr/bin/env python
# kwarrick@uga.edu
import csv
import subprocess
from itertools import groupby
def identity(infile, outfile):
def key(row):
return row[0]
@kwarrick
kwarrick / fncache.py
Last active March 25, 2023 01:28
Redis-backed LRU cache decorator in Python.
#!/usr/bin/env python
__author__ = 'Kevin Warrick'
__email__ = 'kwarrick@uga.edu'
import cPickle
from functools import wraps
def redis_lru(capacity=5000, slice=slice(None)):
"""
Simple Redis-based LRU cache decorator *.