Skip to content

Instantly share code, notes, and snippets.

Clayton Watts cletusw

Block or report user

Report or block cletusw

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cletusw
cletusw / git-sync-ship.sh
Created Sep 14, 2017
Git aliases for an easier rebase workflow
View git-sync-ship.sh
git config --global alias.sync '!f() { echo "$(tput setaf 4)Syncing this branch with origin master$(tput sgr 0)" && git fetch origin master && git rebase origin/master && echo "$(tput setaf 2)Branch sync successful$(tput sgr 0)"; }; f'
git config --global alias.ship '!f() { BRANCH=$(git symbolic-ref --short HEAD) && MERGE_BASE=$(git merge-base origin/master HEAD) && NUM_COMMITS=$(git rev-list --count $MERGE_BASE..) && git log --oneline --stat $MERGE_BASE.. && read -p "$(tput setaf 4)Are you sure you want to ship $(tput bold)$NUM_COMMITS$(tput sgr 0)$(tput setaf 4) commits to $(tput bold)master$(tput sgr 0)? [Y/n] " response </dev/tty && case $response in [yY][eE][sS]|[yY]|"") echo "$(tput setaf 4)Shipping branch $(tput bold)$BRANCH$(tput sgr 0)" ;; *) echo "$(tput setaf 1)Ship aborted by user$(tput sgr 0)"; return 1 ;; esac && git checkout master && (git merge --ff-only - || (echo "$(tput setaf 1)Could not merge branch into local master\nRun git sync before running this command\nIf this error persists, you ha
@cletusw
cletusw / angular-injection-to-import.js
Last active May 16, 2019
Converts the given angular injected parameter into an explicit require statement
View angular-injection-to-import.js
/*
* Converts the given angular injected parameter into an explicit require statement
*
* Run this with jscodeshift
* @example
* jscodeshift . --specifier='Auth' --source='application/Auth'
*
* Live demo: https://astexplorer.net/#/gist/5492d2b9850a451d8e8d532bc64f21ce/latest
*
* Converts:
@cletusw
cletusw / each-with-context-to-bind.js
Created Aug 17, 2017
Converts underscore/lodash `.each()` with context to use Function.prototype.bind()
View each-with-context-to-bind.js
/**
* Converts underscore/lodash `.each()` with context to use Function.prototype.bind()
*
* Run this with jscodeshift
* Live demo: https://astexplorer.net/#/gist/b4294e95ef898af1d19cd3db19f9e8b0/latest
*
* Converts:
* _.each(array, function(item) {
* // ...
* }, context);
@cletusw
cletusw / each-with-this-to-arrows.js
Last active Aug 17, 2017
Converts underscore/lodash `.each()` with `this` context to use arrow functions.
View each-with-this-to-arrows.js
/**
* Converts underscore/lodash `.each()` with `this` context to use arrow functions.
*
* Run this with jscodeshift
* Live demo: https://astexplorer.net/#/gist/0a47495d69719449d2afbb0f0c50f8ea/latest
*
* Converts:
* _.each(array, function(item) {
* // ...
* }, this);
@cletusw
cletusw / amd-to-common.js
Created Aug 16, 2017
A codemod to transform amd style includes into commonjs includes
View amd-to-common.js
/**
* Modified from https://github.com/skratchdot/amd-to-commonjs-codemod
*/
const buildRequire = (j, v, r) => {
let code = "";
if (v && v.type === "Identifier" && v.name.length) {
code += `const ${v.name}`;
}
if (r && r.type === "Literal" && r.value.length) {
@cletusw
cletusw / remove-top-use-strict.js
Last active Aug 16, 2017
Remove top-level `"use strict";`. It can cause problems with bundlers that concatenate scripts, and so is not a recommended practice.
View remove-top-use-strict.js
module.exports = function transformer(file, api) {
const j = api.jscodeshift;
return j(file.source)
.find(j.ExpressionStatement).filter(path => (
path.parentPath.node.type === "Program" &&
path.value.expression.type === 'Literal' &&
path.value.expression.value === 'use strict'
))
.forEach(path => j(path).remove())
@cletusw
cletusw / almost-amd-to-commonjs.js
Last active Aug 16, 2017
Codemod: AMD in CommonJS style -> CommonJS
View almost-amd-to-commonjs.js
/**
* Run this with jscodeshift
* Live demo: https://astexplorer.net/#/gist/3aec6fa8858f3ec0e0a82ab5ec4ad32d/latest
*
* Converts:
* define(function (require) {
* var React = require('react');
* const props = { foo: 'bar' };
* return React.createClass(props);
* });
@cletusw
cletusw / html-webpack-header-loader.js
Last active Jul 14, 2017
Add javascript to be added to the webpack-built JS file directly in your HTML (for declaring dependencies, etc.)
View html-webpack-header-loader.js
/*
Usage:
// template.html
<script type="text/javascript-webpack-header">
console.log('loaded template');
require('./nested.js');
</script>
<h1>This is the template</h1>
View test
http://sjc-uhls-proxy116.ustream.tv/watch/playlist.m3u8?cid=9408562&appType=11&appVersion=2&locks=97d170e1550eee4afc0af065b78cda302a97674c&geo=US&geocity=Riverton&userId=&connectionId=sjc-flot-omega02_5962147&ts=1474908924&ip=50.207.240.162&cdn=uhs_akamai&sgn=d94ad210a8701db5c72f0924bb0df4f7179b8df3
View My Git config
apply.whitespace fix
core.whitespace 'space-before-tab,-indent-with-non-tab,trailing-space'
core.ignorecase true
diff.renames copies
merge.ff only
merge.conflictstyle diff3
pull.ff only
push.default upstream
push.followTags true
rerere.enabled 1
You can’t perform that action at this time.