Skip to content

Instantly share code, notes, and snippets.

View theAlgorithmist's full-sized avatar

Jim Armstrong theAlgorithmist

View GitHub Profile
<div class="mat-elevation-z8">
<table mat-table matSort [dataSource]="dataSource">
<tr mat-header-row *matHeaderRowDef="displayOrder"></tr>
<tr mat-row *matRowDef="let row; columns: displayOrder" (click)="onTouched(row)"></tr>
<ng-container matColumnDef="year">
<th mat-header-cell *matHeaderCellDef mat-sort-header="year"> Year </th>
@theAlgorithmist
theAlgorithmist / input-selector.directive.ts
Created April 25, 2019 12:31
Keyup handler for input editing
@HostListener('keyup', ['$event']) onKeyUp(evt: KeyboardEvent): boolean
{
// test for singleton leading negative sign as first character
const v: string = this._input.value;
const n: number = v.length;
// for now, allow a blank field as it is possible that the entire number could be deleted by backspace before
// entering a new number
if (n == 0) {
return true;
@theAlgorithmist
theAlgorithmist / cc-data.ts
Last active February 20, 2020 20:29
Basic credit card data
/**
* Credit card data for all supported card types (note that the MC data is old and does not consider that some new cards
* issued in 2017 and beyond may have a BIN starting with 2)
*
* @author Jim Armstrong (www.algorithmist.net)
*
* @version 1.0
*/
import { CCTypes } from "../cc-types";
<div [formGroup]="ccSubGroup" class="form-content">
<div *ngIf="showCardType">
<img src="{{creditCardData[cardType].image}}" width="40" height="25">
<span> {{creditCardData[cardType].name}} </span>
</div>
<label for="creditcard">
Credit Card
<input creditCardNumber
[class]="ccnClass"
type="text"
import {
AbstractControl,
FormGroup,
ValidationErrors,
ValidatorFn,
} from '@angular/forms';
import { isCCLengthValid } from '../libs/is-length-valid';
import { getCardType } from '../libs/get-card-type';
import { isValidLuhn } from '../libs/is-valid-luhn';
.
.
.
this._expirationMonth = new FormControl(months[this._curMonth].value, Validators.required);
this._expirationYear = new FormControl(this._userSelectedYear, Validators.required);
this._cvv = new FormControl('', Validators.required);
this._expirationMonth.disable();
this._expirationYear.disable();
this._cvv.disable();
@theAlgorithmist
theAlgorithmist / __initSimulation
Created March 27, 2020 22:07
Init Simulation
await this.__loadComponent();
if (this.ComponentInstance)
{
// on every intersection
this.ComponentInstance.instance.intersect$.subscribe( (id: string) => this.__updateIntersection(id) );
// begin simulation
timer(100, this._delta)
.pipe(
private async __loadComponent(): Promise<any>
{
let factory: ComponentFactory<IPointInCircle>;
if (this.picContainer) {
this.picContainer.clear();
}
// lazy-load the required component based on the algorithm id
switch (this.algorithm)
@theAlgorithmist
theAlgorithmist / __initCircles
Created March 30, 2020 11:59
Initialize circle layout inside simulation area
protected __initCircles(): void
{
// Draw the point
this.__drawPoint();
// Draw the circles at pseudo-random locations around the drawing area
const xHigh: number = (this._width - CircleService.MAX_RADIUS) + 0.499;
const yHigh: number = (this._height - CircleService.MAX_RADIUS) + 0.499;
let i: number;
@theAlgorithmist
theAlgorithmist / next.ts
Created March 30, 2020 13:14
Advance a point-in-circle simulation one step
public next(): void
{
let circ: TSMT$Circle;
let g: PIXI.Graphics;
// first, redraw any circles previously marked as containing the point with the default stroke color
while (this._identifiedDO.length > 0)
{
g = this._identifiedDO.pop();
circ = this._identified.pop();