Skip to content

Instantly share code, notes, and snippets.

James 'zofrex' Sanderson zofrex

  • London, UK
View GitHub Profile
View Vagrantfile
config.vm.provision 'sync-clock', type: 'shell', path: 'sync-clock.sh', run: 'always'
@zofrex
zofrex / main.rs
Created Dec 10, 2016
Code to handle the challenging cases described in https://mortoray.com/2013/11/27/the-string-type-is-broken/
View main.rs
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 Nov 21, 2016
Dockerfile for Ocelot
View Dockerfile
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
View httpd.rs
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
A git pre-commit hook to make sure your Rust code is properly formatted and the tests pass, so you never commit bad code
View pre-commit
#!/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
View 0-bootstrap.sh
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
View bootstrap.sh
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
View 00-summary
# 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 ..
View test2.tcl
proc is_admin {
user_id
} {
switch $user_id {
1 -
3 -
5 { return true }
default { return false }
}
}
View test.tcl
rename if if_old
proc if {
condition
block
} {
if_old {! [expr $condition]} {
uplevel 1 $block
}
}
You can’t perform that action at this time.