My Blog

21/04/2010

Try to understand .htaccess file in default symfony 1.4 project

Filed under: Công việc,Học tập — dinhnhy @ 5:29 pm

Options +FollowSymLinks +ExecCGI

  RewriteEngine On                      # <-- switch the rewrite engine on

  # uncomment the following line, if you are having trouble
  # getting no_script_name to work
  #RewriteBase /                        #  The resource requested in the HTTP request line, eg: "/index.html"

  # we skip all files with .something
  #RewriteCond %{REQUEST_URI} \..+$     # <-- if uri match  'dot "something"' at the end of string
  #RewriteCond %{REQUEST_URI} !\.html$  # <-- and if uri does not match 'dot &quot;html&quot;' at the end of string
  #RewriteRule .* - [L]                 # <-- rule: don't substitute any thing; this is the last rule, don't run any other rule

  # we check if the .html version is here (caching)
  RewriteRule ^$ index.html [QSA]       #  append to the URL instead of replacing it
  RewriteRule ^([^.]+)$ $1.html [QSA]   #  append to the URL instead of replacing it
                                        # %{REQUEST_FILENAME} -> The full local filesystem path to the file or script matching the request
  RewriteCond %{REQUEST_FILENAME} !-f   # <-- if the local file does not exist

  # no, so we redirect to our front web controller
  RewriteRule ^(.*)$ index.php [QSA,L]  #  append to the URL instead of replacing it; this is the last rule, don't run any other rule

19/03/2010

Install HirenBootCD and FreeNas on the same USB stick

Filed under: Công việc,Học tập — dinhnhy @ 12:20 pm

My purpose:
- Setup a USB stick to boot my FreeNAS (default)
- In the same USB stick, setup HirenBootCD so that I can troubleshoot (esp. in NTFS dics) should things went wrong

Note: most of steps below are performed in VirtualBox 3.1.4 run in my MBP

Steps:
1. Setup VirtualBox (if not already installed)
-> Create a new VM with 128MB, no HDD, and boot from CD
-> Set the USB filter to allow the USB stick to plug into the VM by default

2. Setup HirenBootCD on the usb stick: http://www.hiren.info/pages/bootcd-on-usb-disk
-> Get HirenBootCD.10.2 iso file
-> Mount the iso file to the VM and boot it, go to mini winXP mode
-> Format the USB stick (mine is 2GB)
-> Install Grub4Dos
-> Copy HBCD content and other files to USB
(-> Note that the Grub menu can be modified at this point to prevent the complicated mount command)
-> Shutdown the VM

3. Modify the USB partition and spare space for FreeNAS
-> Get FreeNAS iso file from sourceforge.net
-> Mount FreeNAS iso to the VM and boot it
-> When the boot process done, choose 6 to enter the shell
-> Get the current USB partition table: # fdisk -p /dev/da0 > fdisk.conf
Should note that the USB stick is now having only 1 partition
-> Modify fdisk.conf to prepare the partition table: # nano fdisk.conf
-> fdisk.conf content could be:

# /dev/da0
# geometry of the usb disk
g c245 h255 s63

# resize first partition (0x0c: FAT32) to 2056257 sectors (~1000MB)
p 1 0x0c 63 2056257

# set partition 1 active
a 1

# create second primary partition (0xa5: freebsd) start at 2056383 (beginning of cylinder) and size is 144522 sectors (~70MB)
p 2 0xa5 2056383 144522

-> Test this partition arrangement on the usb stick: # fdisk -f fdisk.conf -itv /dev/da0
-> Apply this partition arrangement to the usb stick: # fdisk -f fdisk.conf /dev/da0
-> Write FreeNAS embedded image to the partition just created: # gunzip -c /cf/FreeNAS-i386-embedded.gz | sudo dd of=/dev/da0s2 bs=512
-> the command above take a very long time to finish (about 30 mins for my case)

4. Mofify the default grub menu come with HirenBootCD
-> Mount the first partition of USB stick: # mount -t msdosfs /dev/da0s1 /mnt/test (remember to create folder /mnt/test first)
-> modify menu.lst: # nano /mnt/test/menu.lst
-> add this session anywhere you lile:

title FreeNAS 7.1.5024
root (hd0,1)
chainloader +1

Bravo, we are done! you now can test it

12/01/2010

Configure PHP5.3, Apache and MySQL on my MBP

Filed under: Công việc,Học tập — dinhnhy @ 2:53 pm

I followed most of step on this: http://kevchapman.co.uk/development/setting-up-apache-on-snow-leopard/

Below is copy from above steps for archiving purpose only:

sl-apache

I’ve upgraded both my Macs to Snow Leopard, and a few things have changed with the built in Apache webserver.

As a web developer it’s important for me to have a fully functional
development environment so the first thing I had to do with the new
install is get Apache set up and running as I need it.

This post shows how to set up PHP, mySql, Virtual Hosts & .htaccess

PHP

By default PHP is disabled so let’s turn that on.

In the finder navigate to the /etc folder, this houses all the files
we need to configure. This is a hidden system level folder so to access
it press “apple shift G” and type /etc.

go-to

Find the folder Apache 2 and open httpd.conf

This is the main config file for Apache, I use textMate to edit these files but you can use any text editor.

Go to line #115 and uncomment (remove the starting #) “LoadModule php5_module”

Save the file, you will be asked to enter your password.

After every change you make to the Apache or PHP config files you
will need to restart the webserver. This can be done in the Terminal
with “sudo apachectl graceful” or go to System Preferences and untick
then tick Web Sharing in the Sharing Pane.

Now PHP is running.

Error Messages when using date() function

PHP has been upgraded to V5.3 and the Snow Leopard version doesn’t
have a timezone set, this will give you errors when you use the date()
function. To fix this go back to the “/etc” folder and open
“PHP.ini.default”

Go to Line #997 and enter your timezone, here in the UK it’s Europe/London find your timezone.

Remove the semicolon and the line should read “date.timezone = yourtimezone”

Save this file as PHP.ini in the etc folder, restart the webserver and PHP is now all good to go.

mySQL

mySQL doesn’t come as standard on OS X so we need to install it
luckily this is nice and easy because we can get a dmg file. I choose
the 64bit version, head over and grab it scroll down to “Mac OS X (TAR packages) downloads” and choose “Mac OS X 10.5 (x86_64)”.

Open the dmg and run the installer. I also installed the prefPane,
double click the “MySQL.prefPane” It’s a good idea to use this as you
can use System Preferences to start/stop mySQL.

Setting the password

The mySQL install doesn’t set a password so we need to set it.

For this task we need to use the Terminal. Open Terminal located in
the “Applications/Utilities” folder and type
“/usr/local/mysql/bin/mysqladmin -u root password yourpassword” (where
yourpassword is the password you want.) hit enter and the password is
set.

terminal

Fixing the PHP socket

Before we can use mySQL we need to point PHP to the correct place.
Open the PHP.ini file as before and change line #1213 to
mysql.default_socket = /tmp/mysql.sock

Save this file and restart the server.

phpMyAdmin

I use phpMyAdmin to manage mySQL. So here’s how to do that.

Head over to the phpMyAdmin Site and download the latest version.

Unzip the downloaded file and place in either your Sites folder or
the servers root (Library/WebServer/Documents) I use the root as I
class this as a management tool and like to keep my Sites folder for
projects.

This needs configuring too. It does come with a documentation file
so you could go through that and set it up as you like. I keep mine
nice and simple and have it so I don’t need to log in each time.

Open “config.sample.inc.php” and add after “$i++” the lines:

$cfg['Servers'][$i]['user'] = 'root';

$cfg['Servers'][$i]['password'] = 'yourpassword';

$cfg['Servers'][$i]['auth_type'] = 'config';

Remove the line “$cfg['Servers'][$i]['auth_type'] = ‘cookie’;”

Save this file as config.inc.php.

In a browser go to “http://localhost/phpMyAdmin/” if you moved the
folder to the root as I did or if you placed into your Sites folder go
to “http://localhost/~yourusername/phpMyAdmin”.

Virtual Hosts

Open the “httpd.conf” and uncomment line #461 which reads “Include /private/etc/apache2/extra/httpd-vhosts.conf”, then save.

Now open “/etc/apache2/extra/httpd-vhost.conf”

I commented out each VirtualHost block and made my own underneath, You really do need this one:

<VirtualHost *:80>

DocumentRoot /Library/WebServer/Documents

ServerName localhost

</VirtualHost>

After this block you can add your own

<VirtualHost *:80>

DocumentRoot /Users/youruser/Sites/yoursitefolder

ServerName yoursitesname

</VirtualHost>

You will need to add a new VirtualHost block for each VirtualHost you wish to set up.

Save this file and we’re almost done. Open “/etc/hosts” and add
“127.0.0.1 yoursitename” you will need to add a new line for each
Virtual Host you have set up where “yoursitename” matches the name
chosen name in the VitrualHost block in the previous step.

Save this file and restart the webserver. Now in a browser type the
VirtualHost name and you will see the corresponding site. A link to “/”
within this site will take you to the root of that site as if it was on
a remote server.

.htaccess

Open the “httpd.conf” file and change line #210 to read “AllowOverride All”.

Open “/etc/Apache2/Users/youruser.conf”

Change AllowOverride to All

Add a new Directory Block

<Directory "/Users/youruser/Sites/*/">

Options Indexes MultiViews FollowSymLinks

</Directory>

Save and restart the server. Everything should now be all set up and you can use .htaccess and mod_rewrite.

Blogged with the Flock Browser

10/11/2009

Slideshow module (Gallery 2) hack to let it run in ULink

Filed under: 1 — dinhnhy @ 4:00 pm

Gallery 2, slideshow module hack to let it run in ULink portal:
(Application to: Gallery version = 2.2.2 core 1.2.0.4)

- I tried to install Slideshow plugin under the Site Admin > Plugins -> Get more Plugins and download the compactible SlideShow version (1.0.5.1)
- Dont know why the slideshow link is not appear in the album page. Maybe because it is a integration installation of Gallary into symfony
- Found a manual link as follow: http://domainname.com/gallery?g2_itemId=xxx&g2_view=slideshow.Slideshow
- Try it out. unfortunately it’s not running properly since there’s a JS error says that bCanBlend variable is not defined
- Hack the module: copy the JS content in Header.tpl into Slideshow.tpl
-> it works! ^_^
- But the default image size & timing is … strange. Found this: http://gallery.menalto.com/node/35992
- Modify the Slideshow.tpl accordingly
-> it works nicely ^_^

27/10/2009

Try to setup a “by-pass” proxy for iphone use

Filed under: 1 — dinhnhy @ 12:04 pm

Try to setup a “bypass firewall” proxy on a PC for iPhone use:

- Download the latest version of Privoxy from http://www.privoxy.org/
- Install it on the PC
- Edit the main configuration:

+ Section “listen-address”
-> Add in “listen-address :”

+ Section “Debugging” (for logging purpose)
-> Remove comment in these entry “debug 1″, “debug 1024″, “debug 4096″, “debug 8192″

+ For SOCKS proxy via SSH tunneling, modify this section “forward-socks4, forward-socks4a and forward-socks5″
-> Add in this entry: “forward-socks4 / 127.0.0.1:9999 .”
-> Add a tunnel in the SSH Putty: Dynamic, Source: 9999, Destination: empty

- Enable the application and start the Putty connection
- In iPhone, simply configure the HTTP proxy and point it to the correct IP & port

For more info about SSH tunnel, can ask Google or http://www.makeuseof.com/tag/how-to-tunnel-traffic-with-ssh/
For more info about Privoxy, refer to their documentation

19/10/2009

My journey “In Search of the Holy Grail”

Filed under: Công việc,Học tập — dinhnhy @ 11:41 am

“In Search of the Holy Grail” – http://www.alistapart.com/articles/holygrail
I found the article is very good for me to understand the whole idea about the “standard design” (aka Holy Grail in web design). And the best thing is it is build “On the shoulders of giants” ^_^

So after understanding the idea, I try to implement my own three column web layout for our website:

main.css

/* Start of modification to adjust the column width */
/* Center column: fluid + side paddings (20px) + topbot paddings (20px) */
/* Left column: 140px + side paddings (2px) */
/* Right column: 1px + side padding (0px) */
/* Body min-width: (LC fullwidth + CC side paddings)*2 + RC fullwidth */
body {
  min-width: 321px;          /* 2x(140+20) + 1 */
}

#banner {
  height: 80px;
}

#mainContainer {
  padding-left: 140px;      /* LC fullwidth */
  padding-right: 21px;      /* RC fullwidth + CC both side paddings */
  overflow: hidden;
}

#centerCol {
  padding: 10px 10px;       /* CC padding top/bottom & left/right */
  width: 100%;
}

#leftCol {
  width: 138px;             /* LC width */
  padding: 2px 1px 2px 1px; /* LC padding */
  right: 160px;             /* LC fullwidth + CC both side paddings */
  margin-left: -100%;
}

#rightCol {
  width: 1px;               /* RC width */
  padding: 0 0px;           /* RC padding */
  margin-right: -21px;      /* - RC fullwidth - CC right padding */
}

* html #leftCol {
  left: 1px;                /* RC fullwidth */
}

/* End of modification */


* html body {
  overflow: hidden;
}

#mainContainer .column {
  position: relative;
  float: left;
  padding-bottom: 10010px;  /* X + padding-bottom */
  margin-bottom: -10000px;  /* X */
}

#footer {
  clear: both;
  padding: 5px;
  position: relative;
}

* html #footer-wrapper {
  float: left;
  position: relative;
  width: 100%;
  padding-bottom: 10010px;
  margin-bottom: -10000px;
}

theme_gray.css

/* Color theme */
#banner {
  background: #eee url(/images/banner-MIS.jpg) no-repeat 0 -10px;
}

#mainContainer {
  background-color: #fff;
}

#centerCol {
  background-color: #fdd;
}

#leftCol {
  background-color: #eee;
}

#rightCol {
  /*background-color: #eee;*/
}

#footer {
  background-color: #ddd;
}

* html #footer-wrapper {
  background: #ddd;         /*** Same as body background ***/
}
/* End of color theme*/

A CSS Menu that fail my expectation

Filed under: Công việc,Học tập — dinhnhy @ 10:14 am

Recently I did a test to see if the CSS Menu at http://www.alistapart.com/articles/horizdropdowns/ can replace my currently JS Menu used for our website. After several tweaking and tuning, I finally got it works with the current website. However, it fails to convince me that I should replace the current JS menu with that. Even thought the setup for menu items is very neat (I like that), the event and effect of menu do not feel very friendly. I used transmenu for the current website since 3 years back and now it’s still very good. I think  I will stick with transmenu for a little bit longer.

Below is the detailed CSS & JS files I have got from that website (after several tweaks):

layout.html

<!-- ... -->
<!-- Begin of the main menu -->
<ul id="nav">
  <li><a href="#">Front page</a></li>
  <li class="subnav"><a href="/Admin">Administration</a>
    <ul>
      <li><a href="/User">Users Control Panel</a></li>
      <li><a href="/Role">Roles Control Panel</a></li>
      <li><a href="/Objects">Objects Control Panel</a></li>
      <li><a href="/Permission">Permissions Control Panel</a></li>
      <li><a href="/uiClrcache">Update Homepage</a></li>
    </ul>
  </li>
  <li class="subnav"><a href="#">Human Resource</a>
    <ul>
      <li><a href="/IDV">Internal Published Documents</a></li>
    </ul>
  </li>
  <li class="subnav"><a href="#">Sales &amp; Marketing</a>
    <ul>
      <li><a href="/SaleQuote2">Sales Quotation Database</a></li>
      <li><a href="/BusinessTarget">Business Target</a></li>
      <li><a href="/ShipMast">Shipping Master List</a></li>
    </ul>
  </li>
  <li class="subnav"><a href="#">Customer Service</a>
    <ul>
      <li><a href="/CsrQuote2">CSR Quotation</a></li>
    </ul>
  </li>
<!-- ... -->
</ul>

main_menu.css

/* Color theme */
#leftCol ul {
  border-bottom: 1px solid #ccc;
}

#leftCol ul li {
  background: #eee;
}

#leftCol ul li.subnav {
  background:#eee url(/ul2/images/nav/submenu.gif) no-repeat scroll 100% 5px;
}

#leftCol ul li a {
  color: #111;
  /*background: #fee; /* IE6 Bug */
  border: 1px solid #ccc;
}

#leftCol ul li a:hover {
  color: #E2144A;
  font-weight: bolder;
  /*background-color: #fee; /* */
} /* Hover Styles */

/* End of color theme */

#leftCol {
  font-size:0.9em; /* 11.7px */
}

#leftCol ul li {
  position: relative;
  margin-left: 0px;
}

/* Styles for Menu Items */
#leftCol ul li a {
  display: block;
  width: 96.5%; /**/
  /*background-color: #faa; /**/
  text-decoration: none;
  padding: 3px;
  border-bottom: 0;
}

/* Fix IE. Hide from IE Mac \*/
* html #leftCol ul li { float: left; height: 1%; }
* html #leftCol ul li a { height: 1%; }
/* End */

#leftCol ul {
  margin: 0;
  padding: 0;
  list-style: none;
  width: 138px; /* Width of Menu Items */
}

/* first sub level */
#leftCol li ul {
  position: absolute;
  left: 140px;
  top: 0;
  display: none;
  width: 190px;
}

/* second sub level */
#leftCol li ul li ul {
  left: 190px;
  width: 210px;
}

#leftCol li ul li ul li ul, /* third sub level */
#leftCol li ul li ul li ul li ul /* fourth sub level */
{
  left: 210px;
  width: 210px;
}

/* The magic for first level */
#leftCol li:hover ul,
#leftCol li.over ul { display: block; }

/* The magic for second level */
#leftCol li:hover ul li ul,
#leftCol li.over ul li ul { display: none; }
#leftCol li:hover ul li:hover ul,
#leftCol li.over ul li.over ul { display: block; }

/* The magic for third level */
#leftCol li:hover ul li:hover ul li ul,
#leftCol li.over ul li.over ul li ul { display: none; }
#leftCol li:hover ul li:hover ul li:hover ul,
#leftCol li.over ul li.over ul li.over ul { display: block; }

/* The magic for fourth level */
#leftCol li:hover ul li:hover ul li:hover ul li ul,
#leftCol li.over ul li.over ul li.over ul li ul { display: none; }
#leftCol li:hover ul li:hover ul li:hover ul li:hover ul,
#leftCol li.over ul li.over ul li.over ul li.over ul { display: block; }

main_menu.js

function attach_hover(navRoot, level)
{
  for (var i=0; i<navRoot.childNodes.length; i++)
  {
    var node = navRoot.childNodes[i];
    if (node.nodeName=="LI")
    {
      node.onmouseover=function() {
        this.className+=" over";
      };
      node.onmouseout=function() {
        this.className=this.className.replace(" over", "");
      };

      for (var j=0; j<node.childNodes.length; j++)
      {
        if (node.childNodes[j].nodeName=="UL")
        {
          attach_hover(node.childNodes[j], level+1);
        }
      }
    }
  }
}

startList = function() {
  if (document.all&&document.getElementById)
  {
    navRoot = document.getElementById("nav");
    if (navRoot && (navRoot.nodeName=="UL"))
    {
      attach_hover(navRoot, 1);
    }
  }
};

window.onload=startList;

07/09/2009

Backup & store batch scripts with PortableApps and 7z

Filed under: Công việc,Học tập — dinhnhy @ 4:43 pm

Below are just an easy way to compress & extract PortableApps using 7z utilities:

compressAllApps.bat

@SET _apps_path=..\PortableApps
@SET _arch_path=..\Compressed

@>%0.log    ECHO Update and compress all apps in %_apps_path%
@>>%0.log ECHO ======================================================
@>>%0.log ECHO.
@>>%0.log ECHO.

@(FOR /F "delims==" %%i IN ('dir /b %%_apps_path%%\*') DO @(
	ECHO Processing %%i
	7-Zip\7z.exe u "%_arch_path%\%%i.7z" "%_apps_path%\%%i" -ms=off
	ECHO ======================================================
	ECHO.
) ) 1>>%0.log 2>&1

@>>%0.log ECHO ======================================================
@>>%0.log ECHO Execution finished.

extractAllApps.bat

@SETLOCAL ENABLEDELAYEDEXPANSION
@SET _apps_path=..\PortableApps
@SET _arch_path=..\Compressed

@>%0.log    ECHO Extract all apps in %_arch_path%
@>>%0.log ECHO ======================================================
@>>%0.log ECHO.
@>>%0.log ECHO.

@(FOR /F "delims==" %%i IN ('dir /b %%_arch_path%%\*') DO @(
	SET tempVar=%%i
	ECHO Processing !tempVar!
	IF "!tempVar:~-3!"==".7z" (
		IF NOT EXIST "%_apps_path%\!tempVar:~0,-3!" (
			7-Zip\7z.exe x "%_arch_path%\!tempVar!" -o"%_apps_path%" 
		)
	)
	ECHO ======================================================
	ECHO.
) ) 1>>%0.log 2>&1

@>>%0.log ECHO ======================================================
@>>%0.log ECHO Execution finished.
@ENDLOCAL

24/08/2009

SIFT & VSIFT in Microsoft Dinamics NAV

Filed under: Công việc,Học tập — dinhnhy @ 2:24 pm

After countless of time searching the Internet, finally I answer the question “How Navision (4.0 SP2 & 5.0 SP1) mantain the FlowField calculation in SQL Server?”.

There’s not must information provided in the “bible” Application Designer’s Guide come with Navision CD. The answer is SIFT (Sum Index Flow Technology) for Navision below 5.0 SP1 and VSIFT (or Indexed Views) for Nav 5.0 SP1.

More information can be read here: http://dynamicsuser.net/blogs/mark_brummel/archive/2009/04/12/vsift-the-day-after.aspx

How do I install zend Server CE (ZendServer-CE-php-5.2.10-4.0.5-Windows_x86)

Filed under: Công việc,Học tập — dinhnhy @ 1:48 pm

How do I install zend Server CE (ZendServer-CE-php-5.2.10-4.0.5-Windows_x86)
-> Download from file:///D:/Users/nguyen%20le/Downloads/Chrome/ZendServer-CE-php-5.2.10-4.0.5-Windows_x86.exe
-> Install Type: Custom
-> Check all extensions for PHP & Zend
-> Check phpMyAdmin, MySQL Server & MSSQL Native Client
-> Install an Apache 2.2.12 WS
-> Destination: D:\Users\nguyen le\Tools\Zend
-> Apache port: 8080

Next Page »

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.