Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Locche: The Untouchable Pastebin


I did ma­na­ge to wri­te this thin­g, sort of, in 2 hour­s. You can see it in ac­tion he­re: http://­tin­yur­l.­co­m/­loc­che1 and it has so­me ra­ther unu­sual fea­tu­res :-)

  • You can ha­­ck Lo­c­­che in­­si­­de Lo­c­­che.

  • You can go ba­­ck to pre­­vious ve­r­­sions of the text (or Lo­c­­che) from any co­­­py of Lo­c­­che

  • It uses no se­r­­ver wha­­tsoe­­ver (o­­­ther than a CDN to get JS and co­­­de­­mi­­rro­­­r)

Wha­t's mis­sin­g?

  • Making it pre­­tty

  • Sho­r­­ten his­­to­­­ry URLs so the si­­ze does­n't ex­­plo­­­de so mu­­ch

  • Fix han­d­­ling of ' " and pro­­­ba­­bly other cha­­ra­c­­ters in the text

  • Do­­­cu­­ment it

But I thi­nk it's cool. Be­low is the li­ve­blog of how it was do­ne. Ha­ve fun ma­tching it wi­th the co­m­mit his­to­ry at http­s://­gi­thu­b.­co­m/­ral­si­na/­loc­che

I am going to li­ve-­co­de a pas­te­bi­n, wi­th a few twis­ts.

It's ca­lled Loc­che, in ho­nour of Ni­co­lino Loc­che, The Un­tou­cha­ble.

This pa­ge wi­ll up­da­te eve­ry 5 mi­nu­tes un­til I am do­ne, or 2 hours ha­ve elap­se­d.


Idea: A rea­lly ser­ver­le­ss pas­te­bi­n. AL­ready created the gi­thub re­po and am cu­rren­tly in the fea­tu­re plan­ning sta­ge (le­t's gi­ve it 10 mi­nu­tes).

I want it to be what Shor­tly clai­ms to be. But le­t's try to take it to the next le­ve­l.

It wi­ll not be as fea­tu­re­ful as Ki­li­nk (be­cau­se I ha­ve on­ly 2 hour­s), but it should be use­ful enou­gh.

So, fea­tu­res:

  • Ni­­ce edi­­tor (co­­­de­­mi­­rro­­­r?)

  • Se­r­­ve­r­­le­ss (da­­ta UR­L­s)

  • Se­­l­­f-u­­p­­da­­ting (whoa)

  • Ve­r­­sio­­­ned pa­s­­te­­bins (whoa^2)

I do­n't ex­pect I wi­ll get to all of the­m, bu­t... le­t's tr­y.


So, this wi­ll in­vol­ve JS. Le­t's use JQue­r­y, and Co­de­mi­rror for the edi­to­r. GOod thin­g: they are bo­th hos­ted in CD­N­s. js­De­li­vr has the awe­so­me fea­tu­re of just gi­ving me a chunk of HT­ML I can co­p­y-­pas­te.


So, how does co­de­mi­rror wo­rk? Le­t's fi­gu­re that out and fi­nish the 1st dra­ft of the UI.


I ha­ve a pa­the­tic 22-­li­ne pa­ge sho­wing an edi­tor and a bu­tto­n. Tha­t's ok, most of this is going on in my head ri­ght now ;-)


Now the bu­tto­n, when cli­cke­d, wi­ll show the con­ten­ts of the edi­to­r. This is 30% do­ne, in a wa­y.


So, the raw con­tent of loc­­ml is he­re. that is going to co­me handy soon (as in, when I find out how JQue­ry le­ts you do­wn­load a fi­le).


Pi­ty, gi­thub on­ly pu­ts raw fi­les on http­s, and I can't load it from a lo­cal fi­le, and the sa­me ha­ppens for http. Boo. Ok, mo­ving on.


No­te: I ha­ve just wri­tten what see­ms to be a me­mo­ry bomb for Ch­ro­miu­m, and I was not even tr­yin­g.


I just found a re­so­na­ble way to keep a co­py of the pa­ge's HT­ML in­si­de the HT­M­L. So, no need to fe­tch it from so­mewhe­re el­se (good)


I can now save the edi­to­r's con­ten­ts in­si­de a tex­ta­rea so that the con­ten­ts of the tex­ta­rea are ... a co­py of loc­che but wi­th the edi­to­r's da­ta in­si­de it.


And no­w, ini­tia­li­ze the edi­tor wi­th the ri­ght va­lue, and hi­de the tex­ta­rea. No­w, I need to fi­gu­re out how to crea­te a da­ta URL from JS.


No­w, Loc­che can se­l­f-­mo­di­fy itself on­ce to ha­ve the edi­to­r's con­ten­ts in its HT­ML and then fo­rward itself to the new ver­sio­n.


Wi­th a re­gexp I can make the subs­ti­tu­tion wo­rk for mo­re than one ge­ne­ra­tio­n.

So, what ha­ve we got no­w?

  • You start wi­­th lo­c­­che.h­t­­ml

  • You edit the tex­­t, and cli­­ck "Pa­s­­te!"

  • This wi­­ll crea­­te a new ge­­ne­­ra­­tion of Lo­c­­che, whe­­re in­s­­tead of "W­­RI­­TE HE­­RE" the edi­­tor wi­­ll co­n­­tain what you ty­­pe­­d.

  • That pa­­ge wi­­ll be tu­r­­ned in­­to a da­­ta URL

  • You get sent to that da­­ta URL

So, you can keep as many ver­sions of your pas­te­bin as you wan­t, just re­mem­ber the chan­ging URLs ;-)


Added a li­nk to the pre­vious UR­L. This means that any gi­ven co­py of Loc­che con­tains all the pre­vious ver­sions of the pas­te­bi­n, nes­ted like a Ma­trios­hka. Of cour­se that means things ex­plo­de a bit in si­ze ;-)


It can now hand­le mul­ti­li­ne da­ta, but it breaks if you use "'" and adds so­me dou­ble quo­tes around stu­ff. I'd say good enou­gh for no­w. Al­mos­t. Le­t's make it ha­cka­ble by the re­ci­pien­t.


Do­ne, mo­re or le­ss in ti­me. The end re­sult is, of cour­se, he­re: http://­tin­yur­l.­co­m/­loc­che1

And he­re is the ori­gi­na­l, the un­tou­cha­ble Loc­che:

ddevine / 2013-10-11 02:35:

It'd be cool to have for collaborative editing.

Contents © 2000-2024 Roberto Alsina