Skip to content

Instantly share code, notes, and snippets.

View cefaijustin's full-sized avatar

Justin Cefai cefaijustin

View GitHub Profile
@cefaijustin
cefaijustin / nomster logs
Created February 11, 2018 19:06
nomster logs
[Web Dev]: /vagrant/src/nomster $ heroku logs --tail
▸ heroku-cli: update available from 6.14.42-3ba878b to 6.15.24-e5de04c
2018-02-11T18:59:22.231712+00:00 app[web.1]: D, [2018-02-11T18:59:22.231639 #4] DEBUG -- : [32c68627-efc0-4131-bd9f-823a8b669ac4] (0.7ms) SELECT COUNT(*) FROM "comments" WHERE "comments"."user_id" = $1 AND "comments"."rating" = $2 [["user_id", 1], ["rating", "5_stars"]]
2018-02-11T18:59:22.233247+00:00 app[web.1]: D, [2018-02-11T18:59:22.233170 #4] DEBUG -- : [32c68627-efc0-4131-bd9f-823a8b669ac4] Comment Load (0.7ms) SELECT "comments".* FROM "comments" WHERE "comments"."user_id" = $1 [["user_id", 1]]
2018-02-11T18:59:22.234919+00:00 app[web.1]: D, [2018-02-11T18:59:22.234851 #4] DEBUG -- : [32c68627-efc0-4131-bd9f-823a8b669ac4] Place Load (0.6ms) SELECT "places".* FROM "places" WHERE "places"."user_id" = $1 [["user_id", 1]]
2018-02-11T18:59:22.237186+00:00 app[web.1]: D, [2018-02-11T18:59:22.237111 #4] DEBUG -- : [32c68627-efc0-4131-bd9f-823a8b669ac4] Comment Load (0.
class Bike
attr_accessor :brand, :color
def initialize(brand, color)
@brand = brand
@color = color
end
end
class Bike
attr_accessor :brand, :color
def initialize(brand, color)
@brand = brand
@color = color
end
end
module Luhn
def self.is_valid?(number)
# ----------------------------------------------------
#
# line 17 - take the number, convert it to a string
# and reverse it. '.chars' splits it by digit, then
@cefaijustin
cefaijustin / collatz.rb
Created May 12, 2018 20:25
Longest Collatz Sequence with comments.
# n → n/2 (n is even)
# n → 3n + 1 (n is odd)
# Write a method to determine a number's collatz sequence.
# Find the number (1 to 1,000,000) with the longest sequence.
# collatz method defined below with (n) as an argument.
def collatz(n)
"use strict";
var _ = {
join: (array, separator = ",") => {
var str = "";
for (var i = 0; i < array.length; i++) {
str += separator + array[i];
}
return str.substring(2);
}
// write a function that creates a black and white chess board.
function mineColor(line, number) {
if ((line === 'a' || line === 'c' || line === 'e' || line === 'g') && number % 2 == 0) {
return 'white';
} else if ((line === 'b' || line === 'd' || line === 'f' || line === 'h') && number % 2 != 0) {
return 'white';
} else {
return 'black';
}
@cefaijustin
cefaijustin / toWeirdCase.js
Created June 2, 2018 03:50
To Weird Case
// Write a function toWeirdCase (weirdcase in Ruby) that accepts a string, and returns the same string with all even indexed characters in each word upper cased, and all odd indexed characters in each word lower cased. The indexing just explained is zero based, so the zero-ith index is even, therefore that character should be upper cased.
// The passed in string will only consist of alphabetical characters and spaces(' '). Spaces will only be present if there are multiple words. Words will be separated by a single space(' ').
function toWeirdCase(string){
return string.split(' ').map(function(word){
return word.split('').map(function(letter, index){
if (index % 2 === 0) {
return letter.toUpperCase();
} else if (index % 2 != 0) {
@cefaijustin
cefaijustin / spinWords.js
Created June 2, 2018 03:59
Stop Spinning My Words
// Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present.
function spinWords(string){
return string.split(' ').map(function(word){
if (word.length >= 5) {
return word.split('').reverse().join('');
} else {
return word;
}
}).join(' ');
@cefaijustin
cefaijustin / tree.rb
Created June 14, 2018 02:09
Final Tree Traversal
class Tree
attr_accessor :payload, :children
def initialize(payload, children)
@payload = payload
@children = children
end
# depth_first returns nil if 11 isn't in the tree
def search_node(number)