Skip to content

Instantly share code, notes, and snippets.

View jgaskins's full-sized avatar

Jamie Gaskins jgaskins

View GitHub Profile
@jgaskins
jgaskins / dependency_requires.rb
Created November 17, 2016 16:27
See how long it takes to load each dependency
# These don't load properly with this technique, so we preload them if the app
# needs them. :-(
require 'psych'
require 'bigdecimal'
alias zomg_require require
auto_create_hash = proc do |h,k|
hash = h[k] = {}
hash.default_proc = auto_create_hash
@jgaskins
jgaskins / app.rb
Last active February 16, 2019 13:36
React Router v4-style routing in Clearwater
require 'opal'
require 'clearwater'
require 'routing'
class Layout
include Clearwater::Component
include Routing
def render
div([
@jgaskins
jgaskins / components.rb
Last active February 16, 2019 13:36
React Router v4-style routing for Clearwater
require 'routing'
class Layout
include Clearwater::Component
include Routing
def render
div([
nav([
Link.new({ href: '/' }, 'Home'),
@jgaskins
jgaskins / omg.rb
Created October 17, 2016 18:11
Unindented rescue
def foo
florpty_doop
rescue => e
zomg_lol
end
foo
@jgaskins
jgaskins / attr_writer.rb
Last active August 31, 2016 17:18
Comparing types of dependency injection
class Widget
attr_writer :dependency
def dependency
@dependency ||= Dependency.new
end
end
widget = Widget.new
widget.dependency = StubbedDependency.new
@jgaskins
jgaskins / Gemfile
Created July 27, 2016 23:27
Clearwater app to fetch and render data from the GitHub API
source 'https://rubygems.org'
gem 'clearwater', '~> 1.0.0.rc1'
gem 'opal-rails'
gem 'grand_central'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
@jgaskins
jgaskins / method_object.rb
Last active May 30, 2016 22:02
Modules vs method objects
class OrderPriceCalculation
def initialize(order, tax_rate:)
@order = order
@tax_rate = tax_rate
end
def total
subtotal + sales_tax + fees
end
@jgaskins
jgaskins / index.js
Created May 4, 2016 04:51
virtual-dom `thunk.count` being used in diffing
const { h, create, diff, patch } = require('virtual-dom');
class App {
constructor (count) {
this.count = count
}
render () {
return h('div', {}, [
new MyThunk(this.count),
@jgaskins
jgaskins / 0-model
Created March 8, 2016 19:55
ActiveRecord has_secure_password
$ rails g model User email password_digest
@jgaskins
jgaskins / gantt_chart.rb
Created March 4, 2016 02:08
Nested render caching in Clearwater
class GanttChart
include Clearwater::Component
include Clearwater::CachedRender
attr_reader :tasks
def initialize(tasks)
@tasks = tasks
end