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 | |
| """Shuffle sentences in a StackOverflow question. | |
| http://stackoverflow.com/q/19471967 | |
| """ | |
| import random | |
| import sys | |
| import urllib | |
| import requests # $ pip install requests |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 | |
| """`cat` for Python 3. | |
| - if a file has no newline at the end then the last line is merged | |
| with the first line of the next file like `cat` does | |
| - os.fsencode() is not used to encode error message therefore there | |
| could be surrogates in the output (encoded using the default for | |
| errors 'backslashreplace' error handler): it is always possible to | |
| restore the original filename whatever (ascii-based) locale |
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
| """Demonstrate why tz.normalize() may be useful after dt.replace().""" | |
| from datetime import datetime | |
| import pytz | |
| # see Localized times and date arithmetic section in pytz docs | |
| # http://pytz.sourceforge.net/#localized-times-and-date-arithmetic | |
| eastern = pytz.timezone('US/Eastern') | |
| dt = eastern.localize(datetime(2002, 10, 27, 7, 0, 0), is_dst=None) | |
| unnormalized_dt = dt.replace(hour=0, minute=0, second=0) | |
| print(unnormalized_dt.utcoffset()) |
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
| NAME := sum1Gints | |
| CC := gcc -std=c89 | |
| INPUTFILE := /tmp/1G-int-per-line | |
| .PHONY: clean run | |
| run: $(NAME) | |
| /usr/bin/time ./$< $(INPUTFILE) | |
| # Recommended gcc warning options for C, from: |
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
| /** To make shared library, run: | |
| $ gcc -shared -O3 -o libcsum_block.so -fPIC csum_block.c | |
| Algorithm from: | |
| http://stackoverflow.com/questions/25606833/fastest-way-to-sum-integers-in-text-file/25607155#comment40046670_25607155 | |
| */ | |
| #include <stdint.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
| #!/usr/bin/python3 | |
| """Demonstrate that PySide can display Unicode characters. | |
| To install on Ubuntu: | |
| $ sudo apt-get install python3-pyside | |
| """ | |
| import PySide | |
| print(PySide.__version__) # 1.2.1 | |
| import PySide.QtCore |
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
| // show that c99 isspace returns the same result for char and unsigned char | |
| #include <algorithm> | |
| #include <cctype> | |
| #include <climits> | |
| #include <iostream> | |
| int main() { | |
| for (char c = CHAR_MIN; ; ++c) { // iterate over all char values | |
| unsigned char u = c; | |
| if (::isspace(c) != ::isspace(u)) { // error |
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
| /1/ | |
| /2/ |