Skip to content

Instantly share code, notes, and snippets.


Denis Loginov dinvlad

View GitHub Profile
dinvlad /
Created Jul 17, 2020
Validate interactive request from Slack
import hashlib
import hmac
import os
from time import time
from flask import Request, abort
dinvlad /
Last active May 10, 2020
Script to configure encrypted GCS backend and GCP project-specific .tfvars for Terraform
#!/usr/bin/env bash
set -euo pipefail
# define GCP project and GCS bucket backend for Terraform state
# create versioned bucket if it doesn't exist, skip otherwise
if gsutil mb -p "${GCP_PROJECT}" "gs://${BACKEND_BUCKET}" ; then
dinvlad / retries.ts
Last active May 20, 2021
Retries with exponential backoff and jitter for idempotent background Google Cloud Functions
View retries.ts
// one can also use Google Cloud Firestore library,
// with a slight change in semantics
import { firestore } from 'firebase-admin';
import { EventContext, runWith } from 'firebase-functions';
import { promisify } from 'util';
const eventCollection = 'function-events';
enum EventStatus {
RUNNING = 'running',
dinvlad / cloudrun.jinja
Created Sep 6, 2019
Create Cloud Run Service through Deployment Manager
View cloudrun.jinja
{% set PROJECT = env['project'] %}
{% set REGION = properties['region'] | default('us-east1') %}
{% set PARENT = 'projects/' + PROJECT + '/locations/' + REGION %}
{% set PREFIX = env['deployment'] %}
{% set CLOUDRUN_TYPE_PROVIDER = PREFIX + '-provider' %}
dinvlad / gist:83c078481649a35e16d9112d2743dab9
Last active Jul 28, 2019 — forked from mackstann/gist:4229933
Gigantic recursive directory entry counter
View gist:83c078481649a35e16d9112d2743dab9
#define _GNU_SOURCE
#include <dirent.h> /* Defines DT_* constants */
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/syscall.h>
dinvlad /
Last active Sep 18, 2018
Workaround for listening on PubSub subscriptions even when StreamingPull stops silently
// ... other dependencies ...
import org.springframework.stereotype.Service;
dinvlad / pre_request.js
Last active Oct 24, 2021
Auto-generate Google Access and ID tokens from a Service Account key and save it in Postman
View pre_request.js
/* This script auto-generates a Google OAuth token from a Service Account key,
* and stores that token in accessToken variable in Postman.
* Prior to invoking it, please paste the contents of the key JSON
* into serviceAccountKey variable in a Postman environment.
* Then, paste the script into the "Pre-request Script" section
* of a Postman request or collection.
* The script will cache and reuse the token until it's within
dinvlad / get-aws-token
Created Oct 25, 2016
Get session token for virtual MFA-enabled actions through AWS CLI
View get-aws-token
# Thanks to MattJ at:
# User must have 'iam:GetUser' permission on themselves that doesn't require MFA
[ -z $1 ] && echo "Please enter your MFA code" && exit 1
user=$(aws iam get-user \