Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Van Gheem vangheem

View GitHub Profile
@vangheem
vangheem / gist:6358511
Created Aug 27, 2013
archetypes note patch
View gist:6358511
import transaction
from copy import deepcopy
from cgi import escape
from cStringIO import StringIO
from logging import ERROR
from types import ClassType, FileType, StringType, UnicodeType
from zope.contenttype import guess_content_type
from zope.i18n import translate
View gist:2c625d89c33c1010662c
def renderTiles(request, tree):
"""
copy from blocks minus ESI stuff
"""
site = getSite()
siteUrl = site.absolute_url()
try:
root = tree.getroot()
except AttributeError:
@vangheem
vangheem / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
View widget.py
import zope.interface
import zope.schema.interfaces
import z3c.form.interfaces
import z3c.form.browser.textarea
import z3c.form.widget
from plone.app.z3cform.widget import RelatedItemsWidget
class MyRelatedItemsWidget(RelatedItemsWidget):
View example-image-tile.py
from plone.tiles import Tile
from plone.app.z3cform.widget import RelatedItemsFieldWidget
from plone.app.standardtiles.image import image_scales
from plone.autoform import directives as form
from plone.supermodel import model
from zope import schema
from zope.component import getMultiAdapter
from zope.component.hooks import getSite
from zope.globalrequest import getRequest
from zope.interface import Invalid
View example-image-tile.pt
<tal:container tal:define="image python: view.get_image()">
<div class="image-tile-container" tal:define="caption view/data/caption|nothing">
<p class="image" tal:condition="nocall: image">
<img src="${image/absolute_url}/@@images/image/${view/data/scale|large}" alt="${image/Title}" />
<p class="description" tal:condition="caption">${caption}</p>
</p>
<p tal:condition="python: not image">
No image specified
</p>
View patterns.js
/* globals define */
define(function(){
'use strict';
var REGISTERED = {};
var register = function(name, config){
REGISTERED[name] = config;
};
@vangheem
vangheem / view.py
Created Feb 27, 2017
Streaming s3 file for downloads
View view.py
# using aiobotocore and plone.server(aiohttp)
ob = await client.get_object(Bucket=bucket, Key=key)
info = ob['ResponseMetadata']['HTTPHeaders']
resp = aiohttp.web.StreamResponse(headers=aiohttp.MultiDict({
'CONTENT-DISPOSITION': 'attachment; filename="%s"' % self.filename,
'Content-Type': info['content-type']
}))
resp.content_type = info['content-type']
resp.content_length = info['content-length']
@vangheem
vangheem / tablo-export.py
Last active May 8, 2017
Export all your tablo vidoes
View tablo-export.py
#
# Requirements:
# - Python >= 3.5
# - requests
# - aiohttp
#
import argparse
import asyncio
import json
import os
View keybase.md

Keybase proof

I hereby claim:

  • I am vangheem on github.
  • I am vangheem (https://keybase.io/vangheem) on keybase.
  • I have a public key ASCNjRhUMtWBRcsWbhvLA8bxXGTtTbURKVorvouxR9rsdwo

To claim this, I am signing this object: