Skip to content

Instantly share code, notes, and snippets.

module Thing (isThingy) where
isThingy x = x == "thingy"
-- later...
import Thing
filter isThingy ["stuff", "thingy", "pancakes"]
defmodule Thing do
def thingy?(incoming_thing) do
incoming_thing == "thingy"
end
end
defmodule StringCalculator.DelimiterTest do
use ExUnit.Case
import StringCalculator.Delimiter
test "when given a string with no custom delimiter, the default delimiter is returned" do
assert delimiter_from("1,2,3") == ~r/(?:,|\n)/
end
test "when given a string with a custom delimiter, the custom delimiter is extracted and added to the defaults" do
assert delimiter_from("//;\n1,2,3") == ~r/(?:;|,|\n)/
def add(input) do
sum map split(delimiter_from(input), numbers_from(input)), &to_integer/1
end
defmodule MyApp.PostsController do
use Phoenix.Controller
require IEx
plug :action
def index(conn, _params) do
IEx.pry
conn |> render "index"
end
def add(input) do
delimiter_from(input)
|> split(numbers_from(input))
|> map(&to_integer/1)
|> sum
end
#!/usr/bin/env bash
git add -A && git commit -m "WIP [ci skip]"
mspring() {
be spring && \
while true
do
spring 2>&1 > /dev/null
SPRING_STATUS=`spring status`
clear
echo `date`\\n$SPRING_STATUS
sleep 2
done
@jtrim
jtrim / database.yml.example
Last active August 29, 2015 14:00
Duplicates a database from the master version. Useful for having different databases per branch in a codebase.
<%
current_branch_name ||= begin
`/usr/bin/env git branch` =~ /^\*\s+(.*)$/
current_branch_name = $1.gsub('-', '_')
end
%>
development:
adapter: postgresql
database: myapp_development_<%= current_branch_name %>
@jtrim
jtrim / smartspec.rb
Created April 23, 2014 14:12
Runs specs based on a fuzzy match of the file path
#!/usr/bin/env ruby
require 'rubygems'
require 'thor'
require 'pry'
class SmartSpec < Thor
option :all, type: :boolean, aliases: ['-a']
desc 'fuzzy [PATTERN] *OR* smartspec -- [PATTERN]', 'Find specs matching PATTERN and run one or all of them.'
long_desc <<-DESC
This is the default action of smartspec, so:\x5