Skip to content

Instantly share code, notes, and snippets.

View qiuchengxuan's full-sized avatar

qiuchengxuan qiuchengxuan

View GitHub Profile
@qiuchengxuan
qiuchengxuan / gist:55042746682098e5f536
Created March 17, 2015 05:23
Winsock2 server side with random listening port
WSADATA wsaData;
int iResult;
iResult = WSAStartup(MAKEWORD(2,2),&wsaData);
if (iResult != 0) {
return;
}
SOCKADDR_IN server;
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
@qiuchengxuan
qiuchengxuan / gist:6ae947cd1f6d1fff1a49
Created March 17, 2015 05:27
MFC message only invisible window
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg) {
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
@qiuchengxuan
qiuchengxuan / A simple shell script to attach usb device to kvm
Created September 12, 2015 05:48
A simple shell script to attach usb device to kvm
#!/bin/bash
IFS=$'\r\n'
array=(`lsusb -v 2> /dev/null | grep "\(Bus\|bInterfaceClass\)" | awk -F ' ' '{if(/Bus/){printf "%s ",$0} else {$1="";$2="-";print $0}}' | grep -o "ID.*"`)
for i in `seq 0 $(expr ${#array[*]} - 1)`; do
echo -n "$i "
echo "${array[$i]}"
done
echo -n "choose usb device: "
id=`echo ${array[$(read)]} | grep -o "[0-9]\+:[0-9]\+"`
virsh list --all
@qiuchengxuan
qiuchengxuan / sudoku.py
Last active January 4, 2016 13:42
simple sudoku solver
#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
def parse(s):
return list(map(lambda c : 0 if c == ' ' else ord(c) - ord('0'), s))
board = [parse(input()) for i in range(9)]
# s = input()
# board = [parse(s[i * 9 : i * 9 + 9]) for i in range(9)]
# input()
# answer = [parse(input()) for i in range(9)]
@qiuchengxuan
qiuchengxuan / netconf_huawei.py
Last active October 20, 2022 18:56
Access Huawei switch via NETCONF with python script
#!/usr/bin/python
import sys
import code
from lxml import etree
from lxml.builder import E
from ncclient import manager
_, ip, user, passwd = sys.argv
netconf = manager.connect(host=ip, port=830, username=user, password=passwd,
@qiuchengxuan
qiuchengxuan / netconf_h3c.py
Last active December 10, 2017 03:55
Access H3C switch via NETCONF with python script
#!/usr/bin/python
import sys
import code
from lxml import etree
from lxml.builder import E
from ncclient import manager
_, ip, user, passwd = sys.argv
netconf = manager.connect(host=ip, port=830, username=user, password=passwd,
@qiuchengxuan
qiuchengxuan / huawei_cli.py
Last active July 13, 2023 08:39
Access HUAWEI Switch via CLI with python script
#!/usr/bin/python
import sys
_, ip, user, passwd = sys.argv
CLI_PROMPT = r'[\[<][^>\]]+[\]>]'
ssh = spawn('ssh %s@%s' % (username, ip))
if not ssh:
return
ssh.expect('password')
@qiuchengxuan
qiuchengxuan / mininet_sshd.py
Created December 10, 2017 03:50
Create a lot of sshd host for testing, based on mininet
#!/usr/bin/python
import ipaddress
import argparse
from mininet.topo import Topo
from mininet.nodelib import LinuxBridge
from mininet.net import Mininet
from mininet.cli import CLI
from mininet.util import waitListening
@qiuchengxuan
qiuchengxuan / emacs-latest.spec
Last active March 2, 2021 02:06
build latest emacs into rpm package
Name: emacs25
Version: 25.3
Release: 1%{?dist}
Summary: GNU Emacs
#Group:
License: GPL
URL: http://www.gnu.org/software/emacs/
Source0: http://mirrors.ustc.edu.cn/gnu/emacs/emacs-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
@qiuchengxuan
qiuchengxuan / hotplug.sh
Created December 11, 2019 12:56
A simple script to hotplug hard drives on linux
#!/bin/bash
entries=($(find /dev/disk/by-id -type l -printf '%l %f\n' | grep -v '\(part\|wwn\)' | sed 's#../../##g' | tr '\n' ' '))
entries+=('' '' 'rescan' 'RESCAN')
choice=$(whiptail --notags --title "Hotplug" --menu "Select device" 16 100 9 "${entries[@]}" 3>&1 1>&2 2>&3)
test -n "$choice" || exit 0
case $choice in
"rescan")
echo 'Rescan disks...'
echo '- - -' > /sys/class/scsi_host/host0/scan