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
davidbgk /
Last active September 18, 2023 23:07 — forked from magopian/
Auto-reload turtle code on file save (
"""Reloads the `` code on save.
Put simple turtle instructions in the `` file,
and they'll be re-run (on a clean window) on each file save.
1/ put some turtle instructions in a `` file
(eg `turtle.forward(100)`)
2/ run `python` on a commandline
(no dependencies needed)
davidbgk /
Created April 11, 2017 15:39
An attempt to create the simplest HTTP Hello world in Python3
import http.server
import socketserver
from http import HTTPStatus
class Handler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
self.wfile.write(b'Hello world')
davidbgk / index.html
Created May 10, 2016 16:06
Test DOM Content Loaded and promises
View index.html
<!doctype html>
<meta charset=utf-8>
<title>Test DOM Content Loaded and promises</title>
console.log(document.querySelector('main')) // => null
document.ready = new Promise(
(resolve) => document.addEventListener('DOMContentLoaded', resolve))
document.ready.then(() => console.log(document.querySelector('main'))) // => <main>
davidbgk /
Created October 28, 2010 10:30
Easily add an empty choice to a Django ChoiceField
from django import forms
class EmptyChoiceField(forms.ChoiceField):
def __init__(self, choices=(), empty_label=None, required=True, widget=None, label=None,
initial=None, help_text=None, *args, **kwargs):
# prepend an empty label if it exists (and field is not required!)
if not required and empty_label is not None:
choices = tuple([(u'', empty_label)] + list(choices))
davidbgk /
Created February 13, 2023 13:45 — forked from baldurbjarnason/
Book production files for Out of the Software Crisis

Book production files

For Out of the Software Crisis.

These are under the MIT License. Do what you want, essentially. Probably doesn't work out of the box. Uses Pandoc, zx, weasyprint, and Literata.

You'll need to download them for this to work. And you'll need to edit the build script to point at the correct CSS files. And you'l need to edit the CSS to point at the correct font files.

davidbgk /
Created October 20, 2022 02:41 — forked from eyeseast/
How to set up Python in 2022


This is my recommended Python setup, as of Fall 2022. The Python landscape can be a confusing mess of overlapping tools that sometimes don't work well together. This is an effort to standardize our approach and environments.

Tools and helpful links:

davidbgk /
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 / utils.css
Last active August 13, 2022 20:07
Let's start to reference some CSS utils
View utils.css
/* Applying it to the html element will provide smooth scrolling to anchors */
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
davidbgk /
Last active July 4, 2022 01:22 — forked from karlcow/
Using gunicorn
def server_app(environ, start_response):
method = environ.get('REQUEST_METHOD', 'GET')
if method == 'GET':
return get_response(start_response)
elif method == 'POST':
accept_header = environ.get('HTTP_ACCEPT', '*/*')
post_data = environ.get('wsgi.input').read()
return post_response(start_response, accept_header, post_data)
davidbgk /
Created June 9, 2022 22:47 — forked from willurd/
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000