Skip to content

Instantly share code, notes, and snippets.

View vasanthk's full-sized avatar

Vasa vasanthk

View GitHub Profile
@vasanthk
vasanthk / cb.js
Last active December 3, 2015 08:02
For understanding callback hell better... and inversion of control.
var cbFn = function() {
console.log('Done')
}
// Run Async API call
completeAsyncCheckout(data, cbFn);
cbFn = function() {
// Guessing it prints 'Finished' since it has reference.
console.log('Finished');
// Control the flow of asynchronous calls with ES6 generator functions
// http://chrisbuttery.com/articles/synchronous-asynchronous-javascript-with-es6-generators/
/**
* get - XHR Request
*/
let get = function (url) {
return function (callback) {
let xhr = new XMLHttpRequest();

Do not underestimate credentials leaks.

Gist copied from here for my own reference

While one might think that leaking credentials is pretty much a noob mistake, and if you are feeling yourself being safe because you are an experienced developer, that’s a wrong impression leading to underestimation of the problem.

I performed a rather simple credentials search using only two methods: wget/untar/grep on npm packages and GitHub Search. The queries were pretty simple, it did not take much time, and that’s a quite obvious thing to do. Do you remember yourself laughing at «begin rsa private key» search results over GitHub and people who publish that?

@vasanthk
vasanthk / RootedTreeTraversal.js
Created December 16, 2015 04:29 — forked from dineshrajpurohit/RootedTreeTraversal.js
Preorder, Postorder,Inorder and Levelorder traversal of rooted trees using Javascript
/**
*
* Dinesh
*
* RootedTreeTraversal
* - Preorder Traversal
* - Postorder Traversal
* - Inorder Traversal
* - Levelorder Traversal
*
@vasanthk
vasanthk / frontend-challenges.js
Created December 16, 2015 08:13
Frontend coding challenges
/*
* A child is running up a staircase with n steps, and can hop either 1 step, 2 steps,
* or 3 steps at a time. Implement a method to count how many possible ways the
* child can run up the stairs.
*/
var countSteps = (function () {
var memo = [0,1];
var fn = function (numStairs) {
@vasanthk
vasanthk / gist:06680b52a0c6aae5d121
Created December 16, 2015 08:13 — forked from mcsheffrey/gist:6977999
Given an input array and another array that describes a new index for each element, mutate the input array so that each element ends up in their new index. Discuss the runtime of the algorithm and how you can be sure there won't be any infinite loops. Run time of this solution is THETA(n) as indexOf is a constant-time operation since an array in…
var input = [1,2,3,4,5],
specArr = [0,2,1,4,3];
function mutate(input, specArr) {
var visited = [0,2]
for(var i=0; i<specArr.length; i++) {
var tmp;
//keep track of array items we've already looped through (wouldn't want to mutate twice :D)
@vasanthk
vasanthk / require-js-discussion.md
Created December 23, 2015 19:22 — forked from desandro/require-js-discussion.md
Can you help me understand the benefit of require.js?

I'm having trouble understanding the benefit of require.js. Can you help me out? I imagine other developers have a similar interest.

From Require.js - Why AMD:

The AMD format comes from wanting a module format that was better than today's "write a bunch of script tags with implicit dependencies that you have to manually order"

I don't quite understand why this methodology is so bad. The difficult part is that you have to manually order dependencies. But the benefit is that you don't have an additional layer of abstraction.


@vasanthk
vasanthk / books.md
Created January 6, 2016 20:16 — forked from bevacqua/books.md
Books I plan on buying this week

Web Performance

  • High Performance Web Sites: Essential Knowledge for Front-End Engineers
  • High Performance JavaScript (Build Faster Web Application Interfaces)
  • Even Faster Web Sites: Performance Best Practices for Web Developers
  • Designing for Performance: Weighing Aesthetics and Speed

Web Design

  • Adaptive Web Design: Crafting Rich Experiences with Progressive Enhancement (2nd Edition) (Voices That Matter)
@vasanthk
vasanthk / bitcolor.js
Created January 27, 2016 07:36 — forked from lrvick/bitcolor.js
Javascript functions for doing fast binary/hex/RGB color conversions using bitwise operations.
// convert 0..255 R,G,B values to binary string
RGBToBin = function(r,g,b){
var bin = r << 16 | g << 8 | b;
return (function(h){
return new Array(25-h.length).join("0")+h
})(bin.toString(2))
}
// convert 0..255 R,G,B values to a hexidecimal color string
RGBToHex = function(r,g,b){
@vasanthk
vasanthk / pagination.md
Created February 2, 2016 07:23 — forked from mislav/pagination.md
"Pagination 101" by Faruk Ateş

Pagination 101

Article by Faruk Ateş, [originally on KuraFire.net][original] which is currently down

One of the most commonly overlooked and under-refined elements of a website is its pagination controls. In many cases, these are treated as an afterthought. I rarely come across a website that has decent pagination, and it always makes me wonder why so few manage to get it right. After all, I'd say that pagination is pretty easy to get right. Alas, that doesn't seem the case, so after encouragement from Chris Messina on Flickr I decided to write my Pagination 101, hopefully it'll give you some clues as to what makes good pagination.

Before going into analyzing good and bad pagination, I want to explain just what I consider to be pagination: Pagination is any kind of control system that lets the user browse through pages of search results, archives, or any other kind of continued content. Search results are the o