Skip to content

Instantly share code, notes, and snippets.

View Harshakvarma's full-sized avatar
🎯
Focusing

Harshavardhan Kalidindi Harshakvarma

🎯
Focusing
View GitHub Profile
@Harshakvarma
Harshakvarma / App.js
Created January 15, 2018 06:42
Axios react API subreddit demo
import React from 'react';
import ReactDOM from 'react-dom';
import axios from 'axios';
class FetchDemo extends React.Component {
constructor(props) {
super(props);
this.state = {
posts: []
@Harshakvarma
Harshakvarma / Aysnc Await nodejs syncronous Even Odd numbers
Created January 23, 2018 22:46
Using aysnc await features in Nodejs (ES6 Javascript) created Even Odd filter of random numbers
randomArray = Array.from({length: 10}, () => Math.floor(Math.random() * 40));
console.log("Random: ",randomArray);
var even = [];var odd = [];
processArray(randomArray)
async function processArray(data) {
for(const item of data){
// console.log(item)
await asyncCall(item)
@Harshakvarma
Harshakvarma / model|User.js
Last active February 4, 2018 20:53
Sequelize example
module.exports = function(sequelize, Sequelize) {
var User = sequelize.define('user', {
id: { autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER},
firstname: { type: Sequelize.STRING,notEmpty: true},
lastname: { type: Sequelize.STRING,notEmpty: true},
username: {type:Sequelize.TEXT},
about : {type:Sequelize.TEXT},
email: { type:Sequelize.STRING, validate: {isEmail:true} },
password : {type: Sequelize.STRING,allowNull: false },
@Harshakvarma
Harshakvarma / splitJson.js
Created February 19, 2018 03:31
Splitting a large json file into small files
if(process.argv.length < 3){
console.log('target file path is required.')
process.exit(1)
}
var target = process.argv[2]
console.log('file: ' + target)
var fs = require('fs')
fs.readFile(target, function (err, data) {
@Harshakvarma
Harshakvarma / delay.js
Created February 19, 2018 06:39 — forked from daliborgogic/delay.js
Node.js Async/Await delay
'use strict'
const timeout = ms => new Promise(res => setTimeout(res, ms))
function convinceMe (convince) {
let unixTime = Math.round(+new Date() / 1000)
console.log(`Delay ${convince} at ${unixTime}`)
}
async function delay () {
@Harshakvarma
Harshakvarma / myscript
Created February 25, 2018 00:38
Custom script for executing shell commands faster
PS3='Select your choice: '
options=("Quit" "pm2 restart App_Backend" "Option 2" "Option 3")
select opt in "${options[@]}"
do
case $opt in
"Quit")
break
;;
"pm2 restart App_Backend")
pm2 restart App_Backend/server/server.js --name=GIG_backend
@Harshakvarma
Harshakvarma / server.js
Created March 8, 2018 20:54 — forked from taion/server.js
GraphQL subscription server with Socket.IO, backed by Redis Pub/Sub
const redisClient = redis.createClient(REDIS_URL);
const listeners = Object.create(null);
function addListener(channel, listener) {
if (!listeners[channel]) {
listeners[channel] = [];
redisClient.subscribe(channel);
}
listeners[channel].push(listener);
router.post('/addUserSocialProfile', function (req, res) {
var profileData = req.body.social;
var data = {};var output = [];var changed = 0;var now = new Date();
processObject(profileData)
async function processObject(profileData) {
for(var key in profileData){
// console.log(item)
await asyncCall(key, profileData[key])
@Harshakvarma
Harshakvarma / geo.js
Created April 13, 2018 19:56 — forked from mkhatib/geo.js
A Javascript utility function to generate number of random Geolocations around a center location and in a defined radius.
/**
* Generates number of random geolocation points given a center and a radius.
* @param {Object} center A JS object with lat and lng attributes.
* @param {number} radius Radius in meters.
* @param {number} count Number of points to generate.
* @return {array} Array of Objects with lat and lng attributes.
*/
function generateRandomPoints(center, radius, count) {
var points = [];
for (var i=0; i<count; i++) {
@Harshakvarma
Harshakvarma / test.js
Created April 16, 2018 19:26
Async/await simple example
const items = [1, 2, 3, 4, 5, 6];
// do something that takes time with the item
function f1(item) {
console.log('[f1] received', item);
return new Promise(function(resolve, reject) {
setTimeout(resolve, 1000);
});
}