Skip to content

Instantly share code, notes, and snippets.

View pragdave's full-sized avatar
🖍️
Alternating between Haskell and PDP-11 assembler

Dave Thomas pragdave

🖍️
Alternating between Haskell and PDP-11 assembler
View GitHub Profile
#
# 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
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
[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
@pragdave
pragdave / roman1.ex
Last active September 24, 2019 02:21
defmodule RomanNumeral do
@mapping [
{1000, 'M'},
{900, 'CM'},
{500, 'D'},
{400, 'CD'},
{100, 'C'},
{90, 'XC'},
{50, 'L'},
{40, 'XL'},
@pragdave
pragdave / ansible_logging.py
Last active December 9, 2016 03:56
Logging plugin for Ansible
# 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]
provision_list:
############################################
"staging-apps+search":
############################################
env: staging
count: 1
roles:
master: yes # has all the background services (cron)
# -*- coding: utf-8 -*- #
module Rouge
module Lexers
class EmbeddedJSX < RegexLexer
tag :xml_inside_jsx
def self.analyze_text(text)
0
end
#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 } ->
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,
;; 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)))