Skip to content

Instantly share code, notes, and snippets.

View iosdevzone's full-sized avatar

idz iosdevzone

View GitHub Profile
@iosdevzone
iosdevzone / gist:8e7bcb904f604eeba2c6a2b5fd39d322
Created October 23, 2017 22:27
Swift: debugDescription excluding some fields
extension CustomDebugStringConvertible {
public func debugDescription(excluding fields: [String]) -> String {
let excluded = Set<String>(fields)
let m = Mirror(reflecting: self)
let arguments = m.children
.filter { child in
return (child.label == nil) || !excluded.contains(child.label!)
}
.map { c -> String in
let value = (type(of: c.value) == String.self) ? "\"\(c.value)\"" : "\(c.value)"
@iosdevzone
iosdevzone / file_creation_test.c
Created November 24, 2017 10:41
A quick and dirty POC (Plain Ol' C) program to test file creation.
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, const char* argv[])
{
char name[1024];
char buffer[150];
for (int i = 0; i < 100000; ++i) {
@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 {
@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 / 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 / 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 {
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
//
// main.swift
//
// Created by idz on 10/23/20.
//
import Foundation
import CryptoSwift
import CommonCrypto
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
```
@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;