Posts tagged as:

ruby

When I started playing with Cassandra, I wound up writing part of an ORM to get what I needed from it.

I want to build actual projects with Rails, Ruby, or other technologies for my videos rather than just narrowly demonstrate a piece of technology. So, I’m bringing you up to speed with Sandra so that as I continue with the Twitter Clone, you’ll know what I’m using and why I’m adding things to it.

Sandra is available on Github at https://github.com/charlesmaxwood/sandra

Download 531.0 MB
Download (iPod & iPhone) 111.8 MB
Take the 2011 Readers Survey

{ 3 comments }

Marty is the organizer of the Boulder Ruby Users’ Group and Rocky Mountain Ruby Conference. He’s been programming Ruby since 2005.

Charley has been programming Ruby for about 6 or 7 years and doing IT for about 15 years. He got involved with Watir, which led him to Ruby.

The Rocky Mountain Ruby Conference is held in Boulder and includes several hikes and other activities not normally included in a conferences. I’ll also be speaking at the conference.

We went over the differences between the “Boulder Area” and the “Denver Area”. They’re 15-30 minutes apart, but culturally they’re pretty diverse. Boulder is small, but is becoming a startup and technology hub.

Both Marty and Charley have been talking about the food experience in Boulder and they’re setting up the conference to be a great food experience as well.

I asked if Marty and Charley view the community and regional conferences has changed after organizing a conference. Marty actually helped with Mountain West Ruby Conference. He also went into some of the challenges of picking a date and arranging the conference. He came up with the conference to get local people involved.

They also went into how they work around repeated talks and whether or not they want them. Repeaters are OK, but you want a unique program and conference.

We also discussed how talks are picked. How much weight the topics, speakers, and explanations get.

The discussion finally turned to the venue, which is the historic Boulder Theater. It sounds like a terrific way to run a conference with some of the options they have with setting up the experience. Much different from the hotel based conferences.

{ 0 comments }

I’m working on another Cassandra demo, but didn’t have time to finish, so I decided to show you Ruby Koans. It’s a very interesting test-driven approach to learning Ruby. I hope you enjoy it.

Download 52.5 MB
Download (iPod & iPhone) 31.1 MB
Take the 2011 Readers Survey

{ 1 comment }

You can get cassandra at cassandra.apache.org and the ruby gem by running:

gem install cassandra

I did run into a problem with the trift_client gem when installing. If you get a Load Error, run this.

sudo chmod 644 /usr/local/lib/ruby/gems/1.8/gems/thrift_client-0.6.3/lib/thrift_client/*.rb
sudo chmod 755 /usr/local/lib/ruby/gems/1.8/gems/thrift_client-0.6.3/lib/thrift_client/connection

Here are some of the Cassandra commands from the video:

#connects to the cassandra server using the Twitter keyspace
store = Cassandra.new(“Twitter”)

# create a new column family in the Twitter keyspace called Users
cf_def = CassandraThrift::CfDef.new(:keyspace => “Twitter”, :name => “Users”)
store.add_column_family(cf_def)

# add or create a row to the column family
store.insert(“Users”, “cmaxw”, {“name” => “Charles Max Wood”, “description” => “Awesome coder”})

# remove a column from a row
store.remove(“Users”, “cmaxw”, “description”)

Download 17.2 MB
Download (iPod & iPhone) 20.9 MB
Take the 2011 Readers Survey

{ 5 comments }

Here’s a list of several of the things we discussed:

To hire Josh’s guys, go to http://pgexperts.com.

Download 6.08 MB
Download (iPod & iPhone) 4.61 MB

{ 5 comments }

With the recent release of the Google Plus beta (ask me for an invite if you want one), I felt it appropriate to show a simple way to create a Like or +1 button for your Rails application. The app and concept is pretty simple, so I won’t worry about posting the code below.

Install:

gem 'make_flaggable', :git => 'git://github.com/cavneb/make_flaggable.git'
bundle install
rails generate make_flaggable
rake db:migrate

Models:

class Article < ActiveRecord::Base
  make_flaggable :like
end

class User < ActiveRecord::Base
  make_flagger
end

Links:

https://github.com/medihack/make_flaggable
https://github.com/cavneb/make_flaggable

Download 93.4 MB
Download (iPod & iPhone) 43.9 MB

{ 6 comments }

One of my clients had Pivotal Labs build them a website. After Pivotal Labs finished the project, they helped them find a developer to maintain it for them. I took over from him.

This last week, I had to dig deeply into the javascript code to make a piece of functionality I was modifying conform to what they had in other places on the site. What happened during the two days I worked on it was that I learned how they had things set up. Here are some of the things I found.

Jelly

Jelly provides you with an extension to the JQuery framework that allows you to trigger callbacks from your Rails controller. It’s exceptionally useful for things you need to occur when your server call is completed.

Namespaced Functions

The Pivotal Labs developers put a lot of things under a namespace named after the project. They further namespaced functions under namespaces corresponding to controllers and widgets, with some functions matching up with action names where widgets and other functionality could be implemented and initialized.

This is really handy in cases where you need specific functionality only is specific cases.

Javascript Loading at the end of the page

Finally, a method in the ApplicationHelper was provided that added all of the requisite javascript files to an array and then called javascript_include_tag on the array to include all of the files. This was done at the bottom of the page to avoid holding up the rest of the page loading while waiting for assets.

This also allowed for functions that required the DOM to be loaded to simply be called instead of using the JQuery $(function(){…}) callback style.

{ 1 comment }

Specification

  • Clicking a star rating turns on the stars to the left of the star I clicked.
  • Clicking a star submits the star rating.
  • When I refresh the page, the star ratings should be persistent.

We’ll be using Rails’ functions including:

  • form_for
  • hidden_field
  • Rails Helpers

We’ll be using jQuery functions including:

  • click
  • each
  • ajax

<code>
<% form_id = “movie_#{movie.id}_rating” %>
<%= form_for movie.ratings.last || movie.ratings.build, :html => {:id => form_id , :class => “star_rating_form”} do |f| %>
<%= f.hidden_field :movie_id %>
<%= f.hidden_field :stars, :id => form_id + “_stars” %>
<% end %>
<% (1..5).each do |i| %>
<li id=”<%= form_id %>_<%= i %>” data-stars=”<%= i %>” data-form-id=”<%= form_id %>”></li>
<% end %>
</code>

<code>
var set_stars = function(form_id, stars) {
for(i=1; i <= 5; i++){
if(i <= stars){
$(‘#’ + form_id + ‘_’ + i).addClass(“on”);
} else {
$(‘#’ + form_id + ‘_’ + i).removeClass(“on”);
}
}
}

$(function() {
$(‘.rating_star’).click(function() {
var star = $(this);
var form_id = star.attr(“data-form-id”);
var stars = star.attr(“data-stars”);

$(‘#’ + form_id + ‘_stars’).val(stars);

$.ajax({
type: “post”,
url: $(‘#’ + form_id).attr(‘action’),
data: $(‘#’ + form_id).serialize()
})
});

$(‘.star_rating_form’).each(function() {
var form_id = $(this).attr(‘id’);
set_stars(form_id, $(‘#’ + form_id + ‘_stars’).val());
});
});
</code>

{ 4 comments }

I’ve had two people ask me about freelancing within 1 day of each other. So, I’m going to give some advice. I also talked about finding freelance clients a few weeks ago in this episode.

Talk to other freelancers to see if they know people looking for work. It’s a great way to get advice as well as referrals.

Start talking to people in the community. I found all of my original clients directly or indirectly by talking to people I knew both locally and in the international community.

You should also go find a good accountant and have him advise you on setting money aside for taxes and structuring your business to save you on taxes. My accountant has probably saved me thousands of dollars on just this alone.

Your accountant will probably tell you this, but set up a business entity (usually an LLC or S-Corp) and get an EIN tax ID. It makes it much easier to write off expenses, avoid being dubbed an “employee” of your clients by the IRS, and makes keeping your books simpler since you will have to get a separate bank account.

The IRS looks for freelancers who are, for all intents and purposes, employees of their clients. To avoid this not only do you need your own business entity, but you also should have more than one client and use your own equipment when working for them.

Figure out what you need to charge and charge it. There are cheapskates out there who will be shocked that you want to charge them more than $20-30 per hour. Stick to your guns! Go to the Freelance Switch Hourly Rate Calculator and figure out what you need to charge to get by.

The problem you run into with the cheapskates is that these people are looking at Filipino and Indian developers on oDesk. Several of these developers are decent developers. A lot of them aren’t. Your potential client usually doesn’t know how to weed them out. So, if they insist that they’ll go overseas, let them.

Start a blog. Write about the stuff you’re doing. Someone will want something similar done. I’ve gotten a bunch of business off the Twitter Clone videos Eric did a while back because people are googling “Twitter clone.” I’ve also seen quite a bit of interest from my podcast, even though it’s geared much more toward programmers.

Finally, don’t be afraid to fire clients that don’t fit with your lifestyle or business. And don’t be afraid to raise your rates periodically when you need more time or money to make things work.

{ 1 comment }

Polymorphic associations are very simple, as are many-to-many associations. When you blend the two, it’s not nearly as simple. Since there isn’t a working build-in mechanism for many-to-many polymorphic associations.

Here’s a quick demo of what happens if you try to set up a traditional has_many :through association with a polymorphic association. I also show how to set things up so you can get the associated objects.

Download 101.3 MB
Download (iPod & iPhone) 45.5 MB

{ 9 comments }