Code Genome
C, Java, .NET, Clojure
Clock = Data.define :hours, :minutes do | |
def initialize(hours:, minutes:) | |
super hours: (hours + minutes / 60) % 24, minutes: minutes % 60 | |
end | |
def add_minutes(minutes) = self.class.new(hours, self.minutes + minutes) | |
def to_s = '%02d:%02d' % [hours, minutes] | |
end |
{ | |
"stay": { | |
"check_in": "2014-07-08", | |
"check_out": "2014-07-09", | |
"participants": { | |
"0": { | |
"variant_id": "2", | |
"count": "2" | |
}, | |
"1": { |
> Time.new(2022,11,6) + 3.hours | |
=> 2022-11-06 02:00:00 -0500 | |
> Time.new(2022,11,6) + 3.hours.in_days.days | |
=> 2022-11-06 02:00:00 -0500 | |
> Time.new(2022,11,6) + 24.hours.in_days.days | |
=> 2022-11-07 00:00:00 -0500 | |
> Time.zone.local(2022,11,6) + 3.hours | |
=> Sun, 06 Nov 2022 02:00:00 EST -05:00 | |
> Time.zone.local(2022,11,6) + 3.hours.in_days.days | |
=> Sun, 06 Nov 2022 03:00:00 EST -05:00 |
/* move middle part of top nav on the side */ | |
div[role="banner"] > div:nth-child(3) { | |
right: auto; | |
top: 70px; | |
} | |
/* remove extra padding from main nav */ | |
div[role="banner"] > div:nth-child(3) ul { | |
padding: 0; | |
} |
# see https://github.com/rails/rails/pull/31442 | |
require 'weakref' | |
module ActiveSupport | |
# This module provides an internal implementation to track descendants | |
# which is faster than iterating through ObjectSpace. | |
module DescendantsTracker | |
@@direct_descendants = {} |
# This script is taken from https://github.com/rails/rails/issues/32892#issuecomment-423376552 | |
require 'ap' | |
require 'json' | |
require 'set' | |
require 'cgi' | |
require 'byebug' | |
class Slot | |
attr_reader :info, :address_to_slot |
Enumerable.module_eval do | |
def frequency | |
Hash.new(0).tap do |h| | |
each { |v| h[v] += 1 } | |
h.define_singleton_method(:highest) { sort_by(&:last).last.first } | |
h.define_singleton_method(:lowest) { sort_by(&:last).first.first } | |
end | |
end | |
end |
Object.class_eval do | |
def hierarch(n = 1) | |
klass_and_ancestry = self.class.ancestors[(n - 1)..-1] | |
klass, *ancestry = klass_and_ancestry | |
to_klass_methods = methods - ancestry.flat_map(&:instance_methods) | |
"#{klass}: #{to_klass_methods}" | |
end | |
end |
Hash.class_eval do | |
def transpose | |
reduce({}) do |rmemo, (rk, rv)| | |
rv.reduce(rmemo) do |cmemo, (ck, cv)| | |
cmemo[ck] ||= {} | |
cmemo[ck][rk] = cv | |
cmemo | |
end | |
rmemo | |
end |