Have you ever wondered how does look the computation of Fibonnaci number in assembly?

Have you ever wondered how does look the computation of Fibonnaci number in assembly?

For sake of curiosity I chose Pep/8 Assembler and Simulator which could be found on http://code.google.com

The original C uncached version looks as following:

#include <iostream>
using namespace std;
int fib (int n)
    if (n == 0)
        return 0; 
    else if (n == 1)
        return 1;
       return fib (n - 1) + fib (n - 2);
int main ()
    int num;
    cout << "Which Fibonacci number? ";
    cin >> num;
    cout << "The number is " << fib (num) << endl; 
    return 0;

The Pep/8 implementation:

( Read more )

Properties vs Attributes

A DOM element is an object, a thing in memory. Like most objects in OOP, it has properties. It also, separately, has a map of the attributes defined on the element (usually coming from the markup that the browser read to create the element). Some of the element's properties get their initial values from attributes with the same or similar names (value gets its initial value from the «value» attribute; href gets its initial value from the «href» attribute, but it's not exactly the same value; className from the «class» attribute). Other properties get their initial values in other ways: For instance, the parentNode property gets its value based on what its parent element is; an element always has a style property, whether it has a «style» attribute or not.

Let's consider this anchor in a page at example.com/testing.html:

<a href='foo.html' class='test one' name='fooAnchor' id='fooAnchor'>Hi</a>

Some gratuitous ASCII art (and leaving out a lot of stuff):

| a                                         |
| href:       "http://example.com/foo.html" |
| name:       "fooAnchor"                   |
| id:         "fooAnchor"                   |
| className:  "test one"                    |
| attributes:                               |
|    href:  "foo.html"                      |
|    name:  "fooAnchor"                     |
|    id:    "fooAnchor"                     |
|    class: "test one"                      |

Note that the properties and attributes are distinct.

Now, although they are distinct, because all of this evolved rather than being designed from the ground up, a number of properties write back to the attribute they derived from if you set them. But not all do, and as you can see from href above, the mapping is not always a straight «pass the value on», sometimes there's interpretation involved.

When I talk about properties being properties of an object, I'm not speaking in the abstract. Here's some non-jQuery code:

var link = document.getElementById('fooAnchor');
alert(link.href);                 // alerts "http://example.com/foo.html"
alert(link.getAttribute("href")); // alerts "foo.html"

(Those values are as per most browsers; there's some variation.)

The link object is a real thing, and you can see there's a real distinction between accessing a property on it, and accessing an attribute.

The vast majority of the time, we want to be working with properties. Partially that's because their values (even their names) tend to be more consistent across browsers. We mostly only want to work with attributes when there is no property related to it (custom attributes), or when we know that for that particular attribute, the attribute and the property are not 1:1 (as with href and «href» above).

The standard properties are laid out in the various DOM specs:

DOM2 Core
DOM3 Core

These specs have excellent indexes and I recommend keeping links to them handy; I use them all the time.

Custom attributes would include, for instance, any data-xyz attributes you might put on elements to provide meta-data to your code (now that that's valid as of HTML5, as long as you stick to the data- prefix). (Recent versions of jQuery give you access to data-xyz elements via the data function, but that function does more than that and if you're just dealing with a data-xyz attribute, I'd actually use the attr function to interact with it.)

The attr function used to have some convoluted logic around getting what they thought you wanted, rather than literally getting the attribute. It conflated the concepts. Moving to prop and attr is meant to de-conflate them. There will be some brief confusion, but hopefully a better understanding of what's really going on going forward.

Via (stackoverflow)

Add "Recent Applications" icon to the dock, and disable windows animation

1) To add Recent Applications icon to the dock, open Terminal and copy paste following:

defaults write com.apple.dock persistent-others -array-add '{ "tile-data" = { "list-type" = 1; }; "tile-type" = "recents-tile"; }' && killall Dock

Don't forget to check recent Items settings in System Preferences>General

2) To disable windows animation, open Terminal and copy paste following:
defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool NO

How to get md5 hash of files in current directory

The following command pretty useful when you need to get a md5 of specific files e.g. only video files in the current dir.

find * -iname '*.mp4' -exec md5 '{}' \; >output.txt

Does anybody know what '{}' \; means?

Removing dangling commits and those reachable from the reflogs

If you see something like that:
$ git fsck --lost-found
dangling commit 9dbd85d427b32773aee016efc7912f9d1c39aac4
dangling commit 604948146be1bdc2181962543cca039c18cc06b4

You might want to get rid of those dangling commits, in order to accomplish it, do following:
git reflog expire --expire=now --all #Dangerous command, it will be very difficult to recover stuff later on, if you execute it
git gc --prune=now

How to hide a folder in Finder

In order to hide a folder in Finder, open Terminal and write following:

setfile -a V /path/to/folder


chflags hidden /path/to/folder

To unhide:

setfile -a v /path/to/folder


chflags nohidden /path/to/folder

Controlling fan speed on Macbook Air (handling noisy fan, by decreasing the fan speed)

Hello all!

Recently I've purchased Macbook Air mid 2011, I very like it so far.
However, I've noticed when I'm watching movies or YouTube videos, the fan is spinning really fast, iStats shows me something like about 6400 (!) RPM.
I've tried to use fan controlling apps like smcFanSpeed or Fan Control.
However, both of those apps doesn't allow you to decrease fan speed (probably it's designed that way in order not to burn the laptop in inexperienced user hands)

I'm kinda experienced user, so I took a risk and wrote simple script that allows you to set fan speed manually.
The instructions are pretty easy:
1) Download it setFanSpeed2011.tgz
2) Open the Terminal, go to folder where the file was downloaded
3) Extract it: tar xf setFanSpeed2011.tgz
4) Go to inside extracted folder: cd setFanSpeed2011
5) Run it: sudo ./setFanSpeed XXXX (Where XXXX should be needed RPM)

P.S. When I'm gaming or watching movies, I found that 3600 RPM work for me pretty well, the CPU stays on ~174F (~79C) temperature.
The same temperature as when fan was spinning at 6200 (!) RPM, but now it's not such noisy!
P.P.S Created and tested on OSX Lion 10.7.1

Note, I'm not taking any responsibilities if you will burn your laptop by using my tool! Decreasing the fan speed is very dangerous!
Since, if you don't watch the CPU temperature it might be overheated!

install telnet client on windiws 7 using console

IT may be useful when you need telnet.exe on win7 machine and for some reason want install/enable it using .bat files

pkgmgr /iu:"TelnetClient"

Top 50 Programming Quotes of All Time

50. «Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning.»
— Rick Cook

49. «Lisp isn't a language, it's a building material.»
— Alan Kay.

48. «Walking on water and developing software from a specification are easy if both are frozen.»
— Edward V Berard

47. «They don't make bugs like Bunny anymore.»
— Olav Mjelde.

46. «A programming language is low level when its programs require attention to the irrelevant.»
— Alan J. Perlis.

45. «A C program is like a fast dance on a newly waxed dance floor by people carrying razors.»
— Waldi Ravens.

44. «I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone.»
— Bjarne Stroustrup

43. “Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter.”
— Eric S. Raymond

42. “Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.”
— Mosher’s Law of Software Engineering

41. “I think Microsoft named .Net so it wouldn’t show up in a Unix directory listing.”
— Oktal

( Read more )

cross-browsed text-overflow

What is text-overflow? http://www.css3.info/preview/text-overflow/

How to implement it nowadays for the most popular browsers?

Here is a solution:


    .wrapper span


    <?xml version="1.0"?>
    <bindings xmlns="www.mozilla.org/xbl" xmlns:xbl="www.mozilla.org/xbl" xmlns:xul="www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
        <binding id="ellipsis">
                    <xul:description crop="end" xbl:inherits="value=xbl:text">