Skip to content

Instantly share code, notes, and snippets.

View GerasimGerasimov's full-sized avatar
🏠
Working from home

GERASIM GERASIMOV GerasimGerasimov

🏠
Working from home
  • Novosibirsk
View GitHub Profile
@GerasimGerasimov
GerasimGerasimov / asciibytes2string.ts
Last active July 14, 2023 16:39
JavaScript (Typecript) convert array of ASCII bytes to String
const numericArray: Array<number> = [49, 50, 51, 52, 53, 54, 55, 56, 32, 79, 76, 69, 68, 46, 67, 77, 52, 32, 118, 51, 46, 48, 46, 49, 32, 50, 50, 46, 48, 52, 46, 50, 48, 50, 51, 32, 119, 119, 119, 46, 105, 110, 116, 109, 97, 115, 104, 46, 114, 117];
const s: string = String.fromCharCode(...numericArray);
console.log('MY DATA-ASCII:', s);//"12345678 OLED.CM4 v3.0.1 22.04.2023 www.intmash.ru"
@GerasimGerasimov
GerasimGerasimov / ObjectFactory.cpp
Last active July 14, 2023 16:29
C++ and TypeScript. Factoty of objects by std::map or dictionary. Getting rid of from "switch case" or "if ..." madness
#include <map>
#include <functional>
typedef pSignal(*createSignal)(TSignalPropsPointers props);
pSignal SignalFactoty::getSignal(TSignalPropsPointers props) {
/*TODO тут надо парсить переданнюу строку и генерить объекты vars, word, bit, float и т.п.*/
int size = 100;
std::string pType = IniParser::getElement('/', &props.pType, size);
/*GIST создание объеата из словаря*/
How to add fontawesome and bootstrap to React project? I'm not doing its often... all time as first time . Reminder:
1) installation
npm install --save bootstrap
npm install --save @fortawesome/fontawesome-free
2) importing to project
to header of root project file index.tsx:
import React from 'react';
import ReactDOM from 'react-dom';
to add imports
import 'bootstrap/dist/css/bootstrap.min.css';
@GerasimGerasimov
GerasimGerasimov / gist:85224b394a6c8f893eefff5438a3f229
Last active March 12, 2021 10:41
валидация переменной типа boolean с присвоением false по умолчанию
//валидация boolean с присвоением false а по умолчанию true
//без этой конструкции всегда присваивался true
let respond: boolean;
result: boolean = (typeof respond !== 'undefined') ? respond : false ;
@GerasimGerasimov
GerasimGerasimov / promise-all-example.ts
Last active July 14, 2023 16:30
вариант чтения слотов с помощью await Promise.all(requests); даёт небольшой выигрыш в скорости, но так как чтение слотов проходит конкурентно, то в JSON объекты располагаются в в порядке "кто раньше загрузился"
async function getSlotsData(request: Object, SlotsDataRequest :TSlotsDataRequest, host:THost): Promise<any>{
const FieldBus: TFieldBus = SlotsDataRequest.AddressableDevice.FieldBus;
const PositionName = SlotsDataRequest.PositionName;
const result: Object = {[PositionName]:{}};
const loadOneSlot = async (SlotDataRequest:TSlotDataRequest) => {
const slot:TSlot = host.SlotsMap.get(SlotDataRequest.SlotName);
const Tag: TParameters = SlotsDataRequest.AddressableDevice.Tags[SlotDataRequest.SectionName.toLowerCase()]
try {
await host.getSlotData(slot)//обновляю данные хоста
FieldBus.checkHeaderOfAnswer(slot);