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: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) => {
> docker run --rm -it -d --name localstack -p 4566:4566 -p 4510-4559:4510-4559 localstack/localstack
> docker ps
> docker exec -it <containerId> /bin/bash
> aws configure
AWS Access Key ID [None]: example-key
AWS Secret Access Key [None]: example-secret-key
Default region name [None]: us-east-1
Default output format [None]:
@ValchanOficial
ValchanOficial / gist:29a283aa78ff7b222d3dbab1fb873993
Created July 26, 2024 16:38
[WSL2][Docker][PowerShell][Win10/11] Command
wsl.exe -u root -e sh -c "service docker status || service docker start"
@ValchanOficial
ValchanOficial / convert-deploymentconfig-to-deployment.md
Created May 23, 2024 03:37 — forked from bmaupin/convert-deploymentconfig-to-deployment.md
Convert OpenShift DeploymentConfig to Kubernetes Deployment
  1. Change apiVersion from:

    - apiVersion: v1

    (or apiVersion: apps.openshift.io/v1)

    to:

@ValchanOficial
ValchanOficial / xmlParser.ts
Created May 22, 2024 06:22 — forked from Aravin/xmlParser.ts
Converting JSON toXML& XML to JSON in Node.js using xml2js package in TypeScript
import { parseString, Builder } from "xml2js";
// Convert string/XML to JSON
function toJson(xml: string) {
parseString(xml, { explicitArray: false }, function(error, result) {
console.log(result);
});
}
@ValchanOficial
ValchanOficial / update-git.sh
Created April 22, 2024 13:48 — forked from YuMS/update-git.sh
Update git to latest version on Ubuntu
#!/bin/bash
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git -y
@ValchanOficial
ValchanOficial / gist:99913fd8f5ae1f7e4c9c4156e282c887
Created April 14, 2024 00:17
[Javascript] Create alphanumeric code
export const alphanumeric = (len) => {
const str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return [...Array(len)].reduce(
(a) => a + str[~~(Math.random() * str.length)],
""
);
};
console.log(alphanumeric(6)); // HNF2RU
@ValchanOficial
ValchanOficial / gist:e34d3ff1bb5bf7b44577fbc681661dac
Last active March 18, 2024 15:11
[Javascript] replaceAt and regex matches between symbol
// https://stackoverflow.com/a/1431113/11842937
const replaceAt = function(str, index, replacement) {
return str.substring(0, index) + replacement + str.substring(index + replacement.length);
}
https://regexr.com/ - regex matches between symbol
regex = new RegExp(`^\\${symbol}(.*)\\${symbol}$`, 'gm')
g = global
m = multiline
function centuryFromYear(year) {
return Math.ceil(year / 100)
}