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
| const domino = require('domino'); | |
| const { getMetadata } = require('page-metadata-parser'); | |
| const fetch = require('node-fetch'); | |
| const request = async (url, cb) => { | |
| const response = await fetch(url).catch(err => console.error(err)); | |
| const html = await response.text(); | |
| const doc = domino.createWindow(html).document; | |
| const metadata = getMetadata(doc, url); | |
| cb(metadata); |
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
| #!/usr/bin/env python | |
| # -*- coding:utf-8 -*- | |
| import scrapy | |
| import random, string, json, re | |
| from selenium import webdriver | |
| from selenium.webdriver.support.ui import WebDriverWait | |
| from selenium.webdriver.support import expected_conditions as EC | |
| from selenium.common.exceptions import TimeoutException, NoSuchElementException | |
| from selenium.webdriver.common.by import By |
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 requests | |
| import logging | |
| logger = logging.getLogger(__name__) | |
| class Client(object): | |
| _page_access_token = '' | |
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
| # Backup | |
| docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql | |
| # Restore | |
| cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE | |
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 |
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/react@16.3.2/umd/react.production.min.js"></script> | |
| <script src="https://unpkg.com/react-dom@16.3.2/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
| ''' | |
| 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
| // 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
| // 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'); |
OlderNewer