Skip to content

Instantly share code, notes, and snippets.

@ilovett
ilovett / README.md
Last active April 26, 2023 13:35
Using GraphQL API and codegen to automatically generate types and using with `react-query` and `axios`

The models are defined on the graphql api and so you never have to worry about manually syncing types on your client code. You will immediately know if your api changed something that will break your code and where.

I'm using the typescript-graphql-request codegen plugin just to generate the docs and types, and ignoring the generated hooks specific to graphql-request

One could write a react-query generator that creates a hook for each query that you write but may need some fetcher adapter.

I was going to wait a bit more to see a pattern emerge. I like to use axios and others use fetch or other libs.

Perhaps some kind of provider with an adapter for axios or fetch or whatever.

@ilovett
ilovett / README.md
Created March 27, 2019 14:20
migrate bitbucket to github private user repo
@ilovett
ilovett / DatePickerValidator.jsx
Last active July 27, 2018 02:18
DatePicker wrapped with ValidatorComponent for use with `material-ui-pickers` and `react-material-ui-form-validator` with `material-ui@v1`
import React from 'react';
import DatePicker from 'material-ui-pickers/DatePicker';
import { ValidatorComponent } from 'react-material-ui-form-validator';
export default class DatePickerValidator extends ValidatorComponent {
setInputRef = (ref) => {
this.input = ref;
}
@ilovett
ilovett / some-es6-class.js
Created April 18, 2017 17:41
elasticsearch 5.0 scroll to end scrolltoend
fetchStuff(min, max = min) {
const body = new Bodybuilder();
body.size(3);
body.filter('range', 'timestamp', {
gte: min,
lte: max
});
@ilovett
ilovett / 404.handlebars
Last active December 30, 2015 17:29
Ember.js - Improving Error.Route with more explicit error code handling
<h2>404</h2>
Sorry bra ,we couldn't find that.
@ilovett
ilovett / child.handlebars
Last active December 17, 2015 15:39
Give multiple arguments to your linkTo function in Ember.js
<ul>
{{#each object in controller}}
<li>{{#linkToContext 'child' object.relatedGrandParent object.relatedParent object }} link {{/linkToContext}}</li>
{{/each}}
</ul>
@ilovett
ilovett / jquery.harlem-shake.js
Last active December 17, 2015 08:38
jQuery Harlem Shake Plugin.
var shake = function() {
function c() {
var e = document.createElement("link");
e.setAttribute("type", "text/css");
e.setAttribute("rel", "stylesheet");
e.setAttribute("href", f);
e.setAttribute("class", l);
document.body.appendChild(e)
}
function h() {
@ilovett
ilovett / models.py
Last active December 15, 2015 14:59
`Tastypie BaseResource to build lists from a queryset` Many to Many relationships in Tastypie Resources require a Manager (9.12 - 9.14), but if you are using a queryset, you can't use the relationship. This base resource allows you to extend your Resources to easily build a pseudo ToMany relationship from your queryset. Special thanks to https:/…
# how the models are related
# track -- generic --> audioclips <-- sample
class SampledTracksManager(models.Manager):
def get_track_samples(self, instance):
# must iterate through list because Audioclip object is unscriptable
audioclip_ids = []
for audioclip in instance.audioclips.all():