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
| class MyCustomElement { | |
| constructor(id) { | |
| let html = this.getHtml(id); | |
| let temporaryContainer = document.createElement('div'); | |
| temporaryContainer.innerHTML = html.trim(); | |
| this.element = temporaryContainer.firstChild; | |
| } | |
| getElement() { | |
| return this.element; |
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 refetchMediaCards from './refetch-media-cards' //refetch media cards is our logic for rehosting images and refetching embeds. Totally up to you what to do here | |
| function refetchMediaCards(item) { | |
| return Promise.resolve(item); | |
| } | |
| export async function convertHTMLToMobiledoc(post, domContext) { | |
| try { | |
| return domContext.evaluate(postObject => window.tzrPostContentToMobiledoc(postObject), post) | |
| .then((bodies) => { |
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 FORCE_ERROR = false; | |
| function countUsersInDatabase() { | |
| return new Promise(function(resolve, reject) { | |
| setTimeout(function() { | |
| if(FORCE_ERROR) { | |
| return reject(new Error('database error')); | |
| } else { | |
| return resolve(44); | |
| } |
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
| class Promyse { | |
| constructor(userFunction) { | |
| this.state = 'pending'; | |
| this.thenCallback = null; | |
| this.errorCallback = null; | |
| userFunction(this._resolve.bind(this), this._reject.bind(this)); | |
| } | |
| _resolve(data) { |
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 React, { useEffect, useState } from "react"; | |
| const App = () => { | |
| cosnt [article, setArticle] = useState({}); | |
| useEffect(() => { | |
| fetch('https://api.example.com') | |
| .then(res => res.json()) | |
| .then(data => setArticle(data)); | |
| }); |
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 CHUNK_SIZE = 10000000; // 10MB | |
| const data = fs.readFileSync('./file'); | |
| for(let bytesRead = 0; bytesRead < data.length; bytesRead = bytesRead + CHUNK_SIZE) { | |
| // do something with data | |
| } |
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 CHUNK_SIZE = 10000000; // 10MB | |
| async function start() { | |
| const stream = fs.createReadStream('./file', { highWaterMark: CHUNK_SIZE }); | |
| for await(const data of stream) { | |
| // do something with data | |
| } | |
| } | |
| start(); |
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
| apiVersion: apps/v1 | |
| kind: Deployment | |
| metadata: | |
| name: grafana-deployment | |
| spec: | |
| selector: | |
| matchLabels: | |
| run: grafana | |
| replicas: 1 | |
| template: |
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 readBytes(fd, sharedBuffer) { | |
| return new Promise((resolve, reject) => { | |
| fs.read( | |
| fd, | |
| sharedBuffer, | |
| 0, | |
| sharedBuffer.length, | |
| null, | |
| (err) => { | |
| if(err) { return reject(err); } |
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
| async function* generateChunks(filePath, size) { | |
| const sharedBuffer = Buffer.alloc(size); | |
| const stats = fs.statSync(filePath); // file details | |
| const fd = fs.openSync(filePath); // file descriptor | |
| let bytesRead = 0; // how many bytes were read | |
| let end = size; | |
| for(let i = 0; i < Math.ceil(stats.size / size); i++) { | |
| await readBytes(fd, sharedBuffer); | |
| bytesRead = (i + 1) * size; |
OlderNewer