Skip to content

Instantly share code, notes, and snippets.

@alterEgo123
alterEgo123 / main.py
Created June 30, 2021 13:43
Importing data to Typesense
import typesense
def init_client():
client = typesense.Client({
'nodes': [{
'host': 'localhost',
'port': '8108',
'protocol': 'http'
}],
@alterEgo123
alterEgo123 / gist:85cba87cc226cc3691e67ef4f522ca93
Created January 13, 2021 15:05
Add/remove LivenessProbe from deployment
kubectl patch deployment X --patch '{"spec": {"template": {"spec": {"containers": [{"name": "Y","livenessProbe": {"httpGet":{"path": "health", "port":8080, "scheme": "HTTP"}, "periodSeconds": 3, "initialDelaySeconds": 3, "timeoutSeconds": 50}}]}}}}'
kubectl patch deployment X --patch '{"spec": {"template": {"spec": {"containers": [{"name": "Y","livenessProbe": null}]}}}}'
@alterEgo123
alterEgo123 / gist:34fb89898dc788491c61daad814baf7b
Created December 28, 2020 10:02
Auto-update containers from local images
docker run -d --name watchtower -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --no-pull -c -e --interval 10 --cleanup --rolling-restart
@alterEgo123
alterEgo123 / gist:4f7622081729663b689e957f7a31dac9
Created November 30, 2020 14:43
Redirect python logging to supervisord's stdout
[supervisord]
nodaemon=true
user = root
[program:launcher]
command=python3 -u launcher.py
autostart = true
autorestart = true
stdout_logfile=/var/log/launcher.log
stderr_logfile=/var/log/launcher.log
@alterEgo123
alterEgo123 / Push images
Created November 20, 2020 12:46
Push multiple images at once
echo 'reg/image:tag' 'reg/image:tag' 'reg/image:tag' | xargs -n 1 docker push
@alterEgo123
alterEgo123 / fluent-bit-configmap-ds-file-output
Last active October 16, 2020 08:25
This is a Kubernetes manifest file containing the configmap and daemonset used to collect application containers' logs and redirect them to files under /var/log/output (directory should be created manually) using Fluent Bit
apiVersion: v1
kind: ConfigMap
metadata:
name: fluent-bit-config
namespace: logging
labels:
k8s-app: fluent-bit
data:
fluent-bit.conf: |
@alterEgo123
alterEgo123 / validators.py
Created September 3, 2020 11:17 — forked from jrosebr1/validators.py
Validator for files, checking the size, extension and mimetype for Django.
# @brief
# Performs file upload validation for django. The original version implemented
# by dokterbob had some problems with determining the correct mimetype and
# determining the size of the file uploaded (at least within my Django application
# that is).
# @author dokterbob
# @author jrosebr1
import mimetypes
# ---- Base python ----
FROM python:3.6 AS base
# Create app directory
WORKDIR /app
# ---- Dependencies ----
FROM base AS dependencies
COPY gunicorn_app/requirements.txt ./
# install app dependencies
RUN pip install -r requirements.txt
@alterEgo123
alterEgo123 / replace.py
Created March 11, 2020 07:16 — forked from carlsmith/replace.py
A Python function that does multiple string replace ops in a single pass.
import re
def replace(string, substitutions):
substrings = sorted(substitutions, key=len, reverse=True)
regex = re.compile('|'.join(map(re.escape, substrings)))
return regex.sub(lambda match: substitutions[match.group(0)], string)