Skip to content

Instantly share code, notes, and snippets.

@janodev
janodev / ThrottledQueue.swift
Created May 1, 2016 11:05
Throttling queue. Useful to discard button clicks until the button action is done executing.
import Foundation
/*
Execute asynchronous tasks concurrently until reaching a given 'max' number.
Tasks queued while there is already a 'max' number of concurrent tasks are silently discarded.
Usage: ThrottledQueue(1).queueAction { finish in /* work */ finish() }
*/
struct ThrottledQueue
{
@janodev
janodev / gist:69fd3d2b2d3c50ca685c
Created February 29, 2016 16:15
How to get, install, and configure a free SSL certificate for your website:
~ $ git clone https://github.com/letsencrypt/letsencrypt
~ $ cd letsencrypt
~ $ letsencrypt-auto --renew-by-default --webroot -w /var/www/ --email [email protected] --text --agree-tos -d website.com -d www.website.com auth
~ $ letsencrypt --apache
@janodev
janodev / chrome.sh
Created November 26, 2014 19:30
Use chrome.sh to launch a stable patched Chrome from the terminal. See https://devforums.apple.com/message/1076597#1076597
clang -dynamiclib -framework AppKit patch.m -o patch.dylib
env DYLD_INSERT_LIBRARIES=patch.dylib "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
//
// GIFDownloader.h
// TheJoysOfCode
//
// Created by Bob on 29/10/12.
// Copyright (c) 2012 Tall Developments. All rights reserved.
//
#import <Foundation/Foundation.h>
@janodev
janodev / BigFactorial.java
Created May 1, 2014 10:53
Factorial with tail-call optimization in Java 8
// Code from “Functional Programming in Java, Chapter 7”.
import java.util.function.Function;
import java.util.stream.Stream;
import java.math.BigInteger;
@FunctionalInterface
interface TailCall<T> {
@janodev
janodev / MJGAvailability.h
Last active December 29, 2015 06:39
Emit build warnings in Xcode 5 for methods only available on a later iOS version than the deployment target. The pch below is set to warn on methods newer than 6.1. Change the __IPHONE_6_1 part for a different version. Code taken from http://stackoverflow.com/a/8919108/412916 and http://stackoverflow.com/a/19704587/412916
//
// MJGImageLoader.h
// MJGFoundation
//
// Created by Matt Galloway on 18/01/2012.
// Copyright 2012 Matt Galloway. All rights reserved.
//
/**
* Example usage:
# Install Xcode 5.0.1 GM seed, open it, install Command Line Tools.
# Uninstall macports, see https://www.macports.org/guide/chunked/installing.macports.uninstalling.html
# Run the following:
curl -O https://distfiles.macports.org/MacPorts/MacPorts-2.2.0.tar.bz2
tar jxvf MacPorts-2.2.0.tar.bz2
cd MacPorts-2.2.0
CC=/usr/bin/cc ./configure --prefix=/opt/local --with-install-user=root --with-install-group=admin --with-directory-mode=0755 --enable-readline \
--with-tclpackage=/Library/Tcl \
--with-tcl=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tcl.framework \

Generate the list yourself:

$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk/System/Library/Frameworks/UIKit.framework/Headers
$ grep -H UI_APPEARANCE_SELECTOR ./* | sed 's/ __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;//'

UIActivityIndicatorView

@janodev
janodev / gist:6620842
Last active December 23, 2015 10:19
“pod install” setting 32 bits instead 64? update CocoaPods to the xcode5-support branch
sudo gem install bundler
printf "gem 'cocoapods', :git => 'http://github.com/CocoaPods/CocoaPods', :branch => 'xcode-5-support' \n" > Gemfile
printf "gem 'xcodeproj', :git => 'http://github.com/CocoaPods/Xcodeproj', :branch => 'redacted-support' \n" >> Gemfile
sudo bundle install
sudo bundle exec pod install
@janodev
janodev / ARSketchView.h
Last active December 22, 2015 19:19
ARSketchView
@interface ARSketchView : UIView
- (IBAction) clear;
- (IBAction) replay;
@end