I hate asynchronous JS programming

Posted on Updated on

This has to be the biggest problem I face when using JS.

It’s not like VB, VBScript, BAT, BAS, C# or other serial, linear programming languages.

It drives me crazy.

I’m still of the opinion that all code should still be sequential by default, and if you want a function to be async, then you should just tell that specific call to be async, rather than the other way around. An opt in, rather than “you’re already in and tough luck”.

To make like easier (and I’ve stolen this code to post here, as it makes life easier and so I can find it again later) here is some code of a working practical example.

 

Serial or Chaining Flow

If you want to execute different promise methods sequential i.e. execute one by one, it is easy using Async/Await and the code looks like synchronous.

async function SerialFlow(){
let result1 = await doJob(1,1);
let result2 = await doJob(2,2);
let result3 = await doJob(3,3);
let finalResult = result1+result2+result3;
console.log(finalResult);
return finalResult;
}
SerialFlow();

In above method first 1 is executed and wait for one sec then 2 is started wait for 2 seconds after that 3 started to execute. 1,2,3 are executed sequentially, hence the total time is 6 seconds.

Console Output:

Start: 1
End: 1
Start: 2
End: 2
Start: 3
End: 3
6

 

Just about every other example online gives non-practical examples and use promises, observables, awaits, asyncs, call-back hell, jargon that mostly doesn’t make sense. I hope this very simple example will help you.

 

Here is my very crude example of partially working code, of which you can see there are things going on.

async function getpostcoderegion(state)
{
  var dataselection = document.getElementById(“dataselection”).value;
  var dateparams = “&date=” + dataselection;
// Confirm as CITY
// Confirm as REGIONAL
  var params = “state=” + state + dateparams;
  var xhttp =  new XMLHttpRequest();
    xhttp.onreadystatechange = await function() {
    if (this.readyState == 4 && this.status == 200) {
      citystations = JSON.parse(xhttp.responseText);
      console.log(citystations);
    }
  };
  xhttp.open(“POST”, “getpostcodecitystate.php”, true);
  xhttp.setRequestHeader(‘X-Requested-With’, ‘XMLHttpRequest’);
  xhttp.setRequestHeader(‘Content-Type’, ‘application/x-www-form-urlencoded’);
  xhttp.send(params);
  return 1;
}

async  function postcodeboundariesshow(state_location)

{
  // Collected the postcodes of those that are for the city/metor areas in that state.
    //getpostcoderegion(state_location);
    var file_location = “../../geo_json/” + state_location + “.postcode.json”;
 geojsonLayer[state_location] = new L.GeoJSON.AJAX(file_location, {
    onEachFeature: onEachFeature,
    “fillOpacity”: .05,
    color: “#F00”,
    weight: 1,
  })
  .addTo(mymap);
   return “2”;
}

 

// RUN THE MAGIC FROM THIS FUNCTION.
async function postcodeboundaries(state_location)
{

  // Collected the postcodes of those that are for the city/metor areas in that state.
    let a = await getpostcoderegion(state_location);
    let b = await postcodeboundariesshow(state_location);
}

Ionic 3 Background Geolocation

Posted on

It’s taken a long time to get to this stage, but this is just the start…

After having followed the instructions on this site, I got a long way.

But, I also only got so far as well… Here is a copy of my “home.ts” file for an app.

 

import { Component } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';
import { BackgroundGeolocation, BackgroundGeolocationConfig, BackgroundGeolocationResponse, BackgroundGeolocationEvents } from '@ionic-native/background-geolocation';
import { LocalNotifications } from '@ionic-native/local-notifications';

@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {

config: BackgroundGeolocationConfig = {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
debug: true, // enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false, // enable this to clear background location settings when the app terminates
};

missionCode: string = "";
userId: string = "";

constructor(public navCtrl: NavController,

private plt: Platform, 
private backgroundGeolocation: BackgroundGeolocation,
public globals: GlobalsProvider,
private localNotifications: LocalNotifications) {


if(this.plt.is('core') || this.plt.is('mobileweb')) {

// NO. It's a browser.
// Use a different GPS method.

} else 
{
// YES. It's a a compilerd app.


this.backgroundGeolocation.configure(this.config)
.then(() => {

this.backgroundGeolocation.on(BackgroundGeolocationEvents.location).
subscribe((location: BackgroundGeolocationResponse) => {
console.log(location);


this.showNotification(location);


// IMPORTANT: You must execute the finish method here to inform the native plugin that you're finished,
// and the background-task may be completed. You must do this regardless if your HTTP request is successful or not.
// IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background. 
this.backgroundGeolocation.finish(); // FOR IOS ONLY
});

}); 
}

}

startBackgroundGeolocation() {
// start recording location
this.backgroundGeolocation.start();
}

stopBackgroundGeolocation() {
// If you wish to turn OFF background-tracking, call the #stop method.
this.backgroundGeolocation.stop();
}

showNotification(data){
// Schedule a single notification
this.localNotifications.schedule({
id: 1,
text: JSON.stringify(data),
sound: 'file://sound.mp3',
data: { secret: "key" }
});
}

}

 

My packages.json file looks like this:

{
"name": "My App",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"start": "ionic-app-scripts serve",
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint"
},
"dependencies": {
"@angular/animations": "5.2.11",
"@angular/common": "5.2.11",
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
"@angular/forms": "5.2.11",
"@angular/http": "^5.2.11",
"@angular/platform-browser": "5.2.11",
"@angular/platform-browser-dynamic": "5.2.11",
"@auth0/angular-jwt": "^1.2.0",
"@babel/core": "^7.8.4",
"@ionic-native/background-geolocation": "^4.20.0",
"@ionic-native/core": "~4.11.0",
"@ionic-native/geolocation": "^4.20.0",
"@ionic-native/http": "^4.20.0",
"@ionic-native/local-notifications": "^4.20.0",
"@ionic-native/splash-screen": "~4.11.0",
"@ionic-native/status-bar": "~4.11.0",
"@ionic/storage": "^2.2.0",
"cordova-android": "^7.1.1",
"cordova-browser": "^6.0.0",
"cordova-plugin-advanced-http": "^2.4.0",
"cordova-plugin-badge": "^0.8.8",
"cordova-plugin-device": "^2.0.3",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-geolocation": "^4.0.2",
"cordova-plugin-ionic-keyboard": "^2.2.0",
"cordova-plugin-ionic-webview": "^2.5.3",
"cordova-plugin-local-notification": "^0.9.0-beta.2",
"cordova-plugin-mauron85-background-geolocation": "^3.0.1",
"cordova-plugin-splashscreen": "^5.0.3",
"cordova-plugin-whitelist": "^1.3.4",
"cordova-sqlite-storage": "^4.0.0",
"emulator": "0.1.0",
"glob": "^7.1.6",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"leaflet": "^1.6.0",
"leaflet-ant-path": "^1.3.0",
"leaflet-draw": "^1.0.4",
"leaflet-gps-tracker": "^1.2.1",
"leaflet-polyline": "0.0.2",
"leaflet.freedraw": "^2.0.1",
"native-run": "^0.3.0",
"node-sass": "^4.13.1",
"resolve": "^1.15.0",
"rxjs": "5.5.11",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.26"
},
"devDependencies": {
"@ionic/app-scripts": "^3.2.4",
"typescript": "~2.6.2"
},
"description": "The best way to manage your searches from an emergency management control point.",
"cordova": {
"plugins": {
"cordova-plugin-geolocation": {
"GEOLOCATION_USAGE_DESCRIPTION": "To locate you"
},
"cordova-plugin-whitelist": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-webview": {},
"cordova-plugin-ionic-keyboard": {},
"cordova-sqlite-storage": {},
"cordova-plugin-advanced-http": {},
"cordova-plugin-mauron85-background-geolocation": {},
"cordova-plugin-local-notification": {}
},
"platforms": [
"browser",
"android"
]
}
}

 

This code is a little old, but please note, the version numbers in my packages.json file.

Leaflet Performance issues

Posted on Updated on

I’m really enjoying working with Leaflet at the moment, but this problem had plagued me for days, where all of a sudden, my performance levels dropped to almost nothing.

Basically I went from this:

this.globals.map.locate(
{ 
maxZoom: 111,
drawControl: true,
watch:true,
enableHighAccuracy:true
}).on('locationfound', (e) => {

this.locationdata = { "coords":{"latitude": e.latlng.lat, 
"longitude": e.latlng.lng,
"accuracy" : e.accuracy, 
"altitude" : e.altitude, 
"heading" : e.heading,
"speed" : e.speed,
"timestamp" : e.timestamp
}};

}

 

To this:

this.map.locate(
{
maxZoom: 111,
drawControl: true,
enableHighAccuracy:true
}).on('locationfound', (e) => {

this.locationdata = { "coords":{"latitude": e.latlng.lat,
"longitude": e.latlng.lng,
"accuracy" : e.accuracy,
"altitude" : e.altitude,
"heading" : e.heading,
"speed" : e.speed,
"timestamp" : e.timestamp
}};
}

 

What’s the difference you say?

” watch:true,”

Basically, if you have have this running like this, it will keep on checking the GPS signal in the background, and eventually cripple everything, because your phone device can’t keep up with the app. GPS time-outs will occur and things won’t complete. So, if you remove the watch:true statement, things will still work well, and you can call it every second, or every 10 seconds, or whatever your tracking needs are.

My full issue was that exponentially, the app was just slowing down to a complete halt and anything to do with the map would slow and stop working. It would begin fine, but within a few minutes, the app was unusable.

So, this is my (partial) solution. It should be enough to help you get by.

I’ve found it’s easier to do something like this:

this.subscr = Observable.interval(1000) 
.flatMap(() => this.getData())
.subscribe(data => { 
//console.log("App 1 second heartbeat"); 
// Call the GPS tracker bit
this.GetRealTimeLocationNow(); /// THIS FUNCTION INCLUDES THAT GPS METHOD
if(this.trackedRoute.length >0)
{
this.redrawPath(this.trackedRoute); 
}
});

 

So, after a couple of days thinking it was layer and mapping problems (with showing hiding markers or tracking lines and rewriting that entire part), and optimising the app even more, I think it’s pretty good now. This will be more or less confirmed over time though.

You can draw a tracking line like this too:

current_positionTrack: any [];


somefunction_etc()
{
// Show the current location on the map
if (this.current_positionTrack != undefined) 
{
 if(this.map)
  {
   this.map.removeLayer(this.current_positionTrack);
  } 
 }; 

this.current_positionTrack = leaflet.polyline(path, {color: 'red', weight: 1, opacity: 0.7, smoothFactor: 1});
this.map.addLayer(this.current_positionTrack); 
}

And even have a marker that stays on the screen on your location too, like this:

marker = null;


some_other_function_etc () //or whatever
{

// Probably should go after this in the GPS tracker bit:
// }).on('locationfound', (e) => {
// You'll figure it out.
 
 if (!this.marker) {
  this.marker = leaflet.marker(e.latlng).addTo(this.map);
 }

 if(e.latlng != null)
 {
  this.marker.setLatLng(e.latlng);
 }
}

node-sass ionic nodejs error fix

Posted on Updated on

Sometimes you go on a bug fixing journey and get no-where. Like always, when I find a solution to a lengthy problem, I write it up so I can remember it later.

I had this error show up, after doing an update to the latest version of Ionic, and for over an hour and a half, I upgraded NPM packages and everything, changed and updated code and got no-where.

I then went back and reverted to my last commit, rerun this command: (as found here)

node node_modules/node-sass/scripts/install.js

Where it eventually started working again.

Happy, but rather frustrated that it has to happen.

stephenmonro@SMMMacPro:~/ionicApps/project$ ionic serve
> ionic-app-scripts serve --address localhost --port 8100 --livereload-port 35729 --dev-logger-port 53703 --nobrowser
[app-scripts] fs.js:114
[app-scripts] throw err;
[app-scripts] ^
[app-scripts] Error: ENOENT: no such file or directory, scandir '/Users/stephenmonro/ionicApps/project/node_modules/node-sass/vendor'
[app-scripts] at Object.readdirSync (fs.js:785:3)
[app-scripts] at Object.getInstalledBinaries (/Users/stephenmonro/ionicApps/project/node_modules/node-sass/lib/extensions.js:132:13)
[app-scripts] at foundBinariesList (/Users/stephenmonro/ionicApps/project/node_modules/node-sass/lib/errors.js:20:15)
[app-scripts] at foundBinaries (/Users/stephenmonro/ionicApps/project/node_modules/node-sass/lib/errors.js:15:5)
[app-scripts] at Object.module.exports.missingBinary (/Users/stephenmonro/ionicApps/project/node_modules/node-sass/lib/errors.js:45:5)
[app-scripts] at module.exports (/Users/stephenmonro/ionicApps/project/node_modules/node-sass/lib/binding.js:15:30)
[app-scripts] at Object.<anonymous> (/Users/stephenmonro/ionicApps/project/node_modules/node-sass/lib/index.js:14:35)
[app-scripts] at Module._compile (internal/modules/cjs/loader.js:701:30)
[app-scripts] at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
[app-scripts] at Module.load (internal/modules/cjs/loader.js:600:32)

[ERROR] ionic-app-scripts has unexpectedly closed (exit code 1).

The Ionic CLI will exit. Please check any output above for error details.
stephenmonro@SMMMacPro:~/ionicApps/project$ nodejs node_modules/node-sass/scripts/install.js
-bash: nodejs: command not found
stephenmonro@SMMMacPro:~/ionicApps/project$ node node_modules/node-sass/scripts/install.js
Downloading binary from https://github.com/sass/node-sass/releases/download/v4.13.1/darwin-x64-64_binding.node
Download complete
Binary saved to /Users/stephenmonro/ionicApps/project/node_modules/node-sass/vendor/darwin-x64-64/binding.node
stephenmonro@SMMMacPro:~/ionicApps/project$ ionic serve
> ionic-app-scripts serve --address localhost --port 8100 --livereload-port 35729 --dev-logger-port 53703 --nobrowser
[app-scripts] [01:26:03] ionic-app-scripts 3.2.4

 

Also, another fun bug you could be chasing for a long this is to do with the .subscribe method.

“ERROR TypeError: Object(…) is not a function”.

For example, the following code:

this.httpClient.post( this.globals.apiserver + "post_user_track_location.php", trackstringdata, options)
.subscribe(data => { 
this.returned = data; 
//console.log (this.items); 
console.log (data); 
});

If you are running off a “localhost” change it to 127.0.0.1.

It may just work for you.

 

DOSBOX Autoexec.bat

Posted on Updated on

This took me a while to locate on my computer, but I eventually found it, and I’ll share the location and what I’ve done.

The current official wiki is here, but it seems to not reflect my current situation.

The settings for me are located here:
/Users/stephenmonro/Library/Preferences/DOSBox 0.74 Preferences

This is a text file, and it can be opened and edited easily.

This is my current dosbox preferences file:

 

# This is the configurationfile for DOSBox 0.74. (Please use the latest version of DOSBox)
# Lines starting with a # are commentlines and are ignored by DOSBox.
# They are used to (briefly) document the effect of each option.

[sdl]
# fullscreen: Start dosbox directly in fullscreen. (Press ALT-Enter to go back)
# fulldouble: Use double buffering in fullscreen. It can reduce screen flickering, but it can also result in a slow DOSBox.
# fullresolution: What resolution to use for fullscreen: original or fixed size (e.g. 1024x768).
# Using your monitor's native resolution with aspect=true might give the best results.
# If you end up with small window on a large screen, try an output different from surface.
# windowresolution: Scale the window to this size IF the output device supports hardware scaling.
# (output=surface does not!)
# output: What video system to use for output.
# Possible values: surface, overlay, opengl, openglnb.
# autolock: Mouse will automatically lock, if you click on the screen. (Press CTRL-F10 to unlock)
# sensitivity: Mouse sensitivity.
# waitonerror: Wait before closing the console if dosbox has an error.
# priority: Priority levels for dosbox. Second entry behind the comma is for when dosbox is not focused/minimized.
# pause is only valid for the second entry.
# Possible values: lowest, lower, normal, higher, highest, pause.
# mapperfile: File used to load/save the key/event mappings from. Resetmapper only works with the defaul value.
# usescancodes: Avoid usage of symkeys, might not work on all operating systems.

fullscreen=false
fulldouble=false
fullresolution=original
windowresolution=original
output=surface
autolock=true
sensitivity=100
waitonerror=true
priority=higher,normal
mapperfile=mapper-0.74.map
usescancodes=true

[dosbox]
# language: Select another language file.
# machine: The type of machine tries to emulate.
# Possible values: hercules, cga, tandy, pcjr, ega, vgaonly, svga_s3, svga_et3000, svga_et4000, svga_paradise, vesa_nolfb, vesa_oldvbe.
# captures: Directory where things like wave, midi, screenshot get captured.
# memsize: Amount of memory DOSBox has in megabytes.
# This value is best left at its default to avoid problems with some games,
# though few games might require a higher value.
# There is generally no speed advantage when raising this value.

language=
machine=svga_s3
captures=capture
memsize=16

[render]
# frameskip: How many frames DOSBox skips before drawing one.
# aspect: Do aspect correction, if your output method doesn't support scaling this can slow things down!.
# scaler: Scaler used to enlarge/enhance low resolution modes.
# If 'forced' is appended, then the scaler will be used even if the result might not be desired.
# Possible values: none, normal2x, normal3x, advmame2x, advmame3x, advinterp2x, advinterp3x, hq2x, hq3x, 2xsai, super2xsai, supereagle, tv2x, tv3x, rgb2x, rgb3x, scan2x, scan3x.

frameskip=0
aspect=false
scaler=normal2x

[cpu]
# core: CPU Core used in emulation. auto will switch to dynamic if available and appropriate.
# Possible values: auto, dynamic, normal, simple.
# cputype: CPU Type used in emulation. auto is the fastest choice.
# Possible values: auto, 386, 386_slow, 486_slow, pentium_slow, 386_prefetch.
# cycles: Amount of instructions DOSBox tries to emulate each millisecond.
# Setting this value too high results in sound dropouts and lags.
# Cycles can be set in 3 ways:
# 'auto' tries to guess what a game needs.
# It usually works, but can fail for certain games.
# 'fixed #number' will set a fixed amount of cycles. This is what you usually need if 'auto' fails.
# (Example: fixed 4000).
# 'max' will allocate as much cycles as your computer is able to handle.
# 
# Possible values: auto, fixed, max.
# cycleup: Amount of cycles to decrease/increase with keycombo.(CTRL-F11/CTRL-F12)
# cycledown: Setting it lower than 100 will be a percentage.

core=auto
cputype=auto
cycles=auto
cycleup=10
cycledown=20

[mixer]
# nosound: Enable silent mode, sound is still emulated though.
# rate: Mixer sample rate, setting any device's rate higher than this will probably lower their sound quality.
# Possible values: 44100, 48000, 32000, 22050, 16000, 11025, 8000, 49716.
# blocksize: Mixer block size, larger blocks might help sound stuttering but sound will also be more lagged.
# Possible values: 1024, 2048, 4096, 8192, 512, 256.
# prebuffer: How many milliseconds of data to keep on top of the blocksize.

nosound=false
rate=44100
blocksize=1024
prebuffer=20

[midi]
# mpu401: Type of MPU-401 to emulate.
# Possible values: intelligent, uart, none.
# mididevice: Device that will receive the MIDI data from MPU-401.
# Possible values: default, win32, alsa, oss, coreaudio, coremidi, none.
# midiconfig: Special configuration options for the device driver. This is usually the id of the device you want to use.
# See the README/Manual for more details.

mpu401=intelligent
mididevice=default
midiconfig=

[sblaster]
# sbtype: Type of Soundblaster to emulate. gb is Gameblaster.
# Possible values: sb1, sb2, sbpro1, sbpro2, sb16, gb, none.
# sbbase: The IO address of the soundblaster.
# Possible values: 220, 240, 260, 280, 2a0, 2c0, 2e0, 300.
# irq: The IRQ number of the soundblaster.
# Possible values: 7, 5, 3, 9, 10, 11, 12.
# dma: The DMA number of the soundblaster.
# Possible values: 1, 5, 0, 3, 6, 7.
# hdma: The High DMA number of the soundblaster.
# Possible values: 1, 5, 0, 3, 6, 7.
# sbmixer: Allow the soundblaster mixer to modify the DOSBox mixer.
# oplmode: Type of OPL emulation. On 'auto' the mode is determined by sblaster type. All OPL modes are Adlib-compatible, except for 'cms'.
# Possible values: auto, cms, opl2, dualopl2, opl3, none.
# oplemu: Provider for the OPL emulation. compat might provide better quality (see oplrate as well).
# Possible values: default, compat, fast.
# oplrate: Sample rate of OPL music emulation. Use 49716 for highest quality (set the mixer rate accordingly).
# Possible values: 44100, 49716, 48000, 32000, 22050, 16000, 11025, 8000.

sbtype=sb16
sbbase=220
irq=7
dma=1
hdma=5
sbmixer=true
oplmode=auto
oplemu=default
oplrate=44100

[gus]
# gus: Enable the Gravis Ultrasound emulation.
# gusrate: Sample rate of Ultrasound emulation.
# Possible values: 44100, 48000, 32000, 22050, 16000, 11025, 8000, 49716.
# gusbase: The IO base address of the Gravis Ultrasound.
# Possible values: 240, 220, 260, 280, 2a0, 2c0, 2e0, 300.
# gusirq: The IRQ number of the Gravis Ultrasound.
# Possible values: 5, 3, 7, 9, 10, 11, 12.
# gusdma: The DMA channel of the Gravis Ultrasound.
# Possible values: 3, 0, 1, 5, 6, 7.
# ultradir: Path to Ultrasound directory. In this directory
# there should be a MIDI directory that contains
# the patch files for GUS playback. Patch sets used
# with Timidity should work fine.

gus=false
gusrate=44100
gusbase=240
gusirq=5
gusdma=3
ultradir=C:\ULTRASND

[speaker]
# pcspeaker: Enable PC-Speaker emulation.
# pcrate: Sample rate of the PC-Speaker sound generation.
# Possible values: 44100, 48000, 32000, 22050, 16000, 11025, 8000, 49716.
# tandy: Enable Tandy Sound System emulation. For 'auto', emulation is present only if machine is set to 'tandy'.
# Possible values: auto, on, off.
# tandyrate: Sample rate of the Tandy 3-Voice generation.
# Possible values: 44100, 48000, 32000, 22050, 16000, 11025, 8000, 49716.
# disney: Enable Disney Sound Source emulation. (Covox Voice Master and Speech Thing compatible).

pcspeaker=true
pcrate=44100
tandy=auto
tandyrate=44100
disney=true

[joystick]
# joysticktype: Type of joystick to emulate: auto (default), none,
# 2axis (supports two joysticks),
# 4axis (supports one joystick, first joystick used),
# 4axis_2 (supports one joystick, second joystick used),
# fcs (Thrustmaster), ch (CH Flightstick).
# none disables joystick emulation.
# auto chooses emulation depending on real joystick(s).
# (Remember to reset dosbox's mapperfile if you saved it earlier)
# Possible values: auto, 2axis, 4axis, 4axis_2, fcs, ch, none.
# timed: enable timed intervals for axis. Experiment with this option, if your joystick drifts (away).
# autofire: continuously fires as long as you keep the button pressed.
# swap34: swap the 3rd and the 4th axis. can be useful for certain joysticks.
# buttonwrap: enable button wrapping at the number of emulated buttons.

joysticktype=auto
timed=true
autofire=false
swap34=false
buttonwrap=false

[serial]
# serial1: set type of device connected to com port.
# Can be disabled, dummy, modem, nullmodem, directserial.
# Additional parameters must be in the same line in the form of
# parameter:value. Parameter for all types is irq (optional).
# for directserial: realport (required), rxdelay (optional).
# (realport:COM1 realport:ttyS0).
# for modem: listenport (optional).
# for nullmodem: server, rxdelay, txdelay, telnet, usedtr,
# transparent, port, inhsocket (all optional).
# Example: serial1=modem listenport:5000
# Possible values: dummy, disabled, modem, nullmodem, directserial.
# serial2: see serial1
# Possible values: dummy, disabled, modem, nullmodem, directserial.
# serial3: see serial1
# Possible values: dummy, disabled, modem, nullmodem, directserial.
# serial4: see serial1
# Possible values: dummy, disabled, modem, nullmodem, directserial.

serial1=dummy
serial2=dummy
serial3=disabled
serial4=disabled

[dos]
# xms: Enable XMS support.
# ems: Enable EMS support.
# umb: Enable UMB support.
# keyboardlayout: Language code of the keyboard layout (or none).

xms=true
ems=true
umb=true
keyboardlayout=auto

[ipx]
# ipx: Enable ipx over UDP/IP emulation.

ipx=false

[autoexec]
# Lines in this section will be run at startup.
# You can put your MOUNT lines here.
MOUNT C ~/DOSGAMES
c:\
m.bat

 

While everything is pretty much standard, the thing you’ll be most interested in is at the bottom under the [autoexec] entry.

I have a path called DOSGAMES in my \Users\StephenMonro\ directory. This becomes my C drive when DOSBox launches.

In there, I make sure I start out and make sure I’m actually in the C drive, and then I call a batch file.

This is the contents of the batch file:

echo off
cls
: Point & Shoot Startup File 
:
: Place this file in a directory in your PATH statement.
:
: To access Point & Shoot, type MENU
:
C:\
cd \MENU
ps

 

That batch file opens the classic “Point and Shoot Menu”, which was, in my opinion one of the easiest and best DOS menu system. I don’t know where we got it from originally, but it worked great. It’s also a little bit of a rarity on the internet too.

I have uploaded the program here which you can download.

Point and Shoot Menu download: menu.zip

Screen Shot 2019-12-12 at 12.18.05

Screen Shot 2019-12-12 at 13.22.31Screen Shot 2019-12-12 at 13.21.43Screen Shot 2019-12-12 at 13.21.00Screen Shot 2019-12-12 at 13.20.40Screen Shot 2019-12-12 at 13.20.51

Enjoy using DOSBox. 🙂

 

 

 

 

Ionic Build Scripts

Posted on Updated on

I don’t like repetitive manual work, especially if can automate or script it.

In honour of that, these are my Ionic build scripts.

Enjoy.

 

Updated: 20200312

I’ve left all the rubbish workings out in there. Feel free to clean them up as required.

To make testing easier on Android, I upload them to Dropbox/Mega and then install them quickly on the device as a deployed test.

 

deploy_android.sh
node ./node_modules/node-sass/scripts/install.js

ionic cordova platform rm android
#ionic cordova platform add android

#cordova platform add android --save

ionic cordova platform add android@7.1.4
#https://forum.ionicframework.com/t/ionic-v1-android-ionic-cordova-platform-add-android/127543
ionic cordova build android --prod --release

#keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias my-alias

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.jks platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk my-alias
cp  ~/Library/Android/sdk/build-tools/28.0.3/zipalign platforms/android/app/build/outputs/apk/release/

cd platforms/android/app/build/outputs/apk/release/
rm c4israel_int.apk
./zipalign -v 4 app-release-unsigned.apk c4israel_int.apk

#copy to dropbox
#cp c4israel_int.apk /Volumes/Creative2HD/DropBox/Dropbox/c4i/c4israel_int_1.apk

# copy to MEGA
cp c4israel_int.apk /Volumes/Creative2HD/MEGASync/C4I/c4israel_int_1.apk


cd ..
cd ..
cd ..
cd ..
cd ..
cd ..
cd ..

 

deploy_ios.sh
# BUILDING FOR IOS

##################################
#
#     MAKE SURE YOU UNPLUG ALL DEVICES!!!!!
#
##################################

# Just in case.
node ./node_modules/node-sass/scripts/install.js

ionic cordova platform remove ios
ionic cordova platform add ios
#ionic cordova platform update ios@3.9.2      #not sure which is best yet... # really old
#ionic cordova platform update ios@3.20.0    #not sure which is best yet...
#ionic cordova platform update ios@4.5.4    #not sure which is best yet...

# --buildFlag="-UseModernBuildSystem=0" is used for onsignal workaround
# https://github.com/apache/cordova-ios/issues/407

npm install -g ios-deploy
#npm install -g ios-deploy --save
#npm install ios-deploy@1.9.2 --save


#sudo gem install cocoapods
cd platforms
cd ios
pod install
#pod repo update
cd ..
cd ..

#ionic cordova build ios -- --buildFlag="-UseModernBuildSystem=0" # worked...

#ionic cordova build ios -- --buildFlag="-UseModernBuildSystem=0" # worked...
#ionic cordova build ios -- --buildFlag="-UseModernBuildSystem=0" 
ionic cordova build ios --prod --release --buildFlag="-UseModernBuildSystem=0" --verbose

# --prod
#ionic cordova build ios --prod --buildFlag="-UseModernBuildSystem=0"

cd platforms
cd ios

pod install
#pod repo update

open "APPNAME.xcworkspace/"

open /Users/PATH/ionicApps/APPNAME/platforms/ios/APPNAME.xcworkspace/


#open APPNAME.xcodeproj/
cd ..
cd ..

 

emulator.sh
ionic cordova platform remove android
ionic cordova platform add android@6.4.0 
ionic cordova build android
ionic cordova run android --no-native-run

 

run_android.sh
ionic cordova run android --device

 

 

 

OLDER VERSIONs:

deploy_android.sh

ionic cordova platform rm android
ionic cordova platform add android@6.4.0
ionic cordova build android --prod --release --debug

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.jks platforms/android/build/outputs/apk/release/android-release-unsigned.apk my-alias

cp ~/Library/Android/sdk/build-tools/27.0.3/zipalign platforms/android/build/outputs/apk/release/

cd platforms/android/build/outputs/apk/release/
rm app_name.apk
./zipalign -v 4 android-release-unsigned.apk app_name.apk

# copy to MEGA
cp app_name.apk /Volumes/Creative2HD/MEGASync/C4I/app_name_1.apk

cd ..
cd ..
cd ..
cd ..
cd ..
cd ..
cd ..

deploy_ios.sh

ionic cordova platform remove ios
ionic cordova platform add ios

cd platforms
cd ios
pod install
cd ..
cd ..

ionic cordova build ios --prod --release --buildFlag="-UseModernBuildSystem=0"

cd platforms
cd ios

pod install
pod repo update

open "APP_NAME.xcworkspace"

cd ..
cd ..

 

Directory listing

Posted on

A part of me feels that the art of command-line usage is leaving us.

If you’ve ever wanted to get a list of files from in a directory and stored in a text file, it’s really simple.

Just do this.

If you are on Windows, open the run box (Windows+R) and type cmd, then enter.

Navigate to the directory you want, or for this example, you’ll get a list of all the files in your home directory (or folder).

Type this: C:\Users\smonro>dir /r/s/b > files.txt

You will then get a long list of everything in the file named “files.txt”.

 

 

Running Catalina on a MacPro 4,1->5,1

Posted on Updated on

I’ll start by saying that I tried, succeeded, and then reverted to High Sierra.

This is not a how to guide, as there are plenty of sites dedicated to that, but this is my journey.

It started my journey with a new 2TB SSD which I cloned my current OS to. It rebooted fine, and everything was great.

I then proceeded to the latest and greatest of Catalina.

Following the instructions from dosdude, it eventually worked. But I ran in to a few minor hiccups.

The computer wouldn’t boot properly with my graphics card of gtx 770.

Once that came out it went to the login screen.

After that it went a little interesting.
Not everything worked.

There are the obvious 32 bit programs that won’t run, but is more than that.
My presonus studio192 wasn’t found, a show stopper, and I got a billion notifications to authorise things.
Filr crashed.

Dark and light mode are still screwy too.
There are no NVidia drivers available or compatible.

In the end I conclude that it’s just not worth the upgrade.

The gains do not outweigh the losses.

Instead of installing catalina and using vms for 32bit programs, I’ll go the other way and use catalina in a vm, and see how that goes, now that I have a 2TB ssd. 😊

As a side note, my GTX770 card has still been working these years without problems, it’s just lack of driver support that will continue now with future versions of the OS X.

Other than that, it all works well. Oh, and computer has had its cpu tray updated since the gfx card upgrade.

But, this is really just a good excuse to vacuum the insides.

Secret menu in an Ionic App

Posted on Updated on

I wanted a way for people to be able to reset the app, kind of for debugging purposes and while a “reset button” works, I don’t think it’s best to have it public.

So, after looking around, I thought that maybe a hold for 5 seconds with a counter would work. However, I came across a post asking a similar, but not the same idea and it triggered my mind to try something different.

Basically, you tap and hold 5 times on the ‘Header Text’ and then, your secret function will trigger.

Here’s my example:

Please note, WordPress source-code formatting is terrible.

 

About.html
<ion-header>
<ion-navbar>
<ion-title (press)="pressEvent($event)">About App {{press_text}}</ion-title>
</ion-navbar>
</ion-header>

<ion-content padding>
<h1>App Name</h1>
<p>Version: 1</p>
<p>Created with love by me </p>
</ion-content>


 

 

About.ts
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ModalController } from 'ionic-angular';
import { Storage } from '@ionic/Storage';
import { StartPopupPage } from '../start-popup/start-popup';

/**
* Generated class for the AboutPage page.
*
*/

@IonicPage()
@Component({
 selector: 'page-about',
 templateUrl: 'about.html',
})

export class AboutPage 
{
 constructor(
  publicnavCtrl: NavController,
  privatestorage: Storage,
  privatemodal: ModalController,
  publicnavParams: NavParams) 
 {}

 publicpress: number = 0;
 publicpress_text: string = "";
 pressEvent(e) 
 {
  this.press++
  this.press_text = this.press + "";
  if (this.press >= 5)
  {
   // Do something after the header has been pressed 5 times.
   // In this case, it runs the function and the resets everything
   // back to 0 ready to reset the function again if required.
   this.resetSettings();
   this.press = 0;
   this.press_text = "";
  }
 }

 ionViewDidLoad() 
 {
  console.log('ionViewDidLoad AboutPage');
 }

// Doing something after the header has been pressed 5 times.
 async resetSettings()
 {
  // clear out the data
  this.storage.set('Settings1', null);
  this.storage.set('Settings2', null);
  // Show a modal.
  // You'll need a popup html page too 
  constprofileModal = this.modal.create(StartPopupPage);
  profileModal.onDidDismiss(data => 
  {
   console.log(data);
  });
  profileModal.present();
 }
}



jVectormap the basics

Posted on Updated on

I needed to make a map with some text labels, and it was not an easy feat, as the documentation (while there) is not very clear, and the examples floating around the internet are sketchy at best as well.

Here’s my little map of Australia.

The labels are permanent, and ready to have the JS changed, to display counts, or values if required.

It’s not entirely finished, but it works.

This needs the Australia map downloaded in the same path as this code.
http://jvectormap.com/maps/countries/australia/
Here is my gist: https://gist.github.com/vrdriver/692c794ac904fa2709d5fdd827735da2

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Country Map Example</title> 
</head>
<body>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jvectormap@2.0.4/jquery-jvectormap.min.css" type="text/css">
<style>
.jvectormap-region.jvectormap-element {
text-shadow: -1px -1px 3px #fff, 1px -1px 3px #fff, -1px 1px 3px #fff, 1px 1px 3px #fff;
}
</style>
https://code.jquery.com/jquery-1.11.2.min.js
https://cdn.jsdelivr.net/npm/jvectormap@2.0.4/jquery-jvectormap.min.js
http://jquery-jvectormap-au-mill.js
</head>
<body>
div id="map1" style="width: 800px; height: 600px"> 
</div

 
var locations = [
{ latLng: [-35.27603, 149.13435], name: "ACT", text: "This is a text of one.", style: {r: 0}},
{ latLng: [-32, 147], name: "NSW", text: "This is a text of one.", style: {r: 0} },
{ latLng: [-22, 144.25], name: "QLD", text: "This is a text of one.", style: {r: 0} },
{ latLng: [-41.5, 146.030], name: "TAS", text: "This is a text of one.", style: {r: 0} },
{ latLng: [ -36.760, 144.280], name: "VIC", text: "This is a text of one.", style: {r: 0} },
{ latLng: [-26.230, 120.380], name: "WA", text: "This is a text of one.", style: {r: 0} },
{ latLng: [-22.000, 133.380], name: "NT", text: "This is a text of one.", style: {r: 0} },
{ latLng: [-29.000, 135.380], name: "SA", text: "This is a text of one.", style: {r: 0} }, 

];

$(document).ready(function () {
var map = "au_mill";
$("#map1").vectorMap({
map: 'au_mill', // map
zoomOnScroll: false, 
zoomButtons : false,
regionStyle: { // color of the map
initial: {
fill: '#B8E186' // standard colour
},
selected: {
fill: '#F4A582' // on hover
}
}, 
backgroundColor: '#383f47', // page color 
markers: locations, // the values
markerLabelStyle: { // the value formatting
initial: {
'font-family': 'Verdana',
'font-size': '40px',
'font-weight': 'bold',
cursor: 'default',
fill: 'red'
},
hover: {
cursor: 'pointer'
}
},

labels: { // this paints the labels on the map
markers: {
render: function(index){
return locations[index].name;
},
offsets: function(index){
var offset = locations[index]['offsets'] || [0, 0];
return [offset[0] - 7, offset[1] + 3];
}
}
}
});
});

</html>