Skip to content

Instantly share code, notes, and snippets.

Avatar

Prasanna Natarajan npras

View GitHub Profile
@npras
npras / af2_original_submission.rb
Last active Mar 10, 2017
AF - Codility: Task2
View af2_original_submission.rb
def solution(a)
total = a.size
lindex = a.size-1
sorted = a.sort
min = total
combos = []
return 0 if a == sorted
(2..total).each do |pair_size|
@npras
npras / bindMethod.js
Last active Feb 22, 2017
Gist explaining method binding to outer scope
View bindMethod.js
let myLib = (function(){
this.libName = 'in lib';
let obj = {
libName: 'in obj',
toCaps() {
return this.libName.toUpperCase();
}
};
@npras
npras / watcher.js
Created Feb 20, 2017
VueJS - Implementing Computed Property - Part Two
View watcher.js
class Watcher {
constructor(vm, valueFn) {
this.vm = vm;
this.getter = valueFn;
this.value = this.get();
}
get() {
let value;
@npras
npras / vuejs-source.js
Created Feb 20, 2017
VueJS - Implementing Computed Property - Part One
View vuejs-source.js
const Watcher = require('./watcher');
const noop = function () {};
const sharedPropDef = {
enumerable: true,
configurable: true,
get: noop,
set: noop
};
@npras
npras / vue_experiment1.js
Created Jan 13, 2017
Reproduce Vue's data object proxy behaviour
View vue_experiment1.js
// https://vuejs.org/v2/guide/instance.html
//
//
//function Vue(opts){
//for(var key in opts.data){
//this[key] = opts.data[key]
//}
//}
function Vue(opts){
this._data = opts.data;
View xml_builder.rb
class XMLBuilder
def initialize
@d = {}
end
def to_xml
@d
end
@npras
npras / js_fn_def_and_calling.js
Created Mar 17, 2016
javascript function definition and calling syntax
View js_fn_def_and_calling.js
// this is function definition.
// you can make a function take zero or more arguments (also called as parameters)
// This Dog fn takes one argument: 'name'
function Dog(name){
return "hello, my name is: " + name;
}
// calling the Dog function
Dog('tommy'); // this will return "hello, my name is: tommy"