Posts

Updating firmware for the Android smartphone

My Android phone is severely old, and obviously not supported by the manufacturer (it's not Nexus). The battery life was too short, and I had concerns that it's not because the phone is too old and battery just died, but because of a number of bloatware installed by the manufacturer (like Facebook applications which can't be deleted). So I decide to update the ROM and use something decent without any junk inside. To my surprise, my concerns were correct, and after upgrade the phone lives much longer on the battery. Let me give simple steps how to do it (because mostly tutorials are too complex for beginners): Root the phone. I recommend Superoneclick Install CWM Recovery , make partitions for FS and SWAP, wipe all the data and cache. Install custom ROM (like Cyanogenmod ). You don't need to copy files to SD card directly, you can use 'mount USB option' from CWM Recovery menu and copy zip-files from PC using the cable. Install gapps if you need Google ac...

Single-quoted attributes are valid HTML

The subj is a small surprise for me, but it's true - single quotes for attributes are valid HTML: HTML 5:  http://dev.w3.org/html5/markup/syntax.html#attr-value-single-quoted <input type='checkbox' /> HTML 4:  http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2 By default, SGML requires that all attribute values be delimited using either double quotation marks (ASCII decimal 34) or single quotation marks (ASCII decimal 39). XHTML(XML):  http://www.w3.org/TR/REC-xml/#sec-common-syn AttValue ::= '"' ([^<&"] | Reference)* '"'  | "'" ([^<&'] | Reference)* "'"

Why jQuery.isFunction?

Usually you can test whether JS object is function by using this test: (typeof fn === 'function') However, this doesn't always work (IE8): typeof alert => 'object' typeof document.createElement('input').getAttribute => 'object' Before jQuery 1.4 internally they used the same check, but now they've fixed it. So to be sure that passed object is a function which can be called, just use $.isFunction method: $.isFunction(function() {}) => true $.isFunction(alert) => true $.isFunction(document.createElement('input').getAttribute) => true

split function behavior differences

A little note from my debugging experience. Split function works differently and I would say unexpectedly for empty string in different programming languages, and it can cause difficult to find bugs (especially if you use a lot of languages simultaneously). I've created a table with the popular programming languages: Language Split without parameters Split with parameter Python ''.split()=[] ''.split(',')=[''] Ruby ''.split()=[] ''.split(',')=[] JavaScript ''.split()=[''] ''.split(',')=[''] PHP N/A explode(',', '')=array(0=>'') Java N/A "".split(",")={""} C# "".Split()={""} "".Split(',')={""} As you can see sometimes it returns empty array, but sometimes an array with the one empty element. So please be careful with the split operation :)

Python templating comparison by memory consumption

Another comparison between: standard formatting; more advanced standard string.template ; Mako Genshi Jinja2 Here the code I used for measuring: #!/usr/bin/env python import sys NAME = 'name' def render1(): template = "<p>Hello %s!</p>" return template % NAME def render2(): from string import Template template = Template("<p>Hello ${name}!</p>") return template.substitute(dict(name=NAME)) def render3(): from mako.template import Template template = Template("<p>Hello ${name}!</p>") return template.render(name=NAME) def render4(): from genshi.template import MarkupTemplate tmpl = MarkupTemplate('<p>Hello $name!</p>') stream = tmpl.generate(name=NAME) return stream.render('xhtml') def render5(): from jinja2 import Template template = Template('<p>Hello ...

Web application framework comparison by memory consumption

Memory consumption is slightly specific to my area of software development now, but I did some research recently and maybe these results can be useful for others. Of course, I know that precious comparison is very difficult to carry out, but actually I needed only overall picture. And let me admit that results are pretty interesting and even frustrated (at least for me). As a basis I took so-starving project, and measured initial RSS (Resident Set Size) of the each process (local development webservers). Platform: x86_64 Linux (latest Ubuntu with all updates). As a reference, here is the RSS of the interpreters in interactive console mode: Interpreter Version RSS (kB) stackless python 2.6.4 3916 ruby (via irb) 1.8.7 4664 python 2.7.1 5624 php 5.3.5 6924 v8 (via node.js shell) 2.5.9.9 8796 One more reference - the most simplest WSGI app ( example  in the Python documentation). It's RSS: 7336 Kb , so I assume it's almost impossible to consume ...

Packing executables

One of the biggest challenges with embedding platforms is the limitation related to file sizes. Here is the hint how to make executables smaller - strip them and pack them: strip is a tool from GNU binutils , it discards symbols. Usually the platform toolchain has one. upx is an excellent executable packer. Can be downloaded as binary or sources from the UPX sf.net site . As an example, I'll show you the packing of Python 2.6.7 binary: $ ls -s --block-size=KB python 6493kB python $ strip -s python $ ls -s --block-size=KB python 1696kB python $ upx --best python                        Ultimate Packer for eXecutables                           Copyright (C) 1996 - 2010 UPX 3.05        Markus Oberhumer, Laszlo Molnar & John Reiser   Apr 27th 2010         File size         Rati...