Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Elsmore ukmadlz

View GitHub Profile
@ukmadlz
ukmadlz / fb.min.js
Created Mar 6, 2018
Fizz Buzz without a for, with ternary operators and even smaller!
View fb.min.js
Array(100).fill().map((v,i)=>!(++i%15)?'FizzBuzz':!(i%3)?'Fizz':!(i%5)?'Buzz':i);
@ukmadlz
ukmadlz / fb.js
Created Mar 6, 2018
FizzBuzz without a for and on one line
View fb.js
console.log([...Array(100).keys()].map(function (i) { return i % 3 === 0 && i % 5 === 0 ? 'FizzBuzz' : i % 3 === 0 ? 'Fizz' : i % 5 === 0 ? 'Buzz' : i; }));
@ukmadlz
ukmadlz / readme.md
Last active Mar 1, 2018
NodeJS Dev: Time API
View readme.md

WebApi Time

Build a simple API to return the current timestamp in Unix time as a JSON object when a GET request is made to /time

Extension

Time is a hard concept.

Produce a system that takes a timestamp and an offset return the UTC, the local timestamp and new timestamp with the relevant offset.

@ukmadlz
ukmadlz / readme.md
Created Mar 1, 2018
NodeJS Dev Questions: SWAPI
View readme.md

Using the swapi.co API answer these questions

API: https://swapi.co/api/

Docs: https://swapi.co/documentation

Questions:

  • What is the difference between the youngest and oldest characters in Star Wars?
  • What’s the most common Species in the Star Wars universe listing the names of the characters that belong to the species?
  • Implement a basic Character search?
View gist:dd9563c15c8efbe5cb8f539510dafe34
Alternative technical tasks
- Time is a hard concept, produce a system that takes a timestamp and an offset return the UTC, the local timestamp and new timestamp with the relevant offset.
- Write a program that prints all the numbers from 1 to 100. For multiples of 3, instead of the number, print "Fizz", for multiples of 5 print "Buzz". For numbers which are multiples of both 3 and 5, print "FizzBuzz".
- Write a single endpoint the accepts Basic Auth access and returns a JSON response of https://www.npmjs.com/package/cowsay (NOTE: you do not need a data structure underneath)
View service-worker-registration.js
// Add Service Worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./sw.js', { scope: './' }).then(function(reg) {
if (reg.installing) {
console.log('Service worker installing');
} else if (reg.waiting) {
console.log('Service worker installed');
} else if (reg.active) {
console.log('Service worker active');
View service-worker-install-task.js
var cacheNameStatic = 'cloudinary-pwa-react-v1';
var currentCacheNames = [ cacheNameStatic ];
var cachedUrls = [
// 3rd party CDN
'https://unpkg.com/babel-core@5.8.38/browser.min.js',
'https://unpkg.com/lodash@4.17.4/lodash.js',
'https://unpkg.com/react@15.3.1/dist/react.min.js',
'https://unpkg.com/react-dom@15.3.1/dist/react-dom.min.js',
View service-worker-fetch-task.js
self.addEventListener("fetch", function (event) {
event.respondWith(
caches.open(cacheNameStatic).then(function(cache) {
return cache.match(event.request).then(function(response) {
var fetchPromise = fetch(event.request).then(function(networkResponse) {
cache.put(event.request, networkResponse.clone());
return networkResponse;
})
return response || fetchPromise;
})
View service-worker-activate-task.js
// A new ServiceWorker is now active
self.addEventListener("activate", function (event) {
event.waitUntil(
caches.keys()
.then(function (cacheNames) {
return Promise.all(
cacheNames.map(function (cacheName) {
if (currentCacheNames.indexOf(cacheName) === -1) {
return caches.delete(cacheName);
}
@ukmadlz
ukmadlz / head-tags.html
Created May 10, 2017
Cloudinary PWA React Blog
View head-tags.html
<!-- Make this a PWA -->
<link rel="manifest" href="/manifest.webapp">
<!-- Display -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="COLOR">
You can’t perform that action at this time.