Skip to content

Instantly share code, notes, and snippets.

View corentinbettiol's full-sized avatar

Corentin Bettiol corentinbettiol

View GitHub Profile
@corentinbettiol
corentinbettiol / README.md
Last active January 27, 2026 13:24
Migrate data from an old instance of aldryn-newsblog to djangocms 4+ djangocms-stories.

Blog Content Migration Scripts

These scripts can export the content of aldryn_newsblog posts in JSON format, then import this content into djangocms-stories posts.

How it works

  1. Serialize plugins content from blog posts placeholder (export).
  2. Write serialized content in a JSON file (export).
  3. Read serialized content, link the old plugins to the new ones, and try to create them (import).
  4. Save those plugins in the placeholder of stories (import).
@corentinbettiol
corentinbettiol / Hacker News – Display user karma next to their usernames.js
Last active December 15, 2025 10:14
Greysemonkey script that displays karma of user next to it's username, using hn firebase api & caching (24h).
// ==UserScript==
// @name Hacker News – Display user karma next to usernames (WCAG-friendly)
// @namespace https://l3m.in
// @version 1.2
// @description Display Hacker News user karma next to usernames using the HN Firebase API, with caching, rate limiting and WCAG-friendly colors.
// @match https://news.ycombinator.com/*
// @grant GM.getValue
// @grant GM.setValue
// @grant GM.xmlHttpRequest
// @connect hacker-news.firebaseio.com
@corentinbettiol
corentinbettiol / djangocms.sh
Created January 17, 2024 16:19
Create a djangocms (v4) website in a few commands.
mkdir mydumbproject
cd mydumbproject
python3 -m venv .venv
. .venv/bin/activate
python3 -m pip install django-cms
djangocms mydumbproject # will ask to type superuser name/email/password
python3 mydumbproject/manage.py runserver 0.0.0.0:8000
@corentinbettiol
corentinbettiol / goaccess.sh
Last active August 24, 2023 12:21
Goaccess script to get a real-time html page with hostnames in requests.
tail -q -n +0 -f \
/var/log/apache2/logs-for-website-1.log \
/var/log/apache2/logs-for-website-2.log \
/var/log/apache2/logs-for-website-3.log \
/var/log/apache2/logs-for-website-4.log \
| awk '$8=$1$8' \
| goaccess \
--log-format='%v %h %l %u [%d:%t +%^] \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"' \
--date-format=%d/%b/%Y \
--time-format=%T \
@corentinbettiol
corentinbettiol / README.md
Last active August 7, 2024 07:13
Run, the command that allows you to execure django commands using poetry.

Install

You should never download a file before checking it, but here you go: just put the function run in your ~/.zshrc.

curl https://gist.githubusercontent.com/corentinbettiol/689d5d9f0989b2f71613b56ab5bc67f6/raw/run.sh >> ~/.zshrc
source ~/.zshrc

Here's how to list all plugins in the post_content placeholder of a djangocms-blog post:

for plugin in post_content.get_plugins():
    print(f"{plugin.plugin_type} - [{plugin.position}][{plugin.depth}][{plugin.path}]")
    try:
        print(plugin.get_plugin_instance()[0].body[:50])
    except:
        pass
 print("\n----\n")
@corentinbettiol
corentinbettiol / fake_plugin.md
Last active August 12, 2022 14:53
Display djangocms cmsplugin instance (and childs) from another page.

Do you ever wanted to display a cms plugin content on any page, without having to copy the plugin? Display multiple plugins too?

Then listenread this

  1. Create a new model:
# my_plugin/models.py
from cms.models.pluginmodel import CMSPlugin

class MyPlugin():
@corentinbettiol
corentinbettiol / get_page.md
Last active August 9, 2022 15:15
Get a djangocms Page object from a slug, without having to launch all the stuff behind djangocms.

Here's a small gist allowing you to find a Page (the DjangoCMS object) from a slug:

def get_page(self, page_url):
    """Try to find a cms page with the same slug, and returns the id of its public page."""
    potential_pages = Page.objects.filter(title_set__slug=page_url.split("/")[-2])  # get "dede" in "https://aa.aa/aa/aa/aa/dede/"
    for page in potential_pages:
        if page.get_absolute_url() == page_url.replace(domain_name, "") and page.publisher_is_draft == False:
            return page
    breakpoint()
@corentinbettiol
corentinbettiol / README.md
Last active April 20, 2023 11:33
Python & Pip invoke commands as a *monkey extension

This extension just replaces python by python3 and pip by python3 -m pip.

Example

image

@corentinbettiol
corentinbettiol / Favicons for HN & Lobsters (updated).md
Last active August 4, 2022 07:14 — forked from frabert/COPYING
Display small, low-opacity favicons of links on HN & Lobsters pages & comments.

Display favicons next to HN & Lobsters posts (and comments)

Fork of this gist.

Main differences:

  • Does not add another favicon when you go back in your history and re-show a hn page,
  • Display favicons on comments links too,
  • Favicons are smaller (12x12px),
  • Favicons are displayed with a opacity = 0.6 (help do not be disturbed by flashy favicons)