Map [1]
| Operation | Time Complexity |
|---|---|
| Access | O(log n) |
| Search | O(log n) |
| Insertion | O(n) for <= 32 elements, O(log n) for > 32 elements [2] |
| Deletion | O(n) for <= 32 elements, O(log n) for > 32 elements |
| defmodule DateTimeGenerators do | |
| use ExUnitProperties | |
| @time_zones ["Etc/UTC"] | |
| def date do | |
| gen all year <- integer(1970..2050), | |
| month <- integer(1..12), | |
| day <- integer(1..31), | |
| match?({:ok, _}, Date.from_erl({year, month, day})) do |
Since a local variable head is defined in the quoted expression, the recursive call to the function overwrites the value of head in the expanded expression. This isn't a problem when quoting in the tail of the list , because head was already used to build as its head. :mindblown:
Here's the final implementation of recurse/1:
def recurse([h|t]) do
t = recurse(t)
quote do| # `Hash#dig!` | |
| # | |
| # Like Ruby 2.3's `Hash#dig`, but raises an exception instead of returning `nil` | |
| # when a key isn't found. | |
| # | |
| # Ruby 2.3 introduces the new Hash#dig method for safe extraction of | |
| # a nested value. See http://ruby-doc.org/core-2.3.0/Hash.html#method-i-dig. | |
| # It is the equivalent of a safely repeated Hash#[]. | |
| # | |
| # `#dig!`, on the other hand, is the equivalent of a repeated `Hash#fetch`. It's |
| defmodule MyApp.Periodically do | |
| use GenServer | |
| def start_link do | |
| GenServer.start_link(__MODULE__, %{}) | |
| end | |
| def init(state) do | |
| Process.send_after(self(), :work, 2 * 60 * 60 * 1000) # In 2 hours | |
| {:ok, state} |
| ;; This is at: https://gist.github.com/8655399 | |
| ;; So we want a rhyming dictionary in Clojure. Jack Rusher put up | |
| ;; this code here: | |
| ;; | |
| ;; https://gist.github.com/jackrusher/8640437 | |
| ;; | |
| ;; I'm going to study this code and learn as I go. | |
| ;; | |
| ;; First I put it in a namespace. |
A micro-gem DSL for compound conditionals.
Allowable lets you decompose large/long conditional chains into readable, testable, and inspectable segments with Ruby blocks.
| require 'fiddle' | |
| module IAmAHorriblePerson | |
| def unset flag | |
| value = _wrap self | |
| flags = 8.times.map { |i| value[i] }.pack('C8').unpack('Q').first | |
| [flags & ~flag].pack('Q').unpack('C8').each_with_index { |n,i|value[i] = n } | |
| end | |
| def class= k |
| # spec/dummy/config/application.rb | |
| ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../../Gemfile', __FILE__) | |
| require 'rubygems' | |
| require 'bundler' | |
| Bundler.setup | |
| $:.unshift File.expand_path('../../../../lib', __FILE__) |
Either copy the aliases from the .gitconfig or run the commands in add-pr-alias.sh
Easily checkout local copies of pull requests from remotes:
git pr 4 - creates local branch pr/4 from the github upstream(if it exists) or origin remote and checks it outgit pr 4 someremote - creates local branch pr/4 from someremote remote and checks it out