Skip to content

Instantly share code, notes, and snippets.

View oleksandr-danylchenko's full-sized avatar

Oleksandr Danylchenko oleksandr-danylchenko

  • Binary Studio
  • Ukraine, Kyiv
  • 16:27 (UTC +03: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 May 13, 2024 07:51
Ctrl + Enter to submit Form (Typescript)
document.body.addEventListener("keydown", (e: KeyboardEvent) => {
if (!(e.key === "Enter" && (e.metaKey || e.ctrlKey))) return
const form = (e.target as HTMLFormElement).form
if (form) form.submit() // or form.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 February 9, 2023 02:10
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 June 12, 2024 09:45
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 July 1, 2024 23:21
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”