Skip to content

Instantly share code, notes, and snippets.

@idStar
idStar / ReachabilityExample.m
Created May 1, 2012 13:59
Reachability for iOS5.x with ARC, sample usage using tonymillion fork
#pragma mark - Reachability
/**
* This kicks off a check for our website's reachability in the context of needing it to display, or alert the user
* of error, just once. That's why we stop the notifier in both reachable and unreachable callback block handlers.
* We're not looking for ongoing callbacks through the life of the application; we just want to know the one time.
*
* This is meant for an iPhone app only, hence, no explicit WWAN setting.
*
* CREDIT
@idStar
idStar / UWFacebookService.m
Created August 30, 2012 16:47
Facebook Utility class to determine if logged in or not
#import "UWFacebookService.h"
@implementation UWFacebookService
// Static
static const int ddLogLevel = LOG_LEVEL_DEBUG;
// Strong
@synthesize facebookGraphUser = _facebookGraphUser;
@idStar
idStar / automation.sh
Created September 2, 2012 23:48
UIAutomation test script invocation from the command line. Works with Xcode 4.4.1 and the iOS Simulator.
#!/bin/bash
# automation.sh
# Created by @idStar - Sohail Ahmed - September 2, 2012
# This script launches the UIAutomation Instrument targeting a pre-existing iOS Simulator app, from the command line.
# Works with Xcode 4.4.1 on Mountain Lion
#
# Usage:
# automation <"App Name.app"> <"testFile.js"> <"base test script path"> <"base iOS Simulator path"> <"results output directory">
#
@idStar
idStar / UITableViewCellSublclass.m
Created October 17, 2013 01:56
Workaround for iOS7 bug where UITableViewCell background in editing mode, covers up the Delete button.
- (void)layoutSubviews {
[super layoutSubviews];
[self applyEditingModeBackgroundViewPositionCorrections];
}
/**
When using a backgroundView or selectedBackgroundView on a custom UITableViewCell
subclass, iOS7 currently
@idStar
idStar / AppDelegate.m
Created September 13, 2014 19:52
A way to exit full app launch mechanics when you're simply invoking the XCTest target and want to speed things up.
#pragma mark - XCTest Support
static BOOL isRunningTests(void) __attribute__((const));
/**
We need a mechanism to detect if we have been invoked / are running from a unit test.
If we are, we'll want to exit early instead of doing all kinds of view controller setup.
This function determines based on the environment, if we're running in a unit test process,
such as XCTest.
@idStar
idStar / gist:485516741b4e5ea95b7b
Created September 17, 2014 13:42
Xcode 6 command line invocation of UIAutomation Test
# This is what I tried, but I just got crickets after executing it; with nothing happening and no results posted.
instruments -t "/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate" "/Users/sohail/Library/Developer/CoreSimulator/Devices/7232A640-A9D2-4626-A2AD-37AFFF706718/data/Containers/Bundle/Application/D07FEC4B-76AD-4844-8362-08E771B81053/MyAppName.app" -e UIASCRIPT "/Users/sohail/source/MyAppName/MyAppNameAutomationTests/TestRunner.js" -e UIARESULTSPATH "Users/sohail/source/MyAppName/MyAppNameAutomationTests/TestResults"
@idStar
idStar / MemoryManagementPlayground.swift
Last active August 29, 2015 14:23
Intermediate Swift Tutorial on RayWenderlich.com: Solution to Exercise in Part 9: Memory Managment
// Part 09: Memory Management
// Swift 2.0 (Xcode 7 Beta 1)
// "Uber" Challenge Exercise from Ray Wenderlich's "Intermediate Swift Series", Part 9.
// Series available here: http://www.raywenderlich.com/video-tutorials#swift
// Solution created by Sohail Ahmed, twitter: @idStar, blog: http://sohail.io
class Conference {
var name:String
var instructors:[Instructor] = Array<Instructor>()
var students:[Student] = Array<Student>()
@idStar
idStar / SpreadsheetExportToCSV.scpt
Last active March 8, 2020 03:57
Export spreadsheet to UTF8 CSV using Numbers 3.6 on a Mac with AppleScript
#! /usr/bin/osascript
(*
---------------------------------------------------------------------------------
Script: SpreadsheetExportToCSV
Command-line tool to convert a spreadsheet document to CSV
This AppleScript is tested with and compatible with Apple iWork Numbers 3.6,
current as at October 23, 2015.
@idStar
idStar / findValueForKeyInFile.sh
Created November 25, 2015 22:18
How to find the value for a given key, in a particular file. The notion of "key" and "value" are a bit loose. See the documentation.
#!/bin/bash
# In this example, we demonstrate how to find the value for a given key, in a particular file,
# using the Bash Shell Scripting language. We've setup some primitive functions to provide
# some modularity. See near the end for example usage on how you might call this.
#
# Assumptions:
# 1. Stripping leading and trailing whitespace in the value string is desired.
# 2. The last occurrence of the key (if there are multiple) is all we care about.
@idStar
idStar / String+Extensions.swift
Created December 11, 2016 16:03
Swift String extension method to provide you with a truncated version of itself, with optional trailing text
extension String {
// Modified from original: https://techvangelist.net/truncate-a-string-in-swift-2-0/
// We respect max character length requested, even if we allow ellipsis.
func truncated(toMaxLength length: Int, trailing: String? = "...") -> String {
if self.characters.count > length {
let trailingText = trailing ?? ""
let uptoIndex = length - 1 - trailingText.characters.count
return self.substringToIndex(self.startIndex.advancedBy(uptoIndex)) + trailingText
} else {