Skip to content

Instantly share code, notes, and snippets.

View bblanchon's full-sized avatar
🌟
No more counting dollars we’ll be counting stars

Benoît Blanchon bblanchon

🌟
No more counting dollars we’ll be counting stars
View GitHub Profile
@bblanchon
bblanchon / slideshow.sh
Created February 16, 2021 21:05
GIF Slideshow with ImageMagick
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 / settings.json
Created March 21, 2021 15:24
VSCode & Cmake: configure out of source build to make hyperlinks work in the output panel
{
"cmake.buildDirectory": "${env:TEMP}/vscode_cmake/${workspaceFolderBasename}"
}
@bblanchon
bblanchon / example.py
Created April 9, 2021 09:03
Django Subquery Aggregate (Count, Sum...)
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 / proxy_response.py
Created April 26, 2021 10:50
Django HTTP proxy response / proxy view
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 / celery_task_failure_email.py
Created April 29, 2021 16:23
Celery/Django: send email when task fails
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 / github-pages.yml
Created June 14, 2021 16:33
Faster Jekyll 4 builds on GitHub Actions
name: Build and deploy Jekyll site to GitHub Pages
on:
push:
branches:
- master
jobs:
github-pages:
runs-on: ubuntu-latest
@bblanchon
bblanchon / DeserializeFromRam.ino
Created June 21, 2021 10:04
ArduinoJson measure deserialization speed
// https://github.com/bblanchon/ArduinoJson/issues/1593
#include <ArduinoJson.h>
void setup() {
// Initialize serial port
Serial.begin(115200);
while (!Serial) continue;
}
@bblanchon
bblanchon / demo.py
Created November 23, 2021 08:23
Nestable Halo spinners
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 / Open with Sublime Merge.reg
Last active August 13, 2024 13:15
Add "Open with Sublime Merge" to Windows Explorer context menu
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 / generate_single_header.bat
Created January 17, 2023 08:32
Generate single header for Catch 1.x
docker run -it --rm -v %CD%:/data python:2 python /data/scripts/generateSingleHeader.py