Skip to content

Instantly share code, notes, and snippets.

View jamesporter's full-sized avatar

James Porter jamesporter

View GitHub Profile
@jamesporter
jamesporter / build.js
Created March 26, 2023 20:35
Convert Sonic Pi Tutorial to epub
const fs = require("fs");
const path = require("path");
const mds = fs.readdirSync("./").filter((f) => f.includes(".md"));
let contents = `
---
title: Sonic Pi Tutorial
author: Sam Aaron
...
@jamesporter
jamesporter / Share.swift
Created May 8, 2022 10:55
Share Sheet in SwiftUI
.sheet(isPresented: $isSharing) {
AppActivityView(activityItems: ["something", URL(string: "https://apps.apple.com/us/app/deadly-divisors/id888788693")!])
}
@jamesporter
jamesporter / CustomFont.swift
Created May 8, 2022 09:23
Adding Noto Emoji to iOS (etc) app
import SwiftUI
enum CustomFont {
static let notoEmoji = "NotoEmoji-SemiBold"
}
struct Emoji: View {
var text: String
var size: CGFloat
@jamesporter
jamesporter / keys.swift
Created April 3, 2022 23:08
Wordle Words in a Swift File
import Foundation
let rawKeys = [
["q","w","e","r","t","y","u","i","o","p"],
["a","s","d","f","g","h","j","k","l"],
["z","x","c","v","b","n","m"]
]
enum InputKey: Hashable, Equatable, Codable {
case letter(key: String)
@jamesporter
jamesporter / quick-tap.swift
Created March 20, 2022 19:23
SwiftUI (Quick) Tap Gesture
import SwiftUI
// fuck it this should be fine-ish (as on main thread)?
fileprivate var lastStartPoint: CGPoint?
extension View {
func quickTap(action: @escaping () -> Void) -> some View {
gesture(DragGesture(minimumDistance: 0).onChanged { value in
if value.startLocation == lastStartPoint {
@jamesporter
jamesporter / promisify-streams-axios-file-get-example.ts
Created November 17, 2021 11:09
Promisify Streams (quick/hacky version)
function dl(url: string, title: string, idx: number): Promise<boolean> {
const file = fs.createWriteStream(`./downloads/${pad(idx)}-${title}.mp4`)
return new Promise((resolve, reject) => {
axios({
method: "get",
url,
responseType: "stream",
}).then((response) => {
response.data.pipe(file)
response.data.on("end", () => {
@jamesporter
jamesporter / SwiftUI-searchable-bug.swift
Created November 10, 2021 17:42
SwiftUI searchable modifier bug
import SwiftUI
struct ContentView: View {
@State var query = ""
var body: some View {
NavigationView {
ScrollView {
LazyVStack {
ForEach(0..<100, id: \.self) { n in
HStack {
@jamesporter
jamesporter / ZoomableView.swift
Created October 23, 2021 10:50
Simple pinch to zoom View extension, allowing for limits to zoom scale
import SwiftUI
enum Config {
static let zoomRange: ClosedRange<CGFloat> = 0.05...1.0
}
extension View {
func zoomable(scale: Binding<CGFloat>) -> some View {
ZoomableView(scale: scale) {
self
@jamesporter
jamesporter / package.json
Created August 25, 2021 20:47
React Native package.json different iOS devices snippet
{
"ios": "react-native run-ios",
"ios:iPad": "react-native run-ios --simulator=\"iPad Pro (11-inch) (3rd generation)\"",
"ios:iPhone8": "react-native run-ios --simulator=\"iPhone 8 Plus\"",
"ios:iPhone11": "react-native run-ios --simulator=\"iPhone 11 Pro Max\""
}
@jamesporter
jamesporter / Info.plist
Created August 25, 2021 20:30
Info.plist with sensible defaults: portrait only on iPhone, all on iPad
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>