Monday, September 20, 2010

FDTG Principles for Developers

this is a small reminder for me no to forget these principles.

Flexibility
Be ready to change your plans when they’re not working the way you expected; don’t count on things remaining stable.

Decentralization
Centralized systems look strong, but when they fail, they fail catastrophically.

Transparency
Don’t hide your systems; transparency makes it easier to figure out where a problem may lie. Share your plans and preparations, and listen when people point out flaws.

Graceful Failure
Failure happens, so make sure that a failure state won’t make things worse than they are already.

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)'