Skip to content

Instantly share code, notes, and snippets.

View sparkydogX's full-sized avatar
🎯
Focusing

sparkydogX

🎯
Focusing
View GitHub Profile
@sparkydogX
sparkydogX / unzip.py
Created September 3, 2018 15:07
Unzip a file use python code. Design for gbk.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import zipfile
#print "Processing File " + sys.argv[1]
file=zipfile.ZipFile(sys.argv[1],"r");
@sparkydogX
sparkydogX / SS+provixy Ubuntu.md
Last active September 12, 2018 02:57 — forked from alexniver/golang, ubuntu go get in china.md
ubuntu下, 使用shadowsock和Privoxy在命令行 : )

shadowsock + Privoxy

使用shadowsock建立一个本地sock5代理, 使用privoxy把sock5代理转为http代理.

shadowsock

首先你有一个的shadowsock服务器, 确保好用.

@sparkydogX
sparkydogX / powershell-proxy-set-clear.ps1
Created September 12, 2018 13:49 — forked from famousgarkin/powershell-proxy-set-clear.ps1
PowerShell Set-Proxy, Clear-proxy
# NOTE: registry keys for IE 8, may vary for other versions
$regPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'
function Clear-Proxy
{
Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 0
Set-ItemProperty -Path $regPath -Name ProxyServer -Value ''
Set-ItemProperty -Path $regPath -Name ProxyOverride -Value ''
[Environment]::SetEnvironmentVariable('http_proxy', $null, 'User')
@sparkydogX
sparkydogX / Find Max in Tensorboard Json.html
Created November 14, 2018 05:20
Find Max in Tensorboard Json
<!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">
@sparkydogX
sparkydogX / 使用matplot绘制混淆矩阵.py
Last active November 21, 2018 13:10
使用matplot绘制混淆矩阵
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):
@sparkydogX
sparkydogX / 使用matplot绘制饼状图.py
Created November 21, 2018 13:09
使用matplot绘制饼状图
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]
@sparkydogX
sparkydogX / Vividict.py
Last active December 3, 2018 11:50
自动实现字典嵌套
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
@sparkydogX
sparkydogX / get-terminal-output.py
Created December 7, 2018 07:38
Execute terminal command and get output in python.
# 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"
@sparkydogX
sparkydogX / autodeny.sh
Last active December 12, 2019 02:55
将ssh登录错误次数过多的ip加入黑名单
#! /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
@sparkydogX
sparkydogX / update_img_juptyter.py
Created December 14, 2018 08:57
在jupyter notebook中使用button更新图像.
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):