Skip to content

Instantly share code, notes, and snippets.

View adampax's full-sized avatar
🏠
Working from home

Adam Paxton adampax

🏠
Working from home
View GitHub Profile
@kwhinnery
kwhinnery / app.js
Created January 2, 2012 18:03
Mixin implementation for Titanium 1.8 - supports shallow or deep copy
var mixin = require('mixin');
var o1 = {
foo:{
something:'osauhduisdfb',
bar:'baz'
}
};
var o2 = {
@furf
furf / _.deep.js
Created July 30, 2012 17:06
underscore.js mixin for plucking nested properties
_.mixin({
// Get/set the value of a nested property
deep: function (obj, key, value) {
var keys = key.replace(/\[(["']?)([^\1]+?)\1?\]/g, '.$2').replace(/^\./, '').split('.'),
root,
i = 0,
n = keys.length;
@stephenfeather
stephenfeather / parse.js
Last active May 28, 2024 15:03
Quick library for using the Parse REST API within Appcelerator's Titanium. Building it out as I need different pieces of the API.
// Copyright Stephen Feather and other contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
@NoobsArePeople2
NoobsArePeople2 / gist:5121597
Last active September 5, 2024 04:27
Configure media keys on a non-Apple keyboard to control Spotify via AppleScript and USB Overdrive on OSX.

Requirements

  1. USB Overdrive
  2. A non-Apple keyboard with media keys (or keys you want to make "media" keys). For reference, I'm using a Microsoft Sidewinder X4

Set Up

  1. Plug in your keyboard and install USB Overdrive.
  2. Open USB Overdrive. Click into the Settings tab.
  3. Click the dropdown and select "Any Keyboard, Any Application"
@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.

@tsteur
tsteur / alloy.jmk
Created July 15, 2013 22:12
Simple build configuration file for Titanium Mobile Alloy. It extends the destroy method of each controller to automatically remove all event listeners which are defined in the view (XML).
function readContentFromFile(file)
{
return require('fs').readFileSync(file).toString();
}
function writeContentToFile(file, content)
{
require('fs').writeFileSync(file, content);
}
@ricardoalcocer
ricardoalcocer / alloy.jmk
Created July 30, 2013 18:38
Alloy JMK file to transfer Android settings from the tiapp.xml to the Alloy assets folder. The use-case for this is that you can know at runtime which Holo Theme the app is using (if any) and based on this, make UI/UX or graphic decisions like setting colors, images, etc. Next on this idea is an app.tss with pre-defined color for Holo Dark and H…
task("pre:compile",function(event,logger){
var fs = require('fs'),
xml2js = require('xml2js');
var parser = new xml2js.Parser();
parser.addListener('end', function(result) {
var androidSettings=JSON.stringify(result["ti:app"].android[0]);
fs.writeFile(event.dir.project + '/app/assets/holosettings.json', androidSettings, function (err) {
if (err) throw err;
@ricardoalcocer
ricardoalcocer / windowopen.js
Last active December 20, 2015 13:59
Dynamically changing menu options on Android
// this goes on the open event of your tabgroup
// what happens here is that you create a single function for the menu options of all tabs
// then upon focus of a tab, you call invalidateOptionsMenu, which triggers the onCreateOptionsMenu event
//
if (OS_ANDROID){
var tabGroup=Alloy.Globals.tabgroup;
var activity = tabGroup.getActivity();
if (activity.actionBar) {
@ricardoalcocer
ricardoalcocer / themes.md
Last active October 15, 2021 08:10
Changing Android ActionBar Theme and Android Style

Customizing the overall App Style

This guide has been updated for Titanium SDK 3.3.0 which uses AppCompat to bring the ActionBar to Android 2.3.x

Android has a build-in theming system. Using this feature you can easily change the base color Android uses for its controls across your app, allowing you to provide better branding and personalization, while maintaining Android's UI and UX.

Android built-in themes are:

  • Holo (Mostly Black and Cyan)
  • Holo Light (Mostly White and Gray)
@jfromaniello
jfromaniello / gist:8418116
Last active September 19, 2023 23:38
Example of authenticating websockets with JWTs.
var WebSocketServer = require('ws').Server;
var wss = new WebSocketServer({port: 8080});
var jwt = require('jsonwebtoken');
/**
The way I like to work with 'ws' is to convert everything to an event if possible.
**/
function toEvent (message) {
try {