Skip to content

Instantly share code, notes, and snippets.

moshmage

Block or report user

Report or block moshmage

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@moshmage
moshmage / force-type.js
Created Oct 16, 2018
force a variable to follow the value of a model
View force-type.js
const isObject = (o) => (o instanceof Object && !Array.isArray(o));
const areObjects = (...o) => !o.some(oo => !isObject(oo));
const areArrays = (...a) => !a.some(aa => !Array.isArray(aa));
function typeCheck(source, mock) {
if (areArrays(source, mock)) {
if (!source.length) return true;
return !mock.some((v, i) => !typeCheck(source[i], v))
}
@moshmage
moshmage / rut-validation.ts
Last active Nov 9, 2017
Chillean RUT validation
View rut-validation.ts
/**
* Provide string of type 12.333.333-k|123456789|12345678-9|12.345678-9
* ???
* profit.
* @param {string} _rut
* @returns {boolean}
*/
function isValidRUT(_rut) {
const isRegexValid = _rut.match(/^\d{1,2}\.?\d{3}\.?\d{3}\-?[0-9kK]$/ig);
if (!isRegexValid) return false;
@moshmage
moshmage / maskValue.ts
Last active Oct 16, 2018
masking a string
View maskValue.ts
/**
* Replaces value inside {value} with a spaced representation of the masked array
* and then replaces the Nth caret with the provided key, returning the new masked
* value.
* @param {(RegExp | string)[]} mask
* @param {string} key
* @param {number} caretPos
* @param {string} value
* @returns <{str: string, pos: number}>
*/
@moshmage
moshmage / CharacterSheet.js
Last active Jan 15, 2017
Character Sheet for a RPG looselly based on FUDGE system
View CharacterSheet.js
"use strict";
import {DiceTransformations} from './roll-transforms.js';
const Dice = new require('roll')();
const BASE_HEALTH = 10;
const BASE_SKILL_MODIFIER = 1.25;
const MINIMUM_SKILL_MODIFIER = 0.1;
const BASE_CRITICAL_FAILURE = -3;
const CRITICAL_DICES = 2;
@moshmage
moshmage / tweet-tweet.js
Last active Nov 10, 2016
quick and dirty handshaker between twitter and an application
View tweet-tweet.js
/**
* Created by Mosh Mage on 10/14/2016.
* quick and dirty handshaker between twitter and an application
* this could be loaded by modules, but time if of the essence
* todo: module loader, add express, make a decent api
*/
"use strict";
var http = require('http');
var request = require('request');
var url = require('url');
@moshmage
moshmage / agenda-class.js
Last active Oct 7, 2016
Simple Agenda Class
View agenda-class.js
class Agenda {
constructor() {
this._AGENDA = [new Pessoa()];
}
/**
*
* @param name {String}
* @param address {String}
* @param mobileNumber {String}
@moshmage
moshmage / withinRadius.js
Last active Jul 5, 2019
compares two objects lat/lon and returns true if within provided kms
View withinRadius.js
/**
* is One Point within Another
* @param point {Object} {latitude: Number, longitude: Number}
* @param interest {Object} {latitude: Number, longitude: Number}
* @param kms {Number}
* @returns {boolean}
*/
function withinRadius(point, interest, kms) {
'use strict';
You can’t perform that action at this time.