Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View ayushgp's full-sized avatar
😁

Ayush Gupta ayushgp

😁
View GitHub Profile
var relativeDate = function(date){
var month = ["January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"];
var now = new Date();
if(date === now){
return "Just now";
}
var yearDiff = date.getYear()-now.getYear();
var monDiff = date.getMonth()-now.getMonth();
var dateDiff = date.getDate()-now.getDate();
if(date.toDateString() === now.toDateString())
#include<iostream>
using namespace std;
template<class T> struct Node{
T data;
Node<T>* next;
Node(T t){
this->data = t;
}
};
/*
Roll No: 101403051
Name: Ayush Gupta
Group: COE3
Question: 1
*/
#include<bits/stdc++.h>
using namespace std;
@ayushgp
ayushgp / query.cc
Last active February 15, 2016 10:27
Xapian 'contains' method for OmegaScript
//Added this at line 886:
CMD_contains,
//Added the function description at line 1012
T(contains, 2, 2, N, 0), //return position of substring, if not found return empty string
//Implemented contains function at line
case CMD_contains: {
size_t pos = args[1].find(args[0]);
if(pos!=string::npos){
/**
* Using Rails-like standard naming convention for endpoints.
* GET /api/things -> index
* POST /api/things -> create
* GET /api/things/:id -> show
* PUT /api/things/:id -> update
* DELETE /api/things/:id -> destroy
*/
'use strict';
@ayushgp
ayushgp / index.js
Last active May 27, 2016 07:06
A cron job that invalidates links and creates new ones.
var express = require("express");
var app = express();
function randomString(length) {
var result = '';
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
for (var i = length; i > 0; --i)
result += chars[Math.floor(Math.random() * chars.length)];
return result;
function LogRequsts(req, res, next){
console.log("A request was received!");
next();
}
var app = require('express')();
function logger(req, res, next){
console.log("A %s request was received at %s", req.method, req.url);
next();
}
// Use the middleware function
app.use(logger);
function NewLogger(req, res, next){
console.log("A request was received at /new");
next();
}
app.use('/new', NewLogger);
// First middleware
app.use(function(req, res, next){
console.log("Started");
next();
});
// Route handler
app.get('/', function(req, res, next){
res.send("Sent to client");
next();