Skip to content

Instantly share code, notes, and snippets.

Brett Dudo dudo

Block or report user

Report or block dudo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View csv_serializer.rb
# frozen_string_literal: true
class CsvSerializer
attr_accessor :data
def initialize(serializer)
@serializer = serializer
@data = serializer&.serializable_hash&.dig(:data) || []
dudo / example.rb
Created Oct 6, 2018
Simple Concern to allow chain-able filtering of ActiveRecord scopes
View example.rb
class Example < ActiveRecord::Base
include Filterable
filterable scopes: %i(search bar)
scope :foo, ->(q) { where(foo: q) }
scope :bar, ->(q) { where(bar: q) }
View find_matching_lines_on_plot.rb
# 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
View pascal_triangle.rb
class PascalTriangle
attr_accessor :height
def initialize(height)
@height = height.to_i
def self.next_row(current_row)
([0] + current_row).zip(current_row + [0]).map{ |a| a.inject(:+) }
View post_fix_calculator.rb
class PostFixCalculator
attr_accessor :list, :original_list
def initialize(list)
@original_list = list
@list = list.split(' ')
def evaluation
View audio_spectrum.js
const audio = new AudioContext(),
sound = audio.createMediaStreamSource(stream),
analyser = audio.createAnalyser();
analyser.minDecibels = -60;
// microphone -> filter -> destination.
const frequencyData = new Uint8Array(analyser.frequencyBinCount).slice(0, 32),
spectrum = document.querySelector('#spectrum');
View tags.rb
class items
has_many :tags, through: :item_tags
has_many :item_tags
belongs_to :city
class cities
has_many_ :items
You can’t perform that action at this time.