Skip to content

Instantly share code, notes, and snippets.

View nicholasjhenry's full-sized avatar

Nicholas Henry nicholasjhenry

View GitHub Profile
@nicholasjhenry
nicholasjhenry / changeset_example.ex
Created April 16, 2016 10:28
Ecto Changeset Example
params = %{
"title" => "Test List",
"todo_items" => %{
"0" => %{"body" => "change to-do A", "id" => "1"},
"1" => %{"body" => "change to-do B", "id" => "2"}
}
}
changeset = %Ecto.Changeset{
action: nil,

Requirements

  • Docker Machine + Docker
  • curl
  • A Virtualbox-driven Docker Machine called "default" docker-machine create --driver virtualbox default (this is the default with Docker toolkit).

Usage

The git.io URL (http://git.io/vsk46) is a shortened form of the raw url of the plist.

I hereby claim:

  • I am nicholasjhenry on github.
  • I am nicholasjhenry (https://keybase.io/nicholasjhenry) on keybase.
  • I have a public key ASDsJIpuc8EXEHnE4g-kQyKfiola8K4ZPZZmGe06Exe4hQo

To claim this, I am signing this object:

{
@nicholasjhenry
nicholasjhenry / eba.rb
Last active February 11, 2016 00:34
EBA Cheatsheet
# Responsibilites:
# - specific, focused task
# - presenting data to the user
class Worker1
end
class Worker2
end
class Builder
@nicholasjhenry
nicholasjhenry / wrapper_spec.rb
Created February 9, 2016 21:49
IODA Wrapper Kata
class Wrapper
def wrap(text, max_line_length)
words = split_words(text)
words = split_long_words(words, max_line_length)
create_lines_from_words(words, max_line_length)
end
private
def split_words(text)
AllCops:
Include:
- "**/*.gemspec"
- "**/*.podspec"
- "**/*.jbuilder"
- "**/*.rake"
- "**/*.opal"
- "**/Gemfile"
- "**/Rakefile"
- "**/Capfile"
@nicholasjhenry
nicholasjhenry / example.rb
Created October 29, 2015 20:26
Overcoming Our Obsession with Stringly-Typed Ruby
class Address < ActiveRecord::Base
serialize :zip_code, ZipCode
end
class ZipCode
def self.load(raw_string)
self.new(raw_string)
end
def self.dump(zip_code)
@nicholasjhenry
nicholasjhenry / debug.php
Created September 18, 2015 13:23
Debugging SQL issues in PHP
<?
if (!$result) {
echo($mysqli->error);
}
?>
@nicholasjhenry
nicholasjhenry / example.rb
Last active August 29, 2015 14:27
Domain-Driven Example (translated from Patterns, Principles, and Practices of Domain-Driven Design)
# work in progress
class RecommendAFriend
def initialize(referrer_id, friends_account_details)
validate(friends_account_details)
end
private
# - check a technical detail such as formatting e.g. email format
@nicholasjhenry
nicholasjhenry / pretty_print_json
Created July 14, 2015 15:30
JSON Pretty Print in Vim
" Requires 'jq' (brew install jq)
function! s:PrettyJSON()
%!jq .
set filetype=json
endfunction
command! PrettyJSON :call <sid>PrettyJSON()