Practical Web Programming

Tuesday, March 25, 2014

Git: Merge Develop Branch to Master

Normally when developing, you would make your changes in develop branch and when releasing, merge develop to master branch. Here's the best way to do it:

$ git checkout master                 # make sure you are in master branch
$ git fetch                                  # download commit from remote branch
$ git reset --hard origin/master     # removes changes/commits in local master branch (if any)
$ git merge origin/develop           # merge remote develop to master (the current branch)
$ git push origin master              # push the changes to remote repo

Git: Delete All Local Branches That Were Already Merged to Master

In Git, to clean up your local repository of already merged branches to master (aka pruning), run this command:

$  git checkout master
$  git branch --merged master | grep -v "\* master" | xargs -n 1 git branch -d

This is three commands in one, made possible via pipes ("|").

1) git branch --merged master     # list all the branches that have been merged to master
2) grep -v "\* master"                 # select all the branches that does not match "* master"
3) xargs -n 1 git branch -d          # execute git branch -d with 1 parameter - the branches that was returned by #2

Wednesday, March 05, 2014

Fix Repeating Content in Email using Handlebars Template

Recently, I reformat our email template and ran into an issue wherein the middle part of the email body is re-populating at the end of the body resulting in duplicate content. The email template was created using Handlebars. My suspect is the character encoding of the production mysql database. But what ever I do (copy the prod DB locally with same encoding, etc), I could not replicate it in my local machine.

Removing the non-printable characters before rendering the content with template fixed it. Here's how I did it.

$cleaned_text = preg_replace('/[\x00-\x1F\x80-\xFF]/', ' ', $text_with_non_printable_chars);

/[\x00-\x1F\x80-\xFF]/ are characters from 0-31, 128-255 in ASCII character code.

Recent Post