Last.fm to Spotify Play

Spotify recently announced their new Play Button. So I thought it'd be cool to incorporate it into my homepage. But what tracks should I have be played? Then I got the idea of using my Last.fm charts to generate the tracklist.

So first I had to grab my weekly track chart from Last.fm, thankfully they provide a nice xml feed which can be found at ws.audioscrobbler.com/2.0/user/[username]/weeklytrackchart.xml. I just used the cURL extension in PHP to grab the XML and the parsed it to grab the track names and artist names and store them temporarily in an array.

Now, for getting the Spotify track IDs so I can generate the play button. Thankfully Spotify has an open MetaData API that I can use to search for and retrieve the IDs. I took great influence from this PHP library called metatune. However, it does far more than I need, and it uses file_get_contents to query the API, which requires having allow_url_fopen set to true in my php.ini file. I'd rather use cURL, its faster and more versatile.

There is one caveat, searching Spotify normally leads to multiple results. I've assumed that the first track is the one I want. I then get this list of track IDs and save them to file. Its then just a question of reading this list and dumping it into the HTML of the homepage.

You can have a look at my code on GitHub, its not quite finished, I need to incorporate some sort of actual error handling.

News this week (12w15)

Oxford University and the Vatican are to digitize 1.5 million pages of ancient texts and make them freely available online. This has been made possible by a donation of £2 million by the Polonksy Foundation. This seems exceptional value. For all I may complain about the church, more freely available knowledge can only be a good thing and for that they have a little bit of my repsect. Though it will be interesting to see just how this is made available. This is still huge news though.

An 8.6 Magnitude earthquake struck near Indonesia on 11th April 2012. Thankfully it appears not to have cause a massive tsunami. The earthquake was a strike-slip earthquake so not too much water was displaced. I will be interested to see how the aftermath of this plays out and I hope things recover to normal as quickly as possible for those affected.

Woop! Looks like ACTA might not pass, it appears that the European Parliament will reject the legislation. This looks increasinlgy likely as the person in charge of taking the legislation through parliament is recommending that the bill be voted against. You can sign an Avaaz petition. Though depressingly it appears the powers that be are working on a replacement.

Anders Breivik, who set off a bomb in Norway and went on a shooting spree that killed 77 people, has been declared sane by a second psychiatric evaluation. This would mean he could stand trial for his crimes and face a jailterm. Though its still up for an actual court to find him legally sane or not. Though if insane he will be sent to a ward instead of a cell, either way the guy is facing life.

Yeah, more religious news, Kuwait are provisionally passing an amendment to their penal code which would allow the death penalty for cursing god. I mean, seriously! Come on! Surely if Allah is all-powerful he can look after himself? Unless this is the usual politicians using religion to pass laws useful for their own needs.

Liam Stacey was jailed for some of his tweets. Miss Coren wrote a superb piece on the matter. It really is something that we in the U.K. need to discuss. The Mayor of London recently stopped a gay therapy advert from being run on some London buses. What is allowed and what isn't? I personally feel people should be allowed to say what they want. As long as they aren't directly insulting someone in an overly aggressive manner or harassing people. What offends me may not offend someone else. We have to be careful as to what our law censors.

News this week (12w14)

The U.K. government has said it wants to monitor all web and e-mail activity to combat terrorism and crime. Though thankfully it appears the Liberal Demecrats might fight the bill. Though I don't hold up too much hope, they've turned on every other promise so far. The Guardian talks about this much better than I can. It is indeed a delicate issue, my only strong opinions are with regard to the internet, which is a force for so much good that I wouldn't want that affected, especially when you consider how non-effective any policy will be in dealing with actual criminals, just pipe everything through a VPN and bam, no government snooping! This is made clear in a story this week from Al Jazeera. Anonymous has hacked several Chinese government websites, the defaced websites then explain how someone in China can circumvent the government's restrictions on internet usage.

The internet really seems to be under attack from all sides. ACTA could pass in 10 weeks, perhaps we should try and do something. Will WW3 be people against their governments? We also have the return of SOPA, though this time it is known as CISPA. Though I'm not sure if the same resistance will be mounted against it by the Internet communities like Wikipedia or reddit. When will the people in power learn?

The I.C.C. says they cannot investigate alleged Israeli crimes in Gaza and the West Bank. They say that because Palestine is not an officially recognised U.N. member state they have not ratified the Rome treaty and therefore these 'crimes' are outside the I.C.C.'s jurisdiction. There is the possibility of the U.N. security council stepping in and giving jurisdiction, but with the U.S. on the council that isn't going to happen. What a sorry state of affairs this all is. I should try and do a post about the whole Israel/Palestine thing sometime.

Some good news from Tunisia, who say they shall reject Sharia law in their new constitution. And some bad news from Tunisia, who jailed two people for drawing cartoons of Mohammed. Religion cannot exist above the law. Of course people should be allowed to practice whatever faith they want in private. The intricacies of such religion cannot be part of the moral fibre that binds us all together. The law needs to protect everyone, especially those that otherwise might find themselves oppressed. This includes people's speech.

Again we have someone decrying the war on drugs. It really is time that politicians realised this. Prohibition doesn't work, it just forces drugs into the black market. So what if someone wants to take drugs. Its their body, its their choice. Hopefully with more people in power taking more moderate stances with regards to drug laws we may some change soon.

And finally, an Irish priest accidentally flashed gay porn during a presentation to parents of children preparing for their first Holy communion.

News this week (12w13)

Guatamala's president Otto Perez says the 'War on Drugs' has failed, and it is time to end the taboo on discussing decriminalisation. Perez thinks that decriminalisation could reduce the amount of drug-related violence. Whilst a complicated issue, there is evidence that this could be a good route. Portugal introduced a progressive drug policy some ten years ago. It is important to realise that information on drugs before this policy change is sketchy, but there are strong indicators of reduced HIV transmission rates and drug related deaths. The workload of the police decreased whilst the amount of drugs seized increased. Perez is right on one thing though. This is something we should be discussing.

Ontario's top court legalises brothels to protect prostitutes. The idea being that it is safer for prostitutes to work in a brothel where protection and security can be provided than in isolation. The situation before the ruling was similar to the situation in my home state the U.K. I agree with the ruling in Canada as I feel nothing will really change except for the improved working conditions of the prostitutes. We won't suddenly be handing them off as we walk down the street!

News surfaces that Murdoch's News Corporation promoted piracy in Australia. By damaging the competing network's pay TV offerings the allegation is that News Corp was able to subsequently corner the market. In case you didn't realise, this is the same News Corp that owned the News of the World newspaper in the U.K. that was ultimately discontinued due to a phone hacking scandal. Ahh, more bad news for Mr. Murdoch, it sometimes makes me wonder weather there is karma in the world, only briefly mind. Here's a Panorama video about the whole thing: http://www.youtube.com/watch?v=0clg2m-ePd0. There's even suggestions they undertook similar business practices in the U.K.

Pakistan is planning to punish parents who do not have their children vaccinated against polio. They plan to fine parents who don't get their kids vaccinated. This part of an effort to stop the spread of the debilitating disease. Pakistan is one of the few remaining countries that hasn't eradicated polio. I am glad that the government is seeing sense, though there are clearly many obstacles to overcome, particularly when the population can be very suspicious of vaccines and other western initiatives.

Denmark aims to get 50% of its electricity from wind power. They ultimately aim to get all their energy from renewables by 2050, a commendable goal. They, like most of us, lag behind Norway, where over 98% of electricity is from renewables. Countries like these are perfect in my opinion in testing and developing the technology required for alternative energy sources on a medium scale. This is going to be one of the toughest challenges the up and coming generation faces, what to do when the oil tap dries up?

French president Sarkozy announces that he will make it a crime to consult web sites advocating terrorism or hate crimes. This is obviously fuelled by the recent killings in Toulouse which was seemingly a terror crime. There is a question of exactly how the French government hopes to do this without unfairly breaching peoples right to privacy on the web.

And finally, Kazakh gold-medallist is shocked when the wrong national anthem is played. Instead of the proper tune, a parody Kazakh anthem made for the film Borat is played instead. Just how lazy was the person responsible for this?

Can Scotland be independent?

Unless you've been living under a rock I'm sure you've no doubt heard that Scotland want independence. Well, the SNP wants an independent Scotland. They currently hold a majority of seats in the Scottish Parliament. Mr. Salmond, leader of the SNP, believes that this gives him a mandate to try and get independence, seeing as this was the idea they ran their election hopes on.

Personally I would be sad to see Scotland leave the United Kingdom. I feel that both Scotland and England have benefited greatly from the partnership. In the long run I feel we are better united than divided. Putting this aside I think there are serious questions that need answering before Independence is ratified.

Mr. Salmond's SNP has said that Scotland would continue to use the Sterling as its currency. This poses certain issues with regards to financial sustainability in my opinion.

First let's consider the U.K. as it currently stands. We are a sovereign state with our own central bank, namely the Bank of England. The central government, located in Westminster, handles the fiscal policy. They decide how much public debt we have. It is important to note here that this public debt is denominated in Sterling. We have an unlimited supply of Sterling. In theory at least, the Bank of England can just 'print' off as much money as is necessary. Obviously this leads directly to inflation and is therefore not the best way to pay off debt. It helps nobody. The point is, however, that the option of simply inflating our way out of debt is there. So technically speaking the U.K. cannot default. Being unable to default makes a government a very safe investment, we shall ignore the situation in the eurozone. Financial institutions with money, e.g. pension schemes, private banks etc., therefore like investing their money in governments. This point is acutely made when we look at the interest rates on U.S. debt. They have real negative interest rates. People are paying America in order to lend America money!

If Scotland leaves the U.K. and remains on the Sterling currency they will be in a position where they take on debt in a denomination they have no control over. They cannot simply inflate there way out of tricky situations. Yes, that last sentence does grossly oversimplify things; but look at the eurozone. The smaller countries are suffering and their situation is in no way being helped by being on the Euro. Greece are the prime example of this. Their economy is not competitive and with the demands being put on them by the rest of the eurozone they are genuinely suffering.

This is the kind of situation Scotland could see themselves in. Staying on Sterling hinders their ability to influence the bond market. So called because if I lend money to a state, they then give me a bond with an interest rate and a maturity date. They have effectively sold me a bond, or debt if you want to call it that. Thus we have the bond market. This is a free market. A government does not decide the interest rate they pay on the debt. The people buying the bonds do. That's how free markets work. If investors think Scotland may default, they won't buy debt unless they get a satisfactory interest rate. If we look in the eurozone we can see the political pressure this is putting on countries like Spain and Italy. An effective tool against this is to buy up some of the debt with the central bank. This doesn't solve any problems directly, it merely delays having to deal with it. If you can get your economy to grow in the meantime you may be able to solve it later.

This is why politicians are always harping on about economic growth. With a bigger economy you can support more debt, which allows us to service the debt we have now. It may seem a weird idea, but that's how our government debt works. Its a bit like musical chairs, though we have seen over the last few years what happens when the music stops playing.

I am simply suggesting that the ability to service debt through the bond market will be of the utmost importance in questioning whether Scotland can exist independently. This is something I think will be made harder by Scotland either staying on the Sterling or joining the Euro.

It is not a question that I am seeing asked.

Chris Brown's Police Report

Here is the LAPD report for Chirs Brown's attack on Rihanna:

\"A verbal argument ensued and Brown pulled the vehicle over on an unknown street, reached over Robyn F. with his right hand, opened the car door and attempted to force her out. Brown was unable to force Robyn F. out of the vehicle because she was wearing a seat belt. When he could not force her to exit, he took his right hand and shoved her head against he passenger window of the vehicle, causing an approximate one-inch raised circular contusion.

\"Robyn F. turned to face Brown and he punched her in the left eye with his right hand. He then drove away in the vehicle and continued to punch her in the face with his right hand while steering the vehicle with his left hand. The assault caused Robyn F.'s mouth to fill with blood and blood to splatter all over her clothing and the interior of the vehicle.

\"Brown looked at Robyn F. and stated, 'I'm going to beat the sh-- out of you when we get home! You wait and see!' \"

The detective said \"Robyn F.\" then used her cell phone to call her personal assistant Jennifer Rosales, who did not answer.

\"Robyn F. pretended to talk to her and stated, 'I'm on my way home. Make sure the police are there when I get there.'

\"After Robyn F. faked the call, Brown looked at her and stated, 'You just did the stupidest thing ever! Now I'm really going to kill you!'

\"Brown resumed punching Robyn F. and she interlocked her fingers behind her head and brought her elbows forward to protect her face. She then bent over at the waist, placing her elbows and face near her lap in [an] attempt to protect her face and head from the barrage of punches being levied upon her by Brown.

\"Brown continued to punch Robyn F. on her left arm and hand, causing her to suffer a contusion on her left triceps (sic) that was approximately two inches in diameter and numerous contusions on her left hand.

\"Robyn F. then attempted to send a text message to her other personal assistant, Melissa Ford. Brown snatched the cellular telephone out of her hand and threw it out of the window onto an unknown street.

\"Brown continued driving and Robyn F. observed his cellular telephone sitting in his lap. She picked up the cellular telephone with her left hand and before she could make a call he placed her in a head lock with his right hand and continued to drive the vehicle with his left hand.

\"Brown pulled Robyn F. close to him and bit her on her left ear. She was able to feel the vehicle swerving from right to left as Brown sped away. He stopped the vehicle in front of 333 North June Street and Robyn F. turned off the car, removed the key from the ignition and sat on it.

\"Brown did not know what she did with the key and began punching her in the face and arms. He then placed her in a head lock positioning the front of her throat between his bicep and forearm. Brown began applying pressure to Robyn F.'s left and right carotid arteries, causing her to be unable to breathe and she began to lose consciousness.

\"She reached up with her left hand and began attempting to gouge his eyes in an attempt to free herself. Brown bit her left ring and middle fingers and then released her. While Brown continued to punch her, she turned around and placed her back against the passenger door. She brought her knees to her chest, placed her feet against Brown's body and began pushing him away. Brown continued to punch her on the legs and feet, causing several contusions.

\"Robyn F. began screaming for help and Brown exited the vehicle and walked away. A resident in the neighborhood heard Robyn F.'s plea for help and called 911, causing a police response. An investigation was conducted and Robyn F. was issued a Domestic Violence Emergency Protective Order.\"

At the end of his statement, Andrews said Brown sent a text message nine days later apologizing.

\"In the text message, Brown apologized for what he had done to Robyn F. and advised [Rihanna's assistant] Ford that he was going to get help.\"

This behaviour by Chris Brown is abhorrent. I find it personally disgusting that this man still has a job in the entertainment industry where he is seen by many young fans as a role model. Further it is a job where he earns millions a year affording him a lucrative lifestyle we mere mortals can only dream of.

Currency

Hopefully no short URL is created for this. Now?

On we go

I have removed the ability to comment, yes, I know a blog without comments isn't a blog. I just need to work out a way of doing it properly. I'd rather not store user details. Hopefully I'll work out how to let you authenticate with facebook/twitter/openid. We'll see. Having looked into this further, it should be possible using OAuth with either Facebook or Twitter. OpenID may well be too hard to implement, seeing as I only want to do a small part of what it is capable of.

Also, I've tweaked the login system slightly, it should now be quite secure, with the use of an authentication token. Both the token and password are stored in the database hashed, using the excelent phpass. There are still a couple of potential weak spots, like session fixation, not sure if I'm secured against that yet.

Till next time. I don't know when that will be though :)

What now?

I have been looking after my uncle's dog for the last two weeks, giving me plenty of time to work on this site. It might not look like much has changed on the surface. Though frontend development isn't my forte.

What has changed is the backend. I now use PHP's PDO for the database interaction. This allows much better management of errors for one thing due to the try/catch nature of PDO coding. It should hopefully make it easier to migrate away from MySQL/Oracle calamity. The obvious choice would be MariaDB but I hear good things about PostgreSQL.

I'm also working on the authentication system. I know use PHP sessions, with a cookie for persistent login. I am taking my inspiration from this well thought article about the matter. Though I still need to sure up the security side of things, particularly against CSRF attacks.

One final thing with regards to security, you may have noticed I know require https to browse this website. Why not?

My blog is coming together

Links now work nicely. Though there's still lots I want to do. Briefly:

  • Show 'archives' better - hmm, this might require a bit of recoding.
  • Get rid off categories, tagging is sufficient.
  • Introduce ability to notify of new posts on fb and twitter - Will do this manually, may not want all posts syndicated.
  • Microblogging to twitter/facebook.
  • More mobile friendly interface

So all I have left is the mobile interface. :)

My name is Jonny Barnes, and jonnybarnes.uk is my site. I’m from Manchester, UK .

I am active to varying degrees on several silos:

My usual online nickname is normally jonnybarnes for other services. I also syndicate my content to the IndieWeb friendly site micro.blog. Here’s a profile pic. I also have a PGP key, with fingerprint. You can email me at jonny at my domain, or message me on XMPP.