Root privilege scripts from Apache
February 17th, 2010
If you have a script that needs to access functions that can only be run as root (e.g. chmod, chgrp, mkdir, etc) you will find that you can’t call these directly since the Apache user is not root (at least it should not be root). There is no perfect solution around this as all solutions involve some security risk, but the least bad seems to be to use sudoer to grant root privileges to the script and then lock down the script so nobody other than root can modify the script.
First chmod the script so that anyone can execute it, but nobody other than root can modify it (I am assuming here that you are logged in as root, otherwise sudo).
chmod 111 /home/path_to_script
Next modify sudoer using visudo. It is a good idea to use visudo so that any change you make are updated without having to restart sudo.
# visudo
Add the following line after the root entry in sudoer
apache_user ALL = NOPASSWD: /home/path_to_script
Change the apache_user to whatever your apache user is (e.g. nobody) and then add the path to your script. You might want to add your favorite editor (mine is nano) to your export in .bashrc. You should now be able to call your script from apache without problem.
Mac OS X compatible external web camera
February 16th, 2010
I use my macbook with an Apple 23 inch monitor at work and so I can’t use the inbuilt iSight camera. Since Apple stopped selling the external iSight camera there is not much choice for Apple compatible web cams since most of the web cameras on the market don’t come with Mac OS X drivers.
One surprisingly option is the xbox360 web cam. This external usb camera works without any drivers and just plugs straight in and works. I managed to pick up a brand new one on eBay for A$35. The quality is pretty good and it sits without any problems on top of my monitor. Nice work microsoft.
Sphere: Related ContentAdding iso repository under XenServer 5.5
September 23rd, 2009
If you want to install an OS from a local repository under XenServer 5.5 then you need to do the following. The documentation on how to do this in the xenserver manual is incomplete.
first ssh into the xenserver
mkdir -p /var/opt/xen/iso_import
Copy your ISO images to the /var/opt/xen/iso_import directory using scp.
Create a repository with this command:
xe sr-create name-label=ISOs type=iso device-config:location=/var/opt/xen/iso_import device-config:legacy_mode=true content-type=iso
You then need to attach the ISO library with this command (nicely not mentioned in the citrix documentation)
xe-mount-iso-sr /var/opt/xen/iso_import
You should then be able to create a VM using the .iso
Sphere: Related ContentApple Bootcamp 2.1 and Windows XP SP3
August 26th, 2009
There is a problem with Bootcamp 2.1 in that you can’t install the Apple drivers under Windows XP SP3. I recently bought a new MacBook Pro and installed Windows XP SP3 from an image and then tried to update the XP hardware drivers using bootcamp 2.1. This didn’t work an instead gave a nice cryptic error 2762. It seems it is not possible to install the drivers manually either as windows can’t install the drivers for the wireless network, iSight camera, and trackpad.
The solution is to install XP from a SP2 image (luckily I had kept one), then install the drivers, and then upgrade to SP3. I hope this saves someone a bit of time.
Update. This has apparently been fixed in snow leopard. I guess another reason to update.
Sphere: Related ContentHow to get total folder / directory size with Linux
May 16th, 2009
If you want to know how much disk space is being used by a directory (including all the sub-directories) then you can use the following command. It will output a single number in human readable form (eg 8.2G). I have found this very useful for finding where all my disk space has gone.
du -h | grep -v '/' | awk '{print $1}'
X11 ssh-forwarding of a gnome-session to Mac OS X 10.5
September 17th, 2008
If you want to X11 ssh-forward a gnome-session on a remote linux server to MacOS X Leopard there seems to be some bug in the 10.5 X11 that causes the gnome desktop to take over the whole screen and you can’t access the session. The solution is to open the gnome-session using Xnest instead. This opens the session in a small X11 window (1024×768 in the example below).
Xnest -geometry 1024x768 :1& DISPLAY=:1 ssh -X <HOST> gnome-sessionSphere: Related Content
Random PHP string
February 14th, 2008
I needed to generate a random string in php that did not repeat. This little snippet will generate a random non-repeating 32 character string.
// Generate random 32 character string
$string = md5(time());
IE 6 javascript onchange() problem
February 6th, 2008
I really hate IE6, but as it is still so common it is important to support it. I recently ran into a problem with the javascript onchange function. I was using onchange to update a text box on the page when the check box was selected. I was using “…onchange(this.checked)…” This worked fine for everything except IE6. It turns out that IE doesn’t fire the onchange state until the checkbox loses focus and so my update was not occurring.
The simple way around for this problem was to change onchange() to onclick(). The function now works in all browsers.
Sphere: Related ContentPHP number_format function problem
February 5th, 2008
I have been using the php number_function() to format currency values in my code and was recently caught by the thousand separator comma. If you use the function and just specify the the number of decimal places (ie $x = number_format ($y,2) ) then you will get a comma introduced for all numbers above 999.99. This comma will break any maths functions that you might use downstream.
The solution is to specify the decimal point but remove the comma. The format to use to achieve this is $x = $number_format ($y,2,”.”,”") – the empty double quotes tell the number format function to not include the thousand separator comma.
Sphere: Related ContentBest Javascript compressor to use
December 18th, 2007
I recently had a relatively large javascript (14KB) that I want to compress down. There are a lot of online JS compressors out there unfortunately not all of them actually work. After testing around a dozen of them I found the best two are JavaScript Utility and Javascript Compressor. JavaScript Utility was able to compress down my code to 5.0KB while Javascript Compressor compressed down to 6.3KB.
While both are good I would recommend using Javascript Utility, not only because it achieved a better compression ratio, but it also has a large number of other JS utilities that are worth using (especially JSLint). The only problem I found is I was only able to get the UTF-8 encoding option to actually run.
Sphere: Related Content