2014-05-18

From blog posts to "html" to editable document

I received the following request: having a blog, I want to put every post altogether into a single document (a word-processor document), keeping just the title, the published date and the content. Can you help me?

I did as follow.
  • Retrieve the full atom feed of the blog… Since the blog was hosted at blogspot, this link was helpful. But I had to add  “?max-results=500” to the url, since otherwise it stops at 50 posts.
  • Now, it is nothing but an xml, so a proper XSLT should be enough. And in fact… I have built upon this, removing everything I didn't need and adding the published date — the date, then, was the only reason for a post processing, since I had no idea how to transform it as I wanted, therefore I have put it raw (almost raw, indeed) into the output html (generated by xsltproc), and then…
  • I wrote few lines of Perl to transform every date from YYYYMMDD to “Weekday name, DD Month Name YYYY” in the generated html;
  • Loaded the html into LibreOffice Writer, then exported to odt.
The result is not perfect, but mainly it's the content's fault, for it is sometimes from a Microsoft Office text (i.e. the entry was written in Microsoft Word, then copy-pasted in the blogger text editor area).

Just to keep this post longer than it could be, here the few lines of Perl code I wrote to reinterpret the dates.
#! /usr/bin/perl
use strict;
while (<>) {
    if (/##(\d{8})##/) {
      my $r = `LC_TIME="it_IT.utf8" date -d$1 +"%A %d %B %Y"`;
      s/##\d{8}##/$r/;
    }
    print $_;
}
In the generated html, the sequence ## was used to mark the date, extracted as YYYYMMDD (using properly substring). I had to set LC_TIME since I am used to set my locale to en_GB.utf8 (I try to keep my system consistent about the language and avoid the mixture that happens when you use locale-aware and locale-unaware softwares), but I needed italian names for week days and months.

Simply silly, but now this post can come to an end. (No, not yet: why do you ignore the export feature? since I have no access to the blog indeed, but I was able to ask for the necessary blogID).


2014-05-10

Particles of coroutines

Following the very same idea of the previous post, I've implemented the same stuff for x86. No worry about details — I am not a x86 fan and lover — except that there are few tests I've not done in the m68k version (namely the latter assumed the compressed stream is not corrupted). But it's just noise, not worth considering.

Intel x86 assembly instructions suck, but I admit I don't know it very well and likely I haven't used some cool feature and I don't know any cool feature which, once I'll know it, will make my mind change. Rants end.

Since x86 has not too many registers, and since I've used C library (compiled with nasm, linked with gcc/ld) and x86 calling conventions apply, and since I wanted to avoid special purpose registers (ECX, ESI, EDI…) as “global” variable storage, there are extra push and pop to keep values between calls to library functions, while each coroutine assumes also that the register it's interested in, are not trashed.

The register EBP can be used for “shared” (or global) storage; in fact, I've used it to store the pointer to the token buffer, and the “continuation” address.

The yield/resume feature is done with this code (kept into a macro):

    mov ebx,[ebp]
    mov dword [ebp],$+9
    jmp ebx

First the next address is put into EBX, then it's replaced by the address of the instruction following the jump, then the jump to the address in EBX is performed.

That's all. Readers interested in the whole code can find it at this gist, but I doubt it's worth it. It'd be far more interesting to study an implementation that could be used for really, as the result of compiling high level language code.

Different calling conventions can make it easier, but then you need extra code to call external functions — sticking to common C calling convention on a system is the key to access a lot of code without the need for any kind of glue — almost. Rants end, again; guess when they began.

This may work fine for two coroutines. Let's reason about a third coroutine. Does it work? No. If you need to create another cooperation, e.g. between the parser which extracts tokens (a “lexical scanner” indeed) and a grammar parser (i.e. a parser), you'll be fucked up.

E.g. our parser at some point, instead of got_token, need to give control to another routine, namely the one which understands the grammar. Thus, for each coroutine pair we need a “slot” similar to the one in [ebp]. A theoretical JCONT macro would be more complex, and take into account at least the coroutine we want to give control to. E.g.

 parse:
     JCONT   parse,getc
     test    eax,eax
     ...
 .wend:
     mov     eax,TWORD
     ; the grammar_parser'd like to have ptr to buffer too
     ; ... but this could be a global, as it is
     JCONT   parse,grammar_parser
     ...

If there's a hashmap for each coroutine, then we need to initialize it first, and the somewhere likely we could need a reset too. The macro could look, in pseudocode, something like

    get_slot_of    %2
    mov            ebx,[ebp]
    mov            dword [ebp],$+9
    store_slot_for %1
    jmp            ebx

Just an idea, at a very late hour.

Crumbs of coroutines

Playing with handmade lexical scanners and parsers you soon discover how cool it would be if you could use coroutines, but unfortunately language like C and C++ haven't such a feature, nor they have a general gear to manage continuations — even though setjmp/longjmp can be thought as what you need to begin, but they maybe do not bring you to the end, not always at least.

2014-04-13

Bison

Today I decided to bite something of Bison. In my far past I had already experimented (though in a strong yacc fashion) with it, and by this I mean I have read few quick and simple tutorials — nothing more than the omnipresent infix calculator with frills, which by the way is also the main example in the manual, with enhancements found in mfcalc (hopefully updated for the future). To me the matter (using the tool as well as understanding bits of its inner working) is vast, deep and really interesting, but this is also the reason why I was always pushed towards stack-based languages in my experimenting with this world. Stack-based languages can polish complexity, largely undesidered in toy languages. But in the very same time it makes these toy languages almost alien. Stack-based or not, beyond a point a computer language can't miss a tool like Bison, unless you want to make a lot of craft work by yourself — there could be good reasons to do so, but I can't imagine one that fits the world of a toy language.

So, maybe only to make a noise and a vibration here and there, here's the result and, ladies and gentlemen, it is … hold on tight … the omnipresent basic infix calculator! More or less. In fact, you can assign the result of an expression to a symbol, and use it later. The lexical scanner reads only from standard input, and … again hold on tight … you can write 0.5a instead of 0.5*a! I admit it, MetaFONT book was very influential over me, and so it was the MetaFONT language, which is by heart the only language I know that accepts a more natural notation for the multiplication. Think about it: 2a is a syntactic error in the vast majority of computer programming languages, at least among the most known. Even languages thought to handle math stuffs, I am thinking about R and Octave mainly (and also Maxima!), disallow this syntactic sugar. Nothing bad, but my very simply infix calculator makes it possible! This is an incredible feature!! (Irony here, of course).

If you are interested in these basic things for beginners and in a complete, messed up, but working example to play on, you can take it from a gist of mine. I have avoided full C++ style (other examples show the “driver class” C++ approach), just used C++ where it turns to be ease (STL map class, since for the rest C would have sufficed). The next idea will be similar, maybe, and it will be about lambda. Indeed, since easter is near, I have started these tests in order to build a toy tool to play with the Church lambda calculus (shame on you, it already exists cool Xyz you can use very profitably! Ok, that's not my plan to be profitable or whatever, I am just playing to keep my last two survivor neurons almost alive), but I suppose I will be late, as usual.

Final note: on gist, if you assign the name for the file, you can't use the highlight you want. So, since .yy is an unknown extension, it made me impossible to select C++ highlight. We live in a world dominated by extensions rather than by users' will.

2014-02-22

Plans for Golfrun

The C Golfrun interpreter is stuck, as it was before. I think there's no reason to keep the idea of a full formalization of the language. I still want to rewrite it in C++11, but I don't want to find myself trying to inflate this or that feature of the language for the sake of it. Rather, I will use bits of C++11 when and if they fit; otherwise, plain C++, and even not too much C++ized i.e., it will be C++ for the STL, rather than for heavy Object Orientation; likely STL will be just a cozy replacement for the glib, and that'll be all.

In the meantime the language drifted and diverged from GolfScript in my mind. And from current Golfrun too! The changes I thought about were
  • no comments: code golfing can lack comments; and if you need them, a string that then you will drop from the stack can be used instead. There's a difference of course, since the string is digested at the lexical analyzer level while a comment is consumed by the parser and never results in a token. In contrast with a common good practice, the rule is: avoid comments! The change makes the symbol # available for other magic;
  • strings: use only "; strings without escape characters interpretation can be added through another syntax, like _"string". Another symbol, ', will be available;
  • case unsensitive symbols: case change can be used to separate symbols; e.g. thisIS has two tokens, THIS and IS. It could be useful to save some extra space.  A sequence like ThIs will produce 4 tokes: T, H, I, S.
  • maybe, rational numbers: a syntax like 0r13/3 could be used. A number like 0.123 would be written as 0r123/100, which has length 9 against 5. Cumbersome, and bad for code golfing in few strokes. Maybe I should accept the fact that a new symbol must be exploited for this; e.g. 0'123. No, I don't want to make it impossible to duplicate a number without adding extra space(s), e.g. 12.13++ must leave 37 on stack and not give a stack underflow instead. So maybe the dup must become ' and the dot must be back to its common meaning as part of syntax for numbers.
    • Rather the ' could be used as part of the syntax to introduce some kind of literals, e.g. '0.123 (where the dot is the decimal separator)
  • underscore can't be part of a symbol anymore, so hey_ and _hey will result both in two symbol tokens. But if followed by a number, it will be the unary minus, as in J; so you can write 5_5+ instead of 5 -5+ and the minus will be only a dyadic operator.
  • assignment syntax can't be used to assign to single character non-alphabetic symbols, e.g. {5}:* won't work. Instead, the syntax could be used to mean some sort of symbol modifier, i.e. interpreted as the token :*. The longer assignment syntax will be used (to be defined; it will be similar to the lookup system service) 
Other syntax changes were already made, in particular those allowing to feed the stack with complex numbers and to write the colon symbol (simply doubling it). Data types are or will be:
  • numbers
    • integers (arbitrary precision using the GNU Multiprecision arithmetic library)
    • complex integers, i.e. there's a real (integer) part and an imaginary (integer) part
    • rationals (complex or not), maybe
  • strings (of bytes; not C strings, so that they can contain zero bytes as well)
  • blocks, they are strings after all, but with a different syntax and can trigger different behaviour of operators
  • arrays (collection of eterogeneous objects)
  • hashmaps (keys are only strings; these strings can be the string representation of an object)
There will be 2 stacks: operands stack, and context stack. The context stack "contains" the operands stack and the symbol table. Currently, Golfrun can restore the original symbol table using a specific “system service”. This won't be needed anymore and the mechanisms of the context can be used instead. The context provides basically local variables capabilities and local stack capabilities.

Some extra built-ins will be kept, e.g.
  • dd (as 2dup in Forth); shorter synonym: D
  • sys (“system service”); single symbol ":" (written :: in the syntax) as synonym
  • stack (debug purpose mainly: dump the stack => stack associated with the topmost context)
  • sqrt (now it could return rational numbers approximating the result); shorter synonym: ST.
  • type (return the type of the object on the stack, without dropping it; shorter synonym: T
Others, added: e.g. 2swap (Forth) as SS, and rotation of more than 3 objects (@), as R.

A lot of symbols are now "free", and others need to have a defined behaviour with some kind of arguments. Coercion/implicit conversions need a clear, easy to remember rule.

An example of unclear behaviour is: [97 98]""+1/ will result in an array with two single character strings, "a" and "b". How do you go back? Something more elaborated as {(\;}%. This means that ( (or )) over a string will behave as if the string is an array of integers, except that the "head" (or "tail") is pushed as such, while the string remains a string. This is the same in GolfScript, where "ab") will result in two objects on stack, the string "a" and the integer 98. To get the "head" or the "tail" as single character, we need some extra work. In the eye of some operators, a string is an array of integers. Which is not wrong, but sometimes the information of the original interepretation is lost and coercion makes sense only if I am going to sum it with an integer. Something like Erlang $a could be desiderable (not using $  but something else instead).

Ok, I think it's time I start to code, without needing to have all this already planned in details, otherwise I won't start it again anymore.

2013-12-31

Am I a human?

Indeed, sometimes I have doubts about it.

Anyway, Happy New 2014.

2013-10-03

Github. A note

I had (and now I have again) a github account. My intention was to move Golfrun C++11 implementation there, but indeed I've never started it, nor I've finished plain C implementation, which is a mess. I had used only the gist, and there's a couple of articles here linking to gists. But they disappeared, I suppose since my account was “dormient”. Now I have created it again, but those gists are gone. I think I should rewrite them, but I am too lazy these days (months? years?). A lesson: figure if you can trust (free) clouds. I am joking, of course.

Edit

Indeed, gists are back, but now they think I am not a human… I think I'll be human again in 2014.

2013-09-29

Debian Wheezy, GNOME 3 and others small things


When my Ubuntu GNU/Linux distro received the "alert" that it wasn't supported anymore and the upgrade failed, instead of finding out why, first I tried to transform the distro into a LTS one (not totally successful because I had to downgrade too many packages), then I decided to compile what I "needed"; but my final thought is that it is not a good idea mixing automatically installed packages and packages compiled by you (out of the APT world), especially if you begin updating libs which many other programs rely on, or if you compile the last version of a program that needs the last version of a "core" lib. To make it short, the system started to behave inconsistently (maybe since I circumvented some dependency…). Time for a brand new installation.

2013-09-07

Pick a framework

I am paying for a website I do not update since I started paying for it. The reason why I decided to purchase the domain and the web space was that another site was gently hosting some content of mine, but that site was going to go down soon (and in fact, currently is). So I needed some room for my old content, but I also wanted to do something modern, maybe cool, to experiment with several technologies (?). Thus, instead of copy-pasting my old site into the new space, I decided to carve my own custom CMS from scratch. It soon turned out to be a task beyond the quantity of my spare time, and my ability and my will too. I lost interest in it and in the same time decided to wait before to put the old content back, soon I will pick some cooked CMS or alike and inflate the old contents in it, I was saying to myself. But that "soon" became years. Since 2011 my site is simply dead (and it exists since 2011…!). Maybe like me (don't you hear my cavernous voice?)

I have renewed the fee until 2014, therefore I have to do something with it before that endline. If the aim is to host contents online, then creating a custom CMS is totally worthless. I like the idea that if the content of a site is great, then you don't need too much lights and fireworks, since people land on your site searching for the content you provide, and they end to be caught by it, despite of what it looks like — and of course I am not chasing the fame. I agree with this simple idea: a website is about its contents. It could be made even by plain HTML, for the sake of its hypertextual power, and be successful among the target niche (i.e. the two or three persons interested in that content). I am thinking about a site like Fravia's. But if I look to my own content, I see poor things. This blog contains cheap tech posts, simple sillyness, pointless speechs, and other few stuffs that hardly are worth a reading, like this very same post. This is supposed to be a "tech blog" about mainly computer related topics, but it is no more than "curiousity material for computer unsavvy". Moreover my research (I dare to call it so) flow is dried since at least 1 year. I am like a surfer surfing on a wave, a moment it's up, then you slip, gaining speed, and at last you are down waiting for the next wave. But each wave has its own peculiarities. The wave I am (more or less satisfactorily) surfing now is more about literature and politics, even if there are some hook in the computer world — but it's just because their are powerful tools you can use for several aims. The fact is, I am not using my spare time to program (though I do it, say, 8h/day, 5 days per week) as I did before. This is going to change, soon, or maybe later, the problem is exactly when, I say tomorrow, then I wake up and realize a whole year has flied away, and there's dust on several project, and on knowledge too, and on partners too, and on languages I was learning like Erlang. Currently, as said, I am more on other interests, but something started to seethe underneath. It begins with idea like the following: let's pick a framework and put anything on the site.

It seems a simple idea, but as usual I put my goals too far from where I am now, likely overstimating my current skills and the amount of spare time I am willing to consume for those goals.

Instead of creating something from scratch, the idea is to practice a framework like CakePHP. I picked it since it was the one I already knew a bit someway, but not enough. But the drift is lurking, and I am very prone to it, I am always drifting someway. The clear, fast, almost near goal to use CakePHP to develop something to give life to my site was going a little bit further. It starts with asking few questions, but the most important is: what kind of content do you want for your site? For my old content I don't need more than a directory listing, and something like a wiki or a blog, but for these I've chosen third party places like blogspot. So, I can't focus on the old content. The reason why I need a lights-and-fireworks site is indeed that my content sucks: i.e. nobody can be interested in it spontaneously. I have to add some spice, some seasoning, tasty sauces, to avoid people run away. Or rather I stick to simple directory listing, which works for so-called "nerds" and content-searcher. It'd be easy. But also boring to me. 

At first I had maybe just a problem: what kind of web application I need in order to present my old contents and likely to be able to add new one easily and swiftly? This is a great problem: saying I want to develop something is greatly silly: it seems the aim is not clear. And in fact, it is so! So I have to take a pencil and a paper, or other tools on the computer, and sketch the site, I know the contents I have, I need to imagine how I want to show them. Do I need just a showcase? I can add things later, maybe in the 2023, when a bloody world war (maybe nuclear) will be in progress, and I will be biologically dead. Questions that need to be answered, not necessarily in the order I write them:
  • What kind of content will you put on your site? I could be interested in many things, though how much time I spend on them depends on the wave,  and there are waves that haven't risen yet.
    • Graphic creations
      • 3D (Blender, POV-Ray, etc.)
      • 2D (GIMP, gfx tablet,  photos, generated by computer programs/simulations or drew by hand, etc.)
      • vector gfx (SVG, PostScript, Metafont/Post)
      • short films (link to youtube channel), in fieri
    • Music/noise creation
      • MIDI (composition, algorithmic composition etc.)
      • samples (Csound, etc.)
      • songs (likely link to other hosting sites)
      • articles about processes about "music" (another blog?)
    • Programming and computer related topics
      • desk/laptop (Amiga, GNU/Linux, ...etc.)
      • mobile (Android, Java, etc.)
      • articles (this blog?)
    • Writings (PDF + LaTeX/TeX / wiki content?)
      • Essays, lessons, articles, papers, slides (wide range topics)
      • Tales, novels, scripts
      • blogs (this one, the others, new one?)
    • Link collection / social
      • Linking with "streams" from social network like Diaspora, Twitter, Pump.io or alike
      • Linking with articles on external blogs
      • Bookmarks (delicious?)
      • links to github, sourceforge, bitbucket, wherever I have something hosted (few things, mostly crap)
    • Experimenting with web apps and services
      • social networks
      • rendezvous-point (f2f apps?) 
    • Advertising myself
      • who am I? what I do? what I've done?
  • What kind of technology do you want to use?
    • Currently I am bound to PHP+MySQL serverside. I don't want to make something that works on every browser, so I can stay on the edge of HTML5/CSS3 and Javascript without problems.
      • RAD PHP frameworks (which paradigm? MVC...?)
        • CakePHP?
        • Yii?
        • Symfony?
        • Others?
  • How do you think to show the contents? Can the user add their own? (No, but I'd like to experiment with OAuth and allow limited controlled access to some service, but I don't know which, clear, isn't it?)
    • No idea.
I thought to have found the right one in CakePHP, but then I've seen how many other there are out there, some are maybe "smaller", and therefore they can fit my need better. Or maybe not,... but there would be always time to add another framework in another dir!

Ok, now it's clear I should be studying CakePHP and planning the app in details (and in surface, I am going for the minimalism), instead of writing too many words like these. And my Android device is even waiting for some fresh original bytes to bite from me. It must wait. O and I have admit that such posts comes to life just to remember me that this blog exists! (While I am feeding the italian side blog, with a lot of posts, not technical one of course).

P.S. Forgot the only maybe meaningful part: the problem with RAD tools is that they are Rapid only if you know them, so, let us suppose, they will be Rapid the second time you develop using them; otherwise, they are not rapid. But how fast you can learn them, how steep is the learning curve? This may affect the choice. I started with CakePHP, but now I consider interesting Yii, but which one fits better my need? And so on, in a circular trip!