View convert-urls-to-origins.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Convert a list of full URLs into just origins (just the base domains with the protocols) | |
let s = ''; | |
['https://www.whatever.com/narf', | |
'https://beta.something.co.uk/?3920#fjfjf'].map((u) => { | |
let url = new URL(u); | |
s += url.origin + '\n'; | |
}); | |
console.log(s); |
View job.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () => { |
View simple-email-debug.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//String | |
mail("me@example.com", __FILE__ . ":" . __LINE__, "Example"); | |
//Export variable | |
mail("me@example.com", __FILE__ . ":" . __LINE__, var_export($alternative_image, true)); |
View test-brisk.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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], | |
flags = cv.IMREAD_GRAYSCALE) | |
image2 = cv.imread(filename = sys.argv[2], |
View call-with-trackbars.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Usage: `python call-with-trackbars.py 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) |
View optimal-resize.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 (https://groups.google.com/g/tesseract-ocr/c/Wdh_JJwnw94/m/24JHDYQbBQAJ). 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 https://groups.google.com/g/tesseract-ocr/c/Wdh_JJwnw94/m/24JHDYQbBQAJ | |
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 |
View playwright-wait-for-mutation-to-stop.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////// | |
//To test this code, execute it locally or copy/paste it at https://try.playwright.tech/ | |
//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) => { |
View plugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
View UsHolidays.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Adapted by rich at byu.net from https://www.damia.no/calculating-u-s-federal-holidays-with-php/ | |
class UsHolidays { | |
private $year; | |
private $list; | |
const ONE_DAY = 86400; //Number of seconds in one day | |
View script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function contact_form_7_recaptcha_callback() { | |
jQuery(function($){ | |
$('.g-recaptcha-explicit-id').each(function(){ | |
$(this).data('grecaptcha_id', grecaptcha.render($('#' + this.value)[0], { | |
'sitekey' : contact_form_7_recaptcha_data.sitekey | |
})); | |
}); | |
}); | |
}; |
NewerOlder