Skip to content

Instantly share code, notes, and snippets.

View okjodom's full-sized avatar
:octocat:
octocatin

okjodom

:octocat:
octocatin
View GitHub Profile
@okjodom
okjodom / breakpoints.scss
Last active August 29, 2017 05:59
experimental breakpoints
// breakpoints
@mixin desktop_up{
// includes very large screens
@media (min-width: 768px){
@content;
}
}
@mixin desktop{
@media (min-width: 768px) and (max-width: 1024px){
@content;
@okjodom
okjodom / arrtraverse.py
Created April 18, 2018 10:03
Traverse a 2D Array in a circular manner.
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])
@okjodom
okjodom / arrtraverse.py
Last active April 18, 2018 10:11
Traverse a 2D Array in a circular clockwise path.
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])
# 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
@okjodom
okjodom / __offlinefirst.js
Created May 11, 2018 05:23
Offline first Using service workers - Broken
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 {
@okjodom
okjodom / _offlinefirst.js
Created May 11, 2018 05:27
Offline first Using service workers, after coffee break, Yaay!
(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);
}
@okjodom
okjodom / _trackSWInstalling.js
Last active May 11, 2018 08:53
Installing service worker : Listen for change
...
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.
@okjodom
okjodom / _cleanImgCache.js
Created May 12, 2018 06:52
My solution to clean image cache, promises :)
...
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) => {
@okjodom
okjodom / _serverAvatars.js
Created May 12, 2018 08:05
Attempt to serve avatars from cache then update cache
...
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$/, '');
@okjodom
okjodom / _pirates.js
Last active May 14, 2018 07:48
Javascript Loop family
/* 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