All posts by admin

Moving my blog from Blogger to WordPress

Hi folks…. I’m in the process of moving my blog posts from Blogger.com to here at mattslay.com. The process should be finished by December 1, 2010, so give me a few more days.

Update (only a few hours later): Well, I’m done already. I found this very helpful post on the web for Moving Your Blog from Blogger to WordPress. Check it out if you decide to make the switch.

For now, you can still reach the old blog at http://therealmattslay.blogspot.com

Rails Authorization and Authentication

Some developers confuse the terms Authentication and Authorization. At first, I also kind of lumped them both in the same bucket. Eventually, I figured out the differences, and wanted to address the issue here to help clarify things a bit.
Definitions:

User *authentication* is looking them up in the Users database to ensure they have an account in your system.

User *authorization* is a system of determining what areas of your app the User can access once they are authenticated into the site. 

I use two popular Rails gems that pretty much give you a drop-in solution for authentication and authorization. Devise is a Rails gem for User Authentication, and CanCan (by Ryan Bates of RailsCasts fame) is for User Authentication.
I ran across these great articles on another blog that describes using Rails and CanCan together:

Article 1: Getting Started with Devise and CanCan The article includes very detailed steps and code samples for both Devise and CanCan. 

Article 2: Devise and CanCan – Restful Resources for Administrators

You can also read my blog post about Getting started with Devise, which includes lots of other helpful Devise links to get you started.

WPF Hole Patterns

After I got my head above water in C# and WPF back in 2008, I created and published a sample of my first C# work that used the WPF platform for the UI. See my WPF Hole Patterns application on CodePlex to take a look at some of the vector graphics that are possible with C#, as well as how clean and pretty a WPF UI can be.

WPF Hole Patterns app is a vector based, CAD-like geometry program for laying out circular and linear hole patterns. In all, between the app and the source code, I’ve had over 100 downloads, so hopefully, it’s been helpful to some curious developers to see what they can learn from my efforts. I’ve since ported the app to Silverlight and used it as a practice field for learning the basics of the MVVM pattern. If you’d like the latest version in Silverlight, just drop me an email.

Another Example

You can also another great example (much better than mine) by checking out this Silverlight Live Geometry app on CodePlex. It’s another vector based drawing program intended to show off the Silverlight vector canvas. You can find a live version of the app at the Codeplex site, or here: http://livegeometry.com/http://livegeometry.com/

Both apps include full source code in C# and can be a helpful too in learning some geometry-based programming in C#, as well as WPF and Silverlight drawing.

HAML example

I wanted find out for myself what the reported HAML goodness is all about, so I spent a little time to educate myself on the basics, and then I took to converting one of my Rails erb files over to HAML. I’m posting the before and after results here as HAML examples to give one more convincing example of how much easier it is to read and write HAML views than the more noisy erb you-must-close-every-tag format.
At the end of this article, I list a few links to resources I found useful as I was getting started with HAML in my Rails application development.

Before (erb):

After (HAML):

More HAML examples and links

Some Thoughts on HAML by Rob Conery

Daniel Fischer says HAML is beautiful poetry

This article by Eric Davis exposes why he thinks HAML is bad, so you may want to study what he has to say

HAML cheat sheet

another HAML Cheat Sheet on http://cheat.errtheblog.com

HAML questions on StackOverflow

HAML user group on Google

http://www.rubyinside.com/haml-a-new-view-template-language-for-rails-235.html

http://haml-lang.com/

Learn more about HAML on Wikipedia

Latest HAML links on Coder I/O

Use this tool to automatically convert erb and html to HAML

HAML Videos

A video on HAML by Jason McCay from BarCamp Birmingham 2008-04-12

A HAML video from John Schult at merb day Atlanta 2008-12-06

HAML and SASS video (2007-11-20) – http://www.podcast.tv/video-episodes/episode-038-haml-and-sass-in-15-minutes-5214343.html

HAML and SASS video on Doctype video podcast Episode 38

Shredder vs Grinder vs Granulator

Announcing a new blog post on our Jordan Reduction Solutions web site comparing the different functions of a shredder versus a grinder versus a granulator. Our engineering team has compiled a brief summary comparing each of these pieces of equipment used in grinding, shredding, and granulating processes in industrial applications. Follow this link to compare a shredder, a grinder, and a grinder to a granulator.

WordPress is double awesome

I’ve just got say “WOW!” on this one… I recently wanted to add a blog to one of our corporate web sites so we could begin publishing a few articles about the equipment we manufacture in that division (heavy industrial shredders). Now, I had set up a Blogger account back in 2009 for my personal blogging effort, where I post mostly about software development stuff I’m working on or studying. But for this new corporate blogging plan I knew I wanted it living on our own server that we would fully control, rather than the Blogger model where your stuff is kind of under some control of Blogger. (Not that they are evil or anything, I’m just saying it didn’t seem like the right choice for a corporate blog)

Anyway, I had heard about WordPress in the past, but never really knew what it was all about. Turns out… It’s VERY powerful, simple to install, easy to use, and free.

All you do is download the zip file from WordPress.org, then FTP it to a folder on your web hosting company, say in a /blog folder. It has great instructions on how to configure MySql to host your blog, and you have to edit a config file to wire it up once the database is setup. (MySql database is included in most web hosting accounts. Our corporate web sites live on 1and.com and the installation and configuration went very well).

The whole thing is written in PHP. Now, I know nothing about PHP but that really doesn’t matter. There’s a Control Panel that you hit with your browser to configure everything. You can create as many Authors as you want, you can create Categories for your posts, installing Themes is easy, and there are tons of useful plugins that are available to do all kinds of cool stuff. There is a huge community around this software, and I plan to dig into that a little more in the future.

I’m not trying to give a complete tutorial on how install and set it up. Those topics have been covered in tons of places already. My point is that this “tool” is awesome! I learned the basics and had it installed, configured, and live all in one stay-up-late evening. I’m sure you can too.

Oh, by the way… you can see the blog here: http://www.JordanReductionSolutions.com/blog

Industrial Shredders and Tire Shredders are on the move

I’ve been at Jordan Machine Company for about 18 years now, and for many of those years we have been a key vendor to what is now Jordan Reduction Solutions – a manufacturer who designs and installs heavy duty industrial shredders, tire shredder (like the PT-6000 Passenger Tire Shredder).

All of these machines are really quite impressive in their brute force way of ripping and tearing apart anything you throw at them. You can see several impressive videos on their web site on the shredder videos page.

Granulator

For instance, the granulator machine is for fine shredding and grinding of materials like plastic, PVC, wood, and just about anything else you throw at it.  These are the smallest of all the machines, and cut with a high-speed rotor machine from solid steel, and has replaceable hardened knives that can be swapped out when the wear.

Tire Shredder

I’ve personally stood over a tire shredder and looked into the cutting chamber while it ripped up a car tire in seconds and dropped out little bits of rubber through the discharge screen. The sound is absolutely incredible; like something you’d hear in a scary movie. They can shred up the whole tire all at once, even that heavy bead that’s on the inside where the tire mounts to the rim.

Rubber Grinder

Some of the rubber grinder machines can even separate the wire out of the rubber, since that is required in some applications. The tire rubber (sometimes called “tire shreds” or “crumb rubber”) is used for a variety of things from Tire Derived Fuel to manufacturing rubber hoses and mats, to playground coverings. Jordan doesn’t market the rubber products that these machines generate, they just specialize in helping companies get the tires shredded up.

Hog Mill and Hog Grinder

These Grinders machines were once actually called “hog mills” or “hog grinders” because way back in time, they were commonly used to grind up, well, hogs for the food processing industry. These days they have become very popular for other industrial grinding applications like plastic grinding. These machines were originally designed and sold by Mitts and Merrill, so many of them would be known by that brand.

Twin Shaft Shredder

Then there are the dual shaft, or, twin shaft shredders. These machines have two shafts, rotating in opposite directions, and each shafts is loaded full of thick cutting knives with hooks on them to grab the product and pull it into the machine, chop it up, and discharge it out the bottom. The shafts are hex shaped, and the knives also have an internal hex shape so they can be driven by the shafts. The machines typically rotate at slower speeds, and they can also be equipped with screens to filter and refine the product size that comes out of the shredding process. Other ways to refine the process include using thinner knives, or adding more hooks onto the knives, and even altering the reach of each hook to grab more or less of the product being processed.

Wrapping up

They also have plenty of shredding equipment set up in a test lab where customers send in samples of product they’d like to be shredded up into various sizes. I’ve seen them chop up carpet scraps, entire wooden pallets, and they can even grind up large bails of rubber and various plastics into small shavings or pellets. The machines use a qualifying screen to determine the final particle size, so they can swap out the screens and achieve different output.

So that’s a little info on what it’s like to be involved in the shredder industry. Jordan Reduction Solutions is a great company to work with for your shredding, chopping, and grinding needs for industrial applications. Please check them out at the links I provided at the top of this article.

Devise authentication for Rails

I am proud to report that I have successfully installed and used the Devise authentication gem in my little test app that I am building learn Rails. I’m still a newbie at all this stuff, so anything that I can “gem install” and then hack my way through configuring and actually see the thing work in my app always brings a smile to my face. The Introducing Devise (#209) and Customizing Devise (#210) screencasts on RailsCasts.com really helped me a lot by showing how simple it is to set it up and do some customization. Plus, the documentation for basic configuration and use is pretty easy to follow. That’s always a good thing to see in these gems. Since I’m still playing around on Rails 2.3.5, I had to use version 1.0.7 of Devise, but they do have a Rails 3 version on the download page too, so be sure you use the right version.

With Devise in place in your app (it only requires a few lines to configure it, see the documentation on the web site for how to set it up), not only can you handle all the basic needs of authenticating a user login from your Users table (without writing as single line of code!), it also gives you built-in functions to create new user accounts, emailing them their forgotten password, and letting them change their password while logged in.  Beyond those basics, you can then easily restrict access to certain parts of your app to only those users of a certain role. You simply create a Model for each role that you want to work with in your app.

I originally found some code samples for a roll-your-own authentication approach on the Building a New Web Site with Rails blog post over at a ThinkingInRails.com, and it did show me how to approach this if I wanted to have and maintain my own code base for this matter, but I really wanted to use a ready-made solution for this so I could move on to other matters in my Rails learning.
So, at this point, I must say that I’m going with the Devise gem for authentication in my Rails apps (like I have a lot of Rails apps, but hey, this thing is a great way to go when that does happen).

Other Devise resources:


Ruby on Rails forever!

May 26, 2010 – Last night I attended my first ever Ruby users group meeting. It’s a meeting of the RubyHam Yahoo group for us folks here in Birmingham, Alabama. There were about 15 people there, and four short presentations on various Ruby and Rails topics, most of which were over my head at this point in my Ruby walk.

I began my study of Ruby and the Ruby on Rails framework in early April 2010. With my long FoxPro background (1992) and some .Net (2008), I’ve pretty much been a Microsoft man for a long time, so I’m not really sure what drew me to study Ruby and the Rails framework in the first place. I guess I’m just an easy sell on coding tools that sound cool. I knew the basics of the MVC pattern from my recent study of ASP.Net MVC, so I kind of knew what to expect, since Rails is an MVC framework too.

Mac, Windows, Linux? – At work I’m a Microsoft guy, but at home in the evenings I dance on the Apple floor (since about 2006) with my beautiful white iMac 20”. Since all of this was going to be new to me anyway, I decided to go the route that was the most foreign to me so I could really learn a lot of new things from this venture… So, I decided to setup that unsuspecting Mac to explore this dark new world.

Terminal Window vs. IDE…

I am an IDE guy, and not a terminal window guy, so I started out by installing the NetBeans 6.8 IDE (free, and it runs on Linux, Windows, and OSX). There are several choices when it comes to Ruby IDEs: RadRails from Aptana (free), Ruby In Steel (not free), RubyMine (not free), and many more. You can read this blog post to learn the pros and cons of some of these (and perhaps find a few more choices down in the blog comments). You’ll want to study them all to see which one you like best. Note: Ruby/Rails doesn’t require an IDE… you can do it all from the command line, but surely you’ll want a good IDE of some sort.

Database Choices…

The Rails framework (that is: the generated app it creates) defaults to work with the SQLite database thingy, which I knew little about, other than its simple life as an embedded database, which is a cool thing for sure. But I wanted to go with a more complex stack using MySql just because it seemed like a more big-boy thing to do. So I downloaded, installed, and configured MySql (for the first time ever, since I’ve always used Microsoft SQL Server) and now some of those mysteries about MySQL are now cleared up for me as well.

Now, I’m still a relative newbie on Mac stuff that takes me to that scary Terminal window, and man, it took some work to get my machine all gem’d up and ready for Ruby / Rails / MySql development, but I somehow stumbled through it all by surfing around for instructions. I’m still not exactly sure what all those ‘sudo’ commands did, but hey, it now works.

On Max OSX, Ruby is already installed with the OS, but I still had to get the rest of the bits in place. I may have installed a few things along the way that were already in present, but it seemed to work out fine.

First Rails app…

So there I was… Ruby, RubyGems, Rails, MySql, NetBeans 6.8. Ready to rock!

NetBeans has a New Project wizard for Ruby on Rails apps, so I fired that off to create my first ever Ruby on Rails app. The Project Wizard guides you through choosing your project name and location, Ruby version, database choice, web server, and Rails version. After the project is generated, if you decide to change which databases engine you’d like to use, you just edit the database.yml config file in the projects /Configuration folder to tell it which database adapter to use.

(I later setup and tested SQLite and it was cool to get that working too. Seems like I had to install some Ruby SQLite gems in the environment to get it set up.)

So the whole install/configure thing was surrounded with several mysterious activities to get everything in the environment setup properly, but I did it. I can’t express the feeling of success I had after spending a couple of hours hacking away at my machine to install all this stuff, much of which I didn’t understand at the time.

By “success” I simply mean that I can now:

  • start MySql server (I have not set it up to automatically start up yet. I don’t want it running all the time)
  • launch the NetBeans IDE and create a new Ruby on Rails project
  • ‘script/generate scaffold’  – code generates a model, the views, and the controller (from the IDE, mind you, not that crazy command line)
  • ‘migrate’ that model schema to the database (again, from the NetBeans IDE)
  • and finally, hit the Run button to watch the web server start up and take me to the default generated landing page for my app.

That wasn’t so bad..

Hearing all those smart guys talking in the room last night, I’d say I’ve got a LOT to learn from here, but I guess they all started where I am today, or even where I was back April wondering what this Ruby thing is all about.

You can do it too…

Now it’s your turn to give Rails a test drive. Configuring the environment is different on every OS platform, so depending on what OS you’re running (Mac OSX, Windows, or Linux) you’ll just have to surf around and find the instructions.

Here is a link to basic Ruby installation instructions for each OS. Then, you’ll still have to do some more work to install the Ruby on Rails framework.

Here’s is her set of instructions you can follow which guide you through installing Ruby, Ruby Gems, and Ruby on Rails.

Sadly, like many resources on the internet, the setup information is scattered all about. Many instructions assume you already know certain things about the platform. And there are different versions of everything… Ruby has a version, Rails has a versions, gems have versions. Heck, the gem installer even has versions. Oh yeah, and what is a gem in the first place? (You’ll find out soon enough once you get started.) I swear, it seems like more than you can keep straight at first. Oh, wait, but there’s RVM (Ruby Version Manager, I think). What the heck is that all about? Maybe I’ll find out if I keep digging.

Resources to help *YOU* get started

You can Google “Ruby on Rails” and get more info than you can shake a stick at, but below I’ll list out some resources that were helpful to get me started (I’ll add more to the list when I can go back and find them). There are podcasts, videos, and blogs galore.

RailsTutourial.org (Check out the online Book link at the top of the page)

http://www.sitepoint.com/books/rails2/samplechapters.php (free book chapters in PDF, including setup for each OS)

http://guides.rubyonrails.org/ (good getting started info from the mail Rails site)

http://www.ruby-forum.com/ (very active user forum)

http://railscasts.com/ (videos. very good videos!)

youtube videos (more videos)

http://5by5.tv/rubyshow ( a good podcast)

http://www.buildingwebapps.com/learningrails (audio lessons and video screencasts)

RubyFlow.com Daily Ruby/Rails links added my community members

How to install Ruby 1.9.2 and Rails 3 in Ubunto 10.10

See more resource links here: Resources for getting started with Ruby on Rails

Using Linq to count rows in a DataTable based on a field value

// Using Linq To DataSet to count rows based on a filter
// compared to
// Using the plain old Select() method that's been on DataTables since the beginning.
// Learn more about Linq To DataSet here: http://msdn.microsoft.com/en-us/library/bb386977(VS.100).aspx

using System;
using System.Linq;
using System.Data;
using System.Data.Common;

namespace ConsoleApplication
{
 class Program
 {
  static void Main(string[] args)
  {
   // Build up some sample data in a DataTable...
   DataTable dt = new DataTable();
   dt.Columns.Add("nMenuLevel", Type.GetType("System.Int32"));
   dt.Rows.Add(new object[] { 1 });
   dt.Rows.Add(new object[] { 1 });
   dt.Rows.Add(new object[] { 2 });
   dt.Rows.Add(new object[] { 3 });

   // Here's one way using Linq
   int linqCount1 = (from DataRow row in dt.Rows where (int)row["nMenuLevel"] == 1 select row).Count();
   Console.Write("linqCount1 = " + linqCount1.ToString() + "\n\n");

   // Here's another way using Linq
   int linqCount2 = dt.AsEnumerable().Where(c.Field("nMenuLevel") == 2).Count();
   Console.Write("linqCount2 = " + linqCount2.ToString() + "\n\n");

   // Here's a non-Linq way, using the old Select() method thats been available on DataTables
   // since the beginning. It's acutally much shorter and easier to read.
   // But watch out! Notice this Select syntaxt only requires 1 equal sign, not 2.
   int countWithSelect = dt.Select("nMenuLevel = 3").Count();
   Console.Write("countWithSelect = " + countWithSelect.ToString() + "\n\n");
   Console.ReadLine();
   }
 }
}