Skip to content

Instantly share code, notes, and snippets.

class Cohort < Database::Model
def self.all
Database::Model.execute("SELECT * FROM cohorts").map do |row|
Cohort.new(row)
end
end
def self.create(attributes)
record = self.new(attributes)
record.save
require 'sqlite3'
# class Student
# attr_accessor :first_name, :last_name, :created_at, :updated_at
$db = SQLite3::Database.new "students.db"
module StudentDB
def self.setup
$db.execute(
http://imgur.com/QszNrs4
<?xml version="1.0" encoding="utf-8" ?>
<!-- SQL XML created by WWW SQL Designer, https://github.com/ondras/wwwsqldesigner/ -->
<!-- Active URL: http://ondras.zarovi.cz/sql/demo/ -->
<sql>
<datatypes db="mysql">
<group label="Numeric" color="rgb(238,238,170)">
<type label="Integer" length="0" sql="INTEGER" quote=""/>
<type label="TINYINT" length="0" sql="TINYINT" quote=""/>
#Tic-Tac-Toe
10.times do
#create an array of 4 "x" and "o" each.
#Append(push) either "x" or "o" into the array. This is because there are 9 boxes in a board and there must be either 5 "x" and 4 "o" or vice versa.
board = ["x", "o", "x", "o", "x", "o", "x", "o"] << ["x","o"].sample
#Create 3 new arrays, shuffle the "x" and "o" (destructive shuffle so the same value is not in the main array anymore) and shift it so there are 3 values in each of the 3 new arrays
Array.new(3) {p board.shuffle!.shift(3)}
end
# Objective 2: Chessboard
chessboard = Array.new(8) do
array = [0..7]
end
infantry_row = ["P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8"]
royalty_row = ["Rook", "Knight", "Bishop", "Queen", "King", "Bishop", "Knight", "Rook" ]
chessboard[1] = infantry_row
def fibonacci(n)
a = 0
b = 1
# Compute Fibonacci number in the desired position.
n.times do
temp = a
a = b
# Add up previous two numbers in sequence.
b = temp + b
def is_anagram?(input1, input2)
input1 = input1.downcase.split(//).sort
input2 = input2.downcase.split(//).sort
return input1 == input2
end
puts is_anagram?("cinema", "iceman")