Skip to content

Instantly share code, notes, and snippets.

@joyrexus
joyrexus / README.md
Last active February 20, 2025 18:04 — forked from liamcurry/gist:2597326
Vanilla JS equivalents of jQuery methods

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@pi-chan
pi-chan / compareUIImage.m
Last active December 14, 2016 12:52
compare uiimage by md5 hash
- (void)md5HashFromUIImage:(UIImage*)image
hash:(unsigned char*)hash
{
CGDataProviderRef dataProvider = CGImageGetDataProvider(image.CGImage);
NSData *data = (NSData*)CFBridgingRelease(CGDataProviderCopyData(dataProvider));
CC_MD5([data bytes], [data length], hash);
}
- (BOOL)compareUIImages:(UIImage*)image1
image:(UIImage*)image2
@brocoo
brocoo / Available UIFonts
Last active August 29, 2015 13:57
Available UIFonts on iOS
NSArray *fontFamilies = [UIFont familyNames];
for (int i = 0; i < [fontFamilies count]; i++){
NSString *fontFamily = fontFamilies[i];
NSArray *fontNames = [UIFont fontNamesForFamilyName:fontFamilies[i]];
NSLog (@"%@: %@", fontFamily, fontNames);
}
@brocoo
brocoo / Maths macros
Last active August 29, 2015 13:57
Maths macros
#define FLT_EQUAL(a, b) (fabs((a) - (b)) < FLT_EPSILON)
#define FLT_ZERO(a) (fabs(a) < FLT_EPSILON)
@brocoo
brocoo / Prevent iCloud Backup
Created April 23, 2014 14:00
This method should be implemented in a NSURL category
- (BOOL)addSkipBackupAttribute{
if (![[NSFileManager defaultManager] fileExistsAtPath:[self path]]) return NO;
NSError *error = nil;
BOOL success = [self setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
if(!success){
NSLog(@"Error excluding %@ from backup %@", [self lastPathComponent], error);
}
return success;
}
@calebd
calebd / AsynchronousOperation.swift
Last active February 27, 2025 09:17
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
@jstn
jstn / Timer.swift
Last active June 19, 2022 15:14
simple nanosecond timer using mach_absolute_time
/*
var t = Timer()
t.start()
// do something
t.stop()
print("took \(t.seconds)")
*/
@chriseidhof
chriseidhof / routes.swift
Created August 17, 2014 21:04
Type-safe routes in Swift
//
// main.swift
// Routes
//
// Created by Chris Eidhof on 17/08/14.
// Copyright (c) 2014 Chris Eidhof. All rights reserved.
//
import Foundation
@brocoo
brocoo / Swift NSNotification extension
Last active May 13, 2016 09:51
Extension of NSNotification to use a key enum as the notification name.
public enum NotificationKey: String {
case UserSignedIn = "UserSignedInNotification"
case UserSignedOut = "UserSignedOutNotification"
case SomeOtherEvent = "SomeOtherEventNotification"
}
extension NSNotificationCenter {
func addObserver(observer: AnyObject, selector aSelector: Selector, key aKey: NotificationKey) {
self.addObserver(observer, selector: aSelector, name: aKey.rawValue, object: nil)
@brocoo
brocoo / Result.swift
Last active August 29, 2015 14:16
A result enum, storing a boxed type or a NSError meant to be return from any process (API call, etc) (Swift 1.2)
// MARK: - Box
final public class Box<T> {
public let unbox:T
public init(_ value: T) { self.unbox = value }
}
// MARK: - Result enum
public enum Result<T: Printable> {