Skip to content

Instantly share code, notes, and snippets.

View bradgessler's full-sized avatar

Brad Gessler bradgessler

View GitHub Profile
@bradgessler
bradgessler / posterous-importer.php
Created July 27, 2012 00:01
Posterous WordPress importer (this one makes sure that the links don't break)
<?php
/*
Plugin Name: Posterous Importer
Plugin URI: http://wordpress.org/extend/plugins/posterous-importer/
Description: Import posts, comments, tags, and attachments from a Posterous.com blog.
Author: Automattic, Brian Colinger, Peter Westwood, Daryl L. L. Houston
Author URI: http://automattic.com/
Version: 0.10
License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
@bradgessler
bradgessler / table_component.rb
Created March 3, 2024 21:56
Playing around with a table component
TableComponent.new @items do |table|
# Emmits a `thead > th` with "Name" and a `tbody > td` with the name of each item.
table.column("Name") { _1.name }
# Emmits a `thead > th` with "Name" and a `tbody > td` with the name of each item.
table.column(:name)
# Emmits a `thead > th` with "Interview Times" and a `tbody > th` with the name of each item.
table.column("Name").th(class: "bg-read-100") { show(_1, :name) }
@bradgessler
bradgessler / move.rb
Created March 1, 2024 00:41
Rename symbols and objects in a Rails project
#!/usr/bin/env ruby
require 'fileutils'
require "active_support/all"
# Check for arguments
unless ARGV.length == 2
puts "Usage: #{$PROGRAM_NAME} <original_class_name> <new_class_name>"
exit
end
@bradgessler
bradgessler / phlex-pdf.rb
Last active February 23, 2024 23:44
Phlex::PDF
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "prawn"
gem "zeitwerk"
gem "matrix"
end
@bradgessler
bradgessler / test.rb
Created February 9, 2024 20:52
Super duper forms
require "bundler/inline"
gemfile do
source 'https://rubygems.org'
gem 'phlex'
end
class Field < Phlex::HTML
def template
@bradgessler
bradgessler / version.rb
Last active February 8, 2024 03:07
Upgrade a method in place
class Foo
# Define the original render method
def render
puts "Foo#render"
end
end
module Overrides
def self.prepended(klass)
klass.alias_method :base_render, :render
@bradgessler
bradgessler / server.rb
Last active February 7, 2024 19:29
Bi-directional HTML
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "sinatra", "~> 3.1"
gem "nokogiri", "~> 1.15"
gem "puma"
end
require "sinatra"
@bradgessler
bradgessler / component_helper.rb
Last active February 1, 2024 20:15
Component helper
module ComponentHelper
def component(name, *args, **kwargs, &block)
render componentize(name).new(*args, **kwargs), &block
end
private
def componentize(name)
"#{name.to_s.classify}Component".constantize
end
end
@bradgessler
bradgessler / phlex_element.rb
Last active January 3, 2024 22:21
The Phlex::Element class makes creating simple Phlex components easier
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "phlex"
end
require "phlex/testing/view_helper"
include Phlex::Testing::ViewHelper