Skip to content

Instantly share code, notes, and snippets.

View camflan's full-sized avatar

Camron Flanders camflan

View GitHub Profile
@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,
#! /bin/sh
CURRENT_DAY=`date '+%Y%m%d'`
/usr/sbin/ioreg -w0 -l | grep Capacity | cut -d " " -f 17-50 > $HOME/Dropbox/backups/battery/$CURRENT_DAY.log
"insert/swap iScript debug statements {{{
function! Logging(level)
let base_string = 'debug.log("' . a:level . '", "'
let curr_line = getline('.')
let match = match(curr_line, "debug")
if match == -1
execute "normal i" . base_string
else