Skip to content

Instantly share code, notes, and snippets.

View adamtarmstrong's full-sized avatar
🏠
Working from home

Adam T Armstrong adamtarmstrong

🏠
Working from home
View GitHub Profile
@adamtarmstrong
adamtarmstrong / money_format.js
Created August 11, 2017 19:22
JS - Format Number as Currency
exports.format = function(number, decimals, decSymbol, thousSymbol) { //number, decimal places , decimal symobl (.), thousands separator (,)
decimals = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals,
decSymbol = decSymbol == undefined ? "." : decSymbol,
thousSymbol = thousSymbol == undefined ? "," : thousSymbol,
posNegSymbol = number < 0 ? "-" : "",
i = parseInt(number = Math.abs(+number || 0).toFixed(decimals)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return posNegSymbol + '$' + (j ? i.substr(0, j) + thousSymbol : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousSymbol) + (decimals ? decSymbol + Math.abs(number - i).toFixed(decimals).slice(2) : "");
};
@adamtarmstrong
adamtarmstrong / youversion_event.js
Last active August 18, 2017 17:39
YouVersion Event - Deep-Link (Cross-Platform)
/*
* You Version Sample Event URL: http://bible.com/events/264769
*/
var sermonNoteURL = "youversion://events?id=" + eventID; //where eventID = 6 digit from YouVersion Event URL
openYouVersionSermonNotes(sermonNoteURL);
function openYouVersionSermonNotes(eventURL){
if (OS_ANDROID){
try {
var intent = Ti.Android.createIntent({
@adamtarmstrong
adamtarmstrong / xplatform_bio_auth.js
Last active February 6, 2018 15:06
iOS/Android Biometric Auth
/*
The Android UI is provided via my Ti.Widget: ti.androidfingerprintalertdialog
https://github.com/adamtarmstrong/ti.androidfingerprintalertdialog
referenced in the code below as: $.androidFingerprint
*/
function promptForTouchAuth(){ "use strict";
if (OS_IOS) {
$.emailAddress.blur(); //hide keyboard before prompting for biometrics
TiTouchId.authenticate({
04f2a15dc90ddb1e9fcbe51c9450bf1a4655e7ffec0d7db4092d6b7633fc9ff8a126d12d53286a3a6e094eda60922b699fc1e708b888deef8581096773ccb653b3;m1ga
@adamtarmstrong
adamtarmstrong / appc_reste_sqlite_usage.js
Last active April 11, 2018 08:55
AppC: Using RESTe + local sqlite DB
//alloy.js
require("sqlite_reste_config");
var localDB = require('sqlite_db');
localDB.initDB();
//sqlite_reste_config.js
Alloy.Globals.reste = require("reste");
@adamtarmstrong
adamtarmstrong / appc_func_decode-jwt.js
Last active June 9, 2020 13:06
Decode JWT in Axway Titanium
/**
* token
* claim = "registered" || "public" || "private"
*/
exports.decodeJWT = function(token, claim) {
var base64Url;
if (claim == "registered") {
base64Url = token.split('.')[0];
} else if (claim == "private") {
base64Url = token.split('.')[2];
@adamtarmstrong
adamtarmstrong / ti_helper.js
Created July 24, 2018 16:48
Titanium Helper Functions
//var tiHelper = require('ti_helper');
/*
* USAGE
* tiHelper.currency(numberToFormat,0);
*/
exports.currency = function(number, decimals, decSymbol, thousSymbol) { //number, decimal places , decimal symobl (.), thousands separator (,)
decimals = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals,
decSymbol = decSymbol == undefined ? "." : decSymbol,
@adamtarmstrong
adamtarmstrong / ti_modal-bottomsheet.js
Last active September 4, 2018 17:39
Ti Modal BottomSheet - Fragment
/*
* Ti Modal BottomSheet - Fragment
* Sample/Screenshot - https://imgur.com/EPHd7D2
*/
/*
* USAGE WITHIN YOUR MAIN APP:
* Simply use:
* Alloy.createController("modalBottomsheet").getView().open();
@adamtarmstrong
adamtarmstrong / ti_splitwindow.js
Created May 29, 2019 13:37
Use SplitWindow w/ Titanium and toggle MasterView based on both orientation + if in SplitView/SplitOver Mode
//XML
<Alloy>
<SplitWindow id="splitWindow" backgroundColor="white" showMasterInPortrait="true" masterIsOverlayed="true" platform="ios">
<!--MASTER-->
<NavigationWindow platform="ios">
<Window title="Master" layout="vertical">
<LeftNavButtons>
<Label id="masterCollapseButton" class="navButton" text="<<" onClick="toggleMaster" />
</LeftNavButtons>
@adamtarmstrong
adamtarmstrong / SwiftUIObjectBindingIssue.swift
Last active July 3, 2019 16:11
Issue updating @object in Class and reflecting in View
class ResultsObserver : NSObject, SNResultsObserving { //https://developer.apple.com/documentation/soundanalysis/analyzing_audio_to_classify_sounds
@ObjectBinding var whistle = Whistle()
func request(_ request: SNRequest, didProduce result: SNResult) {
... //removed for simplicity
if (classification.identifier == "my classification") {
print("Detected my classification - setting Object to true") //This shows in console (when appropriate)
DispatchQueue.main.async {
self.whistle.detected = true