User Alicia Sykes - Stack Overflow most recent 30 from stackoverflow.com 2026-06-16T23:32:48Z https://stackoverflow.com/feeds/user/979052 https://creativecommons.org/licenses/by-sa/4.0/rdf https://stackoverflow.com/questions/55882171/-/55882280#55882280 3 Answer by Alicia Sykes for How can I format telephone numbers in input fields using JavaScript? Alicia Sykes https://stackoverflow.com/users/979052 2019-04-27T15:52:20Z 2025-08-15T18:55:12Z <p>There is actually an <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/tel" rel="nofollow noreferrer">input type of <code>tel</code></a>, which will save you a lot of hassle. Using <code>&lt;input type=&quot;tel&quot; ...</code> would be the correct approach, and it also allows you to specify a regex to validate the phone number to your specification, using the <code>pattern</code> attribute.</p> <p>For example:</p> <pre><code>&lt;input type=&quot;tel&quot; &gt; </code></pre> <p>It is worth noting, that you will still need server-side validation, of course. You should use the same regex on both client, and server.</p> <p>This is widely supported now, but if you are worried, see <a href="/q/2813997">this answer</a>.</p> https://stackoverflow.com/questions/79664676/-/79666213#79666213 4 Answer by Alicia Sykes for Is visual studio standard conformant when it seemingly doesn't elide a copy when calling a function Alicia Sykes https://stackoverflow.com/users/979052 2025-06-14T23:19:58Z 2025-06-15T15:26:19Z <p>As mentioned by <a href="https://stackoverflow.com/users/817643/storyteller-unslander-monica">@StoryTeller - Unslander Monica</a>, that MSVC behavior is non‑conformant, i.e it's a compiler bug</p> <p>The workaround would be to define a trivial copy constructor (e.g. <code>Foo(const Foo&amp;) = default;</code>). Or, update to the latest MSVC version (C++17)</p> <hr /> <p>Since C++17, prvalue temporary materialization is <em>deferred</em> into the direct constructor of the function parameter—so in:</p> <pre class="lang-cpp prettyprint-override"><code>foo(Foo()); </code></pre> <p>there should be <strong>only one</strong> <code>Foo</code> object constructed, namely <code>foo</code>'s param, and therefore only one destructor call</p> <p>GCC/Clang follow that - your program prints a single <code>~Foo</code>.</p> <p>MSVC prints:</p> <pre><code>~Foo ~Foo </code></pre> <p>Meaning it creates two instances: one temporary in <code>main</code>, one for <code>foo</code>'s parameter.</p> <p>This breaks the C++17 guarantee: the temporary shouldn't materialize independently - so MSVC is failing to implement the standard's prvalue semantics correctly.</p> <ul> <li><a href="https://devblogs.microsoft.com/cppblog/guaranteed-copy-elision-does-not-elide-copies/" rel="nofollow noreferrer">https://devblogs.microsoft.com/cppblog/guaranteed-copy-elision-does-not-elide-copies/</a></li> <li><a href="https://devblogs.microsoft.com/oldnewthing/20190429-00/?p=102456" rel="nofollow noreferrer">https://devblogs.microsoft.com/oldnewthing/20190429-00/?p=102456</a></li> </ul> https://stackoverflow.com/questions/79666146/-/79666208#79666208 2 Answer by Alicia Sykes for How to autocomplete brackets in Vim only in some cases Alicia Sykes https://stackoverflow.com/users/979052 2025-06-14T23:09:36Z 2025-06-14T23:09:36Z <p>You could get Vim to handle this smartly using an expression mapping, like with pure Bash-like Vimscript. So it checks whether you're inside a string before deciding what to do.</p> <p>For example::</p> <pre class="lang-none prettyprint-override"><code>&quot; Only enable this when editing Rust autocmd FileType rust inoremap &lt;expr&gt; { s:SmartBrace() function! s:SmartBrace() &quot; get syntax groups at cursor (before the &quot;{&quot;) let syn = synstack(line('.'), col('.')-1) &quot; get their names let names = map(syn, 'synIDattr(v:val, &quot;name&quot;)') &quot; check for string context (contains &quot;string&quot;) if !empty(filter(names, 'v:val =~# &quot;string&quot;')) &quot; inside a string: just insert {} and place cursor inside return '{}'.nr2char(27).'i' endif &quot; not in a string: expand a block with newline return '{\&lt;CR&gt;}'.nr2char(27).'ko' endfunction </code></pre> <hr /> <p>So, this should...</p> <ul> <li><code>inoremap &lt;expr&gt;</code>: inserts code dynamically based on context</li> <li><code>synstack()</code> gives syntax IDs under cursor; <code>synIDattr(...,&quot;name&quot;)</code> converts them to names</li> <li>We search for <code>&quot;string&quot;</code> in those names. Ifit matches, we’re inside a string</li> <li>Inside string: produce <code>{}</code>, escape to normal mode, then <code>i</code> to position cursor inside</li> <li>Outside string: do your original block expansion, open bracket, newline, close bracket, and go inside</li> </ul> https://stackoverflow.com/questions/79666191/-/79666204#79666204 2 Answer by Alicia Sykes for Error generating Mermaid diagrams with Asciidoctor-pdf and asciidoctor-diagrams Alicia Sykes https://stackoverflow.com/users/979052 2025-06-14T22:59:47Z 2025-06-14T22:59:47Z <p>I've faced something similar (well, issues with Chromium on GH Actions). Yours is failing becos the Chromium sandbox isn't correctly setup. So, you have two options: 1. Properly install chrome and configure the sandbox, or 2. Just disable sandbox!</p> <h2>Option 1: Install Chrome + configure sandbox</h2> <ol> <li>Install Google Chrome / or Chromium and it's sandbox helper</li> <li>Copy and set perms on the sandbox helper</li> <li>Export the env var to point to it</li> <li>Then run <code>asciidoctor-pdf</code> as normal</li> </ol> <p><strong>Add this before your <code>asciidoctor-pdf</code> step in the workflow:</strong></p> <pre class="lang-yaml prettyprint-override"><code>- name: Setup Chrome sandbox for diagram rendering run: | apt-get update apt-get install -y google-chrome-stable CHROME_SANDBOX=$(dirname &quot;$(which google-chrome-stable)&quot;)/chrome-sandbox sudo chown root:root &quot;$CHROME_SANDBOX&quot; sudo chmod 4755 &quot;$CHROME_SANDBOX&quot; echo &quot;CHROME_DEVEL_SANDBOX=$CHROME_SANDBOX&quot; &gt;&gt; $GITHUB_ENV </code></pre> <p>Then your diagram step stays the same:</p> <pre class="lang-yaml prettyprint-override"><code>- name: Convert AsciiDoc to PDF run: | set -o pipefail OUTPUT=$(asciidoctor-pdf -r asciidoctor-diagram -a allow-uri-read -a ./mybook.adoc 2&gt;&amp;1) echo &quot;$OUTPUT&quot; if echo &quot;$OUTPUT&quot; | grep -i -E &quot;error.*image|could not generate image|failed to generate image&quot;; then echo &quot;Error: Image generation failed in asciidoctor-pdf output.&quot; exit 1 fi </code></pre> <p>So, this <em>should</em> ensure that Puppeteer can launch Chrome with a properly permissioned sandbox.</p> <hr /> <h2>Option 2: Just disable sandbox (less secure, simpler)</h2> <p>This should actually be fine in GH actions runners, and is much easier. You can just bypass the issue with a Puppeteer config.</p> <ol> <li>Create a file <code>puppeteer-config.json</code> with:</li> </ol> <pre class="lang-json prettyprint-override"><code>{ &quot;args&quot;: [&quot;--no-sandbox&quot;, &quot;--disable-setuid-sandbox&quot;] } </code></pre> <ol start="2"> <li>Tell Asciidoctor Diagram to use it:</li> </ol> <pre class="lang-yaml prettyprint-override"><code>- name: Convert AsciiDoc to PDF (no sandbox) run: | export ASCIIDOCTOR_DIAGRAM_PUPPETEER_CONFIG=./puppeteer-config.json OUTPUT=$(asciidoctor-pdf -r asciidoctor-diagram -a allow-uri-read -a ./mybook.adoc 2&gt;&amp;1) ... </code></pre> <p>Or, pass it directly via an attribute in the AsciiDoc command</p> <hr /> <h3>TL;DR</h3> <pre class="lang-yaml prettyprint-override"><code>- name: Setup Chrome sandbox run: | apt-get update apt-get install -y google-chrome-stable CHROME_SANDBOX=$(dirname &quot;$(which google-chrome-stable)&quot;)/chrome-sandbox sudo chown root:root &quot;$CHROME_SANDBOX&quot; sudo chmod 4755 &quot;$CHROME_SANDBOX&quot; echo &quot;CHROME_DEVEL_SANDBOX=$CHROME_SANDBOX&quot; &gt;&gt; $GITHUB_ENV - name: Convert AsciiDoc to PDF run: | set -o pipefail OUTPUT=$(asciidoctor-pdf -r asciidoctor-diagram -a allow-uri-read -a ./mybook.adoc 2&gt;&amp;1) echo &quot;$OUTPUT&quot; if echo &quot;$OUTPUT&quot; | grep -i -E &quot;error.*image|could not generate image|failed to generate image&quot;; then echo &quot;Error: Image generation failed in asciidoctor‑pdf output.&quot; exit 1 fi </code></pre> <p>or</p> <pre class="lang-yaml prettyprint-override"><code>- name: Convert AsciiDoc to PDF (with no-sandbox diagrams) env: # Tell Puppeteer (used by asciidoctor-diagram) to skip sandbox PUPPETEER_ARGS: &quot;--no-sandbox --disable-setuid-sandbox&quot; run: | set -o pipefail OUTPUT=$(asciidoctor-pdf \ -r asciidoctor-diagram \ -a allow-uri-read \ -a ./mybook.adoc 2&gt;&amp;1) echo &quot;$OUTPUT&quot; if echo &quot;$OUTPUT&quot; | grep -i -E &quot;error.*image|could not generate image|failed to generate image&quot;; then echo &quot;Error: Image generation failed in asciidoctor-pdf output.&quot; exit 1 fi </code></pre> https://stackoverflow.com/questions/72050104/-/72050171#72050171 3 Answer by Alicia Sykes for Javascript Logical OR operator in return statement of a function Alicia Sykes https://stackoverflow.com/users/979052 2022-04-28T20:59:45Z 2025-05-23T20:59:55Z <pre class="lang-js prettyprint-override"><code>(title) =&gt; !!title || &quot;Title is required&quot;] </code></pre> <p>This line is saying:</p> <blockquote> <p>If <code>title</code> is present, return <code>true</code>, otherwise return <code>&quot;Title is required&quot;</code>.</p> </blockquote> <p>Let's break it down...</p> <p>To start with, the arrow function is just shorthand for:</p> <pre><code>function xxxx (title) { return !!title || &quot;Title is required&quot;]; } </code></pre> <p>Next, the <code>!!</code> is a double negation, effectively just the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOT" rel="nofollow noreferrer">logical not operator</a> twice. The first negation converts the data (whatever it data type it may be) to a boolean. The second negation changes the boolean again to give the desired result.</p> <p>E.g. <code>!!'hello'</code> --&gt; <code>true</code>, <code>!!0</code> --&gt; <code>false</code>, <code>!!undefined</code> --&gt; <code>false</code></p> <p>The next part is a comparison. The <code>||</code> is <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR" rel="nofollow noreferrer">OR operator</a>, so if the first half is true / present, then it will be returned, if not, the part after the <code>||</code> will be returned.</p> <p>E.g. <code>true || 'some text'</code> will return <code>true</code>, whereas <code>false || 'some text'</code> will return <code>some text</code></p> <hr /> <p>Here are some example, try running the snippet to see the outputs</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false" data-babel-preset-react="false" data-babel-preset-ts="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>const checkTitle = (title) =&gt; !!title || "Title is required" // 1. No parameters, should print "Title is required" console.log('Test 1', checkTitle()); // 2. Parameter presentbut empty, should print "Title is required" console.log('Test 2', checkTitle("")); // 3. Title present, and valid, should preint 'true' console.log('Test 3', checkTitle('Hello World!')); </code></pre> </div> </div> </p> <hr /> <p>It's not the best code, because it's not super clear, and you usually don't want to mix types like this. It also doesn't check if the title is a valid type, so <code>123</code> or <code>true</code> would be accepted as valid.</p> https://stackoverflow.com/questions/27873771/-/79556030#79556030 0 Answer by Alicia Sykes for How to show the "Repositories contributed to" on github Alicia Sykes https://stackoverflow.com/users/979052 2025-04-04T18:16:42Z 2025-04-04T20:03:43Z <h2>Quick Answer</h2> <pre class="lang-bash prettyprint-override"><code>USERNAME=&quot;Lissy93&quot; for PAGE in {1..10}; do curl -s &quot;https://api.github.com/search/issues?q=author:$USERNAME+type:pr&amp;per_page=100&amp;page=$PAGE&quot; | jq -r '.items // [] | .[].repository_url' done | sort -u | cut -d '/' -f 5,6 </code></pre> <p>This snippet will:</p> <ul> <li>Output just the required [org]/[repo]</li> <li>Deduplicate contributions to the same repo</li> <li>Page through results (so you can get more than 1000 repos)</li> </ul> <p>Just paste it into your terminal, update the username, and you should see a list of repos.</p> <hr /> <h2>Longer Answer</h2> <p>Or take a look at this API endpoint: <a href="https://api.github.com/search/issues?q=author:lissy93+type:pr" rel="nofollow noreferrer"><code>https://api.github.com/search/issues?q=author:lissy93+type:pr</code></a>. Since it returns duplicates, a lot of extra info, and is limited to 100 results per page, we need to format that to get a nice list.</p> <h3>JavaScript Example</h3> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false" data-babel-preset-react="false" data-babel-preset-ts="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>(async () =&gt; { const repos = new Set(); for (let page = 1; page &lt;= 10; page++) { const res = await fetch(`https://api.github.com/search/issues?q=author:lissy93+type:pr&amp;per_page=100&amp;page=${page}`); const data = await res.json(); if (!data.items?.length) break; data.items.forEach(i =&gt; { const m = i.repository_url.match(/repos\/([^/]+\/[^/]+)/); if (m) repos.add(m[1]); }); } console.log([...repos].sort()); })();</code></pre> </div> </div> </p> <h3>Python Example</h3> <pre class="lang-py prettyprint-override"><code>import requests repos = set() for page in range(1, 11): url = f&quot;https://api.github.com/search/issues?q=author:octocat+type:pr&amp;per_page=100&amp;page={page}&quot; res = requests.get(url).json() for item in res.get(&quot;items&quot;, []): parts = item[&quot;repository_url&quot;].split(&quot;/&quot;)[-2:] repos.add(&quot;/&quot;.join(parts)) if not res.get(&quot;items&quot;): break print(&quot;\n&quot;.join(sorted(repos))) </code></pre> <hr /> <h2>Via the GitHub UI</h2> <p>I don't think there's an easy way to do this in the GitHub UI anymore; You can go to the user's profile, under Contribution Activity --&gt; See all activity. But that includes more than just contributions.</p> <p>Or, there's also <a href="https://github.com/settings/repositories" rel="nofollow noreferrer">github.com/settings/repositories</a> which will show all repositories that you (the authenticated user) have access to (write permissions).</p> https://stackoverflow.com/questions/76406446/error-cannot-resolve-type-entity-i29-draganddropmodule-to-symbol/79119384#79119384 0 Answer by Alicia Sykes for Error: Cannot resolve type entity i29.DragAndDropModule to symbol Alicia Sykes https://stackoverflow.com/users/979052 2024-10-23T19:06:13Z 2024-10-23T19:06:13Z <p>In case anyone whose not using Kendo is facing this issue, then it can commonly be resolved by ensuring that Angular CDK is installed.</p> <pre class="lang-bash prettyprint-override"><code>npm install @angular/cdk </code></pre> <p>This is because the drag 'n drop functionality is provided by Angular CDK which interfaces with the HTML 5 Drag and Drop API.</p> <p>I encountered this while using PrimeNG's PickListModule which used drag and drop, and found the solution in <a href="https://github.com/primefaces/primeng/issues/11581" rel="nofollow noreferrer">primefaces/primeng#11581</a></p> <hr /> <p>In the future, I expect this to be resolved upstream in most Angular 18+ libraries, so long as you have <code>preserveSymlinks</code> set in your TSConfig's compiler options, like:</p> <pre class="lang-json prettyprint-override"><code>&quot;compilerOptions&quot;: { &quot;preserveSymlinks&quot;: true } </code></pre> https://stackoverflow.com/questions/42749704/-/74235768#74235768 18 Answer by Alicia Sykes for Reindex a source code in the VSCode Alicia Sykes https://stackoverflow.com/users/979052 2022-10-28T12:56:54Z 2023-12-17T20:36:42Z <p><em>This question is a few years old now, but this is an issue I've seen a lot, and can usually be fixed with <a href="https://stackoverflow.com/a/74235768/979052">one of the following</a> 5 options:</em></p> <h3>Reload Session</h3> <p>You can reload the current session, with the <code>workbench.action.reloadWindow</code> command:</p> <blockquote> <p>Open the Command Palette with <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd> Then type <code>Reload Window</code></p> </blockquote> <hr /> <h3>Filter Files being Indexed</h3> <p>For C/C++ projects specificially, sometimes the intellisense indexing can be really slow, and feel like it's not working. One solution for this is to limit what it indexes with something like <code>limitSymbolsToIncludedHeaders</code>, or reduce the amount of parsed files in <code>c_cpp_properties.json</code></p> <pre class="lang-json prettyprint-override"><code>&quot;browse&quot;: { &quot;path&quot;: [ &quot;/usr/include/&quot;, &quot;/usr/local/include/&quot;, &quot;${workspaceRoot}/../include&quot;, &quot;${workspaceRoot}/dir2&quot;, &quot;${workspaceRoot}/dir3/src/c++&quot; ... ] } </code></pre> <hr /> <h3>Set File Associations</h3> <p>Sometimes the file associations are incorrect, so files are not indexed as expected. This can be fixed by adding something similar to this into your VS Code settings (<code>settings.json</code>):</p> <pre class="lang-json prettyprint-override"><code>&quot;intelephense.files.associations&quot;: [&quot;*.php&quot;, &quot;*.phtml&quot;, &quot;*.inc&quot;, &quot;*.module&quot;, &quot;*.install&quot;, &quot;*.theme&quot;, &quot;.engine&quot;, &quot;.profile&quot;, &quot;.info&quot;, &quot;.test&quot;] </code></pre> <hr /> <h3>Rebuild System Index</h3> <p>For Windows users, VS Code uses the system search index, so <a href="https://www.kapilarya.com/how-to-reset-and-rebuild-search-index-in-windows-10" rel="noreferrer">rebuilding that</a> may help.</p> <hr /> <h3>Network Drive Setup</h3> <p>If you're project is sourced on a network drive, there's an extra step involved to get indexing working, by mounting to a local drive. This is a known issue (see <a href="https://github.com/microsoft/vscode-cpptools/issues/4008" rel="noreferrer">#4008</a>), which can be resolved by mounting the app from a fixed drive or mapping the network drive to a local drive letter (e.g. if your network drive is located at <code>\\NETWORKPATH\home\USER\REPO\GITREPO</code>, then map it to <code>X:/</code> on your local machine.</p> <hr /> <h3>Ensure Intellisense Enabled</h3> <p>Finally, it may seem obvious, but just confirm that <a href="https://code.visualstudio.com/docs/editor/intellisense" rel="noreferrer">Intellisense</a> is actually enabled, with <code>editor.tabCompletion</code> in your settings.json. And if you're searching with results not displaying, ensure there aren't any filters preventing results.</p> https://stackoverflow.com/questions/75961468/-/76743730#76743730 2 Answer by Alicia Sykes for "Could not find Chromium" when using puppeteer in a Netlify lambda function Alicia Sykes https://stackoverflow.com/users/979052 2023-07-22T12:17:53Z 2023-07-22T12:17:53Z <p>A little bit late here, but I was trying to do something similar, and got it working using <a href="https://github.com/Sparticuz/chromium" rel="nofollow noreferrer">@Sparticuz/chromium</a> and <a href="https://www.npmjs.com/package/puppeteer-core" rel="nofollow noreferrer">puppeteer-core</a>.</p> <p>The <a href="https://github.com/Sparticuz/chromium#migration-from-chrome-aws-lambda" rel="nofollow noreferrer">docs</a> show how to migrate from <a href="https://github.com/alixaxel/chrome-aws-lambda" rel="nofollow noreferrer">chrome-aws-lambda</a>, which does not run on Netlify anymore.</p> <hr /> <p>So here's a working example, which takes a <code>?url=https://example.com</code> param, loads the content in headless chromium, takes a screenshot, and returns it as base64 encoded data. I deployed it to Netlify, and seems to work great.</p> <pre class="lang-js prettyprint-override"><code>const puppeteer = require('puppeteer-core'); const chromium = require('@sparticuz/chromium'); exports.handler = async (event, context, callback) =&gt; { let browser = null; let targetUrl = event.queryStringParameters.url; if (!targetUrl) { callback(null, { statusCode: 400, body: JSON.stringify({ error: 'URL is missing from queryStringParameters' }), }); return; } if (!targetUrl.startsWith('http://') &amp;&amp; !targetUrl.startsWith('https://')) { targetUrl = 'http://' + targetUrl; } try { new URL(targetUrl); } catch (error) { callback(null, { statusCode: 400, body: JSON.stringify({ error: 'URL provided is invalid' }), }); return; } try { browser = await puppeteer.launch({ args: chromium.args, defaultViewport: { width: 800, height: 600 }, executablePath: await chromium.executablePath(), headless: chromium.headless, ignoreHTTPSErrors: true, }); let page = await browser.newPage(); // Emulate dark theme await page.emulateMediaFeatures([{ name: 'prefers-color-scheme', value: 'dark' }]); // Set navigation timeout page.setDefaultNavigationTimeout(8000); await page.goto(targetUrl, { waitUntil: 'domcontentloaded' }); // Ensure the page has some minimal interactivity before taking the screenshot. await page.evaluate(() =&gt; { const selector = 'body'; return new Promise((resolve, reject) =&gt; { const element = document.querySelector(selector); if (!element) { reject(new Error(`Error: No element found with selector: ${selector}`)); } resolve(); }); }); const screenshotBuffer = await page.screenshot(); const base64Screenshot = screenshotBuffer.toString('base64'); const response = { statusCode: 200, body: JSON.stringify({ image: base64Screenshot }), }; callback(null, response); } catch (error) { callback(null, { statusCode: 500, body: JSON.stringify({ error: `An error occurred: ${error.message}` }), }); } finally { if (browser !== null) { await browser.close(); } } }; </code></pre> <p>Only thing to note, is when I was running this locally (with <code>netlify dev</code>), it was unable to find the path to my Chromium executable, so as a temporary work-around, I switched the <code>executablePath: '/usr/bin/chromium'</code> (for Arch Linux) during dev - I'm sure there's better way though.</p> <p>I also couldn't get it to respond with the normal <code>resolve</code> methods, which is why I defaulted back to the older <code>callback</code> approach using the third param in the handler. Again, I'm sure there's a better way to do this.</p> https://stackoverflow.com/questions/75965447/-/75965533#75965533 0 Answer by Alicia Sykes for dockerized Kafka service stuck at producer.send Alicia Sykes https://stackoverflow.com/users/979052 2023-04-08T13:33:21Z 2023-04-08T13:33:21Z <p>It looks like your Kafka procucer isn't able to reach the Kafka broker in the Docker network.</p> <p>Since you've got the Kafka service in your docker-compose, that will act as the hostname within the Docker network.</p> <p>So it should just be a case of updating the <code>bootstrap_servers=['kafka:9092']</code> in your <code>producer.py</code> with an environmental variable, so it can be used both within the Docker netowork, and when the script is run outside Docker (w <code>python3 src/producer.py</code>).</p> <pre class="lang-py prettyprint-override"><code># Get env var kafka_bootstrap_servers = os.environ.get(&quot;KAFKA_BOOTSTRAP_SERVERS&quot;, &quot;localhost:9092&quot;) # Use in producer producer = KafkaProducer(bootstrap_servers=kafka_bootstrap_servers, api_version=(0, 10)) </code></pre> <p>Then, under <code>publisher</code> in your <code>docker-compose.yml</code> add:</p> <pre class="lang-yaml prettyprint-override"><code>environment: KAFKA_BOOTSTRAP_SERVERS: kafka:9092 </code></pre> <p>Then, when running within the Docker network is will use the environmental variable (<code>KAFKA_BOOTSTRAP_SERVERS</code>), but when running directly it will use the default value (<code>localhost:9092</code>)</p> https://stackoverflow.com/questions/75965206/-/75965401#75965401 1 Answer by Alicia Sykes for Jquery - Download data in chunks from server and keep appending to a file on client Alicia Sykes https://stackoverflow.com/users/979052 2023-04-08T13:09:27Z 2023-04-08T13:09:27Z <p>You'd probably want to use the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Streams_API" rel="nofollow noreferrer">JS Streams API</a>, which let's you break large resources down into smaller chunks for easier processing.</p> <p>Here's an (untested) example, based on your initial code.</p> <pre class="lang-js prettyprint-override"><code>// Prepare the stream for writing async function prepareStream(filename) { const encoder = new TextEncoder(); const stream = new WritableStream({ write(chunk) { return encoder.encode(chunk); } }); const response = new Response(stream); const blob = await response.blob(); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.setAttribute('href', url); link.setAttribute('download', filename); link.setAttribute('target', '_blank'); link.style.visibility = 'hidden'; document.body.appendChild(link); link.click(); document.body.removeChild(link); return stream.getWriter(); } // Write data to the stream async function writeDataToFile(writer, data, delimiter) { const rows = data.map((obj) =&gt; Object.values(obj).join(delimiter)); const csvContent = rows.join('\n') + '\n'; await writer.write(csvContent); } // Close the stream when finished async function closeStream(writer) { await writer.close(); } // Example usage (async () =&gt; { const delimiter = ','; const filename = 'export.csv'; const writer = await prepareStream(filename); // Replace this loop with your API call loop for (let i = 0; i &lt; 10; i++) { const data = [ { id: i * 10 + 1, name: 'John', age: 25 }, { id: i * 10 + 2, name: 'Jane', age: 24 }, ]; await writeDataToFile(writer, data, delimiter); } await closeStream(writer); })(); </code></pre> https://stackoverflow.com/questions/64780498/-/75402379#75402379 1 Answer by Alicia Sykes for Differentiate between Server Side and Client Side on fetch Sapper Alicia Sykes https://stackoverflow.com/users/979052 2023-02-09T17:34:05Z 2023-02-09T17:34:05Z <p>Just an update, for SvelteKit 1.0.0 and later...</p> <p>The <a href="https://kit.svelte.dev/docs/modules#$app-environment" rel="nofollow noreferrer"><code>environment</code></a> module includes the <a href="https://kit.svelte.dev/docs/modules#$app-environment-browser" rel="nofollow noreferrer"><code>browser</code></a> property, which returns <code>true</code> if being run client-side.</p> <p>For example,</p> <pre class="lang-js prettyprint-override"><code>import { browser } from '$app/environment'; if (browser) { // Running client-side // Can use the browser APIs here } else { // Running server-side // Can use private env vars here } </code></pre> https://stackoverflow.com/questions/74804013/-/74804049#74804049 1 Answer by Alicia Sykes for How do I align text in top left corner of div? Alicia Sykes https://stackoverflow.com/users/979052 2022-12-14T20:52:12Z 2022-12-14T21:03:34Z <p>(I'll update my answer with more specific code samples, once you've shared your markup)</p> <h2>Option #1 - Absolute Positioning</h2> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>.wrapper { position: relative; min-height: 300px; border: 2px dashed red; } .top-left { position: absolute; top: 0.25rem; left: 0.25rem; border: 2px dashed blue; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="wrapper"&gt; &lt;div class="top-left"&gt;[123]&lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <h2>Option #2 - Flex Layout</h2> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>.wrapper { display: flex; justify-content: flex-start; align-items: baseline; min-height: 300px; border: 2px dashed red; } .top-left { border: 2px dashed blue; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="wrapper"&gt; &lt;div class="top-left"&gt;[123]&lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <h2>Option #3 - Grid Layout</h2> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>.wrapper { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); min-height: 200px; border: 2px dashed red; } .top-left { grid-column-start: 1; grid-column-end: 1; border: 2px dashed blue; } .cell { border: 2px dashed yellow; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="wrapper"&gt; &lt;div class="top-left"&gt;[123]&lt;/div&gt; &lt;div class="cell"&gt;[CELL]&lt;/div&gt; &lt;div class="cell"&gt;[CELL]&lt;/div&gt; &lt;div class="cell"&gt;[CELL]&lt;/div&gt; &lt;div class="cell"&gt;[CELL]&lt;/div&gt; &lt;div class="cell"&gt;[CELL]&lt;/div&gt; &lt;div class="cell"&gt;[CELL]&lt;/div&gt; &lt;div class="cell"&gt;[CELL]&lt;/div&gt; &lt;div class="cell"&gt;[CELL]&lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> https://stackoverflow.com/questions/74648912/-/74648959#74648959 2 Answer by Alicia Sykes for Compile Error: Assign arrow function to a variable before exporting as module default Alicia Sykes https://stackoverflow.com/users/979052 2022-12-01T22:40:25Z 2022-12-01T22:56:54Z <p>For arrow functions, since they're anonymous you'll need to assign it to a variable which you can then export. This example, based on your code should work (but don't forget to fill in the logic within the tasks.map function)</p> <pre class="lang-js prettyprint-override"><code>import React from 'react'; import TaskList from './TaskList'; const Tasks = ({ tasks }) =&gt; { return tasks.map(task =&gt; ( ... )); } export default Tasks; </code></pre> <p>It's caused by the <a href="https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-anonymous-default-export.md" rel="nofollow noreferrer"><code>import/no-anonymous-default-export</code></a> rule, which prevents a module's default export from being unnamed.</p> <p>Since it's a lint warning, and not a syntatical error, if you were to disable that rule, your existing code would work (but I recommend <strong>not</strong> doing that!).</p> <p>This rule is useful, as ensuring that default exports are named helps improve the grepability of the codebase by encouraging the re-use of the same identifier for the module's default export at its declaration site and at its import sites.</p> https://stackoverflow.com/questions/74606483/-/74606625#74606625 1 Answer by Alicia Sykes for Trying to figure out how to add this javascript Alicia Sykes https://stackoverflow.com/users/979052 2022-11-28T21:25:44Z 2022-11-28T21:25:44Z <p>Here's a working snippet. As mentioned by Kinglish (in the comments), the issue is there is no value property in the objects you are looping through it should say <code>customerid</code> instead.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>const orderlist = document.getElementById('orderlist'); let orderid = [0]; const loadorders = async() =&gt; { try { const res = await fetch('https://www.cc.puv.fi/~asa/cgi-bin/fetchOrders.py'); orderid = await res.json(); displayorderid(orderid); } catch (err) { console.error(err); console.log(res); } }; const displayorderid = (orderObject) =&gt; { const htmlString = orderObject .map((orderObject) =&gt; { return ` &lt;li class="orderid"&gt; &lt;h2&gt;${orderObject.customerid}&lt;/h2&gt; &lt;/li&gt; `; //&lt;------- the customerid property exists }) .join(''); orderlist.innerHTML = htmlString; }; loadorders();</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>body { font-family: Georgia, serif; background-color: rgb(59, 59, 243); } * { box-sizing: border-box; } h1 { color: azure margin-bottom:30px; } .container { padding: 35px; margin: 0 auto; max-width: 1000px; text-align: center center; } #customerslist { padding-inline-start: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); grid-gap: 15; } .Customer { list-style-type: none; background-color: aquamarine; border-radius: 5px; padding: 10px 25px; grid-template-columns: 3fr 1fr; grid-template-areas: ; text-align: left; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="container"&gt; &lt;h1&gt;tilaukset&lt;/h1&gt; &lt;div id="search"&gt; &lt;input type="text" name="Hakupalkki" id="Hakupalkki" placeholder="Hae tilausta" /&gt; &lt;/div&gt; &lt;ul id="orderlist"&gt;&lt;/ul&gt; &lt;/div&gt;</code></pre> </div> </div> </p> https://stackoverflow.com/questions/73765634/-/73765751#73765751 1 Answer by Alicia Sykes for Vue js does not bind values to form Alicia Sykes https://stackoverflow.com/users/979052 2022-09-18T19:14:57Z 2022-09-18T22:24:25Z <h3>Vue 2</h3> <p>Use <code>v-model</code> instead of <code>value</code></p> <p>Here's a working example:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>Vue.config.devtools = false; Vue.config.productionTip = false; new Vue({ el: '#app', name: 'memite7760-demo', data() { return { email: '', password: '', } }, })</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://unpkg.com/vue@2.x/dist/vue.js"&gt;&lt;/script&gt; &lt;div id="app"&gt; &lt;form&gt; &lt;div&gt; &lt;label for="email"&gt;Email:&lt;/label&gt; &lt;input type="text" name="email" id="email" v-model="email"&gt; &lt;/div&gt; &lt;div&gt; &lt;label for="email"&gt;Password:&lt;/label&gt; &lt;input type="password" name="password" id="password" v-model="password"&gt; &lt;/div&gt; &lt;button type="submit"&gt;Submit&lt;/button&gt; &lt;/form&gt; &lt;div&gt; Username: {{ email }}, Password: {{ password }} &lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <hr /> <h3>Vue 3</h3> <p>As <a href="https://stackoverflow.com/a/73766658/979052">pointed out by @tao</a>, you have a small typo: <code>date</code> should be <code>data</code>. He also gives some good advice re imports</p> <p>Again, here's a working example:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>const App = { data() { return { email: 'example@roocket.ir', password: '123456' } } }; Vue.createApp(App).mount('#app');</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"&gt;&lt;/script&gt; &lt;div id="app"&gt; &lt;form&gt; &lt;div&gt; &lt;label for="email"&gt;Email:&lt;/label&gt; &lt;input type="text" name="email" id="email" v-model="email"&gt; &lt;/div&gt; &lt;div&gt; &lt;label for="email"&gt;Password:&lt;/label&gt; &lt;input type="password" name="password" id="password" v-model="password"&gt; &lt;/div&gt; &lt;button type="submit"&gt;Submit&lt;/button&gt; &lt;/form&gt; Email: {{email}}, Pass: {{password}} &lt;/div&gt;</code></pre> </div> </div> </p> https://stackoverflow.com/questions/73757719/-/73757893#73757893 1 Answer by Alicia Sykes for I Need Help Randomizing an <a> Tag Alicia Sykes https://stackoverflow.com/users/979052 2022-09-17T19:27:28Z 2022-09-17T19:27:28Z <p>The key is to break it down:</p> <ol> <li>Define your list of possible destinations</li> <li>Select one at random</li> <li>Grab the DOM element to change</li> <li>Set the DOM element's href link to your random page</li> </ol> <p>Here's a working example:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>const destinations = [ 'my-destination-1.html', 'my-destination-2.html', 'my-destination-3.html', 'my-destination-4.html', 'my-destination-5.html' ]; const randomIndex = Math.floor(Math.random()*destinations.length); const randomDestination = destinations[randomIndex]; const randomJokeLink = document.getElementById('random-joke-link'); randomJokeLink.setAttribute("href", randomDestination);</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;a id="random-joke-link" href="#"&gt;Random Joke&lt;/a&gt;</code></pre> </div> </div> </p> https://stackoverflow.com/questions/73675353/-/73675425#73675425 1 Answer by Alicia Sykes for datepicker does not work even after following the same script Alicia Sykes https://stackoverflow.com/users/979052 2022-09-10T21:57:17Z 2022-09-10T21:57:17Z <p>Looks like the DOM hasn't finished loading at the time that you're executing your JavaScript.</p> <p>jQuery has an implementation of the window <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event" rel="nofollow noreferrer">load event</a>, which is <a href="https://learn.jquery.com/using-jquery-core/document-ready/" rel="nofollow noreferrer"><code>$( document ).ready()</code></a>.</p> <p>In your example, that would be:</p> <pre class="lang-js prettyprint-override"><code>$(document).ready(() =&gt; { $('.pickupDate').datepicker(); $('.dropoffDate').datepicker(); $('.pickupDate').change(() =&gt; { const date2 = $('.pickupDate').datepicker('getDate', '+1d'); $('.dropoffDate').datepicker('setDate', date2.getDate() + 1); }); }); </code></pre> <p>Also, you probably want to load those external scripts from within your <code>&lt;head&gt;</code> tag. You could also consider downloading them locally using <a href="https://npmjs.com/" rel="nofollow noreferrer">NPM</a>.</p> https://stackoverflow.com/questions/73664724/-/73665133#73665133 0 Answer by Alicia Sykes for How do I use my existing toggle to also switch between two css sheets? Alicia Sykes https://stackoverflow.com/users/979052 2022-09-09T16:36:38Z 2022-09-09T16:43:27Z <p>The easiest method would be to determine the theme based on HTML data attribute, then check which theme is applied in the CSS using <code>html[data-theme='dark']</code> or <code>html[data-theme='light']</code>.</p> <p><em>This can be broken down into several steps:</em></p> <h2>Apply Styles Based on Data Attribute</h2> <p>You can apply CSS to any given element by targetting data values. In this instance, you'd probably want to apply this value to an upper-most node, like <code>&lt;html&gt;</code>.</p> <p>In JavaScript, you can change this value with:</p> <pre><code>document.getElementsByTagName('html')[0].setAttribute('data-theme', 'dark'); </code></pre> <p>Which will update the HTML to look like:</p> <pre class="lang-html prettyprint-override"><code>&lt;html data-theme=&quot;dark&quot;&gt; ... &lt;/html&gt; </code></pre> <p>That can then be targeted in CSS with:</p> <pre class="lang-css prettyprint-override"><code>html[data-theme='light'] { --background: #fff; --foreground: #000; } html[data-theme='dark'] { --background: #000; --foreground: #fff; } </code></pre> <hr /> <h2>Store User Preference</h2> <p>When the user changes theme, store their choice in the browsers local storage, using <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage" rel="nofollow noreferrer"><code>Window.localStorage</code></a>, then apply it again next time they visit your site.</p> <pre class="lang-js prettyprint-override"><code>// Set window.localStorage.setItem('theme', 'dark'); // Get const theme = window.localStorage.theme; </code></pre> <p>Here's a more <a href="https://listed.to/p/YcUgsjeFPh" rel="nofollow noreferrer">detailed tutorial</a>.</p> <hr /> <h2>Detect User Light / Dark Preference</h2> <p>You can check if the user's OS / browser is set to prefer light or dark mode, and apply that theme on initial page load. This is done using <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme" rel="nofollow noreferrer"><code>prefers-color-scheme</code></a></p> <pre class="lang-css prettyprint-override"><code>@media (prefers-color-scheme: dark) { --background: #000; --foreground: #fff; } @media (prefers-color-scheme: light) { --background: #fff; --foreground: #000; } </code></pre> <hr /> <h2>Putting it all Together</h2> <p>Here's a live example, which combines the above points into a runnable code snippet, which you can integrate into your app</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>const setTheme = () =&gt; { const newTheme = document.getElementById('theme-selector').value; const htmlTag = document.getElementsByTagName('html')[0]; if (htmlTag.hasAttribute('data-theme')) htmlTag.removeAttribute('data-theme'); htmlTag.setAttribute('data-theme', newTheme); window.localStorage.setItem('theme', newTheme); } // Apply previously saved theme, on page load document.onload = function() { const savedTheme = window.localStorage.theme; if (savedTheme) { document.getElementsByTagName('html')[0].setAttribute('data-theme', savedTheme) } };</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>html[data-theme='light'] { --background: #fff; --foreground: #000; } html[data-theme='dark'] { --background: #000; --foreground: #fff; } body { background: var(--background); color: var(--foreground); }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;label for="theme-selector"&gt;Theme&lt;/label&gt; &lt;select id="theme-selector" onchange="setTheme()"&gt; &lt;option value="light"&gt;Light&lt;/option&gt; &lt;option value="dark"&gt;Dark&lt;/option&gt; &lt;/select&gt;</code></pre> </div> </div> </p> <p>If you want to see a real-world example, of how this could scale up for larger code bases, I am using this approach in <a href="https://github.com/lissy93/dashy/" rel="nofollow noreferrer">this app</a>, and the theming is explained in <a href="https://github.com/Lissy93/dashy/blob/master/docs/theming.md" rel="nofollow noreferrer">this docs</a></p> https://stackoverflow.com/questions/73651059/-/73651156#73651156 1 Answer by Alicia Sykes for How to display current date in in html using javscript (jquery) Alicia Sykes https://stackoverflow.com/users/979052 2022-09-08T14:55:43Z 2022-09-08T15:36:29Z <p>Here's a working proof of concept, without using any external libraries. It basically just converts seconds to minutes if it's over 60, minutes to hours if over 60, hours to days if over 24, etc...</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>/* Given two timestamp, return the difference in text format, e.g. '10 minutes' */ const getTimeDifference = (startTime, endTime) =&gt; { const msDifference = new Date(endTime).getTime() - new Date(startTime).getTime(); const diff = Math.abs(Math.round(msDifference / 1000)); const divide = (time, round) =&gt; Math.round(time / round); if (diff &lt; 60) return `${divide(diff, 1)} seconds`; if (diff &lt; 3600) return `${divide(diff, 60)} minutes`; if (diff &lt; 86400) return `${divide(diff, 3600)} hours`; if (diff &lt; 604800) return `${divide(diff, 86400)} days`; if (diff &lt; 31557600) return `${divide(diff, 604800)} weeks`; if (diff &gt;= 31557600) return `${divide(diff, 31557600)} years`; return 'unknown'; }; /* Given a timestamp, return how long ago it was, e.g. '10 minutes' */ const getTimeAgo = (dateTime) =&gt; { const now = new Date().getTime(); const isHistorical = new Date(dateTime).getTime() &lt; now; const diffStr = getTimeDifference(dateTime, now); if (diffStr === 'unknown') return diffStr; return isHistorical ? `${diffStr} ago` : `in ${diffStr}`; }; /* Update the UI at intervals */ const startTime = new Date(); const timer = setInterval(() =&gt; { document.getElementById('comment').innerHTML = getTimeAgo(startTime); }, 1000);</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;p id="comment"&gt;&lt;/p&gt;</code></pre> </div> </div> </p> https://stackoverflow.com/questions/73531705/-/73531789#73531789 1 Answer by Alicia Sykes for How to Combine Same key JavaScript Object to one Array Dynamically Alicia Sykes https://stackoverflow.com/users/979052 2022-08-29T16:24:09Z 2022-08-29T16:24:09Z <p>You can just iterate over your input data's keys. Then if the key already exists in your results you append the new value, otherwise create an array with the first value within your results.</p> <p>Here's a working demo:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>const sample = [ { 1: { date: 1638334800, value: 0 }, 2: { date: 1638334800, value: 19.71 }, nth: { date: 1638334800, value: 19.71 } }, { 1: { date: 1638334800, value: 0 }, 2: { date: 1638334800, value: 23.77 }, nth: { date: 1638334800, value: 19.71 } } ]; const generateOutput = (inputData) =&gt; { const results = {}; inputData.forEach((dataSet) =&gt; { Object.keys(dataSet).forEach((key) =&gt; { if (results[key]) { results[key].push(dataSet[key]); } else { results[key] = [dataSet[key]]; } }); }); return results; } console.log(generateOutput(sample));</code></pre> </div> </div> </p> https://stackoverflow.com/questions/73522370/-/73522520#73522520 1 Answer by Alicia Sykes for How to capitalize all keys in an array of objects? Alicia Sykes https://stackoverflow.com/users/979052 2022-08-28T21:50:21Z 2022-08-28T22:18:39Z <p>It looks like the issue is with your capitalization method.</p> <p>The following alternative should work:</p> <pre class="lang-js prettyprint-override"><code>const capitalizeKey = (key) =&gt; key.charAt(0).toUpperCase() + key.slice(1); </code></pre> <p>Here's a very basic live demo:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>const capitalizeObjectKeys = (obj) =&gt; { if (!obj) return; if (Array.isArray(obj)) { return obj.map((each) =&gt; capitalizeObjectKeys(each)) } const results = {}; Object.keys(obj).forEach((key) =&gt; { const newKey = key.charAt(0).toUpperCase() + key.slice(1); const objVal = (typeof obj[key] === 'object') ? capitalizeObjectKeys(obj[key]) : obj[key]; results[newKey] = objVal; }); return results; }; const sample = [{"id":3,"accountId":6,"title":"ABCDF Copy","versionDto":{"id":3,"entitlementsTemplateId":3,"status":"Draft","entitlementElementsTemplateDto":[{"id":5,"isHeaderCategory":false,"order":1},{"id":6,"isHeaderCategory":false,"order":2}]}}]; const results = capitalizeObjectKeys(sample) console.log(results);</code></pre> </div> </div> </p> https://stackoverflow.com/questions/73522434/height-100-in-css-does-not-behave-how-i-expect/73522476#73522476 1 Answer by Alicia Sykes for Height 100% in CSS does not behave how I expect Alicia Sykes https://stackoverflow.com/users/979052 2022-08-28T21:42:08Z 2022-08-28T22:07:09Z <p>The <a href="https://www.w3.org/TR/CSS22/visudet.html#the-height-property" rel="nofollow noreferrer"><code>height: 100%</code></a> attribute's percentage is calculated based on the containing block's height. And if that containing block doesn't have a specified and fixed height, then the percentage is invalid, and behind the scense it will default back to <code>auto</code> (which if the inner has no content, it will be zero).</p> <p>So, for percentage height to work on an in-flow child, the parent must have a set height.</p> <hr /> <p>In your example, just setting a display method to the outer container, and then setting height to fill parent will fix your issue, here's an <a href="https://codepen.io/Lissy93/pen/QWmXBrj?editors=1100" rel="nofollow noreferrer">updated CodePen</a>.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>* { box-sizing: border-box; } .outer { background-color: yellow; height: 1000px; width: 300px; } .inner { min-height: 500px; width: 200px; background-color: green; display: flex; } .inner-inner { height: fill; width: 100px; background-color: aqua; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt; &lt;div class="outer"&gt; &lt;div class="inner"&gt; &lt;div class="inner-inner"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt;</code></pre> </div> </div> </p> https://stackoverflow.com/questions/71873824/-/71876238#71876238 182 Answer by Alicia Sykes for Copy text to clipboard: Cannot read properties of undefined reading 'writeText' Alicia Sykes https://stackoverflow.com/users/979052 2022-04-14T18:37:51Z 2022-08-27T18:27:07Z <p>The use of <code>navigator.clipboard</code> requires a secure origin. So if your dev environment is being served over HTTP, then the clipboard method won't be available.</p> <p><em>According to MDN <a href="https://developer.mozilla.org/en-US/docs/Web/API/Clipboard" rel="noreferrer"><code>Clipboard</code></a> docs</em></p> <blockquote> <p>This feature is available only in <a href="https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts" rel="noreferrer">secure contexts</a> (HTTPS), in some or all <a href="https://developer.mozilla.org/en-US/docs/Web/API/Clipboard#browser_compatibility" rel="noreferrer">supporting browsers</a>.</p> </blockquote> <p>Maybe you could check if this method is available with <code>window.isSecureContext</code>, and disable the Copy Text button accordingly.</p> <hr /> <h3>Workaround</h3> <p>The best option is to use HTTPS in your dev environment.</p> <p>But since you asked for a workaround, here's a (very hacky) working method. Using <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand" rel="noreferrer"><code>Document.exec</code></a> command, which is no longer recommended, in favour of <a href="https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API" rel="noreferrer"><code>ClipboardAPI</code></a>.</p> <pre class="lang-js prettyprint-override"><code>function unsecuredCopyToClipboard(text) { const textArea = document.createElement(&quot;textarea&quot;); textArea.value = text; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { document.execCommand('copy'); } catch (err) { console.error('Unable to copy to clipboard', err); } document.body.removeChild(textArea); } </code></pre> <h3>Usage</h3> <p>You can then just check if <code>!navigator.clipboard</code> and call the fallback method, otherwise continue with the normal <code>navigator.clipboard.writeText(...)</code> function. For example:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>const unsecuredCopyToClipboard = (text) =&gt; { const textArea = document.createElement("textarea"); textArea.value=text; document.body.appendChild(textArea); textArea.focus();textArea.select(); try{document.execCommand('copy')}catch(err){console.error('Unable to copy to clipboard',err)}document.body.removeChild(textArea)}; /** * Copies the text passed as param to the system clipboard * Check if using HTTPS and navigator.clipboard is available * Then uses standard clipboard API, otherwise uses fallback */ const copyToClipboard = (content) =&gt; { if (window.isSecureContext &amp;&amp; navigator.clipboard) { navigator.clipboard.writeText(content); } else { unsecuredCopyToClipboard(content); } };</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;button onClick="buttonPress()"&gt;➡️ Copy Message to Clipboard&lt;/button&gt; &lt;script type="text/javascript"&gt; const buttonPress = () =&gt; { copyToClipboard('Hello World!'); console.log('Clipboard updated 📥\nNow try pasting!'); }; &lt;/script&gt;</code></pre> </div> </div> </p> https://stackoverflow.com/questions/43953001/-/43953236#43953236 1 Answer by Alicia Sykes for Change source on audio end [multiple audios] JS & jQuery Alicia Sykes https://stackoverflow.com/users/979052 2017-05-13T12:36:33Z 2022-08-07T12:28:58Z <p>Here's a working <a href="https://jsfiddle.net/" rel="nofollow noreferrer">JSFiddle</a></p> <pre class="lang-js prettyprint-override"><code>// Plays random song from array function playNextRandom(){ const allSongs = [ &quot;http://www.noiseaddicts.com/samples_1w72b820/281.mp3&quot;, &quot;http://www.noiseaddicts.com/samples_1w72b820/4939.mp3&quot; ]; const randomIndex = allSongs[Math.floor(Math.random() * allSongs.length)]; $(&quot;audio&quot;).src = randomIndex; } // Executed when document has loaded $(document).ready(function(){ // Append audio element const audioElement = document.createElement(&quot;audio&quot;); audioElement.controls = true; audioElement.setAttribute(&quot;id&quot;, &quot;au&quot;); document.body.appendChild(audioElement); // Append Audio source const audioSource = document.createElement(&quot;source&quot;); audioSource.src = &quot;http://www.noiseaddicts.com/samples_1w72b820/4927.mp3&quot; audioElement.appendChild(audioSource); audioElement.play() audioSource.setAttribute(&quot;onended&quot;, &quot;playNextRandom&quot;); }) </code></pre> https://stackoverflow.com/questions/73259699/-/73259733#73259733 3 Answer by Alicia Sykes for cannot clear Interval within if query Alicia Sykes https://stackoverflow.com/users/979052 2022-08-06T12:28:04Z 2022-08-06T12:28:04Z <p>You need to put the <code>( y &gt; 3)</code> check within the <code>countdown</code> function. Currently it'll only be executed once, and at the end.</p> <p>Here's a working example:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>let y = 1; const countdown = () =&gt; { y += 0.5; console.log(y); if( y &gt;= 3) { clearInterval(timerId); } } const timerId = setInterval(countdown, 500);</code></pre> </div> </div> </p> https://stackoverflow.com/questions/73004461/-/73004916#73004916 0 Answer by Alicia Sykes for Vue not rendering fetched html Alicia Sykes https://stackoverflow.com/users/979052 2022-07-16T14:15:54Z 2022-07-16T14:26:47Z <p>You're approaching this in the traditional JavaScript way of manipulating the DOM directly. In Vue, we set state which can then be rendered by your template.</p> <p>Instead:</p> <ol> <li>Create a <code>data</code> attribute to store your state</li> <li>Under <code>methods</code>, write a function to fetch your data, then update the components <code>data</code></li> <li>Call your function in the components <code>created</code> hook</li> <li>In you're <code>template</code> render the results <ul> <li>Don't forget to check it's present first, with <code>v-if</code></li> <li>You can use <code>v-for</code> to iterate over, and render lists</li> </ul> </li> </ol> <p>Here's a <a href="https://codesandbox.io/s/nice-kilby-hupvj5?file=/src/components/HelloWorld.vue" rel="nofollow noreferrer">working demo</a></p> <hr /> <p>I don't have access to your API endpoint, so for demo purposes, am just using the GitHub API, to fetch and render a list of all repos in the Vue.js organization.</p> <p>Here's what it looks like:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>Vue.config.devtools = false; Vue.config.productionTip = false; new Vue({ el: '#app', name: 'dbzx10299-demo', data() { return { loaded: false, response: null, } }, methods: { fetchData() { const demoEndpoint = 'https://api.github.com/orgs/vuejs/repos'; fetch(demoEndpoint) .then(response =&gt; response.json()) .then(data =&gt; { this.response = data; this.loaded = true; }) }, }, mounted() { this.fetchData(); }, })</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://unpkg.com/vue@2.x/dist/vue.js"&gt;&lt;/script&gt; &lt;div id="app"&gt; &lt;div class="hello"&gt; &lt;h2&gt;Vue Repo List - Data fetching example&lt;/h2&gt; &lt;div v-if="!loaded"&gt;Loading...&lt;/div&gt; &lt;ul v-else&gt; &lt;li v-for="(repo, index) in response" :key="index"&gt; &lt;a :href="repo.html_url" :title="repo.description" target="_blank"&gt; {{ repo.name }} &lt;/a&gt; &lt;i&gt;★ {{ repo.stargazers_count }}&lt;/i&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> https://stackoverflow.com/q/44859961 1 How to manage multiple versions of the same NPM dependency? Alicia Sykes https://stackoverflow.com/users/979052 2017-07-01T10:37:56Z 2022-07-15T11:49:54Z <h4>Situation</h4> <p>I've written a bunch of <a href="https://d3js.org/" rel="nofollow noreferrer">D3.js</a> charts using the latest version of <a href="https://github.com/d3/d3/releases/tag/v4.9.1" rel="nofollow noreferrer">D3 (4.9.1)</a>.</p> <p>However I also need to include the occasional <a href="http://c3js.org/" rel="nofollow noreferrer">C3.js</a> chart in my app, problem is- C3 requires <a href="https://github.com/d3/d3/releases/tag/v3.5.17" rel="nofollow noreferrer">D3 v3.5.0</a>.</p> <hr /> <h4>What I've considered so far</h4> <ul> <li><p>Forking C3 to update it to the latest version of D3 (it's not really feasible though)</p> </li> <li><p>Using a different package manager, such as Yarn</p> </li> <li><p>Just forgetting about C3.... (don't want to do this, as it will involve a lot of re-work!)</p> </li> <li><p>Specifying a URL of an older version in the bower.json. However, I still was not able to reference to just that version for C3, and the latest for everything else.</p> <pre><code> &quot;d3&quot;: &quot;^4.9.1&quot;, &quot;d3-3.5.0&quot;: &quot;https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.0/d3.min.js&quot; </code></pre> </li> </ul> <hr /> <h4>Question</h4> <p>Is it possible to manage multiple versions of the same dependency, cleanly? And if not, what would be a sensible work-around?</p> https://stackoverflow.com/questions/18470069/-/18470362#18470362 0 Answer by Alicia Sykes for PHP timezone ahead or behind? Alicia Sykes https://stackoverflow.com/users/979052 2013-08-27T15:58:23Z 2022-06-30T05:01:11Z <p><strong>Greenwich Mean Time</strong> <br> Well if your using time(), it's in GMT as it is the Unix timestamp that's been counting seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).</p> https://stackoverflow.com/q/31524353 0 Gulp watch not called from within Nodemon Alicia Sykes https://stackoverflow.com/users/979052 2015-07-20T19:02:27Z 2022-06-30T05:00:09Z <p>So I have my Gulp file as below.</p> <p>The 'watch' block seems to work absolutely fine, and do what is expected. Nodemon works in the way that it detects file changes and refreshes the server, that works too.</p> <p>But I can't for the life of me get Nodemon to call the 'watch' method when a file changes.</p> <p>On line 81, the .on('start' is called succesfully from nodemon, but the code inside the 'watch' method is never executed.</p> <pre><code>var gulp = require('gulp'); var gutil = require('gulp-util'); // For logging stats and warnings var jshint = require('gulp-jshint'); // For checking JavaScript for warnings var concat = require('gulp-concat'); // For joining together multiple files var uglify = require('gulp-uglify'); // For minimising files var coffee = require('gulp-coffee'); // For compiling coffee script into js var cofLint = require('gulp-coffeelint');// For checking coffee script for errors var less = require('gulp-less'); // For compiling Less into CSS var cssLint = require('gulp-csslint'); // For checking the awesomeness of css var minCss = require('gulp-minify-css');// For minifying css var uncss = require('gulp-uncss'); // For deleting unused CSS rules var footer = require('gulp-footer'); // For adding footer text into files var nodemon = require('gulp-nodemon'); // For the super cool instant refreshing server var bSync = require('browser-sync'); // Syncs the place between multiple browsers for dev var es = require('event-stream'); // For working with streams rather than temp dirs var sourcePath = &quot;sources&quot;; var destPath = &quot;public&quot;; var jsFileName = &quot;all.min.js&quot;; var cssFileName = &quot;all.min.css&quot;; var footerText = &quot;&quot;; /* JavaScript Tasks */ gulp.task('scripts', function(){ var jsSrcPath = sourcePath + '/javascript/**/*'; var jsResPath = destPath + '/javascript'; var jsFromCs = gulp.src(jsSrcPath+'.coffee')// Get all coffee script .pipe(cofLint()) // Check CS for errors or warnings .pipe(cofLint.reporter()) // Output the error results .pipe(coffee()); // Convert coffee to vanilla js var jsFromPlain = gulp.src(jsSrcPath+'.js');// get all vanilla JavaScript return es.merge(jsFromCs, jsFromPlain) // Both js from cs and vanilla js .pipe(jshint()) // Check js errors or warnings .pipe(jshint.reporter('jshint-stylish')) // Print js errors or warnings .pipe(concat(jsFileName,{newLine: ';'})) // Concatenate all files together .pipe(uglify()) // Minify JavaScript .pipe(footer(footerText)) // Add footer to script .pipe(gulp.dest(jsResPath)); // Save to destination }); /* CSS Tasks */ gulp.task('styles', function(){ var cssSrcPath = sourcePath + '/styles/**/*'; var cssResPath = destPath + '/stylesheet'; var cssFromLess = gulp.src(cssSrcPath+'.less') // Get all Less code .pipe(less()); // Convert Less to CSS var cssFromVanilla = gulp.src(cssSrcPath+'.css');// Get all CSS return es.merge(cssFromLess, cssFromVanilla) // Combine both CSS .pipe(cssLint()) // Check CSS for errors or warnings .pipe(cssLint.reporter()) // And output the results .pipe(concat(cssFileName)) // Concatenate all files together .pipe(minCss({compatibility: 'ie8'})) // Minify the CSS .pipe(gulp.dest(cssResPath)); // Save to destination }); /* Configure files to watch for changes */ gulp.task('watch', function() { gulp.watch(sourcePath+'/**/*.{js,coffee}', ['scripts']); gulp.watch(sourcePath+'/**/*.{css,less}', ['styles']); }); /* Start Nodemon */ gulp.task('demon', function () { nodemon({ script: './bin/www', ext: 'js coffee css less html', env: { 'NODE_ENV': 'development'} }) .on('start', ['watch'])//TODO: ERROR: watch is never called, even though start is called .on('change', ['watch']) .on('restart', function () { console.log('restarted!'); }); }); /* Default Task */ gulp.task('default', ['demon']); </code></pre> <p>Any suggestions why this may be happening? Is there something wrong with my Gulp file?</p> <p>(and yes, I know the code is a little over-commented, I work with apprentices and they like English better than code ;)</p> https://stackoverflow.com/questions/79664676/is-visual-studio-standard-conformant-when-it-seemingly-doesnt-elide-a-copy-when/79666213?cid=140536220#79666213 Comment by Alicia Sykes on Is visual studio standard conformant when it seemingly doesn't elide a copy when calling a function Alicia Sykes https://stackoverflow.com/users/979052 2025-06-23T19:56:23Z 2025-06-23T19:56:23Z @Fedor tested and can confirm this does not occour in 17.14. So, once out then update and issue should be resolved. https://stackoverflow.com/questions/1188587/cache-invalidation-is-there-a-general-solution/1188719?cid=140256596#1188719 Comment by Alicia Sykes on Cache Invalidation — Is there a General Solution? Alicia Sykes https://stackoverflow.com/users/979052 2025-03-24T12:46:37Z 2025-03-24T12:46:37Z I love that you aced cache invalidation, but totally failed on the naming things. Just to prove Phill Karlton&#39;s point! https://stackoverflow.com/questions/71873824/copy-text-to-clipboard-cannot-read-properties-of-undefined-reading-writetext/71876238?cid=135134922#71876238 Comment by Alicia Sykes on Copy text to clipboard: Cannot read properties of undefined reading 'writeText' Alicia Sykes https://stackoverflow.com/users/979052 2023-07-09T13:53:33Z 2023-07-09T13:53:33Z @bpGusar Locally-delivered resources are also considered secure, as there&#39;s no opportunity for an external actor to use a MITM attack :) See the <a href="https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts#when_is_a_context_considered_secure" rel="nofollow noreferrer">When is a context considered secure?</a> section in the MDN docs for more info. https://stackoverflow.com/questions/75971880/why-does-docker-compose-up-get-stuck-starting-when-i-give-the-container-access-t?cid=134007153 Comment by Alicia Sykes on Why does docker-compose up get stuck starting when I give the container access to my GPU? Alicia Sykes https://stackoverflow.com/users/979052 2023-04-10T18:28:49Z 2023-04-10T18:28:49Z Sorry, should have said that I just used Nvidia as an example - you&#39;d need to put your actual GPU runtime info in there. https://stackoverflow.com/questions/75971880/why-does-docker-compose-up-get-stuck-starting-when-i-give-the-container-access-t?cid=133994795 Comment by Alicia Sykes on Why does docker-compose up get stuck starting when I give the container access to my GPU? Alicia Sykes https://stackoverflow.com/users/979052 2023-04-09T17:19:45Z 2023-04-09T17:19:45Z Have you tried specifying the <code>runtime</code> in your compose? (e.g. <code>runtime: nvidia</code> and also maybe the <code>NVIDIA_VISIBLE_DEVICES=all</code> env var). Can you share some more detailed logs too (use the <code>docker-compose logs</code> command) https://stackoverflow.com/questions/75971814/binary-array-present-in-response-is-being-converted-to-string-in-react?cid=133994724 Comment by Alicia Sykes on Binary array present in response is being converted to string in react Alicia Sykes https://stackoverflow.com/users/979052 2023-04-09T17:11:15Z 2023-04-09T17:11:15Z Axios doesn&#39;t convert byte arrays to strings. So it sounds like it could just be a missing content type header (e.g. <code>application&#47;octet-stream</code> for binary). https://stackoverflow.com/questions/75965562/redux-dispatch-is-looping-when-success-is-true-in-state?cid=133984493 Comment by Alicia Sykes on Redux Dispatch Is Looping When Success is true in state Alicia Sykes https://stackoverflow.com/users/979052 2023-04-08T13:55:33Z 2023-04-08T13:55:33Z Just splitting your success state into a separate states (e.g. <code>addNoteSuccess</code> and <code>getNotesSuccess</code>) for each action in your Redux slice, should fix this, by letting you listen specifically for one action in your <code>useEffect</code>. https://stackoverflow.com/questions/75965423/how-to-type-firestore-queries-in-firestore-for-nodejs?cid=133984189 Comment by Alicia Sykes on How to type Firestore queries in Firestore for NodeJS Alicia Sykes https://stackoverflow.com/users/979052 2023-04-08T13:18:51Z 2023-04-08T13:18:51Z Could you create a custom utility that handles the type conversion on retrieved Firestore query data? https://stackoverflow.com/questions/75965206/jquery-download-data-in-chunks-from-server-and-keep-appending-to-a-file-on-cli?cid=133984130 Comment by Alicia Sykes on Jquery - Download data in chunks from server and keep appending to a file on client Alicia Sykes https://stackoverflow.com/users/979052 2023-04-08T13:10:07Z 2023-04-08T13:10:07Z Why is this tagged with jQuery? https://stackoverflow.com/questions/75285948/javascript-css-determine-content-dimensions-before-rendering-to-see-if-it-will?cid=132857300 Comment by Alicia Sykes on JavaScript/CSS. Determine content dimensions before rendering, to see if it will overflow container dimensions Alicia Sykes https://stackoverflow.com/users/979052 2023-01-30T23:56:14Z 2023-01-30T23:56:14Z You don&#39;t need to create new elements, all the overflow capabilities should be able to be handled with proper CSS. https://stackoverflow.com/questions/75285948/javascript-css-determine-content-dimensions-before-rendering-to-see-if-it-will?cid=132848321 Comment by Alicia Sykes on JavaScript/CSS. Determine content dimensions before rendering, to see if it will overflow container dimensions Alicia Sykes https://stackoverflow.com/users/979052 2023-01-30T15:07:20Z 2023-01-30T15:07:20Z This should be possible to do with just pure CSS, no need for the JS. If you can share the rest of your code, that&#39;d help us write an answer. But it&#39;s probably going to be using flexbox, and flex wrap to make use of available space https://stackoverflow.com/questions/75286188/unexpected-output-from-array-method?cid=132848223 Comment by Alicia Sykes on Unexpected Output from Array() Method Alicia Sykes https://stackoverflow.com/users/979052 2023-01-30T15:03:11Z 2023-01-30T15:03:11Z The output is <code>abcabcabc</code> (so abc 3x times) - which is expected, because your passing in <code>3</code> https://stackoverflow.com/questions/57354001/how-to-focus-on-input-field-loaded-from-component-in-svelte/57355578?cid=132303963#57355578 Comment by Alicia Sykes on How to focus on input field loaded from component in Svelte? Alicia Sykes https://stackoverflow.com/users/979052 2023-01-01T00:37:49Z 2023-01-01T00:37:49Z @mikemaccana - ref just short for reference, but it&#39;s commonly used in this context so for the sake of an example should be fine. https://stackoverflow.com/questions/72030745/onkeydown-event-with-enter-key-in-svelte/72031473?cid=132303916#72031473 Comment by Alicia Sykes on on:keydown event with Enter Key in svelte Alicia Sykes https://stackoverflow.com/users/979052 2023-01-01T00:27:08Z 2023-01-01T00:27:08Z This should be the accepted answer - very clearly described, and after testing against your scenario seems to work perfectly. https://stackoverflow.com/questions/74817558/how-to-add-docker-volume-for-zipkin-server?cid=132042207 Comment by Alicia Sykes on How to add docker volume for zipkin server Alicia Sykes https://stackoverflow.com/users/979052 2022-12-15T23:22:05Z 2022-12-15T23:22:05Z Use <code>--volume</code> to mount your own file or directory to where the log files are