Skip to content

Instantly share code, notes, and snippets.

View thinhdanggroup's full-sized avatar

thinhda thinhdanggroup

View GitHub Profile
@thinhdanggroup
thinhdanggroup / k8s-ssh-tunnel.md
Created March 13, 2022 04:04
Access another pod over SSH tunnel in K8s
  1. Install devspace to access k8s easily
    brew install devspace
  2. accessable-pod is a pod that you can access over ssh
    devspace -n <accessable-pod> enter -- bash -c "echo $(cat ~/.ssh/id_rsa.pub) >> ~/.ssh/authorized_keys"
  3. copy local key to
@thinhdanggroup
thinhdanggroup / example.go
Created April 2, 2020 10:10
Executor Example
func main() {
executor, err := executor.New(executor.DefaultConfig())
if err != nil {
logrus.Error(err)
}
// close resource before quit
defer executor.Close()
@thinhdanggroup
thinhdanggroup / config.go
Created April 2, 2020 10:08
Config Executors
type Config struct {
ReqPerSeconds int
QueueSize int
NumWorkers int
}
@thinhdanggroup
thinhdanggroup / validate.go
Created April 2, 2020 10:07
Validate Handler and Input Params
func validateFunc(handler interface{}, nArgs int) (interface{}, error) {
method := reflect.ValueOf(handler)
f := reflect.Indirect(method)
// check type func
if f.Kind() != reflect.Func {
return f, fmt.Errorf("%T must be a Function ", f)
}
methodType := method.Type()
#!/bin/sh
error_msg="Aborting commit. Your commit must:
[SCOPE - which part of the source code is impacted]: <Short (72 chars or less) summary>
<The body, details explain what's this commit does?>
Issues: <Jira issue link>"
@thinhdanggroup
thinhdanggroup / ExceptionTranslationInterceptor.java
Created December 18, 2019 02:44
Exception Translation Interceptor gRPC example
import io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener;
import io.grpc.*;
import lombok.extern.slf4j.Slf4j;
import org.lognet.springboot.grpc.GRpcGlobalInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.AuthenticationTrustResolver;
import org.springframework.security.authentication.AuthenticationTrustResolverImpl;
import org.springframework.security.core.Authentication;
@thinhdanggroup
thinhdanggroup / AnonymousAuthenticationInterceptor.java
Created December 18, 2019 02:41
Anonymous Authentication Interceptor gRPC example
import io.grpc.Metadata;
import io.grpc.ServerCall;
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.lognet.springboot.grpc.GRpcGlobalInterceptor;
import org.springframework.core.annotation.Order;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
@thinhdanggroup
thinhdanggroup / GRpcAuthenticationInterceptor.java
Created December 18, 2019 02:36
authenticate interceptor grpc
import io.grpc.*;
import lombok.extern.slf4j.Slf4j;
import org.lognet.springboot.grpc.GRpcGlobalInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.StringUtils;
import static com.google.common.base.Strings.nullToEmpty;
@thinhdanggroup
thinhdanggroup / worker_test.go
Created October 20, 2019 13:51
Example worker locust
func worker() {
request, err := http.NewRequest(method, url, bytes.NewBuffer(postBody))
if err != nil {
log.Fatalf("%v\n", err)
}
request.Header.Set("Content-Type", contentType)
startTime := time.Now()
response, err := client.Do(request)
@thinhdanggroup
thinhdanggroup / worker.go
Created September 18, 2019 15:43
example boomer and locust
func worker() {
request, err := http.NewRequest(method, url, bytes.NewBuffer(postBody))
if err != nil {
log.Fatalf("%v\n", err)
}
request.Header.Set("Content-Type", contentType)
startTime := time.Now()
response, err := client.Do(request)