better living through python

An adventure in programming and recovery.

Mountains of trash, and how good they are for you

October 10, 2011

I read a blog about a man who has been blogging for eight years.  He mentions several times in his blog that for him, his blog is almost purely selfish.  He writes it to connect with others, to create dialog and discussion, and because of how much the writing/connections/discussions mean to him.

While thinking about his message I starkly realized just how selfish my own blog is as well.  I use it to create, to converse, and to process.  Much of it is simply for me.  To make my life better, to bring a consistency and purpose.  I hope to help others through my musings and discussion but that’s all dependent on aspect I’ve no control over.  A person will take what they will from my creations; all I can do is hope to provide something meaningful.

That brings me to the next discovery that I’ve come upon.  The idea of creation simply for creation’s sake.  The understanding that, yes, there is a ton of crap out there.  Without society continuing to create, we will not develop.  There are more of us, and therefore more crap, which just means that the more we try and the more we learn, the better chance we have of providing or producing something meaningful.  

Enough of this self doubt and concern that everyone else has already done it!  I’ll continue to write my blog.  I will continue to create and produce other things.  I will continue to try and experiment.  I will produce a mountain of trash if it means I can eradicated my uncreative thinking, for then I will have released my innovative soul.  

Up Next Time: A run in with a previous coworker

 

There is a squatter residing in my head

October 07, 2011

Something I think about off and on is the enticement of revenge.  Normally ideas of revenge come to mind when considering the things that happened at my previous job, prior to FlamingLunchbox.  More specifically the feelings of being harassed by my immediate supervisor.  Most of these ideas are simply daydreams.  It reminds me, I suppose, that I am human.  For many people the idea of reacting in anger, or feeling or wishing to enact revenge, is considered a bad side of a human being.  

It’s considered bad because it promotes social dysfunction, and increases anger overall.  Anger and dysfunction promotes less production and a less productive society is, over all, supposed to be not good.  People react with anger or hurt for so many reasons.  Many of those reasons are because they feel threatened.  In ways I felt threatened at my previous job; most explicitly felt threatened with job loss, which created a feeling of loss of self worth, and loss of respect.  It has taken me months of reflection and thought to get to a point where the anger doesn’t burn as hot.  

What I’m getting at is that despite the time it’s been and my months of reflection, I still have this anger burning inside me.  It’s not as strong or potent, but it’s still there.  People try to offer advice by saying to forgive or simply let go.  Others say I should simply accept it and find a way to not let it bother me anymore.  Life’s too short and all that jazz.

Sometimes I tell myself I should be thankful.  I would never have taken the leap without that, shall we say, ‘encouragement’ that was provided.  But I’m still hurt, and I’m still angry.  I’m still recovering from that loss of self worth, and teaching myself that I’m capable and talented.  I feel again that I can do things.  I’m no longer shut down by the simple reminder of the humiliation I felt.  

I still write blog entries about my anger.  I continue to try to process it by throwing it out there for the world to see.  For people to criticize me and tell me something, anything, that might help make it go away.  I saw something recently that said, “If you continue to hate or be angry about someone, you’re simply allowing them free rent in your head.”    

In a way that comment hit home.  I’m still allowing this woman to reside in the my thoughts and affect the way I feel about myself.  I don’t know how to get her to leave.  Every time I start to question myself there she comes again, parading in and telling me where to move the furniture to her preference.  This squatter simply needs to go.    

 

Musings regarding my programming hurdles

October 06, 2011

 

As I’ve been learning to program, there have been some personal hurdles that I’ve run into that have made it harder to progress.  These vary from simple background education, or lack of, to overcoming personal beliefs.
 
Was math a problem?

I’m a woman, but that age old adage “I can’t do math because my brain isn’t set up that way” was never something that even entered my mind.  I honestly really have issues with women who try to get away with that excuse when it comes to learning math.  It’s just so stupid.  I spent most of my youth in creative pursuits, learning music and producing music, writing and learning other languages.  Those pursuits never interfered from my ability to learn math.  I also never had any teachers that I can remember, who felt that women were less capable when it came to learning mathematics.  I feel that these two aspects are important to understand for my next statement to be taken at face value.

I have never felt I couldn’t do math, but I always felt like math was an option I could always pursue when I felt like it.  One never has a problem finding a math course, almost wherever you go.  When I was in college all I wanted to do was learn things that I might not have access to later in life.  Therefore I learned about languages, alive and dead, history and culture.  I studied subjects less common because they were interesting.  I wasn’t expecting to do anything with my degree beyond satisfy my own need to learn.  Anyways, so the base point, I never took any math in college.  When I started programming I was 5 years out of my undergraduate degree, and I had just taken Math 111 and 112 at the local community college.  Getting over my symbol shock took a bit, because it had been a while.  But that was it, that is my background in mathematics.

That simple lack in a sufficient mathematical background made me apprehensive at first when I decided to learn to program.  I knew that it would be logic and math heavy, but I knew that I was intellectually capable and that I had a math grad student (Robey) to help me out when I needed.  I think that’s why, in some ways, when I was presented with one of the first Problem Set’s I fought it.  It was regarding prime numbers.  I didn’t fight it because I felt incapable of learning and using math, but because of my recognition of just how much I didn’t know.           

Learning to stay focused by using music

Another hurdle that presented itself was learning how to use the energy and creativity of music while still being able to think.  That took time.  While I was still getting over programming symbol shock it was almost impossible to listen to music while trying to program.  It wasn’t until recently that I truly felt able to program while listening to music.  Once I was able to do so, I saw an increase in the amount I programmed, and in the enjoyment from programming.  I definitely started feeling the creativity of the music and the energy, and my code thus improved.  That’s all I can think of for now.  I’ll keep you posted as I realize/jump more hurdles.

Up Next Time: Mental health check-in

 

The final Ghost() function

October 05, 2011

 

When I started creating the ghost() function, I thought I could do most of it within one function.  I probably still could, but at the time it made it really difficult to understand what I was doing.  I had almost written it all when I realized I had no idea how to implement a cycle between the two players.  At first I had no idea how to do it.  Then Robey showed me a pretty common way to cycle, by using mod.  

Mod is a way to wrap, or find the remainder of something.  Bare with me here, because I’m still learning this myself.  Here is the basic code for using mod to cycle (or toggle) between two different players.  

 

i = 0
while True:
i += 1
i %= 2
if i == 1:
   print "player 1 action's"
if i == 0:
   print "player 2 action's"

 

First you assign your base variable i, which instigates the cycle.  Then you create a while loop that will increase incrementally, here it is incrementally increased by one.  Then you choose a total number of players.  You can see that we indicate two.  Then we place in an if statement which allows us to designate the different players actions.

How does mod work?  Mod will show the remainder, after i is divided by the number given.  The first time our loop is run, i is equal to one.  One is not divisible by two, and therefore the remainder of that division is one.  The second time this loop is run i is equal to two.  When two is divided by two the remainder is zero.  The third time this loop runs i is equal to three, and when three is divided by two the remainder is one.  Thus the cycle continues, and that’s how I was able to set up a system to cycle between the two players.  Using this idea, I was able to finish creating my function, shown below.

 

def ghost():
   i = 0
   word = ""
   while True:
       i += 1
       i %= 2
       if i == 1:
           print "Player 1's turn"
           word = play(word)
           if preghost(word) == False:
               return "Game cannot proceed as there were no vowels in the first three entries."
           elif word in word_list and len(word) > 3:
               return "Player 1 has lost the game."
       elif i == 0:
           print "Player 2's turn"
           word = play(word)
           if preghost(word) == False:
               return "Game cannot proceed as there were no vowels in the first three entries."
           elif word in word_list and len(word) > 3:
               return "Player 2 has lost the game."                      

 

As you can see I assign i to zero and word to a blank string before I implement the while loop.  This while loop uses mod to cycle and then the rest of the functions created are inserted.  First I show whose turn it is and then run the function play(word).  That function provides the variable word,which I then run against the preghost() function.  That function returns True or False.  If it’s False I know that the word has no vowels within the first three letters submitted and the game is over.  Otherwise the game continues until one player, I’m assuming accidentally, creates a word.  Once that occurs, the player who has lost the game is identified and the game ends.  

What did I learn? The major things I learned from creating this game was how to create a cycle between n amount of players.  I feel like I better understand how to use mod.  I relearned that strings can be used like lists with for loops.  I also better understand how the incorrect placement of return statements can, at times, make functions interact entirely differently than you want.  Lastly I learned the importance of separating out my processes into smaller functions, even if simply to create code that is more easily read.

Up Next Time: Musings on my own personal programming hurdles     

 

Functions 2 and 3 of the ghost() problem

October 04, 2011

 

Moving along with the ghost() function today.  If you remember from my last entry, I noted that I decided to separate out several of my smaller processes into individual functions.  I started out with explaining my function that collects the letters inputted by the players, verified that they are letters of the alphabet, and then added them to the list variable word.  

Today I’m going to explain the last two smaller functions I created.  These two functions are meant to verify that there is a vowel in the first three letters submitted, and once verified will return True.  First I started by creating a function only meant to check for vowels.  Here is my function.

 

def vowel(word):
   vowel = 'aeiou'
   for v in vowel:
       if v in word:          
           return True
   return False

 

This function takes in the word created and returned from the function play() I discussed in my last related entry.  The first variable I have assigned is vowel.  It’s assigned to a string of all the vowels in the English alphabet.  Then I use a for loop to go through each letter in the string vowel and check that letter against the word already created.  If there is a vowel in the word then the function will return True, otherwise it will return False.  Here is the second function.

 

def preghost(word):
   if len(word) == 3:
       foundvowel = vowel(word)
       if foundvowel == False:
           return False
       else:
           return True
   else:
       return True

 

This second function is used simply to check on the length of the word submitted, and then verify if the vowel() function returned a True or False value.  To do that, it checks if the length (len) of the word submitted was equal to 3.  If it is, then it checks to see if there is a vowel present by using the before mentioned function.  If there is no vowel the function will return False, otherwise it will return True.

I separated the two functions because it made it easier for me to view and understand my code.  I could most certainly have combined them, and might do so in the future, but as this was my first attempt at creating a more complicated piece of code on my own I decided to simplify it as much as possible.  Doing so helped me a lot in later debugging.

Notes on Debugging: The preghost() function was originally written differently.  When I first wrote it I hadn’t put in my return statements in the correct spots.  I had only placed them in once or twice and because of that my final processing function (ghost()), wasn’t actually running the function.  As my vowel() function is only called within the preghost() function, that meant I wasn’t calling either function.  When I started debugging I had no idea my bug lay in my poorly inputted return statements, that is, I didn’t have any idea until I had Robey review if for me.  It was a learning experience to know that my return statements from the preghost() function, placed incorrectly, was bypassing a good chunk of my code.  

Up Next Time: The final processing function to ghost()



 

 

Problem Set 5; Problem 6 of 6

October 03, 2011

 

This final problem was to create a python version of the game Ghost.  Ghost is a two player game.  Each player simply enters a letter until a word is created.  Once a word is created, the player who did so has lost the game.  There are few rules to this game.  First rule is that a vowel must be present in the first three letters entered.  Due to that rule a word can be (and often is found) present within the first three letters.  Creating a word within the first three letters is the only acceptable way to create a word without losing.  Once beyond the three letter mark, if a word is created that player loses the game.  

I rewrote this code so many times.  I might have finished this problem earlier in the week, but I had to create most of the functions on my own.  Please note that it wasn’t just creating the functions itself that was difficult, but mostly it was understanding what kinds of functions to create and how to organize them.  I was only provided with two functions with which to make my game.  This was the first time I attempted something this complicated without more help from the MIT course information provided.  In order to better explain my organization and final code I’m going to split this game up into a couple of blog entries, specifically as there were several function mishaps I want to discuss in detail.

To create this game I separated it into four different functions.  Three of those functions were supportive to the final function, which processed the game.  In this post I’ll just talk about my first function, the play function.
 

 

def play(word):
   print word
   player = raw_input("Please enter a letter:")
   for p in player:
       if p in alpha:
           word = word + player
   return word

 

This function was created to separate the play aspect and word creation out from the main processing function.  Here I have the word printed for the player, then I ask the player to enter a letter.  Then I verify that the player has submitted an alphabetic letter by comparing it against list of the alphabet.  Once that’s confirmed, I make sure to add the letter to a list that is being created.  Therefore I keep all the data entered by the two players in the game.

 

Changing my career trajectory and starting a business at 28

September 30, 2011

 

The family I come from has never really been into starting or running their own business.  My family was always about getting a job from someone else, making a living, finding hobbies, starting a new family.  My family was also about always wanting their children to have better lives than they did.  That meant providing as much as they could for them, helping them out when needed, helping them to get a better education and so on.  But because my family was never much into starting their own thing, I never really learned much about it.
  
I’ve never had a huge inkling to start my own business.  I’ve never had an inkling to run my own business either, simply to do well and continue to progress in my career.  Because of the problems I was having at my former place of employment, I was presented with this situation.  A situation I now consider was a huge opportunity.  A chance to try striking out on my own, with a partner that partially knew what he was doing, and to try something totally different.  Something that could mean more to me than paper pushing and answering to people who really didn’t care.
  
I chose to give up a stable income.  I chose to give up what was known, what was easy.  I chose to begin a path that would allow me to create my own future.  Albeit, hacking down the bushes in a jungle to start your path is a rough way to start, but sometimes you have no choice.  
 
In all honesty we’re lucky.  We looking into two entirely new markets.  We’re learning tons about how things work within programming and how to start a business.  We’re learning how to control our own bad habits and what financially is more important.  
I used to think all I wanted was to have more freedom to my schedule, to have more flexibility.  In part I was right.  I wanted more flexibility, but I don’t think I ever realized how much I wanted the ability to be more challenged every day.  Not challenged by the amount of work I had to do.  Not challenged by the multitude of different people I had to understand in order to get my job done.  But challenged by all the different and interesting tasks I could present myself with.  
I get to write everyday.  I write about myself and my challenges.  I get to learn better ways to express myself.  I get to learn how to program and understand technology better than I ever have before.  I’m learning how to use graphic editing programs, which allows me to create art all the time.  I can make beautiful things.  I can write beautiful things.  I can create.  Best and worst of all I get to learn how to deal with my mistakes.  The longer I work at this, the better I get to know myself.  The better I seem to accept myself.  I don’t think I could have made a better decision.  Even if this business doesn’t pan out.  Even if we have to put a stop to all these wonderful things, I will have been a better person because I had the time to learn who I was and what I was capable of.  After feeling abused and harassed at my previous job, and despite the difficult challenges I put myself through, I don’t think any other path would have been as rewarding or as satisfying as choosing to start a business.          

 

Problem Set 5; problem 4 and 5 of 6

September 29, 2011

At this point in the Problem Set, we’ve created and finished all the necessary functions required.  Now to put them together in one final function called play_hand().  This function will take all the other functions, and run them as needed to play the game.

 

def play_hand(hand, word_list):
   n = HAND_SIZE
   display_hand(hand)
   print "You may enter '.' if you cannot create a word."
   word = raw_input("Please enter a word:")
   score = 0
   totalscore = 0
   while not len(hand) == 0 and not word == ".":
       score = get_word_score(word,n)
       if is_valid_word(word,hand,word_list) == False:
           print "That is not a valid word"
           word = raw_input("Please enter a word:")
       elif is_valid_word(word,hand,word_list) == True:
           print "You word was worth " + str(score) + " points."
           totalscore = totalscore + score
           print "Your total score is: " + str(totalscore) + "."
           print "Here is your updated hand."
           hand = update_hand(hand,word)
           display_hand(hand)
           if len(hand) != 0:
               word = raw_input(enterword)
   print "Your total score is: " + str(totalscore) + "."
   return

The first chunk of this function is starting the game up.  First the hand size is defined as n.  Then the current hand is displayed using the display_hand function.  The player is then told they can enter a period ‘.’ if they cannot create a word.  The player is then asked to enter a word.  Finally one sees that score and totalscore are given arbitrary integer assignments, as they will be replaced as the game continues.  

The majority of this problem is solved using a combination of a while loop and three if statements.  In the beginning when I was trying to create this function I created it using a common misconception regarding while loops.  When I first wrote my while not line, I used or between my two conditionals.  I thought I was creating a while not loop that would take into consideration both conditionals, and only allow it to continue process while both were not valid.  However, it seems that with programming, a common misunderstanding is that exact linguistic difference.  One might think to use or, however within python one would use and.  Using and will make it a requirement that both conditionals be met before it exits the loop.  

So, back to the loop at hand.  Here I use a while not loop and state that as long as the length of the hand, len(hand),is not equal to zero and while the word entered is not equal to ‘.’, the following processes will occur.  

First the word that was entered is scored via the get_word_score(word,n) function.  Then an if statement is used as a conditional.  If the word is not a valid word (via the is_valid_word(word,hand,word_list) function), then the player is told that the word is not valid, and the player is then requested to enter another word.  

If the word is valid, then the player is told it is valid, along with the points for the word.  Then the total score is shown and the players hand is updated as the letters have been used.  Finally the newly updated_hand is displayed.  As long as the length of the hand is not zero, then the player will be requested to enter a word based on their current hand of letters.  Once there are no more words capable of being made or a ‘.’ is entered the while not loop is exited, and the total score is once more shared before one leaves the play_hand() function.  
          
One might ask why the score (via get_word_score()) is not calculated outside the loop.  This was a problem I had myself.  I originally calculated the score outside the loop and because I did it that way it never allowed the score or the totalscore to differentiate.  That meant that my total score was never being fully calculated.  The lesson learned here was the importance of identifying what items you want to be updated within a loop and which ones must be identified outside the loop.  If you place them in the wrong spot your information will never collect correctly.  

The last little piece I wanted to mention about problem four, was in how I learned to use if statements within a while loop.  I am still working on fully comprehending where the loop begins and ends, and sometimes loops within loops still confuse me.  I knew I could create an if block within a loop, I just wasn’t used to the logic.  As it was unfamiliar to me still I noticed how interacting with it was fairly confusing.  Until I finished debugging the problem and talked about it with Robey did I start to get a better handle on how they worked together, and how to use such combinations in the future.  

This was the first time I collected such a large group of functions to create one bigger final function.  It seemed quite easy at first, but I quickly learned how difficult debugging such a beast can be.  That knowledge was put to good use when working on the final problem in this set, problem 6.

What happened to problem 5?  Well, it seems that all problem 5 was, was to delete some sections of the previously written code and un-comment other parts, so the entire game could play once my final play_hand() function was finished.  So I did it, and the game was completed.

Up Next Time: Problem 6 of 6, the creation of a game called ghost.

 

Seasonal Productivity

September 28, 2011

There are days, some serious days, when I simply wish this was a private diary where I could simply rant about everything.  Days when I wish this was a blog where even if I simply ranted there would be plenty of people who commented, or days when if I didn’t want comments and none were given.  Days when I didn’t have to care about whom I wrote about, and whether or not they would read it.  Days when I didn’t have to worry about someone else getting hurt by what I said.  
There are times when I wish I could give more, give more and provide more for my family and friends.  Times when I wish I could be that pillar, that one person who might change the lives of my nieces and nephews drastically.  Times when I wish I could do a million things and then I get worried about all of these millions of things and am unable to actually get anything done.  I end up too stressed out and drained like a keg after a frat party.  

Sometimes I feel like there are simply so many things to be doing and accomplishing that I freak out, and my momentum stops before I even get started.  All these ideas are boiling around in my head but getting them out is just taking time from something else I could be doing.  Something else that is equally important.  I need to learn more programming, then I realize I could be spending my time teaching my niece soccer.  Or I feel I need exercise more and realize I could equally be cleaning up the house.  

What I don’t understand is boredom.  I used to understand boredom when I was much younger.  When I would stay in Texas for the summer with my father in this 500 person podunk town, with no friends or family, and one room with air conditioning.  A summer where all I did was watch TV or read books and hang out with my dad.  Boredom is now a luxury.  One that only occurs when my body, mind, and heart are done for the day and cannot do much else.  Although lately even that isn’t occurring.  

Lately I’ve been reading books, and learning about things until I start to pass out.  Then I wake up and get going again.  Something about the Fall makes me more capable, more productive.  It reminds me of starting school, and the excitement of it all.  

Do the seasons heavily affect your productivity?  Another, more important question, is how can we expect them not to?

  

 

Can I cut off my fingers please?

September 27, 2011
This past weekend I was BUSY.  I had three indoor soccer games on Saturday, after a month of not playing any soccer.  I was also planning on running a 5k Sunday morning for the Corvallis Fall Festival, along with playing yet another soccer game that early evening.  Robey and I had a fair amount of canning type projects to finish up with, using the last of our garden’s tomatoes, the plums we had collected, and chopping up the Serrano peppers so we could put them in the freezer.
  
So....Serrano peppers, not to mention all peppers (with varying degrees in intensity), have this oil on them.  That oil can be washed off your skin in the beginning, but if you wait too long it will soak in and one of the elements of the oil will attach itself to your nerves.  What did I do?  Why am I mentioning this?  I cut up about 30 to 40 Serrano peppers (and a couple of Jalapenos), with no gloves on, and then proceeded to my three soccer games without a worry in my mind.  I’d cut up peppers before and had slightly tingly, firey hands, but that was all.  No major pain, and I just went about my business.  
  
Well, what I didn’t mention above is that this element (I think it’s called Capsaicin), binds to your nerves, making your subsequent body part feel like it’s ON FIRE.  Luckily I only really used one hand when touching the peppers.  After my third soccer game on Saturday, my left hand started to hurt.  It started getting worse.  
  
It was late, so I began getting ready to hit the sheets so that I could make it to my run in the morning for the Corvallis Fall Festival.  I took some pain killers for my hand, and then sat in a bathtub to let my legs relax for a while.  While sitting in the bathtub I put my hands in the water, trying to relax.  Bad idea.  Hot water set my hand off and it started seriously burning.  After getting out of the bath I finished getting ready for bed and then put some lotion on my hands.  Another Bad Idea.  Now my hand was literally so painful I felt like I could chop off my fingers and I wouldn’t know the difference.  The only thing that seemed to help was running cold water over it.  I tried to go to sleep but it was just too painful.  So I put my hand in a bowl of cold water and tried to go to sleep, but unless the water was constantly moving it still hurt profusely.  
  
Then I thought, I’ll leave my hand alone for a while, let it dry off, and it will probably numb up so I can get some sleep and still make my run.  I tried to sleep for about 30 minutes but by the end of it I was starting to moan in pain and Robey was getting really worried.  So, we both got up and started looking for a solution on the Internet.
There are all sorts of would-be doctors online, with a variety of different solutions.  We started with the ones that made the most sense to us.  Then we moved on to the more questionable ones.  In total we tried olive oil, vinegar, regular soap, ice, Lysol, rubbing alcohol, triple sec, lotion, bleach spray, Pepto Bismol, and finally crushed up tums in water.  We were both up until 3am, when finally Robey couldn’t get to sleep anymore because I kept shaking my hand vigorously because it was the only thing to temporarily relieve the pain.  He went to sleep on the couch, while I tried to distract myself by watching some TV on the laptop.  I was up for probably another 2 hours until my hand finally calmed down enough for me to pass out.   
Why didn’t I try pain killers, you ask?  I did.  However along with our research came the revelation that pain killers simply don’t work for something like this.  You just have to wait it out.  
  
Other interesting/scary tidbits about this oil:  It’s the same oil used in pepper spray.  One site we found online had a training MD quoted as saying during his experience with a very similar situation, he would express the pain he experienced as 8 our of 10.

Moral of the story: USE GLOVES WHEN CUTTING HOT PEPPERS.      

 

Links