Below you will find pages that utilize the taxonomy term “Programming”
July 12, 2022
SQLSTATE[HY000]: General error: 1366 Incorrect string value: ‘\xE2\x80\x8B\xE2\x80\x8B…’ for column
If you get this (or similar) when trying to insert/update in a MySQL database, you table is not able to cope with the extended version of the UTF8 character set.
You will need to convert your table to use the utf8mb4 character set, and utf8mb4_unicode_ci collation.
An example to do so:
ALTER TABLE `your_table_here` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
read more
February 23, 2018
Unable to install sass gem on CentOS 6.9 with Ruby 2.4
Something changed recently, preventing a VM from fully provisioning. Tracking it down was a bit of a PiTA.
OS: CentOS 6.9
Ruby: 2.4 - installed from source with the gearlingguy.ruby ansible role
Gems to be installed: sass
Output of attempting to install the sass ruby gem:
$ sudo gem install sass
Fetching: rb-fsevent-0.10.2.gem (100%)
Successfully installed rb-fsevent-0.10.2
Fetching: ffi-1.9.21.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing sass:
ERROR: Failed to build gem native extension.
read more
February 6, 2013
Symfony2 pagination
Using Symfony2, DQL and knplabs/knp-paginator-bundle - how to get around “Cannot count query which selects two FROM components, cannot make distinction”
Fails:
Works:
read more
February 4, 2013
Making an entity repository container aware in Symfony2.1
I had a need to add ACL rules to entities at the repository level.
My biggest struggle was getting dependancy injection working.
This is what I finally came up with after a fresh mind and an instant coffee:
Comments KingCrunch says: 16th February 2013 at 11:30 am
If your EntityRepository needs to know about the DIC, you made it wrong…
Wessel says: 13th June 2013 at 12:03 pm
Mmm nice trick.
read more
June 24, 2012
Updating a WordPress database with new domain details
Further to my original quick db update queries, I found the need for a more in-depth approach.
A WordPress site my father works on has weekly backups, but he wanted to see that they actually worked.
To do so, I set up a subdomain vhost on my bytemark server and set about getting the back to work with it.
One of the most annoying/lazy/strange things about WordPress is that it uses serialised arrays within database fields.
read more
February 2, 2012
Symfony 1.4 Doctrine 1.2 MS SQL Server
Web server: Linux (Ubuntu on my dev setup), Apache, PHP 5.3, Symfony 1.4, Doctrine 1.2.
Database server: Microsoft Windows 2008 Server, MS SQL Server
Trying to get Symfony to talk to the database server has been a painful experience for the last few days. But perseverance has paid off.
Lots of Googling with trial & error has resulted in actually achieving a development setup that will mirror the eventual production setup.
read more
August 4, 2011
Fixing odd characters
One of the biggest complaints that web developers have is their lack of control over end users.
When will we be able to tell them a) not to paste Micosoft Word or b) if you must, paste it into something that doesn’t do formatting 1st.
It has a nasty habit of converting quotes into “smart” quotes as well as messing up characters such as the euro symbol €.
This is the fix I came up with that allows end users to continue to paste from such programs and bring their weird charset issues with them:
read more
July 19, 2011
Downloading SoundCloud Playlists
[Update 21st Aug 2013
Post code replaced with a Github GIST.
Please fork and help improve this script 🙂
[Updated 7th Feb 2012
Changes:
file names are now as they would be if you downloaded via web browser Playlist is now in reverse date uploaded order] I like to have music while I’m coding. It breaks the silence while working alone at home.
When I have music playing, it’s best if I don’t have to think about setting up playlists, which is why I used to listen to the radio.
read more
March 21, 2011
wp-block as a shortcode
In my last post I raved about the excellent plugin wp-blocks by Keir Whitaker and then went on to extend it a little.
Time to extend it a little further, this time by adding a shortcode.
Shortcodes are the handy square bracketed code snippets which conjure up more content and functionality direct from a page or post content.
The wp-blocks plugin is currently intended to work with the theme template files in PHP.
read more
March 18, 2011
Getting a random wp-block by regex
If you’re used to developing with a CMS such as CMS Made Simple, you would be quite used to having blocks of content separate from the main content system. These blocks can be re-used through-out existing content and within the theme templates.
One might even consider this a core function for a CMS. Sadly it’s missing from WordPress. Keir Whitaker has been working on this missing option and gives us wp-blocks.
read more
March 7, 2011
Mimicking wordpress.com’s image resize URIs
To follow up from last night’s entry [Resize images on the fly without messing with image URLs]](/2011/03/07/resize-images-on-the-fly-without-messing-with-image-urls/), I was determined to remove the intermediary step of my_resize_script.php.
I’ve acheived this goal in the mod_rewrite rule, file name and query string now get passed on to timthumb.php.
Updated rules:
RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{REQUEST_URI} .(gif|png|jpg|jpeg) RewriteCond %{QUERY_STRING} (w|h)=(.*)$ RewriteRule (.*) /full/path/to/timthumb.php?src=$1&%1=%2&%3=%4 [L] This will pass both width and height variables into timthumb if they are declared.
read more
March 7, 2011
Resize images on the fly without messing with image URLs
[EDIT: I’ve made this simpler with a follow up post: Mimicking wordpress.com’s image resize URIs]
Exporting a wordpress.com site for use on a standalone wordpress.org install is a joy to set up. The export and import system are simple to use and give little or no issues.
What is a problem is the automatic resizing of images that wordpress.com offers.
One can insert an image in the normal way and then append the image URI with some variables such as width (w) and height (h).
read more
March 3, 2011
Updating WordPress site URLs for different hosts
Why oh why does WordPress insist on storing the site URLs within the database?
Every other project I can think of either keeps it in a config file or doesn’t bother with one and just works with whatever URL it finds itself on.
This is most irritating when you have:
more than one developer working on the same project more than one system for hosting the project (dev, test, live, etc) One way to cope with this irritation is to have a collection of .
read more
October 17, 2010
How to get sfFormExtraPlugin working in Symfony 1.4 using Doctrine
I’m talking about this plugin: http://www.symfony-project.org/plugins/sfFormExtraPlugin
For some reason, getting the plugin to work took a lot of Googling and some trial and error.
So here is how I got it working. Hopefully I did this in the ‘correct’ way…
cd plugins wget "http://plugins.symfony-project.org/get/sfFormExtraPlugin/sfFormExtraPlugin-1.1.3.tgz" tar zxvf sfFormExtraPlugin-1.1.3.tgz mv sfFormExtraPlugin-1.1.3 sfFormExtraPlugin cd .. ./symfony plugin:publish-assets cd web/js wget "http://code.jquery.com/jquery-1.4.3.min.js" wget "http://jqueryui.com/download/jquery-ui-1.8.5.custom.zip" mkdir jquery-ui cd jquery-ui unzip ../jquery-ui-1.8.5.custom.zip mv jquery-ui/css/smoothness ../css</pre> Edit config/ProjectConfiguration.
read more
July 15, 2010
Which Windows applications are used by this web developer?
This list is partly to remind myself what essential apps need to be reinstalled after a system wipe.
But it does have me thinking, what do other web developers use on a daily basis?
Web browsers:
Google Chrome FireFox IE Opera Safari FireFox addons:
Adblock Plus British English Dictionary ColorZilla Dummy Lipsum Firebug Html Validator Web Developer Xmarks Code editing:
PhpEd Eclipse PDT TextPad vim Code tools:
SQLyog WinMerge System tools:
read more
July 4, 2010
Magento: pre filter by multiple option custom attributes
Requirement: pre-filter products by customer group name to product attribute.
I was looking for the “proper” way of filtering items by multiple custom attribute settings, but couldn’t find out how.
So, the following is a brief explanation of how I’ve got this running in Magento 1.4.1.
There are two ways of editing core code in Magento.
Wrong: edit files directly in app/code/core/Mage Right: extend modules and keep them in app/code/local/MyDevCompany If you’re in a hurry, you might edit core files directly and then later copy the altered code out into correctly extended module files.
read more
June 24, 2010
White space trim for JavaScript
I originally blogged about this on my other site lazygnome.net but that was simply a quick place to record it.
I present to you a very quick and handy way of replicating PHP’s trim() function in JS:
function ws_trim(value) { return value.replace(/(^s+|s+$)/g, ''); } There it is, simple and usable.
I don’t claim to be original with this code. I’m sure that others have done exactly the same themselves. But it surprises me that JS doesn’t come with such a text manipulation method by default.
read more
March 17, 2010
writeAttribute() example
The documentation on http://prototypejs.org/api/element/writeAttribute is a wee bit scarce. So here’s a quick one on usage.
To add an attribute:
$('foo').writeAttribute('title', 'bar'); To remove an attribute:
$('foo').writeAttribute('title', null); To enable all disabled form elements (in a form with the id ‘container’):
$('container').select('[disabled="disabled"]').each(function(e) { $(e).writeAttribute('disabled', null); });
read more
October 23, 2009
Please, somebody standadise the order of function variables
Finding a needle in a haystack is a wonderful bit of symbolism and I welcome its use in many situations.
It’s just the implementation of that symbolism that needs to be standardised. For forgetting the order in which a function expects variables to be passed in is tedious.
In PHP, for example, there are some very useful functions: in_array() and str_pos() to name but two.
Usage is in_array($needle, $haystack) and makes sense as you want to check that the needle is in the haystack.
read more