technology

Can't test if a non-image file exists on a remote server

I've been messing around with javascript, trying to find out if a javascript file exists on a remote server before loading it. It turns out the same origin policy thwarts my ajax attempts and <img> tags can only test for images.

Vertical centering in CSS for content of unknown height

I read this excellent article on centering and as the comments are suspended, I thought I'd post about it instead.

I think the floater div position is inconsistent. In 'Which Method?' the floater is a closed tag above the content. In Method 3 the floater wraps the content.

Also a potential con for Method 3 is that you need to know the height of the content, where as you don't for Method 1.

I went with Method 1 as IE9 supports it, though for wider compatibility I should include the IEx hacks.

Drupal code formatting for Zend Studio or Eclipse

This post started out about code formatting, but it's grown to include all my Eclipse setup.

History
Originally I built a PHP formatter in Zend Studio, but I had difficulties setting up the free Eclipse PDT with this config. I followed instructions at: http://drupal.org/node/75242, then tweaked some of the configuration. I pulled it into Eclipse (Juno), changed the XML paths and ignored the warnings, then resaved it out again from the wizard to get it in the right format.

Eclipse setup

PHP development IDEs and why you should have one

I've been doing a lot of development in PHP recently. I started programming in C/Codeworks, but it wasn't until I did some work in OpenCV and Visual Studio that I started seeing the value of IDEs. Having a good debugger is essential to resolving bugs in a timely manner. While it's possible to integrate a text editor, profiler and version control system with a debugger, it takes time to setup and maintain this tool chain, time that I'd rather pay someone else to spend.

Linux shutdown command variants

shutdown -r now
resets and restarts the computer

shutdown now
turns some machines off (which is technically called a halt)

shutdown -h now
shutdown and halt/turn machine off

Can't call arguments.slice() in JS

Javascript is a wonderful language, full of twists and turns. I was surprised that I could:


arguments.length

but not


arguments.slice()

It turns out it's because arguments is not a real array, but a function, which you can access like an array, e.g.:


arguments[0]

To do a slice() op on it:


var args = Array.prototype.slice.call(arguments, 1);

Debugging concurrent javascript in Firebug using QUnit

QUnit queues up all the javascript tests, then runs them. This means you get an accurate picture of how long the tests take to run sequentially, but you have to be very careful about multi-threaded execution. When testing DiSCO, I had to keep using QUnit.stop and .start() whenever I had an asynchronous event between tests.

Also, when setting breakpoints in Firebug, be careful to set them inside the test functions as your code will be operating in two different timeframes. Below t0 is the test setup timeframe and t1 the test execution timeframe.


------- |-t0--- |-t1---

Using SVN hooks to run QA tests on Javascript

Read a great primer by Amaxus on Using JSlint with Subversion hooks. There were a few bugs, largely created by missing \ characters in the published source. My working version is published zipped up below.

Multithreaded wget alternative for Linux or Mac OS X

Happened across aget today. The source is available from http://www.enderunix.org/aget/aget-0.4.1.tar.gz.

To compile under Mac OS X (10.6 Snow Leopard), you need to add -D_DARWIN_C_SOURCE to the gcc compile flags in the Makefile.


# EnderUNIX Aget Makefile
# http://www.enderunix.org/aget/

OBJS = main.o Aget.o Misc.o Head.o Signal.o Download.o Resume.o
CFLAGS = -g -W -D_DARWIN_C_SOURCE
LDFLAGS = -pthread
CC = gcc
STRIP = strip

all: $(OBJS)

Windows 7 file sharing with XP/OSX peers

Recently I've been blighted by a minor network glitch that meant I couldn't file share from my Windows 7 laptop. I was convinced it was something to do with Windows Firewall, ESET NOD32 or even the ZyXel router. I downloaded the excellent Wireshark and used it to analyse the packets; lots of outgoing requests but nothing back from my server (miata). I could ping and transfer HTTP packets, but no file sharing.

Wireshark set up


Alex Stanhope is a Technology consultant to the UK Creative Industries and Venture Catalyst. This is my personal website.
Bristol | Lightenna | ManKind Project | goodkarma
All material copyright (c) 2006-2010 | Website by Lightenna, featuring N.Design's GlossyBlue theme.
Syndicate content