Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan Draper coderdan

View GitHub Profile
View example2.ex
["Crocodile", "Giraffe", "Lion", "Tiger"]
|> Enum.map(&String.capitalize/1)
|> Enum.sort
View example2.rb
["Crocodile", "Giraffe", "Lion", "Tiger"].map { |word|
word.capitalize
}.sort
View example2.ex
def print_name(%User{firstname: fname, lastname: lname}) do
"#{fname} #{lname}"
end
View example1.ex
def print_name(%User{} = user) do
"#{user.firstname} #{user.lastname}"
end
def print_name(_) do
"Unknown"
end
View example1.rb
def print_name(user)
if user.present? and user.kind_of?(User)
"#{user.firstname} #{user.lastname}"
else
"Unknown"
end
end
@coderdan
coderdan / resolver.ex
Last active Apr 18, 2018
Edge resolution with dataloader
View resolver.ex
import Absinthe.Resolution.Helpers
connection field :contracts, node_type: :contract do
resolve fn %{id: project_id}, args, %{context: %{current_user: current_user}, dataloader: loader} ->
loader
|> Dataloader.load_many(Engagement, :contract_ids_for_project_id, project_id)
|> on_load(fn loader ->
{
:ok,
Connection.from_list(
View shared-protocol.ex
defprotocol Foo do
def example()
end
defimpl Foo, for: [List, MyType] do
def example do
"Example"
end
end
View gist:5ef0099582984cdc34e6ae141df61609
Verifying my Blockstack ID is secured with the address 1EHxKJHoX7XQMBRxvAjUNQxbxF7fZRNwUX https://explorer.blockstack.org/address/1EHxKJHoX7XQMBRxvAjUNQxbxF7fZRNwUX
View gist:6a1df7175999fdd6bd15
def site_path(site)
val = if site.respond_to?(:to_param)
site.to_param
else
site
end
"/sites/#{val}"
end
View gist:bf65027e91fde06e8360
Meggings you probably haven't heard of them swag, gastropub green juice keytar art party echo park locavore jean shorts. Gentrify brunch bespoke portland normcore listicle. Offal umami freegan bushwick listicle. Ethical art party cardigan health goth, master cleanse cronut listicle tote bag tumblr wayfarers biodiesel beard deep v iPhone hoodie. Austin seitan 3 wolf moon flannel, cold-pressed etsy fap. Slow-carb gastropub tumblr, plaid you probably haven't heard of them yuccie trust fund paleo gentrify kinfolk. Mustache narwhal listicle, viral plaid drinking vinegar franzen flexitarian tofu biodiesel bushwick flannel.
Fingerstache etsy franzen, shabby chic crucifix roof party gluten-free marfa mustache flexitarian viral gentrify locavore paleo +1. Paleo XOXO forage dreamcatcher, disrupt keffiyeh organic roof party chicharrones YOLO sartorial. Bespoke kinfolk williamsburg, asymmetrical pinterest four dollar toast kogi farm-to-table try-hard bicycle rights 8-bit tote bag. Chillwave jean shorts sriracha knausgaa