API Gateway & ‘Single’ Quotes

Very quick post to explain something that has bothered me for longer than it should have today and it needn’t bother anyone else.

When you use API Gateway and Lamba you will likely use the standard ‘Body Mapping’ function that passes through everything in the request to the Lambda function. It parses url parameters and delivers it to Lambda as a nice JSON object you can quickly make use of.

There is one snag however, it doesn’t like single quotes. The minute you pass in a url parameter with a single quote you will get this error:

{"message": "Could not parse request body into json: Unrecognized character escape \'\'\' (code 39)\n at [Source: [B@7d54c1f5; line: 7, column: 27]"}

Ugh you think, it was all working so nicely. Well there’s a simple fix. Replace your body mapping template with this one, actually there are only two line changes to the default one.

## See http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
## This template will pass through all parameters including path, querystring, header, stage variables, and context through to the integration endpoint via the body/payload
#set($allParams = $input.params())
{
"body-json" : $input.json('$'),
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
#set($pval = $util.escapeJavaScript($params.get($paramName)).replaceAll("\\'","'"))
"$paramName" : "$pval"
#if($foreach.hasNext),#end
#end
}
#if($foreach.hasNext),#end
#end
},
"stage-variables" : {
#foreach($key in $stageVariables.keySet())
"$key" : "$util.escapeJavaScript($stageVariables.get($key))"
#if($foreach.hasNext),#end
#end
},
"context" : {
"account-id" : "$context.identity.accountId",
"api-id" : "$context.apiId",
"api-key" : "$context.identity.apiKey",
"authorizer-principal-id" : "$context.authorizer.principalId",
"caller" : "$context.identity.caller",
"cognito-authentication-provider" : "$context.identity.cognitoAuthenticationProvider",
"cognito-authentication-type" : "$context.identity.cognitoAuthenticationType",
"cognito-identity-id" : "$context.identity.cognitoIdentityId",
"cognito-identity-pool-id" : "$context.identity.cognitoIdentityPoolId",
"http-method" : "$context.httpMethod",
"stage" : "$context.stage",
"source-ip" : "$context.identity.sourceIp",
"user" : "$context.identity.user",
"user-agent" : "$context.identity.userAgent",
"user-arn" : "$context.identity.userArn",
"request-id" : "$context.requestId",
"resource-id" : "$context.resourceId",
"resource-path" : "$context.resourcePath",
"radiobase" : "now-playing-submit"
}
}

Read More

Alzheimer’s light therapy

An article published in New Scientist today suggests that light therapy may help in the treatment of Alzheimers. There are many caveats around it, it’s only been tested in mice and only seemed to benefit the visual cortex, not other areas of the brain. So the chances of it working on humans are perhaps slim, however the experiment was rather straight forward and low risk. It just used a 40hz light source which is easily recreated on a computer, so I thought it would be cool to build a little page that simply generates a 40zh flash from black to white. If you suffer from Epilepsy then it’s obviously a bit risky so I put a warning on the page before it starts. It’s only roughly 40hz as the timer in the browser isn’t all that accurate – so for that reason alone this is probably useless.

https://madel.in/dev/flash.html

Read More

Friday Lunchtime Playlist

Well I’ve had a month off to collect my thoughts, decide if I want to Vote Remain or Vote Leave, do the hokey cokey, go to a few weddings and do some running up REALLY massive hills. Anyway, The Friday Lunchtime Playlist is back!!! Yay! ‪#‎NewMusicFriday‬

This week featuring music from these great people/bands…
MontaigneBecause I Love You
BrijsThunder
DROWNERSConversations With Myself
of Montrealits different for girls
Death Valley GirlsIm A Man Too
Earth HeartHomesick
Savoy MotelSouvenir Shop Rock
Ethan BurnsHomeward
Smith & ThellStatue
REPARTEEDukes
ZAYDE WØLFHustler
Moons Of MarsTake It Easy
AVI ON FIREPearls
Free SwimThe Slingshot Maneouvre In Apollo 13
Goon SoulWhos Gonna Love Me
Lake JonsIn Time
John SplithoffSing To You
Jim Caesar5050
NeikedSexual
FLUIR & Jesse MarantzIve Gotta Have You

Read More

Friday Lunchtime Playlist

In many ways its been a horrible week – we’ve lost some legends of both comedy and music. The great Victoria Wood and the music legend Prince! So this week we kick off the playlist with a nod to Prince from an of Montreal cover of Computer Blue.

This weeks playlist is as follows:

of Montreal – Computer Blue
The Perks – Enough Of This Place
THANKS – Dizzy
Tancred – Bed Case
Fragile Creatures – Fragile Creatures
Love in October – Teenage Evolution
Jerry Williams – Mother
Hanni El Khatib – “Baby’s OK”
Pretty City – Running Around
Magic Potion – “Cola Boyys”
Carnival Youth – Surf
Weaves – Candy
The Academic – Chasers
Marsicans – Swimming
YOKE LORE – HOLD ME DOWN
Spring Break – Degenerative Eloquence
Sheer Mag – Can’t Stop Fighting
ELEL – Animal
Two Year Vacation – Love Will Come Back To You

Read More

Getting Apache to work under Ubuntu on Windows Insider Preview build 14316

OK – so that’s a very long title to this post for what is actually a very simple solution.

Like many I’m sure I was eager to try the new build of Windows 10. The first thing I wanted to try when it first booted? Ubuntu and bash of course.

By default, it’s not installed, you have to go into Windows Update Settings, down to ‘For Developers’ and make sure ‘Developer Mode’ is switched on.

Then you have to hit windows key, type ‘Windows Features’ [enter], and scroll to the bottom of the list and tick ‘Windows Subsystem for Linux (Beta)’.

For some I gather you then need to reboot, but on my machine it didn’t.

Anyway, after all that, I thought, ooh, let’s try running Apache on Ubuntu on Windows.

First I typed ifconfig to see what ip address it had, was it different? .. well that command doesn’t work yet so I was thinking maybe apache wouldn’t work either.

So I installed with ‘apt-get install apache2’.

It installs fine, but its not running. It throws the error:

mktemp: failed to create directory via templat ‘/var/lock/apach2.xxxx…’.

Turns out that /var/lock is a symbolic link to /run/lock, which doesn’t exist.

So all you need to do is mkdir /run/lock, restart apache, and hey presto you are up.

But what IP address is it at? .. as Ubuntu is running natively on Windows there is no virtualisation so it has the same IP address as your local machine.

So browsing to localhost should do the trick. If you have another service using that port then edit /etc/apache2/ports.conf and change to a different port.

Hope that helps a few people.

Read More

Homemade Radio

Reading this week about the sad demise of Live365 it got me thinking about the hopes and dreams of younger Dave. Younger Dave wanted many things, to travel the world, to drink lots of beer, meet lots of girls and of course – make my millions and run a radio station. Some how I was deluded into thinking the last two were interlinked, run a radio station and make a fortune, it was simple. Build something great and the masses will come. It’s a common fallacy, you have the best idea – of course you do, everybody else must think the same as you do, it’s so brilliant! It’s as true now with the multitude of stations/platforms as it was a decade ago.

Older Dave is a little wiser, he knows radio stations don’t attract an audience just by being brilliant, you have to bang on doors, spend money on advertising and build brand awareness. He also knows it’s a lot of work, and as I’ve already alluded involves a lot of money. That’s where Live365 went some way to help new entrants, it provided the infrastructure to get you going. True most of them were tin pot jukeboxes that had few listeners, but still if you had an idea you could get it on the internet for virtually nothing. So I did a bit of hunting around and came across another similar platform, Radionomy, and had a go at creating a station. I already had a catalogue of music from my weekly playlists that would act as a playlist, all I had to do was upload it all, throw in a bit of cheesy production and hey presto young Daves hopes and ambitions would not be completely forgotten.

So an evening or two later and I have a rather basic radio station that’s on TuneIn and soon to be on Pure Connect (the Pure Radio platform). Have I got any listeners, no, of course not, but I knew that. This was born more out of curiosity than any real ambition to make anything proper, but I’ll keep it going as a vehicle to help promote (to one man and his cat) The Friday Lunchtime Playlist – which is slightly more manageable than a fully fledged radio station.

If you fancy a listen you can find it on TuneIn by searching “FLP Radio”

Read More

Friday Lunchtime Playlist

It is week two of trying to get artists to record intro’s (drops) to songs, I think it makes these shows sound a lot better and hopefully from a listener perspective it increases the likelihood they will check out the band more deeply.

Featuring this week, music from : Katy Gunn, Laney Jones, Mass Gothic, Slutface, Weezer, Robert Pollard, argonaut&wasp, SOFI TUKKER, Nat Slater, JUNIOR PROM, Banta, Radiation City, Oscar, exmagician, Get Inuit, kakkmaddafakka, Santigold, Stealth and Melaena Cadiz.

Please LIKE and REPOST on MixCloud, this really helps get the show up the charts 🙂

The Friday Lunchtime Playlist – 2016-01-22 by The Friday Lunchtime Playlist on Mixcloud

Read More