Skip to content

Instantly share code, notes, and snippets.

View sacarino's full-sized avatar

Shane sacarino

View GitHub Profile
@sacarino
sacarino / regex.txt
Last active March 18, 2017 03:45
Incredibly useful regex for URL parsing
(http[s]?:\/\/)?([^\/\s]+)\/?([^\/\s]+)\/(.*)\?(.*)\#(.*)\b
example here: https://regex101.com/r/QJdP9m/1
Full match: https://www.somehost.com/path/that/you/can/target?query=butwhy#because
Group 1: https://
Group 2: www.somehost.com
Group 3: path
Group 4: that/you/can/target
Group 5: query=butwhy
@sacarino
sacarino / controllers.application.js
Last active March 23, 2017 03:58
Playing around with an accelerating spinner
import Ember from 'ember';
var pfx = ["webkit", "moz", "MS", "o", ""];
export default Ember.Controller.extend({
appName: 'spinner demo',
isLoading: true,
speed: null,
startEngine: false,
@sacarino
sacarino / components.form-wizard.js
Last active August 22, 2017 12:36
Notifications Signup Wizard v3
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'ul',
classNames: ['steps'],
currentPath: null, //passed in value, is current route
steps: null,
activeIndex: function(){
var currentPath = this.get('currentPath');
var steps = this.get('steps');
@sacarino
sacarino / BsonToGuid.cs
Created June 28, 2017 14:04
C# - Generate a GUID from an ObjectID
using System;
using System.Linq;
using MongoDB.Bson;
namespace Extensions
{
internal static class BsonToGuid
{
internal static Guid AsGuid(this BsonObjectId oid)
{
@sacarino
sacarino / loopback_and_postgresql_cheatsheet.md
Created August 24, 2018 02:49
Cheatsheet for creating LoopbackJS relationships using the PostgreSQL connector

This is my cheatsheet, because the Loopback docs aren't the best and I spent way too long puzzling this stuff out.

Consider this a living document. If it helps you, too... great! If you want to make a suggestion, lmk.

First... the why.

It's a PostgreSQL best-practice to use lowercase names, using snakecase if you need to. ie, my_column_name. You CAN force CamelCase or all uppercase, but it's a really bad idea. Don't.

Also, since I'm using a JSON API client, I've installed the excellent loopback-component-jsonapi to handle the serialization stuff... but that just added additional complexities.

@sacarino
sacarino / admin_and_owner_crud_plus_read_authenticated.js
Last active October 25, 2018 17:05
Some sane LoopbackJS ACL defaults / examples
// authenticated access to READ the model, but only admin or owner of the model can CRUD
...
"acls": [{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
}, {
"accessType": "*",
"principalType": "ROLE",
@sacarino
sacarino / 0-schema-update.js
Last active December 19, 2018 18:41
Loopback v3.x boot script to automatically update schemas for any datasources that have models connected to them.
'use strict';
const debug = require('debug')('custom:boot:schema-update');
/* Name: 0-schema-update.js
* Purpose: Automatically updates all data sources to match current model definitions
* Warnings: ds.autoupdate does a diff and updates table schemas so it's a non-destructive
* change, but if you remove a property/column then data will be lost!!!
* See more: https: //loopback.io/doc/en/lb3/Creating-a-database-schema-from-models.html#auto-update
*/
@sacarino
sacarino / components.repositories-row\.js
Created May 27, 2021 21:52
Expandable table example
import Component from '@glimmer/component';
import {
tracked
} from '@glimmer/tracking';
import {
action
} from '@ember/object';
export default class extends Component {
@tracked showDetail = false;
@sacarino
sacarino / components.big-button\.js
Last active June 12, 2021 01:49
Testing sibling interaction
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { task, timeout } from 'ember-concurrency';
import { tracked } from '@glimmer/tracking';
export default class extends Component {
@service store;
@tracked timers = [];
@tracked activityLabel = 'Start';
@sacarino
sacarino / deploy-to-cluster.sh
Created January 27, 2023 04:36
Bash script to build a docker image, tag it, push to ECR, and deploy to ECS
#!/bin/bash
# Script to build, tag, auth, and deploy to production
# Call it like `./deploy-to-cluster.sh {profile}`
# AWS ECS task definition that we'll be updating at the end.
# This assumes your service and task are named the same thing!
TASK_DEFINITION_NAME="my-task-name"
# name of the cluster you're deploying to