Skip to content

Instantly share code, notes, and snippets.

View iosdevzone's full-sized avatar

idz iosdevzone

View GitHub Profile
@iosdevzone
iosdevzone / ContentView.swift
Created November 10, 2023 00:09
Update to ContentView.swift to synchronize Core Data context with Swift Data
// Modified version of ContentView.swift from Pol Piella's blog
// post "Using Core Data and Swift Data side by side".
//
// See: https://www.polpiella.dev/core-data-and-swift-data
//
// Crux is in the `onAppear`.
// ```
// .onAppear() {
// NotificationCenter.default.addObserver(forName: Notification.Name.NSManagedObjectContextDidSave,
// object: nil,
import UIKit
///
///Declaration
///
protocol UIViewBuilder: AnyObject {}
extension UIViewBuilder where Self: UIView {
init(_ build: ((Self) -> Void)) {
@iosdevzone
iosdevzone / list_fonts.c
Last active November 18, 2020 06:56
Quick and dirty `xcb_list_fonts` demo
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <xcb/xcb.h>
static void list_fonts(xcb_connection_t *c)
{
// On my mac there are 10,000+ fonts!
uint16_t max_names = 20000;
The answer, in case the question does not get enough reopen votes, is that you need to invoke the dll using `dotnet <dllname>`.
The easiest way to make sure that this works is to publish the app from Visual studio **Build > Publish To Folder...** and add
a script like the following in the produced folder.
```bash
#!/bin/bash
APP_NAME="HelloWorld" # Replace this with your app name
DIR="$(dirname ${BASH_SOURCE[0]})"
dotnet "$DIR"/"$APP_NAME".dll
```
//
// main.swift
//
// Created by idz on 10/23/20.
//
import Foundation
import CryptoSwift
import CommonCrypto
madra:tad danny$ npm install
> sqlite3@4.1.1 install /Users/danny/Documents/GitHub/tad/tad/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build
node-pre-gyp WARN Using request for node-pre-gyp https download
node-pre-gyp WARN Tried to download(403): https://mapbox-node-binary.s3.amazonaws.com/sqlite3_ac/v4.1.1/node-v51-darwin-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for sqlite3@4.1.1 and node@7.1.0 (node-v51 ABI, unknown) (falling back to source compile with node-gyp)
ACTION deps_sqlite3_gyp_action_before_build_target_unpack_sqlite_dep Release/obj/gen/sqlite-autoconf-3310100/sqlite3.c
TOUCH Release/obj.target/deps/action_before_build.stamp
@iosdevzone
iosdevzone / ViewController.swift
Created April 29, 2020 23:28
Source code demonstrating placement of alternately flipped triangles to form hexagon in SceneKit (StackOverflow question)
//
// ViewController.swift
// StockOverflowSceneKit
//
// Created by idz on 4/28/20.
//
import SceneKit
class TrianglePlane: SCNNode {
@iosdevzone
iosdevzone / LineEndsFind.mm
Last active April 22, 2018 13:20
A function to find the offsets of newlines ('\n') in UTF-16 encoded string. Try as I might, I cannot get a Swift version within an order of magnitude of the C++ version. Both routines must return arrays of the same size and with equal elements.
#import <Foundation/Foundation.h>
#import <vector> // Needed for gist to compile.
#pragma mark - Pure Implementation Functions
const static unichar kUTF16Newline = (unichar)'\n'; // old naming habits die hard!
/**
* Calculates an array of line end "positions" for a given string.
* The equivalent Swift function was `(String) -> [Int]` or `(NSString) -> [Int]`
*
* In this context a "position" is the zero-based index of a newline
* character in the string as if it were an array of UTF-16 codepoints.
@iosdevzone
iosdevzone / gist:e3617dbcd9d75d78453c1599b71f1901
Created March 28, 2018 08:32
Modified test for Antlr4 to demonstrate ParserTree crash
func calculatorHelper() -> ParseTree {
let input = "2 + 8 / 2"
let lexer = VisitorCalcLexer(ANTLRInputStream(input))
let parser = try! VisitorCalcParser(CommonTokenStream(lexer))
return try! parser.s()
}
func calculatorHelper2() -> VisitorCalcParser {
let input = "2 + 8 / 2"
let lexer = VisitorCalcLexer(ANTLRInputStream(input))
@iosdevzone
iosdevzone / RecursiveSubSequence.swift
Last active January 19, 2018 23:34
RecursiveSubSequence is a protocol I've found useful.
protocol RecursiveSubSequence: Sequence where SubSequence: RecursiveSubSequence { }
extension String: RecursiveSubSequence { }
extension Substring: RecursiveSubSequence { }
extension Array: RecursiveSubSequence {}
extension ArraySlice: RecursiveSubSequence {}
func process<T>(_ value: T) -> T { return value }
func count<S: RecursiveSubSequence>(_ s: S) -> Int {