Skip to content

Instantly share code, notes, and snippets.

View klipstein's full-sized avatar

Tobias von Klipstein klipstein

  • glomex GmbH
  • Augsburg, Germany
View GitHub Profile
@klipstein
klipstein / get-url.js
Last active January 10, 2020 12:11
Get top-most URL from within an iFrame. It either uses the referrer or the current location.
export default getUrl;
function getUrl(window) {
const topMostWindow = getTopMostIframeWithReferrer(window);
const { referrer } = topMostWindow.document;
if (!isInIframe(window)) return window.location.href;
// in Firefox it won't fill the referrer for friendly iframes
if (referrer === '' && isParentFrameFriendly(topMostWindow)) {
@klipstein
klipstein / index.js
Created July 8, 2016 13:05
requirebin sketch
var uniqid = require('uniqid');
document.body.innerHTML = uniqid();
@klipstein
klipstein / dependency-injection-idea.js
Last active August 29, 2015 14:19
Dependency injection idea
function createFactory() {
var args = [].slice.call(arguments);
var createFunc = args.pop();
return function() {
if (arguments.length > 0) {
return createFunc.apply(null, arguments);
} else {
return createFunc.apply(null, args);
}
};
@klipstein
klipstein / index.js
Created September 22, 2014 21:51
requirebin sketch
// hello world
var lodash = require('lodash');
console.log(lodash);
@klipstein
klipstein / android23_autoplay.js
Created November 25, 2013 14:21
Video autoplay on Android 2.3 stock browser
// Embed that snippet on your site to rick-roll every Android 2.3 user
// by opening a video in fullscreen without asking for user permission
var v = document.createElement('video');
v.src = 'http://vid297.photobucket.com/albums/mm238/daystar170/RickRoll.mp4';
v.load();
document.body.appendChild(v);
setTimeout(function() {
// jumping to a certain position is also possible
// v.currentTime = 0;
v.play();
@klipstein
klipstein / opera_worker_bug2.html
Created February 2, 2013 17:13
Webworker Bug in Opera with importScripts (2)
<html>
<head>
<title>Using importScripts in a file which was imported via importScripts prevents loading following scripts.</title>
<script>
var worker = new Worker('worker_bug2.js');
var callCount = 0;
worker.addEventListener('message', function() {
callCount++;
}, false);
setTimeout(function() {
@klipstein
klipstein / opera_worker_bug1.html
Last active December 12, 2015 02:19
Webworker Bug in Opera with importScripts (1)
<html>
<head>
<title>Loading an empty JS-file within worker#importScripts prevents loading following requests</title>
<script>
var worker = new Worker('worker_bug1.js');
var callCount = 0;
worker.addEventListener('message', function() {
callCount++;
}, false);
setTimeout(function() {
@klipstein
klipstein / foo-spec.js
Created November 5, 2012 21:44
Execute Jasmine Tests within BonsaiJS runner context
require([], function() {
describe('bar', function() {
// ...
});
});
@klipstein
klipstein / blob_worker.js
Created October 2, 2012 16:59
Spawning Worker using Blob
var b = new Blob();
var u = window.URL.createObjectURL(b);
var w = new Worker(u); // throws Security Error in IE 10
@klipstein
klipstein / b64field.py
Created November 22, 2010 12:25
Base64 file handling for django-tastypie
import base64
import os
from tastypie.fields import FileField
from django.core.files.uploadedfile import SimpleUploadedFile
class Base64FileField(FileField):
"""
A django-tastypie field for handling file-uploads through raw post data.
It uses base64 for en-/decoding the contents of the file.
Usage: