Big O – w/ Ruby Examples

I had a hard time finding an explanation of all basic Big O concepts with practical use cases and code examples (ruby).

Each algorithm is broken down into 4 parts:
  1. Basic Definition (only what you need to know to understand the basics of this approach).
  2. Real life example (what you do in your daily life that mirrors this algorithm, reading a book, feeding your cat etc).
  3. Ruby code example (the most basic code example that I can think of).
  4. Other things you have done or may do in your programming day to day.

Continue reading

Simple Guide To Responsive Design (10 minute tutorial)

When I wanted to convert my web application for mobile and pad devices I had a hard time finding a step by step guide.There are a lot of grid systems and paid templates but what if I already made my site and now I want it to work seamlessly on all devices? This is the tutorial for you.

Responsive websites are not optimized for specific devices, like the iphone but optimized to work on all phones, all pad devices etc.  This is obtained by using a fluid grid and media queries.

The three things we will be covering to get your website working on all devices is:

1. Fluid grid

2. Using em instead of px

3. Media Queries

In this tutorial I will be optimizing the homepage of  Mia Math. This is an application I built that helps girls second to fourth grade learn math.
Continue reading

Twitter-Bootstrap-Sass & Rails – Getting Started

Update: Bootstrap 3 now ships with Sass, Yay!

If you’re like me you prefer sass to less but like using bootstrap to quickly make your app look beautiful on all devices and browsers.

I like to use the bootstrap-sass-rails gem so I am not stuck using less. Go ahead and add this to your gemfile in the assets group.

gem 'bootstrap-sass-rails'

Next run bundle and restart the server.

You’re going to have to change the stylesheets/application.css
to stylesheets/application.css.scss. Now you’re ready to import all the components that the gem gives you.

@import "twitter/bootstrap";

note: I generally delete everything that is in this file.

If you refresh your browser you should see the bootstrap styles.

Google Trends API Work-around – The Right Way

Google does not have an easy way to grab data from google/trends, I think they had an API awhile ago but this has long been deprecated. There are handful of posts online that show you how to make calls and get the raw data but this will get you banned very quickly.

What I ended up doing is embedding the  script, that google provides, in a view and embedding ruby into the script and escaping the js. This way it will be dynamically updated depending on what value I am pulling from my database.

It looks like this:

<script type="text/javascript" src='//www.google.com/trends/embed.js?hl=en-US&q=<%=escape_javascript @profile.firstname %>+<%=escape_javascript @profile.lastname %>&content=1&cid=GEO_MAP_0_0&export=5&w=400&h=430'></script>

This is great solution that will not get you banned and allow you to show data.
There is one major downside to this solution. You’re stuck with the google design and logo.

Git Workflow For Beginners

When I first started to learn git I found it terribly unintuitive. What the heck is master and why I am not the master on my own computer?! She has been lying to me all along, wench…grrr.

No one wanted to give me a simple workflow. Because it always “depended on what I was doing.” This is true but I am going to give out a workflow anyway. Here is the one I wish I had when I first started to learn git. Enjoy.

Note: Commit early and often. This will save you from doing too much damage as you’re learning version control.

Step 1 – See what branch you’re on:

git status

You want the output to look something like this:

# On branch master

Step 2 – Create a new branch:

git co -b "name_your_branch"

Code on this branch.

Step 3 – Checkout Master Branch

git checkout master

Step 4 – Pull in changes that may have been made while you were working on your branch

git pull origin master

Step 5 – Merge your branch

git merge name_your_branch

Step 6 – Push your branch “up to” master

git push origin master

rinse, repeat….

Rails – Deploying to Heroku – Postgres

I find myself coming back to the same set of notes every time I am about to deploy. Here is my workflow for deploying my rails apps to heroku, enjoy.

Step 1: – Open up your terminal and create a new application on heroku:

heroku create

Step 2: – Declare your ruby version in your gemfile

ruby '1.9.3'

Step 3: – Add this to config/applications.rb

config.assets.initialize_on_precompile = false

Step 4 – Push your git repository to heroku

git push heroku master

Step 5 – Include postgres add on

heroku addons | grep POSTGRES

Step 6 – Add it to development

heroku addons:add heroku-postgresql:dev

Step 7 – Create Database

heroku run rake db:create

Step 8 – Migrate Database

heroku run rake db:migrate

Step 9 – Domain

heroku domains:add www.example.com

cname and dns

https://devcenter.heroku.com/articles/custom-domains