Skip to content

Instantly share code, notes, and snippets.

View filipbech's full-sized avatar

Filip Bech-Larsen filipbech

View GitHub Profile
@filipbech
filipbech / uBookmarklet.js
Last active August 14, 2020 12:09
POC Umbraco edit bookmarklet
/*
Install from here: https://codepen.io/filipbech/full/RwarLVL
Before this becomes external, we should probably make the bookmarklet a loader and have the
source somewhere remote, so we can update it withot people having to re-install
*/
(async () => {
const pageIdMetaTag = document.querySelector('meta[name=umb-page-id]');
self.addEventLister('fetch', event => {
if (event.request.url === 'app.js') {
event.respondWith(caches.match(new Request(event.request.url, {
mode: 'cors',
credentials: 'omit'
})
}
});
@filipbech
filipbech / sw.js
Last active March 15, 2018 10:49
Caching ES modules
const moduleRequests = ['app.js', 'module1.js']
.map(url => new Request(url, {
mode: 'cors',
credentials: 'omit'
}));
cache.addAll([
'index.html',
...moduleRequests
]);
@filipbech
filipbech / index.html
Created March 7, 2018 19:28
element-router
<element-router>
<element-route path="/" element="home-page"></element-route>
<element-route path="/product/:uid" element="product-page"></element-route>
<element-route path="/lazy" import="lazy-element.js" element="lazy-element"></element-route>
<element-route path="/no-element">
<template>
<style>h1 { color:red; }</style>
<h1>Yo this is an inline-template</h1>
</template>
</element-route>
@filipbech
filipbech / dynamic.ts
Created October 25, 2017 17:33
More dynamic example
@Component({ ... })
class ExampleComponent {
static name = 'Some arbitrary name';
}
/*list of componentClasses that should be available this way*/
const allComponents = [ ExampleComponent, /*more...*/ ];
@Component({
template:`
@filipbech
filipbech / bulb.js
Created October 6, 2016 18:12
Playing around with an BLE LED bulb and web-bluetooth
const serviceId = 0xffe5;
const characteristicId = 0xffe9;
const btn = document.getElementById('btn');
const form = document.forms[0];
let bulb;
document.getElementById('random').addEventListener('click',()=> {
setInterval(()=> {
bulb.writeValue(getColorValue(Math.ceil(Math.random()*255), Math.ceil(Math.random()*255), Math.ceil(Math.random()*255)));
@filipbech
filipbech / fetch POST like jQuery.js
Last active August 23, 2016 06:30
Using the native fetch-api to send POST-request encoded like jQuery.ajax does it.
fetch('/endpoint', {
method: 'POST',
headers: new Headers({
'Content-Type': 'application/x-www-form-urlencoded'
}),
body: serialize({
value: 1,
nested: {
value: '2'
}
@filipbech
filipbech / $Ohttp.js
Created June 17, 2016 12:13
$Ohttp - Simple wrapper (with cancellation) for using observables for http in Angular 1 today...
angular.module('$Ohttp',[]).factory('$Ohttp', function($http, $q) {
var $Ohttp = function(settings) {
var defer = $q.defer();
return Rx.Observable.create(function(observer) {
$http(angular.extend(settings,{
timeout:defer.promise
})).then(function(response) {
observer.next(response);
observer.complete();
},function(err) {
@filipbech
filipbech / snap-gsap
Last active August 10, 2018 00:38
Running snap.svg animations with GSAP
/* Define the animation with snap.svg*/
var mySnapAni = myPath.animate({
d:newDValue
},200); /* duration:200 doensn't matter since playback is via GSAP */
/* Get the animation controller */
var mySnapAniCtrl = mySnapAni[0].anims[Object.keys(mySnapAni[0].anims)[0]];
/* Pause the animation right away*/
mySnapAniCtrl.pause();
@filipbech
filipbech / gist:51077b076aa3f330e735
Last active September 22, 2015 08:24
Htaccess+php stuff for api redirect (for local development without xss issues)
.htaccess
RewriteEngine on
RewriteRule ^umbraco/(.+?)$ umbraco.php?url=$1 [QSA,L]
## Nedenstående er til spa-ting
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]