Skip to content

Instantly share code, notes, and snippets.

View giner's full-sized avatar

Stanislav German-Evtushenko giner

View GitHub Profile
@giner
giner / xorg_remap_play_to_micmute.sh
Last active November 30, 2021 03:46
Remap Play button to Mic Mute (primarily for Bluetooth Headsets)
#!/bin/sh
# NOTE: This change won't persist if package xkb-data is reinstaled or updated
sudo sed -i '/key <I208>/s/\bXF86AudioPlay\b/XF86AudioMicMute/' /usr/share/X11/xkb/symbols/inet
@giner
giner / HelloFeignmTLS.java
Last active August 28, 2024 14:38
Java: Feign Client mTLS (by enabling custom keystore and truststore for a specific enpoint)
// How to test
//
// Update uriPrefix, keystoreFile, keystorePassword, truststoreFile, truststorePassword with your values and run:
// curl -L -O https://repo1.maven.org/maven2/io/github/openfeign/feign-core/11.6/feign-core-11.6.jar
// java -cp feign-core-11.6.jar HelloFeignmTLS.java
// Feign
import feign.Feign;
import feign.RequestLine;
@giner
giner / java-mtls-client.sh
Last active August 29, 2021 12:33
Java: Enable client side mTLS without modifying application
# Notes:
# - option javax.net.ssl.trustStore replaces default java truststore
# i.e. TLS connections other than mTLS won't be possible unless
# the new truststore contains Common CA certificates
# - The custom CA certificate from truststore.pkcs12 will be used by
# all TLS connections initiated from the app. Make sure you can
# fully trust this CA in your specific case.
# - Generation of the keystores is not a part of this snippet and can
# be easily found on other resources
#
@giner
giner / HelloWorldJava
Last active August 29, 2021 13:35
Java: Run Java code without compiling (JEP 330)
#!/usr/bin/env -S java --source 11
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
@giner
giner / HelloFeign.java
Last active August 29, 2021 11:39
Java, OpenFeign: Minimalistic quick start example
// Usage:
// curl -L -O https://repo1.maven.org/maven2/io/github/openfeign/feign-core/11.6/feign-core-11.6.jar
// java -cp feign-core-11.6.jar HelloFeign.java
import feign.Feign;
import feign.RequestLine;
public class MyFeignClient {
private static final String uriPrefix = "https://github.com";
@giner
giner / cache.py
Last active September 2, 2022 18:48
Python: Simple way to cache function result using decorator
#!/usr/bin/python
def cache(func):
def wrapper(*args, **kwargs):
if hasattr(func, "cache"):
return func.cache
func.cache = func(*args, **kwargs)
return func.cache
return wrapper
@giner
giner / drawio_mime_type.sh
Last active August 17, 2023 13:50
Give *.drawio files MIME type to make application association work
#!/bin/sh
# drawio.xml is taken from Draw.io debian package
cat > ~/.local/share/mime/packages/drawio.xml << 'EOF'
<?xml version="1.0" encoding="utf-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/vnd.jgraph.mxfile">
<glob pattern="*.drawio"/>
<comment>draw.io Diagram</comment>
<icon name="x-office-document" />
@giner
giner / decat.sh
Last active May 15, 2023 00:17
Encrypt / Decrypt files with OpenSSL
#!/bin/bash
# Inspired by https://www.meixler-tech.com/web-browser-based-file-encryption-decryption.html
set -eu
openssl_enc_opts=()
file_no_ext=$(basename "$@" .enc)
[[ $# != 1 ]] && { echo "Usage: $(basename $0) FILE_NAME.enc"; exit 1; }
@giner
giner / install_ansible.sh
Last active November 25, 2020 15:45
Install ansible to a dedicated directory with all dependencies
ansible_version="2.9.*"
sudo apt-add-repository universe
sudo apt install -y python3-pip python3-venv
[[ -d "$HOME/bin" ]] || { mkdir "$HOME/bin"; source $HOME/.profile; }
python3 -m venv ~/ansible
~/ansible/bin/pip3 install wheel
@giner
giner / fix_ibus-mozc.sh
Last active October 27, 2024 13:16
JAPANESE: Make ibus-mozc remember last used mode
# Make ibus-mozc remember the last used mode (e.g. hiragana) and not switch back to Alphabet on restart
# See https://github.com/google/mozc/issues/381
cd $(mktemp -d)
apt source ibus-mozc
cd mozc-*/
patch src/unix/ibus/property_handler.cc << 'EOF'
--- src/unix/ibus/property_handler.cc.orig 2020-10-28 17:21:18.000849932 +0900
+++ src/unix/ibus/property_handler.cc 2020-10-28 17:21:34.172696046 +0900
@@ -80,7 +80,7 @@