Skip to content

Instantly share code, notes, and snippets.

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

Jamie Birch shirakaba

💭
🧙‍♂️
View GitHub Profile
@shirakaba
shirakaba / ModalView.svelte
Last active April 21, 2022 20:47
Scroll-trapping view (modal overlay)
<script lang="ts">
import Popover from "./Popover.svelte";
import InputView from "./InputView.svelte";
import { onMount } from "svelte";
import type { InputViewProps } from "./InputInterfaces";
import { InputParser } from "./InputParser";
import Loader from "./Loader.svelte";
export let inputModel: InputViewProps|undefined = void 0;
export const inputParser: InputParser = new InputParser();
@shirakaba
shirakaba / ViewController.swift
Last active March 26, 2022 16:32
Injecting a stylesheet into a WKWebView
import WebKit
import UIKit
class ViewController: UIViewController {
let webView: WKWebView = WKWebView(frame: self.view.frame, configuration: WKWebViewConfiguration())
override func loadView() {
super.loadView()
self.view = webView
@shirakaba
shirakaba / renderers.md
Created January 1, 2022 17:35
The many UI renderers of NativeScript

The many UI Renderers of NativeScript

Introduction

In this article, we'll learn how NativeScript was adapted into so many different flavours (Angular, Vue, React, Svelte, and more). We'll cover what makes it such a good target for adapting, but also lift the curtain on some of the technical challenges involved in the process. And through the article, you should gain a sense of what's involved in creating a new flavour for NativeScript (or indeed any other host!).

Background

NativeScript's cross-platform UI modules (broadly everything under the ui directory in the @nativescript/core npm package) can be described as a "UI runtime". In other words, a library that allows you to manipulate the user interface for your app while it is running.

@shirakaba
shirakaba / nix.md
Last active February 3, 2023 19:54
Setting up Nix and Home Manager on a new M1 Mac (circa Dec 2021)

Background

I have a brand new M1 MacBook Pro. I have a long list of complaints with homebrew, so I want to try Nix as my package manager instead, along with Home Manager to control my setup on a per-user basis. Once I've set this all up, theoretically, I should be able to reuse the same configuration on any other Macs I own.

What is Nix?

A reproducible, declarative package manager.

More info:

@shirakaba
shirakaba / vite-configuration.md
Last active July 8, 2023 03:19
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 November 17, 2023 00:52
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