Skip to content

Instantly share code, notes, and snippets.

@perryism
perryism / README.md
Last active February 26, 2020 22:45
Backup s3 bucket to a different account

How to copy a bucket from one account to the other

Ref

Prerequisites

  • Setup aws profile for both source and destination

Setup parameters

@perryism
perryism / .es_proxy
Created April 16, 2020 22:17
ElasticSearch Proxy
function es_proxy () {
if [ ! -z $1 ]
then
profile="-e AWS_PROFILE=$1"
echo $1 profile will be used
fi
if [ -z $REGION ]
then
REGION="us-west-2"
echo $REGION region is used
@perryism
perryism / dict_as_an_object.py
Created April 24, 2020 16:19
Use dict as an object
class DictAsObject:
def __init__(self, dic):
self._dict = dic
def __getattr__(self, name):
if name == "value":
return self._dict
v = self._dict[name]
return DictAsObject(v)
@perryism
perryism / items_contains_in_list.py
Created April 24, 2020 17:21
Return an intercept(or not) list
import re
list_one = ["apple", "orange", "banana", "pineapple", "watermelon"]
list_two = ["apple", "water"]
filter_func = lambda x, lst: all(i not in x for i in lst)
select_func = lambda x, lst: any(i in x for i in lst)
def intercept(list_one, list_two, select=True):
func = select_func if select else filter_func
return filter(lambda x: func(x, list_two), list_one)
@perryism
perryism / log_level_argparse.py
Last active April 25, 2020 03:44
Log level arparse
import argparse
import logging
import os
import sys
parser = argparse.ArgumentParser(description='Read a teflon event file')
parser.add_argument("--log", choices=["NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], default="INFO",
help="Log level")
args = parser.parse_args()
@perryism
perryism / Dockerfile
Created August 5, 2020 20:50
Rails 6 alpine
FROM ruby:2.7.1-alpine3.12
RUN apk add --no-cache build-base nodejs nodejs-npm yarn sqlite-dev tzdata && \
gem install nokogiri && \
gem install rails
WORKDIR /app
COPY Gemfile /app
@perryism
perryism / codebuild_creds.sh
Created December 17, 2020 01:47
Update codebuild github token to access private repos
# Ref: https://docs.aws.amazon.com/codebuild/latest/userguide/sample-access-tokens.html
cat <<EOT >> creds.json
{
"username": "perryism",
"token": "my_access_token",
"serverType": "GITHUB",
"authType": "OAUTH",
"shouldOverwrite": true
}EOT
@perryism
perryism / prometheus-endpoint.yaml
Last active October 22, 2021 17:54
prometheus_metrics_outside_of_cluster.yaml
apiVersion: v1
kind: Endpoints
metadata:
name: gpu-metrics
namespace: monitoring
labels:
app: gpu-metrics
release: prometheus
subsets:
- addresses:
@perryism
perryism / build_and_deploy.yaml
Created March 16, 2022 16:47
Github actions to deploy react app as a static site to google cloud
name: Deployment
on: [push]
jobs:
  Build-App:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
from random import randrange
from datetime import datetime, timedelta
def random_date_between(start_date, end_date):
time_between_dates = end_date - start_date
days_between_dates = time_between_dates.days
random_number_of_days = randrange(days_between_dates)
return start_date + timedelta(days=random_number_of_days)
def random_date_from(start_date, time_between_dates):