Skip to content

Instantly share code, notes, and snippets.

View davidrleonard's full-sized avatar

David Leonard davidrleonard

View GitHub Profile
@davidrleonard
davidrleonard / hi.sh
Last active June 13, 2017 23:52
Opens 10 browser windows that say "Hi Kate"
if [ ! -f ~/.hi.html ]; then echo '<title>Hi Kate</title><h1>Hi Kate</h1>' > ~/.hi.html; fi && echo 'Opening gulp or whatever...' && for ((n=0;n<10;n++)); do open -a 'Google Chrome' ~/.hi.html; done
@davidrleonard
davidrleonard / stealing-an-icon.js
Last active May 25, 2017 17:13
Get an icon's source SVG from Polymer `iron-iconset-svg`
// You need to have already loaded an `iron-iconset-svg` tag on the page
var iconDb = Polymer.Base.create('iron-meta', {type:'iconset'});
var pxIconSet = iconDb.byKey('px');
var airplaneIconSvg = pxIconSet._cloneIcon('aircraft', false); // ... `airplaneIconSvg` now has an `<svg>` node with the icon.
@davidrleonard
davidrleonard / test-analyzer.js
Created May 16, 2017 18:50
Simple polymer analyzer example
const {Analyzer, FSUrlLoader} = require('polymer-analyzer');
let analyzer = new Analyzer({
urlLoader: new FSUrlLoader('./'),
});
analyzer.analyze(['px-app-nav.html'])
.then((document) => {
const els = [];
for (const element of document.getFeatures({kind: 'element'})) {
function callFnOnListInFrames(scope, list, fn, args) {
return new Promise(function(resolve, reject) {
args = args || [];
// var start = performance.now();
var workInd = 0;
var results = [];
var start;
var elapsed;
function _workInOneFrame(now) {
@davidrleonard
davidrleonard / git_replace.sh
Created March 31, 2017 17:43
Bash function to replace your Github HTTP remotes with a new password/access token
# Updates your git remote named `origin` with a new password if you're authenticating
# using basic auth (and not SSH). E.g. if you work for a corporatin with a proxy that
# murders your attempt to connect over SSH.
#
# How to use:
#
# 1. Put the function in your ~/.bash_profile or ~/.zshrc
# 2. Replace old_access_pass with your old password/access token and new_access_pass with your new password/access token
# 3. Run `fixremote` in any repo folder when your git push or pull fails
@davidrleonard
davidrleonard / 1-repeat-markers.html
Last active March 27, 2017 17:43
Create px-map markers with a dom-bind and dom-repeat
<!--
In this example, we use a template dom-repeat to insert multiple markers into a map
from an array of simple objects. This is a way to use markers and other components
without feeding in a complex blob of GeoJSON.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<title>Map 1 Demo -- Simple Map</title>
@davidrleonard
davidrleonard / distribute-properties.js
Created March 1, 2017 18:50
Polymer behavior to distribute properties on lazily added Light DOM children
/**
* When light DOM children are distributed into a `px-map` framework component,
* that component will often have to share a reference to one of its properties
* with the child. This behavior wraps around that use case, ensuring that
* properties will be applied to any distributed light DOM children and that
* changes to those properties on the parent will trigger a re-distribution
* to the children that keeps them up-to-date.
*
* Distributions should be configured in the component's Polymer constructor
* in a similar way to the `observers` block provided by the Polymer library.
@davidrleonard
davidrleonard / execAsync.js
Last active November 29, 2022 03:42
Node exec async (with shell.js and bluebird)
const Promise = require('bluebird');
const sh = require('shelljs');
/**
* Asynchronously executes a shell command and returns a promise that resolves
* with the result.
*
* The `opts` object will be passed to shelljs's `exec()` and then to Node's native
* `child_process.exec()`. The most commonly used opts properties are:
*
@davidrleonard
davidrleonard / 1-steps.md
Last active December 8, 2016 00:53
Upgrade Px element to Polymer 2.0

Step-by-step upgrade from Polymer 1.6 -> 2.0

Before you start

  1. Install Polymer/polymer#2.0-preview bower package and webcomponents/webcomponentsjs#v1 bower package
$ bower install --save Polymer/polymer#2.0-preview
$ bower install --save webcomponents/webcomponentsjs#v1