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
# selecting | |
def choose_best_guess(ary) | |
ary.select{ |v| v <= t }.max | |
end | |
# rejecting | |
def choose_best_guess(ary) | |
ary.reject{ |v| v > t }.max | |
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 LinkedListNode | |
attr_accessor :value, :next_node | |
def initialize(value, next_node=nil) | |
@value = value | |
@next_node = next_node | |
end | |
end | |
def print_list(list_node) |
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
"use strict"; | |
var _ = { | |
// Implements: | |
// https://lodash.com/docs#map | |
map: (array, callback) => { | |
var newArray = [] | |
array.forEach(function(item){ | |
newArray.push(callback(item)) |
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
// Palindromes are the same forwards as in reverse | |
// As an example, if the input was “I like racecars that go fast”, | |
// the largest palindrom substring (racecar) | |
// would have the length of 7. | |
var longestPalindrome = function(s){ | |
let biggest = 0; | |
const stringLength = s.length; |
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
/* -- Problem -- | |
* Have the function alphabetShift(str) take the str parameter | |
* being passed and modify it using the following algorithm. | |
* Replace every letter in the string with the letter following it | |
* in the alphabet (ie. c becomes d, z becomes a). Then capitalize | |
* every vowel in this new string (a, e, i, o, u) and finally return | |
* this modified string. | |
*/ | |
/* -- Examples -- |
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
/* mergeSort | |
* | |
* basic idea is as follows: | |
* break an array of integrers into pieces recursively | |
* and merges it back together using its sorted pieces | |
* | |
* this implementation uses "take from the front put in | |
* the back" logic while merging | |
* | |
* find diagram at http://quiz.geeksforgeeks.org/merge-sort/ |
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
const linearRegression = (data, y_attr, x_attr) => { | |
//separate data into x and y sets | |
let y_data = []; | |
let x_data = []; | |
for (let i = 0; i < data.length; i++) { | |
y_data.push(data[i][y_attr]); | |
x_data.push(data[i][x_attr]); |
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
# Place in your project here: .git/hooks/pre-commit | |
# Runs all cops on newly added files | |
# Runs standard cops on files that have been modified | |
#!/usr/bin/env ruby | |
require 'rubocop' | |
def get_files(selector) |
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
# If you want to add to your list, you can sniff using a binding.pry | |
# Look at the ActionDispatch::Http::UploadedFile object's Content-Type in the @header variable | |
validates_attachment :attachment, | |
allow_blank: false, | |
content_type: { content_type: ['image/jpg', #image | |
'image/jpeg', #image | |
'image/gif', #image | |
'image/png', #image | |
'application/pdf', #pdf |
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
# run from console with `rails runner /path/to/this/file.rb` | |
# a timestamped file is placed in a Rails' app's tmp folder | |
require 'csv' | |
def file_path(name_of_file) | |
Rails.root.join('tmp', "#{name_of_file}_#{sanitize_time(Time.zone.now)}.csv") # don't edit name set on line 22 | |
end | |
def sanitize_time(time) |