Skip to content

Instantly share code, notes, and snippets.

@nickludlam
nickludlam / personalize_mammoth.rb
Last active February 21, 2024 16:15
This file will adapt the Mammoth git repo to a personal bundle identifier and development team, so it becomes locally buildable
#!/usr/bin/env ruby
# File: personalize_mammoth.rb
# Description: Adapt the Mammoth project to a personal bundle identifier and development team
# and change the entitlements files to match the desired bundle identifier
# When run again, it will revert the changes
# Usage: ruby personalize_mammoth.rb
# Deps: xcodeproj
require 'xcodeproj'
@nickludlam
nickludlam / svelte_experience.md
Last active February 19, 2024 17:54
A Rails guy learns SvelteKit

My experience coming to SvelteKit from Rails and Ruby

This is specifically because my experience in webdev is very informed by Ruby on Rails. I've done plenty of work with strongly typed languages, but never webdev. My experience is also from 2018 and older, so there may well be modern solutions that achieve parity with the clever things I'm finding in SvelteKit that I feel were not as present in Rails work. Don't at be bro!

Strong types are extraordinary at catching inter module communication issues. Any time you’re putting polymorphic messages into Redis, etc. Also it's very nice having a strongly typed, schema-aware database client. The auto-completion is very useful.

Idea: make some playgrounds to show examples live

Frustrations

Sometimes the VSCode plugins don’t update when you push prisma schema changes

@nickludlam
nickludlam / test-form.svelte
Last active February 4, 2024 14:43
In this scenario we want to have a <Slider/> component driving a numeric 'volume' value within the form, but also have an input element where you can type the value
<script lang="ts">
import { onDestroy } from "svelte";
import { writable } from "svelte/store";
import type { SuperValidated } from "sveltekit-superforms";
import { formFieldProxy, superForm } from "sveltekit-superforms/client";
import * as Form from "$lib/components/ui/form";
import { Slider } from "$lib/components/ui/slider";
@nickludlam
nickludlam / gist:7d3d8bf83fd5f6b0768bf04ddf11bc9f
Created January 17, 2024 19:13
Grabbing this from a Slack post by twitter.com/kieran_nee - How to be a good dev in a studio
## Good Conduct
- Fix all warnings in your code before commits
- I don’t want to have to turn on Warnings as Errors, but I will if I have to discuss this more than a few times.
- Keep an eye on runtime warnings. If they’re ones you’ve introduced, fix them before committing.
- If they’re ones you think you can fix, please fix them.
- If you aren’t sure what’s causing them. Let the rest of the team know so someone who knows the root cause can fix them.
- Check your references for NULL and handle gracefully, don’t just assume they exist.
- If you see something broken
- FIX IT if you are confident you know how and it won’t massively impinge on your current work
@nickludlam
nickludlam / solve.cr
Created December 4, 2023 15:33
Advent of Code 2023 - Day 4
require "string_scanner"
# Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
puts "Let's gooooo!"
lines = [] of String # ooh fancy, types!
part_one_score = 0
part_two_card_count = 0
@nickludlam
nickludlam / sync_bookmarks.py
Created October 29, 2023 17:54
Sync mastodon bookmarks to linkding
"""Sync Mastodon bookmarks to Linkding
This script will automatically fetch a user's bookmarks from a
Mastodon instance. If the bookmark is not yet present in the
Linkding bookmark site, it's created as an unread, along with
any other things like custom tags.
Optionally, if the bookmarked Mastodon toot only contains one
link, excluding any others like user mentions and hashtags,
then that link is used for the bookmark URL, instead of the
@nickludlam
nickludlam / GetPixelBilinearFromNativeArray
Last active May 16, 2023 22:57
The equivalent to GetPixelBilinear() but using a NativeArray
private float4 GetPixelBilinearFromNativeArray(float2 uv, float size, NativeArray<half4> data)
{
float2 pixelLocation = uv * size;
float2 floorPixelLocation = math.floor(pixelLocation);
float2 ceilPixelLocation = floorPixelLocation + new float2(1, 1);
float xDistance = pixelLocation.x - floorPixelLocation.x;
float yDistance = pixelLocation.y - floorPixelLocation.y;
#ifndef FOLIAGE_WIND_INCLUDED
#define FOLIAGE_WIND_INCLUDED
// This is the Unity Shadergraph port of https://mtnphil.wordpress.com/2011/10/18/wind-animations-for-vegetation/
#define SIDE_TO_SIDE_FREQ1 1.975
#define SIDE_TO_SIDE_FREQ2 0.793
#define UP_AND_DOWN_FREQ1 0.375
#define UP_AND_DOWN_FREQ2 0.193
@nickludlam
nickludlam / GetNoiseUV.hlsl
Created February 12, 2023 19:16
Function to sample a blue noise texture for use with each screen pixel
// Requires NDC from GetVertexPositionInputs() in the vert shader
float2 GetNoiseUV(float2 positionNDC) {
float2 blueTexSizeMultiplier = _BlueNoise_TexelSize.xy; // i.e. 1/32
float2 screenWidthHeight = _ScreenParams.xy + float2(0.5, 0.5); // i.e. 1920,1080 + half to center
return screenWidthHeight * blueTexSizeMultiplier * positionNDC;
}
@nickludlam
nickludlam / sync_mastodon_bookmarks.py
Last active January 26, 2023 19:49
Sync Mastodon bookmarks with an instance of the bookmarking website Linkding at https://github.com/sissbruecker/linkding
"""Sync Mastodon bookmarks to Linkding
This script will automatically fetch a user's bookmarks from a
Mastodon instance. If the bookmark is not yet present in the
Linkding bookmark site, it's created as an unread, along with
any other things like custom tags.
If the bookmarked Mastodon toot only contains one link, excluding
any others like user mentions and hashtags, then that link is
used for the bookmark URL, instead of the toot itself.