January 28, 2012 at 10:30pm
CSS Cross-Country solutions
http://www.codeschool.com/courses/css-cross-country
Level 1
Challenge 1/6 : External Stylesheets
index.html:
<!doctype html>
<html lang="en">
<head>
<title>Sven's Snowshoe Emporium</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<section class="content">
<header>
<h1>Sven's Snowshoe Emporium</h1>
</header>
</section>
</body>
</html>
style.css:
body {
color: #4b4648;
font-family: tahoma, arial, sans-serif;
font-size: 14px;
}
.content {
border: 1px solid #cac3c6;
margin: 0 auto;
padding: 20px;
width: 260px;
}
h1 {
color: #6d9fac;
font-size: 22px;
text-align: center;
}
Challenge 2/6 : ID Selector
#slogan {
text-align: center;
font-style: italic;
}
Challenge 3/6 : Compound Selector
.content { border: 2px solid #ccc; }
.content.home { border: 0; }
Challenge 4/6 : Style Specificity
index.html:
<!doctype html>
<html lang="en">
<head>
<title>Sven's Snowshoe Emporium</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<section class="content home">
<header>
<h1>Sven's Snowshoe Emporium</h1>
<h2>"For the Snow-Savvy Shoe-Shopper"</h2>
</header>
</section>
</body>
</html>
style.css:
header { background: #e0e2e6; }
Challenge 5/6 : Floats
aside {
width: 120px;
float: right;
margin-left: 10px;
margin-bottom: 10px;
}
Challenge 6/6 : Columns
aside { float: right; width: 120px; }
article { float: left; width: 120px; }
Read More
#html5
#css3
#code school solutions
January 22, 2012 at 9:52pm
CoffeeScript solutions
http://www.codeschool.com/courses/coffeescript
Level 1
Challenge 1/7 : Variable Assignment
person = "Bohdan"
Challenge 2/7 : Functions
greet = -> alert "Hello CoffeeScript"
Challenge 3/7 : Functions II
greet = (argument) ->
alert argument
Challenge 4/7 : Functions III
greet = (argument1, argument2) ->
alert argument1 + " " + argument2
Challenge 5/7 : Functions IV
greet = (name='Stranger') ->
alert name
Challenge 6/7 : Functions V
greet = (name='Stranger') ->
"Hello, #{name}"
Challenge 7/7 : Sum Function
sum = (argument1, argument2) ->
return argument1 + argument2
Read More
#coffeescript
#javascript
#jquery
#code school solutions
January 12, 2012 at 12:38pm
jQuery Air: Captain’s Log solutions
http://www.codeschool.com/courses/jquery-air-captains-log
Level 1
Challenge 1/12 : HTML Value
$('ol.economy-class li.row:first li:first').html();
Challenge 2/12 : Text Value
$('ol.economy-class li.row:first li:first a').text();
Challenge 3/12 : Text Value II
$('ol.economy-class li.row:eq(1) li:eq(3)').html();
Challenge 4/12 : Attributes
$('ol.economy-class li.row:eq(1) li:eq(3) a').attr('href');
Challenge 5/12 : Data Attributes
$('ol.economy-class li.row:eq(1) li:eq(3) a').data('seat');
Challenge 6/12 : Click Event
$('div.seating-chart a.available').click(selectSeat);
function selectSeat(event) {
event.preventDefault();
$('.selected').removeClass('selected');
$(this).addClass('selected');
}
Challenge 7/12 : Bind Click Event
$('div.seating-chart a.available').bind({
click: selectSeat
});
Challenge 8/12 : Using Data Attributes
function selectSeat(e) {
e.preventDefault();
$('.selected').removeClass('selected');
$(this).addClass('selected');
$('#seatSelected').text($(this).data('seat'));
$('div#confirm-seat').show();
}
$('div.seating-chart li a.available').click(selectSeat);
Challenge 9/12 : Unbind Event
function selectSeat(e) {
e.preventDefault();
$('.selected').removeClass('selected').bind('click', selectSeat);
$(this).addClass('selected').unbind('click', selectSeat);
$('#seatSelected').text($(this).data('seat'));
$('#confirm-seat').show();
}
$('div.seating-chart li a.available').click(selectSeat);
Challenge 10/12 : Multiple Click Handlers
$('div.seating-chart ol.first-class li a.available').click(selectFirstClass);
$('div.seating-chart ol.economy-class li a.available').click(selectSeat);
Challenge 11/12 : Live
$('#confirm-first-class a.confirm-upgrade').live('click', confirmUpgrade);
Challenge 12/12 : Delegate
$("#confirm-first-class").delegate("a.confirm-upgrade", "click", confirmUpgrade);
Read More
#jquery
#javascript
#code school solutions
October 29, 2011 at 2:29pm
jQuery Air: First Flight solutions
http://www.codeschool.com/courses/jquery-air-first-flight
Level 1
Challenge 1/13 : Creating Variables
var flight = 16;
Challenge 2/13 : Fixing Common Errors
var flight = 232;
var pilot = "Steeley Dan";
var weight = 367.5;
Challenge 3/13 : The Alert Dialog
alert("Prepare for takeoff!");
Challenge 4/13 : Write a Confirm Dialog - Part I
confirm("Turn on the fasten seatbelt sign?");
Challenge 5/13 : Write a Confirm Dialog - Part II
var belts = confirm("Turn on the fasten seatbelt sign?");
alert("Seatbelts: " + belts);
Challenge 6/13 : The Prompt Dialog
var headCount = prompt("How many passengers do we have?");
alert("We have " + headCount + " passengers today.");
Challenge 7/13 : Working with Data - Part I
var totalSeats = 130;
var headCount = prompt("How many passengers do we have?");
parseInt(headCount);
var empty = totalSeats - headCount;
alert("There are " + empty + " seats remaining");
Challenge 8/13 : Working with Data - Part II
var headCount = prompt("How many passengers do we have?");
headCount = parseInt(headCount);
var averageWeight = prompt("What's the average weight?");
parseFloat(averageWeight);
var totalWeight = headCount * averageWeight;
alert("Total passenger weight is about " + totalWeight + " pounds");
Challenge 9/13 : String Manipulation - Part I
var pilotName = "Shirley Rumack";
pilotName = pilotName.toUpperCase();
Challenge 10/13 : String Manipulation - Part II
var flightSummary = "Flight 603: PHX to LAX";
var flightSummary = "Flight 603: PHX to LAX".replace("603", "754");
Challenge 11/13 : Arrays - Part I
var flights = ["603", "754", "256"];
Challenge 12/13 : Arrays - Part II
var today = ["603", "754", "256"];
var yesterday = ["893", "923", "664", "232", "499"];
var flights = yesterday.length - today.length;
alert("Yesterday there were " + flights + " more flights than today");
Challenge 13/13 : Arrays - Part III
var flights = ["603", "754", "256"];
var gates = [26, 27, 28];
alert("Flight " + flights[2] + " departs from Gate " + gates[2]);
Read More
#jquery
#javascript
#code school solutions
October 26, 2011 at 11:32pm
Functional HTML5 & CSS3 solutions
http://www.codeschool.com/courses/functional-html5-css3
Level 1
Challenge 1/8 : HTML5 Doctype and Head
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body></body>
</html>
Challenge 2/8 : HTML5 Div Refactor
<header>
<h1>That's right Ice Man, I am dangerous</h1>
</header>
<footer>
<h3>USS Enterprise</h3>
<p>© 2011 United States Navy</p>
</footer>
Challenge 3/8 : Navigation Tag
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Aircraft</li>
<li>Pilots</li>
<li>Apply</li>
</ul>
</nav>
Challenge 4/8 : Section Tag
<section>
<header>
<h1>Navy Fighter Weapons School</h1>
</header>
<h2>Maverick & Goose Crash and Burn</h2>
<p>Aha, Jester's dead...</p>
</section>
Challenge 5/8 : Article Tag
<section id="top-gun">
<header>
<h1>Navy School Updates</h1>
</header>
<article>
<h2>Maverick & Goose Crash and Burn</h2>
<p>Aha, Jester's dead...</p>
</article>
<article>
<h2>She's Lost That Lovin' Feelin'</h2>
<p>I hate it when she does that...</p>
</article>
</section>
Challenge 6/8 : Aside Tag
<section id="top-gun">
<header>
<h1>Navy Fighter Weapons School</h1>
</header>
<article>
<h2>Maverick & Goose Crash and Burn</h2>
<p>Aha, Jester's dead...</p>
<aside>
<p>FACT: The airspeed velocity of an F14 Tomcat is much faster than an unladen swallow...</p>
</aside>
</article>
</section>
Challenge 7/8 : Bringing It All Together - Part I
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Top Gun - Highway to the Danger Zone</title>
<link href="css/style.css" rel="stylesheet" />
</head>
<body>
<header>
<h1>Top Gun</h1>
<h2>Navy Fighter Weapons School</h2>
</header>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Aircraft</li>
<li>Pilots</li>
<li>Apply</li>
</ul>
</nav>
<footer>
<h3>Top Gun</h3>
<p>© 2011 United States Navy, Miramir, CA</p>
</footer>
</body>
</html>
Challenge 8/8 : Bringing It All Together - Part II
<section>
<h2>Top Gun Aircraft</h2>
<article>
<h3>The F14 Tomcat</h3>
<p>Tower this is Ghost Rider requesting a flyby. Negative, Ghost Rider, the pattern is full.</p>
<aside>
<p>FACT: Son, your brain's writing checks your body can't cash...</p>
</aside>
</article>
<article>
<h3>The MIG-28</h3>
<p>You were in a 4g inverted dive with a MIG-28? Yes, ma'am. At what range?</p>
</article>
</section>
Read More
#functional html5 and css3
#html5
#css3
#code school solutions
Rails Best Practices solutions
http://www.codeschool.com/courses/rails-best-practices
Level 1
Challenge 1/6 : Named Scope
app/models/following.rb:
class Following < ActiveRecord::Base
scope :recent, order('created_at desc').limit(10)
belongs_to :user
end
app/controllers/user_controller.rb:
class UserController < ApplicationController
def index
@followings = current_user.followings.recent
end
end
Challenge 2/6 : Scope with Lambda
app/models/following.rb:
class Following < ActiveRecord::Base
scope :recent, lambda { where('created_at > ?', 2.days.ago) }
end
app/controllers/user_controller.rb:
class UserController < ApplicationController
def index
@followings = current_user.followings.recent
end
end
Challenge 3/6 : Default Scope
app/models/following.rb:
class Following < ActiveRecord::Base
default_scope order('created_at DESC')
end
app/controllers/user_controller.rb:
class UserController < ApplicationController
def index
@followings = current_user.followings
end
end
Challenge 4/6 : Model Creation Scope
class FollowingsController < ApplicationController
def create
current_user.followings.create
redirect_to root_url, :notice => 'Successfully followed!'
end
end
Challenge 5/6 : Skip a Filter
class ProfilesController < ApplicationController
skip_before_filter :require_login, only: :show
def show
@user = User.find(params[:id])
end
end
Challenge 6/6 : Fat Model / Skinny Controller
app/models/user.rb:
class User < ActiveRecord::Base
has_many :followings
def follow(user)
unless followings.where(:followed_user_id => user.id).present?
followings.create(:followed_user => user)
else
false
end
end
end
app/controllers/users_controller.rb:
class UsersController < ApplicationController
def follow
@user = User.find(params[:id])
if current_user.follow(@user)
redirect_to root_url
else
redirect_to @user
end
end
end
Read More
#rails best practices
#ruby on rails
#code school solutions
October 21, 2011 at 10:47pm
Rails for Zombies 2 solutions
http://www.codeschool.com/courses/rails-for-zombies-2
Level 1
Challenge 1/12 : Rails New
rails new ZombieTweets
Challenge 2/12 : Generate Scaffold
rails g scaffold tweet status:string zombie_id:integer
Challenge 3/12 : Create Tweets Table
class CreateTweets < ActiveRecord::Migration
def change
create_table :tweets do |t|
t.string :status
t.integer :zombie_id
end
end
end
Challenge 4/12 : Run Migration
rake db:migrate
Challenge 5/12 : Boot it up
rails s
Challenge 6/12 : Add Column to Table
rails g migration AddPrivateToTweets private:boolean
Challenge 7/12 : Create Migration by Hand
class AddLocationToTweets < ActiveRecord::Migration
def change
add_column :tweets, :location, :string, limit: 30
add_column :tweets, :show_location, :boolean, default: false
end
end
Challenge 8/12 : Rollback Migration
rake db:rollback
Challenge 9/12 : Change Table
class AddLocationToTweets < ActiveRecord::Migration
def change
add_column :tweets, :location, :string, limit: 30
add_column :tweets, :show_location, :boolean, default: false
add_column :tweets, :category_name, :string
rename_column :tweets, :status, :message
end
end
Challenge 10/12 : Remove Column
class RemoveCategoryNameFromTweets < ActiveRecord::Migration
def up
remove_column :tweets, :category_name
end
def down
add_column :tweets, :category_name, :string
end
end
Challenge 11/12 : Database Setup
rake db:setup
Challenge 12/12 : In the Console
rails c
Read More
#rails for zombies
#ruby on rails
#code school solutions
#rails for zombies 2
October 10, 2011 at 12:04pm
Rails for Zombies solutions
Last night I was watching these “Walking Dead” mini-series on YouTube, and after that I was googling zombies and somehow I ended up learning Ruby on Rails by playing Rails for Zombies, a really great introduction for newbies. Why don’t you try it?
On the off chance you get stuck at some point, here are my solutions. But I’d strongly recommend you do not give up too early and hence do not miss the fun of solving problems.
Level 1
Challenge 1/6 : Find
t = Zombie.find(1)
Challenge 2/6 : Create
t = Zombie.new(:graveyard => "Punchbowl Cemetery",
:name => "Stubbs")
t.save
OR
Zombie.create(:graveyard => "Punchbowl Cemetery",
:name => "Stubbs")
Challenge 3/6 : Find 2
Zombie.last
Challenge 4/6 : Query 1
Zombie.order(:name)
Challenge 5/6 : Update
t = Zombie.find(3)
t.attributes = {:graveyard => "Benny Hills Memorial"}
t.save
OR
t = Zombie.find(3)
t.update_attributes(:graveyard => "Benny Hills Memorial")
Challenge 6/6 : Destroy
t = Zombie.find(3)
t.destroy
OR
Zombie.find(3).destroy
Read More
#rails for zombies
#ruby on rails
#code school solutions