Skip to content

Instantly share code, notes, and snippets.

View tadger's full-sized avatar

Jared Donaldson tadger

View GitHub Profile
@tadger
tadger / quadtree.ts
Created January 20, 2025 21:58
A simple quadtree implementation
export class Point<Data = any> {
public x: number
public y: number
public userData?: Data
constructor(x: number, y: number, userData?: Data) {
this.x = x
this.y = y
if (userData) {
@tadger
tadger / rename-js-to-jsx.js
Last active January 26, 2024 13:04 — forked from Reeska/rename-js-to-jsx.js
A script to convert .js to .jsx when they contains JSX tags
// node ./rename-js-to-jsx.js ./my/folder
const fs = require('fs')
const path = require('path')
// Options
const src = process.argv[2] ?? './'
const pattern = process.argv[3] ? new RegExp(`${process.argv[3].replace('.', '\\.')}$`) : /\.js$/
const newExtension = process.argv[4] ?? '.jsx'
@tadger
tadger / vite.config.js
Created January 4, 2024 20:16
vite configuration - JSX in .js files
import react from '@vitejs/plugin-react-swc'
import { defineConfig, transformWithEsbuild } from 'vite'
import { resolve } from 'path'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
{
name: 'load+transform-js-files-as-jsx',
async transform(code, id) {
@tadger
tadger / index.js
Created January 2, 2020 17:47
A tool for generating random release names
#!/usr/bin/env node
const Haikunator = require('haikunator')
const boxen = require('boxen')
const chalk = require('chalk')
const { bold } = require('chalk').default
const { name, version } = require('./package.json')
const haikunator = new Haikunator({
seed: new Date().getTime().toString(),
@tadger
tadger / safariDate.js
Last active August 9, 2019 14:15
A frightening monkey-patch for the Safari Date constructor to construct dates using ISO strings without applying the timezone offset.
(function (w) {
// latest versions of Safari will have an Apple Pay object
if (!w.ApplePaySession) {
return;
}
var _Date = window.Date;
var unbind = Function.bind.bind(Function.bind);
function instantiate(constructor, args) {
@tadger
tadger / post-merge
Last active December 31, 2016 02:21
#/usr/bin/env bash
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
@tadger
tadger / gh-create.sh
Created March 31, 2016 03:16
A bash script for creating new repos on github from the command line. Usage: $ gh-create [repo-name]
gh-create() {
repo_name=$1
dir_name=`basename $(pwd)`
if [ "$repo_name" = "" ]; then
echo "Repo name (hit enter to use '$dir_name')?"
read repo_name
fi