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
// 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'));
@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
<?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
//
@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 / 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";
// 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 / 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).