This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const audio = new AudioContext(), | |
sound = audio.createMediaStreamSource(stream), | |
analyser = audio.createAnalyser(); | |
analyser.minDecibels = -60; | |
// microphone -> filter -> destination. | |
sound.connect(analyser); | |
analyser.connect(audio.destination); | |
const frequencyData = new Uint8Array(analyser.frequencyBinCount).slice(0, 32), | |
spectrum = document.querySelector('#spectrum'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. | |
# y = mx + b (Equation of a straight line) | |
class Plot | |
attr_accessor :coordinates | |
def initialize(points=[]) | |
@coordinates = points |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PascalTriangle | |
attr_accessor :height | |
def initialize(height) | |
@height = height.to_i | |
end | |
def self.next_row(current_row) | |
([0] + current_row).zip(current_row + [0]).map{ |a| a.inject(:+) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostFixCalculator | |
attr_accessor :list, :original_list | |
def initialize(list) | |
@original_list = list | |
@list = list.split(' ') | |
end | |
def evaluation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class CsvSerializer | |
attr_accessor :data | |
def initialize(serializer) | |
@serializer = serializer | |
@data = serializer&.serializable_hash&.dig(:data) || [] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApiConstraint | |
def initialize(options) | |
@version = options[:version] | |
@default = options[:default] | |
end | |
def matches?(request) | |
@default || request.headers.fetch(:accept).include?("version=#{version}") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FastJsonapi | |
module ErrorSerializer | |
extend ActiveSupport::Concern | |
included do | |
include FastJsonapi::ObjectSerializer | |
attr_accessor :with_root_key | |
set_id :title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def encrypt(k) | |
lower_alphabet = [*'a'..'z'] | |
lower_translation_map = lower_alphabet.zip(lower_alphabet.rotate(k%26)).to_h | |
upper_alphabet = [*'A'..'Z'] | |
upper_translation_map = upper_alphabet.zip(upper_alphabet.rotate(k%26)).to_h | |
translation_map = lower_translation_map.merge(upper_translation_map) | |
chars.map { |char| translation_map[char] || char }.join | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Return a boolean indicating whether the number is a palindrome. Raises a | |
# TypeError if the argument is not an integer | |
# | |
# Caveat: Try to accomplish this without converting the number to a string. | |
# The goal is to understand your approach to a problem with constraints | |
# rather than seeing how quickly you can jump to an easy solution. | |
# | |
# Example | |
# palindrome?(1001) => true | |
# palindrome?(1234) => false |
OlderNewer