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 / qpdf-context-menu.reg
Created January 15, 2024 12:49
Add PDF rotation to Windows Explorer's context menu
Windows Registry Editor Version 5.00
; Adds Rotate +90 and Rotate -90 to the context menu for PDF files
; Assumes qpdf is installed in C:\Program Files\qpdf
[HKEY_CLASSES_ROOT\SystemFileAssociations\.pdf\shell\Rotate +90]
"icon"="%SystemRoot%\\system32\\imageres.dll,-5345"
[HKEY_CLASSES_ROOT\SystemFileAssociations\.pdf\shell\Rotate +90\command]
@="\"C:\\Program Files\\qpdf\\bin\\qpdf.exe\" --replace-input --rotate=+90 \"%1\""
@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
@bblanchon
bblanchon / Open with Sublime Merge.reg
Last active September 1, 2023 13:53
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 / 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 / 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 / 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 / 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 / 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 / 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 / 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}"
}