Skip to content

Instantly share code, notes, and snippets.

View nvjkmr's full-sized avatar

Vijay Kumar nvjkmr

View GitHub Profile
@nvjkmr
nvjkmr / ocw-download.sh
Last active April 17, 2018 06:30
Bash script to download all the files from a given URI
#!/bin/bash
# defaults
LINK=http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-spring-2008/lecture-notes/
NUMBER=5
FILE=lec$.pdf
throwErr()
@nvjkmr
nvjkmr / bput_result.py
Created June 6, 2016 05:24
Check BPUT results from old website
#!/usr/bin/python3
import sys
import requests
reg_id = sys.argv[1]
print("Fetching results of "+ reg_id + " from http://results.bput.ac.in/")
for i in range(1,610):
url = 'http://results.bput.ac.in/'+ str(i) +'_RES/'+ reg_id +'.html'
@nvjkmr
nvjkmr / divideAndConquer.h
Created October 27, 2016 10:56
Divide and conquer search for sorted integer array
/* Divide and conquer search for sorted integer array.
* Pre: Takes array pointer
* Integer to find
* Last index of array
* Initial of array
* Return: Index of the array
*/
int divideAndConquer(int* arr, int toFind, int lastIndex, int initialIndex) {
int mid = initialIndex + ((lastIndex - initialIndex) / 2);
@nvjkmr
nvjkmr / getting-started-with-node-js.md
Created January 22, 2017 13:43 — forked from joepie91/getting-started.md
Getting started with Node.js

"How do I get started with Node?" is a commonly heard question in #Node.js. This gist is an attempt to compile some of the answers to that question. It's a perpetual work-in-progress.

And if this list didn't quite answer your questions, I'm available for tutoring and code review! A donation is also welcome :)

Setting expectations

Before you get started learning about JavaScript and Node.js, there's one very important article you need to read: Teach Yourself Programming in Ten Years.

Understand that it's going to take time to learn Node.js, just like it would take time to learn any other specialized topic - and that you're not going to learn effectively just by reading things, or following tutorials or courses. _Get out there and build things!

@nvjkmr
nvjkmr / JavascriptBasics.js
Created January 23, 2017 15:46
Basics of JavaScript
// Statements can be terminated by ;
doStuff();
// ... but they don't have to be, as semicolons are automatically inserted
// wherever there's a newline, except in certain cases.
doStuff()
// Because those cases can cause unexpected results, we'll keep on using
// semicolons in this guide.
@nvjkmr
nvjkmr / .js
Last active January 29, 2017 14:57 — forked from joepie91/.js
Callbacks in Javascript
function getUser(userID) {
/* This is a hypothetical function. Normally we'd talk to a database or so, but this is to illustrate the concept... */
var someUser = {name: "Joe Bloggs", age: 42};
cb(someUser); /* Here we call the callback from the second function argument, with our fake user */
}
var cb = function(user){
/* Now `user` contains {name: "Joe Bloggs", age: 42} */
}
@nvjkmr
nvjkmr / binding-controller.js
Last active February 4, 2017 15:03
Controller functions being referenced in the routes.
var knex = require('../database/db');
var Promise = require('bluebird');
var getRandom = function(numChars) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for(var i = 0; i < numChars; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
@nvjkmr
nvjkmr / promises-reading-list.md
Created February 2, 2017 20:29 — forked from joepie91/promises-reading-list.md
Promises (Bluebird) reading list

Promises reading list

This is a list of examples and articles, in roughly the order you should follow them, to show and explain how promises work and why you should use them. I'll probably add more things to this list over time.

This list primarily focuses on Bluebird, but the basic functionality should also work in ES6 Promises, and some examples are included on how to replicate Bluebird functionality with ES6 promises. You should still use Bluebird where possible, though - they are faster, less error-prone, and have more utilities.

I'm available for tutoring and code review :)

You may reuse all gists for any purpose under the WTFPL / CC0 (whichever you prefer).

// Initialization
var log = "";
function doWork() {
log += "W";
return Promise.resolve();
}
function doError() {
log += "E";
@nvjkmr
nvjkmr / filter-assoc-array.php
Last active March 21, 2017 14:42
Filter associative array with an array of keys
<?php
$data = array(
'key1' => 'val1',
'key2' => 'val2',
'key3' => 'val3',
'key4' => 'val4',
'key5' => 'val5',
'key6' => 'val6',
'key7' => 'val7',