Skip to content

Instantly share code, notes, and snippets.

View camflan's full-sized avatar

Camron Flanders camflan

View GitHub Profile
@camflan
camflan / utils.sh
Created February 12, 2025 18:26
Shell script helpers
beginswith() { case $2 in "$1"*) true;; *) false;; esac; }
@camflan
camflan / load_dotenv.sh
Created February 11, 2025 20:39 — forked from mihow/load_dotenv.sh
Load environment variables from dotenv / .env file in Bash
# The initial version
if [ ! -f .env ]
then
export $(cat .env | xargs)
fi
# My favorite from the comments. Thanks @richarddewit & others!
set -a && source .env && set +a
@camflan
camflan / django_perf_decorators.py
Created May 18, 2023 20:39
Handy decorators for timing and counting django db queries
import functools
import time
from django.db import connection
def timer(func):
@functools.wraps(func)
def wrapper_timer(*args, **kwargs):
tic = time.perf_counter()
import { useState, useCallback, useLayoutEffect } from "react";
export interface DimensionObject {
width: number;
height: number;
top: number;
left: number;
x: number;
y: number;
right: number;
@camflan
camflan / cache.ts
Last active May 26, 2023 00:50
A handy HOF for creating cacheable resources
const DEFAULT_CACHE_KEY_FN = JSON.stringify;
/**
* @typedef MakeCacheReaderOptions
* @property {Function} [makeCacheKey] - Fn to serialize loader args for caching. Defaults to JSON.stringify
* @property {Map} [cacheMap] - Existing map to use for promise caching
*/
export type MakeCacheReaderOptions<LoaderArgs extends unknown[]> = {
makeCacheKey?: (args: LoaderArgs) => string;
cacheMap?: Map<string, Promise<unknown>>;
@camflan
camflan / useRouterNavigation.ts
Created November 2, 2021 19:27
Stable nextjs router navigation methods
import { useRouter } from "next/router";
import type { NextRouter } from "next/router";
import { useRef, useState } from "react";
type RouterNavigationMethods = Pick<NextRouter, "back" | "push" | "reload" | "replace">;
/**
* useRouter doesn't return stable navigation methods, this gives us something
* stable to call, even as the router changes behind the scenes.
*
@camflan
camflan / QueryCounter.php
Created June 28, 2018 17:22
Debugging class for mysqli connections in php. Lets you mark places in the code that you'd like statistics about. Place many markers, and see the stats differentials between them, as well as totals for the entire run.
<?php
/**
* QueryCounter
* A class useful for debugging mysqli connections
*/
class QueryCounter {
public $connection;
private $stats = [];

Keybase proof

I hereby claim:

  • I am camflan on github.
  • I am camflan (https://keybase.io/camflan) on keybase.
  • I have a public key ASBWldj25UstKpIdjR1041dhtSkquNTiGiIyWP0zrYHGpAo

To claim this, I am signing this object:

@camflan
camflan / SassMeister-input.scss
Created October 28, 2015 19:20
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
$type-scale: (
-15:0.066667rem,
-10:0.186rem,
-9:0.211rem,
-8:0.26rem,
-7:0.295rem,
@camflan
camflan / SassMeister-input.scss
Created October 28, 2015 15:51
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
$type-scale: (
-15:0.066667rem,
-10:0.186rem,
-9:0.211rem,
-8:0.26rem,
-7:0.295rem,