Skip to content

Instantly share code, notes, and snippets.

Avatar
🕴️
I may be slow to respond.

Tomáš Ehrlich tricoder42

🕴️
I may be slow to respond.
View GitHub Profile
@tricoder42
tricoder42 / 00_GraphQL_Subscriptions.md
Last active Sep 7, 2020
GraphQL Subscriptions with django-channels
View 00_GraphQL_Subscriptions.md

GraphQL Subscription with django-channels

Django channels are official way for implementing async messaging in Django.

The primary caveat when working with GraphQL subscription is that we can't serialize message before broadcasting it to Group of subscribers. Each subscriber might use different GraphQL query so we don't know how to serialize instance in advance.

See related issue

View 00_GraphQL_example.md

GraphQL example

Graphene Tutorial

Example of authentication mutations and user queries in GraphQL API.

View hammerspoon.lua
local hyper = {"cmd", "alt"}
--Predicate that checks if a window belongs to a screen
function isInScreen(screen, win)
return win:screen() == screen
end
function focusScreen(screen)
--Get windows within screen, ordered from front to back.
--If no windows exist, bring focus to desktop. Otherwise, set focus on
View NotificationsWrapper.js
function NotificationsHeader({ fetchNotifications, subscribeNotifications }) {
const [notifications, setNotifications] = useState([])
useEffect(() => {
// fetch initial notifications
fetchNotifications().then(notifications => {
setNotifications(notifications)
})
// subscribe to new notifications
@tricoder42
tricoder42 / README.md
Last active May 29, 2019
Webpack plugin which injects code, module dependency and async context to each chunk
View README.md

I'm writing a webpack plugin, which should generate message catalogs for each chunk.

I know how to split main message catalog by inspecting modules inside chunk.

In build folder, I have:

index.js
index.en.js
index.cs.js
@tricoder42
tricoder42 / README.md
Last active May 14, 2019
Centralized routing for Next.js
View README.md

I'm using this approach to have centralized route config in Next.js. I don't have the fully automated solution. Right now I'm writing route configs and links manually to figure out if it works and what are the drawbacks.

I believe the automation is the last step to make it completely seamless.

1. Define routes in centralized config

This is the only file that needs to be wrote manually.

@tricoder42
tricoder42 / example.ts
Created Apr 25, 2019
Next.js Route Configs
View example.ts
// 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.
View settings_development.py
# BAD:
from production import *
# Good (my personal preference):
from myproject.settings.production import *
# Good (probably your choice):
from .production import *
@tricoder42
tricoder42 / 03_local_selector.js
Created Jun 6, 2017
2017/06/06 [Medium] Use Selectors in Redux for Great Good
View 03_local_selector.js
// 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}
@tricoder42
tricoder42 / app.js
Last active Oct 19, 2018 — forked from NgesBrian/app.js
error message is this.props.language is undefined
View app.js
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 {
You can’t perform that action at this time.