This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Transform Bookrepublic catalogue API books data | |
# into an input suitable for CSV generation. | |
# Example call: see transform_array_via_ruby.sh | |
# we're interested in these fields: | |
[ | |
"isbn", "title", "description", | |
"authors", "publisher", "publication_year", "created_at", | |
"language", "translator", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require: rubocop-rspec | |
AllCops: | |
Include: | |
- "**/*.gemspec" | |
- "**/*.podspec" | |
- "**/*.jbuilder" | |
- "**/*.rake" | |
- "**/*.opal" | |
- "**/Gemfile" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# Usage: | |
# $ sh rbenv_local_ruby.sh {VERSION} | |
# If VERSION is missing, builds and installs 'local-ruby' | |
VERSION=${1:-local-ruby}; | |
echo $VERSION | |
./configure --prefix=~/.rbenv/versions/$VERSION | |
make |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set up a bash function to cd to a Rails app's current directory and set the prompt | |
rails_app () | |
{ | |
cd "$APP_PATH/current"; | |
export PS1="(\$APP_NAME:\$RAILS_ENV)\w>" | |
} | |
my_rails_app () | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tags: #code-golf | |
# Define a method like this: | |
# `VarArgs.def(:hi, [:there, :world]) | |
# You get a function: | |
# `def hi(there, world) ...` | |
defmodule VarArgs do | |
defmacro def(name, args) do | |
params = Enum.map(args, fn(a) -> Macro.var(a, nil) end) | |
quote do | |
def unquote(:"#{name}")(unquote_splicing(params)) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule GenServerThatUsesStdio do | |
use GenServer | |
def start_link() do | |
GenServer.start_link(__MODULE__, []) | |
end | |
def handle_cast(message, state) do | |
IO.puts message | |
{:noreply, state} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HTTP | |
require "net/http" | |
Net::HTTP.start(host) do |http| | |
response = http.send_request("FOO", "/", nil, nil) | |
puts response.body | |
end | |
# HTTPS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dump_table(sums) | |
sums.each.with_index { |row, sum| puts "#{sum}: #{row.inspect}" } | |
end | |
def solvable?(set, size, sum) | |
sums = (0 .. sum).map do |i| | |
(0 .. size).map do |j| | |
nil | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defimpl JSX.Encoder, for: Tuple do | |
def json({__t1, __t2}) when is_list(i1) do | |
[:start_object, "__t1", __t1, "__t2", JSX.encode!(__t2), :end_object] | |
end | |
def json({__t1, __t2}) do | |
[:start_object, "__t1", __t2, "tuple_list", __t2, :end_object] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defp combine(list1, list2) do | |
Keyword.merge(keyword_list(list1), keyword_list(list2), fn _k, _v1, v2 -> | |
v2 | |
end) | |
end | |
def keyword_pair({key, value}) when is_atom(key) do | |
{key, value} | |
end | |
def keyword_pair({key, value}) do |