Skip to content

Instantly share code, notes, and snippets.

View taylorlapeyre's full-sized avatar

Taylor Lapeyre taylorlapeyre

View GitHub Profile
@taylorlapeyre
taylorlapeyre / fizzbuzz.rb
Created July 6, 2012 21:52
My shortest fizzbuzz to date
30.times do |num|
puts (num % 15 == 0) ? "Fizzbuzz" : (num % 5 == 0) ? "Fizz" : (num % 3 == 0) ? "Buzz" : num
end
@taylorlapeyre
taylorlapeyre / form.html
Created December 12, 2012 01:02
Simple PHP form example.
<html>
<head>
<title>Basic Form</title>
<style type="text/css">
label, input { display: block; }
</style>
</head>
<body>
<h2>Basic Form</h2>
<form method="post" action="report.php">
@taylorlapeyre
taylorlapeyre / rectangle.rb
Created December 12, 2012 01:03
Used to detect if two Rectangles are intersecting
# A simple Rectangle class
class Rectangle
attr_accessor :x, :y, :width, :height
def initialize(x, y, width, height)
@x, @y = x, y
@width, @height = width, height
end
def empty?
@taylorlapeyre
taylorlapeyre / Guardfile
Created December 12, 2012 01:07 — forked from yknd/Guardfile
guard 'rspec', :version => 2, :cli => "-c -fs" do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
watch(%r{^views/(.+)\.(slim|scss)$})
end
@taylorlapeyre
taylorlapeyre / answer.md
Created December 13, 2012 00:26
Question: "If you were asked to design a role-based (users, moderators, admins, etc) user system, how would you approach the problem? Briefly explain."

Question 3

There would first be a base User class, which would take necessary attributes, such as an ID, username, password, etc. Users would be able to do anything that any user of the system can do - for instance, post a comment or submit something.

There would then be other User classes that inherit from the User superclass, such as moderators or administrators. These Users would have respective abilities which extend the basic User model. For instance, a moderator may have a ban_user action and an administrator might have the ability to edit other User's profiles.

Users would be perhaps kept in a UserList object that would contain a hash of users and their respective IDs. The UserList could be the superclass of a ModeratorList or AdminList. Alternatively (depending on the scale of the system), we could store the Users in a database - probably mysql - with tables.

@taylorlapeyre
taylorlapeyre / gallery.rb
Created December 17, 2012 23:19
Basic outline / idea for a Gallery model
@taylorlapeyre
taylorlapeyre / galleryimage.rb
Created December 17, 2012 23:28
Basic outline / idea for a GalleryImage model
class GalleryImage
attr_reader :url, :description
def initialize(url, description)
@url = url
@description = description
end
def to_html
"<img src=\"#{@url}\" alt=\"#{@description}\" />"
@taylorlapeyre
taylorlapeyre / Gallery.php
Created December 18, 2012 03:22
Example Gallery class in PHP
@taylorlapeyre
taylorlapeyre / ImageGallery.php
Created December 18, 2012 20:22
Gii Generated ImageGallery model class.
<?php
/**
* This is the model class for table "image_galleries".
*
* The followings are the available columns in table 'image_galleries':
* @property integer $gallery_id
* @property string $gallery_name
* @property string $description
* @property integer $default_image_id
IMAGE_DIRECTORY = '/images'
def determine_image_location
for base_directory in IMAGE_DIRECTORY
for 2nd_level_directory in base_directory
if number_of_files_in(2nd_level_directory) < 100
return 2nd_level_directory.name
end
if number_of_files_in(base_directory) < 100
return base_directory.name