Skip to content

Instantly share code, notes, and snippets.

View hampusborgos's full-sized avatar

Hampus Joakim Borgos hampusborgos

View GitHub Profile
@hampusborgos
hampusborgos / AdalAuthentication.jsx
Last active July 12, 2019 08:01
An example using adal.js with React.
// Set up the ADAL instance, we will use the throughout the app
export var adalInstance = new AuthenticationContext({
instance: 'https://login.microsoftonline.com/',
// The client ID of the app from the Azure Portal
clientId: 'aabbccee-aabb-1122-3344-556677889900',
// Where do we want to go after logging out
postLogoutRedirectUri: window.location.origin,
@hampusborgos
hampusborgos / BaseStore.js
Created April 18, 2016 06:13
addChangeListener / removeChangeListener that can find a bound function on it's own.
import Constants from '../Constants';
import {EventEmitter} from 'events';
let _listenerArguments = {};
let _listenerIds = 1;
export default _.assign({}, EventEmitter.prototype, {
// Allow Controller-View to register itself with store
addChangeListener(listener) {
@hampusborgos
hampusborgos / web.js
Created January 3, 2016 13:26
Force specific domain and HTTPS on Heroku using Express
app.use(function (req, res, next) {
var newURL;
// If not on HTTPS, or not on the main domain, redirect
if (process.env.NODE_ENV === 'production' &&
(req.headers['x-forwarded-proto'] !== 'https' || req.headers.host !== 'hjnilsson.com')) {
newURL = ['https://hjnilsson.com', req.url].join('');
return res.redirect(newURL);
}
@hampusborgos
hampusborgos / web.js
Last active August 31, 2018 09:39
Force HTTPS on Heroku using Express
app.use(function (req, res, next) {
var sslUrl;
if (process.env.NODE_ENV === 'production' &&
req.headers['x-forwarded-proto'] !== 'https') {
sslUrl = ['https://hjnilsson.com', req.url].join('');
return res.redirect(sslUrl);
}
@hampusborgos
hampusborgos / donottrack.js
Last active June 3, 2018 09:54
How to respect Do Not Track header and ignore IE
// Respect do not track for all browsers. Except for IE 10 and 11 where we ignore it
var dnt_isIe10or11 = (navigator.appVersion.indexOf("MSIE 10") !== -1) || (navigator.userAgent.indexOf("Trident") !== -1 && navigator. userAgent.indexOf("rv:11") !== -1);
var DNT = (navigator.doNotTrack || navigator.msDoNotTrack || window.doNotTrack);
DNT = !DNT || DNT == "unspecified" || DNT == "0" ? false : true;
if (!DNT || dnt_isIe10or11) {
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
// GA loading code
}