Skip to content

Instantly share code, notes, and snippets.

View seanupton's full-sized avatar

Sean Upton seanupton

  • Mostscript, LLC
  • Salt Lake City, Utah USA
View GitHub Profile
@seanupton
seanupton / event_view_date_normalize.js
Created August 30, 2012 21:54
Proposed local time normalization in JavaScript for plone.app.event event view.
_pad2 = function (v) { return (v < 10) ? ('0' + v) : ('' + v); }
utc_offset = function (dt) {
var tzoffset = 'Z', offset=dt.getTimezoneOffset();
if (offset != 0) {
tzoffset = (offset < 0) ? '+' : '-';
offset = Math.abs(offset);
tzoffset += _pad2(Math.floor(offset/60)) + ':' + _pad2(offset%60);
}
return tzoffset;
@seanupton
seanupton / gist:5717390
Last active December 18, 2015 03:19
How zope people really want to write JavaScript...
/*jshint browser: true, nomen: false, eqnull: true, trailing:true */
/* global habitable, console */
var mycalendar = (function (ns, core) {
"use strict";
var schema = core.schema,
Schema = schema.Schema;
ns.ICalendarEvent = new Schema({
@seanupton
seanupton / zope2.py
Last active May 11, 2017 19:53
Example of possible thread-based scanner and email notification for unpatched Plone... YMMV, this code is completely untested aside from passing flake8 checks I have in my editor, I just put this together for explanatory purposes of my intent.
import datetime
import pkg_resources
import re
import smtplib
import socket
import threading
import time
from App.config import getConfiguration
from plone.break_core import VulnerabilityCheck as VC
@seanupton
seanupton / gist:9902518
Last active August 29, 2015 13:57
JavaScript Geometric ajax request batching
// premise:
// all items in collection of AJAX-loaded content have about same complexity.
//
// first item in a collection should be loaded as quickly as possible, as it
// is the first item to be seen.
//
// But generally, larger batch sizes are more efficient, for fewer requests
//
// the closer to the end of the collection, the larger the batch size.
//
@seanupton
seanupton / check.py
Created March 31, 2014 22:44
Recursive checker for Plone 3 to Plone 4 product upgrade
import os
import re
import sys
import urllib2
from z3c.pt.language import Parser
defines = {
'template_id' : 'template/getId',
'normalizeString' : 'nocall:context/@@plone/normalizeString',
@seanupton
seanupton / solr-build.cfg
Created April 1, 2014 17:23
Solr plone buildout example
[buildout]
parts =
productdistros
instance
zopepy
solr-download
solr-instance
extends =
http://download.zope.org/Zope2/index/2.12.3/versions.cfg
http://dist.plone.org/release/4.0.1/versions.cfg
@seanupton
seanupton / gist:9918888
Created April 1, 2014 17:27
LDAP client example bulidout
[buildout]
extensions = buildout.extensionscripts
extension-scripts = ${buildout:directory}/src/osdetect.py:osdetect
parts =
opt
bdb-source
bdb-build
openssl-build
zlib
sasl-build
@seanupton
seanupton / gist:f1e0e72efed014d400b4
Last active August 29, 2015 14:07
Media encoding options (policy) utility interface
from zope.interface import Interface
class IMediaEncodingPolicy(Interface):
"""
Utility interface, to determine options for transcoding based on
container and/or stream metadata, which is assumed to be a dict matching
the avprobe JSON schema, with two primary keys of 'format' (container),
and 'streams' -- merged from two respective avprobe commands:
@seanupton
seanupton / gist:7697e21bb906478488d0
Created January 12, 2015 20:08
Making zodbupdate play nice with RelStorage
# somewhere in zodbupdate, likely at the end of update.py,
# add a monkey-patch for RelStorage to have a record_iternext() method:
# relstorage monkey patch for zodbupdate compatibility
# BIG caveat: FileStoreage record_iternext() is only current records; this
# will only ever work on a history-free or zero-day-packed
# RelStorage, and as such it is a hack.
import itertools
from relstorage.storage import RelStorage
@seanupton
seanupton / pkgcomp.py
Created February 24, 2015 17:41
Detect possible typosquatting package names in PyPI -- warning: slow, noisy
# compare package names in PyPI for possible typosquatting
# WARNING: slow O(n^2), even if optimized, may yield 1000+ results
import time
from lxml import html
import urllib2
LISTURL = 'https://pypi.python.org/simple/'