Programming

Disable Apache 404 ErrorDocument HTML

0

While implementing a REST service, Apache started to append HTML 404 error HTML to my custom 404 application/json response.
It seems the Windows Apache version which comes with Zend Server requires a httpd.conf entry to disable the HTML to be appended to the response:

To disable it for a 404 error:
ErrorDocument 404 ” ”

So in general:
ErrorDocument ” ”

It’s weird though that the Linux version does not append this HTML error code by default.

ZF ReCaptcha Inline Configuration Code Snippet

0

Somehow it’s always a pain to find the right configuration parameters and proper format in ZF which makes me reverse engineer them.

$this->captcha = new Zend_Form_Element_Captcha('captcha',
	array(
		'captcha'=>array ('ReCaptcha'),
		'captchaOptions'=>array (
			'pubkey'=>'...',
			'privkey'=>'...'
		)
	)
);

Show the LIVE Status from an OWN3D.TV Livestream with a jQuery Plugin

4

Demo
jQuery plug-in source at BitBucket

Examples of how to use the plug-in.

// global configuration options
$.own3d.liveurl = 'http://ingol.nl/own3d/live.php';
$.own3d.channelurl = 'http://ingol.nl/own3d/channel.php';

// A single stream
$('#own3d-cowclan').own3d({liveid:'1213', title:'COWCLAN'});
// A single stream with HD
$('#own3d-rebootgpf').own3d({liveid:'1208', title:'REBOOTGPF', hd:true});
// A single stream without title
$('#own3d-1208').own3d({liveid:'1208', hd:true, embed:true, channelid: 'orlissenberg'});
// A single channel, live streams only
$('#channel').own3d({channelid:'clgame', hd:true, embed:true});
// A single channel, live and offline streams
$('#channel-all').own3d({channelid:'clgame', hd:true, showall:true});

The jQuery OWN3D Plug-in Code.

(function($){
  $.own3d = {
    liveurl : 'live.php',
    channelurl : 'channel.php'
  };

  $.fn.own3d = function(options) {
    return this.each(function(){
      var self = $(this);
      self.data('liveid', options.liveid);

      if (options && options.liveid) {
        $.ajax({
            type: "GET",
            async: true,
            data: {live_id:options.liveid},
            url: $.own3d.liveurl,
            dataType: "jsonp",
            success: function(data){
              var title = (options.title) ? options.title : 'OWN3D CHANNEL ['+options.liveid+']';
              var liveclass = (options.hd) ? 'own3d-live-hd' : 'own3d-live';

              self.empty();
              self.addClass('own3d');

              var link = $('<a/>')
                  .attr('href','http://www.own3d.tv/live/'+options.liveid)
                  .attr('target','_blank');

              if (data.isLive && data.isLive == 'true') {
                link.html(title+' - LIVE (viewers: '+data.liveViewers+' - duration: '+Math.round(parseInt(data.liveDuration) / 60)+' minutes)');

                if ((options.showthumbnail || options.embed) && options.channelid) {
                  $.ajax({
                      type: "GET",
                      async: true,
                      data: {channel_id : options.channelid, stream_guid : 'http://www.own3d.tv/live/'+options.liveid},
                      url: $.own3d.channelurl,
                      dataType: "jsonp",
                      success: function(data){
                        if (options.showthumbnail && data.thumbnail) {
                          var table = $('<table/>');

                          var status = $('<td/>').append($('<div/>').addClass(liveclass).append(link));
                          table.append($('<tr/>').append(status));

                          var thumbnail = $('<td/>').append($('<img/>').attr('src',data.thumbnail));
                          table.append($('<tr/>').append(thumbnail));

                          self.append(table);
                        } else if (options.embed && data.title) {

                            var e = '<iframe height="360" width="640" frameborder="0" src="http://www.own3d.tv/liveembed/'+self.data('liveid')+'"></iframe>';
                            var table = $('<table/>');

                            var status = $('<td/>').append($('<div/>').addClass(liveclass).append(link));
                            table.append($('<tr/>').append(status));

                            var embeddedplayer = $('<td/>').html(e);
                            table.append($('<tr/>').append(embeddedplayer));

                            self.append(table);
                        };
                      },
                      error: function(XMLHttpRequest, textStatus, errorThrown){
                        // console.debug(errorThrown);
                      }
                  });
                } else {
                  self.append(link);
                  self.addClass(liveclass);
                }
              } else {
                link.html(title+' - OFFLINE');
                self.removeClass(liveclass);
                self.append(link);
              }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                // console.debug(errorThrown);
            }
        });
      } else if (options && options.channelid) {
        var ajaxdata = {
          channel_id : options.channelid
        };
        if (options.showall) { ajaxdata.showall = 1; };

        $.ajax({
            type: "GET",
            async: true,
            data: ajaxdata,
            url: $.own3d.channelurl,
            dataType: "jsonp",
            success: function(data){
              self.empty();

              var embedded = true;
              for(var i=0;i<data.streams.length;i++) {
                var stream = data.streams[i];

                var plugindata = {
                  liveid : stream.liveid,
                  title : stream.title,
                  channelid : options.channelid,
                  // embed the first, thumbnail the rest
                  showthumbnail : (options.showthumbnail) || (!(options.showthumbnail) && options.embed && !embedded) ? true : false,
                  embed : (options.embed) ? true && embedded : false
                };

                // prevent opening multiple embedded players
                embedded = false;                

                self.append($('<div/>').own3d(plugindata));
              }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
              // console.debug(errorThrown);
            }
        });
      }
    });
  }
})(jQuery)

A simple PHP – Zend Framework script to enable a cross domain request to the OWN3D API (the full project contains two, one for the live status and one for the channel information).

<?php

// Define path to application directory
define('APPLICATION_PATH', realpath(dirname(__FILE__)));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../../apps/library'),
    get_include_path(),
)));

$liveid = isset($_GET['live_id']) ? intval($_GET['live_id']) : 0;

require_once 'Zend/Http/Client.php';
$client = new Zend_Http_Client('http://api.own3d.tv/liveCheck.php?live_id='.$liveid, array('adapter' => 'Zend_Http_Client_Adapter_Socket'));

$xmlstr = $client->request()->getBody();
$xml = new SimpleXMLElement($xmlstr);

require_once 'Zend/Json/Encoder.php';
header('Content-Type: application/json');

// JSONP
if (isset($_GET['callback'])) {
        echo $_GET['callback'].'('. Zend_Json_Encoder::encode(array(
        'isLive'=>(string)$xml->liveEvent->isLive,
        'liveViewers'=>(string)$xml->liveEvent->liveViewers,
        'liveDuration'=>(string)$xml->liveEvent->liveDuration,
    )).')';
}
// JSON
else {
    echo Zend_Json_Encoder::encode(array(
        'isLive'=>(string)$xml->liveEvent->isLive,
        'liveViewers'=>(string)$xml->liveEvent->liveViewers,
        'liveDuration'=>(string)$xml->liveEvent->liveDuration,
    ));
}

jQuery UI Day-Calendar Widget

5

I’m working on a generic calendar widget for event scheduling. It’s my first jQuery UI widget experience which I really like thus far. The calendar widget itself is a sort of complete re-implementation of the jQuery-Week-Calendar made by Rob Monie. However the week-calendar widget was end-of-life and no longer maintained.

A repository has been setup at Bitbucket: jQuery Day Calendar

Specs:
- Drag and drop events (which contains various resources).
- Slot-based event containers of variable length (variable event length).
- Both calendar and event components are jQuery UI Widget based.
- Supports the jQuery Theme Roller.
- Support all major browsers.
- Very reusable, should not be a one-trick-pony.
- Using multiple day-calendars would create something similar to the jQuery-Week-Calendar (maybe make another composite UI widget for it even).

DEMO

jQuery Plugins Day Calendar

TIP: Get rid of “It is not safe to rely on the system’s timezone settings.”

0

Warning: strtotime() [function.strtotime]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.

; Copy this line into the php.ini
; http://php.net/manual/en/timezones.php
date.timezone = “Europe/Amsterdam”

Oracle Tip: Ignoring case and diacritic differences in an Oracle search.

0

http://forums.oracle.com/forums/thread.jspa?threadID=14970

Instead of using the SQL UPPER and LOWER functions to perform case-insensitive queries, an alternative approach is to utilize the linguistic sort GENERIC_BASELETTER. GENERIC_BASELETTER groups all characters together based on their base letter values, this is achieved by ignoring their case and the diacritic differences.
Here is an example of a GENERIC_BASELETTER query.

ALTER SESSION SET NLS_COMP=ANSI;
ALTER SESSION SET NLS_SORT=GENERIC_BASELETTER;

SELECT * FROM PRODUCT
WHERE PRODUCT_NAME = database;

All other operators, such as LIKE, perform comparisons in binary mode only. i.e. they do not honor the NLS_SORT value. This has now been be enhanced in 10gR2.

See also:
Diacritics in like clause, Globalization support
http://dbaforums.org/oracle/index.php?showtopic=915

Diacritics
http://en.wikipedia.org/wiki/Diacritic

Oracle® Database Globalization Support Guide
http://download.oracle.com/docs/cd/B14117_01/server.101/b10749/ch5lingsort.htm#i1006463

Oracle NLS_LOWER
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions098.htm#i78373

Oracle Replace
http://www.psoug.org/reference/translate_replace.html

SELECT translate('árvíztűrőtükörfúrógép','áéíóöőúüű','aeiooouuu') without FROM dual

To GUID or not to GUID, on Oracle …

1

I keep running into that issue when I design a database, this time around it’s an Oracle schema, thus I need fresh input on GUIDs and Oracle. It’s basically the old story, if distribution and replication is a serious feature, a GUID would be very welcome. We could also create a hybrid monster, take a numeric primary key and supplement a GUID field for distribution purposes, sure it takes up additional space …

Arguments for the use of GUIDs

- Makes distribution and replication a lot easier.
- ID’s can be created in the application, thus no ID would need to fetched from a DB insert.
- Creating ID’s on the “client” side enables working “offline”.
- Enabled (dirty?) cross-table references, e.g. a table which contains website url’s could contain a generic “ID” column which contains id’s from the “books” table or “articles” table. This also applies for class models ofcourse.
- Security (by obscurity) in urls.
- don’t have to create those (annoying) sequences with triggers in Oracle :)

Arguments against the use of GUIDs

- Performance (will depend on which database, e.g. Oracle also has sequential GUIDs and MS-Sql has a native guid type).
- Universally small chance that it’s not unique.
- Looks ugly (heard that a LOT)
- It has a Microsoft feel to it :)

Well, Google also supplies some nice information about the performance, reasons to use (or not) and options:

[1] How should I store a Guid in Oracle
[2] Unique IDs for multi-master replication – Sequence or SYS_GUID?
[3] Watch out for sequential Oracle GUIDs!
[4] UUIDs as primary keys

- Probable performance loss of 40% when using a CHAR / RAW(16) instead of an integer. [1] (Searching is faster in CHAR as all the strings are stored at a specified position from the each other, the system doesnot have to search for the end of string, thus CHAR instead of VARCHAR2, plus the length of a GUID is fixed anyway)
Whereas in VARCHAR the system has to first find the end of string and then go for searching.
- SYS_GUID is sequential because random GUIDs play hell with indexes. SQL Server has a sequential GUID generator as well for the same reason.
- On SQL Server, the base datatype of a Guid is actually a binary(16) (equivalent to Raw(16) on Oracle). But when the Guid value is marshalled into the binary, the bytes are re-ordered!
- You can uses sys_guid() as a default column so that it is automatically populated. CREATE TABLE guid_table (pky RAW(16) default sys_guid() PRIMARY KEY, NAME VARCHAR2(100));
- Using UUIDs in URLs is more secure. [4]
- A nice function to format the SYS_GUID() [3] :

CREATE OR REPLACE FUNCTION GET_FORMATTED_GUID RETURN VARCHAR2 IS guid VARCHAR2(38) ;
BEGIN
SELECT SYS_GUID() INTO guid FROM DUAL ;

guid :=
'{' || SUBSTR(guid,  1, 8) ||
'-' || SUBSTR(guid,  9, 4) ||
'-' || SUBSTR(guid, 13, 4) ||
'-' || SUBSTR(guid, 17, 4) ||
'-' || SUBSTR(guid, 21) || '}' ;

RETURN guid ;
END GET_FORMATTED_GUID ;
/
/*
CREATE TABLE "TEST_GUID_FORMATTED"
(  "GUID_FORMATTED" CHAR(36),
"NAME" NVARCHAR2(50),
CONSTRAINT "PK_GUID_FORMATTED" PRIMARY KEY ("GUID_FORMATTED"
)</code>

truncate table test_guid_formatted;
commit;
*/

declare
stopwatch date;
begin
stopwatch := sysdate;
for counter in 1..1000000 loop
insert into test_guid_formatted (guid_formatted, name)
values (get_formatted_guid, 'test: ' || to_char(counter));
end loop;
dbms_output.put_line(to_char(sysdate - stopwatch));
commit;
end;

Oracle Tip: The decimal marker to a dot, and the thousands marker to a comma in to_number().

0
to_number(t.yournumbercolumn,'9G999G999D99','NLS_NUMERIC_CHARACTERS='',.''')

See also:

Oracle NLS_NUMERIC_CHARACTERS
http://download.oracle.com/docs/cd/B28359_01/olap.111/b28126/dml_options072.htm

Go to Top