Skip to content

Instantly share code, notes, and snippets.

View akingdom's full-sized avatar

Andrew Kingdom akingdom

  • Australia
View GitHub Profile
@akingdom
akingdom / printerror.js
Last active March 14, 2025 06:35
Example of printing a source code line at an error position (based on an index within the entire source code)
// Example of printing a source code line at an error position
// (based on an index within the entire source code)
//
// By Andrew Kingdom
// MIT license
// (and use at own risk)
//
// Example prints:
//
// DEFGH
@akingdom
akingdom / build.gradle
Last active January 17, 2023 14:25
Auto-increment the version number in an Android App
// Android build.gradle
// How to auto-increment the version.
// There are many ways to do this - this is only one example. Its downside is that it updates the gradle file (which will ask for a Sync when opened).
// Note that the 10001 (rather than just 1) is ensure there are enough digits to prevent comparison/sorting issues.
//
// By Andrew Kingdom
// MIT license
// (and use at own risk)
//
@akingdom
akingdom / Xcode-add-Sandbox-Capability.md
Last active March 14, 2025 06:35
Add the App Sandbox capability to an Xcode project when it is missing from the standard capabilities area.

Add the App Sandbox capability to an Xcode project when it is missing from the standard capabilities area.

(Straightforward to do but a pain to remember.)

  1. If your project lacks a .entitlements file, create a new one:
  • Menu: View > Navigators > Project
  • Select the root level (project icon) of your project
  • Menu: File > New > File...
  • Use the Property List template
@akingdom
akingdom / FullyReplaceSegue.h
Last active November 15, 2022 03:38
A custom iOS segue to fully replace the current UIViewController with a new UIViewController.
// Objective C
// Display initial screen before final UIViewController loads (e.g. Login credentials)
//
// By Andrew Kingdom
// MIT license
//
// Instructions:
//
// On the main storyboard, create your login screen as, say, a subclass of UIViewController.
// Make sure it is the initial scene (check Is Initial View Controller).
@akingdom
akingdom / android_FLAG_KEEP_SCREEN_ON.java
Created October 21, 2022 01:25
How to programmatically control whether the screen may or may not turn off.
// Android Java
// How to programmatically control whether the screen may or may not turn off.
//
// By Andrew Kingdom
// MIT license
//
package com.example.sample;
import android.os.Bundle;
@akingdom
akingdom / is_Android_app_debuggable.java
Last active March 14, 2025 06:34
check if the Android app is a debug build versus a release build
// Android Java
// How to check if the app is a debug build versus a release build.
//
// By Andrew Kingdom
// MIT license
//
public class MainActivity extends AppCompatActivity {
// Returns true if the app is debuggable
@akingdom
akingdom / js_instantiates_swift_class.swift
Last active July 10, 2022 15:21
Example showing how to allow a Swift class to be instantiated via a 'new' in Javascript.
// Swift 5.0 + Javascript
// How to use 'new <classtype>' in Javascript to instantiate a Swift object (from JavaScriptCore).
//
// I couldn't find this clearly documented in any one place.
//
// By Andrew Kingdom
// MIT license
//
@objc
public protocol SampleProtocol: JSExport {
@akingdom
akingdom / README-UIColourExtension.md
Last active November 8, 2023 04:36
Convert an HTML-style web hexadecimal color string to a UIColour instance. See also C# version.

Swift 5.0

Swift 5.0 cannot use the #ffffff syntax directly. Here is the code I use for web-related projects. Supports alpha and three-digits.

Usage example (uppercase values are fine too):

    let hex = "#FADE2B"  // yellow
    let color = UIColor(fromHex: hex)
@akingdom
akingdom / PreviouslyLaunched.mm
Last active July 10, 2022 15:31
Code to detect whether this is an initial app launch or subsequent.
// Objective C++
// Detects whether this is an initial or subsequent launch of this app.
//
// By Andrew Kingdom
// MIT license
//
static BOOL _appDidLaunchPreviously;
static BOOL _appDidLaunchPreviously_known;
static NSString * kAppDidLaunchPreviously = @"priorLaunch";
static NSString * vAppDidLaunchPreviously = @"Y";
@akingdom
akingdom / Useful-Excel-Formulas.txt
Last active March 14, 2025 06:34
Useful Excel Formulas
Useful Excel Spreadsheet Formulas
---------------------------------
By Andrew Kingdom
MIT license
Shows the number of weeks covering two dates. This works across year boundaries. This is not the same as the number of weeks between two dates.
[B7] 2022-11-23 Date 1
[B8] 2023-01-15 Date 2
[B9] =ROUNDUP(((B8-WEEKDAY(B8,1)+7)-(B7-WEEKDAY(B7,1)+1))/7,0)