Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

MinCSS is amazing

I had this is­sue open in the bug tra­cker for Niko­la (my sta­tic si­te ge­ne­ra­to­r) for a long ti­me: "A­dd min­css su­ppor­t".

We­ll, no, it does­n't ha­ve it ye­t, but I did so­me re­sear­ch on whe­ther it would be wor­th addin­g. And bo­y, min­css im­press­ed the he­ck out of me.

You see, Niko­la's the­mes tend to use una­dul­te­red boots­tra­p, whi­ch means they ca­rry a lar­ge num­ber of things that are not us­ed in their CSS. Be­si­des, it uses se­ve­ral sty­les­hee­ts from do­cu­til­s, pyg­men­ts, and mo­re.

What min­css does is exa­mi­ne your HT­ML and your CSS, and re­mo­ve all the unu­s­ed CSS. So, I wro­te a script that exa­mi­nes the Niko­la ou­tput and ove­rw­ri­tes the CSS fi­les wi­th the mi­ni­mal things that are ac­tua­lly nee­ded the­re.

And the re­sul­t?

He­re is the be­fo­re/a­fter for ea­ch CSS fi­le in Niko­la's de­mo si­te:

bootstrap-responsive.min.css  16849  3251
bootstrap.min.css            106059 14737
code.css                       3670  2114
colorbox.css                   6457   774
rst.css                        6559  2581
theme.css                      1287  1061
-----------------------------------------
                             140881 24518

But wai­t, Niko­la su­ppor­ts bund­ling all tho­se fi­les in­to a sin­gle lar­ge CSS fi­le to avoid ne­two­rk re­ques­ts (u­sing we­ba­sse­ts). Does it wo­rk in that ca­se too?

We­ll ye­s:

all-nocdn.css                167457 29496

But that is not all. The min­css fi­les are not mi­ni­fie­d. Pa­s­sing all-­no­cd­n.­css th­rou­gh Yui-­com­pres­sor sh­ri­nks it fur­ther to 20599 by­tes. Whi­ch, gzi­ppe­d, is a pal­try 4801 by­tes. That means the com­ple­te sty­ling of the who­le si­te is a sin­gle CSS fi­le le­ss than 5KB in si­ze.

Tha­t, is im­pres­si­ve.

Red Country

Cover for Red Country

Review:

Good end for the pen­ta­l­o­gy.

Deploying Django Into My Cheap VPS

I am pre­pa­ring to open my cheap si­te-an­d-­blo­g-hos­ting ser­vi­ce to the pu­blic at so­me poin­t, so I nee­ded to do so­me groun­dwo­rk in­to de­plo­y­men­t. Con­si­der that the host that wi­ll run it wi­ll ha­ve ve­ry li­mited re­sour­ce­s, so I nee­ded to find lean and cheap so­lu­tions when po­s­si­ble, but at the sa­me ti­me, I want to achie­ve rea­so­na­ble re­lia­bi­li­ty and ea­se of de­plo­y­men­t.

Sin­ce this is a tes­ting ser­ve­r, I want it to ha­ve git mas­ter de­plo­ye­d. I do­n't want au­to­ma­tic de­plo­y­men­t, but I want to de­ploy often, mea­ning se­ve­ral ti­mes dai­l­y.

I pre­fe­rred sim­ple tools ins­tead of com­plex tool­s, li­gh­twe­ight tools wi­th just enou­gh fea­tu­res ins­tead of hea­vie­r, mo­re fu­ll­y-­fea­tu­red tool­s. Your choi­ces on ea­ch step could and pro­ba­bly should be di­ffe­rent than mi­ne, de­pen­ding on your si­tua­tio­n, re­qui­re­men­ts and per­so­nal pre­fe­ren­ce­s.

So, he­re's my no­tes from how it's do­ne cu­rren­tl­y. This is not meant as a HO­W­TO, just a des­crip­tion of what see­ms to be wo­rking we­ll enou­gh so fa­r.

Leer más…

Javascript Makes Me Cry: Turning a Date into a String

Wo­rking la­te last ni­ght in Al­va I wanted to do so­me­thing that soun­ded tri­via­l:

When the pa­ge load­s, get the cu­rrent da­te and ti­me, and if a cer­tain in­put is emp­ty, put it the­re like this:

28/05/2013 23:45

So, how hard can that be, ri­gh­t? We­ll not har­d, bu­t...

Getting the current date-time is easy: now = new Da­te(); So, is there something like strftime in Javascript? Of course not. You can get code from the usual places and have a untested, perhaps broken, limited version of it. And I am not about to add a strftime implementation to use it once. Sure, there are a number of Date methods that convert to strings, but none of them lets you specify the output format. So, let's try to do this The Javascript Way, right?

To get the ele­men­ts I want to put in the va­lue, I us­ed ac­ce­s­sor me­tho­d­s. So, ob­vious­l­y, the­se should gi­ve me what I want for the strin­g, ri­gh­t?

no­w.­ge­tDa­y(), no­w.­ge­t­Mon­th(), no­w.­ge­tYea­r(), no­w.­ge­tHou­r() no­w.­ge­t­Mi­nu­te()

We­ll, they are, at the da­te men­tio­ned abo­ve, res­pec­ti­ve­l­y: 2, 4, 113, erro­r, error

Ok, the errors are easy to fix from the docs. It's actually getHours() and getMinutes(), so now we have 2, 4, 113, 23, 45 and of those five things, the last two are what one would expect, at least. Let's go over the other three and see why they are so weird:

Date.getDay() returned 2 instead of 28

Because getDay() gives you the week day and not the day of the month. Which is absolutely idiotic. So, you have to use getDate() instead. Which means the name is a lie, becasue the logical thing for getDate() to return is the whole date.

Date.getMonth() returned 4 instead of 5

Because getMonth() returns months in the [0,11] range. Which is beyond idiotic and bordering in evil. Come on, Javascript, people have been referring to may as "5" for nearly two thousand years now! What other language does this? Anyone knows one?

Date.getYear() returned 113 instead of 2013

Because it uses offset-from-1900. Which is amazing, and I had never heard of a language doing in a standard type. Because why? So, use getFullYear() instead.

No­w, ar­med wi­th the ri­ght 5 num­ber­s, le­t's for­mat it. Does Ja­vas­cript ha­ve the equi­va­lent of sprin­tf or for­mat ? Of cour­se not. In Ja­vaS­crip­t, wi­thout 3rd par­ty mo­du­le­s, you crea­te strings by addi­tio­n, like a ca­ve­man. Agai­n, I know I could add a for­mat me­thod to the String pro­to­ty­pe and make this wo­rk, but I am not adding an im­ple­men­ta­tion of for­mat or sprin­tf just to use it on­ce!

So, this pro­du­ces that I wan­t:

now.getDate()+'/'+(now.getMonth()+1)+'/'+now.getFullYear()+' '+now.getHours()+':'+now.getMinutes()

Un­le­ss... the day or mon­th are lo­wer than 10, in whi­ch ca­se it's mis­sing the le­ft-­pa­dding ze­ro. Lu­cki­l­y, for the pur­po­se I was using it, it wo­rked an­ywa­y. Be­cau­se OF COUR­SE the­re's no in­clu­ded func­tion to le­ft-­pad a strin­g. You ha­ve to do it by addi­tio­n. Or, of cour­se, add a 3rd par­ty func­tion tha­t's out the­re, in the in­ter­ne­t, so­mewhe­re.


Contents © 2000-2023 Roberto Alsina