10K Apart challenge

13 August, 2010 (18:08)

An Event Apart has put together a 10K Apart challenge in which participants must write a fully functional HTML5 application while using only 10K. I had to take part, so I’ve made a simple, totally unoriginal and ugly todo app called FuglyDo5 (I’ll appreciate a vote).
It uses some new HTML5 tags some basic CSS3 and localStorage so that data is persistent across browser sessions. You can export/import your data and you can undo if you mark a item as completed or deleted.

I haven’t spent as merely enough time on it as I wanted, but I have a tendency to give up on a project if I don’t have a pretty design to work with. And since I have no artistic skills what so ever, the design isn’t much (hence the name) and I lost interest as soon as all functionality was complete. I hope I’ll at least get a book out of this, aiming for anything more would be unrealistic as some of the entries are simply amazing and I really can’t compete with that. Maybe if I had a better idea and somebody to do the design for me. Well, maybe next year.

On a related note: there is also the JS1k contest, in which you have to build a cool JavaScript demo using only 1K of code. Check it out.

FuglyDo5

I may, or may not, be incompetent

4 June, 2010 (17:11)

By I, I mean we, and by we, I mean me and my boss. And by me and my boss, I mean everybody who manages other people or their experiences of whatever sort.
For example, you walk into a groceries store and immediately see 10 things that are just wrong or plain old stupid. And you think: “if I ran this I’d be so much better”. For instance, I would open the second (and the third), cash register when there are 20 people queuing behind one that is open (and operated by an old lady whose source of joy, it seems, is making other people wait indefinitely).

And then there is me, co-managing many online communities thinking that all is well and fair. But there are still countless people complaining constantly about this and that.

So, either I’m a incompetent fool, or they are. The catch is that I simply don’t know.
When I’m in my “customers” shoes, everybody else is incompetent. And when I’m the boss of my “customers” it seems, to me, that they are the fools (dear customer, if you read this: I love you).

I see no way of resolving this right now. So, sadly, no advice here, just food for thought.

Knowledge is a tricky business

1 April, 2010 (20:51)

Working in IT, I’m painfully aware that technology I learn about today can, and most probably will, be obsolete tomorrow. And I’m quite happy with that as it gives me reason to learn new stuff constantly. But recently I was reminded that even stuff that you think you know and generally doesn’t change can … well change, some APIs change constantly and you have to re-learn them all the time. But that usually isn’t a problem as you will be reminded of the change by your program not working (and by the yelling of your customers, off course). The problem is when something changes in a way that the old way still works but is suddenly extremely inefficient, and you simply don’t know that something changed.

I was also recently reminded that I might have to re-learn some of the stuff I already know and hasn’t changed. I was reading a book called High performance MySQL (it was sitting on my shelf for almost a year now) and it shook the foundations of my knowledge that I base my code on. I learned that VARCHAR can be longer than 255 chars. Where did I pick that limitation up I don’t know (probably from CHAR, now that I have re-read the documentation), but I’ve been designing my schemas all this years with this limitation in mind and it never occurred to me that, in reality, I can define VARCHAR to be 65,535 chars long. I always used TEXT (or some variation) when it was required to store longer text.
This case by itself is no big deal, but I’m now trying to figure out what else I’ve also learned the wrong way in my early days as a programmer (I started to learn MySQL almost right from the start). The problem is that there’s simply no easy way to find out. I’d have to re-read every manual for every technology I use, and since I kinda need to sleep I think I won’t be doing that. What I will do, however, is open the manual every time I start using something that I take for granted so I will find out if there is anything rotten in my knowledge on that particular topic.

Why I worked on Sunday?

21 January, 2010 (18:41)

I was in the office almost all day this past Sunday. Many people asked me: “why”? Here is my answer: I love what I do, I don’t consider my work as a job but something I do because I enjoy it. The fact that I’m living off of it is just a bonus.

It never ceases to amaze me, how almost nobody I know, outside of my colleagues,  likes what he is doing.

What I’ve done in 2009

31 December, 2009 (13:01)

I don’t really get the whole new year thing. Everybody is talking about change and good wishes and what not, but I don’t see how anything will change just because of a simple date increment. I guess humanity needs this artificial mile stones to reflect on what has been done and what has happened. Having said that, today probably is a day, as good as any, to look back and think a little.
Since I like bullet points I’ll use those to list what I’ve done in 2009 (in no particular order):

  • I finally took some time to actually learn something about JavaScript and I feel in love with it, jQuery has probably helped here a lot and I can’t imagine how the internet worked without this beautiful language in the past.
  • I improved my knowledge of PHP, written a brand new framework with which I’m happy with (for now), it even got some praise from someone I worked with for a short while.
  • Like with JavaScript above, I took the time to improve my HTML&CSS skills and that worked out quite well. These three things are so easy that nobody actually learns them but just pick up on them as he goes along. Luckily I realized this is a mistake and I am still working on improving my skills in this area.
  • I started reading technical blogs and web pages again. I learned a lot from other (smarter) people this way.
  • I used memcache on a couple of our projects, great technology.
  • I learned Comet and developed chat with it, hackish stuff Comet, but the future is looking bright on the real-time-web front.
  • I’ve started to actively participate on StackOverflow (see my badge on the left) again. It’s a great way to brush up on your skills and give something back to the community.
  • I’ve started to write here on this page again which is a great way to, hopefully, give back something to the community.
  • I went to my first conference (PHP Konferenca)
  • I had my first lecture at WebCampLjubljana, and that was a great experience and I hope I’ll have a chance to do it again sometime.
  • I was given a task to find another programmer for our company and although that didn’t quite work out in the end, I gained a lot of experience from that process.
  • We launched a brand new web page (spored.tv), redid another one from scratch (mojalbum.com) and cloned a couple of others (igre123.rs, mojnet.rs). It’s always great to work on something completely new and, like I said, I had the pleasure to develop two brand new web pages in one year.
  • I’ve lost a customer for reasons I don’t quite understand which has hurt me financially but all is well.
  • I’ve developed a system that uses the Aliiike recommendation engine
  • I’ve written so many lines of code that I’ve forgotten half the stuff I did this year :)

There is probably some more stuff that I can’t remember right now, I’ll edit if I remember something else.
And here is what I’d like to do/improve in the next year:

  • I’d like to play with the technologies that are behind the NoSQL movement.
  • I will introduce a versioning software to our company (yes I know, shame on me).
  • I will set-up a wiki where I will try to document as much as possible.
  • I will try to get some more break from my work as to avoid burning out.
  • I will improve my PHP/JavaScript/HTML/CSS/whatever else I’m using skills.
  • I would like to learn a new programming language.
  • I will work on my people skills and try to bring my arrogance down for just a notch :)

Again there is probably something I’ve forgotten to put on that list.

All in all as far as my professional life/career goes this was a successful year. I won’t talk about my personal life here, but I will say that it kinda sucked. That is all.

My lecture at WebCampLjubljana – video

30 December, 2009 (15:06)

As I’ve mentioned in my previous post, I had a lecture about Sass at WebCampLjubljana in November. Guys that put the whole thing together now published the videos (every lecture was recorded) and here is my lecture:

Sass – a better way to write CSS from Jan Hančič on Vimeo.

It was my first time doing something like this, so I was a wee nervous but I think it doesn’t show (except that I used “amm” as every second word). Since this was also my first *Camp, I also didn’t quite know what the target audience will be, and I think (as some have pointed out) I was a little bit to technical. I should have probably focused more on describing the benefits of Sass and how it can speed up your development, not how to actually use it.
But I hope somebody will find some use of it now that is floating around the internet.

update: Slides (PDF) from my talk are here

Badge animator for Chrome extensions

5 December, 2009 (17:15)

I’ve been playing with extensions in Chrome lately. It’s amazing how simple it is to make an extension, if you know JavaScript, HTML and CSS you are all set to go. Read this tutorial from Google to see for yourself. I’m now coding something that will, hopefully, someday become a “new private message notifier” for Mojvideo.com, nothing fancy but a great start for someone who has never developed an extension for anything (well OK I have written some jQuery plugins). And plus this extension might please a user or two when it’s released (once Google includes extensions in the main build of Chrome off course).

While coding I thought it would be cool if I could scroll some text in the, what Chrome calls, badge. Kinda like those signs on train stations:

Well below is the code that achieves that (you can freely use it if you like). The code hasn’t been fully tested but I haven’t seen any problems with it.

function BadgeTextAnimator ( options ) {
	if ( options === undefined ) {
		return null;
	}

	this.options = {
		text: options.text,
		interval: ( options.interval === undefined ? 500 : options.interval ),
		repeat: ( options.repeat === undefined ? true : options.repeat ),
		size: ( options.size !== undefined && options.size > 0 && options.size <= 6 ? options.size : 6 )
	};

	this.intervalId = null;
	this.index = 0;
}

BadgeTextAnimator.prototype.doAnimate = function () {
	var startAt = this.index;
	var cutAt = this.options.size;
	var addBefore = false;
	if ( this.index < this.options.size ) {
		cutAt = this.index + 1;
		addBefore = true;
		startAt = 0;
	}

	var chunk = this.options.text.substr ( startAt, cutAt );

	if ( chunk.length < this.options.size ) {
		var difference = this.options.size - chunk.length;
		for ( var i = 0; i <= difference; i++ ) {
			if ( addBefore === true ) {
				chunk = ' ' + chunk;
			} else {
				chunk = chunk + ' ';
			}
		}
	}

	chrome.browserAction.setBadgeText ( { text: chunk } );

	this.index = this.index + 1;
	if ( this.index === this.options.text.length ) {
		if ( this.options.repeat === true ) {
			this.index = 0;
		} else {
			this.stop ();
		}
	}
};

BadgeTextAnimator.prototype.animate = function () {
	var spaces = Array ( '', ' ', '  ', '   ', '    ', '     ', '      ' );
	chrome.browserAction.setBadgeText ( { text: spaces[this.options.size] } );

	this.doAnimate ();
	this.intervalId = setInterval ( (function ( self ) {
			return function () {
				self.doAnimate();
			};
		} ) ( this ),
		this.options.interval
	);
};

BadgeTextAnimator.prototype.stop = function () {
	clearInterval ( this.intervalId );
	this.intervalId = null;

	chrome.browserAction.setBadgeText ( { text: '' } );
};

And you use the badge animator like so:

var animator = new BadgeTextAnimator ( {
	text: 'this is some sample text', // text to be scrolled (or animated)
	interval: 200, // the "speed" of the scrolling
	repeat: false, // repeat the animation or not
	size: 6 // size of the badge
} );
animator.animate ();

And this is how it looks in the browser:

simple jQuery optimization tips

4 December, 2009 (14:40)

JavaScript is getting more and more important in the development of web pages and web applications. Unfortunately JavaScript is rather slow on some of the browsers (I’m looking at you IE), so we must strive to make our code as efficient as possible so that our users get a quick and responsive user interface.
I use jQuery on all of my projects so I’ll share some tips on how to improve the performance here.

This first tip is hopefully painfully obvious to most of you. If you are referencing a jQuery element more than once store it in a variable so you don’t select it over and over again (DOM traversing is slooooooow):

$( '.SomeDivs' ).each ( function () {
	var $this = $( this );
	// do something with the current element
	// repeatedly
} );

The second tip is not so obvious. jQuery comes equipped with a powerful selector engine, which allows you to find some element(s) on various ways. And there can be a great difference between doing $( ‘.SomeClass’ ) and $( ‘p.SomeClass’ ).
I won’t go into details here as somebody else has already done this. I’ll just post this quick summary here:

// find element by ID
$( '#d-2642' ).html (); // is (obviously) much faster than
$( '[id="d-2642"]' ).html(); // or
$( 'small[id="d-2642"]' ).html();

// find element by class
$( 'p.p-4781' ).html(); // is faster than
$( 'p[class="p-4781"]' ).html(); // or
$( 'p' ).filter ( '.p-4781' ).html(); // or (this method is the fastest in Firefox)
$('.p-4781').html()

// find element by attribute
$( 'p[row="c-3221"]' ).html(); // is faster than
$( 'p' ).filter ( '[row="c-3221"]' ).html(); // or
$( 'p[@row]' ).filter ( '[row="c-3221"]' ).html(); // or
$( '[row="c-3221"]' ).html();

My lecture at WebCampLjubljana

16 November, 2009 (23:06)

I will have a lecture next weekend at WebCampLjubljana. I will be lecturing about Sass (Syntactically Awesome Stylesheets), a better way of writing CSS. I don’t know at what time my lecture will be so come and stay the whole day, there will be tons of other great lectures.

I am a little bit nervous since this will be my first talk before about 100 people and in English to top it off (and my English, as you can read, is not all that good). Well I hope I see you there.

WebCampLjubljana

Hey Opera … I hate you!

12 November, 2009 (19:41)

Based on recent experience, Opera is a really crappy browser to develop for. It’s developer tools are almost totally useless and it has this wired bugs that you can’t find any info on how to fix them. At least with IE every bug and quirk is covered in great detail on many pages over the internet. Once you start doing something fancy and try to make it work in Opera you are pretty much on your own.

I’ve had this problem that I now managed to solve. If you have a bunch of floated DIVs that need to be sorted using the (excelent) jQuery UI Sortable, then make sure that the “position” CSS property of the floated DIV is not “relative”. The “effect” that you get with “position: relative” was quite “funny”; once you dragged a DIV to a new position it just disappeared into mid air, or it just hid behind the other DIVs at some random position. I mean, how the fuck do you even debug something as stupid as this? And now I have found a new bug while using jQuery UI Draggable/Droppable in Opera. The “effect” is similar; DIVs are now accelerating from the place you drop them to some place that is not on my monitor …