Skip to content

Instantly share code, notes, and snippets.

View kissgyorgy's full-sized avatar

György Kiss kissgyorgy

View GitHub Profile
@kissgyorgy
kissgyorgy / ternary.go
Created September 30, 2019 16:54
Ternary operator in Go
package main
import "fmt"
type ternary struct {
conditionIsTrue bool
trueValue interface{}
}
func If(condition bool) *ternary {
@kissgyorgy
kissgyorgy / gote.sh
Created September 26, 2019 23:09
Bash: Run go tests with rakyll/gotest
# Run gotest with the module name found in go.mod in the current directory
# gotest is: https://github.com/rakyll/gotest
gote () {
# run in a subshell, so errexit will exit the subshell, not the terminal shell
# https://unix.stackexchange.com/questions/207732/local-set-e-for-functions
(
set -eo pipefail
local options
local test_path
local module_name
@kissgyorgy
kissgyorgy / plex.conf
Last active September 5, 2019 20:50
nginx configuration for Plex
server {
listen 443 ssl http2;
server_name plex.example.com;
location / {
proxy_pass http://127.0.0.1:32400;
include proxy_params;
# This is for proxying websocket connections for the web interface
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
@kissgyorgy
kissgyorgy / list_plex_movie_files.py
Last active January 10, 2022 21:25
List movies from Plex database
#!/usr/bin/python3
import sqlite3
from urllib.parse import unquote, parse_qs
PLEX_DB = '/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db'
conn = sqlite3.connect(PLEX_DB)
res = conn.execute('SELECT hints FROM media_items WHERE library_section_id = 1;')
@kissgyorgy
kissgyorgy / wsgi.py
Created May 25, 2018 20:46 — forked from rbarrois/wsgi.py
Django uWSGI warmup
# -*- coding: utf-8 -*-
import io
import os
import sys
import time
import wsgiref.util
import uwsgidecorators
@kissgyorgy
kissgyorgy / integer_copy.py
Last active February 21, 2018 20:29
Python: CPython integer optimization
>>> import copy
>>> copy.deepcopy(257) is copy.deepcopy(257)
True
>>> a = copy.deepcopy(257)
>>> b = copy.deepcopy(257)
>>> a is b
False
@kissgyorgy
kissgyorgy / sqlite_magic.py
Last active November 13, 2021 01:21
Python3: load multiple SQLite rows into one NamedTuple object
import sqlite3
from typing import namedtuple
class Environment(NamedTuple):
SLACK_CLIENT_ID: str
SLACK_CLIENT_SECRET: str
SECRET_KEY: str
conn = sqlite3.connect('config.db')
conn.row_factory = sqlite3.Row
certPem := result.Data["certificate"]
certString := certPem.(string)
certBytes := []byte(certString)
block, _ := pem.Decode(certBytes)
cert, err := x509.ParseCertificate(block.Bytes)
@kissgyorgy
kissgyorgy / go_version.go
Created June 5, 2017 07:15
Python vs Go HTTP Request
func (b *vaultBackend) Version() string {
r := b.client.NewRequest("GET", "/v1/sys/health")
resp, err := b.client.RawRequest(r)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
var result struct {
Version string
}
@kissgyorgy
kissgyorgy / crypto_lib_matrix.txt
Last active March 18, 2017 11:45
Pyton Crypto lib matrix
Subdomain Marked OpenSSL OpenSSL Certifi OSCrypto urllib3
expired.badssl.com ❌ ❌ ❌ ❌ ❌
wrong.host.badssl.com ❌ ❌ ❌ ❌ ❌
self-signed.badssl.com ❌ ❌ ❌ ❌ ❌
untrusted-root.badssl.com ❌ ❌ ❌ ❌ ❌
revoked.badssl.com ❌ ✅ ✅ ✅ ✅
incomplete-chain.badssl.com ⚠ ❌ ❌ ✅ ❌
sha256.badssl.com ✅ ✅ ✅ ✅ ✅
1000-sans.badssl.com ✅ ✅ ✅ ✅ ✅
10000-sans.badssl.com ✅ ❌ ❌ ✅ ❌