snippets.rb: Titanium Studio Snippets Ruble Customizations

Posted by Quinn Madson | Posted in | Posted on 8:54 AM

1

This here is just a space for holding my Titanium Studio customizations to extend or overwrite the provided ruble for snippets. Feel free to use them and let me know if you have any additions that help you code faster.

snippet 'inspectObject' do |s|
    s.trigger = "inspect"
    s.expansion = 
'Ti.API.info("Inspecting Object: " + ${1:myObject});
for (var thing in ${1:myObject}) {
  Ti.API.info("${1:myObject}." + thing + " = " + ${1:myObject}[thing]);
}'
  end
  
  snippet 'Ti.API.info qk' do |s|
    s.trigger = 'dump'
    s.expansion = 'Ti.API.info(\'[qk]:${1:variableName}\ = \' + ${1:variableName});'
  end
  
  snippet 'Alloy On Event' do |s|
    s.trigger = 'on'
    s.expansion = 
'${1:myObject}.on("${2:click}", function(e){
    
});'
  end
  
  snippet 'Ti.API.info' do |s|
    s.trigger = 'info'
    s.expansion = 'Ti.API.info("${0:log}");'
  end
  

Titanium & Usergrid

Posted by Quinn Madson | Posted in | Posted on 7:39 PM

0

I was trying to get a Titanium app up and running with a Usergrid backend and I kept getting the error:

[INFO] {"error":"web_application","timestamp":1344133939838,"duration":0,"exception":"javax.ws.rs.WebApplicationException"}

Turns out it was an issue with how the the Titanium HTTPClient serializes JSON data. (I thought the Ti API did this auto-magically but, maybe I'm mistaken.) If you run into the same problem, call JSON.stringify() manually on the JSON data that you are posting. Seems to do the trick. Here is an example:

var xhr = Ti.Network.createHTTPClient();
            
xhr.open("POST", "https://api.usergrid.com/YOUR_ORG-NAME/YOUR-APP-NAME/users");
xhr.setRequestHeader('Content-Type','application/json');

xhr.onload = function(){
    try {
        Ti.API.info(this.responseText);                
    } catch(e) {
        Ti.API.info(e);
    }
};
    
var data = {
    username: "raoul.duke",
    email: "raoul.duke@doomed.net",
    name: "Raoul Duke",
    password: "b4tc0untry!!"
};
                
xhr.send(JSON.stringify(data)); //this is the important bit

ColdFusion RegEx White List Example

Posted by Quinn Madson | Posted in | Posted on 9:49 AM

0

I needed to build a function that would strip out characters in event information because, otherwise it would break a JSON feed. Here is what I used:


<cffunction name="jsonSafe" access="private">
<cfargument name="str" type="string" required="true">
<cfset newStr = reReplace(arguments.str, '[^[:alnum:][:space:]$=;.?!\\/&"''`():,\[\]{}_\-]', '_','all')>
<cfreturn newStr>
</cffunction>

Preserve epoch dates in Zimbra JSON via ColdFusion DeserializeJSON function

Posted by Quinn Madson | Posted in | Posted on 2:14 PM

0

The DeserializeJSON() function in ColdFusion converts an epoch date/time in JSON from something like: 1281364965000 to: 1.281364965E+012.


To prevent this from happening, you can use something like this:

<cfset jsonData = reReplace(jsonData, '([0-9]{13})', '"\1"', 'ALL')>


Alternatively, to convert any number, 10 digits or more into a string to preserve the proper formatting, use something like this:

<cfset jsonData = reReplace(jsonData, '([0-9]{10,})', '"\1"', 'ALL')>

Fixing bootloaders when dual booting OS X and Ubuntu

Posted by Quinn Madson | Posted in | Posted on 9:03 PM

0

I ran into a problem the last time Ubuntu upgraded either the kernel or grub (not sure which); Either way, it blew away my Chameleon bootloader and replaced it with Grub. Here's how to fix it:


  • Reboot from the iATKOS v7 CD
  • Deselect all checkboxes except the one for Install Chameleon
  • Install
Now you should be able to boot into OS X but, Ubuntu will be unavailable.

  • Boot from the Ubuntu Live CD
  • Open the Terminal from Applications >> Accessories
sudo -s
mkdir /mnt/r
mount /dev/sda4 /mnt/r
mount --bind /dev /mnt/r/dev
mount --bind /proc /mnt/r/proc
chroot /mnt/r
update-grub
grub-install --force /dev/sda4

Adding CFWheels Applications as "Custom Script" elements in the CommonSpot CMS

Posted by Quinn Madson | Posted in | Posted on 1:43 PM

0

It appears that CommonSpot (version 5, at least) ignores Application.cfc files when using a custom script in the same directory. In CF Wheels, Application.cfc is used to setup the entire framework.

Here is what I did to get it working:

  • Put your CF Wheels application in the customcf/ subdirectory
  • Rename Application.cfc to application.cfc (This is done to prevent the application from being initialized twice if accessed outside the CMS.)
  • Edit the index.cfm at the root of the application directory:
<!--- Manually instantiate the application.cfc --->
<cfset server.railo = structNew()>
<cfset server.railo.version = "fake version">

<!--- If this is the first time the application has run, call the onApplicationStart method --->
<cfset app = CreateObject("component","application")>

<!--- Call the onRequestStart method and pass the current page as a parameter --->
<cfif not structKeyExists(application, "wheels")>
<cfset app.onApplicationStart()>
</cfif>

<!--- Call the onRequestStart method and pass the current page as a parameter --->
<cfset app.onRequestStart(cgi.script_name)>


<!--- This is the only original line in the file --->
<cfinclude template="wheels/index.cfm">

Gnome Screensaver Missing Lock Screen Prompt in Ubuntu Lucid 10.04

Posted by Quinn Madson | Posted in | Posted on 12:43 PM

4

For some reason, the unlock dialog box for Gnome Screensaver suddenly stopped appearing. Screensaver works fine but, move the mouse and no unlock prompt, just back to the screen saver. The only work-around was to press Ctrl-Alt-F1, login, and type the command:

killall gnome-screensaver
Although, after a while this gets annoying so, I looked for a better long term solution. Here it is:
sudo chmod a+r /etc/pam.d/*
That's it. I assume that the permissions may have been messed up during an update. Posted here for posterity.