Skip to content

Instantly share code, notes, and snippets.

View JosephDunivan's full-sized avatar
🏠
Working from home

Little Red JosephDunivan

🏠
Working from home
View GitHub Profile
@JosephDunivan
JosephDunivan / gist:11002040f7cec4d0f6ff6a5901b3e60c
Created March 9, 2019 05:34
React Native Clear Cache Yarn
watchman watch-del-all && rm yarn.lock && rm -rf node_modules && rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/haste-map-* && yarn
@JosephDunivan
JosephDunivan / git_cheat-sheet.md
Created September 7, 2018 16:29 — forked from GBspace/git_cheat-sheet.md
git commandline cheat-sheet
@JosephDunivan
JosephDunivan / Cut_array_in_half.rb
Created May 16, 2017 21:01
Ruby Cuts and array in half and nest it in itself. Divides and Array in half.
#Ruby
#cuts array in half and nest in new array
#can be kept as an Enumerator
#useful for creating buckets for dynamic programming
#useful for finding palidromes
#arrays can be called individually using input[0] or input[1]
def cut_in_half(input)
input.each_cons(input.length/2).to_a
end
@JosephDunivan
JosephDunivan / adjacentElementsProduct.rb
Last active May 4, 2021 15:08
Ruby finds the largest product of two adjacent numbers in an array in linear time O(1)
#finds the largest product of two adjacent numbers in an array
def adjacentElementsProduct(inputArray)
inputArray.each_cons(2).map { |x, y| x*y }.max
end
@JosephDunivan
JosephDunivan / largest_number_of_n_digits.rb
Last active May 16, 2017 21:04
Calculates the largest number possible given n digits.
def largestNumber(n)
new_array = Array.new(n, 9)
new_array.join.to_i
end
@JosephDunivan
JosephDunivan / Adds Digits of an Integer.rb
Last active May 16, 2017 21:04
Ruby Adds Digits of An Integer
def add_digits(n)
#maps characters of a string and converts it back to integers in an array
sum = n.to_s.chars.map(&:to_i)
#collapses the array by adding elements together. Same as inject.
sum.reduce(:+)
end
@JosephDunivan
JosephDunivan / centuryFromYear.rb
Last active June 15, 2022 10:39
centuryFromYear in Ruby
def centuryFromYear(year)
#solution requires us find out if the century has a remainder of 0 or not.
#we can remove the remainder from the year to get a clean number since centuries happen in multiples of 100
if (year % 100) == 0
year/100
else
(year - (year % 100))/100 + 1
end
end