Skip to content

Instantly share code, notes, and snippets.

View Jeff-Russ's full-sized avatar

Jeffrey Russ Jeff-Russ

View GitHub Profile
@Jeff-Russ
Jeff-Russ / gitReview.sh
Last active December 16, 2022 19:41
gitReview allows navigation through commit histories and release tags, avoiding detached HEAD annoyances.
# Copyright (c) 2022, Jeff Russ
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
# NOTE: This script requires zsh and peco (see https://github.com/peco/peco)
# It be sourced from ~/.zshrc and the gitReviewSetup function should be called
# once per terminal session where the $PWD is under git revision control.
@Jeff-Russ
Jeff-Russ / Show Safari History with Timestamps.md
Last active June 18, 2020 21:01
Show recent Safari history with timestamps (command line function)

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
Jeff-Russ / arduinoVCC.md
Last active October 31, 2018 16:11
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
Jeff-Russ / wrap_to_range.h
Last active October 31, 2018 05:00
C/C++ function to wrap out-of-bounds numbers to a specific range (modulo with an offset)
/* 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
Jeff-Russ / Bit_Manipulation.h
Created October 22, 2018 07:18
C/C++ Macros for Bit Manipulation i.e. Arduino
/* Bit Manipulation Macros
A good article: http://www.coranac.com/documents/working-with-bits-and-bitfields/
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
Jeff-Russ / download_numbered_files.rb
Last active July 24, 2018 10:26 — 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.
#!/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

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.

Numerics

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

@Jeff-Russ
Jeff-Russ / recursive_search.php
Last active February 18, 2017 05:09
PHP Recursive Array 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
Jeff-Russ / regex_capture_checker.php
Last active February 21, 2017 17:18
Regex Capture Checker (in PHP)
<?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
Jeff-Russ / Sequence.md
Last active March 1, 2017 18:17
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