Skip to content

Instantly share code, notes, and snippets.

@joeskeen
joeskeen / 2promise.ts
Created February 15, 2016 10:34
Convert an asynchronous function requiring a callback parameter to a promise.
'use strict';
export async function fromNoErrCallback<TResult>(func: Function, thisArg: any, args?: any) {
return toPromise<TResult>(func, thisArg, args, createNoErrCallback);
}
export async function fromErrCallback<TResult>(func: Function, thisArg: any, args?: any) {
return toPromise<TResult>(func, thisArg, args, createErrCallback);
}
@joeskeen
joeskeen / .bashrc
Created April 10, 2018 20:45
My custom shell definition
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\n\[\033[0;92m\]\u@\h\[\033[0m\] \[\033[32m\]\w\[\033[33m\]$(parse_git_branch)\[\033[00m\]\n\[\033[0;96m\]$\[\033[0m\] "
@joeskeen
joeskeen / case.pipe.ts
Last active March 27, 2019 19:07
Angular pipe for changing to any case (esp. not those included in @angular/common)
import { PipeTransform, Pipe } from '@angular/core';
import * as changeCase from 'change-case';
type TransformFn = (val: string) => string;
@Pipe({ name: 'joeCase', pure: true })
export class CasePipe implements PipeTransform {
/**
* changes the case of a value
* @param value the value to change the case of
@joeskeen
joeskeen / gist:f27c22e5ec179c8773237049ac1a6aac
Created July 12, 2019 15:11
Trying to get Git LFS to work with Azure Repos
joeskeen@DESKTOP /mnt/c/code/sandbox/bug-repro
$ git clone git@ssh.dev.azure.com:v3/joeskeen/Test%20Project/With%20File%20Size%20Restriction
Cloning into 'With%20File%20Size%20Restriction'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
joeskeen@DESKTOP /mnt/c/code/sandbox/bug-repro
$ git clone git@ssh.dev.azure.com:v3/joeskeen/Test%20Project/Without%20File%20Size%20Restriction
Cloning into 'Without%20File%20Size%20Restriction'...
warning: You appear to have cloned an empty repository.
/**
* Returns whether the given value is an integer
* @param value the value to test
* @returns whether the value is an integer
*/
export function isInteger(value) {
return Math.floor(value) == value;
}
@joeskeen
joeskeen / is-integer.spec.js
Created September 16, 2019 16:34
a sample specification for a function that determines whether a given value is an integer
describe('isInteger', () => {
describe('when provided an integer value', () => {
it('should classify 5 as an integer');
it('should classify -5 as an integer');
it('should classify 0 as an integer');
});
describe('when provided a numerical value that is not an integer', () => {
it('should classify 3.14 as not an integer');
it('should classify -3.14 as not an integer');
it('should classify NaN as not an integer');
@joeskeen
joeskeen / is-palindrome.spec.ts
Created September 16, 2019 18:37
a sample spec file for an isPalindrome function
describe('isPalindrome', () => {
describe('when provided a palindrome', () => {
describe('consisting of letters', () => {
it('should classify `"racecar"` as a palindrome');
describe('ignoring case', () => {
it('should classify `"Racecar"` as a palindrome');
});
describe('ignoring spaces', () => {
it('should classify `"taco cat"` as a palindrome');
});
import { Injectable } from '@angular/core';
import { LocalStorage } from '@ngx-pwa/local-storage';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
@Injectable()
export class PreferencesService {
constructor(private localStorage: LocalStorage) {
}
@joeskeen
joeskeen / preferences.service.spec.ts
Created October 1, 2019 23:14
A sample spec demonstrating Arrange, Act, Assert
describe('PreferencesService', () => {
describe('.getPreference', () => {
it('should call getItem from LocalStorage', () => {
// Arrange: initialize spy and test subject
const getItemSpy = jasmine.createSpy('getItem');
const service = new PreferencesService({ getItem: getItemSpy } as LocalStorage);
// Act: call getPreference
service.getPreference('test key');
@joeskeen
joeskeen / preferences.service.spec.ts
Created October 1, 2019 23:17
A sample spec using a beforeEach block
describe('PreferencesService', () => {
describe('.getPreference', () => {
let service: PreferencesService;
let testValue: Observable<string>;
let result: Observable<string>;
let getItemSpy: jasmine.Spy;
beforeEach(() => {
testValue = scheduled(['test value'], asapScheduler);
getItemSpy = jasmine.createSpy('getItem').and.returnValue(testValue);