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
WEB_SAFE_NUMBERS = [ | |
0, # 00 | |
51, # 33 | |
102, # 66 | |
153, # 99 | |
204, # cc | |
255 # ff | |
] | |
def closest_web_safe_color(string) |
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
WEB_SAFE_NUMBERS = [ | |
0, # 00 | |
51, # 33 | |
102, # 66 | |
153, # 99 | |
204, # cc | |
255 # ff | |
] | |
def closest_web_safe_color(string) |
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
# https://leetcode.com/problems/count-primes/description/ | |
# return the number of prime numbers less than a positive number n | |
def count_primes(n) | |
primes = [] | |
(2..n-1).each do |i| | |
primes[i] = true | |
end | |
(2..Math.sqrt(n)).each do |i| |
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 Solution | |
def initialize | |
@known_strings = {} | |
end | |
def word_break(string, word_dict) | |
if @known_strings[string] | |
return @known_strings[string] | |
end |
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
def replace_words(dict, sentence) | |
regex = /\A(#{dict.join('|')})/ | |
sentence.split.inject([]) do |new_words, word| | |
if match_data = word.match(regex) | |
new_words << match_data.captures[0] | |
else | |
new_words << word | |
end | |
end.join(' ') |
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
-# This file contains the 'layout' for this section of the site | |
%section.how-it-works-page.content-section | |
.container | |
.row | |
.col-md-12 | |
%h2.section-title How It Works | |
.sub-nav.row | |
.col-sm-3 | |
= active_link_to how_we_find_kids_path, class: 'link-wrap' do | |
.img.school |
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 GeneratedPDF | |
def generate | |
# pdf stuff... | |
pdf_file = Tempfile.new(['something', '.pdf']) | |
pdf_file.binmode | |
pdf_file.write(pdf_string) | |
pdf_file | |
end | |
end |
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
# rails 3, invalid times are set to nil | |
> m = Model.new some_timestamp: '2010-33-22T09:30:25Z' | |
=> #<Model ...> | |
> m.some_timestamp | |
=> nil | |
# rails 4, invalid times raise an exception | |
> m = Model.new some_timestamp: '2010-33-22T09:30:25Z' | |
=> ArgumentError: argument out of range |
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
defmodule Search do | |
def chop(_val, []), do: -1 | |
def chop(val, [head|tail]) when tail == [] do | |
if val == head, do: 0, else: -1 | |
end | |
def chop(val, list) do | |
chop(val, 0, length(list) - 1, list) | |
end |
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 Dependencies | |
def initialize | |
@dependencies = Hash.new {|h,k| h[k] = []} | |
end | |
def add_direct item, new_dependencies | |
@dependencies[item] += new_dependencies | |
end | |
def dependencies_for item |
NewerOlder