Skip to content

Instantly share code, notes, and snippets.

View danott's full-sized avatar
📈
Chart with upward trend

Dan Ott danott

📈
Chart with upward trend
View GitHub Profile
@danott
danott / feed.html
Created January 18, 2024 16:34
Hypothetical markup for HTML based feeds. Riffing on the ideas shared at https://blog.jim-nielsen.com/2024/rss-in-html/
<!DOCTYPE html>
<!--
This is hypothetical markup for HTML based feeds.
Riffing on the ideas shared at https://blog.jim-nielsen.com/2024/rss-in-html/
-->
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Dan Ott's HTML Feed</title>
<!-- Tell the machines that there's an HTML feed available at /feed.html -->
@danott
danott / html_rendering_test.rb
Created December 21, 2023 23:03
Embracing the grain of the web's <template> and <slot> tags for rendering declarative markup on the server.
class HtmlRenderingTest < Minitest::Test
CRUST = <<~HTML.strip
<!doctype html>
<html lang="en">
<head>
<title><server-side-slot name="title"><%= title %></server-side-slot></title>
<server-side-slot name="head"></server-side-slot>
<% meta.each do |name, content| %>
@danott
danott / main.rb
Created January 28, 2022 21:32
A WIP of codifying the Planning Center company calendar
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'repeatable', "= 1.0.0"
end
weekdays = Repeatable::Expression::Union.new(
Repeatable::Expression::Weekday.new(weekday: 1),
Repeatable::Expression::Weekday.new(weekday: 2),
@danott
danott / 99bottles_shameless_green.js
Last active September 2, 2021 18:19
My time boxed shameless green for Sandi Metz's 99 Bottles of OOP, JS Edition
import { downTo} from './helpers';
export class Bottles {
verse(number) {
return SONG.split('\n\n').map((v) => v.trim() + '\n').reverse()[number];
}
verses(begin, end) {
return downTo(begin, end).map(n => this.verse(n)).join('\n');
}
@danott
danott / react_helper.rb
Created October 5, 2019 21:09
A minimal Rails helper for rendering a React component into the DOM
module ReactHelper
def render_react_component(component:, props: {}, dom_id:)
<<-REACT_DOM_RENDER.strip_heredoc.squish.html_safe
ReactDOM.render(
React.createElement(#{sanitize(component)}, #{raw json_escape(props.to_json)}),
document.getElementById("#{sanitize(dom_id)}")
);
REACT_DOM_RENDER
end
end
@danott
danott / pre-commit
Last active July 23, 2024 21:51
A git hook that automatically formats JavaScript and Ruby code on commit
#!/bin/sh
# ./.git/hooks/pre-commit
.git/hooks/pre-commit-format-javascript
.git/hooks/pre-commit-format-ruby
@danott
danott / react_controller.js
Last active March 2, 2018 16:51
Someone will probably want this.
import { Controller } from "stimulus"
import ReactDOM from "react-dom"
import React from "react"
/* HTML
<div controller="react"
data-react-component="HelloWorld"
data-react-props="{ \"name\": \"Daniel\" }"
/>
*/
@danott
danott / _show.js.coffee
Last active June 29, 2017 01:53
An idea for page-specific sprinkles that automatically setup and teardown. Doubling down on Server Rendered JavaScript...
class Sprinkle
run: =>
document.addEventListener("turbolinks:load", @setup)
setup: =>
console.log "Sprinkle setup"
document.removeEventListener "turbolinks:load", @setup
document.addEventListener "turbolinks:before-cache", @teardown
teardown: =>

Question

Two intelligent, honest students are sitting together at lunch one day when their math teacher hands them each a card. "Your cards each have an integer on them," the teacher tells them. "The product of the two numbers is either 12, 15 or 18. The first to correctly guess the number on the other's card wins."

The first student looks at her card and says, "I don't know what your number is."

The second student looks at her card and says, "I don't know what your number is, either."

The first student then says, "Now I know your number."

@danott
danott / princes.rb
Created March 18, 2017 20:16
TDD'ing a Riddle
require "minitest/autorun"
def yes
true
end
def no
false
end