This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from "stimulus" | |
export default class extends Controller | |
@get: (name, getter) -> | |
Object.defineProperty @::, name, | |
get: getter | |
configurable: true | |
@set: (name, setter) -> | |
Object.defineProperty @::, name, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module Fingerprinting | |
def full_fingerprint | |
generate_fingerprint( | |
ip_fingerprint, | |
browser_fingerprint | |
) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render TableComponent.new(@posts) do |t| | |
t.column("Title", &:title) | |
t.column("Author") { |post| post.author.name } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Okay | |
class Foo < Literal::Data | |
attribute :sizes, Array | |
end | |
# Better | |
class Foo < Literal::Data | |
attribute :sizes, Array(Symbol) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class Run | |
def initialize(files) | |
@files = files | |
end | |
def call | |
@files.each(&:process) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
def then_maybe | |
yield(self) || self | |
end | |
def then_if(condition) | |
condition ? yield(self) : self | |
end | |
def then_unless(condition) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
NewerOlder