Skip to main content

Posts

PHP 7.1, all languages converge here please...

Well, I've just spent the last half an hour reading the release notes for PHP 7.1 alpha, and in particular the changes regarding the use of array short-form syntax, that's '[]' to you and me. My lasting impression what that: other scripting languages already do this so PHP is only playing catch-up. Lisp Once again, a language proudly announces a "new" feature that actually already exists half a century ago in Lisp. One day we will all realise that Lisp is actually more productive than "ECMA script based language foo" and start using it. Lisp For all of its wondrous capabilities, Lisp still suffers from a seemingly snobby community that eschews anything remotely close to a "noob" question at times and it can be hard to get to grips with because as yet, apart from Slime and Emacs, there is still a lack of decent IDE support. There's been a lot of discussion recently on the Lispworks forums about tarting up the appearance of ...

AndroidStudio and a RAM Disk

Ok, my iMac is late 2012 and only has 8GB of RAM. I decided to see if it would be possible to speed up my development cycle, especially for running unit tests and the like but just as much for an improved build time as well. After much fiddling in the dark and reading some great pages, I eventually came up with the following solution that works for me but bear this in mind: Danger Will Robinson RAM is volatile so everything you do is gone forever when you unmount it or shutdown so don't forget to copy your changes elsewhere. If you have Git integrated properly then get into the habit of committing frequently. I have considered writing a small bash script to run `rsync` from a custom menu option  (and thus a shortcut key binding) or look into using the Apple Automator to transfer any changed files across to the hard drive. Whatever... you have been warned! Step one: Create the RAM disk, I do it like this: diskutil erasevolume HFS + "RAMBO" `hdiutil attac...

Using a RAM disk with Opera on OS X

Having recently configured AndroidStudio to use a RAM disk for Gradle, I thought I would look around and see if I can use the remaining space for Opera. This is essentially a reproduction of this fine page: http://www.ghacks.net/2010/10/20/how-to-change-the-opera-cache-directory/ That page does not deal with Macs though and after a little bit of experimentation I came up with this spell: open /Applications/Opera.app/ --args --disk-cache-dir=/Volumes/RamDisk/opera For the record, here is my Opera version: Make sure that the specified folder exists before starting Opera, if might automatically create the folder for you but I didn't bother to find out, I hate disappointment. And for the record, the way I create a RAM disk on my iMac, which is done automatically when I log in, is like this: diskutil erasevolume HFS+ "RamDisk" `hdiutil attach -nomount ram://4194304` The above line was courtesy of this YouTube video: Thanks to Bartech TV then! So, with Turbo m...

Handling multipart/form-data with NanoHTTPD

I am in the process of reviving an old project from 2014 that I never finished because of other work commitments. In that time, bitrot has set in, the Android API has moved on and all in all, the home-brewed HTTP server I wrote using SocketServer and the org.apache libraries had to go! I looked around, found a couple of contenders and after much time decided to go with NanoHTTPD because it is lean, small and fits in exactly two files. The main server is in one file `NanoHTTPD.java`and there is another file called `ServerRunner.java` which manages instances of running servers. The others The other project I looked at is this one:  https://github.com/koush/AndroidAsync which led me a merry dance and I just couldn't figure out how get the POST data I had uploaded. I spent a few days really digging at it with Wire Shark too to make sure the data was going up. It was. Whatever... I had used it via a gradle dependency entry but I dropped it and went back to NanoHTTPD. For m...

Quick and dirty Android YouTube fullscreen sample code.

I am currently developing an application that requires playing YouTube videos in full screen mode. After scraping around and putting together the pieces, I currently have the following code which I hope is of use to anybody else out there. public void playYouTubeVideo(String videoId) { String videoTemplate = "@YTBASE@@VIDEO@"; String videoAction = videoTemplate .replace("@YTBASE@", "vnd.youtube://") .replace("@VIDEO@", videoId); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(videoAction)); intent.putExtra("VIDEO_ID", videoAction); intent.putExtra("force_fullscreen", true); startActivity(intent); } There are some points to bear in mind though... Once the ACTION_VIEW intent has control, your application is effectively paused i.e. it won't work until you use the back button to exit the player intent and return to your application. It may or may not work in t...

Prime Peace

I think prime numbers are the numerical expression of peace. Restful nodes in the vibration of everything. Prime factorisation has always struck me as something truly astounding and it is reassuring to know that awsesome minds are hard at work trying to solve the Riemann hypothesis right now. There are some truly wonderful professional and amateur (in the nicest sense of the word) explorations I have watched recently and the ones that moved me the most, in order of cool factor were: This guy,Carlos Paris, has put in some serious work with AutoCAD and made some interesting observations. I truly enjoyed watching all of his four videos. Awesome work Carlos. As an interested amateur I found his work and thoughts to be very compelling. I am sure the professionals would groan or moan but to me this video is most excellent and informative. Speaking of the professionals, this video is also very interesting to watch as it goes some way to visually explaining the Riemann hypothesis in...

Cross platform development with Scheme

Just a quick note about something I recently found whilst trying not to buy MOCL… http://www.lambdanative.org/ LambdaNative is developed and maintained by the Pediatric Anethesia Research Team (PART) and the Electical and Computer Engineering in Medicine (ECEM) group at the University of British Columbia (UBC). I have spent a week or two evaluating it and accidentally contributed a pull request that got merged and one that didn’t and I have to say that, for what it offers, it is awesomely good. Having personally spent many hours with it now, I do not yet think it is ready for mainstream development for a few reasons. I don’t mean that it a bad way either. What I mean is that the language, Scheme, is not really that widely known and as such it probably won’t break out into the public arena any time yet. That’s a real shame because I think that they have achieved an amazing thing; total abstraction of the underlying platform with a really powerful, underestimated language. ...

Control OSX Screen Brightness from Ubuntu 14.04 (on a USB stick!)

After trawling here and there and trying lots of different things, for me this works on my late 2012 21″ iMac with an ACPI card. It’s best to put the script into a file, make sure the file is discoverable on PATH. All details are in the folder: /sys/class/backlight/acpi_video0 which on my machine looks like this: ubuntu@ubuntu:~/mc2$ cd /sys/class/backlight/acpi_video0 ubuntu@ubuntu:/sys/class/backlight/acpi_video0$ ls -l total 0 -r--r--r-- 1 root root 4096 Oct 7 08:29 actual_brightness -rw-r--r-- 1 root root 4096 Oct 7 08:29 bl_power -rw-r--r-- 1 root root 4096 Oct 7 08:28 brightness lrwxrwxrwx 1 root root 0 Oct 7 08:29 device -> ../../../0000:01:00.0 -r--r--r-- 1 root root 4096 Oct 7 08:03 max_brightness drwxr-xr-x 2 root root 0 Oct 7 08:29 power lrwxrwxrwx 1 root root 0 Oct 7 08:29 subsystem -> ../../../../../../class/backlight -r--r--r-- 1 root root 4096 Oct 7 08:03 type -rw-r--r-- 1 root root 4096 Oct 7 08:03 uevent WARNING: If you use values higher than the maximum...

Emacs fat fringes and colours

Having gotten used to various editors implementations of distraction free or presentation mode views, I figured that emacs could probably do something similar with little effort. As usual, it could. For me, distraction free means no clutter, no menu bars, tool bars, gutters, line numbers, just the code. The first step is to be able to set the size of the left and right margins to something large, 100px works quite well. I use Aquamacs a lot. This does not work in the terminal! So, here is the little bit of code you need to place into your beloved ~/.emacs file: (defun fringe-bars (width) (interactive "pWidth:") (fringe-mode (cons width width)) (set-face-attribute 'fringe nil :foreground (face-foreground 'default) :background (face-background 'default))) Then, using the Ctrl-U prefix, you would set the left and right margins to be whatever you want, let’s say we wanted to have 500px left and right, which wor...

OSX GNU Guile — beating libltdl into submission

After encountering an issue with socket handling in the remote REPL server code I needed to build guile from source but it just wouldn’t. I downloaded a mint latest source from http://www.gnu.org/software/libtool/ and gave it this spell: ./configure --prefix=/opt/local to make it overwrite the Mac Porst version to see if that would fix it. It didn’t. After further close reading of the configure help text for guile the answer was there as usual, resulting in this incantation: ./configure --with-libltdl-prefix=/opt/local --prefix=/opt/local Result… clean run of the configure script! Now all I have to do is build it and get to the bottom of the problem. Apparently it only happens on OSX, Ubuntu is not affected, nor presumably is any other *nix. Oddly, geiser mode works, if that is using com-int buffers then I don’t see why I cannot then use telnet or netcat to connect to the REPL server. We’ll see! It’s got something to do with opening a socket in non-blocking mode then sen...

The ultimate programming language ?

After many years of thought and many years of using many languages, I am now more and more convinced that the “perfect” combination, if such a thing exists, is going to be a mix of Haskell, LISP and Prolog. Exactly what “combination” means in terms of the different programming paradigms each presents is completely unknown to me at this point! Haskell is functional, Prolog is logical and LISP is everything. LISP First of all, the uniform s-expression shape of LISP is so absolutely pure, clean and simple that I feel it’s the true shape of expressing thoughts as code. If you work in LISP long enough you don’t even see the parens any more. Really. And the implied return value being the last thing you did is also useful. Haskell Haskell is incredibly clean in its form. The use of a space character as the argument separator is cool. The functional aspect is also very very nice. What I don’t like about Haskell is the IO / monad thing, Sometimes it feels incredibly hard work to do th...

Why is software development still so hard?

Total experience to date: thirty-one years. Started with UCSD Pascal and Z80 assembler. Currently into Haskell and Prolog and anything functional. Putting all that to one side, as we all know that the language you use to implement a solution is by and large irrelevant, no really, you know it is… I find myself lately finding it harder and harder to want to embark on any sort of personal project. A mere twenty years ago I was brimming with enthusiasm for it but these days I just find myself wanting to watch cat videos on YouTube. Initially... I was spell-bound (and to some extent still am) at the age of eleven that you could “express an idea” in the language that the computer could understand, be it BASIC or whatever was available and then sometime later have that idea executing. Of course, the idea has to be information processing centric; that’s what the infernal machines do so well. Eventually... I realised that you could express solutions using any number of techniques rang...

Command line atmospherics with mpg123

I have loved listening to SOMA.FM for years, especially Groove Salad. I also recently found a brilliant little site called soundrown.com , which plays various background noises in response it seems to recent scientific study that shows a certain level of background noise helps you get in the zone, stay there and be more productive. Being a command line person, I looked around to see if I could mix the two and not have to use a browser, and here is my solution, using mpg123: $ mpg123 -q http://173.239.76.148:8032 & $ mpg123 -q http://www.soundrown.com/Audio/Final%20Normalized/mp33/CoffeeShopFinal15.mp3 & You can put it into a script I guess like I did. The “-q” stops any output and the trailing ampersand backgrounds the processes; this stops junk appearing in your terminal window from time to time. I can’t work without it much these days, it helps to drown out the office noise around me.

Communicating between controllers in AngularJS

I have seen many solutions to how to make controllers talk to each other whilst at the same time remaining within "da rulez" of writing Angular applications. I have been using Angular for about a month now and at times it has been swearier than a good Haskell session, it is most definitely worth it all in the end. I have written a really nice looking web application for my employer and they seem to like it. I think Angular. One thing I really aced (to my own satisfaction at least) was wrapping a REST (of any type) API using a resource. I will make a separate post about that. Do the simplest thing... Here is my own solution to the problem of how you can make different controllers communicate cleanly using the "event" system that Angular provides. All you have to do is ensure that the following event listener is added to your application root-scope: App.run( function( $rootScope )) { $rootScope.$on('broadcast', function( e, data ) { if (undef...

Angular.JS ... absolutely awesome BUT...

Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaagh! Sort the documentation soon please!  More soon, I really do like it though. :)

Curried Functions, my favourite!

I have understood the concept of "currying" for quite some time now but it wasn't until last night that I really understood how useful it (currying) can be when you want to use a standard library function but pass it something slightly different... I was playing with reading a file using the "withFile" function, withFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r Thing is, the function I wanted to write, as part of its duties, needed to print the filename to the console output before doing its thing... I knew that it could be done and for once I was going to think it through and make it happen! My function had the same type, (Handle -> IO r) , but now I wanted to add in the String that would be the filename and the penny dropped... by using partial application I could "part-bake" a call to my function and leave it in such a state that it would "fit" the required type... read on... got: Handle -> IO r...

Haskell, GHC and --hash-size=31

A few nights back I decided to return to an on-going self-education project in Haskell and much to my dismay, when I issued the "ghc --make ..." utterance it failed to complete and instead gave me the error: $ ghc --make hwtest.hs Linking hwtest ... /usr/bin/ld: --hash-size=31: unknown option usr/bin/ld: use the --help option for usage information collect2: error: ld returned 1 exit status WTF? When did my linker system or GHC break when I wasn't looking? After two unsuccessful postings to the Haskell beginners newsgroup (unsuccessful as in they appeared not to have made it through the inter-web) I gave up and dug a little harder and turned up this post on the web: http://www.haskell.org/pipermail/cvs-ghc/2011-November/068562.html Bingo. I remedied the situation by performing this from the command line: sudo apt-get remove binutils-gold I didn't even know I had this package but then I suddenly remembered that a few nights previous and had foun...

PHP and Lisp: multiple-value-bind (MVB)

This is another article in my attempts to find new ways of looking at PHP and making it less of a chore to type in all that code. As much as I love PHP I hate wasting keystrokes. More typing is more errors is more grief. Being an off and on user of Lisp, although not as much as I used to, one of the things that I always liked in Lisp was the ability to be able to return multiple values from a function at once using (values) and then marry that with (multiple-value-bind) to create convenient named bindings for whatever you were about to do. I recently found myself wanting to return a couple of values from a helper function and I just didn't want to go to the trouble of having to type all those character required to create an array with keys for the two values and then I remembered MVB and a little light went on in my head! If somebody else has already done this then I apologise up front but it was new to me and I haven't seen it anywhere else so this could be a first! ...

PHP and Maybe miserable Monads

I decided recently, while starting a new project, that it would be interesting to try and take some of my new found paradigms from Haskell back into the relative slums of PHP. As much as I like the fact that PHP just works, the more I get into Haskell the more I resent having to type reams and reams of code in PHP just to get things done. That's just me and I won't change! One of the things that I am really starting to miss now that I understand Monads (at least enough to write them and use them, my own and the libraries) is the ability to be able to have "Maybe". It is such a lovely way of handling data when there really isn't anything and it sure as hell kicks ass over using "NULL" as a return type. PHP is riddled with functions that return FALSE to mean they didn't actually work or some other value if they did which makes a whole mockery of its so called "types". Case in point, when using PDO for example (I could be w...

Using PHP_CodeSniffer for nefarious purposes!

I recently had the task of learning how to implement our internal company PHP coding standards documents which exist only as a set of JIRA pages into something that could be integrated into the subversion pre-commit checking phase so that not only does code have to be syntax error free, it now also has to adhere to the coding standards. I remembered reading about PHP_CodeSniffer (PCS) and volunteered to "have a look" and see if I could implement one of the more simpler standards, our variable naming convention, as a starter exercise. Well, after the mandatory head-banging and spike in coffee consumption that accompanies learning new stuff, I became very impressed by the way that PCS actually does what it does. It builds upon the token_get_all()   function and creates not just an array of tokens and there positions but it also figures out (I read the source for half an hour!) which bits of code are contained within other bits of code; in other words the context within which...