Skip to content

Instantly share code, notes, and snippets.

View kmaida's full-sized avatar

Kim Maida kmaida

View GitHub Profile
@kmaida
kmaida / workstation.md
Last active September 9, 2020 16:30
Kim's remote work station - September 8, 2020
@kmaida
kmaida / functions.php
Last active June 30, 2020 20:31
WordPress - Custom Post Type and ACF -> REST API: add "acf" property to REST API for posts, pages, and custom post types; include the following code blocks in wp-includes/functions.php
/**
* Register Activities as a custom post type
*/
function cpt_register_activities() {
$labels = array(
"name" => __( "Activities", "twentytwenty" ),
"singular_name" => __( "Activity", "twentytwenty" ),
"menu_name" => __( "Activities", "twentytwenty" ),
"all_items" => __( "All Activities", "twentytwenty" ),
"add_new" => __( "Add New Activity", "twentytwenty" ),
@kmaida
kmaida / slack-app-snippets.js
Last active June 30, 2020 13:40
Useful little snippets for building Slack apps
// Username regex
// Starts with @
// Can contain only numbers, lowercase letters, -, ., _
// NOTE: this can be avoided by escaping characters (slash command settings)
const usernameRegex = /^@+[0-9a-z_\-.]*$/;
// Get all user ID mentions from a string
// <@UXXXX|user> (slash commands)
// <@UXXXX> (app mention text)
// Returns an array of user mentions
@kmaida
kmaida / api.service.ts
Created February 20, 2018 16:23
MEAN RSVP API service with pipeable RxJS operators
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
import { AuthService } from './../auth/auth.service';
import { Observable } from 'rxjs/Observable';
import { catchError } from 'rxjs/operators';
import 'rxjs/add/observable/throw';
import { ENV } from './env.config';
import { EventModel } from './models/event.model';
import { RsvpModel } from './models/rsvp.model';
@kmaida
kmaida / firebase-owner-firestore-crud-rules.txt
Last active March 25, 2021 17:52
Firebase Cloud Firestore rules: all users can read, authenticated users can create if they provide a UID, owner can delete, owner can update.
service cloud.firestore {
match /databases/{database}/documents {
match /<COLLECTION_NAME>/{document=**} {
allow read: if true;
allow create: if request.auth != null && request.auth.uid == request.resource.data.uid;
allow update, delete: if request.auth != null && request.auth.uid == resource.data.uid;
}
}
}
@kmaida
kmaida / firebase-owner-rtdb-crud-rules.json
Last active January 3, 2018 14:49
Firebase rules: all users can read, authenticated users can create if they provide a uid, owner can delete, owner can update.
{
"rules": {
".read": "true",
".write": "auth != null",
"<ITEMS>": {
".indexOn": "<PROPERTY TO INDEX BY>",
"$comment": {
".write": "(!data.exists() && newData.child('uid').val() == auth.uid) || (data.exists() && data.child('uid').val() == auth.uid && !newData.exists()) || (data.exists() && data.child('uid').val() == auth.uid && newData.child('uid').val() == auth.uid)"
}
}
@kmaida
kmaida / autoP.js
Last active November 27, 2017 21:40
Convert newlines to markup (e.g., from a textarea)
newlinesToMarkup(text) {
const withPTags = '<p>' + text.replace(/\n([ \t]*\n)+/g, '</p><p>').replace('\n', '<br>') + '</p>';
return withPTags;
}
@kmaida
kmaida / app.module.ts
Last active November 12, 2017 18:36
Sharing module with providers in Angular (i.e., https://alligator.io/angular/providers-shared-modules/)
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { CoreModule } from './core/core.module';
@NgModule({
declarations: [],
imports: [
BrowserModule,
CoreModule.forRoot()
@kmaida
kmaida / indexOfObjInArray.js
Created October 19, 2017 19:53
Find the index of a particular object in an array by key/value pair.
const indexOfObj = (array, key, value) => {
for (let i = 0; i < array.length; i++) {
if (array[i][key] === value) {
return i;
}
}
return -1;
};
@kmaida
kmaida / anim.component.ts
Last active May 22, 2017 19:30
Animate ngIf with Angular (v4+)
import { Component, OnInit, Input, OnDestroy } from '@angular/core';
import { expandCollapse } from './expandCollapse.animation';
@Component({
selector: 'app-anim',
animations: [expandCollapse],
template: `
<button (click)="toggle()">{{showText}}</button>
<div *ngIf="show" [@expandCollapse]>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vestibulum bibendum justo sed posuere. Integer consequat nec nisi ac lacinia. Nulla a urna at risus tempus mattis a ut sapien. Mauris eleifend ornare nibh, a semper ligula hendrerit ut. Nullam sit amet elementum mauris, ac lobortis lacus. Cras vestibulum pellentesque ligula vel laoreet. Vivamus eget nibh consequat, viverra mi vel, commodo lectus. Donec cursus aliquam purus nec blandit. Etiam et pellentesque diam, at egestas nisl. Mauris faucibus non erat quis malesuada.</p>