Skip to content

Instantly share code, notes, and snippets.

// Heading Level Numbering for Google Docs
// Created by Sohail Ahmed
// Created On October 3, 2023
// This series of functions will install an 'Auto Numbering' menu with a couple of options in it.
// The most important is 'Update Heading Numbers', which will generate/update outline numbering.
function onOpen() {
updateMenu();
}
@idStar
idStar / JiraTicketsIssueHyperlinker.gs
Created December 29, 2023 16:47
Install this Apps Script code into your default Code.gs or create a new file to house it, and have Jira ticket numbers in your Google Sheets automatically turn into hyperlinks that will open the relevant ticket. Only works in cells where the ticket reference is the only content in the cell.
// Jira Tickets Issue Hyperlinker
// Created by Sohail Ahmed
// Created on September 29, 2023
// Developed iteratively with the aid of OpenAI's GPT-4
// Instructions:
// PREFIXES: Define the prefixes for the Jira namespaces you might include in this file that need hyperlinking.
// SUBDOMAIN: Change this to the desired subdomain / Atlassian account token.
var PREFIXES = ['MYAPP', 'OTHERAPP'];
@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 {
@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 / 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 / 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 / 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 / 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 / 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 / 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">
#