Skip to content

Instantly share code, notes, and snippets.

View stevej's full-sized avatar

Steve Jenson stevej

View GitHub Profile
@stevej
stevej / gist:3868225
Created October 10, 2012 20:29 — forked from anonymous/gist:3868185
Queue Anti-patterns (an argument in DMs)
I can make a case that queues only do what people want if you don’t consider failure cases.
Qs are empty (normal) or full (fail). Normally things are processed quickly. Failure case processing time is unbounded (or “too long”).
Solution is always “dump the Q”. Which means you do care about how long it takes to process items. So you want the queue to always be empty
Which means you only want a non-failing Q.
So why not admit it, use in-proc buffers, run enough servers to handle load? Reject work up front instead of dropping oldest items w/…
@stevej
stevej / board_searcher.rb
Created November 2, 2012 22:28
Letterpress board searcher
#/usr/bin/env ruby
# A brute-force letterpress board searcher. It takes about 90 seconds to search a board.
#
# Good uses: train on your vocabulary with boards you lost on.
#
# LAZY AND STUPID CHEATERS: DO NOT USE THIS FOR CHEATING. CHEATERS NEVER WIN.
class BoardSearcher
attr_reader :board
@stevej
stevej / lazy.rs
Created December 6, 2012 04:57
Thunks in Rust
use core::option;
/**
* Implementation of thunks in Rust.
*/
pub struct Lazy<T> {
code : @fn() -> T,
mut value : Option<T>
}
@stevej
stevej / divis.c
Last active August 29, 2015 14:04
Epiphany-III disassembly for division
int main(void) {
// unsigned is not much better
int i = 3;
int j = 7;
double k = i / j;
return k;
}
/Users/stevej/src/CutieBaby/CutieBaby/GameScene.swift:12:6: error: unimplemented IR generation feature non-fixed multi-payload enum layout
enum Tree<T>:TreeLike {
^
0 swift 0x0000000101e6f028 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x0000000101e6f514 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff89c395aa _sigtramp + 26
3 libsystem_platform.dylib 000000000000000000 _sigtramp + 1983670896
4 swift 0x0000000101ce7290 llvm::ConstantFoldGetElementPtr(llvm::Constant*, bool, llvm::ArrayRef<llvm::Value*>) + 112
5 swift 0x0000000101cef6f3 llvm::ConstantExpr::getGetElementPtr(llvm::Constant*, llvm::ArrayRef<llvm::Value*>, bool) + 51
6 swift 0x0000000101252c0b llvm::IRBuilder<true, llvm::ConstantFolder, llvm::IRBuilderDefaultInserter<true> >::CreateConstInBoundsGEP2_32(llvm::Value*, unsigned int, unsigned int, llvm::Twine const&) + 123
BigEasy% pwd
/Users/stevej/local/src/rust-sdl2
BigEasy% cargo clean
BigEasy% cargo build
Compiling pkg-config v0.1.3
/Users/stevej/.cargo/registry/src/github.com-1ecc6299db9ec823/pkg-config-0.1.3/src/lib.rs:62:24: 62:43 error: the trait `core::marker::Sized` is not implemented for the type `str`
/Users/stevej/.cargo/registry/src/github.com-1ecc6299db9ec823/pkg-config-0.1.3/src/lib.rs:62 .collect::<Vec<_>>();
^~~~~~~~~~~~~~~~~~~
/Users/stevej/.cargo/registry/src/github.com-1ecc6299db9ec823/pkg-config-0.1.3/src/lib.rs:62:24: 62:43 error: the trait `core::marker::Sized` is not implemented for the type `str`
/Users/stevej/.cargo/registry/src/github.com-1ecc6299db9ec823/pkg-config-0.1.3/src/lib.rs:62 .collect::<Vec<_>>();
@stevej
stevej / playground.rs
Created January 8, 2017 21:24 — forked from anonymous/playground.rs
Shared via Rust Playground
// In Rust, much like Go, you organize functions around structs.
#[derive(Debug)]
struct Person {
id: u64,
name: String,
twitter_handle: String
}
// Here we hang a function off of a struct.
impl Person {
@stevej
stevej / lesson1.rs
Last active January 9, 2017 17:27
Rust for the Experienced Programmer. Lesson 1: The Basics
// In Rust, much like Go, you organize functions around structs.
#[derive(Debug)]
struct Person {
id: u64,
name: String,
twitter_handle: String
}
// Here we hang a function off of a struct.
impl Person {
@stevej
stevej / lesson2.rs
Created January 8, 2017 22:50
Rust for the Experienced Programmer. Lesson 2: references vs values
#[derive(Debug)]
struct Person {
id: u64,
name: String,
}
impl Person {
// Because we're passing a value, we take ownership of it. If we want to give
// ownership back, we have to return it.
fn set_name(mut self, new_name: String) -> Person {
@stevej
stevej / lesson3.rs
Created January 21, 2017 23:04
Lesson #3: Borrow Checker Challenge Nested Borrows
// Nested borrows are a common source of trouble. This example is a bit contrived
// but illustrates the challenge.
fn main() {
let mut numbers = vec![1,2,3,4];
// Because push() needs a mutable borrow and len() needs an immutable borrow,
// the borrow checker lets you know you've broken the rules.
numbers.push(numbers.len());
println!("numbers has length {}", numbers.len());
}