Skip to content

Instantly share code, notes, and snippets.

@wildhart
wildhart / consoleColors.js
Created February 11, 2020 01:20
Colorful console.logs in Meteor
console.col = {
colours: {
red: "31", // prefix with 1; for light/bold colours
green: "32",
yellow: "33",
blue: "34",
magenta: "35",
cyan: "36",
default: "0",
white: "0",
@wildhart
wildhart / accountsSessionStorage
Created October 24, 2019 20:55
monkey patch Meteor.Accounts to store login token in sessionStoage instead of localStorage
// monkey patch Meteor.Accounts to store login token in sessionStoage instead of localStorage
// https://forums.meteor.com/t/security-dont-store-tokens-in-localstorage/50539/13
// original code: https://github.com/meteor/meteor/blob/af26e8b052a5135033e561cf4e4347eee585ab3b/packages/accounts-base/accounts_client.js#L477
Accounts._storeLoginToken = function(userId, token, tokenExpires) {
Meteor._localStorage.setItem(this.USER_ID_KEY, userId);
sessionStorage.setItem(this.LOGIN_TOKEN_KEY, token);
if (! tokenExpires)
tokenExpires = this._tokenExpiration(new Date());
@wildhart
wildhart / Interval.vue
Last active February 24, 2021 17:33
Interval component for vue.js - self cancelling
<script>
// <Interval delay="10m" @tick="doSomething()" immediate />
// delay = 100[ms|s|m|h|d] - default is ms
// immediate = true/false, emit the 'tick' event immediately upon creation
export default {
props: {
delay: {
required: true,
},
@wildhart
wildhart / dateProtypes.js
Last active March 21, 2023 02:11
Date prototype functions
Date.prototype.addMins = function(mins) {
var dat = new Date(this.valueOf()); // make a new date coz we can't change the original
dat.setMinutes(dat.getMinutes() + mins*1); // force mins to be integer instead of string
return dat;
};
Date.prototype.addDays = function(days) {
var dat = new Date(this.valueOf()); // make a new date coz we can't change the original
dat.setDate(dat.getDate() + days*1); // force days to be integer instead of string
return dat;