⌘T | go to file |
⌘⌃P | go to project |
⌘R | go to methods |
⌃G | go to line |
⌘KB | toggle side bar |
⌘⇧P | command prompt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
item = Item.find 328 | |
item.transaction do | |
item.feelings.create!(size: 'huge') | |
item.update_attributes!(state: "sold") | |
end | |
# item.update_attributes! fails a validation, which we rescue. new feeling that we created is rightly rolled back | |
item.save #saves the feelings record that was rolled back as part of our transaction! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns erdos-c.core | |
[:require [yokogiri.core :refer :all]]) | |
(def client (make-client :javascript false)) | |
(defn page [uri] | |
(get-page client (str "http://en.wikipedia.org" uri))) | |
(defn link-snippets [uri] | |
(xpath (page uri) "//a")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Take a sequence of N numbers. We'll call the sequence a "Clean Chain of length N" | |
# if the sum of the first N - 1 numbers is evenly divisibly by the Nth number. | |
# For example, the sequence [2, 4, 6, 8, 10] forms a clean chain of length 5, | |
# since 2 + 4 + 6 + 8 = 20, which is divisible by 10, and the sequence has 5 numbers. | |
# The first clean chain formed out of the sequence of primes is simply [2], with length 1. | |
# The second is [2, 3, 5] with length 3. | |
# The third is [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, | |
# 53, 59, 61, 67, 71], with length 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(1..100).map {|i| (fb = [["Fizz"][i%3],["Buzz"][i%5]].compact.join).empty? ? i : fb} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<!-- | |
normalize.css removes cross-browser differences in defaults, e.g., | |
differences in how form elements appear between Firefox and IE | |
See: http://necolas.github.com/normalize.css/ | |
--> | |
<link rel="stylesheet" href="normalize.css"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RPNCalculator | |
def initialize | |
@special_cases = [->(op, arr) {arr.include?('0') && op == '*' && '0'}, | |
->(op, arr) {arr.first == ('0') && op == '/' && '0'}, | |
->(op, arr) {arr.include?('1') && op == '*' && (arr-['1']).first}, | |
->(op, arr) {arr.include?('0') && op =~ /[+-]/ && (arr-['0']).first}] | |
end | |
def evaluate(*inputs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CalculatesRoute | |
def self.calculate(points) | |
remaining_points = points | |
route = [] | |
route << remaining_points.slice!(0) | |
until remaining_points == [] do | |
next_point = shortest_distance(route.last, remaining_points) | |
route << remaining_points.slice!(remaining_points.index(next_point)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'geocoder' | |
require 'shoulda-matchers' | |
require 'geocoder' | |
require 'debugger' | |
class ActivityCluster | |
MAX_ROUTE_LENGTH = 4 | |
MAX_DISTANCE = 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function justify(str, width) { | |
var whitespace = ' '; | |
while (str.length < width) { | |
var oldLength = str.length; | |
var spacing = new RegExp("(\\w)" + whitespace + "(\\w)"); | |
str = str.replace(spacing, '$1 ' + whitespace + '$2'); | |
if (oldLength === str.length) { | |
whitespace += ' '; | |
} | |
} |
OlderNewer