I hereby claim:
- I am johnb on github.
- I am johnb (https://keybase.io/johnb) on keybase.
- I have a public key ASB5S-uxyB8B6V4NPLsrhSuT5YiyajgCUXwWVDoQ_eHGPAo
To claim this, I am signing this object:
| # each_with_index is useful, so why not inject_with_index? | |
| module Enumerable | |
| def inject_with_index(memo) | |
| each_with_index {|obj, idx| memo = yield(memo, obj, idx)} | |
| memo | |
| end | |
| end | |
| def passes_lun?(cardnum) | |
| digits = cardnum.gsub(/\D/,'').reverse.split('').map(&:to_i) |
| # We need to create Array.extract if it doesn't already exist | |
| class Array | |
| # Delete some of our items and return (or "extract") a new array holding the deleted items. | |
| # Very similar to partition, but instead of returning copies, it modifies the original list | |
| def extract | |
| extracted = [] | |
| # reverse our deletion so indexes don't get messed up while we're deleting | |
| (length - 1).downto(0) do |idx| | |
| item = self[idx] | |
| extracted << delete_at(idx) if yield(item) |
| #!/usr/bin/env bash | |
| # Canonical location: https://gist.github.com/kljensen/4434992 | |
| ########################################################## | |
| # | |
| # This is a shell script for keeping a journal that is | |
| # * plaintext, | |
| # * time-stamped, | |
| # * encrypted, and |
| require 'json' | |
| # | |
| # List your repositories and their collaborators | |
| # | |
| # Before running this script, follow these steps: | |
| # 1) get an OAuth token from https://github.com/settings/applications | |
| # 2) add it to your environment with "export GW=abc123..." | |
| # 3) add your github user to your environment (e.g. "export GWUSER=JohnB" is mine) | |
| # 4) run this script via "ruby collabotators.rb" | |
| # |
| # Inspired by https://blog.engineyard.com/2014/ruby-list-comprehension | |
| module Kernel | |
| def c(comprehension, &block) | |
| scope = block.send(:binding) | |
| if comprehension =~ /^\s*(\S.*)\s+for\s+(\S+)\s+in\s+(.*)$/ | |
| amount, for_variable, in_range = $1,$2,$3 | |
| scope.send(:eval, in_range).map do |value| | |
| scope.send(:eval, "#{for_variable} = #{value}") | |
| scope.send(:eval, "#{for_variable} = #{amount}") |
| defmodule Stack do | |
| use GenServer | |
| # Public Interface (runs in the caller's process) | |
| def create() do | |
| {:ok, pid} = GenServer.start_link(__MODULE__, []) | |
| pid | |
| end |
| gist --login |
I hereby claim:
To claim this, I am signing this object:
| defmodule YAxis do | |
| @moduledoc """ | |
| The YAxis module attempts to find "reasonable" values for the MapMyWalk | |
| altitude graph. For example, my MapMyWalk graph (as of 7/2022) offers | |
| these altitude values when my workout goes from 138 to 198 feet: | |
| 20.4, 79.5, 138.5, 197.6, 256.6, 315.7 | |
| Which I find to be much less readable/understandable than: | |
| 120, 140, 160, 180, 200, 220 |