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 os | |
import logging | |
if __name__ == '__main__': | |
logging.basicConfig(filename='example.log',format='%(asctime)s %(process)s %(module)s %(message)s',level=logging.DEBUG) | |
logging.debug('This message should go to the log file') | |
logging.info('So should this') | |
logging.warning('And this, too') | |
logging.warning('Watch out!') # will print a message to the console | |
logging.info('I told you so') # will not print anything |
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 numpy as np | |
class rint(object): | |
def __init__(self,stat='A'): | |
self.val = 0 | |
if stat == 'train': | |
self.rng = np.random.RandomState(seed=100) | |
else: | |
self.rng = np.random.RandomState(seed=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
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
sparkydog = r''' | |
-os+` | |
`hmmds------------------------------------. | |
-oymddddddddddddddddddddddddddddddddddddd+ | |
:dmmmmmmmmmd+///////////////////////hmm+ | |
`smmmmmmmmd+ -::::. ymm+ | |
`ydmmmdds: :/sy/` ..` ymm+ | |
`odmdy-` `` /ddy. ymm+ |
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
from IPython import display | |
import time | |
import ipywidgets | |
from ipywidgets import widgets | |
button = widgets.Button(description = "Click") | |
out = widgets.Output() | |
display.display(widgets.VBox([out,button],layout=ipywidgets.Layout(align_items='center'))) | |
def on_button_clicked(b): |
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
#! /bin/bash | |
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > /usr/local/bin/black.list | |
for i in `cat /usr/local/bin/black.list` | |
do | |
IP=`echo $i |awk -F= '{print $1}'` | |
NUM=`echo $i|awk -F= '{print $2}'` | |
if [ ${#NUM} -gt 1 ]; then | |
grep $IP /etc/hosts.deny > /dev/null | |
if [ $? -gt 0 ];then | |
echo "sshd:$IP:deny" >> /etc/hosts.deny |
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
# For short output. | |
import subprocess | |
cmd = "git branch | grep '*' | cut -d ' ' -f2" | |
output = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True).communicate()[0] | |
print(output.strip()) # For single line output. | |
# For long output. | |
import subprocess | |
import tempfile | |
cmd = "git branch | grep '*' | cut -d ' ' -f2" |
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
class Vividict(dict): | |
def __missing__(self, key): | |
value = self[key] = type(self)() | |
return value | |
def walk(self): | |
for key, value in self.items(): | |
if isinstance(value, Vividict): | |
for tup in value.walk(): | |
yield (key,) + tup |
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 itertools | |
import matplotlib.pyplot as plt | |
import numpy as np | |
plt.rcParams['font.family'] = 'sans-serif' | |
plt.rcParams['font.sans-serif']=['Tahoma', 'DejaVu Sans','Lucida Grande', 'Verdana'] | |
if __name__ == '__main__': | |
plt.figure(figsize=(6,9)) | |
labels = ['stand', 'walk', 'run'] | |
sizes = [3322,13331,277] |
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 itertools | |
import matplotlib.pyplot as plt | |
import numpy as np | |
plt.rcParams['font.family'] = 'sans-serif' | |
plt.rcParams['font.sans-serif']=['Tahoma', 'DejaVu Sans', | |
'Lucida Grande', 'Verdana'] | |
def plot_confusion_matrix(cm, classes, | |
normalize=False, | |
title='Confusion matrix', | |
cmap=plt.cm.Blues): |
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Find Min/Max Value</title> | |
<meta name="description" content="The HTML5 Herald"> | |
<meta name="author" content="sparkydog"> |