Skip to content

Instantly share code, notes, and snippets.

View davidbgk's full-sized avatar
🚪
Let’s escape GAFAM+ when/while we can!

David Larlet davidbgk

🚪
Let’s escape GAFAM+ when/while we can!
View GitHub Profile
"""
Implements a simple HTTP/1.0 Server
"""
import socket
def handle_request(request):
"""Handles the HTTP request."""
@davidbgk
davidbgk / utils.css
Last active August 13, 2022 20:07
Let's start to reference some CSS utils
/* Applying it to the html element will provide smooth scrolling to anchors
https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-behavior */
html {
scroll-behavior: smooth;
}
/* Remove animations for folks who set their OS to reduce motion.
1. Immediately jump any animation to the end point
2. Remove transitions & fixed background attachment
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
@davidbgk
davidbgk / saveTextarea.js
Created October 14, 2020 13:23 — forked from adactio/saveTextarea.js
Put the contents of a textarea into localStorage if the user leaves the page before submitting the form.
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function (win, doc) {
// Cut the mustard.
if (!win.localStorage) return;
// You should probably use a more specific selector than this.
var textarea = doc.querySelector('textarea');
// The key for the key/value pair in localStorage is the current URL.
var key = win.location.href;
@davidbgk
davidbgk / utils.py
Last active August 13, 2022 20:08
Let's start to reference some Python utils
def neighborhood(iterable, first=None, last=None):
"""
Yield the (previous, current, next) items given an iterable.
You can specify a `first` and/or `last` item for bounds.
"""
iterator = iter(iterable)
previous = first
current = next(iterator) # Throws StopIteration if empty.
for next_ in iterator:
@davidbgk
davidbgk / utils.js
Last active March 25, 2022 16:23
Let's start to reference some JS utils
// More resources: https://1loc.dev/ + https://htmldom.dev/ + https://thisthat.dev/ + https://vanillajstoolkit.com/
const qsa = (selector) => Array.from(document.querySelectorAll(selector))
// Another way inspired by fluorjs https://fluorjs.github.io/
function $(selector, root = document) {
if (selector instanceof Node) {
return [selector]
}
return root.querySelectorAll(selector)
@davidbgk
davidbgk / markup.py
Created June 13, 2020 14:38 — forked from miraculixx/markup.py
an extensible multi-markup reader in less than 100 lines of python code
# (c) miraculixx, licensed as by the terms of WTFPL, http://www.wtfpl.net/txt/copying/
# License: DO WHATEVER YOU WANT TO with this code.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
from io import StringIO
from contextlib import contextmanager

To install this:

$ pip install getgist pyyaml && getgist miraculixx markup.py && alias markup="python markup.py"

Then use it from your Python code

from markup import markup

data = markup(file_or_str)
@davidbgk
davidbgk / .zshrc
Last active March 15, 2021 23:21
Configuration file for ZSH (macOS), current status
# to avoid Last login blah
# touch .hushlogin
# https://scriptingosx.com/2019/07/moving-to-zsh-06-customizing-the-zsh-prompt/
PROMPT='%(?.%F{green}√.%F{red}?%?)%f %B%F{235}%2~%f%b %# '
# case insensitive path-completion
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
# partial completion suggestions
@davidbgk
davidbgk / index.html
Created February 18, 2020 18:31
An attempt to implement a smoothscrolling while keeping :target selector in CSS
<!doctype html><!-- This is a valid HTML5 document. -->
<!-- Screen readers, SEO, extensions and so on. -->
<html lang="fr">
<!-- Has to be within the first 1024 bytes, hence before the <title>
See: https://www.w3.org/TR/2012/CR-html5-20121217/document-metadata.html#charset -->
<meta charset="utf-8">
<!-- Why no `X-UA-Compatible` meta: https://stackoverflow.com/a/6771584 -->
<!-- The viewport meta is quite crowded and we are responsible for that.
See: https://codepen.io/tigt/post/meta-viewport-for-2015 -->
<meta name="viewport" content="width=device-width,initial-scale=1">