Sunday 20 May 2012

Getting started with Ruby on Rails


I started to learn Ruby on Rails recently. I thought I would document what’s helped me out along the way.

Ruby:
Ruby Koans - http://rubykoans.com/
This is a form of Test Driven Learning. It is free and can be run from a web browser without having anything installed on your computer (though I would recommend downloading it as it seems to be easier to keep track of where you are when you break). It’s an interactive way to learn Ruby and helps you keep testing in mind while you learn.

I did end up buying a book. It has been surprisingly quite pleasant to read and has worked out well by reading concurrently with doing the ruby koans problems. The two styles of learning seem to compliment each other nicely. There is also a free version of the book for Ruby 1.8, which can be found here http://pragprog.com/book/ruby/programming-ruby. This book does assume you have some level of programming experience.

why’s (poignant) guide to Ruby - http://mislav.uniqpath.com/poignant-guide/
While I’m not working with the book currently, I did read a good bit of it a couple years ago when I was getting started out programming. It’s a free, weird, and a pretty fun way of learning but may not suited for everyone. I think it’s worth checking out the first chapter to see if you enjoy it. Here’s a pdf if you get tired of the online version too http://www.thinkingaloud.net/wp-content/uploads/2010/08/wpgtr.pdf.

Rails:
Code School: Rails for Zombies - http://railsforzombies.org/
The first lessons are free. Everything runs inside a browser so no need to install anything on your computer. It’s a pretty easy going interactive way to learn rails.

While I haven’t gotten started on this book yet, I’ve heard really good things and many people I work with recommend it.

Getting the code working on your machine…
Some tools that I found useful:
Homebrew (package manager): http://mxcl.github.com/homebrew/
RVM (helps to manage your ruby environments): https://rvm.io// https://github.com/wayneeseguin/rvm
Just doing a search for these tools can give a pretty nice step-by-step walk through on how to install them all http://www.frederico-araujo.com/2011/07/30/installing-rails-on-os-x-lion-with-homebrew-rvm-and-mysql/




Monday 13 February 2012

Downcasting Using Dynamics- C#

A few days ago I learned something new. 

For certain unfortunate reasons sometimes one is forced to downcast an object before sending it to a method which takes a generic parameter. Again, this isn't an ideal case as it seems less generic, but just in case someone else has found themselves in such a pickle because of other constraints, I hope you find this solution as helpful as I have. In C# 4.0 the dynamic was introduced.



Given a couple of tools that inherit from a tool object:



public abstract class Tool {
}
public class Wrench : Tool {
}
public class ScrewDriver : Tool {
}

And a method that takes the generic:


public class ToolHandler {
    public virtual void Tighten<T>(T tool) {
    }
}


How does one downcast the object from a list before calling the method without checking each type in a list?


public List<Tool> Tools { get; set; }

var _toolHandler = new ToolHandler();
List<Tool> tools = new List<Tool>{new Wrench(), new ScrewDriver()};



*************Former sloppy way******************

foreach(var tool in tools){
    if (tool is Wrench) {
        _toolHandler.Tighten((Wrench)tool);
    }
    if (tool is ScrewDriver) {
        _toolHandler.Tighten((ScrewDriver)tool);
    }
}    

****************************************************

The answer- use a dynamic. 

foreach(var tool in tools){
    _toolHandler.Tighten((dynamic)tool);
}


*Special thanks to M.Babcock on stackoverflow for answering my co-worker's and my question. http://stackoverflow.com/questions/9116034/downcast-instance-using-its-type

Feel free to paste this inside Rextester (http://rextester.com/runcode) or wherever you would like to run it for an example. Hopefully the link still works too http://rextester.com/live/IJWT40081.



using System;
using System.Collections.Generic;

namespace Rextester
{
    public class Program
    {
        public abstract class Tool {
        }
        public class Wrench : Tool {
        }
        public class ScrewDriver : Tool {
        }
        public class ToolHandler {
            public virtual void Tighten<T>(T tool) {
                Console.WriteLine(typeof(T));
            }
        }
   
        public static void Main(string[] args)
        {
            List<Tool> tools = new List<Tool>{new Wrench(), new ScrewDriver()};
       
            var handler = new ToolHandler();
            foreach(var tool in tools){
                handler.Tighten((dynamic)tool);
            }
        }
    }
}

Rextester - Neat way to run C# code online

http://rextester.com/runcode

See next post for example.

Friday 10 February 2012

A Soap Holder Worth Mentioning

Vertical Soap holder 

Maybe these things are more popular than I think, but it's new to me so I thought I'd mention it. What a great invention. I found it in the corporate apartment I've been staying in. I know bar soap isn't as popular with so many liquid/gel body wash options out there, but it's still the classical cheaper solution to get yourself clean. Unfortunately, sometimes those bars don't last as long as they should when they sit in water 24/7. This creation holds your soap bar in an isolated vertical position that allows the water to constantly roll off the majority of surface area. For an extra effect, you can hang it outside of the shower head drip/spray direction.

Under 100 Calories Squawk

90 calorie granola bar in what appears to be it's former full breakfast bar's wrapper


Low calorie food options have become very popular as of lately. For multiple reasons, I am usually happy about this. If you can make the same dish at a restaurant with half as much goose fat, butter, or whatever your favorite lard choice is, great! *(Assuming they are not substituting it with something worse). In general, people don't need as much fat. However, like every fad, it has been taken to a bit of extreme. I feel like some companies are loving the fact they can put half as much food in a wrapper; label it as a healthy food option because it has lower calories; and then sell it for the same price. The recipe hasn't changed. When I purchase food to bring home, I'm paying for a quantity of the substance. That quantity happens to be measured in calories. Now I'm stuck buying twice as many and buried under 3' of wrappers. What happened to the '25% more' marketing fad?

Saturday 7 January 2012

Android 4.0 MMS Error: Currently unable to download. Please try again later.

I recently got a new Samsung Galaxy Nexus with Google's new Ice Cream Sandwich OS (currently 4.0.2) through Verizon Wireless. I like what they have done, but I think there are new things to learn/get used to, important features missing, and some bugs. Since currently only 0.6% of users currently have the 4.0 OS (http://developer.android.com/resources/dashboard/platform-versions.html) and there isn't a lot of resources out there for it, I figured I would try to help out other lost users by trying to post my problems and solutions.

A recent error that I received while trying to download a multimedia message was "Currently unable to download. Please try again later."

I am using the phone in Canada and don't remember having to do anything special on my last Android phones to avoid this error while here. I also didn't seem to get it the error while in the states.

But to fix it I had to go to Settings > More... (under Wireless & Networks) > Mobile networks, and check Data enabled. Hope this helps.

Hello

I originally thought that I would have a nice preface to my blog describing everything. As you can see, this is not the case. I figured there is no use in holding up on starting a blog because of undefined whys. So hopefully one day I might create one.