Bali Web Design Studio is a small enthusiast web design studio based in Bali, Jakarta, Indonesia.

Recursive directory iteration with PHP Filesystem API

I have a small stuff to do this morning related to php filesystem api, warming memcached for static files and php template to reduce I/O process overhead in front-end application

$dir = '/path/to/some/dir';
$flags = FilesystemIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS;
$iterator = new RecursiveDirectoryIterator($dir, $flags);
$result = array();
foreach ($iterator as $file) {
    $result[] = $file->getFilename();
}
print_r($result);

The result will be list of files and directories exist in `$dir`, somehow i need a recursive iterator, luckily php has it all, with small pimp I can have it, just before line where `$result` declaration, I add this line

$iterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);

bingo! now it running recursively, i need some filtering here since i only need files with `.txt` or `.html` files, currently it returned all files and directories exists in `$dir` so i created a new iterator filtering class as below

class FilterTxtHtml extends FilterIterator {
    public function accept() {
	$fileinfo = $this->getInnerIterator()->current();
	if (preg_match('/\.(txt|html)$/', $fileinfo)) {
	    return true;
	}
	return false;
    }   
}

save it somewhere, include it and put this line before `$result` declaration,

$iterator = new FilterTxtHtml($iterator);

final code as below:

$dir = '/path/to/some/dir';
$flags = FilesystemIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS;
$iterator = new RecursiveDirectoryIterator($dir, $flags);
$iterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
$iterator = new FilterTxtHtml($iterator);
$result = array();
foreach ($iterator as $file) {
    $result[] = $file->getFilename();
}
print_r($result);

Easy enough.

Twitter API + jQuery JSONP

Here i will show you how easily fetch non authenticated Twitter API methods using ajax json callback functions with jQuery framework, I use user_timeline method as an example but you can use this sampel to fire other twitter api method as long as its needless authorization.

The TwitterAPI Class

TwitterAPI = {
	Statuses: {
		user_timeline:function(screen_name, count, callback){
			jQuery.getJSON("http://twitter.com/statuses/user_timeline/" + screen_name + ".json?count="+count+"&b="+Math.random()+"&callback=?", 
			callback);
		}
	}
};

Read the rest →

PHP Error Exception Handling

Got a question from a friend today who is actually a great desktop programmer and just learn PHP since he believe that the future is in the web (hope you’re right dude). He asked me about how to handling error in PHP. Well i’ll write my answer here so can share with others and got feedback when I was wrong.

In PHP there are few options that you can use to handle errors & exceptions during script executions and as developer you must considering not the easiet but the most flexible approach which will help you when debugging your appllication, the more detail error message provided the faster you can fix it. Flexible means its easy for you to change the application behaviour when unexpected things happened during execution like: display error, logging error or even automatically notice you via email.

Read the rest →

Install, Configure & Running Memcache in Windows as Service

Installing memcache server in windows is a little bit complicated compared to how it can be done in *nix since theres not yet available ready to use package for win32.

Luckily i found the compiled memcached for win32 (exe) which was made by jellycan, within this exe file you can install configure and running memcached as a service in your windows environment, here are how i made it:

*** updated ****
Newer version available at northscale, thanks to Matt Ingenthron for pointing this.

Read the rest →

DynamicWP Image Cube WordPress Plugin

DinamicWP Image Cube is a free plugins for wordpress which will turn your selected images into a 3D image cube slideshow. This plugin will randomly show your image with beautiful fadein/fadeout 3D cube effects.

Released under GPL License means you can use it for all your project or at least use it as a foundation for your next projects for free and without any restrictions.

Download & Demo

Creative Entrepreneur Portfolio & Blog

Joel Dumas

Joel Dumas is a Creative Entrepreneur, an Artist. This site is the showcase of his previous projects & creations while also the place where he share his visions, journeys & experiences. Built using wordpress with great arts imagery.

have a look at my portfolio here »

Personalized Your Diving Experiences in Bali Indonesia

Dive Around Bali

divearoundbali.com is a new guide service that will show you Bali’s underwater miracles in style. Established by couple certified dive instructors from Belgium. Provides unique, fully personalized diving experiences in Bali.

Built in wordpress, Multilingual with unique theme and uses some jQuery based animation.

have a look at my portfolio here »

Simple Unique Wordpress Theme with Coffee Taste

Real Kopi Luwak

Real Kopi Luwak is a small website built in wordpress dedicated to introduces kopi luwak but also sell kopi luwak if you want to try it :-) taste good anyway.

have a look at my portfolio here »

Simple Wordpress Theme for Villa in Lombok

Ocean Heaven

Lightweight and Simple Wordpress theme for Ocean Heaven Villa Accomodation in Lombok.

have a look at my portfolio here »

Scuba Diving Services Website

For Fun Diving Bali

A small dive operator based in Padang Bay, Bali, Indonesia. Established by professional female diver who has big concern to marine conservation and focus on providing environmental oriented scuba diving services.

This website was built in wordpress with multilanguage supported, nice warm colors with sleek jQuery animation integrated.

have a look at my portfolio here »

bali web design studio Freelance Web Developer Works Bali Web Design Portfolio Get Web Design Quotation RSS Feeds