This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // breakpoints | |
| @mixin desktop_up{ | |
| // includes very large screens | |
| @media (min-width: 768px){ | |
| @content; | |
| } | |
| } | |
| @mixin desktop{ | |
| @media (min-width: 768px) and (max-width: 1024px){ | |
| @content; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import unittest | |
| def traverse(board, start): | |
| ''' | |
| Traverse a 2d array in an anti-clockwise manner | |
| array: board | |
| start[r,c] : start position | |
| ''' | |
| r, c = start | |
| size = len(board[0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import unittest | |
| def traverse(board, start): | |
| ''' | |
| Traverse a 2d array in an anti-clockwise manner | |
| array: board | |
| start[r,c] : start position | |
| ''' | |
| r, c = start | |
| size = len(board[0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # On 7/13/15 John Bohlhuis contribute his own Python code that he is using to automate the reading of distance values. | |
| # We gladly share this for your use in your projects. | |
| # Thank you John for sharing. | |
| # *************************************************************************** | |
| # First, the Python module that does the actual work: | |
| # *************************************************************************** | |
| #!/usr/bin/python3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| self.addEventListener('fetch', function (event) { | |
| // TODO: respond with an entry from the cache if there is one. | |
| // If there isn't, fetch from the network. | |
| const res = caches.open('wittr-static-v1').then(cache => { | |
| return cache.match(event.request).then(response => { return response; }); | |
| }); | |
| console.log(res); | |
| if (res !== undefined) { | |
| event.respondWith(res); | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (coffee break).then( freshMind => { | |
| self.addEventListener('fetch', function (event) { | |
| // TODO: respond with an entry from the cache if there is one. | |
| // If there isn't, fetch from the network. | |
| event.respondWith( | |
| caches.open('wittr-static-v1').then(cache => { | |
| return cache.match(event.request).then(response => { | |
| if (!response) { | |
| return fetch(event.request); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| IndexController.prototype._registerServiceWorker = function() { | |
| if (!navigator.serviceWorker) return; | |
| var indexController = this; | |
| navigator.serviceWorker.register('/sw.js').then(function(reg) { | |
| // TODO: if there's no controller, this page wasn't loaded | |
| // via a service worker, so they're looking at the latest version. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| IndexController.prototype._cleanImageCache = function() { | |
| return this._dbPromise.then(function(db) { | |
| if (!db) return; | |
| // TODO: open the 'wittr' object store, get all the messages, | |
| // gather all the photo urls. | |
| var store = db.transaction('wittrs').objectStore('wittrs'); | |
| return store.getAll().then((messages) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| function serveAvatar(request) { | |
| // Avatar urls look like: | |
| // avatars/sam-2x.jpg | |
| // But storageUrl has the -2x.jpg bit missing. | |
| // Use this url to store & match the image in the cache. | |
| // This means you only store one copy of each avatar. | |
| var storageUrl = request.url.replace(/-\dx\.jpg$/, ''); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Three for loops in JavaScript */ | |
| const pirates = ['Davy Jones', 'Blackbeard', 'Cap`n Barbossa', 'Hook', 'Long Jon Silver', 'Jack Sparrow']; | |
| // classical for loop | |
| for (let i = 0; i < pirates.length; i++) { | |
| console.log(`Yarrr! Ye can call me ${pirates[i]}`); | |
| } | |
| // for-in loop |