Skip to content

Instantly share code, notes, and snippets.

View martinsvalin's full-sized avatar

Martin Svalin martinsvalin

  • Stockholm, Sweden
View GitHub Profile
@martinsvalin
martinsvalin / lazy_permutations.exs
Created August 27, 2015 08:41
Lazy permutations in Elixir
defmodule LazyPermutations do
def permutations(list) do
list
|> Enum.sort
|> Stream.unfold fn
[] -> nil
p -> {p, next_permutation(p)}
end
end
@martinsvalin
martinsvalin / weekday.ex
Created June 3, 2015 19:07
Elixir Weekday struct with Range.Iterator implementation
defmodule Weekday do
defstruct name: nil, number: nil
def monday, do: %Weekday{name: "Monday", number: 1}
def tuesday, do: %Weekday{name: "Tuesday", number: 2}
def wednesday, do: %Weekday{name: "Wednesday", number: 3}
def thursday, do: %Weekday{name: "Thursday", number: 4}
def friday, do: %Weekday{name: "Friday", number: 5}
def saturday, do: %Weekday{name: "Saturday", number: 6}
def sunday, do: %Weekday{name: "Sunday", number: 7}
@martinsvalin
martinsvalin / a_bug_report.md
Created March 30, 2012 08:41
Steps to reproduce bug in rspec-rails

Steps to reproduce bug in rspec-rails.

When render_views is enabled globally, it cannot be disabled with a local render_views(false) call.

Create rails project with rspec-rails, a simple controller with one action

rails new reproduce_bug
cd reproduce_bug
echo 'gem "rspec-rails"' >> Gemfile

bundle

@martinsvalin
martinsvalin / gist:915170
Created April 12, 2011 08:26
feature tagging in locale files
blog_post:
body: Body
header: Heading
summary: Summary
topics: Topics #categories
@martinsvalin
martinsvalin / locales-wc
Created April 11, 2011 08:15
word count in our locale files
~/Sites/newsdesk master$ wc config/locales/*
3846 19378 188890 config/locales/da.yml
3891 20588 186542 config/locales/en.yml
3841 15668 186940 config/locales/fi.yml
3839 19352 185267 config/locales/no.yml
3905 19149 191660 config/locales/sv.yml
19322 94135 939299 total