Skip to content

Instantly share code, notes, and snippets.

View zofrex's full-sized avatar

James 'zofrex' Sanderson zofrex

View GitHub Profile
config.vm.provision 'sync-clock', type: 'shell', path: 'sync-clock.sh', run: 'always'
@zofrex
zofrex / main.rs
Created December 10, 2016 01:46
Code to handle the challenging cases described in https://mortoray.com/2013/11/27/the-string-type-is-broken/
extern crate unicode_segmentation;
extern crate unicode_normalization;
use unicode_segmentation::UnicodeSegmentation;
use unicode_normalization::UnicodeNormalization;
fn main() {
let noel = "noe\u{0308}l";
println!("Input: {}", noel);
println!("Naively reversed: {}", naive_reverse(noel));
println!("Graphemes reversed: {}", grapheme_reverse(noel));
@zofrex
zofrex / Dockerfile
Created November 21, 2016 01:44
Dockerfile for Ocelot
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y g++ \
make \
libboost-all-dev \
libev-dev \
libmysqlclient-dev \
libmysql++-dev
COPY ocelot ocelot/
WORKDIR ocelot
RUN ./configure --with-boost-libdir=/usr/lib/x86_64-linux-gnu --with-ev-lib=/usr/lib/x86_64-linux-gnu --with-mysql-lib=/usr/lib/x86_64-linux-gnu
let listener = TcpListener::bind("0.0.0.0:80");
let listener = match listener {
Ok(r) => r,
Err(_) => std::process::exit(1),
};
unsafe {
libc::setgid(501);
libc::setuid(501);
@zofrex
zofrex / pre-commit
Created May 11, 2016 22:17
A git pre-commit hook to make sure your Rust code is properly formatted and the tests pass, so you never commit bad code
#!/bin/bash
set -eu
check_char='\xE2\x9C\x93'
cross_char='\xE2\x9D\x8C'
green='\033[0;32m'
nc='\033[0m'
check="$green$check_char$nc"
cross="$green$cross_char$nc"
errors=0
set -eux
rm -r ../cargo-out/*
./bootstrap.py --crate-index=/home/zofrex/crates --target-dir=/home/zofrex/cargo-out --no-clone --no-clean --target x86_64-unknown-openbsd --download || true
sed -i"" -e 's/\(\[\[test\]\]\) /\1\
/' ../cargo-out/url-0.5.9/Cargo.toml
sed -i -e 's/^\(miniz-sys.*\), optional = true/\1/' ../cargo-out/flate2-0.2.13/Cargo.toml
set -eux
./bootstrap.py --crate-index=/home/zofrex/crates --target-dir=/home/zofrex/cargo-out --no-clone --no-clean --target x86_64-unknown-openbsd --download || true
sed -i"" -e 's/\(\[\[test\]\]\) /\1\
/' ../cargo-out/url-0.5.9/Cargo.toml
sed -i -e 's/^\(miniz-sys.*\), optional = true/\1/' ../cargo-out/flate2-0.2.13/Cargo.toml
./bootstrap.py --crate-index=/home/zofrex/crates --target-dir=/home/zofrex/cargo-out --no-clone --no-clean --target x86_64-unknown-openbsd --download
# which rustc
which: rustc: Command not found.
# ./rustc-1.8.0/x86_64-unknown-openbsd/stage2/bin/rustc test.rs
./rustc-1.8.0/x86_64-unknown-openbsd/stage2/bin/rustc: can't load library 'libstd-db5a760f.so'
# cd rustc-1.8.0
# gmake install
. . . the usual, full output below ...
# which rustc
/usr/local/bin/rustc
# cd ..
proc is_admin {
user_id
} {
switch $user_id {
1 -
3 -
5 { return true }
default { return false }
}
}
rename if if_old
proc if {
condition
block
} {
if_old {! [expr $condition]} {
uplevel 1 $block
}
}