Best smartwatch ever

July 30th, 2016, 19:52 +0200 (KI)

Right now I’m wearing in my wrist best smartwatch ever manufactured. This superbeast watch has features beating down all other competing smart watches.

  • battery life around 10 years (other smart watches average into 0.0003 years)
  • knows time around the world in 40 different timezones
  • Intelligent 5 alarms per day (yes intelligent, I set them up myself)
  • can count time (useful)
  • can count time up with lap times (super useful)
  • has backlight (yep, useful)
  • super lightweight but still very stylish
  • 200M water resistant (very useful)
  • very durable (useful)

What else one would need from smartwatch. Battery life itself is real killer feature

References:

Trying to like angularjs 2

July 11th, 2016, 10:41 +0200 (KI)

Trying to make angularjs 2 work, and it’s failing miserably in rails.

  • Trying to make babel and typescript modules to co-operate (since part of the project is written with es6). FAIL
  • Referencing ts/es6 modules from typescript module. FAIL
    • HACK to workaround
    • ///<reference path="xxx.es6" >
  • Battling between different “define” variants (interestingly various incompatible “define” variants exist…). FAIL
  • AMD modules generated without names. FAIL
    • HACK to workaround:
    • ///<amd-module name='dirx/moduley'>
    • It seems that making files to be “.es6.ts” and using compile options to produce ES6 works better than AMD (which fails miserably due to different “define” standards).
    • Typescript::Rails::Compiler.default_options = [
        '--target', 'ES6',
      #  '--noImplicitAny',
        '--isolatedModules',
        '--noResolve',
      #  '--module', 'amd',
        ]

    So far haven’t got even as far as trying actual angularjs, since even basic plain typescript compiling fails to work as expected. Based into this is hard to like angularjs 2 if co-operation with other modules and even setting up basic environment is so much hassle.

    I would call this “climbing ass first to tree” design.

    Continuing experimenting… If I manage to get get babel and typescript to co-operate and even compile basic module dependencies, then I might even reach actual goal; trying out angularjs 2….

    Starting to seem that angularjs2 is not worth of the effort. Too bad, since angularjs1 was decent framework. It seems that angularjs2 is designed to not co-operate with any backend, but assume that whole frontend and backend live in same land. That is however, truly invalid assumption, since proper frameworks are designed to work in different environments. Thus integration with rails assets pipeline is mandatory feature.

    Update 30.7.2016

    Re-investigating @angular RC4 packaging.

    • bundles: Contain some “UMD” packaged angular2 libraries. So far this was most succesful attempt, but still failing
    • esm: To ensure that building ES6 modules will not work, angular2 is deciding to use “.js” extension in ES6 modules, making impossible for build logic to know which files are normal JS files and which ones are ES6 files. Thus failure so far
    • plain: Mix of typescript/undeciphered packaging format. Not yet resolved how to utilize these; need investigation

    So no progress yet, while angular 1 was dead simple and it just worked, angular 2 is seemingly decidedly difficult to use.

    find vendor/assets/javascripts/@angular-2.0.0-rc.4/ -name *.js | xargs rename .js .es6

New domain

May 22nd, 2015, 13:13 +0200 (KI)

Finally, after idling in the topic for a long-long time, I finally registered my own domain ikari.fi.

So new main site is http://www.ikari.fi

However, this blog is still residing, at least for a while, in old address due to necessity of doing additional database migrations and such to make WordPress to co-operate with site name change.

Refererences:

Flying with new wings

April 26th, 2015, 10:48 +0200 (KI)

Okey, today it’s time to see how this site keeps up via nginx instead of apache. So far so good, at least almost everything seems to still work as expected.

In switchover, getting nginx + passenger + rails to work took some effort, but this was still reasonably easy. However, bigger trouble was getting this WordPress installation to co-operate with nginx. I believe it would have been trivial but since I’m using multisite setup, it made life more complicated. Took for a while to get configuration to work (based configuration mostly into “How To Configure Single and Multiple WordPress Site Settings with Nginx“. However, this seems to work now in the end.

Remaining issues

  • Favicons seem to leak from virtual site to another
  • WordPress automatic upgrade logic not working
  • Didn’t migrate all virtual sites; with consideration that “I won’t need them right now”

Also, while Rails configuration logic was now much less hassle than with apache, trouble with WordPress triggered negative counter balance.

Troubleshooting

Nokogiri + Linux => trouble?

April 20th, 2015, 14:55 +0200 (KI)

Nokogiri gem version 1.6.x has been a bit problematic in Linux, since by default it just fails to install. And only workaround for it has been to use 1.5.x version instead. Now recently I hit the trouble, since another gem required at least version 1.6 of nokogiri, so I didn’t any longer have option to avoid resolving the issue.

After a bit of googling fix was easy. Just need to explicitly state for nokogiri to use system libraries.

~/.profile

export NOKOGIRI_USE_SYSTEM_LIBRARIES=1

And in bash

. ~/.profile
bundle install

Praise yourself – test yourself

April 20th, 2015, 12:49 +0200 (KI)

Finally, after a while I started applying into development projects some automated tests using Travis CI. Thanks to Travic CI documentation integration of projects was rather painless.

So far following projects are running in Travis CI:

In both of these projects I needed to take advantage of Travis features. Namely I needed to utilize gemfile feature in both. In additona in ngannotate-rails project it was necessary to opt also for build matrix in order to test gem functionality with both sprockets 2.x and 3.x versions.

Walking in the assets land

April 11th, 2015, 21:35 +0200 (KI)

Welcome daisy!

Setup done earlier for Apache2 + Rails wasn’t yet very optimal. This fact was neatly indicated by google pagepeed index tools. Luckily few fixes are rather easy to apply.

Assets not compressed
Ups, this is triviality, I had forgotten to copy relevant caching logic config when setting up new virtual host config.

/etc/apache2/v.hosts.d/host.kari.dy.fi.conf

# enable compression for all relevant assets
  <Location />
    # normal web pages
    AddOutputFilterByType DEFLATE text/html
    # material icons and such
    AddOutputFilterByType DEFLATE image/svg+xml
    # XHR calls
    AddOutputFilterByType DEFLATE application/json

    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
    # Don't compress images
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
  </Location>

Notice that compression is not applied to all possible types. Reason for this lies ahead in the road, namely in the logic of dealing pre-created “.gz” files by rails. In other words this is a bit hacky way of solving conflict arising with “js.gz” and “css.gz” matching.

Thumbnails not cached
Hmm… need to setup expiration when serving assets via “send_file”.

class ThumbController
  def show
    ...
    response.headers["Expires"] = CGI.rfc1123_date(Time.now + 365.days)
    send_file ...
  end
end

Assets not cached properly
Trickier, apache2 + passenger + rails are not playing neatly together. Luckily this is not new problem and solution was readily available via apache conf for Rails asset pipeline.

First of all was necessary to enable “headers” module for apache2, since seemingly it’s not enabled by default.

# Rails finger-printed assets, make them cached forever.
  # Try only match if the asset actually has a fingerprint in it.
  <LocationMatch "^/assets/.*-[0-9a-f]{32}.*$">
    Header unset ETag
    FileETag None
    # RFC says only cache for 1 year
    ExpiresActive On
    ExpiresDefault "access plus 1 year"
  </LocationMatch>

Pregenerated .gz files are not utilized for assets
Would be practical that web server would be able to directly server .gz -files generated by rails assets pipeline.

# Let apache serve the pre-compiled .gz version of static assets,
  # if available, and the user-agent can handle it. Set all headers
  # correctly when doing so.
  #
  # SOMEWHAT EXPERIMENTAL. If you think it's causing problems,
  # just remove the following three LocationMatch.
  <LocationMatch "^/assets/.*-[0-9a-f]{32}.*\.(css|js)$">
    RewriteEngine on

    # Make sure the browser supports gzip encoding before we send it,
    # and that we have a precompiled .gz version.
    RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b
    RewriteCond %{REQUEST_FILENAME}.gz -s
    RewriteRule ^(.+)$ $1.gz
  </LocationMatch>

  # Make sure Content-Type is set for 'real' type, not gzip,
  # and Content-Encoding is there to tell browser it needs to
  # unzip to get real type.
  #
  # Make sure Vary header is set; while apache docs suggest it
  # ought to be set automatically by our RewriteCond that uses an HTTP
  # header, does not seem to be reliably working.
  <LocationMatch "^/assets/.*-[0-9a-f]{32}.*\.css\.gz$">
    ForceType text/css
    Header set Content-Encoding gzip
    Header add Vary Accept-Encoding
  </LocationMatch>
  <LocationMatch "^/assets/.*-[0-9a-f]{32}.*\.js\.gz$">
    ForceType application/javascript
    Header set Content-Encoding gzip
    Header add Vary Accept-Encoding
  </LocationMatch>

As you can see, logic is not dealing all possible cases properly (especially it’s not dealing bootstrap glyphfonts case). However, point here was to make some incremental improvement, and that goal should be now reached. Work what server needs to do to serve common resource cases should be now decreased. That said, I feel that this solution is still imperfect and requires further iteration. Additionally this struggle to get such basic logic to work causes consideration if host web server could be switched into nginx instead.

Tuning up apache2 + passenger

March 30th, 2015, 20:36 +0200 (KI)

Todays topic to is tuneup a bit more server what was setup earlier.

Goal is to,

  • Improve logic for redeploy, thus to avoid breaking running server when doing new deploy
  • Remove dependency into private user account, but use instead account specific to this deploy only
  • To use server instance specific ruby version instead of globally installed OS default ruby version

1) Make my dreams true, aka. use separate release directory via symlink

Cleanup server directory structure

cd /home/www/virtual/host.kari.dy.fi
mkdir release_20150330
mv * release_20150330
mv .* release_20150330
ln -s release_20150330 current

/etc/apache/vhosts.d/host.kari.dy.fi.conf
Update config

<VirtualHost *:80>
  ServerName host.kari.dy.fi
  # !!! Be sure to point DocumentRoot to 'public'!
  DocumentRoot /home/www/virtual/host.kari.dy.fi/current/public

  # if not specified, the global error log is used
  ErrorLog /var/log/apache2/host.kari.dy.fi-error_log
  CustomLog /var/log/apache2/host.kari.dy.fi-access_log combined

  # to allow symbolic link for server release
  <Directory /home/www/virtual/host.kari.dy.fi>
    Options FollowSymLinks
  </Directory>

  <Directory /home/www/virtual/host.kari.dy.fi/current/public>
    # This relaxes Apache security settings.
    AllowOverride all
    # MultiViews must be turned off.
    Options -MultiViews
    # Uncomment this if you're on Apache >= 2.4:
    Require all granted
  </Directory>
 </VirtualHost>

2) Get of my lawn, aka. use different user

adduser rails
/home/www/virtual
chown -R rails host.kari.dy.fi

okey, server is going to broken at this point, and will be fixed into running stage in step (3). Meanwhile, need to setup ssh keys (Generating SSH keys) for “rails” user to allow “bundle install” to succeed later on

ssh-keygen -t rsa -C "xxx@gmail.com"

3) Use server specific ruby version.

This is a bit trickier, i.e. instead of using globally installed ruby version, desire is to use ruby version specific to account owning rails app (aka. user “rails” in this case).

/etc/apache2/conf.d/mod_passenger.conf

...
#  PassengerRuby "/usr/bin/ruby"
  PassengerRuby "ruby"
  ...

Setup ruby (using RVM)

cd /home/www/virtual/host.kari.dy.fi
\curl -sSL https://get.rvm.io | bash
rvm install 2.1.5
cd current
bundle
gem install passenger -v 4.0.53

Restart apache2

service apache2 restart

Done!

Cameras, action: setup passenger to apache2

March 27th, 2015, 23:02 +0200 (KI)

Our guidance sources shall be today:

Now, when having all interesting source material in hand lets proceed with install

Step 1: Install passenger and various relevant development libraries

zypper addrepo http://download.opensuse.org/repositories/OBS:Server:Unstable/openSUSE_13.2/OBS:Server:Unstable.repo
zypper refresh
zypper install rubygem-passenger
zypper install apache2-devel
zypper install curl-devel
zypper install ruby-devel
zypper install pcre-devel

Step 2: Configure passenger
[code=”bash”]
passenger-install-apache2-module

[/code]

This will compile bunch of stuff and eventually (hopefully give following info)

--------------------------------------------
Almost there!

Please edit your Apache configuration file, and add these lines:

   LoadModule passenger_module /usr/lib64/ruby/gems/2.1.0/gems/passenger-4.0.53/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /usr/lib64/ruby/gems/2.1.0/gems/passenger-4.0.53
     PassengerDefaultRuby /usr/bin/ruby.ruby2.1
   </IfModule>

After you restart Apache, you are ready to deploy any number of web
applications on Apache, with a minimum amount of configuration!

Press ENTER to continue.

--------------------------------------------

Deploying a web application: an example

Suppose you have a web application in /somewhere. Add a virtual host to your
Apache configuration file and set its DocumentRoot to /somewhere/public:

   <VirtualHost *:80>
      ServerName www.yourhost.com
      # !!! Be sure to point DocumentRoot to 'public'!
      DocumentRoot /somewhere/public
      <Directory /somewhere/public>
         # This relaxes Apache security settings.
         AllowOverride all
         # MultiViews must be turned off.
         Options -MultiViews
         # Uncomment this if you're on Apache >= 2.4:
         #Require all granted
      </Directory>
   </VirtualHost>

And that's it! You may also want to check the Users Guide for security and
optimization tips, troubleshooting and other useful information:

  /usr/lib64/ruby/gems/2.1.0/gems/passenger-4.0.53/doc/Users guide Apache.html
  https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html

Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
https://www.phusionpassenger.com

Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.

Lets ignore for a while instructions about apache2 configuration, and see what got so far.

Step 3: Try if apache2 still starts

# need to create this dir; it's seemingly not autocreated
mkdir /run/passenger
service apache2 restart
service apache2 status
less /var/log/apache2/error_log

Okey, at this point error_log contains various errors from passenger but apache2 itself is still running (and luckily so, since otherwise writing this blog post would become challenging since we are doing changes in server hosting this blog).

Step 4: Setup new virtual host config

emacs /etc/apache2/vhosts.d/host.kari.dy.fi.conf

/etc/apache2/vhosts.d/host.kari.dy.fi.conf

<VirtualHost *:80>
  ServerName host.kari.dy.fi
  # !!! Be sure to point DocumentRoot to 'public'!
  DocumentRoot /home/www/virtual/host.kari.dy.fi/public

  # if not specified, the global error log is used
  ErrorLog /var/log/apache2/host.kari.dy.fi-error_log
  CustomLog /var/log/apache2/host.kari.dy.fi-access_log combined

  <Directory /home/www/virtual/host.kari.dy.fi/public>
    # This relaxes Apache security settings.
    AllowOverride all
    # MultiViews must be turned off.
    Options -MultiViews
    # Uncomment this if you're on Apache >= 2.4:
    Require all granted
  </Directory>
</VirtualHost>

Step 5: Setup virtual server

cd /home/www/virtual
git clone https://github.com/kikonen/host host.kari.dy.fi
cd host.kari.dy.fi
bundle

okey… lets cross fingers and restart apache2 yet’another time.

Step 6: Try if apache2 still starts

service apache2 restart
service apache2 status
less /var/log/apache2/error_log
ls -l /var/log/apache2/host.kari.dy.fi-*

If we are lucky, then passenger is starting up, and new virtual host is also configured up.

Step 7: Lets try it out in web browser

http://host.kari.dy.fi/

Okey, not good, getting in web browser

cannot load such file -- phusion_passenger (LoadError)
  /usr/lib64/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  /usr/lib64/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  /usr/lib64/passenger/4.0.53//helper-scripts/rack-preloader.rb:73:in `init_passenger'
  /usr/lib64/passenger/4.0.53//helper-scripts/rack-preloader.rb:157:in `<module:App>'
  /usr/lib64/passenger/4.0.53//helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/lib64/passenger/4.0.53//helper-scripts/rack-preloader.rb:28:in `<main>'

Lets start troubleshooting that. Even if we are getting this error, it indicates already that we are getting somewhere, since error is pointing into Passenger, so at least something is working.

Searching for help,

  • http://stackoverflow.com/questions/27058601/passenger-load-error-cannot-load-such-file-phusion-passenger-loaderror
  • http://stackoverflow.com/questions/27058601/passenger-load-error-cannot-load-such-file-phusion-passenger-loaderror

Step 8: Fiddle with config files
This might be totally redundant, but lets’ try it anyway.

/etc/apache2/http.conf.local;

<IfModule passenger_module>
  PassengerRoot /usr/lib64/ruby/gems/2.1.0/gems/passenger-4.0.53
  PassengerDefaultRuby /usr/bin/ruby.ruby2.1
</IfModule>

Step 9: What about running passenger manually?

# start passenger manually
passenger start
# That triggers "Compiling Phusion Passenger..."
# => sounds promising
# => also irrelevant since that is just passenger standalone, so waste of time

service apache2 restart

In the end, it appears that trouble came from the user for which gems were installed. I.e. “passenger” gem needs to be installed for correct ruby version in the environment of the user used to run rails server application in virtual host. If not so, passenger will just promptly fail.

TODO: Need to cleanup gem setup logic, and perhaps see if it’s possible setup passenger to run using rvm, so that it wouldn’t depend from the globally installed ruby version. I.e. I would rather use ruby version, which can be updated without dependency into one deployed via Linux package manager.

After fixing gem issue, rails seems to boot, but fails with error page. However, this is good thing, since some clear progress is done in this journey.

However, next problem is easy familiar error; just need to setup secret_key for production

*** Exception RuntimeError in Rack application object (Missing `secret_token` and `secret_key_base` for 'prod\
   uction' environment, set these values in `config/secrets.yml`)

…. and after fixing that small mistake, our rails server popups into aliveness. Neat!

Mission completed
Host Rails Server

Boxing match: traceur vs babel

March 25th, 2015, 20:51 +0200 (KI)

Evaluating traceur and babel in rails environment to see how well they behave in converting simple Ecmascript 6 file.

Our competitors today are

Notes:

  • traceur-rails works for some cases but fails for “let” statement
  • sprockets-traceur seems to fare better than traceur-rails
  • sprockets-es6 is not production ready yet (depends from beta version of sprockets 4)

Original

import { Example } from 'test/example';

class Test {
  constructor() {
    console.log("test class instantiated");
  }

  foo() {
    return "x";
  }
}
console.log("loaded test module");

new Test();
new Example();

traceur-rails

Configuration:

Traceur::Config.compile_to = :register

Result:

System.register("test/test", [], function() {
  "use strict";
  var __moduleName = "test/test";
  var Example = $traceurRuntime.assertObject(System.get("test/example")).Example;
  var Test = function Test() {
    console.log("test class instantiated");
  };
  ($traceurRuntime.createClass)(Test, {foo: function() {
      return "x";
    }}, {});
  console.log("loaded test module");
  new Test();
  new Example();
  return {};
});

sprockets-traceur

Configuration:

Traceur.configure do |c|
  precompiled = !(Rails.env.development? || Rails.env.test?)
  c.default_compilation_options.modules = :register
  c.default_compilation_options.source_map = !precompiled
end

Result:

System.registerModule("test/test", [], function() {
  "use strict";
  var __moduleName = "test/test";
  var Example = System.get("test/example").Example;
  var Test = function Test() {
    console.log("test class instantiated");
  };
  ($traceurRuntime.createClass)(Test, {foo: function() {
      return "x";
    }}, {});
  console.log("loaded test module");
  new Test();
  new Example();
  return {};
});

//# sourceMappingURL=data:application/json;base64,eyJ2ZX...

;

sprockets-es6

// NA - failed to get sprockets-es6 to work

sprockets-es6 using online test in babel website
Babel online transform tester

"use strict";

var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };

var Example = require("test/example").Example;

var Test = (function () {
  function Test() {
    _classCallCheck(this, Test);

    console.log("test class instantiated");
  }

  _createClass(Test, {
    foo: {
      value: function foo() {
        return "x";
      }
    }
  });

  return Test;
})();

console.log("loaded test module");

new Test();
new Example();

Notes

  • traceur-rails wants files to use .tc extension, which is a bit ackward
  • sprockets-traceur uses .js.es6 or .es6 file extension
  • sprockets-es6 uses .es6 file extension for files
  • sprockets-traceur generates embedded source maps by default into generated files. These source maps work well in development mode, in production they naturally won’t work, thus generation of them for production should be turned off
  • Regarding editors, Emacs with latest version of js2-mode combined with latest version of flycheck (with jshint) appears to be now in usable state. Just check and install latest versions of packages via “M+x package-list-packages.
  • Caveat Emptor: Traceur requires that nodejs is installed, which causes slightly undesired extra dependency for assets precompile. Possible fix for this is to precompile assets locally and scp results to deployed server.

Conclusion
For a while, I would recommend sprockets-traceur, since it appears to be most robust from this set of competitors. Considering output format, not seeing real benefits into either direction, but I slightly prefer more compact output of traceur. However, traceur output format with “:register” mode works neatly with rails javascript assets precompile. In the future if sprockets-es6 becomes standard part of sprockets gem, then I would start considering switching into it. However, it’s very likely thjat sprockets 4 will work only with very latest version of rails, which would hinder it very quickly as no-go option.