Skip to content

Instantly share code, notes, and snippets.

View ValchanOficial's full-sized avatar
:octocat:
Happy Octocat

Valéria Padilha de Vargas ValchanOficial

:octocat:
Happy Octocat
View GitHub Profile
@ValchanOficial
ValchanOficial / gist:9730fb2bfbd93a5ae838f909235999ac
Created February 9, 2025 14:07
[Docker] Failed to start Docker Application Container Engine
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
@ValchanOficial
ValchanOficial / gist:3210ab2e0cf9f892b1a5d234218de708
Last active February 9, 2025 19:47
WSL2 + ollama + deepseek + open-webui
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
@ValchanOficial
ValchanOficial / gist:8840067e273e5eb92793b35a6e546c7d
Created January 9, 2025 23:20
[Postgres][jsonb_insert][jsonb_array_elements][with ordinality arr] objects + arrays
-- 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(
@ValchanOficial
ValchanOficial / gist:77b63835705042f78bfc2f1521d015fe
Created January 8, 2025 21:22
[Postgres] select data where date is greater than day YYYY-MM-DD
select * from my_table where created_at::date >= '2025-01-07';
@ValchanOficial
ValchanOficial / gist:4484d9aa7795d5044bcb5f997def6ae1
Last active January 9, 2025 12:23
[Postgres][jsonb_set][jsonb_insert] nested field
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;
@ValchanOficial
ValchanOficial / gist:7daef999edbad3edfae360ee921fbe9f
Created November 21, 2024 12:45
Using the MediaStream Recording API
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/
@ValchanOficial
ValchanOficial / gist:471919bbf1fa841ec7b5d301485335a2
Created October 11, 2024 17:52
[Javascript] Generate a random number within a range using crypto.getRandomValues
// 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)
@ValchanOficial
ValchanOficial / gist:6dc1cd4203101d38b3c93f865313c92e
Created September 24, 2024 13:27
[Javascript][NumberFormat][toLocaleString][currency]
// 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"
@ValchanOficial
ValchanOficial / gist:f190f72f951809c2927a546411489130
Last active September 9, 2024 12:51
[AWS SDK V3][S3 getSignedUrl][ERROR][Test][Sinon] TypeError: Descriptor for property getSignedUrl is non-configurable and non-writable
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";
@ValchanOficial
ValchanOficial / gist:3ebbf01b3de40ec326d3994c5286446b
Created August 20, 2024 22:33
[The Daily Byte][Student Averages]
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) => {