Category Archives: Programming

Delete recursively lines from files that match a given string

This is just a small snipplet to remind me of how to delete lines recursively that match a string needle

#!/bin/sh
grep -rl "needle" . |
while read filename
do
(
echo $filename
sed '/needle/d' $filename> $filename.xx
mv $filename.xx $filename
)
done

References used:
www.mehtanirav.com
www.cs.mcgill.ca

PHP Template Caching

This new year brought some inspiration in respect of coding to me and I have decided to research and possibly implement my own template caching system. I have looked around for some solutions but I wasn’t able to locate a system that could handle partial caching, although this could just be my poor googling skills. By partial caching I mean caching the whole template (for example: the <head> section which might be generated automatically, the body with the news and the comments) but don’t cache blocks of data of my choice. A good example of these blocks could be a box looking like this:

Welcome back, DummyUser (link to personal profile)
You have X new messages

So I have spent two days to put down the list of features I want on paper so here it goes:

  • Easy to integrate with other PHP aplications.
  • An ability to work with <meta> tags, <script> and <link> includes.
  • Per template caching on-demand.
  • Caching of whole pages (based on REQUEST_URI) but with an option for non cached blocks of data (example above).
  • Assignment of template variables.
  • Dynamic generation of page titles.

Some of the features are already implemented (and are working!), like caching of templates on demand and caching of whole pages with ability to leave non cached blocks of data.

Hopefully this inspiration will stay for a couple of more days so I accually post a stable version of the class for others to explore and play around with.

CakePHP – First impressions

My first framework after developing with PHP for 4-5 years was CodeIgniter, which I’ve been using for a while and have already dugg into it’s core to go on and make a lite version for personal use. For the past year or two I’ve been hearing a lot about CakePHP framework and have finally found some time to play around with it.

After spending 3 hours last night with the Cake’s online manual (although skipping basic stuff) and reading through the blog tutorial, I have to say I was impressed with CakePHP. Although the convensions could be somewhat difficult for new comers to remember, I have to agree that they are very useful and increase the development speed.

I have also enjoyed their support for third party classes (with javascript includes too!), very well commented API and plugin support:

CakePHP allows you to set up a combination of controllers, models, and views and release them as a packaged application plugin that others can use in their CakePHP applications.
Cookbook

In love with jQuery

jQuery is around for a while already, but only recently I actually sat down and decided to give it a go. jQuery website defines itself as:

jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.

After trying it out, going through jQuery wiki pages I have to say it probably is the best Javascript framework I’ve seen. I have tried mootools (not very recent though), scriptaculous, but jQuery just beats them all. It’s lightweight, very easy to use, has a bunch of ready-made plugins and a large community.

If you’re planning to do some Javascript, try jQuery. Meanwhile I am placing jQuery on my must-use list.