Skip to content

Instantly share code, notes, and snippets.

View jeroenransijn's full-sized avatar
:atom:

Jeroen Ransijn jeroenransijn

:atom:
  • San Francisco
View GitHub Profile
const getValidationRules = (el) => {
const rules = [];
const required = el.hasAttribute('required')
const min = el.getAttribute('min')
const max = el.getAttribute('max')
const maxlength = el.getAttribute('maxlength')
const minlength = el.getAttribute('minlength')
const pattern = el.getAttribute('pattern')
if (required) {
@jeroenransijn
jeroenransijn / responsive-rem.css
Last active February 20, 2020 19:01
Hacking CSS rem into a responsive unit
/**
* Responsive rem hack
* ---
* Makes the `rem` unit behave like a dynamic value based on the viewport, with a max width.
* This makes it easy to apply dynamic values to margin and paddings.
* warning, `rem` becomes useless for font-sizes.
*
* Usage:
*
* .vertical-spacing {
@jeroenransijn
jeroenransijn / Events.es2015.js
Created February 2, 2016 07:09
Events.es2015.js
/**
* Class representing an events interface similar to EventEmitter/Backbone.Events
* @author Jeroen Ransijn [@Jeroen_Ransijn]
* @example
* const events = new Events();
*
* events.on('change', (...args) => { console.log(args); });
* events.trigger('change', 'firstArg', 'secondArg');
* // Returns ['firstArg', 'secondArg']
*
@jeroenransijn
jeroenransijn / 0_reuse_code.js
Last active August 29, 2015 14:17
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jeroenransijn
jeroenransijn / mixin.js
Created August 5, 2014 12:43
mix().in()
/**
* Author: Jeroen Ransijn
* Date: August 5 2014
* Pass functions as arguments
*/
function mix () {
var args = Array.prototype.slice.call(arguments), argsLength = args.length;
return {
in: function (fn) {
for (var i = 0; i < argsLength; i++) {
function typed (types, cb) {
if (Object.prototype.toString.call(types) === '[object Array]' && typeof cb === "function") {
return function () {
var i = arguments.length, areTypesCorrect = true;
while (i--) {
// need to check for some literals: string/number/boolean
var type = typeof arguments[i], arg;
if (type === 'string') {
function add() {
// Start from zero
var total = 0;
// Floating-points, bah!
// 1e12 = 1000000000000.
var factor = 1e12;
// Undefined, set in the loop
var value;
<body>
<h1>Website title</h1>
<h2>Slogan</h2>
<div id="content">
<article class="blog-post">
<h1>Blog title</h1>
<section class="abstract">
Lorem ipsum
@jeroenransijn
jeroenransijn / Cache.coffee
Created November 22, 2012 19:13
CoffeeScript Cache Class on localStorage
# Cache.coffee
# ------------------------------------------------------------
# Hard dependency: underscore.js
class Cache
# @description if a string is given it will be the namespace
# @param {string|object} options
constructor: (options) ->
settings = {
# will be used for the localStorage
namespace: 'global'