Skip to content

Instantly share code, notes, and snippets.

View thing.ex
defmodule Store do
def get(ptr) do
Metrics.count()
Metrics.timed do
ptr.store.get(ptr)
end
end
end
defmodule Macro do
View special-forms.plsql
-- 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(
View operators.plsql
-- math
2 + 2
2 - 2
2 / 2
2 * 2
4 % 1
-- boolean
not true
true or false
View functions.plsql
-- 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)
@rozap
rozap / soql-primitives.sql
Last active Feb 8, 2018
SoQL transformation crash course
View soql-primitives.sql
-- strings
'hello'
"or double quoted"
-- numbers
-1.8
47
-- booleans
true
View gcc.sh
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
View segfault.sh
chris@chris-mbp:~/workspace$ uname -a
Linux chris-mbp 4.4.0-75-generic #96-Ubuntu SMP Thu Apr 20 09:56:33 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
^Cchris@chris-mbp:~/workspace$ iex --version
Erlang/OTP 19 [erts-8.1] [source-4cc2ce3] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
IEx 1.3.3
chris@chris-mbp:~/workspace$ rustc --version
rustc 1.18.0 (03fc9d622 2017-06-06)
chris@chris-mbp:~/workspace$ $CC --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
View wat.ex
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
View gist:e8c8698ff685c83477c490225aec2682
# In the container
root@9b44a35fe04c:/etc/service/dsmapi# bin/dsmapi start
/etc/service/dsmapi/releases/0.0.1/dsmapi.sh: 388: /etc/service/dsmapi/releases/0.0.1/dsmapi.sh: /etc/service/dsmapi/erts-8.2/bin/run_erl: not found
root@9b44a35fe04c:/etc/service/dsmapi/erts-8.2# ls
doc src
root@9b44a35fe04c:/etc/service/dsmapi/erts-8.2# erl -version
Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 8.2
@rozap
rozap / chicago_crimes.ex
Last active Jan 25, 2017
elixir + socrata API
View chicago_crimes.ex
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