Skip to content

Instantly share code, notes, and snippets.

@shadow1349
shadow1349 / app-routing.module.ts
Created June 2, 2021 18:37
Main Angular routes
const routes: Routes = [
/**
* When the path is '' it will know to redirect the user to the landing page.
* This is setting up the default route that the user will always land on at first.
*/
{ path: '', redirectTo: '/landing', pathMatch: 'full' },
{
/**
* Landing will always be the first route we get to in order to bootstrap
* the virtual pages and make our lives a little easier in so far as routing
@shadow1349
shadow1349 / palindromQuestion.js
Last active May 18, 2021 20:22
Basic Interview Question in JavaScript
/**
* Create a simple function which returns
* a boolean value indicating if a given
* string is a palindrome. Punctuation should
* be ignored.
*
* palindrome: a word, phrase, or sequence
* that reads the same backward as forward,
* e.g., madam or nurses run.
*/
@shadow1349
shadow1349 / firestore.rules
Created July 8, 2020 02:48
Setting Custom User Claims in Firebase
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /AdminStuff/{StuffId} {
allow read, write: if isAdmin();
}
function isAdmin() {
return request.auth.token['isAdmin'] == true;
}
@shadow1349
shadow1349 / firestore.rules
Last active July 7, 2020 16:58
Firestore Rules
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /Users/{UserId} {
// Allow anyone to create an account
allow create: if true;
// UserId comes from {UserId} above
// the UserId will be auto-filled with the UserId
// of the user trying to access this record
allow read, update, delete: if isOwner(UserId);
@shadow1349
shadow1349 / index.ts
Created July 6, 2020 22:53
Firebase Functions Express API
import * as express from 'express';
import * as cors from 'cors';
import * as bodyParser from 'body-parser';
import * as sentry from '@sentry/node';
import * as admin from 'firebase-admin';
import { APIResponse } from '@sredmond/apiresponse';
import * as functions from 'firebase-functions';
const app = express();
@shadow1349
shadow1349 / note.component.html
Created September 17, 2019 03:51
Notes with tag inputs
<mat-card class="md-margin">
<mat-toolbar [style.background]="'none'" *ngIf="note !== undefined">
<span flex>{{ note.Title }}</span>
<button mat-icon-button color="warn" (click)="deleteNote()">
<mat-icon>delete</mat-icon>
</button>
</mat-toolbar>
<div layout="column" *ngIf="noteForm.disabled" class="md-padding">
<p>{{ note.Note }}</p>
@shadow1349
shadow1349 / notes.component.html
Created September 17, 2019 03:06
Notes page using algolia instant search
<div *ngIf="user | async as User">
<button mat-raised-button color="accent" (click)="newNote = true">
Create Note
</button>
<h2 *ngIf="User.NumNotes === 0">Looks like there are no notes to display</h2>
<h2 *ngIf="User.NumNotes > 0">You have {{ User.NumNotes }} notes</h2>
<app-note *ngIf="newNote" (update)="createNote($event, User.Id)"></app-note>
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
import { INote, IUser, NoteModel } from "firebasenoteapptypes";
import { AlgoliaSearch } from "../algolia";
const index = new AlgoliaSearch("Notes");
export const NoteCreated = functions.firestore
.document("Notes/{NoteId}")
.onCreate(async (snapshot, context) => {
import * as algoliasearch from "algoliasearch";
import * as functions from "firebase-functions";
import { Model } from "firebasenoteapptypes";
const algolia = algoliasearch(
functions.config().algolia.appid,
functions.config().algolia.adminkey
);
type IndexName = "Notes" | "Users" | "Notifications";
export interface IModel {
Id: string;
CreatedOn: number;
}
export interface IAlgoliaModel {
objectID: string;
_tags?: string[];
}