Borgar.net

— Jump to the navigation index

Latest entries

miðvikudagur, 5. ágú 2009

CSS :target

jQuery (or Sizzle) supports :target in browsers where it runs querySelectorAll to handle the work. In older browsers, it doesn’t offer fallback support. I guess that this is simply because :target is such an uncommon selector?

I have no idea why you would want to use it, but because I have this selector extension and nowhere to put it, here it is:

jQuery.expr[':'].target = function ( a, h ) {
  return (a.id && (h = document.location.hash) && h === '#' + a.id)
};

Updated 6. aug. 2009: Optimized by @maranomynet

Published: 5. 8. 2009 23:24. Tagged: , , , .

mánudagur, 13. júl 2009

Sōkoban

A few days without internet do strange things to a computer addict. In my case I start to rummage frenetically though old projects to see if there is anything I can finish, polish, or do something with that doesn’t require internet access.

sokoban

So I found my old Sokoban game. Originally a Windows application, I though it could be fun to try to remake it in JavaScript. So that’s what I did.

I wrote the bulk of it in about an evening, and spent a few more evenings applying spit and polish until I was satisfied that it worked the way I wanted. The whole thing is about 300 lines of mostly uncommented code running on top of jQuery — well, actually as a jQuery plugin.

The interresting bits

There are a few characteristics that make this implementation interesting. The first is that the game uses progressive enhancement methodology. The script runs through marked items on the webpage and makes valid Sokoban levels playable. If you don’t have JavaScript you can still read the level codes, which are normally written in a standard like this:

####
# .#
#  ###
#*@  #
#  $ #
#  ###
####

The @ is the worker, # are walls, . are docks, $ are boxes, and so on…

The symbols are image-replaced with CSS when the level is live, but the whole thing works without CSS. You can disable the styles if you desire to play the levels in pure ASCII.

This also means that the game is printable. At any moment in gameplay you can grab a hardcopy of your status and frame it. I am hard pressed to think of other printable games. Copying the level onto the clipboard also works just as it would any other text. Not really useful features for a game, but interesting side-effects nonetheless.

Because parsing all the levels immediately as the game loads up — especially on level collections that have very many levels — is quite labour intensive, I am applying a recent jQuery plugin of mine, .processEach(), to prevent the browser from locking up. In short, it works like .each() but yields the process every iteration to allow the browser some time to do other things. It’s perhaps a subject of another entry.

Have fun

Have fun with the game and the source (which are released under the GPL v3). I suspect that it might one day be exactly what a Sokoban level blog is looking for, but for now it mostly remains a curiosity rather than a spectacular reproduction of the game,

Published: 13. 7. 2009 22:57. Tagged: , , , .

sunnudagur, 12. júl 2009

Gecko & Webkit

I stumbled over Zeldman’s opening statement:

When Apple chose Webkit rather than Mozilla Gecko as the basis for its Safari browser, some of us in the web standards community scratched our heads. Sure, Webkit was open-source and standards-compliant.

Really? People were puzzled by this? This always seemed the obvious choice to me.

First of all, Apple didn’t choose WebKit, they chose KHTML to become WebKit. And while Firefox may have been more mature as a browser, the Gecko engine was not mature in ways that mean “sophisticated”.

At the time (7-8 years ago today) the Gecko codebase was a notorious mess and the rewrite work only so far along the way. It was such as mess that it was a running joke on Slashdot and cited as a perfect example of the code equivalent of spaghetti. Gecko still needed a completely new text layout handler to do things like ‘inline-block display‘ and ‘hyphenation‘.

Additionally, the Mozilla developers’ “if you want this feature so much then you are welcome to implement it yourself” vitriol towards web developers wasn’t much better than the apathy Microsoft had. And while it was certainly technically right, it was neither reasonable nor to their credit. But that may not have been so much a factor for Apple.

KHTML, on the other hand, was in heavy development with a much fresher codebase and had nice things that only IE supported, like right-to-left language text. Things that are important to corporations that intend to sell computers to the millions of non-english speakers of the world.

From a purely technical point of view KHTML was a much better choice. Dave Hyatt, who probably had a large say in the selecting KHTML to become WebKit, knew this all to well having worked with, and written some of, the mess Gecko was at the time.

Time passes and we may not remember all of this so clearly or, as things change, these things cease to matter. I am a bit surprised to hear that web developers, even heavy weights like Zeldman, were unaware of the state of the browsers they worked on. Are they still?

Published: 12. 7. 2009 15:46. Tagged: , , .

sunnudagur, 16. nóv 2008

Islenska.org opin almenningi

Á þessum annars ágæta sunnudegi íslenskrar tungu hef ég opnað fyrir notkun á nýrri rímorðabók, orðskiptu, og niðurhali á frumstæðri orðskiptilýsingu sem ég hef haft í smíðum um nokkurt skeið.

Þetta er allt að finna á slóðinni islenska.org, en það er lén sem hefur staðið autt í nokkur ár, eða síðan að ég fékk þá hugmynd að ég gæti framleitt stafræna orðabók.

Hugmyndin er að fleiri tól og virkni færist þarna inn með tímanum. Næstu verkefni verða að auka sjálfvirkni á ýmsum hlutum þarna, ss. útgáfu á gagnagrunninum sem á bakvið þetta liggur (þeas. orðabókinni sjálfri). Mig langar t.d. til þess að varpa orðabókinni yfir í stafsetningarorðabækur fyrir OS X, Ispell, Aspell, og Firefox.

Mér fannst þó vera kominn tími til þess að opna fyrir eitthvað af þessu, enda er enginn ávinningur fólginn í því að þetta liggi dögum saman óhreift á einkatölvunni minni.

Verði ykkur að góðu.

Published: 16. 11. 2008 22:17. Tagged: , , , .

fimmtudagur, 4. sep 2008

Opin gögn og endurnýtanleg

Við félagarnir tókum okkur til og opnuðum vef, opingogn.net, til þess að reyna að gera upplýsingar um opin gögn á Íslandi aðgengileg miðlægt. Hver sem er má bæta sinni vitneskju inn, og eitthvað er þegar farið að tínast inn.

Það leið ekki langur tími þangað til að ég fékk ábendingu í pósti um áhugaverða klausu í landslögum:

Stjórnvöld skulu birta á heimasíðu sinni lista yfir þær skrár sem hafa að geyma upplýsingar í þeirra vörslum sem heimilt er að endurnota, svo og þau skilyrði sem slík endurnot eru bundin.
Upplýsingalög, 1996 nr. 50 24. maí

Þetta er úr lögum um breytingu á upplýsingalögum, nr. 50/1996 sem tóku gildi 1. janúar 2007. Eitthvað er þessu ennþá ábótavant, eins og við er að búast. Það er rétt að benda á að stjórnvöldum er sjálfsagt að endurnýta þær upplýsingar sem safnast á opingögn.net, þær eru jú opnar.

Það er mikilvægt að gera sér grein fyrir því að þótt heimilt sé skv. upplýsingalögum að endurnýta tiltekin gögn, þá er ekki þar með sagt að það sé hægt. Fyrst þarf jú að komast í gögnin. Þeir þættir upplýsingarlaga sem opna fyrir endurnýtingu gagna stofnanna sem ekki fá undanþágu frá þeim, gefa þó engan rétt til aðgengi að þeim.

Glöggt dæmi um þetta er að finna í úrskurði Úrskurðarnefndar um upplýsingamál frá 21. desember 2007:

Í 1. mgr. 24. gr. laganna segir að markmið kaflans sé að auka endurnot opinberra upplýsinga til hagsbóta fyrir samfélagið í heild. Samkvæmt 3. mgr. 24. gr. hefur umræddur kafli þó ekki bein áhrif á rétt til aðgangs að gögnum samkvæmt upplýsingalögum. Þar segir að ákvæði kaflans gildi einvörðungu um endurnot fyrirliggjandi upplýsinga sem séu í vörslum stjórnvalda og almenningur eigi rétt til aðgangs að á grundvelli 3. gr. laganna eða annarra ákvæða sem veita almenningi slíkan rétt. Í skýringum við þessa málsgrein í frumvarpi því sem varð að lögum nr. 161/2006 er áréttað að ákvæði kaflans gildi “einungis um endurnot upplýsinganna en mæli ekki á neinn hátt fyrir um rétt til aðgangs að opinberum upplýsingum.”

Þetta þarf að laga. Það þarf að fjarlægja þessar undanþágur skóla, bóka- og skjalasafna, rannsóknastofnanna, ríkisútvarpsins, menningarstofnanna; Það þarf að fjarlægja ákvöður um upprunatilgreiningar og ábyrgðaryfirlýsingar; Það þarf að takmarka leyfi til gjaldtöku við einhver sértilfelli (ef einhver eru); Og það þarf að afnema ákvæði um vernd og gjaldtöku þeirra stofnanna sem rekin eru samkvæmt sérlögum.

Þannig breytum við þessari vannýttu skúffuauðlind í hagvöxt og kreppumeðal. Ég hvet lesendur sem þekkja ekki málið að lesa sér til, og kynna sér málstaðinn.

Published: 4. 9. 2008 19:48. Tagged: , .

föstudagur, 8. ágú 2008

DV fjallar um tekjur bloggara

Skarast hóparnir bloggarar og lesendur DV nægilega mikið til þess að nokkrum sé sama um þetta? Eru bloggarar raunverulega áhugaverður hópur, eða eru leikarar og fréttamenn á hinum miðlinum orðin þreyttar tuggur? Hvað á að sýna fram á með þessu?

Hvað með að birta tekjur einhverra sem raunverulega mundu vera forvitnilegir. Hvað hafa td. miðlar í laun – hversu mikla peninga hafa þeir af þeim fáfróðu og auðtrúa? Hvað hafa lyfjafræðingar í laun – er okrið að skila sér til starfsmanna? Hvað með pólska verkamenn, er verið að svína á þeim? Hvað með stéttirnar sem sífellt eru að berjast; kennarar, flugumferðarstjórar og mjólkurfræðingar – er einhver fótur fyrir þessu?

Ennfremur má benda á að ef DV vildu raunverulega hrista upp í mönnum ættu þeir að birta tekjur bloggara í einhverjum miðli sem bloggarar raunverulega lesa – til dæmis veflægt – en ekki í einhverjum pappírsgerðum leifum af miðaldahefðum. En það sést kannski best á þessu úrtaki, að blaðið er jafn hugmyndaríkt og það er vandað.

Published: 8. 8. 2008 17:19. Tagged: , , .

mánudagur, 4. ágú 2008

Contrived

From the wikipedia entry on Baa, Baa, Black Sheep:

In more recent politically correct times, the nursery rhyme has come under criticism for having racially discriminatory undertones. [...] More recently, in 2006, a nursey school in Abingdon, Oxfordshire, England have contrived a version which contains the phrase “rainbow sheep”. They claim this was for “educational reasons” and not for any reasons concerning race discrimination.

The subtle use of the word contrived in the quote is simply delightful. For those of you not entirely familiar with the word, here are two entries from my dictionary.

Contrived
“Deliberately created rather than arising naturally or spontaneously.”
“Manage to do something foolish or create an undesirable situation.”

The whole “racially discriminatory” thing is farcical of course, as the rhyme may date back as far as the middle ages. Effectively predating modern racial hate by a good couple of hundred years. Additionally, in it’s older-ending form the rhyme criticized social imbalance:

Two for the master,
one for the dame,
but none for the little boy
who lives down the lane.

I’ve long since stopped expecting people to stop and think about their actions (I certainly know how frequently I fail at this). But wikipedia user 213.9.220.254, who so beutifully selected contrived in that excerpt; I salute you!

Published: 4. 8. 2008 23:16. Tagged: , .