Skip to content

Instantly share code, notes, and snippets.

View ErickWendel's full-sized avatar

Erick Wendel ErickWendel

View GitHub Profile
const heroes = `NickName: Chapolin, Power: Hammer
Nick: Batman, Power: Money
`
const exp = /(NickName|Nick):\s(?<nickname>\w+),\sPower:\s(?<power>\w.*)/gm
const matchAll = [...heroes.matchAll(exp)].map(({
groups: {
nickname,
power
}
@ErickWendel
ErickWendel / concat-streams.mjs
Last active August 15, 2024 10:17
Example of how to consume multiple Web APIs in parallel via Node.js Streams
// npm i axios stream-concat
import { pipeline } from 'stream/promises'
import StreamConcat from 'stream-concat'
import axios from 'axios'
const API_01 = 'http://localhost:3000'
const API_02 = 'http://localhost:4000'
const streams = (await Promise.all([
axios({
class Context {
static printSomething() { console.log('context working',) }
static initializeTerminalWithClosure() { return () => this.printSomething() }
static initializeTerminal() { this.printSomething() }
}
setTimeout(Context.initializeTerminal)
// erro pois "this" é do contexto de setTimeout
setTimeout(Context.initializeTerminal.bind(Context))
// com bind você fala o que é para ter no "this" da função
@ErickWendel
ErickWendel / gde-post-contribution.js
Last active March 11, 2025 00:47
Example of how to automate contribution submissions on GDE API
const axios = require('axios')
class GDEAPI {
constructor({ token }) {
this.token = token
}
async submitContributions(body) {
const headers = {
"accept": "application/json, text/plain, */*",
"accept-language": "en-US,en;q=0.9",
@ErickWendel
ErickWendel / youtube-video-analytics.js
Created September 16, 2021 20:00
Example of how to get video views from youtube
const YOUTUBE_KEY = "YOUR YOUTUBE KEY"
import axios = from 'axios';
function getVideoId(link) {
const videoId = link.match(/v=(?<videoId>.*)/)?.groups?.videoId
return videoId
}
async function getVideoViews(link) {
const videoId = getVideoId(link)
@ErickWendel
ErickWendel / linkedin-post-analytics-example.mjs
Last active September 25, 2024 07:45
Example of how to get post Analytics such as Views from a Linkedin post
// paste this file on a empty directory
// npm i axios
// You should go to your browser on Cookie session and get JSESSIONID and li_at from Linkedin Section
const JSESSIONID = 'YOUR JSESSIONID'
const liAT = 'YOUR li_at'
import axios from 'axios'
const headers = {
diskutil list
NAME=SD_NAME
sudo diskutil eraseDisk FAT32 $NAME MBRFormat /dev/disk2
@ErickWendel
ErickWendel / ps3-controller-esp32.cpp
Last active August 7, 2021 20:04
Example of moving wheel (2 motor DC) sending PWM commands through an ESP32 and a PS3 Controller/Joystick
#include <Arduino.h>
#include <Ps3Controller.h>
// https://wouterdeschuyter.be/blog/configure-a-ps3-controller-to-automatically-connect-to-a-raspberry-pi
// http://www.squids.com.br/arduino/index.php/projetos-arduino/projetos-squids/intermediario/305-i08-como-controlar-motores-dc-com-o-driver-ponte-h-l9110-e-arduino
// Motor A
const uint8_t RIGHT_WHEEL_A1_A_DIR = 32; //M-A1-A
const uint8_t RIGHT_WHEEL_A1_B_PWM = 33; //M-A1-B // PWM
@ErickWendel
ErickWendel / accent-regex.js
Last active March 30, 2021 13:47
Example of keeping only words and words which have accents on a JS String
'N,.ã_o)d-á'.replace(/([^A-zÀ-ÿ]|_)/g, '')
// "Nãodá"
// ( => starts a group
// [^A-zÀ-ÿ]=> find only not words including with accents
// |_ => or find _ literally
// ) => ends a group
// g => global - keep searching 'till the end
@ErickWendel
ErickWendel / websocket-client.js
Last active March 3, 2025 17:04
Pure WebSocket Node.js Server using Native HTTP Module
// make a request
const options = {
port: 1337,
host: 'localhost',
headers: {
'Connection': 'Upgrade',
'Upgrade': 'websocket'
}
};
const protocol = 'http'