Skip to content

Instantly share code, notes, and snippets.

@kevsmith
kevsmith / b2f.erl
Last active November 2, 2021 09:15
Erlang/Elixir BEAM decompiler
#! /usr/bin/env escript
%% -*- mode: erlang -*-
%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ts=4 sw=4 ft=erlang et
%%
%% Copyright 2016 Operable, Inc. All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
@kevsmith
kevsmith / mdpreview.sh
Last active August 13, 2016 17:13
Markdown previewer using pandoc, chrome-cli, and fswatch
#!/bin/sh
# To install dependencies: brew install pandoc chrome-cli fswatch
# To use: mdpreview /path/to/content.md
monitored_file=`basename $1`
preview="/tmp/${monitored_file}.html"
preview_url="file://${preview}"
trap "rm -f ${preview};exit;" SIGINT SIGTERM
@kevsmith
kevsmith / example.exs
Created November 25, 2015 14:44
Hacked up call/cc in Elixir
iex(1)> f = Contex.Target.compute(10, 20)
# c is 30
iex(2)> f.(100)
3000
@kevsmith
kevsmith / switcherl
Created September 30, 2015 14:01
Switch Erlang/Elixir scripts
#!/bin/bash
ERL_HOME=/opt/erl
if [[ "${ERL_HOME}" != */ ]]; then
ERL_HOME=${ERL_HOME}/
fi
LINK_DIRS="bin lib man"
find_active() {
HOME_DEPTH=`echo ${ERL_HOME} | grep -o / | wc -l`
drop function get_table_metrics CASCADE;
drop type operable_table_metrics CASCADE;
CREATE TYPE operable_table_metrics AS (what text, bytes bigint, bytes_pretty text, per_row_bytes bigint);
CREATE OR REPLACE FUNCTION get_table_metrics(tname text)
RETURNS SETOF operable_table_metrics
LANGUAGE plpgsql
STABLE
STRICT
@kevsmith
kevsmith / elixir-shell.sh
Created September 24, 2015 15:53
Open a Elxir shell w/project code on the code path (handy when you're dealing w/compile problems)
#!/bin/sh
ebin_glob=""
if [ $# -eq 0 ]; then
printf "Detecting build path..."
if [ -d ./_build/dev/lib ]; then
ebin_glob="./_build/dev/lib/*/ebin"
printf "found (${ebin_glob})\n"
else
printf "skipped\n"
iex(1)> foo
** (RuntimeError) undefined function: foo/0
iex(1)> %{a: foo} = %{a: 1}
%{a: 1}
iex(2)> foo
1
iex(3)> %{a: foo} = %{a: 2}
%{a: 2}
iex(4)> foo
@kevsmith
kevsmith / enumerator.ex
Created September 7, 2015 23:17
Dynamically generate protocol impl w/no runtime overhead
defmodule Fstop.Model do
defmacro __using__(_) do
quote do
use Ecto.Model
@after_compile {Fstop.Enumerator, :generate}
end
end
end
@kevsmith
kevsmith / git-checkpoint
Last active August 29, 2015 14:28
git commands for quickly iterating on code locally
#!/bin/sh
# Put this script in your path and execute it like so:
# `git checkpoint`
# or
# `git checkpoint lib/foo/foo_thing.ex`
# Bail as soon as an error happens
set -e
@kevsmith
kevsmith / gist:68a9e8c88a1af0b1e8ab
Created March 16, 2015 21:01
Default mounts on Centos 7
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=16327544k,nr_inodes=4081886,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)