Skip to content

Instantly share code, notes, and snippets.

@nonlogos
nonlogos / timelog-console.md
Created December 10, 2017 17:15
Using console log to log out time it takes to run a function

To set up the time log function

const timeIt = (label, fn) => {
  console.time(label);
  fn();
  console.timeEnd(label);
}
@nonlogos
nonlogos / vsSetup.md
Created December 10, 2017 17:13
my steps for setting up Visual Studio

Visual Studio Set Up

add Quakka plugin

Quokka.js is a rapid prototyping playground for JavaScript and TypeScript. It runs your code immediately as you type and displays various execution results in your code editor.

get installed

@nonlogos
nonlogos / factorial
Last active November 30, 2017 21:04
fibonacci with memoisation
// 5 * 4 * 3 * 2 * 1
const factorial = (n) => {
//base case
if (n === 1) return 1;
// logic
return n * factorial(n-1);
}
console.log(factorial(5))
@nonlogos
nonlogos / indexDB.js
Last active November 21, 2017 15:53
IndexDB
const dbPromise = idb.open('post-store', 1, function(db) {
if (!db.objectStoreNames.contains('posts')) {
db.createObjectStore('posts', {keyPath: 'id'});
}
});
// service worker implementation
...
event.respondWith(fetch(event.request)
.then(res => {
@nonlogos
nonlogos / srcset.html
Created November 19, 2017 00:42
Responsive Image
<img src="/src/images/main-image.jpg"
srcset="/src/images/main-image-lg.jpg 1200w",
"/src/images/main-image.jpg 900w",
"/src/images/main-image-sm.jpg 480w"
alt="Explore the city"
class="main-image" />
@nonlogos
nonlogos / cache_then_network
Last active November 18, 2017 16:09
Service Work with Cache API
// show cache version first and fetch new data, then swap out the new data with the cached ones
caches.match('/very-important-data.json')
.then(response => {
return response.json();
}).then(data => {
if (!didWeReceiveFreshNetworkData) {
doSomethingWithData(data);
}
}).catch(() => {
@nonlogos
nonlogos / deep_copy
Created November 16, 2017 15:04
deep copy for objects and arrays
function copy(object) {
var output, value, key;
output = Array.isArray(object) ? [] : {};
for (key in object) {
value = object[key];
output[key] = (typeof value === 'object') ? copy(value) : value;
}
return output;
}
@nonlogos
nonlogos / HomeScreenIcon
Last active November 17, 2017 17:54
Progress Web App
# meta tag for apple
<link href="https://placehold.it/152"
sizes="152x152"
rel="apple-touch-icon">
# square dimension for home screen icons for the diff devices
size device
57 iPhone1, 2
72 ipad1,2
@nonlogos
nonlogos / Client #client
Created November 13, 2017 23:10
Web Protocols #general
# Clients
Clients are computer programs that connect to servers
initiate a connection
Any computer can be a client
@nonlogos
nonlogos / check for lines of code
Last active October 30, 2017 19:18
Terminal Scripts #bash
git ls-files | xargs wc -l