Skip to content

Instantly share code, notes, and snippets.

View joeldrapper's full-sized avatar
💖
Loving Ruby

Joel Drapper joeldrapper

💖
Loving Ruby
View GitHub Profile
@joeldrapper
joeldrapper / native.css
Last active April 13, 2017 12:22
Native Theme
.editor-content .editable#note-text-editor {
line-height: 1.6 !important;
font-family: -apple-system, BlinkMacSystemFont, 'avenir next', avenir, helvetica, 'helvetica neue', ubuntu, roboto, noto, 'segoe ui', arial, sans-serif !important;
padding: 21px;
}
/* General */
body {

Keybase proof

I hereby claim:

  • I am joeldrapper on github.
  • I am joeldrapper (https://keybase.io/joeldrapper) on keybase.
  • I have a public key ASCZ2b-hvm_0Cs0MyWXInpqRI__fqd5wVAZBNBUe0nHaiQo

To claim this, I am signing this object:

@joeldrapper
joeldrapper / formatter.coffee
Created September 26, 2022 18:34
Trix stuff
class @TrixFormatter extends @BaseObject
constructor: (editor) ->
@editor = editor
format: ->
@position = @editor.getPosition()
@text = @editor.getDocument().toString()
@before = @text.substr 0, @position
@after = @text.substr @position, @text.length
@character = @text.charAt(@position - 1)
@joeldrapper
joeldrapper / ar_spy.rb
Last active October 7, 2022 09:17
Active Record Spy
class Spy
def initialize(object)
@object = object
end
def respond_to_missing?(name)
@object.respond_to?(name)
end
def method_missing(name, *args, **kwargs, &block)
@joeldrapper
joeldrapper / object.rb
Last active October 20, 2022 15:28
Object yielders
class Object
def then_maybe
yield(self) || self
end
def then_if(condition)
condition ? yield(self) : self
end
def then_unless(condition)
@joeldrapper
joeldrapper / attribute_memoization.rb
Last active December 13, 2022 12:24
Attribute Memoization
module AttributeMemoization
def attr_accessor(*names, &block)
return super(*names) unless block_given?
attr_reader(*names, &block)
attr_writer(*names)
end
def attr_reader(*names, &block)
return super(*names) unless block_given?
@joeldrapper
joeldrapper / freeze.rb
Created April 17, 2023 14:49
Enforce frozen string literals when possible and output a list of problematic files
#!/usr/bin/env ruby
class Run
def initialize(files)
@files = files
end
def call
@files.each(&:process)
@joeldrapper
joeldrapper / packer.rb
Last active July 12, 2023 12:58
Paquito Job Packer
# frozen_string_literal: true
module Packer
# A special packer class for globally identifiable objects. It takes a global ID and packs it as a String, then rehydrates it as a GlobalID lookup.
class GloballyIdentifiable
def self.from_pack(uri)
GlobalID::Locator.locate(uri)
end
def initialize(identifiable)
@joeldrapper
joeldrapper / accordion_of_types.rb
Created November 29, 2023 14:44
Accordion of Literal types
# Okay
class Foo < Literal::Data
attribute :sizes, Array
end
# Better
class Foo < Literal::Data
attribute :sizes, Array(Symbol)
end
@joeldrapper
joeldrapper / example.rb
Last active January 25, 2024 06:57
Table component
render TableComponent.new(@posts) do |t|
t.column("Title", &:title)
t.column("Author") { |post| post.author.name }
end