Skip to content

Instantly share code, notes, and snippets.

View corentinbettiol's full-sized avatar

Corentin Bettiol corentinbettiol

View GitHub Profile
@syrusakbary
syrusakbary / benchmark.md
Created March 16, 2024 20:16
Pystone benchmark comparison (Native vs CPython interpreter vs Nuitka)

Native

When executing Python natively:

$ python pystone.py
Pystone(1.1) time for 50000 passes = 0.129016
This machine benchmarks at 387549 pystones/second
@p4bl0-
p4bl0- / Pure HTML TicTacToe.md
Last active November 15, 2023 15:31
Pure HTML playable TicTacToe game (no CSS nor JavaScript) in 367KB

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
@pmoranga
pmoranga / .pre-commit-config.yaml
Last active February 28, 2024 11:14 — forked from skwashd/pre-commit
Git pre-commit hook that blocks commits for files that contain swear words.
## 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]
@frabert
frabert / COPYING
Last active December 21, 2023 13:35
Favicons for HN
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
@huytd
huytd / wordle.md
Last active December 17, 2024 13:06
Wordle in less than 50 lines of Bash

image

How to use:

./wordle.sh

Or try the unlimit mode:

@trey
trey / alpine.html
Last active August 27, 2024 09:33
JavaScript confirmation message with Alpine.js and htmx
<!--
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>
@cb109
cb109 / visualize_django_template_include_hierarchy_with_graphviz.py
Last active December 21, 2021 17:06
Visualize Django Template Include Hierarchy with Graphviz
"""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";
...
@linkdd
linkdd / hackernews-new-comms.js
Last active August 25, 2024 11:15
Add a bell emoji to unread comments on HackerNews
// 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 = '&#x1f514;' // :bell: emoji