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 / 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 / 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.
"""
>> org.unicode.cldr.tool.GenerateProductionData
[-s, /Users/kip/Development/cldr_repo/common, -d, /Users/kip/Development/cldr_staging_data/common]
#-s sourceDirectory ≔ /Users/kip/Development/cldr_repo/common
#-d destinationDirectory ≔ /Users/kip/Development/cldr_staging_data/common
#-l logicalGroups ≝ true
#-t time ≝ true
#-S Sideways ≝ true
#-r root ≝ true
#-c constrainedRestoration ≝ true
#-i includeComprehensive ≝ true
@kipcole9
kipcole9 / distance.ex
Last active March 29, 2022 00:23
Distance graph builder
defmodule Distance do
@moduledoc """
Ensure that you have the following in your mix.exs
file:
def deps do
{:libgraph, "~> 0.13"}
end
"""
@kipcole9
kipcole9 / string_index.ex
Created July 5, 2022 00:32
Index a binary at newlines and get a line using the index map
defmodule StringIndex do
@newline 10
@doc """
Returns a map of line numbers to
a 2-tuple that is the index at which
the line starts in `string` and the
length of the line.
### Example