Archive for the ‘geeky’ Category

What do a philologist and a lollipop have in common?

Wednesday, February 24th, 2010

Question: What do a philologist and a lollipop have in common?

Answer: LOL (if you don’t get it, you will LOL when you see it below)

The generalized problem statement

Given a few strings:

  ewf3hardyharharoiew
  p90weuhardyharhar
  hardyharharoie78wjf
  ahardyharhar787834

Determine the longest substring that they all have in common:

 p90weuhardyharhar
       |||||||||||
      ahardyharhar787834
       |||||||||||
   ewf3hardyharharoiew
       |||||||||||
     d1hardyharharoie78wjf

Which in this example above, is ‘hardyharhar’. The question is, how do you code this?

The solution

Today on Hug-An-Algorithm day, we’re giving the hat-tip to an algorithm called longest common substring (LCS).

The solution can be implemented using a generalized suffix tree, or by dynamic programming
(Wikipedia).

Specifically, I’ll walk you through a Python implementation—but focusing on the approach behind it, so that you can implement this in any language you want. I found a few LCS implementations on Wikibooks.org, which is where I got this simple Python implementation from (and adapted it slightly for this demo).


Technical nitty-gritty details warning! (If you’re interested in how this may be useful to you, skip to real-world applications section after it):

Select full screen + high quality plz:

Code from the video above for plugging into your python interpreter:

def LCS(S, T):
    m = len(S); n = len(T)
    L = [[0] * (n+1) for i in xrange(m+1)]
    LCS_set = set()
    longest = 0
    for i in xrange(m):
        for j in xrange(n):
            if S[i] == T[j]:
                v = L[i][j] + 1
                L[i+1][j+1] = v
                if v > longest:
                    longest = v
                    LCS_set = set()
                if v == longest:
                    LCS_set.add(S[i-v+1:i+1])
    print LCS_set

Real world application

As researchers, we often find ourselves swimming in a sea of seemingly random data, and we’re always looking for ways to make sense of this wealth of data, how we can obtain insights and the act accordingly.

Here’s how I use the LCS algorithm to find patterns in malicious links. Obviously, it can be applied to any kind of data outside the boundaries of security research. Hope you’ll find this tool handy in your problem-solving toolkit!

Security Researcher: Jay Liew

p.s. This blog post is dedicated to the folks in #python on Freenode.

This is a cross-post from my company’s blog.

Best thing since emoticons

Wednesday, September 23rd, 2009

Math and physics geeks rejoice! Instant messaging in LaTeX. Very cool. Check it out: http://www.mathim.com/

(char)lotte: my- *love –

Monday, November 24th, 2008

I almost fell off my chair reading this. Funniest thing I’ve seen in a while! :D C/C++ hackers would <3 this! Even if you’re not a hacker, you can still appreciate the English poetry. It’s just expressed, differently ;)

From the International Obfuscated C Code Contest, may I present to you this lovely poem:

char*lie;

	double time, me= !0XFACE,

	not; int rested,   get, out;

	main(ly, die) char ly, **die ;{

	    signed char lotte,

dear; (char)lotte--;

	for(get= !me;; not){

	1 -  out & out ;lie;{

	char lotte, my= dear,

	**let= !!me *!not+ ++die;

	    (char*)(lie=

"The gloves are OFF this time, I detest you, snot\n\0sed GEEK!");

	do {not= *lie++ & 0xF00L* !me;

	#define love (char*)lie -

	love 1s *!(not= atoi(let

	[get -me?

	    (char)lotte-

(char)lotte: my- *love -

	'I'  -  *love -  'U' -

	'I'  -  (long)  - 4 - 'U' ])- !!

	(time  =out=  'a'));} while( my - dear

	&& 'I'-1l  -get-  'a'); break;}}

	    (char)*lie++;

(char)*lie++, (char)*lie++; hell:0, (char)*lie;

	get *out* (short)ly   -0-'R'-  get- 'a'^rested;

	do {auto*eroticism,

	that; puts(*( out

	    - 'c'

-('P'-'S') +die+ -2 ));}while(!"you're at it");

for (*((char*)&lotte)^=

	(char)lotte; (love ly) [(char)++lotte+

	!!0xBABE];){ if ('I' -lie[ 2 +(char)lotte]){ 'I'-1l ***die; }

	else{ if ('I' * get *out* ('I'-1l **die[ 2 ])) *((char*)&lotte) -=

	'4' - ('I'-1l); not; for(get=!

get; !out; (char)*lie  &  0xD0- !not) return!!

	(char)lotte;}

(char)lotte;

	do{ not* putchar(lie [out

	*!not* !!me +(char)lotte]);

	not; for(;!'a';);}while(

	    love (char*)lie);{

register this; switch( (char)lie

	[(char)lotte] -1s *!out) {

	char*les, get= 0xFF, my; case' ':

	*((char*)&lotte) += 15; !not +(char)*lie*'s';

	this +1s+ not; default: 0xF +(char*)lie;}}}

	get - !out;

	if (not--)

	goto hell;

	    exit( (char)lotte);}

iPhone Tech Talk – Los Angeles

Monday, November 10th, 2008

(I’ve been rather caught up lately, and this is a slightly late post!)

Update 11/11/08: Correction, when I wrote below that a certain Apple product did not have a camera, I was referring to the iPod Touch, not the iPhone 2G! Tks CaArRrRny.

About 2.5 weeks ago, I took a day off from work and drove 2 hours up to LA to attend a mini iPhone developer conference. It was a free event, but seating was limited and reservation was a must. I was lucky to get a spot, a few of my developer buddies from the San Diego area were not able to secure one (the event “sold out” almost immediately!)

photo.jpg
 

Apple also announced that they have just launched a developer forum site just the night before. This forum is late in the game, also because it was only recently that Apple decided to lift the developer-community-killing NON DISCLOSURE (duh) agreement.

I got to meet some interesting dev guys, and learned a bit more about this new mobile platform (below are some pictures). Some of my thoughts:

The iPhone App Store really does provide value

As much as some folks criticise this “centralized” distribution method, it provides value like Digg.com, Reddit.com, and Slashdot.org does – in discovery. Does Digg create its own content? No. Digg’s largest value prop: The most interesting news at that point in time on the ‘net, when you visit the site (great for ADD news addicts). It’s a great discovery service. So if you’re an iPhone app developer, the App Store is a great way for people to discover your app. You are exposed to an audience world-wide. Or at least, the 50-60 some countries that iPhone is officially distributed in.

To contrast, in absence of the App Store, you can distribute your app on your own personal web site. Uhh, and how are you going to get discovered? Are you going to spend $ on a marketing SEO force? Look at Windows Mobile and Symbian. If you developed an app on these said platforms, you are free to give/sell it exclusively from on your own web site. There’s not an equivalent “App Store” for Windows Mobile and Symbian OS. (And how are apps doing on those platform again? Right..)

Apple’s seemingly arbitrary process of approving apps sucks

Yeah it sucks. Apple provided lunch at the Grand Wilshire hotel, so we didn’t have to go out and spend money. Nice move, because developers can discuss and get to know each other over a meal (aligned with AAPL’s motive of cultivating a developer community – and oh, I like free food too). One thing that appears to be the consensus is Apple’s no-guidance on what apps they will approve or not approve to be on the App Store.

For an app developer, after you have done building your app, you then have to wait for Apple’s final thumbs up/down on whether your app will be accepted for distribution. While some checks and balances are necessary for various reasons (quality assurance, no malware apps, etc.) – this current process is one big black box and the trouble is that if you were a real corporation who had to justify engineering resources to allocate, complete with revenue projection plans, you have this one step where it looks like it’s a dealbreaker: the review process.

The trouble is, you don’t know before hand if Apple would say “hell no” to distributing your app after you have already spent the time/money/effort toiling away learning the platform, and then painstakingly building an app. Your resources spent would be effectively be written off as a sunk lost, if they just rejected the app. This is arbitrary outcome is hard to accept, if you’re the I-allocate-my-engineering-resources-wisely-with-planning kind. If you’re a {one, two, three}-man “side project” startup guy app developer, then whatever .. because you’ll just likely chalk it up to fun. But if you’re doing this solely to put food on the table, this process sucks.

One developer over lunch mentioned how his app was submitted, and Apple did not deliver a decision within the time they said they would (IIRC, 90 days), and told him to resubmit (essentially beginning the whole submission process from beginning again). He did call once in a while to check the status, and he said the operator’s sole job was to basically just remind callers that the 90 days have not been reached, and they should just wait by the mailbox for an answer.

Fragmentation is veeeery minimal in the iPhone

Minimal, yes, not zero. Why? Because the older iPhone iPod Touch does not have a camera. So if you’re developing an app using a camera, you had to include in your code an “if no camera, do this, else do that” statement. Think about the Android. It’s made to run on a bazillion type of different hardware from different manufacturers. If you were developing an app using the a camera, you have to do a “if no camera, break, if else, camera supports X resolution, do this, else if, camera has this special feature, do this, else … ” nesting an unnecessarily long if/else conditional (or a conditional equivalent type check).

The art of symbiotic co-creation

Back “in the day”, one has to negotiate with carriers and stuff (no one man dev shop is going to do that) – clearly the barrier-to-entry has been lowered significantly for mobile app developers. Also, Apple takes care of billing, local taxation stuff (recall that the iPhone is distributed globally in 50-60 some countries), and the hosting of your app. I think the 30% cut is reasonable, as they are creating real value for mobile developers.

It’s really nice how Apple has removed a lot of friction in developing a mobile app. The success of the iPhone hinges just as much on the app developers as do the success of the mobile developers, on the success of the iPhone. The more attractive applications exist out there, the more that would drive iPhone sales globally, further strengthening the buyer-seller network-effect (like eBay, they are un-toppable at this point). As an app developer, you’d want to develop for the platform with the widest audience possible.

Anyone can engineer an app for any niche they choose, so even obscure verticals may have their needs met. Apple knows there’s no way it can possibly meet *everyones* app tastes, so it’s smart to just farm out that piece to the free capitalistic market.

On the flip side, not providing an open market for developers would mean not being able to feasibly meet a certain need by a certain category of consumers (some will be left out, by definition!), and those folks would be ripe for poaching by iPhone-competitors. Thus, AAPL is really covering themselves from a potential attack from the low-end of the market there (which if were to occur, would force Apple to keep moving higher in the market – classic b-school case study stuff). This reminds me of an article on innovation by McKinsey Quarterly that I had just previous blogged about (good read about innovation, do check it out. Warning: soul-sucking registration required).

In all, this was a nice event to get to know other iPhone devs around the Socal area (one guy actually flew in from Phoenix!). I learned a lot of best practices type stuff, e.g. excessive and unnecessary polling of the GPS quickly drains the battery life, and most apps don’t need that kind of geo-location precision (so don’t be a hog!)

Hooking up an iPhone to a Macbook for real-time live debugging:

photo.jpg
 

Real-time performance benchmark stats:

photo.jpg
 

Hey, does that spell an “A” for .. Aquaduct?

photo.jpg
 

I’m proud to be a geek

Friday, October 17th, 2008

A gem quote I found from the blog of Justine Musk:

A lot of geeks are pale, bespectacled, wear dark clothing and don’t get out much – the stereotype exists because it is very often true. I could pass for a non-geek but it would be inaccurate. As you get into your late twenties and thirties you get into the era of ‘the revenge of the geek’. Geeks run the world. Condoleeza Rice is a geek, Bill Gates is clearly a geek, many of the big filmmakers and writers are geeks, lots of military people are geeks. Anyone who has heard Donald Rumsfeld talk about military hardware knows they are in the presence of a geek. Geeks use their powers for good and for evil.

— China Miéville

Mobile data adoption on the rise

Saturday, July 26th, 2008

Some mobile data trends (numbers + commentary):

  • Total mobile data revenues for 2007: US$157 Bil
  • Total mobile data revenues for Q1 2008: >US$49 Bil, 42.7% y-o-y increase. Of this, non-SMS data made up approx US$17.46 Bil (35.6% of total data revenues)
  • Mobile data revenues is now almost 20% of mobile operator total revenues
  • 40% of world’s data revenues come from APAC (>US$20 Bil in Q1 2008)
  • Fastest growing is EMEA, which despite only representing 2% of world’s data revenues, is growing at 91.7% y-o-y to US$927 Mil. This acceleration is aided by the 321% y-o-y increase of HSPA subscribers
  • Operator that generated highest non-voice revenues this quarter is Japan’s NTT DoCoMo (US$3.6 Bil), overtaking China Mobile (US$3.5 Bil)
  • As a % of overall revenue, Filipino mobile operator Smart Communication is the world’s market leader, and the only carrier to depend on non-voice revenues for > 50% of its income *I wonder how much of this is attributed to microfinance and mobile payments i n that region, hmm ..

And as always, I’d like to extrapolate some meaning from raw numbers, so let’s go.

Obviously, the trend clearly indicates that your cell phone is becoming more of a general purpose computing device (like your desktop PC, as opposed to a single-purpose device that makes phone calls only), with more rich features that PCs don’t have (e.g. GPS and accelerometer), and it’s all hooked up to the wonderful internet.

Action items: First, we have to get out of the habit of thinking of cell phones as desktops, because the use-cases are completely different; treating them as such is the clearest way to die. Second, with mobile devices becoming more powerful (computationally, Moore’s law), having more storage (cost of storage trending down, Moore’s law), internet connectivity improving (coverage, speed, cost, again, Moore’s law), and throw on top of that added new hardware features (GPS, accelerometer, etc) .. this sounds to me like having richer and more powerful tools in a technologist’s problem solving warchest — so bring on the problems, bring on the opportunity.

I chuckle as I write this because this reminds me of what Stanford University’s president John Hennessy once mentioned in an interview, about his prediction of what would happen in mobile technology down the road:

  1. Information at any where, at any time, on any device
  2. A user experience that works well, independent of what that information is: Be it a Google map, stock listing, web site, email, etc. Making that convenient and natural, and seamless
  3. Imagine walking in a brick and mortar store and wanting to buy a product. I want to look up my phone and do a price comparison on the product and know what people are saying about it. I want to do that in 5 seconds. Today, I have to open a browser, visit a review site, search, etc. (too much work)

The iPhone is clearly one of the pioneers in making that happen, especially with the iPhone app store. I have previously commented on why I think the iPhone app store is very much Apple’s competitive advantage, and as much as I root for Google’s Android, it remains to be seen how the Android incarnations would address the iPhone platform threat.

With mobile carriers having trouble increasing revenues from voice, you betcha they are thinking of every single way to make money from mobile data. I have also previously written a rant about iPhone/AT&T’s data pricing strategy (there’s nothing wrong with the strategy per se, I’m just a price-sensitive geek at heart).

Now’s a good time to be a mobile app developer .. there’s money already being pledged for the BlackBerry platform (US$150 Mil) , Google Android platform (US$10 Mil), and the iPhone platform (US$100 Mil). I can see mobile carriers snapping up these mobile app startups to further bolster their mobile data revenues. Technology IPOs are almost non-existent today, much to a Silicon Valley VC’s annoyance, so exits via acquisition to a mobile operator would make sense for mobile app startups.

I’m passionate about innovation and problem solving with tech, and I can’t wait to see more new applications in mobile given these trends. The question I try to ask myself given these stats above are, “what else is possible today that wasn’t yesterday?” Think it about it.

If I were to wish for anything, I should not wish for wealth and power, but for the passionate sense of the potential, for the eye which, ever young and ardent, sees the possible. Pleasure disappoints, possibility never. And what wine is so sparkling, what so fragrant, what so intoxicating, as possibility!
–Søren Kierkegaard

To go off on a slight tangent, it’s interesting to note that a Filipino mobile operator is the world’s market leader in depending on non-voice revenues. I wonder how much mobile payments contribute to their revenue stream, and how much of that is related to microfinance. If anything, I think that could be a classic BoP example because it would illustrate another example to bust the myth that corporations cannot make a significant and sustainable profit in selling to the poor.

If I was all the other mobile carriers looking to make more $ from mobile data, I’d be watching this Filipino carrier, Smart Communications closely to glean some lessons.

Click here for the full story of the stats above from cellular-news, and regional breakdown of revenues.

And I’ll end this blog post with vivid taste of possibilities for mobile — a very cool Android project in the making called Enkin. Do check it out!

My App Engine “Wall”

Friday, June 13th, 2008

I was messing around with Google’s App Engine this week, and learning some Python (the programming language, not the snake! I had someone ask me that) at the same time.

App Engine (for scalability reasons) does not support SQL, but instead provide and API they call Datastore for persistent storage. For the app I made, I queried for data ordered by date, but for some reason the result set still comes out unordered. Odd. I’m probably not calling it right. Anyway, it was just an exercise to see what App Engine was all about.

Here’s a replica of the Facebook Wall I made, feel free to write your heart out. As you can see, I’ve had friends say some really nice things about me already. The full address is liew.appspot.com .. but there’s an iframe to it if you’re too lazy to click on that link :)

Update 6/15/2008 — Tinkered around a little and realized why its unordered .. I lost the timestamps on some of the posts, so for those that come out unordered, it’s because there are no records of which came first (the timestamp was NULL). It should be fine going forward. The un-stamped posts take precedence in ordering over the stamped ones, so you may have to scroll down a little to see your post (or just CTRL-F it).