$ rails g model User
belongs_to
has_one
| ActiveRecord cheat sheet / EXAMPLES | |
| INSTALL | |
| ======= | |
| $ gem install activerecord | |
| in GEMFILE: gem ‘activerecord’ | |
| REQUIRE | |
| ======= | |
| require ‘active_record’ |
| <h1>Equations for Organic Motion - Test Sheet</h1> | |
| <div id="more"> | |
| <span class="arrow">↑</span> | |
| Resize for more | |
| </div> |
| module DefaultValues | |
| def has_default_values(default_values = {}) | |
| class_attribute :default_values | |
| self.default_values = default_values | |
| after_initialize :assign_default_values | |
| include InstanceMethods |
| // Mocked Service | |
| angular.module('mock.users', []). | |
| factory('UserService', function($q) { | |
| var userService = {}; | |
| userService.get = function() { | |
| return { | |
| id: 8888, | |
| name: "test user" | |
| } |
| // 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!"); |
A queue just preserves the order in which items arrived into it. This helps model real world problems around waiting in your turn or in line.
Directions: Write a ruby script to do the following with a queue.
Scenario: you have a store and you're writing a script to help calculate a quick receipt. The one problem is that every 3rd and 5th item a customer buys is on sale. Every 3rd item is 10% off and every 5th item is 20% off, but also, an item that is both a 3rd and 5th item is 30% off.
| // Bonfire: Check for Palindromes | |
| // Author: @goodbedford | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes?solution=function%20palindrome(str)%20%7B%0A%20%20%20%20str%20%3D%20str.toLowerCase()%3B%0A%20%20%20%20str%20%3D%20str.replace(%2F%5B%5Cs%2B%2C.%5C%5C()_%5C%2F-%5D%2Fg%2C%20%22%22)%3B%0A%20%20%20console.log(str)%3B%0A%20%20%20tempStr%20%3D%20str.split(%22%22).reverse().join(%22%22)%3B%0A%20%20%0A%20%20for%20(%20var%20i%20%3D0%3B%20i%20%3C%20tempStr.length%3B%20i%2B%2B)%7B%0A%20%20%20%20if(tempStr%5Bi%5D%20!%3D%3D%20str%5Bi%5D%20)%7B%0A%20%20%20%20%20%20return%20false%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20%0A%20%20%2F%2F%20Good%20luck!%0A%20%20return%20true%3B%0A%7D%0A%0A%0A%0Apalindrome(%22eye%22)%3B%0A | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function palindrome(str) { | |
| str = str.toLowerCase(); | |
| str = str.replace(/[\s+,.\\()_\/-]/g, ""); | |
| console.log(str); | |
| tempStr = str.split("").reverse().join(""); |
| // 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 = []; | |
| import React from "react"; | |
| import { render } from "react-dom"; | |
| const ParentComponent = React.createClass({ | |
| getDefaultProps: function() { | |
| console.log("ParentComponent - getDefaultProps"); | |
| }, | |
| getInitialState: function() { | |
| console.log("ParentComponent - getInitialState"); | |
| return { text: "" }; |