Monday, November 8, 2010

Some simple commands to setup your first git repository coming from a subversion background.

Coming from Subversion we're used to a primary repository that we can import, do editing and commit our changes to.

Git can do this, but it may be a little slow going until you read a few pages of docs. One concept that I had to understand was that every git project directory is a repository with a history of changes. Subversion only keeps revisions on the server.

To create your a primary git repository and another directory in your main dir:
  1. First make a bare git repository
    Create a directory to store this project. I used /srv/git/yourappname
  2. cd /srv/git/yourappname and run git init --bare
    This is important and it will act only as a repository. In other words without the --bare flag, a repository is created with the expectation that source files will be in this directory and will be editted.
  3. Go to your workspace directory and import, or in git terminology - clone the project
    cd ~/workspace
    git clone /srv/git/yourappname myapp
At this point you now have your project setup and you can start to edit files. Like any versioning control system, you will want to know how to add and commit your changes.
  1. cd ~/workspace/myapp
  2. Edit some files
  3. git add .
    (do this in myapp)
  4. git commit -a -m  'my commit'
Your own repository will have all the changes, they're committed, and you may continue to edit. If you want to revert or check history like you do with subversion, you will be able to. The next consideration is what if you want to now sync up with the original repository aka in svn syncing with the trunk. There's a nuance here that the first committer needs to do or you get a message like this:

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '/srv/git/yourappname'


Reading some of the docs, one would expect you would only need to type in git push to do this. The first time you need to do:
  1. git push origin master
    What this does is create the the master branch on the origin repository. I supposed this is like creating the trunk in svn.
  2. Subsequent pushes only require git push to update your code on master.
  3. Even if you delete ~/workspace/myapp and do another clone, you will again only need to do git push

Getting this to work with Eclipse

If you're using linux, there are a few gui's available gitg, gitk, git gui (That's the command 'git gui'). Some of us use eclipse as our primary ide, so it's convenient to have git integrated with our workflow. Here's how to set it up. Sorry I'm too lazy for screenshots. I'm using Eclipse Helios SR-1

  1. Make sure you have the git plugin.
  2. If you did the above steps you can add that git project to the Git Repository Interface.
  3. Select 'Add an existing repository to this view'
  4. Select /home/you/workspace/myapp
  5. The repository will appear in the interface, like a repository appears eclipse subclipse.
  6. Click on Working Directory and select 'Import Projects'
  7. Go through the wizard, select your project type and tada, that's all there is. You will now have a git managed project where you can commit your changes to. Like SVN, you go to TEAM and perform the operations tasks you want.
To push with eclipse, select master, master and add spec.

Monday, September 27, 2010

Eclipse Helios PDT and 50% CPU Usage

Running Windows XP, PDT 2.2 and Eclipse Helios All In One.

Eclipse would remain sluggish even after a clean install and waiting for a period of time for the build to finish.

One possible to having unaturally high CPU usage is:

Go to preference and turn off Semantic Highlighting.

As a side note another one is to turn off code folding.

Wednesday, January 27, 2010

mod_rails We're sorry, but something went wrong. message

After running rails by exec'ing script/server I installed mod_rails/Phusion to run rails through apache.

I was getting this message

"We're sorry, but something went wrong. message"

Not a lot of help, and I was uanble to find much in the logs and user manuals either.

Solution:

1) By default, mod_rails runs your app in production mode. When you're running rails through script/server it is in development mode.

2) You can either run rake db:migrate RAILS_ENV="production" which will build the production database from the values in database.yml

3) Or if you want to keep on using the dev database add this line to your apache virtual host



RailsEnv development

Thursday, January 21, 2010

cakephp mod_rewrite optimizations

A few people on the wordpress forums were discussing ways to improve the performance by editing the .htaccess file. Since WP and cakephp along with other PHP frameworks use a similar method of improving URLs, here's my attempt at improving cakephp's ./webroot/.htaccess

# http://www.phpdeveloper.org/news/13883 optimizations
RewriteEngine On

# images in these dirs tells mod_rewrite to stop processing
# '-' means to pass request unchanged. ie serve it immediately
RewriteRule ^(img|css|js)/(.*)\.(gif|jpe?g|png|ico)$ - [L,NC]
# these other files are served as is anywhere in ./webroot
RewriteRule \.(swf|css|js)$ - [L,NC]
# If File is a file or is a DIR then skip (1 rule) and serve the file
# (vs before where it was !-f AND !-d Not a file AND not a dir, two checks vs less than two if the first one matches)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [S=1]
# else rewrite the request
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

Tuesday, November 3, 2009

Adobe Flex Day 4 Embedding Font

On day four of the flex 3, Embedding fonts tutorial, it asks you to try and embed a font. After trying several methods to get my truetype font to rotate 45 degrees, I was unable to get the font appear. Only after using embedAsCFF attribute did it finally work. Set it to false and the Compact Font Format is ignored. This has something to do with how Adobe Flex 4 renders text.

[Embed(source='c:/windows/fonts/Consola.ttf', fontName="fontConsola",
mimeType="application/x-font-truetype", embedAsCFF="false")]

Tuesday, September 1, 2009

Analysis of several ratings / popularity algorithms

Here's a great article on the math behind some rating, ranking, popularity algorithms.

How to Build a Popularity Algorithm You can be Proud of

Wednesday, July 29, 2009

Fun with jQuery Form Validate Plugin

Things to know about the jQuery form validation plugin

http://bassistance.de/jquery-plugins/jquery-plugin-validation/

1. When dealing with input text you just need to add 'class' => 'required' to
<input type="text" 'class' => 'required' name="username"/>

2. Then add this line to get the form to validate
<script>
$().ready(function() {
$("#formValidate").validate();
});
</script>

3. What to do about checkboxes and how to position your error messages:

The form validate will auto insert your error messages when dealing with text fields and other input types. However when you're validating across multiple items like a checkbox you often want to position the error message in in a specific area.

eg.
<input type="text"><label class="error"> // Is fine

<input type="checkbox" name="data[]" value="1"><label class="error">
<input type="checkbox" name="data[]" value="1">

// The above error is out of place.

We can specify a label and use the for attribute to state where we want the error message to always show up.

<label class="error" for="data[]" >Pleased select at least two types of spam.</label> // insert this code anywhere on the page where you want the error message to appear

The problem arises when we
i) label.error { display: block; } // This causes the above label to always appear on first load of the page cause it's not hidden. Other inputs are fine as the validate 'auto-inserts' the errors.

ii) label.error { display: none; } // Next we try this style to make the explicit label.error disappear on first page load, but a side effect occurs. This style is inserted into ALL label.errors

style="display: inline"

Every label.error now loses their block style and we have a formatting problem

Solution:
1) http://groups.google.com/group/jquery-en/browse_thread/thread/2d87de7f74021f1a

<label for="data[]" class="error" style="display: none !important; clear: both; padding-bottom: 5px;">Pleased select at least two types of spam.</label> // This causes the label to be displayed hidden on the first load, and puts it on a new line cause of the clear: both;

2) OR wrap the label in a
<div class="errorCheckBoxBox"><label for="data[]" class="error"></label></div>

with the style
.errorCheckBox label{
display: none;
}



A better solution as it doesn't need additional style tags.