Skip to content

Instantly share code, notes, and snippets.

Avatar

Brett Dudo dudo

View GitHub Profile
View useViewportSize.js
import { useState, useLayoutEffect } from "react";
export const useViewportSize = (debounceTime = 250) => {
const [viewportSize, setViewportSize] = useState({
width: undefined,
height: undefined
});
const debounce = (fn, ms) => {
let timer;
return () => {
View esbuild.build.js
const { build } = require('esbuild');
const manifestPlugin = require('esbuild-plugin-manifest');
const options = {
entryPoints: ['src/index.js'],
entryNames: '[dir]/[name]-[hash]',
outdir: 'dist',
bundle: true,
minify: true,
plugins: [manifestPlugin()],
View t9.rb
require 'set'
module Trie
class T9
attr_reader :root
def initialize
@root = Hash.new
end
@dudo
dudo / wrapper.rb
Last active Jun 30, 2021
Wrap a method with a macro. Allow for procs to be passed.
View wrapper.rb
module Wrapper
def wrap(method_name, options: {})
proxy = Module.new
proxy.define_method(method_name) do |*args, &block|
options = instance_exec(&options) if options.is_a?(Proc)
target = is_a?(Module) ? "#{self}." : "#{self.class}#"
puts "#{target}#{method_name} is about to be called. `wrap` options #{options}"
super *args, &block
end
self.prepend proxy
@dudo
dudo / .env
Last active Dec 4, 2020
docker-compose example
View .env
# https://github.com/bkeepers/dotenv
COMPOSE_PROJECT_NAME=my_app
REDIS_URL=redis://redis:6379
PGHOST=db
PGUSER=postgres
PGPASSWORD=postgres
View jeep.md

Engagement

Jeep

  • 2006 Wrangler Unlimited (LJ)
    • 4.0L
    • 6 speed manual

Drivetrain

View api_client_spec.rb
RSpec.describe Api::ClientBase do
subject(:api) { described_class.new(config) }
let(:scheme) { 'https' }
let(:host) { Faker::Internet.domain_name }
let(:port) { 3000 }
let(:config) do
{
'scheme' => scheme,
View 4_must_know_functions.md

The 4 simple math functions

Lerp

Lerp is the acronym for linear interpolation. The idea is very simple, you have 2 values, and you want to “walk” between those values by a factor.

func lerp = (start, end, factor) => 
  start * (1-factor) + end * factor;
View acts_as_csv.rb
require 'csv'
require 'activerecord-import'
module ActsAsCsv
extend ActiveSupport::Concern
class_methods do
def filename
if const_defined? :CSV_FILENAME
self::CSV_FILENAME
View enum_I18n_helper.rb
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
def self.human_enum_name(enum_name, enum_value)
I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{enum_name.to_s.pluralize}.#{enum_value}")
end
def self.human_enum_collection(enum_name)
send(enum_name.to_s.pluralize).keys.map do |val|
[human_enum_name(enum_name, val), val]