Skip to content

Instantly share code, notes, and snippets.

@mariapacana
mariapacana / gist:5354325
Last active December 16, 2015 01:19
The first file is a Jasmine test, the second is the file I am trying to test. When I try to run both tests (one for adding a row and one for deleting a row), Jasmine gives me a "TypeError: Object is not a function" error. But if I comment out one of the tests and just run the other test, it works perfectly. Specifically, Jasmine says: TypeError:…
//The Jasmine test.
describe("A suite", function() {
var addFriendButton;
var removeFriendButton;
var contacts;
beforeEach(function() {
addFriendButton = document.createElement("button");
document.body.appendChild(addFriendButton);
addFriendButton.setAttribute("id", "addFriendButton");
@mariapacana
mariapacana / guessing_game.rb
Created April 25, 2013 17:24
Revised guessing game.
class GuessingGame
def initialize(answer)
@answer = answer
end
def guess(guess)
@guess = guess
if guess > @answer
puts "high"
return :high
@mariapacana
mariapacana / nums_subtraction.rb
Created May 9, 2013 18:58
Converts integers to Roman numerals.
def numerals_subtraction(int)
values = %w(M D C L X V I)
roman_num = ""
values = {"M" => 1000, "D" => 500, "C" => 100, "L" => 50, "X" => 10, "V" => 5, "I" => 1}
values.keys.each do |i|
if (int % values[i]) then
@mariapacana
mariapacana / knapsack.rb
Last active December 17, 2015 05:19
Shows whether a knapsack problem is solvable or unsolvable.
menu_1 = [1, 2.50, 3.50]
target_1 = 450
menu_2 = [0.31]
target_2 = 450
menu_3 = [2.15, 2.75, 3.35, 3.55, 4.20, 5.80, 6.55]
target_3 = 15.05
def knapsack(menu, target, current_price)
@mariapacana
mariapacana / knapsack2.rb
Created May 11, 2013 01:55
second knapsack
def knapsack2(menu, target, steps, next_step)
size = menu.size
current_price = (0...size).inject(0) {|r, i| r + menu[i]*steps[i]}
# File.open("knapsack.txt", 'w') {|f| f.write("menu = #{menu}, target = #{target}, current_price = #{current_price}" + "steps = #{steps}") }
if current_price == target
return steps
elsif current_price > target
# require 'Math'
def is_prime?(num)
(2..Math.sqrt(num)).each { |factor| return false if num % factor == 0 }
true
end
def prime_factors(num)
primes_hash = {}
primes = []

Instructions:

  1. Download this application skeleton.
  2. Convert the app to use AJAX.
  3. Add any files you changed to your gist and submit your code.

Instructions:

  1. Download this application skeleton.
  2. Convert the app to use AJAX.
  3. Add any files you changed to your gist and submit your code.
$(document).ready(function () {
$('form').submit(function (e) {
e.preventDefault();
$.post('/', function(response) {
source = response + '.png';
$('#die_pic').attr('src', source);
});
});
@mariapacana
mariapacana / index.html
Last active December 18, 2015 11:20 — forked from dbc-challenges/index.html
DBC Phase 2 Practice Assessment Part 3
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.jsdelivr.net/normalize/2.1.0/normalize.css">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Lato:100,900">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.0.2/css/font-awesome.min.css">
</head>