Skip to content

Instantly share code, notes, and snippets.

View FokkeZB's full-sized avatar
*️⃣
Zappin'

Fokke Zandbergen FokkeZB

*️⃣
Zappin'
View GitHub Profile
@FokkeZB
FokkeZB / README.md
Created April 19, 2013 08:59
Setting default unit of measurement.

To make sure your lay-outs look pretty much the same on all devices, including the thousands of different Android resolutions and densities, it's always best to use the 'dp' unit. However, typing '10dp' instead of 10 is quite a pain. A pain you can easily take away by changing the default unit in your tiapp.xml.

@FokkeZB
FokkeZB / app.js
Last active December 16, 2015 12:28
CommonJS module to spin a view in Titanium
var v = Ti.UI.createView();
var s = new require('spinner').Spinner(
v, // View to spin
30 // Degrees to spin per millisecond
); // Auto-starts
// Stop
s.stop();
@FokkeZB
FokkeZB / SHARING.md
Last active December 16, 2015 15:49
Sharing lib for Titanium
@FokkeZB
FokkeZB / RATING.md
Last active December 16, 2015 16:49
Rate-my-app CommonJS module for Titanium
@FokkeZB
FokkeZB / VERSION.md
Created April 29, 2013 09:52
CommonJS version comparison library for Titanium

The Titanium docs tell you Ti.version is a number, but it's not... it's a string, that can include stuff like beta, GA etc.

@FokkeZB
FokkeZB / UPDATE.md
Last active August 23, 2017 16:26
Update lib for Titanium

I like easy drop-in CommonJS libraries that need minimal configuration to perform common tasks.

This CommonJS library checks with Apple every X days to see if there's a new version available. If so, it asks the user if he/she would like to update and then opens the app in the App Store.

At minimum, the library requires no configuration at all and just a single line of code.

Look at advanced.js for all available options and methods.

Also check out my rating library:

@FokkeZB
FokkeZB / ALLOY.md
Last active February 13, 2019 20:01
Alloy constants and helpers for non-Alloy Titanium projects.

If you want to your CommonJS modules to work in both Alloy and plain Titanium projects, you might need a way to detect if you're in Alloy. For instance, if you're in Alloy you would get Underscore from the alloy-module, while in plain Titanium you would require Underscore directly.

Well, you can:

var _ = require((typeof ENV_TEST === 'boolean') ? 'alloy' : 'underscore')._;

The above works by utilizing Alloy's optimization process. In this process, constants like ENV_TEST will be either TRUE or FALSE. The actual expressions in wich they are used will then be evaluated. If FALSE the code block will be removed. In plain Titanium projects the constants are undefined and this typeof ENV_TEST will be undefined, so the code block will be executed.

@FokkeZB
FokkeZB / CROP.md
Created May 2, 2013 09:43
Image (cropping) CommonJS lib for Titanium

Often I need to display a user-provided picture in an ImageView in such a way that the whole ImageView is filled with as much of the picture possible.

This is how I do it:

var image = require('image');

Ti.Media.showCamera({
        mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
 success: function (e) {
@FokkeZB
FokkeZB / LAZY.md
Last active December 16, 2015 21:39
Lazy exporting expensive properties

If you have a CommonJS module that exposes properties that are expensive to create (e.g. other CommonJS modules or some external resource), you can load them lazy using Object.defineProperty().

@FokkeZB
FokkeZB / ALERT.md
Created May 3, 2013 11:06
Replacement for Titanium's alert()

I guess just like me you like to do alert('My message'); instead of:

Ti.UI.createAlertDialog({
        message: 'My message'
}).show();

But I'd even more like to do alert('My message', 'My title', myCallback); instead of: