Skip to content

Instantly share code, notes, and snippets.

@martinandersen3d
martinandersen3d / String.pluralization.js
Created April 24, 2019 00:04 — forked from alexdemers/String.pluralization.js
Laravel's pluralization logic in JavaScript
// replace occurences of :vars in the string.
// "This :thing is great!".format
String.prototype.format = function(replacements) {
var str = this;
for (var key in replacements) {
if (replacements.hasOwnProperty(key)) {
str = str.replace(':' + key, replacements[key]);
}
}
@martinandersen3d
martinandersen3d / axiosget.js
Created April 29, 2019 20:57 — forked from pastranastevenaz/axiosget.js
Example of an axios get request using arrow functions
var albums = [];
axios.get('https://jsonplaceholder.typicode.com/albums')
.then(response =>{
this.albums = response.data
})
.catch(error =>{
console.log(error);
})
// Add a 401 response interceptor
window.axios.interceptors.response.use(function (response) {
return response;
}, function (error) {
if (401 === error.response.status) {
swal({
title: "Session Expired",
text: "Your session has expired. Would you like to be redirected to the login page?",
type: "warning",
showCancelButton: true,
@martinandersen3d
martinandersen3d / settings.json
Created December 14, 2019 00:13 — forked from lighthouse-dev/settings.json
vs-code settings.json inspiration fra anden bruger
{
// "workbench.iconTheme": "material-icon-theme",
"window.zoomLevel": 0,
// "materialTheme.fixIconsRunning": false,
// "[javascript]": {
// "editor.tabSize": 2
// },
// "[html]": {
// "editor.tabSize": 2
@martinandersen3d
martinandersen3d / VS Code JSON Settings
Created December 14, 2019 05:59 — forked from uysalserkan/VS Code JSON Settings
JSON settings instpiration
{
// Most Commonly Used
// Controls auto save of dirty files. Accepted values: 'off', 'afterDelay', 'onFocusChange' (editor loses focus), 'onWindowChange' (window loses focus). If set to 'afterDelay', you can configure the delay in 'files.autoSaveDelay'.
"files.autoSave": "off",
// Controls the font size in pixels.
"editor.fontSize": 14,
// Controls the font family.
# Git aliases
alias gs="git status"
alias ga="git add"
alias gaa="git add ."
alias gc="git commit"
alias gp="git push"
alias gpl="git pull"
alias gcm="git commit -m"
alias gl="git log"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>HTML inputmode attribute</title>
<style>
* {
padding: 0;
//Array custom sort() function
let log = console.log;
let movies = ['Star Wars', 'Star Trek', 'Jaws', 'Jurassic Park', 'Gross Pointe Blank', 'Eternal Sunshine of the Spotless Mind', 'Memento', 'Dog Soldiers', 'The Host', 'Gran Torino', 'Close Encounters of the Third Kind', 'Good Will Hunting', 'Layer Cake', 'Casino Royale', 'Almost Famous'];
let numbers = [40,16,67,345,22,23,142,63,59,283];
let people = [
{"id":123, "name":"Rick Deckard", "email":"rick@bladerunner.org"},
{"id":456, "name":"Roy Batty", "email":"roy@replicant.io"},
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>LuxonJS The Modern MomentJS</title>
<meta name="viewport" content="width=device-width">
<style>
#output{
font-size: 2rem;
}
//Array reduce method
//reduce all the values in an array into a single result
// Uses a callback function just like map, forEach, filter, etc
// array.reduce(callback, initialValue)
// also has a second parameter which is an initialValue
let numbers = [12, 34, 56, 78, 91];
//find the sum of all the numbers