Skip to content

Instantly share code, notes, and snippets.

View J3RN's full-sized avatar
💼
Seeking a new job

Jonathan Arnett J3RN

💼
Seeking a new job
View GitHub Profile
@J3RN
J3RN / naive performance
Created January 10, 2022 20:54
"optimizing" Gleam code
****** Process <0.91.0> -- 100.00 % of profiled time ***
FUNCTION CALLS % TIME [uS / CALLS]
-------- ----- ------- ---- [----------]
erl_eval:exprs/5 1 0.00 0 [ 0.00]
erl_eval:ret_expr/3 2 0.00 0 [ 0.00]
erl_eval:eval_fun/2 1 0.00 0 [ 0.00]
erl_eval:expr_list/4 1 0.00 0 [ 0.00]
erl_eval:guard/4 1 0.00 0 [ 0.00]
erl_eval:guard0/4 1 0.00 0 [ 0.00]
erl_eval:match_list/4 1 0.00 0 [ 0.00]
@J3RN
J3RN / map_benchmark.ex
Created January 15, 2021 06:27
Benchmark of different methods of map transformation
sample = Enum.map(1..1000, &{&1, &1}) |> Map.new()
Benchee.run(%{
"maps:map" => fn -> :maps.map(fn _k, v -> v * 2 end, sample) end,
"Map.new" => fn -> Map.new(sample, fn {k, v} -> {k, v * 2} end) end,
"for" => fn -> for {k, v} <- sample, into: %{}, do: {k, v * 2} end
})
@J3RN
J3RN / elixir_test.exs
Created October 9, 2018 03:47
Trying to pattern match in Elixir, variable to variable
pattern = %{foo: "bar", bar: %{baz: "qux"}}
good_data = %{foo: "bar", bar: %{baz: "qux", qux: "asdf"}}
bad_data = %{foo: "baz", bar: %{baz: "asdf"}}
### This is perfect
match?(%{foo: "bar", bar: %{baz: "qux"}}, good_data)
#=> true
match?(%{foo: "bar", bar: %{baz: "qux"}}, bad_data)
#=> false
@J3RN
J3RN / backup.sh
Created January 14, 2018 01:13
A simple script I use to backup my flashdrive
#!/bin/bash
# Usage: ./backup.sh <path to directory to archive> <GPG user>
tar -C $1 -c . | gpg --recipient $2 -e > $(date -Iminutes | tr -d ':').tar.gz.gpg
@J3RN
J3RN / old2new.zsh
Last active March 9, 2017 15:30
old2new, the Ruby hash syntax updater
# This script has been tested with zsh 5.2 on macOS 10.12.3 with BSD sed and find.
# It may work under other conditions, but likely does not.
# old2new, the Ruby hash syntax updating function
# Takes the given files and replaces all instances of `:key => value` with the equivalent `key: value`
# Usage: old2new <path>
# NOTE: <path> can be a file or directory
function old2new() {
find $argv \( -name "*.haml" -or -name "*.rb" -or -name "*.erb" \) -exec sed -E -i '' 's/:([A-z]+) =>/\1:/g' '{}' \;
}
@J3RN
J3RN / proc_fix.rb
Last active January 23, 2017 16:22
Convert proc scopes to stabby lambda scopes
# USAGE: ruby proc_fix.rb <one or more space-separated model names without path or extension>
# e.g. ruby proc_fix.rb activity
# e.g. ruby proc_fix.rb accessory bill_charge
# **Must be run in Rail's root**
# What it do: Converts all "Proc.new { |foo|" to "(foo) -> {"
before = /scope(.*)Proc\.new\s*\{\s*\|(.*)\|/
after = 'scope\1->(\2) {'
ARGV.each do |modelname|
@J3RN
J3RN / parser.rb
Last active June 16, 2016 14:38
Another balanced parens parser
class Parser
ENCLOSURES = {
'"' => '"',
'(' => ')',
'{' => '}',
'[' => ']'
}
def initialize
@i = 0
@J3RN
J3RN / keybase.md
Created March 19, 2016 01:39
keybase.md

Keybase proof

I hereby claim:

  • I am j3rn on github.
  • I am j3rn (https://keybase.io/j3rn) on keybase.
  • I have a public key ASBhifQXfnaOXVcs8wkePXEhYqHf5sX7-XkL_U5IX_CALwo

To claim this, I am signing this object:

@J3RN
J3RN / post-update
Created October 20, 2015 02:31
A post-update Git hook that I use to deploy my portfolio site
#!/bin/sh
GIT_REPO=$HOME/portfolio.git
TMP_GIT_CLONE=$HOME/tmp_portfolio
PUBLIC_WWW=$HOME/www
touch $HOME/deploy
git clone $GIT_REPO $TMP_GIT_CLONE
cp -rv $TMP_GIT_CLONE/* $PUBLIC_WWW
rm -rf $TMP_GIT_CLONE
#!/usr/bin/env python
import RPi.GPIO as GPIO
from time import *
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(12, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)