Skip to content

Instantly share code, notes, and snippets.

Sohail A. idStar

View GitHub Profile
@idStar
idStar / String+Extensions.swift
Created Dec 11, 2016
Swift String extension method to provide you with a truncated version of itself, with optional trailing text
View String+Extensions.swift
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 {
@idStar
idStar / findValueForKeyInFile.sh
Created Nov 25, 2015
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.
View findValueForKeyInFile.sh
#!/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 / SpreadsheetExportToCSV.scpt
Last active Mar 8, 2020
Export spreadsheet to UTF8 CSV using Numbers 3.6 on a Mac with AppleScript
View SpreadsheetExportToCSV.scpt
#! /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 / MemoryManagementPlayground.swift
Last active Aug 29, 2015
Intermediate Swift Tutorial on RayWenderlich.com: Solution to Exercise in Part 9: Memory Managment
View MemoryManagementPlayground.swift
// 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 / gist:485516741b4e5ea95b7b
Created Sep 17, 2014
Xcode 6 command line invocation of UIAutomation Test
View gist:485516741b4e5ea95b7b
# 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 / AppDelegate.m
Created Sep 13, 2014
A way to exit full app launch mechanics when you're simply invoking the XCTest target and want to speed things up.
View AppDelegate.m
#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 / UITableViewCellSublclass.m
Created Oct 17, 2013
Workaround for iOS7 bug where UITableViewCell background in editing mode, covers up the Delete button.
View UITableViewCellSublclass.m
- (void)layoutSubviews {
[super layoutSubviews];
[self applyEditingModeBackgroundViewPositionCorrections];
}
/**
When using a backgroundView or selectedBackgroundView on a custom UITableViewCell
subclass, iOS7 currently
@idStar
idStar / automation.sh
Created Sep 2, 2012
UIAutomation test script invocation from the command line. Works with Xcode 4.4.1 and the iOS Simulator.
View automation.sh
#!/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 / UWFacebookService.m
Created Aug 30, 2012
Facebook Utility class to determine if logged in or not
View UWFacebookService.m
#import "UWFacebookService.h"
@implementation UWFacebookService
// Static
static const int ddLogLevel = LOG_LEVEL_DEBUG;
// Strong
@synthesize facebookGraphUser = _facebookGraphUser;
@idStar
idStar / ReachabilityExample.m
Created May 1, 2012
Reachability for iOS5.x with ARC, sample usage using tonymillion fork
View ReachabilityExample.m
#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
You can’t perform that action at this time.