Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View dcyoung-dev's full-sized avatar
🥞
Full Stacking

David Young dcyoung-dev

🥞
Full Stacking
View GitHub Profile
@dcyoung-dev
dcyoung-dev / auto_save_controller.js
Created March 23, 2023 10:11
Using lodash debounce function in a Stimulus controller
import {Controller} from "@hotwired/stimulus"
import {debounce} from "lodash/function";
// Connects to data-controller="auto-save"
export default class extends Controller {
initialize() {
this.autosave = debounce(this.autosave, 200).bind(this)
}
autosave(event) {
@dcyoung-dev
dcyoung-dev / active_link_to.rb
Last active April 10, 2023 16:54
An `active_link_to` helper that adds the `.active` class and sets `aria-current="page"`
module TurboFrameHelpers
def turbo_frame_id(*ids)
ids.map { |id| id.respond_to?(:to_key) ? ActionView::RecordIdentifier.dom_id(id) : id }.join("_")
end
end
RSpec.configure do |config|
config.include TurboFrameHelpers
end
@dcyoung-dev
dcyoung-dev / capybara.rb.sample
Last active January 28, 2022 10:44
Setup script and templates for installing and configuring RSpec
require 'capybara'
@dcyoung-dev
dcyoung-dev / .tool-versions
Last active February 21, 2022 16:57
Rails Scripts
ruby 3.0.1
nodejs 16.0.0
@dcyoung-dev
dcyoung-dev / Procfile.dev
Last active June 18, 2021 10:56
Development Procfile
web: bundle exec rails server
worker: bundle exec sidekiq
webpack: bundle exec bin/webpack-dev-server
@dcyoung-dev
dcyoung-dev / netlify.toml
Created May 24, 2021 15:12
Opt-out of Google's FLoc tracking on Netlify
# Stop Google's FLoc https://andycroll.com/ruby/opt-out-of-google-floc-tracking-on-netlify
[[headers]]
for = "/*"
[headers.values]
Permissions-Policy = "interest-cohort=()"
@dcyoung-dev
dcyoung-dev / custom-jquery-functions.html
Created April 8, 2021 13:44
Create your own custom jQuery functions
<script>
// Declaring a new jQuery function
(function ($) {
$.fn.newSuperCoolFunction = function () {
return this.each(function (_, selector) {
var elements = $(selector)
elements.each(function (_, elementSelector) {
var element = $(elementSelector);
element.addClass('super-cool')
@dcyoung-dev
dcyoung-dev / fizz_buzz.rb
Created December 15, 2020 07:45
Fizz Buzz solution in Ruby
# FizzBuzz
def add_trigger_word(number, factor, output_array, word)
output_array << word if number % factor == 0
output_array
end
word_map = {
3 => "Fizz",
5 => "Buzz",
@dcyoung-dev
dcyoung-dev / README.md
Last active April 1, 2020 10:01
CSS Rules Draft

CSS Rules for Harmonious Living

Sizing

  • Prefer to use em/rem rather than px
    • rem is the browser's default size - usually equal to 16px
    • em is relative to it's parent's sizing
  • Consider which sizing makes most sense - should the sizing increase if the parent's increases (em) or should it remain constant (rem).

Colours

  • Always move colours into a separate file and reference through CSS variables var()