Skip to content

Instantly share code, notes, and snippets.

Lukas Graf lukasgraf

  • 4teamwork AG
  • Bern, Switzerland
Block or report user

Report or block lukasgraf

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View com.py
from log import setup_logger
class Communicator(object):
def __init__(self, logger=None):
if logger is None:
logger = setup_logger(__name__)
self.log = logger
@lukasgraf
lukasgraf / session_example.py
Created Oct 27, 2015
Using requests sessions
View session_example.py
import requests
urls = ['https://en.wikipedia.org/wiki/%s' % n for n in range(100)]
# Code that creates a new connection for every request
for url in urls:
r = requests.get(url)
data = r.text
print len(data)
@lukasgraf
lukasgraf / configure.zcml
Created Oct 11, 2015
CSRF debug helper: Trigger CSRF protection
View configure.zcml
<configure
xmlns:browser="http://namespaces.zope.org/browser">
<browser:page
name="trigger-csrf"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
class=".trigger.TriggerCSRFProtection"
permission="cmf.ManagePortal"
/>
@lukasgraf
lukasgraf / trace_register.py
Created Oct 11, 2015
CSRF debug helper: Trace object registrations
View trace_register.py
"""Helper to trace ZODB object registrations in order to debug CSRF false
positives with plone.protect.
This helper is intended for DEBUGGING, not for use in production!
"""
from collections import namedtuple
from functools import partial
from threading import local
from ZODB.utils import u64
@lukasgraf
lukasgraf / checkout.py
Created Jan 21, 2015
External Payment Processor example
View checkout.py
# -*- coding: utf-8 -*-
from ftw.shop.interfaces import IPaymentProcessor
from ftw.shop.interfaces import IShoppingCart
from ftwshop.adminpay.interfaces import IAdminpayAccountConfig
from ftwshop.adminpay.interfaces import IGlobalAdminpaySettings
from plone.registry.interfaces import IRegistry
from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope.component import adapts
from zope.component import getMultiAdapter
View gist:7d6091462afb481731ae
lukasgraf@helios ~/Plone/buildouts/opengever/og-core-4.x $ bin/buildout -vvvvvvv
Installing 'mr.developer', 'lovely.buildouthttp'.
We have the distribution that satisfies 'mr.developer==1.21'.
We have the best distribution that satisfies 'lovely.buildouthttp'.
Picked: lovely.buildouthttp = 0.5.0
mr.developer: Queued 'opengever.maintenance' for checkout.
mr.developer: Updated 'opengever.maintenance' with git.
lovely.buildouthttp: Added credentials 'foo', 'http://psc.4teamwork.ch'
lovely.buildouthttp: Added credentials 'bar', 'https://svn.4teamwork.ch'
Installing 'zc.buildout', 'setuptools'.
View gist:ca6750fe3ff0fb13d5ad
lukasgraf@helios ~/Plone/buildouts/opengever/og-core-4.x $ md5 bootstrap.py
MD5 (bootstrap.py) = dcf4d3aa7102eb3885a7cea1f6b50a23
lukasgraf@helios ~/Plone/buildouts/opengever/og-core-4.x $ python2.7 bootstrap.py
Downloading https://pypi.python.org/packages/source/s/setuptools/setuptools-7.0.zip
Extracting in /var/folders/d5/8djs4qxd78lb98g8r7hyp7wr0000gn/T/tmpDoh09p
Now working in /var/folders/d5/8djs4qxd78lb98g8r7hyp7wr0000gn/T/tmpDoh09p/setuptools-7.0
Building a Setuptools egg in /var/folders/d5/8djs4qxd78lb98g8r7hyp7wr0000gn/T/tmpt3fsyg
/var/folders/d5/8djs4qxd78lb98g8r7hyp7wr0000gn/T/tmpt3fsyg/setuptools-7.0-py2.7.egg
View logging_sslsocket.py
from http.server import BaseHTTPRequestHandler, HTTPServer
from socket import socket
from socketserver import ThreadingMixIn
from threading import Thread
import logging
import ssl
class LoggingSSLSocket(ssl.SSLSocket):
View gist:7326a14c3ff5adcbb745
<?xml version="1.0" encoding="UTF-8"?>
<rules
xmlns="http://namespaces.plone.org/diazo"
xmlns:css="http://namespaces.plone.org/diazo/css"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<rules css:if-not-content="body.template-mail_password_form, body.template-mail_password_response, body.template-pwreset_form, body.template-register, body.template-registered">
<drop css:content="#hugo" />
</rules>
</rules>
View gist:9135385
<?xml version="1.0" ?>
<ldapplugins>
<ldapplugin title="Example LDAP" id="ldap" meta_type="Plone LDAP plugin" update="False">
<interface value="IAuthenticationPlugin"/>
<interface value="ICredentialsResetPlugin"/>
<interface value="IGroupEnumerationPlugin"/>
<interface value="IGroupIntrospection"/>
<interface value="IGroupManagement"/>
You can’t perform that action at this time.