Skip to content

Instantly share code, notes, and snippets.

View kartikag01's full-sized avatar
🎯
Focusing

KARTIK AGARWAL kartikag01

🎯
Focusing
  • Banglore, India
View GitHub Profile
alias gs='git status'
alias gst='git status -sb'
alias ga='git add .'
alias gau='git add -u' # Removes deleted files
alias gp='git pull'
alias gpu='git push'
alias gc='git commit -v'
alias gca='git commit -v -a' # Does both add and commit in same command, add -m 'blah' for comment
alias gco='git checkout'
alias gl='git log --oneline'
@kartikag01
kartikag01 / elasticInit.js
Created December 13, 2017 16:57
nodejs elastic connection
import elasticsearch from "elasticsearch";
let elasticClient;
export const getElasticInstance = () => {
if (elasticClient)
return elasticClient;
elasticClient = new elasticsearch.Client({
host: 'localhost:9200'
});
return elasticClient;
import mongoosastic from "mongoosastic";
import {getElasticInstance} from "../elastic-search";
//... your schema defination
YourSchame.plugin(mongoosastic, {
esClient: getElasticInstance()
});
@kartikag01
kartikag01 / sample_lookup.js
Last active December 17, 2017 20:43
Mongo Query for lookup
db.Users.aggregate(
[
{
$lookup: {
"from" : "UsersSubscriptions",
"localField" : "_id",
"foreignField" : "user_id",
"as" : "subscriptions"
}
},
@kartikag01
kartikag01 / output.bson
Created December 17, 2017 20:45
Mongo Output for lookup query
{
"_id" : ObjectId("5a36ce46f7a13634daf1214c"),
"name" : "Jayden",
"created_at" : ISODate("2017-12-14T12:49:01.746+0000"),
"subscriptions" : [
{
"_id" : ObjectId("5a36ce84f7a13634daf1214e"),
"user_id" : ObjectId("5a36ce46f7a13634daf1214c"),
"topic" : "nodejs"
},
const buttonStyle = {
fontSize: "1em",
margin: "1em",
padding: "0.25em 1em",
border: "2px solid palevioletred",
borderRadius: 3,
color: "white",
background: "palevioletred"
};
@kartikag01
kartikag01 / Before.jsx
Created August 30, 2018 05:47
react method before change in lifecycle
componentWillReceiveProps(nextProps) {
if (nextProps.pageNo !== this.state.pageNo) {
this.setState({ pageNo: nextProps.pageNo });
fetchNextPageData(nextProps.pageNo);
}
}
@kartikag01
kartikag01 / After.jsx
Created August 30, 2018 05:51
react method after change in lifecycle
static getDerivedStateFromProps(nextProps, prevState) {
if (prevState.pageNo !== nextProps.pageNo) {
return { pageNo: nextProps.pageNo };
}
}
componentDidUpdate(prevProps) {
if (prevProps.pageNo !== this.props.pageNo) {
fetchNextPageData(this.props.pageNo);
}
@kartikag01
kartikag01 / BeforeComponentWillMount.jsx
Created August 30, 2018 07:42
Before ComponentWillMount method
componentWillMount() {
this.setState({ loading: true });
this.props.fetchData(); // action dispatch
}
@kartikag01
kartikag01 / AfterComponentWillMount.jsx
Created August 30, 2018 07:46
After ComponentWillMount lifecycle change
constructor(props) {
super(props);
this.state = { loading: true };
}
componentDidMount() {
this.props.fetchData(); // action dispatch
}