Skip to content

Instantly share code, notes, and snippets.

View jaroel's full-sized avatar

Roel Bruggink jaroel

View GitHub Profile
@jaroel
jaroel / ftpproxy.py
Created July 16, 2023 15:39
ftp proxy with FastAPI
import aioftp
from fastapi import FastAPI, HTTPException, Request
from fastapi.responses import StreamingResponse
app = FastAPI()
@app.get('/fetch/{filename}', name='fetch')
async def ftp_fetch(request: Request, filename: str):
return StreamingResponse(
stream_file(filename),
@jaroel
jaroel / solid-start-form-post-ssr.tsx
Created February 24, 2023 00:18
Use POST data in forms in SSR with SolidStart
import {isServer} from 'solid-js/web'
import {createRouteData} from 'solid-start'
import {useRequest} from 'solid-start/server'
export default function FormPage() {
const postData = createRouteData(async () => {
const event = useRequest()
if (!isServer || event.request.method !== 'POST') {
return undefined
}
@jaroel
jaroel / site.zcml
Created April 4, 2016 20:21
Minimal site.zcml to make my Plone 5 instance running without z3c.autoinclude.
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:meta="http://namespaces.zope.org/meta"
xmlns:five="http://namespaces.zope.org/five">
<include package="Zope2.App" />
<include package="Products.Five" />
<meta:redefinePermission from="zope2.Public" to="zope.Public" />
<!-- Load the meta -->
@jaroel
jaroel / make_constraintstxt.py
Created April 4, 2016 20:02
Outputs a constraints.txt compatible pinning from a Plone versions.cfg. Requires zc.buildout for parsing the .cfg files, naturally.
from pkg_resources import parse_version
from zc.buildout.buildout import Buildout
def get_buildout(version):
versions_url = 'http://dist.plone.org/release/{version}/versions.cfg'
url = versions_url.format(version=version)
buildout = Buildout(
config_file=url,
[settings]
multi_line_output=3
known_first_party=ames
default_section=THIRDPARTY
@jaroel
jaroel / add_hotfix.sh
Last active December 8, 2015 17:16
Unpack Plone hotfixes into parts/products
#!/bin/bash
# ./add_hotfix.sh url md5hash [target basedir]
# i.e. ./add_hotfix.sh http://plone.org/products/plone-hotfix/releases/20110928/PloneHotfix20110928-1.0.zip aab87c2904754a2f6374f52c441fb97f /zeoclients/
PATCHFILE="/tmp/$(basename $0).$$"
rm -rf "$PATCHFILE"
curl "$1" > "$PATCHFILE"
MD5=`openssl md5 "$PATCHFILE"|cut -d " " -f 2`
[[ $MD5 != $2 ]] && echo "Hashes do not match." && exit 1
stationDepartures id sc=map (\(s1,list)->(stationName $ (stationMap $ system sc) Map.! s1,list)) ( Map.toList (Map.fromListWith (++) (map (\((s1,s2),(d,start,dur))->(s2,[start])) (Map.toList (Map.filterWithKey (\(s1,s2) _ ->s1==id) (Map.unions (List.map times (Map.elems $ schedule sc))))))))
@jaroel
jaroel / gist:741ed34d0a1528792aec
Created October 8, 2014 12:29
Ploneconf 2014 schedule
Wednesday
http://2014.ploneconf.org/talks/@@list#talk_8 Journeys with Transmogrifier & friends or How not to get stuck in the Plone dark ages
http://2014.ploneconf.org/talks/@@list#talk_16 Code analysis for a better future
http://2014.ploneconf.org/talks/@@list#talk_1 RelStorage for mere mortals
http://2014.ploneconf.org/talks/@@list#talk_20 Why Plone is going to die!
http://2014.ploneconf.org/talks/@@list#talk_42 The Beauty and the Beast. Modern Javascript Depelopment with AngularJS and Plone
http://2014.ploneconf.org/talks/@@list#talk_24 ApplicationCache and Plone: An ongoing battle
http://2014.ploneconf.org/talks/@@list#talk_31 Easy Online Business Processes with Plone Forms and Workflow
Thursday
@jaroel
jaroel / gist:6ea92dafd1c61dc08de9
Last active August 29, 2015 14:00
Show message for end user on errors with LDAP server in Plone
patches.py:
from plone.api.portal import show_message
from cStringIO import StringIO
import logging
fake_log_file = StringIO()
aux_logger = logging.StreamHandler(fake_log_file)
aux_logger.setLevel(logging.ERROR)
ldap_logger = logging.getLogger('event.LDAPDelegate')
ldap_logger.addHandler(aux_logger)
@jaroel
jaroel / gist:5345403
Created April 9, 2013 12:42
Parameterised dynamic vocabulary. Shows unique values for catalog index. Pass in the index name in the schema.
Definition:
===========
from zope.schema.interfaces import IContextSourceBinder, IBaseVocabulary
class CatalogIndexValuesSource(object):
grok.implements(IContextSourceBinder, IBaseVocabulary)
def __init__(self, index_name):
self.index_name = index_name