Alexa Skill Error: The remote endpoint could not be called, or the response it returned was invalid.

Alexa Skill Tutorial Error - The remote endpoint could not be called or the response it returned was invalid.

If you have tried building an Alexa Skill, you might have gotten the error “The remote endpoint could not be called, or the response it returned was invalid.”

For me, the error was related to uploading a zip file with the index.js and its node_modules libraries to the Lambda service. No matter what zip file I would upload, I’d get the following error:


{
"errorMessage": "Cannot find module '/var/task/index'",
"errorType": "Error",
"stackTrace": [
"Function.Module._load (module.js:276:25)",
"Module.require (module.js:353:17)",
"require (internal/module.js:12:17)"
]
}

It turns out when Amazon means zipping, they are expecting a different zip file structure than the one created by the default Mac OS X action of right click and compress the directory. When a Mac compresses a folder, the output is a folder with the files in it. Amazon wants it without that root folder.

Assume you have a source folder called TestSkill with index.js in it. Then you do a right click and Compress “TestSkill” on it. If you run this:

nali-iMacs-iMac:Downloads nali$ zipinfo TestSkill.zip | grep index.js |more

you’ll see this:

16-Dec-30 15:42 TestSkill/index.js

Pretty much what Amazon does not want. Instead, go into the folder and type this:

zip -r foobar.zip package.json *.js node_modules

You want the ‘-r’ so folders in node_modules get added to the zip file as well. Then let’s run the following command to look into the zip file:

nali-iMacs-iMac:Downloads nali$ zipinfo foobar.zip | grep index.js |more

Here is what you should see:

16-Dec-30 15:42 index.js

That is the structure Amazon wants.

Let’s turn this into an npm command. In your package.json, add a script:


{
"name": "foobar",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"zip": "zip -r foobar.zip package.json *.js node_modules"
}
}

When in the folder, running ‘npm run zip’ will create a foobar.zip that can be successfully uploaded to Amazon’s Lambda service and the error “The remote endpoint could not be called, or the response it returned was invalid.” should go away.

Galaxy Nexus + Straight Talk + AT&T + MMS APN Settings

If you are using a Galaxy Nexus on Straight Talk with a AT&T provisioned SIM card and having issues with sending and receiving MMS, here are the APN settings that should work for you.

The Galaxy Nexus that I bought through Google Play had a Cingular APN already on it. Delete it. Or at least write down the settings just in case everything breaks on you. And then delete it.

Add a new APN with exactly these entries:

  • Name: straight talk (or whatever you want it to be)
  • APN: att.mvno
  • Proxy: proxy.mvno.tracfone.com
  • Port: 80
  • Username: Not set
  • Password: Not set
  • Server: Not set
  • MMSC: http://mmsc.cingular.com
  • MMS proxy: 66.209.11.33
  • MMS port: 80
  • MCC: 310
  • MNC: 410
  • Authentication type: Not set
  • APN type: Not set
  • APN protocol: IPv4
  • APN enable/disable: APN enabled
  • Bearer: Unspecified

That should be it.

Fixing Contact Form 7 Redirection Referrer Failure with IE

On a client WordPress site, we wanted to use Contact Form 7 to grab visitor information and redirect them to an inner page after submission. To make sure they filled out the submission form, the destination page checked the referrer to make sure they came from the form page. Now, there are other ways of doing this, like setting cookies, but this method was good enough for the client.

So this all worked in Chrome and Firefox, but not Internet Explorer.

Shocking.

The Contact Form 7 blog has instructions on how to redirect users to a different page after a successful submission. Under Additional Settings, simply do this:

on_sent_ok: “location=’http://www.fubar.com/thanks’;”

The on_sent_ok is a Javascript hook. Inside of scripts.js in the plugin, it eventually makes this call:

if (data.onSentOk) $.each(data.onSentOk, function(i, n) { eval(n) });

So “location=’http://www.fubar.com/thanks’;” gets evaluated by Javascript and the page redirects. Great.

On the destination page, we were checking the referrer to verify they were coming from the form, here is an example of how you could do it:

/* Set where they should be redirected to if user didn’t come from the form */$redirectString = “Location: “. get_site_url() . “/contactform”;

$referrer = $_SERVER[‘HTTP_REFERER’];

if ($referrer == NULL){ header($redirectString); exit();}else{ $domain = parse_url($referrer); $pos = strpos ($domain[“path”], “contactform”); if ($pos == false) { header($redirectString); exit(); }}

Now, your PHP should be cleaner, more error checking, check for XSS, don’t hard-code anything, etc, etc.

The problem was that the referrer would always be null when the visitor was using Internet Explorer. Referrer isn’t required to be set by the browser. Browsers won’t set it if you started out on a HTTPS site but click on a non-secure link.

And IE won’t set it on redirection, but it will set it if you click on a link. So if a fake a link click, IE will set the referrer.

Lets create a Javascript function to fake a link click. This code is stolen from Stack Overflow:

function goTo(url){ var a = document.createElement(“a”); if (a.click) { // HTML5 browsers and IE support click() on <a>, early FF does not. a.setAttribute(“href”, url); a.style.display = “none”; document.body.appendChild(a); a.click(); } else { // Early FF can, however, use this usual method // where IE cannot with secure links. window.location = url; }}

Ok. Remember, the Contact Form 7 redirection is a Javascript hook. So now we change the on_sent_ok to call the goTo function instead:

on_sent_ok: “goTo(‘http://www.fubar.com/thanks’);”

Bam. Done.

ASP.net MVC: The controller for path /favicon.ico does not implement IController

One of Run Level Media’s project involves migrating a Windows application over Terminal Services, to the web. A previous programmer had started building the web app in C#, ASP.NET MVC 2. We decided to upgrade for the sake of maintainability and wanting to use some of the newer features in MVC 3 (like Razor).

After upgrading and trying to debug code, I kept running into the following error on every page load: ASP.net MVC: The controller for path /favicon.ico does not implement IController

It was true that the favicon.ico was missing, but we didn’t want to make a temporary one. We just needed requests for dot files to the root directory to be ignored.

Most Global.asax have route definitions like this:

routes.MapRoute( “Default”, “{controller}/{action}/{id}”, new { controller = “Home”, action = “Index”, id = “” });

There are really two problems here. First, the controller looks for something to handle favicon.ico. More than likely, you don’t have a function to deal with favicon.ico (why should you). Second, the HttpException should be caught and dealt with. Either log it or provide a more helpful message. Otherwise you’ll see ‘HttpException was unhandled by user code’ errors.

To fix the controller, try this:

routes.MapRoute( “Default”, “{controller}/{action}/{id}”, new { controller = “Home”, action = “Index”, id = “” }, new { controller = @”[^.]*” } );

new { controller = @”[^.]*” } means ignore anything that matches that regex.

How to Flash / Install Ubuntu Touch on Galaxy Nexus from Mac OS X

ubuntu-touch-preview-on-galaxy-nexus-smaller

These are instructions for how to flash / install Ubuntu Touch on a Galaxy Nexus GSM from Mac OS X.

If you brick your Galaxy Nexus by following these instructions, its your fault. Don’t do this if you are a noob or never installed a custom ROM. Consider yourself warned.

Pre-requisite: Unlock your phone. Google it.

  • Download the following files from http://cdimage.ubuntu.com/ubuntu-touch-preview/quantal/mwc-demo: quantal-preinstalled-phablet-armhf.zip, quantal-preinstalled-recovery-armel+maguro.img, and quantal-preinstalled-armel+maguro.zip.
  • Download the Android SDK
  • Unzip the SDK.
  • Open up Terminal.
  • cd into adt-bundle-mac-x86_64/sdk/platform-tools
  • (Optional: move the above downloaded files into the platform-tools directory or just specify the location of the files below)
  • Turn off the phone.
  • Boot into bootloader (as in press down both Volume up/down and power for a couple seconds).
  • Back in the Terminal, type:
./fastboot flash recovery quantal-preinstalled-recovery-armel+maguro.img

Looks like this installs a version of ClockworkMod Recovery.

  • Reboot back into the bootloader by clicking on Volume Up or Down till you see ‘Restart bootloader’ and clicking on Power.
  • Go into Recovery Mode by clicking the Volume Up/Down button a couple of times till you see Recovery Mode. Then click the Power button.
  • Back in the Terminal:
./adb push quantal-preinstalled-phablet-armhf.zip /sdcard/0/Download/quantal-preinstalled-phablet-armhf.zip

And then:

./adb push quantal-preinstalled-armel+maguro.zip /sdcard/0/Download/quantal-preinstalled-armel+maguro.zip

The sdcard is referring to the internal storage, not a separate SD card (which the Galaxy Nexus doesn’t support anyway).

  • Select ‘install zip from sdcard’ (use Volume keys to scroll and Power to select)
  • Select ‘choose file from sdcard’
  • Go into /sdcard/0/Download.
  • Select quantal-preinstalled-phablet-armhf.zip.
  • Scroll to ‘Yes – Install…’ and select it. The zip will get installed.
  • Select ‘choose file from sdcard’
  • Go into /sdcard/0/Download.
  • Select quantal-preinstalled-armel+maguro.zip.
  • Scroll to ‘Yes – Install…’ and select it. The zip will get installed.
  • Select ‘+++++Go Back+++++’ a few times to go back.
  • Select ‘reboot system now’

Have fun.

G+

Magento: PHP Fatal error Undefined class constant ‘TYPE_CONDITION’ Abstract.php on line 296

This is what happens when you don’t pay attention. I was working on a project that started out when Magento 1.4.1.1 was the latest stable version. There is a bit of development left, but I decided to upgrade the install to 1.4.2 via subversion. I go get some coffee, come back, and assume the upgrade is done.

Then I try to load the homepage, and I get a blank screen. Eh, ok. Time to display errors by commenting the following line in index.php.

[code]ini_set(‘display_errors’, 1);[/code]

Lets see what the logs say:[code]PHP Fatal error: Undefined class constant ‘TYPE_CONDITION’ in /home/dev/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php on line 296[/code]

Well, what exactly is the code throwing this error? In Abstract.php:

[code] if (!empty($conditionSql)) { $this->getSelect()->where($conditionSql, null, Varien_Db_Select::TYPE_CONDITION); } else { Mage::throwException(‘Invalid attribute identifier for filter (‘.get_class($attribute).’)’); }

return $this; }[/code]

How can Varien_Db_Select::TYPE_CONDITION not exist? I looked at my Varien/DB/Select.php and there was no TYPE_CONDITION. Then I looked at Varien_Db_Select in the Magento docs, and it was there. Weird.

Then I looked back at the terminal which was doing Subversion update, and noticed that there was an error. Apparently my Internet connection had died and the update didn’t complete. Ugh.

After restarting the Subversion update, I look at Varien_Db_Select:

[code]class Varien_Db_Select extends Zend_Db_Select{ const TYPE_CONDITION = ‘TYPE_CONDITION’;

const STRAIGHT_JOIN_ON = ‘straight_join’; const STRAIGHT_JOIN = ‘straightjoin’; const SQL_STRAIGHT_JOIN = ‘STRAIGHT_JOIN’;[/code]

There it is.

Moral of the story. Make sure your updates actually complete before making such an assumption.

ImageMagick: Batch Crop and Rename Files

There are many better ways to do this, but here is one method if you need to do a quick and dirty jobs of cropping and renaming a bunch of files in a batch with ImageMagick.

Quick little background. Even though I’ve got a Macbook, if I have to look at code, I’m usually on a desktop thats running Ubuntu 10.04. We host client sites on servers running Ubuntu 10.04, so its best to write code in that environment. So today, after finishing up code for a Magento site, I needed to upload a set of fabric swatches that would be used with configurable products. The client provided images for the fabric swatches, but they were all different sizes. All I needed was a 60x60px selection of each image and the filenames to be something descriptive with the image size. 

Of course, this can be done pretty easily in Photoshop. I’m sure there is some plugin for it, but you can record an action, and run it against a batch of files. The problem was that I didn’t want to hop on my Macbook just to crop and rename files.

Since I was on an Ubuntu machine, my first gut reaction was to fire up Gimp and see if I could do it. Turns out there is a plugin called David’s Batch Processor that pretty much does that. Ubuntu has the plugin in the repository, just search for ‘gimp-plugin-registry’ in Synaptic. Gimp also supports scripting, but the scripting language is Scheme-like, and I didn’t want to recall knowledge from freshman year in college to do this.

Then I remembered ImageMagick. While ImageMagick has a GUI for image manipulation, its got a powerful CLI that lets you do pretty much anything you want to do. So no need to open up a big honkin’ application just to do some basic cropping and renaming.

So save the following code in the directory of the files you want cropped and renamed and run it:

[code]#!/bin/bashwidth=60;height=60;x_offset=10;y_offset=5;filelist=`ls | grep ‘.jpg’`for image_file in $filelistdo preextensionfilename=`convert $image_file -format “%t” info:` convert $image_file -crop ${width}x${height}+${x_offset}+${y_offset} ${preextensionfilename}_${width}x${height}.jpgdone[/code]

Most of this should be pretty self-explanatory. Up top we define what sizes we want the images to be cropped to and from where in the image we want to crop. Then we grab a list of all the files we want to crop, and grab the filename before the extension (to be used for saving the new files). The convert command is what actually does the cropping and saving the files with the new names, in this case, something like oldgold_60x60.jpg.

The script is most definitely not robust, but hopefully it will be a good starting off point for some.

How to do a Jawbone Icon Hard Reset

With a new Galaxy Nexus, I couldn’t pair my bluetooth headset with it. Seemed like I needed to reset it. So here are instructions on how to reset the Jawbone Icon:

  • Turn it on
  • Wait for white blinking light.
  • Very quickly, click the talk button 6 times
  • Wait for white blinking light to blink red.
  • Hold down the talk button.

When it flashes red and white alternately, the Jawbone Icon is done resetting.

iPad Pin It Pinterest Bookmarklet in Safari

iPad Pin It Pinterest Bookmarklet in Safari

It looks like Pinterest hasn’t provided a convenient way of adding the Pin It bookmarklet to Safari on the iPad. But try the instructions below. Its been tested with iOS 5.

Step 1Bookmark this page in Safari on the iPad. Give it a useful name like Pin It.

iPad Pin It Pinterest Bookmarklet in SafariiPad Pin It Pinterest Bookmarklet in SafariStep 2Copy the javascript below:

javascript:void((function(){var%20e=document.createElement(‘script’);e.setAttribute(‘type’,’text/javascript’);e.setAttribute(‘charset’,’UTF-8’);e.setAttribute(‘src’,’http://assets.pinterest.com/js/pinmarklet.js?r=’+Math.random()*99999999);document.body.appendChild(e)})());

iPad Pin It Pinterest Bookmarklet in SafariStep 3Go back and replace the bookmarklet address with the javascript above.

iPad Pin It Pinterest Bookmarklet in SafariStep 4Pin away!

iPad Pin It Pinterest Bookmarklet in SafariiPad Pin It Pinterest Bookmarklet in SafariiPad Pin It Pinterest Bookmarklet in SafariiPad Pin It Pinterest Bookmarklet in SafariFollow me on Pinterest.

Tweet me if the Pin It bookmarklet no longer works.