Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
🧙‍♂️

Jamie Birch shirakaba

💭
🧙‍♂️
View GitHub Profile
@shirakaba
shirakaba / How to install pip and six on macOS with Nix and home-manager.md
Created January 25, 2023 08:45
How to install pip and six on macOS with Nix and home-manager
View How to install pip and six on macOS with Nix and home-manager.md

Given the following Nix packages (you may be able to install six manually rather than managing it by Nix, but anyway, this was my setup):

pkgs.python310Full
pkgs.python310Packages.six

I would very often run into this situation:

/usr/local/bin/pip: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory

@shirakaba
shirakaba / clang ast dumping.md
Last active January 18, 2023 09:44
How dump the ASTs for an Obj-C file using the clang CLI tool
View clang ast dumping.md

For example, for the NSString.h header:

clang \
  -Xclang \
  -ast-dump \
  -fsyntax-only \
  -x objective-c \
  -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers \
 -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks \
@shirakaba
shirakaba / Building and running the NativeScript metadata generator.md
Last active January 28, 2023 07:37
Building and running the NativeScript metadata generator
View Building and running the NativeScript metadata generator.md
@shirakaba
shirakaba / How NativeScript's JS->native bindings work.md
Last active June 4, 2022 10:17
How NativeScript's JS->native bindings work
View How NativeScript's JS->native bindings work.md

[Draft] Deep-dive: How NativeScript's JS->native bindings work

What is NativeScript?

NativeScript is a JavaScript runtime that allows you to write an iOS or Android app entirely in TypeScript or JavaScript with no compromises. That is to say, it provides you with the same level of native access that writing the app in Obj-C/Swift (for iOS) or Java/Kotlin (for Android) does. Not just JSON-serialisable data types like NSString, but all data types are supported. To illustrate what it's all about, here's how you would get the battery level using NativeScript (the below snippet is entirely JS code!):

import { isIOS, isAndroid, Application } from "@nativescript/core";

/**
@shirakaba
shirakaba / ModalView.svelte
Last active April 21, 2022 20:47
Scroll-trapping view (modal overlay)
View ModalView.svelte
<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
View ViewController.swift
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
View renderers.md

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)
View nix.md

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 September 28, 2022 21:25
How to configure Vite from svelte.config.js in SvelteKit projects
View vite-configuration.md

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
View AndroidManifest.xml
// 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"