Skip to content

Instantly share code, notes, and snippets.

Avatar
☮️

Benoît Blanchon bblanchon

☮️
View GitHub Profile
@bblanchon
bblanchon / Open with Sublime Merge.reg
Last active Jan 6, 2022
Add "Open with Sublime Merge" to Windows Explorer context menu
View Open with Sublime Merge.reg
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\smerge]
; %PROGRAMFILES%\Sublime Merge\sublime_merge.exe
"Icon"=hex(2):25,00,50,00,52,00,4f,00,47,00,52,00,41,00,4d,00,46,00,49,00,4c,\
00,45,00,53,00,25,00,5c,00,53,00,75,00,62,00,6c,00,69,00,6d,00,65,00,20,00,\
4d,00,65,00,72,00,67,00,65,00,5c,00,73,00,75,00,62,00,6c,00,69,00,6d,00,65,\
00,5f,00,6d,00,65,00,72,00,67,00,65,00,2e,00,65,00,78,00,65,00,00,00
@="Open with Sublime Merge"
@bblanchon
bblanchon / demo.py
Created Nov 23, 2021
Nestable Halo spinners
View demo.py
from halo_nestable import HaloNestable
import time
with HaloNestable("Top level") as spinner:
time.sleep(2)
with HaloNestable("Nested"):
time.sleep(2)
time.sleep(2)
spinner.succeed("Great success!")
@bblanchon
bblanchon / DeserializeFromRam.ino
Created Jun 21, 2021
ArduinoJson measure deserialization speed
View DeserializeFromRam.ino
// https://github.com/bblanchon/ArduinoJson/issues/1593
#include <ArduinoJson.h>
void setup() {
// Initialize serial port
Serial.begin(115200);
while (!Serial) continue;
}
@bblanchon
bblanchon / github-pages.yml
Created Jun 14, 2021
Faster Jekyll 4 builds on GitHub Actions
View github-pages.yml
name: Build and deploy Jekyll site to GitHub Pages
on:
push:
branches:
- master
jobs:
github-pages:
runs-on: ubuntu-latest
@bblanchon
bblanchon / celery_task_failure_email.py
Created Apr 29, 2021
Celery/Django: send email when task fails
View celery_task_failure_email.py
from celery.signals import task_failure
from django.core.mail import mail_admins
from pprint import pformat
@task_failure.connect
def celery_task_failure_email(task_id, sender, exception, einfo, *args, **kwargs):
mail_admins(
f"ERROR: Task {sender.name} raised {exception.__class__.__name__}",
f"""Task {sender.name} with id {task_id} raised exception:
{exception!r}
@bblanchon
bblanchon / proxy_response.py
Created Apr 26, 2021
Django HTTP proxy response / proxy view
View proxy_response.py
import requests
from django.http import StreamingHttpResponse
class ProxyHttpResponse(StreamingHttpResponse):
def __init__(self, url, headers=None, **kwargs):
upstream = requests.get(url, stream=True, headers=headers)
kwargs.setdefault('content_type', upstream.headers.get('content-type'))
kwargs.setdefault('status', upstream.status_code)
@bblanchon
bblanchon / example.py
Created Apr 9, 2021
Django Subquery Aggregate (Count, Sum...)
View example.py
from django.db.models import OuterRef
weapons = Weapon.objects.filter(unit__player_id=OuterRef('id'))
units = Unit.objects.filter(player_id=OuterRef('id'))
qs = Player.objects.annotate(weapon_count=SubqueryCount(weapons),
rarity_sum=SubquerySum(units, 'rarity'))
@bblanchon
bblanchon / settings.json
Created Mar 21, 2021
VSCode & Cmake: configure out of source build to make hyperlinks work in the output panel
View settings.json
{
"cmake.buildDirectory": "${env:TEMP}/vscode_cmake/${workspaceFolderBasename}"
}
@bblanchon
bblanchon / slideshow.sh
Created Feb 16, 2021
GIF Slideshow with ImageMagick
View slideshow.sh
magick \
\( -delay 100 image-00.png \) \
\( -delay 10 image-00.png image-01.png -morph 3 -delete 0 \) \
\( -delay 100 image-01.png \) \
\( -delay 10 image-01.png image-02.png -morph 3 -delete 0 \) \
\( -delay 100 image-02.png \) \
\( -delay 10 image-02.png image-03.png -morph 3 -delete 0 \) \
\( -delay 100 image-03.png \) \
\( -delay 10 image-03.png image-04.png -morph 3 -delete 0 \) \
\( -delay 200 image-04.png \) \
@bblanchon
bblanchon / StringDeduplicationDemo.ino
Created Aug 1, 2020
See ArduinoJson memory usage and speed with string deduplication
View StringDeduplicationDemo.ino
#include <ArduinoJson.h>
void setup() {
Serial.begin(9600);
while (!Serial) continue;
StaticJsonDocument<516> doc;
const char* json = R"({"list":[{"temperature":21.2,"humidity":68.9,"weather":"overcast clouds"},{"temperature":19.7,"humidity":62.1,"weather":"clear sky"},{"temperature":18.6,"humidity":59.8,"weather":"clear sky"}]})";