Skip to content

Instantly share code, notes, and snippets.

View python012's full-sized avatar

Reed Xia python012

View GitHub Profile
@python012
python012 / gist:21317c81469326bd3100
Last active August 29, 2015 14:10
Practice multiple threads code, will improve one of my Python programs' efficiency.
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 2014年12月7日
@author: reed
'''
import thread
import time
@python012
python012 / gist:81e159df93665c465005
Created December 9, 2014 02:31
Use yield in Fibonacci list
#!/usr/bin/env python
# -*- coding:utf-8 -*-
def fab(max):
n, a, b = 0, 0, 1
while n < max:
yield b
a, b = b, a + b
n = n + 1
@python012
python012 / gist:4cf7fe6a4dc63ef047b4
Last active August 29, 2015 14:11
Try the code with multiprocessing
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from multiprocessing import Process
from multiprocessing import Queue
from multiprocessing import Pool
import multiprocessing
path_list = range(10)
bad_path_list = []
@python012
python012 / settings.xml
Created April 20, 2017 03:10
Maven settings.xml with aliyun mirror
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
@python012
python012 / py_unittest.py
Last active April 14, 2018 00:56
Try patch and mock functions in unit test
#!/usr/bin/env python3
from unittest import TestCase
from unittest.mock import patch
from unittest import main
class Person(object):
def __init__(self, name):
self.name = name
@python012
python012 / ScreenshotRule.java
Last active May 15, 2018 01:35
A JUnit TestWatcher to take screenshot when test fails.
package com.ibm.robot.web.testrules;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.openqa.selenium.OutputType;
@python012
python012 / function.py
Created June 26, 2018 08:40
python lib inspect, could help check the target function's caller
import copy
import os
from importlib import import_module
from importlib.util import find_spec as importlib_find
import inspect
def import_string(dotted_path):
"""
Import a dotted module path and return the attribute/class designated by the
@python012
python012 / settings.json
Created September 14, 2018 08:37
VS Code settings as json file
{
"explorer.confirmDelete": false,
"workbench.iconTheme": "vscode-great-icons",
"editor.minimap.enabled": true,
"terminal.integrated.rendererType": "dom",
"editor.renderWhitespace": "none",
"files.autoSave": "afterDelay",
"editor.wrappingIndent": "none",
"window.zoomLevel": 0,
"vsicons.dontShowNewVersionMessage": true,
@python012
python012 / settings.json
Created September 18, 2018 06:10
Custom VS code settings
{
"explorer.confirmDelete": false,
"workbench.iconTheme": "vscode-great-icons",
"editor.minimap.enabled": false,
"terminal.integrated.rendererType": "dom",
"editor.renderWhitespace": "none",
"files.autoSave": "afterDelay",
"editor.wrappingIndent": "none",
"window.zoomLevel": 0,
"vsicons.dontShowNewVersionMessage": true,
@python012
python012 / vpn_monitor.py
Last active November 9, 2018 07:55
new version of vpn monitor.py
#coding: utf-8
import smtplib
import config
import urllib.request as urllib2
import time
import base64
last_email_sent_time = None
error_info = None