Thursday, July 14, 2016

Javascript is weirder than Perl

Found something weird in here https://github.com/happypoulp/redux-tutorial.git: a Javascript object/associative array declared without keys. First I thought it might be a fat-comma-is-just-a-comma situation like in Perl, but there were three elements between { and }. So I investigated.

If you thought that in Perl there are too many ways to do it, run this with ES6 enabled:

const bla = () => { console.log("ran bla") };
const gar = () => { console.log("ran gar") };
function asdf () {
    console.log("ran asdf");
}

const xxx = { bla, gar, asdf };

console.log(xxx);




for the impatient, this is the output
{ bla: [Function], gar: [Function], asdf: [Function: asdf] }


I did not expect that.

Wednesday, July 13, 2016

execute ES6 scripts with ease

with modules installed privately
mkdir my_tests

cd my_tests

# you need an npm project to install npm modules locally
npm init -y

npm install --save-dev babel-core babel-cli babel-preset-es2015

# let babel know what version you want to use
echo '{ "presets":["es2015"] } ' > .babelrc

# use the new "import" syntax; here I imported something from redux just to get it to fail
echo 'import { createStore } from "redux";' > t1.js

# this will fail 
node t1.js 

# this will not fail 
./node_modules/.bin/babel-node t1.js


with modules installed globally you don't need a npm project file
mkdir my_other_tests

cd my_other_tests

npm install -g babel-core babel-cli babel-preset-es2015

# specify the ES version in the command line or create a .babelrc file like above
babel-node --presets es2015 t1.js

Monday, July 11, 2016

linode migration and downgrade

Finally began to understand Webpack. No clue as to how Redux works; I can follow the instructions but they don't make sense yet. Will persist.

Went through all the sites I had on my public servers and removed all those I did not use any more. Then noticed I was offered to migrate my Linode VPS from Xen to KVM and did it, upgraded to 4GB of RAM for free, resized my disks without losing data and then downgraded the account to a 2GB of RAM account ... all in less than 60 minutes and without losing data. I am thinking of consolidating the servers and I know which one will stay.

Also found a MongoDB database with data for an old project I might revive. Upgraded MongoDB on my workstation, upgraded the Perl bindings (required a server upgrade, else testing was failing).

Tuesday, June 21, 2016

sabbatical

After a few intense months I am taking a sabbatical.

Started looking in depth into React and the node.js ecosystem, mostly because those months would have been less intense if I had more confidence I understand what React.js is about.

Also trying to find out why f...g Agile is a pain in the behind.

Sunday, June 5, 2016

tracking page loads on this blog

The blogger.com stats do not seem to make any sense lately, so I am attempting to so some tracking of my own. I uploaded a transparent one pixel image on one of my servers. To force the browsers to reload my transparent pixel I added this snippet right in the template after the <head> tag.

<script type="text/javascript">
  var tracker = new Image();
  tracker.src = "http://lunch-break.ro/000000-0.png?data=" + Date.now();
</script>

Seems to be working. Maybe I'll even discover that the information in the "Stats" section is correct.

Thursday, September 17, 2015

double encoding of UTF8 strings

Turns out I was focusing on the wrong leads. These strings became values in a hash which was run through JSON->encode before saving to db. What prompted the re-encoding was not the values of the hash, but the keys. These were string literals in my program which were not marked as UTF8. Perl looked at my keys, looked at my values, saw a mixed bag, and decided to run the whole thing through the shredder again, just to be on the safe side.

The solution was simple:
use utf8

Because my keys were source-code string literals, I want my source code to be UTF8. use utf8 assures that.

thanks to: http://perlgerl.com/2011/04/08/utf8-follies/

Monday, August 10, 2015

how to debug anonymous functions and coderefs in Perl 5

http://perldoc.perl.org/B/Deparse.html


use strict;
use warnings;
use B::Deparse;

sub debug_coderef {
    my $possibly_code = shift; 
    my $deparse = B::Deparse->new();
    if (ref $possibly_code && ref $possibly_code eq 'CODE') {
        print STDERR "CODEREF: ", $deparse->coderef2text($possibly_code), "\n";
    }  else {
        print STDERR "NOT A CODEREF: ", Dumper($possibly_code), "\n";
    }
}

debug_coderef(sub {print "a";});