Skip to content

Instantly share code, notes, and snippets.

@mjurincic
mjurincic / SQLCache.js
Created January 23, 2020 20:31 — forked from cvburgess/SQLCache.js
Knex - caching and batching
const { InMemoryLRUCache } = require("apollo-server-caching");
const DataLoader = require("dataloader");
class SQLCache {
constructor(cache = new InMemoryLRUCache(), knex) {
this.cache = cache;
this.loader = new DataLoader(queries =>
Promise.all(queries.map(query => knexInstance.raw(query)))
);
}
@mjurincic
mjurincic / nodejs-custom-es6-errors.md
Last active November 20, 2019 15:55 — forked from slavafomin/nodejs-custom-es6-errors.md
Custom ES6 errors in Node.js

Here's how you could create custom error classes in Node.js using latest ES6 / ES2015 syntax.

I've tried to make it as lean and unobtrusive as possible.

Defining our own base class for errors

errors/ApplicationError.js

@mjurincic
mjurincic / submodulewiki.md
Created September 2, 2019 11:53 — forked from iracooke/submodulewiki.md
Wiki as a submodule

From within the parent repo do

        git submodule add [email protected]:iracooke/transcriptomes.git/wiki wiki
        git commit -m "Adding wiki as submodule"
        git push

Making changes to the wiki and to the parent require separate git commit commands.

@mjurincic
mjurincic / gitflow-breakdown.md
Created March 25, 2019 17:13 — forked from JamesMGreene/gitflow-breakdown.md
A comparison of using `git flow` commands versus raw `git` commands.

Initialize

gitflow git
git flow init git init
  git commit --allow-empty -m "Initial commit"
  git checkout -b develop master

Connect to the remote repository

@mjurincic
mjurincic / setup.sh
Created February 6, 2019 10:06 — forked from bradp/setup.sh
New Mac Setup Script
echo "Creating an SSH key for you..."
ssh-keygen -t rsa
echo "Please add this public key to Github \n"
echo "https://github.com/account/ssh \n"
read -p "Press [Enter] key after this..."
echo "Installing xcode-stuff"
xcode-select --install
@mjurincic
mjurincic / Secure Sessions Howto
Created January 22, 2019 13:33 — forked from nikmartin/A: Secure Sessions Howto
Secure sessions with Node.js, Connect, and Nginx as an SSL Proxy
Secure sessions are easy, but it's not very well documented, so I'm changing that.
Here's a recipe for secure sessions in Node.js when NginX is used as an SSL proxy:
The desired configuration for using NginX as an SSL proxy is to offload SSL processing
and to put a hardened web server in front of your Node.js application, like:
[NODE.JS APP] <- HTTP -> [NginX] <- HTTPS -> [CLIENT]
To do this, here's what you need to do:
function translateError(msg) {
var newErr = new Error(msg); // placed here to get correct stack
return e => {
newErr.originalError = e;
throw newErr;
}
}
async function asyncTask() {
const user = await UserModel.findById(1).catch(translateError('No user found'))
@mjurincic
mjurincic / duplicate-select-list.html
Created May 30, 2018 15:27 — forked from sleepdeprecation/duplicate-select-list.html
Duplicate a select list using jQuery
<!DOCTYPE html>
<html>
<head>
<title>Duplicate a select list using jQuery</title>
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="selectScript.js"></script>
</head>
<body>
<div id="d1">
@mjurincic
mjurincic / apps.js
Created May 24, 2018 12:12 — forked from eliOcs/apps.js
Express and Handlebars
/*jslint node: true */
"use strict";
var express = require("express"),
consolidate = require("consolidate"),
Handlebars = require("handlebars"),
fs = require("fs");
var app = express();
@mjurincic
mjurincic / logging.js
Created April 3, 2018 18:06
A simple node module that makes console.log/error/warn/debug statements log through winston (simply include at the beginning of your app)
'use strict';
var util = require('util'),
winston = require('winston'),
logger = new winston.Logger(),
production = (process.env.NODE_ENV || '').toLowerCase() === 'production';
module.exports = {
middleware: function(req, res, next){
console.info(req.method, req.url, res.statusCode);