Skip to content

Instantly share code, notes, and snippets.

import Cocoa
// for-in
func checkForIn(array: [Int], dict: [Int: String]) {
for num in array where dict[num] != nil {
num
}
}
checkForIn([1,2,3,4], dict: [1:"one", 2:"two"])
@AliSoftware
AliSoftware / Generics-Macros.h
Last active December 11, 2020 17:18
ObjCGenerics
// Allow to use generics even if not supported yet
#if __has_feature(objc_generics)
#define NSArrayOf(x) NSArray<x>
#define NSMutableArrayOf(x) NSMutableArray<x>
#define NSDictionaryOf(x,y) NSDictionary<x, y>
#define NSMutableDictionaryOf(x, y) NSMutableDictionary<x, y>
#define NSSetOf(x) NSSet<x>
#define NSMutableSetOf(x) NSMutableSet<x>
#else
#define NSArrayOf(x) NSArray
@jazzychad
jazzychad / ZZZTypewriterLabel.h
Last active August 29, 2015 14:20
ZZZTypewriterLabel
//
// ZZZTypewriterLabel.h
//
// Created by Chad Etzel on 4/30/15.
// Copyright (c) 2015 Chad Etzel, MIT License.
//
//
// The MIT License (MIT)
//
// Copyright (c) 2015 Chad Etzel
@JeOam
JeOam / Animation.md
Last active February 18, 2024 21:18
iOS Core Animation: Advanced Techniques, Part 1: The Layer Beneath

Author: https://www.cyanhall.com/

1. The Layer Tree

Core Animation's original name is Layer Kit

Core Animation is a compositing engine; its job is to compose different pieces of visual content on the screen, and to do so as fast as possible. The content in question is divided into individual layers stored in a hierarchy known as the layer tree. This tree forms the underpinning for all of UIKit, and for everything that you see on the screen in an iOS application.

In UIView, tasks such as rendering, layout and animation are all managed by a Core Animation class called CALayer. The only major feature of UIView that isn’t handled by CALayer is user interaction.

There are four hierarchies, each performing a different role:

@calebd
calebd / AsynchronousOperation.swift
Last active April 29, 2023 13:12
Concurrent NSOperation in Swift
import Foundation
/// An abstract class that makes building simple asynchronous operations easy.
/// Subclasses must implement `execute()` to perform any work and call
/// `finish()` when they are done. All `NSOperation` work will be handled
/// automatically.
open class AsynchronousOperation: Operation {
// MARK: - Properties
@irace
irace / gist:27c72d538b02d33cd714
Last active May 17, 2016 22:02
CSS and JavaScript from Tumblr 3.0 for iOS (Summer 2012)
// Copyright (c) 2012 Tumblr. All rights reserved.
// License: Apache 2.0
// We're using an 'active' class instead of the default :active pseudo selector because we can add/remove it easily
var elementsWithActiveStateSelector = ['.tumblelog', '.control', '.audio-player', '.tag', 'a', '.video',
'.gif-container', '.external-image-placeholder'].join(',');
$('#content').on('touchstart', elementsWithActiveStateSelector, function() {
var $el = $(this);
@monkeydom
monkeydom / swiftc.sh
Last active October 24, 2015 23:50
Script to be used in a hashbang to conditionally compile and then run the swift script referenced. usage #!/usr/bin/env swiftc.sh in your swift file, and put in path
#!/bin/sh
SWIFT=$(/usr/bin/env xcrun -f swift)
SCRIPTPATH=$1
COMPILEDPATH="$SCRIPTPATH.o"
SDKPATH=$(/usr/bin/env xcrun --show-sdk-path --sdk macosx)
#compile if necessary
@tsiege
tsiege / The Technical Interview Cheat Sheet.md
Last active May 9, 2024 13:54
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

ANNOUNCEMENT

I have moved this over to the Tech Interview Cheat Sheet Repo and has been expanded and even has code challenges you can run and practice against!






\

@spoletto
spoletto / gist:9383098
Created March 6, 2014 05:23
The undocumented behavior of ALAssetPropertyDate
/*
* In practice, what I've found is that ALAssetPropertyDate, which is documented as the "asset creation time"
* will return (always in UTC):
*
* (1) If taken from the native camera, a ms-precision time of when the photo was taken.
* (2) If EXIF exists, EXIF time converted to UTC based on the timezone the device was in when
* the photo was saved to the camera roll. This is sec-precision.
* (3) If EXIF does not exist, the time the photo was written into the camera roll. This is sec-precision.
*/
NSDate *timeTaken = [asset valueForProperty:ALAssetPropertyDate];
@lisamelton
lisamelton / convert-mp4-to-mkv.sh
Last active March 2, 2020 10:26
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