Skip to content

Instantly share code, notes, and snippets.

Avatar

Alessandro Pisa ale-rt

View GitHub Profile
View check_distrowatch_py_support.py
from lxml import html
import requests
template = "https://distrowatch.com/search.php?pkg=Python&relation=greaterequal&pkgver={}&distrorange=InLatest#pkgsearch"
def get_distros(min_python_version):
response = requests.get(template.format(min_python_version))
distros = set()
@ale-rt
ale-rt / update_membrane_users.md
Created Aug 18, 2020
How to update membrane users
View update_membrane_users.md

Change some properties

>>> profiles = app.quaive.profiles
>>> profiles["foo"].email = "foo.bar@example.com"
>>> from transaction import commit
>>> commit()

Set an encrypted password

@ale-rt
ale-rt / vm-backup.sh
Created Aug 7, 2018 — forked from cabal95/vm-backup.sh
I use this script to backup my QEMU/KVM/libVirt virtual machines. The script requires KVM 2.1+ since it uses the live blockcommit mode. This means the data in the snapshot disk is rolled back into the original instead of the other way around. Script does NOT handle spaces in paths.
View vm-backup.sh
#!/bin/bash
#
BACKUPDEST="$1"
DOMAIN="$2"
MAXBACKUPS="$3"
if [ -z "$BACKUPDEST" -o -z "$DOMAIN" ]; then
echo "Usage: ./vm-backup <backup-folder> <domain> [max-backups]"
exit 1
View patch_resolveResource.py
# coding=utf-8
from plone.app.blocks import utils
from plone.subrequest import subrequest
from zExceptions import NotFound
from zope.site.hooks import getSite
def resolveResource(url):
"""Resolve the given URL to a unicode string. If the URL is an absolute
path, it will be made relative to the Plone site root.
View YAPF configuration (.style.yapf)
[style]
# Align closing bracket with visual indentation.
align_closing_bracket_with_visual_indent=True
# Allow dictionary keys to exist on multiple lines. For example:
#
# x = {
# ('this is the first element of a tuple',
# 'this is the second element of a tuple'):
# value,
View Example of a recipe that auto applies the hotfixes
[instance]
eggs+=
${hotfix:eggs}
[hotfix]
recipe = mr.scripty
eggs=
from urllib import urlopen
version = self.buildout['versions']['Plone']
base_url = 'https://raw.githubusercontent.com/starzel/buildout/master/linkto/hotfixes/%s.cfg'
@ale-rt
ale-rt / gist:3c7741dd2013f364ac8370bc07273727
Created Apr 27, 2016
bin/instance run this script to dump your Plone site into an a folder
View gist:3c7741dd2013f364ac8370bc07273727
# coding=utf-8
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManager import setSecurityPolicy
from collective.jsonify.export import export_content
from logging import DEBUG
from logging import getLogger
from Products.CMFCore.tests.base.security import OmnipotentUser
from Products.CMFCore.tests.base.security import PermissiveSecurityPolicy
from Testing.makerequest import makerequest
View gist:ffdf2ad7ec7a6c6eee614cb3d984498c
# coding=utf-8
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManager import setSecurityPolicy
from collective.jsonify.export import export_content
from logging import DEBUG
from logging import getLogger
from Products.CMFCore.tests.base.security import OmnipotentUser
from Products.CMFCore.tests.base.security import PermissiveSecurityPolicy
from Testing.makerequest import makerequest
@ale-rt
ale-rt / dx-overrire-nexturl.py
Created Nov 19, 2015
Dexterity example: override nextURL
View dx-overrire-nexturl.py
class BaseEditForm(DefaultEditForm):
def nextURL(self):
''' Try to guess in a smart way what will bethe next url
'''
next_url = super(BaseEditForm, self).nextURL()
current_tab = getattr(self, 'tab_id', '')
if not current_tab:
return next_url
if not current_tab in self.wizard_tabs:
@ale-rt
ale-rt / cssfrompngs
Created May 14, 2015
Script that creates css rules to add background png images with data-uris
View cssfrompngs
#!/usr/bin/env python
from PIL import Image
from base64 import encodestring
import sys
template = '''.%(classname)s {
width: %(width)spx;
height: %(height)spx;
background-repeat: no-repeat;