Skip to content

Instantly share code, notes, and snippets.

Avatar

Jasmine F dubistdu

View GitHub Profile
View pyramid array in Ruby
def pyramid(numbers)
Array.new(numbers) { |i| [1] * (i + 1) }
end
View pyramid array JS
function pyramid(n) {
return Array(n).fill(1).map((elemeent, index) => Array(index + 1).fill(1));
}
View min_max_min ruby
def min_min_max(array)
sorted = array.sort
sorted_all=[*sorted.first..sorted.last]
[sorted.first, (sorted_all-sorted).min, sorted.last]
end
View split_and_add_both_sides
def split_and_add(arr, n)
n.times { arr.length.odd? ? arr.unshift(0) : arr
arr = arr.each_slice(arr.length/2).to_a.transpose.map { |x| x.sum }
}
arr
end
@dubistdu
dubistdu / perimeter_of_squares_in_a_rectangle.md
Last active May 8, 2019
perimeter_of_squares_in_a_rectangle
View perimeter_of_squares_in_a_rectangle.md

ruby

def perimeter(n)
  num = [0,1]
  i = 0
  until i == n do
    num << num[i] + num [i+1]
    i += 1
  end
View soduku.md
def validSolution(board)
  return false if board.flatten.include?(0)
  board.map {|a| a.uniq.count == 9}.include?(false) ? false : board
  square_of_3 = board.map { |a| a.each_slice(3).to_a }
  s1=square_of_3[0][0].zip(square_of_3[1][0],square_of_3[2][0])
  s2=square_of_3[0][1].zip(square_of_3[1][1],square_of_3[2][1])
  s3=square_of_3[0][2].zip(square_of_3[1][2],square_of_3[2][2])
  
  s4=square_of_3[3][0].zip(square_of_3[4][0],square_of_3[5][0])
View gist:d64f8a4c560e8507dfd0efd234cbc373

*JS

const solution = (number) => {
  return (number < 1 ? 0 : [...Array(number).keys()].filter(num => num % 3 == 0 || num % 5 == 0).reduce((a,b) => a+b));
}

*ruby

@dubistdu
dubistdu / terminal_flicker.md
Last active Oct 4, 2018
Troubleshoot - Terminal Gone!
View terminal_flicker.md

Issue I had was terminal flashing and disappearing after removing Zsh while Terminal app was still running

Solution
  • Before removing shell, I should have switched to bash using chsh -s /bin/bashsince I can't uninstall zsh as I was using zsh!

    • It should have been chsh -s /bin/bash
    • to swich back to bash temporarily
    • then uninstall / reinstall zsh
    • then chsh -s /usr/local/bin/zsh to switch back to zsh
  • Since I didn't switch to bash first....

@dubistdu
dubistdu / git commands.md
Last active Sep 29, 2018 — forked from scootcho/git commands.md
git commands #git #commands
View git commands.md

initialize git depository in the current directory

git init .

display the git remote/origin

cat .git/config
@dubistdu
dubistdu / RAILS_5_CHEATSHEET.md
Created Sep 17, 2018 — forked from harrietty/RAILS_5_CHEATSHEET.md
Ruby on Rails 5 Cheatsheet
View RAILS_5_CHEATSHEET.md

Ruby on Rails Cheatsheet (5.1)

Architecture

RVM

$ rvm list - show currently installed Rubies

You can’t perform that action at this time.