Skip to content

Instantly share code, notes, and snippets.

View BlairCurrey's full-sized avatar
🌎

Blair Currey BlairCurrey

🌎
View GitHub Profile
@BlairCurrey
BlairCurrey / PersonService.test.ts
Created August 7, 2023 19:54
How to Mock Objection Models
// https://github.com/Vincit/objection.js/issues/1477
import { Model, QueryBuilder } from "objection";
class Person extends Model {
static get tableName() {
return "persons";
}
id!: number;
@BlairCurrey
BlairCurrey / wait.js
Created June 6, 2023 11:24
wait utility function for js
// Prevents have to do a callback in setTimeout
function wait(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
// no top level await :/
async function someAsyncFunction() {
await wait(1000); // Wait for 1 second
}
@BlairCurrey
BlairCurrey / hideGithubCodeCoverage.js
Created February 2, 2023 22:03
Hides code coverage "missing coverage" card element warnings from github pull requests
// hides the code coverage boxes on gh file pr diff view.
// added this because it makes it difficult to read
const rule = '.check-annotation-warning { display: none; }'
const sheet = window.document.styleSheets[0];
sheet.insertRule(rule, sheet.cssRules.length);
// workaround to make snippet gloab fn
// can run hideCC() from console
window.hideCC = function (value) {
const sheet = window.document.styleSheets[0];
@BlairCurrey
BlairCurrey / getMyCodeCoverage.js
Last active February 2, 2023 22:43
Sums Codecov coverage changes by Github username on codecov.com
// navigate to https://app.codecov.io/gh/[ORG]/[REPO]/pulls?prStates%5B0%5D=MERGED
function sleep(delay) {
return new Promise(function(resolve) {
setTimeout(resolve, delay);
});
}
async function loadAll(){
while(true) {
@BlairCurrey
BlairCurrey / reorder_execution_count.py
Created January 9, 2022 20:31
python function to re order execution count of jupyter nb cells
import json
def reorder_execution_count(infile, outfile):
with open(infile, encoding='utf-8') as f:
nb = json.load(f)
count = 1
for c in nb['cells']:
# This command-line test gets an input from the user and
# attempts to square it. If there are no issues it
# prints the result of squaring the input. If the input
# is not an integer a ValueError is raised which triggers
# the 'except' which prints the issue to the user. If another
# exception occurs it will not be caught and will terminate the
# program and print the error message to the console.
while True:
val = input("Enter a number to square: ")
@BlairCurrey
BlairCurrey / asserttest.py
Last active March 9, 2021 15:41
Python Assertion Fail Test
# In this python command-line assertion test, ENTER
# results in an assertion failure which stops the program.
# Anything else will continue, which results in being asked for
# input again and again.
while True:
# Get command-line input
val = input("Press enter to test assertion failure: ")
# Enter for assertion failure
if val == "":
@BlairCurrey
BlairCurrey / setup.sql
Last active January 28, 2021 22:07
setup script for grade/ranking view
DROP DATABASE IF EXISTS grades_leaderboard;
CREATE DATABASE IF NOT EXISTS grades_leaderboard CHARACTER SET utf8 COLLATE utf8_general_ci;
USE grades_leaderboard;
DROP TABLE IF EXISTS grades;
DROP TABLE IF EXISTS study_sessions;
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS courses;
DROP VIEW IF EXISTS modules_with_grades;