Skip to content

Instantly share code, notes, and snippets.

View klebba's full-sized avatar

Casey klebba

View GitHub Profile
@klebba
klebba / x-pages.js
Last active July 23, 2020 02:03
x-element / potential bug
import XElement from '../@netflix/x-element/x-element.js';
export default class XPages extends XElement {
static get properties() {
return {
current: {
type: String,
reflect: true,
},
items: {
@klebba
klebba / router.js
Last active November 15, 2018 00:28
A primitive pushState router
export default class Router {
static init(routes, wildcard) {
Object.defineProperty(this, 'routes', {
value: routes,
writable: false,
});
Object.defineProperty(this, 'patterns', {
value: this.build(routes),
writable: false,
});
@klebba
klebba / gist:64be7526f0b2c5f17af6
Last active January 7, 2018 20:07
keybase.md
### Keybase proof
I hereby claim:
* I am klebba on github.
* I am klebba (https://keybase.io/klebba) on keybase.
* I have a public key ASD6FN0tTME_UAZyWUjnobSCici__ULNRou_PdZAZurOXgo
To claim this, I am signing this object:
@klebba
klebba / google-analytics.html
Created November 2, 2014 20:14
Google Analytics + Polymer web component
<link rel="import" href="/bower_components/polymer/polymer.html">
<polymer-element name="google-analytics" attributes="account domain">
<script>
// Google Analytics snippet
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
var randomRGBA: function(alpha) {
var r = function () { return Math.floor(Math.random()*256); );
var a = alpha || 1;
return 'rgba(' + r() + ',' + r() + ',' + r() + ',' + a + ')';
}
@klebba
klebba / gist:6313636
Created August 22, 2013 22:33
Transparently intercept requests for templates that are known to rails and rewrite the URL
angular.module('templates', []).config(['$httpProvider', function($httpProvider) {
/* Injector to rewrite template filenames like template.html to
rails asset paths like /assets/template-0def1e14f3772cda8a0110f73fb6beb1.html */
$httpProvider.interceptors.push(['$cacheFactory', '$sce', function($cacheFactory, $sce) {
var cache = $cacheFactory('templatesMap');
/* Rails derives this list automatically */
// <% Dir.glob(Rails.root.join('app','assets','templates', '*.html')).each do |f| file = File.basename(f) %>
cache.put('<%= file %>', '<%= asset_path file %>');
// <% end %>
return {
@klebba
klebba / gist:6302016
Created August 22, 2013 00:46
Angular animation service (tested with 1.1.5, breaks in 1.2.0rc1)
(function() {
'use strict';
var app = angular.module('App');
/**
* Provide a means for hooking into view animation events
*/
app.factory('transitionService', [function() {