Skip to content

Instantly share code, notes, and snippets.

@simonwhitaker
simonwhitaker / swmath.m
Last active January 1, 2016 22:58
Architecture-independent floor() function
/*
* Calling math.h functions like `floor` and `floorf` on CGFloat variables
* becomes problematic when compiling the same code for both 32-bit and
* 64-bit platforms, since CGFloat is double on 64-bit, float on 32-bit.
* Hence, if you compile with -Wconversion set, `floorf` will give a warning
* on 64-bit, while `floor` gives a warning on 32-bit.
*
* Here's a suggested implementation of an architecture-independent `floor`
* function, written using plain old function overloading which is enabled
* using the `__attribute__((overloadable))` Clang language extension.
// I wish something like this (with a better name for the keyword):
@missing UILabel *titleLabel {
UILabel *label = [[UILabel alloc] init];
return label;
};
// Could turns into this:
@interface ViewController ()
@steipete
steipete / Macros.h
Last active January 6, 2024 07:24
Declare on your main init that all other init methods should call. It's a nice additional semantic warning. Works with Xcode 5.1 and above. Not tested with earlier variants, but should just be ignored. A reference to this macro shortly appeared in https://developer.apple.com/library/ios/releasenotes/ObjectiveC/ModernizationObjC/AdoptingModernObj…
#ifndef NS_DESIGNATED_INITIALIZER
#if __has_attribute(objc_designated_initializer)
#define NS_DESIGNATED_INITIALIZER __attribute((objc_designated_initializer))
#else
#define NS_DESIGNATED_INITIALIZER
#endif
#endif
//
// DUXClientsManager.h
//
//
// Created by Kevin Vitale on 3/25/14.
//
//
@class RACSignal;
#!/usr/bin/env python
# Quick and dirty demonstration of CVE-2014-0160 by
# Jared Stafford (jspenguin@jspenguin.org)
# Modified so that it finds cookies
import sys
import struct
import socket
import time
import select
#if DEBUG
/**
Toggles assertion of Core Data managed object contexts. Only available when DEBUG is defined.
When enabled, your application will throw an exception when accessing or modifying entities in a context other than their own.
*/
void TCBToggleAssertingContextQueues();
#endif
#!/usr/bin/env python
#
# git-flip-flop: checks out two or more commits in a periodic cycle
#
# Save on your $PATH as git-flip-flop
#
# EXAMPLES
#
# Check out abc1234, then def5678, then abc1234, etc, with
# the default 2s between each checkout
@Inferis
Inferis / ViewController.swift
Last active December 1, 2019 23:27
Beginnings of a GCD wrapper in swift
import UIKit
import QuartzCore
class ViewController: UIViewController {
@IBOutlet weak var label: UILabel
@IBOutlet weak var counter: UILabel
override func viewDidLoad() {
super.viewDidLoad()
@jmont
jmont / curriedfuncs.m
Last active August 29, 2015 14:02
Curried Functions in Swift
// Curried Functions in Swift
// Juan C. Montemayor (@norsemelon)
// Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l
// Syntax: func name (x1: t1)(x2: t2) -> t { ... }
// Note: it has a paren pair for every variable, as opposed to `(x1: t1, x2: t2)`
func addTwoNumbers(a: Int)(b: Int) -> Int {
return a + b
}
@kristopherjohnson
kristopherjohnson / pipe-forward.swift
Last active March 29, 2024 19:44
Swift: define F#-style pipe-forward (|>) operator that evaluates from left to right.
// F#'s "pipe-forward" |> operator
//
// Also "Optional-chaining" operators |>! and |>&
//
// And adapters for standard library map/filter/sorted
infix operator |> { precedence 50 associativity left }
infix operator |>! { precedence 50 associativity left }
infix operator |>& { precedence 50 associativity left }
infix operator |>* { precedence 50 associativity left }