PHP 6 features

What will PHP6 bring? This article has a little summary of what the future of PHP holds.

No Comments

Custom sql queries in Views

I came across this when i was looking for a way to use my own sqly queries in combination with views.
Sometimes you can’t always get the things you want by using views (or you’re too lazy to fiddle around with arguments, relationships, etc.)

The idea is simple :

1) test your own custom query in phpmyadmin for example.

2) create a view and save it. You don’t have to set any filters since the SQL will be overwritten.

2) if you haven’t created your own module yet, create one now and place the following code in it.  replace MYMODULE by the name of your own module and VIEW_NAME by the name of the view you’ve just created. Then, change the sql query you see here by your own.

function MYMODULE _views_pre_execute(&$view) {

//drupal_set_message(’—->>>’.$view->name);
if($view->name==”VIEW_NAME”) {

$view->build_info['query']=”SELECT vidnode.nid as nid, vidnode.title as title
FROM node vidnode WHERE vidnode.type=’ptl_remotevideo’
AND vidnode.status <> 0
AND vidnode.nid NOT IN (
SELECT DISTINCT media.field_media_video_ref_nid as video_nid
FROM content_field_media_video_ref media
)”;

}

}

That’s it. I used a node view and it gave me what i wanted. I didn’t have time to check out other settings but i guess it shouldn’t be too hard.

, ,

1 Comment

Upgrade ImageMagick to the latest version

A lot of people are looking for an updated installation of ImageMagick instead of those pesky yum packages on Redhat or CentOS. To upgrade to the last version, use these commands :

# uninstall old ImageMagick
yum remove ImageMagick

# get new ImageMagick sources
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz

# untar
tar -zxvf ImageMagick*.tar.gz
cd ImageMagick*

# configure and make
./configure
make

# install
make install

# test ImageMagick (shouldn’t report an error)
convert logo: logo.gif

# fix problem with rmagick not finding ImageMagick libraries
echo /usr/local/lib >> /etc/ld.so.conf.d/ImageMagick.conf
ldconfig

# update rmagick
gem install rmagick

I found this at https://support.railsmachine.com/index.php?pg=kb.page&id=133

No Comments

How to put a hyperlink on your building

Have you ever wondered how to link your building to a webpage?

article_hyperlink

With 2D barcodes you can.

A 2D barcode or Matrix code is a two-dimensional way of representing information.
It has more data representation capability then a (1-dimensional) barcode.

What is cool about a 2D barcode is that it can be read by every mobile device that has a camera and the reader software. So no special hardware required to scan a 2D barcode

You can store some formatted information on a 2D barcode. This information is in the form of an URI.

Most 2D barcode readers will send the URI encoded in the 2D barcode to the platform specific implementation.
That is why some URI’s will not been interpreted by one phone but will be by another phone.

These are some informartion you can encode in a 2D barcode:

  • Link to a website.
    http:// is required, otherwise it will not know it is a website
    example : http://www.calibrate.be
  • Email address
    example : mailto:newmedia@calibrate.be
  • Telephone numbers
    example :  tel:+3238719962
  • Contact Information based on the “MECARDâ€�
    MECARD:N:Hermans,Joris;ADR: Veldkant 31, 2550 Kontich, Belgium;TEL: +32 3 871 99 62;EMAIL:joris@calibrate.be;;
  • SMS hava some few possibilities : sms or smsto
    sms:number:subject or smsto:number:subject
  • Geographic information
    example : geo:40.71872,-73.98905,100

The QR Code is a type of 2D barcode that you can use for free. You will find also a lot of mobile reader software for this type of 2D barcode (for example zxing).
So putting a hyperlink to the digital world on your building is easy.

qrcode

building with a qrcode

If you want to play with it already you can always use a QR-Code generator like this.
And if you want to add dynamic behavior easily to it, you can always take a look at touchatag.

, , ,

No Comments

Tracing output with line numbers

Problem:

When coding AS3, the trace() function comes in very handy for debugging.
In some cases however, it can be quite annoying as well. Sometimes you don’t remember where you put the trace() action,
or you get an output, from which you don’t know exactly where it comes from. Also, when adding trace() actions,
it can take you some seconds to find where this trace() -code is written, especially in bigger classes or functions.
A few seconds might not seem much, but at the end of the project, it’ll be a lot of seconds lost, and a lot of frustration comes along with it.

Solution:

I’ve written a class called DebugTracer, which will output your message, and add a prefix to it, which indicates the ClassName and line number of the trace action.

How it works:

It’s a bit of a trick. Line numbers are not directly accessible in AS3.
However, when an error occurs, the error information output contains the ClassName and line number of the code that generates the error.
In AS3, we refer to this info as the stackTrace. So the trick is to create an error object, and get this information out of the errors stackTrace.

Example:

Let’s output a classic “Hello world”.
Using the basic built-in trace() action:

trace ("Hello world");
       // output: Hello world

And now the same thing with the DebugTracer class:

DebugTracer.getInstance().report ("Hello world");
       // output: DebugExample (Line 21): Hello world

Additional Info:

Because the DebugTracer class works with errors, it needs a debugger version of flash player to make this work.
Also, in order to get the line number, you need to check “Permit debugging” option in the Publish Settings>Flash.
If not, only the ClassName will be added to the prefix.

Files:

You can download the DebugTracer Class here:
DebugTracer.zip

No Comments

Admin section won’t load properly

Problem

A problem that a lot of people seem to encounter when working with Drupal and especially after a new installation,  is the fact that the admin section loads very slow or sometimes not at all. This is due to the fact that Drupal by default is configured to automatically check for updates. Often this is blocked however causing Drupal to keep trying.

Solution

You could solve this by disabling the Update module in the Modules section but sometimes it’s impossible to get to that page due to the problem.
A second option is to disable it manually by going to the ’system’ table in your Drupal MySQL database, explore the table and look for the ”modules/update/update.module’ entry.
Once you have found it, edit the status field of the module to 0 (should have been 1).  Your problem is most likely fixed now.

Some pointers:

  • Drupal needs at least 16MB to run properly - if you feel your local configuration is running very slow, verify your apache settings and change the memory limit to a higher number (like 64M)
  • Importing sql.zips can sometimes fail, in this case you could try adjusting the maximum allowed packet size in your mysql settings.
    ==> the best solution however is to export all your tables except the ‘watchdog’ table and every table with ‘cache’ in it’s tablename as these are the ones to take up most of the volume.

No Comments

PHP closing tags

A little something I found out recently :

when you’re writing a PHP script, you don’t need to end your file with closing tags. In fact, this is better because it removes the chances of having troubles with invisible spaces or line endings.

so, not this:

<?php

echo “Very nice!”;

//closing tag

?>

But rather just this

<?php

echo “this is even better!”;

//no closing tag

2 Comments

AnalyticsManager with multi-tracker support

Problem:

I was working on an international website for Le Pain Quotidien.
Depending on which country is chosen on the homepage, an other Google Analytics Tracker had to be used.

Solution:

I wrote a class which allows to create trackers at Runtime, and send tracking information to a specific tracker.

How it works:

The system consists of 2 classes:
- An AnalyticsManager class, which allows to add or remove trackers at runtime.
- An AnalyticsTracker class, which uses ExternalInterface to send the tracking-information to it’s associated tracker.

Code in AS3:

var analytics:AnalyticsManager = new AnalyticsManager ();
analytics.addTracker ("pageTracker1");
analytics.addTracker ("pageTracker2");

analytics.getTracker ("pageTracker1").track ( "tag_for_tracker_1" );
analytics.getTracker ("pageTracker2").track ( "tag_for_tracker_2" );

Code in HTML:

<script type="text/javascript">
   var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
   document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
   var pageTracker1 = _gat._getTracker("UA-xxxxxxx-1");
   var pageTracker2 = _gat._getTracker("UA-xxxxxxx-2");

   pageTracker1 ._trackPageview("/home");
</script>

Files:

You can download the files here:
AnalyticsManager.zip

The class uses a HashMap to save the trackers.
The HashMap classes are included in the zip-file.

1 Comment

AIR Updater

I’ve written a class to make the updating process of AIR-projectors easier.
The class uses the great AIRRemoteUpdater classes, written by Claus Wahlers (http://codeazur.com.br/lab/airremoteupdater/).

How it works:

You create an AIRUpdater object, configure the wanted listeners, and ask it to check for an update.

Code in AS3:

var updater:AIRUpdater = new AIRUpdater ("path_to_air_file", true, true);
updater.addEventListener(AIRUpdaterEvent.COMPLETE, updateCompleteHandler);
updater.addEventListener(AIRUpdaterEvent.CONFIRM, updateConfirmHandler);
updater.addEventListener(AIRUpdaterEvent.WARNING, updateWarningHandler);
updater.addEventListener(AIRUpdaterEvent.CONNECTION_ERROR, updateErrorHandler);
updater.update();

function updateCompleteHandler(event:AIRUpdaterEvent):void
{
   // Starting application.
}

function updateConfirmHandler(event:AIRUpdaterEvent):void
{
   // Update confirmation requested.
   // Current version: updater.localVersion
   // Remote version: updater.remoteVersion

   // on confirm: updater.update (false);
}

function updateWarningHandler(event:AIRUpdaterEvent):void
{
   // Update warning message.
   updater.install ();
}

function updateErrorHandler(event:AIRUpdaterEvent):void
{
   // Update file not found.
}

The constructor of the class requires the path to the air file, and gives you the choice to stop the updating process for a confirmation and/or a warning.

Files:

You can download the zip-file here:
AIRUpdater.zip

I’ve included the original AIRRemoteUpdater classes in the zip file.
Note that these classes are not written by me, so more recent versions might be available.

,

No Comments