Skip to content

Instantly share code, notes, and snippets.

View vibhanshuc's full-sized avatar

Vibhanshu Chaturvedi vibhanshuc

View GitHub Profile

Keybase proof

I hereby claim:

  • I am vibhanshuc on github.
  • I am vibhanshu (https://keybase.io/vibhanshu) on keybase.
  • I have a public key ASCbWudPsa9ONq7cwt_KhxghIKeumsghMVclP6XQkNSfiwo

To claim this, I am signing this object:

@vibhanshuc
vibhanshuc / default-args-1.js
Last active February 9, 2017 20:08
Default Arguments in ES2015
function calculateBill(total, tax = 0.15, tip = 0.05){
console.log(total + (total * tax) + (total * tip));
}
// usage
calculateBill(500); // 600
calculateBill(500, 0.2); // 625
@vibhanshuc
vibhanshuc / array_iteration_thoughts.md
Created January 13, 2017 04:31 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

from scrapy import cmdline
from swishpick.pipelines import *
from datetime import datetime
import subprocess
import time
_week_day_relations = {
'Monday': 1,
'Tuesday': 2,
@vibhanshuc
vibhanshuc / SingletonDemo.js
Created August 25, 2016 18:46
Contains an example of a singleton
// Create a closure
var SecretStore = (function() {
var data, secret, newSecret;
// Emulation of a private variables and functions
data = 'secret';
secret = function() {
return data;
}
newSecret = function(newValue) {
@vibhanshuc
vibhanshuc / CSS SNIPPETS.md
Last active July 5, 2016 15:22
Contains snippets of CSS utilities

Center a div in middle of screen

<div class="container">
    <div class="box blueBox"></div>
</div>

.container {

(function () {
'use strict';
function Person(name, age, gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
Person.prototype.getName = function () {
@vibhanshuc
vibhanshuc / Inheritance.js
Last active February 13, 2016 11:23
Defines a superclass named Person and subclass named Studenusing prototype chain
(function () {
'use strict';
function Person(name, age, gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
Person.prototype.getName = function () {

Javascript

  1. What is a closure in JavaScript?
  2. What is strict mode in JavaScript? How do you enable it? How does it affect your code ? Any examples.
  3. Which design patterns in Javascript you are aware of ? Any prefernce in known patterns. If yes , reason?
  4. How do you convert a varibale to boolean type?
  5. Are you aware of any bugs related to floating points arithmetic in javascript. What precatuions do you follow to ensure nothing goes wrong with floating point arithmetic in JS.
  6. How do you iterate through properties of an object?
  7. How do you check if a given variable is array.
@vibhanshuc
vibhanshuc / readme.markdown
Created November 27, 2015 10:49 — forked from jonah-williams/readme.markdown
Readme template

Project

Description: What does this project do and who does it serve?

Project Setup

How do I, as a developer, start working on the project?

  1. What dependencies does it have (where are they expressed) and how do I install them?
  2. How can I see the project working before I change anything?