Skip to content

Instantly share code, notes, and snippets.

View cburgmer's full-sized avatar

Christoph Burgmer cburgmer

View GitHub Profile
@cburgmer
cburgmer / gist:862398
Created March 9, 2011 15:32
Extracting a file with Solr & Tika for indexing using Python
import json
import os
import urllib2
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
# Register poster to urllib2
register_openers()
@cburgmer
cburgmer / validator-steps.py
Created April 17, 2011 13:52
Using Selenium to validate XHTML markup using lettuce
# -*- coding: utf-8 -*-
import re
from lettuce import world, step, before
from lettuce_webdriver.util import find_field
from lettuce_webdriver import webdriver # We need this to register "I visit..."
from nose.tools import assert_true
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
@before.all
@cburgmer
cburgmer / example.py
Created June 1, 2011 17:59
Using proper timezone information with SuRF
from datetime import datetime
# Get the UTC tzinfo object, alternatively use the solution from http://docs.python.org/library/datetime.html#tzinfo-objects
from pytz import utc
my_article = Article()
# Save timestamp "now" as UTC
my_article.dc_created = datetime.now(utc)
my_article.save()
@cburgmer
cburgmer / gist:1121011
Created August 2, 2011 19:39
Here is a quick snippet how to test if overflow is happening in a DOM element, shamelessly taken from http://www.bramstein.com/projects/text-overflow/.
// Check if overflow happens for a given jquery element
function check_overflow(element) {
var element_clone = element.clone();
element.after(element_clone.hide().css({
'position': 'absolute',
'width': 'auto',
'overflow': 'visible',
'max-width': 'inherit'
}));
@cburgmer
cburgmer / Area.java
Created October 4, 2011 17:36
OOPExercise3
public class Area extends Measurement {
public Area(int value) {
super(value);
}
}
@cburgmer
cburgmer / SpecRunner.html
Created April 3, 2012 19:37
Using Gradle & ANT to get JUnit XML results (e.g. from Jasmine) in HTML
<!DOCTYPE html>
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="stylesheet" type="text/css" href="../lib/jasmine-1.1.0/jasmine.css">
<script type="text/javascript" src="../lib/jasmine-1.1.0/jasmine.js"></script>
<script type="text/javascript" src="../lib/jasmine.junit_reporter.js"></script>
</head>
<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('../../build/reports/jasmine/', false)); // don't consolidate so that JUnitReport can pick up the XML
@cburgmer
cburgmer / wiki2text.py
Created April 18, 2012 21:07
Mediawiki markup to text converter that operates on dumps
import sys
import logging
from lxml import etree
# Install from https://github.com/erikrose/pijnu & https://github.com/erikrose/mediawiki-parser
from pijnu.library.error import IncompleteParse
from preprocessor import make_parser as make_preprocessor_parser
from text import make_parser
@cburgmer
cburgmer / htmlparser.js
Created June 5, 2012 20:46
John Resig's JavasScript HTML parser with bug fixes for parsing <script> & <style>
/*
* HTML Parser By John Resig (ejohn.org)
* Original code by Erik Arvidsson, Mozilla Public License
* http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
*
* // Use like so:
* HTMLParser(htmlString, {
* start: function(tag, attrs, unary) {},
* end: function(tag) {},
* chars: function(text) {},
@cburgmer
cburgmer / example.html
Created June 20, 2012 21:37
Minimal example for rasterizeHTML.js
<!DOCTYPE html>
<html>
<head>
<title>rasterizeHTML.js example</title>
<script type="text/javascript" src="lib/htmlparser.js"></script> <!-- Needed for Chrome & Safari to work around buggy XMLSerializer -->
<script type="text/javascript" src="lib/cssParser.js"></script> <!-- Needed to embed backgroundImages -->
<script type="text/javascript" src="lib/URI.js"></script> <!-- Needed to calculate paths when embedding stuff -->
<script type="text/javascript" src="rasterizeHTML.js"></script>
</head>
<body>
@cburgmer
cburgmer / binaryfile.js
Created July 4, 2012 20:36
Reading a binary file through AJAX
// See https://developer.mozilla.org/en/DOM/XMLHttpRequest/Sending_and_Receiving_Binary_Data
var readBinaryFile = function (url) {
var content, newContent = "";
$.ajax({
dataType: 'text',
mimeType: 'text/plain; charset=x-user-defined',
url: url,
async: false,
cache: false,