Skip to content

Instantly share code, notes, and snippets.

View johan's full-sized avatar

Johan Sundström johan

View GitHub Profile
@johan
johan / Svenska Akademien.svg
Last active September 17, 2015 18:53
Svenska Akademien + SAOB
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@johan
johan / README.md
Last active September 18, 2015 02:55
git rsif

git rsif

Usage

git rsif 'REPLACE-FROM' 'REPLACE-WITH'

Background

@johan
johan / GM_queryContentVar.js
Created September 27, 2010 05:01
Lets a GM script safely read variables from the content scope (untested)
// Query page javascript for the identifier "name", and call callback(value),
// when found, or undefined, if not found or some error occurred. This works
// only for values that can be JSON serialized -- numbers, strings, booleans,
// null, or nested structures like Arrays and Objects that only contain above
// mentioned types of data.
function queryContentVar(name, callback) {
// makes a random 20-char lowercase id
function random() {
var rand = '';
while (rand.length < 20)
@johan
johan / README.md
Last active September 24, 2015 05:23
Portal Signs

I just want the stickers. :-) (Original)

@johan
johan / README.md
Created September 24, 2015 20:54
getXPathTo / getRootXPathTo

I was looking for two clean, tiny and elegant element-to-xpath functions producing short and complete xpaths like id("main")/ul/li[3] or /html/body/ul/li[3] for a given element, and figured I'd just craft my own.

@johan
johan / grep-count.pl
Created March 26, 2011 10:25
Like fgrep / egrep (symlink it as egrep-count to regexp match by default), but for more than one pattern at a time, generating tsv output, and where you list all the patterns and what you want the count columns to be named as a JSON object on stdin.
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
use File::Basename;
use JSON;
use utf8;
my $prog = basename($0);
@johan
johan / gravatar.rb
Created April 3, 2011 09:01
Takes a list of email addresses (or files with email addresses) and lists gravatars for them, if set.
#! /usr/bin/ruby
require 'digest/md5'
require 'net/http'
require 'uri'
$unknown_gravatar = 'd5fe5cbcc31cff5f8ac010db72eb000c'
$email_addr_regex = /[^\[{(< @"']+@[^\]})> @"']+\.[^\]})> @"']+/
def md5(str)
@johan
johan / google-closure-library.js
Created May 22, 2011 03:09
Google Closure Library loader bookmarklet
// Enumerate your own list of goog.require:s, if you want something else than TableSorter and XhrIo.
// Similarly, you can pass a callback that will get the library in its first parameter, once loaded,
// or leave it as is, if you'd rather overwrite the top window's "goog" with your own custom version.
javascript:(function(requires, callback) {
var base = 'http://closure-library.googlecode.com/svn/trunk/closure/goog/'
, iframe = document.body.appendChild(document.createElement('iframe'));
iframe.src = 'about:blank';
iframe.style.display = 'none';
iframe.contentWindow.cb = callback;
iframe.contentDocument.write('<head><script src="'+ base +'base.js"></script><script src="'+ base +
@johan
johan / draw-svg.js
Created June 4, 2011 10:18
Draw an SVG bit by bit
var steps = 0 // steps drawn on the current element, so far
, info = document.getElementById('next_step')
, svgs = [].slice.call(document.getElementsByTagName('svg'))
, svg, walker, current;
function lexSVGPath(d) {
function command(seg) {
var cmd = seg.match(/[a-z]/i), arg, cnt;
if (cmd) {
cmd = cmd[0]; // which subcommand
@johan
johan / github-logo.svg
Created June 4, 2011 11:15
Github social coding logo, minimal SVG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.