November 12, 2012

Don’t stop no matter how hard the material is

Today I bummed the quiz getting a 3/10 on it but the mistakes were minor. Even though the mistakes were minor a bad grade is a bad grade. After class I worked on more problems that were similar to the problems on the quiz so I could better understand what I was doing. After working on all problems in about 3-4 hours I finally understood my mistakes and am ready for the test.

November 6, 2012

Challenging yourself by solving problems everyday

Hello fellow readers, welcome to my new personal site. I have always wanted to start a personal blog for some years now and finally decided to just do it. I created this blog for my personal use and of course for you to follow me or learn something from me along the way. I am in the process of trying to complete my degree in computer science and would love to look back on all the things and events that I have experience from here on out. If you’re interested in learning more about me or the type of work I specialize in, check out my portfolio website cell- designs.  

2 years ago I officially decided that I would like to become a back-end programmer rather then just a front-end developer. I loved designing and creating websites for the frontend but I wanted to dive into the dark stuff and create web applications. Ever since I was a kid I always challenged myself in everything I decided to do.  Maybe I would play a video game and try to beat the game in 24hours, get an A on a school test, or I would take apart my bikes to make one good one. Though I was not sure the bike would work or that I would beat a video game or even ace the test at school I knew that I was trying and learning along the way.  

Everyday is a new day and a day to challenge yourself. Ever since I started to write code in terms of programming (Ruby, PHP etc) I’ve wanted to solve problems and that is what I am doing. I figured the best way or challenging your brain is to push yourself everyday to solve a problem. Though I was solving problems in my earlier days of writing code, I did not fully understand what I was solving but now I am making myself aware and setting my goals high. Everyday I have been solving math problems, writing new features into my web application, and of course writing it down in my blog.  I plan to take everyone who would love to follow me on my journey of pursuing a degree in computer science. In this blog you find pictures, blogs, videos, short quotes, and everything that inspires, bugs or motivate me as a young individual. That is all for this note and if you’ve read this far you’re a brave one. Much success to everyone who is trying to make a difference in the world and solve problems daily. 

June 15, 2012

Setting up a production server with ruby on rails (Deployment included) Part 3

Welcome to part 3 of setting up a production server with rails 3. In part 1 of this series we installed rvm, ruby, rails and setup a firewall. In part 2 of this series we installed mysql/postgresql, apache, and passenger. In part 3 of this tutorial we will install capistrano so we can deploy our application to our server.

What you will need

Make sure you have a git repository setup for your rails application so that you can deploy your app

Installing Capistrano

Now that our server is setup we can install capistrano. Logout of your server in go inside your local application folder. Once inside run

gem install capistrano

After you have installed the capistrano gem lets capify our rails project. This will create a couple of files for us but the one that we’re most interested in is the deploy.rb file.

capify .

Open the deploy.rb file and add in your server and git information.

set :application, "appname"
set :repository, "git@github.com:username/appname.git"

set :scm, 'git'

set :user, 'usernameyousetupforserver'
set :branch, "master"

set :git_shallow_clone, 1
set :use_sudo, false
set :deploy_to, "/path/public/#{application}"
set :deloy_via, :remote_cache
set :keep_releases, 1
set :rails_env, "production"
set :migrate_target, :latest

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

role :web, "xx.xxx.xx.xxx" # Your HTTP server, Apache/etc
role :app, "xx.xxx.xx.xxx" # This may be the same as your `Web` server
role :db, "xx.xxx.xx.xxx", :primary => true # This is where Rails migrations will run

 namespace :deploy do
   task :start do ; end
   task :stop do ; end
   task :restart, :roles => :app, :except => { :no_release => true } do
     run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
   end
 end

 namespace :deploy do
   desc "Recreate symlink"
   task :resymlink, :roles => :app do
     run "rm -f #{current_path} && ln -s #{release_path} #{current_path}"
   end
 end

After you have setup your information above run the following

  cap deploy:setup
  cap deploy
  cap deploy:check

The above will setup the necessary files then deploy your application and finally check to see if you’ve encountered any errors while deploying.

June 13, 2012

Setting up a production server with ruby on rails (Deployment included) Part 2

Welcome to part 2 of setting up a production server for your ruby on rails application. In part 1 we setup rvm, ruby, and rails. In Part 2 of this tutorial we will setup a mysql, postgresql, and finally install apache & passenger.

Installing Mysql

Since we have rails and ruby setup lets install mysql. If you would like to use postgresql skip this part in go down below.

sudo apt-get install mysql-server mysql-client libmysqlclient-dev`

Now install the mysql2 gem for rails

gem install mysql2

Installing Postgresql

Now that we have ruby and rails installed we can install postgresql. First lets install the python software properties.

sudo apt-get install python-software-properties

Next well add the backports and repo and update apt

    sudo add-apt-repository ppa:pitti/postgresql
    sudo apt-get update

Next we’ll install postgresql

sudo apt-get install postgresql-9.1 libpq-dev`

Apache & Passenger

Now that you have your database setup we can finally install Apache and passenger which is what we’ll be using to power our server.

    sudo apt-get install apache2 libcurl4-openssl-dev apache2-prefork-dev \
                     libapr1-dev libaprutil1-dev

Next we will install the passenger gem

gem install passenger

Now we’re ready to install the Passenger Apache2 module which will setup our server files etc.

passenger-install-apache2-module`

After the installation is complete you will need to add in the three lines of code from the installation into your passenger.load file. After you have pasted the code into the file press cmd + x and Y to save the file.

sudo vim /etc/apache2/mods-available/passenger.load

Here is the 3 lines of code. Do not copy below, just for example

  LoadModule passenger_module /home/yourusername/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.5/ext/apache2/mod_passenger.so
  PassengerRoot /home/yourusername/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.5
  PassengerRuby /home/yourusername/.rvm/wrappers/ruby-1.9.2-p180/ruby

Now lets enable the passenger module

sudo a2enmod passenger

Next we will setup a virtual host for our website.

sudo vim /etc/apache2/sites-available/appname

Then well add our server and site information into the file.

      ServerName xx.xx.xx.xx
      DocumentRoot /home/yourusername/appname/public

        AllowOverride all
        Options -MultiViews

Now lets disable the default Apache page and enable our website

    sudo a2dissite default
    sudo a2ensite appname

Now reload your web server and go to your ip and you should see a blank white screen.

sudo /etc/init.d/apache2 reload

In part 3 of this tutorial we will deploy our rails application with capistrano.

June 11, 2012

Setting up a production server with ruby on rails (Deployment included) Part 1

When first creating a ruby on rails application I thought about going with a service like heroku. Yes heroku is great since they manage your server but the prices and addons can get very expensive. If you’re a developer who is not scared to dive deep into the command line then look no further. In this tutorial I am going to share with you all how to setup your very own production server with rails 3.

What well be using

  • Ubuntu 10.04
  • RVM
  • git
  • Ruby 1.9.3
  • Rails 3.2.4
  • Mysql / Postgresql

What you will need

Setup server

Now since you are aware of the tools that we’ll be using, lets begin setting up our server from scratch. When you are all signed into your hosting account setup a new ubuntu 10.04 lts(Lucid Lynx) server. If you are using rackspace then I would start with the 256mb of ram(you can scale if needed). After you have picked your server and have setup a root password we will begin logging into the server via ssh and the terminal.

Open your terminal and type root@ your ip address for your server. A prompt should ask if you would like to save key. Yes is the answer.

ssh root@xx.xx.xxx.xxx

Now that your logged into the server lets create a new user so that you are not logged in as root for everything. It will ask for you to enter a password for that user. Enter the password then press enter to skip full name etc.

adduser yourusername

Now that our user account is setup we need to allow our user to install programs but not as root. Open the sudoers file.

sudo vim /etc/sudoers
    # User privilege specification
    yourusername ALL=(ALL) ALL

Now that we have our user created(though we’re still logged in as root) we can stop people from trying to brute-force our root password and take over out account.

vim /etc/ssh/sshd_config

Look for the line that has "PermitRootLogin" and change it from yes to no. Now lets restart the server.

/etc/init.d/ssh restart

Then logout of your server as root

logout

Now that we are all logged out, lets login using our new user credentials. Connect to the server using ssh

yourusername@xx.xx.xxx.xxx

Installing rvm

After successfully logging in as the new user let;s update the software on the server.

    sudo apt-get update
    sudo apt-get upgrade

Now we’ll install git so that we can install rvm, ruby, and other dependencies that we may need.

sudo apt-get install git-core

Next we’ll install rvm

    gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
    \curl -s

Then run source so we will not have to exit terminal.

source ~/.rvm/scripts/rvm

Type code below, if working correctly it will return "RVM is a function"

type rvm | head -n1

Now that rvm is setup let’s install ruby dependencies

#!/bin/bash

###### CONFIG
ACCEPTED_HOSTS="/root/.hag_accepted.conf"
BE_VERBOSE=false

if [ "$UID" -ne 0 ]
then
 echo "Superuser rights required"
 exit 2
fi

genApacheConf(){
 echo -e "# 
}
    sudo apt-get install build-essential bison openssl libreadline6 \
                     libreadline6-dev curl git-core zlib1g zlib1g-dev \
                     libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev \
                     sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev \
                     ncurses-dev

Installing ruby & rails

Now we’re ready to install ruby. This will take a while

rvm install 2.2

Now set ruby 2.2 as default

rvm --default use 2.2
gem install rails -v4.2.4

Before moving on make sure ruby and rails are installed in that you’re using the correct version and that they are both installed.

    ruby --version
    rails --version

Adding a firewall

Now lets install a firewall so we’re not easily venerable to outsiders. For this tutorial I will use Uncomplicated Firewall – UFW, which is a firewall for our ubuntu server.

sudo apt-get install ufw

Now lets setup the rules for our firewall

    sudo ufw default deny
    sudo ufw allow ssh
    sudo ufw allow http
    sudo ufw enable

Now lets check our rules to see if port 22, and 80 are open to the internet

sudo ufw status

In Part 2 of the next tutorial we will setup mysql, apache, and get our web server up and running.

December 22, 2011

How to Install imagemagick on mac os x for rails 3

I love coding but sometimes it just gets frustrating when you’re stuck on something particular for hours. In my case I were trying to add file uploads to my web app using paperclip and as soon as I were ready to upload an image rails returned an error saying I must install imagemagick. In today’s post I am going to share with you all how I have gotten this to work and hopefully this saves you hours of trying to find the right solution.

Install gem

First things first, open your gemfile located in your rails root directory then add the following to your gemfile. Though this tutorial is fairly new I recommend checking the latest version to see where rmagick is currently at.
gem 'rmagick', '2.13.1'

Install Homebrew

When getting your mac you notice mac’s come without tons of programs which means you have to install them manually. After you have added rgmagick to your gemfile go to homebrew homepage.

Open your terminal and add the following code:
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
After running the above command run this command. Should start installing imagmagick this take a bit of time.
brew install imagemagick

Permission issues

If you get an error in rails saying

Errno::EACCES: Permission denied - /Users/path
An error occured while installing rmagick (2.13.1), and Bundler cannot continue.
Make sure that `gem install rmagick -v '2.13.1'` succeeds before bundling.

Go to the path where rmagick is(gems folder) and pull the folder to your desktop then create a new folder with the same name and finally copy the content from the first folder to your newly created folder. After you have successfully done so you should now have full permission. Finally go into your terminal and run bundle install command and everything shou