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
| /** Print the _known_ (2013) perfect numbers less than *limit* given on stdin to stdout. | |
| It uses gmplib (-lgmp) to support arbitrary precision integer arithmetic. | |
| To compile and print all perfect numbers that are less than 100000000: | |
| $ gcc print-perfect-numbers.c -lgmp && echo 100000000 | ./a.out | |
| */ | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <gmp.h> |
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
| # Answer for http://stackoverflow.com/questions/26528007/parse-date-based-on-locale-php-python | |
| from datetime import date | |
| import parsedatetime as pdt # $ pip install parsedatetime | |
| def unix(utc_date, epoch_ord=date(1970, 1, 1).toordinal()): | |
| return (utc_date.toordinal() - epoch_ord) * 86400 | |
| for date_string, locale in [("30 juin 2009", "fr_FR"), | |
| ("30.06.2009", "de_DE"), |
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 | |
| """Generate data at constant rate (float interval). | |
| To try, run: | |
| $ python3 constant-bit-rate-modulo.py | pv >/dev/null | |
| """ | |
| from time import sleep, monotonic as timer |
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
| /** Enumerate integer partitions using Algorithm P from Knuth's TOACP V4 7.2.1.4 | |
| $ cc -std=c99 *.c && echo 4 | ./a.out | |
| # Output: | |
| 4 | |
| 3 + 1 | |
| 2 + 2 | |
| 2 + 1 + 1 | |
| 1 + 1 + 1 + 1 | |
| */ |
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 | |
| """Print info in json format about OS process specified by its pid. | |
| Usage: procinfo PID | |
| To install: | |
| $ sudo apt-get install python-psutil # install dependencies | |
| # https://pypi.python.org/pypi?:action=display&name=psutil#downloads |
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 -*- | |
| import os | |
| import posixpath | |
| try: | |
| from urlparse import urlsplit | |
| from urllib import unquote | |
| except ImportError: # Python 3 | |
| from urllib.parse import urlsplit, unquote |
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 | |
| """Play a media (audio/video) file using GStreamer. | |
| To install Gstreamer and its Python bindings on Ubuntu, run: | |
| $ sudo apt-get install python-gi python3-gi \ | |
| gstreamer1.0-tools \ | |
| gir1.2-gstreamer-1.0 \ | |
| gir1.2-gst-plugins-base-1.0 \ | |
| gstreamer1.0-plugins-good \ |
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 | |
| """Save all Unicode characters as individual images. | |
| Based on @JackNova's answer http://stackoverflow.com/a/22612295 | |
| To save as jpeg, install libjpeg before installing Pillow e.g.: | |
| $ sudo apt-get install libjpeg-dev -y | |
| $ pip install -U pillow # assuming a virtualenv is active |
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
| import os | |
| import asyncio | |
| import sys | |
| from asyncio.streams import StreamWriter, FlowControlMixin | |
| reader, writer = None, None | |
| @asyncio.coroutine | |
| def stdio(loop=None): |
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 | |
| """Test functions from | |
| http://stackoverflow.com/questions/28680896/how-can-i-get-the-3rd-friday-of-a-month-in-python | |
| """ | |
| import calendar | |
| from datetime import date, datetime, time, timedelta | |
| from itertools import islice | |
| DAY = timedelta(1) |