Skip to content

Instantly share code, notes, and snippets.

View evadne's full-sized avatar
🎣
gone fishing

Evadne Wu evadne

🎣
gone fishing
View GitHub Profile
@evadne
evadne / gist:440558b18228ca657ef22b465793a0c3
Last active April 5, 2024 14:11
Using SchemaCrawler on PostgreSQL databases
@evadne
evadne / srcds_rcon.ex
Created November 12, 2018 01:13
Source RCON client in Elixir (using gen_tcp)
defmodule HuddleGateway.External.SourceRemoteControl do
@moduledoc """
A simple gen_tcp based implementation of a Source RCON client
- [Source RCON Protocol](https://developer.valvesoftware.com/wiki/Source_RCON_Protocol)
By calling `connect/2`, you can obtain an open TCP socket,
which can then be used with `auth/3` or `exec/3`.
"""
@evadne
evadne / environment.ex
Created November 11, 2018 01:06
Environment Variable based Config Provider
defmodule Huddle.Environment do
use GenServer
@config_entries [
{:huddle_web, HuddleWeb.Endpoint, ~w(http port)a, {:system, "PORT"}}
]
def start_link(args) do
GenServer.start_link(__MODULE__, args)
end
@evadne
evadne / xmastree.ex
Last active December 16, 2019 06:29
Christmas Trees in Elixir
defmodule Tree do
def print(n) do
for i <- 1 .. n do
p(n - i, " ")
p(i * 2 - 1, "*")
w("\n")
end
p(n - 1, " ")
w("|\n")
end
#!/usr/bin/env bash
export AWS_PROFILE=<snip>
ImageDescription="Amazon Linux AMI 2017.09.1.20180115"
RegionNames=$(aws ec2 describe-regions --region eu-west-1 --query 'Regions[*].[RegionName]' --output text)
function getImages () {
region=$1
filters="[
defp prepare_signed_url({region, bucket, object}, friendly_name) do
config = ExAws.Config.new(:s3, %{region: region})
encoded_name = URI.encode(friendly_name, fn
x when ?0 <= x <= ?9 -> true
x when ?A <= x <= ?Z -> true
x when ?a <= x <= ?z -> true
_ -> false
end)
options = [
@evadne
evadne / a-reverse-bench.exs
Last active January 5, 2024 10:57
Reversing Binaries in Elixir
defmodule Benchmarker do
def run(title, module, function, size \\ 1024, iterations \\ 100) do
times = for (_ <- 1 .. iterations) do
data = :crypto.strong_rand_bytes(size)
{duration, _value} = :timer.tc fn ->
apply(module, function, [data])
end
duration
end
@evadne
evadne / wxmac.rb
Created July 14, 2017 02:10
wxmac for Homebrew on macOS 10.13 Beta (17A306f)
class Wxmac < Formula
desc "Cross-platform C++ GUI toolkit (wxWidgets for macOS)"
homepage "https://www.wxwidgets.org"
url "https://github.com/wxWidgets/wxWidgets/releases/download/v3.0.3.1/wxWidgets-3.0.3.1.tar.bz2"
sha256 "3164ad6bc5f61c48d2185b39065ddbe44283eb834a5f62beb13f1d0923e366e4"
head "https://github.com/wxWidgets/wxWidgets.git"
bottle do
cellar :any
sha256 "9766307eb821a254c81002e7318aa89dc2f4cd7a5a09515fce54eb96ae70f898" => :sierra
@evadne
evadne / gist:8424f4dee3243e96e35ec5b6ecc8568f
Created June 29, 2017 19:13
Erlang/OTP 20, wxmac 3.1.0, macOS 10.13 17A291m
Overlord:~ evadne$ brew install erlang
==> Installing dependencies for erlang: autoconf, automake, libtool, pkg-config, makedepend, openssl, jpeg, libpng, libtiff, wxmac
==> Installing erlang dependency: autoconf
==> Using the sandbox
==> Downloading https://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/autoconf/2.69 --with-lispdir=/usr/local/Cellar/autoconf/2.69/share/emacs/site-lisp/autoconf
==> make install
==> Caveats
Emacs Lisp files have been installed to:
@evadne
evadne / main.exs
Last active June 25, 2017 22:35
Cosine Similarity with Elixir
defmodule Script do
def cosine_similarity(lhs, rhs) do
{ab, aa, bb} = accumulate(lhs, rhs)
ab / (:math.sqrt(aa) * :math.sqrt(bb))
end
defp accumulate(lhs, rhs) do
accumulate(lhs, rhs, 0, 0, 0)
end