Just to get everyone up to speed; Structs are a great because they provide compile time checks. Compile-time checks are awesome as we can catch errors before we run our application in the run-time. Structs also allow us to make custom data types, and we can implement protocols that amongst other things allow us to tell Elixir how it should enumerate over our data type, or insert items into our data type using Protocols.
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
Begin the morning by saying to thyself, I shall meet with the | |
busy-body, the ungrateful, arrogant, deceitful, envious, unsocial. All | |
these things happen to them by reason of their ignorance of what is | |
good and evil. But I who have seen the nature of the good that it is | |
beautiful, and of the bad that it is ugly, and the nature of him who | |
does wrong, that it is akin to me, not only of the same blood or seed, | |
but that it participates in the same intelligence and the same portion | |
of the divinity, I can neither be injured by any of them, for no one | |
can fix on me what is ugly, nor can I be angry with my kinsman, nor | |
hate him, For we are made for co-operation, like feet, like hands, |
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
(use-package eshell | |
:after projectile | |
:preface | |
(defun universal-argument-eshell () | |
"wrap the `eshell'-command, with a check for whether or not | |
the universal argument has been applied, and how many times. | |
Zero times: normal behavior (eshell); Once: open a shell in the | |
current project root" | |
(interactive) | |
(cond ((equal current-prefix-arg nil) |
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
{ pkgs ? import <nixpkgs> {} }: | |
with pkgs; | |
let | |
inherit (lib) optional optionals; | |
erlang_wx = erlangR21.override { | |
wxSupport = true; | |
}; |
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
test "take and free" do | |
mutex_pid = Mutex.start() | |
parent = self() | |
assert :ok = Mutex.wait(mutex_pid) | |
spawn_link(fn() -> | |
send parent, :ready | |
:ok = Mutex.wait(mutex_pid) | |
send parent, :done |
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 MqttTest.Handler do | |
@moduledoc false | |
require Logger | |
defstruct [:name] | |
alias __MODULE__, as: State | |
@behaviour Tortoise.Handler |
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
;; Read the inserted word out loud using the macOS speech synthesizer | |
;; when a misspelled word is corrected using the flyspell | |
;; `flyspell-auto-correct-word'-command. | |
;; | |
;; Note this only work on macOS. It should be fairly easy to change to | |
;; work with other command line interface speech synthesize systems. | |
;; | |
;; In a previous version this used to be a defadvice, but I've changed | |
;; it to implementing a custom flyspell insert function. This seems to | |
;; work a bit more reliably. |
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 Dice do | |
@moduledoc """ | |
The best I could come up with... | |
iex> import Dice | |
...> ~d'1d6'+3 | |
""" | |
def sigil_d(input, []) do | |
[n, eyes] = |
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 has(bitfield) do | |
count_elements(bitfield.pieces, 0) | |
end | |
defp count_elements(0, acc), do: acc | |
defp count_elements(pieces, acc) do | |
count_elements(pieces >>> 1, acc + (pieces &&& 1)) | |
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
[1,0,1,1,1] |> Enum.reduce(0, fn | |
1, acc -> acc * 2 + 1 | |
0, acc -> acc * 2 | |
end) |
NewerOlder