Skip to content

Instantly share code, notes, and snippets.

View mkompanets's full-sized avatar

Michael Kompanets mkompanets

  • Bellicose
  • South Lake Tahoe
View GitHub Profile
@mkompanets
mkompanets / nested_maps_in_elixir.exs
Created September 24, 2019 22:45
fetching and updating from nested elixir maps
# elixir provides a way to fetch from and update nested maps
# lets say you have a map:
greetings = %{morning: %{friend: "sup", coworker: "hey"}, afternoon: %{friend: "sup", coworker: "good afternoon"}}
# there is a built in (erlang) Kernel function `get_in`
get_in(greetings, [:morning, :coworker]) #=> "hey"
# to updated a nested map use `put_in`
new_greetings = put_in(greetings, [:afternoon, :friend], "yo there") # => %{afternoon: %{coworker: "good afternoon", friend: "yo there"}, morning: %{coworker: "hey", friend: "sup"}}
@mkompanets
mkompanets / protocol.md
Created June 4, 2015 19:23
Adolf the monkey

Pimp my site

![](data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wgARCAMABAADASIAAhEBAxEB/8QAGwAAAwEBAQEBAAAAAAAAAAAAAQIDAAQFBgf/xAAYAQEBAQEBAAAAAAAAAAAAAAAAAQIDBP/aAAwDAQACEAMQAAABVdTxSL9UWYbsReY7pONfQjXIelLecdPSnnt1NJw7pioWrJBbxtVetq4SnSc49KNefufN9W52k6DzmOjQY6TzGOk8+joPOS2lktomWwnh8i210sVaBlsYEsYNFm52LaOKvzst9Jsy2ibroPM9tWg8USQstpyXrRBmU0wmVV1WVBpkVacTybKtFQllBNasYYvoEsefHRucL07nx0bnx0Hl1dB5cXHNq6jyZOo8uOpIAuvOp1bk1dY5QnUOUV09Hm9S+zJpcM10jJQKFYKtUVdRAwXnkco0EZQjCspxgVMrLWVhaNsFlMMQYLq8mO0FlMHHBJMA4gzFVV9SBis84ELZTg0YgmOKpQFp8NnJSkt7OU61cypmTEqarzKx0CNc5OUyLNjqyZXtjK6zMxbasZ0KTl0TSD0FkQ+uVzaEz62ecCkkGbExUVNaLU1qlLtg7Y2wQI6UuGo5cmI1Dq5epfTlSHCVyhHCgITWuUwwwGKlGZDDAEAIAMocuohRTDAYhoDYmctliTCk6McQ7GCcQMGUg422FxyqxwubADKo2Jqzu1zutLtSumRdaXpA1naDaayZ5QS+rSsyTfnqmfFZpVSbVMcaWTWUD4g1AQoyovPdXOT5kQs0IKEjq6p5sKKYkKiopdLOdbJohwrAg

@mkompanets
mkompanets / protocol.md
Created June 4, 2015 19:11
Pimp my site

Pimp my site

Intro

JETHRO: Hello, my name is Jethro Wilkins and you're on pimp my site.

JETHRO: Craig came in today looking for some help with his blog. Craig loves his cat but his blog could really use some help. It looks dull, uninteresting and boring to look at. Looks like something his grandma would blog about. So he came in here looking for some help.

CRAIG: Everyone says they like the pictures of my cat, but they can't stand be on the site for more than 2 minutes. I don't know, maybe it's the gray background or something...but bottom line is I need these guys to really help me out.

@mkompanets
mkompanets / relevant_tag.rb
Created June 4, 2014 23:22
Tag Concern Example
module RelevantTag
extend ActiveSupport::Concern
included do
has_many :taggings, as: :taggable
has_many :tags, through: :taggings
class_attribute :tag_limit
end
@mkompanets
mkompanets / gist:d7353645084d4600b919
Created May 19, 2014 17:37
git yank from another branch
git checkout <branch_name> -- <space-separated paths>
# Change field_with_errors to just add 'error' class to label and element
# instead of wrapping input and label in a div tag
# label blocks do not proc for errors in rails 3.2
ActionView::Base.field_error_proc = Proc.new do |tag, full_html|
if tag =~ /<(input|label|textarea|select)/
field = Nokogiri::HTML::DocumentFragment.parse(tag)
field.children.add_class 'error'
field.to_s.html_safe
else
tag