Run brew install elixir
I'm not going to be able to do a better job giving an overview of the language than what's already documented here:
| defmodule Store do | |
| def get(ptr) do | |
| Metrics.count() | |
| Metrics.timed do | |
| ptr.store.get(ptr) | |
| end | |
| end | |
| end | |
| defmodule Macro do |
| -- maybe our dataset has a column that looks like '(47.000, -128.000)' but some of those values | |
| -- are 'unknown', so this will parse the lat/lng from the string if it's there, and if not, then | |
| -- geocode using different columns, but both branches of this case return a point. | |
| case( | |
| location LIKE '%(%' and location LIKE '%)%' and location LIKE '%,%', | |
| make_point( | |
| to_number( | |
| regex_named_capture(incident_location, '\((?<latitude>[-\d\.]+)', 'latitude') | |
| ), | |
| to_number( |
| -- math | |
| 2 + 2 | |
| 2 - 2 | |
| 2 / 2 | |
| 2 * 2 | |
| 4 % 1 | |
| -- boolean | |
| not true | |
| true or false |
| -- call the replace function on the `response_type` column | |
| -- which will replace the string 'Medic' with 'Medical' | |
| replace(`response_type`, 'Medic', 'Medical') | |
| -- call the to_number function on the `latitude` column | |
| to_number(`latitude`) | |
| -- call the to_boolean function on the incident column. Note we don't need the | |
| -- `backticks` when the column name is alphanumeric+underscores. | |
| to_boolean(incident_number) |
| -- strings | |
| 'hello' | |
| "or double quoted" | |
| -- numbers | |
| -1.8 | |
| 47 | |
| -- booleans | |
| true |
| sudo apt-get update && \ | |
| sudo apt-get install build-essential software-properties-common -y && \ | |
| sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \ | |
| sudo apt-get update && \ | |
| sudo apt-get install gcc-6 g++-6 -y && \ | |
| sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6 | |
| To verify if it worked: | |
| gcc -v |
| def print_mem(label) do | |
| case :erlang.process_info(self, :binary) do | |
| {:binary, bins} -> | |
| {size, count} = Enum.reduce(bins, {0, 0}, fn {_bid, size, count}, {s, c} -> {size + s, count + c} end) | |
| Logger.warn("#{label} usage in #{__MODULE__} is #{size / 1000000}mb, #{count} of them") | |
| _ -> :ok | |
| end | |
| end |
| import Exsoda.Reader | |
| with {:ok, rows} <- query("6zsd-86xi", domain: "data.cityofchicago.org") | |
| |> select(["date_trunc_ym(date) as month", "count(*)"]) | |
| |> where("primary_type = 'HOMICIDE' AND month = '2001-01-01T00:00:00.000'") | |
| |> group("month") | |
| |> order("month") | |
| |> run do | |
| rows |
| defmodule Advance do | |
| defp advance_by(stream, count) do | |
| Enumerable.reduce(stream, count, fn | |
| x, {acc, 1} -> {:suspend, {[x | acc], 0}} | |
| x, {acc, counter} -> {:cont, {[x | acc], counter - 1}} | |
| end) | |
| end | |
| defp continue(cont, by) do |