Skip to content

Instantly share code, notes, and snippets.

@PavanKu
PavanKu / readConsole.js
Created January 26, 2022 14:52
Read input from console in NodeJS
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let stdin_input = "";
process.stdin.on("data", function (input) {
stdin_input += input; // Reading input from STDIN
});
process.stdin.on("end", function () {
main(stdin_input); // Calling function with input
@PavanKu
PavanKu / PictureList.js
Created May 20, 2019 02:55
React native Ajax example
import React from 'react';
import { View, Text, Image, ActivityIndicator, StyleSheet, FlatList } from "react-native";
const initialState = { pictures: [] }
class PictureList extends React.Component {
constructor(props) {
super(props);
this.state = initialState;
}
async fetchPictures() {
@PavanKu
PavanKu / SimpleScrollView.js
Last active May 20, 2019 02:31
React native scroll view
import React from 'react';
import { View, Text, Image, ActivityIndicator, StyleSheet, ScrollView } from "react-native";
const initialState = { pictures: [
{id:0, download_url:"https://picsum.photos/id/0/5616/3744" },
{id:1, download_url: "https://picsum.photos/id/1002/4312/2868"},
{id:2, download_url: "https://picsum.photos/id/1006/3000/2000"},
{id:3, download_url: "https://picsum.photos/id/1015/6000/4000"}
] };
class PictureList extends React.Component {
@PavanKu
PavanKu / login.js
Created May 19, 2019 18:55
Login form in React native
import React from 'react';
import { View, StyleSheet, Text, TouchableOpacity, TextInput, Alert } from "react-native";
const initialState = { username: '', password: '' };
class LoginForm extends React.Component {
constructor(props) {
super(props);
this.state = initialState;
this.handleSubmitForm = this.handleSubmitForm.bind(this);
this.handleUsernameChange = this.handleUsernameChange.bind(this);
this.handlePasswordChange = this.handlePasswordChange.bind(this);
@PavanKu
PavanKu / SimpleButton.js
Created May 19, 2019 18:50
React Native Button Component
import React from 'react';
import { View, Alert, Button, StyleSheet } from "react-native";
const SimpleButton = (props) => {
return ( <Button style={styles.button} onPress={() => Alert.alert("You pressed button")} title="Click Me"/> );
};
const styles = StyleSheet.create({
button: {
padding: 5,
@PavanKu
PavanKu / SimpleInputText.js
Created May 19, 2019 18:32
Simple Input Text in React Native
import React from 'react';
import { View, Text, TextInput, StyleSheet } from "react-native";
class SimpleTextInput extends React.Component {
constructor(props) {
super(props);
this.state = { text: '', isSubmitted: false };
}
handleChangeText = (text) => {
this.setState({ text, isSubmitted: false });
@PavanKu
PavanKu / functional_vs_classBasedComponent.js
Created May 19, 2019 18:05
Functional vs Class based component
/* Class based component */
import React, { Component } from 'react';
import { Text } from 'react-native';
export default class Greeting extends Component {
render() {
return (
<Text>Hello {this.props.name} !</Text>
);
}
@PavanKu
PavanKu / Counter.js
Created May 7, 2019 13:39
Counter In React native
import React from 'react';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
class Counter extends React.Component {
state = { count: 0 };
increment = () => this.setState({count: this.state.count + 1});
decrement = () => this.setState({count: this.state.count - 1});
render() {
return (
<View style={styles.container}>
@PavanKu
PavanKu / App.js
Created May 7, 2019 13:37
Simple React Native Example
import React from 'react';
import { StyleSheet, Text, View, Image } from 'react-native';
import Counter from './components/Counter';
import Greeting from "./components/Greeting2";
import SimpleTextInput from './components/SimpleTextInput';
import SimpleButton from './components/SimpleButton';
import LoginForm from './components/LoginForm';
import PictureList from './components/PictureList';
export default class App extends React.Component {
@PavanKu
PavanKu / ShakaPlayer.js
Created May 3, 2019 10:34
Add custom player in react-player
import React, { Component } from 'react'
import shaka from 'shaka-player';
import createSinglePlayer from 'react-player/lib/singlePlayer'
const IOS = typeof navigator !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream
const AUDIO_EXTENSIONS = /\.(m4a|mp4a|mpga|mp2|mp2a|mp3|m2a|m3a|wav|weba|aac|oga|spx)($|\?)/i
const DASH_EXTENSIONS = /\.(mpd)($|\?)/i
function canPlay (url) {