Skip to content

Instantly share code, notes, and snippets.

View akingdom's full-sized avatar

Andrew Kingdom akingdom

  • Australia
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / !Line Record Format.txt
Last active May 29, 2023 16:16
A very simple human-friendly parsable data format. I use this in a number of projects.
# Format Objectives
1. Suitable for editing by humans, especially those with minimal technology skills.
2. Readable by computers.
3. Readability by humans is preferred over reducing file size.
# Basic Format
* The basic line format is a name, some space(s) and a value.
* A record starts with RECORD or # (then an optional identifier).
@akingdom
akingdom / DynamicMemberLookupExample.swift
Last active May 17, 2023 05:14
Use a string key to reference a property in a class or struct; Get the name of a property as a string
// Demonstrates Swift-based reflection concept like Key-Value coding in Objective-C (but slower)
// and use of @dynamicMemberLookup.
//
// Uses Mirror to reference a property in a class or struct by string key name;
// Uses @dynamicMemberLookup to get the name of a property as a string, to reverse the reflection.
//
// DynamicMemberLookupExample.swift
//
// Copyright Andrew Kingdom 2023-05-17.
// MIT License
@akingdom
akingdom / google-drive-link-transform.m
Last active June 5, 2023 09:29
Code snippet to transform a Google Drive link to a directly accessible URL (2023)
@akingdom
akingdom / editable-dropdown.html
Last active September 5, 2024 17:36
Example of a basic editable HTML dropdown (SELECT menu).
<html>
<!--
This replaces the SELECT dropdown menu with an editable INPUT textbox,
when the last ('other') option is selected from the list.
Note that this may not be a good fit when supplying both display values and raw values,
as evidenced by the 'spanish' option.
By Andrew Kingdom (C) 2023 all rights reserved. MIT License.
-->