Skip to content

Instantly share code, notes, and snippets.

View hansemannn's full-sized avatar
🗺️

Hans Knöchel hansemannn

🗺️
View GitHub Profile
@hansemannn
hansemannn / ti.speech.example.js
Created April 8, 2019 05:29
Realtime Speech Recognition in Titanium
var TiSpeech = require('ti.speech');
TiSpeech.initialize('en_US'); // locale is optional
var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var currentValue = '';
func handleData() {
let jsonData: [String: Any]
let text = String(describing: self.data)
// JSON serialisation can fail, use do-catch (like try-catch in
// to cope with possible failuresJava/C)
do {
// JSON data is copied into a key/value dictionary
jsonData = try JSONSerialization.jsonObject(with: self.data, options: [.mutableContainers]) as! [String: Any]
} catch {
return debugPrint("Error occurred: \(error.localizedDescription)")
@hansemannn
hansemannn / cropping-manager.js
Created March 14, 2019 11:04
An example of cropping images cross-platform on Titanium.
/**
* Crops a given image URL to an optional aspect ratop (square by default).
*
* Example:
*
* const image = await ImageCroppingManager.crop(myImageURL);
*
*/
export default class ImageCroppingManager {
@hansemannn
hansemannn / gist:60f22d6df3cfb73ba317630da7093ea4
Created February 10, 2019 14:11
Test socket.io connection
# Either use "polling" or "websocket" for the "transport" option
curl --include \
--no-buffer \
--header "Connection: Upgrade" \
--header "Upgrade: websocket" \
--header "Host: example.com:80" \
--header "Origin: http://google.com:80" \
--header "Sec-WebSocket-Key: jJSjsoSlsjSh37==" \
--header "Sec-WebSocket-Version: 13" \
@hansemannn
hansemannn / app.js
Created January 28, 2019 12:11
An example of using a cross-platform rounded shadow view in Appcelerator Titanium.
import RoundedShadowView from 'rounded-shadow-view';
const view = new RoundedShadowView({ backgroundColor: 'red' }).instance;
// ... add to your window
@hansemannn
hansemannn / app-utils.js
Last active October 15, 2019 20:16
Using ES7+ async/await in Appcelerator Titanium
export function showOptions (args) {
const title = args.title;
const message = args.message;
const options = args.options;
const destructive = args.destructive !== undefined ? args.destructive : -1;
let cancel = -1;
return new Promise((resolve, reject) => {
if (OS_IOS) {
options.push('Cancel');
@hansemannn
hansemannn / cache.js
Created December 12, 2018 10:19
Caching remote images in Titanium (asynchronously)
export default class Utils {
static loadCachedImageFromURL(url, cb) {
let filename;
try {
filename = url.substring(url.lastIndexOf('/') + 1);
} catch (err) {
cb(null);
}
@hansemannn
hansemannn / liveview-from-cli.md
Last active December 9, 2022 17:12
Use LiveView from the Titanium CLI (without Studio)
  1. Install LiveView globally:
npm i -g liveview
  1. Change the ~/.titanium/config.json to include the CLI hook (under paths -> hook):
{
	"user": { ... },
	"app": { ... },
	"cli": { ... },
@hansemannn
hansemannn / .bash_profile
Created August 20, 2018 09:51
Titanium Shortcuts for Bash
alias tomodules="cd ~/Documents/appcelerator_modules/"
alias toapps="cd ~/Documents/Apps/"
alias dev="cd ~/Documents/dev/"
alias totimob="cd ~/Documents/titanium_mobile/"
alias toappc="appc new --import --no-services"
alias iossim="ti build -p ios"
alias lint="clang-format -i -style=file "
alias iosdevice="appc run -p ios -T device -V \">YOUR_NAME (YOUR_TEAM_ID)\" -P \"YOUR_PROVISIONING_PROFILE\""
alias iosprod="appc run -p ios -T dist-appstore"
alias androidsim="ti build -p android"
@hansemannn
hansemannn / titanium-encrypted-database-json1.js
Created August 8, 2018 14:07
Use the SQLite JSON1-extension in Appcelerator Titanium.
const dbobj = require('appcelerator.encrypteddatabase');
var win = Ti.UI.createWindow({ backgroundColor: 'white' });
var btn = Ti.UI.createButton({ title: 'Trigger' });
btn.addEventListener('click', accessDatabase);
win.add(btn);
win.open();