Skip to content

Instantly share code, notes, and snippets.

View coryodaniel's full-sized avatar
☘️
O'Internets

Cory O'Daniel coryodaniel

☘️
O'Internets
View GitHub Profile
POST /api/organizations/35/employees HTTP/1.1
Host: example.com
X-Api-Version: 1
Accept: application/vnd.api+json
Content-Type: application/vnd.api+json
Cache-Control: no-cache
{
"data": {
"type": "employees",
@coryodaniel
coryodaniel / flog_ci.rake
Created September 6, 2016 16:11
CI Flog Take 2
namespace :ci do
desc "Flog it"
task :flog do
max_score = 10.0
changed_files = `git diff develop --name-only | grep "app/" | grep ".rb" | tr '\n' ' '`.split(' ')
if changed_files.any?
lines = `flog #{changed_files.join(' ')}`
failures = lines.split("\n").
drop(3).
@coryodaniel
coryodaniel / validate_review_app.rake
Created September 19, 2016 17:16
Validate Heroku Review App ENV configuration in CI before building
namespace :ci do
namespace :heroku do
desc "Validate Heroku Review App ENV configuration"
task :validate_review_app do
# load files in development or CI
env_file = File.exists?("config/application.yml") ? "config/application.yml" : "config/application.yml.example"
env = YAML.load_file(env_file)
env_keys = env.keys.map(&:to_s) - %w(test development staging production)
env_keys += env['development'].keys
@coryodaniel
coryodaniel / macro.ex
Created September 20, 2016 08:03
Unhygienic macro ? :D
defmodule Documenation.Case do
defmacro __using__(options) do
quote do
use ExUnit.Case, unquote(options)
import Documenation.Case
end
end
defmacro verify(verb, path, http_status, config) do
quote bind_quoted: binding() do
@coryodaniel
coryodaniel / dredd.rb
Created September 20, 2016 17:10
Running Dredd Hooks / Apiary Blueprint in same thread as Rails test environment to share SimpleCov, FactoryGirl, DatabaseCleaner etc
include DreddHooks::Methods
ENV["RAILS_ENV"] = "test"
require "rubygems"
require "bundler/setup"
unless ENV["SKIP_COVERAGE"]
require "simplecov"
SimpleCov.command_name "Dredd"
SimpleCov.at_exit do
@coryodaniel
coryodaniel / stream.md
Last active September 27, 2016 23:31
Elixir Stream Resource

in sample.txt

line1
line2
line3
line4

in iex

@coryodaniel
coryodaniel / put_assoc.ex
Last active October 1, 2016 22:06
Elixir Ecto put_assoc
defmodule Comment do
def changeset(comment, params) do
comment
|> cast(params, @allowed_params)
|> validate_required([:text])
|> put_assoc(:user, params.user)
end
end
comment = %{text: "Hey, sup?", user: some_user}
@coryodaniel
coryodaniel / cast_assoc.ex
Last active October 5, 2016 09:08
Elixir Ecto cast_assoc
defmodule User do
def changeset(user, params) do
user
|> cast(params, @allowed_params)
|> validate_required(@required_params)
# Account.changeset is inferred by default
|> cast_assoc(:account, required: true, with: &Account.registration_changeset/2)
end
end
@coryodaniel
coryodaniel / shitty.rb
Created October 1, 2016 00:31
Shitty random ID generator
((0..9).to_a + ("a".."z").to_a).shuffle.take(8).join('')
@coryodaniel
coryodaniel / elixir-atom-pkgs.txt
Created October 1, 2016 21:16
Elixir atom pkgs
language-elixir
script
build-elixir
elixir-cmd
linter-elixirc
elixir-docs
iex
autocomplete-elixir