Skip to content

Instantly share code, notes, and snippets.

import React from "react";
import fetchData from "./fetchData";
export default function permitList(props) {
const data = fetchData("https://data.cityofchicago.org/resource/ydr8-5enu.json?");
return (
<div>
<ul>
{data.map(el => (
<li key={el.id}>{el.permit_type}</li>
// fetchData.js
import { useState, useEffect } from "react";
export default function fetchData(url) {
const [data, setData] = useState([]);
useEffect(() => {
fetch(url)
.then(response => response.json())
.then(data => setData(data));
<DataFetcher
render={data => {
return (
<div>
<ul>
{data.map(el => (
<li key={el.id}>{el.title}</li>
))}
</ul>
</div>
@Chryus
Chryus / .jsx
Last active March 12, 2020 15:52
import React, { Component } from "react";
export default class DataFetcher extends Component {
state = { data: [] };
componentDidMount() {
fetch("https://data.cityofchicago.org/resource/ydr8-5enu.json?")
.then(response => response.json())
.then(data =>
this.setState(() => {
// dataFetcher.js
import { useState, useEffect } from "react";
export default function dataFetcher(url) {
const [data, setData] = useState([]);
useEffect(() => {
fetch(url)
.then(response => response.json())
.then(data => setData(data));
# graffiti.rb
class Graffiti < ActiveRecord::Base
belongs_to :artist, class_name: "User"
has_many :uploads
has_many :comments
has_many :upvotes, as: :upvotable
end
# upload.rb
class Upload < ApplicationRecord
@Chryus
Chryus / user.rb
Last active February 15, 2017 16:39
class User < ActiveRecord::Base
# ...
has_many :upvotes
has_many :graffiti, through: :upvotes, source: :upvotable, source_type: "Graffiti"
has_many :uploads, through: :upvotes, source: :upvotable, source_type: "Upload"
# ...
end
# graffiti.rb
class Graffiti < ActiveRecord::Base
has_many :uploads
has_many :upvotes, as: :upvotable
end
# upload.rb
class Upload < ApplicationRecord
belongs_to :user
belongs_to :graffiti
# user.rb
class User < ActiveRecord::Base
has_many :upvotes
has_many :graffiti, through: :upvotes
end
# graffiti.rb
class Graffiti < ActiveRecord::Base
has_many :upvotes
has_many :users, through: :upvotes
// In the initial code, I wasn't aware that let would create a new binding for
// each variable inside my loop. I assumed a closure around the setTimeout function
// was necessary to create new copy of the variables at each step.
animate() {
let previousDelay = 0;
let styles = null;
for (let sequence of this.dataSet) {
let delay = sequence[0] + previousDelay;
let objects = sequence.filter(this.isObject);
styles = this.formatStyles(objects);