Skip to content

Instantly share code, notes, and snippets.

View TaylorAckley's full-sized avatar

Taylor Ackley TaylorAckley

View GitHub Profile
@TaylorAckley
TaylorAckley / curried-search.ts
Created August 20, 2021 16:01
Search with Curry
export class GithubSearchCurryService extends BaseGithubSearch {
searchClient!: (term: string) => Observable<any>;
constructor(http: HttpClient) {
super(http)
}
/**
* Execute a search - calling this consecutively will page through results
*/
search(term: string) {
@TaylorAckley
TaylorAckley / allowed-origins.middleware.js
Last active August 15, 2021 05:14
Allowed Origins Middleware
const express = require('express');
const app = new Express();
const cache = require('origin-cache');
require('api-keys.script');
const allowedOrigins = cache.get();
// see full example: https://github.com/TaylorAckley/cors-app/blob/main/api/index.js
/** Use CORS. If RESTRICT_ORIGINS is enabled, only certain domains can call the API. **/
@TaylorAckley
TaylorAckley / origins-cache.js
Last active August 15, 2021 05:09
Origins Cache
'use strict';
const NodeCache = require('node-cache');
const chalk = require('chalk');
const origins = new NodeCache();
const ApiKey = require('./models/api-key.model');
// https://www.npmjs.com/package/node-cache
const cache = {};
@TaylorAckley
TaylorAckley / pager.js
Last active August 15, 2021 04:54
Simple Paging Example
require('dotenv').config();
const request = require('request-promise');
// Hoist our users array.
let users = [];
const API_ENDPOINT = `https://publicapi.knowledgeanywhere.com`;
const CLIENT_ID = process.env.LMS_CLIENT_ID; // Loaded from our .env file
const CLIENT_SECRET = process.env.LMS_CLIENT_SECRET; // Loaded from our .env file
const PAGE_SIZE = 1000; // How many records the API returns in a page.
import { HttpClient } from '@angular/common/http';
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'hello',
template: `<h1>Hello!</h1>`,
styles: [`h1 { font-family: Lato; }`]
})
@TaylorAckley
TaylorAckley / nested-observable-switchmap.ts
Created February 22, 2021 20:24
Return from nested observable
import { Observable, of } from "rxjs";
import { switchMap, map } from "rxjs/operators";
class DataFactory {
static getSetupData() {
return of({ param1: "someparam" });
}
static getUsefulData(setupData: any) {
// pretend we use setupData in some fancy way
@TaylorAckley
TaylorAckley / nested-observable-create.ts
Created February 22, 2021 20:23
Return value from nested observable using Observable.create
import { Observable, of, Subject } from "rxjs";
class DataFactory {
static getSetupData() {
return of({ param1: "someparam" });
}
static getUsefulData(setupData: any) {
// pretend we use setupData in some fancy way
return of({ datapoint: "x" });
@TaylorAckley
TaylorAckley / nested-observable.ts
Last active February 22, 2021 20:23
Nested Observable
// returns the outermost subscription, which is not what we want.
someMethod(): Observable<string> {
return this.someService.getSetupData().subscribe(setupData => {
this.someOtherService.getUsefulData(setupData).subscribe(usefulData => {
return of(usefulData.someString);
})
});
}
@TaylorAckley
TaylorAckley / gulpfile-minimal.js
Last active June 29, 2019 18:30
Example Gulpfile with concat, minify, bundle and image optimization
"use strict";
var gulp = require('gulp'),
sass = require('gulp-sass'),
uglify = require('gulp-uglify'),
notify = require('gulp-notify'),
autoprefixer = require('gulp-autoprefixer'),
sourcemaps = require('gulp-sourcemaps'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
plumber = require('gulp-plumber'),
-- psuedo code, example.
INSERT INTO LocaleKeys (LocaleKey, LocaleKeyValue, Locale, Templates) VALUES N'TITLE_LOGIN', N'Login to your account', N'en-us', N'LOGIN_PAGE, SIDE_MENU'
INSERT INTO LocaleKeys (LocaleKey, LocaleKeyValue, Locale, Templates) VALUES N'TEXT_LOGIN', N'Already have an account? <a href="/login">Login Here</a>', N'en-us', N'LOGIN_PAGE'
INSERT INTO LocaleKeys (LocaleKey, LocaleKeyValue, Locale, Templates) VALUES N'APIERROR_UNKOWN', N'An unkown error happened processing your request.', N'en-us', N'*''