Skip to content

Instantly share code, notes, and snippets.

View parwatcodes's full-sized avatar

Parwat Kunwar parwatcodes

View GitHub Profile
@parwatcodes
parwatcodes / casperfile.js
Last active December 29, 2016 04:17
casper
var casper = require('casper').create();
var fs = require('fs');
casper.on('remote.message', function (msg) {
console.log('Casper Console Listener: ' + msg);
});
casper.start('http://www.google.com/', function () {
this.fill('form', { q: 'hello world' }, true); // this keyword is referring to casper object
});
app.post('/users', function(req, res) {
var user = new User({
username: req.body.username
});
user.save(function(err) {
if (err) {
if (err.name === 'MongoError' && err.code === 11000) {
// Duplicate username
return res.status(500).send({ succes: false, message: 'User already exist!' });
@parwatcodes
parwatcodes / graphql.js
Created April 11, 2017 08:39
passing fakedatabase from rootquery
const graphql = require('graphql');
const fakeDatabase = require('./fakeDatabase');
const newFake = require('./newFake');
const fakeDatabaseType = new graphql.GraphQLObjectType({
name: 'fakeDatabase',
fields: {
id: { type: graphql.GraphQLID },
name: { type: graphql.GraphQLString },
description: { type: graphql.GraphQLString },
const fakeDatabase = [
{
id: 1,
name: 'Abhay',
description: 'This is Abhay\'s Database'
},
{
id: 2,
name: 'Bankimchandra',
description: 'This is Bankimchandra\'s Database'
const express = require('express')
const bodyParser = require('body-parser')
var mysql = require('mysql')
var alasql = require('alasql');
var async = require('async');
const request = require('request')
const app = express()
var json;
//const botBuilder = require('claudia-bot-builder');
//const fbTemplate = botBuilder.fbTemplate;
@parwatcodes
parwatcodes / install-zsh.sh
Created May 12, 2017 09:14 — forked from mkalygin/install-zsh.sh
Install zsh on Elementary OS.
# Source: http://choyan.me/oh-my-zsh-elementaryos/
sudo apt-get update && sudo apt-get install -y curl vim git zsh
curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | bash
sudo chsh -s $(which zsh) $(whoami)
import { createStore, combineReducers } from 'redux';
export const ONLINE = `ONLINE`;
export const AWAY = `AWAY`;
export const BUSY = `BUSY`;
export const OFFLINE = `OFFLINE`;
export const UPDATE_STATUS = `UPDATE_STATUS`;
export const CREATE_NEW_MESSAGE = `CREATE_NEW_MESSAGE`;
@parwatcodes
parwatcodes / thisInReact.js
Last active August 23, 2017 06:01
Why we have to bind this in react, if not bind we have to use arrow function
class HelloWorld extends React.Component {
constructor(props) {
super(props);
this.state = { message: 'Hi' };
}
logMessage() {
console.log(this.state.message);
}
const currentMonth = 8;
const data = [{
employee: 70,
month: 0,
year: 2017,
id: 3,
createdAt: '2017-09-15T09:42:37.000Z',
updatedAt: '2017-09-15T09:42:37.000Z',
organization: 41,
@parwatcodes
parwatcodes / constructor.js
Created October 10, 2017 11:33
changing a constructor function definition using `functionaName.prototype.constructor`
function Rabbit() {
this.jumps = "yes";
};
var rabbit = new Rabbit();
console.log(rabbit.jumps);
// Rabbit.prototype.constructor is a pointer to the original constructor `function Rabbit(){..})` so that the users of the class can detect the constructor from an instance
console.log(Rabbit.prototype.constructor);
// outputs exactly the code of the function Rabbit()