Skip to content

Instantly share code, notes, and snippets.

@ajjames
ajjames / Downloader.swift
Last active June 14, 2020 08:12
Cancelable UIImageView async download extension (with simple NSCache-backed ImageManager class, and cancelable Downloader class)
//
// Downloader.swift
// Copyright (c) 2015 Andrew James. All rights reserved.
//
import Foundation
import UIKit
public class Downloader : NSObject
{
@ajjames
ajjames / DispatchUtility.swift
Last active August 29, 2015 14:13
Dispatch Utility for succinct ways of calling GCD
//
// DispatchUtility.swift
//
// Copyright (c) 2015 Andrew James. All rights reserved.
//
import Foundation
func GCDDispatchMain(closure:()->())
{
@ajjames
ajjames / find4Largest.swift
Created January 19, 2015 03:21
Find 4 Largest
import UIKit
func find4Largest(numbers:[Int]) -> [Int]
{
let count = 4
assert(count < numbers.count, "Error: numbers must have at least \(count) elements")
if numbers.count < 2
{
return numbers
}
@ajjames
ajjames / UpgradeHelper.m
Last active August 29, 2015 14:13
UpgradeHelper
//Objective-c
//HEADER
#import <Foundation/Foundation.h>
@interface UpgradeHelper : NSObject
+(BOOL)isUpgradeAvailable:(NSString*)localVersion releasedVersion:(NSString*)releasedVersion;
@end
//IMPLEMENTATION
#import "UpgradeHelper.h"
//.h
@interface TabBarHidingCollectionViewController : UICollectionViewController
@end
//.m
@interface TabBarHidingCollectionViewController ()
@property (nonatomic) CGFloat lastOffsetY;
@end
@implementation TabBarHidingCollectionViewController
@ajjames
ajjames / DictionaryExtension.swift
Last active August 29, 2015 14:11
DictionaryExtension to get implicit type
internal extension Dictionary
{
internal func get<V>(key:Key) -> V? {
return self.indexForKey(key) as? V
}
}
@ajjames
ajjames / Macros.h
Last active August 29, 2015 13:56
DLog: Obj-C Logging Macros
#ifdef DEBUG
#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define DLog(...)
#define NSLog(...)
#endif
#define IS_PAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? YES : NO)
#define IS_PHONE !IS_PAD
/*
File: UIImage+ImageEffects.h
Abstract: This is a category of UIImage that adds methods to apply blur and tint effects to an image. This is the code you’ll want to look out to find out how to use vImage to efficiently calculate a blur.
Version: 1.0
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
//
// UIView+Parallax.h
//
#import <Foundation/Foundation.h>
@interface UIView (Parallax)
-(void)addBackgroundParallax:(CGFloat)strength;
-(void)addForegroundParallax:(CGFloat)strength;
-(void)removeParallax;
@ajjames
ajjames / RetryManager.cs
Created November 28, 2012 01:39
Simple retry class
using System;
using System.Threading;
using NUnit.Framework;
namespace Tests
{
class RetryManager
{
public void AttemptToRetryUntilTrue(Func<bool> condition, int timeoutMilliseconds = 5000, int delayMiliseconds = 100)
{