Installed Julia, just to take a look at it. (A filler article follows…)
Showing posts with label computer. Show all posts
Showing posts with label computer. Show all posts
2015-08-08
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:
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!
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.
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!
Labels:
blabbering,
cakephp,
computer,
controller,
crap,
death,
drifting,
hobby,
life,
mauropanigada.net,
model,
mvc,
mysql,
PHP,
view,
yii
2010-07-20
Syntax and efficiency in C
Time for a brand new post.
In my last job interview I was asked to write a function to copy a string. Thinking not about compactness, I wrote on the fly the following code
That of course works, but it is longer than the need (and by the way, it is not compliant with what standard says about real strcpy, but this is not interesting since making a standard-compliant function was not the point of the question).
As noticed by the person making the interview, such a copy can be written in one line. When I've finished the interview and went back with the mind to what I've said and what I could have said, I realized that I could have defended my on-the-fly implementation: it is clearer (isn't it?), it has the same efficiency of the "compact" version, being this one possible just because of the great flexibility of the C syntax... which is, however, a boomerang if abused.
Second thought. The "long" code is clearer. Maybe (usually, not using C compactness ability makes code clearer; but likely in this particular case the one-line version is even clearer). But, my doubt is now: is it really the same with respect to efficiency?
Let us first see how to "convert" the long version to the short one. First, post-increments can be done "in place".
Then, assignment can be put into the while:
And here's the trap. We don't need the final "terminator-missing fix". Apparently, the short version looks also more efficient. But if we unroll the loops, we have the same amount of assignments, of course. Moreover, the short version assign the terminator reading it from the source; this gives two memory access (one for reading from s, one for writing into d).
On the other hand, the long version, does not need the extra reading access to memory and can be optimized on many processor with a single instruction writing a byte constant (read at the instruction fetch time).
So, it seems that is is the opposite: long version is (slightly) more efficient!
Of course modern compilers' optimization can cancel this apparent advantage. But let's look what gcc does with the basic "implicit" optimization level.
The "short version" (S) x86 code (with added comments):
The "long version" (L) x86 code (with added comments)
The M marks instructions that do memory access; let's count only the in-loop instructions first. S has 8 memory access instrs in loops; L has 8 memory access instrs in loop but S has 3 "register" instrs in loop, while L has none. So for S we have 8+3 in loop, for L only 8.
In S, when the '\0' is reached, the whole 8+3 instruction are performed; then the jump is not taken (JT stands for Jump Taken most of the times). In L, when the '\0' is found, (2+2)+1 instructions are executed (2 M after the .L5 label, and 2 M after the conditional jump). In fact S performs all the "actions" of the C code (post-increments inclusive) in the while; but L does only the test on *s and the final termination of d. (This means also that if we access s and d in the S version, they point one char beyond '\0', while in the L version we do not increment them, since we exit the loop, so s and d will point to the '\0').
On modern processors it is hard to say which is really more efficient. Likely, the difference in performance is negligible. Moreover, optimizations done by the compilers may level down the difference, if any.
It is however worth noting that L version does not produce a so longer code (considering also loop unrolling), and it could be even more efficient than S version!
In my last job interview I was asked to write a function to copy a string. Thinking not about compactness, I wrote on the fly the following code
void strcpy(const char *s, char *d)
{
while( *s != '\0' ) {
*d = *s; s++; d++;
}
*d = '\0';
}
That of course works, but it is longer than the need (and by the way, it is not compliant with what standard says about real strcpy, but this is not interesting since making a standard-compliant function was not the point of the question).
As noticed by the person making the interview, such a copy can be written in one line. When I've finished the interview and went back with the mind to what I've said and what I could have said, I realized that I could have defended my on-the-fly implementation: it is clearer (isn't it?), it has the same efficiency of the "compact" version, being this one possible just because of the great flexibility of the C syntax... which is, however, a boomerang if abused.
Second thought. The "long" code is clearer. Maybe (usually, not using C compactness ability makes code clearer; but likely in this particular case the one-line version is even clearer). But, my doubt is now: is it really the same with respect to efficiency?
Let us first see how to "convert" the long version to the short one. First, post-increments can be done "in place".
*d++ = *s++;
Then, assignment can be put into the while:
while( (*d++ = *s++) != '\0' ) ;
And here's the trap. We don't need the final "terminator-missing fix". Apparently, the short version looks also more efficient. But if we unroll the loops, we have the same amount of assignments, of course. Moreover, the short version assign the terminator reading it from the source; this gives two memory access (one for reading from s, one for writing into d).
On the other hand, the long version, does not need the extra reading access to memory and can be optimized on many processor with a single instruction writing a byte constant (read at the instruction fetch time).
So, it seems that is is the opposite: long version is (slightly) more efficient!
Of course modern compilers' optimization can cancel this apparent advantage. But let's look what gcc does with the basic "implicit" optimization level.
The "short version" (S) x86 code (with added comments):
mstrcpy:
pushl %ebp # prolog
movl %esp, %ebp
.L2:
movl 8(%ebp), %eax # get s in eax M
movzbl (%eax), %edx # *s in edx (dl) M
movl 12(%ebp), %eax # get d in eax M
movb %dl, (%eax) # *d = *s (dl) M
movl 12(%ebp), %eax # M
movzbl (%eax), %eax # take char*d in eax M
testb %al, %al # I
setne %al # is not 0? in the same al I
addl $1, 12(%ebp) # these are the post M
addl $1, 8(%ebp) # increments of d and s M
testb %al, %al # check al I
jne .L2 # loop if not 0 ('\0') JT
popl %ebp # epilog
ret
The "long version" (L) x86 code (with added comments)
mstrcpy2:
pushl %ebp # prolog
movl %esp, %ebp
jmp .L5 # uncond. jump
.L6:
movl 8(%ebp), %eax # get s in eax M
movzbl (%eax), %edx # *s in edx (dl) M
movl 12(%ebp), %eax # get d in eax M
movb %dl, (%eax) # *d = *s M
addl $1, 12(%ebp) # d++ M
addl $1, 8(%ebp) # s++ M
.L5:
movl 8(%ebp), %eax # get s M
movzbl (%eax), %eax # *s in eax (al) M
testb %al, %al # I
jne .L6 # exec body if not 0 JT
movl 12(%ebp), %eax # get d M
movb $0, (%eax) # *d = '\0' M
popl %ebp # epilog
ret
The M marks instructions that do memory access; let's count only the in-loop instructions first. S has 8 memory access instrs in loops; L has 8 memory access instrs in loop but S has 3 "register" instrs in loop, while L has none. So for S we have 8+3 in loop, for L only 8.
In S, when the '\0' is reached, the whole 8+3 instruction are performed; then the jump is not taken (JT stands for Jump Taken most of the times). In L, when the '\0' is found, (2+2)+1 instructions are executed (2 M after the .L5 label, and 2 M after the conditional jump). In fact S performs all the "actions" of the C code (post-increments inclusive) in the while; but L does only the test on *s and the final termination of d. (This means also that if we access s and d in the S version, they point one char beyond '\0', while in the L version we do not increment them, since we exit the loop, so s and d will point to the '\0').
On modern processors it is hard to say which is really more efficient. Likely, the difference in performance is negligible. Moreover, optimizations done by the compilers may level down the difference, if any.
It is however worth noting that L version does not produce a so longer code (considering also loop unrolling), and it could be even more efficient than S version!
2010-03-30
One-liners and why to get it harder than it could be
Since I've updated kernel and X server, my computer became slower... new "softwares" require new hardware to do the same things. This is a fact that always upset me. Anyway, I abandoned KDE (unusable... and half-mixed KDE3-4!) and installed WindowMaker. I also abandoned full graphics file-manager (avoid the loading of Qt libs and KDE services, being used to use Konqueror, uncomparable to Dolphin), tried lightweight Gtk file-managers but none satisfied me. I used midnight commander for a while and tried also gnu-git ... But now mainly I use simply the command line, in a simple xterm of course...
So it happens that something easy and fast with a filemanager becomes a little bit harder. But still the command line, with all GNU tools around and interpreters of languages like perl, is powerful.
When I download pictures from the cam, I need renaming them according to EXIF date; so I've created a script (exifrename.sh), which uses exif the extract the date and rename the object the way I want. I use it like this
The pipe is because the script outputs the commands rather than executing them (it could be useful to check everything's fine).
My cam creates a directory for each day, like NUMcanon where NUM is a number not related to the day. What I want is to copy just some days, not all, into the local hard disk and in the same time I want to strip the "canon" part. It would be easier maybe to copy the dirs and then rename them. But less fun for me. So what I do is
Ok not so funny but useful to... Recently I had to convert several scattered .doc (alas Microsoft stuff) into HTML, I've used this
As last example, a "oneliner" to read FASTA headers / sequences and sort them (just the header). Don't ask why, I've found the request on Yahoo Answer.
A perl guru can make surely better (and what about perl6?), anyway the solution worked .
Now we discover that there are things that can't be done simply by a graphics interface but... These examples are taken directly from the history of the shell; there are other two similar examples. The history has 1045 entries. Of these, 1039 are mainly simple commands like cd, rm, cp, ls, mkdir (and sometimes mount and umount). Actions that would have been a lot easier using a graphical file manager!
So the problem said at the beginning is back: I need keeping running few processes/programs. ... I'm going to hate the computer business, because I can't see a reason why to do the same thing I did before now I need more memory or a more powerful processor... or downgrading the software (meaning I should compile by myself a lot of codes since oldest packaged pre-compiled programs are already too recent, or there are too many dependencies issues I don't want to cope with!)
I hope things will be better, but looking around I see things indeed get worse: we can say Berlusconi is the winner, and this means there's no hope to change for Italy (it seems OT, but is not...).
Ah, the exifrename.sh code:
So it happens that something easy and fast with a filemanager becomes a little bit harder. But still the command line, with all GNU tools around and interpreters of languages like perl, is powerful.
When I download pictures from the cam, I need renaming them according to EXIF date; so I've created a script (exifrename.sh), which uses exif the extract the date and rename the object the way I want. I use it like this
exifrename.sh *.jpg |bash
The pipe is because the script outputs the commands rather than executing them (it could be useful to check everything's fine).
My cam creates a directory for each day, like NUMcanon where NUM is a number not related to the day. What I want is to copy just some days, not all, into the local hard disk and in the same time I want to strip the "canon" part. It would be easier maybe to copy the dirs and then rename them. But less fun for me. So what I do is
for el in 101 102 105 ; do mkdir $el ;
pushd $el ;
cp -r /media/usbpen/dcim/${el}canon/* . ;
popd ; done
Ok not so funny but useful to... Recently I had to convert several scattered .doc (alas Microsoft stuff) into HTML, I've used this
find . -iname "*.doc" |
(
while read line;
do wvHtml "$line" "${line%.doc}.html ; done
)
As last example, a "oneliner" to read FASTA headers / sequences and sort them (just the header). Don't ask why, I've found the request on Yahoo Answer.
perl -e '%p=();
while(<>) {
if (/^>/) {
s/^>//; chomp;
foreach $v (split("\x01", $_)) {
$p{$v} = 1 if !exists $p{$v} ;
}
}
}
print join(" ", sort keys %p)' <fasta.txt
A perl guru can make surely better (and what about perl6?), anyway the solution worked .
Now we discover that there are things that can't be done simply by a graphics interface but... These examples are taken directly from the history of the shell; there are other two similar examples. The history has 1045 entries. Of these, 1039 are mainly simple commands like cd, rm, cp, ls, mkdir (and sometimes mount and umount). Actions that would have been a lot easier using a graphical file manager!
So the problem said at the beginning is back: I need keeping running few processes/programs. ... I'm going to hate the computer business, because I can't see a reason why to do the same thing I did before now I need more memory or a more powerful processor... or downgrading the software (meaning I should compile by myself a lot of codes since oldest packaged pre-compiled programs are already too recent, or there are too many dependencies issues I don't want to cope with!)
I hope things will be better, but looking around I see things indeed get worse: we can say Berlusconi is the winner, and this means there's no hope to change for Italy (it seems OT, but is not...).
Ah, the exifrename.sh code:
for el in "$@"; do
pathpart=$( dirname "$el" )
namepart=$( basename "$el" )
data=$( exif "$el" |egrep "Date and Time \(orig" \
|sed -e 's/^.*|\([0-9]\{4\}\):\([0-9][0-9]\):\([0-9][0-9]\) \([0-9][0-9]\):\([0-9][0-9]\):.*$/\1\2\3-\4\5/' )
echo "mv \"$el\" \"$pathpart/$data-$namepart\""
done
Subscribe to:
Posts (Atom)