Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am tilgovi on github.
  • I am tilgovi (https://keybase.io/tilgovi) on keybase.
  • I have a public key whose fingerprint is 9255 5CDE B2C1 5E97 0AD8 FDE8 5994 A5A1 8F13 626A

To claim this, I am signing this object:

@tilgovi
tilgovi / dom-traversals.coffee
Last active October 8, 2015 00:09
DOM tree traversal helpers
# Return true if the given predicate is true for every Node of the tree.
# The predicate function is invoked once for each Node in the tree.
# An optional third argument specifies a traversal order and should be a
# function that takes a Node and returns its successor. The default order is
# DOM position order (pre-order).
everyNode = (node, fn, next = preFirst) ->
return !someNode(node, ((n) -> !fn(n)), next)
# Return the first Node in the tree that matches the predicate.
@tilgovi
tilgovi / annotation-mapper-sqla.patch
Created September 23, 2015 17:01
SQLAlchemy-style mapper class beginnings in CoffeeScript, for Hypothesis
commit 962fe64b4dd5b0a4b02fda6f08a7c81d0e40d961
Merge: 367c72c 595968e
Author: Randall Leeds <[email protected]>
Date: Mon Feb 9 14:47:14 2015 -0800
WIP on master: 367c72c Remove selenium test requirement
diff --cc h/static/scripts/annotation-mapper-service.coffee
index 62d2c08,62d2c08..d95fed1
--- a/h/static/scripts/annotation-mapper-service.coffee
@tilgovi
tilgovi / hypothesis-hashchange.js
Last active August 29, 2015 14:27
Reloading Hypothesis annotations on hash change
// Function to check whether an anchor is currently attached to the document.
function isAttached(anchor) {
// If there are no highlights it is not attached at all.
if (anchor.highlights == null) {
return false;
}
// Check if any of highlights have since been removed from the document.
for (var i = 0 ; i < anchor.highlights.length ; i++) {
if (!document.contains(anchor.highlights[i])) {
@tilgovi
tilgovi / stream-unfiltered.diff
Created April 17, 2015 20:31
Disable the page search on stream results
diff --git a/h/static/scripts/stream-controller.coffee b/h/static/scripts/stream-controller.coffee
index 1a275a1..ccb4575 100644
--- a/h/static/scripts/stream-controller.coffee
+++ b/h/static/scripts/stream-controller.coffee
@@ -5,26 +5,32 @@ module.exports = class StreamController
this.inject = [
'$scope', '$rootScope', '$routeParams',
'auth', 'queryParser', 'searchFilter', 'store',
- 'streamer', 'streamFilter', 'annotationMapper'
+ 'streamer', 'streamFilter', 'threading', 'annotationMapper'
@tilgovi
tilgovi / highlights-metadata.diff
Created March 11, 2015 20:59
Annotator cross frame highlights metadata
diff --git a/h/static/scripts/annotator/monkey.coffee b/h/static/scripts/annotator/monkey.coffee
index da800da..51c8561 100644
--- a/h/static/scripts/annotator/monkey.coffee
+++ b/h/static/scripts/annotator/monkey.coffee
@@ -9,6 +9,12 @@ Util = Annotator.Util
delete Annotator.prototype.events[".annotator-hl mouseover"]
delete Annotator.prototype.events[".annotator-hl mouseout"]
+# Add createHighlight
+Annotator.prototype.createHighlight = ->
@tilgovi
tilgovi / MyPlugin.js
Created October 15, 2014 23:06
Annotator v1.2.x Plugin Skeleton
function MyPlugin(element, options) {
Annotator.Plugin.call(this, element, options);
// At this point, `this.element` will be a jQuery-wrapped reference to
// the element argument and `this.options` will be a copy of the options
// object (if any) that you define on the prototype with overrides specified
// by the argument to this function. See below for more.
this.options.someObject = {}; // See below.
}
@tilgovi
tilgovi / index.js
Created October 15, 2014 22:25
annotator-storage-oacg
var Annotator = require('annotator');
function dump(data) {
var result = {};
result['@context'] = 'http://www.w3.org/ns/oa-context-20130208.json';
if (typeof(data.id) !== 'undefined') {
result['@id'] = data.id;
@tilgovi
tilgovi / history.coffee
Created September 27, 2014 00:39
iframe history decorator for history in iframes with angular
angular.module('h.history', [
'h.settings'
],
[
'$provide', 'settings'
($provide, settings) ->
if settings.framed
$provide.decorator '$window', captureHistory
$provide.decorator '$sniffer', forceHistory
])
@tilgovi
tilgovi / reject.py
Created September 6, 2014 01:47
Testing FIN and RST behavior in gunicorn
# Log localhost port 8000 in the background
sudo tcpdump -i lo tcp port 8000 > log.txt &
# Send 5 megabytes upload
head -c5M /dev/urandom | curl -v -XPOST -d@- localhost:8000
# End the tcpdump and cat the log file
fg
^C
cat log.txt