This file contains hidden or 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
# | |
# Given a list, return a new list with all occurrences of consecutive | |
# duplicated elements replaced by `{element, count}` | |
# | |
# compress [ 1,2,2,3,4,4,4,5,6,6] | |
# → [1, {2, 2}, 3, {4, 3}, 5, {6, 2}] | |
# | |
# This version uses the head of the result to give the effect of lookahead |
This file contains hidden or 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 FibAgent do | |
defstruct cache: nil, highest_n: 0 | |
def start_link do | |
initial_cache = Enum.into([ {0, 0}, {1, 1}], HashDict.new) | |
state = %__MODULE__{cache: initial_cache, highest_n: 1} | |
Agent.start_link(fn -> state end, name: __MODULE__) | |
end |
This file contains hidden or 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
[elixir/Book] svn commit -m 'prep for 0.15' [Book:158836] | |
Sending Changes.pml | |
Sending Enumeration.pml | |
Sending Introduction.pml | |
Sending Nodes.pml | |
Sending OTP-applications.pml | |
Sending OTP-servers.pml | |
Sending OTP-supervisors.pml | |
Sending Project.pml | |
Sending Protocols.pml |
This file contains hidden or 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 RomanNumeral do | |
@mapping [ | |
{1000, 'M'}, | |
{900, 'CM'}, | |
{500, 'D'}, | |
{400, 'CD'}, | |
{100, 'C'}, | |
{90, 'XC'}, | |
{50, 'L'}, | |
{40, 'XL'}, |
This file contains hidden or 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
# Interpret the Ansible log for humans. In particular, we | |
# look for command executions and format their content | |
# | |
# - name: list files | |
# shell: "ls -lrt *e*" | |
# | |
# Might produce | |
# | |
# TASK: [1] *********************************************************** | |
# changed: [localhost] |
This file contains hidden or 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
provision_list: | |
############################################ | |
"staging-apps+search": | |
############################################ | |
env: staging | |
count: 1 | |
roles: | |
master: yes # has all the background services (cron) |
This file contains hidden or 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
# -*- coding: utf-8 -*- # | |
module Rouge | |
module Lexers | |
class EmbeddedJSX < RegexLexer | |
tag :xml_inside_jsx | |
def self.analyze_text(text) | |
0 | |
end |
This file contains hidden or 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
#START:solver1 | |
defmodule FibSolver do | |
def fib(scheduler) do | |
send scheduler, { :ready, self } | |
receive do | |
{ :fib, n, client } -> | |
send client, { :answer, n, fib_calc(n), self } | |
fib(scheduler) | |
{ :shutdown } -> |
This file contains hidden or 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
generate_match_vars([{Key, Value, Expr} | T], ClauseVars, Left, Right) -> | |
case maps:find(Key, ClauseVars) of | |
{ok, Value} -> | |
generate_match_vars(T, ClauseVars, Left, Right); | |
{ok, Clause} -> | |
generate_match_vars(T, ClauseVars, | |
[{var, 0, element(1, Value)} | Left], | |
[{var, 0, element(1, Clause)} | Right]); | |
error -> | |
generate_match_vars(T, ClauseVars, |
This file contains hidden or 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
;; Mode line setup | |
(setq-default | |
mode-line-format | |
'(; Position, including warning for 80 columns | |
(:propertize "%4l" face mode-line-position-face) | |
":" | |
(:eval (propertize "%c" 'face | |
(if (>= (current-column) 80) | |
'mode-line-80col-face | |
'mode-line-position-face))) |