Skip to content

Instantly share code, notes, and snippets.

View xta's full-sized avatar

Rex Feng xta

View GitHub Profile
@xta
xta / 1.README.md
Created July 16, 2022 06:24 — forked from brettohland/1.README.md
ISBN example with FormatStyle, AttributedStringFormatStyle, ParseableFormatStyle conformance.

Supporting FormatStyle & ParseableFormatStyle To Your Custom Types

A full example of adding String and AttributedString output to our custom types, as well as adding the ability to parse String values into your custom type.

Read the blog post

See the Xcode Playground

ko-fi

import SwiftUI
let width : CGFloat = 82.0
let height : CGFloat = 82.0
struct ContentView: View {
@State private var toggle = false
var body: some View {
VStack {
Spacer()
ZStack {
Image(systemName: "heart.fill")
@xta
xta / swirls.pde
Created January 5, 2022 02:26 — forked from beesandbombs/swirls.pde
swirls
// by dave
float[][] result;
float t, c;
float ease(float p) {
p = c01(p);
return 3*p*p - 2*p*p*p;
}
float ease(float p, float g) {
//------------------------------------------------------------------------
// Author: The SwiftUI Lab
// Post: Advanced SwiftUI Animations - Part 4
// Link: https://swiftui-lab.com/swiftui-animations-part4 (TimelineView)
//
import SwiftUI
struct CyclicTimelineSchedule: TimelineSchedule {
let timeOffsets: [TimeInterval]
@xta
xta / jq-cheetsheet.md
Created June 22, 2021 19:12 — forked from olih/jq-cheetsheet.md
jq Cheet Sheet

Processing JSON using jq

jq is useful to slice, filter, map and transform structured json data.

Installing jq

On Mac OS

brew install jq

@xta
xta / web-servers.md
Created May 13, 2021 07:09 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten

Async calls

<template>
<!-- 
When isLoading is true, the <div> is in the DOM, the <p> is not.
When isLoading is false, Vue will remove the <div> and add the <p> to the DOM,
at which point <MyComponent> will be created and passed the fetched data.
-->
import Foundation
import SwiftUI
struct GradientCircle: View {
var body: some View {
let color1 = Color.init(red: 81/255, green: 204/255, blue: 159/255)
let color2 = Color.init(red: 154/255, green: 255/255, blue: 248/255)
let spectrum = Gradient(colors: [ color1, color2])
let conic =
LinearGradient(gradient: spectrum, startPoint: UnitPoint(x: 0, y: 0.5), endPoint: UnitPoint(x: 0.5, y: 1))
//--------------------------------------------------
// The SwiftUI Lab: Advanced SwiftUI Animations
// https://swiftui-lab.com/swiftui-animations-part1
//--------------------------------------------------
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {