Thursday, May 21, 2015

Bypassing the UEFI

I'd like to outline the procedure to install dual booting Windows/Linux on computers with the UEFI security system This abominable bit of malware can be found on recent models produced by HP and Acer etc. It seems to be associated with Windows 8. The required procedure is a departure from that of the straight forward BIOS machines, and following those original procedures will meet with failure. It's not difficult to bypass the UEFI but I struggled with it, spent a frustrating day consulting many difficult and confusing HOWTOs such as this one. I've done installations hundreds of times on pre-UEFI computers. It's possible to follow basically the same procedure once the UEFI has been bypassed. Here's how: Once you switch on the computer, having backed up any precious data in preparation, check very quickly for the key to enter the BIOS configuration. You'll only have a few seconds and there should be a message briefly displayed at the bottom of the screen. It's often F2 or the DELETE key, but it varies from machine to machine. Once in BIOS, a screen something like the following should displayed:

 Select the security tab:
 
And create a supervisor password. It doesn't have to be elaborate. Just ensure it's memorable. Once the password is created, select the boot tab:
 
Now the 'secure boot' option can be disabled. And the 'UEFI booting' option can be switched to 'legacy BIOS.' The booting sequence should also be altered at this point, so that USB containing the source iso should be given priority over the hard drive. The images used here will almost certainly differ from what is seen on your computer, but that's nothing to worry about. What's important is to 1) give yourself a supervisor password, 2) disable secure booting, 3) switch from UEFI to legacy BIOS, and 4) prioritize USB booting. Press F10 to save the settings. Now the computer is ready for normal installation. Use a 64bit Linux iso on these machines.

Saturday, May 9, 2015

I am the Game of Life. Play me.



## This post is meant to be copied and pasted into a text        
## file with a .py extension and run as a python programme.  
## If you are using Windows, you can download the  
## Windows X86 MSI Python 2.7.9 installer from the www.python.org   
## website. I wrote the programme, based on John Conway's  
## Game of Life to learn more about Python and especially Tkinter. 
## Tkinter is a bit of a disappointment but I'm pleased with
## the results.       
##               
## It was John Conway, the Liverpudlian mathematician, who
## invented the game in 1970. He first played it on paper and
## pencil rather than computer, and even the thought of this is
## exhausting. It's not hard to see what computers have done
## for new fields of math. The Game of Life is credited to have
## helped in opening up the study of Cellular Automata. It's
## really not a game in the conventional sense, but it's fun
## to watch.
##
## Each red cell, or square, is a living organism. And each cell
## is surrounded by 8 other neighbouring cells. If a living red 
## cell is surrounded by 0 or only 1 other red cell, that cell will
## die in the next generation. Die of loneliness, I suppose. To
## die means to be replaced by a yellow cell. Similarly, if the
## red cell is surrounded by 4 to 8 other red cells, that cell
## will die in the next generation of over-crowding. A red cell
## will survive and continue to live in the next generation if it
## is surrounded by 2 or 3 neighbouring red cells. One more rule,
## if a yellow cell is surrounded by exactly 3 red cells, it will
## come to life in the next generation and be replaced by a red 
## cell. You can read Martin Gardner's original introduction to 
## the game in his 1970 column in Scientific American. 
##  
#!/usr/bin/env python2

import Tkinter as tk

def quitgame():
    root.destroy()

def advance1():
    gen_number = 1
    advance(gen_number)
    
def advance10():
    gen_number = 10
    advance(gen_number)

def advance100():
    gen_number = 100
    advance(gen_number)

def advanceinfinity():
    gen_number = 100000
    advance(gen_number)

def advance(gen_number):
    global tally
    for k in range (gen_number):
        ##main loop to check neighbours
        for x in range (25):
            for y in range (42):
                Matrix[x][y][1] = 0

                if Matrix[x][y][0] == 6:        
                    colour_flag = 'red'
                    tally_neighbours(x,y)
                else:
                    colour_flag = 'yellow'
                    tally_neighbours(x,y)

                if (tally>3 or tally < 2) and colour_flag=='red':
                    Matrix[x][y][1] = 7
                    A=tk.Button(frame2, bg='yellow')
                    A.grid(row=x,column=y)
                    frame2.grid()

                if tally == 3 and colour_flag == 'yellow':                    
                    Matrix[x][y][1] = 5
                    A=tk.Button(frame2, bg='red')
                    A.grid(row=x,column=y)
                    frame2.grid()

                tally = 0
            root.update()

        for x in range (25):   
            for y in range (42): 
            ## transferring info from 3rd to 2nd dimension
                if Matrix[x][y][1] == 5:
                    Matrix[x][y][0] = 6
                if Matrix[x][y][1] == 7:
                    Matrix[x][y][0] = 0

def tally_neighbours(x,y):
    global tally
    if x!=0 and y !=0 and Matrix[x-1][y-1][0]==6:
        ## for checking surrounding 8 squares
        ## of middle cell
        tally = tally + 1                              
    if x!=0 and y !=0 and Matrix[x-1][y][0]==6:
        tally = tally + 1
    if x!=0 and y !=0 and Matrix[x][y-1][0]==6:
        tally = tally + 1
    ## these try statements make sure
    ## no error message occurs when i
    ## overstep the bounds positively.
    ## Negative overstepping is not OK
    try:                                                
        if x!=0 and y !=0 and Matrix[x+1][y+1][0]==6:   
             tally = tally + 1                          
    except IndexError:                                  
        pass
    try:
        if x!=0 and y !=0 and Matrix[x][y+1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x!=0 and y !=0 and Matrix[x+1][y][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x!=0 and y !=0 and Matrix[x-1][y+1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x!=0 and y !=0 and Matrix[x+1][y-1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
########################
## for checking 5 squares surrounding
## top row cell
    if x == 0 and y != 0 and Matrix[0][y-1][0]==6:      
        tally = tally + 1                               
    try:
        if x == 0 and y !=0 and Matrix[0][y+1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x == 0 and y !=0 and Matrix[1][y][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:              
        if x == 0 and y !=0 and Matrix[1][y-1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x == 0 and y !=0 and Matrix[1][y+1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
#########################
## for checking 5 cells surrounding
## left column cell
    if x != 0 and y == 0 and Matrix[x-1][0][0]==6:      
        tally = tally + 1                               
    try:
        if x != 0 and y == 0 and Matrix[x-1][1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x != 0 and y == 0 and Matrix[x][1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x != 0 and y == 0 and Matrix[x+1][0][0]==6:
            tally = tally + 1
    except IndexError:
        pass
    try:
        if x != 0 and y == 0 and Matrix[x+1][1][0]==6:
            tally = tally + 1
    except IndexError:
        pass
#################
## for checking 3 cells surrounding
## top left cell
    if x == 0 and y == 0 and Matrix[0][1][0]==6:       
        tally = tally + 1                               
    if x == 0 and y == 0 and Matrix[1][0][0]==6:
        tally = tally + 1
    if x == 0 and y == 0 and Matrix[1][1][0]==6:
        tally = tally + 1
    return tally
## for choosing (and correcting) initial configuration
def startMove(i,j,event):               
    if Matrix[i][j][0]== 0:
        event.widget.config(bg='red')
        Matrix[i][j][0]=6
    else:
        event.widget.config(bg='yellow')
        Matrix[i][j][0]=0
    
root = tk.Tk()

Matrix = [[[0 for z in range(2)] for y in range (42)] for x in range (25)]

tally = 0

frame1 = tk.Frame(root)
frame2 = tk.Frame(root)

instruct = tk.Label(frame1, text="Initialize the game by clicking on a few yellow squares. ")
instruct.pack(side=tk.TOP)
onebutton = tk.Button(frame1, text="Advance 1 generation", command=advance1)
onebutton.pack(side=tk.LEFT)
tenbutton = tk.Button(frame1, text="Advance 10", command=advance10)
tenbutton.pack(side=tk.LEFT)
hundredbutton = tk.Button(frame1, text="Advance 100", command=advance100)
hundredbutton.pack(side=tk.LEFT)
infinitybutton = tk.Button(frame1, text="Advance forever", command=advanceinfinity)
infinitybutton.pack(side=tk.LEFT)
quitbutton = tk.Button(frame1, text="Quit", command=quitgame)
quitbutton.pack(side=tk.LEFT)
frame1.grid()

for x in range (25):
    for y in range (42):
        A=tk.Button(frame2, bg='yellow')
        A.grid(row=x,column=y)
        frame2.grid()
        A.bind('', lambda e, x=x, y=y: startMove(x, y, e))

root.title("Martin's Conway's Game Of Life")
root.mainloop()

Saturday, March 14, 2015

Clone That Puppy

If you read my previous post on the Live USB Puppy for Python education, you may have noticed at least two problems with it. I will address them here.


The first is that the Python graphics package Tkinter is not designed to deal with animation. I tried anyway, it was awkward, and I abandonned the idea. I installed the Pygame package and have been working happily with that instead. Since I believe that writing simple games and animation are the best way to teach programming to youngsters, something like Pygame is essential. There's a .deb package available for download here. And there is a pretty good introductory tutorial here. Pygame can be installed on Puppy clicking on the .deb file, same as outlined for the other packages in the previous post.

The second problem lies in using the USB in the classroom rather than anything to do with the USB itself. It takes about 25 minutes at least to prepare a USB in the manner I outlined. For a class of 10 students, that means the teacher is facing hours of tedious and attention demanding time at the terminal, if each student is to get their own USB. Intuitively, I'd just like to simply copy whatever is on the Puppy and paste it onto an empty USB. However, this doesn't work. I have something else in mind. Something that works. I found that I can cut down the time it takes to reproduce a USB to around 7 minutes. Still tedious and attention demanding, and fraught with the dangers of destroying valuable data at just about every step, but I managed to get the hang of it after only a couple of false starts. What we want to do is called cloning a drive or partition. You can also make an image of the USB and go from there, but it seems cloning is a little easier and no slower than going down the image route.

Download Clonezilla, (~160MB) and put it on a USB following these instructions. I followed the GNU/Linux method B and found it surprisingly easy. Prepare a target USB stick, where you intend to put the cloned copy. The source will be the 'original' USB created following the instructions in the previous post. Once Clonezilla is booted, I inserted the other two sticks. It's important to know which is the source with your Puppy on it and which is the target which should be empty. You also need to know how to identify the USB with Clonezilla on it, and also the hard drive and the partitions on it. I'm leery about altering my hard drive in any way, so my method only involves USB sticks. On this Toshiba laptop, that means every USB slot (all 3) is in use. Still the possiblilty exists of doing damage to data on the hard drives, so take care to identify them when presented with the chance. Here is an accurate walk-through of the cloning process. As I say, it takes around 7 minutes. Good luck and take care.

Friday, March 6, 2015

A Puppy in the Classroom

I've been quite busy over the past few months working with my computer. Something I'd like to present here is an arrangement (dare I say an invention) for teaching computer programming to young students. The classroom I have in mind has only one computer, that of the teacher. In my case, I have a Raspberry Pi connected to a large television set. The students have pens and notebooks and a USB memory stick prepared by the teacher.



This article is about the memory stick and how to make your own.

My goal is to teach elementary programming skills with the Python language, and the Tkinter modules for graphical user interface - buttons and menus etc. The Idle integrated development environment is included for convenience. A text editor like Notepad is all that is necessary, but Idle will help the programmer with tasks like indentation, parentheses balancing and identifying syntax errors. I'm using the Python 2.7 version, which is still pretty ubiquitous, rather than the newer and incompatible Python 3. Other languages are also possible.

I suppose each student could have their own laptop with them in class, but I don't believe this solution is practical, desirable, or necessary. Laptops are expensive and not every family has one. Those that do may well be reluctant to pack it up and allow their 12 year old child to take it back and forth to class. Every student with their own laptop in class would also create a lot of avoidable distraction and classroom clutter, never a good thing.

My solution is the Raspberry Pi with screen suitable for classroom use, and equipping each student with a USB memory stick. These memory sticks can be used in the classroom and at home, or anywhere else there's a computer, whether it's Windows, Apple or Linux. My design should also be reasonably easy to use and prepare and as safe as can be expected. If they are lost, they can easily be replaced in about 20 minutes. Technically, I think the most difficult task might be the changing of the booting sequence in BIOS at startup. This page should help in that regard.

Getting down to specifics, what I'm proposing here is putting an operating system on a USB memory stick. It can be installed on a stick as small as 1 GB, or even less, and to access the data therein, booted or simply be plugged into an already running system, whether it's Windows or whatever. The Live CD or Live USB that many linux distributions make available seem only meant as a test drive vehicle and not something permanent. A USB that holds an operating system with persistence, ie permanently saves any data files, WIFI passwords etc, created during the session is rare. The technical name for this is a persistent live USB. It's also possible to install an operation system onto a USB as though it were a hard disk drive, but I found these installs slow and prone to problems. All the software necessary is listed down below. No alteration to the parent's computer is needed except for the change to the BIOS booting sequence.

I must have tried out at least 10 different Linux distributions before settling on Puppy Linux. Lubuntu was a runner up and had some advantages over Puppy, more up-to-date for one, but Puppy did everything I wanted without any fuss. I've used Puppy for years now on my older computers, installed on the hard drive. It's fast and stable. At about 150 MB it's extremely light weight, yet requires very little extra software for my intended use. I have listed all the necessary downloads below, in total well under half a gigabyte, about half the size of the Lubuntu .iso file.

I will explain here how a teacher with any computer can prepare the student's USB. First, might as well download all 9 files listed below. Keep them together in a safe place. Then, using the windows .exe file Universal USB Installer, create a bootable thumbdrive by loading the file 'precise-5.7.1.iso.' There's a menu and there's an entry for 'precise' under the Puppy heading.  Preparing the USB will take a couple of minutes.

Once complete, reboot with the USB in place. To boot from the thumbdrive, you may need to change the booting sequence of the computer. On switching the computer on, press the F2 key and this should bring up the BIOS screen which allows the user to change the booting priorities among other things. Different computers may use a different key than F2. Look carefully and quickly at the messages at the bottom of the screen for instructions before the Windows starts to boot. It's all covered in the link I provided above. Booting from USB should be given top priority so that an inserted USB rather than the DVD or hard disk will be booted. This setting can be kept without any inconvenience to normal usage of the computer as long as you are aware that the computer will always attempt to boot whatever is in the USB slot on startup. For normal use, it's best to remove anything from the USB slots on startup. Attempting to boot a non-bootable (ie normal) thumbdrive may result in an error and necessitate a power down and restart.

Now you should have booted the Puppy Linux. You can connect to internet and make any adjustments in time and date if you want.  This is not necessary for the usage I have in mind. Maybe leave it to the more curious students to further explore the system. Beware it is possible to do real harm to the host computer such as formatting the hard drive using a programme like Gparted but that kind of risk remains with any system.

At the root of the USB drive, accessed by single clicking one of the drive icons at the bottom left of the Puppy Linux desktop screen, probably the one labelled 'sdb1,' create a folder called 'homework,' or whatever and copy any of your working files into it. This is done by right-clicking on the desired location and following the instructions to create a new folder. There will also be another folder, probably called 'UUI.' The new homework folder should appear beside 'UUI.' In my homework folder I have some pdf tutorials and other documentation and some projects both complete and incomplete. Also into the USB root, beside 'homework' and 'UUI,' copy the previously downloaded "devx_precise_5.7.1.sfs" file.

 Now single click on menu button, bottom left corner of the desktop, then choose 'Setup' then 'SFS-Load on-the-fly.' Follow the dialogue to load the 'devx_precise_5.7.1.sfs' file just copied to the USB root.The python language modules will now be ready.

The biggest challenge I faced designing the USB was to allow users to access data on the stick without booting, simply by plugging into an already running system, probably Windows. Here is my solution, Single click on the 'File' icon, top left hand corner of the desktop screen. This takes you to the Puppy home folder. Keep the 'Choices' and 'Startup' folders, the rest can be optionally deleted. Less clutter, more clarity is my mantra. Create a folder here, again right-clicking and following the instructions, called 'homework,' exactly like the one created a couple of paragraphs ago. There will now be a 'homework' folder in the USB root and one in the Puppy home.

Copy the following:

#!/bin/bash
# my start up

mv /mnt/home/homework/* ~/homework/

# put following in /etc/rc.d/rc.shutdown (at end)
# mv ~/homework/* /mnt/home/homework/


into a new text file and call it 'my_startup.' Again right-clicking and following instructions to create a file this time. In scripts like this lines beginning with # are comments and not executed. The action is all in the third line which on startup moves the homework folder in the USB root to the homework folder in the Puppy home. Save and store the 'my_startup' file in the 'Startup' folder. To take care of the shut down, navigate to the 'etc' folder. This can be found in the next level up from your present location in 'home.' Click on the up arrow of the file manager. From 'etc' enter the 'rc.d' folder then find the file (not folder) called 'rc.shutdown.' Edit this file by adding the following line to the end:

mv ~/homework/* /mnt/home/homework/

Save the changes. On shutdown now, the contents of the 'homework' folder in the Puppy 'home' will be moved to the 'homework' folder in the USB root. The data on the USB will be easily accessible from any computer.

Almost finished now. Click on the partition icon at bottom left of desktop screen. The icon should be 'sda1' or something like this and navigate to where you stored the 6 smallish '.deb' files downloaded earlier. Click (not double click) on one, (the order doesn't seem to matter) and follow the brief dialogue to install. Continue with the other five. Tkinter and Idle are now installed.

Go to the Menu => Desktop => Desktop drive icons manager. Untick the boxes, This removes the icons from the desktop that give easy access to the hard drive. This amounts to 'child proofing' the system and ideally, I'd like to go further, also removing potentially dangerous software, but I want to do this as quickly and easily as possible.While you are at it, you can optionally remove as many of the desktop icons as you wish. None of them are necessary.

You can also put an 'Idle' icon on the desktop. Go to Menu => File System => 'ROX-Filer file manager,' Navigate to 'usr' at the Puppy root then 'share' then 'applications.' Simply find the 'idle.desktop' icon file and drag and drop it to the desktop.

That's about it. If you want to connect to the internet or adjust time and locality setting etc, it's possible. I typically change the desktop background picture and remove superfluous icons from the desktop. Note that Puppy is a complete system and it's possible to surf the web, watch and download videos, and do whatever is normally done with computers.

When ready, go to the menu to shut down. On shutting down for the first time, you must create a save file. It takes a couple of minutes. My own is a fairly modest-sized 128 MB. I don't need any bigger and the larger the file, the longer the booting time.

That's it. For now, anyways.

from here:
download "precise-5.7.1.iso"  (156 MB)
AND from same place download "devx_precise_5.7.1.sfs"   (148 MB)

from here:
download the following: "blt_2.4z-4.2ubuntu1_i386.deb" (1.5 MB)

from here:
download the following: "idle_2.7.3-0ubuntu2.2_all.deb" (3 KB)

from here:
download the following:"idle-python2.7_2.7.3-0ubuntu3.5_all.deb"   (254 KB)

from here:
download the following:"python-tk_2.7.3-1_i386.deb"  (27 KB)

from here:
download the following:"tcl8.5_8.5.11-1ubuntu1_i386.deb" (1.1 MB)

from here:
download the following:"tk8.5_8.5.11-1_i386.deb" (1 MB)

finally from here:
download the following:"Universal-USB-Installer-1.9.5.9.exe"   (1 MB)

Sunday, October 26, 2014

Time for smut

This morning I woke up to discover that during the night the clocks had been set back an hour back to standard time. This gave me an extra hour. Why not share my latest adventures in cuisine? I bought some huitlcoche yesterday. At 20 peso an ear it's not cheap and its nickname is Mexican truffles. More properly it's called corn smut. It's a kind of fungus that infests corn. I'd read of huitlacoche but I don't believe I'd seen it in the market place and certainly never eaten it. Here it is:


I fried the huitlacoche into a hastily improvised salsa and enjoyed with tortilla chips. Unfortunately, neither my wife nor my dogs were willing to do much more than sniff at the results.


Monday, February 10, 2014

Libertarianism, Children and Smoking

I follow, with increasingly less interest, a libertarian website called Reason.com. Libertarians believe that people should be free to do as they choose as long as they don't hurt anyone. A laudable principle, I think.



So Brendan O'Neill, a libertarian writer who posts at Reason.com, posts this article recently about the Totalitarian Crusade Against Second Hand Smoke. It's all about the attempts to ban smoking in cars where children are present. Brendan argues these attempts "show what shockingly low esteem the ideal of autonomy is held in these days, so that anyone who stands up and says "I think adults should be free to choose what vices to indulge in and pleasures to pursue" is either laughed at for being naive or branded a wicked stooge for Big Tobacco."

Brendan also derides the 'Nanny State' and questions the sincerity of anyone who would speak on behalf of the children. Those commenting on the article take up this line of, let's be generous, argument and we find those disagreeing with Brendan mocked with  cries of "IT'S FOW DA CHILLDRUUUUNZ!"

What I found noteworthy in this exchange is how it squares with Libertarian ethics. Libertarians base their ethics on the sanctity of people to do as they choose, and the honouring of contracts freely entered into by parties who enjoy equal standing before the law. On the surface, it's fairly compelling, but for the fact that children are overwhelming the largest class of society that is systematically, legally prohibited from entering into contracts and fully taking part in society. IT'S FOW DA CHILLDRUUUUNZ only makes sense when one accepts the second class nature of children's participation in society.

Not only do most self-styled libertarians seem to accept this state of affairs, they revel in it. Why are children and the causes that benefit children treated with such contempt? To me, this illustrates the underside of Libertarianism. On the surface, it's all about reason and freedom. Only on the underside does it show its ugly nature: bullying, smugness, cheap-jack cynicism and spite. Children are society's weakest members, legally only a few steps away from a woman's or a slave's position a couple hundred years back. Rather than try to draw children into the circle of freely choosing people that constitutes a Libertarian society, libertarians seem content to kick a man (even better a child) while he's down.

Thursday, January 30, 2014

A Visit to Potaltik

Last Sunday, we enjoyed a visit to Potaltik, a large garden/nature reserve on the outskirts of Comitan, Chiapas, not far from the border with Guatemala. It was not the best season for viewing flowers as the garden was in a quiet period, but I look forward to another visit in a few months when the plants are blossoming. The owners of the garden, Ceci and Jorge, are especially interested in orchids and bromeliads, and they are dedicated to preserving and promoting these plants more than anything else.

http://lagaleriadelcorazonabierto.blogspot.mx/2013/08/el-paraiso-de-potaltik.html


Jorge is proud of his garden, gave us a tour and told us about the orchids. I'd come across the orchid/wasp mimickry in A Thousand Plateaus by Deleuze and Guattari. They use this example of the orchid relying on the wasp, (or with other varieties, other insects and spiders etc) to illustrate their key notions of rhizome and territorialization. (Becoming-Intense, Becoming-Animal) An interesting read but apparently these authors don't nearly do justice to the bizarre complexity of orchid sexuality. I learned from Jorge that orchids can't reproduce without the presence of a certain fungus, and wikipedia backs him up. The orchid's parasitism on the fungi is critical to germination.

It's important to note, that unlike the honey bee, the wasp doesn't feed off the orchid. His attraction is purely sexual, and it is often the case that the visiting wasp will actually ejaculate into the orchid. He'll be fooled again by another orchid and spread pollen in the attempt to find a true female wasp. Another parasitic relationship.

Despite all the fuss and bother, human sexuality is a surprisingly simple affair. Typically, a male and female of the same species get together and they produce offspring.

Orchid sexuality is anything but simple. Life on earth is divided into kingdoms. For those of us without microscopes, there are three kingdoms: plants, animals and fungi. What's significant to me about the orchid's sexuality is that it involves a collaboration spread across three taxonomic kingdoms. I wonder if there is any other living thing, so beautiful and close to us, that enjoys a sexuality so heterogeneous, wide-ranging and dispersed.