Skip to content

Instantly share code, notes, and snippets.

View davidrleonard's full-sized avatar

David Leonard davidrleonard

View GitHub Profile
@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
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 / 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'})) {
@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 / 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 / build-css.js
Created July 14, 2017 16:45
Sass->CSS build task that can be run as an npm script (not done)
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const glob = require('glob');
const sass = require('node-sass');
const importOnce = require('node-sass-import-once');
const postcss = require('postcss');
const autoprefixer = require('autoprefixer');
const cssmin = require('clean-css');
@davidrleonard
davidrleonard / node-crawling-utils.js
Last active September 1, 2017 17:44
Node utility functions for crawling files (for when you want to check a bunch of repos without bash)
/*
* Run in a directory with a bunch of subdirectories.
*
* Example: Get all subdirectories with names ending in '-design'
*
* ```
* const subdirs = getDirectories(__dirname).filter(isMatch.bind(null, /\-design$/));
* ```
*
* Example: Get all subdirectories that have any subfiles named *.es6.js
loader: 'vue-loader',
options: {
extractCSS: true,
loaders: {
sass: 'vue-style-loader!css-loader!sass-loader?'+
'{"includePaths":["bower_components"]}'
}
}
@davidrleonard
davidrleonard / addtoken.sh
Last active October 5, 2017 17:16
Add your Github token to existing remotes
## If you have to create a Github access token (e.g. if you enabled two-factor auth for the same time)
## and you used https:// formatted git remotes for all your local repos, you won't be able to push
## or pull anymore. This allows you to fix all your remotes whenever you need to with a simple
## bash alias.
##
## Put this in your ~/.bash_profile or ~/.zsh_profile, then run `$ fixremote` in a repo directory
## to fix it.
##
## P.S. You should use SSH remotes for your Github repos. But if you're behind a corporate proxy
## that messes up SSH to the public internet, you can't... :(