Skip to content

Instantly share code, notes, and snippets.

@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 / .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 / 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 / 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 / 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 / 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 . .