Skip to content

Instantly share code, notes, and snippets.

View khusamov's full-sized avatar
:octocat:
Working...

Khusamov Sukhrob khusamov

:octocat:
Working...
  • Khusamov Soft Company
View GitHub Profile
@khusamov
khusamov / YF-S201.ino
Created March 11, 2021 06:24
Датчик потока воды Sea YF-S201
// http://digitrode.ru/computing-devices/mcu_cpu/1806-arduino-i-datchik-rashoda-vody.html
const int watermeterPin = 2;
volatile int pulse_frequency;
unsigned int literperhour;
unsigned long currentTime, loopTime;
byte sensorInterrupt = 0;
void setup()
@khusamov
khusamov / Sketch1.ino
Last active April 5, 2021 15:21
GSM-модуль SIM800L: самый полный мануал (на примерах с Arduino Uno) https://bit.ly/2PEIB3H
#include <SoftwareSerial.h>
SoftwareSerial SIM800(8, 9); // 8 - RX Arduino (TX SIM800L), 9 - TX Arduino (RX SIM800L)
void setup() {
Serial.begin(9600); // Скорость обмена данными с компьютером
Serial.println("Start!");
SIM800.begin(9600); // Скорость обмена данными с модемом
SIM800.println("AT");
}
void loop() {
@khusamov
khusamov / Sketch_LCD_MQ135.ino
Created March 7, 2021 19:22
Датчик углекислого газа MQ-135 (Troyka-модуль)
// библиотека для работы с дисплеем
#include <TroykaTextLCD.h>
// библиотека для работы с датчиками MQ (Troyka-модуль)
#include <TroykaMQ.h>
// имя для пина, к которому подключен датчик
#define PIN_MQ135 A0
// имя для пина, к которому подключен нагреватель датчика
#define PIN_MQ135_HEATER 11
@khusamov
khusamov / declare-module-types-yandex-maps.d.ts
Last active March 2, 2020 14:17
Добавление метода once() в интерфейс IEventManager из пакета @types/yandex-maps
declare module '@types/yandex-maps' {
import {IEvent} from '@types/yandex-maps';
declare namespace ymaps {
interface IEventManager {
once(types: string[][] | string[] | string, callback: (event: object | IEvent) => void, context?: object, priority?: number): this;
}
}
export = ymaps;
export as namespace ymaps;
}
@khusamov
khusamov / ApplicationProviders.tsx
Last active March 5, 2020 10:59
Решение проблемы типа 'Providers Hell'
import React, {FunctionComponent, ReactElement, Fragment, cloneElement} from 'react';
/**
* Решение проблемы типа 'Providers Hell'.
* @link https://gist.github.com/khusamov/58da3cebde3913aacf3e0b4fdfd48b70
*/
const ApplicationProviders: FunctionComponent<{providers: ReactElement[]}> = (
({children, providers}) => {
return (
[...providers, <Fragment>{children}</Fragment>]
@khusamov
khusamov / getBuildDate.ts
Last active April 29, 2020 17:14
Как добавить дату и время сборки в приложение на CRA2?
import preval from 'preval.macro';
const buildDate = new Date(Number(preval`module.exports = new Date().getTime();`));
/**
* Дата сборки.
* @link https://stackoverflow.com/questions/53028778/how-to-show-build-datetime-on-my-react-web-app-using-create-react-app
* @link https://gist.github.com/khusamov/2a9ce98bd1e5eff247502bdadaa4443a
*/
export default function getBuildDate(): Date {
@khusamov
khusamov / NoPrint.tsx
Last active February 12, 2020 11:51
Способ пометки 'Не для печати' блоков Grid из material-ui.com
import React, {FunctionComponent} from 'react';
import makeStyles from '@material-ui/core/styles/makeStyles';
import cn from 'classnames';
const useNoPrintStyles = (
makeStyles({
root: {
'@media print': {
display: 'none'
}
@khusamov
khusamov / usePrevious.ts
Created January 25, 2020 19:47
Хук возвращающий предыдущее состояние
import {useEffect, useRef} from "react";
/**
* Хук возвращающий предыдущее состояние
* @param value
*/
export const usePrevious = (value: any) => {
const ref = useRef(null);
useEffect(() => {
@khusamov
khusamov / example.js
Last active January 20, 2020 11:17
Условный рендеринг для функциональных компонент
function Mailbox(props) {
const unreadMessages = props.unreadMessages;
return (
<div>
<h1>Здравствуйте!</h1>
{renderIf(unreadMessages.length > 0, (
<h2>
У вас {unreadMessages.length} непрочитанных сообщений.
</h2>
)}
@khusamov
khusamov / Floating.style.tsx
Last active January 18, 2020 14:26
Плавающий элемент (React)
import React, {forwardRef} from 'react';
import {styled} from '@material-ui/styles';
import {TopProperty, LeftProperty} from 'csstype';
type TLength = string | 0;
type TDivProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
interface IFloatingDivProps {
x: number;
y: number;