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 urlBase64ToUint8Array(base64String) { | |
| const padding = "=".repeat((4 - base64String.length % 4) % 4); | |
| const base64 = (base64String + padding) | |
| .replace(/\-/g, "+") | |
| .replace(/_/g, "/"); | |
| const rawData = window.atob(base64); | |
| const outputArray = new Uint8Array(rawData.length); | |
| for (let i = 0; i < rawData.length; ++i) { |
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 subscribeUserToPush() { | |
| return navigator.serviceWorker.register('service-worker.js') | |
| .then(function(registration) { | |
| const subscribeOptions = { | |
| userVisibleOnly: true, | |
| applicationServerKey: <public key ArrayBuffer not string> | |
| }; | |
| return registration.pushManager.subscribe(subscribeOptions); | |
| }) | |
| .then(function(pushSubscription) { |
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
| var CACHE_NAME = 'my-site-cache-v1'; | |
| var urlsToCache = [ | |
| '/', | |
| '/styles/main.css', | |
| '/script/main.js' | |
| ]; | |
| self.addEventListener('install', function(event) { | |
| // Perform install steps | |
| event.waitUntil( |
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
| // client.js | |
| if ('serviceWorker' in navigator) { | |
| // register a service worker for this site | |
| navigator.serviceWorker.register('cache-worker.js'); | |
| navigator.serviceWorker.ready | |
| .then((reg) => { | |
| // registration worked | |
| console.log('Registration succeeded. Scope is ' + reg.scope); | |
| }).catch((error) => { | |
| // registration failed |
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
| // some old browsers don't support web worker | |
| if (window.Worker) { | |
| // create a worker thread | |
| const worker = new Worker('web_worker.js'); | |
| // send the first msg to worker | |
| worker.postMessage('hello worker'); | |
| worker.addEventListener('message', function(event) { | |
| if (event.data === 'msg received, ack') { | |
| console.log('main thread received the ack'); |
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
| // web-worker.js | |
| self.addEventListener('message', (event) => { | |
| console.log('worker receives a msg'); | |
| if (event.data === 'close your thread') { | |
| console.log('close msg received'); | |
| try { | |
| self.close(); | |
| // this thread is terminated. | |
| } catch (error) { | |
| self.postMessage('cannot terminated by itself'); |
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
| ''' | |
| qsize raises NotImplementedError on Unix platforms like Mac OS X where sem_getvalue() is not implemented. | |
| https://docs.python.org/3.6/library/multiprocessing.html#multiprocessing.Queue.qsize | |
| ''' | |
| import multiprocessing.queues | |
| from queue import Empty, Full | |
| class SharedCounter(object): | |
| """ A synchronized shared counter. |
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
| <!DOCTYPE html> | |
| <html> | |
| <body> | |
| <div id="root"></div> | |
| <script src="https://unpkg.com/[email protected]/umd/react.production.min.js"></script> | |
| <script src="https://unpkg.com/[email protected]/umd/react-dom.production.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js" charset="utf-8"></script> | |
| <script type="text/babel"> | |
| function Greeter(props) { | |
| return <div>Hello {props.user}</div>; |
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
| #!/bin/bash | |
| sudo apt-get remove docker docker-engine docker.io | |
| sudo apt-get update | |
| sudo apt-get install htop apt-transport-https ca-certificates curl software-properties-common -y | |
| curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
| sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | |
| sudo apt-get update | |
| sudo apt-get install docker-ce docker-compose -y |
NewerOlder