Sometimes I have a melody in my head that just needs to come out, so I sit in my keyboard and start playing until it sees the light. It's not like I'm an expert or anything, it usually take hours before the melody comes out the way I want.
I also write my own lyrics. I always try to brainstorm on every chance I have. Most of the time I carry my backpack, so I'm sure I have a notebook to write in. I have even stopped while walking just to write down something that was going through my mind at the moment, lol. There are also times where I just find myself singing the first thing I can think of, and before I realize, I come out with a verse or a chorus idea.
It's quite therapeutic xD!