Skip to content

Instantly share code, notes, and snippets.

View pzol's full-sized avatar

Piotr Zolnierek pzol

View GitHub Profile
@pzol
pzol / README.md
Created June 25, 2012 07:45
Monadic vs Imperative code in ruby

Monadic vs Imperative

Here is a comparison of two pieces of code that do basically the same thing.

So what we have here is a chain of functions depending on each other, each consecutive takes the result of the previous one for further processing. If either of them fails, the rest shall not be executed.

  1. validate parameters received from the outside world in a Hash
  2. convert one of the parameters into an object
  3. do a search in the database
#!/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
@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
@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 / 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 / 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 / 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
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 / 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 / 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;