Skip to content

Instantly share code, notes, and snippets.

View shirakaba's full-sized avatar
💭
🧙‍♂️

Jamie Birch shirakaba

💭
🧙‍♂️
View GitHub Profile
@shirakaba
shirakaba / vite-configuration.md
Last active November 18, 2024 03:50
How to configure Vite from svelte.config.js in SvelteKit projects

SvelteKit

In SvelteKit projects, SvelteKit wraps around Vite.

This example is for configuring path aliases, but you get the idea. There's a kit.vite property in svelte.config.js, and you'd configure vite through there.

https://kit.svelte.dev/faq#aliases

Vite's plugins should be API-compatible with Rollup, to my understanding.

@shirakaba
shirakaba / AndroidManifest.xml
Created September 26, 2021 15:35
NativeScript Android generated files
// example/android/app/src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.reactnativenativescriptruntime">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
@shirakaba
shirakaba / iOS Safari text selection.md
Last active August 22, 2021 10:07
How text selection works in iOS Safari (inconclusive investigation)

Logging all events

Object.keys(window).forEach(key => {
    if (/^on/.test(key)) {
        window.addEventListener(key.slice(2), event => {
            const date = new Date();
            const timestamp = `${date.getMinutes()}:${date.getSeconds()}:${date.getMilliseconds()}`;
            console.log(`${timestamp} ${event.type} isTrusted: ${event.isTrusted}`);
        });
@shirakaba
shirakaba / ffmpeg.md
Last active June 21, 2022 03:25
Halve the size of a video, but properly

Use the flag:

-vf "scale='bitand(oh*dar, 65534)':'bitand(ih/2, 65534)', setsar=1"

For example (this also removes metadata and audio, and re-encodes at high quality):

ffmpeg -i landscape_safe_area_insets.mov -qscale 0 -vf "scale='bitand(oh*dar, 65534)':'bitand(ih/2, 65534)', setsar=1" -metadata location="" -metadata location-eng="" -an landscape_safe_area_insets.mp4
@shirakaba
shirakaba / README.md
Last active April 9, 2022 10:44
Swapping between Amazon Japan and Amazon UK on your Kindle

This guide is aimed at people outside of Japan (I use UK for the sake of discussion) trying to learn Japanese by reading Kindle books, or vice versa. This approach may well work for other Amazon regions, though it should be noted that to my understanding, Amazon Japan is a special case amongst the regions (I believe it's a separate business entity from typical Amazon regions in ways that the other regions aren't) and therefore may work somewhat differently.

How to switch Kindle between Amazon accounts

Once your Kindle is registered to your Amazon UK account, you must deregister that account before registering the Amazon Japan account.

Any time you switch accounts, your downloaded library will be cleared. By that, I mean that your downloads will be deleted from disk – but you are still entitled to redownload whichever purchases are associated with your currently-registered account. Rest assured that any manually-added files (PDFs that you've added via file transfer, for example) will not be cleared w

@shirakaba
shirakaba / README.md
Last active March 27, 2025 15:25
GUI-based debugging of iOS/macOS Rust projects in Xcode

Here's how to get your environment set up to:

  1. Develop iOS and Android apps using Rust.
  2. Enable GUI debugging of Rust projects in Xcode.

If you just want to enable GUI debugging of macOS Rust projects in Xcode, I'm not actually sure whether you need cargo-mobile at all. But one benefit of installing it is that it automatically installs rust-xcode-plugin for you, giving you syntax highlighting of Rust sources in Xcode.

Prerequisites

cargo-mobile

@shirakaba
shirakaba / guard.ts
Created May 14, 2021 13:53
TypeScript guard function for type-checking records by index signatures
type Check<T> = {
[K in keyof T]: K extends `dull.${string}`
? T[K] extends string
? T[K]
: never
: K extends `rich.${string}`
? T[K]
: never
}
@shirakaba
shirakaba / custom store.js
Last active May 6, 2021 20:12
Svelte custom store example
import { writable, derived } from 'svelte/store';
function createCountries() {
const { subscribe, update } = writable([
{
name: "United Kingdom",
weather: "Cold",
description: "Nice tea",
},
{
@shirakaba
shirakaba / MWE.svelte
Last active April 28, 2021 16:40
Svelte store contract for all APIs of a class
<script>
import { writable } from "svelte/store";
class TransactionManager {
constructor(){
this.transactionCount = -1;
this.transactionQueue = [];
this._transactionIsInFlight = writable(this);
}
@shirakaba
shirakaba / MWE.svelte
Last active April 28, 2021 16:40
Svelte store contract for one API of a class
<script>
import { writable } from 'svelte/store';
class TransactionManager {
constructor(){
this.transactionCount = -1;
this.transactionQueue = [];
this._transactionIsInFlight = writable(false);
}
startTransaction(){