Skip to content

Instantly share code, notes, and snippets.

View smrfeld's full-sized avatar
🙂

Oliver K. Ernst smrfeld

🙂
View GitHub Profile
@smrfeld
smrfeld / ContentView.swift
Created April 12, 2022 21:23
Animation V2
struct ContentView: View {
@State var xpos: CGFloat = 400
@State var ypos: CGFloat = 200
var body: some View {
ZStack {
Circle()
.frame(width: 50, height: 50)
.foregroundColor(.blue)
.position(x: xpos, y: ypos)
@smrfeld
smrfeld / ContentView.swift
Created April 12, 2022 21:21
Animation v1
struct ContentView: View {
@State var xpos: CGFloat = 400
@State var ypos: CGFloat = 200
var body: some View {
ZStack {
Circle()
.frame(width: 50, height: 50)
.foregroundColor(.blue)
.position(x: xpos, y: ypos)
@smrfeld
smrfeld / ContentView.swift
Last active April 12, 2022 21:17
Simple circle content view
import SwiftUI
struct ContentView: View {
@State var xpos: CGFloat = 400
@State var ypos: CGFloat = 200
var body: some View {
ZStack {
Circle()
.frame(width: 50, height: 50)
@smrfeld
smrfeld / export_reading_list.py
Created December 16, 2021 19:40
Dump reading list to json or csv
# Dump
if args.output_mode == 'json':
# Write JSON
with open(args.fname_out,'w') as f:
rjson = [ r.to_json() for r in ritems ]
json.dump(rjson,f,indent=3)
print("Wrote reading list to JSON file: %s" % args.fname_out)
elif args.output_mode == 'csv':
@smrfeld
smrfeld / export_reading_list.py
Created December 16, 2021 19:39
Convert reading list to custom objects
@dataclass
class ReadingListItem(json.JSONEncoder):
title: str
ServerID: str
neverFetchMetadata: bool
WebBookmarkType: str
WebBookmarkUUID: str
URLString: str
DateAdded: datetime.datetime
@smrfeld
smrfeld / export_reading_list.py
Created December 16, 2021 19:37
Find reading list items
def find_dicts_with_rlist_keys_in_dict(base_dict):
ret = []
for key,val in base_dict.items():
if key == "Children":
# Recurse down
for child_dict in val:
ret += find_dicts_with_rlist_keys_in_dict(child_dict)
elif key == "ReadingList":
ret.append(base_dict)
# Copy the plist file for safety
fname_plist = "tmp.plist"
command = "cp %s %s" % (args.fname_bookmarks, fname_plist)
print("Making temporary copy of reading list: %s" % command)
Popen(command, shell=True).wait()
@smrfeld
smrfeld / lazy.swift
Created November 26, 2021 04:20
Lazy navigation link example
// Lazy navigation link
NavigationLink {
NavigationLazyLoadView(
DetailView(idx: idx)
)
} label: {
Text("Go to \(idx)")
}
@smrfeld
smrfeld / detail.swift
Created November 26, 2021 04:09
Detail view
// The detail view
struct DetailView: View {
var idx: Int
init(idx: Int) {
self.idx = idx
print("Page: \(idx) constructed")
}
@smrfeld
smrfeld / non_lazy.swift
Created November 26, 2021 04:07
Non-lazy navigation links
// The list view
struct ListView: View {
var body: some View {
NavigationView {
List {
ForEach(1...10, id: \.self) { idx in
// Navigation link
NavigationLink {