Skip to content

Instantly share code, notes, and snippets.

View akingdom's full-sized avatar

Andrew Kingdom akingdom

  • Australia
View GitHub Profile
//application/javascript
//
// A simple sequential calculator.
// By Andrew Kingdom
// MIT license
//
// Operator order/precedence is ignored.
// The calculation string is expected to have numbers and operators separated by spaces.
//
function operate(x,oper,y) {
//application/javascript
//
// Demonstrates callback from a class method
// By Andrew Kingdom
// MIT license
// Define a class
let MyClass1 = class {
constructor(initialValue) {
this.prop = initialValue; // store the parameter value in a property
@akingdom
akingdom / swift-enums
Last active March 25, 2022 14:25
enum tricks in Swift
// Means to provide an alias to a value
// in a similar manner to Objective-C
// since Swift does not permit duplicate raw values
//
// By Andrew Kingdom
// MIT license
enum SomeOption : Int
{
case First = 0
// Returns the minimum download limit specified in the current php.ini file.
//
// By Andrew Kingdom
// MIT license
function max_upload_size() {
$max_size = PHP_INT_MAX;
$post_overhead = 2048; // Reserve 2k for non-file data in the POST.
$tmp = shorthand_bytes(ini_get('upload_max_filesize'));
<?php
// An example of receiving file(s) POSTed by an HTML web form (PHP language)
//
// Please add any necessary path and file handling, security, etc. that you require.
//
// By Andrew Kingdom
// MIT license
//
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)
@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 / 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 / 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 {
// 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