Skip to content

Instantly share code, notes, and snippets.

View duchenpaul's full-sized avatar
:shipit:
Out sick

Chenny Du duchenpaul

:shipit:
Out sick
  • Citrix Systems, Inc.
  • Nanjing
View GitHub Profile
  • Add sudoer
# Config editor
sudo update-alternatives --config editor

#add user to sudoer
vi /etc/sudoers (visudo)

## Allow root to run any commands anywhere
@duchenpaul
duchenpaul / win_path2wsl_path.py
Last active December 7, 2020 08:33
Convert windows path to wsl path
'''Convert windows path to wsl path'''
import sys
windows_path = sys.argv[1]
MOUNT_PATH = '/mnt'
windows_path_split = windows_path.split(':\\')
diskLabel, path = windows_path_split[0].lower(), windows_path_split[1].replace('\\', r'''/''').replace(' ', r'''\ ''')
wsl_path = '/'.join((MOUNT_PATH, diskLabel, path))
@duchenpaul
duchenpaul / data_group.py
Created September 22, 2018 09:15
Grouping data
def cluster(data, maxgap):
'''Arrange data into groups where successive elements
differ by no more than *maxgap*
>>> cluster([1, 6, 9, 100, 102, 105, 109, 134, 139], maxgap=10)
[[1, 6, 9], [100, 102, 105, 109], [134, 139]]
>>> cluster([1, 6, 9, 99, 100, 102, 105, 134, 139, 141], maxgap=10)
[[1, 6, 9], [99, 100, 102, 105], [134, 139, 141]]
@duchenpaul
duchenpaul / caffeine.ps1
Last active October 27, 2021 05:14
A simple vbs to prevent your PC from policy screen lock
Add-Type -AssemblyName System.Windows.Forms
New-Variable -name INTERVAL -Value (60 * 2) -Option Constant -Description 'for 5mins lock default'
get-date
echo `start`
while ($true) {
$key = '{SCROLLLOCK}'
get-date
echo "press key $key`n"
try {
[System.Windows.Forms.SendKeys]::SendWait($key)
@duchenpaul
duchenpaul / service_controller.sh
Created February 23, 2018 09:28
Simple script to control service
#!/bin/bash
TARGET_SERVICE=server_status_web
service_start_cmd='/home/pi/run/server_statisic/FlaskApp/server_status_web.py'
usage(){
echo -e "Usage: bash $0 [ start | stop | restart ] "
exit 1
}
start_service(){
@duchenpaul
duchenpaul / starwars.py
Last active September 13, 2017 16:32 — forked from stestagg/starwars.py
micropython starwars
import gc
import machine
# import machine
import time
import network
SSID='Poop'
PWD='cockcock'
# Configure GPIO pins 0 and 2 to be used for
@duchenpaul
duchenpaul / gist:8ec1efae0880397d1a9643f0edaaa998
Last active May 11, 2017 02:31 — forked from alphazo/gist:3303282
Clone MiFare cards using chinesse UUID writable cards

libnfc supports UUID writable cards and even has some dedicated tools for them.

However it doesn't work with some of the cards found on eBay that are even simpler to use. Sector 0 is unlocked and can be written without any additional commands. libnfc requires a small patch to get it working.

Following has been tested under ArchLinux with modified libnfc 1.5.1, mfoc 0.10.2 and a SCL3711 dongle.

Patch & recompile libnfc

The patch is fairly simple, open libnfc-1.5.1/utils/nfc-mfclassic.c and comment 2 lines (it was lines 384 and 385 for me):

// Try to write the trailer

for %%F in (*.zip) do ( "C:\Program Files\7-Zip\7z.exe" x -y -o"%%F_tmp" "%%F" * & pushd %%F_tmp & "C:\Program Files\7-Zip\7z.exe" a -y -r -t7z ..\"%%~nF".7z * & popd & rmdir /s /q "%%F_tmp" )
@duchenpaul
duchenpaul / Linux_hardware_emonitor.sh
Created October 8, 2015 13:22
监测服务器CPU、内存MEM、磁盘DISK数据。
#!/bin/bash
#filename seerver_moniter.sh
mem_quota=20
hd_quota=50
cpu_quota=80
# watch memory usage
watch_mem()
#!/bin/bash
TIMESTAMP=$(date +%F)
ssh -i /home/pi/.ssh/id_rsa_3072 root@192.168.31.240 <<'ENDSSH'
#commands to run on remote host
rm reaver_backup_*.zip;
zip -r ~/reaver_backup_`date +"%Y%m%d"`.zip /usr/local/etc/reaver;
scp -i /root/.ssh/id_rsa_3072 ~/reaver_backup*.zip pi@192.168.31.179:~/;
exit