Skip to content

Instantly share code, notes, and snippets.

Avatar
💢
wtf is this code doing!?

Richmond richmondwang

💢
wtf is this code doing!?
View GitHub Profile
View global-gitignore.md

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 Oct 23, 2019 — forked from joar/jq-insert-var.sh
Add a field to an object with JQ
View jq-insert-var.sh
# 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}'
{
View sample.go
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 — forked from sosedoff/1_simple.go
Golang Custom Struct Tags Example
View 1_simple.go
package main
import (
"fmt"
"reflect"
)
// Name of the struct tag used in examples
const tagName = "validate"
@richmondwang
richmondwang / mongodb-oneliner-cmds.md
Last active Apr 4, 2018
mongodb useful oneliner commands
View mongodb-oneliner-cmds.md

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 Jan 16, 2018 — forked from mgoodness/helm-rbac.md
Helm RBAC setup for K8s v1.6+ (tested on minikube)
View helm-rbac.md
kubectl -n kube-system create sa tiller
kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller
helm init --service-account tiller
View keybase.md

Keybase proof

I hereby claim:

  • I am richmondwang on github.
  • I am richmondwang (https://keybase.io/richmondwang) on keybase.
  • I have a public key ASCvZ3XpTxksEvVYhQLV8yWszXLcCP1i-kZctaVlac85ogo

To claim this, I am signing this object:

@richmondwang
richmondwang / requestcontexttask.py
Created May 23, 2017 — forked from Xion/requestcontexttask.py
Base class for Celery tasks running inside Flask request context
View requestcontexttask.py
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 Apr 25, 2017 — forked from vjcagay/.tmux.conf
my tmux config
View .tmux.conf
# 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 Apr 13, 2017
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!!!
View graphene_sqlalchemy_optimizer.py
# -*- 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