Skip to content

Instantly share code, notes, and snippets.

View darylwright's full-sized avatar

Daryl Wright darylwright

View GitHub Profile
@darylwright
darylwright / layout.tsx
Created July 9, 2023 03:34
This is an implementation of theming in a Next.js app using the App Router API.
import {ReactNode, ReactElement} from "react";
import RootComponent from "@/components/root";
export default function RootLayout({ children }: { children: ReactNode }): ReactElement {
return (
<html suppressHydrationWarning>
<body>
<RootComponent>
{children}
</RootComponent>
@darylwright
darylwright / gist-test0.ts
Created June 18, 2023 20:38
This is an example code snippet for test data.
const twitterUrlRegex = /(https?:\/\/)(www.)?twitter.com\//g;
export function getTwitterHandleFromUrl(profileUrl: string): string {
const twitterUserName = profileUrl.replaceAll(twitterUrlRegex, ``);
if (twitterUserName) {
return `@${twitterUserName}`;
}
return ``;
@darylwright
darylwright / gist-test.ts
Created June 1, 2023 12:50
This is an example code snippet used for test data
export default function compare<T>(a0: T, b0: T): number {
if (a0 === b0) return 0;
if (a0 > b0) return 1;
return -1;
}
@darylwright
darylwright / clean-tailwind-classes.tsx
Last active March 16, 2023 21:37
Write easily maintainable Tailwind CSS classes with this simple tag function.
/*
This tag function enables the entry of Tailwind classes within a template string
without cluttering the source DOM with unnecessary whitespace. This approach is
better than using the `classnames` package since commas are not needed to break
classes into separate lines. Additionally, it's easier to organize and rearrange
classes within a template string compared to using `classnames`.
Simply copy the function below and paste it in a utilities file or another
location where it makes sense to be imported from.
@darylwright
darylwright / loading-button.tsx
Last active March 3, 2023 13:47
A simple React HTML button for asynchronous onClick event handlers. Can change appearance and render button content differently depending on its loading state.
import { ReactNodeLike } from "prop-types";
import { MouseEvent, useState } from "react";
type LoadingState = `default` | `loading` | `complete` | `error`;
type LoadingButtonProps = {
render: (state: LoadingState) => ReactNodeLike;
className?: string | undefined;
loadingClassName?: string | undefined;
completeClassName?: string | undefined;
@darylwright
darylwright / gcash2ledger.py
Last active September 16, 2022 18:23 — forked from nonducor/gcash2ledger.py
A simple script to convert an (uncompressed) gnucash XML file to the ledger-cli format
#! /usr/bin/python3
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# (1) Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# (2) Redistributions in binary form must reproduce the above copyright
@darylwright
darylwright / EasyRobocopyBackup.ps1
Last active March 10, 2022 20:07
An opinionated backup script using Robocopy. This script will sync files onto a path that you specify. Must be run as an Administrator. Modify as per your use case.
#Requires -RunAsAdministrator
param(
[Parameter(Mandatory)]
[string]$BackupPath
)
# You can use this function on its own instead of using the entirety of this script
function SyncFiles {
param (
@darylwright
darylwright / OfficeHotKeyEmancipation.ahk
Last active April 19, 2020 18:52
This is an AutoHotKey script which works with DisableOfficeKey.ps1 so that disabling and reenabling the Office hot key is as easy as a couple key presses. By default, (Meh + `) disables the Office key and (Hyper + `) reenables it.
#NoEnv
#Warn
#SingleInstance force
SendMode Input
SetWorkingDir %A_ScriptDir%
disableCommand := A_ScriptDir . "\DisableOfficeKey.ps1"
enableCommand := disableCommand . " -Reenable"
!^+`::
@darylwright
darylwright / DisableOfficeKey.ps1
Created April 19, 2020 11:50
This PowerShell script frees up the Hyper key, which Windows uses as the Office key, so that it is freed up for other use cases.
# DisableOfficeHotKeys
#
# This script disables the hot keys that Windows 10 uses as a result of hijacking
# the Hyper key (Alt + Ctrl + Shift + Win/Super/Command), otherwise known as the
# Office key on some Microsoft devices. This is accomplished by stopping the
# explorer process and registering the hot keys before explorer has a chance to
# do so. The hot keys are then unregistered so that they are free for other use
# cases. This process is reversible via the -Reenable flag.
#
# References:
@darylwright
darylwright / Test.xml
Last active September 8, 2015 14:03
This is a simple MSBuild configuration file that will run xUnit tests based on a project name convention and output the results in NUnit format. Borrowed pieces of this file from https://gist.github.com/coldacid/52d645897fedcacb09e3#file-after-solutionname-sln-targets.
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(BuildConfiguration)' == '' ">
<BuildConfiguration>Release</BuildConfiguration>
</PropertyGroup>
<PropertyGroup>
<TestResultFile>$(SolutionDir)TestResult.xml</TestResultFile>
</PropertyGroup>