Doug’s Blog

Handily dispensing information to .00000001% of the world’s population

Archive for the ‘Coding’ Category

Having trouble accessing your Alexa skill

Friday, June 21st, 2019

We have done a number of Alexa skills for clients and recently one of them would give this message to users: “Sorry, I’m having trouble accessing your {} skill right now”

Not much to go on! It turns out the problem was the content that was getting delivered for Alexa to say had some non-ASCII characters in it. The skill has dynamic content the client would update, and apparently they pasted from a Word doc which then translated a quote character into one of those annoying double wide Word characters which Alexa does not like!

So basically run your content through an ASCII-only parse before delivering it and you’re good.

Applying callback to grecaptcha

Tuesday, June 5th, 2018

We were having some troubles with some users rushing to click the submit button on a form immediately after clicking the good ‘ole “I’m not a robot” checkbox, instead of waiting nicely for the captcha to verify. By the way, that is TOTALLY what a robot would do, so it’s probably good that it fails the verification.

But to get the submit button to only enable after the checkbox turns green, you need to provide a “callback” routine for the grecaptcha. And, you can also provide a “expired-callback” routine for if the captcha box sits around too long after a check and then turns red. Note that you need to put the defined callbacks without quotes.

Also to add some complexity, we had two separate captchas in our page, so we had to define two of them. Some people have reported troubles doing so, but our final solution worked.

We had a problem where the callback routines were not being called, but everything else was working — it turns out we have the callback functions defined AFTER the render, and moving them before that section made everything work. So, the final layout:

<script src=”” async defer></script>
var myCaptInit = function() {
var buton11 = function() {
var butoff11 = function() {
$(“#mainsubmit”).attr(“disabled”, “disabled”);
grecaptcha.render(‘recaptcha11′, {
‘sitekey': ‘xxxx’,
‘callback': buton11,
‘expired-callback': butoff11,
‘size': ‘compact’
grecaptcha.render(‘recaptcha10′, {
‘sitekey’ : ‘xxxx’,
‘size’ : ‘compact’

SFTP in Perl Connecting to Legacy Server

Tuesday, January 16th, 2018

We had a client that had a need to do automated SFTPs to various sites. It turns out that some of the sites had an older SSHD that would generate an error like “DH Group Exchange reply out of range”, and that required this parameter if you were using SFTP from the command line:


Now in Perl we were using Net::SFTP and it took some finagling (yes, that’s really a word) to figure out the proper settings, so here they were in case you were having trouble. And we had to add the warn flag otherwise we would get this warning:

Couldn’t fsetstat: Permission denied

Another oddity was that when we were putting files, the SFTP server allowed multiple files with the same name! Very odd, so we had to make sure to add a $sftp->do_remove command prior to the put command.

Here is what we used for the function call:

%sftp_args =
( “user” => “myuser”,
“password” => “mypass”,
“debug” => 0,
“warn” => 0,
“ssh_args” => [ options => [ “KexAlgorithms diffie-hellman-group1-sha1″ ] ]

$sftp = Net::SFTP->new($sftp_host,%sftp_args);

Installing Node.js4 in Centos7 with Yum

Saturday, July 23rd, 2016

A quick summary that may help people who are installing AngularJS v2 and need to make sure they have the latest stuff.

First off, CentOS does not use a recent version of Node,js or NPM due to, well, lots of reasons! In fact the version the repo has for Nodejs is ZERO and it is already up to 4, 5 and 6. So that’s pretty damn old. When I’m in the software store and the guy asks “hey, do you want version 6 of that software?”, I rarely find myself saying, “Nah, please hit me with version zero.” What software store do I speak of? Well, this one of course!

All your software needs conveniently located at the shopping mall

Anyway, here is what you do to get the version 4 for nodejs etc:

curl –silent –location | bash –

yum install -y nodejs

PHP is unable to retrieve information via $_POST on my localhost but $_GET works

Thursday, August 14th, 2014

I encountered this odd problem where FORM POSTs would not work! Other peoples comments on this were along the lines of server misconfiguration, which is sort of true — the reason for me was that I had some rewrite rules so I could leave .php extensions off the path — and I had forgotten to put ACTION in the form to leave off the extension!

Once I fixed that it all worked.

Automatically insert Current Date and Time in MySQL table

Saturday, March 16th, 2013

I was trying to recall how to create a field in a MYSQL table that will auto timestamp on inserts or updates, and surprisingly google did not give any direct and easy results! Seriously, the results were either off topic or packed with ads and off topic.

Here it is, simple and to the point:

`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP

http AJAX fails in Internet Explorer

Friday, December 3rd, 2010

I ran across an interesting bug recently where I had an AJAX routine failing when I viewed the page in IE8. When you clicked the little warning icon in the lower left, it gave a message of “Object doesn’t support this property or method”!

It was failing around code that looks like:

function parseCalcResponse() {
if (http.readyState == 4 && http.status == 200) {
results = http.responseText;
results = results.split(“|||”);
document.getElementById(‘test’).innerHTML = results;

It turns out, the fix was to declare “results” at the top of the function code with:

var results=”;

And that fixed it!

PHP not fully recognizing php.ini

Saturday, October 3rd, 2009

OK, here’s an odd one I encountered on one of my older servers running Apache2 and PHP 5.2.5

I had php scripts failing and generating “500” errors on the browser because they were running too long, or sometimes because a large file was being uploaded. I spent time playing with php.ini variables, only to find out that PHP wasn’t processing some of them!

Using phpinfo(), I noticed that the vars were not being set via php.ini, which I had set properly when it was compiled, ala:

‘./configure –with-apxs2=/opt/apache2/bin/apxs –with-mysql=/opt/mysql –with-zlib –with-config-file-path=/etc/php.ini –with-curl=/usr/lib64 –with-pear=/usr/share/pear –libdir=lib64 –with-pdo-mysql –with-gettext –enable-bcmath –with-oci8=instantclient,/home/instantclient10_1′ ‘–enable-sigchild –with-pdo-oci=instantclient,/home/instantclient10_1,′

I didn’t want to risk affecting the system by re-installing PHP, so instead I found the workaround was to create a .htaccess file that contained:

php_value upload_max_filesize 8M
php_value max_execution_time 600

and this did the trick! So hopefully that helps anyone who is running this version of php and encountered this problem.

Inline Poker Cards

Friday, July 11th, 2008

I created a WordPress plugin to display small poker cards in blog posts. Once you install the plugin you can use the nomenclature of:


to show the card of Ace of Clubs for example. You use a two-letter code that is Rank and Suit to show a card. The ranks/suits are as follows:

Ranks: 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A

Suits: c, d, h, s, x

where c=Clubs, d=Diamonds, h=Hearts, s=Spades, and x=Unknown

So go ahead and tell people how you had your cracked by a donkey with !

Download the plugin here

Tips Using Amazon EC2

Wednesday, May 21st, 2008

When I started using Amazon’s EC2 service, I found it hard to gather all the info I needed. There was no easy guide that provided all the steps in an easy format. So, here are some tips I hope some might find helpful. I am interacting with EC2 from a Linux system, so my tips are from that viewpoint.

I assume you have already done the basics, like created your developer account (and know your secret key), and installed the command line tools.

Note that you will need Java installed on your system for the tools to function.

You can find the official EC2 docs here.

Now, on to my tips!

Find A Starter Image

You can browse the images at Amazon via the command :

% ec2-describe-images

You’ll see a bunch of images that are out there, in different UNIX flavors, and some with LAMP already installed. I found that whatever you pick, you’ll want to do your own package installs anyway, so just pick a baseline that you like, i.e. Ubuntu or Redhat or whichever you feel comfortable.

Note that you need the AMI string of your choice to continue. Not only will you see a number of Amazon created AMI’s, but other folks have created some public AMIs that you can choose from. Here are some AMIs for Ubuntu you can check out.

Choose A Server Size

Note that EC2 provides a small, large, and extra-large version your can use. I’ve found that the small instances are incompatible with the the large and XL, so be careful! You should start with the large if you plan on any expansion whatsoever.

So when you are ready to create an instance, you’ll need to specify the size (m1.large or m1.xlarge) on the command line otherwise it will default to small, i.e.:

% ec2-run-instances ami-20b65349 -k gsg-keypair -t m1.large

You’ll need to create a gsg-keypair file first of course. This is described nicely in the command line docs, you’ll use “ec2-create-keypair”.

Note that you can apply a firewall to your instance via the “-g <name>” option, where you define a group with the name of “<name>”. You can see what groups you have via:

% ec2-describe-group

You can create these groups using commands like:

% ec2-authorize mygroup -P tcp -p 22 -s

Access Your Instance

After you run an instance, you can check on the progress via:

% ec2-describe-instances

And you can provide the instance name also, e.g.

% ec2-describe-instances i-be9237aaa

Then you can SSH into it when it is ready by using the domain name it returns, e.g.

% ssh -i gsg-keypair

Customize Your Instance

You should now make sure your instance has all the packages you want, and configure them how you like. I install the latest Apache, MySQL, PHP, Perl, etc, and edit all the configuration files to my liking.fone

Make sure you stay in “/”, and do not use “/mnt” since this will go away if you reboot and won’t be saved when you save your instance.

If you need more space, you can use the extra storage service from Amazon although I have not done that at this point.

When you have everything the way you like it, you should save your instance. You will use ec2-bundle-vol to create the image, and ec2-upload-bundle to upload it to Amazon’s storage service.

You’ll need your secret key, access key, cert key, user id and a sample command set is as follows. You will run these from your Amazon instance (where real keys and numbers are replaced by X’s and fake numbers):

amazon% ec2-bundle-vol -d /mnt -k pk-XXXXXXX.pem -c cert-XXXXXXX.pem -u 432132132132 -s 1536
amazon% ec2-upload-bundle -b my_image_name -m /mnt/image.manifest.xml -a XXXXXXX -s XXXXXX

Once it is uploaded, you will need to now register it as an AMI image you can access later. You need to do this command from your local host:

% ec2-register my_image_name/image.manifest.xml

This will output your AMI string that you need to note so you can use it later to use your new instance on new Amazon servers.

Cleanup When Done

Don’t forget to make sure you terminate instances you don’t need to use anymore, or you will continue to be charged for them! Run “ec2-describe-instances” to see what you are running, and then you can use “ec2-terminate-instances” with the instance string as an argument to remove them.