Skip to content

Instantly share code, notes, and snippets.

View keul's full-sized avatar
🏠
Working from home

Luca Fabbri keul

🏠
Working from home
View GitHub Profile
@zopyx
zopyx / gist:2fb8fc905db542807fe1
Created September 19, 2014 08:04
CORRECT copying of all fields from one Dexterity content object to another instance of the same type
def clone_plone_metadata(source, target):
""" Copy all metadata key-value pairs of the 'source'
Dexterity content-object to 'target'.
"""
from plone.dexterity.interfaces import IDexterityFTI
from plone.behavior.interfaces import IBehaviorAssignable
if not isinstance(source, target.__class__):
raise TypeError('source and target must be the same class ({} vs {})'.format(source.__class__, target.__class__))
@gforcada
gforcada / warmup_plone.py
Last active December 25, 2015 21:08
Script that (re)starts a Plone instance, loads its main page and all links within the Plone instance that are on the main page (some filters provided)
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------------
# Script to warm up the instance.
#
# The script starts/restarts the instance and measures the time it takes the
# instance to become responsive. Afterwards it crawls the front-page for links
# and warms up these resources.
# ----------------------------------------------------------------------------
from datetime import datetime
@leophys
leophys / git-merge-pick
Last active June 28, 2018 14:46
An extension for git to git-merge a single specified file from another revision
#!/usr/bin/env bash
usage () {
cat << EOH
git merge-pick [flags] <tree-ish> path/to/file
being <tree-ish> a commit-like object (a commit sha1,
a branch name or a tag).
[flags]
@thet
thet / earchwallpaper.sh
Created November 9, 2018 08:13
World Sunlight Map Wallpaper
#!/bin/bash
#
# Changes the wallpaper hourly and displays a projection of the earth with
# a semi-realistic rendered sunglight mapping.
#
# This script will download hourly the "World Sunlight Map" by die.net.
# You can choose the world_sunlight_wallpaper.jpg picture as background image for your Desktop.
# Gnome recognizes file changes and updates the background accordingly.
#
# See:
@thet
thet / upgrades.py
Created June 12, 2017 13:53
Plone / Zope Component Architecture: Unregister all broken persistent utilities
# -*- coding: utf-8 -*-
from zope.component.hooks import getSite
import logging
log = logging.getLogger(__name__)
def unregister_broken_persistent_components(context):
portal = getSite()
sm = portal.getSiteManager()
@jimfb
jimfb / react-refs-must-have-owner.md
Last active July 13, 2019 06:35
addComponentAsRefTo Invariant Violation

You are probably here because you got the following error messages:

addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's render method, or you have multiple copies of React loaded.

This usually means one of two things:

  • You are trying to add a ref to an element that is being created outside of a component's render() function.
  • You have multiple (conflicting) copies of React loaded (eg. due to a miss-configured NPM dependency)

Invalid Refs

@benpickles
benpickles / action.js
Created March 18, 2016 16:19
Inject an Authorization header into a redux-api-middleware request with a Redux middleware.
import { CALL_API } from 'redux-api-middleware'
export function fetchLocations() {
return {
[CALL_API]: {
endpoint: 'http://api.somesite.com/api/locations',
method: 'GET',
// Don't have to manually add the Authorization header to every request.
headers: { 'Content-Type': 'application/json' },
types: ['REQUEST', 'SUCCESS', 'FAILURE']
@thet
thet / memoize.py
Created November 30, 2020 10:36
plone.memoize helpers with support for plone.subrequest
# -*- coding: utf-8 -*-
# memoize support for plone.subrequest subrequests.
# usage:
# >>> import ./memoize
# >>> from ./memoize import instance_memoize
# >>> @memoize.parent_request_memoize
# >>> def _results(self):
# >>> return "expensive calculation"
# >>>
@DimitryDushkin
DimitryDushkin / react-shadow-dom-fix.js
Last active December 23, 2020 07:48
React v15 Shadow Dom events fix. Based on http://stackoverflow.com/a/37891448/297939. Unnecessery events removed and fix for multiple dispatches added.
export default function retargetEvents(el) {
// Here include necessary events' name to track
['onClick', 'onChange'].forEach(eventType => {
const transformedEventType = eventType.replace(/^on/, '').toLowerCase();
el.addEventListener(transformedEventType, event => {
for (let i in event.path) {
const item = event.path[i],
internalComponent = findReactInternal(item);
@jelmervdl
jelmervdl / index.html
Created December 1, 2016 11:03
Pure Python & Flask server-side event source
<script>
var stream = new EventSource('/api/stream');
stream.onmessage = function(e) {
console.info(e.data);
};
</script>