Skip to content

Instantly share code, notes, and snippets.

View hvelarde's full-sized avatar

Héctor Velarde hvelarde

View GitHub Profile
@hvelarde
hvelarde / default
Created November 23, 2016 17:17
nginx configuration for Plone
# Configuration file for nginx
#
# This file must me symlinked to /etc/nginx/sites-enabled/default
upstream plone {
server localhost:8081;
server localhost:8082;
}
server {
@hvelarde
hvelarde / nginx.conf
Created November 23, 2016 17:13
nginx configuration for Plone
# Configuration file for nginx
#
# This file must me symlinked to /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 4096;
@hvelarde
hvelarde / default.vcl
Last active November 23, 2016 18:36
Varnish 4 configuration for Plone
# VCL configuration file for Varnish. It defines 2 backends, one for
# each Plone instance, and uses hash load balancing.
#
# This file must me symlinked to /etc/varnish/default.vcl
vcl 4.0;
import directors;
import std;
@hvelarde
hvelarde / varnish
Last active November 23, 2016 17:14
Varnish 4 configuration for Plone
# Configuration file for varnish
#
# /etc/init.d/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK
# to be set from this shell script fragment.
#
# This file should be symlinked to /etc/default/varnish
# Should we start varnishd at boot? Set to "no" to disable.
START=yes
@hvelarde
hvelarde / spoof.py
Last active February 28, 2018 13:19
Spoofing request when running Zope from the command line
from plone import api
from zope.component.hooks import setSite
import transaction
def spoof_request(app):
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManager import setSecurityPolicy
from Testing.makerequest import makerequest
@hvelarde
hvelarde / api_hacks.py
Created April 6, 2016 16:22
Hacks to work around API inconsistencies between Archetypes and Dexterity
# -*- coding: utf-8 -*-
"""Hacks to work around API inconsistencies between Archetypes and Dexterity."""
def set_image_field(obj, image, content_type):
"""Set image field in object on both, Archetypes and Dexterity."""
from plone.namedfile.file import NamedBlobImage
try:
obj.setImage(image) # Archetypes
except AttributeError:
@hvelarde
hvelarde / gist:82dab21a803f8d68a217
Last active August 29, 2015 14:03
Using bpython and IPython
eggs += bpython
bin/instance debug
import bpython; bpython.embed(locals_=locals())
eggs += IPython
bin/instance debug
@hvelarde
hvelarde / pep257.cfg
Created May 1, 2014 00:42
Add support for docstring style checker on buildout
[buildout]
parts = pep257
[pep257]
recipe = zc.recipe.egg
eggs = pep257
entry-points = pep257=pep257:main
arguments = *pep257.parse_options()
@hvelarde
hvelarde / github3.py example
Last active December 27, 2017 12:40
Getting your contributions on a GitHub organization using github3.py to access the GitHub API.
>>> user, password = 'hvelarde', 'password'
>>> from github3 import login
>>> g = login(user, password=password)
>>> o = g.organization('collective')
>>> g.ratelimit_remaining
3369
>>> my_stats = []
>>> for r in o.iter_repos():
... for c in r.iter_contributor_statistics():
... if user in repr(c.author):
(python-2.7)# hvelarde@nanovac (master u=) ~/collective/cover
# git shortlog -s | sort -nr
697 hvelarde
312 Juan Pablo Giménez
91 Héctor Velarde
78 Franco Pellegrini
76 Marcos F. Romero
71 quimera
71 Cleber J Santos
66 Gonzalo Almeida