Skip to content

Instantly share code, notes, and snippets.

Avatar

Benjamin Charity benjamincharity

View GitHub Profile
@benjamincharity
benjamincharity / deletebranch.gitconfig
Last active Jan 8, 2020
Git alias function to delete local AND remote branch(s). NOTE: If dealing with branches that are not fully merged, the `-d` would need to change to `-D`.
View deletebranch.gitconfig
[alias]
deletebranch = "!f() { \
git push origin --delete "$@"; \
git branch -d "$@"; \
}; f"
# usage:
# git deletebranch my-branch
# git deletebranch branch-1 branch-2 branch-3
View strikethrough.js
{
const sheet = window.document.styleSheets[0];
const rule = '.task-list-item-checkbox:checked+.task-list-item-text{opacity:.5;text-decoration:line-through;}';
sheet.insertRule(rule, sheet.cssRules.length);
const listItems = document.querySelectorAll('.task-list-item');
Array.from(listItems).forEach(item => {
const nodes = Array.from(item.childNodes).filter(item => item instanceof Text || item.tagName === "CODE");
const checkbox = item.querySelectorAll('input')[0];
const originalText = nodes.map(node => node.nodeValue || node.textContent).join('').trim();
@benjamincharity
benjamincharity / Local Fallback for jQuery and Modernizr
Created Jan 6, 2012
Include jQuery and Modernizr from a CDN and add local fallbacks in case the CDN fails. Versions written in HTML and HAML.
View Local Fallback for jQuery and Modernizr
HTML
=====
<script type='text/javascript'>
window.jQuery || document.write('<script src="js/jquery-1.7.1.js">\x3C/script>')
</script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.0.6/modernizr.min.js' type='text/javascript'></script>
<script type='text/javascript'>
window.Modernizr || document.write('<script src="js/modernizr-2.0.6.js">\x3C/script>')
</script>
View component.ts
public readonly headerCellResizes: Observable<TsHeaderCellResizeEvent> | Observable<{}> = defer(() => {
if (this.headerCells && this.headerCells.length) {
return merge(...this.headerCells.map(cell => cell.resized));
}
// If there are any subscribers before `ngAfterViewInit`, `headerCells` may be undefined.
// In that case, return a stream that we'll replace with the real one once everything is in place.
return this.ngZone.onStable
.asObservable()
.pipe(take(1), switchMap(() => this.headerCellResizes));
@benjamincharity
benjamincharity / zepto.smoothScroll.js
Last active Oct 4, 2019 — forked from austinpray/zepto.smoothScroll.js
Smooth scrolling with Zepto.js
View zepto.smoothScroll.js
function smoothScroll(el, to, duration) {
if (duration < 0) {
return;
}
var difference = to - $(window).scrollTop();
var perTick = difference / duration * 10;
this.scrollToTimerCache = setTimeout(function() {
if (!isNaN(parseInt(perTick, 10))) {
window.scrollTo(0, $(window).scrollTop() + perTick);
smoothScroll(el, to, duration - 10);
View qeury.ts
public queryStates(query: string): State[] {
query = query.toLowerCase();
if (query) {
const letters = query.split('').map(l => `${l}.*`).join('');
const regex = new RegExp(letters, 'ig');
return this.states.filter(s => !!s.name.match(regex));
} else {
// if no query, return first 10 states
return STATES.slice(0, 10);
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
@benjamincharity
benjamincharity / circle.yml
Last active Apr 23, 2019
CircleCI deploy to NPM
View circle.yml
machine:
node:
version: 6.9.5
dependencies:
pre:
- 'echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc'
test:
override:
- rm -rf $CIRCLE_ARTIFACTS/coverage
View pipe.spec.ts
import { TestBed, inject } from '@angular/core/testing';
import { ConvertStatusPipe } from './convert-status.pipe';
import { ConversationStatus } from '@remedy/models';
import { LoggingService } from '../core/services/logging.service';
import { LoggingServiceMock } from './../core/services/logging.service.mock';
describe(`ConvertStatusPipe`, () => {
let pipe;
@benjamincharity
benjamincharity / gitGrepDirectory.bash
Created Feb 26, 2016
Git grep within a specific sub-directory.
View gitGrepDirectory.bash
# Search for `analytics` only inside `./src/app`
git grep analytics -- "./src/app/*"