Skip to content

Instantly share code, notes, and snippets.

Avatar

Vlad Fratila vladfr

  • Adobe
  • Bucharest, Romania
View GitHub Profile
@vladfr
vladfr / go_defer_order_explained.go
Last active February 6, 2022 11:18
Go defer order explained
View go_defer_order_explained.go
// This example shows how Go executes deferred statements in relation to a return
//
// This will output:
//
// Setting string to My first program says:
// Setting string to 3. Hello
//Setting string to 2. world
// Setting string to 1. from Deferred Go
// In main(), deferred() returned 3. Hello
// but str is now 1. from Deferred Go
View closure_fail.go
func (a *IDPConfig) AuthUnaryInterceptor(authFunc AuthFunc) grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
meta, ok := metadata.FromIncomingContext(ctx)
// [...]
token, err := a.validateToken(ctx, rawToken)
if err != nil {
return nil, status.Errorf(codes.Unauthenticated, "invalid auth token: %v", err)
}
@vladfr
vladfr / completion.sh
Created May 26, 2020 18:16
kubectl shell completion
View completion.sh
## Bash - OSX
# Get bash-completion going
$ brew install bash-completion
$ echo "[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion" >> ~/.bash_profile
# Put this in ~/.bash_profile
source <(kubectl completion bash)
alias k=kubectl
complete -F __start_kubectl k
@vladfr
vladfr / 1-standard.js
Last active November 7, 2022 13:26
Use async/await and for..of in Cloud Firestore
View 1-standard.js
// In a Firestore standard example, we quickly create a 'xmas tree' of nested stuff
// We use Promises directly: get().then(callback) and use snapshot.forEach() to iterate
let campaignsRef = db.collection('campaigns');
let activeCampaigns = campaignsRef.where('active', '==', true).select().get()
.then(snapshot => {
snapshot.forEach(campaign => {
console.log(campaign.id);
let allTasks = campaignsRef.doc(campaign.id).collection('tasks').get().then(
snapshot => {
snapshot.forEach(task => {