Skip to content

Instantly share code, notes, and snippets.

@4lun
4lun / inertiaui-modal-react.d.ts
Last active October 14, 2025 11:33
Typescript type declarations for "@inertiaui/modal-react" (generated against 1.0.0-beta-4) https://github.com/inertiaui/modal/issues/158
import type {
ComponentPropsWithoutRef,
ComponentType,
ElementType,
ForwardRefExoticComponent,
ReactElement,
ReactNode,
RefAttributes,
} from "react";
import type { AxiosResponse } from "axios";
@4lun
4lun / p1s-machine-start-gcode-default.txt
Created September 29, 2025 07:32
Default and modified machine start gcode for Bambu P1S printer (modified reduces prime lime leaving 50mm gap on right)
;===== machine: P1S ========================
;===== date: 20231107 =====================
;===== turn on the HB fan & MC board fan =================
M104 S75 ;set extruder temp to turn on the HB fan and prevent filament oozing from nozzle
M710 A1 S255 ;turn on MC fan by default(P1S)
;===== reset machine status =================
M290 X40 Y40 Z2.6666666
G91
M17 Z0.4 ; lower the z-motor current
G380 S2 Z30 F300 ; G380 is same as G38; lower the hotbed , to prevent the nozzle is below the hotbed
🚫 <style>body { opacity: 0.2; filter: grayscale(1); font-size: 10em; font-family: sans-serif; display: flex; align-items: center; justify-content: center } h1 { display: none; }</style>
@4lun
4lun / useAPIForm.ts
Last active August 29, 2025 14:05
A (React) utility hook that is a drop in replacement for the useForm hook from Inertia.js, but for use with general API endpoints. Any page updates or navigation needs to be handled manually via onSuccess callback.
/**
* A utility hook that is a drop in replacement for the useForm hook from
* Inertia.js, for use with general API endpoints. Any page updates or
* navigation needs to be handled manually via onSuccess callback.
*
* Author: https://github.com/4lun
* Source: https://gist.github.com/4lun/b91cdc4b82c1ff3b5506b47cb29dcfd4
*
* Based on a combination of
* - https://gist.github.com/mohitmamoria/91da6f30d9610b211248225c9e52bebe
@4lun
4lun / 2024_05_16_152355_create_system_meta_table.php
Last active May 16, 2024 16:40
Laravel faux scheduler (i.e. faux cron), if running in an environment that lacks a decent scheduler/cron option (e.g. DigitalOcean App Platform). Primarily designed to be triggered via uptime checker, e.g. can hook into health check endpoint `Event::listen(function (DiagnosingHealth $event) { FauxScheduler::dispatch(); });`
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
@4lun
4lun / helpers.php
Created April 22, 2024 12:00
Laravel Route macros/helpers for serving multiple domains
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
// Usage:
//
// Route::domain('domain.com', function () {
// Route::get('/', [DomainController::class, 'index']);
// });
@4lun
4lun / apache_app.conf
Last active April 18, 2024 16:32
Get access logs on DigitalOcean App Platform (with PHP via heroku-php-apache2) logging the forwarded Client IP by default on the "Runtime Logs" tab
# Update run_command in app spec to pass config, e.g. `run_command: heroku-php-apache2 -C apache_app.conf public/`
DirectoryIndex index.php index.html index.htm
# mod_remoteip should be loaded by default, but needs configuration
RemoteIPHeader DO-Connecting-IP
# Trust any private IPv4 ranges
RemoteIPTrustedProxy 10.0.0.0/8
RemoteIPTrustedProxy 172.16.0.0/12
@4lun
4lun / git-clone-different-ssh-key.sh
Created February 20, 2024 10:32
Clone a git repo using an alternative ssh key
GIT_SSH_COMMAND="ssh -i ~/.ssh/PRIVATE_KEY" git clone [email protected]:ORG/REPO.git
@4lun
4lun / gist:9a9bd9c3d195d22005216d71ec661b55
Created January 19, 2024 15:15
Nginx server block config lines for piping access_log and error_log to syslog (useful for then getting relayed to papertrail). Source: https://chabik.com/nginx-logging-to-syslog/
access_log syslog:server=unix:/dev/log,tag=nginx,nohostname,severity=info combined;
error_log syslog:server=unix:/dev/log,tag=nginx,nohostname,severity=error;
@4lun
4lun / toBlueprint.js
Created November 30, 2023 10:20
Generate a quick and dirty type "blueprint" of a JS object/array/variable
function toBlueprint(obj) {
if (!obj || typeof obj !== 'object') {
return obj;
}
if(Array.isArray(obj)) {
return obj.map(toBlueprint) // nit: won't unify common props
}
return Object.keys(obj).reduce((acc, key) => {
let blueprint = typeof obj[key];
if (blueprint === "object" && blueprint) {