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 / _partial_that_sets_content_for_block.html.erb
Created December 21, 2016 21:11
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
<% 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 December 20, 2016 17:50
A rough example of the idea that you can blow-away child state by passing a new key
class CanResetChildren extends React.Component {
constructor(props) {
super(props)
this.state = this.initialState
window.setTimeout(this.reset.bind(this), 60000)
}
render() {
return (
<div>
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 June 15, 2016 18:49
I tend to not use getters.
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 June 3, 2016 18:04
Prevent those double clicks in React
React.creatClass({
render() {
return (
<form onSubmit={handleSubmit}>
<input
type="submit"
value={this.state.loading ? "Doing it..." : "Do it!"}
disabled={this.state.loading}
/>
</form>

Keybase proof

I hereby claim:

  • I am danott on github.
  • I am danott (https://keybase.io/danott) on keybase.
  • I have a public key ASBbSv8_mpTXYuH9FlG3Q4Xmcef5dk2ocfVF8HRk8KyfBwo

To claim this, I am signing this object:

@danott
danott / edit.html.erb
Created May 12, 2016 22:09
React + Rails
<div id="person_form"></div>
<script>
ReactDOM.render(
React.createElement(PersonForm, <%= @person.to_json.html_safe %>),
document.getElementById("person_form")
)
</script>
@danott
danott / single-to-double-quotes.js
Created April 29, 2016 22:05
A transform for use with jscodeshift
module.exports = function(fileInfo, api) {
var j = api.jscodeshift;
var out = j(fileInfo.source)
.find(j.Literal)
.forEach(function (path) {
// Only consider literals that start/end w/ double quotes
if (!/^'.*'$/.test(path.value.raw)) {
return;
}
-const Something = ({ name }) => {
- const localAction = () => console.log(name)
+const Something = React.createClass({
+ propTypes: {
+ name: React.PropTypes.string.isRequired
+ },
- return <div onClick={localAction}>Log {name}</div>
+ localAction() { console.log(this.props.name) },
+
@danott
danott / generic.swift
Created September 17, 2015 04:50
Some generic, functional swift methods.
func any<S>(source: [S], predicate: (S) -> Bool) -> Bool {
for element in source {
if predicate(element) { return true }
}
return false
}
func any<S>(source: [S], predicate: (Int, S) -> Bool) -> Bool {
for (index, element) in enumerate(source) {