Skip to content

Instantly share code, notes, and snippets.

Avatar

Gregory Bown gregbown

View GitHub Profile
@gregbown
gregbown / routes.js
Last active Jul 22, 2020
Test login flow with CSRF token using Mocha, Chai, and Supertest
View routes.js
const assert = require('chai').assert;
const cookiejar = require('cookiejar');
const injector = require('../di-injector');
const testAccounts = require('../data/accounts.json');
const grabToken = new RegExp(/value=[a-zA-Z0-9\-_"]*(?= name="_csrf")/);
let agentFactory;
/** If you are using the tdd interface, suiteSetup maps to beforeAll, and setup maps to beforeEach. */
suite('routes', () => {
@gregbown
gregbown / express-app.js
Last active Dec 27, 2019
i18next server AND client side setup with express
View express-app.js
/* Note: Just enough to get the idea here.
resources/
|- locales/
|- en/
|- translation.json
|- zh/
|- translation.json
|- static/
|- css/
|- fonts/
@gregbown
gregbown / client-form-rws.js
Created Nov 11, 2019
How to use csurf with multipart/form-data example with express, express-fileupload, csurf and jquery + a bit of bootstrap and ejs
View client-form-rws.js
/* Form AJAX JavaScript. Requires jQurery to be loaded */
window.DEMO = window.DEMO || {};
/**
* @method rws
* @description RESTful Web services (RWS)
* Wrapped in an IIFE (Immediately Invoked Function Expression)
* @paraam $ {object} jQuery object, used for ajax methods.
*/
// eslint-disable-next-line no-undef
@gregbown
gregbown / .clang-format
Created Aug 28, 2018
Local clang format for typescript
View .clang-format
Language: JavaScript
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignEscapedNewlinesLeft: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
@gregbown
gregbown / .clang-format
Created Apr 24, 2018
Clang format YAML file for local overrides in TypeScript
View .clang-format
Language: JavaScript
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignEscapedNewlinesLeft: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
@gregbown
gregbown / pagination-control.component.html
Created Sep 27, 2017
i18n components with multiple instances
View pagination-control.component.html
<div class="form-group row-select">
<label for="rowDropdownMenu" i18n="the title for pagination results@@controlPaginationResults">Results per page</label>
<div ngbDropdown class="d-inline-block">
<button class="btn btn-outline-primary" id="rowDropdownMenu" ngbDropdownToggle>{{rows.current.text}}</button>
<div class="dropdown-menu" aria-labelledby="rowDropdownMenu">
<ng-template ngFor let-option [ngForOf]="rows.options | displays">
<button
class="dropdown-item"
value="{{option.value}}"
(click)="changed.emit({value:option.value, bubbles: true})">{{option.text}}</button>
You can’t perform that action at this time.