Skip to content

Instantly share code, notes, and snippets.

View dawsontoth's full-sized avatar

Dawson Toth dawsontoth

View GitHub Profile
@dawsontoth
dawsontoth / populateYUVLuminanceFromRGB.java
Created November 29, 2011 16:48
How to take a Bitmap (in RGB) and grab the luminance values for YUV. Useful for passing an image to ZXing for processing.
public void handleBitmap(Bitmap image) {
int w = image.getWidth(), h = image.getHeight();
int[] rgb = new int[w * h];
byte[] yuv = new byte[w * h];
image.getPixels(rgb, 0, w, 0, 0, w, h);
populateYUVLuminanceFromRGB(rgb, yuv, w, h);
}
// Inspired in large part by:
@dawsontoth
dawsontoth / app.js
Created October 10, 2011 10:11
iOS Text Field Suggestions in Appcelerator Titanium
/**
* This demonstrates how to show suggestions on a text field using just JavaScript with Appcelerator Titanium.
*
* You will need to download four images to get this to work:
*
* 1) http://dl.dropbox.com/u/16441391/Suggest/bg.png
* 2) http://dl.dropbox.com/u/16441391/Suggest/bg@2x.png
* 3) http://dl.dropbox.com/u/16441391/Suggest/separator.png
* 4) http://dl.dropbox.com/u/16441391/Suggest/separator@2x.png
*
@dawsontoth
dawsontoth / app.js
Created October 6, 2011 23:27
This test exhibits a memory leak interaction between setting table data and the http network client.
var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var table = Ti.UI.createTableView({
bottom: 50
});
win.add(table);
var startTime = new Date().getTime(), startMemory = Ti.Platform.availableMemory;
@dawsontoth
dawsontoth / app.js
Created October 6, 2011 07:00
Deferred Execution Queue
var deferredExecutionQueue = [];
function deferExecution(func, delayMS) {
deferredExecutionQueue.push({ func: func, time: new Date().getTime() + delayMS });
}
setInterval(function() {
if (!deferredExecutionQueue.length)
return;
if (deferredExecutionQueue[0].time < new Date().getTime()) {
var deferred = deferredExecutionQueue.pop();
deferred.func();
@dawsontoth
dawsontoth / app.js
Created September 7, 2011 14:08
QR Codes in Titanium Mobile
/**
* Creates an image view using Google's QR Code generator.
* @param text The text to be encoded in the QR code
* @param size The size of the QR code; Possible Sizes: 100x100, 150x150, 200x200, 250x250, 300x300, 350x350, 400x400, 500x500
*/
function createQRCodeImageView(text, size) {
var url = 'http://chart.apis.google.com/chart?cht=qr&chs=' + size + '&chl=' + encodeURI(text) + '&chld=H|0';
var width = size.split('x')[0], height = size.split('x')[1];
if (Ti.Android) {
width += 'dp';
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
*/
package ti.modules.titanium.paypal;
import java.math.BigDecimal;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.titanium.proxy.TiViewProxy;
@dawsontoth
dawsontoth / app.js
Created June 6, 2011 20:40
Rate my app in Appcelerator Titanium Mobile
/**
* The following snippet will ask the user to rate your app the second time they launch it.
* It lets the user rate it now, "Remind Me Later" or never rate the app.
*/
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
win.addEventListener('open', checkReminderToRate);
win.add(Ti.UI.createLabel({ text: 'This is a simple app that will remind you to rate it.' }));
win.open();
function checkReminderToRate() {
@dawsontoth
dawsontoth / tiapp.xml
Created May 23, 2011 18:32
Android tiapp.xml supports-screens example
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ti:app xmlns:ti="http://ti.appcelerator.org">
...
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest android:versionCode="1" android:versionName="1.0">
<supports-screens
android:smallScreens="false"
android:normalScreens="true"
android:largeScreens="false"
android:anyDensity="false"/>
@dawsontoth
dawsontoth / app.js
Created May 10, 2011 14:05
Loading images in @appcelerator #Titanium
/* The images for this example can be downloaded from http://j.mp/loadingimagesforti */
var win = Ti.UI.createWindow({ backgroundColor: '#f00'});
var loading = Ti.UI.createImageView({
images: [
'images/loading/00.png', 'images/loading/01.png', 'images/loading/02.png',
'images/loading/03.png', 'images/loading/04.png', 'images/loading/05.png',
'images/loading/06.png', 'images/loading/08.png', 'images/loading/09.png',
'images/loading/10.png', 'images/loading/11.png'
],
width: 33, height: 33
@dawsontoth
dawsontoth / app.js
Created April 23, 2011 02:14
Simple remote on demand image caching.
var iconStore = Ti.Filesystem.applicationDataDirectory + '/CachedRemoteImages';
var dir = Ti.Filesystem.getFile(iconStore);
if (!dir.exists()) {
dir.createDirectory();
}
function cacheRemoteURL(image, imageURL) {
if (imageURL) {
var hashedSource = Ti.Utils.md5HexDigest(imageURL + '') + '.' + imageURL.split('.').pop();
var localIcon = Ti.Filesystem.getFile(iconStore, hashedSource);
if (localIcon.exists()) {