Skip to content

Instantly share code, notes, and snippets.

// See: https://devforums.apple.com/message/1000934#1000934
import Foundation
// Logic
operator prefix ¬ {}
@prefix func ¬ (value: Bool) -> Bool {
return !value
}
@sbilstein
sbilstein / bash_prompt
Last active December 31, 2015 11:59
BASH prompt with git branch name and status. Fixed to handle directory names with spaces and checks to see if nested directories are under source control.
#!/bin/bash
# BASH prompt builder
#
# This is a script I use to generate BASH prompts that look like this:
# (master)*
# [sbilstei@sbilstei-mn1:~/localcode/git-sandbox]:$
#
# Basically user, the machine's hostname, current working directory tilde condensed and an optional branch name
# when navigating a git repo. The asterisk is visible if there are uncommitted changes.
@neonichu
neonichu / dashpod.rb
Created August 7, 2013 19:44
Ruby script which adds documentation for all dependencies from a Podfile to Dash. It's rather hacky and was only tested on Sea Lion, so use at your own risk.
#!/usr/bin/env ruby
require 'rubygems'
require 'cocoapods-core'
require 'json'
require 'mechanize'
require 'rest-client'
docs = JSON.parse(RestClient.get('http://cocoadocs.org/documents.jsonp')[12..-22])
@jspahrsummers
jspahrsummers / gist:5812222
Last active December 18, 2015 16:29
Make "self" cause a compilation error only within blocks.
#define self \
( \
_Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wunused-value\"") self, \
/* Depends on _cmd being a const copy, like other captured variables. */ \
_Pragma("clang diagnostic pop") (*(_cmd = _cmd, &self)) \
)
// Replace libextobjc's @weakify with one that's aware of the "self" macro.
#undef ext_weakify_
#define ext_weakify_(INDEX, CONTEXT, VAR) \
@brentsimmons
brentsimmons / gist:5810992
Last active January 3, 2021 02:22
Detect a tap on a URL inside a UITextView. Note: the rs_links method isn't included -- you'll need something that takes text and returns an array of detected links. This gist just demonstrates walking through the UITextView characters.
@implementation UITextView (RSExtras)
static BOOL stringCharacterIsAllowedAsPartOfLink(NSString *s) {
/*[s length] is assumed to be 0 or 1. s may be nil.
Totally not a strict check.*/
if (s == nil || [s length] < 1)
return NO;
@steipete
steipete / PSPDFUIKitMainThreadGuard.m
Last active March 10, 2024 19:23
This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.You might n…
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
// PLEASE DUPE rdar://27192338 (https://openradar.appspot.com/27192338) if you would like to see this in UIKit.
#import <objc/runtime.h>
#import <objc/message.h>