Skip to content

Instantly share code, notes, and snippets.

View jonathan-fielding's full-sized avatar

Jonathan Fielding jonathan-fielding

View GitHub Profile
@jonathan-fielding
jonathan-fielding / gist:5867484
Created June 26, 2013 13:46
JS State Manager (none library based)
var stateManager = (function () {
var state = null;
var setState = function () {
if ($('body').width() < 768) {
if (state !== "mobile") {
state = "mobile";
displayMobile();
}
}
@jonathan-fielding
jonathan-fielding / gist:8912560
Last active August 29, 2015 13:56
Rem Calculator with fallback
@mixin rem($property, $px-values) {
// Convert the baseline into rems
$baseline-rem: $font-size-base / 1rem * 1;
// Print the first line in pixel values
#{$property}: $px-values;
// If there is only one (numeric) value, return the property/value line for it.
@if type-of($px-values) == "number" {
#{$property}: $px-values / $baseline-rem;
}
@else {
@jonathan-fielding
jonathan-fielding / gist:35592260770bf6649aee
Created June 9, 2015 09:44
Links for a new Developer
So here are a few links I have put together for new developers
MDN - A bible of web development https://developer.mozilla.org/en-US/
Dash - not a website, more of a tool for looking at documentation https://kapeli.com/dash
CSS Tricks - https://css-tricks.com/
Smashing Magazine - http://www.smashingmagazine.com/
Code School - https://www.codeschool.com/
A list apart - http://alistapart.com/ - this is where the first article on responsive design was published so definitely worth watching here for new trends
My blog - contains a wealth of information, and as typically I write blog posts as im learning something new its all in order I learned stuff https://www.jonathanfielding.com/
@jonathan-fielding
jonathan-fielding / example.js
Last active October 16, 2020 18:46
Add an element to end of array
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
console.log(fruits); // ["Banana", "Orange", "Apple", "Mango", "Kiwi"]
@jonathan-fielding
jonathan-fielding / example.js
Created October 16, 2020 18:52
Add an item to beginning of an array
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.unshift("Kiwi");
console.log(fruits); // ["Kiwi", "Banana", "Orange", "Apple", "Mango"]
@jonathan-fielding
jonathan-fielding / example.js
Created October 16, 2020 18:55
Remove last element from array
const fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
fruits.pop();
console.log(fruits); // ["Banana", "Orange", "Apple", "Mango"]
@jonathan-fielding
jonathan-fielding / example.js
Created October 16, 2020 19:03
Removing first item from an array
const fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
fruits.shift();
console.log(fruits); // ["Orange", "Apple", "Mango", "Kiwi"]
@jonathan-fielding
jonathan-fielding / example.js
Created October 16, 2020 19:07
Duplicating an array
const fruits = ["Banana", "Orange", "Apple", "Mango"];
const newFruits = [ ...fruits ];
console.log(newFruits); // ["Banana", "Orange", "Apple", "Mango"]
@jonathan-fielding
jonathan-fielding / example.js
Created October 16, 2020 19:18
Array.forEach()
const fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
fruits.forEach((fruit) => {
console.log(fruit); // Each fruit will be logged out one at a time
});
@jonathan-fielding
jonathan-fielding / example.js
Last active October 16, 2020 19:48
Array.map()
const fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
const numberedFruits = fruits.map((fruit, index) => {
return `${index + 1} - ${fruit}`;
});
console.log(numberedFruits); // ["1 - Banana", "2 - Orange", "3 - Apple", "4 - Mango", "5 - Kiwi"]