Skip to content

Instantly share code, notes, and snippets.

View rahulrajaram's full-sized avatar

rahulrajaram rahulrajaram

View GitHub Profile
@rahulrajaram
rahulrajaram / .py
Last active October 24, 2017 22:10
Python print colored STDOUT
COLOR_MAP = {
'black': '30',
'red': '31',
'green': '32',
'yellow': '33',
'blue': '34',
'magenta': '35',
'cyan': '36',
'white': '37',
}
@rahulrajaram
rahulrajaram / .md
Last active September 30, 2018 22:01
Ruby: Where is the method defined?

Ruby: Different ways to define methods in

The Ruby Object Model

One of the central aspects of  the Ruby programming language is the Ruby object model, as per which everything (but for constructs such as methods, and keywords) in Ruby -- ​​classes, instances, lambdas, procs, strings, numbers, decimals, hashmaps -- is an object. This renders a kind of uniformity to Ruby that few other languages offer.

At the very same time, the object model can also become confusing. In particular, the following two questions can sometimes become difficult to answer, but being able to readily answer which can set you apart as a Ruby programmer.

  1. What is self in a given context?
  2. If I define a method here, where will it go? That is, which object is it going to be defined on?
@rahulrajaram
rahulrajaram / .cpp
Last active August 13, 2017 05:53
Tail recursive function to find arithmetic sum in C++/C
/*
TL;DR: Compile the program as follows:
------
g++ add.cpp -O2 && ./a.out
RIGOROUS DISCUSSION:
--------------------
Suppose you want to compute the sum of the series: