case
ADM Blog
16Jun/110

Steve Wozniak wrote BASIC for the Apple computer in binary

“If you wanted to write a computer program like the programs of the Apple II, you would write your program with another computer that would compile the code and turn it into 1s and 0s that my microprocessor could understand. Well, I couldn’t afford this little program called a compiler. You could rent terminals and time-shared computer systems, and pay a certain amount of money per month, and you could actually write your programs. But since I couldn’t afford that, either, I wrote my programs on one side of a piece of paper by hand. Then I wrote the 1s and 0s that they would translate into on the other side, figuring it out from little cards I had about how the microprocessors work. No other project that large has probably ever been done that way. I still have the whole handwritten manual. But that made me very intimate with the code. Every little line mattered a lot, and it was a representation of myself, too. It had to be so perfect that nobody else could have thought of a better way. If I ever thought of any little section of code that had a slightly better way, I would change it and go that way. The lack of money actually helped lead to that because the lack of money forced me to be very intimate with the code I was writing. Then I would have to type the 1s and 0s into my computer. For BASIC, it took me 40 minutes. I’d turn on the power, type it in for 40 minutes, test that there weren’t any errors, and then go on debugging the next section. So it was like, no tools, no money—I did it all myself without tools, and that led to a very noticeable type of skill excellence.”

source

4May/110

jQuery.quickEach

With jQuery, when you need to iterate all elements with a specific class for example, you use the each() method and inside the callback function you must convert the DOM element you receive as this to a jQuery object in order to access it's jQuery specific methods: $(this)
This is not such a big issue but if you have a lot of items and/or do this often, then times ads up. It would be a blast to have the this object directly as a jQuery instance. So here's a $ little plugin that does exactly that

Source website:
http://jsperf.com/jquery-each-vs-quickeach

The code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
jQuery.fn.quickEach = (function() {
  var jq = jQuery([1]);
  return function(c) {
   var i = -1,
       el, len = this.length;
   try {
    while (++i < len && (el = jq[0] = this[i]) && c.call(jq, i, el) !== false);
   } catch (e) {
    delete jq[0];
    throw e;
   }
   delete jq[0];
   return this;
  };
 }());

If you run the test on that page, on most browsers you'll see that quickEach() is about 80% faster than native each()

30Mar/110

For Javascript devs

If you write Javascript apps you may want to dynamically add some HTML here and there and having HTML strings that need concatenation with different variables is bad and ugly at the same time. So here is a little nugget you might find useful.

1
2
3
4
5
    // standard style
    x = '<div class="' + classnames + '" rel="' + somevar + '" id="' + othervar + '">' + content + '</div>';
 
    // html tag style
    x = htmlTag('div', {class:classname, rel:somevar, id:othervar}, content);

Usage

htmlTag(tagName [, attributes [, content]])
or
htmlTag(tagName [, content [, attributes]])

The function can be called with one, two or three arguments. Beside the first one which is the name of the tag (string), the other two are optional and can be placed in whatever order you like.
For img tags, the content argument is set as src attribute or as value attribute for input tags if the attributes argument doesn't specify otherwise

attributes argument must be an object with key:value pairs and will be expanded as attributes of the tag
content argument is a string or number

1
2
3
4
5
6
7
8
9
10
11
12
13
    var classname = 'test', somevar = 2, id = 'mydiv', content = 'hello';
 
    htmlTag('div', {class:classname, rel:somevar, id:othervar}, content);
    htmlTag('div', content, {class:classname, rel:somevar, id:othervar});
    // will both return <div class='test' rel='2' id='mydiv'>hello</div>
 
    htmlTag('img', content)
    // <img src='hello' />
    htmlTag('img', {src:'myImage.jpg'}, content)
    // <img src='myImage.jpg' /> content is discarded and attributes src is used as source
 
    htmlTag('input', {type:'text', name:id}, content)
    // <input type="text" name="mydiv" value="hello" />

The code

1
2
3
4
5
6
7
8
9
10
11
function htmlTag(type) {
    var r="< "+type,o={},v='',x=0,a=arguments;
    a.length==3&&(((x=typeof a[1]=='object')||1)&&((o=a[-~!x]||{})&&(v=a[-~x]||'')))||a.length==2&&(typeof a[1]=='object'&&(o=a[1]||{})||(v=a[1]||''));
    for(var i in o)r+=" "+i+"='"+o[i]+"'";
    (type=='img'||type=='br'||type=='input')&&((!o.src&&v)&&((type=='img'&&(r+=" src='"+v+"' />"))||(type=='input'&&(r+=" value='"+v+"' />")))||(r+=' />'))||(r+=">"+v+"< "+"/"+type+">");
    return r;
}
 
function queryTag(type) {
     return $(htmlTag.apply(this, arguments))
}

queryTag function just wraps the newly created html in a jQuery object so you can have something like this

1
2
3
4
5
     $("#menu").append(
             queryTag('div', {class:'menuItem'}, 'Click me').click(function() {
                      alert('clicked');
             })
      )
4Jan/110

Delete old snapshots from Alfresco

If you're an Alfresco user, you may have noticed that it creates a snapshot of the store every time you publish something in the staging sandbox. In time this ads up to a lot of MB. If you wish to delete old snapshots of your store, here's the way to do it with version 2.2+ of Alfresco using the AVM Console

First, open up the console at http://host:port/alfresco/faces/jsp/admin/avm-console.jsp
In the command line box, write

lsver, mystore

(where mystore is the name of your store)
This command will list all the snapshots. Now, you can remove individual snapshots by their id with

rmver, mystore, version

or remove a bunch of snapshots between two dates with

rmvers, mystore, 2010-06-25T10:43:06.214Z, 2010-12-09T12:30:26.769Z

The dates you can get from the list of snapshots. The documentation says that the date must be in ISO 8601 but I got an error trying to copy-paste the date from the list with the timezone at the end (+01:00) so I replaced that with Z and worked just fine.

13Nov/100

Gnome – multiple monitor taskbar

If you are using Linux on multiple monitors you are surely going to miss Utramon, but don’t worry. You can get your task-bar on multiple monitors using the following instructions

Instructions:
1.) Right click on anywhere on the launch-bar, click “New Panel”
2.) Drag that to any monitor.
3.) Right click on that panel, and click “Add to Panel”
4.) Select “Window List” under Desktop and Windows
5.) Click Add.
6.) Add as many widgets you want to the taskbar
7.) Click Close, and you’re done.