Skip to content

Instantly share code, notes, and snippets.

View alex-1q84's full-sized avatar
🎯
Focusing

dahai alex-1q84

🎯
Focusing
View GitHub Profile
@alex-1q84
alex-1q84 / rsync-usb.sh
Last active October 26, 2022 03:31 — forked from ground-creative/rsync-usb.sh
auto backup files to usb device using rsync
#!/bin/bash
####### RSYNC AUTO BACKUP TO USB DEVICE V0.5 ##########
####### Developed by Carlo Pietrobattista ###########
### CONFIG VARS #####################################
LOCK_FILE="/tmp/rsync-usb.pid" # the lock file name
MOUNT_DEV="/dev/sdh1" # mount device
MOUNT_PATH="/mnt/autobackup-usb" # mount point
BACKUP_DIR="/home/*" # backup directory
RSYNC_LOG_FILE="/var/log/rsync/usb_backup.log" # rsync log file
#####################################################
@alex-1q84
alex-1q84 / group_number.py
Created September 4, 2019 09:00
任意个整数尽量平均分配到多个组
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pprint
class Node:
def __init__(self, id, count):
self.id = id
self.count = count
@alex-1q84
alex-1q84 / Python TCP Client Example.py
Created August 20, 2019 07:51 — forked from Integralist/Python TCP Client Example.py
Python TCP Client Server Example
import socket
hostname, sld, tld, port = 'www', 'integralist', 'co.uk', 80
target = '{}.{}.{}'.format(hostname, sld, tld)
# create an ipv4 (AF_INET) socket object using the tcp protocol (SOCK_STREAM)
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# connect the client
# client.connect((target, port))
@alex-1q84
alex-1q84 / callJmx.groovy
Created October 14, 2016 08:31
call jmx use groovy
import java.lang.management.*
import javax.management.ObjectName
import javax.management.remote.JMXConnector
import javax.management.remote.JMXConnectorFactory as JmxFactory
import javax.management.remote.JMXServiceURL as JmxUrl
def callJmx(String jmxUrl, String beanName, String operator, Object args, String userName=null, String password=null) {
def jmxEnv = null
if (userName != null && password != null) {
jmxEnv = [(JMXConnector.CREDENTIALS): (String[])[userName, password]]
@alex-1q84
alex-1q84 / wall.action
Last active November 11, 2015 13:34
privoxy rule
#append the "actionsfile wall.action" to the config
#and save this file as wall.action into the same dir as config file
#restart the privoxy to see if these configuration actived
{{alias}}
direct = +forward-override{forward .}
ssh = +forward-override{forward-socks5 127.0.0.1:7070 .}
default = direct
#gappproxy = +forward-override{forward localhost
{default}
@alex-1q84
alex-1q84 / gen_prod_profile_table.groovy
Created April 10, 2015 02:57
解析maven pom.xml并生成指定profile的配置详情表格
def htmlHead(){
println("""<html lang="en">""")
println("<body>")
}
def htmlTail(){
println("</body>")
println("</html>")
}
@alex-1q84
alex-1q84 / 37persent_simulator.py
Last active December 16, 2015 05:59
未婚妻问题 关于女神选择白马王子的最佳方案和常数e的关系 see http://www.guokr.com/article/6768/
#!/usr/bin/env python
#-*-coding: UTF-8-*-
'''未婚妻问题
关于女神选择白马王子的最佳方案和常数e的关系
see http://www.guokr.com/article/6768/
'''
import random
import math
@alex-1q84
alex-1q84 / compild.py
Last active March 8, 2022 09:22
使用python的sched和Timer执行定时任务
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sched, time
from threading import Thread, Timer
import subprocess
s = sched.scheduler(time.time, time.sleep)
class Job(Thread):