Skip to content

Instantly share code, notes, and snippets.

'use strict'
import { Initializer, api, action, log } from 'actionhero'
let compression = require('compression')
export class CompressMiddleware extends Initializer {
constructor() {
super()
this.name = 'CompressMiddleware'
this.loadPriority = 1000
this.startPriority = 1000
@chimmelb
chimmelb / QuantumAction.ts
Created June 30, 2020 16:19
Error Handling Pattern for actionheroJS
import { Action, ActionProcessor, log } from 'actionhero'
import { SmartError } from './SmartError'
export abstract class QuantumAction extends Action {
constructor() {
// extends Abstract class Action only to wrap
super()
}
async run(data: ActionProcessor): Promise<void> {
try {
/**
* This is the test file that is run by Jest.
* It has the (single) setup for the actionhero instance
*/
import { Process, env, id, specHelper } from 'actionhero'
import createTests from './lib/create'
import updateTests from './lib/update'
const actionhero = new Process()
let api
@chimmelb
chimmelb / primus-ping-pong.js
Created June 20, 2019 19:14
primus ping-pong for own websocket
const pingRegex = /^primus::ping::(\d{13})$/
private onMessage = (messageEvent: MessageEvent) => {
try {
const data = JSON.parse(messageEvent.data)
if (pingRegex.test(data)) {
let pingResults = pingRegex.exec(data)
if (pingResults) {
this.pong(pingResults[1])
}
} else if (data.context && data.context === 'response') {
@chimmelb
chimmelb / chromiumpackages.config
Last active June 7, 2024 14:55
.ebextensions config file to load NodeJS EB instance with packages needed for Puppeteer/Chromium
# This is for ElasticBeanstalk with Amazon Linux 2023. For previous Linux 2 or Linux 1, see revisions for ideas
packages:
yum:
cups-libs: []
libdrm: []
libXdamage: []
libXfixes: []
libXrandr: []
mesa-libgbm: []
libxkbcommon: []
@chimmelb
chimmelb / snippet.js
Last active July 30, 2018 13:44
JSON Data to AWS SNS publish
//text, topicArn, and api.aws.sns all defined elsewhere in scope
var apnsMessage = JSON.stringify({
aps: {
alert: text,
extraData: 'thing'
}
});
var gcmMessage = JSON.stringify({
data: {
message: text,
<template is="dom-repeat" items="{{data}}">
<game-card style$="{{calcMargin(reverse, index, cardWidth)}}" class="card-in-stack" rank="{{item}}" card-width="[[cardWidth]]" card-height="[[cardHeight]]">
</game-card>
</template>
<style include="shared-styles">
.card-in-stack {
position: absolute;
}
</style>
.game-card {
position: relative;
transition: transform .5s linear 0s;
backface-visibility: hidden;
}
.game-card .front {
transform: rotateY( 180deg);
position: absolute;
}
Polymer({
is: 'card-stack',
behaviors: [Polymer.IronResizableBehavior],
listeners: {
"iron-resize": "resized"
},
resized: function() {
var height = this.offsetHeight - 2;
var stackWidth = this.offsetWidth - 2;
if (height > 0) {
<section data-route="game">
<div>Game board</div>
<game-board game="{{game}}"></game-board>
</section>