Skip to content

Instantly share code, notes, and snippets.

View kenhowardpdx's full-sized avatar

Ken Howard kenhowardpdx

View GitHub Profile
@kenhowardpdx
kenhowardpdx / shopping-list.ts
Last active February 19, 2018 22:43
Type-Safe JavaScript w/ TypeScript
var shoppingList = {
items: {},
addItem: function (item:string, qty:number) {
if (typeof item === 'string' && typeof qty === 'number') {
item = item.trim(); // clean this up a bit
qty = item[item] ? item[item] + qty : qty; // calc qty
this.items[item] = qty;
console.log(`Added ${this.items[this.items.length - 1]}`);
} else {
@kenhowardpdx
kenhowardpdx / shopping-list.js
Last active June 8, 2017 20:16
Type-Safe JavaScript (No Safety)
var shoppingList = {
items: {},
addItem: function (item, qty) {
item = item.trim(); // clean this up a bit
qty = item[item] ? item[item] + qty : qty; // calc qty
this.items[item] = qty;
}
}
@kenhowardpdx
kenhowardpdx / shopping-list.js
Last active September 12, 2017 20:39
Type-Safe JavaScript
var shoppingList = {
items: [],
addItem: function (item, qty) {
if (typeof item === 'string' && typeof qty === 'number') {
this.items.push(`${qty} ${item}`);
console.log(`Added ${this.items[this.items.length - 1]}`);
} else {
// throw exception
console.error('Invalid parameters');
}
@kenhowardpdx
kenhowardpdx / bookmarklet-example.markdown
Last active January 11, 2020 10:12
Bookmarklet Example
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes!
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
@kenhowardpdx
kenhowardpdx / backend.ts
Last active March 3, 2017 03:45
Angular In Memory Backend
import { InMemoryDbService } from 'angular-in-memory-web-api';
declare var file: any;
export class InMemoryEntryService implements InMemoryDbService {
createDb() {
let entries = [
{
id: 1,
title: 'Burning Sundown Behind Trees',
@kenhowardpdx
kenhowardpdx / default-parameters-es2015.js
Created August 1, 2016 00:46
Default Parameters Through Destructuring (ES2015)
// Clear the console on each refresh
console.log('\033c');
function addToCart(product, price, { quantity = 1, currency = 'USD' }) {
console.log(product, price, quantity, currency);
}
let Bicycle = {
product: 'Bicycle',
price: 99.99
@kenhowardpdx
kenhowardpdx / index.html
Created May 4, 2016 16:41
Angular Navbar Component
<!DOCTYPE html>
<html ng-app="app">
<head>
<meta http-equiv="cache-control" content="no-cache" />
<meta name="robots" content="noindex, nofollow" />
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width" />
<title ng-bind="APP_NAME">Loading...</title>
<link rel="icon" href="data:;base64,=" />
<link rel="stylesheet" href="css/lib.css" />
@kenhowardpdx
kenhowardpdx / .gitignore
Last active January 27, 2016 03:26
TypeScript settings in Visual Studio Code
node_modules
src/**/*.js
src/**/*.js.map
typings/**/*.d.ts
!typings/tsd.d.ts
@kenhowardpdx
kenhowardpdx / tslinter.ts
Created January 2, 2016 22:01
TS Linter
'use strict';
import * as fs from 'fs';
import * as Linter from 'tslint';
let configuration = require('./tslint.json');
let options = {
formatter: 'prose',
configuration: configuration,
rulesDirectory: '',
formattersDirectory: ''