Skip to content

Instantly share code, notes, and snippets.

View tomayac's full-sized avatar

Thomas Steiner tomayac

View GitHub Profile
@tomayac
tomayac / lucky-winner.js
Created May 29, 2015 12:41
Highlights a lucky random attendant who RSVP'ed to a meetup organized via www.meetup.com
// Test at http://www.meetup.com/Google-Developer-Group-Hamburg/events/222392017/
document.querySelector('#rsvp-list').querySelectorAll('li')
[
Math.floor(
Math.random() *
document.querySelector('#rsvp-list').querySelectorAll('li').length
) + 1
].style.backgroundColor =
'rgb(' +
(Math.floor(Math.random() * 256)) + ',' +

Keybase proof

I hereby claim:

  • I am tomayac on github.
  • I am tomayac (https://keybase.io/tomayac) on keybase.
  • I have a public key whose fingerprint is 6897 81EF 64CF F41E 7497 C1B4 5A9B C2AC 857C 0A63

To claim this, I am signing this object:

@tomayac
tomayac / avgWikipediaDeltas.js
Created November 25, 2014 08:20
Average Edit Length (Delta) for Wikipedias by Language
// Full source
var source = new EventSource('http://wikipedia-edits.herokuapp.com/sse');
var languages = {};
var avgDeltas = {};
source.addEventListener('message', function(e) {
var edit = JSON.parse(e.data);
if (!languages[edit.language]) {
languages[edit.language] = [];
}
@tomayac
tomayac / remoteStorage_adWordsScripts.js
Last active October 29, 2019 12:37
Remote Storage for AdWords Scripts
/**
* @author Thomas Steiner (tomac@google.com)
* @license CC0 1.0 Universal (CC0 1.0)
*
* Provides a simple key-value storage API modeled closely after
* the localStorage API in Web browsers, but tailored to AdWords Scripts.
* AdWords Scripts, due to execution time limits published at
* https://developers.google.com/adwords/scripts/docs/limits,
* forces users to store the state of a given script using either labels
* (https://developers.google.com/adwords/scripts/docs/tips#labels), or
@tomayac
tomayac / gist:c2358b1cbee764b679e9
Last active August 29, 2015 14:06
TwitPic backup script
// Browse through your photo collection page-by-page,
// each time pasting the script in the console.
// Then save images one-by-one, or just "Save as" > "Web page complete".
// The alt attribute contains the original tweet text.
// License: CC0. Author: Thomas Steiner (tomayac).
var images = [];
Array.prototype.forEach.call(document.querySelectorAll('div[class~="user-photo"] a img'), function(img, i) {
img.src = /.*?\/thumb\/.*?/g.test(img.src) ? img.src.replace('/thumb/', '/large/') : img.src;
images[i] = '<img src="' + img.src + '" alt="' + img.alt.replace(/"/g, '&quot;')+ '"/>';
});
@tomayac
tomayac / barcelona.js
Last active December 16, 2015 21:59
Sample app created for Barcelona.js
var irc = require('irc');
var request = require('request');
var express = require('express');
var http = require('http');
var app = express();
var server = http.createServer(app);
// IRC details for the recent changes live updates
var IRC_SERVER = 'irc.wikimedia.org';
var IRC_NICK = 'YOUR_APP_NAME_HERE';
@tomayac
tomayac / getUserMedia.html
Created December 6, 2011 16:44
navigator.getUserMedia Test
<html>
<head>
<title>navigator.getUserMedia() Demo</title>
</head>
<body>
<h1>See yourself?</h1>
If your browser supports
<span style="font-family:monospace;">navigator.getUserMedia()</span>
you should see yourself below. If you don't see yourself, try
downloading the
@tomayac
tomayac / gist:1205635
Created September 9, 2011 06:48
POST to DBpedia Spotlight
# This is what I try:
curl -i -X POST -d "text=dbpedia+spotlight+is+neat.&confidence=0.2&support=10" -H "Accept:application/json" -H "Content-Type:application/x-www-form-urlencoded" http://spotlight.dbpedia.org/rest/annotate
# This is what I get:
HTTP/1.1 415 Unsupported Media Type
Date: Fri, 09 Sep 2011 06:46:25 GMT
Transfer-Encoding: chunked
Content-Type: text/plain
# What is the correct "Content-Type" header if not "application/x-www-form-urlencoded"?
@tomayac
tomayac / content_script.js
Created April 18, 2011 14:46
The core "magic" of the Creative Commons Laser Highlighter Chrome extension (https://chrome.google.com/extensions/detail/iceopjodmdipccjbknbjolkfogkgloei)
// namespaced my implementation of the RDFa
// API using "LinkedData.API" to avoid confusion
// with real (and correcter) implementations.
LinkedData.API.data.setMapping(
'cc',
'http://creativecommons.org/ns#');
// capture @rel="license"...
var licensedElements = LinkedData.API.getElementsByProperty('license');
// ...and @rel="cc:license"