Skip to content

Instantly share code, notes, and snippets.

@AndyDangerous
AndyDangerous / faker_bm.rb
Created March 31, 2022 20:01
Faker vs. constant performance benchmarks
require 'benchmark'
require 'faker'
require 'securerandom'
n = 5000
Benchmark.bm(26) do |x|
NUM = 123.freeze
PASSWORD = "Password!1".freeze
UUID = SecureRandom.uuid.freeze
RAND = 1000.freeze
@AndyDangerous
AndyDangerous / rescuer.rb
Created November 18, 2019 03:31
`Foo.new.rescuer` seems like it shouldn't fail, but does in CI
class Foo
class FooError < StandardError; end
def rescuer
failer
rescue FooError => e
puts "Rescued #{e}"
end
def failer
raise FooError.new("FAILED")

Git resources

@AndyDangerous
AndyDangerous / jdk.sh
Created February 5, 2019 17:50
JAVA_HOME get 'n set script
#!/bin/sh
if [["-h" = "$1" || "--help" = "$1" || $# != 1 ]]; then
echo "Switches your JAVA_HOME from jdk using /usr/libexec/java_home. USAGE: "
echo " jdk [1.8 | 11]"
echo "Your current JAVA_HOME=$JAVA_HOME"
exit
else
export JAVA_HOME=`/usr/libexec/java_home -v $1`
echo "You now have JAVA_HOME=$JAVA_HOME"
@AndyDangerous
AndyDangerous / Ski traverses from Pb.md
Last active February 2, 2019 18:38
Links to a bunch of different ski traverses on hillmap
#!/usr/bin/env bash
set -ex
sudo apt update
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.6.1
echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.bashrc
echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc

This is the recipe I used to make Chili for the Post-Turing bash. It was well received. The source is this gnarly sounding blog called Alaska from scratch

Ingredients

  • 1lb ground turkey, beef, or moose (I used moose)
  • 1 onion, chopped
  • 4 cloves of garlic, smashed and minced
  • 1/3c tomato paste
  • 1 (14oz) can diced tomatoes (or tomato sauce, your preference)
  • 1 (14oz) can red kidney beans, rinsed
@AndyDangerous
AndyDangerous / stream_lines.ex
Created December 9, 2016 20:48
From the little elixir and OTP book. This exercise is about using `Stream` to do some lazy enumeration. The takeaway is that the _last_ enumerable thing has to be an enumerable.
defmodule StreamLines do
@path "./some_text.txt"
def large_lines!(path \\ @path) do
path
|> File.stream!
|> Stream.map(&String.replace(&1, "\n", ""))
|> Enum.filter(&(String.length(&1) > 70))
end
@AndyDangerous
AndyDangerous / recursion_examples.ex
Created December 8, 2016 22:58
a bunch of recursive functions based on the little elixir and OTP book
defmodule Mods do
def list_len(list) do
list_len(0, list)
end
defp list_len(acc, []), do: acc
defp list_len(acc, [_h|t]) do
list_len((acc + 1), t)
end
@AndyDangerous
AndyDangerous / Plug.Conn.ex
Created October 29, 2016 00:32
Plug.Conn from my phone sent to my little phoenix thing though twilio
%Plug.Conn{adapter: {Plug.Adapters.Cowboy.Conn, :...}, assigns: %{},
before_send: [#Function<1.27086174/1 in Plug.Logger.call/2>,
#Function<0.78287744/1 in Phoenix.LiveReloader.before_send_inject_reloader/1>],
body_params: %{"AccountSid" => "My-Account-Sid",
"ApiVersion" => "2010-04-01", "Body" => "Hello", "From" => "+12076666",
"FromCity" => "PORTLAND", "FromCountry" => "US", "FromState" => "ME",
"FromZip" => "04101", "MessageSid" => "SMb9ef4379773d0515b906ea007d5a3934",
"NumMedia" => "0", "NumSegments" => "1",
"SmsMessageSid" => "some-SmsMessageSid",
"SmsSid" => "some-SmsSid", "SmsStatus" => "received",