Skip to content

Instantly share code, notes, and snippets.

View sushiljainam's full-sized avatar
💻
Working from home

Sushil Jain sushiljainam

💻
Working from home
View GitHub Profile
It's beautiful in its simplicity, as Terence Parr notes:
For the "MVC" of a web app, I make a direct analogy with the Smalltalk notion of MVC. The model is any of the logic or the database or any of the data itself. The view is simply how you lay the data out, how it is displayed. If you want a subset of some data, for example, my opinion is that is a responsibility of the model. The model knows how to make a subset. You should not be asking your graphics designer to filter a list according to age or some other criteria.
The controller in a web app is a bit more complicated, because it has two parts. The first part is the web server (such as a servlet container) that maps incoming HTTP URL requests to a particular handler for that request. The second part is those handlers themselves, which are in fact often called "controllers." So the C in a web app MVC includes both the web server "overlord" that routes requests to handlers and the logic of those handlers themselves, which pull the data from the database a
@sushiljainam
sushiljainam / js_array_pushUnique.js
Created December 27, 2016 09:48
enhancing array capabilities
Array.prototype.pushUnique = function(elem) {
if(this.indexOf(elem) == -1){
this.push(elem);
}
};
@sushiljainam
sushiljainam / array_Filters.js
Last active December 27, 2016 11:06
object as filter to filter array of objects returning array of lesser objects
Array.prototype.pushUnique = function(elem) {
if(this.indexOf(elem) == -1){
this.push(elem);
}
}
//filters are in OR, any one true will add, array result will be returned
Array.prototype.filterAny = function (filter,callback) {
var result = [];
@sushiljainam
sushiljainam / arrayFilters.min.js
Last active December 27, 2016 11:08
object as filter to filter array of objects returning array of lesser objects: minified
Array.prototype.pushUnique=function(t){-1==this.indexOf(t)&&this.push(t)},Array.prototype.filterAny=function(t,n){var r=[];return this.forEach(function(n){for(var i in t)n[i]==t[i]&&r.pushUnique(n)}),"function"!=typeof n?r:void n(r)},Array.prototype.filterAll=function(t,n){var r=[];return this.forEach(function(n){var i=0;for(var o in t)n[o]==t[o]&&i++,i==Object.keys(t).length&&r.pushUnique(n)}),"function"!=typeof n?r:void n(r)};
@sushiljainam
sushiljainam / rules.js
Created January 19, 2017 12:02
array of rules
var autoSelect = {};
autoSelect.rules = [
{"playerChipsRange": [1000, 10000], "stakes":[25, 50], "buyIn":[0,2000]},
{"playerChipsRange": [10001, 25000], "stakes":[50, 100], "buyIn":[0,2000]},
{"playerChipsRange": [25001, 50000], "stakes":[100, 200], "buyIn":[0,2000]},
{"playerChipsRange": [50001, 100000], "stakes":[250, 500], "buyIn":[0,2000]},
{"playerChipsRange": [100001, 250000], "stakes":[1000, 2000], "buyIn":[0,2000]},
{"playerChipsRange": [250001, 500000], "stakes":[5000, 10000], "buyIn":[0,2000]},
{"playerChipsRange": [500001, 1000000], "stakes":[10000, 20000], "buyIn":[0,2000]},
@sushiljainam
sushiljainam / rankname.js
Last active February 13, 2017 13:50
find alphabetical rank of a name
/*
* @Author: Sushil Jain
* @Date: 2017-02-13 17:06:37
* @Last Modified by: csnodejs4
* @Last Modified time: 2017-02-13 19:19:49
*/
'use strict';
var input = "sushil";
@sushiljainam
sushiljainam / rankName.php
Created February 18, 2017 18:08
php code to find rank of a name
function findRankByString($input){
$input = strtolower($input);
if(strlen($input) <= 1){
return 1;
}
$chars = [];
for ($i = 0; $i < strlen($input); $i++) {
array_push($chars, $input[$i]);
};
@sushiljainam
sushiljainam / combo.js
Last active February 20, 2017 14:15
to print all combinations for states, given length
function comb(len, states, rules){
if(len>16){
// return "out of limit, put force if you know better";
}
var states = states || ["0","1"];
var pos = [];
var powers = [];
for (var i = 0; i < len; i++) {
pos.push(0);
@sushiljainam
sushiljainam / linkedList.js
Last active April 5, 2017 20:30
linked list using JS, simple
var node = function (value){
this.value = value;
this.next = null;
return this;
}
var list = function (){
this.head = null;
return this;
}
//regular expressions
v = /^a/.test('asdasaabb');
console.log("/^a/.test('asdasaabb')", v);
console.log("/.*/.test('/^a+b+$/')", /.*/.test('/^a+b+$/'));
console.log("/^\/.*\/$/.test('/^a+b+$/')", /^\/.*\/$/.test('/^a+b+$/'));
console.log("/^\/.\/$/.test('/^a+b+$/')", /^\/.\/$/.test('/^a+b+$/'));
console.log("/^a/.test('/^a+b+$/')", /^a/.test('/^a+b+$/'));
console.log("/^a/.test('/^a+b+$/')", /^a/.test('/^a+b+$/'));
//s = readline();