Skip to content

Instantly share code, notes, and snippets.

View richmondwang's full-sized avatar
🎯
Focusing

Richmond richmondwang

🎯
Focusing
View GitHub Profile
@richmondwang
richmondwang / global-gitignore.md
Created November 7, 2019 04:46 — forked from subfuzion/global-gitignore.md
Global gitignore

There are certain files created by particular editors, IDEs, operating systems, etc., that do not belong in a repository. But adding system-specific files to the repo's .gitignore is considered a poor practice. This file should only exclude files and directories that are a part of the package that should not be versioned (such as the node_modules directory) as well as files that are generated (and regenerated) as artifacts of a build process.

All other files should be in your own global gitignore file. Create a file called .gitignore in your home directory and add anything you want to ignore. You then need to tell git where your global gitignore file is.

Mac

git config --global core.excludesfile ~/.gitignore

Windows

git config --global core.excludesfile %USERPROFILE%\.gitignore
@richmondwang
richmondwang / jq-insert-var.sh
Created October 23, 2019 02:05 — forked from joar/jq-insert-var.sh
Add a field to an object with JQ
# Add field
echo '{"hello": "world"}' | jq --arg foo bar '. + {foo: $foo}'
# {
# "hello": "world",
# "foo": "bar"
# }
# Override field value
echo '{"hello": "world"}' | jq --arg foo bar '. + {hello: $foo}'
{
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"
@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"
@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 / 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 / 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 / .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 / 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 / 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