mina86.com

CSS sprites as background

Get back to “Jump to”

CSS sprites aren't anything new. They have been around for years now, and are one of the methods to optimise website load time. The idea is to incorporate several images into a single bigger one and in this way decrease number of round trips between HTTP server and a browser.

In its traditional use, CSS sprites work as a replacement for images and cannot be used as a background. But background is exactly how I'd implemented quote image left of long quotes and flags indicating paragraph language, eg:

A few of the entries on my blog have text both in English and Polish. On those, I use some simple icons to indicate which is which:

Polish flag on the left indicates paragraphs written in Polish.

UK flag on the left indicates paragraphs written in English.

After a bit of playing around I finally figured out how to get this working, and even though there are some caveats, sprites can be used as a top-left no-repeat background image as well.

The fifth generation

Get back to “Jump to”

This day must have come sooner or later. Even more so since I love squeezing every byte out of the data being sent over the network, which is why source of this website is so unreadable (don't worry though, readable sources are available in a git repository).

So yeah, I've switched this website to HTML5 with some of it's new elements and optional tags removed. After years of using XHTML 1.1 it feels a bit weird not closing tags, but I guess a few saved bytes are worth it, aren't they? ;)

I've even got my electric slash working in Emacs's html-mode (ie. if I press slash after < sign, inner most element is closed automatically).

Unfortunately, not all is so shiny. For some reason, automatic pagination on entries list page and “load content” link stopped working under Opera. The way those work is by making an XMLHttpRequest and injecting portion of the fetched document in appropriate place. For some reason, Opera ends up with a DOMException: INVALID_STATE_ERR.

SSL and dropping “www.” with mod_rewrite

Get back to “Jump to”

Surprisingly I couldn't find on the Internet any HTTPS-aware example how to drop the www. prefix from web hosts in Apache, so I had to come up with one myself. Firstly, the following lines need to find their way to the end of Apache configuration file (/etc/httpd/conf/httpd.conf or something):

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule ^(.*)$ http://%1$1 [L,R=301]

Secondly, analogous lines need to be added inside of the <VirtualHost _default_:443> directive of mod_ssl configuration file (/etc/httpd/conf.d/ssl.conf or similar), like so:

<VirtualHost _default_:443>
	# … various directives …

	# Here's what needs to be added:
	RewriteEngine on
	RewriteCond %{HTTP_HOST} ^www\.(.*)$
	RewriteRule ^(.*)$ https://%1$1 [L,R=301]
</VirtualHost>

Now, after a restart, Apache will drop the www. prefix for both secure and insecure connections.

Deep Dive into Contiguous Memory Allocator, Part I

Get back to “Jump to”

This is the first part of an extended version of an LWN article on CMA. It contains much more detail on how to use CMA, and a lot of boring code samples. Should you be more interested in an overview, consider reading the original instead.

Contiguous Memory Allocator (or CMA) has been developed to allow big physically contiguous memory allocations. By initialising early at boot time and with some fairly intrusive changes to Linux memory management, it is able to allocate big memory chunks without a need to grab memory for exclusive use.

Simple in principle, it grew to be a quite complicated system which requires cooperation between boot-time allocator, buddy system, DMA subsystem, and some architecture-specific code. Still, all that complexity is usually hidden away and normal users won't be exposed to it. Depending on perspective, CMA appears slightly different and there are different things to be done and look for.

Null: The never-ending story

Get back to “Jump to”

I have already mentioned some problems with the null pointer but my recent discovery knocked my socks off.

By now, it should come with no surprise to anyone that 0 in pointer context acts as a null pointer (no matter of its actual representation). Moreover, it takes only a tiny bit of experimenting to figure out that expressions like (int)0 do as well. The latter is in itself a bit of a pita but it is conforming to the C++ standard which says:

Braid

Get back to “Jump to”

So I've just finished Braid. Not a very impressive achievement, I admit, but just as I finished the last world (or should I say the first) I immediatelly felt the need to spread the word about this wonderful game. (I do need to apologise at this point for yet another non-technical entry on my blog.)

I probably wouldn't got myself to writing anything about the game if I hadn't seen Video Games are Art talk by Kellee Santiego of That Game Company, who, as it turns out, mentions Braid. (Not that I consider the speech to be particularly interesting or well presented – on the contrary, in my opinion it is unstructured with rather poor arguments, I don't care what some film critic says, and besides “art” is just a buzzword anyway – but it somehow stuck in my memory.)

Fixing XML

Get back to “Jump to”

(photo ItsMe1985)

It has been pointed out to me that my website does not open on some web browsers due to XML error. This undesired state was caused by the &nbsp; entity that XML does not define by itself. I have noticed this some time ago and thus switched to numeric notation (&#160;) but the named entity still prevailed in a few places.

Interestingly, I was unable to reproduce the error myself but nonetheless I have seen it happen on my friend's computer so this was a real issue.

I'm writing “was” because I got rid of all occurrences of the &nbsp; entity so this problem should not affect anyone anymore. Had you been affected by this problem, consider revisiting. :)

I'm also extremely grateful for reporting any problems either via email (mina86 at mina86.com), jabber (mina86 at jabber.org) or on IRC (mina86 on FreeNode network).

Prime numbers less than 100

Get back to “Jump to”

Anyone working in a big corporation must have been hit by some “funny” mail from a coworker that helps everyone gets through the day. No different at my office – at one point all engineers have been challenged to write the shortest code in C that prints all prime numbers (and only prime numbers) less than a hundred each on separate line.

This is an interesting brain-teaser so posting it here so others may choose to think about it while their code's compiling.

Of course, a “C program” needs not to be taken too seriously – depending on not too far fetched undefined behaviours of given implementation is all right (but please do not use system() or exec() family of calls ;) ).

0 is ambiguous

Get back to “Jump to”

It has been a long time since my last entry. In fact, it was so long, that this condition has already been pointed out pushing me into finally writing something. Inspired by Adriaan de Groot's entry, I decided to write something about 0, NULL and upcoming nullptr.

I will try to be informative and explain what the whole buzz is about and then give my opinion about nullptr. Let us first inspect how a null pointer can be donated in C and C++.

End of the page, get back to “Jump to”.