Skip to content

Instantly share code, notes, and snippets.


Rich Christiansen rinogo

  • Social5
  • Utah, USA
View GitHub Profile
rinogo / convert-urls-to-origins.js
Created Apr 12, 2022
[Convert URLs to origins (domains)] Convert a list of full URLs into just origins (just the base domains with the protocols)
View convert-urls-to-origins.js
//Convert a list of full URLs into just origins (just the base domains with the protocols)
let s = '';
''].map((u) => {
let url = new URL(u);
s += url.origin + '\n';
rinogo / job.service.spec.ts
Last active Jun 28, 2022
Integration Testing a NestJS Service that leverages Prisma
View job.service.spec.ts
import { Test, TestingModule } from '@nestjs/testing';
import { PrismaService } from '../prisma.service';
import { JobService } from './job.service';
import * as crypto from 'crypto';
describe('JobService', () => {
let service: JobService;
let prisma: PrismaService;
beforeEach(async () => {
rinogo / simple-email-debug.php
Created Apr 28, 2021
[Simple email debug] Instead of a bunch of `var_dump()` or `echo` statements (which can break AJAX responses, etc.), use these simple `mail()` lines.
View simple-email-debug.php
mail("", __FILE__ . ":" . __LINE__, "Example");
//Export variable
mail("", __FILE__ . ":" . __LINE__, var_export($alternative_image, true));
rinogo /
Created Apr 14, 2021
BRISK keypoint detection and brute force matching using OpenCV (Source:
# Imports
import cv2 as cv
import matplotlib.pyplot as plt
import sys
# Open and convert the input and training-set image from BGR to GRAYSCALE
image1 = cv.imread(filename = sys.argv[1],
image2 = cv.imread(filename = sys.argv[2],
rinogo /
Last active Apr 30, 2021
An OpenCV utility function for displaying a set of easily-configurable trackbars and providing their results to an arbitrary callback - useful for quick prototyping and testing
#Usage: `python example.jpg`
import sys
import cv2
#### Example usage ####
def edge_detect(p):
edged = cv2.Canny(p["img"], p["low"] * 15, p["high"] * 15, apertureSize = (p["aperture"] * 2) + 3)
cv2.imshow("Edged", edged)
rinogo /
Created Mar 31, 2021
Optimally resize an image so that its line height is approximately 32 pixels (Keywords: OpenCV, Tesseract, OCR)
#Optimally resize `img` according to the bounding boxes specified in `boxes` (which is simply the (pruned) results from `pytesseract.image_to_data()`).
#Tesseract performs optimally when capital letters are ~32px tall ( Smaller text obviously can't be OCR'd as accurately, but weirdly enough, larger text causes problems as well. So, this function uses the bounding boxes we've found and resizes the image so that the median line height should be ~32px.
def optimal_resize(img, boxes):
median_height = np.median(boxes["height"])
target_height = 32 #See
scale_factor = target_height / median_height
print("Scale factor: " + str(scale_factor))
#If the image is already within `skip_percentage` percent of the target size, just return the original image (it's better to skip resizing if we can)
skip_percentage = 0.07
rinogo / playwright-wait-for-mutation-to-stop.js
Last active Dec 10, 2021
Wait for an element to remain unchanged for a period of time. Useful for waiting for asynchronous (AJAX) updates. Playwright, ES6, Promise, Mutation, MutationObserver
View playwright-wait-for-mutation-to-stop.js
//To test this code, execute it locally or copy/paste it at
//Usage example: `await waitForMutationToStop(await page.$("#container"));`
// @ts-check
const playwright = require("playwright");
//Wait for `elem` to have no mutations for a period of `noMutationDuration` ms. If `timeout` ms elapse without a "no mutation" period of sufficient length, throw an error. If `waitForFirstMutation` is true, wait until the first mutation before starting to wait for the `noMutationDuration` period.
const waitForMutationToStop = async (elem, noMutationDuration = 3000, timeout = 60000, waitForFirstMutation = true) => {
rinogo / plugin.php
Created Jan 3, 2019
YOURLS plugin: keep query string
View plugin.php
Plugin Name: Keep Query String
Description: Adds short URL query string, if any, to the long URL
Version: 0.1
Author: Ozh
yourls_add_filter('redirect_location', 'ozh_kqs');
rinogo / UsHolidays.php
Created Nov 26, 2018
Simple unit-tested class to calculate federal holiday dates for the United States. Methods are included for determining if a date (timestamp) is considered a date and for accessing holidays by name and by timestamp.
View UsHolidays.php
//Adapted by rich at from
class UsHolidays {
private $year;
private $list;
const ONE_DAY = 86400; //Number of seconds in one day
rinogo / script.js
Last active Apr 10, 2018
Improved script.js for Contact Form 7 reCAPTCHA Wordpress plugin. It shows an error message if the user fails to check the reCAPTCHA ("I am not a robot") box.
View script.js
function contact_form_7_recaptcha_callback() {
$(this).data('grecaptcha_id', grecaptcha.render($('#' + this.value)[0], {
'sitekey' : contact_form_7_recaptcha_data.sitekey