Skip to content

Instantly share code, notes, and snippets.

View krazylearner's full-sized avatar
🏠
Working from home

Ankur Bansal krazylearner

🏠
Working from home
View GitHub Profile
@krazylearner
krazylearner / gist:c91b300599144d59391e187956b0523f
Created January 14, 2018 16:06
Error handling in node.js
http://goldbergyoni.com/checklist-best-practices-of-node-js-error-handling/
best article

qdqdqdqdq

@krazylearner
krazylearner / alexa-sdk-https-server-how-to.js
Created August 10, 2017 06:50 — forked from oprog/alexa-sdk-https-server-how-to.js
alexa-sdk how to use it with an express https server
'use strict';
const express = require('express');
const https = require('https');
const fs = require('fs');
const bodyParser = require('body-parser');
const context = require('aws-lambda-mock-context');
// lambda.js contains the lambda function for Alexa as in https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs
var lambda = require('./lambda');
@krazylearner
krazylearner / directives.js
Created June 15, 2017 06:34 — forked from jakemmarsh/directives.js
AngularJS directive to create a functional "back" button
app.directive('backButton', function(){
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', goBack);
function goBack() {
history.back();
scope.$apply();
@krazylearner
krazylearner / av.js
Last active April 9, 2017 17:39
testing apache benchmark node.js
***************Without CLuster ***********************
=====================================================
ab -n 1000 -c 50 http://dev.lihaoma.com:4002/v2/offer/58cab6b177bf5930ae85dee4
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking dev.lihaoma.com (be patient)
Completed 100 requests
Completed 200 requests
@krazylearner
krazylearner / express-server-side-rendering.md
Created February 18, 2017 11:45 — forked from joepie91/express-server-side-rendering.md
Rendering pages server-side with Express (and Pug)

Terminology

  • View: Also called a "template", a file that contains markup (like HTML) and optionally additional instructions on how to generate snippets of HTML, such as text interpolation, loops, conditionals, includes, and so on.
  • View engine: Also called a "template library" or "templater", ie. a library that implements view functionality, and potentially also a custom language for specifying it (like Pug does).
  • HTML templater: A template library that's designed specifically for generating HTML. It understands document structure and thus can provide useful advanced tools like mixins, as well as more secure output escaping (since it can determine the right escaping approach from the context in which a value is used), but it also means that the templater is not useful for anything other than HTML.
  • String-based templater: A template library that implements templating logic, but that has no understanding of the content it is generating - it simply concatenates together strings, potenti

Show User

Returns json data about a single user.

  • URL

    /users/:id

  • Method:

@krazylearner
krazylearner / documentsize.js
Created September 15, 2016 14:23
Testing the codument size with embedded array of 30000 Object ids
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/my_databasetest');
var Schema = mongoose.Schema;
var ObjectId = Schema.Types.ObjectId;
var UserSchema = new Schema({
name: String,
friends: [{type: ObjectId}]
@krazylearner
krazylearner / random.js
Created June 27, 2016 11:40 — forked from kerimdzhanov/random.js
Javascript get random number in a specific range
/**
* Get a random floating point number between `min` and `max`.
*
* @param {number} min - min number
* @param {number} max - max number
* @return {float} a random floating point number
*/
function getRandom(min, max) {
return Math.random() * (max - min) + min;
}
@krazylearner
krazylearner / frontendDevlopmentBookmarks.md
Created May 28, 2016 12:31 — forked from dypsilon/frontendDevlopmentBookmarks.md
A badass list of frontend development resources I collected over time.