February 14, 2011
Happy Valentines Day
I woke up on time around 0630. I went to college but missed the 8am class, Swarnlata madam‘s class again.
I was marked absent for not bringing the file by this pathetic woman, Neeru ma’am, in the DCS (Digital Circuits and Systems) lab. The period after break, CS communication systems class, was mass-bunked and class attended DCS, Neeru madam’s period.
I sat in library till 1800 and I had this nice bus ride to get back home.
I deleted my song ‘Flashback’ from my school-profile on Facebook before accepting Jagdish (JD sir, my high school class teacher) sir’s friend request. I had written that song to just speak out my unsaid thoughts and feelings about my school life-and-Sonal to my school friends and Sonal. That song posted in May 2010 after declaration of JEE result just got deleted. I very critically acclaimed by many who were tagged in that note and who read that note. It was my first public release. I removed “married to my ego” thing from “about me” column, but didn’t change my “married” relationship status. And my birthday date is 18th Dec again.
Babaji handed me R500 note in the morning for studying. Now, my money-packet is pregnant again, it breached R4700 mark after 1 year and 3 months.
God Bless ‘Me’
Ashish
P: Polymorphism
I: Inheritance
E: Encapsulation
A: Abstraction
Apple PIE
How and where OOP concepts are used?
Because using classes well requires some up-front planning, they tend to be of more interest to people who work in strategic mode (doing long-term product development) than to people who work in tactical mode (where time is in very short supply).
The concept of “self”
class C2: pass # Make superclass objects
class C3: pass
class C1(C2, C3): # Make and link class C1
def setname(self, who): # Assign name: C1.setname
self.name = who # Self is either I1 or I2
I1 = C1() # Make two instances
I2 = C1()
I1.setname('bob') # Sets I1.name to 'bob'
I2.setname('sue') # Sets I2.name to 'sue’
print(I1.name) # Prints 'bob'
There’s nothing syntactically unique about def in this context. Operationally, though, when a def appears inside a class like this, it is usually known as a method, and it automatically receives a special first argument—called self by convention—that provides a handle back to the instance to be processed. Any values you pass to the method yourself go to arguments after self (here, to who).
If you’ve ever used C++ or Java, you’ll recognize that Python’s self is the same as the “this” pointer, but self is always explicit in both headers and bodies of Python methods to make attribute accesses more obvious: a name has fewer possible meanings.
Concept of Inheritance of Variables and Methods
class Employee: # General superclass
def __init__(self, who = "NA", sal = 0): # Set name when constructed
self.name = who
self.salary = sal
def getDetails(self):
rtn = (self.name, self.salary)
print("rtn: ", rtn)
return rtn
class Engineer(Employee): # Specialized subclass
pass
print("Defaults:")
e = Engineer()
e.getDetails()
print()
print("Custom:")
e = Engineer(who = 'Ashish', sal = 100)
e.getDetails() $ python inheritance.py
Defaults:
rtn: ('NA', 0)
Custom:
rtn: ('Ashish', 100)
Error Alert
class Employee: # General superclass
def __init__(self, who, sal): # Set name when constructed
self.name = who
self.salary = sal
class Engineer(Employee): # Specialized subclass
pass
e = Engineer()
$ python inheritance.py
Traceback (most recent call last):
File "inheritance.py", line 14, in <module>
e = Engineer()
TypeError: __init__() missing 2 required positional arguments: 'who' and 'sal'
Polymorphism
class Employee:
def __init__(self, who = "NA", sal = 0):
self.name = who
self.salary = sal
def getDetails(self):
rtn = (self.name, self.salary)
print("rtn: ", rtn)
return rtn
class Engineer(Employee):
def reviseSalary(self):
self.salary =+ 100
def reviseSalary(self, inc = 200):
self.salary =+ inc
e = Engineer(who = 'Ashish', sal = 100)
e.getDetails()
e.reviseSalary()
e.getDetails()
e.reviseSalary(inc = 500)
e.getDetails()$ python polymorphism.py
rtn: ('Ashish', 100)
rtn: ('Ashish', 200)
rtn: ('Ashish', 500)
Abstraction
When we call "print()" for an object it prints some object details like these:
<__main__.Employee object at 0x000001F549F7A1D0>
However, when we define the Python's in-built __str__() for an object, we are essentially telling what should happen when print() is called for the object and end-user would not have to know how to get user-friendly details of the object. This is abstraction (abstraction of print()'s output in __str__() redefining it).
class Employee:
def __init__(self, who = "NA", sal = 0):
self.name = who
self.salary = sal
def getDetails(self):
rtn = (self.name, self.salary)
print("rtn: ", rtn)
return rtn
class Engineer(Employee):
def reviseSalary(self):
self.salary =+ 100
def reviseSalary(self, inc = 200):
self.salary =+ inc
def __str__(self): # Higher priority than __repr__ when using with print()
return '[From __str__: %s, %s]' % (self.name, self.salary)
#def __repr__(self):
# return '[From __repr__: %s, %s]' % (self.name, self.salary)
e = Engineer(who = 'Ashish', sal = 100)
e.getDetails()
print("e:", e)
print("e.__repr__():", e.__repr__())
f = Employee()
print("f = Employee():", f) $ python abstraction.py
rtn: ('Ashish', 100)
e: [From __str__: Ashish, 100]
e.__repr__(): <__main__.Engineer object at 0x000001F549C2F8D0>
f = Employee(): <__main__.Employee object at 0x000001F549F7A1D0>
Script: s1.py
import numpy as np
import doctest
def factorial(n):
"""
Test for the factorial of 3 that should pass.
>>> factorial(3)
6
Test for the factorial of 0 that should fail.
>>> factorial(0)
1
"""
return np.arange(1, n+1).cumprod()[-1]
doctest.testmod() OUTPUT:
(base) CMD>python s1.py
**********************************************************************
File "s1.py", line 11, in __main__.factorial
Failed example:
factorial(0)
Exception raised:
Traceback (most recent call last):
File "E:\programfiles\Anaconda3\lib\doctest.py", line 1329, in __run
compileflags, 1), test.globs)
File "<doctest __main__.factorial[1]>", line 1, in <module>
factorial(0)
File "s1.py", line 14, in factorial
return np.arange(1, n+1).cumprod()[-1]
IndexError: index -1 is out of bounds for axis 0 with size 0
**********************************************************************
1 items had failures:
1 of 2 in __main__.factorial
***Test Failed*** 1 failures.
(base) CMD>python s1.py -v
Trying:
factorial(3)
Expecting:
6
ok
Trying:
factorial(0)
Expecting:
1
**********************************************************************
File "s1.py", line 11, in __main__.factorial
Failed example:
factorial(0)
Exception raised:
Traceback (most recent call last):
File "E:\programfiles\Anaconda3\lib\doctest.py", line 1329, in __run
compileflags, 1), test.globs)
File "<doctest __main__.factorial[1]>", line 1, in <module>
factorial(0)
File "s1.py", line 14, in factorial
return np.arange(1, n+1).cumprod()[-1]
IndexError: index -1 is out of bounds for axis 0 with size 0
1 items had no tests:
__main__
**********************************************************************
1 items had failures:
1 of 2 in __main__.factorial
2 tests in 2 items.
1 passed and 1 failed.
***Test Failed*** 1 failures.
Code with two functions
import numpy as np
import doctest
def factorial(n):
"""
Test for the factorial of 3 that should pass.
>>> factorial(3)
6
Test for the factorial of 0 that should fail.
>>> factorial(0)
1
"""
return np.arange(1, n+1).cumprod()[-1]
def isEven(n):
"""
Test that would pass
>>> isEven(10)
True
Test that would fail
>>> isEven(9)
True
Test that would pass
>>> isEven(9)
False
"""
rtn = n % 2
return rtn == 0
doctest.testmod() Output
(base) CMD>python script.py
**********************************************************************
File "script.py", line 11, in __main__.factorial
Failed example:
factorial(0)
Exception raised:
Traceback (most recent call last):
File "E:\programfiles\Anaconda3\lib\doctest.py", line 1329, in __run
compileflags, 1), test.globs)
File "<doctest __main__.factorial[1]>", line 1, in <module>
factorial(0)
File "script.py", line 14, in factorial
return np.arange(1, n+1).cumprod()[-1]
IndexError: index -1 is out of bounds for axis 0 with size 0
**********************************************************************
File "script.py", line 24, in __main__.isEven
Failed example:
isEven(9)
Expected:
True
Got:
False
**********************************************************************
2 items had failures:
1 of 2 in __main__.factorial
1 of 3 in __main__.isEven
***Test Failed*** 2 failures.
Writing unit tests
Test-driven development (TDD) is the best thing that has happened to software development this century. One of the most important aspects of TDD is the almost manic focus on unit testing.
The TDD methodology uses the so-called test-first approach, where we first write a test that fails and then write the corresponding code to pass the test. The tests should document the developer's intent, but on a lower level than functional design. A suite of tests increases confidence by decreasing the probability of regression and facilitates refactoring.
Unit tests are automated tests that test a small piece of code, usually a function or method. Python has the PyUnit API for unit testing. As NumPy users, we can make use of the convenience functions in the numpy.testing module as well. This module, as its name suggests, is dedicated to testing.
Script.py:
import numpy as np
import unittest
def factorial(n):
if n == 0:
return 1
if n < 0:
raise ValueError("Don't be so negative")
return np.arange(1, n+1).cumprod()
class FactorialTest(unittest.TestCase):
def test_factorial(self):
#Test for the factorial of 3 that should pass.
self.assertEqual(6, factorial(3)[-1])
np.testing.assert_equal(np.array([1, 2, 6]), factorial(3))
def test_zero(self):
#Test for the factorial of 0 that should pass.
self.assertEqual(1, factorial(0))
def test_negative(self):
# Test for the factorial of negative numbers that should fail.
# It should throw a ValueError, but we expect IndexError
self.assertRaises(IndexError, factorial(-10))
if __name__ == '__main__':
unittest.main()
OUTPUT:
(base) CMD>python script.py
.E.
======================================================================
ERROR: test_negative (__main__.FactorialTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "script.py", line 24, in test_negative
self.assertRaises(IndexError, factorial(-10))
File "script.py", line 8, in factorial
raise ValueError("Don't be so negative")
ValueError: Don't be so negative
----------------------------------------------------------------------
Ran 3 tests in 0.078s
FAILED (errors=1)
(base) CMD>
(base) CMD>
'Ignorance isn't bliss forever'
When one gets along an irritating person, thing, or habit, it may sound intelligent to ignore them all. But, it doesn't work that way for our psych, our mental being. Attention seeking irritating people can keep one's brain highly occupied in inhibiting from producing thoughts. So it is supposed to be fought, not escaped. Look onto them, recognize them, people like them, their behavior, actions. Once you know what they do and what they are, it should not be difficult to device a reaction for their actions. Plus, there will be nothing you need to know, or don’t need to know, because you already know it all.
February 11, 2011
That old woman, Ms. Bhati died last night. She used to look well in her health; she used to walk around in the society, had friends with most extravagant house-wives, and used to look like in the early years of old age. News came home via chachi; she had seen her last night around ten when she was walking in the society. And around 0030 last night, she just slipped after the attack of some ailment.
I was thinking about her death, and thinking of amma growing old each day. Huh!
It was the second day of the sports meet. I sat in the library to study Communication Systems. I have no place on earth where I can be alone. I mean, being alone is not what I want but I want no disturbance. That’s impossible at home, chachi and Prashant both are d**kheads, I can’t even expect them to act like normal, let alone intelligent.
I was home around seven. It feels good to travel at night, crowded bus passing by traffic of Delhi roads.
God Bless ‘Me’
Ashish
February 10, 2011
I didn’t wake up to study early after having wasted time in sleeping, watching TV, and watching movie on laptop last night. Chachi and kids had gone to a wedding, then.
I reached college at around eleven. And I sat there till four-thirty in the evening. I studied ‘Communication Systems’ it required third semester math which I had missed, so I had to do and still have to do that missing part of math course from third semester.
Result is still a month away but the way chachi ask for it is disturbing, as if she owns me.
God Bless ‘Me’
Ashish
February 9, 2011
I wasn’t about to miss today’s ADA (Algorithms Analysis and Design) class after being made the class coordinator yesterday. I reached college on time well around eight. It wasn’t difficult to study Prashant’s sir subject after having spent hours in library to do the same.
Well, getting to class was worth the money I spent on reaching college on time. I spent R29 to get there. Otherwise, I travel free for weeks!
It was a fine day at college, I came back home early at four. Oops, I had not thought that I would find chachaji on the door. I thought he left but when I reached home, he was about to leave. Huh!
I also have to count the R50 I gave up to Hemanshu Verma of S2. I didn’t mind lending him that money; otherwise, I am not even a spender.
I was doing second semester Math, now I should better catch up with this, the 4th semester subjects. First terminal tests are nearing. First is on 27th of February.
God Bless ‘Me’
Ashish
February 7, 2011
I woke up in a rush at 0802, something. I went to amma’s room to get ready and leave with babaji.
As we waited for Manju buaji on the bus stop, driver told babaji to clean the wound which was bleeding on his forehead. Actually, babaji bruised his forehead near the brow by the edge of the door. It felt extremely awful to see yet another loss in by some means. How can I be so thoughtful about such things at this age?
I couldn’t attend even the nine-am class for coming late. Then we were just made to sit in the DCS (Digital Circuits and Systems) lab. Ms. Neeru ma’am was not in the mood to teach, you see! I was left alone. The class is so poor! I was reading Abhilash’s notebook and when I tried to ask him and Mukul what they were talking about I was looked down by the Mukul Chandra, wow, wow, wow, is that reality I am living in?
I was in the badminton court eating my lunch and I didn’t raise my head up to see but I knew I was being watched by people hanging on the bridges on the top floors on my left. Well, the game was going on the right, so that kept me at ease.
After sitting alone whole day, I was met by Neha in the last class. She came by to ask about that post. And after a hearty talk, she just said if next time to any such thing, I should be excluding her name too. It was a favor, she said, she was asking for. And, I learnt what this bitch was up about, well, that doesn’t hurt anymore. I have a clear pass to Apurva Sood, but my pocket is not filled enough for nobody.
Neeru ma’am is after me. She was acting totally slutty whenever I saw her. The way she eyes me, and I was literally scared for a second when I was bent down to search for a page in my bag and she came down the row to stand next to me. She had run her finger on my table like trying to seduce. This is going beyond limits. I am totally infamous at college, just one case and I am dead.
You know, it felt proud when in the break Apurv referred to me as ‘Tank of Our Class’.
God Bless ‘Me’
Ashish
February 6, 2011
I went to buy books today. And chachaji came back today, for mere two days to my gladness. We saw each other before I left for Daryaganj.
I collected books from a single shopkeeper. I mean, I didn’t get to go to another. He suited me. Though, he wasn’t very profitable for me.
After that, I went to badi buaji’s house. I had sort of breakfast around twelve, I told badi buaji to keep it light but it went on to becoming heavy, though I had never expressed myself in words. Huh!
Then, it was normal life at her place. I sat on computer with Ankur in the office, and we were upstairs for lunch. After lunch, Shruti and I had kind of a serious talk about her preparation for board exams and life after that. I mean, she is troubled by her almost nil preparations for three subjects. And, in those subjects, she failed to clear the pre-board exam. It is Chemistry, Physics, and Math. It is funny how a science student can fail in PCM.
I was just sitting downstairs whole time long, taking x-rated movies from Ankur. I was home with Ankur in his car because badi buaji sent him to buy some bakery items from some far away shop and in the process, he just came by to Manu Apartments with me.
Chachaji saw the books, and not much inspection of the prices and other details, just a casual view of everything. That was easy to handle.
God Bless ‘Me’
Ashish
February 5, 2011
Last night I was crying in bed for having such a f***ing sick life. Today while sitting in college I almost structured a new religion, Modern-Day-Jainism, or more clearly Jainism-post-2011. It states that God has no known face on name. And god is neither omniscient, nor a retard, unlike what all other religions try to prove.
Before writing this, I literally went to dropping two heavy drops of tears on the page on the book I was reading. It was more noticeable how I got back to normal in no time. Crying was because of the last night again. Life never felt so sick before.
I have been missing sleeping hours and have been napping in evenings and afternoons so I generally feel my head shaking which remind me of earthquakes. I mean I have faced quaking tremors one night I always get the same feeling every time my spins out of natural weakness.
In the library after having shed tears, it went quite around me. These days, I can hear my heart beating; I can feel my blood pumped into my skull, that’s it is so heavy because of all kinds of troubles from life.
I was home in the evening, and I was asleep.
God Bless ‘Me’
Ashish
4 February 2011
Babaji said Manju buaji was angry with him yesterday morning. I get to hear this kind of bullshit when I am there in amma’s room for bathing, or changing purposes. I was there in the morning. I didn’t pay attention to that, but still it comes to my mind and I have to make special efforts to avoid it.
Later when amma called Manju buaji on phone, buaji almost wept as I heard amma saying.
I went to the college and it was fine. During the return trip, as I climbed the bus a girl was doing her hair and I just found it funny somehow. I had to first laugh and as she saw me, my pursed lips opened up in smile. She was cute: I have to say that. And I didn’t mean to scare her. But she and her friend checked me almost a dozen times after that, it was awful in its own. Her friend changed the bus on Red Fort and the girl changed her seat from second to mine in the next row to the most distant one. The first one in the same row, the one that also falls in the seats reserved for women. Huh!
I was asleep and there was this drama from Prashant, of leaving the lights and door opened. I couldn’t sleep after ten, that’s when he begins his activities. I was reckoning my options of living life here. One is going to Trinagar, second is managing time-table to adjust the disturbances which this idiot creates, and continuing a life here. It sucks when I have to tell myself that Ashish cut down your hopes for reaching high because your run isn’t on the same track as that of a professional. I can’t even trust babaji when it comes to the most important decisions of my life, because on almost every such point of my life he has always disappointed me, not once or twice.
I am not lying nor do I have words to describe how it feels. Just tell me, when does a grown man cry?
I am no more going to follow the practice of reading Bhaktamar and counting beads on fingers. I just did it twice today because I missed doing it yesterday due to busy schedule. I don’t believe in blindly following any religion whatever it might be. I don’t believe in ‘God’ as the people describe them. I do believe in teachers but not gods as the people describe Him. And I don’t even understand Sanskrit; I don’t understand pure Hindi properly, let alone Sanskrit. English is my mother tongue now!
-Ashish
February 3, 2011
I posted in C.S1.E on Facebook at 2 a.m.
” Except Karishma, Astha, Shreya, Sonam, and Arushi Jain, all other females are total rude hags.
Listen bitches please take no offence. I was just putting light on your reality.”
It was deleted when I checked my account in the morning (1330). I was in library as I switched on my phone I received Vibha’s messages sent an hour before.
I studied ADA till four-thirty and then I came back home. I watched TV from 1830 to 1930, Hip-Hop Hustle, and Ticket to V.I.P.
I was asleep after that, and I got two missed calls from Vibha.
Vibha had called me ‘THE BLOODY F***ER.’ And was she threatening me of breaking up with me earlier, as if I ever felt for her!
I had never replied to her since my message card got over, funny.
Teachers in college were watching my moves, they had planned to even check it when I saw that naughty-in-forty (maidservant) walking upstairs to the classrooms. I quickly turned and headed to the library to avoid any confusion. These college keepers were everywhere, ignoring or noticing me, god knows.
I met principal today. I showed her the notice and she carefully went through it taking her full time. Then she comments in the language used in the notice itself. Like I am some fool. She never did anything about it the way she had said last time when we met.
God Bless ‘Me’
Ashish
February 2, 2011
Without tea, I can’t stay awake whole night. It feels so tiring to go to college in half-sleep.
Today again, I was thrown out in the first class. It wasn’t my fault completely. It was 10 a.m. class, Operating Systems. That stupid looking teacher (who really is stupid if trust anyone from the class) came and asked some question from the first bencher. We missed the question. And, then Aditya had opened the notebook. She probably saw that and stood him. He said he didn’t know the question, so she passed the same one on to me. I told her the same thing that she wasn’t audible here in the end. So she sent all three of us out, Aditya, Nitish, and me.
Huh, because lately I have been feeling alone so I just sat with these two and talked for an hour. Next class of Comm. Graphics was fine, and the practical class of S.E. (Software Engineering).
Sometimes you know it feels awesome to be single, the attention one gets from these single-girls most of whom are single because of there attitude. You know it just raises your price. Kanika (fatso), Shreya, Karishma, Tanvi all look at me like I am an eye-candy.
God Bless ‘Me’
Ashish
February 1, 2011
“You should not dive into murky waters”
Had I not slept till seven-forty I would have got to attend ADA class. ‘Analyzing and Designing Algorithms’ taught by Mr. Prashant. His class started at nine and I reached college at nine-thirty. I sat alone in the next class, and studied the ADA book which I had. Faizan, Apurv, and Rizwan came there; Faizan had come late while Apurv and Rizwan said they were thrown out of the class for entering late. They had entered the class a few seconds late and sir was rubbing the board when he didn’t let them in.
‘A’ Batch had Computer Graphics lab but the teacher wasn’t coming so we were free, while B-batch went to attend their lab session. I was roaming like lost soul in the break; I am supposed to be like that. I haven’t made any friends yet. Life sucks in those fifteen-twenty minutes, which seem to be like hours.
Communication Systems teacher asked for introduction today. Ah, I was literally huffing while speaking and teacher asked why I was looking tired while speaking. I didn’t want to give introduction, it sucks, and my results were oh-so-f***ing-poor. That is which every teacher asks.
Swarnlata ma’am came to the class but just let us go after taking the attendance.
The class almost seems to hate me, the groups have formed, and I can’t find a place nowhere. Plus, I learned from examination cell that 90% of the first year back-log would have to be cleared. So, I was seen in Principal’s (Yamini) room again. She said she would check it and tell me tomorrow. Now, I’m wondering at what time I should get back to her.
God Bless ‘Me’
Ashish