Skip to content

Instantly share code, notes, and snippets.

View acdha's full-sized avatar

Chris Adams acdha

View GitHub Profile
@acdha
acdha / media-element-events.md
Created June 30, 2014 19:07
Writeup for browser non-compliance with HTML spec for media element event handling

Spec

According to the HTML specification, native controls on the media element should not trigger normal mouse events:

“If the user agent exposes a user interface to the user by displaying controls over the media element, then the user agent should suppress any user interaction events while the user agent is interacting with this interface. (For example, if the user clicks on a video's playback control, mousedown events and so forth would not simultaneously be fired at elements on the page.)”

@acdha
acdha / sha256 performance log
Created August 5, 2014 15:11
Simple comparison of SHA-256 performance reading random bytes from SSD (context: http://www.avpreserve.com/wp-content/uploads/2014/08/ChecksumComparisons.pdf)
time ./simple-sha256.pl 1GB 10GB
1GB 1872c9662b6cd15fbbb66be3a760d4bd02ab5077429db21103ac8f63538d8a5f
10GB 732377e7f4a2abdc13ddfa1eb4c9c497fd2a2b294674d056cf51581b47dd586d
real 1m31.644s
user 1m26.695s
sys 0m4.465s
SHA256(1GB)= 1872c9662b6cd15fbbb66be3a760d4bd02ab5077429db21103ac8f63538d8a5f
SHA256(10GB)= 732377e7f4a2abdc13ddfa1eb4c9c497fd2a2b294674d056cf51581b47dd586d
{
"indent_size": 4,
"indent_char": " ",
"preserve_newlines": true,
"max_preserve_newlines": 2,
"jslint_happy": true,
"keep_array_indentation": true,
"break_chained_methods": false,
"keep_function_indentation": true
}
@acdha
acdha / leaflet-fit-points.js
Created September 12, 2014 15:26
JS fragment to zoom a Leaflet JS map to fit all points
function fitBounds(map, initialBounds, fitOptions) {
var bounds = new L.LatLngBounds(),
options = {reset: true};
if (typeof(fitOptions) == 'undefined' && initialBounds && !initialBounds.getCenter) {
fitOptions = initialBounds;
initialBounds = null;
}
if (initialBounds) {
@acdha
acdha / sass-force-static-url.rb
Last active August 29, 2015 14:08
Sass function which generates an absolute URL using an explicit hostname and an MD5 cache key compatible with django-staticfiles
require 'digest/md5'
require 'pathname'
module Sass::Script::Functions
def force_static_url(absolute_path_str)
base_path = Pathname.new(File.dirname(__FILE__))
absolute_path = Pathname.new(File.join(base_path, absolute_path_str.value))
if !File.exist?(absolute_path)
raise Sass::SyntaxError, "File not found: #{absolute_path}"
@acdha
acdha / dump-ddc-translations.py
Created November 24, 2014 22:25
Experiment with rdflib to retrieve DDC translations from http://dewey.info using rdflib
#!/usr/bin/env python
# encoding: utf-8
from __future__ import absolute_import, print_function, unicode_literals
import rdflib
g = rdflib.Graph()
for code in ('6', '64', '641'):
@acdha
acdha / es6-destructuring-assignment.js
Last active August 29, 2015 14:10
Things which work in Firefox, Safari and maybe even IE but not V8
/* jshint esnext:true */
var [foo, bar] = [1, 2];
console.log('Foo is', foo);
console.log('Bar is', bar);
@acdha
acdha / gist:f1f506b47a38574f3a5f
Last active August 29, 2015 14:13
Quick mock example showing how to simulate errors
>>> from unittest import mock
>>> import json
>>> m_o = mock.mock_open()
>>> m_o.side_effect = OSError('Insufficient voltage')
>>> json.load(m_o('foo.json', 'rb'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/mock.py", line 896, in __call__
return _mock_self._mock_call(*args, **kwargs)
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/mock.py", line 952, in _mock_call
--- py-svn.c 2015-02-24 10:10:21.000000000 -0500
+++ py-hg.c 2015-02-24 10:11:11.000000000 -0500
@@ -11,7 +11,7 @@
/* Ensure ob_item has room for at least newsize elements, and set
* ob_size to newsize. If newsize > ob_size on entry, the content
* of the new slots at exit is undefined heap trash; it's the caller's
- * responsiblity to overwrite them with sane values.
+ * responsibility to overwrite them with sane values.
* The number of allocated elements may grow, shrink, or stay the same.
* Failure is impossible if newsize <= self.allocated on entry, although
@acdha
acdha / post-checkout
Created March 24, 2015 21:03
Git post-checkout hook for projects which use npm
#!/bin/sh
echo "Installing npm dependencies"
npm install ~/Projects/bagger-js