Skip to content

Instantly share code, notes, and snippets.

View lenary's full-sized avatar

Sam Elliott lenary

View GitHub Profile
@lenary
lenary / test.hs
Last active October 10, 2017 20:40 — forked from elliotdavies/test.hs
Haskell pattern question
-- In `f` we want to keep piping (part of) the result of one function into
-- another, and stop as soon as something fails
f :: [A] -> Either String (B, [A])
f xs =
case f1 xs of
Left s -> Left s
Right (res1, xs') ->
case f2 xs' of
Left s -> Left s
Right (res2, xs'') ->
@lenary
lenary / gcounter.idr
Created June 25, 2014 14:31 — forked from mrb/cong.idr
module Main
import Prelude.Algebra
record GCounter : Type where
MkGCounter : (value : Int) -> GCounter
gcjoin : GCounter -> GCounter -> GCounter
gcjoin l r = (MkGCounter ((value l) + (value r)))
@lenary
lenary / 00demo.md
Last active December 18, 2015 17:49 — forked from seancribbs/00demo.md
@lenary
lenary / hello.rb
Created February 3, 2012 14:48 — forked from urfolomeus/hello.rb
Class level privates
class Hello
def self.first
"Boo!"
end
private
def self.second
"Buh!"
end
woop = {
foo: "bar",
qux: "baz"
}
woop.each.with_index do |(name, value), index|
puts "#{index}: #{name} = #{value}"
end
class Chapter
include Mongoid::Document
field :position, :type => Integer
field :title, :type => String
field :identifier, :type => String
embedded_in :book
embeds_many :elements
def self.process!(git, file)
def foo
begin
raise ""
rescue StandardError
p "error"
end
end
foo
@lenary
lenary / gist:984744
Created May 21, 2011 18:18 — forked from baxter/gist:984701
each_with_object
# Why does the first one work but not the second one?
> (1..10).each_with_object([]) {|i, a| a << i*2; puts a.object_id }
2151926500
2151926500
2151926500
2151926500
2151926500
2151926500
2151926500
Feature: Admin signing in
In order to modify content
As an admin
I want admin login
Scenario: Signing in as an admin
Given there is an admin with the username "seivan@kth.se" and the password "secret"
When I go to the admin path
And I fill in "Login" with "seivan@kth.se"
And I fill in "Password" with "secret"
source 'http://rubygems.org'
gem 'rails', '3.0.0.beta3'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg', '0.8.0'
gem 'inherited_resources', '1.1.2'