This file contains 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
/*** Native messaging "ping_pong" example in C. | |
* | |
* It is reimplementation of the corresponding Python example from | |
* https://github.com/mdn/webextensions-examples/tree/master/native-messaging | |
* | |
* # Python 3.x version | |
* # Read a message from stdin and decode it. | |
* def getMessage(): | |
* rawLength = sys.stdin.buffer.read(4) | |
* if len(rawLength) == 0: |
This file contains 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
/*.json | |
/*.xml |
This file contains 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 | |
""" | |
- read subprocess output without threads using a socket pair | |
- show the output in a tkinter GUI (while the process is still running) | |
- stop subprocess on a button press | |
""" | |
import logging | |
import os | |
import socket | |
import sys |
This file contains 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 | |
"""Send telegrams about new videos on subscribed YouTube channels. | |
To try it, install dependencies: | |
$ python3 -mpip install aiohttp feedparser werkzeug | |
run the callback server: | |
$ env TELEBOT_TOKEN=<token> TELEBOT_CHAT_ID=<chat_id> python3 ytcallback-server.py |
This file contains 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 | |
"""Closed formula (safe_position3(n)) for Josephus3 problem for 1<=n<2**31""" | |
from decimal import Decimal, getcontext, localcontext | |
def safe_position3(n, *, precision=getcontext().prec): | |
# [jos]: http://user.math.uzh.ch/halbeisen/publications/pdf/jos.pdf | |
# j(n, k, n - l) = (n - c_m) * k + d_m; | |
# c_m <= n < c_m_plus_1 | |
# return j(n, 3, n) + 1; |
This file contains 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 | |
"""Draw text in the center of the screen.""" | |
import sys | |
from PyQt5.QtCore import Qt | |
from PyQt5.QtGui import QFont | |
from PyQt5.QtWidgets import QApplication, QLabel | |
app = QApplication(sys.argv) | |
w = QLabel() |
This file contains 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 Youtube video on remote VLC. | |
Usage: play-youtube-video-on-remote-vlc <webpage-url> | |
Send media url to remote (desktop) VLC using (Lua) http interface | |
https://wiki.videolan.org/VLC_HTTP_requests/ | |
""" | |
import base64 | |
import os |
This file contains 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
/** Convert Roman numerals given on the command line to decimals. | |
$ ragel -F0 -o roman_numerals.c roman_numerals.rl | |
$ gcc -finput-charset=utf-8 -fexec-charset=utf-8 -o roman_numerals roman_numerals.c | |
$ ./roman_numerals IX Ⅻ CCCC | |
9 | |
12 | |
400 | |
$ ./roman_numerals IIX && exit 1 || echo invalid | |
invalid |
This file contains 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
/scheme.png |
This file contains 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
# $ grako -o kv_parser.py KV.ebnf | |
@@grammar :: KV | |
# whitespace inside a string excluding the start/end of the line | |
@@whitespace :: /((?!^)(?![\r\n])\s)+/ | |
@@eol_comments :: /#[^\r\n]*/ | |
@@left_recursion :: False | |
# input is zero or more assignments |
NewerOlder