rulururu

post Basic branching with git

September 5th, 2008

Filed under: Linux, Software, git — Brenton Alker @ 12:48

With 3 long-running tasks concurrently on my plate, I finally got around to learning branching in git, and it’s easy!

Until this week, I had managed to get by without learning to branch. I have looked previously but got a little lost. I often temporarily stored my work using “git-stash” to work on multiple things at once, but this is very limiting.

So, Here we go. My basic workflow now look like this.

Create a new branch (based on the HEAD of your current branch), and automatically switch to it:

git checkout -b my_branch

Then you can work within this branch as you always would.

Work, work, work…

git add files_i_have_edited.txt
git commit -m 'My changes'

Repeating this step until the task is complete. Then, to get the changes back into the master branch. Switch to it

git checkout master

And pull the changes from the branch

git pull . my_branch

Easy. No need to remember revision numbers where you branched, or which changed have already been merged. You can of course switch back to the branch and continue work with

git checkout my_branch

this “edit, commit, pull” cycle can continue until the task is complete. Then, once you’re satisfied you can delete the branch with

git branch -d my_branch

It’s still in the history of course, but no need to keep old branches around.

Hope that makes things clear to anyone else who was confused as I was by some of the overly complicated explanation of branching in git.

post New VPS Hosting

August 11th, 2008

Filed under: General — Brenton Alker @ 21:38

If you’re reading this then I have successfully migrated to my new VPS hosting on Slicehost.

post trim() Validation

July 15th, 2008

Filed under: Code, PHP — Brenton Alker @ 13:11

While writing a fairly standard sign-up/log-in system, I got to the point of validating the password to make sure it only contained acceptable characters. Now for me this would usually mean a regular expression. But, since this system wasn’t for me I decided to make the “valid characters” configurable, and generally the people configuring it won’t be able to write a regular expression.

My solution is to use php’s trim() (or more specifically rtrim(), but it doesn’t really matter) by passing the users input as the first argument, and the string of valid characters as the second; I should get an empty string in return. So the test, only allowing lowercase letters, becomes:

if ('' !== rtrim($input, 'abcdefghijklmnopqrstuvwxyz')) {
return false;
}

Simple! I don’t know how it compares speed wise with other methods, but it seems simple and effective and I can’t imagine it’s terribly slow unless your strings get larger.

I’m also not sure how it would handle multi-byte characters. But I don’t think it would be a problem if it doesn’t. Anyone got any insight?

ruldrurd
« Previous PageNext Page »
Powered by WordPress, Web Design by Laurentiu Piron
Entries (RSS) and Comments (RSS)