When you enter an empty train carriage do you choose to sit on the left or right side? Do you sit facing the direction in which the train is travelling or facing the direction from which the train is coming?
I think it is fairly clear that most people prefer to sit “facing forward” and some people claim “facing backwards” makes them ill. Observation also suggests that people also have a preference for the side of the carriage on which they sit. I have not tested this, but have observed that people prefer to sit on the left side of the carriage with their right side closest to the middle aisle. It is a matter of speculation as to why this should be the case. It may be a security instinct. I recall reading that the British originally established left hand travel on roads to allow travellers to have their right arm free to defend themselves when they passed people coming from the opposite direction. Perhaps a similar instinct makes people choose to sit on the left side of trains. Of course this would indicate that left handed people should have a preference for the right side of the carriage.
There is also a subsection of people ( I don’t know how large) who prefer to sit in one of the four corners of the carriage with their back to the carriage wall so that they are facing into the carriage. I don’t know if security, politeness or some other reason is responsible for this preference. Was it Doc Holliday who would always sit with his back to the wall facing the door when in a pub? 

Until recently when I started paying more attention to my surroundings from the left side of the car, I assumed naively that most drivers obeyed speed limits.

The title is a little contentious since there are some restrictions. Obviously cars can’t speed when other cars or traffic lights get in the way. However, when there are no restrictions on speed other than the speed limit itself, it seems most drivers speed most of the time.

The proof involves sampling from a population to estimate the proportion of cars that are speeding. At each point in time each car on the road is either speeding or not speeding. I have assumed that the proportion of cars which are speeding does not change over time. This is a necessary assumption as the sample is collected at different points in time so we want to assume we are still sampling from the same population.

The sampling itself is fairly straight forward. Just jump in the car and drive (and count). Drive just above the speed limit on a road where there are no traffic lights and traffic conditions do not impede driver’s speeds. Count the number of cars you pass (non-speeders) and the number of cars that pass you (non-non-speeders). Collect enough sample points as per standard statistical theory and use the results to estimate the proportion of drivers who speed.

I have done the experiment and the result is summarised by the title of the story. It’s clear now why my dad used to say that most drivers consider the speed limit as a minimum rather than a maximum.

One of the strange characteristics of the driver population is that individual cars can change their state from one time to another by either slowing down or speeding up. This is different from the usual scenario where for example the proportion of defectives on a production line is estimated. An item that is defective stays defective. The car is like Schrödinger’s cat in the famous thought experiment.

As an addendum, I note that The Age newspaper recently (2 June 2017) published an article bearing out the above observation using a survey of drivers. See the story Motorists behaving badly

Motorists behaving badly … and they know it Speeding, texting while driving and answering hand-held mobile phones. These dangerous driving practices are rife on Victorian roads. 

From Wikipedia:

Zenity is free software and a cross-platform program that allows the execution of GTK+ dialog boxes in command-line and shell scripts.

Scripts run from the command line generally by default print results to the command line. For example this simple script prints the md5 hashes for files in a directory.


#!/bin/sh
#
# This script prints md5 output for files
#

for file in *.*
do
rhash -M $file
done

In Ubuntu scripts can also be run from the nautilus context menu. Scripts are first placed in a designated location (depending on the Ubuntu version). The scripts in this location can then be run on files in nautilus by selecting the file(s), right clicking and choosing the script. As there is no terminal the script will not be able to display text by default. Zenity will allow the script to display text in a dialogue box. Here is an example of a script which allows you to select a number of files and print their md5 hashes to a dialogue box.


#!/bin/sh
#
# This script prints md5 output for files
#
ZENITY=$(which zenity)

# Check if we have selected any files...
if [ -z "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ]; then
 $ZENITY --error --text="No files selected"
 exit 0;
fi

md5Output=""

for file in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
 a=$md5Output
 b=`rhash -M "$file"`
 md5Output=$a"\n"$b
done

$ZENITY --info --text="$md5Output"

SSH may be installed on Ubuntu via the command line
sudo apt-get install openssh-server

The file /var/log/auth.log contains events related to SSH. Once SSH has been installed you will start to see lines like the ones below in the auth.log file indicating that someone from
outside is trying to break in.

Dec 29 13:44:14 xxx sshd[4075]: reverse mapping checking getaddrinfo for 67-208-39-157.neospire.net [67.208.39.157] failed – POSSIBLE BREAK-IN ATTEMPT!
Dec 29 13:44:14 xxx sshd[4075]: Invalid user admin from 67.208.39.157
Dec 29 13:44:14 xxx sshd[4075]: input_userauth_request: invalid user admin [preauth]
Dec 29 13:44:14 xxx sshd[4075]: Received disconnect from 67.208.39.157: 11: Bye Bye [preauth]
Dec 29 13:44:17 xxx sshd[4079]: reverse mapping checking getaddrinfo for 67-208-39-157.neospire.net [67.208.39.157] failed – POSSIBLE BREAK-IN ATTEMPT!
Dec 29 13:44:17 xxx sshd[4079]: Invalid user admin from 67.208.39.157
Dec 29 13:44:17 xxx sshd[4079]: input_userauth_request: invalid user admin [preauth]
Dec 29 13:44:17 xxx sshd[4079]: Received disconnect from 67.208.39.157: 11: Bye Bye [preauth]
Dec 29 13:44:20 xxx sshd[4081]: reverse mapping checking getaddrinfo for 67-208-39-157.neospire.net [67.208.39.157] failed – POSSIBLE BREAK-IN ATTEMPT!
Dec 29 13:44:20 xxx sshd[4081]: Invalid user admin from 67.208.39.157
Dec 29 13:44:20 xxx sshd[4081]: input_userauth_request: invalid user admin [preauth]
Dec 29 13:44:20 xxx sshd[4081]: Received disconnect from 67.208.39.157: 11: Bye Bye [preauth]
Dec 29 13:44:23 xxx sshd[4083]: reverse mapping checking getaddrinfo for 67-208-39-157.neospire.net [67.208.39.157] failed – POSSIBLE BREAK-IN ATTEMPT!
Dec 29 13:44:23 xxx sshd[4083]: Invalid user agata from 67.208.39.157
Dec 29 13:44:23 xxx sshd[4083]: input_userauth_request: invalid user agata [preauth]
Dec 29 13:44:23 xxx sshd[4083]: Received disconnect from 67.208.39.157: 11: Bye Bye [preauth]
Dec 29 13:44:30 xxx sshd[4085]: reverse mapping checking getaddrinfo for 67-208-39-157.neospire.net [67.208.39.157] failed – POSSIBLE BREAK-IN ATTEMPT!
Dec 29 13:44:30 xxx sshd[4085]: Invalid user arbab from 67.208.39.157
Dec 29 13:44:30 xxx sshd[4085]: input_userauth_request: invalid user arbab [preauth]
Dec 29 13:44:31 xxx sshd[4085]: Received disconnect from 67.208.39.157: 11: Bye Bye [preauth]
Dec 29 13:44:33 xxx sshd[4087]: reverse mapping checking getaddrinfo for 67-208-39-157.neospire.net [67.208.39.157] failed – POSSIBLE BREAK-IN ATTEMPT!

or these

Dec 29 13:48:00 xxx sshd[4180]: Connection closed by 103.41.124.58 [preauth]
Dec 29 13:48:12 xxx sshd[4182]: User root not allowed because account is locked
Dec 29 13:48:12 xxx sshd[4182]: input_userauth_request: invalid user root [preauth]
Dec 29 13:48:13 xxx sshd[4182]: Received disconnect from 103.41.124.58: 11: [preauth]
Dec 29 13:48:15 xxx sshd[4184]: User root not allowed because account is locked
Dec 29 13:48:15 xxx sshd[4184]: input_userauth_request: invalid user root [preauth]
Dec 29 13:48:17 xxx sshd[4184]: Received disconnect from 103.41.124.58: 11: [preauth]
Dec 29 13:48:19 xxx sshd[4186]: User root not allowed because account is locked
Dec 29 13:48:19 xxx sshd[4186]: input_userauth_request: invalid user root [preauth]
Dec 29 13:48:20 xxx sshd[4186]: Received disconnect from 103.41.124.58: 11: [preauth]
Dec 29 13:48:22 xxx sshd[4188]: User root not allowed because account is locked
Dec 29 13:48:22 xxx sshd[4188]: input_userauth_request: invalid user root [preauth]
Dec 29 13:48:23 xxx sshd[4188]: Received disconnect from 103.41.124.58: 11: [preauth]
Dec 29 13:48:44 xxx sshd[4190]: Received disconnect from 103.41.124.58: 11: [preauth]
Dec 29 13:49:05 xxx sshd[4192]: User root not allowed because account is locked
Dec 29 13:49:05 xxx sshd[4192]: input_userauth_request: invalid user root [preauth]
Dec 29 13:49:10 xxx sshd[4192]: Received disconnect from 103.41.124.58: 11: [preauth]
Dec 29 13:49:14 xxx sshd[4194]: User root not allowed because account is locked
Dec 29 13:49:14 xxx sshd[4194]: input_userauth_request: invalid user root [preauth]
Dec 29 13:49:16 xxx sshd[4194]: Received disconnect from 103.41.124.58: 11: [preauth]
Dec 29 13:49:23 xxx sshd[4196]: User root not allowed because account is locked

It is therefore very important to secure SSH by following the instructions at
https://help.ubuntu.com/community/SSH/OpenSSH/Configuring

I have listed the most common ways of improving security below. You can implement these by editing the ssh configuration file at /etc/ssh/sshd_config

1. Disable password authentication. Online attackers can guess passwords. It is safer to use SSH keys to authenticate a connection. Add this line to sshd_config
PasswordAuthentication no

2. Disable root login. If an attacker does break in to your system, the damage is reduced if he does not have root access. Add this line to sshd_config
PermitRootLogin no

3. Change the port on which ssh operates. The default port is 22 and attackers often only test this port when trying to break in. Add this line to sshd_config
Port xxxxx
where xxxxx is the chosen port number. If you do change the ssh port then clients trying to connect with your machine will need to know the correct port number and use it when asking for a connection. E.g. if 22222 is the chosen port then the connection is made by
ssh -p 22222 some_user@some_machine
Finally, in order to access your home network via SSH you will need to set up port forwarding for the new port on your modem or router.

Note: changing the SSH port on OSX is a less straightforward. Instructions for changing the SSH port on OSX are given at
http://serverfault.com/questions/18761/how-to-change-sshd-port-on-mac-os-x/67616#67616
In summary, edit the file
/System/Library/LaunchDaemons/ssh.plist
as follows to use the port 22222 say,

<key>Sockets</key>

<dict>

<key>Listeners</key>

<dict>

<key>SockServiceName</key>

<string>22222</string>

<key>SockFamily</key>

<string>IPv4</string>

<key>Bonjour</key>

<array>

<string>22222</string>

<string>sftp-ssh</string>

</array>

</dict>

</dict>

Then reload the file so that the new setting takes effect:

sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
sudo launchctl load /System/Library/LaunchDaemons/ssh.plist

4. Don’t use PAM authentication unless you understand it. PAM can override other security settings.

5. Use fail2ban or a similar third-party product to prevent an attacker making unlimited attempts to break in to your system. fail2ban takes appropriate action when it detects an abusive IP address. fail2ban can be installed from the terminal
sudo apt-get install fail2ban

After making changes to the sshd_config file and saving the changes, you apply the changes by restarting ssh with
sudo restart ssh.

I have an NSWindowController that swaps between various NSViews using animations.

@interface MyWindowController : NSWindowController
{
    IBOutlet NSWindow*  window;
    IBOutlet NSView*    view;
	NSViewController*	myCurrentViewController;	// the current view controller
    FirstViewController *fvc;
    SecondlViewController *svc;    
    CATransition *transition;
}
- (IBAction)changeToFirstView:(id)sender;
- (IBAction)changeToSecondView:(id)sender;
@end


@implementation MyWindowController

- (void)awakeFromNib
{
    transition = [CATransition animation];
    [transition setType:kCATransitionPush];
    [transition setSubtype:kCATransitionFromLeft];
    NSDictionary *ani = [NSDictionary dictionaryWithObject:transition
                                                    forKey:@"subviews"];
    [view setAnimations:ani];
    [view setWantsLayer:YES];   //  turns on Core Animation

    fvc = [[FirstViewController alloc] initWithNibName:@“FirstView" bundle:nil];
    [view addSubview:[fvc view]];
    myCurrentViewController = fvc;
}

- (IBAction)changeToFirstView:(id)sender;
{
        fvc = [[FirstViewController alloc] initWithNibName:@“FirstView" bundle:nil];
        [[view animator] replaceSubview:[myCurrentViewController view] with:[fvc view]];
        myCurrentViewController = fvc;
}

- (IBAction)changeToSecondView:(id)sender;
{
        svc = [[SecondViewController alloc] initWithNibName:@“SecondView" bundle:nil];
        [[view animator] replaceSubview:[myCurrentViewController view] with:[svc view]];
        myCurrentViewController = svc;
}

However, when the secondView was swapped in for the first time, parts of the firstView remained visible within secondView. These parts were NSTextViews. After playing around for a while I discovered that switching off the drawBackground option for the NSTextViews in Interface Builder stopped the views leaking through to secondView. It also meant that the boxes were no longer distinguishable from the rest of the background in the view. I think the correct solution is to use setNeedsDisplay to force view to redraw its contents when the subviews are swapped. The issue may be related to the use of CoreAnimation in the swapping of the subviews. So I have added a line

    [view setNeedsDisplay:YES];

within the changeToFirstView and changeToSecondView methods.

Dynamic libraries are explained in https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/000-Introduction/Introduction.html

There are advantages to using dynamic libraries in applications but extra effort is also required in order for the application to be able to locate and use the library when needed.

Firstly, the install names of the libraries need to be changed so that the target system knows where to find them. Secondly, the dynamic libraries need to be copied into the applications package directory. Finally, it seems that with OS X 10.9 Apple now requires third party libraries to be signed by developers separately. Steps 2 and 3 are accomplished via a script which is placed in the build phases section of Xcode. I needed to add a number of dynamic libraries to an application. One of these was libpari-gmp.dylib and I will use this here as an example.

The first step above is accomplished using the install_name_tool to change the dynamic library install name and dependency names so that the target system knows where to find them. I used otool to find the current install name of the file and dependencies:

otool -L libpari-gmp.dylib

This showed that libpari-gmp.dylib has libgmp.10.dylib as a dependency. The following command line instructions will then change the install names to the same location as the application binary (given by “@executable_path”):

install_name_tool -id @executable_path/libpari-gmp.dylib libpari-gmp.dylib

install_name_tool -change “/path/to/dependency/file/libgmp.10.dylib” @executable_path/libgmp.10.dylib libpari-gmp.dylib

The script that accomplishes steps 2 and 3 above looks like this:

Step 2.

###  Copy the library and dependencies from wherever they are located to the appropriate part of the application package (@executable_path above also known as “”$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/“).

cp -f “/path/to/library/libpari-gmp.dylib” “$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/libpari-gmp.dylib”;

cp -f “/path/to/library/libgmp.10.dylib” “$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/libgmp.10.dylib”

Step 3.

#  Sign the dynamic library as now required by Apple (see http://furbo.org/2013/10/17/code-signing-and-mavericks/ for a good explanation of the change).

LOCATION=”$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/”

IDENTITY=“Put you code signing identity here”

codesign –verbose –force –sign “$IDENTITY” “$LOCATION/libpari-gmp.dylib”

codesign –verbose –force –sign “$IDENTITY” “$LOCATION/libgmp.10.dylib

In fact step 1 can be performed after step 2 and this is what I did for the dynamic library libiconv.2.dylib. The script for ,ibiconv2.dylib is

cp -f “/opt/local/lib/libiconv.2.dylib” “$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/libiconv.2.dylib”

install_name_tool -id @executable_path/libiconv.2.dylib “$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/libiconv.2.dylib”;

View based tableviews may contain many subviews. For example, a twitter tableview needs to include outlets for an icon image, date, user name, real name, retweeting, favouriting, replying, following and the text of the tweet. In my twitter implementation I had trouble implementing the resizing of the tableview row to show tweets that extended over more than 2 lines. Instead of resizing the view I decided to truncate tweets that were more than 2 lines long and only show first 2 lines of the tweet. Apple in fact provides the necessary code to count the number of lines needed to display an attributed string in a view. This code was easy to adapt to my purpose. The work is done in the tableview delegate method tableView:viewForTableColumn:row. I created a ‘Tweet’ object to hold the relevant information about each tweet (user details, date, text etc). The ‘Tweets’ array holds the downloaded tweets. RBTwitterCellView is the top view in the tableview. It contains all the subviews mentioned above. The relevant parts of tableView:viewForTableColumn:row are given below.


- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
RBTwitterCellView *result = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
Tweet *tempTweet = [tweets objectAtIndex:row];
.
(allocate values to the various subviews of 'result' and created the attributed tweet text string)
.
[[[result tweetTextView] textStorage] setAttributedString:attributedTextString];

// The following code calculates the number of lines required to display the tweet in the given view within the tableview.
// If the number of lines required is more than 2 I truncate the tweet after the second line (line2index points to the end
// of the second line).
NSLayoutManager *layoutManager = [[result tweetTextView] layoutManager];
NSUInteger numberOfLines, index, line2index, numberOfGlyphs = [layoutManager numberOfGlyphs];
NSRange lineRange;
for (numberOfLines = 0, index = 0; index 2){
[[result tweetField] setString:[[attributedStatusString string]substringToIndex:line2index]];
}

return result;
}