Skip to content

Instantly share code, notes, and snippets.

View reke592's full-sized avatar

Erric Rapsing reke592

  • Bulacan, Philippines
View GitHub Profile
@reke592
reke592 / sample-digest-auth.js
Created October 3, 2020 15:49
Sample digest challenge for API key authentication
/**
Pseudo : API key digest authentication rfc2617
Pre-requisite
internal secret
shared secret
H = hash algorithm (SHA256)
H1 = H + internal secret
nc = counter
Transaction flow
@reke592
reke592 / report-builder.js
Last active January 1, 2021 18:24
helper factory for report builder using puppeteer, mustache and bootstrap
/**
* It requires *.min.css to be in same directory
* we need to update the @media print part in css file to correct the color rendering issues when generating pdf files
*/
const fs = require('fs')
const mustache = require('mustache')
const path = require('path')
const puppeteer = require('puppeteer')
// dynamic cache for templates
@reke592
reke592 / mustache-value-formatter.js
Created January 1, 2021 18:21
sample value formatter for mustache template
/**
* {{#currency}}{{value}}{{/currency}}
*/
let formatter = {
currency: () => (val, render) => {
return render(val).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
}
@reke592
reke592 / event-bus.js
Created November 6, 2021 14:10
Sample event bus implementation in Nodejs
//require('./experimental')(__filename); // helper that throws when process.EXPERIMENTAL=false
//const { debug } = require('./static'); // overriden debug function that includes user_id and transaction_id
const debug = require('debug')('app');
/**
* usage:
* // eg. api/subscribers/email-notifications/index.js
* const {debug} = require('../../commons/static');
* const events = require('../../commons/event_types');
*
@reke592
reke592 / web-notes.txt
Last active June 11, 2023 09:36
web notes
-- Disclaimer: not a standard rule. just a collection of ideas/experience while doing a fullstack development task --
identify the configurations that can affect the application restart, put those dynamic configuration in database. (eg. email config).
create server.js (exports app and start function), and index.js (imports start function), so we can use the server.app for unit testing with supertest.
identify the common functions and store them inside `commons` folder.
create commons/errors to contain all the possible application errors we can throw, include the http status code.
[frontend]
eg. /commons
'-- debouncer.dart
'-- errors.dart
@reke592
reke592 / encryption.js
Last active November 7, 2021 13:20
Sample data encryption in nodejs
/** Sample usage:
*
* let _encrypt, _decrypt, _createIV;
*
* repo.useEncryption = async (encryption) => {
* if (!toString.call(_encrypt).match(/Function/)
* && !toString.call(_decrypt).match(/Function/)) {
* let config = encryption.configure([
* 'first_name',
* 'last_name',
@reke592
reke592 / rarlogs.bat
Created November 7, 2021 13:29
sample apache log rotation batch file for windows
@echo off
REM this file is being called by apache via pipe in rotatelogs.exe
REM adjustments to be made in apache httpd.conf (search for log_config_module)
REM to rotate the logs every midnight
REM CustomLog "|bin/rotatelogs.exe -p c:/<path to this dir>/rarlogs.bat -l c:/<path to client>/logs/access-%Y-%m-%d.log 86400" common
REM rotate when reached 100Mb limit
REM CustomLog "|bin/rotatelogs.exe -p c:/<path to this dir>/rarlogs.bat -l c:/<path to client>/logs/access-%Y-%m-%d-%H_%M.log 100M" common
REM %1 new .log, %2 old .log
set compress=1
@reke592
reke592 / sample-dropdown-option-test.js
Created November 7, 2021 13:58
Sample dropdown option test case using supertest
const request = require('supertest');
const { app } = require('../server');
describe('Form input options', () => {
it('GET /option/regions --> array public list regions', () => {
return request(app)
.get('/option/regions')
.expect('Content-Type', /json/)
.expect(200)
@reke592
reke592 / Debouncer.dart
Created November 7, 2021 14:11
Sample debouncer in dart for flutter
import 'dart:async';
class Debouncer {
final Duration duration;
Timer? debouncer;
/// cancel previous action if recur within debounce duration
Debouncer({
this.duration = const Duration(milliseconds: 200)
});
@reke592
reke592 / ModalPrompt.dart
Created November 7, 2021 14:17
Sample common modal prompt for flutter
import 'package:flutter/material.dart';
import 'package:animations/animations.dart';
import 'package:sample/widgets/app_loading_indicator.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';
class ModalPrompt {
static Future<R?> showProcessing<R>({
required context,
required String message,
required Future<R> Function() process,