Setting up PIL with libjpeg on Mac OS X Leopard
by Reza Muhammad on Apr.01, 2009, under Apple, Python
Background
For the past few months I’ve been playing around with Django, and it has come to a situation where I need Imaging Library to fulfill my project’s requirements. In Python, it is handled with PIL. So, here’s what I did to setup PIL with libjpeg support on Mac OS X Leopard.
Default vanilla Mac OS X install doesn’t have libjpeg by default, so I need to install them first.
Methods of Installing PIL on Leopard
There are a few methods you can use to install PIL on Mac OS X, they are:
- Install libjpeg from source, and then also install PIL from source
- Use MacPorts/fink to install libjpeg and PIL automatically.
- Or, you can also install libjpeg from MacPorts, and then PIL from source
I decided to use the third approach. First of all, I’m still not confident to install library from source, and also I want to use binary form where as much as possible. Also, I didn’t install everything from MacPorts even though they are available. My primary reason is, if I installed PIL from MacPorts, it will also install Python, which I don’t want. Apple already included Python in the default install. If you prefer to use fink over MacPorts, you can also do this.
Installation
- Download MacPorts and run the installer.
- Install libjpeg by using these command lines:
sudo port install jpeg
This will install libjpeg in “/opt/local/lib“ - Download PIL from source from pythonware
- Extract the file:
$ tar zxvf Imaging-1.1.6.tar.gz
$ cd Imaging-1.1.6 - Edit setup.py, and change the line JPEG_ROOT to:
JPEG_ROOT = "/opt/local/lib/libjpeg.dylib" - Compile and build the source:
sudo python setup.py install
The above step will install PIL package in “/Library/Python/2.5/site-packages/“. This is the default directory where Python packages are located in Mac OS X.
Verify the Package
Now, here’s what I did to check whether PIL was successfully installed on my computer.
In Python interpreter, I did the following:
% python
Python 2.5.1 (r251:54863, Nov 12 2008, 17:08:51)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Image
>>> image = Image.open("/Users/rezmuh/test-image.jpg")
>>> image.save("/Users/rezmuh/pil-image.jpg")
>>> ^D
If there is no error and you can see the new image copied from an old image, then congratulations, PIL is successfully installed
If you know any simpler ways to install PIL, please let me know
PHP Frameworks: So many options, few are sufficient
by Reza Muhammad on Jan.10, 2009, under PHP, Reviews
For the past few months I have been playing around with CakePHP. Most of the people who have used PHP frameworks have probably heard of it. CakePHP’s features are quite good, and extensive. Their function names are quite self explanatory that I don’t need to look at the API documentation very often. But after a while, I’m starting to look at its ugliness. I am now starting to try different frameworks to see which I like best. This article are some of the things I like and I dont like from each of the frameworks.
CakePHP
I found CakePHP to be one of the easiest framework to get started right away. Their documentation was quite helpful to get me going to start my first “simple” application.
However, the more I played with the framework, I started to feel like I was forced to do certain things because it was the “Cake way”. One of their main features is “conventions over configurations”. This might seem quite useful at first, but I’ve past that stage, and now I feel that feature is becoming more of a burden. Their conventions are very strict. For example, you need to have a model in a singular form, and a controller in a plural form. It’s so strict that I didn’t even know that “data” is a plural word of “datum”. I thought data could be used as singular, and plural word. I even searched for it. It turned out I was wrong. This singular-plural-word thingy is not always useful for me since I’m not always developing application in English. In Indonesian, there is no such thing that differentiate singular and plural words.
Another thing I don’t like about CakePHP is that their data validations are tied with the models. Sometimes you need to have different validations on the same model depending on the forms (assuming you have more than one form to do data manipulation on your model).
CodeIgniter
Next, I looked at CodeIgniter. I have to admit that I have never tried CodeIgniter, I’ve only looked at their documentation. My first impression was, their documentation is superb. That’s also what I’ve been hearing from people who’ve used the framework. While skimming through their documentation, I noticed that the syntax and their idealogies are very similar to CakePHP, and I thought I would feel right at home.
Some of the noticable differences from CakePHP are CodeIgniter doesn’t force you to have a model for each controllers you have, and data validations are located in forms. And I’ve also heard that generally CodeIgniter gives you alot more freedom (in terms of how you code) compared to CakePHP.
Another good thing I’ve heard about CodeIgniter is that it’s very fast. Part of the reasons why it is so fast is because CodeIgniter doesn’t use OOP on all of their codes, and this was said that it could gain performance.
However, out of all the good things I’ve heard about CodeIgniter, it doesn’t have the “corporate” feel. Funny i feel that way since it is actually developped by a company called EllisLab. Another thing I don’t like about CodeIgniter is that I have to “load” everything for each functions I create. I might be wrong on this, I’ve only looked at their documentation. But it seems that you have to call the template, and helpers everytime.
Symfony
Then, I continued my next journey to symfony. Some of the good things I’ve hear about symfony is that it’s an enterprise-ready kind of framework. Having been used at various sites by Yahoo! and some other professional websites, I thought the performance would be good.
Then, I tried to search about its performance but I couldn’t get a recent benchmarks. If you have any, please let me know. But from a one-year-old benchmark, symfony performed quite slow even though the test case didnt exactly prove any real life usage.
Symfony has a very extensive documentation, which they call “The Book”. Alot of topics are covered thoroughly, my only gripe is their documentation structure since I’m not used to it.
Another thing I’m interested in Symfony is their CLI (Command Line Interface). Their CLI seems very powerful. You can generate codes (CakePHP’s bake does this too), insert sql queries, and so on. Although at this point, I think they have too many features on their CLI.
The other thing I don’t like so much about symfony is their extensive use of YAML for the configurations. I definitely choose YAML over XML for configurations, but there seems to be alot.
Zend Framework
Last but not least, I looked at Zend Framework. I’ve been avoiding to use Zend Framework because they don’t look like a framework. It’s been discussed very often that Zend Framework looks more like a sets of libraries that are ready to use. And I agree with that.
However, I finally tried it, and tried some of the examples given from the quickstart guide at their documentation, and I couldn’t stop thinking, why do I have to go through all of this stuff just to get my framework up and running? Those things are creating directories (controllers, models, application, etc), .htaccess file, bootstrap file, index.php file, and more. My goal on using a framework is so that I can get my web applications done faster, but this itty-bitty work at the beginning turns me off.
The good side about ZF is that their collections of “libraries” are very complete. From creating RSS feeds to creating a Web service, they have it. And I find this very useful when I need to build a complex web applications.
Another good thing about ZF is, well, Zend. Who should be able to create a better software than the maker of the language itself? At least that’s what I hoped for when I first heard about ZF. It is obviously not the best framework now, but it might change in the future.
Conclusion
After looking at these frameworks, I’m still having doubts which of the frameworks should I invest my time in. But these days, I’m leaning towards either Symfony, or Zend Framework, although Zend Framework probably has a bigger chance, only because it’s developed by Zend. After all, if ZF will become a standard de-facto of PHP framework, it will be easier for me to look for programmers who understand ZF.
Also, I’m quite aware that most of the features of each frameworks I mentioned above can be overridden (for Example, validation in CakePHP, YAML in Symfony), but those are the default settings on their respective frameworks.
This post doesn’t mean to be a flame, or anything, they are simply my point of view. This doesn’t intend to “attack” any supporters of any framework they are proud of. Also, you should probably read this with a grain of salt
Is PHP really that bad?
by Reza Muhammad on Sep.13, 2008, under PHP
First of all, let me state that I don’t think I’m an expert programmer, but I think I’ve learned programming from some very good people (at my previous work) who were perfectionists in terms of how the code should look like.
When I first started programming (it has not been long, trust me), I started to work on a real-project using PHP. I was taught to use it because PHP is considerably easy to learn. I believed it, after all, lots of universities in Indonesia didn’t have PHP in their curriculum, yet there were so many PHP developers in Indonesia. I thought these people must’ve been self-taught, hence the languge itself isn’t really difficult. It turned out to be true. PHP isn’t really hard. I’m now used to it, even though I’m still looking at other programming language to learn from.
When I worked as a developer in the past, my employer was very strict on coding style. Everything has to look similar from one file to another. We also followed (kinda) MVC where View should not interact to the Model right away. Instead, it will be the controller’s job. We also tried to maintain that there should be no PHP codes in HTML files or vice versa. The solution was to use Smarty, for better or worse.
Some of the strictness we used were:
We use:
$n = count ($var);
for ($i = 0; $i < $n; $i++);Instead of:
for ($i = 0; $i < count ($var); $i++);
Also, spacing between characters, variable assignments, calculation, curly braces, and all that stuff are maintained. No one is allowed to write:
for($i=0;$i<$n;$i++);
Well, one line of code might not matter. But if you have hundreds or thousands of files, your eyes will eventually be tired to read some of these codes. To cut story short, we used K&R style as much as possible.
Now, my problem is, I resigned from my old company, and started on my own business, and I’m still doing PHP work. For the first few months I could work by myself. But sooner or later, I started to need some help from other developers, so the job vacancies began.
Here’s what I found out when I interviewed and tested some of the guys:
- Their codes are truly a mess. No indentation, no spaces between assignments, calculations, and etc.
- They don’t understand the concept of MVC. So, they write their codes on Dreamweaver where they can mix the HTML codes and PHP codes
- Even worse, some of them don’t even know how to write codes from scratch. One of the applicants actually asked me if I had a PHP file where he could edit and finish it.
I know that some of the problems I faced was because some of these people might “lie” on their resume, or maybe their codes was good enough for their former employer. Now, this leads me to my question:
Is PHP really that bad? Don’t people learn how to code nicely so that others can read/understand them? Is it because of the IDE? Or is it because PHP is not in our universities’ curriculum so that people practice PHP in different ways (I noticed Java people or .NET people don’t have these problems since they are taught in the University)?
The last thing is, is PHP really that easy to learn that it becomes a disadvantage, where people can just abuse the language, in terms of how it is written?
iPhone 2.0 firmware jailbroken with PwnageTool: The Good, The Bad, and The Ugly
by Reza Muhammad on Jul.21, 2008, under Apple, Reviews, iPhone
Recently, the iPhone Dev Team just released a PwnageTool 2.0.1, an update to PwnageTool 2.0 that was released yesterday. This tool will activate, jailbreak, and unlock your iPhone with iPhone 2.0 firmware. My first generation iPhone was successfully upgraded to iPhone 2.0 firmware and now running quite smooth.
What Works and What Not
- Currently, PwnageTool will activate, jailbreak and unlock iPhone first generation even though you had used ZiPhone, iJailbreak, or other methods.
- It works on iPod Touch.
- It will activate, and jailbreak iPhone 3G, but it cannot unlock it yet. So, if you’re with carriers that is not in partnership with Apple, you cannot use your iPhone to send/receive calls or messages.
The Procedure
PwnageTool 2.0/2.0.1 will create a custom iPhone 2.0 firmware for you to upgrade/restore. It will read from the original 2.0 firmware from Apple, the 3.9 and 4.6 baseband, and then create a custom firmware. The new firmware will be located in your Desktop, by default. Finally, you can use iTunes to restore your iPhone with the firmware that is created by PwnageTool.
Pre-requisites
In order to create a new firmware by PwnageTool, you will need the following:
- iTunes 7.7 or higher
- An original iPhone 2.0 firmware from Apple. You can download them through iTunes. Choose “Download Only” as opposed to “Download and Install”
- 3.9 and 4.6 baseband files. You can download them here
- Last but not last, the PwageTool itself.
Upgrading Steps:
Make sure you remember where you save your 3.9 and 4.6 baseband files in case the PwnageTool cannot find the file.
- Start PwnageTool
- Choose which iPhone or iPhone touch you have.
- Select which firmware you want to use. By default, your downloaded firmware is located in ~/Library/iTunes/iPhone Software Updates
- Select the baseband files. If PwnageTool cannot find the files in your computer, it will ask if you want to search on the web. Choose “no”, as it will let you search the files on your computer manually.
- Pwnage Tool will ask whether you are a legit iPhone user. The difference is, if you choose yes, it will only jailbreak the iPhone. Choose “no” if you want to activate, jailbreak, and unlock your iPhone.
- PwnageTool will ask you to reset your phone into a DFU mode.
- When your phone is on DFU mode, press “alt” and click on Restore. Choose the firmware that PwnageTool created. By default, it is on your Desktop.
- When the restoring process finish, your phone will launch BootNeuter automatically. This will upgrade your baseband to 4.6. Your iPhone will reboot after it upgrades to 4.6 baseband.
- Voila, you can now happily running iPhone 2.0 firmware.
Conclusion
The Good
The are lots of new features that is added to iPhone 2.0 but I haven’t used all of them. Apple’s website has a summary of these features. But one thing that I like a lot is the “AppStore”. I can download and install alot of iPhone applications and games. Some other features I like is “Contact Search”. You can now search for your contacts rather than flicking it up and down (if you have lots of contacts on your phone, flicking takes time too). Oh and their “Email Management” is awesome. You can select multiple entries to delete/move emails as opposed to deleting/moving them one by one.
The Bad
If you have been on an unlock phone for quite some time, you must have heard about Installer.app. Well, Installer.app is not compatible with iPhone 2.0 yet. So there is only Cydia. Some people might like Cydia, but personally I’m not looking to install Python or OpenSSL and some sorts on my iPhone (command line tools like these are the area where Cydia shines).
The Ugly
Now, this is the first time I’ve used PwnageTool. Previously, I used iJailbreak to jailbreak and activate my phone. One thing that really distracts my eyes is they changed the apple logo during boot time to a pineapple. My first reaction was, “WTF?”. But then I got a jailbreak 2.0 for free, so I can’t really complain. I just have to live with a Pineapple’s iPhone, not Apple’s iPhone
My journey of finding an impressive web hosting: From DreamHost to ANHosting to WebFaction
by Reza Muhammad on Jul.18, 2008, under Miscellaneous
Over the years, I have used many web hosting services, and their quality services varied from poor to great. Since I’m from Indonesia, I’ve also tried Indonesian Web Hosting.
Generally speaking, Indonesian Web Hosting services are average. If you don’t care about about disk space limitations, or bandwidth usage, they are sufficient enough. Alot of Indonesian Web Hosting services offer less than 1GB disk space and 5GB – 100GB bandwidth usage.
However, I wanted more, not necessary need them though
. I like to think if I have multiple websites on the same host, I want to be able keep my web hosting plan. Now, I just started my own company (sixceed), and one of our service is building websites. If clients don’t want to have their own web hosting plan, I want my hosting plan to be able to handle those websites. SSH Access is also a plus for me. I hate having to fix my codes and then upload them through FTP. I’d rather fix it on the server using their built-in text editor. SSH can also be useful when running web applications that involve command line utility such as: Django, Ruby on Rails, and some others. Control panel is also what I’m looking for in a web host. I hate cPanel. I hate it a lot. I have the functionality of it, I hate the way it works, and I hate the way it looks. So, my criteria when looking for a web hosting service is flexibility for my sites to expand, ssh access, and a great control panel.
DreamHost
In the past, I have used DreamHost. Their web hosting service is great. It offers 500GB disk space, 5TB bandwidth usage, SSH access, and a great control panel. The price is not too bad either, starting from $5.95/month to $10.95/month depending how long you are willing to pay in advanced. My only gripe about DreamHost was they refused to setup my account. I had an account with them a few years back, then I terminated it because I didn’t intend on using it anymore. I signed up again a few months ago, but they said they couldn’t setup my account, and they refund the money. Pretty weird, huh? So, i searched for other web hosting and never look back.
ANHosting
ANHosting is owned by midPhase, and it has mixed reviews. It offers 500GB disk space, and 5TG bandwidth usage. The hosting package supports only 20 domains (DreamHost offers unlimited domains). SSH access is optional, meaning you have to pay more if you want to get the feature. So is Awstats. ANHosting’s default package include Webalizer, but you have to pay more to have Awstats installed on your web hosting plan. The hosting plan costs about $6.95/month. I also have a coupon code: ANHOST911 for 2 months free or SAVINGCENTER-93818 for 3 months free if you’re interested in joining ANHosting. Both of them are valid until December 31, 2008. ANHosting uses cPanel, which I do not like. During my time with ANHosting, it went pretty well, it’s just that whenever I look at the cPanel, it made me want to move to other hosting. And I did.
WebFaction
Currently, I host my domains on WebFaction. WebFaction offers four web hosting plans for you to choose. I went with the cheapest one since I had no idea how good they were. The disk space is a bummer, they only offer 10GB (it’s only about 2% worth of disk space than what DreamHost or WebFaction offer), and 600GB bandwith usage. positive side of WebFaction are they provide unlimited domains, unlimited MySQL databases, and SSH access. They even have sets of software collections like WordPress, Ruby on Rails, Django, Turbo Gears, Awstats, and more. You only need to choose what type of applications you want, and what domain will be using that application, then you’re website is built. Their screencasts made me signed up with WebFaction.
In summary, these are the advantages and disadvantages of each Web Hosting services I’ve used.
DreamHost
Advantages
- Very Affordable
- Great Control Panel
- Custom Scripts
- Very generous with disk space & bandwidth
Disadvantages
- Support sucks
- Different host for databases; a little slower to fetch data from database.
- Account activation rejected
ANHosting
Advantages
- Cheaper than DreamHost. Especially they have lots of available coupons
- Database relies on the same host
- One free domain for life
Disadvantages
- Limited flexibility (they use cPanel)
- Account activation is a hassle. It took me three days until I had to call them to ask for an account activation.
- Free domain might not be able to be transferred to other registrars.
WebFaction
Advantages
- They use cutting-edge software
- Great Control Panel
- Custom scripts
- Database relies on the same host
Disadvantages
- Disk space is limited
- Quite expensive
In summary, I’m very happy with my current Web Hosting company, WebFaction. I wish they will upgrade our disk space usage in the near future. Since they support WebDav, the addition of disk space will be beneficial
So, where do you host your websites?
A little introduction – This just started
by Reza Muhammad on Jul.14, 2008, under Miscellaneous
Hello,
It took me months to start on blogging again. After a few months of installing Wordpress, but does not write anything to it, I finally decided to start again.
Nowadays, I don’t really have a lot of free time, so new posts probably won’t be as frequent as I would like for it to happen.
The content of this blog will mostly related to technologies. I hate to talk about personal, as I think I should write them on a notebook instead of publishing on the Internet. Although I can’t blame people who write some kind of “diaries” on their blog. Hey, it’s theirs, not mine.
The theme of this blog is taken from WordPress Template, and they’re free
One of the reasons it took so long for me to start blogging again because I thought I would create a custom template for WordPress. But then it took so long to start creating new idea of a template. Besides, most of these free templates available online already suits my needs.
That’s about the little introduction from me. Hopefully there will be more posts soon