Skip to content

Instantly share code, notes, and snippets.

View evolutionxbox's full-sized avatar
👀
Trying my hardest

Jonathan Cousins evolutionxbox

👀
Trying my hardest
View GitHub Profile
@evolutionxbox
evolutionxbox / Quick-FED-Interview-Questions.md
Last active January 29, 2018 15:56
Quick Front-end Interview Questions

General

  1. Describe three ways to test accessibility?
  2. How would you approach fixing browser-specific styling issues?
  3. In what ways can a websites loading performance be improved?

HTML

  1. Have you used different HTML templating languages before?
  2. Describe at least one way you check the accessibility of written HTML?

CSS

@evolutionxbox
evolutionxbox / classNameToSelector.js
Created October 26, 2017 08:58
Takes className(s) and converts it to a CSS string (although a little buggy)
/**
* "foo bar baz", "bar foo moo" -> ".foo.bar.baz .bar.foo.moo"
* @param {String...} classString
* @return {String}
*/
module.exports = function classNameToSelector(classString) {
var selector = [];
for (var i = 0, len = arguments.length; i < len; i++) {
selector.push(_classNameToSelector(arguments[i]));
}
@evolutionxbox
evolutionxbox / simpleSerializeFormData.js
Created June 23, 2017 12:04
Simple Serialize Form Data
// Serialize form data
function serialize (form) {
return [...form.elements]
.filter(element => element.type !== 'radio' || element.checked)
.map(element => element.name + '=' + encodeURIComponent(element.value))
.join('&');
}
@evolutionxbox
evolutionxbox / generateUniqueID.js
Created June 13, 2017 09:01
Simple Unique ID Generator (well, not entirely unique...)
function generateUniqueID() {
function chr4(){
return Math.random().toString(16).slice(-4);
}
return chr4() + chr4() +
'-' + chr4() +
'-' + chr4() +
'-' + chr4() +
'-' + chr4() + chr4() + chr4();
}
@evolutionxbox
evolutionxbox / Array.prototype.reject.js
Last active April 12, 2017 12:28
Like filter, but negated
/*
# `Array.prototype.reject`
## Summary
Like `filter`, except negated.
**Example:**
```js
@evolutionxbox
evolutionxbox / loadstyles.js
Created March 23, 2017 11:29
Load those styles all async like!
// TODO: convert into promise =)
// Load Style
function loadStyle(url, callback) {
if (!url || url === '') return;
var linkElement = document.createElement('link');
linkElement.href = url;
linkElement.setAttribute('rel', 'stylesheet');
@evolutionxbox
evolutionxbox / loadscripts.js
Last active March 23, 2017 11:27
Load those scripts all async like!
// TODO: convert into promise =)
// Load Script
function loadScript(url, callback) {
if (!url || url === '') return;
var scriptElement = document.createElement('script');
scriptElement.src = url;
if(typeof callback === 'function') {
@evolutionxbox
evolutionxbox / roguetext-wrapper.js
Created March 23, 2017 11:09
Wrap those rogue text nodes (inside table-cells)!
// Wrap all "rogue" textNodes in a paragraph
(function wrapAllRogueTextNodes () {
var allowedElements = [ 'A', 'B', 'BIG', 'I', 'SMALL', 'TT', 'ABBR', 'ACRONYM', 'CITE', 'DFN', 'EM', 'KBD', 'STRONG', 'TIME', 'BR', 'SUB', 'SUP' ];
function arrayFrom (arrayLike) {
return Array.prototype.slice.call(arrayLike);
}
function wrapInParagraph (nodes) {
if (nodes.length > 0) {
@evolutionxbox
evolutionxbox / outofhours-redirect.js
Created March 8, 2017 10:36
Link Out-of-Hours Redirect
//---------------------------------------------------------------------
function dateObj(d) {
var parts = d.split(/:|\s/),
date = new Date();
if (parts.pop().toLowerCase() == 'pm') parts[0] = (+parts[0]) + 12;
date.setHours(+parts.shift());
date.setMinutes(+parts.shift());
return date;
}
@evolutionxbox
evolutionxbox / params.js
Created March 2, 2017 16:27
Get URL params (querystring), returns object
// Get URL params (querystring)
if (!location.params) {
Object.defineProperty(location, 'params', {
enumerable: false,
get: function () {
var search = location.search;
var all = /(?:[?&;])(?:[^&;#]+)/g;
var pair = /[?&;]([^&;=#]+)=?([^&;#]*)/;
var results = {};