This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def in_order_morris(root): | |
while root: | |
if not root.left: | |
# no left child, output and go right | |
print(root.val) | |
root = root.right | |
else: | |
# has left child | |
# find the most right left child | |
predecessor = root.left |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def thread_run(func): | |
import functools | |
import threading | |
@functools.wraps(func) | |
def wrapper(*args): | |
threading.Thread(target=func, args=(*args,), daemon=True).start() | |
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
class MonkeyPatch(object): | |
def __init__(self, original, patch): | |
self.original = original | |
self.patch = patch | |
self.cache = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo autossh -f -M 999 -N -o "PubkeyAuthentication=yes" -o "StrictHostKeyChecking=false" -o "PasswordAuthentication=no" -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 0.0.0.0:9091:localhost:9091 -i /home/lane/.ssh/id_rsa [email protected] | |
sudo autossh -f -M 888 -N -o "PubkeyAuthentication=yes" -o "StrictHostKeyChecking=false" -o "PasswordAuthentication=no" -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 0.0.0.0:2222:localhost:22 -i /home/lane/.ssh/id_rsa [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
LOG_LEVEL = logging.DEBUG | |
formatter = logging.Formatter('%(asctime)s - %(name)s:%(lineno)-4s - %(levelname)s - %(message)s') | |
logger = logging.getLogger("logger.py") | |
handler = logging.FileHandler(LOG_FILE) | |
logger.setLevel(level=LOG_LEVEL) | |
handler.setLevel(level=LOG_LEVEL) | |
handler.setFormatter(formatter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import paramiko | |
# create ssh clinet | |
ssh = paramiko.SSHClient() | |
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
ssh.connect("domain", 22, "username", "password") | |
# execute ssh command | |
cmd = 'echo $HOSTNAME' | |
stdin, stdout, stderr = ssh.exec_command(cmd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sudo pip install sshtunnel | |
import sshtunnel | |
with sshtunnel.open_tunnel( | |
# jumpserver host, port. port 22 in general(ssh port) | |
("jumpserver_host", 22), | |
# username for jumpserver | |
ssh_username="jumpserver_username", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use 5.016; | |
use File::Find; | |
find(\&wanted, $target); | |
sub wanted { | |
my $path = $File::Find::name; | |
say $path; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'Find' | |
def each_file target | |
Find.find(target) do |path| | |
if not File.directory? path | |
yield path | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use Cwd; | |
use File::Spec; | |
use File::Basename; | |
sub each_file { | |
my $givenFolder = shift @_; | |
our @pList; # path list to be returned | |
&innerEachFile($givenFolder); |