Appcelerator’s Titanium: Inherit from Ti objects.

So, in Titanium, you are unable to extend the native classes. You’re also unable to add methods to native objects or re-assign methods (so, if you wanted to, say, modify an object so that the “hide” function triggers an event, tough sh*t). There is, however, a decent way of getting around this inadequacy (read: violant violation of the ECMA standards, but who are we to judge).

var Klass = function(){
    this.toView = function(){ return Klass.prototype }
}
Klass.prototype = Ti.UI.createView({
    /*... the rest of the parameters here (as usual) ... */
});
var view = new Klass();

Then, if you want to add the object to a window, you need to remember to call win.add(view.toView()), but it means you can now carry around the data object with *all* of its data.

Posted in Frameworks | Tagged , , , , | Leave a comment

jQuery without a DOM

If you’re ever using jQuery without a proper DOM, you may want to use this. It provides enough of a DOM-like syntax to suffice. (Literally, this is every function which jQuery calls on the DOM directly (assuming no selectors). I really wish they abstracted the AJAX functionality so that it would be trivial to use it without the whole framework)

var emptyFunction = function(){ return ""; },
      gebi = function(elm){
				return {
					nodeType: '',
					innerHTML: '',
					insertBefore: emptyFunction,
					removeChild: emptyFunction,
					appendChild: emptyFunction,
					getAttribute: emptyFunction,
					setAttribute: emptyFunction,
					getElementsByTagName: function(){
						return {};
					},
					style: {}
				};
		}
window = {
	document:{
		getElementById: gebi,
		createComment: emptyFunction,
		createElement: gebi,
		createDocumentFragment: gebi,
		documentElement: ntx.extend( {
			createElement: gebi,
			childNodes:(function(){
				var g = gebi();
				return [g]
			})()
		}, gebi() )
	},
	location: {
		href:""
	},
	navigator:{
		userAgent: ""
	}
};
Posted in Uncategorized | Tagged , , | Leave a comment

Big-O is important, damn it!

A fried of mine recently complained that they sent his package east to send it west, and if they only sent it west it would be faster.

My response:
The process is local post office -> central hub -> local post office. It means that all routes are 2 long, but it means you only need to support routes to and from that hub. At most, that is 2 * number of post office.

On the other hand, if they were to support “every post office to every post office” that would be (number of post offices)!.

So, if there are, say, 1000 post offices, the hub plan means that there are only 2000 routes at most. If each office were to send to each other office, that would be 10002, or 1,000,000…

Posted in Uncategorized | Leave a comment

Ubuntu location of Empathy logs

I’m writing this post because the rest of the interwebs seems to be hopelessly out of date. Hopefully some search engine will find my site and lead people here.

Anyway, the location of the log files for Empathy in Ubuntu 10x-11.x is:
./.local/share/TpLogger/logs/

This is because while the default bundled IM client is Empathy, it is used as a part of Telepathy (hence the “TpLogger” part). It is annoying as anything to figure this out especially since (as of this date), the official FAQ does not come up as part of the top 5 search results on Google.

Posted in Products | Tagged , , , | Leave a comment

Don’t change my UI, that is bad UX

Two percent of the people think; three percent of the people think they think; and ninety-five percent of the people would rather die than think
— attributed to both Thomas Alva Edison and George Bernard Shaw[1]

Continue reading

  1. [1] Note: Edison quote is purported to be 5% thinkers, 10% think-thinkers, and 85% non-thinkers
Posted in Business | Tagged , , | 1 Comment

Inconsistency: A most dangerous game

One of the absolutely worst things you can do in the entire world is being 99% consistent.

While this is especially apt in code, it is a general truth in life. Small inconsistencies are deadly. Don’t believe me? Two characters difference has cost the U.S. government $125 million dollars.
Continue reading

Posted in Business, Code theory, Communication, Inter-personal Relations, UI | Tagged , , , , | Leave a comment

Mapping of HTML5 tags to their legal attributes

You know what would be great? If someone were to create a map of all of the HTML5 attributes to their legal properties. Oh, wait, I did.
Continue reading

Posted in PyFram | Tagged , | Leave a comment

PyFram: Create your HTML Tags!

I created an easy way to create smart HTML tags. You can see the source here.

Basically, it’ll let you create a tag object which restricts what properties you can assign it. This means that you’ll get an error if you try to assign a property which does not exist.

Check it out:

>>> tag = view.tags.Tag('a',href='foo',valid=['href','title'])
>>> tag.contents.append(view.tags.Tag('img',src='angry.gif',valid=['src','title']))
>>> tag
<a href="foo" ><img src="angry.gif" /></a>
>>> tag.src = "timbuktu"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "view/tags.py", line 28, in __setattr__
    elif hasattr(self,"attrs"):
  File "view/tags.py", line 35, in trigger_keyerror
 
KeyError: '"src" is not a valid attribute for a a tag.
>>> tag.href = "http://google.com"
>>> tag
<a href="http://google.com" ><img src="angry.gif" /></a>

Then there is the UnstrictTag, which will allow all attributes to pass:

>>> tag = view.tags.UnstrictTag('a',href='foo',valid=['href','title'])
{'href': 'foo'}
>>> tag.contents.append(view.tags.Tag('img',src='angry.gif',valid=['src','title']))
{'src': 'angry.gif'}
>>> tag
<a href="foo" ><img src="angry.gif" /></a>
>>> tag.foo = 1
>>> tag
<a href="foo" foo="1" ><img src="angry.gif" /></a>

I admit it does need an official test framework built, and the comments are missing. That’s for next week.

Posted in PyFram, PyFram tutorial | Tagged , , , | Leave a comment

My browser does too much.

Requisite XKCD referenceWe’ve entered the age of the browser. Even without such things as Eyeos, we’ve come to the point where you can literally do anything without leaving Chrome, Firefox, or even Internet Explorer. Need email? We got that. What about RSS? Do you have a document you want to edit?

Heck, you can even get an SSH plugin for Firefox. Continue reading

Posted in Chrome, Products | Tagged , , | 3 Comments

McCarthy’s Lisp

So, I got no sleep last night due to a client project. Profitable, but exhausting. Not wanting to have a Monday go by without a post, however, I thought I would comment on McCarthy’s original definition of Lisp, which is sited here.

There are few times I have felt the privilege of reading code which is awe-inspiringly brilliant. This is one of those times. It is remarkably simple. Take the “and” function, for example:

(defun and. (x y)
  (cond (x (cond (y 't) ('t '())))
        ('t '())))

Translated:

  1. Define and
  2. cond is basically a switch, it looks for the first “car” which is true. So (cond (x ...) means if x then …
  3. Repeat cond with y
  4. 't is a catch-all so that the cond will definitely hit something. It is the “default” in the C-style switch. In both case ('t '()) means, “if nothing before this is true, return false.

You never get to see a definition of the logic behind “and”, “and” just works, however in this case, it is clearly a beautiful and clear construct built out of the language itself. Truly, this is a thing of beauty.

Posted in Uncategorized | 5 Comments