Skip to content

Instantly share code, notes, and snippets.

@ofen
ofen / aio_sheets.py
Created January 17, 2019 20:00
Basic async Google Sheet api request based on aiohttp and asyncio
# Require PyJwt, AIOHTTP and PyCrypto (for RS256 in JWT)
import jwt
import time
import json
from pprint import pprint
import aiohttp
import asyncio
@ofen
ofen / bottle_cache.py
Last active December 28, 2021 13:20
Simple cache middleware for Bottle
from bottle import route, run, response, request
import datetime
import json
import requests
# Cache middleware
def cache(callback, ttl=datetime.timedelta(hours=1)):
cache = {}
def wrapper(*args, **kwargs):
key = request.path
@ofen
ofen / dns_to_ip.py
Last active April 1, 2020 15:46
Simple asyncio socket DNS to IP resolver
import socket
import asyncio
from urllib.parse import urlsplit
async def get(url):
url = urlsplit(url)
hostname = url.hostname
if url.scheme == 'https':
port = url.port or 443
@ofen
ofen / rc-local.service
Last active May 9, 2020 22:18
Simple Bluetooth auto-connect script for systemd
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=simple
ExecStart=/etc/rc.local start
ExecStop=/etc/rc.local stop
@ofen
ofen / webhook.groovy
Created June 23, 2020 08:15
Jenkins Glip webhook notification
def glip(java.util.LinkedHashMap params) {
def payload = [
activity: params.activity,
title: params.title,
icon: params.icon,
body: params.body
]
httpRequest(
acceptType: 'APPLICATION_JSON',
contentType: 'APPLICATION_JSON',
@ofen
ofen / fetch_grafana.sh
Last active July 7, 2020 12:27
Export Grafana dashboards via API
#!/usr/bin/env bash
HOST="http://grafana.local:3000"
mkdir dashboards && \
for dashboard in $(wget -qO- "$HOST/api/search?query=&" | jq -r .[].uri); do
wget -qO- "$HOST/api/dashboards/$dashboard" | jq -r '.dashboard | del(.uid)' > dashboards/"$(basename "$dashboard")".json
done
@ofen
ofen / monokai-dark.theme
Last active July 9, 2020 17:42 — forked from tsbarnes/monokai-dark.theme
Monokai color scheme for XFCE4 terminal, place it in /usr/share/xfce4/terminal/colorschemes
[Scheme]
Name=Monokai (dark)
TabActivityColor=#a6a6e2e22e2e
ColorCursor=#f8f8f8f8f2f2
ColorForeground=#f8f8f8f8f2f2
ColorBackground=#272728282222
ColorPalette=#272728282222;#f9f926267272;#a6a6e2e22e2e;#f4f4bfbf7575;#6666d9d9efef;#aeae8181ffff;#a1a1efefe4e4;#f8f8f8f8f2f2;#757571715e5e;#f9f926267272;#a6a6e2e22e2e;#f4f4bfbf7575;#6666d9d9efef;#aeae8181ffff;#a1a1efefe4e4;#f9f9f8f8f5f5
@ofen
ofen / _helper.tpl
Last active May 12, 2023 08:40
Helm helper to convert label map to comma-separated string
{{/*
Convert labels to string like: key1="value1", key2="value2", ...
*/}}
{{- define "chart.external_labels" -}}
{{- $list := list -}}
{{- range $k, $v := .Values.external_labels -}}
{{- $list = append $list (printf "%s=\"%s\"" $k $v) -}}
{{- end -}}
{{ join ", " $list }}
{{- end -}}
@ofen
ofen / backtick-surround.json
Last active July 16, 2020 08:38 — forked from beechnut/backtick-surround.js
Surround with backticks in Sublime Text 3
// Copy the following into Preferences > Key Bindings -- User
// Thanks to:
// http://sublimetext.userecho.com/topic/86166-backtick-quoting-selected-text-does-not-work-like-single-quotes-and-double-quotes/
[
{
"keys": [
"`"
],
"command": "insert_snippet",
@ofen
ofen / Go.sublime-build
Created September 23, 2020 08:58
"gofmt + go run" Sublime Text 3 build system
{
"shell_cmd": "gofmt -w \"$file\" && go run \"$file\"",
"selector": "source.go",
"file_regex": "go$"
}