Skip to content

Instantly share code, notes, and snippets.

View edennis's full-sized avatar

Erick Dennis edennis

  • Barcelona, Spain
View GitHub Profile
defmodule ChainedStream do
# [#Function<59.77324385/2 in Stream.unfold/2>, #Function<59.77324385/2 in Stream.unfold/2>]
def test do
states = count(%{}, ["a", "b", "c"]) |> Enum.to_list
# [{%{"a" => 1}, ["b", "c"]}, {%{"a" => 1, "b" => 1},
# ["c"]}, {%{"a" => 1, "b" => 1, "c" => 1}, []}]
states |> Enum.at(-1) |> elem(0) |> count(["a", "b", "d"])
# [{%{"a" => 2, "b" => 1, "c" => 1}, ["b", "d"]},
# {%{"a" => 2, "b" => 2, "c" => 1}, ["d"]},
iex(10)> m = %{a: 1}
%{a: 1}
iex(11)> %{a: 1} = %{a: 1, b: 2}
%{a: 1, b: 2}
iex(12)> ^m = %{a: 1, b: 2}
** (MatchError) no match of right hand side value: %{a: 1, b: 2}
@edennis
edennis / stream.ex
Created October 3, 2016 15:52
rescue/catch from stream?
iex(1)> stream = File.stream!("does_not_exist")
%File.Stream{line_or_bytes: :line, modes: [:raw, :read_ahead, :binary],
path: "does_not_exist", raw: true}
iex(2)> stream |> Enum.take(1)
** (File.Error) could not stream "does_not_exist": no such file or directory
(elixir) lib/file/stream.ex:78: anonymous fn/2 in Enumerable.File.Stream.reduce/3
(elixir) lib/stream.ex:1121: anonymous fn/5 in Stream.resource/3
(elixir) lib/enum.ex:2161: Enum.take/2
@edennis
edennis / 1.9.3-p448-railsexpress
Created August 22, 2013 09:43
ruby-build definition for ruby-1.9.3-p448 with patches from rails express
build_package_patch_ruby_railsexpress() {
fetch_git rvm-patchsets git://github.com/skaes/rvm-patchsets.git master
for p in rvm-patchsets/patches/ruby/1.9.3/p448/railsexpress/* ; do
patch -p1 < $p
done
}
install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz#36c852831d02cf90508c29852361d01b"
install_package "ruby-1.9.3-p448" "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p448.tar.gz#a893cff26bcf351b8975ebf2a63b1023" patch_ruby_railsexpress autoconf standard
@edennis
edennis / gist:5029143
Created February 25, 2013 11:04
ruby-build definition to install railsexpress patches on ruby-1.9.3-p392
build_package_patch_ruby_railsexpress() {
fetch_git rvm-patchsets git://github.com/skaes/rvm-patchsets.git master
for p in rvm-patchsets/patches/ruby/1.9.3/p392/railsexpress/* ; do
patch -p1 < $p
done
}
install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz"
install_package "ruby-1.9.3-p392" "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz" patch_ruby_railsexpress autoconf standard
@edennis
edennis / gist:4662592
Created January 29, 2013 08:04
ruby-build definition for 1.9.3-p374-railsexpress
# Save file as 1.9.3-p374-railsexpress and copy to ruby-build definitions directory.
# If you've installed ruby-build with brew this will be /usr/local/share/ruby-build/
build_package_patch_ruby_railsexpress() {
fetch_git rvm-patchsets git://github.com/skaes/rvm-patchsets.git master
for p in rvm-patchsets/patches/ruby/1.9.3/p374/railsexpress/* ; do
patch -p1 < $p
done
}
@edennis
edennis / gist:4249067
Created December 10, 2012 07:38
ruby-build definition for 1.9.3-p327-railsexpress
# Save file as 1.9.3-p327-railsexpress and copy to ruby-build definitions directory.
# If you've installed ruby-build with brew this will be /usr/local/share/ruby-build/
build_package_patch_ruby_railsexpress() {
fetch_git rvm-patchsets git://github.com/skaes/rvm-patchsets.git master
for p in rvm-patchsets/patches/ruby/1.9.3/p327/railsexpress/* ; do
patch -p1 < $p
done
}
@edennis
edennis / gist:3187189
Created July 27, 2012 09:55
Colorized irb prompt for production: ~/.irbrc
# .irbrc
if defined?(Rails) && Rails.production?
conf = IRB.conf[:PROMPT][IRB.conf[:PROMPT_MODE]]
red = "\033[0;31m"
reset = "\033[0m"
[:PROMPT_S, :PROMPT_C].each do |p|
conf[p].gsub!(/^(.*)$/, "#{red}\\1#{reset}")
end
conf[:PROMPT_I] = "#{red}%N(%m):%03n:%i (PRODUCTION) > #{reset}"
end
@edennis
edennis / 1.9.3-p194-railsexpress
Created May 16, 2012 16:01
ruby-build definition to install railsexpress patches on ruby-1.9.3-p194
build_package_patch_ruby_railsexpress() {
fetch_git rvm-patchsets git://github.com/skaes/rvm-patchsets.git master
for p in rvm-patchsets/patches/ruby/1.9.3/p194/railsexpress/* ; do
patch -p1 < $p
done
}
install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz"
install_package "ruby-1.9.3-p194" "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz" patch_ruby_railsexpress autoconf standard