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 DBTransactions do | |
use ExUnit.CaseTemplate | |
setup_all do | |
Ecto.Adapters.SQL.begin_test_transaction(Repo) | |
on_exit fn -> | |
Ecto.Adapters.SQL.rollback_test_transaction(Repo) | |
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
defmodule WeatherParser do | |
require Record | |
Record.defrecord :xmlElement, Record.extract(:xmlElement, from_lib: "xmerl/include/xmerl.hrl") | |
Record.defrecord :xmlText, Record.extract(:xmlText, from_lib: "xmerl/include/xmerl.hrl") | |
def parse(xml, attrs) do | |
xml | |
|> :binary.bin_to_list | |
|> :xmerl_scan.string | |
|> extract_values(attrs, []) |
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
Enum.each 1..100, fn (n) -> | |
fizzbuzz = fn | |
(0, 0, _) -> "fizzbuzz" | |
(0, _, _) -> "fizz" | |
(_, 0, _) -> "buzz" | |
(_, _, n) -> n | |
end | |
IO.puts fizzbuzz.(rem(n, 3), rem(n, 5), n) | |
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
before_script: | |
- ./script/travis/setup_db.sh | |
script: bundle exec rspec spec/ --tag $TEST_TAG | |
env: | |
matrix: | |
- TEST_TAG=js DB_TEST=1 | |
- TEST_TAG=~js DB_TEST=2 |
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
# Had some issues, so referenced these 3 solutions: | |
# https://gist.github.com/cjolly/2870054 | |
# https://gist.github.com/cloud8421/6667898 | |
# http://stackoverflow.com/questions/20754669/how-to-fix-postgres-after-updating-upgrading-brew | |
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist | |
pg_dumpall > ninedottwo-dump | |
# Not sure if this is necessary, but has to be cleared out no matter what for when we run initdb |
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 'date' | |
DateRange = Struct.new(:start_date, :end_date) do | |
def start_date | |
self[:start_date] || Date.today - 30 | |
end | |
def end_date | |
self[:end_date] || Date.today | |
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
" Example: | |
" response.body.should have_content("something") | |
" expect(response.body).to have_content("something") | |
" ================================================= | |
" Macro that converts rspec "should"s to "expect"s | |
" ================================================= | |
function! ConvertToExpect() | |
:normal! dd | |
:normal! P |
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
describe UserMailer do | |
it "there is a corresponding text email template for each HTML template" do | |
# Path to the mailer templates | |
mailers_path = "#{Rails.root}/app/views/user_mailer/" | |
result = Dir.foreach(mailers_path) do |template| | |
# Ignore partials | |
next if template.match /^_/ | |
# Check if it is an HTML template |
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
Tweet.where('created_at > ?','2012-11-15 02:18:28') | |
Tweet Load (0.5ms) SELECT "tweets".* FROM "tweets" WHERE (created_at > '2012-11-15 02:18:28') ORDER BY published_at DESC | |
=> [#<Tweet id: 30, content: "RARARA", published_at: "2012-11-15 02:18:28", handle: nil, created_at: "2012-11-15 02:18:28", updated_at: "2012-11-15 02:18:28", person_id: 1>] | |
#Aren't the created_at dates equal? So the query should return false... | |
'2012-11-15 02:18:28'.to_datetime.in_time_zone('UTC') |
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
original = 'g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.' | |
original.each_char.each_with_object("") do |character, final| | |
character.next!.next! unless character.match /\W/ | |
final << character | |
end |
NewerOlder