August 12, 2008 by pierre
I’m working on PDF templates using FPDF, the templates are based on a grid and I had to find how much of the grid’s units different images are using, e.g. if an image width is 1.3 units I need to make 2 units space for it in the the grid.
In other words I needed to “round” a floating point number, but always to a bigger number so the round php function would not be usefull :
echo round(1.2); // 1
echo round(1.6); // 2
Then I thought that what I wanted was the “next bigger integer”, and it felt in place : change the float to an integer and add one.
echo ((int) 1.2) + 1; // 2
echo ((int) 1.6) + 1; // 2
This is super simple but it seem to me a good exemple of how formulating what you want to do in english can help when programming.
Tags: maths, php, type | Comments (4)
May 30, 2008 by pierre
Once it is compiled, PHP can be configured using a file called “php.ini”.
If you are using PHP as a server module (mod_php in Apache) this file is read when the server is started, this implies that you need to restart the server to update the configuration. But using php via CGI or command line interface, it is read each time a script is executed.
You can have several php.ini files and it is searched in an ordered orthodox serie of locations. Thanks to this feature you can have specific configurations of PHP per level of directory trees on your server. In some systems though (we just experienced this on a Site5 shared hosting account) you can somehow bypass this list (I don’t know exaclty how you do this) and have php.ini files setting the defaults for only the folder that contains it. In other words each php.ini files can then only affect scripts that are in the same folder.
For example if you are using a script to upload files bigger than than upload_max_filesize you can reset this limit in a php.ini file but it then has to be in the same folder as your uploading script. In this situation if you are using a framework like Code Igniter or CakePHP the code that is executed when you upload a file will be scattered in many files and directories. We thought and googled hard for a cleaner solution (please comment if you know a better way!), but we ended up duplicating the php.ini file in all the application and framework core dirs so that our settings are applied correctly.
To do this from the command line, cd to the top dir containing the php.ini file and do something like:
for i in `ls -aR | grep \: | cut -f 1 -d :`; do if [ -d $i ]; then cp php.ini $i; fi; done
Tags: command line, configuration, php, php.ini, server | Comments (0)
May 24, 2008 by pierre
Tommi recently showed me a service called Friendfeed, it is an rss aggregator for everything that you post on a bunch of online services and your personal rss feeds. It is very well integrated with those services and building a profile is quick. You can then subscribe to other people profile, and see an overview of their updates in a “friends” tab on the main page.
We were recently discussing about this site with Jérôme and he mentioned that it would be nice to have it in IM, I did a quick search of existing solutions or possibilities.
Post: there is posting bot provided by imified for Friendfeed.
Read new posts: you can use an IM feedreader, I tried with inezha.com. Once you have an account on inezha (anothr), you can subscribe to your “friends” activity feed (the feed’s link on Friendfeed is in the page header or at the bottom of the friends tab) and regularly receive IM updates of the content that appears in this feed.
These are two immediate solutions, it worked ok in a few minutes. The output of inezha.com bot is a bit ascii-arty but I guess it won’t be difficult to have something more minimal for ex. preprocessing the Friendfeed feed in yahoo pipes.
A more complete solution would be to use the Freindfeed API. There are wrappers in Python and PHP for it. It has a read method (/api/feed/home) for your homepage view (friends updates) and one (/api/share) for creating new entries. I know three python jabber modules, words, based on the twisted framework, and then there is xmpp.py and jabber.py. I think the most lively one is xmpp.py (last updated in 2007). Php has a xmpphp package.
Tags: friendfeed, IM, instant messaging, php, python, reader | Comments (0)