Skip to content

Instantly share code, notes, and snippets.

View Jared-Prime's full-sized avatar
📚

Jared Davis Jared-Prime

📚
View GitHub Profile
@Jared-Prime
Jared-Prime / gist:2501154
Created April 26, 2012 17:28
sample of Sass responsive grid
@for $i from 1 through 4 {
.span#{$i} {
margin:0;
padding:0;
float:left;
@media (min-width:960px) {
width: percentage(1/$i);
}
@media (max-width:780px) and (max-width:959px) {
require 'rspec'
require './../core_arithmetic'
class DataSet < Array
def input(data)
if data.kind_of?(Enumerable)
data.each do |item|
if item.kind_of?(Numeric) == true
self << item
class DataSet < Array
def input(data)
if data.kind_of?(Enumerable)
data.each do |item|
if item.kind_of?(Numeric) == true
self << item
else
self.input(item)
end
@Jared-Prime
Jared-Prime / gist:2424438
Created April 19, 2012 21:50
beginning additive color theory
# this gist teaches you how to balance colors using HEX-to-DEC conversions.
# In color theory, additive colors are colors that, when combined, produce solid white.
# HEX primaries, plus black and white
# remember, HEX colors desribe the state of a color channel. think of 00 as "OFF" and FF as "ON".
@red = "FF0000" # red channel fully ON, all else fully OFF
@green = "00FF00" # green channel fully ON, all else fully OFF
@blue = "0000FF" # blue channel fully ON, all else fully OFF
@black = "000000" # all channels fully OFF
@Jared-Prime
Jared-Prime / fizz_buzz.rb
Created April 13, 2012 01:01
FizBuz - shorter & sweeter
# the classic FizzBuzz exercise, implemented with Ruby syntax
# at first, I wrote a script similar to the JavaScript exercise on Codeacademy.com
# Needless to say, the chain of if..else... statements just feels wrong.
# Below, with comments, is far superior code, modeled off http://www.rubyquiz.com/quiz126.html
# Start with an array of integers. We'll pass each integer individually to the block.
(1..100).each{ |i|
# Set an empty string as a default.
@Jared-Prime
Jared-Prime / gist:2371377
Created April 12, 2012 22:09
Address Book - using objects
// Codeacademy.com project, "Address Book"
// the functions input and output information about objects collected in the array.
// Note that there's no class; you have to define the attributes explicitly when creating the object.
var contacts = [];
function printPerson (person) {
console.log(person.firstName + " " + person.lastName);
}
@Jared-Prime
Jared-Prime / fizzbuzz.js
Created April 12, 2012 21:59
FizzBuzz - fun with the modulus and loops
// Codeacademy.com project, "FizzBuzz"
// Goal: counting from 1 to 100, print "Fizz" if the numeral is divisible by 3, "Buzz" if divisible by 5, and "FizzBuzz" if divisible by both 3 and 5.
for (i=1; i<=100; i++) {
if ( i % 3 === 0 && i % 5 === 0 ) {
console.log("FizzBuzz")
}
// if the number is divisible by 3, write "Fizz"
@Jared-Prime
Jared-Prime / gist:2371404
Created April 12, 2012 22:16
Guessing Games - interactive object
// Codeacademy.com project, "Guessing Game"
// Simple interactive game, prompting the user to guess a number between 1 and 10, giving clues for the correct answer.
GuessingGame = function(min, max) {
this.init(min, max);
};
GuessingGame.prototype = {
minNumber: 1,
maxNumber: 10,
@Jared-Prime
Jared-Prime / gist:2371354
Created April 12, 2012 22:03
Cash Register - using objects and methods
// Codeacademy.org project, "Cash Register"
// Note that you cannot change prices without changing the methods!
// A better project would ask the student to calculate the total bill using price and quantity as input.
function StaffMember(name,discountPercent){
this.name = name;
this.discountPercent = discountPercent;
}
var cashRegister = {
@Jared-Prime
Jared-Prime / gist:2371299
Created April 12, 2012 21:55
Olympic Tryouts - basic data validation
// Codeacademy.com project, "Olympic Tryouts"
// find the runner's average time
function calculateAverage(runnerTimes) {
var runnerTotal = 0;
for(i=0;i<runnerTimes.length;i++){
runnerTotal += runnerTimes[i];
}
var averageTime = runnerTotal / runnerTimes.length;