Archive for the ‘howto’ Category

Mp3TubeVideoToMp3.exe ? Mp3TubeSvc.exe ?

Saturday, August 20th, 2011

“Pa, what are you doing?”

“I’m trying to open a video file but none of the video players are working, so I’ve downloaded some codecs and installed them”

(sunken feeling as I hit CTRL-ALT-DEL ..)

“URRRGHHHHH!!!!!!”
(more…)

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.

Bristlebot

Wednesday, December 19th, 2007

Haha, this has got to be the simplest but elegant nerdy toy I have seen in a long time!

Ubuntu touchpad fix

Sunday, November 18th, 2007

At work, my company issued me a Dell D620L laptop. For whatever reason, the touchpad moves the cursor painfully slow in Ubuntu (but not Windows). As a quick stop-gap measure, I just stick in a USB mice and use that. Today, I forgot my mouse so I decided that I’d look to see how I could fix it.

After some digging online for documentation, this is what worked for me:

  1. Open xorg.conf for edit (I found mine in /etc/X11/)
  2. Look under “synaptics” and add the following options
       Option	"MinSpeed"	 "1.5"
       Option	"MaxSpeed"	 "1.7"
       Option	"AccelFactor"    "1.8"
    
  3. Tweak these three numbers as necessary to suit your taste

Here’s a screenshot (click for larger):

ubuntu-touchpad-fix

I hope this helps anyone facing the same annoying problem I did.

On shameless-promo note, check out my cool wallpaper :p The scenery is a picture I took when I was in Grindelwald, Switzerland.

Google Maps fun!

Thursday, August 23rd, 2007

Cool stuff, Google has just lowered the barrier even further to mashing up Google Maps with any web page you have. All you do is go to Google Maps, pick your address, click on “Link to this page”, and cut-paste the HTML iframe code they provide you. Can it get any easier? Previously you had to register and get a Google developer API key and what not, and they were fussy about where the Maps could be placed, and so forth.

But now, you can cut and paste hassle free anywhere you wish! So here’s my first Google Maps mash into my blog. Here’s my favorite hangout place: Panera Bread. Why? Because it has a flat-rate coffee charge, and free electricity and wifi!


View Larger Map