Skip to content

Instantly share code, notes, and snippets.

View tricoder42's full-sized avatar
🕴️
I may be slow to respond.

tricoder42

🕴️
I may be slow to respond.
View GitHub Profile
@tricoder42
tricoder42 / schema.py
Created September 8, 2017 09:38
GraphQL in Python - Concept
class ProjectType(graphql.DjangoModel):
class Meta:
model = Project
class ProjectSchema(graphql.DetailQuery,
graphql.ListQuery,
graphql.CreateMutation,
graphql.UpdateMutation,
graphql.DeleteMutation,
@tricoder42
tricoder42 / twilight.py
Last active November 6, 2017 13:09
Show times for dusk, dawn, sunset and sunrise.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Usage: twilight.py [--city=<city> | --coordinates=<coordinates>]
[--date=<date> | --tomorrow] [--week]
[-h | --help | --version]
Options:
-h --help Show this help.
--version Show version.
@tricoder42
tricoder42 / 02_anonymous_user.js
Created June 6, 2017 19:30
2017/06/06 [Medium] Use Selectors in Redux for Great Good
const initialState = {
user: {
name: 'anonymous',
token: null
}
}
const getUser = state => state.user || {}
const isAuthenticated = state => Boolean(getUser(state).token)
const isAnonymous = state => !isAuthenticated(user)
const flip = () => ({
flipResults: Math.random()
})
// creation of headlesscomponent
class CoinFlip extends React.Component {
state = flip()
handleClick = () => this.setState(flip)
api() {
@tricoder42
tricoder42 / deprecate.js
Created August 25, 2018 13:42
Deprecate renamed packages on NPM and update their READMEs
/*
Usage: node ./deprecate.js OTP_TOKEN
OTP_TOKEN is used for 2FA
*/
const path = require("path")
const fs = require("fs-extra")
const { exec } = require("child_process")
  1. Query projectIssue is resolved with an object "IssueType:18"
  2. Mutation issueEdit is called and returns the same object with updated attachments
  3. Object "IssueType:18" is updated correctly in cache (checked in Apollo DevTool and also manually by store.readFragment)
  4. Query projectIssue reloaded from cache automatically, but this this it doesn't return object

In Apollo DevTool I see this field in root query: issue({"issueId":"18","project":"IEP001"}): IssueType:18. I believe the query should be updated when object IssueType:18 in cache is updated, but when it happens, the object is empty.

@tricoder42
tricoder42 / app.js
Last active October 19, 2018 17:55 — forked from NgesBrian/app.js
error message is this.props.language is undefined
import React, { Component } from 'react';
import './App.css';
import { connect } from 'react-redux';
import Main from './Main/Main.js';
import FooterPage from './Footer/Footer.js';
import { I18nProvider } from '@lingui/react'
class App extends Component {
@tricoder42
tricoder42 / 03_local_selector.js
Created June 6, 2017 19:51
2017/06/06 [Medium] Use Selectors in Redux for Great Good
// const reducer = ...
const ID = 'auth'
const local = state => state[ID]
const getUser = state => local(state).user
const isAuthenticated = state => Boolean(getUser(state))
export default {[ID]: reducer}
# BAD:
from production import *
# Good (my personal preference):
from myproject.settings.production import *
# Good (probably your choice):
from .production import *
@tricoder42
tricoder42 / example.ts
Created April 25, 2019 08:15
Next.js Route Configs
// I believe this file could be automatically generated. Each route
// could be typechecked that all params are passed into it.
import { projectRoute } from "routes.js"
import { ProjectLink } from "routes.utils.ts"
export const ProjectLink = makeLink(projectRoute)
// Example usage of `ProjectLink` component. It's like regular Link, but it accepts `params`
// which are injected into `routeConfig.as` pattern.