Skip to content

Instantly share code, notes, and snippets.

View sridharrajs's full-sized avatar

Sridhar Raj Sampath Kumar sridharrajs

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<meta name="description" content="This is what the user will read, so keep it short. Set expectation in terms of what they can expect once they visit the page." />
@sridharrajs
sridharrajs / use-flatmap.js
Last active April 4, 2023 18:51
Use flatMap instead of filter + map
const ipl2023Auction = [
{ name: "Dhoni", broughtBy: 'CSK' },
{ name: "Santner", broughtBy: 'CSK' },
{ name: "Faf", broughtBy: 'RCB' },
{ name: "Kohli", broughtBy: 'RCB' },
{ name: "Rohit", broughtBy: 'MI' },
{ name: "Archer", broughtBy: 'MI' }
];
ipl2023Auction.filter(player => player.broughtBy === 'MI').map(player => player.name) // [ 'Rohit', 'Archer' ]
@sridharrajs
sridharrajs / basic-rss.xml
Last active December 19, 2022 08:56
basic-rss.xml
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<!-- channel details here -->
<title>Example Domain</title>
<link>http://example.org</link>
<description>A sample description.</description>
<pubDate>Tue, 13 Dec 2022 08:12:58 GMT</pubDate>
<image>
<url>http://example.co/avatar.png</url>
{
"text": {
"react": "react",
"javascript": "js",
"graphql": "graphql",
"node": "node"
},
"urls": {
"youtube.com": "video",
"kencdodds.com": "react"
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App'; // Root of our application
// parameter 1 => which react component to render
// parameter 2 => the mount location where the react wants to write to the acutal DOM
ReactDOM.render(<App />, document.getElementById('root'));
import React, { Component } from 'react';
class Cricketers extends Component {
//property initializer
state = {
players: [
{
name: 'dravid',
avg: 52.3,
},
import React from 'react';
const row = ({ name, age, mark }) => {
return (
<tr>
<td>{name}</td>
<td>{age}</td>
<td>{mark}</td>
</tr>
);
@sridharrajs
sridharrajs / setstatus-asynchronous.js
Created January 9, 2020 18:35
asynchronous setstate
this.setState(previousState => {
return {
age: previousState.age + 1
};
});
@sridharrajs
sridharrajs / return-values.js
Created June 13, 2019 04:21
predict the output
function fun(){
try{
console.log("try");
return true;
} catch (e){
console.log("catch");
return false;
} finally {
return 21212;
}