Skip to content

Instantly share code, notes, and snippets.

View CHBaker's full-sized avatar

Charles Hudson Baker CHBaker

View GitHub Profile
@CHBaker
CHBaker / switch.ts
Created September 5, 2023 22:23
Strong Typed Switch Functional
const executeIfFunction =
<Wrapped extends Unwrapped | (() => Unwrapped), Unwrapped>(f: Wrapped): Unwrapped =>
typeof f === 'function' ? f() : f;
const switchf =
<ValueType>(cases: { [key: PropertyKey]: ValueType }) =>
(defaultCase: ValueType) =>
(key: PropertyKey) =>
cases.hasOwnProperty(key) ? cases[key] : defaultCase;
@CHBaker
CHBaker / app.component.ts
Created December 12, 2019 19:23
dummy/fake/mock/stub
import { Component } from '@angular/core';
import { MyService } from './my-service.service';
export interface Item {
price: number;
name: string;
quantitiy: number;
}
export interface Groceries {
@CHBaker
CHBaker / delete_email.py
Created October 5, 2018 16:04 — forked from giovaneliberato/delete_email.py
Python script to delete emails from a specific sender at gmail
#coding: utf-8
import imaplib
import sys
'''
Simple script that delete emails from a given sender
params:
-username: Gmail username
-pw: gmail pw
-label: If you have a label that holds the emails, specify here
@CHBaker
CHBaker / child.component.ts
Created February 8, 2018 16:26
A basic child/dumb component with a form
import { Component, Input } from '@angular/core';
import { FormGroup } from '@angular/forms';
@Component({
selector: 'app-child',
template: `
<h1>Enter your name</h1>
<form
[formGroup]="nameForm"
(ngSubmit)="submitForm(nameForm)"
@CHBaker
CHBaker / child-test-2.component.spec.ts
Created February 8, 2018 16:26
Working test with FormBuilder passing in dynamically a ReactiveForm
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule, FormBuilder } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { AppModule } from './app.module';
import { ChildComponent } from './child.component';
describe('StaticComponent', () => {
let component: StaticComponent;
let fixture: ComponentFixture<ChildComponent>;
@CHBaker
CHBaker / child-test-1.component.spec.ts
Last active February 8, 2018 16:27
Dynamically pass a FormGroup to a child component in a Karma test (Angular)
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule, FormBuilder } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { AppModule } from './app.module';
import { ChildComponent } from './child.component';
describe('StaticComponent', () => {
let component: StaticComponent;
let fixture: ComponentFixture<ChildComponent>;
@CHBaker
CHBaker / webcrawler_index.py
Created February 8, 2018 02:05
indexing function for storing website keywords and URL's
# skips repeat keywords and URL's
index = []
def find(keyword, index):
for i, item in enumerate(index):
try:
r = item.index(keyword)
except ValueError:
continue