Skip to content

Instantly share code, notes, and snippets.

View tobie's full-sized avatar

Tobie Langel tobie

View GitHub Profile
@tobie
tobie / gist:113280d3b3db714dc199
Created July 3, 2014 16:36
Desired priming solution.
this.oninstall = function(e) {
// Create a cache of resources.
var resources = new Cache();
var visited = new Cache();
// Fetch them.
e.waitUntil(resources.add(
"/index.html",
"/fallback.html",
"/css/base.css",
"/js/app.js",
store.match('/api.json').then(function(response) {
return response || store.prime('/api.json');
}).then(asJSON).then(updatePage).catch(displayError);
var ENV_REGEXPS = {};
for (var k in process.env) {
ENV_REGEXPS["[" + k + "]"] = new RegExp(escRegExp(process.env[k]), "g");
}
// Make sure ENV VARS don't accidentally end-up in a log.
// Note this opens up the risk of ENV VARS being
// leaked if known content contains the value of ENV VARS.
var log = kue.Job.prototype.log;
kue.Job.prototype.log = function() {
var str = arguments[0];
@tobie
tobie / bundler.js
Created November 25, 2014 16:28
Checking input file exists and isn't empty before browserifying.
var fs = require("fs");
var browserify = require("browserify");
var through2 = require("through2");
module.exports = function(input, output, callback) {
var inputstream = fs.createReadStream(input).on("error", callback);
var isEmpty = through2(
function (chunk, enc, cb) {
if (this._notEmpty || (/\S/).test(chunk)) this._notEmpty = true;
cb(null, chunk);
# original sentence:
You need to run JS to scrape things off of web pages with client-side logic so now you need Selenium for web scraping.
# what I understood:
"You need to run JS to (scrape things off of web pages with client-side logic) so now you need Selenium for web scraping."
i.e. the scraping needs client side logic
# what retorspecitvely I think you meant
"You need to run JS to scrape things off of (web pages with client-side logic) so now you need Selenium for web scraping."
i.e. the web page has client side logic
@tobie
tobie / gist:ee9f00d6cefc35f104f7
Last active August 29, 2015 14:11
Search term highlighter for well-formed HTML content.
function highlight(str, searchString) {
var regexp = new RegExp("(<[^>]+>)|(" + searchString + ")", "gi");
return (str || "").replace(regexp, function wrap(_, tag, txt) {
if (tag) return tag;
return "<strong class=\"highlight\">" + txt + "</strong>";
});
}
{
"html5": {
"authors": [
"Ian Hickson",
"Robin Berjon",
"Steve Faulkner",
"Travis Leithead",
"Erika Doyle Navara",
"Edward O'Connor",
"Silvia Pfeiffer"
function uniq(sortedArray) {
var output = [];
sortedArray.reduce(function(previous, current) {
if (current != previous) {
output.push(current);
}
return current;
}, null);
return output;
}
@tobie
tobie / _design_xxx.js
Created June 30, 2015 13:45
CouchDB design doc
module.exports = {
_id: "_design/xxx",
views: {
by_date: {
map: function(doc) {
var parts = doc._id.split(":");
emit(parts, { shortname: parts[0], date: parts[1] });
}
},
updates_by_date: {