Skip to content

Instantly share code, notes, and snippets.

View loicteixeira's full-sized avatar

Loic Teixeira loicteixeira

View GitHub Profile
@loicteixeira
loicteixeira / README.md
Last active November 26, 2022 12:06
[Wagtail] Conversion scripts for wagtail/wagtail#9377

Steps taken to merge this (for posterity, and also because I'll have to do it all over again for wagtail-localize which is in the same Transifex project).

BRANCH_NAME="7111-enforce-translation-string-formatting"

# Merge
git switch main
git pull --ff-only upstream main
git switch "${BRANCH_NAME}"
git reset $(git merge-base main "${BRANCH_NAME}")
@loicteixeira
loicteixeira / sort.py
Created April 19, 2022 15:30
Python alphanumeric/natural sort
import re
import unicodedata
# Case insensitivity
sorted(["Hola", "hello"])
# => ['Hola', 'hello']
sorted(
["Hola", "hello"],
@loicteixeira
loicteixeira / console.js
Created November 27, 2021 17:14
Formula1.com cookies consent toggles count
// For https://www.reddit.com/r/formula1/comments/r39q00/formula1com_cookies_are_out_of_control/hm9hqma/?context=8&depth=9
// 1. Navigate to https://www.formula1.com/
// 2. Select "No, Manage Settings"
// 3. Run the following in the developer console
document.querySelectorAll("[class^='categories_']").forEach((el) => {
const sectionTitle = el.querySelector(".categoryTitle").textContent
const companiesCount = el.querySelectorAll("tbody > tr").length / 2 // 2 lines per company
console.log(`${sectionTitle}: ${companiesCount} companies`)
})
Verifying my Blockstack ID is secured with the address 1Be7X31o6UPoKExkwfavisnbUqrycAtQPM https://explorer.blockstack.org/address/1Be7X31o6UPoKExkwfavisnbUqrycAtQPM
@loicteixeira
loicteixeira / README.md
Last active August 23, 2019 14:50
[Wagtail] Create pages in migrations

Unfortunately because models returned by apps.get_model in migrations aren't the actual class, methods like Page.add aren't available and we have to do it manually. The most sensitive part being the handling of the path.

As an aside, deleting pages in migration will not update the numchild of the parent page. Unfortunately, the fixtree command doesn't play nice within a migration so it will need to be ran separately (or the parent page should manually be updated).

Notes: When not within a migration, a page path could be created with parent_page.get_last_child()._inc_path() or Page._get_children_path_interval(parent_page.path)[1].

@loicteixeira
loicteixeira / form.py
Created April 17, 2017 06:50
[Django] Dynamically require a field
from django import forms
class MyForm(forms.Form):
def clean(self):
is_something = cleaned_data.get('is_something')
if is_something:
validate_required_field(self, cleaned_data, 'name_of_dynamically_required_field')
@loicteixeira
loicteixeira / README.md
Last active August 17, 2017 23:01
[Wagtail 1.6.x] Rich editor configuration per field
@loicteixeira
loicteixeira / README.md
Last active September 15, 2016 20:26
[Django] Options block in Template

Add the possibility to save options to the current context.

Save the different files in the proper folders:

DJANGO_PROJECT
  APP_NAME
    templates
      APP_NAME
        index.html
 templatetags
# From https://github.com/ngerakines/commitment/issues/69#issuecomment-91053061
git config --global alias.yolo '!git add -A && git commit -m "$(curl -s whatthecommit.com/index.txt)"'
@loicteixeira
loicteixeira / GetUserFromWeb.cs
Last active August 29, 2015 14:19
Retrieve GameJolt user credentials from Unity for WebPlayer and WebGL builds (and simulate in the Editor)
using UnityEngine;
using System.Collections;
public class GetUserFromWeb : MonoBehaviour
{
// Set those up in the inspector if you want to simulate the GetFromWeb behaviour in within the Editor.
public string debugUser;
public string debugToken;