Skip to content

Instantly share code, notes, and snippets.

Peter Marreck pmarreck

  • formerly, and currently a contractor
  • Long Island, NY
  • Sign in to view email
Block or report user

Report or block pmarreck

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
pmarreck /
Last active May 14, 2020
Some easy bash scripts to encrypt/decrypt data, for anyone who wants to go all cloak&dagger. (bitcoin private keys, etc.)
# Encryption functions. Requires the GNUpg "gpg" commandline tool. On OS X, "brew install gnupg"
# Explanation of options here:
# --symmetric - Don't public-key encrypt, just symmetrically encrypt in-place with a passphrase.
# -z 9 - Compression level
# --require-secmem - Require use of secured memory for operations. Bails otherwise.
# cipher-algo, s2k-cipher-algo - The algorithm used for the secret key
# digest-algo - The algorithm used to mangle the secret key
# s2k-mode 3 - Enables multiple rounds of mangling to thwart brute-force attacks
# s2k-count 65000000 - Mangles the passphrase this number of times. Takes over a second on modern hardware.
# compress-algo BZIP2- Uses a high quality compression algorithm before encryption. BZIP2 is good but not compatible with PGP proper, FYI.
pmarreck / migrations_in_console_cheatsheet.exs
Created Sep 25, 2017
How to run Ecto migrations in Elixir/Phoenix from an `iex -S mix` or production console
View migrations_in_console_cheatsheet.exs
# How to run Ecto migrations from IEx console... Examples
# preliminaries assumed in the following code, change to fit your environment:
alias YourAppName.Repo
your_app_name_as_atom = :mpnetwork
downto_version = 20170724182558
# Down:, "priv/repo/migrations/", :down, [to: downto_version])
pmarreck / Ruby.sublime-build
Last active May 1, 2020
Get Sublime Text 2 (or 3) to use your RVM ruby and bundle Gemfile
View Ruby.sublime-build
# Get Sublime to use your rvm ruby... Change your ~/Library/Application Support/Sublime Text 2/Packages/Ruby/Ruby.sublime-build
# (for ST3: ~/Library/Application Support/Sublime Text 3/Packages/User/Ruby.sublime-build) to this, replacing YOURUSERNAME.
# I am still looking to optimize this further... For example, avoiding hardcoding by using something like $HOME, although
# I have yet to get any form of that to work.
"working_dir": "${project_path}",
"cmd": [
"/Users/YOURUSERNAME/.rvm/bin/rvm-auto-ruby", "-Ilib:test", "$file"
pmarreck / fibonacci.exs
Last active Apr 28, 2020
Enumerative and recursive (via TCO) fibonacci in Elixir, with timings
View fibonacci.exs
defmodule Fib do
def run_recursive(num) do
run_recursive(num, 0, 1)
# FYI: tail call optimized
def run_recursive(0, res, _), do: res
def run_recursive(n, res, nxt) when n > 0 do
run_recursive(n-1, nxt, res+nxt)
pmarreck / ecto_postgres_fulltext_search_querying_example.ex
Last active Mar 17, 2020
How to set up postgres fulltext search triggers, index, and tsvector column on Elixir/Phoenix, with Ecto querying, including ranking and sorting by rank
View ecto_postgres_fulltext_search_querying_example.ex
defmodule YourAppName.Search do
# ...
@doc """
Queries listings.
def query_listings(query, current_user) do
default_scope = from l in Listing, where: l.draft == false or l.user_id == ^, order_by: [desc: l.updated_at], limit: 50
id = _try_integer(query)
pmarreck / realityisprobablynotwhatwethink.txt
Last active Jan 12, 2020
Account/testimony of my possible ghost experience aboard USAF KC-10A tail number 2-0191 circa late 1994
View realityisprobablynotwhatwethink.txt
From 1993 until 1997 I served as AFSC 2A636 (aircraft electrical and environmental systems specialist) in the USAF on the KC-10 aircraft.
I was stationed at March AFB from 1993-1995, it was subsequently closed to active duty by Pres. Clinton and they shipped us all north to Travis AFB, where I served until 1997.
The following happened while I was at March (which was a lovely base, btw... possibly one of the best times in my life was spent there).
It was an activity-free Friday afternoon- all missions were done, we were sitting around.
Erik Anderson (who outranked me) suggested we take the downtime to catch up on some OJT (on the job training) to sign off some stuff.
So we go to the flightline, which is completely dead at this point, and we pick any old available jet, the one we picked happened to
be 02-0191 (tail number; we just called it 2191). I remember this because of a reason you will learn shortly.
We board the jet and since it was so dead, Erik did not bother tagging the battery switch (which normally
View Sorting accented characters in Ruby correctly.rb
class String
# note: very rough, does not handle caps (but that could be added), just something to help sort accented characters correctly...
TRANSLATION_HASH = {"’"=>"'","åäáàâ" => "a", "ëéèê" => "e", "ïíìî" => "i", "öóòô" => "o", "üúùû" => "u", "ß" => "ss"}
UNUNICODE = Hash[*{|u,as| u.unpack("U*").inject([]){|sum,e| sum << e; sum << as}}.flatten]
def un_unicode
self.unpack("U*").map{|c| UNUNICODE[c] ? UNUNICODE[c] : c.chr}.join
# use case
pmarreck /
Last active Nov 22, 2019
A single Time Machine snapshot directory's extended attributes (!)
bash>> ls -@l PeterMBP
drwxr-xr-x@ 13 root wheel 442 Nov 6 05:23 2019-11-06-052333 5 1 16 16 1 8 1
pmarreck / email_header_parser.rb
Last active Oct 29, 2019
Superfast email header parser in Ruby, using regular expressions. This solution is 250 times faster than using the "Mail" gem. :O Time with my regex: 0.063965 seconds Time with Mail gem: 16.327161 seconds Note that I included some encoding-fix code. YMMV and encoding fixes are all debatable or fail in some corner case.
View email_header_parser.rb
require 'ap'
require 'mail'
# String monkeypatch
# This is one of many possible "encoding problem" solutions. It's actually an intractable problem
# but you'd have to read "Gödel, Escher, Bach" to understand why...
class String
def clean_utf8
# self.force_encoding("UTF-8").encode("UTF-16BE", :invalid=>:replace, :replace=>"?").encode("UTF-8")
unpack('C*').pack('U*') if !valid_encoding?
View mix deps.tree output
$ mix deps.tree
├── eliver ~> 2.0 (Hex package)
│ └── enquirer ~> 0.1.0 (Hex package)
├── ecto_sql ~> 3.1.6 (Hex package)
├── gettext ~> 0.13 (Hex package)
├── lz4 ~> 0.2.2 (Hex package)
├── briefly ~> 0.3 (Hex package)
├── number ~> 0.5 (Hex package)
You can’t perform that action at this time.