Skip to content

Instantly share code, notes, and snippets.

View leastbad's full-sized avatar
🤠
Keeping it real for the rest of us.

leastbad leastbad

🤠
Keeping it real for the rest of us.
View GitHub Profile
@leastbad
leastbad / select_controller.js
Created June 10, 2021 23:53
SlimSelect Stimulus wrapper
import ApplicationController from '../application_controller'
import SlimSelect from 'slim-select'
export default class extends ApplicationController {
static values = {
limit: Number,
placeholder: String,
searchText: String,
searchingText: String,
reflex: String,
@leastbad
leastbad / application_controller.rb
Created March 25, 2021 16:05
Notifications are fun (Devise, Bootstrap 5, Notyf, FontAwesome)
class ApplicationController < ActionController::Base
include CableReady::Broadcaster
include Toastable
end
@leastbad
leastbad / application_controller.rb
Created November 20, 2020 20:19
Nate's flash setup
add_flash_types :primary, :secondary, :success, :danger, :warning, :info, :light, :dark
@leastbad
leastbad / timer_controller.js
Created July 17, 2021 20:13
timer_controller.js WIP
import { Controller } from 'stimulus'
export default class extends Controller {
static values = {
idleTimeoutMs: 30000,
currentIdleTimeMs: Number,
checkIdleStateRateMs: 250,
isUserCurrentlyOnPage: true,
isUserCurrentlyIdle: Boolean,
currentPageName: 'default',
@leastbad
leastbad / README.md
Last active July 4, 2021 00:33
mrujs w/ cable-car plugin

"dependencies": { "cable_ready": "5.0.0-pre1", "mrujs": "^0.3.0-beta.25" }

@leastbad
leastbad / Gemfile
Last active July 2, 2021 00:43
Webpacker 5 config
gem "webpacker", "~> 5.4.0"
@leastbad
leastbad / struct.rb
Created May 7, 2021 10:15 — forked from KonnorRogers/struct.rb
Using hashes for structs
# using a predefined hash
hash = { field1: "foo", field2: "bar" }
HashStruct = Struct.new(*hash.keys, keyword_init: true)
hash_struct = HashStruct.new(hash)
hash_struct.field1 # => "foo"
hash_struct.field2 # => "bar"
hash_struct.field3 # => ERROR!
@leastbad
leastbad / application.js
Created April 21, 2021 17:14
CableReady + Notyf
// partial file
// you will need to `yarn add notyf`
import CableReady from 'cable_ready'
import { Notyf } from 'notyf'
import flash from '../shared/notyf'
CableReady.DOMOperations.toast = operation => {
new Notyf(flash).open(operation)
}
@leastbad
leastbad / README.md
Last active April 15, 2021 22:30
Mapbox controller

Using Stimulus v2, FontAwesome 5, Bootstrap 5, and Mapbox

You can grab a copy of marker.svg here - put it in your /public folder.

@leastbad
leastbad / remove_in_iframe.js
Created April 15, 2021 14:58
CableReady custom operations
import CableReady from 'cable_ready'
import { dispatch } from 'cable_ready/javascript/utils'
CableReady.DOMOperations.removeSubelement = operation => {
const { element, subElement } = operation
dispatch(element, 'cable-ready:before-remove-subelement', operation)
element.contentDocument.querySelector(subElement).remove()
dispatch(element, 'cable-ready:after-remove-subelement', operation)
}