Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# EXAMPLE: crev-truster.sh BurntSushi matklad
cd /tmp
for USER in "$@"; do
git clone https://medwards:$GITHUB_TOKEN@github.com/$USER/crev-proofs.git tmp-crev-proofs 2> /dev/null
TRUST_ID=`ls -d tmp-crev-proofs/*/reviews 2> /dev/null | cut -d'/' -f2`
if [ -n "$TRUST_ID" ]; then
@medwards
medwards / walker.rs
Last active August 10, 2021 21:04
Example lifetime problem
struct RepositoryHolder {
repository: std::rc::Rc<git2::Repository>,
}
impl RepositoryHolder {
fn commits(&self) -> impl Iterator<Item = git2::Commit> {
let repo = self.repository.clone();
self.walker()
.flat_map(move |oid| repo.find_commit(oid.expect("Revwalk didn't get oid")))
// maybe I want to filter the commits by whether they touched a path:
set noswapfile
syntax enable
filetype plugin indent on
" rust.vim
" git clone https://github.com/rust-lang/rust.vim ~/.vim/pack/plugins/start/rust.vim
let g:rustfmt_autosave = 1
" kotlin-vim
" git clone https://github.com/udalov/kotlin-vim.git ~/.vim/pack/plugins/start/kotlin-vim

Xmonad + Gnome integration for Ubuntu 19.10

The guide at https://wiki.haskell.org/Xmonad/Using_xmonad_in_Gnome#Ubuntu is increasingly out of date and was already pretty flaky by Ubuntu 16-18. This guide is for Ubuntu 19.10.

I'll try to include some additional context for whats going on so that when things change again it should hopefully not leave you completely lost.

What I want (AKA you can ignore this if your response isn't "Just don't use xmonad + gnome")

BASELINE (NO TRIMMING)
running 34 tests
test count_game_deserialize_borrowed_bytes ... bench: 15,067,145 ns/iter (+/- 549,500) = 172 MB/s
test count_game_deserialize_borrowed_str ... bench: 10,969,616 ns/iter (+/- 388,855) = 237 MB/s
test count_game_deserialize_owned_bytes ... bench: 29,264,088 ns/iter (+/- 939,824) = 88 MB/s
test count_game_deserialize_owned_str ... bench: 25,742,820 ns/iter (+/- 439,986) = 100 MB/s
test count_game_iter_bytes ... bench: 13,310,272 ns/iter (+/- 415,833) = 195 MB/s
test count_game_iter_str ... bench: 15,788,007 ns/iter (+/- 982,664) = 164 MB/s
test count_game_read_bytes ... bench: 7,129,372 ns/iter (+/- 1,590,015) = 364 MB/s
test count_game_read_str ... bench: 8,459,162 ns/iter (+/- 494,247) = 307 MB/s
use std::cmp::PartialOrd;
fn largest<T: PartialOrd + Copy>(list: &[T]) -> T {
let mut largest = list[0];
for &item in list.iter() {
if item > largest {
largest = item;
}
}
import urlparse
host = 'http://example.com'
endpoint = 'endpoint'
thing_id = 226
print "naive urljoin: ", urlparse.urljoin(host, endpoint, thing_id)
print "less naive urljoin: ", urlparse.urljoin(urlparse.urljoin(host, endpoint), str(thing_id))
print "ugly working urljoin: ", urlparse.urljoin(host, "%s/%s" % (endpoint, thing_id))
"""
@medwards
medwards / expected
Created October 24, 2014 09:45
Expected GOES FIRST
from nose.tools import assert_equals # pip install nosetests
assert_equals("first", "second")
# Nothing fancy here, just default string comparison
# AssertionError: 'first' != 'second'
# Lets compare a dictionary
assert_equals({'a': 'foo'}, {'a': 'bar'})
# This produces a cool little diff
# AssertionError: {'a': 'foo'} != {'a': 'bar'}
@medwards
medwards / mock_helpers.py
Last active August 29, 2015 14:05
Helps mock the open context manager (or any contextmanager!) and does some doublechecking that the mock was used properly
from contextlib import contextmanager
from nose.tools import assert_equals
from mock import patch, Mock
from StringIO import StringIO
@contextmanager
def mock_io_open(content, *args):
stream = StringIO(content)
with mock_context_manager('io.open', stream, *args) as mock:
yield mock
@medwards
medwards / JAVA_TODO.md
Last active December 22, 2015 19:49
JAVA_THINGS_TODO.md

Objective

Zero Eclipse Development (ZED)

ctags

In .vimrc:
autocmd FileType java set tags=tags,~/.tags_java