New Joke Site

Anyone that knows me, knows that I have a problem with hoarding domains. So bad that I’d probably be a good candidate for the A&E show, Hoarders. At the height of my ‘addiction’ I hit 76 domains. Sure, not that bad in reality. But of those 76 domains I had 2-3 active websites going. The rest, well, the rest were what makes the internet suck. Adsense domains. Great for me, but sucky to click on a search result. Only to be taken to another page with even more search results.

I’ve since had my addiction under control a bit. Narrowing it down to 60 domains. On top of that I’m making a small effort to actually put some content with the domains (what a concept!). The first site was the easiest to setup. Taking only a day or two…including an Android app!

The cool thing, at least I think it’s cool. Is that there is  a rating system associated with the site. So every time someone ‘votes’ a joke either ‘Stupid’ or ‘Funny’ some nifty calculations happen. I say nifty because there’s some magic happening from people trying to screw things up. The hope is, that over time, only the really truly funny jokes will survive. Give it a go!

Click to Visit! Joke Roullete - Even misspelled it's funny!

Click to Visit! Joke Roullete - Even misspelled it's funny!

Yep, it’s misspelled. Next time I’ll use a spellchecker before buying rushing to buy a domain :)  Anyway, kinda neat and simple project I did for fun. 1 down 57 to go…

Appcelerator Titanium vsdoc for Visual Studio (update)

Just a quick post to give you some of the updates I’ve made to the vsdoc since the last post.

New File: Ti-vsdoc (master – 5/14/11)

Changes:

Added some VS intellisense hints — All titanium modules will now show up as namespaces. Titanium objects will now show up as classes.

New vsdoc now returns the titanium type. For example Ti.UI.createWindow() actually returns a Ti.UI.Window so you’ll get intellisense for the Ti window instead of a plain object.

A few fixes for invalid datatypes in the tdocs.

‘Aliased’ Titanium with Ti

Ti.UI.currentWindow returns null — due to the way VS intellisense works and when Ti.UI.Window is defined the type can’t be returned. Kinda screws things up.

That’s all. I haven’t created a pull request to get these fixes in the master. Hopefully I’ll get to that sometime next week.

Submitted a pull request.

Code merged into main project

 

Adding Content URI support to your Titanium App (Android)

A while back I finally got a chance to dive into making an app with Appcelerator’s Titanium framework. Part of that task was trying to figure out how to add content uri support to the app. What that means is making your application aware of a certain content scheme. For example, a url. This of course could be expanded out to supporting your own content uri such as somethingawesome://do-something, mime types and few other methods.

I searched for quite awhile on this and found bits and pieces that helped in getting this accomplished but nothing from start to end. I tried a bunch of ways to get this done but nothing worked like I wanted. So here’s my attempt to make it easier for someone else.

For this example I’ll keep it simple by listening to a url of jeremymelton.com

First things first, open your tiapp.xml file.

In the android section of the file you’ll add an ‘activities’ section:

<android xmlns:android="http://schemas.android.com/apk/res/android">
   <activities>
     <activity url="app.js">
        <intent-filter>
          <action android:name="android.intent.action.VIEW"/>
          <category android:name="android.intent.category.DEFAULT"/>
          <category android:name="android.intent.category.BROWSABLE"/>
          <data android:host="jeremymelton.com" android:scheme="http"/>
        </intent-filter>
     </activity>
   </activities>
</android>

A few quick points here. Notice the url=”app.js” in the activity element. This could be any .js file you want to launch when the activity is started. For this example I wanted to launch the main app and parse the query string of the url.

The second point is the data element. This is letting Android know that we can handle a http link for jeremymelton.com using our activity(app.js). As mentioned earlier, there’s more you can do with the data element. I’ll leave that up to your investigation.

At this point when you click on a link to jeremymelton.com you will get an intent chooser popup asking if you want to use the browser or your app to open the link. If you choose your app…it will open your app.

Now, you’ll probably want to actually DO something when this happens. A very simple example we’ll grab the data of the intent, parse a querystring, then load a blog post by the post id in the url querystring.

In app.js (or whatever file you used for the activity url):

var activity = Ti.Android.currentActivity;
var intentData = activity.getIntent().getData();
getPost(intentData ? queryString(intentData, 'postID') : null);

To test this you’d click a link; jeremymelton.com?postID=1. You’d be prompted if you’d like to open this in the browser or your app. Click your app. The data from the getIntent().getData() call will contain http://jeremymelton.com?postID=1.

I grabbed a querystring function to parse out the querystring and voilà. We now have the postID of the link and can load a specific blog post.

And that’s it. Pretty simple to implement but potentially very powerful for your app.

 

The querystring function (original):

this.queryString = function (url, key)
{
    var results = new RegExp('[\\?&]' + key + '=([^&#]*)').exec(url);
    if (!results) return 0;
    return results[1] || null;
};

Validating Taiwan Personal IDs

I Recently had to write some simple client side validation for validating Taiwan (Republic of China) Personal/Government IDs. Pretty simple, really. But, I couldn’t find anything with a few simple searches. So, I reverted back to what documentation I had – a document…in Chinese. So I fired up google translate and whipped up some javascript.

Grab the uncompressed (1.36KB) or minified (0.664 KB)

Usage:

ValidTaiwanPersonalID('F121899987')  ?  'Valid'  :  'Invalid'

Nothing spectacular — hopefully it will save someone else some trouble.

Appcelerator Titanium vsdoc for Visual Studio

Click here to get the updated file, otherwise read on :)

If you just want the vsdoc, here you go: Titanium-vsdoc.js

This weekend, I finally broke down and [re]learned Python. Got acquainted with Git (which I am really starting to dig). And for the trifecta, signed up for github. Why? Well, I had a sudden burst of inspiration while trying to write a walk through on how to generate a vsdoc using my C# app. About half way through I realized this was just too much work; not to mention really lame. So I buckled down for a few hours and got something that is good enough to throw out to the world. This time…it’s open source (David Caruso stole my keyboard…I swear!).

Changes from v1:

Code to generate the vsdoc is released
Includes Titanium objects
Added module events
Types now return the correct type. (ie. Function returns an array, VS will treat it as an array)

Unfortunately, Visual Studio doesn’t support comments for objects. Which, of course, a large portion of the vsdoc is made up of objects.

Anyway, if you’re interested you can view my forked project here: JeremyMelton/titanium_mobile

This has now been merged into the titanium mobile master: https://github.com/appcelerator/titanium_mobile

How to use the vsdoc

  1. Download the vsdoc
  2. Add the Titanium.vsdoc.js to your project
  3. In the [js] file you want to use Titanium add the following line to the first line of the file.
    ///<reference path=”~/path/to/Titanium.vsdoc.js”/>
  4. Use it!

 

Any feedback is welcome.

Next Page »