Aashish's blog

Method, interface and pointers in golang

• go, and golang

go play link

type struct1 struct {
	greeting string
}

func (s *struct1) hello() {
	s.greeting = "hello"
}

func main() {
	ptr_s1 := &struct1{}
	fmt.Printf("ptr_s1 is of type : %+T\n", ptr_s1) // *main.struct1
	fmt.Printf("ptr_s1.greeting: %+v\n", ptr_s1)    // &{greeting:}

	ptr_s1.hello()
	fmt.Printf("ptr_s1.greeting: %+v\n", ptr_s1) // &{greeting:hello}

	s1 := struct1{}
	fmt.Printf("s1 is of type : %+T\n", s1) // main.struct1
	fmt.Printf("s1.greeting: %+v\n", s1)    // {greeting:}

	s1.hello()
	fmt.Printf("s1.greeting: %+v\n", s1) // {greeting:hello}
}

Why do we like reading old books?

• books

There is a strange timelessness in reading an old book because it is a physical piece of history. A book carries stories about not only the protagonists and antagonists but also about the countless readers who read the book. In a way, the readers themselves become part of the “plot” that the book carries with it.

The crease at the end of the chapters add another layer of history to the original plot. Holding an old book is almost like meeting grandma as a kid. She is sweet and innocent like kids; she has the same childishness, and carefreeness as we once did as kids. But contrasting to her demeanour is her body - it is covered with stretched and wrinkled skin; it bears witness to the countless lives and stories it was once part of. Similar to our grandma, an old book, too, bears witness to the countless lives it has been part of. The spice-stained pages, the tear wrinkled edges and the sun-dried fluffy pages bear witness to both important and frivolous events of a life that has passed. The person who lived that life may be alive or long dead but his remnants continue to live and be part of other reader’s lives through books. If the person is alive, does he ever think about these spice-smeared pages? Does he remember how his tears shriveled these edges? Or has he forgotten these pages and also the events that caused the deformation?

Sometimes I recur these ideas on myself. Have I forgotten important events of my life? Have the remnants of those events been part of someone else’s life or have they all vanished? Will I live in people’s mind as a single person or will I disintegrate into little unidentifiable cues in old shabby books?

Notes from javascript the good parts

• javascript, good, and parts

var empty_object = {};
var stooge = {
    "first-name": "Jerome",
    "last-name": "Howard"
};
var middle = stooge["middle-name"] || "(none)";
var status = flight.status || "unknown";
var x = stooge;
x.nickname = 'Curly';
var nick = stooge.nickname;
    // nick is 'Curly' because x and stooge
    // are references to the same object
var a = {}, b = {}, c = {};
    // a, b, and c each refer to a
    // different empty object
a = b = c = {};
    // a, b, and c all refer to
    // the same empty object
// Create a variable called add and store a function
// in it that adds two numbers.
var add = function (a, b) { return a + b;};
// Source: http://javascriptissexy.com/javascript-variable-scope-and-hoisting-explained/
// If you don't declare your local variables with the var keyword, they are part of the global scope​
var name = "Michael Jackson";

function showCelebrityName () {
	console.log (name);
}

function showOrdinaryPersonName () {	
	name = "Johnny Evers";
	console.log (name);
}
showCelebrityName (); // Michael Jackson​

// name is not a local variable, it simply changes the global name variable​
showOrdinaryPersonName (); // Johnny Evers​

// The global variable is now Johnny Evers, not the celebrity name anymore​
showCelebrityName (); // Johnny Evers​

// The solution is to declare your local variable with the var keyword​
function showOrdinaryPersonName () {	
	var name = "Johnny Evers"; // Now name is always a local variable and it will not overwrite the global variable​
	console.log (name);
} 
for (var i = 1; i <= 10; i++) {
	console.log (i); // outputs 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;​
};

// The variable i is a global variable and it is accessible in the following function with the last value it was assigned above ​
function aNumber () {
console.log(i);
}

// The variable i in the aNumber function below is the global variable i that was changed in the for loop above. Its last value was 11, set just before the for loop exited:​
aNumber ();  // 11​
function showName () {
console.log ("First Name: " + name);
var name = "Ford";
console.log ("Last Name: " + name);
}

showName (); 
// First Name: undefined​
// Last Name: Ford​

// The reason undefined prints first is because the local variable name was hoisted to the top of the function​
// Which means it is this local variable that get calls the first time.​
// This is how the code is actually processed by the JavaScript engine:​

function showName () {
	var name; // name is hoisted (note that is undefined at this point, since the assignment happens below)​
console.log ("First Name: " + name); // First Name: undefined​

name = "Ford"; // name is assigned a value​

// now name is Ford​
console.log ("Last Name: " + name); // Last Name: Ford​
}
// Both the variable and the function are named myName​
var myName;
function myName () {
console.log ("Rich");
}

// The function declaration overrides the variable name​
console.log(typeof myName); // function
 // But in this example, the variable assignment overrides the function declaration​
var myName = "Richard"; // This is the variable assignment (initialization) that overrides the function declaration.​

function myName () {
console.log ("Rich");
}

console.log(typeof myName); // string 
var myName = function () {
console.log ("Rich");
} 

Unix crashcourse

• unix, shell, and shellpower

Following is a list of basic shell commands for Unix:

ls

ls -l 

Outputs

drwxr-x---   2 akarki15 akarki15       6 Jun  2  2011 bin
-rw-r-----   1 akarki15 akarki15 4194304 Apr 22  2014 block-device.data
drwxrwxr-x  17 akarki15 akarki15    4096 Feb 28  2014 cs111
drwxr-x---  19 akarki15 akarki15    4096 May 28  2014 cs112
drwxr-x---   6 akarki15 akarki15     147 May 10  2014 cs-261
drwxr-x---   3 akarki15 akarki15      18 May  1  2013 CS281

How do you change the access settings?

Why does it hurt when someone dies?

• death, and contemplation

I received a call from my sister today who told me that our beloved pet dog “kaale” died today. For a dog, she lived a long life - she was 15 years old this year. I was grieved by the news although I had been in preparing myself to bear the inevitable news of her (Kaale) since returning from my trip to Nepal. She looked frail and thin, ate very little and didn’t move around much. I shudder even now thinking how thin she had gotten- I could feel her spine sticking out of her back and her ribs protruding out of her belly.

I tried to console my sister who was on tears over the phone. I found it meaningful to talk about how important role Kaale had played in our lives- especially in our childhood. She had been with us, and around us throughout as we were growing up. My sister brought Kaale in the little metallic basket of her newly purchased ladybird bike while she was in her 4th grade. She brought her all the way from the bazaar, from our aunt’s big 4-storied house. I can’t remember how young kaale was at that time, but I am fairly confident that she was under a month old. I think my mom was surprised that kaale didn’t die during that bike trip considering the ladybird bike did not have any suspension whatsoever and my sister had to travel around 500 meters of graveled road along the way. I still remember playing with kaale in the front porch- as I fluttered a piece of cloth and ran around with it in the front porch and the verendah, kaale would chase it and try to bite it. I vividly recollect teaching her how to stand on her hind legs and do a “namaste”. Although her face would twitch a little indicating the discomfort she was having, she would silently obey me. I was a proud elder brother who had taught kaale a trick. I also remember that one time during my 8th grade when my sister and I called the local radio station and told the hosts that we wanted to wish Kaale her 4th birthday. We thought it was ingenious and extremely hilarious. I think we have a recording of that broadcast somewhere in our old PC/phone.

As I was recollecting the memory of Kaale with my sister, I realized that it is the memory of the dead that haunts us. Our loved ones embody the times we’ve had together- kaale embodied our childhood, our innocence, our glee and our mischievousness. Last winter when I was with Kaale, I did not see the crooked old body, breaking apart like the rusted 15-year old ladybird on the roof of our house- battered by the rain, the heat and the wind of sub-tropical hill. Instead, I saw the memories we’d created, and the times we’d shared. As I saw Kaale basking in the sun last winter, looking coldly and almost angrily at the jumping little dog (we had recently got another dog), I remembered W.B. Yeat’s poem.

THE LAMENTATION OF THE OLD PENSIONER

Although I shelter from the rain Under a broken tree My chair was nearest to the fire In every company That talked of love or politics, Ere Time transfigured me.

Though lads are making pikes again For some conspiracy, And crazy rascals rage their fill At human tyranny, My contemplations are of Time That has transfigured me.

There’s not a woman turns her face Upon a broken tree, And yet the beauties that I loved Are in my memory; I spit into the face of Time That has transfigured me

And when I heard that Kaale died, I felt that a part of my childhood had died- I felt little pigeonhole that is Kaale through which I could cherish my memories was closed. Although I can’t imagine Kaale’s suffering while she was dying, I was kind of glad that she was ridden of the bitterness that had filled her life- how time had transfigured her. She who used to be more agile, more talented than that little prick (the dog) who constantly teases her, was now rendered so ugly and helpless by time. In a way, my own childhood and my memories were being mocked by that little prick. I am glad that Kaale does not have to endure the bitterness and the pain of old age anymore. But at the same time, my heart is utterly broken because with Kaale, a part of my childhood just died.