Skip to content

Instantly share code, notes, and snippets.

View wichert's full-sized avatar

Wichert Akkerman wichert

View GitHub Profile
@wichert
wichert / queue.py
Created April 15, 2014 08:45
Example of integration rq with transactions
def enqueue(request, queue, func, *a, **kw):
"""Queue a function call.
:param request: Pyramid request object
:param queue: name of the rq queue to use
:param func: function or instance method to call
:return: rq job instance
>>> enqueue(request, 'email', myfunc, arg1, arg2)
"""

Keybase proof

I hereby claim:

  • I am wichert on github.
  • I am wichert (https://keybase.io/wichert) on keybase.
  • I have a public key whose fingerprint is 5D61 B9A0 8594 F6FA 57AB 2EA2 8A93 CA33 1E53 1D8B

To claim this, I am signing this object:

@wichert
wichert / crop.js
Created July 31, 2015 12:22
JavaScript function to dynamically crop text
// Look for all elements with a clip class, and remove words form them
// until the text fits in the available space. This requires the element
// to have a fixed (maximum) width and height.
function cropText(root) {
var victims = root.querySelectorAll(".clip"),
rest, html, victim, $victim, words, cropped;
for (var i=0; i<victims.length; ++i) {
$victim=$(victim=victims[i]);
// We can only measure when the item is visible, but make it transparent
@wichert
wichert / gist:909848
Created April 8, 2011 13:38
C++ Lua wrapper
#include <lua.hpp>
class Lua {
public:
static class Nil { Nil(); } nil;
Lua() {
L=luaL_newstate();
}
@wichert
wichert / gist:1082147
Created July 14, 2011 09:15
Chameleon XI/Metal combination trick
<!-- tools.pt -->
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
xmlns:meta="http://xml.zope.org/namespaces/meta"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:tal="http://xml.zope.org/namespaces/tal"
meta:interpolation="true"
tal:condition="False">
<metal:tooltip define-macro="tooltip">
@wichert
wichert / test_tmpstore.py
Last active September 26, 2015 14:17
redis deform.interfaces.FileUploadTempStore implementation
import unittest
import pyramid.testing
class RedisTempStoreTests(unittest.TestCase):
def setUp(self):
from .tmpstore import DummyRedis
self.config = pyramid.testing.setUp()
self.config.registry.settings['redis'] = self.redis = DummyRedis()
@wichert
wichert / gist:1244896
Created September 27, 2011 12:02
Accept-Language aware locale negotiator for Pyramid
#: Mapping of language codes send by browsers to supported dialects.
BROWSER_LANGUAGES = {
'en-CA': 'en_CA',
'en-GB': 'en_GB',
'en-US': 'en_GB',
'en': 'en_GB',
'nl': 'nl_NL',
'nl-NL': 'nl_NL',
'nl-BE': 'nl_NL',
'zh': 'zh_CN',
@wichert
wichert / gist:3426993
Created August 22, 2012 15:58
errormator javascript logging experiment
<!DOCTYPE html>
<html>
<head>
<title>Javascript error handling logic</title>
</head>
<body>
<script type="text/javascript" src="https://github.com/downloads/eriwen/javascript-stacktrace/stacktrace-0.4.js"></script>
<script type="text/javascript">
// <![CDATA[
// ]]>
@wichert
wichert / convert.py
Created November 5, 2012 12:37
Patternslib syntax converter
import argparse
import os
import re
import sys
from lxml import etree
def read(fn):
with open(fn, 'r') as input:
parser = etree.HTMLParser()
@wichert
wichert / markdown.py
Created November 16, 2015 14:36
Markdown rendering in Chameleon
# This module allows you to use markdown in Chameleon templates from pyramid.
#
# Markdown rendering is only down for text that is translatable, and has its
# message context set to ``markdown``. This is a complete abuse of the translation
# system, but currently provides the simplest way to get markdown running in
# Chameleon.
import CommonMark
from chameleon.utils import Markup
from translationstring import ChameleonTranslate
from pyramid_chameleon.localization import translator