Thursday, October 28, 2010

iPhone - Cocos2D + Lua - Part 1

New Apple licensing finally allows some interpreted code to be executed on the iPhone ( For most people this is an indifferent matter of keeping Flash of the iPhone. On the other hand, great projects like Unity and Corona are effectively prevented from delivering awesome solutions to the mobile world, seeing how they both rely on internal interpreters.

Now that we are over that hump I am glad I can finally start integrating Lua in all my games. Lua ( is a fantastic lightweight language, intended to be embedded and cross platform. There is entire Google on the benefits of this combination but in summary game logic can be implemented outside of the graphic engine (Cocos2D - being my favorite). I've put together a quick demo of Cocos2D and Lua integration and I'll be working more on it as my game SnowRumble ( rises out of ashes.

This post is a little short because I have to get some work done, but as soon as I get a chance I will write up more and try and explain exactly what's going on.

Git your code here: :)


Monday, October 25, 2010

OS X + Dovecot + Postfix

Today I pointlessly spent 4 hours figuring out a local mail setup for Snow Leopard. This is all readily available in _every_ variation of Linux and it upset me greatly that I could not just send test email to myself. (NOTE: THIS IS NOT HOW YOU CONFIGURE A MAIL SERVER!!! THIS IS FOR DEV PURPOSES ONLY.)

Problem 1. Lack of imap server.

For that I just downloaded dovecot. Setup is pretty straight forward.
./configure --prefix=/usr/local/dovecot
make && make install
cp /usr/local/dovecot/share/doc/dovecot/example-config/dovecot.conf /usr/local/dovecot/etc/dovecot/

Make sure all the right permissions are there:

sudo dscl . -create /Users/_dovecot
sudo dscl . -create /Users/_dovecot UserShell /usr/bin/false
sudo dscl . -create /Users/_dovecot UniqueID 104
sudo dscl . -create /Users/_dovecot PrimaryGroupID 104
sudo dscl . -create /Users/_dovecot NFSHomeDirectory /var/empty
sudo dscl . -passwd /Users/_dovecot ''

Then I edited dovecot.conf and commented out these lines:
22: #!include conf.d/*.conf

Then added:
protocols = imap
ssl = no
default_login_user = _dovecot
default_internal_user = _dovecot
mail_location = mbox:/var/mail/folders/%u/:INBOX=/var/mail/%u
disable_plaintext_auth = no

passdb {
driver = pam
args = login

userdb {
driver = passwd

I seriously can't be bothered to setup an SSL for a localhost test mail account only but if you do need one Google is your friend.
Save and start dovecot via /usr/local/sbin/dovecot.
All your issues should be logged in /var/log/mail.log

Problem 2. Postfix.

Since my entry into Linux administration I loathed configuring mail servers. Thankfully you can do everything these days via Google Apps and some quick DNS changes. Dealing with spam, relay blocking, users setups, mail clients and etc was an ongoing pita. But to get started with OSX setup was pretty fast.

Create a file /etc/postfix/virtual if you don't have it.
Add something along these lines. All test emails that go to the domains are forwarded to your user account. It is a quick way of setting up multiple emails for testing and replace 'boris' with your osx username.

@whatever.localhost boris
@me.local boris

Generate a virtual.db via 'postmap virtual'
Save and close and start postfix: 'postfix start'

You can now setup your mail to point to localhost and everything should be working. Open terminal and type:
mail boris (or bee@me.local)
Don't forget the dot on a new line and change boris to your username. Everything should be delivered to your localhost account.

That should be it and if you have serious trouble is an awesome reference.

It is also possible to relay everything to Gmail but you need a valid hostname in your postfix (Gmail rejects localhost). I also do a lot of offline development so I don't always have Gmail there to do my email testing. Local setup + Git is an awesome way to stay off the grid and get some work done.


Friday, August 6, 2010

My build scripts

Because I get tired of trying to find them on Google.

./configure --prefix=/usr/local/php-5.2.5 --with-apxs2=/usr/local/apache2/bin/apxs --with-imap-ssl --with-xsl --enable-sockets --with-config-file-path=/etc --with-mysql=/usr/local/mysql --with-pgsql=/opt/PostgreSQL/8.3 --enable-calendar --with-imap --with-kerberos --with-gd --with-zlib--with-gd --with-bz2 --enable-mbstring --with-xmlrpc --enable-soap --with-freetype-dir=/usr/include/freetype2 --with-pdo-mysql=/usr/local/mysql --with-pdo-pgsql=/opt/PostgreSQL/8.3 --with-curl --with-mcrypt
make && make install

./configure --prefix=/usr/local/apache-2.2.17 --enable-cache --enable-proxy-ftp --enable-proxy-connect --enable-deflate --enable-ssl --enable-setenvif --enable-so --enable-cgi --enable-info --enable-rewrite --enable-speling --enable-usertrack --enable-deflate --enable-ssl --enable-mime-magic --enable-proxy --enable-proxy-http --with-mpm=prefork
ln -s /usr/local/apache-2.2.17 apache
make && make install

PostgreSQL 8.4:
./configure --prefix=/usr/local/postgresql-8.4.1
For 64bit (OSX Snow Leopard) use. If you don't psycopg2 doesn't work very well because 64bit python does not like 32bit postgres:
ARCH=x86_64 CFLAGS="-arch x86_64" LDFLAGS="-arch x86_64"
make && make install
Link /usr/local/pgsql to the installation directory.
Create postgres user and do:
su postgres
/usr/local/pgsql/bin/initdb -E UTF8 -D /usr/local/pgsql/data/
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ -l /usr/local/pgsq/data/postgresql.log start

To test:
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test

Shutdown and startup (as postgres):
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ stop
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ -l /usr/local/pgsq/data/postgresql.log start

Thursday, July 1, 2010

Magento Annoyances

Great e-Commerce but the degree of separation between presentation and logic is about 10 folders from root (if you are a developer). I use vim for everything and it can get pretty annoying to work on Magento. So I present to you my .bashrc snippet:

alias pd=pushd
alias pop=popd
function cs() { cd `dirs -l +$1`; }

Go to code directory and do 'pd .' and go to templates directory and do 'pd .'. This will add presentation and logic folder to a linux directory stack which you can access via 'cs 1' or 'cs 2' or 'cs N' N being whatever folder is in the stack.

Friday, April 9, 2010

File versioning the Git way

One of my favorite features of Git is the ability to create local repositories. Subversion can be a hassle for many multiple projects I go through. The repositories have to live on one central server which stays in constant sync with development. If you've ever tried to merge changes in Subversion with conflict code in repository no need to raise your hand. I can tell by the gray hairs who you are.

Additionally this will work with any file type and will not induce additional load on file server. All the versioning changes will be stored locally and if the need arises, can be pushed out to a central hosting server.

Getting started with Git on Mac/Linux is very easy:
Getting started with Git on Windows is not too bad:

The basics are:
1) Make directory (mkdir project1)
2) Initialize with git to get started (git init)
3) Add your files in there (git add .)
4) Commit changes (git commit -a -m 'My first git project'). Do this as many times as you want after changes.

There you go, code versioning locally without subversion. Home page for Git and a great source of documentation can be found here:

Sunday, January 10, 2010

CentOS 5, Python 2.5 and a first post

So everyone is doing it and so am I. Can't have street cred these days unless you have a blog, Facebook, iPhone app and a Twitter account. So my first one is on CentOS 5.4 and Python 2.4, yeah, also know as RedHat Enterprise Museum. The nice thing about running a proven package such as CentOS is that hardly ever something breaks and then I have more time to drink beer. But, today I ran into a problem of actually needing Python 2.5 and I dared the source install (note: I am good at this but see above reason why I like proven packages). So, without further ranting:
tar -xzvf
cd Python2-5
make altinstall (important to have 2.4 and 2.5 run side by side)
cd /usr/bin
mv python python_org
ln -s /usr/local/bin/python2.5 python

At this point I knowingly broke yum since it has a dependency on 2.4. So,
cd /usr/bin
mv yum yum_org
vi yum
and add this to top:
#!/usr/bin/python2.4 instead of #!/usr/bin/python

Then install setuptools for Python2.5 and you're done. When installing packages simply call easy_install-2.5 or relink easy_install.

This is not recommended unless you really know the consequences and how to deal with them. Most Linux distribution rely heavily on Python for several utilities so if they originally shipped with 2.4 there is probably a good reason for it. Most of my main utilities are build from proven scripts so I am not going to loose sleep over this one and for now the engine rolls on.