Skip to content

Instantly share code, notes, and snippets.

View khan-hasan's full-sized avatar

Hasan Khan khan-hasan

  • Delta Air Lines
  • Atlanta, GA
View GitHub Profile
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
class AddAdminFlagToUsers < ActiveRecord::Migration[5.1]
def change
add_column :users, :admin, :boolean, default: false, null: false
end
end
@khan-hasan
khan-hasan / rock_paper_scissors.rb
Created October 10, 2017 17:40
Rock, Paper, Scissors Game
# ends the game
def end_game
puts "\nBye!"
end
# the game which recursively calls itself until user presses "X" to call end_game and finish the game
def game
puts "==============================\nPlease choose one from the following:\n(R) Rock\n(P) Paper\n(S) Scissors\n(X) End game\n\n"
user_turn = gets.chomp.capitalize!
if user_turn != "R" && user_turn != "P" && user_turn != "S" && user_turn != "X"
@khan-hasan
khan-hasan / 3.5.rb
Created October 7, 2017 22:34
CF 3.5 | oop, pt. 2 (instance methods, inheritance, etc._
str.is_a?(Object)
str.class
# here we extend Ruby's string class meaning that all strings in the environment will belong to this class
class String
def star
self + " *"
end
end
@khan-hasan
khan-hasan / cat.rb
Created October 7, 2017 21:54
CF 3.4 | simple ruby Cat class
class Cat
attr_reader :color, :breed, :name
# There is no need for a separate attr_writer and separate attr_reader for name because attr_accessor can combine those methods into one (DRY)
# attr_writer :name
attr_accessor :name
def initialize(color, breed)
@color = color # Instances variables are available to other methods inside of this class. This is unlike local variables, which only exist inside the method they're called in.
@breed = breed
@hungry = true
@khan-hasan
khan-hasan / fav_foods.rb
Created October 7, 2017 17:13
CF 3.3 | simple ruby program using loops, hashes, and arrays
def fav_foods
food_array = []
3.times do
puts "Name a favorite food."
food_array << gets.chomp
end
food_array.each do |food| # do something to each element in food array; that element is to be referred to as food
puts "I like #{food} too!" # the thing we're doing
end # ends the loop
p food_array
@khan-hasan
khan-hasan / program2.rb
Created October 7, 2017 16:44
CF 3.2 | 3 simple ruby "hello world" programs
if true
puts "this is true"
else
puts "this is false"
end
@khan-hasan
khan-hasan / program.rb
Created October 7, 2017 16:14
CF 3.1 | simple "hello world" program in ruby
def greeting
puts "Please enter your name:"
name = gets.chomp
puts "Hello " + "" + name
end
greeting
@khan-hasan
khan-hasan / index.html (calculator)
Created October 7, 2017 14:47
CF 2.11 | final submission for achievement 2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Calculator</title>
<link rel='stylesheet' href='http://d33wubrfki0l68.cloudfront.net/css/ebe0759bf259b6caeadee6137973481046ac5636/css/normalize.css'/>
<link rel="stylesheet" href="css/styles.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
@khan-hasan
khan-hasan / index.html
Created October 3, 2017 02:13
CF 2.10 | implemented google maps api and added map to contact section
<!-- ******* in the faq section, if you stare at it for a while, it suddenly changes colors slightly. debug it. in fact, the entire page seems to shift slightly. i think all the carousel images have to be the same size (especially height)-->
<!DOCTYPE html><!-- Instructs browser what version of HTML the page is written in. html indicates HTML5 -->
<html lang="en">
<!-- Specifies the language of the element's content -->
<head>
<!-- A container for metadata, data about the HTML document which is not displayed -->
<!-- Google Analytics -->
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-107063946-1"></script>
<script>