Skip to content

Instantly share code, notes, and snippets.

@Noitidart
Noitidart / tma-backend-framework.md
Last active March 29, 2021 02:58
The next backend framework to pick for TMA
  • Typescript
  • Output payload type for each status code of endpoint
  • Multi-roles per endpoint
  • Permissions per endpoint (base permissions provided by role, then extra permissions available)
  • Categorize endpoints by roles
  • Complete Datadog tracing
  • Response of JSON endpoints into datadog (i currently can't see 400 messages for what problems in the fields)
  • Log JSON response from endpoints
  • ORM nested populate
  • ORM find by nested populate critiera
function useRenderCounter(label) {
const ref = React.useRef();
React.useEffect(() => {
ref.current.textContent = [
parseInt(ref.current.textContent || "0", 10) + 1,
label
]
.filter(Boolean)
.join(" - ");
});

Getting Unix In New York (Date.now() as if "run in New York at a given time")

// get utc of Feb2 2021 10am in New York - moment.tz('America/New_York').month(1).date(2).hour(10).minute(0).second(0).valueOf()
// now with the return of the above is Date.now() as if i ran it in New York timezone on Feb2 2021 10am - so doing moment.utc(1612278000203).tz('America/New_York').format('llll') gives 'Tue, Feb 2, 2021 10:00 AM'
/////////
var chunk_cnt = 0;
var upload = function() {
// /{user-id}/feed?message={message}&access_token={access-token}
aReportProgress({
body_prefix: 'Chunk ' + (++chunk_cnt) + ' - ',
reason: formatStringFromName('uploading_init', 'app')
});
const { routes } = require('../../../config/routes');
const pluralize = require('pluralize');
const { camelCase } = require('lodash');
/**
* implicitRoutes hook
*
*
* @description :: A hook definition. Extends Sails by adding shadow routes, implicit actions, and/or initialization logic.
* @docs :: https://sailsjs.com/docs/concepts/extending-sails/hooks
2020-02-22T05:47:29.811462184Z - GET /vod_installer/.env (4ms 404)
2020-02-22T05:47:30.201288566Z - GET /login/.env (2ms 404)
2020-02-22T05:47:30.590670434Z - GET /apps/.env (6ms 404)
2020-02-22T05:47:30.975336099Z - GET /docker/.env (2ms 404)
2020-02-22T05:47:31.356389783Z - GET /engine/.env (2ms 404)
2020-02-22T05:47:31.755648105Z - GET /.env (5ms 404)
2020-02-22T05:47:32.139752236Z - GET /inc/.env (3ms 404)
2020-02-22T05:47:32.523264401Z - GET /development/.env (2ms 404)
2020-02-22T05:47:32.905328696Z - GET /system/.env (2ms 404)
2020-02-22T05:47:33.288912713Z - GET /admin/.env (1ms 404)
import io from 'socket.io-client';
import getBaseUrl from '../../../utils/get-base-url';
let mSocket: null | SocketIOClient.Socket = null;
let mIsConnecting = false;
/**
* Create io.socket if it doesn't exist. If it does, and it's disconnected
* then reconnect it. If io.socket is in process of connecting, this will
/**
* Returns the room names that a socket is connected to.
*
* @param {string} socketId - a socket id - `sails.sockets.getId(this.req)`
*
* @returns {string[]} rooms
*/
function getSocketRooms(socketId) {
return new Promise((resolve, reject) => {
sails.io.of('/').adapter.clientRooms(socketId, (err, rooms) => {
  1. Initialize sails web app by doing sails new sails-webpack and then Choose 1 for “Web App”.
  2. Uninstall Grunt: a. Run npm un grunt sails-hook-grunt. b. Delete /tasks directory.
  3. Install packages for our webpack hook: a. Install dev dependency by running npm i webpack -D. b. Install lodash as prod dependency (as I'm sure you'll use this in prod later) by running npm i lodash.
  4. Create webpack hook: a. Run sails generate hook webpack, this creates file api/hooks/webpack/index.js. b. Overwrite it with this contents - https://gist.github.com/Noitidart/e1a674f9b6dfcd8219baab1e6bce7b04