Author Archives: Shang Erxin

About Shang Erxin

My undergraduate degree is Electrical Engineering and Automation. Graduate degree is Power Electronics and Power Drives. Personal favorite programming languages are C, C++, C# and Python. Currently I works as an architect/ software engineer/ programmer in Micron. During the free time, I also work as a free-lance programmer. Have good knowledge of, WCF, WPF, WF, Silverlight, Django, wxPython, jquery, SQL Server, SQLite, Mongo DB, Mobile development with Mono and Unity. If you want to find a free-lance programmer to solve problems with these techniques feel free to contact me.

Python基础教程,第一章 简介(Python Fundamental, Charpter 01 Introduction)

Make a basic introduction about python programming language.


  • Python的简介, introduction
  • Python的哲学, philosophy
  • Python的排名, current state
  • Python开发的项目, projects
  • Python的编程风格, programming style
  • Python的协议, license
  • Python的开发工具, development environment
  • Get required lasts lines from a huge text file in python

    During my work, I need to parse the result from some huge log files. The result is always save at the end of the file. So I need find a way to get the required last lines to accelerate the parse speed. Here is the function I have written to achieve this requirement in python.

    1. def last_lines(filename, lines=1):
    2. '''
    3. return the last lines from the specify files
    4. '''
    5. with open(filename, 'rb') as fh:
    6., os.SEEK_END)
    7. if fh.tell() == 0:
    8. return []
    9., os.SEEK_END)
    10. #while not BOF
    11. while fh.tell() > 0:
    12. cur_char =
    13. if cur_char == '\n':
    14. lines -= 1
    15. if lines > 0:
    16., os.SEEK_CUR)
    17. else:
    18. break
    19. return [line.decode() for line in fh.readlines()]


    Use oscilloscope Check the AC noise of a Power Source

    How to use a oscilloscope display the wave shape of AC power source?
    1. Check the oscilloscope is connected with attenuator probes, and adjust to the right attenuation factor. 1x, 10x 100x, … the more big the number the more attenuator value

    2. Adjust the oscilloscope to the relative measure scope and set to the right channel

    3. Connect the ground with the clamp to the ground of the source

    4. Use one probe connecting with zero line, the other connected with the supply line

    5. Adjust the sample time to make the wave shape looks better

    6. The noise pulses are displayed during my measurement result



    Use Python puka client with RabbitMQ

    Send a message to RabbitMQ

    1. #!/usr/bin/env python
    3. import sys
    4. sys.path.append("..")
    7. import puka
    9. client = puka.Client("amqp://localhost/")
    11. promise = client.connect()
    12. client.wait(promise)
    14. promise = client.queue_declare(queue='test')
    15. client.wait(promise)
    17. promise = client.basic_publish(exchange='', routing_key='test',
    18. body="Hello world!")
    19. client.wait(promise)
    21. print " [*] Message sent"
    23. promise = client.queue_declare(queue='test', passive=True)
    24. print " [*] Queue size:", client.wait(promise)['message_count']
    26. promise = client.close()
    27. client.wait(promise)