Thursday 31 January 2013

Stage 2 - Discover nginx data must be in a subdirectory of nginxSet up nginx on Windows virtual hosts for multiple domain names

I next put in multiple virtual hosts.

I made the mistake of referring to the files off in absolute paths elsewhere in the PC

It seemed to work - but only sometimes...   The pictures would not appear - or would only appear on the first call.  Further web-page requests after that might be text-only, or might just hang forever.

Returning the locations to be subdirectories of the <nginx>/html directory fixed all the problems.

Stage 1 - Set up nginx on Windows, with ZoneAlarm

Ultimately, my plan is to use nginx to serve the static web pages for multiple domain names, and for it to act as a reverse-proxy to the Seaside web-apps.

Stage 1 - get nginx working, and visible from the internet.

Step 1 - get nginx (pronounced "Engine X") working on Windows.

             At the Command Line (Run cmd from Start Menu),     cd <the folder containing the application app>
             type nginx
      
             On Vista, it works with three processes, all called "nginx" with Process Ids (PIDs) listed by:
              tasklist /FI "IMAGENAME eq nginx*"

             Notes:  It sets up using the parameters contained in the nginx.conf file held in
             <the folder containing the nginx application> /conf

     This nginx.conf file provides a webserver on port 80.

worker_processes  2;    # One for each CPU core
error_log logs/main_error.log;
pid        logs/nginx.pid;
events { worker_connections 1024; }

http 
 { include        mime.types;  
   # On Windows, this goes to [<nginx>/conf/]mime.types
   # i.e. the mime.types file in the conf dir in the nginx's directory

   default_type   application/octet-stream;

   index index.htm index.html index.st index.php;

   server    #default
    { server_name :80;
      access_log logs/catchall.access.log;
      error_log logs/catchall.error.log;
      root html\catchall;
    }

 }

Step 2 - close down nginx on Windows

            run cmd from Start Menu again, to bring up a second Command Line
                  (As the cmd window opened in step 1 gets taken over by nginx, so cannot be used)

            nginx -s stop

            If nginx has had a problem with the configuration file, this sometimes might not work.

            First alternative:
            nginx -s quit

            If this also does not work, the second alternative:
            Find the PIDs for the principal nginx process on Window
             tasklist /FI "IMAGENAME eq nginx*"
           Kill the processes
      taskkill /PID <number in the nginx.pid file>
            
Step 3  get nginx visible through the router's firewall.

           Make sure the PC running nginx has a static IP address.
           Log into the router, and use port-forwarding for HTTP on port 80, to the PC.

Step 4 Get nginx working through ZoneAlarm Free firewall

Check if the server is accessible from outside your local network.  (A good way is to switch off wifi on your phone, and then use the phone's browser to access the website via the website's domain name).

If it works, that's great.

If it doesn't work however...

Switch off ZoneAlarm Free Firewall.
Check if the server is accessible from outside your local network.


If it still doesn't work ...
Re-check that the web-server is running: tasklist /FI "IMAGENAME eq nginx*"
Re-check what IP address the PC is on, and that it matches the IP being used on the router's port-forward.  (Also check that it matches the static IP address that you want the PC to use).

If the server is accessible, switch ZoneAlarm back on.

Delete nginx from the list of programmes in ZoneAlarm 

Try to access the webserver via localhost
and try to access the webserver from another local device via the IP address.

Zonealarm will pop up a window asking if nginx should be allowed to provide local access.


Check if the server is accessible from outside.
Zonealarm will pop up a window asking if nginx should be allowed to provide access to the internet.

Sunday 20 January 2013

Problems moving Seaside to port 80 on Windows

I booted up my Windows PC, and started Seaside, which defaults to running the web-server on port 8080.

I stopped the process, and changed the port number, (action-clicking on the the top pane of the Seaside control panel, then selecting 'Port...' from the menu), then re-starting, and got an error message.

I inferred from the error that port 80 was already in use.


So, at the  Windows command prompt  (Windows Start Menu, "cmd", or "cmd" and Shift-Control-Enter from an administrator account, to run with Administrator privileges)

NETSTAT -p tcp -ano

List all (-a) the ports using the TCP protocol  (-p tcp) in numerical form (-n), and display the process id (PID) for the owning process (-o).

This was good, but it gave a PID of 4112 - which was not appearing on the list of processes and services in Windows Task Manager.

I then ran :

tasklist /FI  "PID eq 4112" /FO table

Which lists the active tasks and processes /FIlterered by process Id equal to "4112", in the /FOrmat of a table  (can also be a list or a csv).

It turned out to be Skype that had control of port 80.  I killed Skype, and everything was ticketty-boo.



Saturday 12 January 2013

File In and File Out

To store a new package to a file, which will be stored in the Contents\Resources subfolder of the Smalltalk folder:

Right-click the package in the class browser, > various > file out (o)


To load the package back in to a fresh image:

Left-click the world, Tools > File Browser

Accessors: getters and setters

Smalltalk accessors are always named after the variable they access.

If a variable is called xVal then the getter is also called xVal and the setter is called xVal:

Copy and Paste tips from Pharo By Example

When you c'n'p from PBE,  beware:  PBE uses  − instead of - (i.e. an m dash instead of a minus sign), so any expression including a - operator will not compile until the m dashes are replaced with minus signs.

Create a new Class in Pharo Smalltalk

Amend the package's sample code - changing "Object" to the class you want to sub-class, and  put the name of the new class, prefixed by #   (The subclass message gets sent to the object you specified, with a parameter of the name you want to give to the new sub-class).

Action-click, then accept (Cmd-s)

On accept, the system, executes the code.

By convention, if a class defines a method named initialize, it will be called right after the object is created.

The first message to send in an initialize method is generally to call the parent class's initialize method, via super initialize.


Open a workspace, and type myNewClassName new    Select it, and inspect it 

The inspector has three panes - the left pane lists the instance variables, and the bottom-right pane is a workspace who's self is bound to the object selected in the browser.
 


Create a new Package in Pharo Smalltalk

In the Class browser, action-click (in Windows, right-click) on the Packages pane (the left-most pane).

The browser automatically generates the code to create the new sub-class of object, with the 'category' set to the Package name.

Packages should have a two or three letter abbreviation at the start of their name.

(Categories and packages are not entirely the same thing:  categories have existed at least since the dawn of Smalltalk-80, and are simply a collections of related classes in a Smalltalk image. A package is a collection of related classes and extension methods that may be versioned using the Monticello versioning tool.)

Creating a method in Pharo Smalltalk

In the Class browser, navigate to the protocol group of the class of the package that you want.

By convention, for Test Driven Development, you first create a test method for your method .

Also by convention, the test for the Shout method of class String in Package Collections-Text is going to be called testShout in StringTest in CollectionsTest-Text.

The test browser is going to refer to this as StringTest>>#testShout  - i.e. the testShout method of class StringTest.


When you run the test, failed tests appear with a  Red background, passed tests appear with a Green background


Friday 11 January 2013

Browser tips in Smalltalk

To bring up a Class browser, aka System browser, type
    aClassName browse 
and do it or (Alt-d)

or World > Class browser (or World > System browser)

The four panes across the browser are (from left to right) Package    Class    Protocol group   Method

The ? button at the bottom of the class pane displays the class comment.



To find an object, focus on the package pane, and Alt-f, or left-click and find class
     
To find a method, World > Tools > Method finder and type the method name in the top left pane
You can find by name, you can QuickPick through the list of names that match the search substring, or search by the method's effects!  (e.g. search 'eureka' . 'EUREKA' and it will return eureka asUppercase --> 'EUREKA' and list the various Classes that implement an asUppercase method in the right-hand pane.

In Pharo 1.4, use the Finder ( World > Finder ).

Thursday 10 January 2013

How to Meta-Click in Pharo and Squeak on Windows

How to Meta-Click
In Squeak and Pharo, on Windows, the default method to Meta-Click is to Shift+Alt+left-click
i.e. click : left-click
      action-click :  right-click
      meta-click: Shift+Alt+left-click


To change the behaviour in Pharo 1.4, use
    System > Settings > Settings Browser, then
    System > Keyboard > Control and Alt Keys.

Where Image files are stored
In both Squeak and Pharo, the image files are stored in  
   ..\Contents\Resources\*.image  (or *.ima)


The other default behaviour I have found, with Seaside On Squeak (3.0.6 on 4.3), is:
   click : left-click

   action-click :  Alt+left-click

   meta-click: right-click

Smalltalk

I've started Smalltalking again.

The plan is to use Smalltalk, and probably Seaside, to create the Fencing Competition App.

Ultimately, the app will work with intelligent clients, but initially, it'll all run on the server.

So I've started working through Pharo By Example Volume 1.



Fencing Competition App - Requirements

Round 1 functionality
  1. The Directoire's computer can cope with one competition format : either the format used in PaFF's 1 to 7, or the evolutions of the PaFF-MacMahon system.
  2. Initial seeding done manually 
  3. Directoire can tweak rankings for second and subsequent rounds, to avoid bouts between classmates.  
  4. Directoire's computer can cope with late arrivals
Round 2 functionality
  1. The Directoire's computer can give the referee's handheld the full set of bouts for the next round.
  2. Referees have the pool information on a handheld device
  3. The referee's handheld copes with pools of 5 or pools of 6, or else PaFF-MacMahon rounds of 3 bouts
  4. The handheld records the results as they referee, 
  5. The handheld returns the whole round's results to the directoire's computer with no additional manual data-entry. 
  6. The system keeps records of which referees are parents of which fencers, and assigns makes sure never to assign a referee to a pool his/her child is fencing in.
Round 3 functionality
  1. The Directoire's computer can cope with various competition formats, including the format used in PaFF's 1 to 7, and the evolutions of the PaFF-MacMahon system.
  2. Referees can choose from a variety of handheld devices
  3. Initial seeding done algorithmically, from age, grade, class coach's assessment of rank-in-own-class and previous competition results
  4. System can tweak rankings for second and subsequent rounds, to avoid bouts between classmates.
  5. Referee's device can cope with a late arrival
  6. The directoire's computer can serve the interim results as poolsheet web pages, or transfer the results to a device which can serve the interim results as local poolsheet web pages.
  7. The directoire's computer can publish the finalised results to a website
Round 4 functionality
  1. The Directoire's computer can display results on a projector, or transfer the results to a device which can display the results on a projector.

Other requirements:
Carry out check-in (Round 1 or Round 2)
Store results in a persistent results database, to provide rankings for future competitions.

The Fencing Competition App - Background

I've been running some fencing competitions in the past few years.

There are a couple of issues that are starting to need to be addressed.

1) We've been running them by hand until now - using small cardboard seeding cards, and totting up the scores from the poolsheets by hand.


The competition has moved from just over a dozen entrants, to over 40 entrants.  So the time taken to process the sheets and determine the winners has moved from 5 minutes to about 25 minutes.  Each round.

Time to automate the process.

The problems remain:  with automation, you simply exchange the time spent totting-up scores for time spent re-typing scores, and (unless you have a printer on-site) you still have to write out the pool sheets.  Plus typing scores from pool-sheet to computer is an error-prone business.  And when the errors so back out on the next round's poolsheet, it becomes a bigger problem...

So what's needed is a system that fills out the poolsheet automatically, and captures the results automatically.

2) For the first 10 fights or so, the pools are mixed ability, so we can stream the fencers together into groups of similar ability for the final round of 5 fights.

So the youngest and the least-skilled spend more than half their time in fights with better or much-better fencers.

What I want is a higher proportion of fights with fencers of your own ability level, as well as results that reflect who fences the best.

Wednesday 9 January 2013

Heat Management issues with HP Pavilion laptops

Well, it's now going on 5 years in to my time with my HP Pavilion dv-6 laptop.

The first one died a death due to heat management issues.

The second one died a death due to heat management issues.

It's safe to say, they have heat management issues.


So, here are some vital pieces of information to know about HP Pavilion laptops, if you want yours to stay alive.

Most important of all:  they are designed to work on a flat level surface.
 - they will overheat if there is too much space between the base of the unit and the flat surface.
 - they will overheat if there is not enough space between the base of the unit and the flat surface.

So do not make a bigger gap - like USB under-laptop fan units, or by putting small spacers under the rear feet of the laptop.  Or it will overheat.

If the little rubber feet fall off (and they fall off easily - the glue is weak, and is weakened more by heat; the plastic they are glued to has been left with a high-gloss finish, and provides a very poor key for the glue) of the bottom of the base, stick them back on immediately!  Or it will overheat.

If you're replacing the feet, it's a very good idea to rough up the surface of the base with sandpaper, just where you'll glue them back on.  This will help them stay on longer.


Remember: HP do not refer to the device as a laptop they call it a 'notebook'.   Using it on your lap is a good way to see it overheat.


The best way to use it as a laptop is to get a solid board with pillow full of foam beads attached underneath it.

AVOID the ones from Ikea - they look a bit like a crescent moon, and the 'solid board' is a thin piece of plastic.  The plastic warps from the heat and from the weight of the laptop, or from the force of your fingers pushing on the keyboard and ...  your laptop will overheat.

They cost £9.99 and are completely useless.


If you've got a suitable bit of MDF or plywood, then you can just sit that under the laptop, on top of a cushion.  (I'd suggest 6mm or 8mm thick)





The one I use came from Aldi or Lidl or somesuch, and is very good.  The board is  nice and thick - I suspect it's veneered plywood - and retains it's essential flatness very well.  The pillow is comfortable and conforms well to whatever position I'm sitting in.