Skip to content

Instantly share code, notes, and snippets.

@mveytsman
mveytsman / Dockerfile
Created July 5, 2021 16:55
Dockerfile for postgis on fly.io
ARG PG_VERSION=12.5
ARG VERSION=dev
FROM golang:1.16 as flyutil
ARG VERSION
WORKDIR /go/src/github.com/fly-examples/postgres-ha
COPY . .
@mveytsman
mveytsman / gigalixir_canonical_host.ex
Last active March 18, 2021 18:58
Gigalixir canonical host
defmodule GigalixirCanonicalHost do
defdelegate init(opts), to: PlugCanonicalHost
def call(conn, opts) do
# There's a bug in gigagilir where requests to foo.gigaglixirapp.com
# get `x-forwarded-proto: https` but `x-forwarded-port: 80` which messes up canonical host
conn =
if Plug.Conn.get_req_header(conn, "x-forwarded-proto") == "https" &&
Plug.Conn.get_req_header(conn, "x-forwarded-port") == "80" do
conn
@mveytsman
mveytsman / honeybadger_telemetry.ex
Last active May 25, 2021 10:24
LiveView -> Honeybadger via telemetry
defmodule BikeBrigade.HoneybadgerTelemetry do
require Logger
@events [
[:phoenix, :live_view, :mount, :start],
[:phoenix, :live_view, :handle_params, :start],
[:phoenix, :live_view, :handle_event, :start],
[:phoenix, :live_component, :handle_event, :start]
]
@mveytsman
mveytsman / shell.nix
Last active June 3, 2020 16:22
elixir project shell.nix (ongoing project)
with (import <nixpkgs> { });
let
inherit (lib) optional;
inherit (python3.pkgs) buildPythonPackage fetchPypi;
basePackages =
[ git libxml2 openssl zlib curl libiconv docker-compose postgresql ]
++ optional stdenv.isLinux inotify-tools;
elixirPackages = [ elixir_1_10 ];
@mveytsman
mveytsman / .bashrc
Last active April 11, 2019 13:38
Localtunnel replacement
#hacky way to get a hosts ip
function ipfor() {
ping -c 1 $1 | grep -Eo -m 1 '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';
}
# localtunnel replacement (note that I default ssh to port 443 because thats how I roll
localtunnel() { if [ $# -lt 2 ]; then echo "Usage: localtunnel hostname port [ssh_port]"; else ssh_port=${3-443}; echo "Setting up localtunnel on `ipfor $1`"; ssh -N -R "*:0:localhost:$2" $1 -p $ssh_port; fi;}
@mveytsman
mveytsman / pedersen.py
Last active July 30, 2017 16:48
Pedersen commitments
# An implementation of Pedersen Commitments.
# This is like tweeting out a hash of a statement you want to make but better.
# Why is it better?
# 1) If the universe of things you want to commit to is small, an attacker can just hash them to see which one you committed to.
# 2) I'm sure there are other nice security properties but I don't know them yet.
# Learning purposes only, DON'T USE THIS, I have no idea what I'm doing, etc etc
@mveytsman
mveytsman / portscanyourself.sh
Last active January 18, 2017 20:55
Check that your firewall is doing what it should be. Post to slack if it's not.
#!/bin/sh
# This is a script that checks to see if the open ports on a host are what you expect them to be.
# If your firewall isn't doing what it's supposed to, it will post a message to Slack to alert you.
# Intended to be run as a cron job.
#
# Requires nmap to be installed
#
# Invoke as
# ./portscanyourself example.com 80 443
# To alert you if any ports other than 80 and 443 are listening on a host
@mveytsman
mveytsman / gist:c03eceb1b02e1eeb3903
Last active August 29, 2015 14:11
Sierpinsky Triangle
(defn sierpinsky [n]
(if (= 0 n)
["*"]
(let [down (sierpinsky (- n 1))
space (apply str (repeat (Math/pow 2 (- n 1)) " "))]
(concat (map #(apply str space % space) down)
(map #(clojure.string/join " " (repeat 2 %)) down)))))
(map println (sierpinsky 4))
@mveytsman
mveytsman / expression-problem.clj
Last active November 24, 2015 12:45
expression problem in clojure
(ns expression-problem)
;; Shapes have area
(defprotocol Areable
(area [this]))
;; We have circles
(defrecord Circle [radius])
;; Circles have area