This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://stackoverflow.com/a/77087453/11842937 | |
sudo rm /var/run/docker.pid | |
sudo apt purge docker.io containerd | |
sudo apt autoremove | |
sudo apt install docker.io containerd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://learn.microsoft.com/en-us/windows/wsl/systemd#how-to-enable-systemd | |
https://ollama.com/download/linux | |
https://docs.openwebui.com/ | |
https://github.com/open-webui/open-webui | |
1 - sudo nano /etc/wsl.conf | |
2 - Add values | |
[boot] | |
systemd=true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- INFO: array starts with 0 and position starts with 1 | |
-- INFO: Get position from pathArray1 element that type is group | |
WITH position AS(SELECT position | |
FROM my_table, jsonb_array_elements(data->'path1'->'pathArray1') with ordinality arr(elem, position) | |
WHERE id = 2 AND elem->>'type' = 'group') | |
-- INFO: Insert new value into pathArray1[position].path2.pathArray2 | |
UPDATE my_table | |
SET data = jsonb_insert( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select * from my_table where created_at::date >= '2025-01-07'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT - jsonb_insert | |
update my_table | |
set my_column = jsonb_insert(my_column, '{field1, field2, newkey}', '"hello insert"') | |
where id = 1; | |
// SELECT result: {"field1": {"field2": {"newvalue": "hello insert"}}} | |
SET - jsonb_set | |
update my_table | |
set my_column = jsonb_set(my_column, '{field1, field2}', '{"existingKey":"bye hello value"}') | |
where id = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://developer.mozilla.org/en-US/docs/Web/API/MediaStream_Recording_API/Using_the_MediaStream_Recording_API | |
https://mdn.github.io/dom-examples/media/web-dictaphone/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/65440696 | |
function random(min, max) { | |
const range = max - min + 1 | |
const bytes_needed = Math.ceil(Math.log2(range) / 8) | |
const cutoff = Math.floor((256 ** bytes_needed) / range) * range | |
const bytes = new Uint8Array(bytes_needed) | |
let value | |
do { | |
crypto.getRandomValues(bytes) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Info: \u00a0 é o que é o espaço sem quebra | |
const number = 123456.789; | |
console.log(new Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(number).replace(/\u00a0/g, ' ')); | |
console.log(Number(number).toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }).replace(/\u00a0/g, ' ')) | |
// Output: "R$ 123.456,79" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Solution: | |
sinon.stub(presigner.prototype, 'presign').returns(Promise.resolve(new HttpRequest(parseUrl(Key)))); | |
----------------------- | |
Tests: | |
import assert from 'assert'; | |
import sinon from 'sinon'; | |
import { GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Question from: https://thedailybyte.dev/ | |
// You are given a two-dimensional matrix that represents the grades of a class of students. Each grade is represented as an array where the first index is the student’s ID and the second student is a grade (0 - 100) that the student has received. Given these grades, calculate the average of each student’s top five scores and return the result. | |
// Note: Each student is guaranteed to have at least 5 scores. Student IDs start from zero and increase by one. Your return variable should be sorted according to student ID. | |
My solution: | |
const grades = [[1, 100], [1, 50], [2, 100], [2, 93], [1, 39], [2, 87], [1, 89], [1, 87], [1, 90], [2, 100], [2, 76]] | |
const averageGrade = (grades) => { |
NewerOlder