Wednesday, January 30, 2013

Ääkköset, merkistöt ja Mac OS X:n komentorivityökaluja

Eiväthän ääkköset enää ole ongelma

Muistiinpanoja sen varalta jos kuitenkin ovat, lähinnä Mac OS X:n komentorivin ja suomenkielisen tekstin yhteydessä.

Oleelliset merkistöt suomenkielisessä ympäristössä

  • UTF-8 : Unicoden vaihtelevanpituinen koodaustapa (1-4 tavua per merkki)
  • ISO 8859-1 (aka. Latin1) : 8-bittinen, eli 8 bittiä (1 tavu) per merkki -> 256 merkkipaikkaa

Tekstitiedoston merkistön tunnistaminen

Lähtökohtaisesti merkistöä ei voi päätellä tekstistä, vaan merkistön tulee olla sovittuna / etukäteen tiedossa. Kun tuntemattomalla merkistöllä koodattu tiedosto kuitenkin tulee vastaan, voidaan (varsinkin jos kielikonteksti on tuttu) tehdä erilaisia akateemisia arvauksia.

Tiedoston tavujen tarkastelu heksadumpista

Tiedostosta voidaan ottaa heksadumppi (jolloin nähdään tiedoston kukin tavu)
$ hexdump -C aeaekkoset-utf8.txt
00000000  c3 84 c3 a4 6b 6b c3 b6  73 74 65 73 74 69 0a     |....kk..stesti.|
0000000f
Olettaen että sana on "Ääkköstesti", on kyse UTF-8:stä. Sama sisältö Latin1-koodauksella:
$ hexdump -C aeaekkoset-latin1.txt
00000000  c4 e4 6b 6b f6 73 74 65  73 74 69 0a              |..kk.stesti.|
0000000c
Oleelliset ääkköset
Kirjain UTF-8 Latin-1
ä c3 a4 e4 (228)
ö c3 b6 f6 (246)
Ä c3 84 c4 (196)
Ö c3 96 d6 (214)

Automaattinen päättely (file-komento)

Hyvän akateemisen arvauksen saa myös komennolla file
$ file aeaekkoset-utf8.txt 
aeaekkoset-utf8.txt: UTF-8 Unicode text
Ja
$ file aeaekkoset-latin1.txt 
aeaekkoset-latin1.txt: ISO-8859 text

Merkistön vaihtaminen

Tekstitiedoston merkistön vaihtaminen onnistuu komennolla iconv.

Latin-1 -> UTF-8
$ iconv -f LATIN1 -t UTF-8 input_file > output_file
UTF-8 -> Latin-1
$ iconv -f UTF-8 -t LATIN1 input_file > output_file

Linkkejä

Monday, January 21, 2013

Misc. notes related to "CSS : Missing Manual"

Recently, I read CSS : The Missing Manual and I got to say that I was pretty satisfied. The book walks through the basics of CSS with examples. The book isn't very deep but covers well the basics.

Misc notes (mostly for myself):

Valid & good HTML & CSS:


  • Remember the basic "official things"
  • Other important things
    • Do not mix HTML & styles (no fonts etc)
    • HTML is for structure & semantics, CSS is for the layout etc
  • Maintainability : CSS class names preferably for content, not for the layout/presentation, for example:
    • use "alert" instead of "red-highlight"
    • use "news" instead of "left-side-bar"

Misc CSS/HTML notes:

  • Block-level vs inline boxes
    • Block-level (div, p, ...) : break before and after element
    • Inline elements (strong, a, ...) : no break

Position

  • absolute : one can define the position him/herself
    • relative to its absolutely positioned parent (tag with absolute, relative or fixed positioning)
    • in other words : positioned with respect to its containing block
    • absolute positioned element is removed from the HTML flow, the space is freed
  • relative : relative to elements "right place" at the HTML flow
  • fixed : fixed position at the window
  • static (the default) : element's box is generated as normal

Thursday, November 22, 2012

SASS vs SCSS vs LESS ... et Compass


Notes on various CSS preprocessors / stylesheet languages
  • SASS (Syntactically Awesome Stylesheets)
    • .sass : the original format (intended syntax, similar to haml)
    • .scss : "sassy css", superset of CSS3
  • LESS
At another level:
  • Compass (CSS Authoring Framework)
    • Uses SASS

Wednesday, July 25, 2012

Notes from "Javascript: The Good Parts"

Some time ago I read JavaScript: The Good Parts, a nice book on Javascript, the lingua franca of the web. Book concentrates on the nice features of Javascript and warns of the not-so-nice features.

My experience with web frontend technologies isn't too strong so I was pretty happy with the book.


This post is a short summary of things that I wasn't too familiar with, mostly in order I encountered them:

Misc things:

  • Javascript has only one numeric type, the same as Java's Double
    • Which means that 1 ends up being 1.0, no separate integers
    • Floating point with computers effects checking of equality, 0.1+0.2==0.3 ends up as false 
  • Javascript has function scope (no block scope)
  • Javascript objects are class-free mutable keyed collections
  • Inheritance : Javascript is a prototypal language
    • Objects inherit straight from other objects
    • prototype objects (e.g. Cat.prototype)
    • Note that this prototype relationship is dynamic.
  • Important widely used convention : constructions functions with capital letter, others with minor
  • A bonus one (not from the book) : For some time I wondered why some variables are started with $ and some not. Seems to be convention to name variables holding jQuery objects to start with a $. See for example Why would a javascript variable start with a dollar sign (at Stack overflow)

The invocation patterns (a.k.a what is 'this')

Method invocation pattern

  • When the function is a property of an object, it is called a method. When the function is called as a method of an object, this points to the object.

Function invocation pattern

  • When the function isn't called as an method, it is invoked as a function -> this points to the global object
  • A mistake in the language design.
  • Causes problems with inner function inside an outer function (inner function doesn't share this of the outer function
    • A common workaround is to save this of outer function to a variable named that.

Constructor invocation pattern

  • According to the writer of the book, "worst of two world" (classical vs. prototypal inheritance)
  • If a function is invoked with the new prefix, a new object will be created with a prototype link and this points to that new object.
  • Functions intended to be called with new are called constructors. They should be given a capitalized name!

Apply invocation pattern

  • Functions can have methods; apply method of a function lets us to choose the value of this, before the arguments.
For those interested, Yehuda Katz has a good summary of these : Understanding Javascript function invocation.

Monday, December 19, 2011

Problems with iMac sleep mode & Spotify

I've had problems with my iMac's sleep mode for some time : Sometimes it takes pretty long (like 10-20 sec or something) to get the computer to sleep mode. More annoying, sometimes the computer wakes up itself after a couple of seconds. But, the problems seem to occur only every now and then, not all the time.

Now I got fed up enough with this and examined things a bit. Short googling didn't help straight but I ended up checking out logs from Console. Spotify seemed to have pretty many log entries there so I ended up closing it. That makes sense, since Spotify's P2P architecture is probably sharing music from it's cache on my computer every now and then.

After that, I haven't had any sleep mode issues at least so far... (went to sleep mode only a couple of times so far). But thought to share it in case somebody ends up googling with similar problems.

Wednesday, December 14, 2011

Minun Kiinani - Isän aika

Kirjastosta tarttui mukaan Minun Kiinani osa 1 - Isän aika, Li Kunwun kolmiosaisen sarjakuvaromaanin 1. osa. Jostain syystä sarjakuvaromaanit ovat viime aikoina olleet suosiossa, varsinaisten lukemiseen ei aika oikein meinaa riittää.

Tarina kuvaa omaelämänkerrallisesti pojan varttumista Maon johtamassa Kiinassa. Elävä kuvaus siitä, mitä kulttuurivallankumous merkitsi käytännössä. Jännä peilata nyky-Kiinaan (vaikken siitä juuri mitään tiedäkään).

Täytyy joka tapauksessa jäädä odottamaan loppujenkin osien ilmestymistä kirjastoon.

Monday, September 5, 2011

Samsung ML-1610 ja iMac

Sattumalta saatiin käyttöön tulostin, Samsung ML-1610. Suoraan ei nähtävästi valmistajalta löytynyt Mac OS X -ajureita (iMac ja Snow Leopard käytössä) mutta SpliX asentui sukkana sisään ja ainakin testisivu tuli moitteettomasti. Pistetäänpä ylös jos joku asiaa joskus googlettaa.