Skip to content

Instantly share code, notes, and snippets.

View rmdort's full-sized avatar

Vinay M rmdort

View GitHub Profile
@rmdort
rmdort / shiftDown.ts
Last active August 11, 2020 04:48
Simple downshift hook
import React, {
useState,
useCallback,
useEffect,
useRef,
useMemo
} from "react";
export enum KeyCodes {
Right = 39,
@rmdort
rmdort / keycodes.ts
Created July 7, 2020 15:21 — forked from kyranjamie/keycodes.ts
TypeScript Browser Key Codes Enum
enum keyCodes {
BACKSPACE: 8,
TAB: 9,
ENTER: 13,
SHIFT: 16,
CTRL: 17,
ALT: 18,
PAUSE: 19,
CAPS_LOCK: 20,
ESCAPE: 27,
@rmdort
rmdort / move.js
Created December 16, 2019 12:46
Array move
export function move<T>(
source: Array<T>,
destination: Array<T>,
droppableSource: number,
droppableDestination: number
) {
const sourceClone = Array.from(source);
const destClone = Array.from(destination);
const [removed] = sourceClone.splice(droppableSource, 1);
destClone.splice(droppableDestination, 0, removed);
@rmdort
rmdort / numberformat.js
Created October 21, 2018 14:19
number_format(number, decimals, decPoint, thousandsSep) in JavaScript, known from PHP. It formats a number to a string with grouped thousands, with custom seperator and custom decimal point Demo: https://jsbin.com/yuremoyalu/edit?js,console
/**
* number_format(number, decimals, decPoint, thousandsSep) in JavaScript, known from PHP.
* It formats a number to a string with grouped thousands, with custom seperator and custom decimal point
* @param {number} number - number to format
* @param {number} [decimals=0] - (optional) count of decimals to show
* @param {string} [decPoint=.] - (optional) decimal point
* @param {string} [thousandsSep=,] - (optional) thousands seperator
* @author Felix Leupold <felix@xiel.de>
*/
function number_format(number, decimals, decPoint, thousandsSep) {
headerProps={{
title: config.chatBotTitle,
inline: config.chatBotInline
}}
avatarProps={{
avatarBot: config.botAvatar,
avatarUser: config.userAvatar,
}}
bubbleProps={{
label: config.chatBotBubbleLabel
@rmdort
rmdort / react-modal-portal.js
Created April 17, 2018 14:20
Simple react modal using portals
import React from 'react'
import PropTypes from 'prop-types'
import ReactDOM from 'react-dom'
import cx from 'classnames'
const TAB_KEY = 9
const ESC_KEY = 27
const FOCUSABLE_ELEMENTS = ['INPUT', 'BUTTON', 'SELECT', 'TEXTAREA', 'A']
class ModalPortal extends React.Component {
{
"docs": [
{
"id": 1,
"content": "A reusable launch system (RLS, or reusable launch vehicle, RLV) is a launch system which is capable of launching a payload into space more than once. This contrasts with expendable launch systems, where each launch vehicle is launched once and then discarded. No completely reusable orbital launch system has ever been created. Two partially reusable launch systems were developed, the Space Shuttle and Falcon 9. The Space Shuttle was partially reusable: the orbiter (which included the Space Shuttle main engines and the Orbital Maneuvering System engines), and the two solid rocket boosters were reused after several months of refitting work for each launch. The external tank was discarded after each flight."
}
],
"query": "how long did it take to work"
}
@rmdort
rmdort / spacy_srl.py
Created January 27, 2018 03:09 — forked from chssch/spacy_srl.py
Use AllenNLP Semantic Role Labeling (http://allennlp.org/) with SpaCy 2.0 (http://spacy.io) components and extensions
# This small script shows how to use AllenNLP Semantic Role Labeling (http://allennlp.org/) with SpaCy 2.0 (http://spacy.io) components and extensions
# Script installs allennlp default model
# Important: Install allennlp form source and replace the spacy requirement with spacy-nightly in the requirements.txt
# Developed for SpaCy 2.0.0a18
from allennlp.commands import DEFAULT_MODELS
from allennlp.common.file_utils import cached_path
from allennlp.service.predictors import SemanticRoleLabelerPredictor
from allennlp.models.archival import load_archive
@rmdort
rmdort / threading_example.py
Created January 8, 2018 09:14 — forked from sebdah/threading_example.py
Running a background thread in Python
import threading
import time
class ThreadingExample(object):
""" Threading example class
The run() method will be started and it will run in the background
until the application exits.
"""
@rmdort
rmdort / gist:6db0ed6eff78b2daa7852f9278f8a17f
Created December 5, 2017 02:56
React fade In component
import React from 'react'
import ReactDOM from 'react-dom'
module.exports = (WrappedComponent) => {
class FadeInComponent extends React.Component {
componentDidMount () {
// Get the components DOM node
var elem = ReactDOM.findDOMNode(this)
// Set the opacity of the element to 0
elem.style.opacity = 0