Skip to content

Instantly share code, notes, and snippets.

@davisagli
davisagli / ram.ipynb
Last active August 8, 2023 16:10
Experiments with Plone object RAM use (ipython notebook viewer: http://nbviewer.ipython.org/7407505)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@davisagli
davisagli / releasenotes.yml
Created September 7, 2022 01:15
Github action to preview release notes
name: Preview release notes
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
release-notes:
@davisagli
davisagli / gist:5824662
Last active April 24, 2022 11:19
Running Zope code as a celery task
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import noSecurityManager
from Testing.makerequest import makerequest
from ZODB.POSException import ConflictError
from celery import Celery, Task
from email.Header import Header
from zope.app.publication.interfaces import BeforeTraverseEvent
from zope.component.hooks import setSite
from zope.event import notify
import email
@davisagli
davisagli / gist:1128383064b1ba5c06b4
Last active May 19, 2021 00:24
authenticating to google API using Service Account credentials
import httplib2
# these are from the google-api-python-client package
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
def _get_google_service(email, key):
"""Get a Google API client using Service Account credentials"""
credentials = SignedJwtAssertionCredentials(
@davisagli
davisagli / pipes.py
Last active February 27, 2020 05:09
pypes
import inspect
import itertools
class Pipe:
def __init__(self, source):
self.source = source
def __or__(self, sink):
if inspect.isgenerator(self.source) and not inspect.isgeneratorfunction(sink):
@davisagli
davisagli / gist:7047450
Created October 18, 2013 20:06
Here's what configuring Plone would look like if ZCML were Python. Wonder if we can cut some of this out.
# --------------------------------------------------
# site.zcml
# --------------------------------------------------
def includeme(config):
zope = config.get_namespace('http://namespaces.zope.org/zope')
meta = config.get_namespace('http://namespaces.zope.org/meta')
five = config.get_namespace('http://namespaces.zope.org/five')
zope.include(package='Products.Five')
schema:
{
"properties": {
"behaviors": {
"additionalProperties": {
"oneOf": [
{
"properties": {
"@type": {
# Change set.__module__ to 'builtins'
# so that it will pickle with the right module for Python 3
from ctypes import Structure, c_ssize_t, c_void_p, c_char_p
class PyTypeObject(Structure):
_fields_ = [
('ob_refcnt', c_ssize_t),
('ob_type', c_void_p),
('ob_size', c_ssize_t),
('tp_name', c_char_p),
]
@davisagli
davisagli / filemaker.py
Created May 17, 2016 19:15
Filemaker CSV reader
import csv
class FilemakerCSVDictReader():
"""CSV reader to read Filemaker CSV exports as dicts.
Applies a few transformations to all values:
* Decodes as cp1252
* Replaces vertical tabs with newlines
* Splits fields containing the Group Separator control character into lists

Keybase proof

I hereby claim:

  • I am davisagli on github.
  • I am davisagli (https://keybase.io/davisagli) on keybase.
  • I have a public key ASDutQViikK1K9Mb7n1PuFHh81ZWUMYDNO-OEIorm5xxTwo

To claim this, I am signing this object: