Skip to content

Instantly share code, notes, and snippets.

@mariapacana
mariapacana / Sublime.md
Last active December 24, 2015 13:59
Sublime shortcuts

Linux

  • Control + Shift + P + rein -- reindent lines
  • Control + D -- select word
  • Control + U -- unselect word
  • Control + O -- open file
  • Control + W -- close tab
  • Control + KK -- delete to the end of line
  • Control + X -- cut entire line (or you can use this to delete)
  • Shift + Alt + (any number) -- split the window into that many panes (1 works, too)
  • Control + Shift + [Group #] -- move file to group
@mariapacana
mariapacana / pair.pl
Created August 23, 2013 03:41
Prolog code for generating pairs.
use_module(library(clpfd)).
:- use_module(library(lists)).
ingroup(1, 1).
ingroup(2, 1).
ingroup(3, 1).
ingroup(5, 1).
ingroup(3, 2).
ingroup(4, 2).
ingroup(5, 2).
@mariapacana
mariapacana / inheritance.md
Last active December 20, 2015 04:49
Javascript and Inheritance

Objects

  • Objects in Javascript are essentially hashes.
  • There are special types of objects such as strings, integers, and functions, but a 'plain Javascript object' is just a hash consisting of key-value pairs.
  • Keys must be strings. Values can be any object, including functions.

Prototypes

  • Every object has a 'prototype' that it inherits from.
  • Prototypes are simply objects containing various properties.
  • When you call a property of an object, Javascript first looks inside the object to retrieve that property. If it doesn't find it, it looks inside the object's prototype.
  • You can only set an object's prototype once; it can never be overwritten.
@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>
$(document).ready(function () {
$('form').submit(function (e) {
e.preventDefault();
$.post('/', function(response) {
source = response + '.png';
$('#die_pic').attr('src', source);
});
});

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.
# 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 = []
@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
@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)