Open Source


13
May 11

Frigging Huge PDFs

Turns out this is how you fix up a frigging huge pdf that probably came out of photoshop or some such beast with all of the layers and history that is mostly useless to you. It seems to work quite well, 230 MB down to 6MB.

Of course you can do some tweaking to reduce the size even more if you want to (take a look at the ghost script manual).

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf


6
Mar 11

Instead of just Killing off IE6…

Why not kill off IE7 while we are at it?

So, IE6 is on the death march. It’s support ended July 13th 2010. Unfortunately it persists because of Windows XP, as it’s support lasts until 2014.

http://www.theie6countdown.com/

I figured I should help out, but I want to help kill of IE7 as well, so I found an IE6 notice script here: https://code.google.com/p/ie6-upgrade-notification-bar/. I have made quite a few changes to it, and here is the result:

http://seanja.com/demos/ie7-notice/.

The source is available on github https://github.com/SeanJA/ie7-notice.


26
Jan 11

PHP SQL Query Builder

As an excersise I have started building another php based sql query builder (separate from my stagnating php framework). So far I can do SELECT [columns] FROM table WHERE [conditions]

This is how it should be used (so far):
(for the examples, assume that $q is a query object)

$q->table('test')
	->column('test_2', 'test')
	->table('test_3', 'test_2');
//=> SELECT test_2 as test FROM test, test_3 AS test_2

You can also group conditions:

$q->table('table')
	->begin_and()
	->and_where('col_1', 1)
	->or_where('col_2', 2)
	->end_and()
	->or_where('col_3', 3, '!=');
 
//=>SELECT * FROM table WHERE ( col_1 = '1'  OR col_2 = '2' ) or col_3 != '3'

which is fun.

I have just tried this example and am pleased to say that you can put multiple groups at the start of the query:

$q->table('table')
	->begin_and()
	->begin_and()
	->and_where('col_1', 1)
	->or_where('col_2', 2)
	->end_and()
	->end_and()
	->or_where('col_3', 3, '!=');
 
//=>SELECT * FROM table WHERE ( ( col_1 = '1' OR col_2 = '2' ) ) OR col_3 != '3'

You can follow along here if you want, suggest improvements, criticize it to no end because I am doing it toally wrong, or “steal” my ideas and make your own (but give me some of the credit at least).


13
Jan 11

Using Valums File Uploader with CodeIgniter

Valums file uploader is a fancy pants ajaxy uploader widgit that is meant to be used with normal php pages. It, by default, doesn’t really play well with CodeIgniter.

Fortunately, it isn’t that hard to make it work. There is a bit of a modification to the .js file:

Basically, you just have to turn the ?qqfile=blah into /blah . Granted, this is a quick fix… and it will not work if you want to pass extra params to the upload. A better fix would be to rewrite parts of the qq.obj2url function so that it accepts a different separator.

The other thing you have to worry about is CodeIgniter’s magical stripping of characters that it doesn’t like specifically: the . in your file’s name. Fortunately this is easy to fix:

//snip [......]
	  //codeigniter replaces the . with a _ argh, we can fix that by doing this:
	  $filename = substr_replace($param1, '.', strrpos($param1, '_'), strlen('_'));
//[......]   /snip

That is about it, the code is available here: https://github.com/SeanJA/uploadr.

Also, since I don’t subscribe to the “we must support php 4 forever” mentality, you will notice that the methods in my classes have private, public, and protected, you can just remove all of those if you need to support PHP 4 still (but you really should upgrade…).


31
Mar 10

PHP DateTime is missing methods in 5.2

It turns out that in PHP 5.2, the DateTime class is missing a couple of methods (get/setTimestamp) that are available in PHP 5.3. These are some strange methods to be missing as a lot of people in the PHP world seem to work on Timestamps using these concepts, so you would have thought that php would have included these methods initially. Unfortunately they did not, so here is a fix for that:

And since using it in production would be no good if it were not tested properly, here are the unit tests to make sure that it returns the same values as the new one in PHP 5.3:

You use it the same way that you would use the normal DateTime class, it even includes the poorly named php functions date_timestamp_get / date_timestamp_set if they don’t exist so you can use them as well.

Hopefully this is helpful for those of you that have used this functionality mistakenly (as I did) before realizing that it wasn’t actually available.

(get it on github: http://gist.github.com/349273)