Skip to content

Instantly share code, notes, and snippets.

View omedale's full-sized avatar
🎯
Focusing

Medale oluwafemi omedale

🎯
Focusing
  • Lagos, Nigeria
View GitHub Profile
@omedale
omedale / binary_tree.rb
Created May 7, 2020 09:45
Binary tree
class BinarySearchTree
class Node
attr_reader :key, :left, :right
#On initialization, the @key variable is set. This is used in the insert method below as the parent for the @left and @right nodes.
def initialize( key )
@key = key
@left = nil
@right = nil
end
@omedale
omedale / import_and_parse_remote_csv_rails.md
Created November 21, 2019 09:51 — forked from wrburgess/import_and_parse_remote_csv_rails.md
Import and parse remote csv with Rails
require 'csv'
require 'open-uri'

csv_text = open('http://www.vvv.hh.yyy.ggg/~hhhh/uuuu.csv')
csv = CSV.parse(csv_text, :headers=>true)
csv.each do |row|
  puts row
end
@omedale
omedale / readline_bundle_image_not_found.md
Created August 6, 2019 08:34 — forked from zulhfreelancer/readline_bundle_image_not_found.md
How to fix 'readline.bundle image not found' problem?

If you get error like this:

Running via Spring preloader in process 7662
/Users/zulh/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require': dlopen(/Users/zulh/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError)
  Referenced from: /Users/zulh/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle
  Reason: image not found - /Users/zulh/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle
	from /Users/zulh/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
	from /Users/zulh/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
	from /Users/zulh/.rvm/gems/ruby-2.3.1@useradmin/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
@omedale
omedale / launch.sh
Created July 29, 2019 10:58 — forked from ltfschoen/launch.sh
Shell script that generates separate Terminal tabs to run a Ruby on Rails web server then automatically opens associated webpage in your web browser
#!/bin/bash
# File: ~/launch.sh
# Original Code Reference: http://dan.doezema.com/2013/04/programmatically-create-title-tabs-within-the-mac-os-x-terminal-app/
# New-BSD License by Original Author Daniel Doezema http://dan.doezema.com/licenses/new-bsd/
# Modified by Luke Schoen in 2017 to include loading new tabs for Rails Server and automatically open webpage in browser.
# References: https://developer.apple.com/library/content/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html
class Computer
def initialize(computer_id,data_source)
@id = computer_id
@data_source = data_source
end
def mouse
info = @data_source.get_mouse_info(@id)
price = @data_source.get_mouse_price(@id)
result = "Mouse:#{info}($#{price})"
@omedale
omedale / create_slug.php
Created May 13, 2019 08:54
Generate slug
public static function createSlug($str, $delimiter = '-'){
$slug = strtolower(trim(preg_replace('/[\s-]+/', $delimiter, preg_replace('/[^A-Za-z0-9-]+/', $delimiter, preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $str))))), $delimiter));
return $slug;
}
@omedale
omedale / inversion.rb
Created April 22, 2019 20:43
Dependency Inversion Principle
# Violation of the Dependency Inversion Principle in Ruby
# The class Printer depends on classes PdfFormatter and HtmlFormatter which are low-level objects
class Printer
def initialize(data)
@data = data
end
def print_pdf
PdfFormatter.new.format(@data)
end
@omedale
omedale / liskov.rb
Last active April 22, 2019 20:13
Liskov Substitution Principle
class Rectangle
attr_accessor :height, :width
def calculate_area
width * height
end
end
class Square < Rectangle
def width=(width)
@omedale
omedale / open-close.rb
Last active April 30, 2019 10:37
Open-Close Principle
# This is a bad solution that violates open-closed principle
class Document
def initialize(path, doc_type)
@path = path
@doc_type = doc_type
end
def parse
case doc_type
when :docx
#Violation of the Single Responsibility Principle in Ruby
class FinancialReportMailer
def initialize(transactions, account)
@transactions = transactions
@account = account
@report = ''
end
def generate_report
@report = "Full Transaction History -> #{@transactions}"