Skip to content

Instantly share code, notes, and snippets.

View iosdevzone's full-sized avatar

idz iosdevzone

View GitHub Profile
@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 / 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 / BasicAuthPlaygroundSeed.swift
Last active September 19, 2015 11:09
Minimal Basic Authentication Demo. Paste into playground & replace username and password. You must be on GitHub for this to work.
import Foundation
let username = "username"
let password = "password"
let base = "https://api.github.com"
let user = "\(base)/user"
let url = NSURL(string: user)
let request = NSMutableURLRequest(URL: url!)
@iosdevzone
iosdevzone / gist:fb06b61dab4ec2dc1801
Created May 22, 2015 22:06
Filtering array based on indexSet
func objectsAtIndexes<T:AnyObject>(array: [T], indexes:NSIndexSet) -> [T]
{
return ((array as NSArray).objectsAtIndexes(indexes) as [T])
}
- (void)drawRect:(CGRect)rect {
[[UIColor lightGrayColor] setFill];
[[UIColor darkGrayColor] setStroke];
UIBezierPath *path = [[UIBezierPath alloc] init];
CGPoint touchPoint = [self.lastTouch locationInView:self];
CGFloat y0 = self.bounds.origin.y;
CGFloat weight = 0.75; // Vary from 0 - 1. Values closed to 1 are more pointy.
CGFloat y1 = y0 + (touchPoint.y - y0) * weight; // between top of screen and touch
CGFloat y2 = touchPoint.y;
CGFloat y4 = CGRectGetMaxY(self.bounds);
OS X 10.10.1/Xcode 6.3 6D520o
inu:Radars idz$ swiftc main.swift
inu:Radars idz$ ./main -radar "is fixed"
[radar: is fixed]
/* ==== KeychainItem.swift === */
public class KeychainItem {
public var dictionary : KeychainDictionary
public init() {
self.dictionary = KeychainDictionary()
}
public init(dictionary: KeychainDictionary) {
@iosdevzone
iosdevzone / Foo2.swift
Created October 2, 2014 00:18
File to demonstrate very slow compilation times on swift when string concatenation operator used rather than string interpolation.
class Foo
{
let a = "a"
let b = "b"
let c = "c"
let values = [ "A", "B", "C", "D", "E" ]
var rawValues: String
{
let a = self.a
@iosdevzone
iosdevzone / CommonCryptoHack
Created September 21, 2014 03:14
A shell script to write a dummy CommonCrypto.framework module into the directory where playgrounds look for frameworks.
#!/bin/bash
if [[ $BASH_SOURCE != $0 ]]; then echo "$BASH_SOURCE must be executed, not sourced."; return 255; fi
#
# A script to fool iOS playgrounds into allowing access to CommonCrypto
#
# The script creates a dummy CommonCrypto.framework in the SDK's System
# Framework Library Directory with a module map that points to the
# umbrella header
#
# Usage:
/*
CommonHMac defines the following enumeration
enum {
kCCHmacAlgSHA1,
kCCHmacAlgMD5,
kCCHmacAlgSHA256,
kCCHmacAlgSHA384,
kCCHmacAlgSHA512,
kCCHmacAlgSHA224