Monday, July 1, 2013
Open Day, Part I
Wednesday, June 12, 2013
Raspberry Pi
SD Card
I bought a new 16 gigabyte SD card for a tenner from the students' union shop. I think I paid about £130 for a 2 gigabyte hard disk back in the mid-nineties (I have a pile of them propping up a bookshelf in my office). Downloaded the raspbian image on to my Linux netbook, popped the SD card into the slot, and created the image (the card was automounted as /dev/sdb1, hence the first command):umount /dev/sdb1
dd if=2013-05-25-wheezy-raspbian.img of=/dev/sdb bs=4M
Network
The RPi was already registered for the campus network, so I haven't bothered with any of the static network address recipes - it picks up its address through DHCP.Additional software
I installed (using apt-get) the following packages:- apache2
- php5
- libapache2-mod-php5
- xfce4
- tightvnc
- arduino
VNC
I want to run the RPi headless most of the time, and don't want to have to muck about with monitor cables and spare keyboards when I do need to use the GUI. Initially, I took the RPi up to one of the labs where I could pinch a monitor with DVI input, and work in peace. These instructions worked to get VNC up and running. I used vinagre and remmina to test the setup - VNC is now starting reliably at boot time.Web server
I want the web server to use one of my subdirectories as root (documents in /home/pi/www/htdocs, CGI scripts in /home/pi/www/cgi-bin), so I edited /etc/apache2/sites-enabled/000-default to change the values of DocumentRoot, ScriptAlias, and the permissions on /home/pi/www/htdocs/.Desktop
I use xfce as my standard desktop (I like Gnome 4 on netbooks, have never got on with Unity). Selecting that as the default is simple (like most of the commands above, this has to be done using sudo to give yourself root privileges):update-alternatives --config x-session-manager
A menu appears, and I was able to choose /usr/bin/startxfce4 as my session manager.
Wednesday, April 17, 2013
Gmail
The answer: https://accounts.google.com/DisplayUnlockCaptcha
This doesn't actually display a Captcha, but it opens a ten minute window during which, if you use the application which is getting password rejections, the password will be accepted and the application added to a "whitelist".
Thursday, September 27, 2012
CTRL-ALT-DEL
I was accidentally switched to the new service a couple of days ago, and found that access to the Z drive from both my Linux PC, and the Windows 7 virtual machine I run on it, no longer work (the X drive still works, but that seems to still be on older file servers). Pending the resolution of that problem, a new PC fell off the back of a lorry and I am back to having two computers on my desk, one running Linux and one Windows 7 (which I think we are officially supposed to call "UOL" because there are no other things associated with the University of Leicester which might use the initials "UOL" and it will not be at all confusing). Linking them using synergy:
Linux
From this page. I had to install a newer version of synergy (1.4, the current Ubuntu version is 1.3).In the instructions below, EG-PC845 is the Linux box which will be running the server, and EG-PC1184 is the Windows machine.
As root, create /etc/synergy, and put this lot into /etc/synergy/synergy.conf:
section: screens
EG-PC845:
EG-PC1184:
end
section: links
EG-PC845:
left = EG-PC1184
EG-PC1184:
right = EG-PC845
end
Then put this lot into /etc/synergy/startsynergys, followed by chmod +x /etc/synergy/startsynergys to make the file executable:
#!/bin/bash /usr/bin/synergys -c /etc/synergy/synergy.conf -n EG-PC845
And finally, append this to /etc/lightdm/lightdm.conf:
greeter-setup-script=/etc/synergy/startsynergys
The synergy server will now start when the machine boots.
Windows
Install synergy as normal, setting it up to start as a client when the machine does, and connect to the IP address of EG-PC845. The only remaining problem is to do CTRL-ALT-DEL to log on to Windows 7, because you are no longer using the keyboard attached to the PC. The solution is to use gpedit.msc again, as described here: enable Local Computer Policy / Computer Configuration / Administrative Templates / Windows Components / Windows Logon Options, with the option "Services and Ease of Access applications". CTRL-ALT-PAUSE then works in place of CTRL-ALT-DEL.Thursday, July 26, 2012
Looking ahead
#!/usr/bin/python
from tempfile import mkstemp
import shutil
import os
ifpath = "a.txt"
fh, ofpath = mkstemp()
ofile = open(ofpath, "w")
ifile = open(ifpath)
lines = []
length = 0
while True:
previous = ifile.tell()
line = ifile.readline()
if length + len(line) < 140:
lines.append(line)
length += len(line)
else:
ifile.seek(previous)
print lines
break
for line in ifile:
ofile.write(line)
ifile.close()
ofile.close()
os.remove(ifpath)
shutil.move(ofpath, ifpath)
This opens a.txt for reading (as ifile), and creates a temporary file (ofile). There's then an infinite loop - each time round, I store the current file location as previous, read in a new line, and check to see if that would take it over the limit. If not, I add the new line to the stored array. If it will go over the limit, I use ifile.seek() to go back to the file location before I read in the new line, and then print out the lines stored so far. All that remains is to write the unread lines (including the one I read in and decided not to use) to a temporary file, remove the original a.txt, and replace it with the temporary one.
Wednesday, July 25, 2012
Twitter Updating
#!/usr/bin/python
import tweepy
import feedparser
import urllib
import urllib2
url = "http://www2.le.ac.uk/departments/engineering/news-and-events/blog/RSS"
oauth_file = open("access_token.txt", "r")
oauth_token = oauth_file.readline().rstrip()
oauth_token_secret = oauth_file.readline().rstrip()
consumer_file = open("consumer_keys.txt", "r")
consumer_key = consumer_file.readline().rstrip()
consumer_secret = consumer_file.readline().rstrip()
bitly_file = open("bitly.txt", "r")
bitly_username = bitly_file.readline().rstrip()
bitly_apikey = bitly_file.readline().rstrip()
bitly_base = "http://api.bit.ly/v3/shorten?"
bitly_data = {
"login" : bitly_username,
"apiKey" : bitly_apikey,
"format" : "txt",
"longUrl" : ""
}
already_done = []
done_file = open("done.txt", "r")
for line in done_file:
already_done.append(line.rstrip())
done_file.close()
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(oauth_token, oauth_token_secret)
api = tweepy.API(auth)
feed = feedparser.parse(url)
count = 0
for item in feed["items"]:
url = item["link"]
title = item["title"]
if url not in already_done and count < 2:
bitly_data["longUrl"] = url
to_shorten = bitly_base + urllib.urlencode(bitly_data)
result = urllib2.urlopen(to_shorten).read()
api.update_status(title + " : " + result)
already_done.append(url)
count = count + 1
done_file = open("done.txt", "w")
for url in already_done:
done_file.write(url + "\n")
done_file.close()
Monday, June 4, 2012
Raspberry Pi
A Raspberry Pi arrived late last week, just before I came away for the bank holiday. So I bought a cheap USB keyboard, checked that an old iPod power supply coupled with a Kindle cable would provide enough oomph (just about), and took the lot to my mother's. Unfortunately the keyboard (PC World Essentials) turned out to be one which won't work. Also, I can't keep coming to my mother's house every time I want access to a TV with an HDMI socket. Here's how I got access to the board via my laptop, which runs both Windows and Ubuntu Linux 12.04 - instructions are for the latter, and while I think the instructions below could be adapted for Windows they would probably be more complex. In any case, if you're going to be doing things with an ARM board running Linux, why wouldn't you also be running Linux on your other machines?
- Enable SSH. I paid for an SD card pre-loaded with Debian. Stick the card in the laptop, rename boot_enable_ssh.rc to boot.rc, and put the card back into the Pi before powering up.
- Plug the Pi into one of the ports on the back of the wireless router. Using a web browser on the laptop, go to the router's management page and look up the list of attached devices. I found that the Pi was on 192.168.0.3.
- Open a command prompt on the laptop, and do "ssh pi@192.168.0.3". Password is "raspberry", and you should be logged on to the Pi.
- Update packages: sudo apt-get update followed by sudo apt-get upgrade.
- Install a VNC server: sudo apt-get install tightvncserver.
- Run the server: tightvncserver - you'll be asked to set a password.
- Start a VNC server with a resolution that will fit in your monitor - I used vncserver :1 -geometry 800x600 -depth 24
- On the laptop, run vinagre, a VNC client, and choose to connect to 192.168.0.3:1 via VNC - the password you will be asked for is the one you set in step 6, not the password from step 3.
- An LXDE desktop should appear: