December 05th 2015

Not an entrepreneur

Tags: thoughts

I had a couple of realisations recently that in hindsight should have been obvious:

I really love to code and often I even get paid to do it.

I should pause to appreciate that and have fun with my work!

I shouldn’t feel guilty when I write code…

Read more...

January 18th 2014

Automatic updates for Chrome extension hosted in private Bitbucket repository

Tags: howto chrome extension code javascript

A while back at work I wrote a Chrome extension and we wanted it to automatically update itself straight from the Git repository. I ran into two problems doing this however:

  1. The extension did not send the browser’s cookie along with the request for the updates.xml and therefore the request was denied by Bitbucket. Without the cookie you are logged out as far as Bitbucket is concerned, and for a private repository that means no access!
  2. Bitbucket annoyingly returned the X-Content-Type-Options: nosniff header which stops Chrome extensions from proceeding with the update.

Luckily the Chrome extension API provides support for reading cookies and modifying web requests + responses. This gives us everything we need to have our plugin trick itself into updating!

Read more...

December 09th 2013

Disabling read-only warnings in emacs using tramp

Tags: emacs code howto vagrant grunt-contrib-watch

Today I had a problem with watch tasks like grunt-contrib-watch not noticing changes to files inside my Vagrant VM’s NFS share. To avoid this I wanted to edit the files over SSH using Emacs’ tramp-mode, but because of NFS share UID differences it proved difficult. NFS is set by Vagrant to write as the correct user but because the host machine’s UID doesn’t match the VM’s vagrant user the files appear read-only from the VM’s perspective. (With a Mac host at least you end up with the files being owned by 501:dialout, instead of vagrant:vagrant.) This confuses tramp mode and ends up with an RSI inducing amount of “File X is write-protected; try to save anyway? (yes or no)” messages. It took far too long to figure out a way around it but I got there in the end with help from the good folks on #vagrant and #emacs. Here’s a snippet to brutally disable the warnings:

Read more...

October 01st 2013

Wordpress rewrite rules

Tags: wordpress php code howto

I found the Wordpress documentation about custom rewrite rules pretty confusing and most of the blog posts / Stackoverflow posts I could find weren’t much better. Silly thing is it’s actually pretty simple to set up your own rewrite rules when you know how. Here’s what I figured out:

  • You want to create your rewrite rules on the Wordpress init action hook AND the plugin activation hook.
  • You should also flush your rewrite rules after creating them in the activation hook.
  • You also need to create custom “rewrite_tags” to access route parameters in the init hook.
  • The rewrite rule seemingly has to point to index.php i.e., you have to use GET parameters instead of using pretty links in the rule.
  • Pretty permalinks must already be enabled!
  • Flushing the rules on the deactivation hook doesn’t seem to do much good!

Read more...

September 23rd 2013

Form validation by expression in AngularJS

Tags: angularjs javascript code howto

I’m having a go at learning AngularJS, it’s been something I’ve used on and off for a while but I’ve never had the chance to study it properly. Whilst I learn I’m working on a project, otherwise it wont sink in!

One thing my project needed was a change password form. Now I used the handy in-built directives required and ng-minlength to ensure they entered something sensible, but there’s nothing built in for checking that you’ve typed the same password in the second time.

Not a big deal really, initially I implemented directive something like this:

Read more...

January 06th 2012

Telit GM862-GPS hex() bug

Tags: code news python embedded

My SHA1 code was returning a different hex digest when run on my Telit GM862 GPS. I eventually tracked the problem down to the hex() function. Simply put hex(3181490320L) does not return the right result!

Run this test script and post your results below.

Read more...

August 22nd 2011

bit-ratchet, easier binary parsing in PHP

Tags: php project code

Recently I needed to write some code to parse a binary protocol in PHP. Given a ASCII hex string representation of the message I needed to pull off bits and bytes, using them in lots of different ways.

Problem was that you have to read a byte at a time from the hex string, then manually shift bits each time to get what you want. This gets old and confusing very quickly! To solve this I’ve written bit-ratchet, a small class that lets you read bits and bytes from a hex string very simply.

Read more...

May 14th 2011

Embedded development setup with Macbook

Tags: python howto embedded

I’ve been put onto an interesting project recently, doing some embedded Python development for a Telit GM862-GPS unit. Being new to this type of thing it took me a while to get a development environment set up that I was happy with. In an effort to share what I’ve learned, here’s my setup:

(To be clear I’m using the Roundsolutions development starter kit for the Telit GM862-GPS with my Macbook pro.)

Read more...

May 09th 2011

Stop Rails trying to parse the POST / PUT request body

Tags: rails ruby howto

Rails 3 has a nice feature where it will parse the body of PUT and POST requests depending on the Content-type given. So for example if I POST XML to Rails it will all be decoded for me and put into the params hash.

Well it’s a nice feature until you try to switch it off, it’s a nightmare to disable! I managed it in the end, here’s what I did.

Created a piece of ‘rack middleware’ that overwrites the Content-Type for given paths:

Read more...

December 11th 2010

Blocking Spotify's P2P Connections

Tags: howto

It turns out Spotify uses P2P technology so that it can reduce the load on it’s servers. Great, except that uses a fair amount of bandwidth and sometimes that’s not OK.

The client always falls back on their central servers, so we could just block P2P. Problem is that we’re given no manual option to disable, (or limit) P2P sharing. Worse still, the client spawns connections to other users within a massive range of ports making them tricky to block.

I just spent the last few hours looking at this because my bandwidth quota has been destroyed, I’ve got a few ideas and some of them have worked.

Read more...

Older posts Newer posts Atom Feed atom-feed