Skip to content

Instantly share code, notes, and snippets.

View pzol's full-sized avatar

Piotr Zolnierek pzol

View GitHub Profile
@pzol
pzol / compare_ci.rs
Created January 26, 2014 19:24
compare two strings ignoring case
fn compare_ci(x: &str, y: &str) -> bool {
if x.char_len() != y.char_len() {
return false;
}
let mut it = x.chars().zip(y.chars());
it.all(|(x,y)|
unsafe {
x.to_ascii_nocheck().to_lower() == y.to_ascii_nocheck().to_lower()
}
@pzol
pzol / 3d_map_test.rs
Created January 18, 2014 11:05
ICE on 3d vector
enum TileSet {
Empty,
Dirt
}
type XYZ = (uint, uint, uint);
static MAXX: uint = 10;
static MAXY: uint = 10;
static MAXZ: uint = 1;
@pzol
pzol / destructuring_test.rs
Created January 15, 2014 19:20
destructuring structs
#[feature(struct_variant)];
struct Bar { num: int}
#[test]
fn test_bar() {
let bar = Bar { num: 1 };
let Bar { num } = bar;
assert!(num == 1);
}
@pzol
pzol / list_test.rs
Created January 11, 2014 07:25
pointer fun with lists
#[allow(dead_code, dead_assignment, unused_variable)];
// recursive types
enum List<T> {
Cons(T, ~List<T>),
Empty
}
fn length<T>(xs: &List<T>) -> uint {
match *xs {
@pzol
pzol / list_test.rs
Created January 11, 2014 05:23
list test in rust
#[allow(dead_code, dead_assignment, unused_variable)];
// recursive types
enum List<T> {
Cons(T, ~List<T>),
Empty
}
fn length<T>(xs: &List<T>) -> uint {
match *xs {
@pzol
pzol / list_test.rs
Last active January 2, 2016 19:09
list_test.rs:35:16: 35:20 error: use of moved value: `list`
enum List<T> {
Cons(T, ~List<T>),
Empty
}
fn length<T>(xs: &List<T>) -> uint {
match *xs {
Empty => 0,
Cons(_, ref rest) => 1 + length(*rest)
}
@pzol
pzol / es.sh
Last active December 22, 2015 09:08 — forked from johnvilsack/es.sh
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre -y
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.3.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
sudo mv elasticsearch-* elasticsearch
sudo mv elasticsearch /opt/
@pzol
pzol / elasticsearch.md
Last active December 14, 2015 02:39
Elastic Search Experiments

Create a mongo replicaset

tutorial

rsconf = {
           _id: "rs0",
           members: [
                      {
                       _id: 0,
                       host: "localhost:27017"

}

@pzol
pzol / action_controller.rb
Last active December 11, 2015 07:29
Hexagonal controller example
module Bmsapp
module Booking
class ActionController
def initialize(ui, deps=Dependencies.new(:current_user => ui.current_user))
@ui, @deps, @bms, @logger = ui, deps, deps.bms, deps.logger
end
def action(action_name, id, params)
@booking = @bms.booking_by_id(id)
@params = params
#!/usr/bin/env bash
apt-get -y update
apt-get -y upgrade
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-gplv2-dev libyaml-dev
apt-get -y install autoconf curl git-core bzip2
apt-get -y autoremove
apt-get -y clean
cd /usr/local/src
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p362.tar.gz
tar -xvzf ruby-1.9.3-p362.tar.gz