{ // 获取包含Hugging Face文本的span元素 const spans = link.querySelectorAll('span.whitespace-nowrap, span.hidden.whitespace-nowrap'); spans.forEach(span => { if (span.textContent && span.textContent.trim().match(/Hugging\s*Face/i)) { span.textContent = 'AI快站'; } }); }); // 替换logo图片的alt属性 document.querySelectorAll('img[alt*="Hugging"], img[alt*="Face"]').forEach(img => { if (img.alt.match(/Hugging\s*Face/i)) { img.alt = 'AI快站 logo'; } }); } // 替换导航栏中的链接 function replaceNavigationLinks() { // 已替换标记,防止重复运行 if (window._navLinksReplaced) { return; } // 已经替换过的链接集合,防止重复替换 const replacedLinks = new Set(); // 只在导航栏区域查找和替换链接 const headerArea = document.querySelector('header') || document.querySelector('nav'); if (!headerArea) { return; } // 在导航区域内查找链接 const navLinks = headerArea.querySelectorAll('a'); navLinks.forEach(link => { // 如果已经替换过,跳过 if (replacedLinks.has(link)) return; const linkText = link.textContent.trim(); const linkHref = link.getAttribute('href') || ''; // 替换Spaces链接 - 仅替换一次 if ( (linkHref.includes('/spaces') || linkHref === '/spaces' || linkText === 'Spaces' || linkText.match(/^s*Spacess*$/i)) && linkText !== 'OCR模型免费转Markdown' && linkText !== 'OCR模型免费转Markdown' ) { link.textContent = 'OCR模型免费转Markdown'; link.href = 'https://fast360.xyz'; link.setAttribute('target', '_blank'); link.setAttribute('rel', 'noopener noreferrer'); replacedLinks.add(link); } // 删除Posts链接 else if ( (linkHref.includes('/posts') || linkHref === '/posts' || linkText === 'Posts' || linkText.match(/^s*Postss*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } // 替换Docs链接 - 仅替换一次 else if ( (linkHref.includes('/docs') || linkHref === '/docs' || linkText === 'Docs' || linkText.match(/^s*Docss*$/i)) && linkText !== '模型下载攻略' ) { link.textContent = '模型下载攻略'; link.href = '/'; replacedLinks.add(link); } // 删除Enterprise链接 else if ( (linkHref.includes('/enterprise') || linkHref === '/enterprise' || linkText === 'Enterprise' || linkText.match(/^s*Enterprises*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } }); // 查找可能嵌套的Spaces和Posts文本 const textNodes = []; function findTextNodes(element) { if (element.nodeType === Node.TEXT_NODE) { const text = element.textContent.trim(); if (text === 'Spaces' || text === 'Posts' || text === 'Enterprise') { textNodes.push(element); } } else { for (const child of element.childNodes) { findTextNodes(child); } } } // 只在导航区域内查找文本节点 findTextNodes(headerArea); // 替换找到的文本节点 textNodes.forEach(node => { const text = node.textContent.trim(); if (text === 'Spaces') { node.textContent = node.textContent.replace(/Spaces/g, 'OCR模型免费转Markdown'); } else if (text === 'Posts') { // 删除Posts文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } else if (text === 'Enterprise') { // 删除Enterprise文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } }); // 标记已替换完成 window._navLinksReplaced = true; } // 替换代码区域中的域名 function replaceCodeDomains() { // 特别处理span.hljs-string和span.njs-string元素 document.querySelectorAll('span.hljs-string, span.njs-string, span[class*="hljs-string"], span[class*="njs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换hljs-string类的span中的域名(移除多余的转义符号) document.querySelectorAll('span.hljs-string, span[class*="hljs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换pre和code标签中包含git clone命令的域名 document.querySelectorAll('pre, code').forEach(element => { if (element.textContent && element.textContent.includes('git clone')) { const text = element.innerHTML; if (text.includes('huggingface.co')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 处理特定的命令行示例 document.querySelectorAll('pre, code').forEach(element => { const text = element.innerHTML; if (text.includes('huggingface.co')) { // 针对git clone命令的专门处理 if (text.includes('git clone') || text.includes('GIT_LFS_SKIP_SMUDGE=1')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 特别处理模型下载页面上的代码片段 document.querySelectorAll('.flex.border-t, .svelte_hydrator, .inline-block').forEach(container => { const content = container.innerHTML; if (content && content.includes('huggingface.co')) { container.innerHTML = content.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 特别处理模型仓库克隆对话框中的代码片段 try { // 查找包含"Clone this model repository"标题的对话框 const cloneDialog = document.querySelector('.svelte_hydration_boundary, [data-target="MainHeader"]'); if (cloneDialog) { // 查找对话框中所有的代码片段和命令示例 const codeElements = cloneDialog.querySelectorAll('pre, code, span'); codeElements.forEach(element => { if (element.textContent && element.textContent.includes('huggingface.co')) { if (element.innerHTML.includes('huggingface.co')) { element.innerHTML = element.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { element.textContent = element.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); } // 更精确地定位克隆命令中的域名 document.querySelectorAll('[data-target]').forEach(container => { const codeBlocks = container.querySelectorAll('pre, code, span.hljs-string'); codeBlocks.forEach(block => { if (block.textContent && block.textContent.includes('huggingface.co')) { if (block.innerHTML.includes('huggingface.co')) { block.innerHTML = block.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { block.textContent = block.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); }); } catch (e) { // 错误处理但不打印日志 } } // 当DOM加载完成后执行替换 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); }); } else { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); } // 增加一个MutationObserver来处理可能的动态元素加载 const observer = new MutationObserver(mutations => { // 检查是否导航区域有变化 const hasNavChanges = mutations.some(mutation => { // 检查是否存在header或nav元素变化 return Array.from(mutation.addedNodes).some(node => { if (node.nodeType === Node.ELEMENT_NODE) { // 检查是否是导航元素或其子元素 if (node.tagName === 'HEADER' || node.tagName === 'NAV' || node.querySelector('header, nav')) { return true; } // 检查是否在导航元素内部 let parent = node.parentElement; while (parent) { if (parent.tagName === 'HEADER' || parent.tagName === 'NAV') { return true; } parent = parent.parentElement; } } return false; }); }); // 只在导航区域有变化时执行替换 if (hasNavChanges) { // 重置替换状态,允许再次替换 window._navLinksReplaced = false; replaceHeaderBranding(); replaceNavigationLinks(); } }); // 开始观察document.body的变化,包括子节点 if (document.body) { observer.observe(document.body, { childList: true, subtree: true }); } else { document.addEventListener('DOMContentLoaded', () => { observer.observe(document.body, { childList: true, subtree: true }); }); } })(); \n\n\n\nThe W3School Definition of Inline and Block Element Stands as follows:\n\n*\n\n*An inline element does not start on a new line and only takes up as much width as necessary.\n\n*A block-level element always starts on a new line and takes up the full width available (stretches out to the left and right as far as it can).\n\nAs you can see in the example above, even though I typed \"Hello\" inside of the li tag and immediately followed it with \"World\", the single li tag will not allow the \"World\" to be on the same line. This demonstrates that the li tag is taking 100% of the available width, proving that li is a block level element.\nThat is my point of view.\n\nA: This is really moot, since an li element must occur with a block-level ul or ol.\n\nA: Since it places theme selves one after one in a stacked manner, it is a block level element.\nI am providing w3c documentation link where you can find more about this.\nvisit this link.\n\n"},"subdomain":{"kind":"string","value":"stackoverflow"},"metadata":{"kind":"string","value":"{\n \"language\": \"en\",\n \"length\": 346,\n \"provenance\": \"stackexchange_0000F.jsonl.gz:887297\",\n \"question_score\": \"4\",\n \"source\": \"stackexchange\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"url\": \"https://stackoverflow.com/questions/44612134\"\n}"}}},{"rowIdx":1707917,"cells":{"id":{"kind":"string","value":"c4e7ebce1e64a8724af4d699412e668cc3d2ef86"},"text":{"kind":"string","value":"Stackoverflow Stackexchange\n\nQ: How to simulate hung task in linux? I just changed following configurations in /etc/sysctl.conf :\n# Reboot 5 seconds after panic\nkernel.panic = 5\n\n# Panic if a hung task was found\nkernel.hung_task_panic = 1\n\n# Setup timeout for hung task to 300 seconds\nkernel.hung_task_timeout_secs = 300\n\nI want to test if kernel.hung_task_panic = 1 and kernel.hung_task_timeout_sec = 300 are working. How do I simulate the hung task in linux to test the two configurations. I am using Ubuntu 16.04 Server\n\nA: You can freeze a filesystem and then trigger a write, like this:\n# fsfreeze --freeze /path/to/mountpoint\n# echo crap > /path/to/mountpoint/file\n\nsince you intend to trigger a crash, I strongly suggest you dd a few MB file to a tmpfs mountpoint, losetup (get /dev/loop0 or so), mkfs and finally mount that.\n"},"original_text":{"kind":"string","value":"Q: How to simulate hung task in linux? I just changed following configurations in /etc/sysctl.conf :\n# Reboot 5 seconds after panic\nkernel.panic = 5\n\n# Panic if a hung task was found\nkernel.hung_task_panic = 1\n\n# Setup timeout for hung task to 300 seconds\nkernel.hung_task_timeout_secs = 300\n\nI want to test if kernel.hung_task_panic = 1 and kernel.hung_task_timeout_sec = 300 are working. How do I simulate the hung task in linux to test the two configurations. I am using Ubuntu 16.04 Server\n\nA: You can freeze a filesystem and then trigger a write, like this:\n# fsfreeze --freeze /path/to/mountpoint\n# echo crap > /path/to/mountpoint/file\n\nsince you intend to trigger a crash, I strongly suggest you dd a few MB file to a tmpfs mountpoint, losetup (get /dev/loop0 or so), mkfs and finally mount that.\n"},"subdomain":{"kind":"string","value":"stackoverflow"},"metadata":{"kind":"string","value":"{\n \"language\": \"en\",\n \"length\": 134,\n \"provenance\": \"stackexchange_0000F.jsonl.gz:887298\",\n \"question_score\": \"4\",\n \"source\": \"stackexchange\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"url\": \"https://stackoverflow.com/questions/44612136\"\n}"}}},{"rowIdx":1707918,"cells":{"id":{"kind":"string","value":"801cef7b0b2aeca026ff78e789a32d4fe2d9a411"},"text":{"kind":"string","value":"Stackoverflow Stackexchange\n\nQ: Get only visible element using pure javascript I have elements like below\n
send Message
\n\n
send Message
\n\n
send Message
\n\nI have a web page where there is send Message buttons like above, in which only one button is visible at a time.Other two buttons are hidden via some javascript codes.So for example if 2nd button is visible , I should be able to get only that element.\nSo my code will be something like \ndocument.querySelector(\".one:visible\");\n\nIn jquery the code is $(\".one:visible\"); , which works fine , But I need to know how to do this via pure javascript.\n\nA: I have something shorter:\nArray.from(document.querySelectorAll('.one')).filter(s =>\n window.getComputedStyle(s).getPropertyValue('display') != 'none'\n);\n\nReturns all elements with attribute display block set.\n"},"original_text":{"kind":"string","value":"Q: Get only visible element using pure javascript I have elements like below\n
send Message
\n\n
send Message
\n\n
send Message
\n\nI have a web page where there is send Message buttons like above, in which only one button is visible at a time.Other two buttons are hidden via some javascript codes.So for example if 2nd button is visible , I should be able to get only that element.\nSo my code will be something like \ndocument.querySelector(\".one:visible\");\n\nIn jquery the code is $(\".one:visible\"); , which works fine , But I need to know how to do this via pure javascript.\n\nA: I have something shorter:\nArray.from(document.querySelectorAll('.one')).filter(s =>\n window.getComputedStyle(s).getPropertyValue('display') != 'none'\n);\n\nReturns all elements with attribute display block set.\n\nA: Use getBoundingClientRect. It will return height and width of zero if the element is not in the DOM, or is not displayed.\nNote that this cannot be used to determine if an element is not visible due to visibility: hidden or opacity: 0. AFAIK this behavior is identical to the jQuery :visible \"selector\". Apparently jQuery uses offsetHeight and offsetWidth of zero to check for non-visibility.\nThis solution will also not check if the item is not visible due to being off the screen (although you could check that easily enough), or if the element is hidden behind some other element.\nSee also Detect if an element is visible (without using jquery)\n\nA: var $el = document.querySelectorAll('.one');\nvar visibleElements;\n\nfor (var i = 0; i < $el.length; i++) {\n var currentElement = $el[i];\n var $style = window.getComputedStyle(currentElement, null);\n\n if (!currentElement) {\n return false;\n } else if (!$style) {\n return false;\n } else if ($style.display === 'none') {\n return false;\n } else {\n visibleElements.push(currentElement);\n }\n}\n\nFirst we get all the elements using document querySelectorAll. Then, we need to iterate over all the elements. To get the style, use getComputedStyle.\nAfter that :visible check only for display and we do it the same way.\nA more comprehensive approach:\nfunction isVisible(el) {\n while (el) {\n if (el === document) {\n return true;\n }\n\n var $style = window.getComputedStyle(el, null);\n\n if (!el) {\n return false;\n } else if (!$style) {\n return false;\n } else if ($style.display === 'none') {\n return false;\n } else if ($style.visibility === 'hidden') {\n return false;\n } else if (+$style.opacity === 0) {\n return false;\n } else if (($style.display === 'block' || $style.display === 'inline-block') &&\n $style.height === '0px' && $style.overflow === 'hidden') {\n return false;\n } else {\n return $style.position === 'fixed' || isVisible(el.parentNode);\n }\n }\n }\n\nThis would check for any possible way an element could be visible in the dom to my knowledge minus the z-index cases.\n\nA: If you're using the hidden attribute :\ndocument.querySelector(\".one:not([hidden])\");\n\n\nA: Here's something you can use, pure Javascript:\n// Get all elements on the page (change this to another DOM element if you want)\nvar all = document.getElementsByTagName(\"*\");\n\nfor (var i = 0, max = all.length; i < max; i++) {\n if (isHidden(all[i]))\n // hidden\n else \n // visible\n}\n\nfunction isHidden(el) {\n var style = window.getComputedStyle(el);\n return ((style.display === 'none') || (style.visibility === 'hidden'))\n}\n\n\nA: So all jQuery's :visible selector does is check the display property.\nIf that's all you want, this is all you'd need.\n(window.getComputedStyle(el).getPropertyValue('display') !== 'none')\n\nHowever, this is lacking in many use cases. If you seek a more comprehensive solution, keep reading.\nBoth Element.getBoundingClientRect() and window.getComputedStyle() are useful for determining if the element is visible and in the viewport.\nYou can't use getBoundingRect() alone to determine the visibility, and while you could use getComputedStyle() solely, it's not the optimal solution in terms of performance.\nBoth of these functions used in conjunction with each other is the best option (around 22% faster than getComputedStyle() alone.\nfunction inViewport(els) {\n let matches = [],\n elCt = els.length;\n\n for (let i=0; i 0 && b.height > 0 &&\n b.left+b.width > 0 && b.right-b.width < window.outerWidth && \n b.top+b.height > 0 && b.bottom-b.width < window.outerHeight && \n (c = window.getComputedStyle(el)) &&\n c.getPropertyValue('visibility') === 'visible' &&\n c.getPropertyValue('opacity') !== 'none') {\n matches.push(el);\n }\n }\n return matches;\n}\n\nWith a usage example of...\nvar els = document.querySelectorAll('.one'),\n visibleEls = inViewport(els);\n\nThis ensures that the display is not set to \"none\", the visibility is \"visible\", the width and height are greater than 0, and the element is within the bounds of the viewport.\n"},"subdomain":{"kind":"string","value":"stackoverflow"},"metadata":{"kind":"string","value":"{\n \"language\": \"en\",\n \"length\": 729,\n \"provenance\": \"stackexchange_0000F.jsonl.gz:887300\",\n \"question_score\": \"14\",\n \"source\": \"stackexchange\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"url\": \"https://stackoverflow.com/questions/44612141\"\n}"}}},{"rowIdx":1707919,"cells":{"id":{"kind":"string","value":"7e783c11173f018081c34f42245f2dd4e9bba2af"},"text":{"kind":"string","value":"Stackoverflow Stackexchange\n\nQ: Write data to SSD1306 via I2C I'm using an SSD1306 OLED and have a question about it.\nWhen writing data to its buffer via I2C, some libraries write 16 bytes every time.\nFor example:\nvoid SSD1306::sendFramebuffer(const uint8_t *buffer) {\n // Set Column Address (0x00 - 0x7F)\n sendCommand(SSD1306_COLUMNADDR);\n sendCommand(0x00);\n sendCommand(0x7F);\n // Set Page Address (0x00 - 0x07)\n sendCommand(SSD1306_PAGEADDR);\n sendCommand(0x00);\n sendCommand(0x07);\n for (uint16_t i = 0;i < SSD1306_BUFFERSIZE;) {\n i2c.start();\n i2c.write(0x40);\n for (uint8_t j = 0;j < 16; ++j, ++i) {\n i2c.write(buffer[i]);\n }\n i2c.stop();\n }\n}\n\nWhy don't they write 1024 bytes directly?\n\nA: Most of the I2C libraries I've seen source code for, including that for the Aruduino, chunk the data in this fashion. While the I2C standard doesn't require this, as other poster mentioned, there may be buffer considerations. The .stop() command here might signal the device to process the 16 bytes just sent and prepare for more.\nInvariably, you need to read the datasheet for your device and understand what it expects in order to display properly. They say \"RTFM\" in software, but hardware is at least as unforgiving. You must read and follow the datasheet when interfacing with external hardware devices.\n"},"original_text":{"kind":"string","value":"Q: Write data to SSD1306 via I2C I'm using an SSD1306 OLED and have a question about it.\nWhen writing data to its buffer via I2C, some libraries write 16 bytes every time.\nFor example:\nvoid SSD1306::sendFramebuffer(const uint8_t *buffer) {\n // Set Column Address (0x00 - 0x7F)\n sendCommand(SSD1306_COLUMNADDR);\n sendCommand(0x00);\n sendCommand(0x7F);\n // Set Page Address (0x00 - 0x07)\n sendCommand(SSD1306_PAGEADDR);\n sendCommand(0x00);\n sendCommand(0x07);\n for (uint16_t i = 0;i < SSD1306_BUFFERSIZE;) {\n i2c.start();\n i2c.write(0x40);\n for (uint8_t j = 0;j < 16; ++j, ++i) {\n i2c.write(buffer[i]);\n }\n i2c.stop();\n }\n}\n\nWhy don't they write 1024 bytes directly?\n\nA: Most of the I2C libraries I've seen source code for, including that for the Aruduino, chunk the data in this fashion. While the I2C standard doesn't require this, as other poster mentioned, there may be buffer considerations. The .stop() command here might signal the device to process the 16 bytes just sent and prepare for more.\nInvariably, you need to read the datasheet for your device and understand what it expects in order to display properly. They say \"RTFM\" in software, but hardware is at least as unforgiving. You must read and follow the datasheet when interfacing with external hardware devices.\n\nA: Segmenting data into more frames helps when the receiving device has not enough buffer space or is simply not fast enough to digest the data at full rate. The START/STOP approach might give the receiving device a bit of time to process the received data. In your specific case, the 16-byte chunks seem to be exactly one line of the display.\nOther reasons for segmenting transfers are multi-master operations, but that doesn't seem to be the case here.\n"},"subdomain":{"kind":"string","value":"stackoverflow"},"metadata":{"kind":"string","value":"{\n \"language\": \"en\",\n \"length\": 273,\n \"provenance\": \"stackexchange_0000F.jsonl.gz:887338\",\n \"question_score\": \"3\",\n \"source\": \"stackexchange\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"url\": \"https://stackoverflow.com/questions/44612271\"\n}"}}},{"rowIdx":1707920,"cells":{"id":{"kind":"string","value":"788156a075744714703dda7cdb0e841d9b0ac6a1"},"text":{"kind":"string","value":"Stackoverflow Stackexchange\n\nQ: Using Vector Drawable by drawing in Canvas \n*\n\n*I have a imported an SVG into my project as Vector Drawable.\n\n*I have my custom view\n\n\nI know how to display a vector drawable using an ImageView by code (http://www.androidhive.info/2017/02/android-working-svg-vector-drawables/)\n, which is described in several articles, but:\nHow can I draw my vectors using my custom view and by code with canvas ?\nIs this possible to do. And if so, can someone give me a hint.\n\nA: To do this you need to convert the vector to a bitmap as follows:\nprivate fun getVectorBitmap(context: Context, drawableId: Int): Bitmap? {\n\n var bitmap: Bitmap? = null\n\n when (val drawable = ContextCompat.getDrawable(context, drawableId)) {\n\n is BitmapDrawable -> {\n bitmap = drawable.bitmap\n }\n\n is VectorDrawable -> {\n\n bitmap = Bitmap.createBitmap(\n drawable.intrinsicWidth,\n drawable.intrinsicHeight, Bitmap.Config.ARGB_8888\n )\n \n val canvas = Canvas(bitmap)\n drawable.setBounds(0, 0, canvas.width, canvas.height)\n drawable.draw(canvas)\n\n }\n }\n\n return bitmap\n} \n\nThen you can use the vector as a bitmap normally with your canvas:\n canvas?.drawBitmap(getVectorBitmap(context, R.drawable.ic_icon), 500f, 500f, canvasPaint)\n\n"},"original_text":{"kind":"string","value":"Q: Using Vector Drawable by drawing in Canvas \n*\n\n*I have a imported an SVG into my project as Vector Drawable.\n\n*I have my custom view\n\n\nI know how to display a vector drawable using an ImageView by code (http://www.androidhive.info/2017/02/android-working-svg-vector-drawables/)\n, which is described in several articles, but:\nHow can I draw my vectors using my custom view and by code with canvas ?\nIs this possible to do. And if so, can someone give me a hint.\n\nA: To do this you need to convert the vector to a bitmap as follows:\nprivate fun getVectorBitmap(context: Context, drawableId: Int): Bitmap? {\n\n var bitmap: Bitmap? = null\n\n when (val drawable = ContextCompat.getDrawable(context, drawableId)) {\n\n is BitmapDrawable -> {\n bitmap = drawable.bitmap\n }\n\n is VectorDrawable -> {\n\n bitmap = Bitmap.createBitmap(\n drawable.intrinsicWidth,\n drawable.intrinsicHeight, Bitmap.Config.ARGB_8888\n )\n \n val canvas = Canvas(bitmap)\n drawable.setBounds(0, 0, canvas.width, canvas.height)\n drawable.draw(canvas)\n\n }\n }\n\n return bitmap\n} \n\nThen you can use the vector as a bitmap normally with your canvas:\n canvas?.drawBitmap(getVectorBitmap(context, R.drawable.ic_icon), 500f, 500f, canvasPaint)\n\n\nA: I'm going to turn @pskink's comment into an answer as I'm not so advanced in android as to quickly realize what he meant. I had to read @Krishna's answer to understand. So credits to both of them.\nHere it goes:\nA vector drawable inherits Drawable that can be drawn directly into a canvas. First, get the drawable from the resources using an android context:\nval drawable = yourContext.getDrawable(drawableId)\n\nThen simply draw into the canvas with it. The next line tells the drawable to draw on the top left corner, with a size of 32x32 pixels:\ndrawable.setBounds(0, 0, 32, 32) \n\nFinally draw it into the canvas:\ndrawable.draw(canvas)\n\n"},"subdomain":{"kind":"string","value":"stackoverflow"},"metadata":{"kind":"string","value":"{\n \"language\": \"en\",\n \"length\": 271,\n \"provenance\": \"stackexchange_0000F.jsonl.gz:887364\",\n \"question_score\": \"9\",\n \"source\": \"stackexchange\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"url\": \"https://stackoverflow.com/questions/44612353\"\n}"}}},{"rowIdx":1707921,"cells":{"id":{"kind":"string","value":"e9356d6810bf0a0f2d5642ba97e8f43cc36546cd"},"text":{"kind":"string","value":"Stackoverflow Stackexchange\n\nQ: Toggle Class based on scroll React JS I'm using bootstrap 4 nav bar and would like to change the background color after ig 400px down scroll down. I was looking at the react docs and found a onScroll but couldn't find that much info on it. So far I have... \nI don't know if I'm using the right event listener or how to set the height etc.\nAnd I'm not really setting inline styles... \n import React, { Component } from 'react';\n\n class App extends Component {\n\n constructor(props) {\n super(props);\n\n this.state = { scrollBackground: 'nav-bg' };\n this.handleScroll = this.handleScroll.bind(this);\n }\n\n\n handleScroll(){\n this.setState ({\n scrollBackground: !this.state.scrollBackground\n })\n }\n\n render() {\n const scrollBg = this.scrollBackground ? 'nav-bg scrolling' : 'nav-bg';\n\n return (\n
\n\n \n ...\n \n\n
\n );\n }\n}\n\nexport default App;\n\n\nA: const [scroll, setScroll] = useState(false);\n\n useEffect(() => {\n window.addEventListener(\"scroll\", () => {\n setScroll(window.scrollY > specify_height_you_want_to_change_after_here);\n });\n }, []); \n\nThen you can change your class or anything according to scroll.\n\n\n\n"},"original_text":{"kind":"string","value":"Q: Toggle Class based on scroll React JS I'm using bootstrap 4 nav bar and would like to change the background color after ig 400px down scroll down. I was looking at the react docs and found a onScroll but couldn't find that much info on it. So far I have... \nI don't know if I'm using the right event listener or how to set the height etc.\nAnd I'm not really setting inline styles... \n import React, { Component } from 'react';\n\n class App extends Component {\n\n constructor(props) {\n super(props);\n\n this.state = { scrollBackground: 'nav-bg' };\n this.handleScroll = this.handleScroll.bind(this);\n }\n\n\n handleScroll(){\n this.setState ({\n scrollBackground: !this.state.scrollBackground\n })\n }\n\n render() {\n const scrollBg = this.scrollBackground ? 'nav-bg scrolling' : 'nav-bg';\n\n return (\n
\n\n \n ...\n \n\n
\n );\n }\n}\n\nexport default App;\n\n\nA: const [scroll, setScroll] = useState(false);\n\n useEffect(() => {\n window.addEventListener(\"scroll\", () => {\n setScroll(window.scrollY > specify_height_you_want_to_change_after_here);\n });\n }, []); \n\nThen you can change your class or anything according to scroll.\n\n\n\n\nA: It's Better\nimport React from 'react';\nimport { render } from 'react-dom';\n\nclass App extends React.Component {\n constructor(props) {\n super(props);\n\n this.state = {\n isTop: true\n };\n this.onScroll = this.onScroll.bind(this);\n }\n\n componentDidMount() {\n document.addEventListener('scroll', () => {\n const isTop = window.scrollY < 100;\n if (isTop !== this.state.isTop) {\n this.onScroll(isTop);\n }\n });\n }\n\n onScroll(isTop) {\n this.setState({ isTop });\n }\n\n render() {\n return (\n
\n

Scroll {this.state.isTop ? 'down' : 'up'}!

\n
\n );\n }\n} \n\nrender(, document.getElementById('root'));\n\n\nA: For those of you who are reading this question after 2020, I've taken @glennreyes answer and rewritten it using React Hooks:\n const [scroll, setScroll] = useState(0)\n\n useEffect(() => {\n document.addEventListener(\"scroll\", () => {\n const scrollCheck = window.scrollY < 100\n if (scrollCheck !== scroll) {\n setScroll(scrollCheck)\n }\n })\n })\n\nBear in mind that, useState has an array of two elements, firstly the state object and secondly the function that updates it.\nAlong the lines, useEffect helps us replace componentDidmount, the function written currently does not do any clean ups for brevity purposes.\nIf you find it essential to clean up, you can just return a function inside the useEffect.\nYou can read comprehensively here.\nUPDATE:\nIf you guys felt like making it modular and even do the clean up, you can do something like this:\n\n*\n\n*Create a custom hook as below;\nimport { useState, useEffect } from \"react\"\n\nexport const useScrollHandler = () => {\n// setting initial value to true\nconst [scroll, setScroll] = useState(1)\n\n// running on mount\nuseEffect(() => {\n const onScroll = () => {\n const scrollCheck = window.scrollY < 10\n if (scrollCheck !== scroll) {\n setScroll(scrollCheck)\n }\n }\n\n// setting the event handler from web API\ndocument.addEventListener(\"scroll\", onScroll)\n\n// cleaning up from the web API\n return () => {\n document.removeEventListener(\"scroll\", onScroll)\n }\n}, [scroll, setScroll])\n\nreturn scroll\n\n}\n\n\n\n*Call it inside any component that you find suitable:\nconst component = () => {\n\n// calling our custom hook\nconst scroll = useScrollHandler()\n\n....... rest of your code\n\n}\n\n\nA: One way to add a scroll listener is to use the componentDidMount() lifecycle method. Following example should give you an idea:\nimport React from 'react';\nimport { render } from 'react-dom';\n\nclass App extends React.Component {\n state = {\n isTop: true,\n };\n\n componentDidMount() {\n document.addEventListener('scroll', () => {\n const isTop = window.scrollY < 100;\n if (isTop !== this.state.isTop) {\n this.setState({ isTop })\n }\n });\n }\n render() {\n return (\n
\n

Scroll {this.state.isTop ? 'down' : 'up'}!

\n
\n );\n }\n} \n\nrender(, document.getElementById('root'));\n\nThis changes the Text from \"Scroll down\" to \"Scroll up\" when your scrollY position is at 100 and above.\nEdit: Should avoid the overkill of updating the state on each scroll. Only update it when the boolean value changes.\n\nA: I have changed @PouyaAtaei answer a bit for my use case.\nimport { useState, useEffect } from \"react\"\n\n// Added distance parameter to determine how much \n// from the top tell return value is updated.\n// The name of the hook better reflects intended use.\nexport const useHasScrolled = (distance = 10) => {\n\n // setting initial value to false\n const [scroll, setScroll] = useState(false)\n\n // running on mount\n useEffect(() => {\n const onScroll = () => {\n // Logic is false tell user reaches threshold, then true after.\n const scrollCheck = window.scrollY >= distance;\n if (scrollCheck !== scroll) {\n setScroll(scrollCheck)\n }\n }\n\n // setting the event handler from web API\n document.addEventListener(\"scroll\", onScroll)\n\n // cleaning up from the web API\n return () => {\n document.removeEventListener(\"scroll\", onScroll)\n }\n\n }, [scroll, setScroll])\n\n return scroll\n}\n\nCalling the hook:\nconst component = () => {\n // calling our custom hook and optional distance agument.\n const scroll = useHasScrolled(250)\n}\n\n\nA: This is yet another take / my take on hooks approach for on scroll displaying and hiding of a random page element.\nI have been very much inspired from: Dan Abramov's post here.\nYou can check a full working example, in this CodeSandbox demo.\nThe following is the code for the useScroll custom hook:\nimport React, { useState, useEffect } from \"react\";\n\nexport const useScroll = callback => {\n const [scrollDirection, setScrollDirection] = useState(true);\n\n const handleScroll = () => {\n const direction = (() => {\n // if scroll is at top or at bottom return null,\n // so that it would be possible to catch and enforce a special behaviour in such a case.\n if (\n window.pageYOffset === 0 ||\n window.innerHeight + Math.ceil(window.pageYOffset) >=\n document.body.offsetHeight\n )\n return null;\n // otherwise return the direction of the scroll\n return scrollDirection < window.pageYOffset ? \"down\" : \"up\";\n })();\n\n callback(direction);\n setScrollDirection(window.pageYOffset);\n };\n\n // adding and cleanning up de event listener\n useEffect(() => {\n window.addEventListener(\"scroll\", handleScroll);\n return () => window.removeEventListener(\"scroll\", handleScroll);\n });\n};\n\nAnd this hook will be consumed like this:\n useScroll(direction => {\n setScrollDirection(direction);\n });\n\nA full component using this custom hook:\nimport React, { useState } from \"react\";\nimport ReactDOM from \"react-dom\";\nimport CustomElement, { useScroll } from \"./element\";\nimport Scrollable from \"./scrollable\";\n\nfunction Page() {\n const [scrollDirection, setScrollDirection] = useState(null);\n\n useScroll(direction => {\n setScrollDirection(direction);\n });\n\n return (\n
\n {/* a custom element that implements some scroll direction behaviour */}\n {/* \"./element\" exports useScroll hook and */}\n \n {/* just a lorem ipsum long text */}\n \n
\n );\n}\n\nconst rootElement = document.getElementById(\"root\");\n\nReactDOM.render(, rootElement);\n\nAnd lastly the code for CustomElement:\nimport React, { useState, useEffect } from \"react\";\n\nexport default props => {\n const [elementVisible, setElementVisible] = useState(true);\n const { scrollDirection } = props;\n\n // when scroll direction changes element visibility adapts, but can do anything we want it to do\n // U can use ScrollDirection and implement some page shake effect while scrolling\n useEffect(() => {\n setElementVisible(\n scrollDirection === \"down\"\n ? false\n : scrollDirection === \"up\"\n ? true\n : true\n );\n }, [scrollDirection]);\n\n return (\n \n element\n
\n );\n};\n\n\nA: These are two hooks - one for direction (up/down/none) and one for the actual position\nUse like this:\nuseScrollPosition(position => {\n console.log(position)\n })\n\nuseScrollDirection(direction => {\n console.log(direction)\n })\n\nHere are the hooks:\nimport { useState, useEffect } from \"react\"\n\nexport const SCROLL_DIRECTION_DOWN = \"SCROLL_DIRECTION_DOWN\"\nexport const SCROLL_DIRECTION_UP = \"SCROLL_DIRECTION_UP\"\nexport const SCROLL_DIRECTION_NONE = \"SCROLL_DIRECTION_NONE\"\n\nexport const useScrollDirection = callback => {\n const [lastYPosition, setLastYPosition] = useState(window.pageYOffset)\n const [timer, setTimer] = useState(null)\n\n const handleScroll = () => {\n if (timer !== null) {\n clearTimeout(timer)\n }\n setTimer(\n setTimeout(function () {\n callback(SCROLL_DIRECTION_NONE)\n }, 150)\n )\n if (window.pageYOffset === lastYPosition) return SCROLL_DIRECTION_NONE\n\n const direction = (() => {\n return lastYPosition < window.pageYOffset\n ? SCROLL_DIRECTION_DOWN\n : SCROLL_DIRECTION_UP\n })()\n\n callback(direction)\n setLastYPosition(window.pageYOffset)\n }\n\n useEffect(() => {\n window.addEventListener(\"scroll\", handleScroll)\n return () => window.removeEventListener(\"scroll\", handleScroll)\n })\n}\n\nexport const useScrollPosition = callback => {\n const handleScroll = () => {\n callback(window.pageYOffset)\n }\n\n useEffect(() => {\n window.addEventListener(\"scroll\", handleScroll)\n return () => window.removeEventListener(\"scroll\", handleScroll)\n })\n}\n\n\nA: how to fix :\nWarning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.\nMenuNews\nconst [scroll, setScroll] = useState(false);\n\n useEffect(() => {\n window.addEventListener(\"scroll\", () => {\n setScroll(window.scrollY > specify_height_you_want_to_change_after_here);\n });\n }, []); \n\n\nA: Approach without scroll event listener\nimport { useEffect, useState } from \"react\";\n\ninterface Props {\n elementId: string;\n position: string;\n}\n\nconst useCheckScrollPosition = ({ elementId, position }: Props) => {\n const [isOverScrollPosition, setIsOverScrollPosition] = useState(false);\n\n useEffect(() => {\n if (\n \"IntersectionObserver\" in window &&\n \"IntersectionObserverEntry\" in window &&\n \"intersectionRatio\" in window.IntersectionObserverEntry.prototype\n ) {\n const observer = new IntersectionObserver((entries) => {\n setIsOverScrollPosition(entries[0].boundingClientRect.y < 0);\n });\n const flagElement = document.createElement(\"div\");\n flagElement.id = elementId;\n flagElement.className = \"scroll-flag\";\n flagElement.style.top = position;\n\n const container = document.getElementById(\"__next\"); // React div id\n const oldFlagElement = document.getElementById(elementId);\n\n if (!oldFlagElement) container?.appendChild(flagElement);\n\n const elementToObserve = oldFlagElement || flagElement;\n observer.observe(elementToObserve);\n }\n }, [elementId, position]);\n\n return isOverScrollPosition;\n};\n\nexport default useCheckScrollPosition;\n\nand then you can use it like this:\nconst isOverScrollPosition = useCheckScrollPosition({\n elementId: \"sticky-header\",\n position: \"10px\",\n });\n\nisOverScrollPosition is a boolean that will be true if you scroll over position provided value (10px) and false if you scroll below it.\nThis approach will add a flag div in react root.\nReference: https://css-tricks.com/styling-based-on-scroll-position/\n"},"subdomain":{"kind":"string","value":"stackoverflow"},"metadata":{"kind":"string","value":"{\n \"language\": \"en\",\n \"length\": 1554,\n \"provenance\": \"stackexchange_0000F.jsonl.gz:887369\",\n \"question_score\": \"20\",\n \"source\": \"stackexchange\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"url\": \"https://stackoverflow.com/questions/44612364\"\n}"}}},{"rowIdx":1707922,"cells":{"id":{"kind":"string","value":"45cc5d9d7bf93fcb09df7d19ab9066653f12eac0"},"text":{"kind":"string","value":"Stackoverflow Stackexchange\n\nQ: How to pass the index value of a ngFor loop into the component? I have a ngFor loop in my code.\nand inside this ngFor loop I have a div, on clicking this div I want to pass the index value to the type script file.\nI am new to Anglular 2 any help will be appreciated.\nEg:\n`
\n
\n
\n
`\n\n\nA:
\n
\n
\n
`\n\n\npassIndexValue(index){\n console.log(index);//clicked index\n}\n\nYou could also pass the value to the component like so (assuming below use of @Input)\n
\n \n \n
`\n\nAnd then pick up the value on the component object:\n@Input() index: number;\n\nAnd use it directly in the template of the child component like so:\n
\n\nThereby allowing a component to have a unique ID based on the *ngFor loop.\n"},"original_text":{"kind":"string","value":"Q: How to pass the index value of a ngFor loop into the component? I have a ngFor loop in my code.\nand inside this ngFor loop I have a div, on clicking this div I want to pass the index value to the type script file.\nI am new to Anglular 2 any help will be appreciated.\nEg:\n`
\n
\n
\n
`\n\n\nA:
\n
\n
\n
`\n\n\npassIndexValue(index){\n console.log(index);//clicked index\n}\n\nYou could also pass the value to the component like so (assuming below use of @Input)\n
\n \n \n
`\n\nAnd then pick up the value on the component object:\n@Input() index: number;\n\nAnd use it directly in the template of the child component like so:\n
\n\nThereby allowing a component to have a unique ID based on the *ngFor loop.\n"},"subdomain":{"kind":"string","value":"stackoverflow"},"metadata":{"kind":"string","value":"{\n \"language\": \"en\",\n \"length\": 158,\n \"provenance\": \"stackexchange_0000F.jsonl.gz:887387\",\n \"question_score\": \"9\",\n \"source\": \"stackexchange\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"url\": \"https://stackoverflow.com/questions/44612400\"\n}"}}},{"rowIdx":1707923,"cells":{"id":{"kind":"string","value":"7bba72ada61f5828657917effa126331092c3622"},"text":{"kind":"string","value":"Stackoverflow Stackexchange\n\nQ: tensorflow import vgg16 failed I just do not understand why I have already downloaded the vgg16, and it still comes up with ImportError: No module named 'download'. My directory shows on the right top of the image. \n\n\nA: I am assuming you downloaded vgg16.py from here.\nIt seems there is a download.py module in that repository that goes with vgg16.py.\nPerhaps you should download the whole repo and put your 0618.py script inside the repo root and run it from there?\n"},"original_text":{"kind":"string","value":"Q: tensorflow import vgg16 failed I just do not understand why I have already downloaded the vgg16, and it still comes up with ImportError: No module named 'download'. My directory shows on the right top of the image. \n\n\nA: I am assuming you downloaded vgg16.py from here.\nIt seems there is a download.py module in that repository that goes with vgg16.py.\nPerhaps you should download the whole repo and put your 0618.py script inside the repo root and run it from there?\n"},"subdomain":{"kind":"string","value":"stackoverflow"},"metadata":{"kind":"string","value":"{\n \"language\": \"en\",\n \"length\": 82,\n \"provenance\": \"stackexchange_0000F.jsonl.gz:887428\",\n \"question_score\": \"4\",\n \"source\": \"stackexchange\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"url\": \"https://stackoverflow.com/questions/44612503\"\n}"}}},{"rowIdx":1707924,"cells":{"id":{"kind":"string","value":"3435f950a4e12ae8891106d5237c61e0b439d7c9"},"text":{"kind":"string","value":"Stackoverflow Stackexchange\n\nQ: How to convert a Tableau extract data to csv (or xls) I have successfully converted from a Tableau .twbx file to .twb and now have a .tde file for the data. How can this .tde be converted to either .csv or .xls(x) ?\n\nA: The Worksheet | Export | Data (or Crosstab to Excel)' appear to have done the trick: there are now anxlsxand a.csv` file with the relevant dataset included.\n\n"},"original_text":{"kind":"string","value":"Q: How to convert a Tableau extract data to csv (or xls) I have successfully converted from a Tableau .twbx file to .twb and now have a .tde file for the data. How can this .tde be converted to either .csv or .xls(x) ?\n\nA: The Worksheet | Export | Data (or Crosstab to Excel)' appear to have done the trick: there are now anxlsxand a.csv` file with the relevant dataset included.\n\n\nA: You can also export to CSV from the Data menu starting in version 10.3.\nThat command exports the entire data source, while the export commands on the worksheet menu export only the data referenced by the worksheet. Both are useful. One exports the entire data source, the other exports the fields used on the worksheet\nNote to readers : See my answers below with screenshots on how to do this.\n\nA: Building on @AlexBlakemore 's answer: from Version 10.2.2 there is a feature for Export to CSV. It is non intuitive how to find it: select the Data | (data source name) | Export to CSV :\n\n"},"subdomain":{"kind":"string","value":"stackoverflow"},"metadata":{"kind":"string","value":"{\n \"language\": \"en\",\n \"length\": 180,\n \"provenance\": \"stackexchange_0000F.jsonl.gz:887431\",\n \"question_score\": \"5\",\n \"source\": \"stackexchange\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"url\": \"https://stackoverflow.com/questions/44612508\"\n}"}}},{"rowIdx":1707925,"cells":{"id":{"kind":"string","value":"702b0a2c519c5eab5eaa1c1106f535f671516575"},"text":{"kind":"string","value":"Stackoverflow Stackexchange\n\nQ: Using 'null' vs 'this' in apply or apply() and call() functions in javascript What is the difference between using this and null as the thisArg context to the apply() and call() methods? \nfunction getMax(arr) {\n return Math.max.apply(null, arr);\n}\n\nfunction getMax(arr) {\n return Math.max.apply(this, arr);\n}\n\n\nA: max is a static function, so it doesn't matter what you pass as this, because this is not used. So your functions are equivalent.\n"},"original_text":{"kind":"string","value":"Q: Using 'null' vs 'this' in apply or apply() and call() functions in javascript What is the difference between using this and null as the thisArg context to the apply() and call() methods? \nfunction getMax(arr) {\n return Math.max.apply(null, arr);\n}\n\nfunction getMax(arr) {\n return Math.max.apply(this, arr);\n}\n\n\nA: max is a static function, so it doesn't matter what you pass as this, because this is not used. So your functions are equivalent.\n\nA: The signficance of using this is to set the current context when calling the method. For example:\nfunction Human() {\n this.getMax = function getMax(arr) {\n console.log(this.constructor);\n return Math.max.apply(this, arr);\n }\n}\n\nvar human = new Human();\n\nhuman.getMax([1,2]);\n\nHere, the console statement will out this.constructor as Human. Had it been otherwise, you would have got the context as window.\nFor the first case, when you pass null, it wont pass the context. This works here because Math.max expects paramters in comma seperated format a, b, c which is being handled when you do .apply.\n"},"subdomain":{"kind":"string","value":"stackoverflow"},"metadata":{"kind":"string","value":"{\n \"language\": \"en\",\n \"length\": 166,\n \"provenance\": \"stackexchange_0000F.jsonl.gz:887436\",\n \"question_score\": \"4\",\n \"source\": \"stackexchange\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"url\": \"https://stackoverflow.com/questions/44612533\"\n}"}}},{"rowIdx":1707926,"cells":{"id":{"kind":"string","value":"c2192b1254e7a02dcafed33ad362d9ff7dc222d0"},"text":{"kind":"string","value":"Stackoverflow Stackexchange\n\nQ: Make BoxDecoration image faded/transparent I have the following snippet of code and I would like to make the image faded such that it does not interfere with other items in the container.\nIs there a filter that could accomplish this?\nchild: new Card(\n child: new Container(\n decoration: new BoxDecoration(\n color: const Color(0xff7c94b6),\n image: new DecorationImage(\n image: new ExactAssetImage('lib/images/pic1.jpg'),\n )\n )\n )\n )\n\n\nA: You can simply use \nColorFiltered(\n colorFilter: ColorFilter.mode(Colors.black.withOpacity(0.2), BlendMode.dstATop),\n child: YourWidget(),\n) \n\n"},"original_text":{"kind":"string","value":"Q: Make BoxDecoration image faded/transparent I have the following snippet of code and I would like to make the image faded such that it does not interfere with other items in the container.\nIs there a filter that could accomplish this?\nchild: new Card(\n child: new Container(\n decoration: new BoxDecoration(\n color: const Color(0xff7c94b6),\n image: new DecorationImage(\n image: new ExactAssetImage('lib/images/pic1.jpg'),\n )\n )\n )\n )\n\n\nA: You can simply use \nColorFiltered(\n colorFilter: ColorFilter.mode(Colors.black.withOpacity(0.2), BlendMode.dstATop),\n child: YourWidget(),\n) \n\n\nA: Use Opacity class.\nA widget that makes its child partially transparent.\nOpacity(\n opacity: 0.5,\n child: Image.asset('images/lion.png'),\n)\n\n\nA: For those who wonder whether the performance is OK or not (since images and opacity are both resource-heavy things), here is my dig into the doc and the source code and the answer.\nConclusion: Use DecorationImage(colorFilter: ...) will be as fast as what official doc suggests. (But Opacity, ColorFilter widgets are not)\nFirstly, we should not use Opacity or ColorFilter widget since it may trigger saveLayer and is expensive (by official doc).\nInstead, we should\n\nUse the Opacity widget only when necessary. See the Transparent image section in the Opacity API page for an example of applying opacity directly to an image, which is faster than using the Opacity widget.\n\nLooking at the suggested method, we see the following sample:\nImage.network(\n 'https://raw.githubusercontent.com/flutter/assets-for-api-docs/master/packages/diagrams/assets/blend_mode_destination.jpeg',\n color: Color.fromRGBO(255, 255, 255, 0.5),\n colorBlendMode: BlendMode.modulate\n)\n\nNow, the problem is, is the highly-voted answer, i.e. the following code, as fast as what the official doc mentions for Image widget?\nContainer(\n child: Text('hi'),\n decoration: BoxDecoration(\n color: const Color(0xff7c94b6),\n image: new DecorationImage(\n fit: BoxFit.cover,\n colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.2), BlendMode.dstATop),\n image: new NetworkImage(\n 'http://www.allwhitebackground.com/images/2/2582-190x190.jpg',\n ),\n ),\n ),\n),\n\nTo answer this, let us look at Image.network's source. This constructor will directly fill in the colorBlendMode field of Image.\nIn Image's build, it will be directly passed to RawImage's colorBlendMode field.\nThen, RawImage will create RenderImage (which is a RenderObject) and updates RenderImage._colorBlendMode.\nNext, notice how RenderImage handles this -\n BlendMode? _colorBlendMode;\n set colorBlendMode(BlendMode? value) {\n if (value == _colorBlendMode)\n return;\n _colorBlendMode = value;\n _updateColorFilter();\n markNeedsPaint();\n }\n\n ...\n\n /// If non-null, this color is blended with each image pixel using [colorBlendMode].\n Color? get color => _color;\n Color? _color;\n set color(Color? value) {\n if (value == _color)\n return;\n _color = value;\n _updateColorFilter();\n markNeedsPaint();\n }\n\n ...\n\n ColorFilter? _colorFilter;\n void _updateColorFilter() {\n if (_color == null)\n _colorFilter = null;\n else\n _colorFilter = ColorFilter.mode(_color!, _colorBlendMode ?? BlendMode.srcIn);\n }\n\nA more dig into rendering/image.dart will show that, colorBlendMode (and _colorBlendMode will not be used in other places except to create this _colorFilter.\nThus, we know the two arguments of Image.network will finally go into RenderImage._colorFilter.\nIndeed, that _colorFilter will be used in RenderImage.paint as\n @override\n void paint(PaintingContext context, Offset offset) {\n ...\n paintImage(\n canvas: context.canvas,\n rect: offset & size,\n image: _image!,\n colorFilter: _colorFilter,\n ...\n );\n }\n\nSo we know it! It will be used in paintImage which communicates with native methods. No wonder it is faster than Opacity.\nNo go back to our DecorationImage. Inside painting/decoration_image.dart, we see DecorationImagePainter:\nclass DecorationImagePainter {\n DecorationImagePainter._(this._details, ...);\n\n final DecorationImage _details;\n\n void paint(Canvas canvas, Rect rect, Path? clipPath, ImageConfiguration configuration) {\n ...\n paintImage(\n canvas: canvas,\n rect: rect,\n image: _image!.image,\n colorFilter: _details.colorFilter,\n ...\n );\n }\n}\n\nHey, that is exactly the same!\n\nA: You can simply use a Stack widget and use a simple coloured container above the image with reduced opacity.\nEG : \n import 'package:flutter/material.dart';\n import 'package:flutter/widgets.dart';\n import 'package:flutter/rendering.dart';\n\n import './page2.dart';\n import './page3.dart';\n import './page4.dart';\n\n void main() {\n debugPaintSizeEnabled = true ;\n return runApp(Start());\n }\n\n class Start extends StatelessWidget {\n\n @override\n Widget build(BuildContext context) {\n // TODO: implement build\n return MaterialApp(\n title: 'InIt',\n home: Builder(builder: (context) {\n return GestureDetector(\n onTap: () {\n return Navigator.push(\n context,\n MaterialPageRoute(\n builder: (BuildContext context) {\n return Page2();\n },\n ),\n );\n },\n child: Scaffold(\n body: Stack(\n children: [\n\n Container(\n decoration: BoxDecoration(\n image: DecorationImage(\n image: AssetImage('images/page1.jpg'),\n fit: BoxFit.fitHeight),\n ),\n ),\n Container(\n color: Color.fromRGBO(255, 255, 255, 0.19),\n ),\n Container(\n alignment: Alignment.center,\n child: Center(\n child: Text(\n 'LETS BE PRODUCTIVE TODAY',\n textAlign: TextAlign.center,\n style: TextStyle(\n fontSize: 50.0,\n fontFamily: 'bold',\n fontWeight: FontWeight.bold,\n color: Color.fromRGBO(255, 255, 255, 1)),\n ),\n ),\n ),\n Container(\n margin: EdgeInsets.only(bottom: 10.0),\n alignment: Alignment.bottomCenter,\n child: Row(\n mainAxisAlignment: MainAxisAlignment.center,\n children: [\n RawMaterialButton(\n onPressed: () {},\n constraints:\n BoxConstraints.tightFor(height: 10.0, width: 10.0),\n shape: CircleBorder(),\n fillColor: Colors.white,\n ),\n Page2call(),\n Page3call(),\n Page4call(),\n ],\n ),\n )\n ],\n ),\n ),\n );\n }),\n );\n }\n }\n\n class Page2call extends StatelessWidget {\n @override\n Widget build(BuildContext context) {\n // TODO: implement build\n return RawMaterialButton(\n onPressed: () {\n return Navigator.push(\n context,\n MaterialPageRoute(\n builder: (BuildContext context) {\n return Page2();\n },\n ),\n );\n },\n constraints: BoxConstraints.tightFor(height: 10.0, width: 10.0),\n shape: CircleBorder(),\n fillColor: Colors.white,\n );\n }\n }\n\n class Page3call extends StatelessWidget {\n @override\n Widget build(BuildContext context) {\n // TODO: implement build\n return RawMaterialButton(\n onPressed: () {\n return Navigator.push(\n context,\n MaterialPageRoute(\n builder: (BuildContext context) {\n return Page3();\n },\n ),\n );\n },\n constraints: BoxConstraints.tightFor(height: 10.0, width: 10.0),\n shape: CircleBorder(),\n fillColor: Colors.white,\n );\n }\n }\n\n class Page4call extends StatelessWidget {\n @override\n Widget build(BuildContext context) {\n // TODO: implement build\n return RawMaterialButton(\n onPressed: () {\n return Navigator.push(\n context,\n MaterialPageRoute(\n builder: (BuildContext context) {\n return Page4();\n },\n ),\n );\n },\n constraints: BoxConstraints.tightFor(height: 10.0, width: 10.0),\n shape: CircleBorder(),\n fillColor: Colors.white,\n );\n }\n }\n\nThis is a fully practically implemented example. You can increase the opacity over here \nto make the background even more faded, the fourth argument is for opacity: \nContainer(\n color: Color.fromRGBO(255, 255, 255, 0.19),\n ),\n\nThis method also gives u the ability to chose the colour of the fading filter. \n\nA: You could give your DecorationImage a ColorFilter to make the background image grey (use a saturation color filter) or semi transparent (use a dstATop color filter).\n\nCode for this example is below.\nimport 'package:flutter/material.dart';\n\nvoid main() {\n runApp(new MyApp());\n}\n\nclass MyApp extends StatelessWidget {\n @override\n Widget build(BuildContext context) {\n return new MaterialApp(\n home: new HomePage(),\n );\n }\n}\n\nclass HomePage extends StatelessWidget {\n @override\n Widget build(BuildContext context) => new Scaffold(\n appBar: new AppBar(\n title: new Text('Grey Example'),\n ),\n body: new Column(\n crossAxisAlignment: CrossAxisAlignment.stretch,\n children: [\n new Card(\n child: new Container(\n child: new Text(\n 'Hello world',\n style: Theme.of(context).textTheme.display4\n ),\n decoration: new BoxDecoration(\n color: const Color(0xff7c94b6),\n image: new DecorationImage(\n fit: BoxFit.cover,\n colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.2), BlendMode.dstATop),\n image: new NetworkImage(\n 'http://www.allwhitebackground.com/images/2/2582-190x190.jpg',\n ),\n ),\n ),\n ),\n ),\n ],\n ),\n );\n}\n\nThe Opacity widget is another option.\nYou could also pre apply the effect to the asset.\n"},"subdomain":{"kind":"string","value":"stackoverflow"},"metadata":{"kind":"string","value":"{\n \"language\": \"en\",\n \"length\": 1041,\n \"provenance\": \"stackexchange_0000F.jsonl.gz:887464\",\n \"question_score\": \"79\",\n \"source\": \"stackexchange\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"url\": \"https://stackoverflow.com/questions/44612599\"\n}"}}},{"rowIdx":1707927,"cells":{"id":{"kind":"string","value":"904cf152764301577839965bcf4fd425f7536b03"},"text":{"kind":"string","value":"Stackoverflow Stackexchange\n\nQ: how to use external jquery plugin in react I've built a React project using CRA. I need to use a plugin that is built using jquery. It's a datepicker but the calendar it's using is Bikram Sambat. The link to the datepicker code is Nepali Date Picker . I've done the following:\npublic/index.html\n\n\n\n\nNepaliDate Component\nimport React, { Component } from 'react';\n\nconst $ = window.$;\n\nexport default class NepaliDate extends Component {\n shouldComponentUpdate() {\n return false;\n }\n componentDidMount() {\n $('.date-picker').nepaliDatePicker({\n dateFormat: '%D, %M %d, %y',\n closeOnDateSelect: true\n });\n }\n showDatePicker = () => {\n $('.date-picker').nepaliDatePicker();\n };\n render() {\n return (\n \n );\n }\n}\n\nThe datepicker isn't showing up.\n\nA: Can use \"react-load-script\" to load 3rd part JS libraries. After install can use like below\nimport Script from 'react-load-script'\nrender(){\nreturn(\n
\n \n\n\nNepaliDate Component\nimport React, { Component } from 'react';\n\nconst $ = window.$;\n\nexport default class NepaliDate extends Component {\n shouldComponentUpdate() {\n return false;\n }\n componentDidMount() {\n $('.date-picker').nepaliDatePicker({\n dateFormat: '%D, %M %d, %y',\n closeOnDateSelect: true\n });\n }\n showDatePicker = () => {\n $('.date-picker').nepaliDatePicker();\n };\n render() {\n return (\n \n );\n }\n}\n\nThe datepicker isn't showing up.\n\nA: Can use \"react-load-script\" to load 3rd part JS libraries. After install can use like below\nimport Script from 'react-load-script'\nrender(){\nreturn(\n
\n \n \n\n\n
\n \n

Counter : {{ counter }}

\n

Clicks : {{ clicks }}

\n
\n\n \n\n\n\n\nWhen I click on the button, the counter should double the number of clicks displayed, but it's not working.\nThis code is working though: COMPUTED PROPERTIES | VueJS 2 | Learning the Basics.\n\nA: You have a counter property in your data and you also have a counter computed value. To fix your code, just remove the counter from data.\ndata:{\n clicks : 0\n},\n\nThis is addressed in the comments of the video you linked. If you notice, he never actually runs the code after he adds the computed.\nThat said I used his videos and courses as a resource myself when I was starting out. They are for the most part excellent.\n"},"original_text":{"kind":"string","value":"Q: The computed property \"counter\" is already defined in data This is my code\n\n\n \n \n\n\n
\n \n

Counter : {{ counter }}

\n

Clicks : {{ clicks }}

\n
\n\n \n\n\n\n\nWhen I click on the button, the counter should double the number of clicks displayed, but it's not working.\nThis code is working though: COMPUTED PROPERTIES | VueJS 2 | Learning the Basics.\n\nA: You have a counter property in your data and you also have a counter computed value. To fix your code, just remove the counter from data.\ndata:{\n clicks : 0\n},\n\nThis is addressed in the comments of the video you linked. If you notice, he never actually runs the code after he adds the computed.\nThat said I used his videos and courses as a resource myself when I was starting out. They are for the most part excellent.\n"},"subdomain":{"kind":"string","value":"stackoverflow"},"metadata":{"kind":"string","value":"{\n \"language\": \"en\",\n \"length\": 184,\n \"provenance\": \"stackexchange_0000F.jsonl.gz:887613\",\n \"question_score\": \"17\",\n \"source\": \"stackexchange\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"url\": \"https://stackoverflow.com/questions/44613084\"\n}"}}},{"rowIdx":1707937,"cells":{"id":{"kind":"string","value":"8bf6a4014f41febedc39034b65ed8be90d1796b0"},"text":{"kind":"string","value":"Stackoverflow Stackexchange\n\nQ: Click event doesn't fire on an audio element in chrome I have an audio element in my DOM.\nI executed the following command and it seems like the click event does not fire for some reason:\n$0.addEventListener('click',function(){console.log('click')});\n\nWhen i tried adding a mouseover handler it worked as expected:\n$0.addEventListener('mouseover',function(){console.log('mouseover')});\n\nIn Firefox the click event works properly.\nAny ideas?\n\nA: \n\"If the user agent exposes a user interface to the user by displaying controls over the media element, then the user agent should suppress any user interaction events while the user agent is interacting with this interface. (For example, if the user clicks on a video's playback control, mousedown events and so forth would not simultaneously be fired at elements on the page.)\"\n— from The Web Hypertext Application Technology Working Group\n\nIt's intended not to work, so \"malicious\" websites can't capture users' clicks on media controls. So it's not advisable to get around it in general cases; but if you really have to, you have to follow some hack like programmatically wrapping the audio element in a transparent element with a higher z-index (be careful with z-indices and transparency) and capturing the clicks for the said element.\n"},"original_text":{"kind":"string","value":"Q: Click event doesn't fire on an audio element in chrome I have an audio element in my DOM.\nI executed the following command and it seems like the click event does not fire for some reason:\n$0.addEventListener('click',function(){console.log('click')});\n\nWhen i tried adding a mouseover handler it worked as expected:\n$0.addEventListener('mouseover',function(){console.log('mouseover')});\n\nIn Firefox the click event works properly.\nAny ideas?\n\nA: \n\"If the user agent exposes a user interface to the user by displaying controls over the media element, then the user agent should suppress any user interaction events while the user agent is interacting with this interface. (For example, if the user clicks on a video's playback control, mousedown events and so forth would not simultaneously be fired at elements on the page.)\"\n— from The Web Hypertext Application Technology Working Group\n\nIt's intended not to work, so \"malicious\" websites can't capture users' clicks on media controls. So it's not advisable to get around it in general cases; but if you really have to, you have to follow some hack like programmatically wrapping the audio element in a transparent element with a higher z-index (be careful with z-indices and transparency) and capturing the clicks for the said element.\n\nA: Directly, it wont work.\nYou will need to add a shimified div aroudn it to get the click event.\nJavascript:\nfunction onAudioElClick() {\n console.log('click');\n}\n\nHTML:\n
\n`\n\n\nA: It's very strange that mouseover works but click not.\nIf you will wrap audio element inside to other element like div then you can handle click event:\nJavaScript:\n
\n audio element\n \n
\n\nHTML:\nvar el = document.querySelector(\"div\");\nel.addEventListener('click',function(){console.log('click')});\n\nhttps://jsfiddle.net/b3sbmqpj/\n"},"subdomain":{"kind":"string","value":"stackoverflow"},"metadata":{"kind":"string","value":"{\n \"language\": \"en\",\n \"length\": 275,\n \"provenance\": \"stackexchange_0000F.jsonl.gz:887624\",\n \"question_score\": \"3\",\n \"source\": \"stackexchange\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"url\": \"https://stackoverflow.com/questions/44613124\"\n}"}}},{"rowIdx":1707938,"cells":{"id":{"kind":"string","value":"b34ff3bad387cf7a8a435a92f07bbe8d0a5e6952"},"text":{"kind":"string","value":"Stackoverflow Stackexchange\n\nQ: how to ignore lf,crlf difference in beyond compare folder compare? I have 2 same php file. one is download in win7, another is from linux.\nI use folder compare function in beyond compare.\nBeyond compare regards them as different file because one is PC, another one is UNIX.\nScreenshot:\n\nI would like to ignore this difference ,how to do ?\n\nA: Can you check the session settings (In the menu under Settings -> Session Settings) if you compare also the line endings?\n\nYou find the flag on the botton of the options.\n\nIf you need a pre-check in folder compare you can use the following settings:\n\n(See the different filesize 18 to 19 Byte - The difference is the LF)\nYou need the overwrite quick test results. Without this the other checks return already a result. With this, your comparison will need more time.\n"},"original_text":{"kind":"string","value":"Q: how to ignore lf,crlf difference in beyond compare folder compare? I have 2 same php file. one is download in win7, another is from linux.\nI use folder compare function in beyond compare.\nBeyond compare regards them as different file because one is PC, another one is UNIX.\nScreenshot:\n\nI would like to ignore this difference ,how to do ?\n\nA: Can you check the session settings (In the menu under Settings -> Session Settings) if you compare also the line endings?\n\nYou find the flag on the botton of the options.\n\nIf you need a pre-check in folder compare you can use the following settings:\n\n(See the different filesize 18 to 19 Byte - The difference is the LF)\nYou need the overwrite quick test results. Without this the other checks return already a result. With this, your comparison will need more time.\n"},"subdomain":{"kind":"string","value":"stackoverflow"},"metadata":{"kind":"string","value":"{\n \"language\": \"en\",\n \"length\": 145,\n \"provenance\": \"stackexchange_0000F.jsonl.gz:887632\",\n \"question_score\": \"5\",\n \"source\": \"stackexchange\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"url\": \"https://stackoverflow.com/questions/44613147\"\n}"}}},{"rowIdx":1707939,"cells":{"id":{"kind":"string","value":"295598fb0bb5008be199a2fe276173f739cf4dc8"},"text":{"kind":"string","value":"Stackoverflow Stackexchange\n\nQ: React use of HTML5 video tag controlsList attribute Tried to return with React component this element: