Skip to content

Instantly share code, notes, and snippets.

View willcosgrove's full-sized avatar
🏠
Working from home

Will Cosgrove willcosgrove

🏠
Working from home
View GitHub Profile
@willcosgrove
willcosgrove / test.rb
Created February 9, 2024 21:27 — forked from bradgessler/test.rb
Super duper forms
require "bundler/inline"
gemfile do
source 'https://rubygems.org'
gem 'phlex'
end
class Field < Phlex::HTML
def template
# This concern will augment the default rendering behavior of a controller. If
# no matching view template is found for an action, a Phlex view will be
# searched for. First at a constant defined within the controller that matches
# the name of the action (`Edit`, `Index`, etc), and then within the views
# folder defined under `#{controller_name}::#{action_name}Page`
# (e.g. Admin::Bottles::IndexPage)
#
# If a matching Phlex view is found, it will be initialized with the defined
# instance variables that match it's own attributes (defined using the
# `attribute` macro).
@willcosgrove
willcosgrove / 0_example.md
Last active January 4, 2022 23:13
Copy the wordle as an emoji text chunk

Running the bookmarklet on a game screen like this:

CleanShot 2022-01-04 at 16 55 38@2x

Would yield this output on your clipboard:

🟨⬜⬜⬜⬜
⬜⬜🟨🟨⬜
🟨⬜🟨⬜🟨

Keybase proof

I hereby claim:

  • I am willcosgrove on github.
  • I am willcosgrove (https://keybase.io/willcosgrove) on keybase.
  • I have a public key ASCgfVUsESgwzlDDf7XB5Oui4uzbJyrKNcQZrVa3OISqQQo

To claim this, I am signing this object:

@willcosgrove
willcosgrove / client_id.rb
Created May 14, 2015 21:39
The ClientID concern is for facilitating a passthrough of client IDs, useful for reconciling created records with their non-ID'd client counterpart.
module ClientID
extend ActiveSupport::Concern
included do
attr_writer :cid
after_commit :_save_cid, on: :create, if: -> { @cid.present? }
end
def cid
Thread.current[_cid_key]
@willcosgrove
willcosgrove / application_helper.rb
Last active August 29, 2015 14:18
blank_or - View helper to render blank text if a value is blank, or ...
def blank_or(attribute, blank_text: "N/A", blank_test: :blank?)
if attribute.send(blank_test)
return blank_text
else
return yield(attribute) if block_given?
return attribute
end
end
class Sync.Server extends Sync.View
constructor: (@$el, @name) ->
@vue = new Vue
el: @$el[0]
data:
editing: false
Supplier Load (0.5ms) SELECT "suppliers".* FROM "suppliers" WHERE "suppliers"."name" = 'S. Rothe' LIMIT 1
PurchaseOrder Load (0.4ms) SELECT "purchase_orders".* FROM "purchase_orders" WHERE (("purchase_orders"."supplier_id" = 43 AND "purchase_orders"."created_at" = '2011-10-31 00:00:00')) LIMIT 1
Winery Load (0.7ms) SELECT "wineries".* FROM "wineries" WHERE "wineries"."name" = 'Robert Keenan' LIMIT 1
Wine Load (0.3ms) SELECT "wines".* FROM "wines" WHERE "wines"."wine_id" = 174385 LIMIT 1
(0.4ms) BEGIN
SQL (0.7ms) INSERT INTO "bottles" ("active", "active_on_winesearcher", "condition", "cost_in_cents", "created_at", "employee_purchase_price_in_cents", "last_sold_on", "marketing_text", "max_quantity_display", "name", "notes", "original_uploaded_quantity", "pick_location", "picture", "purchase_order_id", "purchase_source_type", "quantity", "retail_price_in_cents", "sku", "status", "stock_status", "updated_at", "wine_id", "winesearcher_display_name") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $1
Supplier Load (0.5ms) SELECT "suppliers".* FROM "suppliers" WHERE "suppliers"."name" = 'S. Rothe' LIMIT 1
PurchaseOrder Load (0.4ms) SELECT "purchase_orders".* FROM "purchase_orders" WHERE (("purchase_orders"."supplier_id" = 43 AND "purchase_orders"."created_at" = '2011-10-31 00:00:00')) LIMIT 1
Winery Load (0.7ms) SELECT "wineries".* FROM "wineries" WHERE "wineries"."name" = 'Robert Keenan' LIMIT 1
Wine Load (0.3ms) SELECT "wines".* FROM "wines" WHERE "wines"."wine_id" = 174385 LIMIT 1
(0.4ms) BEGIN
SQL (0.7ms) INSERT INTO "bottles" ("active", "active_on_winesearcher", "condition", "cost_in_cents", "created_at", "employee_purchase_price_in_cents", "last_sold_on", "marketing_text", "max_quantity_display", "name", "notes", "original_uploaded_quantity", "pick_location", "picture", "purchase_order_id", "purchase_source_type", "quantity", "retail_price_in_cents", "sku", "status", "stock_status", "updated_at", "wine_id", "winesearcher_display_name") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $1
@willcosgrove
willcosgrove / syntax_highlighting.py
Created April 17, 2012 17:40 — forked from norbajunior/syntax_highlighting.py
Ruby on Rails syntax highlight switcher for Sublime Text 2
import sublime, sublime_plugin
import os
class DetectFileTypeCommand(sublime_plugin.EventListener):
""" Detects current file type if the file's extension isn't conclusive """
""" Modified for Ruby on Rails and Sublime Text 2 """
""" Original pastie here: http://pastie.org/private/kz8gtts0cjcvkec0d4quqa """
def on_load(self, view):
filename = view.file_name()