Skip to content

Instantly share code, notes, and snippets.

Dan Ott danott

Block or report user

Report or block danott

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@danott
danott / pre-commit
Last active Jul 17, 2019
A git hook that automatically formats JavaScript and Ruby code on commit
View pre-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 Mar 2, 2018
Someone will probably want this.
View react_controller.js
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 Jun 29, 2017
An idea for page-specific sprinkles that automatically setup and teardown. Doubling down on Server Rendered JavaScript...
View _show.js.coffee
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: =>
View riddle.markdown

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 Mar 18, 2017
TDD'ing a Riddle
View princes.rb
require "minitest/autorun"
def yes
true
end
def no
false
end
@danott
danott / _partial_that_sets_content_for_block.html.erb
Created Dec 21, 2016
An example of the gymnastics to use `content_for` blocks between a view and partial, where the partial is supposed to appear after the `content_for` block
View _partial_that_sets_content_for_block.html.erb
<% content_for :content_set_within_partial do %>
"Hello! I'm setting a content_for block within a partial"
<% end %>
Hello!, I'm actually rendered in the partial
@danott
danott / probably_a_bad_idea.jsx
Last active Dec 20, 2016
A rough example of the idea that you can blow-away child state by passing a new key
View probably_a_bad_idea.jsx
class CanResetChildren extends React.Component {
constructor(props) {
super(props)
this.state = this.initialState
window.setTimeout(this.reset.bind(this), 60000)
}
render() {
return (
<div>
View webpack-status-plugin.js
var stripAnsi = require('strip-ansi');
var RequestShortener = require('webpack/lib/RequestShortener');
var requestShortener = new RequestShortener(process.cwd());
function formatError(e) {
var showErrorDetails = true;
var text = '';
if (typeof e === 'string') {
e = {
message: e,
@danott
danott / i_dont_use_getters.jsx
Created Jun 15, 2016
I tend to not use getters.
View i_dont_use_getters.jsx
const Name = React.createClass({
render() {
const { first, last } = this.props
const name = `${first} ${last}`
return (
<div>Your full name is {name}</div>
)
}
})
@danott
danott / loading.jsx
Created Jun 3, 2016
Prevent those double clicks in React
View loading.jsx
React.creatClass({
render() {
return (
<form onSubmit={handleSubmit}>
<input
type="submit"
value={this.state.loading ? "Doing it..." : "Do it!"}
disabled={this.state.loading}
/>
</form>
You can’t perform that action at this time.