Skip to content

Instantly share code, notes, and snippets.

View loginov-rocks's full-sized avatar

Danila Loginov loginov-rocks

View GitHub Profile
@loginov-rocks
loginov-rocks / results.csv
Created March 2, 2025 04:59
Calibrate 4-DOF Robot Arm (MeArm) for Inverse Kinematics (Part 2) - results.csv
Servo Min Actuator Max Actuator Min Joint Max Joint
Base 128 33 -pi/4 (-45°) pi/4 (+45°)
Shoulder 135 35 pi/4 (+45°) 3*pi/4 (+135°)
Elbow 135 45 pi/4 (+45°) -pi/4 (-45°)
Claw 14 41 pi/2 (+90°) 0 (0°)
@loginov-rocks
loginov-rocks / defaults.csv
Last active March 2, 2025 04:34
Calibrate 4-DOF Robot Arm (MeArm) for Inverse Kinematics (Part 2) - defaults.csv
Servo Min Actuator Max Actuator Min Joint Max Joint
Base 145 49 -pi/4 (-45°) pi/4 (+45°)
Shoulder 118 22 pi/4 (+45°) 3*pi/4 (+135°)
Elbow 144 36 pi/4 (+45°) -pi/4 (-45°)
Claw 75 115 pi/2 (+90°) 0 (0°)
@loginov-rocks
loginov-rocks / generatePolicy.js
Created January 22, 2024 04:08
WebSocket API Gateway Cognito Authorizer
/**
* @see https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html
*/
const generatePolicy = (principalId, effect, resource, context) => ({
context,
policyDocument: {
Version: '2012-10-17',
Statement: [
{
Action: 'execute-api:Invoke',
@loginov-rocks
loginov-rocks / verifyToken.js
Created January 22, 2024 04:05
WebSocket API Gateway Cognito Authorizer
import jwkToPem from 'jwk-to-pem';
// Simple in-memory cache, optional. In this Lambda it will always have a single promise stored because Region and User
// Pool ID are taken from the environment variables and remain unchanged within the life cycle of the Lambda, but I
// still kept this flexible in case someone will copy the code. Subject for improvement.
const getPemEncodedPublicKeysPromisesCache = new Map();
const getPemEncodedPublicKeysImplementation = async (jwksUrl) => {
console.log('jwksUrl', jwksUrl);
@loginov-rocks
loginov-rocks / verifyToken.js
Last active January 22, 2024 04:00
WebSocket API Gateway Cognito Authorizer
import { decode, verify } from 'jsonwebtoken';
export const verifyToken = async (region, userPoolId, token) => {
var decodedJwt = decode(token, { complete: true });
if (!decodedJwt || !decodedJwt.header || !decodedJwt.header.kid) {
return null;
}
const pemEncodedPublicKeys = await getPemEncodedPublicKeys(region, userPoolId);
@loginov-rocks
loginov-rocks / sign.mjs
Last active January 22, 2024 03:59
WebSocket API Gateway IAM Signer
import { defaultProvider } from '@aws-sdk/credential-provider-node';
import { Hash } from '@aws-sdk/hash-node';
import { HttpRequest } from '@aws-sdk/protocol-http';
import { SignatureV4 } from '@aws-sdk/signature-v4';
import { URL } from 'url';
export const sign = async (region, url, query = {}, headers = {}) => {
const urlObject = new URL(url);
// Add query parameters passed as argument, if any.
@loginov-rocks
loginov-rocks / platformio.ini
Created January 9, 2022 17:55
DIY Connected Espresso Machine: Over-the-Air Updates (Part 6) - platformio.ini
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
monitor_filters = esp8266_exception_decoder
upload_protocol = espota
upload_port = connected-espresso-machine.local
lib_deps =
@loginov-rocks
loginov-rocks / main.cpp
Last active January 13, 2022 17:23
DIY Connected Espresso Machine: Over-the-Air Updates (Part 6) - main.cpp
#include "ArduinoOTA.h"
#include "EspressoMachine.h"
#include "WiFiManager.h"
#define SERIAL_BAUDRATE 9600
#define WIFI_HOSTNAME "Connected-Espresso-Machine"
#define WIFI_ACCESS_POINT_SSID "Connected-Espresso-Machine"
#define OTA_UPDATES_HOSTNAME "connected-espresso-machine"
@loginov-rocks
loginov-rocks / main.cpp
Last active January 13, 2022 17:18
DIY Connected Espresso Machine: Over-the-Air Updates (Part 6) - setupOtaUpdates
#include "ArduinoOTA.h"
// ...
#define OTA_UPDATES_HOSTNAME "connected-espresso-machine"
// ...
/**
* @see https://github.com/esp8266/Arduino/blob/master/libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino
@loginov-rocks
loginov-rocks / main.cpp
Last active January 13, 2022 17:18
DIY Connected Espresso Machine: Over-the-Air Updates (Part 6) - setupWiFi
#include "WiFiManager.h"
// ...
#define WIFI_HOSTNAME "Connected-Espresso-Machine"
#define WIFI_ACCESS_POINT_SSID "Connected-Espresso-Machine"
// ...
/**