Skip to content

Instantly share code, notes, and snippets.

View clamstew's full-sized avatar
🧘
🎨 🤖 🚀 vibe-coding 24/7. Let's Go!

Clay Stewart clamstew

🧘
🎨 🤖 🚀 vibe-coding 24/7. Let's Go!
View GitHub Profile

Partner Exercise 4:

**View concepts we will cover: **

  • more practice with the Foundation CSS framework and writing minimal layout css
  • using partials to encapsulate parts of your layout
  • using partials and passing in local variables for repeating elements
  • using font-awesome icon set for rapid prototyping
@clamstew
clamstew / polymorphic_associations.md
Last active February 18, 2022 13:18
A blog post on polymorphic associations. By @clamstew and @truffaut

Why Polymorphic Associations:

This was a question from @photonerddan during class, and after looking through many examples online approaching it from an inheritance stance, as well as ones with examples that seemed outside of common use-cases, Mike and I decided to approach it from a problem / solution standpoint, which looks at it from a database perspective.

We will cover it more in-depth during the second week of Rails MakerSquare, but for now here is a short example to highlight the problem that polymorphism is solving in your database.

So let's start with the problem it is solving:

Polymorphism keeps you from having excessive foreign key columns in a database table where multiple things, such as notification feed items, are owned by other objects.

@clamstew
clamstew / gravatar_array_loop.rb
Last active August 29, 2015 13:57
email gravatar each loop. outputs a hash of all the emails input
require 'digest/md5'
# make an email array for images you want to find
array_emails = ["email1", ...]
# make a new hash to store email:image_url as a key value pair
hash_email_image = {}
def gravatar_for(email, options = { size: 50 })
gravatar_id = Digest::MD5::hexdigest(email.downcase)
size = options[:size]
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
@clamstew
clamstew / form_for_lesson.md
Last active August 29, 2015 13:57
rough version of the form for lesson

form_for 'helper' method

Up until now we have looked at the create and update controller action in Rails in the context of using a basic <html> form tag, <form></form>.

When you wanted to POST a new movie to your Metube app:

'new' action

First you made a new controller-action in your videos controller. This action was mapped to the GET route that loaded the new video form from the views/videos/new.html.erb file with a route that looks like get "/videos/new", to: "videos#new" in the routes.rb file.

Looking at the new action in the videos controller, it's time to come clean. There was really no reason in the previous Rails CRUD lesson with the new action that we needed to hand down this instance variable:

@clamstew
clamstew / rotating-images.html
Created May 1, 2014 06:41
I was thinking about an image rotator and started mocking one up on a small scale.
<!DOCTYPE html>
<html>
<head>
<style>
body {margin: 0;}
.container {
margin: 0 auto;
width: 800px;
background: aliceblue;
}
@clamstew
clamstew / shoestring-style-guide.html
Last active August 29, 2015 14:01
style-guide for project shoestring sass
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Shoestring.css Style Guide</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="./css/shoestring/0.0.1/shoestring-dev.css">
<style type="text/css">
@clamstew
clamstew / clearfix.html
Created May 7, 2014 21:03
Add a sample page for the clearfix lesson
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Clearfix Example</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
/* code for debugging */
@clamstew
clamstew / resizer.js
Last active August 29, 2015 14:01
margin top resizer
(function(){
var marginSetter = function () {
var h = ($(window).height()) / .2;
$('#my-element').css("margin-top": h);
};
// to run when the window is resized
$(window).on('resize', function() {
marginSetter();
<div id="result">result text</div>
(function(){
var resizeText = function() {
var text = $("#result").html();
var length = text.length;
if (length > 30){
$("#result").css("font-size", "0.7em");
}
@clamstew
clamstew / rps.rb
Created May 21, 2014 18:21
Show commenting out require relatives and putting in the directory files in a single line
# Create our module. This is so other files can start using it immediately
module RPS
end
# Require all of our project files
# require_relative 'rps/player.rb'
# require_relative 'rps/match.rb'
# require_relative 'rps/round.rb'