Skip to content

Instantly share code, notes, and snippets.

@joepie91
joepie91 / express-server-side-rendering.md
Last active July 26, 2024 09:56
Rendering pages server-side with Express (and Pug)

Terminology

  • View: Also called a "template", a file that contains markup (like HTML) and optionally additional instructions on how to generate snippets of HTML, such as text interpolation, loops, conditionals, includes, and so on.
  • View engine: Also called a "template library" or "templater", ie. a library that implements view functionality, and potentially also a custom language for specifying it (like Pug does).
  • HTML templater: A template library that's designed specifically for generating HTML. It understands document structure and thus can provide useful advanced tools like mixins, as well as more secure output escaping (since it can determine the right escaping approach from the context in which a value is used), but it also means that the templater is not useful for anything other than HTML.
  • String-based templater: A template library that implements templating logic, but that has no understanding of the content it is generating - it simply concatenates together strings, potenti
@joshnuss
joshnuss / app.js
Last active February 18, 2025 15:49
Express.js role-based permissions middleware
// the main app file
import express from "express";
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db)
import authenticate from "./authentication"; // middleware for doing authentication
import permit from "./authorization"; // middleware for checking if user's role is permitted to make request
const app = express(),
api = express.Router();
// first middleware will setup db connection
@terranware
terranware / snsToSlack.js
Last active March 22, 2025 16:43
AWS Lambda function to Slack Channel hookup
var https = require('https');
var util = require('util');
exports.handler = function(event, context) {
console.log(JSON.stringify(event, null, 2));
console.log('From SNS:', event.Records[0].Sns.Message);
var postData = {
"channel": "#aws-sns",
"username": "AWS SNS via Lamda :: DevQa Cloud",
@schmuli
schmuli / Gulp and Bower Components.md
Last active December 29, 2017 15:44
Minify and Concat all bower components

This is an example gulpFile that can be used to minify and concat all bower components marked as dependencies. Also includes the bower.json and package.json files for the project.

The 'vendors' task will extract all bower components, using main-bower-files, but replaces any files that have a matching .min file that exists. Any unminified files are then minified using Uglify, and then all files are concatenated into a single vendors.js file.

The bower.json deliberately includes the SizzleStats dependency, as this component doesn't include a minified file.

@AndreiD
AndreiD / ubuntu server after install TODO
Last active July 31, 2018 18:06
UBUNTU / MINT SERVER - AFTER INSTALL TODO
[ SERVER PART ] (for desktop, scroll down)
sudo apt install -y build-essential libssl-dev libncurses5-dev libpcap-dev git apt-transport-https ca-certificates
git config --global core.autocrlf false
git config --global core.longpaths true
// NodeJS
cd /tmp
curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
@KartikTalwar
KartikTalwar / Documentation.md
Last active February 28, 2025 10:57
Rsync over SSH - (40MB/s over 1GB NICs)

The fastest remote directory rsync over ssh archival I can muster (40MB/s over 1gb NICs)

This creates an archive that does the following:

rsync (Everyone seems to like -z, but it is much slower for me)

  • a: archive mode - rescursive, preserves owner, preserves permissions, preserves modification times, preserves group, copies symlinks as symlinks, preserves device files.
  • H: preserves hard-links
  • A: preserves ACLs
@crtr0
crtr0 / client.js
Created June 8, 2012 17:02
A simple example of setting-up dynamic "rooms" for socket.io clients to join
// set-up a connection between the client and the server
var socket = io.connect();
// let's assume that the client page, once rendered, knows what room it wants to join
var room = "abc123";
socket.on('connect', function() {
// Connected, let's sign-up for to receive messages for this room
socket.emit('room', room);
});