Skip to content

Instantly share code, notes, and snippets.

@ukmadlz
ukmadlz / fb.min.js
Created March 6, 2018 16:46
Fizz Buzz without a for, with ternary operators and even smaller!
Array(100).fill().map((v,i)=>!(++i%15)?'FizzBuzz':!(i%3)?'Fizz':!(i%5)?'Buzz':i);
@ukmadlz
ukmadlz / fb.js
Created March 6, 2018 16:39
FizzBuzz without a for and on one line
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 March 1, 2018 13:56
NodeJS Dev: Time API

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 March 1, 2018 13:52
NodeJS Dev Questions: SWAPI

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?
@ukmadlz
ukmadlz / gist:dd9563c15c8efbe5cb8f539510dafe34
Created January 12, 2018 11:10
Alternative technical tasks
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)
@ukmadlz
ukmadlz / service-worker-registration.js
Created May 10, 2017 17:10
Cloudinary PWA React Blog
// 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');
@ukmadlz
ukmadlz / service-worker-install-task.js
Created May 10, 2017 17:09
Cloudinary PWA React Blog
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',
@ukmadlz
ukmadlz / service-worker-fetch-task.js
Created May 10, 2017 17:09
Cloudinary PWA React Blog
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;
})
@ukmadlz
ukmadlz / service-worker-activate-task.js
Created May 10, 2017 17:08
Cloudinary PWA React Blog
// 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 17:08
Cloudinary PWA React Blog
<!-- 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">