Saturday, June 10, 2017

AF's EN (this is linkjacking)

Arcade Fire - the music band - has come out with a new single, "Everything Now". It is a catchy track, which is likely to get more play.

However, it isn't famous, as in the sense of indexing. There is no direct jump to the new single's page on an authoritative source like Wikipedia, or in other words, the Wikipedia page doesn't show up in its search results on the big G. The search engine's irrelevant weighing of the time dimension, and looking for backlinks, has resulted in a recent emergent fad be buried in inaccessibility.

What's worse, is the results push in a 2005 single "Everything Now!" in the most literal result which will confuse the seeker.

Even the phrase "arcade fire everything now" leads to a smorgasbord of live entities, or to be seen as insufficient knowledge sources, but not to the song's Wikipedia page - yes, there is one.



Tuesday, April 19, 2016

Hacking cars for a ransom

Sometime earlier this year (2016), Eugene Kaspersky commented on the state of "connectedness" of the newer automobiles - on how this symbiosis of several digital components (talking over a CAN bus) is going to invite/foster hacking attacks. An accompanying demo disabled a Cherokee this way, to show what hackers can do to the cars of today.

In the meantime, I had another scenario playing in head. Automated driving is in its infancy (Google cars is demo-ing), but one thing we understand is that it will involve a lot of connected micro-devices inside the car talking over the cloud to a massive central controller (server). Where there's a technology, there exists a way to reverse engineer it. What if we have hackers taking over a fleet of Google Cars and asking for a ransom?

"We have taken control one thousand cars, and hence over a thousand lives. The cars are our slaves now. One command, and they would drive off the road. Somebody gets hurt real bad. The cost to mitigate this situation (ie have us relinquish control) is 100 billion dollars!"
To some extent this is the pulp fiction generator in my head at work. But sometimes reality comes overlapping.

Monday, April 11, 2016

ISRO Bhuvan: go eat it

The ISRO has a very cool portal called running, Bhuvan. I just got to find out. It was a digression from an urgent forest fire situation at hand, that I ended up at the Uttarakhand Forests Dept website, thereby led onto a Forest Fire Info page, which had a banner, saying "View Forest Fire Alert for Uttarakhand State on Bhuvan - collaborative effort between ITGC and NRSC").


The Uttarakhand forest portal homepage [on Bhvan] describes it as
Bhuvan Uttarakhnad Forest portal provides a platform for hosting of all GIS database of Uttarakhnad Forest. It is a satellite based technology to watch over the State's forests boundaries, gives detailed location and satellite images of any area or project under various forestry schemes in the State. 
It can keep an eye over activities like; Plantation, Forest Fire, Protected Areas, Asset Management, Eco-tourism, Forest rest Houses location, land Use cover, Wastelands, Map downloading facility etc. can be visualised. User can add layer over the map and take print out for planning purposes. 

While my original purpose of reporting a LIVE fire incident didn't find an end, I got busy checking out the portal, which is a lotta map data through a easy, working, live-loading form (forms are the horror of Indian govt portals, but this worked).

Though the implementation and the utility of the tool is great, live data part is lacking. I found no forest fire incidents around Nainital in the month (so far). It was the increasing incidents of these fires that got me there, to find that none go reported. I figured they do have a satellite system to monitor the forest cover and report any developing fires, but that doesn't seem likely. No such data exists. The data says, "all clean". It also reminded of other incidents of forged data, as part of some institutional laxity, and a creeping fear that we'll have an under-powered tool in the future is taking shape.


Tuesday, July 14, 2015

PHP cURL Guzzle mbstring apache extension - crap of the day

My day's woes were something like so.. Working on the OAuth driver was throwing some stuff I hadn't seen before. It had a short fix.

Short fix: PHPIniDir directive in Apache, configured alongside PHP extension, should point to the php.ini file, not the php.ini directory!

Platform: Windows 7 / Apache 2.4 / PHP 5.6.11 Thread-safe / Laravel 5.1 / MySQL 5.6

I had set my path variables right, and phpinfo() was showing that it could pick php.ini from its directory just fine. Apache sometimes has a separate php.ini that comes with XAMPP-type installations, but that wasn't the case. I went through all documentation of guzzle and checking out the Middleware and its Promises and dd-ing in my libraries... which was basically pointless.

Finally it was established that cURL wasn't loading because it wasn't being picked up by PHP. I started getting a mbstring error now; while the extension was enabled. Disabling other extensions didn't affect the output. That's when I tried checking all ways php.ini could be popped in, and wallah, editing the PHPIniDir in httpd.conf, worked.

[2015-07-14 15:33:10] local.INFO: Authenticating user with provider: twitter
[2015-07-14 15:33:10] local.INFO: redirecting to twitter
[2015-07-14 15:33:10] local.ERROR: exception 'Guzzle\Common\Exception\RuntimeException' with message 'The PHP cURL extension must be installed to use Guzzle.' in G:\passionstreet\framework\laravel\vendor\guzzle\guzzle\src\Guzzle\Http\Client.php:72
Stack trace:
#0 G:\passionstreet\framework\laravel\vendor\league\oauth1-client\src\Client\Server\Server.php(307): Guzzle\Http\Client->__construct()


And before that a Guzzle Client 400 Error

[2015-07-14 15:13:25] local.INFO: Authenticating user with provider: facebook
[2015-07-14 15:13:25] local.INFO: retrieving social login user, with provider facebook
[2015-07-14 15:13:26] local.ERROR: exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: 400' in G:\passionstreet\framework\laravel\vendor\guzzlehttp\guzzle\src\Middleware.php:69
Stack trace:
#0 G:\passionstreet\framework\laravel\vendor\guzzlehttp\promises\src\Promise.php(198): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#1 G:\passionstreet\framework\laravel\vendor\guzzlehttp\promises\src\Promise.php(152): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)

And before that a Guzzle 403

[2015-07-14 14:41:54] local.INFO: retrieving social login user, with provider google
[2015-07-14 14:41:56] local.ERROR: exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: 403' in G:\passionstreet\framework\laravel\vendor\guzzlehttp\guzzle\src\Middleware.php:69
Stack trace:
#0 G:\passionstreet\framework\laravel\vendor\guzzlehttp\promises\src\Promise.php(199): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#1 G:\passionstreet\framework\laravel\vendor\guzzlehttp\promises\src\Promise.php(152): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)

And before that doing something weird redirecting with a provider 'Rahul'

[2015-07-14 14:41:39] local.INFO: Authenticating user with provider: rahul
[2015-07-14 14:41:39] local.INFO: redirecting to rahul
[2015-07-14 14:41:39] local.ERROR: exception 'InvalidArgumentException' with message 'Driver [rahul] not supported.' in G:\passionstreet\framework\laravel\vendor\laravel\framework\src\Illuminate\Support\Manager.php:90
Stack trace:
#0 G:\passionstreet\framework\laravel\vendor\laravel\framework\src\Illuminate\Support\Manager.php(63): Illuminate\Support\Manager->createDriver('rahul')

Then back to the cURL

Then I got back to the first error to start my day, that in one of the views
[2015-07-14 13:10:06] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Method Illuminate\View\View::__toString() must not throw an exception' in G:\passionstreet\framework\laravel\storage\framework\views\f404135fc8f0d4d388888d2a371ebe1d:0
Stack trace:
#0 {main}
[2015-07-14 13:23:54] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Method Illuminate\View\View::__toString() must not throw an exception' in
 



Sunday, April 19, 2015

Crazy KitKat upgrading Gionee M2

The past weekend I wasted a lot of time, over what seemed an innocuous software update after getting fixed a broken USB/power port on the Gionee M2. 
The original issue that put this phone out of service was a bad USB port. It had been a dead phone for the longest time. Thanks to Delhi's Nehru Place, that what Mumbai's repairmen couldn't do, was done, which is fixing that minor issue. Once the a new jack was soldered onboard, then phone sprang back to life. It was great to know that the battery wasn't screwed up, since that is one component impossible to find as its not a standard "Chinaphone" feature to include 4200mAh brick batteries.

Riding on this success, I then thought of doing a software fix. The Gionee M2 came a JellyBean 4.2.0 phone, and apparently Gionee had been not-so-useless by coming out with a KitKat 4.4.2 upgrade. The instructions were clear and straightforward enough on Gionee (India's) website.

Here's the phone specs.
Hardware : MT6582
Model : M2
Build number : M2
Build date UTC : 20140719-110128
Android  v : 4.2.2
Baseband v: MOLY.WR8.W1315.MD.WG.MP.V11, 2013/11/27 10:34
Kernel v : 3.4.5 (android@android-6) (gcc version 4.6.x-google 20120106 (prerelease) (GCC) ) #1 SMP  Sat Jul 19 18:59:30 CST 2014

It seemed there would be no apparent harm. But being me, keeping out of the harm's way is impossible. Hence, I initially screwed up on the image I'd downloaded for my phone.
Thanks to girlfriend, it was a 4G phone and not 8G as she had remembered. It was her phone, initially, so she'd better remembered. I chose a wrong scatter file (8G), and hesitantly started the firmware upgrade process. The KK upgrade would finally have the BLE working on this phone, which I had been wanting for energy-efficient BT chips found in newer 'lifestyle' devices.

It was a relief to see everything progressing smoothly. The image file started loading one by one, and reached 99%.. that's when the error struck. I was devastated.

After a lot of 'not-getting-it', and confusion between the ADB/Preloader/VCOM drivers, and technique to boot in preloader (with the Power+Volume Up buttons), the 4G KitKat finally got the phone working. Oh, in the meantime, it was considered a brick. Thankfully, it was an incident of 'soft brick'. I am trusting enough that 9 in 10 'bricked' phones would probably be bricked this way, and can be rescued.



Mine, though was unleashing a new story of rescue. On booting the phone to KitKat, it gave an error about "Invalid IMEI". Since I'd forgot to put the SIM card inside, I tried doing that, but it still said the same. The SIM was detected and carrier was displayed on the screen, bu the phone would show no signal or no connection for the carrier (Airtel, Vodafone, tried on both, in this case). 



The phone, it turned out, was more than devastated. It lost its two children, to put it metaphorically. Being a dual-sim phone, it had two SIM slots. That means, two IMEI numbers as well. Both those IMEI numbers had been erased during the fiasco. Some technology. Some neck!
It showed 'null' for both the IMEIs just like the screenie below. 


 I retried doing the same stuff but to no good.


Learnt that it happens to phones. Didn't know IMEI could be accidentally erased. Then learnt that it's easy to reset and change IMEI on MTK chipsets, the types (MT65xx) that the Gionee M2 has. If it is accidental, it should be well within legality as well, I presume, as long as it's being done. I could make a good business out of it.

Anyways that depends on whether I manage to fix this phone or not.
  Lately, I've been traveling a lot.

I took this phone on travel with me and my laptop, as we had to zip through Delhi then zip back and slingshoot ahead to the Airport come back again and slingshoot to Noida. There are ways to reset the IMEI even without rooting, but that involves modifying image files and reapplying scatter files, which is tedious, and besides the phone is outta warranty. 
This Gionee M2 was successfully rooted using this link on XDA-developers . 


Then I installed MTK Engineering Mode, an app that opens you to backdoor stuff. There, you enter the commands to reapply the IMEIs. The instructions are all over. This experience left me a bit disillusioned with MTK chipsets, enamored by the hacker/modification community, and also scared about the ease with which changing IMEI is possible - thought they were the last resort to tracking stolen phones, but it is SO EASY to trust that you have some last-resort security on your device, which turns to be an illusion.

Considerations aside, this Gionee M2 is a working phone now. Its battery is seriously impressive, and I hope that future battery technology will make it reasonable to expect 3 days of active use of our mobile devices with a slow draining battery that will not die so soon as in these days.


Wednesday, September 3, 2014

babies

me: my contract agreement on this planet has no condition for either of those
though i might make babies to research random motion

D: or making your wife looks fat

me: you mean fatter than default setting for women?

D: I must admin there are plenty of uses of babies.  so dont be shy

me: having baby = shared admin = annoying
you will always be arguing about which package to install on the baby 
then one day baby will revoke your admin rights and then its back to base 0

Update with Select using Joins

Using a technique called Path Enumeration, we can arrange hierarchical menus, typically seen on shopping websites. Here's a query to quickly generate the path tree for menu items. Here, it is shown to build paths for children to parent nodes 4 and 6.

UPDATE ADJLIST A INNER JOIN
(
SELECT A1.id, CONCAT(A2.path,A1.id,'/') AS NEWPATH FROM ADJLIST A1
INNER JOIN (SELECT id, path FROM ADJLIST WHERE id IN (4,6)) A2
ON A1.parent_id = A2.id
) A3
ON A.id = A3.id
SET A.path=A3.newpath


See: 
http://stackoverflow.com/a/25328460/1330710
http://stackoverflow.com/questions/1262786/mysql-update-query-based-on-select-query
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat
http://stackoverflow.com/questions/14815668/add-to-existing-value-in-mysql-column-using-concat-function
http://www.slideshare.net/billkarwin/models-for-hierarchical-data

Friday, July 4, 2014

maker fair revolution

https://events.webmaker.org/
http://www.whitehouse.gov/the-press-office/2014/06/18/fact-sheet-president-obama-host-first-ever-white-house-maker-faire

"America has always been a nation of tinkerers, inventors, and entrepreneurs. In recent years, a growing number of Americans have gained access to technologies such as 3D printers, laser cutters, easy-to-use design software, and desktop machine tools, with even more being created by the day. These tools are enabling more Americans to design and build almost anything.

New technologies for rapid prototyping – from laser cutters to CNC routers to 3D printers – have dramatically lowered the cost of developing a prototype and starting a business in manufacturing. The ability to rapidly and affordably test, tinker, monitor and customize places a premium on locating production close to American markets and opens new doors to entrepreneurship and innovation in manufacturing. The power of these emerging technologies creates the opportunity for Makers to launch new businesses, create jobs and build the industries of the future."


Ignorance isn't bliss.

Thursday, July 4, 2013

Sharding (refresher)

Scaling is an eventuality with any growing business. It comes in many forms. For the online business, database scaling is the first big technical hurdle.

The new generation of webapps demand a near-persistent connection with the database, doing multiple read/writes over a single session; the more LIVE data you throw, the longer "they" stick with you. Couple that with the "viral" aspect, and you know that soon as your app gets noticed, the database demands are gonna surge. Databases are the foremost when it comes to contingency planning.

DBs are moving to the cloud, much like our individual data. Clouds, for all the good they offer, aren't strong when it comes to sustained I/O ops.
A 0.9GB database takes 1 min to load.
A 30GB database takes 10 days to load...

Another aspect is that the newer-gen NoSQL DBs are single threaded. Which means the CPU is only handling a single op at a time. In case of a lock, it could take a long time to resolve. Everyone (communicating with the DB) takes the brunt.

Horizontal partitioning is a design principle whereby rows of a database table are held separately, rather than splitting by columns (as for normalization). Each partition forms part of a shard, which may in turn be located on a separate database server or physical location. The advantage is the number of rows in each table is reduced (this reduces index size, thus improves search performance). If the sharding is based on some real-world aspect of the data (e.g. European customers vs. American customers) then it may be possible to infer the appropriate shard membership easily and automatically, and query only the relevant shard.

Another place sharding can be used is to reduce contention on data entities. It is especially important when building scalable systems to watch out for those piece of data that are written often because they are always the bottleneck. A good solution is to shard off that specific entity and write to multile copies, then read the total. An example of this "sharded counter wrt GAE: http://code.google.com/appengine/articles/sharding_counters.html

If you have queries to a DBMS for which the locality is quite restricted (say, a user only fires selects with a 'where username = $my_username') it makes sense to put all the usernames starting with A-N on one server and all from M-Z on the other. By this you get near linear scaling for some queries.
Resources
[1] http://en.wikipedia.org/wiki/Shard_(database_architecture)
[2] http://stackoverflow.com/questions/992988/what-is-sharding-and-why-is-it-important
[3] http://www.slideshare.net/rightscale/rightscale-webinar-scaling-your-database-in-the-cloud
[4] https://vimeo.com/32541189

Wednesday, August 15, 2012

Fight Spam, but how?

Been inundated with spammy referrers in the last few months. I'm sure I'm not the only one. I know what it is - backlink spam [1, 2], which means those dirty ad networks generating fake clicks to blogs, to be displayed in the backlink/trackback list, which in turn adds to their PageRank on Google. So wily are these spammers that instead of using their direct URL they are now masking it through t.co and then further wrapping them into StumbleUpon or Facebook or [insert any respectable sounding name] redirects. The blog owners will both be confused and curious - "Gee, who could be linking to me from http://www.filmhill.com/redirect.php?url=http%3A%2F%2Ft.co%2FUEmjqui3"

Sadly, even though I have turned my backlinks off through Blogger settings, these guys won't stop. The TLDs are too diverse to block out. But one common pattern observed among these links are that all use t.co to masquerade. Probably could insert a JS snippet to block any incomings of this nature. But I don't see how that solves anything - Google Analytics will still register the referral since the page is going to be accessed and its going to show up anyways.

Wednesday, March 14, 2012

97 things

I'm reading a book called "97 things a programmer should know". After the first few pages, it seemed like common sense, so I put it down. It didn't solve my crisis of the stalemate I find myself in. Not only that, it was generally uninteresting.

What I do want to read, however, would be "97 things a programmer wouldn't know", which could introduce some new paradigms to the art of software programming that an average programmer won't be familiar to - after years of being in the industry, I have seen people decaying and falling out-of-date; or "97 things a programmer should forget", which could be a treatise against the prevalent bad practices that every new guy falls into.

Next I pit hopes on "Beautiful Architecture", which I understand as an effort towards creating a "programmauteur", my ideal.

Thursday, September 15, 2011

State-of-the-art Vertical Scroll Sites

http://benthebodyguard.com/ http://2011.beercamp.com/ http://sf-langstrasse.hvo.ch/page/ http://activatedrinks.com/

Thursday, August 4, 2011

Official Google Blog: When patents attack Android

Official Google Blog: When patents attack Android: "I have worked in the tech sector for over two decades. Microsoft and Apple have always been at each other’s throats, so when they get into ..."

Friday, March 4, 2011

Gender Connection

THE MALE PLUG


THE FEMALE RECEPTACLE



Learn More

Friday, January 28, 2011

Notifications in Chrome

Some of us would be familiar, and piqued, by the recent suggestion in our Gmail windows: "Click here to enable mail notifications in Chrome". Choose to, and whichever tab you might be browsing on, any new mail or chat message is reported in a tiny corner bottom right of the screen. This nifty addition surprised me enough to find out more about the concept, and its other possible applications.

Notifications to the desktop are nothing new, but notifications on the browser are.
The OSX folks have had something called Growl notifications in place, which requires installation, then could be accessed through the windows.fluid object built into Safari on Mac.

Google, with their support for Web Notifications, and their W3C recommendation in general, have tried standardizing this concept.
Here's a small working example for the same:

PS: Try it, in baby steps, on Jash. FUN!
<script type="text/javascript">
(function() {
var notificationStatus;

setupNotifications = function() {
if(window.webkitNotifications) {
if(window.webkitNotifications.checkPermission() == 0 ) { //permission granted
notificationStatus = 'Permission granted';
} else if(window.webkitNotifications.checkPermission() == 1 ) { //permission unknown
//notificationStatus = 'Permission not granted yet';
notificationStatus = "Unknown, click to <a href='javascript:window.webkitNotifications.requestPermission(setupNotifications);'>enable web notifications</a>.";
window.webkitNotifications.requestPermission(setupNotifications);
} else { //permission denied
notificationStatus = 'Permission denied';
}
} else alert('Not supported');

if(!!document.getElementById("notificationStatus"))
document.getElementById("notificationStatus").innerHTML = notificationStatus;
}

notifyMe = function() {
//permission already granted
if(window.webkitNotifications.checkPermission() == 0 ) {
var popup = window.webkitNotifications.createNotification(
"myicon.ico",
"You nailed it",
"My good sir, by delving into this notification thingy you open yourself to plenty of bobfoolery"
);
//ondisplay is one of the three events for the notification API
// ondisplay, onerror, oncancel
popup.ondisplay = function() {
setTimeout(function () {popup.cancel();}, 6000);
//we keep a timeout for the notification, since they don't have one by default
};
popup.show(); //this displays the notification
}
}
window.onload = setupNotifications;
})();
</script>
A simplified concept, a small API, and user security considerations - the spec has its bases covered. Presently these notifications only work on the Chrome browser across Windows and Linux.
For the old crowd, things were ridiculous, with the programmers having to resort to annoying and invasive hacks like window.alert. This new feature would give online tools like e-mail clients, calendering software, task managers, monitoring systems, etc. an elegant and consistent way to notify users.

However, not everybody is gaga over it. After some toying around, even I am a bit skeptical about the specs and the architecture: The notifications take a while to associate with their tab. They aren't a welcome experience to deal with when your friends start firing messages in your gmail chat window. Moreover, with the proliferation of these (among Tier 1 sites, to merely begin with) we can only anticipate an avalanche of these, since the recommendation suggests no way to restrict or control the notifications.

Thursday, January 13, 2011

Lightweight gmail

See my gmail inbox above - that's all there is. Pretty light.
How it got so is an inspired tale, having its origins from Matt Cutts' blog (a popular netizen who leads the Google Webspam team). This helps me twofold
* Lighter page
* More relevant inbox

It's the label-and-archive strategy.

Step I> Fix on a scheme

First thing to work out is whether
- I want my email and chats as different entities, or together. Personally, I'd like to keep them separately.
- I want my emails sifted chronologically, or by mail providers, or by family/friends/office. Let's call them sort-order aka "distinctions". For me, chronological distinction is convenient. I'd also like to keep my stupid chain mail forwards away from more important mails.
- Which emails might be overlapping distinctions. For example, I had several joke-of-the-day kinda forwards, that I wouldn't give a damn about; but alongside were other forwards that were important conversations.

Step II> Get your search filters right

This one is a custom affair. I decided to have my emails and chats for past couple of years filtered in separate boxes, while all else (2008 and earlier) went into a single huge box.
Here's a sample of the way my search filters went
for email: before:2011/01/01 after:2009/12/31 -is:chat
for chats: before:2011/01/01 after:2009/12/31 is:chat
for joke-a-day forwards: fw has:attachment -is:important -label:professional

Step III> Label and Archive

- Once I had the result from mail search, I did "Select All" by clicking on the dropdown arrow next to the select checkbox above mails, and then again clicking on "Select all * conversations" link that now appears.
- Then I applied an appropriate label, say "2010 emails", and finally
- Pressed the "Archive" button.

Back in Inbox
This one is easy. If you want your mail to appear back in your inbox, just click the appropriate label (say, "2010 emails"), and in case you want to see some/all in your Inbox, just select those (or all), and click Move To > Inbox

Unlabel My Email
Even easier.
- See those labels listed on the page (which generally lie on bottom left)? If you click on their dropdown, you'll find a "Remove Label" link.
- Or you could goto Label > Manage Labels, and Show/Hide/Delete them through there
- Or just select all those emails you don't want under that label, click on Labels in the bar above, untick the labels you don't want, then click Apply.

Wednesday, January 12, 2011

Fix your PHP!

The exclamation should be taken to its intended effect. A critical PHP vulnerability was identified in the PHP engine (PHP 5.3.4) - which allows an easy, creative, orchestrated DDoS attack. This affects both Windows and Linux. VERY SERIOUS.
"Due to the way the PHP runtime handles internal conversion of floating point numbers, it is possible for a remote attacker to bring down a web application simply by adding a specific parameter to a query string in their web browser.
This vulnerability is present on all versions of PHP including PHP 4.x and 5.x, on all Intel-based 32-bit PHP builds."
I'm merely being the information inspector here - source being a Zend newsletter.

Go Party at Wikipedia's 10


Jan 15th will now trump other days, like your cat's birthday. Wikipedia's 10 anniversary is not a small affair - as they themselves have made evident through their Anniversary page. Celebrations across the planet.
Mumbai (VJTI, Matunga)
New Delhi (IIT, Hauz Khas)
Lucknow (Fun Republic Mall, Gomti Nagar)

Saturday, July 24, 2010

Your Helvetica is not Helvetica

The most popular font on the web, Arial - in wide adoption owing to Microsoft Windows - has a shady history behind it. [As Mr. Mackey would say "Arial is bad, mkay?"]

Helvetica is the original chic; it stands an icon of swiss design and elegance. A font 10 years into India's freedom. It was chosen as one of the base fonts for Adobe's Postscript, and became the standard for much of print media. Trust me, the font is legendary!

All this time I had assumed I had Helvetica on my system. Firing up MSWord07 confirmed that, Helvetica was listed among my installed fonts. At the same time I also decided to check out the differences between either fonts (Helvetica vs Arial), to immediately condition myself to abhor the Helvetica clone. But on blowing up the fonts, I found that they were the exact same - no graceful curls as in the real Helvetica, or the poise in the letters R, G, C...

So finally the followings were done
- Visiting my fonts folder
- Firing up Adobe Photoshop to see the list of available fonts
- Using the fonts side-by-side on an HTML page
And it was confirmed I DID NOT have Helvetica. I have spent my lifetime not appropriately knowing or using Helvetica!
This fact also brought forth that Helvetica is still a licensed font, and it costs INR 1450. Even if people don't buy into the uber-coolness of the font, they would still get it for the association and conformity/exclusivity the font brings.

Why did MS Word 2007 show that Helvetica was installed? This might be because certain printers have this font embedded into their hardware; hence if your system lacks this font, you can still have it in print.

Two fonts walk into the bar, and the barman says, "sorry lads, we don't serve your type".

Sunday, July 12, 2009

Unloading external content doesn't work right

Flash conveniently dictates the use of Loader class to load external files, including SWFs. But what the developers ignored was how the SWF unloading takes place...in theory it doesn't. Besides being an irritation, this can also be exploited as a security flaw.

Symptoms
Loading, then unloading a SWF - with an embedded clip or some sound playing - still keeps that sound going regardless of NO VISIBLE instance of the clip anywhere on the stage or in the memory. In addition (if you check the memory consumption), repeated loads and unloads increase the memory consumption in direction relation to the size of the files being loaded.

Diagnosis
What happens here is memory mismanagement on part of the AVM2 (Actionscript Virtual Machine 2, that was built for Actionscript 3). Dig deeper, and its the garbage handling mechanism at fault. Much of this has to do with what the unload function does. Here's how the story goes:
  1. You write ActionScript 3 code to load/unload the SWF. (Yes, this bug is AS3-specific)
  2. Flash lets loaded child SWFs communicate with the parent container. Hence the events that the SWF monitors are linked to the main timeline. ENTER_FRAME and TIMER events are the lethal events here. [keep that in mind]
  3. Unload() simply removes a reference to the loaded content, and leaves the rest for the garbage collector.
  4. But the garbage collector works on the principle that a resource will be removed only when it has no references. Because the SWF is still linked to the main timeline, it stays in the memory. The SWF - technically - keeps playing.
  5. As a result of the SWF still out there, any sounds that the SWF had been playing continue to play; alongside, your movie file size bloats up because the garbage stays there in the garbage box (and stinks it up).

With nothing but the Flash IDE and its accompanying manual, one can get stuck for hours.

Prognosis (or the future course of events that you take)
There is no straight solution to this. Nothing can be done to fix the issue. Moreover, nothing on part of the parent swf can help (with a trivial exception).
  • Calling SoundMixer.stopAll() method in the parent SWF: This will stop all sounds playing. This is rarely helpful, since there will be other sounds playing as well.

  • Remove select event listeners: Open the FLA file of the one that's being loaded, and remove any ENTER_FRAME or Timer event listeners. These are the ones that communicate with the parent movie.

  • Clean Up on Event.UNLOAD: When unload() is called on an SWF loaded through the Loader component, an 'unload' event is fired. Use this to clean up your child SWF...remove/delete all (dynamic) variables, movie clips, event listeners and timers. Stop any sounds. Stop the advance of the main timeline. Stop any external content from loading (Loader, URLLoader, Socket). This is your best bet.



  • Some enlightening documentation of this bug can be found here, here.