Skip to content

Instantly share code, notes, and snippets.

@glacjay
glacjay / tun-ping-win.py
Created September 19, 2010 16:24
Reading/Writing OpenVPN's TUN/TAP Device under Windows using Python.
import _winreg as reg
import win32file
adapter_key = r'SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}'
def get_device_guid():
with reg.OpenKey(reg.HKEY_LOCAL_MACHINE, adapter_key) as adapters:
try:
@valorin
valorin / mosh-allow-ufw.sh
Created December 6, 2014 20:49
Script to open and close Mosh ports in UFW
#!/bin/bash
# Load active ports
PORTS=`lsof -i | grep mosh-serv | cut -f2 -d":"`
STATUS=`sudo ufw status`
# Add Rules for new ports
for PORT in $PORTS; do
echo $STATUS | grep "$PORT/udp" > /dev/null
@b4tman
b4tman / time_calc.py
Last active April 10, 2020 12:59
Калькулятор для вычисления выражений со значениями указанными в форме времени. Например "(12:05 - 11:30) / 2".
# -*- coding: utf-8 -*-
"""
simple calculator for time
based on fourFn.py (pyparsing module examlple)
"""
from pyparsing import Literal,CaselessLiteral,Word,Combine,Optional,\
ZeroOrMore,Forward,nums,alphas
import sys, operator
@gmolveau
gmolveau / uuid_user.py
Last active January 17, 2025 02:56
sqlalchemy uuid for sqlite
########################
# UUID for SQLite hack #
########################
from sqlalchemy.types import TypeDecorator, CHAR
from sqlalchemy.dialects.postgresql import UUID
import uuid
class GUID(TypeDecorator):
@rpunt
rpunt / mktemp.ps1
Created February 15, 2020 16:52
I've wanted mktemp in powershell forever, so... fine.
function mktemp {
param (
[Parameter(mandatory=$false)]$Extension
)
$randomfile = [System.IO.Path]::GetRandomFileName()
if ($Extension) {
$randomfile = [System.IO.Path]::ChangeExtension($randomfile, $Extension)
}
return Microsoft.PowerShell.Management\Join-Path ([System.IO.Path]::GetTempPath()) "$randomfile"
}
@s3rj1k
s3rj1k / HowTo
Last active January 3, 2026 03:07
Ubuntu 20.04.3 AutoInstall
# For recent versions of Ubuntu:
- https://www.pugetsystems.com/labs/hpc/ubuntu-22-04-server-autoinstall-iso/
# Docs:
- https://wiki.ubuntu.com/FoundationsTeam/AutomatedServerInstalls
- https://wiki.ubuntu.com/FoundationsTeam/AutomatedServerInstalls/ConfigReference
- https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html
- https://discourse.ubuntu.com/t/please-test-autoinstalls-for-20-04/15250/53
# Download ISO Installer:
@doitian
doitian / registries.conf
Last active December 16, 2024 07:56
[Configure Docker Hub mirror in /etc/containers/registries.conf] #docker #podman #proxy
unqualified-search-registries = ['docker.io']
[[registry]]
prefix = "docker.io"
location = "docker.io"
[[registry.mirror]]
prefix = "docker.io"
# This will set the docker registry mirror of a chinese university.
# DON'T use it unless you have a network connection issue and you trust the mirror provider.
@arrowinaknee
arrowinaknee / office_unlocker.pyw
Last active May 11, 2025 13:47
Снимает защиту от редактирования с файлов MS Word (.docx) и MS Excel (.xlsx)
import os
import shutil
import tempfile
import re
import sys
import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox
@CharlesGodwin
CharlesGodwin / How to use ssh-copy-id.md
Last active February 11, 2026 12:25
Windows 10/11 scripts to support ssh-copy-id which is missing in Windows OpenSSH

The Windows version of OpenSSH client doesn't include a ssh-copy-id command. I don't know why. If it does one day, then this gist can be ignored.

  • This script is written in PowerShell as the legacy program cmd.exe is not flexible enough for the required options.
  • Download the file ssh-copy-id.ps1 to your Windows PC, or copy and paste its contents to a file of the same name.
  • Run the script passing your linux account ssh information (for example powershell .\ssh-copy-id.ps1 [email protected]). If you use a non-standard port add the parameter -port=nnnn. This should work with any Linux platform.
  • Run the command for each linux account you connect with. You will be prompted for your Linux host password. If you have more than 1 account on any machine, you must do this for each account.

If the script won't run, then run this command once

Set-ExecutionPolicy RemoteSigned CurrentUser

@seefalert
seefalert / script_input_data.py
Last active September 11, 2025 09:17
Этот код - тестовый скрипт для проверки вашего кода. Убедитесь, что у вас есть папка "tests" с тестовыми файлами и ответами. Также у вас должен быть файл "my_code.py" с кодом, который нужно протестировать. Запустите скрипт, и он выполнит тесты, выведет результаты и сообщит, успешно ли пройдены все тесты.
import os
import pathlib
import time
import psutil
import subprocess
import sys
def load_test_file(file_path):
with open(file_path, encoding='utf-8') as file: