Skip to content

Instantly share code, notes, and snippets.

View goodbedford's full-sized avatar

goodbedford goodbedford

View GitHub Profile

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@goodbedford
goodbedford / problem.rb
Last active August 29, 2015 14:13
problem
phrase5 = "oh i understand banter"
phrase6 = "a ob ooc dd oeoo ooooof"
phrase7 = "a b c"
phrase8 = "a b c d e f g"
def decryptc(message)
m = message.split()
puts "Phase3: Extra-Credit"
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost:27017/weather', function(err, db) {
if (err) throw err;
var query = {};
var options = { 'sort' : [ ['State', 1],
['Temperature', -1] ]
// Bonfire: Title Case a Sentence
// Author: @goodbedford
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence?solution=function%20titleCase(str)%20%7B%0A%20%20%0A%20%20var%20strArr%20%3D%20str.split(%22%20%22)%3B%0A%20%20var%20tempArr%20%3D%20%5B%5D%3B%0A%20%20%0A%20%20strArr.forEach(function(word)%7B%0A%20%20%20%20var%20firstChar%20%3D%20word%5B0%5D.toUpperCase()%3B%0A%20%20%20%20word%20%3D%20word.toLowerCase()%3B%0A%20%20%20%20word%20%3D%20firstChar%20%2B%20word.slice(1)%3B%0A%20%20%20%20tempArr.push(word)%3B%0A%20%20%7D)%3B%0A%20%20%0A%20%20return%20tempArr.join(%22%20%22)%3B%0A%7D%0A%0AtitleCase(%22I%27m%20a%20little%20tea%20pot%22)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function titleCase(str) {
var strArr = str.split(" ");
var tempArr = [];
// Bonfire: Reverse a String
// Author: @goodbedford
// Challenge: http://www.freecodecamp.com/challenges/bonfire-reverse-a-string?solution=function%20reverseString(str)%20%7B%0A%20%20%20%0A%20str%20%3D%20str.split(%22%22).reverse().join(%22%22)%3B%0A%20%20%0A%20%20return%20str%3B%0A%7D%0A%0AreverseString(%22hello%22)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function reverseString(str) {
str = str.split("").reverse().join("");
return str;
// what will Loretta wear?
// she will wear shirt and pants but if the temp is higher than 70 she will wear her shorts and short sleeve shirt.
// write the inner code for the whatToWear function.
// example answer: outfit //[ 'shorts', 'shoes']
function whatToWear( temp ) {
var clothes = ['shorts', 'short sleeve', 'pants', 'shirt', 'coat'];
var outfit =[];
// what will Loretta wear?
// if the temperature out side is below 55 then she will wear a coat and pants. if the temperature is below 70
// she will wear shirt and pants but if the temp is higher than 70 she will wear her shorts and short sleeve shirt.
// write the inner code for the whatToWear function.
function whatToWear( temp ) {
var clothes = ['shorts', 'short sleeve', 'pants', 'shirt', 'coat'];
var outfit =[];
// you want to get a new puppy so you go to the puppy palace. you need to print out the list of
// all the puppies to make your choice. write a function that will
// do loops in three ways and print puppy name,breed and age to each to console.
// for loop, while loop, forEach
function puppyPrint () {
var puppies = [
{name: "ruff",
breed: "beagle",
age: 1
// you want to get a new puppy so you go to the puppy palace. you need to print out the list of
// all the puppies to make your choice. write a function that will
// do loops in three ways and print puppy name,breed and age to each to console.
// for loop, while loop, forEach
function puppyPrint () {
var puppies = [
{name: "ruff",
breed: "beagle",
age: 1
@goodbedford
goodbedford / protips.js
Created November 28, 2015 01:56 — forked from nolanlawson/protips.js
Promise protips - stuff I wish I had known when I started with Promises
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");