Unique Marketing, Guaranteed Results.

Ruby file trimming app

July 17th, 2009 by hals

We recently had an interesting experience with very large files. These were comma delimited files (.csv) containing hundreds of thousands of records, each with a dozen or so fields.

e.g.

rec1,field2,,,,,,xxx,fieldn,,,1,2,3,,,fieldx

rec2,field22,,,a,s,d,fieldmore,,,,etc

.

.

.

recn,field2n,,,,ring,,,,ring,1,2,,,hello?,,etc

While testing the setup, we had smaller files to work with. The goal was to create a new file containing only the first field from each record.

e.g.

rec1

rec2

.

.

.

recn

During testing this was easily done by opening the file in a spreadsheet program (such as OpenOffice), which would split the records on the comma delimiter and place each field in a different column. Then, it was easy to select the first column and write it out to the new file.

On switching to production files, we discovered that OpenOffice has a limit of 65k rows – a fraction of what we needed. We then tried some other spreadsheet programs, which produced the same results. We knew there was at least one spreadsheet program that would work, but it was not open source.

At this point the comment was made: “well, we ARE ruby developers …”

And that lead to the following simple solution to the problem at hand.

With a few lines of ruby code, the source files could be read in, line by line, split on the comma delimiter, and the first entry written out to the destination file.

So, when the usual tools just don’t work – remember that a new ruby tool might be just around the corner.

#!/usr/bin/ruby

#

#  trimfile.rb

#

require “rubygems”

require “ruby-debug”

class Trimfile

attr_accessor :fileName, :newFile

def initialize(fileName, newFile)

puts “\nSplit off first comma delimited item of each line.”

@fnam = fileName

if @fnam == nil then @fnam = “trimin.txt” end

@newfnam = newFile

if @newfnam == nil then @newfnam = “trimout.txt” end

linecount = 0

puts “\nFilenames – input: [email protected]}, output: [email protected]}”

aFile = File.new(@newfnam, “w”)

IO.foreach(@fnam) do |line|

aFile.puts line.split(‘,’)[0]

linecount += 1

end

aFile.close

puts “\nTotal lines: #{linecount}”

end

end

test = Trimfile.new(ARGV[0], ARGV[1])


Working with Git

June 19th, 2009 by Narshlob

This tutorial covers all the commands (hopefully) we’ll need for the projects we build here at PMA. If there’s anything that needs to be added to it, feel free to comment.

Starting with the basics, we’ll first cover retrieving a project:

git clone [repository]

This will get the currently active branch from the repository

Obviously you’ll want to do something with this newly retrieved working copy of the project. Let’s first create a branch for the new features/bug fixes we’ll be coding.

git checkout -b [newbranchname] origin

Ok, so we got a new branch. While we’re coding, it’s a good idea to commit tons of times to preserve the changes we’ve just made. Don’t worry about the log, we’ll make it pretty later. Just commit often.

git add [filename(s)]
git commit

If it’s a small change that doesn’t require much explanation, you can use these commands

git add *
git commit -m "The commit message"

Or, even shorter

git commit -a -m "The commit message"

You finished that feature so now it’s time to merge that branch with the master branch (or some other branch depending on what VCS (Version Control System) paradigm you/your team chose). First, you should make those hard-to-read commits less hard-to-read. Let’s rebase!
Please note that if you rebase after pushing to the repository, you will create problems for those pulling from that repository. Rebase changes the history of the project. Your teammates merges will not be fast-forward[able]. It won’t be pretty, trust me.

git rebase -i HEAD~[number of commits back]

You’ll now be looking at something similar to this:

pick ce86448 A random commit
pick a8564a9 Another random commit

How you order things in this editor will affect the order of the commits. Note that merge commits are not shown here. They aren’t editable.
Replacing “pick” with “edit” will allow you to edit the changes you made as well as the commit message.
After you’ve edited the files you wanted to edit, you can now

git add *

then

git commit --amend

and move on.

As I mentioned before, you have the opportunity to clean up the mess you made with all those many commits using the rebase option. Here’s how:

  1. Run the
    git rebase -i HEAD~[x]

    command from earlier

  2. Replace “pick” with “squash” on the commit you want to be combined with one exactly previous to it.
    pick ace72dd I squashed these commits. I'm cool.
    squash e99fd59 This commit will be sqaushed with the one above it
    pick d0770e8 commited again
    pick af845d0 I'm really committed
    

Pretty straight forward and easy. Everyone loves rebasing
If you want to know more about git-rebase, I recommend checking it out here.

Now, you’ve made all these changes and everything looks great. What are you gonna call this pretty new feature? Are you gonna tag it? I would..

git tag -a [fancy_feature] -m "A fancy message for a fancy feature"

If you happen to leave out the -m, git will open an editor and you’ll be able to add your fancy message there, just like with commit!
Read more about tags here.
One scenario for using tags could be that, within a project, one wants to keep track of versions. Each commit could be tagged with a version number like with bug fixes in some VCSs. If something goes wrong, it’s really simple to go back to a previous version using git rebase, as we’ve already shown.

You’ve squashed those ugly commits, changed the commit message(s), and tagged everything. Time to merge. Switch to the master branch (or whatever branch you’re wanting to merge with) and type this command which will merge [branchname] with the current branch:

git merge [branchname]

You’ll probably want to fix any conflicts and continue with the merge.
It’s now safe to delete [branchname] because all the changes from that branch are now on the current one.

git branch -d [branchname]

This next feature is pretty neat. Say you’ve done a bunch of changes that haven’t been committed yet and you realize you aren’t on a feature branch. Here’s what you do:

git stash
git stash branch [newbranchname]

This will stash away all uncommitted changes, create a new branch and check it out, then unstash all your stashed changes into that new branch. Awesome

Stash is also useful in scenarios where you don’t want to commit yet but you need to switch to a different branch and do something. You could stash the current changes using the above git stash command, do the needed changes, then switch back to the branch you were working on and use this command to unstash the changes:

git stash apply

It’s a good idea to check out the other things offered by git stash (git-stash)

To get this new branch into the origin repository, do:

git push origin [branchname]

To delete a branch from the origin repository, do:

git push origin :[branchname]

Don’t forget the colon!

Another scenario; your co-worker does some work on a feature and gets stuck. You don’t want to type on their computer cause yours is set up just the way you want it. Is there a solution to this quandary? Yeah. There is…
Tell them to push their changes then do this:

git fetch origin [remotebranchname]:[localbranchname]

You now have the branch they were working on locally and can modify to your hearts content.


Noteworthy Notes

There’s a difference between

git pull

and

git fetch

The difference is that “git pull” will run a “git fetch” then a “git merge” to merge the retrieved head into the current branch.

git log -p path/to/file.rb

This command will show the history of a specific file;

git blame path/to/file.rb

will go line by line in a file and give a short description + the name of the person that changed the line last (brilliant, actually)


From the Git manual

check it out
A few configuration variables (see git-config(1)) can make it easy to push both branches to your public tree. (See the section called “Setting up a public repository”.)

$ cat >> .git/config <
      [remote "mytree"]
           url =  master.kernel.org:/pub/scm/linux/kernel/git/aegl/linux-2.6.git
           push = release
           push = test
EOF

Then you can push both the test and release trees using git-push(1):

git push mytree

or push just one of the test and release branches using:

git push mytree test

or

git push mytree release

To rebase your current working tree to obtain the changes from the master tree,
Suppose that you create a branch “mywork” on a remote-tracking branch “origin”, and create some commits on top of it:

git checkout -b mywork origin
$vi file.txt
$ git commit
$ vi otherfile.txt
$ git commit


You have performed no merges into mywork, so it is just a simple linear sequence of patches on top of “origin”:
o–o–o $ git checkout mywork $ git rebase origin

This will remove each of your commits from mywork, temporarily saving them as patches (in a directory named “.git/rebase-apply”), update mywork to point at the latest version of origin, then apply each of the saved patches to the new mywork. The result will look like:
o–o–O–o–o–o $ git rebase –continue

and git will continue applying the rest of the patches.
At any point you may use the —abort option to abort this process and return mywork to the state it had before you started the rebase:


The commands

Here’s a list of all commands covered in this tutorial:
git-clone
git-checkout
git-add
git-commit
git-rebase
git-tag
git-merge
git-branch
git-stash
git-push
git-pull
git-fetch

Culerity and Celerity, JavaScript enabled testing in Cucumber

June 8th, 2009 by fugufish

As you may know, testing JavaScript inesnsive applications using Cucumber can be a pain. There are several ways to handle this; Selenium, Watir and the like. The easiest way I have found however is by using Celerity a jRuby API for htmlUnit, a fully functional headless browser that completely supports JavaScript, and you don’t have to serve your application on jRuby to use it!. I was able to get Celerity to play nice duruing Cucumber tests by doing the following: First, you will need of course jRuby. The Culerity gem will start up Celerity in the jRuby environment, and proxy the actual browser through it. Download jRuby and extract it to wherever you want it located. In my case I put it in /opt, and set your PATH accordingly.

export PATH=$HOME/jruby/bin:$PATH

Next install the Celerity gem in jRuby (we are using the github version rather than the ruby forge version, as it provides a later version):

jruby -S gem install jarib-celerity --source=http://gems.github.com

Now install the Culerity gem. This provides the interface between Celerity and your environment without forcing you to run in jRuby

 gem install langalex-culerity --source http://gems.github.com

Place this in your test environment:

# config/environments/test.rb

config.gem "langalex-culerity", :lib => false

I call :lib => false here to avoid loading the gem. This is done in the file generated by culerity. Finally remove features/steps/webrat_steps.rb as it will conflict with Culerity, and run:

script/generate culerity

Enjoy! Culerity should have very similar syntax to webrat, however keep in mind you may see some differences that you may need to adjust. essay writing service

Google Chrome Commercial

May 8th, 2009 by Brandon Buttars

Here is a sweet Google Chrome advertisement from YouTube. I wonder when Microsoft will come out with one for IE8. Ah oh. Here goes another Mac vs. Windows like fight.

If you don’t need to worry about deadlines and quality of your professor indifferent. Paper writers who work with us, you order with us are competent in all subjects: biology, geography, philosophy, mathematics, sociology, psychology, literature, art, history, and quality of scientific art that won’t leave . Paperell If you order with us are competent in all subjects: biology, geography, philosophy, mathematics, sociology, psychology, literature, art, history, and quality of scientific art that won’t leave your assignment. Our professional paper writing service will create a real piece of your assignment. Our professional paper writing service will create a .

Tutorial: How to Set up Ruby on Rails and MySQL on Mac OSX Leopard

April 7th, 2009 by Chuck Wood

Mac OSX has become extremely popular for Ruby on Rails development. Part of this is the inclusion of Ruby as part of the operating system on Mac OSX Leopard. Here is a quick tutorial on how to get Ruby on Rails and MySQL set up on your Mac OSX Leopard machine. In order to complete this tutorial, you need the Xcode tools installed. You can get them off of the applications disk that came with your mac or from http://developer.apple.com/TOOLS/xcode/.

Read the rest of this entry »

Skype Beta 2.8 – Screen Sharing

April 3rd, 2009 by Brandon Buttars

skype_screensharingI’ve always been a SKYPE fan and a user even though there seem to be a few haters out there. Most of the haters are haters cause they’ve had a bad internet connection when trying to use Skype.  Overall if you have a good connection it doesn’t get much clearer and better than SKYPE.  SKYPE is cheap, has some great plugins and functionality, and I’m sure a whole lot more uses that I even use it for.

Read the rest of this entry »

What? NetBeans 6.5.1 Can Now Recognize My Cucumber .feature Files!

April 2nd, 2009 by Chris Gunnels

After watching Ryan Bates’ screencast on Cucumber, I wanted to start creating my code first through BDD. I used Netbeans 6.5.1 to follow Ryan’s screencast and I found that NetBeans doesn’t recognize the .feature file that you create when you run a Cucumber test. I searched Google for about 3 hours for a plugin, but no such luck! I couldn’t believe it, I thought somebody had to of created a cukes plugin by now. Well, I decided to help the world and of course, myself, by creating a NetBeans plugin that will recognize the .feature files. Here’s a quick view of a .feature file after the plugin has been installed:

Screen Shot of Cucumber .feature

Read the rest of this entry »

20 Mac Apps You Should Install

April 1st, 2009 by Brandon Buttars

I know this list isn’t the same as everyone elses. I know we all have our preferences. I’m sure some of our other designers would have Dreamweaver on their list and some of the Programmers would have Net Beans, but this is my list. Leave you list in the comments below. I’ll make this short and sweet and just give a little bit of information about the different programs. I recommend going to their websites and learning even more of how they can help you. Download the FREE trials and take them for a spin.

Read the rest of this entry »

Copyright © 2005-2016 PMA Media Group. All Rights Reserved &nbsp