Skip to content

Instantly share code, notes, and snippets.

Secure private web server with NodeJS

This article will explain how to set up a secure web server with NodeJS which only accepts connection from users with SSL certificates that you have signed. This is an efficient way to ensure that no other people are able to access the web server, without building a login system which will be significantly weaker.

I will not explain how to create a certificate authority (CA), create certificates or sign them. If you need to read up on this, have a look at this excelent article on how to do it with OpenSSL (Mac and Linux): https://help.ubuntu.com/community/OpenSSL#Practical_OpenSSL_Usage It is also possible to do this on a MAC with the keychain application, and I assume it is possible on a Windows machine aswell.

This architecture will allow you to have one web server communicating with an array of trusted clients, the web server itself can be on the public internet, that will not decrease the level of security, but it will only ser

@r-sal
r-sal / README.md
Last active December 15, 2015 05:09
CSS Files CDN

CSS CDN

@r-sal
r-sal / gist:5218154
Created March 22, 2013 00:58 — forked from remy/gist:350433
Browser storage pollyfill
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
/* Replace all " " with " " */
String.prototype.removeNbsp = function() { return this.replace(/[\u00A0+]/g," "); };
/* Replace one or more spaces with a single space */
String.prototype.collapseStr = function() { return this.replace(/\s\s+/g, " "); };
/* Replace "<br>" with "\n" */
String.prototype.br2nl = function() { return this.replace(/<br\s*\/?>/mg,"\n"); };
String.prototype.removeTabs = function() { return this.replace(/[\u0009+]/g," "); };
@r-sal
r-sal / general-bmlts.js
Last active December 15, 2015 20:41
Various bookmarklets
// bmlt.gmail.unread.js - shows unread emails in gmail
javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.7",function($,L){var input = $('div[role="navigation"]').find('input[type="text"]');input.val(input.val() + " label:unread");$('div[role="navigation"]').find('button').click();});
// PHP Quick Reference
javascript:q=document.getSelection();if(q == '')void(q=prompt('PHP Reference:',''));if(q)location.href='http://www.php.net/'+escape(q)
// imgur-bookmarklet.js
javascript:void(window.location="http://api.imgur.com/2/upload.json?url="+encodeURIComponent(window.location.href));
@r-sal
r-sal / duplicate_window.js
Created April 8, 2013 22:32
Stupid simple bookmarklet function to duplicate the current page in a new window. Boom.
// Stupid simple bookmarklet function to duplicate the current page in a new window. Boom.
javascript:(function(){window.open(window.location.href)})();
// create a 2d array
function createGrid(rows, columns) {
var grid = new Array(rows);
for(var i = 0; i < rows; i++) {
grid[i] = new Array(columns);
for(var j = 0; j < columns; j++) {
grid[i][j] = 0;
}
}
return grid;
// create a 2d array
function createGrid(rows, columns) {
var grid = new Array(rows);
for(var i = 0; i < rows; i++) {
grid[i] = new Array(columns);
for(var j = 0; j < columns; j++) {
grid[i][j] = 0;
}
}
return grid;
@r-sal
r-sal / git_notes.md
Last active December 16, 2015 07:49

* [Git Reference](http://gitref.org/remotes/)

Step 1: Fork the "Spoon-Knife" repository

To fork this project, click the "Fork" button.

Step 2: Clone your fork

To be able to work on the project, you will need to clone it to your local machine.

@r-sal
r-sal / drivers_mobile_web_testing.md
Last active December 16, 2015 10:08
Viewports all the way down…