Skip to content

Instantly share code, notes, and snippets.

View ntucker's full-sized avatar
🚀
to the moon

Nathaniel Tucker ntucker

🚀
to the moon
View GitHub Profile
UnreadablePostError: timed out
Stacktrace (most recent call last):
File "django/core/handlers/base.py", line 109, in get_response
response = middleware_method(request, callback, callback_args, callback_kwargs)
File "django/middleware/csrf.py", line 174, in process_view
request_csrf_token = request.POST.get('csrfmiddlewaretoken', '')
File "django/core/handlers/wsgi.py", line 198, in _get_post
self._load_post_and_files()
@ntucker
ntucker / useResource.tsx
Last active October 16, 2019 01:56
Post component using useResource
function Post({ id }: { id: string }) {
const post = useResource(PostResource.detailShape(), { id });
return (
<article>
<h2>{post.title}</h2>
<p>{post.body}</p>
</article>
);
}
@ntucker
ntucker / useResource.tsx
Last active October 16, 2019 01:38
starter useResource
const myData = useResource(fetchingSpecification, parameters);
@ntucker
ntucker / PostResource.ts
Last active October 16, 2019 02:23
simple Resource class before normalization
class PostResource {
readonly id: number | null = null;
readonly title: string = '';
readonly body: string = '';
constructor(args) {
Object.assign(this, args);
}
static async fetchDetail({ id }: { id: string }): PostResource {
@ntucker
ntucker / PostResource.ts
Created October 16, 2019 19:56
Simplified PostResource
class PostResource extends Resource {
readonly id: number | null = null;
readonly title: string = '';
readonly body: string = '';
static urlRoot = '/post/';
}
@ntucker
ntucker / Resource.ts
Last active October 16, 2019 20:28
base resource definition
class Resource {
constructor(args) {
Object.assign(this, args);
}
static url({ id }: { id: string }) {
return `${this.urlRoot}${id}`;
}
// This generic enables us to establish the correct return value based on the polymorphic call
@ntucker
ntucker / README.md
Last active January 31, 2020 12:06 — forked from gnbaron/README.md
Convert flow typed JS files to Typescript using @khanacademy/flow-to-ts.

Usage: npx https://gist.github.com/ntucker/8c90aff06ceedccd778c84e23052b39e src/folder