Skip to content

Instantly share code, notes, and snippets.

View parwatcodes's full-sized avatar

Parwat Kunwar parwatcodes

View GitHub Profile
@parwatcodes
parwatcodes / hoc.js
Created April 2, 2019 18:34
a example for higher order component
// presentational component
const Greeting = ({ name }) => {
if (!name) {
return <div>Connecting...</div>;
}
return <div>Hi {name}!</div>;
};
// hoc
@parwatcodes
parwatcodes / validate_phone.js
Last active December 16, 2019 11:22
phone number validation
function validate(phone) {
var regex = /^\+(?:[0-9]?){6,14}[0-9]$/;
if (regex.test(phone)) {
// Valid international phone number
return 'valid'
} else {
return 'invalid'
// Invalid international phone number
}
<InlineForm>
<Field
id="first_name"
name="first_name"
type="text"
label="First Name *"
className="input-field left"
component={GTextField}
margin="normal"
onChange={props.handleChange}
import React, { Fragment } from 'react';
import { CopyToClipboard } from 'react-copy-to-clipboard';
import { TransparentButton } from 'Components/Generics/Buttons';
import { Wrapper, CopiedText, TextArea, IdeaAreaContainer, TranscriptAreaContainer } from '../styled';
type Props = {
idea: String,
ideaDetail: Object,
copied: Boolean,
handleCopyText: Function,
@parwatcodes
parwatcodes / select.js
Created February 13, 2019 05:00
select with a callback
function Select ({ values, callback, disabled = false, readonly = false, selected }) {
return (
<select
disabled={disabled}
readOnly={readonly}
onChange={({ target : { value } }) => callback(value)}
>
{values.map(([value, text]) => <option selected={selected === value}value={value}>{text}</option>)}
</select>
);
let user = [{
id: 12,
name: "Richard Johnson"
}, {
id: 21,
name: "David Johnson"
}, {
id: 33,
name: "western Austin"
}, {
@parwatcodes
parwatcodes / transcript_result.rb
Last active February 6, 2019 10:45
data sent from the `start_transcription_job` method and the final output json response from the output bucket
{:transcription_job=>{:transcription_job_name=>"REb6ff296e08085081849b70adea1c9e32.mp3",
:transcription_job_status=>"IN_PROGRESS",
:language_code=>"en-US", :media_sample_rate_hertz=>nil,
:media_format=>"mp3", :media=>{:media_file_uri=>"https://xxssde.s3.us-west-2.amazonaws.com/REb6ff296e080w8508sad1849b70adea1c9e32.mp3"},
:transcript=>nil, :creation_time=>2019-02-06 12:03:20 +0545, :completion_time=>nil, :failure_reason=>nil, :settings=>nil}}
# RESPONSE GIVEN BY AMAZON TRANSCRIBE
# GET TRANSCRIPTION DETAILS BY JOB ID
# RESPONSE
class Ticker extends Component {
constructor(props) {
super(props);
this.state = {ticker: 0}
this.interval = null
}
tick = () => {
this.reset()
this.interval = setInterval(() => {
def number
if params[:redirect]
puts 'From redirect pressed 4'
end
user_id = params[:user_id]
digit = params[:Digits]
response = @@twilio.voice_response
@parwatcodes
parwatcodes / reducer.js
Created December 30, 2018 13:34
alternative reducer patterns
const initialState = [];
export default function (state = initialState, action) {
const { type } = action;
const reducer = {
[ACTION_CONSTANT]: {
...state,
// new state value
}
};