Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import math
import sys
from moviepy.editor import AudioClip, VideoFileClip, concatenate_videoclips
# Get average RGB of part of a frame. Frame is H * W * 3 (rgb)
# Assumes x1 < x2, y1 < y2
@ksatirli
ksatirli / terraform-cloud-ip-ranges.tf
Created August 10, 2020 16:43
Terraform Cloud IP Ranges as Terraform Variables
terraform {
required_providers {
http = "~> 1.2"
}
required_version = "~> 0.12.29"
}
data "http" "terraform_cloud_ip_ranges" {
url = "https://app.terraform.io/api/meta/ip-ranges"
@meshuga
meshuga / assume_role.sh
Created May 20, 2020 08:06
Assume a role with MFA in bash and export session to environmental variables
PROFILE=test
echo "Please, provide MFA code:"
read MFA_CODE
ASSUMED_ROLE=$(aws sts assume-role --role-arn="$(aws configure get role_arn --profile $PROFILE)" --role-session-name=session --token-code=$MFA_CODE --serial-number="$(aws configure get mfa_serial --profile $PROFILE)" --output text)
ASSUMED_ROLE_ARRAY=( $ASSUMED_ROLE )
if [ -z "$ASSUMED_ROLE_ARRAY" ]
then
@elpy1
elpy1 / setup.md
Created May 11, 2020 02:13
quick setup guide for ssm-tool

ezmode ssh over ssm

quick setup and usage guide for SSH access over SSM to private AWS EC2 instances

Requirements

Installation

  1. git clone https://github.com/elpy1/ssm-tool.git
@ayush--s
ayush--s / main.go
Created March 13, 2020 06:59
kill executables of a name over memory usage percentage
package main
import (
"fmt"
"log"
"log/syslog"
"strings"
"github.com/shirou/gopsutil/process"
)
@ayush--s
ayush--s / main.go
Last active June 2, 2020 22:05
Clickup commit msg hook
package main
// put this executable as .git/hooks/prepare-commit-msg
import (
"io/ioutil"
"log"
"os"
"strings"
)
@ayush--s
ayush--s / s3fs setup.sh
Last active June 2, 2020 22:04
S3FS setup with systemd
sudo apt install s3fs
echo "<redacted>" > ~/.passwd-s3fs
sudo nano /etc/systemd/system/s3fs.service
chmod 600 /home/ubuntu/.passwd-s3fs
sudo systemctl daemon-reload
sudo systemctl enable s3fs
@andymotta
andymotta / remote_state.tf
Created December 28, 2018 18:05
Parameterize Terraform remote state (AWS)
data "aws_caller_identity" "current" {}
resource "aws_s3_bucket" "terraform_state" {
bucket = "${data.aws_caller_identity.current.account_id}-tfstate"
versioning {
enabled = true
}
policy = <<POLICY
{
"Version": "2012-10-17",
@jivimberg
jivimberg / takeWhileInclusive.kt
Last active December 18, 2020 10:36
Inclusive implementation of takeWhile for Kotlin. Inspired from this gist: https://gist.github.com/matklad/54776705250e3b375618f59a8247a237 . Read more about this implementation on my blog: https://jivimberg.io/blog/2018/06/02/implementing-takewhileinclusive-in-kotlin/
// kotlin.collections
inline fun <T> Array<out T>.takeWhileInclusive(
predicate: (T) -> Boolean
): List<T> {
var shouldContinue = true
return takeWhile {
val result = shouldContinue
shouldContinue = predicate(it)
result
@joer14
joer14 / rds_download_log.py
Last active March 8, 2024 08:34
workaround for downloading rds logs via the AWS REST interface. This uses the IAM credentials for the session so should 'just work' on a lambda without needing to hardcode credentials/pass them in via environmental variables etc.
"""
Craft a web request to the AWS rest API and hit an endpoint that actually works but isn't supported in the CLI or in Boto3.
Based on this: https://github.com/aws/aws-cli/issues/2268#issuecomment-373803942
"""
import boto3
import os
import sys, os, base64, datetime, hashlib, hmac, urllib
import requests