Skip to content

Instantly share code, notes, and snippets.

@advantis
advantis / ADVExecutionTime.h
Created March 30, 2012 10:15
Measure code execution time
//
// Copyright © 2012 Yuri Kotov
//
/*!
@function ADVGetExecutionTime
@abstract Measure code execution time
@param block
code block to execute
@result elapsed time (in nanoseconds)
@advantis
advantis / mouse_battery.sh
Created April 12, 2012 17:24
Get Magic Mouse battery level
#!/bin/sh
percentage=$( ioreg -rS -c BNBMouseDevice -k BatteryPercent -d 1 | grep BatteryPercent | tail -1 | awk '{print $NF}' )
if [ "$percentage" == "" ]; then
echo "Disconnected";
else
if ((50 <= percentage)); then
color=32; #green
elif ((20 <= percentage)); then
@advantis
advantis / iOS → Export Groups.jsx
Created April 12, 2012 17:29
Export PS top-level layer groups as PNG images
// enable double clicking from the Macintosh Finder or the Windows Explorer
#target photoshop
const ScriptResult =
{
CANCEL: 'cancel' // quit, returning 'cancel' (dont localize) makes the actions palette not record our script
};
function exportGroups(document, folder, retina)
{
@advantis
advantis / ADVNetworkActivityIndicator.h
Created April 15, 2012 19:06
iOS network activity indicator manager
//
// Copyright © 2011 Yuri Kotov
//
#import <Foundation/Foundation.h>
@interface ADVNetworkActivityIndicator : NSObject
+ (ADVNetworkActivityIndicator *) sharedIndicator;
@advantis
advantis / ADVActionSheet.h
Last active October 3, 2015 08:48
UIActionSheet subclass that brings simple block API
//
// Copyright © 2011 Yuri Kotov
//
#import <UIKit/UIKit.h>
typedef void(^ADVSheetAction) ();
@interface ADVActionSheet : UIActionSheet <UIActionSheetDelegate>
@advantis
advantis / NSError+ADVAlertPresentation.h
Created April 22, 2012 09:41
Shortcut method for quick NSError presentation
//
// Copyright © 2010 Yuri Kotov
//
#import <Foundation/Foundation.h>
@interface NSError (ADVAlertPresentation)
- (void) displayInAlert;
@advantis
advantis / UILabel+NibFont.h
Created May 30, 2012 12:00
UILabel category for setting custom font in IB
//
// Copyright © 2012 Yuri Kotov
//
#import <UIKit/UIKit.h>
@interface UILabel (NibFont)
@property (nonatomic, copy) NSString *fontName;
@property (nonatomic) CGFloat fontSize;
@advantis
advantis / ADVTableView.h
Created June 10, 2012 10:06
Backport of the cell-to-nib registration API to iOS < 5.0
//
// Copyright © 2012 Yuri Kotov
//
#import <UIKit/UIKit.h>
@interface ADVTableView : UITableView
- (void) registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier;
@advantis
advantis / gist:3619129
Last active October 10, 2015 02:37
Enumeration benchmark
/* All measurements were done on iPhone 4 */
// MRC:
// for loop: 1.891520ms
// NSFastEnumeration: 0.393583ms
// enumerateObjectsUsingBlock: 0.547250ms
// ARC (w/o __unsafe_unretained):
// for loop: 6.889979ms
// NSFastEnumeration: 0.394479ms
@advantis
advantis / ADVUserInterfaceIdiom.h
Created September 7, 2012 13:11
Easy user interface idiom detection
//
// Copyright © 2012 Yuri Kotov
//
extern BOOL ADVUserInterfaceIdiomIsPhone;