Skip to content

Instantly share code, notes, and snippets.

View sparkydogX's full-sized avatar
🎯
Focusing

sparkydogX

🎯
Focusing
View GitHub Profile
@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 / numpy_randomseed.py
Created December 27, 2018 14:03
在一个文件中控制不同的变量拥有不同的随机数种子
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)
@sparkydogX
sparkydogX / py_logging_example.py
Last active January 3, 2019 02:03
python中内置的logging模块使用示例
# 基础用法
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
@sparkydogX
sparkydogX / convnet_test.py
Created January 4, 2019 13:26 — forked from axel-angel/convnet_test.py
Caffe script to compute accuracy and confusion matrix
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Author: Axel Angel, copyright 2015, license GPLv3.
import sys
import caffe
import numpy as np
import lmdb
import argparse
@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 / tqdm_with_description.py
Created February 18, 2019 13:56
tqdm中加入前缀和后缀进行描述
import time
from tqdm import tqdm
if __name__ == '__main__':
s = 0
t = tqdm(range(100))
for i in t:
s += i
time.sleep(0.05)
t.set_description("step{0:3d}".format(i))
@sparkydogX
sparkydogX / add-notes-head.tex
Created March 1, 2019 15:16
在tex中添加注释
\usepackage[textsize=tiny]{todonotes}
\usepackage{marginnote}
\paperwidth=\dimexpr \paperwidth + 6cm\relax
\oddsidemargin=\dimexpr\oddsidemargin + 3cm\relax
\evensidemargin=\dimexpr\evensidemargin + 3cm\relax
\marginparwidth=\dimexpr \marginparwidth + 3cm\relax
@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={}
@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 / 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")