Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Arnett J3RN

View GitHub Profile
@J3RN
J3RN / map_benchmark.ex
Created Jan 15, 2021
Benchmark of different methods of map transformation
View map_benchmark.ex
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 Oct 9, 2018
Trying to pattern match in Elixir, variable to variable
View elixir_test.exs
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 Jan 14, 2018
A simple script I use to backup my flashdrive
View backup.sh
#!/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 Mar 9, 2017
old2new, the Ruby hash syntax updater
View old2new.zsh
# 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 Jan 23, 2017
Convert proc scopes to stabby lambda scopes
View proc_fix.rb
# 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 Jun 16, 2016
Another balanced parens parser
View parser.rb
class Parser
ENCLOSURES = {
'"' => '"',
'(' => ')',
'{' => '}',
'[' => ']'
}
def initialize
@i = 0
View 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 Oct 20, 2015
A post-update Git hook that I use to deploy my portfolio site
View post-update
#!/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
View aurora.py
#!/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)
@J3RN
J3RN / contractions.txt
Last active Aug 31, 2015
List of Common English Contractions
View contractions.txt
ain't
aren't
can't
could've
couldn't
couldn't've
didn't
doesn't
don't
hadn't