Posted on

Unofficial Metacritic API released as a package

For everyone googling for what happened to the Metacritic API that was published on Mashape.com: it was taken down by Mashape because they received a complaint from CBS Interactive, which owns metacritic.com. Scraping web pages (even though my API is not an automated crawler) is a legally grey area and any centralization is a weakness – it’s pretty easy to either block or attack the origin with legal threats.

Therefore I released the API script as a distributable package that you can host on your server and it’s up to you to get the authorization from them that it’s OK to do whatever you are doing.

Click here if you are interested in buying it. Please note, this is a package for developers. This means it should prevent you from having to implement and maintain it yourself. As such, it also means you can use it in as many of your own projects as you like.

FAQ:

Why did I not release the source as free? I want to offer it as a product with support, and not as an soon-to-be abandoned github project. Also, I have a business and lots of bills to pay.

Why PHP 5.5.9 as a requirement? The script was not meant for distribution and I like Lumen now 🙂 But it’s not out of the question that I will make a back-port. Please let me know if there’s any interest for a PHP 5.3 compatible package. However, as a developer I am sure you have a web server for development purposes. After all, you can get one for as low as 5 EUR / month. I have one at waveride.at and I am happy with it.

What does it mean “support and upgrades”? It means I will fix any bugs, add new functions and regularly release new versions. After your purchase, you will be able to download the newest version of the script from this website.

Posted on

CKEditor save button callback

I am sharing this since it was impossible to find with Google.

Before CKEditor 4.2 if you wanted to handle the save event with a custom function, you had to write your own plugin.

Now all you need to do is to specify the callback upon initialization:

CKEDITOR.replace('ckeditor', {
	on: {
		save: function(evt)
		{
			// Do something here, for example:
			console.log(evt.editor.getData());

			// If you want to prevent the form submit (if your editor is in a <form> element), return false here
			return false;
		}
	}
});
Posted on

Set up the mssql extension on LAMP

Do you need to connect to a MSSQL database from a Linux, Apache, PHP enviroment? Are you tired of going through endless documentation? Could the production of goat cheese be more profitable than being a freelance web developer?

While I still have no idea about the third, there’s an easy solution for the first two problems!

Before you continue, please be warned I am sharing because it worked for me and I think it’s useful, not because I know everything about it. This article is an expansion to Daniel Lang’s PHP 5.3.6 + MSSQL + FreeTDS article.

Basically, all you need to do is to compile FreeTDS and the MSSQL PHP extension. On a debian-flavoured system (Linux Mint 13 here), this is how you do it.

Fetch the FreeTDS package and compile the library.

sudo su
cd ~
mkdir sources
wget ftp://ftp.astron.com/pub/freetds/stable/freetds-stable.tgz
tar -x freetds-stable.tgz
cd freetds-0.91
./configure --enable-msdblib --prefix=/usr/local/freetds
make && make install
cp include/tds.h /usr/local/freetds/include
cp src/tds/.libs/libtds.a /usr/local/freetds/lib

Now we need to compile the MSSQL PHP extension. For that you need to fetch the source of your PHP version. You can get it with:

php -v

My version is 5.3.10 so let’s use that for the example.

cd .. # go back to "sources"
wget https://github.com/php/php-src/archive/php-5.3.10.zip # note the version
unzip php-5.3.10.zip
cd php-src-php-5.3.10/ext/mssql
phpize
./configure -–with-mssql=/usr/local/freetds
make

Let’s copy the extension to the PHP extensions dir. To check where on your system that is:

php -i | grep extension_dir

Mine is at /usr/lib/php5/20090626/, so…

cp modules/mssql.so /usr/lib/php5/20090626/

Proceed to edit your php.ini file (mine is at /etc/php5/apache/php.ini) and add this directive

extension=mssql.so

Please note that if you are running your PHP scripts (with MSSQL code) through the CLI (like usually with cron jobs), you will also need to edit /etc/php5/cli/php.ini in the same fashion.

Now, for each server you need access to, you will need to add a corresponding entry into the freetds.conf config file. This is located in /usr/local/freetds/. Refer to this FreeTDS page for all available options.
Considering this, I added the following:

[testserver]
        host = 123.123.123.123
        port = 1433
        tds version = 7.0
        instance = Instance_name

You can check if you configured your server correctly with the troubleshooting/query tool that comes with FreeTDS:

ln /usr/local/freetds/bin/tsql /usr/bin # make the tsql tool available anywhere
tsql -S testserver -U some_user

If all is well, the server will ask you for your password. You can then type any query and try it out. Note that the query is executed by the word GO (must be in it’s own line).

1> SELECT * FROM INFORMATION_SCHEMA.TABLES
2> GO

At this point there’s nothing more than to restart your apache server (service apache2 restart) and you are good to go!

mssql_connect('testserver', 'some_user', 'some_pass');

Refer to the PHP manual on MSSQL and the FreeTDS User Guide if you are having trouble configuring/accessing your server.

If you have a better solution please let me know.

Posted on

jQuery YoxView “Error loading language file”

A quick note for all googlers: If you happen to stumble upon this error when using the great YoxView plugin for jQuery, make sure you don’t put the script in a folder that has “jquery.yoxview” in it’s name. There’s a bug in the script which uses a loose regular expression, which, when provided the following URL
http://example.com/js/jquery.yoxview/jquery.yoxview.2.21.min.js
will return
http://example.com/js/
and thus will try to request the language files from e.g. http://example.com/js/lang/en.js

I have the habit of unzipping the archive and using a full script name + version for the folder name, which has the benefit, that when you change the script version, all your returning visitors will definitely get the latest script since the cache for it will not exist.