Archive for the 'Tech Stuff' Category

 

A setup project I was working on in Microsoft Visual Studio suddenly stopped building with the following error;

An error occurred while validating. HRESULT = '8001010E'

When I tried to refresh the dependencies I got a nasty error message. If found this post and played with the suggested settings a bit without any joy. Then I shut-down visual studio and restarted and the build error went away! So if this happens to you all I can suggest is to take a look at this post or restart Visual Studio, or both!

 

Q: How can use cURL to emulate a form post with a file upload?
A: It took me a bit of time to figure this out but it is quite straight forward really, you just need to use (possibly multiple) --form (or -F) arguments like this:

 
curl -F appID=1234 -F name=Emulate -F appFile@em.zip http://www.abc.com/na
 

This will emulate a form post to

http://www.abc.com/na

with two named data items (appID and name) and one file upload, the file upload will be named ‘appFile’, the local file em.zip will be uploaded with the post, and that should do it!

If you’re using wordpress and all of a sudden you can’t approve comments, then try deactivating the ‘Cimy Swift SMTP’ module – It worked for us!

 

Q: How do I get the name of the current python function, I want to output its name as part of some logging information.

 

A: Just import the ‘inspect’ module and call its stack() method to get access to the call stack, for example, to get the name of the current function:

 
import inspect

 

fn_name = inspect.stack()[1][3]

 

The first index indicates the stack position, so to get the name of the parent calling function use:

 
import inspect

 

fn_name = inspect.stack()[2][3]

 

or to define a function that returns the name of the function from which it was called:

import inspect

 

def get_current_function():
  return inspect.stack()[2][3]

 

Introspection is one of the really cool features of modern software programming languages!

These days most software developers need deal with more than one software development technology and programming language on a day to day basis. This often means that they have to switch back and forth between coding styles, with this in mind I noticed that although the MS coding guidelines for C# in .NET recommend K&R style braces for code blocks, e.g:

 
if (sneeze) {
  nose.Blow();
}
 

By default Visual Studio’s auto code formatting stuff will format your code with braces on newlines, e.g.:

 
if (sneeze)
{
  nose.Blow();
}
 

Very interesting indeed, I wonder are there internal coding style conflicts within Microsoft…

If you use testimonials on magento and then place them onto a page that contains the prototype extension showcase, you may notice that both the testimonial and showcase animation stops working, and that an absolute snow of javascript errors are generated.

 

If this is happens to you, it may be caused by a jQuery library conflict. The testimonials PHP template directly includes jQuery and this may clash with the prototype library, we found that we could resolve the library conflict by placing good old:

 
jQuery.noConflict();
 

In the file testimonial_advance.phtml just before document/ready, like this…

 
jQuery.noConflict();

 

jQuery(document).ready(function() {
….
}

 

Adding this solved the problem for us.

 

testimonial_advance.phtml should be found in this folder:

 

app/design/frontend/default/default/template/testimonial

 

However, it is not good magento practice to alter this version of the file, instead you should create a testimonials folder under:

 

app/design/frontend/default/[your folder]/template/

 

Then copy testimonial_advance.phtml to this folder and edit it there. Remember to clear the magento cache when testing changes!

In the Software Development game there are always plenty of annoying problems that will just eat up your time, what I really hate is being caught out by the same annoying problem more than once… I have been caught out by this one before so this time I am going to write it down!

 

So the situation is that you just can’t login to Microsoft SQL Express 2008 via the Management Studio or by any other means using the ‘SQL Authentication’ method. You can login using ‘Windows Authentication’ fine, and can then add SQL users and change their passwords and configure their permissions etc. etc. but you can never login with these users…

 

If you are experiencing the above the most likely cause that ‘SQL Authentication’ isn’t enabled at all! And Management Studio doesn’t bother to remind you of this when it lets you add, configure and enable such logins.

 

Well, to check if ‘SQL Authentication’ is enabled, and to enable it if it’s not try the following:

 

Login into Management Studio, right click on your server and choose ‘properties’. Click on the ‘Security’ tab, make sure that the ‘SQL Server and Windows Authentication Mode’ radio button is checked and hit OK.

 

Hopefully all of your SQL logins will work now, ours did!

 

If after you have done this, you still can’t login as ‘sa’, edit the users’s properties and under ‘Status’ tab, make sure that the ‘Login:’ radio button is set to ‘Enabled’ – It may have been disable during installation.

It is a very lucky software developer that doesn’t have to interact with a microsoft windows batch file (.bat) ever now and again, recently my luck ran out and I came across a funny problem:

 

In windows 7, if your batch file does anything interesting (such a registering a COM dll) you may have to run it ‘As Administrator’. When you run it as administrator you may notice that a strange thing happens, it may be run with a different current/working folder to the folder in which it resides – whereas when run normally its current folder is its local folder.

 

This can be a real problem if the batch file needs to reference other files in its folder (such as the COM dll to be registered in my example above…)

 

Well not to worry, it turns out that to change batch file’s current directory to its local directory we just issue this rather esoteric command at the top of the file:

 

pushd %~dp0

 

The pushd bit I get, as for the rest….. well I am just glad it works!

This one catches me out time after time and I always forget how to get around it – so I am writing it down this time. Developing software to run well on multiple browsers is actually not that difficult until, that is, good old IE is thrown into the mix! ;-)

 

The problem is that in Internet Explorer, the .change() event on radio buttons doesn’t get fired properly, or at least it doesn’t behave the same was as it does in the other browsers – it’s a real pain!

 

There is however a relatively easy way to get around the problem, that is to handle the radio’s .click() event, and then, just .blur() and .focus() the radio control – this will cause the change() event to be fired:

 
$(document).ready(function() {
  $('#my-radio-container input:radio').click(function () {
        // Cause the change() event
        // to be fired in IE8 et. al.

        this.blur();

        this.focus();
   });
  $('#my-radio-container input:radio').change(function() {

    // Handle .change() event as normal....

  });

});
 

Remember to replace #my-radio-container with an appropriate selector for your HTML.

 

I am not sure why it works exactly….. but it works well for me!

GPG is great software for manually encrypting data using the OpenPGP standard – good encryption tools are more and more becoming essential to software development.

 

However using GPG from a script sometimes presents problems. Why would you want to GPG from a script? Well you might want to encrypt a backup from within your backup script to allow you to safely FTP the backup file to remote storage, for example.

 

Anyway, one such problem results in the following error message appearing, when you try to encrypt using an imported, but unsigned public key:

 

“It is NOT certain that the key belongs to the person named…”

 

GPG then says something along the lines of ‘do you want to continue anyway?’ and tries to read your response from the terminal – the script is unable to answer the question and so the whole process stalls…

 

One way to get around this problem is to manually set the trust level of the imported public key to ‘ultimate’ so that the situation no longer arises, instructions for how to do this can be found here:

 

http://www.somacon.com/p107.php

 

However in some cases this may not be easy or desirable, especially if you don’t have access to the command line – for example, you may be working with shared hosting. You may also want to ensure that the _whole_ process is automatic with no manual steps required.

 

So, another option is to pass the ‘–trust-model always’ argument to gpg, this will force GPG not to issue the warning and not ask for confirmation – so your script should proceed OK. For example:

 
gpg –encrypt –yes –no-tty –trust-model always –output backup.gpg –recipient backup@software-ireland.ie backup
 

Older versions of GPG may not have this parameter, and will report an error when you pass it, in this case the depreciated ‘–always-trust’ argument can be used instead.

 

Be warned that this does reduce security slightly. If somebody somehow maliciously managed to substitute your public key for theirs and then managed to intercept the encrypted data, then they could decrypt it with their private key. However in most cases this is of small concern – but do be aware of the possible dangers of blindly encrypting without requiring signed public keys.

 

Script & Encrypt!