Skip to content

Instantly share code, notes, and snippets.

View itzbernoulli's full-sized avatar

Ayodeji Oyinloye itzbernoulli

View GitHub Profile
@itzbernoulli
itzbernoulli / square_root
Created September 29, 2016 08:48
This code is meant to calculate the nearest possible value to the square-root of a number.
def mid(x,y)
midpoint = (x + y)/2.0
end
def sqrt(n,d)
lower_range = 0
higher_range = n
div = mid(higher_range,lower_range)
#midpoint = (higher_range + lower_range) / 2.0
@itzbernoulli
itzbernoulli / Array multiplication
Last active October 1, 2016 00:07
Prime number, array_multiplication and Cartesian planes
a = [2,4,5,6]
#product increment
times= 1
#starting value
start = 0
result = []
#loop through the array to get the product
a.each{|i| times = times * i}
def sort_asc(arr):
for y in range(len(arr)-1,0,-1):
for x in range(y):
if arr[x]>arr[x+1]:
temp = arr[x]
arr[x] = arr[x+1]
arr[x+1] = temp
return arr
def sort_desc(arr):
a = [[1,2,4,5],[6,7,8,9],[10,11,12,13],[14,15,16,17]]
def get_position(a,num)
length = a.length-1
(0..a.length).each do |i|
if a[i][a.length-1] >= num
(0..a.length).each do |j|
if a[i][j] == num
return i, j
end
#This code sorts through an array of tuples containing the start and end times of meetings
#then prints out all the available free time during the day in which a new meeting can be scheduled
#This code is written in Python
def free_hours(meeting_time):
start_time = 0
end_time = 0
start = False
end = False
free= []
@itzbernoulli
itzbernoulli / Alternate Sort
Created October 13, 2016 22:55
Another class activity
arr = [1,4,5,6,7,3,2]
#This is a program that creates an alternate sort for an array
def alternate_sort(arr):
f = sorted(arr)
d = []
for i in range(1,(len(arr)/2)+1):
d.append(f[i-1])
d.append(f[-i])
return d
@itzbernoulli
itzbernoulli / code.rb
Created May 31, 2020 00:07
Racing Car (hackerrank)
class Node
attr_reader :value
attr_accessor :right, :left
def initialize(value)
@value = value
@left =nil
@right =nil
end
@itzbernoulli
itzbernoulli / environment.js
Created July 17, 2020 01:34
Add the dollar symbol to reference jQuery in rails webpacker
const webpack = require('webpack')
environment.plugins.prepend('Provide',
new webpack.ProvidePlugin({
$: 'jquery/src/jquery',
jQuery: 'jquery/src/jquery'
})
)
module.exports = environment
@itzbernoulli
itzbernoulli / highlighted_html_creator.rb
Last active December 15, 2020 08:25
This is a Thymebase coding challenge to convert a block of strings to highlighted html
class HtmlCreator
require 'securerandom'
attr_reader :content, :highlights
def initialize(content, highlights = [])
@content = content
@highlights = highlights
end
def convert
regexmap = { /&/ => '&amp;', /</ => '&lt;', />/ => '&gt;' }
@itzbernoulli
itzbernoulli / heroku_pg_db_reset.md
Created December 27, 2021 10:01 — forked from zulhfreelancer/heroku_pg_db_reset.md
How to reset PG Database on Heroku (for Rails app)?

It's important to note that running this reset will drop any existing data you have in the application

How to reset PG Database on Heroku?

  • Step 1: heroku restart
  • Step 2: heroku pg:reset DATABASE (no need to change the DATABASE)
  • Step 3: heroku run rake db:migrate
  • Step 4: heroku run rake db:seed (if you have seed)

One liner