Monday, August 23, 2010

HTML Comments as strings

Reading HTML comments from a DOM tree with JavaScript is easy.

var nodes = document.body.childNodes,
comments = [];

for (var i = 0; i < nodes.length; i++) {

// if the nodeType is 8
if (nodes[i].nodeType == 8) {

// this is a comment
comments.push(nodes[i]);
}
}

Let's say that the comments array is not empty, so the type of comments[0] is a Comment. That's great but how can you read its content?

This is what the W3C DOM-Level-1 spec says. It implements the Comment interface.

interface Comment : CharacterData {
};

This does not really help us but don't despair. It also implements the Node interface.

...
readonly attribute DOMString nodeName;
attribute DOMString nodeValue;
...

Yes, it's read-only but you can get the comment as a string by using its nodeValue.

comments[0].nodeValue


W3C DOM-Level 3 specifies something called textContent. This can also do the job, you can read about them here, textContent vs. innerText

Thursday, August 5, 2010

Blame does not fix bugs

It's always seems hard to deal with people. Here are few thoughts that I'd like to share.

Blame does not fix bugs, the outcome is important, not the credit, the blame, or the ongoing intellectual superiority contest.
You want to focus on fixing the problem, instead of blaming others.

Criticize ideas, not people, keep it professional, not personal.
Ask questions that allows someone to figure out the problem for themselves.

and there is one more thing, negativity kills innovation so be constructive.

Wednesday, July 7, 2010

simpleHTTPServer, a simple web server

If you wish to have a simple web server that shares files inside your local network there is a good news. You can use simpleHTTPServer which is a Python (2.5+) builtin HTTP Server.

Go to the folder that you want to share and start the server.

python -m SimpleHTTPServer 8000

It will start the server at 8000 and it will serve the files that the current folder contains.

Sunday, June 27, 2010

Finding in files

Finding a string in files is useful and not that straightforward. But don't despair, we have bash.

find . -exec grep -q 'foobar' '{}' \; -print

This searches in the current directory including its subdirectories and finds files that contain foobar.

Sunday, June 20, 2010

Smart Keyword Search with Omnibox in Chrome

Omnibox is a prominent feature of Google’s Chrome Browser. Omnibox is Chrome’s combined search and address bar feature, which allows you to use the address bar as a search bar.
Type a search term in the address box (Omnibox) and press enter to see results from your default search engine.

But it happens that you want to use Youtube search or Wikipedia search instead.

Open Chrome/Preferences/Basic
Click to the Manage button next to the Default Search label.



Here you can see what search engines Google Chrome can use (you can remove from the list or you can add a new item to the list)



Double click on an item shows up a dialog where you can set up the keyword.



If you type this keyword and your search query to the Omnibox, Chrome will search with that engine.

I changed youtube's keyword to yt so if I type yt Humcrush to the Omnibox it'll show me Humcruch youtube videos.

That's smart.

Here is my keywords.

Wednesday, June 16, 2010

What changed in your home folder today.

You can perform a simple Spotlight search from the shell

mdfind [query]

for instance

mdfind Ruby
mdfind -name stdlib.h

and then you pipe the result as you want

mdfind Ruby | grep 'pdf'

You can redefine your search by specifying any of the metadata attribute keys.
Here is a helpful list of metadata attributes that you can use.

You'd like to see what changed in your home directory today, easy.

mdfind -onlyin ~/ '(kMDItemFSContentChangeDate >= $time.today)'

Video for IPAD

Problem: You have a DIVX/DVD video on your computer and you want to watch it on your iPad.

Solution: There are a few options how to convert your video:




  • If the original file is supported by QuickTime it would be your first and simplest choice. Just load your file into QuickTime X and choose Save As from the File menu. Then choose HD 480p as a desired format and wait till the conversion is finished (this may take a while)

  • If you have some esoteric data format or you have to get more control over the encoding process or simply you want to get better quality than HD 480p, then you have to use something else.
    Basically there are plenty of choice (I assume you are coming from Unix world):




    1. Mencoder (part of Mplayer)

    2. ffmpeg

    3. x264 - this is free implementation of h.264 codec. The first two use it as a depndecny anyway



    I had a luck with tool number 2. Here is an example how I converted some video files to iPad format:



    for i in *.avi; do ffmpeg -i "$i" -acodec libfaac \
    -ab 96k -vcodec libx264 -s 1024x576 -vpre lossless_ultrafast \
    -crf 20 -threads 2 "$i".mp4; done


    Probably you'd like to set higher audio bitrate etc. But the command above will get you started. If you need explanations what these params do, please refer to the links above.



The only thing left now is to add the newly converted file to your iTunes library and sync with your iPad.

Enjoy!