Skip to content

Instantly share code, notes, and snippets.

View acdha's full-sized avatar

Chris Adams acdha

View GitHub Profile
#!/usr/bin/env python
# encoding: utf-8
"""Attempting to mop up Thomas XML
`pip install requests beautifulsoup4 html5lib lxml`
"""
from __future__ import (absolute_import, division, print_function,
unicode_literals)
{
"@context": "http://iiif.io/api/presentation/2/context.json",
"@id": "http://www.example.org/iiif/book1/manifest",
"@type": "sc:Manifest",
"attribution": "Provided by Example Organization",
"description": "A longer description of this example book. It should give some real information.",
"label": "Book 1",
"license": "http://www.example.org/license.html",
"logo": "http://www.example.org/logos/institution1.jpg",
"metadata": [
@acdha
acdha / test.c
Last active September 8, 2015 15:41
Proof that https://twitter.com/MarcosBL/status/641110424193232897 will segfault in a program which passes “clang -Werror -Weverything -pedantic”
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <float.h>
static int isNegative(float arg) {
char *p = (char*) malloc(20);
sprintf(p, "%f", arg);
return p[0] == '-';
}
@acdha
acdha / congress.gov.log
Last active September 3, 2015 20:57
Simple test of image optimization savings
Optimizing https://www.congress.gov/img/congress_gov_logo2.png
Original: 8654
optipng: 8652
advpng: 8216
zopflipng: 8215
Final: 8215 94.93% (439 bytes saved)
Optimizing https://congress.gov/img/sprite_congress.png
Original: 8137
optipng: 6857
@acdha
acdha / baseline.txt
Last active April 28, 2018 04:37 — forked from jmcnamara/bench_excel_writers.py
Benchmark of several Python Excel writing modules
Versions:
python : 2.7.1
openpyxl : 2.2.5
pyexcelerate: 0.6.6
xlsxwriter : 0.7.3
xlwt : 1.0.0
Dimensions:
Rows = 10000
@acdha
acdha / ga-time-to-first-paint.js
Created August 19, 2015 18:33
Record time to first paint on Chrome/IE using Google Analytics user timing
(function ($) {
'use strict';
/* Based on https://github.com/wikimedia/mediawiki-extensions-NavigationTiming/ */
function recordTimeToFirstPaint() {
// Use Chrome's loadTimes or IE 9+'s msFirstPaint to record the time to render in milliseconds:
var firstPaintTime, timingSource;
if ('chrome' in window && $.isFunction(window.chrome.loadTimes)) {
@acdha
acdha / wdl-video-snippet.html
Last active August 29, 2015 14:26
Simple demonstration of HTML5 video with Flash and warning message fallback
<video id="player" itemprop="video" controls preload="auto" poster="http://content.wdl.org/536/thumbnail/1438262714/616x510.jpg">
<source type="video/mp4" src="http://dl.wdl.org/536/service/536.mp4">
<object id="videoPlayer" type="application/x-shockwave-flash" data="/static/swf/video/videoPlayer.706e405e7ad9.swf" width="320" height="278">
<param name="movie" value="/static/swf/video/videoPlayer.706e405e7ad9.swf">
<param name="flashvars" value="thisVideo=http://dl.wdl.org/536/service/536.flv&amp;thisCC=&amp;thisBg=http://content.wdl.org/536/thumbnail/1438262714/308x255.jpg">
<param name="quality" value="best">
<p class="text-danger">This item is currently unavailable in a format which may be viewed on your device</p>
</object>
@acdha
acdha / get-unicode-blocks.py
Created June 12, 2015 22:32
Ways to get the name of a Unicode block for a character in Python
#!/usr/bin/env PYTHONIOENCODING=utf-8 python
# encoding: utf-8
from __future__ import absolute_import, print_function, unicode_literals
import os
import re
import requests
@acdha
acdha / threaded-requests.py
Created May 15, 2015 18:23
Multi-threaded network I/O in Python 2/3
from __future__ import absolute_import, unicode_literals, print_function
from multiprocessing.pool import ThreadPool
import requests
pool = ThreadPool(processes=8)
for response in pool.imap_unordered(requests.get, urls):
print(response.status_code, response.url)
@acdha
acdha / requests-multiprocessing-test.py
Last active August 29, 2015 14:21
Tracking down sporadic failures in requests under multiprocessing
#!/usr/bin/env python
from __future__ import absolute_import, print_function, unicode_literals
import multiprocessing
import sys
import time
import requests