Archive for the ‘Uncategorized’ Category

Tic Tac Toe bot in Bash

April 6, 2017

Bash’s tic tac toe code that translates the code from Perl’s bot.

I got inspiration from http://curtisquarterly.blogspot.com/2005/04/writing-tic-tac-toe-bot-in-perl.html

Basically the bash code recreates the strategies for:

Making a winning move.

Preventing the opponent from making a winning move

Obtaining a “fork”

Preventing the opponent from being able to fork

Taking the center square

The challenges I faced are briefly summarized below:

  • Finding corresponding functionality in bash for perl’s grep and substitution.
  • Updating the variables, since they don’t get automatically changed like in perl. E.g. in Perl the expression grep { /$piece/ && /$move/ && /\d${piece}?\d/ } @wins would at the same time filter @wins and alter it.
  • Placing the returns in the appropriate places and to clear the variables used for accumulation.

The script: tttbot_blog

Note: You can use cygwin64 to run this script in windows.  However, DO NOT copy and paste the script, as windows introduces \r characters.  Rather, rename the script from tttbot_blog.doc to tttbot_blog.sh or tttbot_blog and run it in bash.

To-do: The performance of the bash program is slow. Please wait for up to 15 seconds in the second player’s move and 10 or less for subsequent moves.

Toshiba Satellite: Upgrading from Windows 8 to Windows 8.1

January 14, 2014

This post shows the steps needed to upgrade from Windows 8.0 into 8.1. 

The motivation for this is to be able to bypass the lock screen and the applications screen and to go directly to the Desktop.  This appears to be possible only with Windows 8.1 as it is explained in the link below:

http://howto.cnet.com/8301-11310_39-57591261-285/how-to-boot-directly-to-the-desktop-in-windows-8.1/

So I set off to download windows8.1, which can be obtained for free for 8.0 users from this link

Once on that page click on the link WINDOWS STORE, which you will find surrounded by the text shown below:

“Already running Windows 8? Update to Windows 8.1 for free through the Windows Store.”

Make sure that your power settings are such that the disk never go to sleep or hibernate and the display never turns off.

With my internet connection it took several hours to download the 3.5 GB upgrade. I left it overnight downloading. It appears that after it finished downloading, it automatically restarted the laptop, which was unattended.  The day after I found out that the installation had finished.

Toshiba has some precautions prior to installing the upgrade:
http://www.toshiba.eu/innovation/generic/windows8_1-upgrade-stepbystep/

However, as I said, I couldn’t get to act on them because the upgrade had finished, yet the upgrade appeared to have finished successfully.

I setup the laptop to boot to the desktop as mentioned in the link above: http://howto.cnet.com/8301-11310_39-57591261-285/how-to-boot-directly-to-the-desktop-in-windows-8.1/ see the part highlighted:

goToDeskTop

Now my laptop has a look and feel closer to what I am used to.

Raspberry pi sending temperature readings to email

March 7, 2013

To send temperatures to an email address I based my script on Matthew Kirk’s.  In his work Matthew describes the devices and the connections to the rpi via the GPIO connectors.

Link to Temperature Sensor

1. I have created a script that collects the temperature every 10min.  Twice a day it sends it to an email specified in mailpy2.py.
2. The modified script also adds the file temp_start to /etc/init.d/  so that the script starts when the rpi is connected.

The contents of temp_start are:
sudo python /home/pi/temp4.py

To move the file to the init.d folder and to make it executable:

sudo mv /temp_start /etc/init.d/

sudo chmod +x /etc/init.d/temp_start

sudo update-rc.d temp_start defaults

##temp4.py is shown at the end.

3. Make sure to change your email address and password in mailpy2.py.  Script is shown at the end.
4. Change the UK time:
sudo dpkg-reconfigure tzdataScripts:

mailpy2.py

temp4.py

5. Sample contents of the email received:

Wed Mar  6 13:49:48 2013 79.25
Wed Mar  6 13:56:53 2013 79.10825
Wed Mar  6 13:59:49 2013 79.10825
Wed Mar  6 14:06:54 2013 78.96875
Wed Mar  6 14:09:50 2013 78.827
Wed Mar  6 14:16:55 2013 79.10825
Wed Mar  6 14:19:51 2013 79.3895
Wed Mar  6 14:26:56 2013 79.3895
Wed Mar  6 14:29:52 2013 79.25
Wed Mar  6 14:36:57 2013 79.25
Wed Mar  6 14:39:53 2013 79.3895
Wed Mar  6 14:46:57 2013 78.96875
Wed Mar  6 14:49:54 2013 79.10825
Wed Mar  6 14:56:58 2013 79.25
Wed Mar  6 14:59:55 2013 79.25
Wed Mar  6 15:06:59 2013 78.96875 …

Displaying the name of the table when using sp_MSforeachtable

February 27, 2013

sp_MSforeachtable is very handy in displaying the contents of tables.

Besides displaying the contents, also displaying the name of the table can be done with the ? variable surrounded by ”.  Notice that for each single ‘, two must be used:

declare @q1 varchar(1000) =

exec(”select ””?”” as [table_name]”)
declare @q varchar(1000)
set @q=”select top 10 * from ?”
exec(@q)’

EXEC sp_MSforeachtable @command1=@q1

Notes:

– If something doesn’t work, troubleshooting the contents of @q1 can be done with:

select @q1

-A filter can be added to the sp:

EXEC sp_MSforeachtable @command1=@q1,@whereand=’and object_id in (your_list_here) ‘

–the @whereand comes from:
select * from sys.objects where object_id in (your_list_here)

Transferring mail from Mac 10.4 to Mac 10.8.2

February 10, 2013

The process of transferring mail using Migration Assistant didn’t work.  It showed a message along the lines of “Upgrade Migration Assistant in the source Mac”.  I have not been able to upgrade the app.

Instead, I opened Mail for the first time in the new Mac and that created the necessary folders in the Mail folder (http://www.macinstruct.com/node/183).

Trying to display the Mail folder under the Library in order to copy and paste can be done with (http://osxdaily.com/2011/07/04/show-library-directory-in-mac-os-x-lion/):

Launch Terminal from Spotlight or Launchpad -> Utilities, and enter the following command to show or hide the directory:
chflags nohidden ~/Library/

The users Library folder will immediately become visible again. Reverting this back to the standard Lion setting is simple too:

This returns to the default setting of hiding the user Library directory:
chflags hidden ~/Library/

Changes take effect immediately again, and Library becomes invisible to the user.

After doing that, I copied the Mail folder from the old Mac into the Library with a name Mail_old.

I overwrote INBOX.mbox and Sent Messages.mbox in the  Mail/V2/POP-user@incoming.server  with the old contents.

Ensure you quit Mail.

Delete the Mail/V2/MailData/Envelope Index* to force Mail to reindex upon starting it again.  See https://discussions.apple.com/thread/3352228?start=0&tstart=0

Upon reopening Mail, the Mail Message  Import process gets started and the mail shows in the Inbox and Sent boxes.

Connecting to the raspberry pi via TightVNC Viewer

January 12, 2013

The information below was taken from the link: http://elinux.org/RPi_Wheezy_VNC    The modifications I used are underlined.

Well here we go.

Login to your RPi with putty

#sudo apt-get update  #run this if you need an update
sudo apt-get install vnc-server
vncserver

follow the instructions to add a server password confirm the password say no to the view only option

Close your putty window but leave your RPi running if you reboot shutdown or restart your RPi you will need to re-run vncserver from the command line as it’s not added automatically to the start up script.

NOTE: If you use sudo su or sudo bash or one of the other commands to change to a root login to install vnc-server you need to get back to a pi login before you run vncserver to set the password it goes through the motions if your logged in as root but if you look at the response root is debarred from this action.

Setting up the PC

Now you need to get some software for your PC use your browser and visit

http://www.tightvnc.com/download.php/

I got the Installer for Windows (32-bit) (1,744,896 bytes) rather than the Java viewer [florespino remark]

Go to

Start | TightVNC Viewer

Type your IP address for your RaspberryPi followed by the port 5901 into the Remote Host field.  E.g. 123.2.23.6::5901

Click connect.  You will be asked for the password you setup when installing vncserver in the rpi.

And voi’ la:
Inline image 2

How to setup a headless raspberry pi via wifi

January 12, 2013

The steps to setup a headless raspberry pi involve installing the usb wifi, in this case I used the Edimax EW-7811Un.

The site is very clear and it explains how to setup:

1. To start with, I have a headless rpi connected via Ethernet cable: https://florespino.wordpress.com/2012/12/23/how-to-setup-a-headless-rpi/

2. install the wifi usb using the $10 usb device.  I mind you, there are two pitfalls in running the otherwise excellent script http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=6256

Hence, first backup /etc/network/interfaces file.  I copied it to interfaces.bkup

The first problem is, don’t copy and paste it to a windows text editor.  That process introduces strange characters.  Just download the file to your pc and then copy it to the rpi via:  scp script.sl pi@x.y.z.a://home/pi/script.sl .

The second problem is, if you enter the password for your router incorrectly then the usb wifi is partially installed and it doesn’t work properly. You will need to remove the /etc/network/interfaces file and restore the original interfaces.

3.  Once you run the script and enter the proper user id and password for your wifi network, you can find out the ip address with: ifconfig. That’ll give you the inet addr of your wifi connection to the rpi !

Note:  For additional details about installation, check out the instructions given in: http://contractorwolf.wordpress.com/raspberry-pi-radio/

2012 in review

December 31, 2012

The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.

Here’s an excerpt:

600 people reached the top of Mt. Everest in 2012. This blog got about 6,900 views in 2012. If every person who reached the top of Mt. Everest viewed this blog, it would have taken 12 years to get that many views.

Click here to see the complete report.

Short python program to change voltages in rpi gpio pins.

December 23, 2012

First I installed python:

sudo apt-get install python-pip

and then a library for gpio:

sudo pip install rpi.gpio

Once that was done, the following python script sets a high and low voltage to physical pin 11. Note: the physical pin 11 corresponds to GPIO 17.  The physical pin 6 corresponds to Ground.  For additional details and diagrams refer to: http://elinux.org/RPi_Low-level_peripherals.

import RPi.GPIO as GPIO
import time
for i in range(5):
   print ‘——————‘
   print ‘now in repetition:’,i
   GPIO.setmode(GPIO.BOARD)
   GPIO.setup(11,GPIO.OUT)
   print ‘ON…’
   GPIO.output(11,GPIO.HIGH)
   time.sleep(5)
   GPIO.output(11,GPIO.LOW)
   print ‘OFF…’
   time.sleep(5)

To run the program above, I created a script prendeApaga.py and ran it as shown below:

sudo python prendeApaga.py

Note: additional information for the rpi unit:

linux distribution: ID=debian

user: pi

password: raspberry

 available from: MCM electronics: http://www.mcmelectronics.com/

How to setup a headless rpi

December 23, 2012

I came across this link http://penguintutor.com/linux/raspberrypi-headless and followed the advise of trying to find out the dhcp address.

I connected the rpi via an ethernet cable to my wireless router and booted the rpi.

Then using ipconfig  gives the Default Gateway of my wireless router, x.x.x.1.  Then I noticed the IP address of my laptop, from which I run Putty: it is under IP Address: x.x.x.4.  Since I connected the ethernet cable for the rpi next to the cable of the laptop, to the right, I tried x.x.x.5 and it worked!