Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / landing-route-routing.module.ts
Created June 2, 2021 18:41
sub-route for app-routing module
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LandingRouteComponent } from './landing-route.component';
/**
* Since this route is lazy loaded in the app-routing.module.ts we will declare a blank
* path here and give it the component we wish to load at the current route.
*/
const routes: Routes = [{ path: '', component: LandingRouteComponent, children: [
{ path: 'variation1', loadChildren: () => import('./variation-1/variation-1.module.ts').then((mod) => mod.Variation1Module) }
<script>
import Thing from './Thing.svelte';
let user = { loggedIn: false };
let things = [
{ id: 1, name: 'apple' },
{ id: 2, name: 'banana' },
{ id: 3, name: 'carrot' },
{ id: 4, name: 'doughnut' },
{ id: 5, name: 'egg' },
@shadow1349
shadow1349 / app-routing.module.ts
Created October 31, 2021 16:13
Non-lazy-loaded
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { MainComponent } from './main/main.module';
const routes: Routes = [
{ path: '', redirectTo: '/main', pathMatch: 'full' },
{
path: 'main',
component: MainComponent
},
import { Store } from '@ngxs/store';
import { AppModule } from 'src/app/app.module';
import { AnalyticsActions } from 'src/app/state/analytics/analytics.actions';
import { isFunction } from 'util';
import { captureBreadcrumb } from '../utils';
/**
* ***************************** WARNING **********************************
* To use this decorator you must ensure that your component implements *
* both OnInit and OnDestroy. If it does not this will not work. *
// create a binary search function that takes in a non-sorted array and a target value
const binarySearch = (arr: number[], target: number) => {
// sort the array
arr.sort((a, b) => a - b);
// create a left and right pointer
let left = 0;
let right = arr.length - 1;
// loop while left is less than or equal to right