Skip to content

Instantly share code, notes, and snippets.

View circa10a's full-sized avatar
🤷

Caleb Lemoine circa10a

🤷
View GitHub Profile
@circa10a
circa10a / add-lifecycle-policy-on-bucket-delete.yaml
Last active January 20, 2023 22:59
cloud custodian policy / lambda to add lifecycle rule on bucket delete attempts
policies:
- name: add-lifecycle-policy-on-bucket-delete
comments: |
In dev, let's start emptying the bucket as soon as delete is requested so that we can have a more ephmeral environment for standup/teardown
resource: s3
mode:
type: cloudtrail
role: cloud-custodian-role
execution-options:
log_group: cloud-custodian
package docker.authz
default allow = false
allow {
not deny
}
deny {
builds_with_cache
}
@circa10a
circa10a / log_analysis.py
Created August 8, 2020 23:17
vimeo sre code eval
#!/usr/bin/env python3
import argparse
from datetime import datetime
from os.path import isfile
from logging import getLogger, basicConfig
# Format used for time range input and parsing strings to date objects (ms)
time_format = '%Y-%m-%d %H:%M:%S.%f'
# Validate user input of timeframes
@circa10a
circa10a / colly.go
Created May 20, 2020 00:47
basic usage of colly go library
package main
import (
"fmt"
"github.com/gocolly/colly/v2"
)
func main() {
c := colly.NewCollector(
@circa10a
circa10a / parse_yaml.sh
Created May 14, 2020 13:30
Shell script to parse yaml
#!/usr/bin/env bash
function parse_yaml {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
package main
import (
"net/http"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)
// Modeled after google docs
func buildFulfillment() *Response {
return &Response{
Payload{
Google{
ExpectUserResponse: false,
RichResponse: RichResponse{
Items: []Item{
{
SimpleResponse: &SimpleResponse{
TextToSpeech: "This is the default audio response",
// Modeled after google docs
// https://developers.google.com/assistant/conversational/responses#browsing_carousel
// Response is the entire JSON payload response
type Response struct {
Payload Payload `json:"payload"`
}
// Payload is a google defined higher structure, see https://developers.google.com/assistant/conversational/responses#browsing_carousel
type Payload struct {
package main
import (
"net/http"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)
func handleWebhook(c *gin.Context) {
c.JSON(http.StatusOK, buildFulfillment())
@circa10a
circa10a / k8s-metrics.go
Last active December 29, 2019 01:55
render terminal ui of cluster usage metrics
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"strconv"