Skip to content

Instantly share code, notes, and snippets.

@pawelszydlo
pawelszydlo / to_utf8
Last active May 24, 2020 18:35
Detect text file encoding and convert to UTF-8
#! /usr/bin/env python3
# Script to auto-detect file encoding and convert it to UTF-8.
# Uses cchardet which provides very good detection.
#
# Newest version can always be found at:
# https://gist.github.com/pawelszydlo/936d9f2cf15d04ab80a0705d1a1bef93
import cchardet
import os
@pawelszydlo
pawelszydlo / create_vpnspace
Created May 16, 2018 21:14
Create a network namespace that is connected through a VPN
#!/bin/bash
if ip netns list | grep "vpnspace" > /dev/null; then
echo "Namespace already exists."
exit 1
fi
# IP address of your external interface
INTERNET_IP=192.168.0.101
# VPN configuration
@pawelszydlo
pawelszydlo / clean_and_unmount.sh
Last active June 15, 2024 17:17
Script for cleaning MacOS related trash (dot files and folders) from a removable disk and unmounting that disk.
#!/bin/bash
# Script for cleaning MacOS related trash (dot files and folders)
# from a removable disk and unmounting that disk.
# Script does sanity checks, should be safe, but use at your own risk!
# Newest version can always be found at https://gist.github.com/pawelszydlo/5eacd49d7e57bce71e96171e9fad1cd2
# Display a dialog box.
@pawelszydlo
pawelszydlo / stream.sh
Created July 8, 2016 17:24
Script for simultaneous streaming and saving output from Raspberry Pi camera.
#!/bin/bash
# Script for simultaneous streaming and saving output from Raspberry Pi camera.
# newest version at: https://gist.github.com/pawelszydlo/ee6d317b2d6f37e32a93f97a3d5615d0
date=`date +%Y-%m-%d_%H-%M-%S`i
recordings_dir="/home/pi/recordings"
stream_dir="$recordings_dir/$date"
min_disk_space=200
@pawelszydlo
pawelszydlo / transmission_remove_finished.sh
Last active June 10, 2024 14:37
Script to clear finished torrents from transmission-daemon
#!/bin/bash
# Clears finished downloads from Transmission.
# Version: 1.1
#
# Newest version can always be found at:
# https://gist.github.com/pawelszydlo/e2e1fc424f2c9d306f3a
#
# Server string is resolved in this order:
# 1. TRANSMISSION_SERVER environment variable
@pawelszydlo
pawelszydlo / bt_pair_export.py
Last active July 6, 2022 10:22
Script to dump bluetooth pairing from OS X into a Windows registry file.
#!/usr/bin/env python
"""
Script for dumping Bluetooth pairings from OS X to a registry file, for Windows
import. This will allow you to have your Bluetooth devices paired with both
operating systems at the same time.
In case of problems with Windows registry entries: pair your device with Windows
first, then with OS X, and then do the dump and import.
Latest version can be found at:
@pawelszydlo
pawelszydlo / ImageWithThumbField.py
Last active August 29, 2015 13:55
Django Image field with thumbnail.
from django.db.models import ImageField
from django.db.models import signals
from django.db.models.fields.files import ImageFieldFile
from PIL import Image
import os
def name_thumb(str):
""" Function for generating thumbnail name from original file. """