This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| """Send email using CC header.""" | |
| import smtplib | |
| from email.mime.text import MIMEText | |
| from email.header import Header | |
| smtp_host = 'smtp.gmail.com' | |
| login, password = ... | |
| to_emails = [...] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """ | |
| - read subprocess output without threads using Tkinter | |
| - show the output in the GUI | |
| - stop subprocess on a button press | |
| """ | |
| import logging | |
| import os | |
| import sys | |
| from subprocess import Popen, PIPE, STDOUT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """Try to cause MemoryError by sending large data via multiprocessing.Pipe. | |
| Context: http://stackoverflow.com/q/22150703 | |
| """ | |
| from multiprocessing import Process, Pipe | |
| def send_big_data(conn): | |
| data = b"a" * (1 << 30) # 1GB | |
| conn.send(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """Print emails from a given date interval. | |
| Usage: | |
| $ %(prog)s <since_date> <before_date> | |
| since_date < before_date | |
| Date format: DD-Mon-YYYY e.g., 3-Mar-2014 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """Translate text_to_translate using microsoft translator service.""" | |
| import json | |
| import xml.etree.ElementTree as etree | |
| try: | |
| from urllib import urlencode | |
| from urllib2 import urlopen, Request | |
| except ImportError: # Python 3 | |
| from urllib.parse import urlencode | |
| from urllib.request import urlopen, Request |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """Show that a daemonic child process may have multiple threads.""" | |
| import multiprocessing | |
| import threading | |
| def child_process(): | |
| # start a thread | |
| threading.Thread(target=child_thread).start() | |
| # show that we can't have grandchildren processes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """Remove consecutive duplicate characters unless inside a known word. | |
| Usage: | |
| $ ./replace-elongated-words input_file | |
| http://stackoverflow.com/questions/22471255/replace-mutiple-occurance-of-characters-as-well-as-punctuation-in-strings-of-fil | |
| """ | |
| import fileinput | |
| import re |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Find maximum memory consumed by a process specified at the command-line. | |
| Usage: | |
| $ python memory-usage-wait3.py cmd arg1 arg2 | |
| """ | |
| import os | |
| import sys | |
| import threading |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """Lookup word definitions on http://www.urbandictionary.com | |
| Print the result as json list. | |
| Example: | |
| $ python -murbandictionary Honorificabilitudinitatibus | |
| Output: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """Make the text green/red if mouse is on the left/right of the window.""" | |
| try: | |
| import tkinter as Tk | |
| import tkinter.ttk as ttk | |
| import tkinter.font as font | |
| except ImportError: # Python 2 | |
| import Tkinter as Tk | |
| import ttk | |
| import tkFont as font |