Skip to content

Instantly share code, notes, and snippets.

View wention's full-sized avatar

WENTION wention

View GitHub Profile
import subprocess
def cmd_run(cmd):
if isinstance(cmd, str):
cmd = cmd.split()
if not isinstance(cmd, list):
raise Exception("TypeError cmd_run only accept str,list")
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
@wention
wention / debug_too_many_open_files.py
Created January 3, 2018 03:53
debug too many open files problem
import __builtin__
openfiles = set()
oldfile = __builtin__.file
class newfile(oldfile):
def __init__(self, *args):
self.x = args[0]
print "\033[01;31m##### %d #### OPENING %s ###\033[00m" % (len(openfiles),str(self.x))
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
@wention
wention / wol.py
Created January 22, 2018 03:41
Wake on Lan
import sys
import socket
import struct
def wake_on_lan(macaddress):
""" Switches on remote computers using WOL. """
# Check macaddress format and try to compensate.
if len(macaddress) == 12:
pass
class NetUtils:
@classmethod
def CheckInterfaceConnected(cls, inDev):
dev_path = "/sys/class/net/%s" % inDev
carrier_path = dev_path + "/carrier"
opersate_path = dev_path + "/operstate"
@wention
wention / list-iommu-groups
Created July 19, 2018 14:10
list iommu groups
#!/bin/bash
shopt -s nullglob
for g in $(ls /sys/kernel/iommu_groups); do
echo "IOMMU Group $g"
for d in /sys/kernel/iommu_groups/$g/devices/*; do
n=${d#*/iommu_groups/*}; n=${n%%/*}
ret=`lspci -nns "${d##*/}"`
@wention
wention / nm-config
Last active July 2, 2019 09:05
NetworkManager python 配置脚本化
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import uuid
import json
import struct
import socket
import logging
@wention
wention / mount-qcow2-lvm-image.sh
Created May 12, 2019 07:01 — forked from pshchelo/mount-qcow2-lvm-image.sh
List of commands to mount/unmount a qcow2 image conatining LVM partitions.
# kudos to dzaku at consolechars.wordpress.com
### MOUNT qcow2 image with lvm partitions
# ensure nbd can handle that many partitions
sudo modprobe nbd max_part=8
# present image as block device through NBD
sudo qemu-nbd --connect=/dev/nbd0 <image.qcow2>
@wention
wention / export_or_import.md
Last active September 27, 2024 20:58
Set Gnome Terminal font using dconf

Export gnome terminal settings

dump gnome terminal settings

dconf dump /org/gnome/terminal/legacy/profiles:/
[:b1dcc9dd-5262-4d8d-a863-c897e6d979b9]
import os
import imp
def import_file(module_path):
base_path = os.path.dirname(module_path)
module_name = os.path.basename(module_path).rstrip('.py')
fp, pathname, description = imp.find_module(module_name, [base_path])
try: