Skip to content

Instantly share code, notes, and snippets.

View richmondwang's full-sized avatar
🎯
Focusing

Richmond richmondwang

🎯
Focusing
View GitHub Profile
@richmondwang
richmondwang / dict.py
Created March 31, 2017 07:15
Creates a dict whose top-level keys are always evaluated to str.
class StringedDict(dict):
def __setitem__(self, key, value):
super().__setitem__(str(key), value)
@richmondwang
richmondwang / totalCount_connection_factory.py
Created March 31, 2017 07:17
Connection factory for graphene-sqlalchemy. This will add the field `totalCount` based on the specification of graphql.
def connection_for_type(_type):
"""Added totalCount node on the Connectionfield"""
class Connection(graphene.Connection):
total_count = graphene.Int(
description="Total count of {}s.".format(_type._meta.name))
class Meta:
description = name = _type._meta.name + 'Connection'
node = _type
@richmondwang
richmondwang / Graphene_Formatted_DateTime.py
Last active March 31, 2017 07:28
This is a custom Scalar type. This DateTime Scalar can be formatted into anything the consumer needs it to be.
# -*- coding: utf-8 -*-
import datetime
import graphene
from graphene.types.datetime import DateTime
class FormattedDateTime(DateTime):
"""
This is a custom Scalar type. This DateTime Scalar can be formatted into
@richmondwang
richmondwang / graphene_sqlalchemy_optimizer.py
Last active April 13, 2017 14:10
This is a fork of yfilali's resolve_related def in his post (https://yacine.org/2017/02/27/graphqlgraphene-sqlalchemy-and-the-n1-problem/). Updated a little to add selecting only the requested fields.!!!This is only experimental!!!
# -*- coding: utf-8 -*-
from inflection import underscore
from sqlalchemy import inspect
from sqlalchemy.orm import RelationshipProperty, joinedload, load_only
class RelationshipPathNode(object):
def __init__(self, value, parent=None):
if parent:
parent.isLeaf = False
@richmondwang
richmondwang / .tmux.conf
Created April 25, 2017 09:14
my tmux config
# Make mouse useful
# Toggle mouse on
bind m \
set -g mouse on \;\
display 'Mouse mode: ON'
# Toggle mouse off
bind M \
set -g mouse off \;\
display 'Mouse mode: OFF'
@richmondwang
richmondwang / requestcontexttask.py
Created May 23, 2017 02:28 — forked from Xion/requestcontexttask.py
Base class for Celery tasks running inside Flask request context
from celery import Task
from flask import has_request_context, make_response, request
from myapp import app
__all__ = ['RequestContextTask']
class RequestContextTask(Task):
@richmondwang
richmondwang / helm-rbac.md
Created January 16, 2018 05:38 — forked from mgoodness/helm-rbac.md
Helm RBAC setup for K8s v1.6+ (tested on minikube)
kubectl -n kube-system create sa tiller
kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller
helm init --service-account tiller
@richmondwang
richmondwang / mongodb-oneliner-cmds.md
Last active April 4, 2018 07:21
mongodb useful oneliner commands

Get index sizes of all collections in db

db.getCollectionNames().map(name => ({totalIndexSize: db.getCollection(name).stats().totalIndexSize, name: name})).sort((a, b) => a.totalIndexSize - b.totalIndexSize).forEach(printjson)

Memory stats

db.serverStatus().tcmalloc.tcmalloc.formattedString

Login to repl member with keyfile

@richmondwang
richmondwang / 1_simple.go
Created May 2, 2018 00:20 — forked from sosedoff/1_simple.go
Golang Custom Struct Tags Example
package main
import (
"fmt"
"reflect"
)
// Name of the struct tag used in examples
const tagName = "validate"
package main
import (
"golang.org/x/net/context"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/cli/command"
"github.com/docker/docker/client"
"fmt"