Skip to content

Instantly share code, notes, and snippets.

View dudo's full-sized avatar
🤙

Brett Dudo dudo

🤙
View GitHub Profile
@dudo
dudo / tags.rb
Last active January 19, 2018 22:06
class items
has_many :tags, through: :item_tags
has_many :item_tags
belongs_to :city
end
class cities
has_many_ :items
end
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');
class PostFixCalculator
attr_accessor :list, :original_list
def initialize(list)
@original_list = list
@list = list.split(' ')
end
def evaluation
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(:+) }
# 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
@dudo
dudo / example.rb
Last active June 19, 2020 01:04
Simple Concern to allow chain-able filtering of ActiveRecord scopes
class Example < ActiveRecord::Base
include Filterable
filterable scopes: %i(search bar)
scope :foo, ->(q) { where(foo: q) }
scope :bar, ->(q) { where(bar: q) }
end
# frozen_string_literal: true
class CsvSerializer
attr_accessor :data
def initialize(serializer)
@serializer = serializer
@data = serializer&.serializable_hash&.dig(:data) || []
end
@dudo
dudo / app-constraints-api_constraint.rb
Last active September 15, 2019 23:59
rails api versioned
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
@dudo
dudo / kubernetes.local.md
Last active December 5, 2021 17:00
Tooling for Interacting with Kubernetes

Kubernetes local development

kubectl

Autocomplete

# Pundit
# Friendly ID
# FastJSON
module ActsAsResource
extend ActiveSupport::Concern
included do
include Pundit