Skip to content

Instantly share code, notes, and snippets.

View oleksandr-danylchenko's full-sized avatar

Oleksandr Danylchenko oleksandr-danylchenko

  • Binary Studio
  • Ukraine, Kyiv
  • 02:53 (UTC +02:00)
View GitHub Profile
@aiphee
aiphee / StringToNode.tsx
Last active April 29, 2024 09:36
Fragment with dangerouslySetInnerHtml replacement -
import React from 'react';
interface IProps {
children: unknown;
}
/**
* Takes node content and makes JSX element out of it (kind of like dangerouslySetInnerHTML)
* Careful, always sanitize input!
* credit @yairEO https://github.com/facebook/react/issues/12014#issuecomment-1621382570
@Fanoflix
Fanoflix / ctrl-enter.ts
Last active October 14, 2024 08:10
Ctrl + Enter to submit Form (Typescript)
document.body.addEventListener("keydown", (e: KeyboardEvent) => {
if (!(e.key === "Enter" && (e.metaKey || e.ctrlKey))) return
if ('form' in e.target) {
const formElement = e.target.form as HTMLFormElement;
formElement?.submit(); // or formElement?.requestSubmit() depending on your usecase
}
})
@adrianhajdin
adrianhajdin / Poll.jsx
Created September 29, 2021 17:28
Agora
import React, { useState, useEffect, useContext } from "react";
import Modal from 'react-modal';
import { Line } from 'rc-progress';
import { Text } from 'react-native';
import chatContext, {controlMessageEnum} from './ChatContext';
import { PollContext } from './PollContext';
import styles from './pollStyles';
@atomiks
atomiks / LazyTippy.jsx
Last active October 7, 2024 08:58
Lazy Tippy
// Will only render the `content` or `render` elements if the tippy is mounted to the DOM.
// Replace <Tippy /> with <LazyTippy /> component and it should work the same.
const LazyTippy = forwardRef((props, ref) => {
const [mounted, setMounted] = useState(false);
const lazyPlugin = {
fn: () => ({
onMount: () => setMounted(true),
onHidden: () => setMounted(false),
@rickyhaswifi
rickyhaswifi / netlify.toml
Last active August 10, 2023 00:48
React Router Netlify - Fix for not found page
#https://stackoverflow.com/questions/58065603/netlify-renders-404-on-page-refresh-using-react-and-react-router
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
@arielweinberger
arielweinberger / strong-password-regex.md
Last active September 8, 2024 06:47
Strong password Regular Expression - NestJS Course
  • Passwords will contain at least 1 upper case letter
  • Passwords will contain at least 1 lower case letter
  • Passwords will contain at least 1 number or special character
  • There is no length validation (min, max) in this regex!

Regular expression for JavaScript:

/((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/
@xeoncross
xeoncross / logger.js
Last active April 21, 2024 00:26
Expressjs Server Monitoring with Winston + Morgan
const { createLogger, format, transports } = require("winston");
// https://github.com/winstonjs/winston#logging
// { error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 }
const level = process.env.LOG_LEVEL || "debug";
function formatParams(info) {
const { timestamp, level, message, ...args } = info;
const ts = timestamp.slice(0, 19).replace("T", " ");
@javilobo8
javilobo8 / download-file.js
Last active October 27, 2024 09:15
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@ntd251
ntd251 / json_snake_keys_to_camel_keys.js
Last active January 10, 2023 09:55
Convert JSON snake-case (underscore) keys to camel-case keys
/**
* @author ntd251
* @dependency underscore.js
* @example
*
* input = {
* arrayItems: [
* numericKey: 10,
* jsonKey: {
@iraSenthil
iraSenthil / gist:3222887
Created August 1, 2012 02:20
Restart ADB in single command
cmd /c “adb kill-server&&adb start-server”