Skip to content

Instantly share code, notes, and snippets.

View kmaida's full-sized avatar

Kim Maida kmaida

View GitHub Profile
@kmaida
kmaida / dynamicPagRepeatAngular.html
Last active December 13, 2023 14:37
AngularJS - Dynamic pagination on ng-repeat with search/filtering. Use with ui.bootstrap
<!DOCTYPE HTML>
<html lang="en" ng-app="myApp">
<head>
<meta charset="utf-8">
<title>Dynamic Pagination w/ Filtering</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="Kim Maida">
<!-- JS Libraries -->
@kmaida
kmaida / convert-UNIX-timestamp.js
Last active March 16, 2023 09:31
Convert a UNIX timestamp to user's local time via JavaScript
function convertTimestamp(timestamp) {
var d = new Date(timestamp * 1000), // Convert the passed timestamp to milliseconds
yyyy = d.getFullYear(),
mm = ('0' + (d.getMonth() + 1)).slice(-2), // Months are zero based. Add leading 0.
dd = ('0' + d.getDate()).slice(-2), // Add leading 0.
hh = d.getHours(),
h = hh,
min = ('0' + d.getMinutes()).slice(-2), // Add leading 0.
ampm = 'AM',
time;
@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 / workstation.md
Last active September 9, 2020 16:30
Kim's remote work station - September 8, 2020
@kmaida
kmaida / formUtils.factory.ts
Last active August 21, 2020 14:06
Angular Date Validator - directive and factory - validates strings m/d/yyyy
// MM/DD/YYYY, M/D/YYYY
const DATE_REGEX = new RegExp(/^(\d{2}|\d{1})\/(\d{2}|\d{1})\/\d{4}$/);
export { DATE_REGEX };
@kmaida
kmaida / slugify.js
Last active July 5, 2020 19:32
Convert string of text into a slug separated by hyphens with no special characters.
function slugify(text) {
const a = 'ãàáäâèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;';
const b = 'aaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------';
const p = new RegExp(a.split('').join('|'), 'g');
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special chars
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
@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 / trustAsHTMLFilter.js
Last active July 13, 2018 20:05
AngularJS 1.2+ - $sce.trustAsHtml() using a filter. Usage: ng-bind-html="string | trustAsHTML"
myApp.filter('trustAsHTML', ['$sce', function($sce){
return function(text) {
return $sce.trustAsHtml(text);
};
}]);
@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';