When executing Python natively:
$ python pystone.py
Pystone(1.1) time for 50000 passes = 0.129016
This machine benchmarks at 387549 pystones/second
This is an attempt to see how small a pure HTML playable TicTacToe game can be. The first script (ttt.py
) generates a 560KB HTML file.
I made it in reaction to this Hacker News post: Implementing Tic Tac Toe with 170MB of HTML – No JavaScript or CSS, because my reaction to "170MB" was "wait, WAT?".
The second script (ttt_smaller.py
) is an attempt to go further, by shortening IDs to maximum 2 chars rather than using 9 characters for full board descriptions as IDs. It does so by using a custom base74, because 74 + 74 × 74 = 5550 which is just above the 5478 game states that have to be represented.
This optimization allows to get down to 412KB, that is a saving of 148Ko, i.e., a 26% size-reduction!
import sys | |
import os | |
import re | |
import json | |
import zipfile | |
from collections import defaultdict, namedtuple | |
from collections.abc import Mapping | |
from email.parser import HeaderParser | |
from email.policy import compat32 | |
from base64 import urlsafe_b64decode |
#!/usr/bin/env bash | |
# journal.sh | |
# ========== | |
# | |
# One daily text file to rule them all. | |
# | |
# Copyright: 2022 Tyler Cipriani <[email protected] | |
# License: GPLv3 | |
set -euo pipefail |
## Example using https://pre-commit.com/ | |
repos: | |
- repo: local | |
hooks: | |
- id: dontship | |
name: DONTSHIP check - Block words | |
entry: '\bdie\b' | |
language: pygrep # https://pre-commit.com/#pygrep | |
types: [php] |
This is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. | |
In jurisdictions that recognize copyright laws, the author or authors | |
of this software dedicate any and all copyright interest in the | |
software to the public domain. We make this dedication for the benefit |
<!-- | |
https://alpinejs.dev/directives/on#prevent | |
https://github.com/alpinejs/alpine/issues/150#issuecomment-580452229 | |
--> | |
<form x-data action="/something" @submit.prevent="if (confirm('Are you sure?')) $el.submit()" method="post"> | |
<button aria-label="Delete this">[some icon]</button> | |
</form> |
"""Point script at Django template name and output DOT text describing the includes. | |
Starting template name must be something relative like | |
'myapp/mysubfolder/template_1.html'. The script will follow the inputs and output a text like: | |
digraph G { | |
node [shape="rectangle"]; | |
"myapp/mysubfolder/template_1.html" -> "myapp/mysubfolder/template_2.html"; | |
"myapp/mysubfolder/template_2.html" -> "myapp/mysubfolder/template_3.html"; | |
... |
// Can be used with https://github.com/xcv58/Custom-JavaScript-for-Websites-2 | |
// This snippet is released under the terms of the CC0 license: https://creativecommons.org/publicdomain/zero/1.0/deed.en | |
const cache_key = 'hn_comments_views' | |
const cache = JSON.parse(localStorage.getItem(cache_key) || '{}') | |
document.querySelectorAll('.athing.comtr').forEach(comm => { | |
if (!cache[comm.id]) { | |
const span = document.createElement('span') | |
span.innerHTML = '🔔' // :bell: emoji |