Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
(╯°□°)╯︵ ┻━┻

David Larlet davidbgk

💭
(╯°□°)╯︵ ┻━┻
View GitHub Profile
@davidbgk
davidbgk / mr-robot-religion.txt
Created Jul 23, 2016
Transcript of Mr Robot S02E03 about religion
View mr-robot-religion.txt
Is that what God does?
He helps?
Tell me,
why didn't God help
my innocent friend
who died for no reason
while the guilty roam free?
Okay, fine.
Forget the one-offs.
How about the countless wars
@davidbgk
davidbgk / utils.css
Last active Mar 24, 2021
Let's start to reference some CSS utils
View utils.css
/* 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
@davidbgk
davidbgk / .zshrc
Last active Mar 15, 2021
Configuration file for ZSH (macOS), current status
View .zshrc
# 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 / server.py
Created Apr 11, 2017
An attempt to create the simplest HTTP Hello world in Python3
View server.py
import http.server
import socketserver
from http import HTTPStatus
class Handler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(HTTPStatus.OK)
self.end_headers()
self.wfile.write(b'Hello world')
@davidbgk
davidbgk / index.html
Created May 10, 2016
Test DOM Content Loaded and promises
View index.html
<!doctype html>
<meta charset=utf-8>
<title>Test DOM Content Loaded and promises</title>
<script>
console.log(document.querySelector('main')) // => null
document.ready = new Promise(
(resolve) => document.addEventListener('DOMContentLoaded', resolve))
document.ready.then(() => console.log(document.querySelector('main'))) // => <main>
</script>
<main></main>
@davidbgk
davidbgk / utils.js
Last active Feb 1, 2021
Let's start to reference some JS utils
View utils.js
// 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 / utils.py
Last active Feb 1, 2021
Let's start to reference some Python utils
View utils.py
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 / fields.py
Created Oct 28, 2010
Easily add an empty choice to a Django ChoiceField
View fields.py
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
davidbgk / index.html
Created Dec 7, 2015
Fake favicon, to avoid extra request to server
View index.html
<!-- Fake favicon, to avoid extra request to server -->
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
View hooks-in-a-nutshell.js
// WARNING: There's much more to know/do around hooks, and
// this is just a simplification of how these work.
// shared references, updated
// per each hook invoke
let execution = null;
let current = null;
let context = null;
let args = null;