Noodlecode parody of spaghetti code

Malaysia weekly fuel prices

RON 95 RON 97 Diesel Euro 5
27/4/2017 2.21 (-0.06) 2.49 (-0.05) 2.14 (-0.07) 2.24 (-0.07)
20/4/2017 2.27 (+0.03) 2.54 (+0.02) 2.21 (+0.05) 2.31 (+0.05)
13/4/2017 2.24 (+0.08) 2.52 (+0.09) 2.16 (+0.08) 2.26 (+0.10)
6/4/2017 2.16 (+0.03) 2.43 (+0.02) 2.08 (-0.03) 2.16 (-0.05)
30/3/2017 2.13 (-0.17) 2.41 (-0.19) 2.11 (-0.09) 2.21 (-0.09)

Previous months:

RON 95 RON 97 Diesel Euro 5
March 2017 2.30 (0.00) 2.60 (0.00) 2.20 (+0.05) 2.30 (+0.05)
February 2017 2.30 (+0.20) 2.60 (+0.20) 2.15 (+0.10) 2.25 (+0.10)
January 2017 2.10 (+0.20) 2.40 (+0.15) 2.05 (+0.20) 2.15 (+0.20)
December 2016 1.90 (-0.05) 2.25 (-0.05) 1.85 (-0.05) 1.95 (-0.05)
November 2016 1.95 (+0.15) 2.30 (+0.15) 1.90 (+0.15) 2.00 (+0.15)
October 2016 1.80 (+0.10) 2.15 (+0.10) 1.75 (+0.05) 1.85 (+0.05)
September 2016 1.70 (-0.05) 2.05 (-0.05) 1.70 (0.00) 1.80 (0.00)

Creating [object] in a different context than the calling function.

Creating [object] in a different context than the calling function.

This warning occured when a JS callback function is passed to Objective-C as KrollCallback and then executed on non-JS thread.

KrollCallback *callback = [args objectForKey@"callback"];

[OneSignal initWithLaunchOptions:[TiApp app].launchOptions appId:appId handleNotificationAction:^(OSNotificationResult *result) {
    [callback call:@[] thisObject:nil];
}];

Problem with this warning is, if the JS callback create Ti.Network.HTTPClient instance, then that instance is null.

function callback() {
    var http = Ti.Network.createHTTPClient();
    http.open('GET', getUrl()); // JS error! http is null
    http.send();
}

To fix, get krollContext instance of current module/proxy and execute callback inside invokeBlockOnThread

// For TiModule / TiProxy descendants
KrollContext *context = [self.executionContext krollContext];

// For TiUIView descendants
KrollContext *context = [self.proxy.executionContext krollContext];

// invoke
[context invokeBlockOnThread:^{
    [callback call:@[] thisObject:nil];
}];

Download youtube video as audio file

Note: using Mac OS X 10.10.5

Install Homebrew

Install youtube-dl

$ brew install youtube-dl

Install ffmpeg

$ brew install ffmpeg

To download & save as audio file

$ youtube-dl -x --audio-format mp3 --prefer-ffmpeg [URL]

Activity & fragment lifecycle events

1. Start new activity

Activity, onCreate
Fragment, onAttach
Fragment, onAttach
Fragment, onCreateView
Fragment, onActivityCreated
Fragment, onStart
Activity, onStart
Activity, onResume
Fragment, onResume

2. Close activity (tap back button)

Fragment, onPause
Activity, onPause
Activity, onStop
Fragment, onDestroyView
Fragment, onDestroy
Fragment, onDetach
Activity, onDestroy

3. Hide activity (tap home button)

Fragment, onPause
Activity, onPause
Activity, onStop

4. Resume activity (from home screen)

Activity, onRestart
Fragment, onStart
Activity, onStart
Activity, onResume
Fragment, onResume

5. Go to other activity

Fragment, onPause
Activity, onPause
Activity, onStop

6. Resume from other activity (return back)

Activity, onRestart
Fragment, onStart
Activity, onStart
Activity, onResume
Fragment, onResume

Compress / Decompress files using XZ

Compress

xz -zk myfile.txt

will produce myfile.txt.xz in the same directory

Decompress

xz -dkc myfile.txt.xz > myfile.txt

Titanium Studio mark occurences

Preferences > Titanium Studio > Editors > JavaScript, check “Mark occurrences with background color”.

Source: https://developer.appcelerator.com/question/143513/highlight-variable-useage-in-a-file

Ti.Network.registerForPushNotifications no response

SDK: 3.5.1.GA, CLI: 4.0.1

Calling Ti.Network.registerForPushNotifications() has no response, whether success, error or callback, basically no response at all. Turned out that the build script can’t detect the method and add USE_TI_NETWORKREGISTERFORPUSHNOTIFICATIONS to defines.h during app compilation.

I created with a plugin that append the macro definition to *.pch file, here it is:

Create plugin folder:

cd $PROJECT_DIR
mkdir -p plugins/ti.pushnotifsymbol/hooks
touch plugins/ti.pushnotifsymbol/package.json
touch plugins/ti.pushnotifsymbol/hooks/pushnotifsymbol.js

pushnotifsymbol.js:

exports.id = 'ti.pushnotifsymbol';
exports.cliVersion = '>=3.2';
exports.init = function (logger, config, cli) {
    var path = require('path');
    var fs = require('fs');
    var util = require('util');
    var os = require('os');
    var pchFile;
    var triggered = false;
    cli.on('build.pre.compile', function(builder, next) {
        pchFile = path.join(builder.buildDir, builder.tiapp.name + '_Prefix.pch');
        next();
    });
    cli.on('build.ios.copyResource', function(builder, next) {
        if (!triggered) {
            triggered = true;
            if (fs.existsSync(pchFile)) {
                fs.appendFileSync(pchFile, os.EOL + '#define USE_TI_NETWORKREGISTERFORPUSHNOTIFICATIONS');
            }
        }
        next();
    });
};

Add <plugin>ti.pushnotifsymbol</plugin> to <plugins> section of your project tiapp.xml

Titanium iOS builder script

Location: TITANIUM_SDK/mobilesdk/osx/3.5.1.GA/iphone/cli/commands/_build.js
(TITANIUM_SDK is commonly at ~/Library/Application Support/Titanium)

1. Cannot change CFBundleVersion

  • CFBundleVersion is the build version number, available to developer and beta testers.
  • CFBundleShortVersionString is the release version number, what the users see on App Store
  • CFBundleVersion is automatically assign to value of <version> in tiapp.xml, but for beta testing purposes, need to change this value everytime we upload new build to iTunes Connect TestFlight
  • To fix this, modify iOS builder script in iOSBuilder.prototype.createInfoPlist() function, around line 2063
plist.CFBundleVersion = String(this.tiapp['build-version'] || this.tiapp.version);

2. If your Titanium SDK location is different from default (custom SDK path), the script doesn’t look up that folder when searching for modules

  • My Titanium SDK is located at ~/Applications/opt/Titanium, when running the ti build -p ios command, it doesn’t lookup for modules there
  • If my project included ti.cloud module, the build script will fail, cannot find the specified module
  • To fix this, in iOSBuilder.prototype.validate() function
// around line 1321, add:
customSDKPaths = config.get('paths.sdks'),

// around line 1331, add:
Array.isArray(customSDKPaths) && customSDKPaths.forEach(addSearchPath);

Git remotes

LIst out all remotes:

git remote -v

Show info about a remote:

git remote show origin

Titanium Android keystore

Location: TI_SDK/mobilesdk/osx/3.5.1.GA/android/dev_keystore
Alias: tidev
Password: tirocks

Reference: http://developer.appcelerator.com/question/162225/what-is-default-password-used-for-titanium-android-keystore-

« Older posts

Copyright © 2017 Noodlecode