Skip to content

Instantly share code, notes, and snippets.

Jeff-Russ / Show Safari History with
Last active Jun 18, 2020
Show recent Safari history with timestamps (command line function)
View Show Safari History with

Show Recent Safari History with Timestamps

This creates a command for you to run in the terminal (or similar) zsh shell terminal app. I believe this should work in bash terminals as well. Once you're done setting it up you simply type

Jeff@MBP ~ % safariHist 8 
Thu Jun 18 16:50:59 EDT 2020 | YouTube
Thu Jun 18 16:50:51 EDT 2020 | Browse All of Google's Products & Services - Google
Thu Jun 18 16:50:49 EDT 2020 | Browse All of Google's Products & Services - Google
Thu Jun 18 16:50:47 EDT 2020 | Google - About Google, Our Culture & Company News
Jeff-Russ /
Last active Oct 31, 2018
Accurate Arduino analogRead() with a Simple VCC Detection

Accurate Arduino analogRead() with a Simple VCC Detection

This is a function to determine your Arduino's supply voltage automatically in order to convert the results of analogRead into a much more accurate voltage. As you may know, analogRead() returns a value that's relative to the supply voltage to the Arduino, which can deviate. If you feed a known voltage to an analog pin, this function can read and use it to calculate what Arduino's supply voltage is:

double getArduinoVcc(int analog_pin, double expected_volt)
    double received_frac = (double)analogRead(analog_pin) / 1023.0;    
Jeff-Russ / wrap_to_range.h
Last active Oct 31, 2018
C/C++ function to wrap out-of-bounds numbers to a specific range (modulo with an offset)
View wrap_to_range.h
/* wrap_to_range() is similar to modulo but, instead of wrapping back to zero, wraps
back to specified range closer to the top (what the modulo value would be).
It was created for musical keyboard to handle a note command that is too high to be
played in order to handle that event that so that the specified note is still played
just in a different octave (the highest octave possible).
For those where that useage doesn't ring true, imagine a clock function (in 24 hour
time) where if 24:01 is attempted to be set (an invalid time) it is adjusted to 23:01.
The same 23:01 would be returned if 25:01 or 26:01 are attempted.
The second arg is the max (allowed) value
Jeff-Russ / Bit_Manipulation.h
Created Oct 22, 2018
C/C++ Macros for Bit Manipulation i.e. Arduino
View Bit_Manipulation.h
/* Bit Manipulation Macros
A good article:
x is a variable that will be modified.
y will not.
pos is a unsigned int (usually 0 through 7) representing a single bit position where the
right-most bit is bit 0. So 00000010 is pos 1 since the second bit is high.
bm (bit mask) is used to specify multiple bits by having each set ON.
bf (bit field) is similar (it is in fact used as a bit mask) but it is used to specify a
range of neighboring bit by having them set ON.
Jeff-Russ / download_numbered_files.rb
Last active Jul 24, 2018 — forked from johnjohndoe/download-url-to-file.rb
Ruby script to download a number of files from individual URLs via HTTP/HTTPS/FTP specified in an external file.
View download_numbered_files.rb
#!/usr/bin/env ruby
# Ruby script to download many numbered of files
# from individual URLs via HTTP/HTTPS/FTP
# specified in an external file.
# Author: Jeff Russ
# Original Author: Tobias Preuss
# License: Creative Commons Attribution-ShareAlike 3.0 Unported
View Handy Regexes .md

Handy Regex Patterns

Here are some handy regex patterns and portions of patterns. I seem to keep coming back to these so it made sense to document them for the sake of memory.


Signed integers or floats. Skipping the zero before the decimal, for example .1, +.1 or -.1 , is valid.

Jeff-Russ / recursive_search.php
Last active Feb 18, 2017
PHP Recursive Array Search
View recursive_search.php
function recursive_search($val, $arr, $mode=1, $strict=true)
$depth = ($depth=(int)$mode) ? $depth : 0;
if (strpos($mode, 'all')!==false) {
$r = function ($val, $a, $d, $s, $l=0, &$path=[], &$keys=[], &$i=0) use (&$r) {
foreach($a as $k=>$v) {
$path[] = $k;
if (!$s && $v==$val || $v===$val) $keys[$i++] = $path;
elseif ($l<$d && (is_array($v) /*|| method_exists($v,'getIterator')*/))
Jeff-Russ / regex_capture_checker.php
Last active Feb 21, 2017
Regex Capture Checker (in PHP)
View regex_capture_checker.php
function regex_capture_checker($regex_pat, $strings) {
foreach ($strings as $k => $v) {
if (is_integer($k)) {
$string = $v;
$comp = false;
} else {
$string = $k;
$comp = $v;
Jeff-Russ /
Last active Mar 1, 2017
PHP: Sequential Array Class

Sequence and TSequence

TSequence is an array trait with numerically sortable keys. Keys can be negative or positive integers or floats. It does not matter whether they are actually numeric types or string and if they are strings they are allowed to contain any character so long as they start with something numeric. The non-numeric ending of the string key, if present, is called the 'tag'.

You can optionally protect to an already assigned element by automatically incrementing the numeric portion of the key you provided until a free slot is

Jeff-Russ / PHP: numeric array
Last active Feb 11, 2017
PHP: numeric array keys
View PHP: numeric array

PHP's Numeric & String Key Type Juggling

Arrays in PHP treat integer and string integers synonymously. If you set $a['1'] = '1' and access $a[1] you will get '1'. This is because php juggled your string key to an integer before assigning it; the assigment was actually made to an integer key. PHP also juggles in the process of accesssing too which means if you try to access [1] with ['1'] it will work. Therefore there is no real distinction between string integers and real integer, you can use them interchangably.

Remember that '1.0' does not equal '1' or 1 with strict comparison. This is true of array keys as well: you can have both ['1.0'] and ['1'] and they would be different elements but not [1] and ['1'].