Skip to content

Instantly share code, notes, and snippets.

View sumanmukherjee03's full-sized avatar

Suman Mukherjee sumanmukherjee03

View GitHub Profile
@sumanmukherjee03
sumanmukherjee03 / gist:5117225
Created March 8, 2013 15:30
Exercise or cars
function logCar(obj) {
console.log("I'm a " + obj.color + " " + obj.make);
}
var Car = function(make, color){
this.make = make;
this.color = color;
};
Car.prototype = (function(){
@sumanmukherjee03
sumanmukherjee03 / gist:5111322
Created March 7, 2013 20:06
Closure example
// Exercise 2 - Closures
// Wrap the following code in a closure and export only the "countdown" function.
// Code
var countdown = function() {
var index;
function log(){
@sumanmukherjee03
sumanmukherjee03 / gist:5111041
Created March 7, 2013 19:33
times prototype for Number
Number.prototype.times = function(str) {
var result = "", i = this;
while(i-- > 0) {result += str;}
return result;
};
@sumanmukherjee03
sumanmukherjee03 / class_var_ex.rb
Created October 19, 2012 00:17
Messing with class variables in ruby
# Execute this file as follows and compare the results in ruby 1.8.*:
#
# ruby class_var_ex.rb
# ruby class_var_ex.rb "include module"
# ruby class_var_ex.rb "include module" "include global"
# ruby "include global"
@@test = 9 if ARGV.last == "include global"
module X
@sumanmukherjee03
sumanmukherjee03 / mess_with_bindings.rb
Created September 20, 2012 12:08
Messing with bindings in ruby
# Coding hazard.
class CoOrdinate
attr_reader :x, :y
def initialize(x, y)
@x = x
@y = y
end
end
@sumanmukherjee03
sumanmukherjee03 / random_string.rb
Created July 2, 2011 17:50
Generate random strings in ruby 1.9
[0..9, ?a..?z, ?A..?Z].map(&:to_a).flatten.sample(10).join #size has been hard coded as 10 here