Skip to content

Instantly share code, notes, and snippets.

View dawsontoth's full-sized avatar

Dawson Toth dawsontoth

View GitHub Profile
@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()) {
@dawsontoth
dawsontoth / LowLevelMouseHooks.cs
Created February 11, 2011 20:42
Adds some low level mouse hooks to a WPF app, turning any left click into a double click.
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Dawson.Accessibility
{
/// <summary>
/// Interaction logic for MouseHooker.xaml
/// Derived from http://blogs.msdn.com/b/toub/archive/2006/05/03/589468.aspx
/// </summary>
@dawsontoth
dawsontoth / restartTerminal.sh
Created December 6, 2012 15:30
osascript to focus terminal, send ctrl+c, then up, then enter.
tell application "System Events"
tell application "Terminal" to activate
keystroke "c" using {control down}
key code 126
key code 52
end tell
@dawsontoth
dawsontoth / generateSplash.js
Last active December 2, 2020 22:55
Start with a 1000x1000 PSD with an icon in the middle. In Photoshop select File > Scripts > Browse... generateSplash.js. Saves out to ../Resources/iphone and android.
/*
Define our various sizes.
*/
var AndroidSizes = {
'android/images/res-ldpi/splash.9.png': 240,
'android/images/res-mdpi/splash.9.png': 360,
'android/images/res-hdpi/splash.9.png': 480,
'android/images/res-xhdpi/splash.9.png': 720,
'android/images/res-xxhdpi/splash.9.png': 960,
'android/images/res-xxxhdpi/splash.9.png': 1440
@dawsontoth
dawsontoth / app.js
Created February 4, 2011 23:21
CSS Injection on External Websites using Appcelerator Titanium
// create our web view
var win = Ti.UI.createWindow({ backgroundColor: "#fff" });
var web = Ti.UI.createWebView({ url: "http://chicago.craigslist.org/" });
// inject our css when the web view finishes loading (because we need to inject into the head element)
web.addEventListener('load', function () {
// first, specify the CSS file that we should load
var cssFileName = 'styles.css';
// read in the contents
var cssFromFile = Ti.Filesystem.getFile(cssFileName);
@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 / 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 December 8, 2011 21:06
StoreKit/Example/app.js
/*
Learn the basics of Storekit with this example.
Before we can do anything in our app, we need to set up iTunesConnect! This process can be a little painful, but I will
guide you through it so you don't have to figure it out on your own.
Follow these steps:
1) Log in to your Apple Developer account at https://itunesconnect.apple.com/
2) Click "Manage Your Applications".
@dawsontoth
dawsontoth / app.js
Created March 4, 2011 00:44
Customize the look of the tab bar in iOS Appcelerator Titanium
Ti.include('overrideTabs.js');
/*
This is a typical new project -- a tab group with three tabs.
*/
var tabGroup = Ti.UI.createTabGroup();
/*
Tab 1.
@dawsontoth
dawsontoth / xmlToJS.js
Created March 22, 2012 17:25
XML to JS Module
/**
* XMLToJS Module 0.1
*
* To use:
* var XMLToJS = require('xmlToJS');
* var jsObject = XMLToJS.convert(xml);
*
* This will take XMl like the following:
*
<atom:feed xmlns:atom="http://www.w3.org/2005/Atom">