Skip to content

Instantly share code, notes, and snippets.

@haikusw
haikusw / BinaryData.swift
Created March 14, 2019 22:31 — forked from iljaiwas/BinaryData.swift
Drop-in replacement for Data ivars that gets stored efficiently in MySQL by Vapor 3.
import Foundation
import Vapor
import FluentMySQL
final class BinaryData {
private let data: Data
init(data: Data) {
self.data = data
}
@haikusw
haikusw / detweet.swift
Created March 3, 2019 19:51 — forked from mxcl/detweet.swift
Delete all tweets and favorites older than two months ago. Instructions in comment.
#!/usr/bin/swift sh
import Foundation
import PromiseKit // @mxcl ~> 6.5
import Swifter // @mattdonnelly == b27a89
let swifter = Swifter(
consumerKey: "FILL",
consumerSecret: "ME",
oauthToken: "IN",
oauthTokenSecret: "https://developer.twitter.com/en/docs/basics/apps/overview.html"
@haikusw
haikusw / Withable.swift
Created January 28, 2019 16:57 — forked from nicklockwood/Withable.swift
Withable.swift
/// Withable is a simple protocol to make constructing
/// and modifying objects with multiple properties
/// more pleasant (functional, chainable, point-free)
public protocol Withable {
init()
}
public extension Withable {
/// Construct a new instance, setting an arbitrary subset of properties
init(with config: (inout Self) -> Void) {
@haikusw
haikusw / !README.md
Created June 22, 2018 07:13 — forked from mayoff/!README.md
Debugging Objective-C blocks in lldb

The attached lldb command pblock command lets you peek inside an Objective-C block. It tries to tell you where to find the source code for the block, and the values captured by the block when it was created.

Consider this example program:

#import <Foundation/Foundation.h>

@interface Foo: NSObject
@end

@implementation Foo

#! /usr/bin/swift
import ScriptingBridge
@objc protocol iTunesTrack {
optional var name: String! {get}
optional var album: String! {get}
}
@objc protocol iTunesApplication {
@haikusw
haikusw / gist:679c0818dbdb5970d5b8
Created November 16, 2014 02:59 — forked from twobitlabs/gist:4226365
Blocks Cheat Sheet
// http://cocoawithlove.com/2009/10/ugly-side-of-blocks-explicit.html has a nice breakdown of the syntax--it helps to think of the ^ as similar to a pointer dereference symbol *
// block typedef:
typedef void(^Block)();
typedef void(^ConditionalBlock)(BOOL);
typedef NSString*(^BlockThatReturnsString)();
typedef NSString*(^ConditionalBlockThatReturnsString)(BOOL);
// block property with typedef:
@haikusw
haikusw / amibeingdebugged.c
Last active August 29, 2015 14:02
drop into the debugger on exception IFF being debugged
//
// amibeingdebugged.c
// HSILibs
//
// based on: https://developer.apple.com/library/mac/qa/qa1361/_index.html
//
#include <assert.h>
#include <stdbool.h>
#include <sys/types.h>
//-----------------------------------------------//
// LIQUIDCRYSTAL LIBRARY FOR SPARK CORE //
//===============================================//
// Copy this into a new application at: //
// https://www.spark.io/build and go nuts! //
//-----------------------------------------------//
// Technobly / BDub - Jan 2014 //
//===============================================//
@haikusw
haikusw / vanillaextract.txt
Last active December 31, 2015 13:59
Make your own Vanilla Extract
a recipe is in "Can it, Bottle it, Smoke it" cookbook
http://www.amazon.com/gp/product/158008575X?ie=UTF8&camp=213733&creative=393185&creativeASIN=158008575X&linkCode=shr&tag=geda-20
Take the whole beans, split them in half, and then scrape the insides, putting
both the scrapings and the rest of the bean in a bottle and fill with vodka.
Vodka should completely cover the beans. Put them in a dark place, shake every
now and then, and store for 4-5 months before using. once you start using it
you can keep topping it off with more vodka, and add more beans, too, from time
to time.
static BOOL PSPDFIsDevelopmentBuild(void) {
#if TARGET_IPHONE_SIMULATOR
return YES;
#else
static BOOL isDevelopment = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// There is no provisioning profile in AppStore Apps.
NSData *data = [NSData dataWithContentsOfFile:[NSBundle.mainBundle pathForResource:@"embedded" ofType:@"mobileprovision"]];
if (data) {