Skip to content

Instantly share code, notes, and snippets.

View kidGodzilla's full-sized avatar
👋
Working from home forever

James Futhey kidGodzilla

👋
Working from home forever
View GitHub Profile
@kidGodzilla
kidGodzilla / flex-center-component.html
Created March 19, 2025 07:21
Flexbox center a div (wrong answers only)
<script>
class FlexCenter extends HTMLElement {
constructor() {
super();
const shadow = this.attachShadow({ mode: 'open' });
const wrapper = document.createElement('div');
wrapper.classList.add('center');
const slot = document.createElement('slot');
@kidGodzilla
kidGodzilla / chunked-video-uploads.js
Created December 19, 2024 07:40
Chunked video uploads frontend/backend
// Frontend
const fileInput = document.querySelector('input[name="video"]');
const file = fileInput.files[0];
const chunkSize = 10 * 1024 * 1024; // 10MB
const totalChunks = Math.ceil(file.size / chunkSize);
for (let chunk = 0; chunk < totalChunks; chunk++) {
const start = chunk * chunkSize;
const end = Math.min(start + chunkSize, file.size);
const blob = file.slice(start, end);
#!/bin/bash
set -e
######################################################################
# This simple backup script generates commands to recreate dokku apps
#
# It creates the app, adds domains, and restores configuration for each app
# It does not handle databases, persistent storage, or other plugin settings
#
# Usage: Run this script on a Dokku server (you must either be logged in as the
@kidGodzilla
kidGodzilla / pdf2png.sh
Last active May 20, 2024 07:03
PDF to PNG Script for Quickdrop App
# PDF to PNG shell script for Quickdrop app
# https://quickdrop.antran.app/
# pdfburst shell script
# chmod 0755 pdfburst
#!/usr/bin/swift
import Foundation
import PDFKit
#!/bin/bash
set -e
######################################################################
# This Bootstrap Script installs Dokku latest on Ubuntu (use LTS or latest)
#
# This script also installs UFW (firewall), some basic Dokku plugins, and
# raises ulimits. Comment out any step you wish to skip.
#
# IMPORTANT: This script also disables password authentication via SSH for
@kidGodzilla
kidGodzilla / random-name.js
Created November 12, 2018 00:07
Generate a random name in adj-noun format as a placeholder (aquatic ninja, calculating banjo, etc.)
function randomName () {
var adjectives = "aback,abaft,abandoned,abashed,aberrant,abhorrent,abiding,abject,ablaze,able,abnormal,aboard,aboriginal,abortive,abounding,abrasive,abrupt,absent,absorbed,absorbing,abstracted,absurd,abundant,abusive,acceptable,accessible,accidental,accurate,acid,acidic,acoustic,acrid,actually,adHoc,adamant,adaptable,addicted,adhesive,adjoining,adorable,adventurous,afraid,aggressive,agonizing,agreeable,ahead,ajar,alcoholic,alert,alike,alive,alleged,alluring,aloof,amazing,ambiguous,ambitious,amuck,amused,amusing,ancient,angry,animated,annoyed,annoying,anxious,apathetic,aquatic,aromatic,arrogant,ashamed,aspiring,assorted,astonishing,attractive,auspicious,automatic,available,average,awake,aware,awesome,awful,axiomatic,bad,barbarous,bashful,bawdy,beautiful,befitting,belligerent,beneficial,bent,berserk,best,better,bewildered,big,billowy,bite-Sized,bitter,bizarre,black,black-And-White,bloody,blue,blue-Eyed,blushing,boiling,boorish,bored,boring,bouncy,boundless,brainy,brash,brave,brawny,
@kidGodzilla
kidGodzilla / dokku_on_digital_ocean.md
Created October 25, 2020 06:43 — forked from henrik/dokku_on_digital_ocean.md
Notes from running Dokku on Digital Ocean.

My notes for Dokku on Digital Ocean.

These may be a bit outdated: Since I originally wrote them, I've reinstalled on a newer Dokku and may not have updated every section below.

Commands

Install dokku-cli (gem install dokku-cli) for a more Heroku-like CLI experience (dokku config:set FOO=bar).

# List/run commands when not on Dokku server (assuming a "henroku" ~/.ssh/config alias)

ssh henroku dokku

@kidGodzilla
kidGodzilla / geoip.js
Created February 22, 2022 20:08
Geo IP node / express
const requestIp = require('request-ip');
function getIp (req) {
let ip = null;
try {
//ip = (req.headers['x-forwarded-for'] || '').split(',').pop() ||
// req.connection.remoteAddress ||
// req.socket.remoteAddress ||
// req.connection.socket.remoteAddress;
@kidGodzilla
kidGodzilla / browser-icon.js
Created May 29, 2022 17:34
Infer Browser by input string & return an icon
/***
* Given a slightly messy set of input strings, attempt to match a well-known browser name, and return an icon
*
* Examples:
* inferBrowserIcon('safari') // exact match
* inferBrowserIcon('Safari Mobile 15.4') // matches "safari" from input string
* inferBrowserIcon('Firefox 99', 128) // pick a specific size (from sizes)
* inferBrowserIcon('unknownbrowser') // fallback if no match
* inferBrowserIcon(null, 128, 'brave') // You know the browser-logos repo key
*/
@kidGodzilla
kidGodzilla / region_code_lookup.js
Last active April 5, 2024 21:16
Region Code Lookup (Javascript)
// Raw data from: https://github.com/country-regions/country-region-data/blob/master/data.json
const data = JSON.parse('[{"countryName":"Afghanistan","countryShortCode":"AF","regions":[{"name":"Badakhshan","shortCode":"BDS"},{"name":"Badghis","shortCode":"BDG"},{"name":"Baghlan","shortCode":"BGL"},{"name":"Balkh","shortCode":"BAL"},{"name":"Bamyan","shortCode":"BAM"},{"name":"Daykundi","shortCode":"DAY"},{"name":"Farah","shortCode":"FRA"},{"name":"Faryab","shortCode":"FYB"},{"name":"Ghazni","shortCode":"GHA"},{"name":"Ghor","shortCode":"GHO"},{"name":"Helmand","shortCode":"HEL"},{"name":"Herat","shortCode":"HER"},{"name":"Jowzjan","shortCode":"JOW"},{"name":"Kabul","shortCode":"KAB"},{"name":"Kandahar","shortCode":"KAN"},{"name":"Kapisa","shortCode":"KAP"},{"name":"Khost","shortCode":"KHO"},{"name":"Kunar","shortCode":"KNR"},{"name":"Kunduz","shortCode":"KDZ"},{"name":"Laghman","shortCode":"LAG"},{"name":"Logar","shortCode":"LOW"},{"name":"Maidan Wardak","shortCode":"WAR"},{"name":"Nangarhar","shortCode":"NAN