Skip to content

Instantly share code, notes, and snippets.

View kevjose's full-sized avatar
👨‍💻
zinging

kevin kevjose

👨‍💻
zinging
View GitHub Profile
var param1 = 'value1';
function method(){
console.log(this.param1);
}
var obj = {
param1: 'value2',
method: function(){
console.log(this.param1);
}
@kevjose
kevjose / example1.js
Created January 14, 2017 10:44
this keyword into
var obj ={
param1: 'value1',
param2: 'value2',
method: function(){
console.log(this.param1, this.param2);
console.log(obj.param1, obj.param2);
}
}
@kevjose
kevjose / express-route-structure.js
Last active December 2, 2016 04:38
basic routing that can be used for routing in express js
/*
* Let server be running at http://localhost:3000
*/
// server.js
var index = require('./routes/index');
var users = require('./routes/users');
app.use('/', index);
app.use('/users', users);//this will prefix all user routes with users. Namespace effect.
@kevjose
kevjose / active-record-migration-expert.md
Created November 21, 2016 07:32 — forked from pyk/active-record-migration-expert.md
become active record migration expert (Rails 4.0.2)

become active record migration expert (Rails 4.0.2)

workflow:

create model

$ rails g model NameOfModel
    invoke  active_record
    create    db/migrate/YYYYMMDDHHMMSS_create_name_of_models.rb
/**
* Regex to find occurences in the lines in any order from different pools (OR and AND)
**/
var pattern = /(?=(?=.*\beducation\b)|(?=.*\bhealth\b))(?=(?=.*\bvideo\b)|(?=.*\baudio\b))/
pattern.test('this education media support both audio video streams') // true
/**
*To add education and educational add .* with education in regex
* */
// to clone one collection to other
db.demo1.find().forEach( function(x){db.demo2.insert(x)} );
// to remove dupliactes based on a key
db.demo1.find({}, {field:1}).sort({_id:1}).forEach(function(doc){
db.demo1.remove({_id:{$gt:doc._id}, field:doc.field});
})
//to find documents added today
var d = new Date()
var startups = [{'score':1},{'score':2},{'score':2},{'score':3},{'score':4}];
startups.sort(function(a, b){
return (b.score - a.score);
});
for(var i =0, rank= 1, j=1; i <startups.length; i++){
startups[i].rank = rank;
if(startups[i+1] && startups[i].score != startups[i+1].score){
rank = rank+j;
j++;
}
var reURLInformation = new RegExp([
'^(https?:)//', // protocol
'(([^:/?#]*)(?::([0-9]+))?)', // host (hostname and port)
'(/[^?#]*)', // pathname
'(\\?[^#]*|)', // search
'(#.*|)$' // hash
].join(''));
var href ="http://www.example.com";
if(href[href.length -1]!='/')
href = href.concat('/');
@kevjose
kevjose / percentile.js
Created May 12, 2016 17:28 — forked from IceCreamYou/percentile.js
Utility functions to calculate percentiles and percent ranks in a JavaScript array.
// Returns the value at a given percentile in a sorted numeric array.
// "Linear interpolation between closest ranks" method
function percentile(arr, p) {
if (arr.length === 0) return 0;
if (typeof p !== 'number') throw new TypeError('p must be a number');
if (p <= 0) return arr[0];
if (p >= 1) return arr[arr.length - 1];
var index = arr.length * p,
lower = Math.floor(index),
var matchString = "/ol?link=http://www.facebook.com/flipkart-practo/kevin-kasrt";
var res = matchString.match(/facebook\.com\/(.+)\/+/);
console.log(res[1]);