Skip to content

Instantly share code, notes, and snippets.

@kipcole9
kipcole9 / 0. nginx_setup.sh
Created July 13, 2012 23:12 — forked from mikhailov/0. nginx_setup.sh
Nginx+Unicorn (production-ready setup)
# Nginx optimal congifuration guide.
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.2.tar.gz
$ tar xzvf ./nginx-1.2.2.tar.gz && rm -f ./nginx-1.2.2.tar.gz
$ wget http://zlib.net/zlib127.zip
@kipcole9
kipcole9 / Map.Helpers
Last active October 24, 2023 22:13
Helpers for Elixir Maps: underscore, atomise and stringify map keys
defmodule Map.Helpers do
@moduledoc """
Functions to transform maps
"""
@doc """
Convert map string camelCase keys to underscore_keys
"""
def underscore_keys(nil), do: nil
@kipcole9
kipcole9 / case_insensitive_string
Last active November 25, 2018 11:22
Case incentive String comparison for ASCII strings
defmodule InsensitiveString do
@moduledoc """
Case insensitive string functions for
ASCII string
"""
@doc """
Compare two ascii strings in a case insensitive
manner
@kipcole9
kipcole9 / tree walk.ex
Created February 16, 2019 19:37
Depth-wise tree walk and execute a function
defmodule Treewalk do
@type tree :: {:node, integer(), tree(), tree()} | nil
def depth({:node, value, nil, nil}, _fun) do
value
end
def depth({:node, value, nil, right}, fun) do
fun.(value, depth(right, fun), nil)
end
@kipcole9
kipcole9 / function_clause.ex
Created October 23, 2019 11:04
Debug Elixir Function Clause errors
defmodule FunctionClause do
@moduledoc """
Format function clauses using Exception.blame/3
"""
@doc """
Given a `module`, `function`, and `args` see
if that function clause would match or not match.
This is useful for helping diagnose function
@kipcole9
kipcole9 / decode.ex
Created January 2, 2020 13:05
Decode a float in Elixir
defmodule Decode do
@moduledoc """
Extracted from https://github.com/ewildgoose/elixir-float_pp
"""
use Bitwise
@float_bias 1022
############################################################################
@kipcole9
kipcole9 / pig_latin.ex
Last active June 2, 2020 19:50
Elixir implementation of pig latin translation
defmodule PigLatin do
# vowels: a, e, i, o, u, y_, x_
@vowels ["a", "e", "i", "o", "u"]
# special constants: "ch", "qu", "squ", "th", "thr", "sch"
@special ["ch", "qu", "squ", "thr", "th", "sch"]
@ay "ay"
defguard is_vowel(c) when c in @vowels
@kipcole9
kipcole9 / Parser.ex
Last active June 21, 2021 13:09
Parsing a simple expression grammar with maybe quoted strings
defmodule ParseHelpers do
import NimbleParsec
def whitespace() do
ascii_char([?\s])
|> repeat
end
def quote_mark(combinator \\ empty()) do
combinator
defmodule Extract do
@moduledoc """
Split into words only when the words have a "%" as a prefix
or a suffix
"""
# Empty string returns empty list
def words("") do
[]
defmodule Channel do
@input [{0, 190}, {1, 0}, {2, 0}, {3, 0}, {6, 220}, {9, 90}]
@doc """
Map a list of {index, value} pairs
into a binary, filling in any gaps in
the index sequence with <<0>> as
the list is built.
"""