CB

I spend an unhealthy amount of time behind a computer. I used to spend an unhealthy amount of time behind a guitar. Recently developed an unhealthy obsession with traditional Irish fiddle and pipes playing.

But other than that, I'm in the best of health.

Save Libraries

A good friend started a campaign about libraries recently, which is getting some international credence (all hail the power of twitter!) My own thoughts take a few more than 140 characters, hence this post.

Some people consider me to be a web 'expert'. I shy from the term, because it is subjective, though I admit to spending an unhealthy amount of time consuming and developing for the web. Recently Amazon's kindle, and the iPad profess to be the future, thousands of books portable, on a single device. Those who search for zeitgeist may agree, the death of the book has been discussed since digitisation and miniaturisation.

However, books have a proven track record. As a child, my grandfather showed me a book from the 1700's from his collection. It had outlasted generations, and wars. I have data on CD-ROMS that haven't lasted 5 years because of a child's sticky fingers. And herein lies the problem. Hard disks fail. CD's will not survive the Frisbee across a room that Tomorrows World promised us. Printing a book remains that the most stable and portable way to encode human knowledge. Encoding errors (smelling pistakes) are reduced toward zero as further editions are produced. And those books are not subject to power surges, or problems when dropped, or solar flares.

While we are distracted by the web, currently the most convenient way to get information, the library is the quiet bedrock of our knowledge, accessible to everyone, always there, and not just available to the internet savvy middle/upper classes. Government beware. Local libraries, no matter how small, are silently important. And they are defended. #SaveLibraries.

Crossing the streams - Land of Lisp chapter 12 - Using SBCL

Previously, I wrote on how to get Chapter 7 of Land of Lisp working in SBCL. To recap my experience with the book, so far it has simply taken the tweak of one line of code, and the rest of the examples have worked straight from the page to the REPL.

Chapter 12 introduces working with streams. It starts by dealing with file read/writes, then ups the ante a little and gets you to create a socket connection between a server and a client. Again, the book posts simple, elegant example code, though it the socket code is not portable to SBCL.

Page 245 offers two libraries cl-sockets, and usocket which attempt to standardise sockets on Common Lisp. After researching them both, I chose to base my solution on usocket for two reasons:

  1. It is used in the hunchentoot web server, which seems to be the most prevalent webserver in Common Lisp.
  2. It is available through Quicklisp.

If you haven't used Quicklisp before, it is an elegant Common Lisp package manager that handles a wide number of libraries (or at least a lot of the ones I've seen in tutorials). My previous attempts at learning the language have all hit the wall over my ineptitude with package management. Quicklisp solved that problem for me, and seems to be idiot (me) proof.  If you choose to use it, once installed, loading usocket should be as simple as typing in the command:

 
(ql:quickload "usocket") 

Once you have usocket we can begin. The API documentation can be found at http://common-lisp.net/project/usocket/api-docs.shtml

Following the examples in the book, there seems to be three parts to getting up and running:

  1. Specify a socket to use on the "server"
  2. Set up a process on the server which listens out on this socket for any action
  3. Set up a process on the client which connects to the socket on the server

To accomplish the first part, which specifies port 4321 to use on localhost "127.0.0.1", I used this code:

 
(defparameter my-socket (usocket:socket-listen "127.0.0.1" 4321)) 

I will interject a thought at this point. Earlier in the book we are given strict instruction to follow convention and use "earmuffs" on global variables. That means that my-socket should be declared *my-socket*. However, in Chapter 12, the code examples do not have * *. I'll follow the books example here, though I've got a suspicion this is one of those earmuff moments.

Once we have a socket declared, we need to set up a process to work with it. From reading the API, I wasn't really sure whether I should use socket-accept, or socket-listen. I chose socket-accept, which worked as I had hoped

 
(defparameter my-stream (usocket:socket-accept my-socket)) 

The REPL may wait at this point, and listen for a connection on this port. Lets set one up on the client side

You'll need to open a new REPL in another window. (I'm using emacs/slime, but this should all work from the terminal too. Note that if you will need to ensure you have usocket loaded into this new instance of the REPL, as above.

Once your client REPL is loaded, you need to create the process that connects to the port on the server REPL

 
(defparameter my-stream (usocket:socket-connect "127.0.0.1" 4321)) 

Now we have a processes on both the client and server, connecting to port 4321 on of "127.0.0.1". We can send our message

From the client REPL, (following the examples in the book)

 
(print "Yo, Server!" (usocket:socket-stream my-stream)) 
(force-output (usocket:socket-stream my-stream)) 

Note that we have to use (force-output). This is because with usocket, the stream is buffered. It will not necessarily send just by printing to it, you must explicitly tell it to do so.

On the server REPL:

 
(read (usocket:socket-stream my-stream)) 
;; "Yo, Server!" 

Remaining with the server

 
(print "What up, Client!" (usocket:socket-stream my-stream)) 
(force-output (usocket:socket-stream my-stream)) 

Then check whether this has been sent to  the client REPL:

 
(read (usocket:socket-stream my-stream)) 
;; "What up, Client!!" 

Once you are finished with the connections, you need to close the connections, by issuing the following command at both REPL's

 
(usocket:socket-close my-stream) 

As you can see, issuing these commands becomes rather cumbersome, so I've hacked together a couple of functions, (stream-read) and (stream-print)

 
(defun stream-read (stream) 
"Reads from a usocket connected stream" 
    (read (usocket:socket-stream stream))) 
 
(defun stream-print (string stream) 
"Prints to a usocket connected stream" 
    (print string (usocket:socket-stream stream)) 
    (force-output (usocket:socket-stream stream))) 

For stream read pass the stream as a parameter and it should return the current stream value.

 
(stream-read my-stream) 

Stream print requires a message, and the stream to send it to.

 
(stream-print "Hello!" my-stream). 

The next chapter in the book deals with creating a webserver. I'm guessing it may also require a work around, if I manage to figure it out, this "series" might continue. :)

I'm also learning to use github, so for those who want it, I created two scripts "server.lisp" and "client.lisp" containing the code above to get the messaging system up and running. The repository is available at https://github.com/ciaranbradley/land-of-lisp-chap-12-usocket

Land Of Lisp chapter 7 - Using SBCL

Over the past few evenings, I've been working through Conrad Barski's "Land of Lisp" book (available at http://nostarch.com/lisp.htm I recommend you watch his groovy video at http://landoflisp.com).

Some of the code in the book is specific to CLISP, however I'm running SBCL, and I thought it might be easier to port the code rather than faff about installing CLISP.

In the book, the code is:


(defun dot->png (fname thunk)
 (with-open-file (*standard-output*
                   fname
                   :direction :output
                   :if-exists :supersede)
 (funcall thunk))
  (ext:shell (concatenate 'string "dot -Tpng -O " fname)))

Most of this block seems to work fine.  it's the call to the shell command to run "dot" that isn't cross platform.


 (ext:shell (concatenate 'string "dot -Tpng -O " fname)))

that isn't cross platform.

With a bit of googling, and trial and error, I have changed the last line, so that it now uses sb-ext:run-program, which I'm presuming is the closest match.  You will need to know the path to your graphviz installation, but the new code should look something like this:


(defun dot->png (fname thunk)
  (with-open-file (*standard-output*
           fname
           :direction :output
           :if-exists :supersede)
    (funcall thunk))
  (sb-ext:run-program "/usr/local/graphviz-2.14/bin/dot" (list "-Tpng" "-O" fname)))

Running it produced the png as expected in the chapter.

I will defer to any experienced LISPer on whether it's best practice to use this command in this way.

Edit:  It's always good to ask :)  I posted this over on HN last night, and this morning I was greeted with a number of great suggestions on how to proceed that should fix the cr:  http://news.ycombinator.com/item?id=1851948

Also if you have ASDF, check out the two liner in the comments provided by fahree.

All of which goes to show me that there is more than one way to skin the proverbial cat in CL, so if one doesn't work out for you all is not lost.

Cappuccino Install Error on OSX 10.4 cygpath: command not found

This is my own hacky resolve of an error while installing cappuccino on a mac (OS 10.4). I just thought I'd share, as I couldn't find any useful stuff online

Basically, the instructions over on http://cappuccino.org/ state that once you download the system, run the bootstrap, and it will pull and install the necessary files. However, in my case, once it got as far as downloading narwhal, it bombed out, throwing the error:

/PATH/TO/NARWHAL/engines/rhino/narwhal-rhino line 1: cygpath: command not found
Exception in thread "main" java.lang.NoClassDefFoundError: ....etc

My fix for this was to go into the narwhal-rhino script and find the block ( at line 35 on my copy)

 
if [ "$(which cygpath 2>/dev/null)" ]; then 
 CLASSPATH=$(cygpath -wp -- "$CLASSPATH") 
 BOOTCLASSPATH=$(cygpath -wp -- "$BOOTCLASSPATH") 
 BOOTSTRAP=$(cygpath -wa -- "$BOOTSTRAP") 
 export NARWHAL_HOME=$(cygpath -wa -- "$NARWHAL_HOME") 
 export NARWHAL_ENGINE_HOME=$(cygpath -wa -- "$NARWHAL_ENGINE_HOME") 
fi 

My shell scripting is shaky at best, but it looks like this conditional is bugging on my system. If I run "which cygpath" from terminal, I get a set of results back saying where it isn't (It's not here). I'm presuming the conditional in this script is looking for NULL, therefore it assumes cygpath is set, and goes to try and run the block.

So I commented out the block (put a # at the start of each line).  Save the file, then try to run Starter/bootstrap again.

This time don't re-download narwhal as it will overwrite your changes. (The script asked me twice if I wanted to download it).

Success. It seems to be working fine for me now.

Check out my new Google background image

Google-background

As ridiculous as it might sound, here's how I got my Google background back to white.  You can also switch off JavaScript (which isn't useful if you are programming in JavaScript, or simply using a web browser in 2010).   The "delete background image" button isn't working for me.  Bad form Google, stop trying to be like Bing!

Edit:  Of course you could be boring (read 'practical), simply follow @cr3's sagelike advice on the matter, and use https://www.google.com/

MPs install malware across every computer in the UK

Members of Parliament voted yesterday 189 to 47 for the new Digital Economy Bill, which would effectively install one of the most cunning pieces of malware ever devised, across every internet ready device in the UK.

 

The bill itself is a rather sprawling piece of legislation attempting to address an eclectic bunch of issues, from the role of Channel 4, to video game classification, to internet usage.  The most contentious parts of the bill are concerned specifically with file sharing on the internet, and specifically with the illicit distribution of copyrighted content.

Peer to peer file sharing is a great way of distributing content, and is an important (if normally unseen) part of the internet.  Universities, and free software organisations (such as vendors for Linux distributions) regularly use file sharing as a free, fast, and reliable way to get their product to the end user.

 

However it is also arbitrarily easy to share content for which you do not hold copyright.  Albums, movies and games regularly show up across these networks, and technical solutions to this problem by copyright holders invariably end up in an "arms race".  The holder will enforce some method to only to have it broken (sometimes hours after release), for them to try harsher technical measures, etc.

 

So copyright groups lobbied the UK government into creating a number of amendments to existing Acts, in a hash fisted attempt to "catch all" eventualities of copyright infringement.  Unfortunately the resultant laws now bear striking similarities to the type of software you pay to keep off your computer systems.

Most people who use a computer nowadays have either fallen victim to, or are at least aware of "malware".  Software which installs on your computer (usually without your explicit consent) and then carries out unauthorised tasks.  The most sophisticated types of malware do not draw attention to themselves, instead they install silently then wait for instruction (sent remotely via the internet at a time suiting the malware creator).  Some variants gather personal data from your computer, then relay that information to a specified server, to be harvested.  Others subtly change the websites you visit.  The most malicious install on so many machines that they can be synchronised to launch large scale attacks, usually "denial of service", where the sheer flood of traffic "takes down" an intended victims internet connection or webserver.

Three tools in the bill, when combined show the hallmarks of a piece of malware.

 

1.  Clause 5, an insertion into the Communications Act (2003) -- 124B Forces an obligation on internet service providers (ISP's) to provide copyright infringement lists to copyright owners.
2.  Clause 17 an insertion into the Copyright, Design and Patents Act 1988 -- 302A (Power granted to Home Secretary to amend the act without consultation).
3.  Clause 4.  Grants powers to force an ISP to disconnect the end user if their IP address is identified in file sharing.
4.  Clause 8.  The Secretary of State for Business can order the blocking of a "location on the Internet which the court is satisfied has been, is being or is likely to be used for or in connection with an activity that infringes copyright."

 

With Clause 17, the Home Secretary gains the power to change the scope of copyright, however he/she sees fit.  Effectively, things that are not illegal today, could be illegal tomorrow, without any requirement by the Home Office to seek parliamentary consent.   Potentially, once the parameters of copyright infringement are changed, a legal order can then be sent to an internet service provider to monitor and subsequently hand over information based on that perceived infringement.  They can then issue a denial of service attack to the end user, using clause 4.  

Taken to a hypothetical case and point.  Many people, and indeed, MP's in the debate pointed at Wikileaks, which regularly publishes information that many political parties, governments, and corporations would rather never saw the light of day.  With the Digital Economy Bill, a piece of damning evidence released on this site could be set as infringing on copyright.  They could block UK wide access to the site.  Then the government could then force your ISP to tell them whether you've downloaded it or not, and take action against you, technically for an infraction.

Of course, that's not what the new legislation is designed to do.  But it wouldn't be the first law that government attempt misuse of an act to silence critics.  Just like well written malware, the Digital Economy Bill will sit there, dormant, waiting to be activated.

David Wright vs The Internet

My local MP, David Wright has hit the headlines for a Twitter faux-pas.  A tweet originating from his account, referred to Tories as "scum-sucking pigs".  It's a cheap nod to the famous "lipstick on a pig" comment from the 2008 US election campaign.  However, the comment flung the MP, who had until then been a relative nobody on the Twitter, into stark, and unwelcome limelight.  

The interesting part is that after the horse had bolted, David issued a statement regarding the affair.  According to him, the offending tweet did refer to lipstick on pigs, but without the "scum-sucking" adjective.  He maintains that the stronger term was added to his tweet in retrospect, by a hacker.  

If you haven't used Twitter yet, the platform does not yet permit the ability to re-edit your tweets (to the annoyance of anyone who has hit the "update" button a little too quickly to catch that blatant smelling pistake).  If you want to correct your actions, you have to delete the message, and start afresh.  Apparently this wasn't the case for David, his message was somehow amended.  

From a technical point of view, I can see only two possible ways for this to happen:

1.  The perpetrator of such a hack would have to be monitoring David's network traffic, then intercept, then re-edit his post before it reached Twitter's server.  Either David's computer/laptop or handset would need to be compromised, or the person issuing the attack would have to be nearby to him when he sent the message (in the event that he sent it over a Wi-Fi network).

2.  The hacker in question somehow broke into Twitter's database server, gained access to the message, and edited it.

Both of the above are no mean feats, the second is a news story in itself.  

The other possible explanation is that David had second thoughts about his tweet.  Looking from a purely technical standpoint, it is a trivial matter of typing into a box, to create an inappropriate message.  Perhaps, after realising the amplified nature of a scandal on twitter, he reconsidered. Something that he saw as fairly innocuous, simply got out of hand.  If this is the case, David should have either offered an apology, or stood by the original statement.  But by telling Twitter (and the news) that his post was re-edited, he's placed himself as the victim of a most sophisticated attack.  Worse in the eyes of Twitter users, he's set himself up as someone who has no real knowledge or interest in the platform which he's chosen for self promotion .

If it turns out that David is lying about the hack, he's taking a very misguided gamble that Twitter users won't be versed enough to catch him out.  Added to the fact that there is a large, active Shropshire contingent on Twitter, such a move could actually affect voting in his own constituency at the next election. 

Lastly, I can point to a precedent in David's past where he succeeded with a similar approach.  Two years back, there was a campaign to keep a small community Post Office open in Randlay, Telford.  Based on his voting record, it seems that the local constituents were fighting against David: 

http://www.publicwhip.org.uk/division.php?date=2004-01-13&number=28&m...

http://www.publicwhip.org.uk/division.php?date=2006-10-16&number=304&...

http://www.publicwhip.org.uk/division.php?date=2007-01-10&number=23&m...

http://www.publicwhip.org.uk/division.php?date=2008-03-19&number=131&...

http://www.publicwhip.org.uk/division.php?date=2008-03-19&number=132&...


His next move was almost Machiavellian. He sent out this letter to all affected constituents:
Wright_letter
It proved to be a coup de grâce, and Randlay lost their Post Office branch.
Good luck to anyone trying something so audacious with the Twitter community.

 

 

Macbook pro battery is utter pants

Just a quick rant, this has been an issue for a while, but looking at the statistics shows just how awful my macbook battery is.

Battery Installed: Yes
First low level warning: No
Full Charge Capacity (mAh): 23
Remaining Capacity (mAh): 23
Amperage (mA): 0
Voltage (mV): 12296
Cycle Count: 388

After 388 charges, my battery now hold 23 mAh, which is about a hundredth of an AA battery.  High end stuff. 

Microsoft openly encourages music piracy?

The videos for the Windows 7 Launch Parties are strikingly odd. With the type of relaxed atmosphere normally associated with the QVC channel, the protagonists try to entice you to hold a party for your friends.

But here at one of the aforementioned parties, a host announces to his friends, "If you've enjoyed the music from tonight... you ought to take it home with you".  He then shows them how effortless it is to burn his music collection to disc. Interesting to note that he doesn't encounter any DRM issues.

Overall the videos feel slightly awkard and unnerving.   Though one only has to point to those Seinfeld adverts..

More at:

http://www.youtube.com/user/LaunchParties

 

Found via @cimota on twitter.

 

 

First post

Just testing, found Posterous through sunnysidecomics, and thought it was a clever idea.