Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View pzol's full-sized avatar

Piotr Zolnierek pzol

View GitHub Profile
@pzol
pzol / maybe.rb
Created March 28, 2012 13:06
Maybe in ruby
def Maybe(obj)
return Maybe.new(Nothing.new) if obj.nil?
return Maybe.new(obj)
end
class Nothing
def method_missing(*args, &block)
self
end
@pzol
pzol / monadic.rb
Created May 30, 2012 17:56
Reliable presenter code with monadic
class MonadicHotelBookingPresenter
def initialize(booking)
@booking = Maybe(booking)
end
def hotel_name
hotel_details['name'].fetch.to_s
end
def hotel_category
@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"

}