Tag Archives: update

Updating Array Elements in CoffeeScript Loops

Notes on updating array elements in CoffeeScript loops.

CoffeeScript doesn’t use the JavaScript C-style for(;;) loops. When one wishes to conditionally modify the array that’s being iterated over, how one might go about it may not be obvious at first.

If I wish to update an array without otherwise disturbing it, the “obvious” answer will not work:

shouldUpdate = (colour) ->
…. details ….

colours = [‘red’, ‘green’, ‘blue’]
for colour in colours
colour = "foo" if shouldUpdate(colour)

This is because the compiler produces code like:

for (_i = 0, _len = colours.length; _i < _len; _i++) {
colour = colours[_i];
if (shouldUpdate(colour)) {
colour = "foo";

Note that in line 2 the value in colours[_i] is copied to a separate variable colour, thus assigning to colour will not affect the array itself.

If we wish to modify the array in place, then we can tell CoffeeScript to provide us with the index thus:

shouldUpdate = (colour) ->
…. details ….

colours = [‘red’, ‘green’, ‘blue’]
for colour, index in colours
colours[index] = "foo" if shouldUpdate(colour)

There may be a slicker way to do this, but for now it suits my purposes.


Upgrading Node.js using npm

The Node.js ecosystem provides a tool to update Node from within npm called, simply, “n”.

Install n thus:

sudo npm cache clean -f
sudo npm install -g n

I don’t know that clearing the cache is actually necessary, but a number of people have recommended doing so.

Update to the latest version of node using:

sudo n stable

n allows node versions to be changed easily. The n package listing has details.

Automatic OS Updates in CentOS

The yum dæmon is capable of controlling updates to fit a variety of scenarios.

The configuration file can be edited with

$ sudo vim /etc/yum/yum-updatesd.conf

Edit the file thus:

  • Change “emit_via = dbus” to “emit_via = email”. This tells the yum dæmon to use e-mail to send an alert.
  • Add “email_to = youremail@domain.com
  • Add “email_from = root@mail.domain.com
  • Change do_download to yes if you want the yum dæmon to automatically download the updates.
  • Change do_download_deps to yes if you changed do_download to yes.

It should look similar to:

  # how often to check for new updates (in seconds)
  run_interval = 3600
  # how often to allow checking on request (in seconds)
  updaterefresh = 600

  # how to send notifications (valid: dbus, email, syslog)
  emit_via = email
  email_to = sysadmin@domain.com
  email_from = root@mail.domain.com
  # should we listen via dbus to give out update information/check for
  # new updates
  dbus_listener = yes

  # automatically install updates
  do_update = no
  # automatically download updates
  do_download = yes
  # automatically download deps of updates
  do_download_deps = yes

WinXP SP3 Breaks Automatic Updates

Windows XP Service Pack 3 can break the automatic updates under certain circumstances due to a DLL that may not be registered. If the update system starts to fail with messages like “updates not installed”, do the following:

  1. Stop the update service:
    net stop wuauserv
  2. Register the DLL:
    regsvr32 %windir%\system32\wups2.dll
  3. Restart the update service:
    net start wuauserv

The update service should work again.