Skip to content

Instantly share code, notes, and snippets.

Benjamin Charity benjamincharity

Block or report user

Report or block benjamincharity

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
@benjamincharity
benjamincharity / app-version.component.ts
Last active Dec 4, 2017
From: https://stackoverflow.com/a/41299263/722367 It's worth to mentioned that if someone encounter on error "Cannot find name require" after applying your solution then needs to add "node" type inside "types" property in tsconfig.app.ts file. << "types": ["node"] >>.
View app-version.component.ts
const { version: appVersion } = require('../../package.json')
// this loads package.json
// then you destructure that object and take out the 'version' property from it
// and finally with ': appVersion' you rename it to const appVersion
@Component({
selector: 'stack-overflow',
templateUrl: './stack-overflow.component.html'
})
export class StackOverflowComponent {
View tslint.json
{
"rulesDirectory": [
"node_modules/codelyzer"
],
"rules": {
"angular-whitespace": [
true,
"check-interpolation"
],
"arrow-parens": true,
View stylelintrc.json
{
"rules": {
"at-rule-name-space-after": "always",
"at-rule-semicolon-space-before": "never",
"at-rule-semicolon-newline-after": "always",
"at-rule-no-vendor-prefix": true,
"block-no-empty": true,
"block-closing-brace-newline-after": [
"always",
"ignoreAtRules": [
View fix.sh
yarn remove karma-sauce-launcher
yarn add -D --exact karma-sauce-launcher
@benjamincharity
benjamincharity / 1.0.1-output.sh
Last active Nov 1, 2017
Docs working on `1.0.1`, not working on `1.0.2`
View 1.0.1-output.sh
➜ my-app git:(fix-link-style-inheritence) ✗ yr docs
yarn run v1.2.1
$ yarn run docs:toc
DocToccing single file "./README.md" for github.com.
==================
"./README.md" will be updated
@benjamincharity
benjamincharity / WindowService.ts
Created Aug 28, 2017
A window service that exposes the native window object AND the width/height of the window as an Observable.
View WindowService.ts
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import 'rxjs/add/operator/distinctUntilChanged';
import 'rxjs/add/operator/pluck';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/observable/fromEvent';
export interface WindowSize {
@benjamincharity
benjamincharity / CreateGuid.ts
Created Aug 10, 2017
A TypeScript class that generates a guid
View CreateGuid.ts
// http://stackoverflow.com/questions/26501688/a-typescript-guid-class
class Guid {
static newGuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0, v = c === 'x' ? r : ( r & 0x3 | 0x8 );
return v.toString(16);
});
}
}
@benjamincharity
benjamincharity / linesperauthor.gitconfig
Created Aug 9, 2017
Git alias function to show how many lines were authored by each contributor.
View linesperauthor.gitconfig
[alias]
linesperauthor = "!f() { \
git ls-files | while read f; do git blame --line-porcelain $f | grep '^author '; done | sort -f | uniq -ic | sort -n; \
}; f"
# usage:
# git linesperauthor
# output:
@benjamincharity
benjamincharity / deletebranch.gitconfig
Last active Mar 28, 2018
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
@benjamincharity
benjamincharity / theme-base.component.ts
Created Aug 7, 2017
Create a base class that will set a theme class on the component.
View theme-base.component.ts
import {
Component,
Input,
ElementRef,
} from '@angular/core';
import { TsStyleThemeTypes } from './../types/style-theme.types';
/**
You can’t perform that action at this time.