Skip to content

Instantly share code, notes, and snippets.

View purplecabbage's full-sized avatar
:shipit:
shippin'

Jesse MacFadyen purplecabbage

:shipit:
shippin'
View GitHub Profile
@purplecabbage
purplecabbage / stateRunCounter.js
Created February 23, 2024 20:14
Use aio-lib-state to increment a counter
const { Core, Files, State } = require('@adobe/aio-sdk')
async function main(params) {
let runCounter = { value: 0 }
// call state lib
const stateLib = await State.init()
try {
runCounter = await stateLib.get('runCounter') || { value: 0 }
console.log('runCounter = ', runCounter)
function setPackageBin (packageBinName, packageJson) {
if (packageBinName && packageBinName.trim().length > 0) {
const [key, value] = Object.entries(packageJson.bin)[0]
packageJson.bin = { [packageBinName] : value }
}
return packageJson
}

Keybase proof

I hereby claim:

  • I am purplecabbage on github.
  • I am purplecabbage (https://keybase.io/purplecabbage) on keybase.
  • I have a public key whose fingerprint is 3AE6 4F0A BB1D 565B 81E8 2AFC 934B A36F D6CF D12D

To claim this, I am signing this object:

@purplecabbage
purplecabbage / execPatch.js
Created November 18, 2014 19:22
Prevent native calls, and do nothing on cordova.exec api calls.
var cordovaExec = cordova.exec;
var log = console.log;
cordova.exec = function(ftw, wtf, service, action, args) {
var cbId = service + cordova.callbackId++;
cordova.callbacks[cbId] = {success: ftw, fail: wtf};
log("Blocked call to : " + service + "/" + action);
log("Args to call were : " + JSON.stringify(args));
log('callbackId is ' + cbId);
}
log("cordova.exec has been plugged, in order to push a result, call : ");
@purplecabbage
purplecabbage / devicereadyPerformance.js
Last active August 29, 2015 14:04
Log time to deviceready event - requires window.performance.timing
document.addEventListener('deviceready',function() {
var deltaT = +new Date() - window.performance.timing.navigationStart;
var perfLog = window.localStorage.perfLog ? JSON.parse(window.localStorage.perfLog) : [];
perfLog.push(deltaT);
window.localStorage.perfLog = JSON.stringify(perfLog);
var maxSamples = 100;
if (perfLog.length < maxSamples) {
window.location.reload();
@purplecabbage
purplecabbage / DelFolder.bat
Created June 6, 2014 23:42
Delete deeply nested folder in windows when path is too long
REM Solution is posted here, saving this if this ever happens to me again.
REM http://windowsitpro.com/windows/jsi-tip-9651-how-can-i-delete-folder-returns-path-too-long
@echo off
if \{%1\}==\{\} @echo Syntax: DelFolder FolderPath&goto :EOF
if not exist %1 @echo Syntax: DelFolder FolderPath - %1 NOT found.&goto :EOF
setlocal
set folder=%1
set MT="%TEMP%\DelFolder_%RANDOM%"
MD %MT%

Notes: PhoneGap/Cordova, Visual Studio 2013 Update 2, and Windows Phone 8.1

Based on observations made with PhoneGap/Cordova 3.4, Visual Studio 2013 Update 2 (RTM), and Windows Phone 8.1.

  1. Projects generated via the PhoneGap or the Cordova CLI can run (unmodified) in emulators for Windows Phone 8.0 and Windows Phone 8.1
  2. Windows Phone 8.0 projects must be re-targeted to Windows Phone 8.1 for script debugging within the Windows Phone 8.1 emulator
  3. Projects generated via the PhoneGap or the Cordova CLI that are re-targeted to Windows Phone 8.1 are converted to Windows Phone Silverlight 8.1 projects
    • Windows Phone Silverlight 8.1 projects do not support script debugging in Visu
@purplecabbage
purplecabbage / WinError.js
Created March 23, 2014 03:09
Catch a log window errors
window.addEventListener("error", function (err) {
console.log("Error in file: " + err.filename +
" ln:" + err.lineno +
" : " + err.message);
});
@purplecabbage
purplecabbage / stackable.js
Last active August 29, 2015 13:57
Get js stack trace from exception
(function () {
var locStr = window.location.toString();
// we will want to clean up the full path for iOS ...
var splitStr = locStr.substring("file://", locStr.lastIndexOf("/") - 1);
console.trace = function () {
try {
throw new Error();
} catch (e) {
// skip the first 2 items, they will be the error we just threw and info on this very function
if (e.stack) {
@purplecabbage
purplecabbage / configPath
Created February 28, 2014 23:26
Cross platform access to the cordova config.xml file.
(function(){
var configPath = "../config.xml";
if( ["android","amazon-fireos"].indexOf(cordova.platformId) > -1 ) {
configPath = "../../android_res/xml/config.xml";
}
else if( ["blackberry10","firefoxos"].indexOf(cordova.platformId) > -1 ) {
configPath = "config.xml";
}
Object.defineProperty(cordova,'configPath', {enumerable: true, value: configPath });