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 Ejixir do | |
def j_tl(coll) do | |
[ _h | t ] = coll | |
t | |
end | |
def j_hd(coll) do | |
[ h | _t ] = coll | |
h | |
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
import Html exposing (div, text) | |
import Html.App as App | |
import Html.Events exposing (onClick) | |
type Msg = Increment | |
main : Program Never | |
main = | |
App.beginnerProgram | |
{ model = 0 |
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
# frozen_string_literal: true | |
module DomHelper | |
# Executes the given block within the context of a specific node identified | |
# using its data-xxx attributes. It will take any number of arguments. | |
# | |
# eg: | |
# user = create_user() | |
# within_element(id: user.id) do | |
# click_on 'Edit' | |
# 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
[commit] | |
template = ~/.gitmessage |
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
def char_combinations(s) | |
length = s.size | |
list_comp = Array.new(length) do |start_index| | |
length.times.inject([]) do |combinations, end_index| | |
sub_str = s[start_index..end_index] | |
sub_str.size > 0 ? combinations << sub_str : combinations | |
end | |
end.flatten | |
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
require 'date' | |
# OK: but the bracket faries are in abundence :() | |
((Date.today)..(Date.today + 7)).to_a | |
# BAD: for performance | |
# https://github.com/bbatsov/rubocop/blob/58761c6bbb0ba68f78651df672b93f9c15e1213f/lib/rubocop/cop/performance/times_map.rb | |
7.times.map { |n| Date.today + n } | |
# GOOD: concise, clear & performant |
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 of a guard clause performing a nil check | |
class BlahSpeaker | |
has_one :audience | |
def speak | |
return if audience.nil? | |
audience.address('blah ' * 100) | |
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
TimeWindow.where(%{EXTRACT(YEAR FROM start_date) = ?}, 2020) |
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
$ irb | |
001:0> Class.new.initialize | |
NoMethodError: private method `initialize' called for #<Class:0x007fc9188e3f08> |
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
class Presenter | |
include SortableColumns | |
def sortable_column_heading(text:, attr:, &block) | |
label = sort_link_text(text, attr) | |
link_params = sort_link_params(attr) | |
block.call(label, link_params) | |
end | |
NewerOlder