Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Building product, looking for consulting work

Chris Sattinger crucialfelix

💭
Building product, looking for consulting work
View GitHub Profile
View check_connections.py
"""Check all required network connections
This can be called in AWS or in local docker-compose to check
that all settings work for connecting to database, memcached and rabbit.
Returns:
exits with error unless all connections are OK
"""
import os
import socket
import subprocess
import sys
@crucialfelix
crucialfelix / analytics.js
Last active Dec 29, 2020
Google Analytics for Next.js with next/router
View analytics.js
/**
* analytics.js;
* Copyright 2019 Chris Sattinger
* MIT license - do as thou wilt
*
* This will send page views on route change to Google Analytics.
* Works with https://nextjs.org/ and https://github.com/fridays/next-routes
**/
import Router from "next/router";
View simplified_django_connection_field.py
import re
from django.db import models
from graphene.relay import PageInfo
from graphene_django.fields import DjangoConnectionField
from graphql_relay.connection.arrayconnection import cursor_to_offset, offset_to_cursor
class SimplifiedDjangoConnectionField(DjangoConnectionField):
"""A simplified extension of DjangoConnectionField
@crucialfelix
crucialfelix / scanner.ts
Created Jul 23, 2018
Scan a directory of music files (mp3 aif wav flac etc.) and collect data grouped by artist, release, tracks
View scanner.ts
import readdir from 'fs-readdir-recursive';
import { List } from 'linqts';
import _ from 'lodash';
import { IAudioMetadata, parseFile } from 'music-metadata';
import path from 'path';
type Common = IAudioMetadata["common"];
export interface Track {
path: string;
View 1-Messages.tsx
import React from "react";
import { MessagesQuery, MessagesQueryVariables } from "../../queries";
import { graphql, QueryProps } from "react-apollo";
import Message from "./Message";
// IMPORTANT: The query is required, not imported.
const query = require("./Messages.graphql");
const POLL_INTERVAL = 7901;
View Messages.graphql
#import './Message.graphql'
query Messages($threadKey: String!) {
viewer {
id
messages(threadKey: $threadKey) {
edges {
node {
id
...Message
}
View Message-gql.tsx
import gql from "graphql-tag";
import React from "react";
interface Props {
message: any;
}
export default class Message extends React.PureComponent<Props, undefined> {
public render() {
return <div>message body</div>;
View gen.sh
apollo-codegen generate frontend/react/**/*.graphql \
--schema frontend/schema.json \
--target typescript \
--output frontend/react/queries.ts
View ClientPage.tsx
import gql from "graphql-tag";
import ShowingRequest from "./ShowingRequest";
import Deals from "./Deals";
const query = gql`
query Client($pk: ID!) {
viewer {
id
agent {
id
@crucialfelix
crucialfelix / schema.json
Created Sep 3, 2017
excerpt from graphql compiled schema for Message and User/Viewer model
View schema.json
[
{
"kind": "OBJECT",
"name": "Message",
"description": null,
"fields": [
{
"name": "id",
"description": "The ID of the object.",
"args": [],