Skip to content

Instantly share code, notes, and snippets.

View zerolab's full-sized avatar
🖖
Live long and prosper

Dan Braghiș zerolab

🖖
Live long and prosper
View GitHub Profile
@zerolab
zerolab / git-delete-history.sh
Last active November 9, 2023 16:29
Script to permanently delete files/folders form your git repository
#!/bin/bash
set -o errexit
# Author: David Underhill
# Script to permanently delete files/folders from your git repository. To use
# it, cd to your repository's root and then run the script with a list of paths
# you want to delete, e.g., git-delete-history path1 path2
if [ $# -eq 0 ]; then
exit 0
@zerolab
zerolab / mkdocs-to-netlify-action.yml
Last active October 28, 2023 15:06
Deploy your mkdocs to NETLIFY
name: Publish docs to Netlify
on:
push:
branches:
- master
jobs:
build:
name: Deploy docs
runs-on: ubuntu-latest
@zerolab
zerolab / gist:1633661
Created January 18, 2012 15:52
Convert smart quotes with regular ones (and vice-versa)
<?php
//Quotes: Replace smart double quotes with straight double quotes.
//ANSI version for use with 8-bit regex engines and the Windows code page 1252.
preg_replace('[\x84\x93\x94]', '"', $text);
//Quotes: Replace smart double quotes with straight double quotes.
//Unicode version for use with Unicode regex engines.
preg_replace('[\u201C\u201D\u201E\u201F\u2033\u2036]', '"', $text);
# myapp/management/commands/fix_alias_page_first_last_published.py
from django.core.management.base import BaseCommand
from django.db.models import Q
from wagtail.core.models import Page
class Command(BaseCommand):
def handle(self, **options):
@zerolab
zerolab / d8_my_advanced_tab.php
Created November 3, 2016 17:18
Drupal 8 move something to the advanced tabs on node forms
<?php
/**
* Implements hook_form_FORM_ID_alter().
*
* Move your field or group of fields to the node form options vertical tabs.
*/
function mymodule_form_node_form_alter(&$form, FormState $form_state, $form_id) {
$form['mygroup'] = [
@zerolab
zerolab / elasticsearch7.py
Created June 18, 2021 09:28
RootFilterField in Wagtail -- enables you to index the field without the specific page model string prefix
from wagtail.search.backends.elasticsearch7 import (
Elasticsearch7Mapping,
Elasticsearch7SearchBackend,
Elasticsearch7SearchQueryCompiler,
Elasticsearch7SearchResults,
)
from .index import RootFilterField
@zerolab
zerolab / responsiveimage_tags.py
Created June 20, 2019 09:55
Wagtail responsive image tag
from django import template
from wagtail.images.models import SourceImageIOError
from wagtail.images.shortcuts import get_rendition_or_not_found
from wagtail.images.templatetags.wagtailimages_tags import ImageNode
register = template.Library()
@register.tag(name="responsiveimage")
@zerolab
zerolab / black-pyproject.toml
Created August 7, 2020 15:28
Example black config with excludes for the migrations directory
[tool.black]
line-length = 120
target-version = ['py38']
exclude = '''
(
/(
\.eggs # exclude a few common directories in the
| \.git # root of the project
| \.mypy_cache
| \.tox
@zerolab
zerolab / cloudflare-bulk-404s.js
Last active April 2, 2020 08:45
Cloudflare Worker - bulk regex 404s
/**
* Sets up routes and 404 any that match the 404 map
* @param {Request} request
*/
async function handleRequest(request) {
let requestURL = new URL(request.url)
let path = requestURL.pathname
if (should404(path)) {
return new Response('Sorry, not found', {
status: 404
@zerolab
zerolab / cf-holding-page.js
Created March 30, 2020 08:09
Cloudflare Worker holding page
addEventListener("fetch", event => {
event.respondWith(fetchAndReplace(event.request))
})
async function fetchAndReplace(request) {
let modifiedHeaders = new Headers()
modifiedHeaders.set('Content-Type', 'text/html')
modifiedHeaders.append('Pragma', 'no-cache')