Monthly Archives: November 2006

mysql modes

I just found out about MySQL “SQL modes”. This allows you to now turn off some of the features that make MySQL so easy to use.

Why would you do that? For the same reason that in Perl, you should use strict, and in PHP, turn off all global variables and GPC variables and turn on all warnings.

In other words, you should lock down your MySQL to not allow any sloppy work. This will train you to write correct code in the future.

What I will be doing is to lock down my home machine to the strictest possible setting, then work on getting my company‘s CMS working with it. Once that’s done, I’ll gradually lock down our development server (can’t just do it immediately, as there are always at least 15 sites in constant development, not all of which I’ve fixed up yet).

What I will /not/ be doing is locking down our production server, for at least a few years! With hundreds of sites of different CMS design, it is not predictable what will work smoothly and what will explode.

imagefader

I was asked to write a simple image fader. I believe I’ve come up with possibly the simplest one out there.

demo

To use this in your own site, link your document to a copy of the javascript and run imagefader_init() upon load, then edit the <img> that you want to run the fader on – here is an example:

<img
  src="/i/test1.png"
  class="imagefader /i/test1.png /i/test2.png /i/test3.png"
/>

That’s it!

using your TV as an external monitor for your computer

This took me a while to figure out. The scenario is that I have a TV in the main sitting-room, and my main computer is in the kitchen (it’s a small house…). I want to be able to watch my vids (video.google.com, youtube.com, dvd backups, etc) on my TV.

The hardware you need is a video card with a TV-out on it (this article uses the nvidia GeForce FX 5500), an s-video to scart connector, and appropriate cables for the audio and s-video connectors.

Connect the video card’s s-video connection to the Scart thing’s s-video (or Video, if that’s the cable you bought), and connect your audio card’s loudspeaker connection to the audio connectors on the Scart thing.

Once the hardware is all hooked up, you need to configure your Xorg to use your monitor as the main display (:0.0), and your TV as a second monitor (:0.1). Here is the content of my /etc/X11/xorg.conf file:

Section "ServerFlags"
       Option   "AllowMouseOpenFail" "true"
       Option   "DontZap"   "True"
       Option   "DontVTSwitch"   "False"
       Option   "DefaultServerLayout" "GeForce_FX_5200_AGP_TV"
Endsection

Section "ServerLayout"
       Identifier     "GeForce_FX_5200_AGP_TV"
       Screen       0 "Screen0" 0 0
       Screen       1 "Screen1" RightOf "Screen0"
       InputDevice    "Mouse0" "CorePointer"
       InputDevice    "Keyboard0" "CoreKeyboard"
       Option         "Xinerama" "off"
EndSection

Section "Files"
	ModulePath   "/usr/lib/xorg/modules/extensions/nvidia"
	ModulePath   "/usr/lib/xorg/modules"
	FontPath     "unix/:7100"
EndSection

Section "Module"
       Load  "dbe"
       Load  "glx"
       Load  "extmod"
       Load  "fbdevhw"
       Load  "record"
       Load  "freetype"
       Load  "type1"
EndSection

Section "Extensions"
       Option "Composite" "Enable"
EndSection

Section "InputDevice"
    Identifier     "Keyboard0"
    Driver         "kbd"
    Option         "XkbLayout" "us,bg"
    Option         "XkbVariant" ",phonetic"
    Option         "XKbOptions" "grp:alt_shift_toggle,grp_led:scroll"
EndSection

Section "InputDevice"
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Device" "/dev/input/mice"
    Option         "Protocol" "IMPS/2"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "Monitor"
	Identifier   "Monitor0"
	VendorName   "Monitor Vendor"
	ModelName    "AOC Spectrum"
	DisplaySize  320	240
	HorizSync    30.0 - 72.0
	VertRefresh  50.0 - 160.0
	Option	    "dpms"
EndSection

Section "Monitor"
       Identifier   "TV"
       VendorName   "Phillips"
       ModelName    "TV"
       HorizSync    30-50
       VertRefresh  60
       Option       "dpms"
EndSection

Section "Device"
       Identifier   "GeForce FX 5200 AGP"
       Driver       "nvidia"
       Option       "UseEdidFreqs" "True"
       VendorName   "GeForce FX 5200"
       BoardName    "GeForce FX 5200"
       BusID        "PCI:1:0:0"
       Option       "NoLogo" "True"
       Option       "TVOverScan" "1.0"
       Option       "NvAGP" "3"
       Option       "ConnectedMonitor" "CRT,TV"
       Option       "RenderAccel" "true"
       Screen 0
EndSection

Section "Device"
       Identifier   "GeForce FX 5200 TV"
       Driver       "nvidia"
       Option       "UseEdidFreqs" "True"
       VendorName   "GeForce FX 5200"
       BoardName    "GeForce FX 5200"
       BusID        "PCI:1:0:0"
       Option       "NoLogo" "True"
       Option       "TVOverScan" "1.0"
       Option       "NvAGP" "3"
       Option       "ConnectedMonitor" "CRT,TV"
       Option       "TVStandard" "PAL-I"
       Option       "TVOutFormat" "COMPOSITE"
       Option       "RenderAccel" "true"
       Screen 1
EndSection

Section "Screen"
    Identifier   "Screen0"
       Device       "GeForce FX 5200 AGP"
       Monitor      "Monitor0"
    DefaultDepth     24
    Subsection "Display"
               Depth       24
               Modes       "1680x1050" "1280x1024" "1280x960" "1024x768" "800x600" "640x480" "400x300"
    EndSubsection
EndSection

Section "Screen"
    Identifier   "Screen1"
    Device       "GeForce FX 5200 TV"
    Monitor      "TV"
    DefaultDepth 24
    Subsection "Display"
               Depth       8
               Modes       "1024x768" "800x600" "640x480"
    EndSubsection
    Subsection "Display"
               Depth       16
               Modes       "1024x768" "800x600" "640x480"
    EndSubsection
    Subsection "Display"
               Depth       24
               Modes       "1024x768" "800x600" "640x480"
    EndSubsection
EndSection

download it here

When you restart your X server, you should see your normal desktop (otherwise, somethings wrong – fix it, and comment about your fix!)

When you run into your TV room and change channel to your AV channel (usually 0 or below). You should see a pretty plain desktop. Note that my setup above is specific to Ireland (PAL-I), and other countries using the above may see their desktop in black and white, or broken up and flickering. If it’s in black/white, then change the “-I” in PAL-I to whatever your local format is (BG, DE, etc). If it’s flickering madly, you probably need NTSC instead.

Okay – it’s all set up!

There are two main ways now to use this – piping the video onto display :0.1, or using the :0.1 desktop directly.

To use the desktop directly, you can use x11vnc, which allows you to export the desktop to a VNC session, which can then be connected to and used from another machine. Anything you do on the local VNC client will be shown on the TV as well.

To do that, open a console window using the desktop user’s account, and type:

x11vnc -display :0.1

The other way is useful if you’re sitting in the sitting-room with a laptop on your lap, and want to play a video without going through the whole VNC thing.

Open a console on your laptop and ssh to the main computer, logging in as the desktop user. Then find the video you wand to display, and open it like this:

DISPLAY=:0.1 mplayer -fs "/archive/films/t/they came from beyond space (public domain, 1967).avi"

That’s quite a good film, by the way – download it here.

I hope this was useful – it’s probably the longest post I’ve written!