Skip to content

Instantly share code, notes, and snippets.

View iamtomcat's full-sized avatar

Tom Clark iamtomcat

View GitHub Profile
@therealjohn
therealjohn / gist:c658d6c087847360afdc
Created July 1, 2014 23:58
UIImage FixOrientation
public static UIImage FixOrientation(this UIImage image)
{
UIImage fixedImage = image;
// No-op if the orientation is already correct
if (image.Orientation == UIImageOrientation.Up) return image;
// We need to calculate the proper transformation to make the image upright.
// We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
CGAffineTransform transform = CGAffineTransform.MakeIdentity();
@peeblesjs
peeblesjs / gist:9288f79322ed3119ece4
Last active February 11, 2016 23:31
A naive "valueForKey:" operator in Swift
operator infix --> {}
func --> (instance: Any, key: String) -> Any? {
let mirror = reflect(instance)
for index in 0 ..< mirror.count {
let (childKey, childMirror) = mirror[index]
if childKey == key {
return childMirror.value
}
}
@nathanhillyer
nathanhillyer / .gitignore
Created May 12, 2016 16:26
Swift gitignore
#####
# Xcode private settings (window sizes, bookmarks, breakpoints, custom executables, smart groups)
#
# This is complicated:
#
# SOMETIMES you need to put this file in version control.
# Apple designed it poorly - if you use "custom executables", they are
# saved in this file.
# 99% of projects do NOT use those, so they do NOT want to version control this file.
# ..but if you're in the 1%, comment out the line "*.pbxuser"
@simenbrekken
simenbrekken / add.js
Created November 24, 2011 14:21
Backbone.js form submission
define([
'backbone',
'underscore',
'project/views/form'
], function(Backbone, _, ProjectFormView) {
var View = Backbone.View.extend({
events: {
'submit form': 'submit'
},
@natecook1000
natecook1000 / shuffle.swift
Last active December 11, 2018 06:53
Shuffle/shuffled functions & Array extensions
// (c) 2014 Nate Cook, licensed under the MIT license
//
// Fisher-Yates shuffle as top-level functions and array extension methods
/// Shuffle the elements of `list`.
func shuffle<C: MutableCollectionType where C.Index == Int>(inout list: C) {
let c = count(list)
for i in 0..<(c - 1) {
let j = Int(arc4random_uniform(UInt32(c - i))) + i
swap(&list[i], &list[j])
@jonreid
jonreid / gist:1258076
Last active November 26, 2020 11:09
Terminal command to help you find preprocessor code smells in Objective-C code
find . \( \( -name "*.[chm]" -o -name "*.mm" \) -o -name "*.cpp" \) -print0 | xargs -0 egrep -n '^\w*\#' | egrep -v '(import|pragma|else|endif|HC_SHORTHAND|MOCKITO_SHORTHAND)'
@yongjun21
yongjun21 / Promise.js
Last active June 28, 2022 11:56
Implement bluebird's Promise.map & Promise.filter with native Promise
Promise.map = function (iterable, mapper, options) {
options = options || {}
let concurrency = options.concurrency || Infinity
let index = 0
const results = []
const iterator = iterable[Symbol.iterator]()
const promises = []
while (concurrency-- > 0) {
@SethCalkins
SethCalkins / LittleSnitch_Block_List.md
Last active January 5, 2023 05:17
Little Snitch Script to block Ad Servers

Here is a script to take the hosts from From http://pgl.yoyo.org/adservers/ and convert them to rules for Little Snitch.

It has options to grab the entire list or grab new entries past a certain date.

Just grab the output and copy/paste into Little Snitch.

The script is written to block access to any process, any port. You can also delete those lines and it will only block Mail. Or use the options to enter any process, port or protocol you want to block.

@mikevoyt
mikevoyt / gist:4613982
Last active February 8, 2023 12:52
Example of how to create a pinned header with UICollectionView (i.e., a header that doesn't scroll with the rest of the cells). As simple as possible - assumes a single header, at index path [0,0], to be pinned at the top of the collection view.
//Override UICollectionViewFlowLayout class
@interface FixedHeaderLayout : UICollectionViewFlowLayout
@end
@implementation FixedHeaderLayout
//Override shouldInvalidateLayoutForBoundsChange to require a layout update when we scroll
- (BOOL) shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
return YES;
}
@adonaldson
adonaldson / gist:1205902
Created September 9, 2011 10:23
Fixing a bug in a tagged release
I have a process for fixing bugs in tagged releases, but it always seems such a faff. This makes
me think I'm doing it wrong. So imagine this scenario:
- I tag a release (v1) and push it onto staging
- I continue work in master
- Client comes back with an issue on v1
- I create a branch based off v1
- I fix the bug
- ...