Labels

css (1) jQuery (7) linux (38) mac (70) php (29) python (1) svn/git (9) trac (4) ubuntu (1) virtualbox (6) vista (2) windows (14)

Thursday, 26 November 2009

Freetype 2 OS X 10.6 build architecture problems.

If you try and build Freetype 2 on OS X 10.6 for a different architecture you must add your arch flags to the LDFLAGS environment variable as well as the CFLAGS variable.

Discussion of this problem is here

http://www.mail-archive.com/freetype-devel@nongnu.org/msg03550.html

A patch has been submitted and I have tested verifying it works, the maintainers hopefully will commit it to git soon and release it in the next version.

Tuesday, 24 November 2009

Trac Authz

I've recently been playing with trac's authz plugin.
I had a problem where trac was passing an empty resource to the plugin and hence it was finding no permission.
Details can be found here
http://trac.edgewall.org/ticket/8445

Edit... edgewall changed their links it's now http://trac.edgewall.org/ticket/8445 I'll leave the old one just in case they change it back.

Friday, 20 November 2009

PHP-FPM

I've been looking at the different ways to server PHP files.

Way back when I used CPANEL (hey everyone has to start off somewhere and it does help when the likes of awk and grep scare you), I used apache with mod_suphp or mod_php (depending on what was running, wordpress=mod_suphp)

Now I know what I'm doing (or at least I like to think I do!) I go for nginx, proxying php files back to apache with mod_php (and mod_suphp for Wordpress still...slow..poopy..need better solution).

Now another player comes into the fray, Wordpress and similar systems to update themselves require write access to themselves now if you run mod_php then the "nobody" user needs write access...ack not that wonderful having to chmod everything to 0777.

So in comes mod_suphp which elevates the PHP process to run under the script owners user (assuming it's not owned by root, that could be very bad in a web environment).

Unfortunately mod_suphp is slow.....I'd say at least 4 times slower than mod_php (that's not a real benchmark just a guess).

Looking for a replacement here comes PHP-FPM which is basically a FCGI process manager (the FPM part) for PHP. Looking at it it's promising (hopefully it'll be integrated into PHP 6). It means you can eliminate apache all together and run processes as the script owner.

I haven't tested it but when I get some free time I think I'll defiantly crank up a new server and test it.

If anyone is wondering why I didn't mention PHP and mod_fcgi or mod_fgicd then FYI they're pants! Not too stable, happen to crash and chew up memory and a pain to configure.

YASU - Hiding Emulators

When I get some time to relax (not too often) I like to play video games, now I don't like carrying around a bunch of cds/dvds so I rip my images using alcohol soft, lately I've had a problem with Dawn of War Soulstorm, it kept detecting the emulator.

The solution, download this tiny little program http://www.free-downloads.net/programs/Yasu Yasu. Click cloak and you're done! It loads up as if the disk was in.

Thursday, 19 November 2009

Git

No I'm not insulting anyone! I've just been setting up a versioning system for a new project and had a choice, CVS, SVN or GIT.

Now why use CVS when you can use SVN so it was between SVN and GIT. I knew SVN so started on that...unfortunately getting smart svn to play nice with SVN+SSH isn't that easy I keep getting a handshake failed error (currently bugging the support team on this one) since I wanted to get cracking soon I tried GIT, damn git is bloody easy to use.

Cool things I like about git

1) Local repository! You don't have to be online to commit!
2) PUSH, you can push data to the master repository whenever you want.
3) No server, yes you don't need a server daemon like you do for SVN, you can do it all through SSH

I'm sure I'll find more, I'm currently using smartgit http://www.syntevo.com/smartgit/index.html same people that do smartsvn since I do like their guis.

Monday, 16 November 2009

PHP conditional evaluation


Something I just remembered that will be useful to any aspiring PHP programmers, PHP uses "Minimal Evaluation", which means when checking an if statement (or some other conditional) it will stop once something satisfies the condition, i.e. if we have

if(isset($a) and $b==2)

if $a isn't set then the $b==2 won't be evaluated.

This is handy to suppress undefined index variables for example say we have

if($arr["index"]==1)

where $arr is an array but there is no index "index" in it, this will throw an E_NOTICE error to suppress these we can change it to

if(isset($arr["index"]) and $arr["index"]==1)

if the index doesn't exist the second part won't execute and no error will be thrown.

Sunday, 15 November 2009

Spamhaus checker

Recently I have been plagued by problems with rackspace and spamhaus (read previous posts for more info) so this afternoon I decided to create a PHP script that checks if the server is blacklisted on any of the lists, and here it is for all to use.



/*
spamhaus.org checking script


This script checks the server's ip to see if it is listed on spamhaus.org


I suggest you run this script once a day at most.


If it finds a record it will create a message and e-mail you the message and add an entry to the syslog (this will probably fail on windows but you never know I've not tested it)


You may add an ip address after the script name to test a specific ip


i.e. php filename.php 192.168.1.1


Licence


The MIT License
Copyright (c) 2009 Rowan Wookey obsidianproject.co.uk
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/


/* add your email here if left empty no warning mail will be sent */
$reportTo="";
/* set the following to true to write to the syslog, this is probably a good idea since if the server IP is blacklisted it might not be able to email you a warning */
$syslog=false;
/* set the following to true to print to screen */
$printToScreen=false;

/* add your ip below*/
$ip=isset($argv[1]) ? $argv[1] : "yourserveripgoeshere";

//return codes used by spamhaus.org
$returnCodes=array(
"127.0.0.2"=>"SBL",
"127.0.0.3"=>"SBL",
"127.0.0.4"=>"XBL",
"127.0.0.5"=>"XBL",
"127.0.0.6"=>"XBL",
"127.0.0.7"=>"XBL",
"127.0.0.8"=>"Reserved",
"127.0.0.9"=>"Reserved",
"127.0.0.10"=>"PBL ISP",
"127.0.0.11"=>"PBL SH",
);



//take the server IP, split it into an array, reverse the array then glue it back together, append the spamhaus dns zone to get the host to check
$host=implode(".",array_reverse(explode(".",$ip))).".zen.spamhaus.org";
//get records as far as I know spamhaus only uses A and TXT records
$records=dns_get_record($host,DNS_A|DNS_TXT);
//no records found ok to kill script
if(empty($records)) exit(0);




//records found
$message=date("r").PHP_EOL;
$message.="Server IP found in spamhaus.org database".PHP_EOL;
foreach($records as $r)
{
//if IP is set add return code
if(isset($r["ip"])) $message.="Return code: ".$r["ip"].":".$returnCodes[$r["ip"]].PHP_EOL;
//if txt record add txt message
if(isset($r["txt"])) $message.="TXT record ".$r["txt"].PHP_EOL;
}
//if reportTo isn't empty send warning email
if(!empty($reportTo))
{
mail($reportTo,"Spamhaus.org listing",$message);
}


Oh and blogger so just filled this post with junk (lots of span tags setting the font to courier)

//write to syslog
if($syslog)
{
//open syslog witdh spamhausCheck ident, if fails prints to console, logged as mail at alert level (pretty critical in my opinion)
openlog("spamhausCheck", LOG_CONS | LOG_PERROR, LOG_MAIL);
syslog(LOG_ALERT,$message);
closelog();
}


//print to screen
if($printToScreen)
{
echo $message;
}


Wednesday, 4 November 2009

Browser compatibility

Here's a tip for any budding web designers out there when dealing with
browser compatibility.

Don't expect all browsers to render pages the same, they won't, and
they shouldn't!

Why? Well think of it this way, you have a Standard definition TV and
an HD TV, you can't expect to see HD programs on a SD TV you need the
latest HD technology for that, the same goes for web browsers, you
can't expect Internet Explorer 6 to render like Internet Explorer 7 or
8.

You can expect IE8, Opera, Safari 4, Google Chrome, Sea Monkey 2 and
Firefox 3 to render in a pretty similar fashion.

IE 7 and 8 as well as Safari 3, Sea Monkey 1 and Firefox 1/2 will
render differently (especially with regards to CSS3 which IE8 doesn't
handle too well either).

Your users won't notice if it doesn't quite look pixel perfect the
same in each browser, they won't come along and open your site in 4 or
5 browsers to make sure it looks the same.

Tuesday, 3 November 2009

Create an Awesome Command Line Calculator [Terminal Tip]


This is an article from lifehacker. Thought it was cool.




When you spend as much time at the terminal as I do, having a calculator at your fingertips can be a really useful feature, and the Command-Line Fu web site tells us how to create one easily.
To create the calculator, you can just enter this function on the command line to test out how it works, or add it into our ~/.bashrc file to make sure that it's always available after restarting the terminal.
calc(){ awk "BEGIN{ print $* }" ;}
To use it, you can simply type calc followed by the calculation you want to solve, making sure to use quotes around the calculation if there are spaces or special characters the shell can't handle. For instance, if you entered calc 3*99/7+18 at the prompt, you'd get 60.4286 as the answer. For more complex calculations, you can use parenthesis, but make sure to put quotes around it, like this:
calc "((3+(2^3)) * 34^2 / 9)-75.89"
It's an extremely useful tip for those of us that live at the terminal. It should work on any OS running the bash shell, including Linux, Mac OS X, or even Windows with Cygwininstalled.
Read more…