Archive for the ‘Uncategorized’ Category

Taking Snapshot of Google Map

Wednesday, August 29th, 2007

My boss is great fan of google map geographical visitors of our website, and he wants to show it in the main page. I was bit worried about the delay caused by the javascript making the overlay on the map. So I decided to taking a snapshot of it and use it for the main page.

First, I didn’t want inventing a wheel, so I tried to use webkit2png. Obviously, I was asked to install PyObjcC, but it wasn’t easy to install in my machine (WebKit problem). I’ve installed Safari beta 3, and some people blamed it as it pretends having WebKit SDK while it doesn’t. But changing symbolic links for WebKit SDK didn’t work.

So, I’ve shifted my gear and thought. What if using AppleScript and Paparazzi? I’m totally newbie in AppleScript world, so I’ve looked for what others have done. Galarrhea is an AppleScript making a snapshot of each of your Ma.gnolia and del.icio.us bookmarks using Paparazzi.

Base of what he have done, I was able to capture the geographical visitor page, and I used ImageMagick to cut off the google map region from the big-fat-page image. And I also used scp to upload the snapshot to the server. I considered exploiting Transmit with AppleScript, but my server is over the firewall, and I need to use SSH Tunneling to go through it directly, so I decided to stick with a shell script.

Here’s the script. geovisitors.scpt

Compiling CHARMM c33a1 on Mac OS X

Wednesday, August 15th, 2007

Compiling CHARMM on Mac OS X is supposed to be easy; The install script has identifier osx. However, I encountered numerous problems while I tried to compile it. So here I leave some comment how I worked around the problems. Probably, I suspect some of the problems are because of my group is using little modified version of CHARMM, so this may not same for everyone.

  1. pre-requisites:

  2. ./install.com osx large ifort nolog

  3. The first error message that I’ve encountered is:

    eutil.f: In subroutine ‘enerin’:
    eutil.f:2234:
    ceterm(XMAP) = ‘XMAP’
    ^
    Invalid declaration of or reference to symbol `xmap’ at (^) [initially seen at (^)]
    make: *** [/Users/sunhwan/Programs/c33a1/lib/osx/energy.a(eutil.o)] Error 1

    The workaround for this error is putting XRAYMAP to the file build/osx/pref.dat.

  4. The second one is:

    /Users/sunhwan/Programs/c33a1/source/machdep/cstuff.c:30:23: error: bits/time.h: No such file or directory
    /Users/sunhwan/Programs/c33a1/source/machdep/cstuff.c: In function ‘fmalloc_’:
    /Users/sunhwan/Programs/c33a1/source/machdep/cstuff.c:104: warning: conflicting types for built-in function ‘malloc’
    /Users/sunhwan/Programs/c33a1/source/machdep/cstuff.c: In function ‘fsystem_’:
    /Users/sunhwan/Programs/c33a1/source/machdep/cstuff.c:145: warning: incompatible implicit declaration of built-in function ‘exit’
    /Users/sunhwan/Programs/c33a1/source/machdep/cstuff.c: In function ‘fputenv_’:
    /Users/sunhwan/Programs/c33a1/source/machdep/cstuff.c:278: warning: incompatible implicit declaration of built-in function ‘exit’

    The workaround: edit the file source/machdep/cstuff.c line 30, from bits/time.h to time.h

  5. Lastly:

    /usr/bin/ld: Undefined symbols:
    xraymap0
    collect2: ld returned 1 exit status

    Workaround: replace build/osx/energy.mk to energy.txt.

Again: I am suspecting the first and the last errors are related with my source, others may not suffer from them.

Accessing Database in Unit Test with sfDoctrine

Monday, July 30th, 2007

Whew! After made autoloading sfDoctrine available last week, I was thinking accessing database or pretending it (for test purpose) is surely easy. However, it wasn’t easy at all. So, here is the record of my struggle and, hopefully, if some knows (has) a better idea, or can point out my wrong, let me know it.

Here’s my idea. I am making a simple cashflow tracking app., so it has cashflow model and account model. If a user entered ‘Walmart’ as the paid account of the transaction, cashflow model would, first, search whether an account titled of ‘Walmart’ exists, and set the paid account id as the id of the account, if it exists. If no record titled of ‘Walmart’ were found, it would create a record titled of ‘Walmart’ and return the id of the record, and this id will be set as the account id of the cashflow. Unit test can validate this process by setting the account id of cashflow object with ‘Walmart’ and ‘Target’, while the account table has the record of only ‘Walmart.’

  1. So, first of all, I thought making a mock object that pretends as a doctrine record, and sfDoctrine has a Mock adapter. And since the Symfony book gave me an impression that propel objects can be filled with fixture data (Chapter 15. Unit and Functional Testing - Accessing Database), I thought it can be done with sfDoctrine as well. But making database connection using Mock adapter and filling the database with the fixture were not easy and I was able to make it after trace down to the Symfony and sfDoctrine execution chains and modification of the source code.

    • I wasn’t able to establish a Mock connection before made some changes in sfDoctrine code
    • I wasn’t able to fill the object with fixture data before made some changes in sfDoctrine code
    • I couldn’t use the filled data to query
  2. So I decided to have a test database. That will make things easier. One other problem that I had here was, if I load data from an array or a fixture, and query the database in the same file, it seems it couldn’t fetch the result. I still don’t know why, I’ll appreciate if anyone can give me a clear idea why. My workaround was putting the database manager initialization call prior to the database initialization.

    Here is my example unit test code. Hope this can help anyone desperate..

<?
include(dirname(__FILE__).'/../bootstrap/unit.php');
require_once($sf_symfony_lib_dir.'/util/sfCore.class.php');

define('SF_APP',         'track');
define('SF_ENVIRONMENT', 'test');
define('SF_DEBUG',       true);

sfCore::initSimpleAutoload(array(
    SF_ROOT_DIR."/lib/model",
    SF_ROOT_DIR."/apps/".SF_APP."/lib",
    SF_ROOT_DIR."/plugins/sfDoctrinePlugin",
    $sf_symfony_lib_dir,
));

require_once(SF_ROOT_DIR.'/apps/track/config/config.php');

$t = new lime_test(3, new lime_output_color());

$t->diag('cashflow test');
$t->is('Paid_account_id', ucfirst('paid_account_id'), 'filter method uses ucfirst function to transform fieldname');
$t->is('Payable_account_id', ucfirst('payable_account_id'), 'filter method uses ucfirst function to transform fieldname');


//
$t->diag('make database connection and fill the fixtures');

$manager = new sfDatabaseManager();
$manager->initialize();

$database = new sfDoctrineDatabase();
$database->initialize(array (
  'dsn' => 'mysql://root:root@localhost/symfony_cashflow_test',
), '');

$data = new sfDoctrineData();
$data->setDeleteCurrentData(true);
$fixtures = array(
  'Account' => array(
    '1' => array(
      'title' => 'Walmart',
    ),
  ),
);
$data->loadDataFromArray($fixtures);


//
$t->diag('test adding account when registering cashflow');

$cashflow = new Cashflow();
$cashflow->set('paid_account_id', 'Walmart');
$account = Doctrine_Query::create()->from('Account')->where('title = ?', 'Walmart')->limit(1)->execute()->getFirst();
$t->is($account->id, $cashflow->paid_account_id, 'set account with account title will set the value with account\'s id');

$t->diag('test end');

IE z-index Bug

Saturday, July 28th, 2007

Again, stupid IE bug made me spent another hour or two to workaround this css bug. The problem is IE seems to have independent z-index stack for a relatively positioned elements. Visit here using IE and FF, to see what the problem is. I am using Safari in my Mac to develop a website, and I don’t really have any problem with FF, but I usually spend two-three hours to fix stupid css mis-behavior in IE. (sigh)

Anyway, to workaround this problem, every relatively positioned elements should have defined z-index. And here are other resources that I’ve used to find it.

The Beauty of Korean Language

Wednesday, July 18th, 2007

iPhone Korean Input Manager

Currently, English is the only language that you can type in the iPhone, though it seems like people don’t have any problem with navigating through multi-language websites. One of Korean iPhone user came up with an iPhone app. that let you type Korean language. After typing some letters, it will send the string to the Google and Naver (Korean search engine) search page or to the Mail app. It is really amazing that he was able to create a screen keyboard on a webpage, so that he may able to expand it and implement different shapes of screen keyboard easily.

Moreover, I also amazed that how small number of keys were needed to represent any letters in Korean. Here only needed 13 buttons. Korean letters were designed to have a small basis, and those basis are added up together to represent a letter. For example, ‘ㅏ’ (sounds like ‘a’) is made by adding two basis, ‘l’ (sounds like ‘i’) and ‘⋄’ (pronunciation depends on where it comes. If it comes later than the other component, it sounds like ‘a’, or if it comes before the other components, it sounds like ‘er’), and ‘가’ (sounds like ‘ga’) is made by adding two letter, ‘ㄱ’ and ‘ㅏ’. In other words, we can split a letter ‘가’ into three pieces of ‘ㄱ’ + ‘ㅣ’ + ‘⋄’. The two horizontal and vertical bars and the dot in the middle row is the very basic basis. Those basis represents the ground (ㅡ), men (ㅣ), and the sun (⋄), respectively. You may noticed that the first and the third row is same. So he may able to reduce the last row, and that would make the buttons even smaller!

Having own language system is something very proud of. And having a beautiful language system is something more than that.

Autoloading sfDoctrin in Symfony Testing Framework

Wednesday, July 18th, 2007

Well.. The unit testing part in symfony documentation is bit disappointing to me. I expected more unit test practice to come, but it spent most of time to explain functional testing. It is still vague how to write a unit test in symfony after reading the part. Actually I am still skeptical about browser functional testing. Maybe because I am not writing professional massive web site, though.

Anyway, like I said, I am interested in unit testing, particularly of a model. My model is based on the sfDoctrine plugin, and it was not easy to turn the autoloading on. So here is how I set the sfDoctrine into the autoloading list.

<?
include(dirname(__FILE__).'/../bootstrap/unit.php');
require_once($sf_symfony_lib_dir.'/util/sfCore.class.php');
sfCore::initSimpleAutoload(array(
    SF_ROOT_DIR."/lib/model",
    SF_ROOT_DIR."/plugins/sfDoctrinePlugin",
    $sf_symfony_lib_dir,
));

define('SF_APP',         'yourapp');
#define('SF_ENVIRONMENT', 'test');
#define('SF_DEBUG',       false);

require_once(SF_ROOT_DIR.'/apps/track/config/config.php');

$data = new sfDatabaseManager();
$data->initialize();

$model = new YourModel();

I’m using symfony 1.0.5 and sfDoctrine is checked out a couple of weeks ago.

Managing Development and Production Directories Using rsync

Friday, July 13th, 2007

In my project, I am having development and production directories in the same machine. I know having subversion and would be better, though I am still not quite comfortable with it. Anyway, they are messy, and have been messy for about a year.

Now I got tired of updating modified files by hand every time, and looked up a software that can handle my need. rsync seems like tiny little tool that I was looking for. I referred two website rsync man page and rsync examples, and let the rsync synchronizes my development and production directories, and backs up both of them in remote server in incremental manner.

So, here is the scheme. I have two directory; devel and www, which is development and production directories, respectively.

  1. I’ve set aliases to do rsync from the development directory to the production directories, and from the production to the development directories.

    alias rsync-devel=’rsync -Cavuzb –filter=’\”dir-merge www/.rsync-filter’\” www/ devel/’
    alias rsync-devel-l=’rsync -Cavuzb -n –filter=’\”dir-merge www/.rsync-filter’\” www/ devel/’
    alias rsync-www=’rsync -Cavuzb –filter=’\”dir-merge devel/.rsync-filter’\” devel/ www/’
    alias rsync-www-l=’rsync -Cavuzb -n –filter=’\”dir-merge devel/.rsync-filter’\” devel/ www/’

    • -a : archives files, means preserve permission, owner, and etc.
    • -v : verbose
    • -u : update, don’t copy if file in destination is newer
    • -z : compress
    • -C : cvs style exclusion, means excludes patterns below

      CS SCCS CVS CVS.adm RCSLOG cvslog.* tags TAGS .make.state .nse_depinfo ~ # .#* ,* _$* $ *.old *.bak *.BAK *.orig *.rej .del- *.a *.olb *.o *.obj *.so *.exe *.Z *.elc *.ln core .svn/

    • -b : leaves backup
    • -n : displays list of files that will be updated (does not update)
  2. This is my filter file. rsync filter

  3. Between the production machine and the remote server, I’ve copied shell script from rsync example website and slightly modified to meet my needs. Since I wish I could back up devel and www directory independently, I would like to call the script as script.sh devel to back up devel directory, script.sh www to back up www directory. So here is the modification. remote rsync

Installing Symfony in Mac with MAMP

Thursday, July 12th, 2007

I installed XAMPP for Mac OS X and installed symfony, and tried to run my project. Then I found XAMPP does not have PDO_MYSQL support. So I tried to install it by pecl install pdo_mysql, however, I was ended up in some problem that I couldn’t fix easily. The first impression was that the path for the php header file was not correct. After a struggle to make it correct, I switched to MAMP (http://www.mamp.info/) and find the peace of mind.

  1. Install MAMP

    1. Put these directories in you path
    • /Applications/MAMP/bin/php5/bin
      1. Most files that will be frequently used is in /Applications/MAMP/bin/
  2. Install Symfony using peardev (to bypass the memory limit exceeding problem)

    1. sudo /Applications/MAMP/bin/php5/bin/peardev channel-discover pear.sy mfony-project.com
    2. sudo /Applications/MAMP/bin/php5/bin/peardev install symfony/symfony
  3. Setting up Symfony

    1. Edit apache configuration file at /Applications/MAMP/conf/apache/httpd.conf
    2. Refer Symfony Documentation Chapter 3
    3. An example virtual host configuration

        <VirtualHost *:80>
          ServerName myapp.example.com
          DocumentRoot "/home/steve/myproject/web"
          DirectoryIndex index.php
          Alias /sf /Applications/MAMP/bin/php5/lib/php/data/symfony/web/sf
          <Directory "/Applications/MAMP/bin/php5/lib/php/data/symfony/web/sf">
            AllowOverride All
            Allow from All
          </Directory>
          <Directory "/home/steve/myproject/web">
            AllowOverride All
            Allow from All
          </Directory>
        </VirtualHost>
    

    1. set $sf_symfony_lib_dir as /Applications/MAMP/bin/php5/lib/php/symfony
    2. set $sf_symfony_data_dir as /Applications/MAMP/bin/php5/lib/php/data/symfony
    3. Checkout Symfony project
    4. Let svn to ignore cache and log directory

        chmod 777 cache log
        svn propedit svn:ignore cache
        svn propedit svn:ignore log
    
  1. I’m using Doctrine as my ORM layer, and PHP CLI seems not working correctly, yet the web was okay. symfony doctrine-insert-sql complained that “doctrine couldn’t locate mysql driver.” It turned out, Mac OS X has php binary in the /usr/bin/ directory. So I put the MAMP bin directory in the path prior to existed path variable.

ffmpeg tips

Saturday, July 7th, 2007

Here are a couple of tips using ffmpeg.

Converting movie to flv:

ffmpeg -i input -f flv -sameq output

Taking a snapshot of a movie:

ffmpeg -i input -f mjpeg -ss 0:10:00 -vframe 1 output

  • -sameq: turn on VBR
  • -ss: seek to 10 seconds after the beginning
  • -vframe: number of frames to take

When Symfony upgrade fails using PEAR

Tuesday, March 20th, 2007

Problem

I noticed my PEAR registry had corrupted, when I tried to upgrade symfony version from 1.0.0 beta 4 to 1.0.1. pear upgrade symfony/symfony kept spit out ERROR: pear.symfony-project.com/symfony not installed, even though it is installed. Also pear list symfony/symfony didn’t work.

Solution

PEAR registries are under the directory of $PEAR_HOMEDIR/.registry/. In case of symfony, the registry file is, .channel.pear.symfony-project.com/symfony.reg, so I removed the file and re-run the upgrade script.

From the PEAR bugtrack system, for some reason, if PEAR complains that the allowed memory has been exhausted, peardev is the alternative. It is disabled memory_limit.