Skip to content

Instantly share code, notes, and snippets.

View onelharrison's full-sized avatar

Onel Harrison onelharrison

View GitHub Profile
@onelharrison
onelharrison / your_order_please.py
Created July 9, 2017 03:34
Your order, please
"""
# Your order, please
#
# Sort a given string. Each word in the String will contain a single number. This number is the position the
# word should have in the result.
#
# Note: Numbers can be from 1 to 9. So 1 will be the first word (not 0).
#
# If the input String is empty, return an empty String. The words in the input String will only contain valid
# consecutive numbers.
@onelharrison
onelharrison / 1_public_and_private_instance_methods.rb
Last active December 27, 2017 23:07
Code snippets showing how to define public and private instance and class methods in Ruby.
class Car
attr_reader :mileage
def initialize
@mileage = 0
end
def drive
update_mileage
end
@onelharrison
onelharrison / public_class_method_v1.rb
Created December 27, 2017 23:09
Code snippet showing how to define public class methods in Ruby.
class Toyota < Car
def self.name
"Toyota #{superclass}"
end
end
# => Toyota.name
# "Toyota Car"
@onelharrison
onelharrison / public_and_private_instance_methods.rb
Created December 27, 2017 23:11
Code snippet showing how to define public and private instance methods in Ruby.
class Car
attr_reader :mileage
def initialize
@mileage = 0
end
def drive
update_mileage
end
@onelharrison
onelharrison / public_class_method_v2.rb
Created December 27, 2017 23:14
Code snippet showing how to define public class methods in Ruby.
class Toyota < Car
class << self
def name
"Toyota #{superclass}"
end
end
end
# => Toyota.name
# "Toyota Car"
@onelharrison
onelharrison / private_class_method_v1.rb
Created December 27, 2017 23:17
Code snippet showing an incorrect attempt to define a private class method in Ruby.
class Toyota < Car
def self.name
self.i_am
end
private
def self.i_am
"Toyota #{superclass}"
end
@onelharrison
onelharrison / private_class_method_v2.rb
Created December 27, 2017 23:20
Code snippet showing how to define private class methods in Ruby.
class Toyota < Car
class << self
def name
i_am
end
private
def i_am
"Toyota #{superclass}"
@onelharrison
onelharrison / private_class_method_v3a.rb
Last active December 27, 2017 23:34
Code snippet showing how to define private class methods in Ruby.
class Toyota < Car
def self.name
self.i_am
end
private_class_method def self.i_am
"Toyota #{superclass}"
end
end
@onelharrison
onelharrison / private_class_method_v3b.rb
Created December 27, 2017 23:24
Code snippet showing how to define private class methods in Ruby.
class Toyota < Car
def self.name
self.i_am
end
def self.i_am
"Toyota #{superclass}"
end
def self.do_something
@onelharrison
onelharrison / moment_undefined.js
Created January 27, 2018 15:39
Code snippet showing undefined being passed to the moment function.
function getDateString() {
let dateString;
// ...
// processing that sometimes resulted
// in dateString evaluating to undefined
return dateString;
}
const dateString = getDateString();
moment(dateString);