Skip to content

Instantly share code, notes, and snippets.

View modocache's full-sized avatar

Brian Gesiak modocache

View GitHub Profile
@nicklockwood
nicklockwood / gist:21495c2015fd2dda56cf
Last active August 13, 2020 13:57
Thoughts on Swift 2 Errors

Thoughts on Swift 2 Errors

When Swift was first announced, I was gratified to see that one of the (few) philosophies that it shared with Objective-C was that exceptions should not be used for control flow, only for highlighting fatal programming errors at development time.

So it came as a surprise to me when Swift 2 brought (What appeared to be) traditional exception handling to the language.

Similarly surprised were the functional Swift programmers, who had put their faith in the Haskell-style approach to error handling, where every function returns an enum (or monad, if you like) containing either a valid result or an error. This seemed like a natural fit for Swift, so why did Apple instead opt for a solution originally designed for clumsy imperative languages?

I'm going to cover three things in this post:

@tenderlove
tenderlove / mt_complete.rb
Last active December 11, 2020 19:56
tab completion for minitest tests
#!/usr/bin/env ruby --disable-gems
# Tab completion for minitest tests.
#
# INSTALLATION:
#
# 1. Put this file in a directory in your $PATH. Make sure it's executable
# 2. Run this:
#
# $ complete -o bashdefault -f -C /path/to/this/file.rb ruby
@lisamelton
lisamelton / convert-mkv-to-mp4.sh
Last active October 17, 2021 13:51
Convert Matroska video file into MP4 format without transcoding.
#!/bin/bash
#
# convert-video.sh
#
# Copyright (c) 2013-2014 Don Melton
#
about() {
cat <<EOF
$program 2.0 of December 3, 2014
@akisute
akisute / GrayShark.swift
Last active May 13, 2016 17:05
I have learned a "Gray Magic" of the Swift.
import Foundation
class GrayShark {
var name:String
var howSwim:String
init(name:String, howSwim:String) {
self.name = name
self.howSwim = howSwim;
}
@luisobo
luisobo / gist:ef9568876d83371ac0a2
Last active August 29, 2015 14:00
Disable advertisingIdentifier to avoid AppStore rejection
__attribute__((constructor))
void PIXWhatPartOfAdvertisingTrackingEnabledDidYouNotUnderstand(void) {
if (![[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) {
IMP newImplementation = imp_implementationWithBlock(^NSUUID *{
return nil;
});
Method m = class_getInstanceMethod([ASIdentifierManager class], @selector(advertisingIdentifier));
method_setImplementation(m, newImplementation);
}
}
@hoshi-takanori
hoshi-takanori / Makefile
Last active October 3, 2019 18:17
Testing Objective-C class by XCTest with plain old Makefile in command line.
CLASS_NAME = MyObject
OBJS = main.o $(CLASS_NAME).o $(CLASS_NAME)Tests.o
PROGRAM = a.out
CFLAGS = -Wall -F$(FWPATH)
LIBS = -F$(FWPATH) -framework XCTest -framework Foundation
FWPATH = /Applications/Xcode.app/Contents/Developer/Library/Frameworks
XCTEST = /Applications/Xcode.app/Contents/Developer/usr/bin/xctest
@lisamelton
lisamelton / convert-mp4-to-mkv.sh
Last active May 24, 2024 17:41
Convert MP4 video file into Matroska format without transcoding.
#!/bin/bash
#
# convert-video.sh
#
# Copyright (c) 2013-2014 Don Melton
#
about() {
cat <<EOF
$program 2.0 of December 3, 2014
@cartazio
cartazio / xcode5-haskell-directions.md
Last active May 28, 2019 00:35
xcode 5 + OS X 10.9 mavericks GHC work around nuttiness

PSA :

just use GHC for OSX https://ghcformacosx.github.io

the rest of these directions are preserved for historical purposes

TLDR version, if you have homebrew

xcode-select --install ; brew tap homebrew/versions ;   brew tap homebrew/dupes \
@steipete
steipete / PSPDFUIKitMainThreadGuard.m
Last active May 27, 2024 12:11
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>
@subdigital
subdigital / xc
Created April 19, 2013 14:27
Open the first Xcode workspace or project found
xcode_proj=`find . -name "*.xc*" -d 1 | sort -r | head -1`
if [ `echo -n $xcode_proj | wc -m` == 0 ]
then
echo "No xcworkspace/xcodeproj file found in the current directory."
exit 1
fi
echo "Found $xcode_proj"
open $xcode_proj