Skip to content

Instantly share code, notes, and snippets.

@georgekettle
georgekettle / 20201223190654_create_questions.rb
Last active December 24, 2020 02:08
Livecode: Active Record Basics (Batch 466)
# migrate/20201223190654_create_questions.rb
class CreateQuestions < ActiveRecord::Migration[6.0]
def change
create_table :questions do |t|
t.string :question
t.string :option_a
t.string :option_b
t.timestamps # add 2 columns, `created_at` and `updated_at`
end
end
@georgekettle
georgekettle / ruby_basics.rb
Created January 11, 2021 23:36
ruby basics
enthusiasm = 10
love_x = "love " * enthusiasm
comment = "I #{love_x}LeWagon"
# airbnb listings // defining an array
listings = []
@georgekettle
georgekettle / days_before_xmas.rb
Created January 13, 2021 00:53
ruby_basics_livecode
require 'date'
# Livecode
def days_until_christmas
# return the number of days until net christmas
today = Date.today
current_year = Date.today.year
christmas = Date.new(current_year, 12, 25)
# subtract to get the amount of days b/w
christmas = christmas.next_year if today > christmas
def acronymize(text)
# 'text' is a string
# we need access to each word (so lets break it up) => array
words = text.split # we have an array now 👍
# get the first letter of each --> join them --> capitalize the whole word
words.map{|word| word[0]}.join.upcase
end
# 'situation normal all fucked up' => snafu
p acronymize('situation normal all fucked up')
# TODO: you can build your calculator program here!
# create a calculator
require 'colorize'
def prompt(text)
puts text.yellow
end
def addition(first, last)
first + second
@georgekettle
georgekettle / database.csv
Last active January 19, 2021 08:44
Christmas gift list
name bought price
macbook pro false 20
handbag false 35
Long Pendant Sterling Silver Necklace false 50
# User stories:
# -list tasks
# -add a task
# -mark a task as done
# -remove a task
# MVC(R)
# model
# view
# controller
@georgekettle
georgekettle / 20210204090708_create_teams.rb
Created February 4, 2021 00:10
ActiveRecord associations & Validations
class CreateTeams < ActiveRecord::Migration[6.0]
def change
create_table :teams do |t|
t.string :name
t.timestamps
end
end
end
.animated {
animation-duration: 0.2s;
animation-fill-mode: forwards;
}
@keyframes fadeIn {
from {
// transform: scale(0.99);
opacity: 0;
}
@georgekettle
georgekettle / attribute_merger.rb
Created November 10, 2023 20:39
AttributeMerger for Phlex Components
class AttributeMerger
attr_reader :default_attrs, :user_attrs
OVERRIDE_KEY = '!'.freeze
def initialize(default_attrs, user_attrs)
@default_attrs = flatten_hash(default_attrs)
@user_attrs = flatten_hash(user_attrs)
end
def call