Skip to content

Instantly share code, notes, and snippets.

View sparkydogX's full-sized avatar
🎯
Focusing

sparkydogX

🎯
Focusing
View GitHub Profile
@sparkydogX
sparkydogX / occupy-memory.py
Last active March 27, 2024 05:55
Pytorch trick : occupy all GPU memory in advance
import os
import torch
from tqdm import tqdm
import time
# declare which gpu device to use
cuda_device = '0'
def check_mem(cuda_device):
devices_info = os.popen('"/usr/bin/nvidia-smi" --query-gpu=memory.total,memory.used --format=csv,nounits,noheader').read().strip().split("\n")
@sparkydogX
sparkydogX / py2_SimpleHTTPServerWithUpload.py
Created February 3, 2019 07:14
在SimpleHTTPServer中加入上传功能
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
__version__ = "0.2"
__all__ = ["SimpleHTTPRequestHandler"]
@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 / overlap-img.tex
Created April 8, 2019 17:44
在tex中重叠图像
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\begin{center}
\begin{tikzpicture}
\node (img1) {\includegraphics[height=3cm]{img0.jpg}};
\pause
\node (img2) at (img1.south west)[yshift=1.4cm,xshift=1.4cm] {\includegraphics[height=3cm]{img1.jpg}};
@sparkydogX
sparkydogX / tikz-example.tex
Created March 28, 2019 05:44
使用tikz在latex中作图--示例
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{minipage}{0.4\textwidth}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=1.8cm,
thick,main node/.style={circle,draw,font=\sffamily\Large\bfseries},
box/.style = {rectangle, draw,minimum width=12mm, minimum height=7mm}]
\node[main node] (1) {4096};
\node[main node] (2) [right of=1]{8};
\node[main node] (3) [below of=2] {4};
@sparkydogX
sparkydogX / conf_matrix_ocr.py
Last active March 22, 2019 02:33
Get array from confusion matrix image. And save it to xlsx file for manual correction.
from __future__ import print_function
import cv2
import pytesseract
import numpy as np
from os import listdir
from os.path import join
import pandas
import xlsxwriter
@sparkydogX
sparkydogX / godblessdbg.py
Created December 18, 2018 12:46
Have fun!
# -*- coding: utf-8 -*-
from __future__ import print_function
sparkydog = r'''
-os+`
`hmmds------------------------------------.
-oymddddddddddddddddddddddddddddddddddddd+
:dmmmmmmmmmd+///////////////////////hmm+
`smmmmmmmmd+ -::::. ymm+
`ydmmmdds: :/sy/` ..` ymm+
`odmdy-` `` /ddy. ymm+
@sparkydogX
sparkydogX / initialize_gitment_via_firefox.py
Last active March 12, 2019 05:03
通过打开firefox标签初始化gitment
import sys
import os
import subprocess
ROOTDIR = '<you path>/hexo/public'
YEAR = ['2017','2018','2019']
URLList = []
BEGIN = 0
NUM = 10
if __name__ == '__main__':
for year in YEAR:
@sparkydogX
sparkydogX / python_filter_example.py
Created March 6, 2019 02:42
This is a simple example for python filter
def evenFilter(d):
if d['idx'] % 2 == 0:
return True
else:
return False
if __name__ == '__main__':
L = []
for i in range(10):
d={}