Skip to content

Instantly share code, notes, and snippets.

View matthewblewitt's full-sized avatar

Matt Blewitt matthewblewitt

View GitHub Profile
@matthewblewitt
matthewblewitt / vue-notes.md
Last active June 11, 2019 18:18
Vue notes

Directives

  • v-bind/:: Pass data from vue instance to html
  • v-on/@: Listen for DOM events e.g. v-on:click="doSomething"
  • v-once: Only render once
  • v-html: Output raw html

We cannot use {{}} syntax inside a html element, use a directive instead e.g:

<a v-bind:href="link">My Link</a>

// Test

@matthewblewitt
matthewblewitt / deep-clone-js-object.js
Created April 26, 2019 10:46
Deep clone JS object
const obj = {
prop: 'val'
};
const clone = JSON.parse(JSON.stringify(obj));
@matthewblewitt
matthewblewitt / attach-to-node-docker.js
Created April 26, 2019 08:29
VS-CODE attache to node docker
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to Docker",
"port": 5100,
"address": "localhost",
"restart": true,
@matthewblewitt
matthewblewitt / find-duplicates-in-array.js
Last active April 24, 2019 14:22
Find duplicates in a array with array filter method
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const fibonacci = [0, 1, 1, 2, 3, 5, 8, 13];
const duplicates = numbers.filter(number => fibonacci.indexOf(number) !== -1);
console.log(duplicates); // [1, 2, 3, 5, 8]
const thing = (obj && obj.thing && obj.thing.stuff) || '';
@matthewblewitt
matthewblewitt / npm-checklist.md
Created November 29, 2018 12:00
npm checklist
  1. Always use latest npm via npm install -g npm@latest
  2. Make distinction between dependencies and devDependencies
  3. Use reproducible builds via npm ci (requires lockfiles on all projects)
  4. Exclude devDependencies from production builds using npm ci --production
  5. Regularly review npm audit reports and make production issues a release blocker
@matthewblewitt
matthewblewitt / PromiseQueue.js
Created November 22, 2018 08:39
Promise Queue
var delay = (seconds) => new Promise((resolves) => {
setTimeout(function(){
console.log(seconds);
resolves();
}, seconds*1000);
});
var tasks = [
delay(2),
delay(4),
@matthewblewitt
matthewblewitt / sql-cheatsheet.md
Last active September 6, 2018 10:12
SQL-cheatsheet
CREATE DATABASE app;
USE app;

CREATE TABLE users (
    id int,
    last_name varchar(255),
    first_name varchar(255)
);
@matthewblewitt
matthewblewitt / util.promisify.js
Created July 18, 2018 14:33
Node util.promisify
const fs = require('fs')
const util = require('util')
const readFile = util.promisify(fs.readFile)
readFile('./test/test.md', 'utf8')
.then(text => {
console.log(text)
})
.catch(err => {
console.log('Error', err)