Skip to content

Instantly share code, notes, and snippets.

View james-jlo-long's full-sized avatar

James Long james-jlo-long

View GitHub Profile
@james-jlo-long
james-jlo-long / validate.js
Last active October 2, 2017 15:30
A form validator that relies on HTML5 Form Validation
/**
* Validates the form. The validation relies on HTML5 Form Validation.
*
* @see https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation
* @alias validate
* @param {Element} form
* Form to validate.
* @param {Object} settings
* Settings for the form.
* @param {String} settings.highlightClass
@james-jlo-long
james-jlo-long / add.js
Last active March 13, 2018 09:42
JavaScript translation
// This demo shows how to simply add some translations.
__.add({
"Hello": "Bonjour"
});
@james-jlo-long
james-jlo-long / con.js
Last active June 7, 2017 10:52
A version of console that can be used on mobile devices such as iPads and iPhones
/**
* @file A version of console that can be used on mobile devices.
* @author James "JLo" Long <[email protected]>
* @version 1.0.0
* @license MIT
*/
var con = (function () {
"use strict";
@james-jlo-long
james-jlo-long / low-poly-es-flag.svg
Last active May 12, 2017 15:15
A version of the flag of Spain with very low detail. Designed with just enough detail for a small icon
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@james-jlo-long
james-jlo-long / OSCAR.md
Last active May 31, 2017 13:20
I'm working on a very basic CSS methodology. I'm saving it here to make it easier to find and modify.

OSCAR

OSCAR stands for "Only Style Classes, AlRight?". It's a CSS methodology that is designed to be very simple and lead into other mentalities such as OOCSS, SMACSS or ITCSS. The idea is to take the most basic parts of the other methodologies and create some simple rules that can be quickly taught to a new-comer without weighing them down with complexities. This is the starting point for better CSS.

Two Simple Rules

1. Only add styles to class selectors

No IDs, no elements. Only classes. You can have up to 1 class, 1 pseudo-element and 1 state or pseudo-class.

@james-jlo-long
james-jlo-long / PW.js
Last active March 22, 2017 10:27
A couple of functions to generate simple passwords. Beware that this is based on Math.random() - it is not cryptographically secure
var PW = (function () {
"use strict";
var sym = "!£$%^&*()-_=+[{]};:@#~,<.>/?\\|";
var getRand = (n) => Math.floor(Math.random() * n);
var basic = () => (
btoa(getRand(Date.now()))
.replace(/=+$/, "")
@james-jlo-long
james-jlo-long / Query.js
Last active January 10, 2017 17:37
A manager for URL query strings
/*
TODO: Allow Query#parseString to correctly parse square brackets.
TODO: Handle nested objects correctly.
*/
var Query = (function () {
"use strict";
var hasOwn = Object.prototype.hasOwnProperty;
@james-jlo-long
james-jlo-long / array-first-last.js
Last active October 8, 2015 09:31
Douglas Crockford mentioned that when JavaScript has proper tail calls, he'll stop using while. This gist is me going through some of my old functions to see how to remove while. This is mainly me thinking aloud, but feel free to comment any changes or suggestions.
// Array first and last
//
// var array = [1, 'two', 3, 'four', 5];
// function isString(o) {
// return typeof o === 'string';
// }
// util.Array.first(array); // -> 1
// util.Array.first(array, isString); // -> 'two'
// util.Array.last(array); // -> 5
// util.Array.last(array, isString); // -> 'four'
@james-jlo-long
james-jlo-long / dom.js
Created October 1, 2015 15:16
Just enough of a framework to get DOM nodes common ancestors - based on https://gist.github.com/benpickles/4059636
var dom = (function () {
'use strict';
var dom = {};
function isElement(element) {
return element instanceof HTMLElement;
}
@james-jlo-long
james-jlo-long / grid.less
Created August 24, 2015 10:45
It can be handy to have a grid layout for very small devided (< 480). This snippit adds "xxs" columns to Bootstrap 3 which solve that purpose
// Generate the extra-extra small columns
// These go from a screen width of 0 to (@screen-xs-min - 1), existing below XS.
.make-xxs-column(@columns; @gutter: @grid-gutter-width) {
min-height: 1px;
padding-left: (@gutter / 2);
padding-right: (@gutter / 2);
position: relative;