Skip to content

Instantly share code, notes, and snippets.

View SeanJM's full-sized avatar

Sean MacIsaac SeanJM

  • Sean J MacIsaac
  • Montreal, QC
View GitHub Profile
@SeanJM
SeanJM / math.js
Last active November 14, 2017 19:58 — forked from FrankFang/math.js
Handlebars Math.
const handlebars = require("handlebars");
const operators = {
"+": (a, b) => a + b,
"-": (a, b) => a - b,
"*": (a, b) => a * b,
"/": (a, b) => a / b,
"%": (a, b) => a % b
};
handlebars.registerHelper("math", function (a, op, b) {
@SeanJM
SeanJM / react-scroll-lock-mixin.js
Last active August 28, 2017 20:29
A mixin to lock the scrolling of a component's parents for react
// Based on https://codepen.io/somethingkindawierd/post/react-mixin-scroll-lock
// How this works is that it will lock the scroll of the component parents
// and allow the current element to scroll
import ReactDOM from "react-dom";
const ScrollLockMixin = {
scrollLock: function (scrollElement) {
let p;
this.scrollElement = scrollElement || ReactDOM.findDOMNode(this);
@SeanJM
SeanJM / getCreditCardIssuer.js
Created March 3, 2017 14:27
A function which returns an object based on the credit card number with credit card issuer properties
function getCreditCardIssuer(number) {
number = number.toString();
if (/^4[0-9]{12}(?:[0-9]{3})?$/.test(number)) { // Visa
return {
issuer : 'Visa',
cidLength : 3,
length : 16
};
} else if (/^5[1-5][0-9]{14}$/.test(number)) { // MasterCard
return {
@SeanJM
SeanJM / generateId.ts
Last active September 20, 2017 14:39
A TypeScript function to generate a random ID
interface ILib {
alpha: string[],
number: string[],
symbols: string[]
}
type Key = keyof ILib;
const lib : ILib = {
alpha: [
@SeanJM
SeanJM / .babelrc
Last active January 14, 2020 03:03
TypeScript, VueJS and JSX webpack configuration
{
"presets": [],
"plugins": ["transform-vue-jsx", "transform-es2015-modules-commonjs"]
}
@SeanJM
SeanJM / promisify.js
Last active October 31, 2017 20:50
A function which will turn node style callbacks into Promises.
module.exports = function promisify(fn) {
const args = [];
for (var i = 1, n = arguments.length; i < n; i++) {
args.push(arguments[i]);
}
return new Promise(function (resolve, reject) {
args.push(function (err) {
const args = [];
@SeanJM
SeanJM / getUsStates.js
Created June 27, 2016 20:18
A function which returns an array of US states.
function getUsStates(number) {
var states = [
'Alabama',
'Alaska',
'American Samoa',
'Arizona',
'Arkansas',
'California',
'Colorado',
'Connecticut',
@SeanJM
SeanJM / hasKey.js
Created April 21, 2016 14:04
A function to see if an object has a key
function hasKey (object, key) {
for (var k in object) {
if (k === key && object.hasOwnProperty(key)) {
return true;
}
}
return false;
}
function partial(fn) {
var left = new Array(arguments.length - 1);
var leftIndex = 0;
for (; leftIndex < left.length; leftIndex++) {
left[leftIndex] = arguments[leftIndex + 1];
}
return function () {
var right = new Array(arguments.length);
@SeanJM
SeanJM / generateId.js
Last active March 14, 2017 12:58
A function which generates a random id
(function () {
var lib = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
var n = lib.length - 1;
function generateId(index) {
var id = [];
while (index-- > 0) {
id.push(lib[Math.round(Math.random() * n)]);
}
return id.join('');