Browsing error logs on a remote node
Wednesday, 18th May, 2011
First, set up your sasl
This config sets up a directory for rolling logs (max ten files, each max 10 megabytes). More configs on the man page.
% erl_config.config
[
{sasl, [
{sasl_error_logger, false},
{error_logger_mf_dir, "/path/to/a/dir/for/erl/logs/"},
{error_logger_mf_maxbytes, 10485760}, % 10 MB
{error_logger_mf_maxfiles, 10}
]
}
].
And when you run erlang, tell it where your config file is:
erl -config /path/to/erl_config -boot start_sasl ... more args ...
n.b.:
- erlang expects the config file to have the extension .config, which you don’t give in the command line.
- the above config is cribbed from Programming Erlang. I was surprised to find that Erlang and OTP in Action does not describe how to configure the sasl error logger.
Connect and browse
Once you’re connected to the above node (see Connecting erlang nodes), you can run rb, the report browser. A little bit of set up is required. See this discussion on stackoverflow, which encapsulates the setup in a function:
%% @doc Start the report browser and reset its group-leader.
%% For use in a remote shell
start_remote_rb() ->
{ok, Pid} = rb:start(),
true = erlang:group_leader(erlang:group_leader(), Pid),
ok.
Connecting erlang nodes
Tuesday, 17th May, 2011
In order to connect to each other, erlang nodes each need a name, they need to share a secret cookie, and if they’re to communicate over the internet, they need access to ports.
The secret cookie can be either set at runtime (as in the examples below), or in each user’s .erlang.cookie file.
For local connection
On the same machine or subnet, each node just needs a short name:
$ erl -sname chico -setcookie marx ... (chico@localhost)1>
For internet connection
Each node must have the following ports available:
- port 4369, used by epmd (the Erlang Port Mapper Daemon, not Erick and Parrish Making Dollars), must be open for both TCP and UDP (n.b.: this is a default).
- another port or range of ports for the erlang nodes themselves. These nodes can be set at run time using the -kernel, inet_dist_listen_min and inet_dist_listen_max flags.
Each node must also use a full name, with either a domain or an IP address:
$ erl -name chico@brothers.org -setcookie longrandomstring -kernel inet_dist_listen_min 9000 inet_dist_listen_max 9005 (chico@brothers.org)1>
Connecting
Erlang nodes are gregarious: as soon as nodes find out about each other, they connect. An easy way to say hello is “ping”:
(chico@localhost)1> nodes(). [] (chico@localhost)2> net_adm:ping(groucho@localhost). pong (chico@localhost)3> nodes(). [groucho@localhost] (chico@localhost)4> ^g User switch command --> r groucho@localhost --> c Eshell V5.7.2 (abort with ^G) (groucho@localhost)1>
You can skip the connection palaver by using the -remsh flag at startup:
$ erl -sname chico -setcookie marx -remsh groucho@localhost ... (groucho@localhost)1>
etc
Introspection GUIs like AppMon and Pman can access any connected node (see the Nodes menu in the toolbar).
DragonFly BSD: copying the image onto a USB stick under MacOS X
Friday, 6th May, 2011
On Unix-like systems low-level byte-to-byte copying is done with dd:
dd if=[input file] of=[output location]
n.b.: of is a location, not a filename, so you can’t use the file path to your USB stick, as in:
dd if=dfly-i386-gui-2.10.1_REL.img of=/Volumes/MyUSBStick
The path to the device location is required, as in:
dd if=dfly-i386-gui-2.10.1_REL.img of=/dev/disk1
On MacOSX, how to find out the dev name of your USB port is described in this Ubuntu help page. The following will list the currently mounted devices, with their dev names:
$ diskutil list
This will unmount the device, ready for dd:
$ diskutil unmountDisk /dev/[name]
And this will do the deed:
$ dd if=/path/to/input/image of=/dev/[name] bs=2048
Finally, this will make your device safe for removal.
$ diskutil eject /dev/
A screen cheat sheet
Sunday, 30th January, 2011
I’ve recently been using screen quite a lot when working on a client’s servers. I like it. However, my fingers haven’t yet learnt the default key-bindings for the commands I use. In an attempt to speed that learning, here’s a list of them (copied and pasted from the manual page).
| Keys | Command | Description |
|---|---|---|
| C-a c | screen | Create a new window with a shell and switch to that window. |
| C-a A | title | Allow the user to enter a title for the current window. |
| C-a N | number | Show the number (and title) of the current window. |
C-a ' |
select | Prompt for a window identifier and switch. |
C-a " |
windowlist -b | Present a list of all windows for selection. |
| C-a k | kill | Destroy the current window. |
| C-a ? | help | Show key bindings. |
wave.erl: an erlang script to read and write .wav files
Tuesday, 1st June, 2010
Please find below wave.erl, an erlang script for reading and writing .wav audio files. I am releasing it under the ISC license.
The script exports functions read/1, write/3 and write/2, and the wave record:
Using lists:map/2 with a named function
Tuesday, 11th May, 2010
When using a named function (i.e., rather than an anonymous function) with lists:map/2, it is necessary to use the form fun module:function/arity. For example, the module [1] will raise the error [2]:
[1]
-module(maptest).
-export([test/0]).
-export([double/1]).
double(N) ->
2 * N.
test() ->
List = [1,2,3,4,5],
lists:map(double, List).
[2]
1> c(maptest).
{ok,maptest}
2> maptest:test().
** exception error: bad function double
in function lists:map/2
Module [3] works:
[3]
-module(maptest).
-export([test/0]).
%% -export([double/1]). %% not necessary
double(N) ->
2 * N.
test() ->
List = [1,2,3,4,5],
lists:map(fun double/1, List).
[4]
1> c(maptest).
{ok,maptest}
2> maptest:test().
[2,4,6,8,10]
So the first argument of map — whether the function is named or anonymous — always starts with the keyword fun:
[5]
lists:map(fun(X) -> 2 * X end, List).
As an aside, it is not necessary to export the function in order to make it accessible to map (cf. [3]).
This is a summary of recent discussion on the erlang-programming-book Google group.
Compiling HTK 3.4 on Mac OS X
Sunday, 1st November, 2009
Download the HTK source tarball from the HTK website. Note you must register — and make sure you read the licence! — before you can download either the code or the documentation.
Then, …
$ cd /path/to/directory/containing/htk/tarball $ tar zxf HTK-3.4.1.tar.gz $ cd htk $ ./configure $ make all $ sudo make install
…, installs everything into /usr/local/bin/.
Compiling HTK 3.4 on Windows XP
Wednesday, 14th October, 2009
[This post is from my old blog, originally posted Monday 30th July 2007. As it is still read, I have moved it here with no revisions]
Introduction
Here are some notes on my experiences of compiling HTK 3.4 on Windows XP. I compiled HTK successfully, but some research and experiment was necessary. In the end I tried and was successful with Cygwin and with Visual Studio Express. I hope you find these notes useful.
The issues addressed here will obtain whether you’re using the makefiles that come bundled in the htk3.4 zipfile or the winmakefiles makefiles refered to by Anna Langley in her 02/02/07 post to htk-users.
These notes do not cover getting HSLab to run on Windows. I recommend Praat for labelling, and Praat or SpeechRecorder for recording.
Adding a Chat application to pinax
Tuesday, 13th October, 2009
How do you add a Django application to Pinax? Below is my experience with one Django app. For some related reading see Fernando Correia’s series on Exploring Pinax and Greg Allard’s How to Write Reusable Apps for Pinax and Django.
Here I want to separate the two issues of (a) developing a Django app and (b) integrating a Django app into Pinax. This post will look at Pinax integration only, the only Django app “development” will be making sure the app is ready for integration. I am using a third-party Django application, namely jchat by Federico Cáceres, covered in his blog posts on his Django powered AJAX Chat project.
Install lxml on Mac OS X without fink or MacPorts
Thursday, 10th September, 2009
This worked for me, statically linking:
cd /tmp wget http://codespeak.net/lxml/lxml-2.2.2.tgz tar -xzvf lxml-2.2.2.tgz cd lxml-2.2.2 python setup.py build --static-deps --libxml2-version=2.7.3 --libxslt-version=1.1.24 sudo python setup.py install
I found it at stack overflow.