Skip to content

Instantly share code, notes, and snippets.

@DroopyTersen
DroopyTersen / SPFxKeepReactGulpFile.js
Created February 15, 2019 15:32
Prevent SPFx from marking React as an external so that React in included in your bundle
const gulp = require('gulp');
const build = require('@microsoft/sp-build-web');
build.addSuppression("Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.");
build.configureWebpack.mergeConfig({
additionalConfiguration: (generatedConfiguration) => {
generatedConfiguration.externals = generatedConfiguration.externals
.filter(name => !(["react", "react-dom"].includes(name)))
return generatedConfiguration;
}
@DroopyTersen
DroopyTersen / Eventer.js
Last active November 3, 2017 21:16
barebones ES6 Event Aggregator
class Eventer {
constructor() {
this.events = {};
}
ensureEvent(key) {
return this.events[key] || (this.events[key] = { subscriptions: [] });
}
on(key, cb) {
if (typeof cb !== "function") throw new Error("You must pass a function when you subscribe");
this.ensureEvent(key).subscriptions.push(cb);
@DroopyTersen
DroopyTersen / domUtils.js
Created March 22, 2017 15:09
DOM Utils
var find = exports.find = function(selector) {
return [].slice.call(document.querySelectorAll(selector), 0);
};
var findOne = exports.findOne = function(selector) {
return document.querySelector(selector);
};
var getClassList = exports.getClassList = function(elem) {
return elem.className.split(" ").map(c => c.trim());
@DroopyTersen
DroopyTersen / Swiper.js
Created December 28, 2016 17:28
lets you subscribe to touch events without having to include jquery and touch events. i'll turn this into an npm module soon
var EventAggregator = require("droopy-events");
var touchEvents = ["touchstart", "touchmove", "touchend"];
var defaultOptions = {
swipeLength: 30
}
// Store initial values to make reset easier
var defaultSwipe = {
start: { x: -1, y: -1 },
var createChangeToken = function(date,listId) {
//Change token format:
// http://sharepoint.stackexchange.com/questions/194152/sharepoint-sharepoint-online-how-can-i-create-changetoken-without-using-msft-li
// The tricky part is the .NET ticks (micrsseconds since 1/1/1)
// Got the static number by running C#:
// (DateTime.MinValue.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds
// Add the static milliseconds since 1/1/1 to the JS milliseconds since 1/1/1970
console.log(date);
console.log(new Date());
var middlewarify = function(pre, done) {
var middleware = [];
var func = function(...args) {
if (done) middleware.push(done);
return middleware.reduce( (chain, fn) => chain.then(fn)
, Promise.resolve(pre.apply(null, args)))
};
var middlewarify = function(pre, done) {
var middleware = [];
var func = function(...args) {
if (done) middleware.push(done);
return middleware.reduce( (chain, fn) => chain.then(fn)
, Promise.resolve(pre.apply(null, args)))
};
var middlewarify = function(pre, post) {
post = post || function(next) { next() }
var doIt = function(next, params) {
return pre(next, params);
}
var func = function(params) {
func.use(post)
return new Promise((resolve, reject) => {
// THIS IS A NODEJS WEB SERVER RUNNING ON PI
var bodyParser = require("body-parser");
var express = require("express");
var createGuid = require('node-uuid').v4;
var app = express();
app.use(bodyParser.json()); //to handle POST body
// THESE DONT EXIST YET
var azureCam = require("azure-cam"); // bschlintz npm published module
@DroopyTersen
DroopyTersen / Cache.js
Created September 19, 2016 19:10
Supports localStorage or sessionStorage. Supports optional expiration. Supports regex key cache clearing
var storage = localStorage;
var cache = {};
cache.setStorageType = function(localOrSessionStorage) {
storage = localOrSessionStorage
}
var _isExpired = function(cacheValue) {
return (cacheValue.expiration) && ((new Date()).getTime() > cacheValue.expiration);
};