Skip to content

Instantly share code, notes, and snippets.

View vangheem's full-sized avatar

Nathan Van Gheem vangheem

View GitHub Profile
@vangheem
vangheem / gist:6358511
Created August 27, 2013 20:11
archetypes note patch
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
@vangheem
vangheem / gist:2c625d89c33c1010662c
Created June 26, 2014 13:26
alternative renderTiles
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 August 29, 2015 14:09
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@vangheem
vangheem / widget.py
Last active September 11, 2015 16:12
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):
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
<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>
/* globals define */
define(function(){
'use strict';
var REGISTERED = {};
var register = function(name, config){
REGISTERED[name] = config;
};
@vangheem
vangheem / view.py
Created February 27, 2017 14:59
Streaming s3 file for downloads
# 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 22:54
Export all your tablo vidoes
#
# Requirements:
# - Python >= 3.5
# - requests
# - aiohttp
#
import argparse
import asyncio
import json
import os

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: