Skip to content

Instantly share code, notes, and snippets.

View nathanl's full-sized avatar

Nathan Long nathanl

View GitHub Profile
@christhekeele
christhekeele / ALLOWABLE.md
Last active May 16, 2023 10:27
Allowable: A Ruby gem DSL for compound conditionals.

Allowable

A micro-gem DSL for compound conditionals.

Allowable lets you decompose large/long conditional chains into readable, testable, and inspectable segments with Ruby blocks.

Installation

@ftrain
ftrain / rhymes.clj
Last active July 14, 2023 22:20
Annotated rhyming dictionary
;; 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.
@trestrantham
trestrantham / periodic_task.ex
Created January 27, 2016 05:19
Run a task periodically natively in Elixir
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}
@dogweather
dogweather / dig_bang.rb
Last active February 18, 2020 11:40
DigBang: Safely unsafe hash traversal
# `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
@iamvery
iamvery / README.md
Last active June 20, 2016 13:08
Interesting behavior with recursive macro in Elixir

ANSWERED!

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
@LostKobrakai
LostKobrakai / date_time_generators.ex
Last active March 17, 2024 17:21
stream_data generators to create elixir date/time structs
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
@PJUllrich
PJUllrich / big-o.md
Last active February 13, 2025 23:48
Big-O Time Complexities for Elixir Data Structures

Big-O Time Complexities for Elixir data structures

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