Skip to content

Instantly share code, notes, and snippets.

View jgaskins's full-sized avatar

Jamie Gaskins jgaskins

View GitHub Profile
@jgaskins
jgaskins / example.rb
Created July 5, 2017 22:42
React Router v4-style routing
require 'opal'
require 'clearwater'
require 'routing'
class Layout
include Clearwater::Component
include Routing
def render
div([
@jgaskins
jgaskins / app.rb
Last active September 12, 2018 13:04
Ryan Florence's "Compound Components" in Clearwater
require 'opal'
require 'clearwater'
require 'clearwater/memoized_component'
class Layout
include Clearwater::Component
def render
div([
Tabs.memoize(
@jgaskins
jgaskins / foo.js
Created June 29, 2017 14:04
Objects as curried functions
class Foo {
constructor(bar) { this.bar = bar }
getBar() { return this.bar }
setBar(newBar) { this.bar = newBar }
}
function FuncFoo(bar) {
function getBar() { return bar }
function setBar(newBar) { bar = newBar }
@jgaskins
jgaskins / time_travel.rb
Last active September 12, 2018 13:05
Time travel component for Clearwater+GrandCentral
class TimeTravel
include Clearwater::Component
# @param store [GrandCentral::VersionedStore]
def initialize(store)
@store = store
end
def render
div([
@jgaskins
jgaskins / jbuilder_controller.rb
Last active May 12, 2017 18:48
jbuilder vs non-jbuilder examples
# app/controllers/messages_controller.rb
class MessagesController < ApplicationController
def show
message = Message.find(params[:id])
respond_to do |format|
format.json { render :show, locals: { message: message } }
end
end
end
@jgaskins
jgaskins / episode.rb
Last active March 9, 2017 02:40
Parse a Podcast feed into episodes
class Episode
def self.from_rss_feed(url)
xml = Nokogiri.parse(Net::HTTP.get(URI(url)))
xml.xpath('//channel/item').map do |item|
new(
title: item.at_xpath('title').text,
subtitle: item.at_xpath('itunes:subtitle').text,
link: item.at_xpath('link').text,
audio_url: item.at_xpath('enclosure')[:url],
duration: item.at_xpath('itunes:duration').text
@jgaskins
jgaskins / toggle.rb
Created January 27, 2017 15:39
Stateful Clearwater components using nested Clearwater apps
# Wrapper for a UI component that needs to maintain its own state
class Toggle
include Clearwater::BlackBoxNode
attr_reader :app, :component :state
def initialize(state=false)
@state = state
end
@jgaskins
jgaskins / hash.rb
Created January 17, 2017 19:14
Pure-Ruby port of MRI's Hash class
class MyHash
include Enumerable
def initialize(data=nil, capacity=11)
@capacity = capacity
@data = Array.new(capacity) { [] }
@keys = []
return unless data
data.each do |key, value|
@jgaskins
jgaskins / app.rb
Last active February 16, 2019 13:35
Compositional Components with Clearwater
require 'opal'
require 'clearwater'
require 'profile_page'
class Layout
include Clearwater::Component
def render
ProfilePage.new('yoxtb')
@jgaskins
jgaskins / keybase.md
Created November 28, 2016 16:20
Keybase identity

Keybase proof

I hereby claim:

  • I am jgaskins on github.
  • I am jgaskins (https://keybase.io/jgaskins) on keybase.
  • I have a public key ASCed-Umwz9z8RWPBYomPslpI7TsIMEXNySBh0B0pVOcrAo

To claim this, I am signing this object: