better living through python

An adventure in programming and recovery.

One more day to the launch of my new blog via github

March 15, 2012

One of the major programming and web development projects I’ve been working on lately has been my web page redo.  At this point I am almost fully complete.  Tomorrow I will be finishing up porting many of my blog entries over to the new system.  I will also be creating a tagging system so I can organize my blog content.  Once those two are complete the new blog will be up and running late tomorrow evening, just in time for the weekend.  

I’ve learned quite a bit through this process, and I’ll be linking and discussing much of it over the next couple of weeks.  I’ll be talking about the various services I’m using to create the blog, as well as some of the sites where I’ve found inspiration.  

One of the things I learned from this whole experience, is just how much juice goes into attempting to create something creatively original.  At least, something interesting enough to be not only recognizable but also functional.  Don’t get me wrong, I still have some work to do.  One aspect of which I will be going back through my css and converting all my css over to one file, instead of including it in the <style /> section at the top of each page.

But the truly exciting thing is that I’ve now learned the basics of how to set up a blog.  I am still learning how it all works, and I’ll be blogging about that later on.  I’ve also learned the basics of using github.  For now, I hope people enjoy my new blog look once it’s up and running tomorrow evening.  I’ll post a link to it here on my posterous site, so you can find the new location easily.  If you want to get rss (email) updates, simply select the rss icon on the new main blog page.  As always, feel free to comment on my entries or email if you have questions or comments.       

Recent goings and doings

March 14, 2012

I’ve been busy lately.  My last entry last week was about how I was going to be out as I was busy helping with the Homeless Connect Event in Corvallis.  I was on the planning committee last year and partially this year (it only partially existed).  This event is basically a one stop shop for the local homeless, however the services are available for almost all who attend if they wish it.  These services include some mobile dental and medical vans, that provide services to those without insurance.  There are also a plethora of local assistance programs in attendance at this event, who provide information and sometimes even simply process requests at the event.  There is also HIV testing, free hair cuts provided by Supercuts, a meal by Stone Soup and some donated items for those who attend the even can take with them.  This event is a great opportunity for those in need to get many of the services they need taken care of all in one afternoon.  

So yes, I assisted at this this event on Friday, and then after a successful Friday I went and sprained my left ankle at a soccer game early in the afternoon on Saturday.  Luckily Robey and I were to go visit his family over the weekend, so I was able to stay off my feet all weekend and let my ankle partially recover.  

Then I went to a Timbers game on Monday.  The Timbers are the local MLS soccer team in Portland, OR.  It was a very rainy and cold evening for sitting in a stadium, but the game was worth it and tons of fun.  I also had good company, a friend had invited me along earlier last week, and it made for a very wonderful end to an odd weekend.

I’ve been busy, but I’m now back to posting, and am available and everything else.    

I'm a ninja in my dreams

March 08, 2012

It was requested that I describe my dream from this morning, for my blog entry today.  It’s just as well, because I’ll be busy over the next two days and won’t have time to post anything.  I’m helping with the local Homeless Connect Event.  I made muffins this morning, and will be picking up some coffee and oranges for it later this evening.  Then tomorrow I volunteer.

Anyways, back to my dream.  This morning I had to wake up earlier than usual to go make muffins for the Homeless Connect Event tomorrow.  Suffice it to say I don’t normally wake up early, so I hit my snooze button a couple of times.  But before I originally hit my snooze button, I dreamt I was a ninja.

Not a ninja in the ‘wear black and hide in shadows’ thing, which some might argue is the whole point.  I was more a ninja in the I’m jumping on and off rooftops, bounding across a city and attacking with killer Kung Fu moves.  I was one of the ‘chosen ones’.  However it’s important to note that I wasn’t the ‘actual chosen one’ that was expected to fulfill some famous prophecy.  That person was still a child, around 4 or 5, and had to grow up yet before they could complete their destiny.  In the meantime I was supposed to stick around, distract all the bad guys from the real chosen one so he could grow up.  
Unfortunately the last time I went to visit the chosen one I stayed too long, because I cared for him so much.  As I felt the time press upon me, I left in a hurry to distract any bad guys trying to home in on me to find the ‘actual chosen one’.  What I didn’t realize until after I’d gone back to sleep after several snooze button hits, was that I’d lingered too long.  I had led the bad guys straight to this young child, whose keepers couldn’t fully protect him.  

Thus at one point when I’m fighting bad guys in town with awesome kicks and slashes (no blood though, it’s a rather PG dream), this little kid comes up to me.  I don’t recognize him at first, but then I realize it’s the chosen one out in the middle of nowhere I grab him up quickly.  Only after a few moments of checking on him do I realize he’s recently been turned into a vampire.  Gasping in horror at what’s happened it comes to me that the chosen one can no longer fulfill the prophecy.  As I’m the only chosen one left, I realize that I must complete it, no matter what it takes.  As the child is lost due to becoming a vampire,  I  leave him there after slightly bashing his head so he will die and not hurt anyone.  The last part of my dream I remember is running off, still running away from bad guys and having no idea where to start with saving the world.   

Clicking and file creation

March 06, 2012

The last part of the .ready() function is defining what happens when the buttons from the popupcalendar div are clicked on.  As shown below each button is placed in a different div.  Once the button is clicked on, the .click() function runs.  For the #csv, #ics2 and #ics divs, they then construct a data URI that holds the csv or ics file.  This is done by the downloadDataURI() function.  Inside of this the file names are designated, first by team name and second by making it either a .csv or .ics file.  Then the next part is telling the browser to download that data and give it that file name.  I won’t be going into more depth on the downloadDataURI  function at this time, as I don’t understand it fully myself.  Robey helped me a fair portion with that.  

$j(document).ready(function(){

...

   $j('#csv').click(function(){

     downloadDataURI({

       filename: schedule[0].teamname + ".csv",

       data: 'data:text/calendar;base64,' + btoa(csv)

     });

   });

   $j('#ics2').click(function(){

     downloadDataURI({

       filename: schedule[0].teamname + ".ics",

       data: 'data:text/calendar;base64,' + btoa(csv)

     });

   });      

   $j('#ics').click(function(){

     downloadDataURI({

       filename: schedule[0].teamname + ".ics",

       data: 'data:text/calendar;base64,' + btoa(ics)

     });

   });

   $j('#close').click(function(){

     $j('#popupcalendar').css({'display':'none'});

     return false;

   });

 }        

 });

});


The last .click() function is the small ‘X’ in the lower right corner.  It uses jQuery to change the css of the popupcalendar from display ‘block’ to display ‘none’.  This will close the window and make it no longer display.    Now that the functions running the processes, and the needed interactive aspect are complete, the last part is to input this into the extension framework.

Up Next Time: Creating an extension within Chrome, the final steps

 

Displaying the inserted html after a button click

March 05, 2012

Continuing on from yesterday.  Once the ‘Download Calendar’ button is clicked on, the following image pops up on the screen.

<insert image of popupcalendar>

I use the .insertAdjacentHTML() function in order to insert this image.  As you can see in the code below, I indicate the div where I am inserting the html (#downloadcalendar), and then inside of the .insertAdjacentHTML() function I input the html and css aspects of the image shown above.  All of that is shown in the documentation below.  I’m not going to go into details about the css and html, but if you have any questions let me know.

$j(document).ready(function(){

...else{

  $j('#downloadcalendar')[0].insertAdjacentHTML('beforeend',

    "<div id='popupcalendar' style='position: fixed; display: block; color: white; font-size: 135% ;background-color: #000040; width: 88%; height: 30%; top: 10%; left: 5%; border: 3px solid #1c328c; z-index: 2000; padding: 10px;'>\

    <p>Once you have selected your calendar type below, you will be provided a file to import into your calendar.  Depending on your calendar type, you will be downloading either a csv(Microsoft Outlook, Gmail) or an ics(iCalendar) file.</p>\

    <p>For help on how to import this file, please see the following documentation for <a href='http://docs.info.apple.com/article.html?path=iCal/3.0/en/9870.html' style='color:#ff7004;'>iCalendar</a>, <a href='http://support.microsoft.com/kb/290859' style='color:#ff7004;'>Microsoft Outlook</a>, and <a href='http://support.google.com/mail/bin/answer.py?hl=en&answer=14024' style='color:#ff7004;'>Gmail</a>.</p>\

    <button id='ics' style='width: 150px; background-color: #1c328c; font-size: 110%; color: white;'>iCalendar</button>\

    <button id='csv' style='width: 190px; background-color: #1c328c; font-size: 110%; color: white;'>Microsoft Outlook</button>\

    <button id='ics2' style='width: 150px; background-color: #1c328c; font-size: 110%; color: white;'>Gmail</button>\

    <p style='margin-left: 1.75ex;'>Brought to you by <a href='http://www.flaminglunchbox.net/' style='color:#ff7004;'>FlamingLunchbox<img src='chrome-extension://"+chrome.i18n.getMessage("@@extension_id")+"/final32.png' style='margin-left: .5ex; margin-bottom: -7px;'></img></a></p>\

    <div id='close' style='float:right; margin-right: .5ex; margin-top: -.5ex; font-size: 125%;'>x</div>\

    </div>");...

});

});


Up Next Time: Clicking and file creation

 

Using jQuery to create an interface for my extension

March 01, 2012

The first multiple pieces of setting up my Schedule Converter was creating functions that would process the information on the screen and convert them into csv and ics formats for calendar upload.  Now it’s time to create the part of my file that actually interacts with the webpage, and allows you to access the other functions I’ve made.  To do this I’ve used a variety of jQuery functions.  

$j(document).ready(function(){

 $j('.boxLight div:last-child')[1].insertAdjacentHTML('beforeend', "<button id='downloadcalendar' style='width: 140px'>Download Calendar</button> <br>");

 $j('#downloadcalendar').click(function(){

     if ($j('#popupcalendar').length > 0){

       $j('#popupcalendar').css({'display':'block'});        

     }else...

});

});


To begin with I use .ready() which calls a specific function once the page has fully loaded.  I fill .ready() with a function that does some HTML adjustments and buttons that call the createcsv() and createics() functions explained previously.  When I started creating this part of the extension, I decided I wanted the initial adjustments to the screen to flow with the page layout already.  Therefore I simply added in another button with the same style as the others, and I put it with the other related buttons in the Team Tools box.

<insert pic from file ‘before’>

This was fairly simply to do using something from HTML5.  By using .insertAdjacentHTML() I was able to indicate where I wanted the new bit of HTML to go, what I wanted it to look like, and any text that was to be entered.  Thus the button that didn’t exist in the above mentioned photo, once the extension is loaded into your browser, will insert this button shown below:

<insert pic from file ‘after’>

Once the button is displayed, the user can click on it.  Once a click occurs, the .click() function runs.  This will begin with using the .length property which determines if the current length of the jQuery array is more than zero.  This is done to prevent the code from continuously recreating the popupcalendar.  Basically if popupcalendar has already been created, the length will be more than zero and at this time it will simply adjust the css to show the element again by making the display equal to block.  Otherwise it will create the element for the first time.    

Up Next Time: Displaying the inserted HTML after a button click

 

Completing my ics file function

February 29, 2012

Today I’ve returned to my explanation of the CSP Schedule Converter extension.  At the very end of the function the rest of the parts are identified and the information is concatenated into the end resulting ics file.  

function createics (schedule) { ….

   var begin = "BEGIN:VEVENT";

   var end = "END:VEVENT";

   var summary = "SUMMARY:" + schedule[i].teamname + " " + schedule[i].tshirtcolor;

   var description = "DESCRIPTION:" + "Game #" + schedule[i].game + " vs " + schedule[i].competitor;

   var pprivate = "CLASS:PRIVATE";

   var icsevent = begin + "\n" + summary + "\n" + description + "\n" + dtstamp + "\n" + dtstart + "\n" + dtend +   "\n" + pprivate + "\n" + end + "\n";

   finalics += icsevent;  

 }

finalics += "END:VCALENDAR";

return finalics

};


As mentioned previously, ics and csv files need to be formatted a particular way in order to be imported correctly as calendar files.  To start an ics file event entry you input this text: BEGIN:VEVENT.  Subsequently END:VEVENT identifies the end of an event entry in an ics file.  I’ve created these for each entry, and labeled them as begin and end variables.  Then I create a variable called summary which includes the team name and whether or not you’re home or away for that game.  The description variable includes the game number of the season, game and the competitor.  

As with the csv file, use pprivate to identify that the event is classified as private unless the particular user wishes to adjust it otherwise.  Then to complete it I concatenate it all together into a singular icsevent variable.  As I go through each event on the page an ics version is created and added to the finalics list.  To complete the entire ics file, the string “END:VCALENDAR” is added.  The variable finalics is then returned from the function createics().

Up Next Time: Using jQuery to create an interface for my extension

 

Self-prescribed stress prevention methods

February 28, 2012

Went running in the sun.  I started feeling a panic attack coming on right before we left to go jogging, and I’m still feeling the edges of one.  However it feels like I can control it today.  For a while (since the beginning of the year) I’ve been attempting to control my general stress levels by running more often, taking vitamin D3 and drinking more tea and water.  

I’ve been taking from 2000 to 4000 I.U.’s of vitamin D3 daily.  Normally I only take 2000, but lately I’ve been taking 4000 on days when I feel like I could lose control.  I’ve also been drinking around 2 cups of this tea that is high in phytoestrogen called Mother’s Milk from Traditional Medicinals.  It’s normally used for increased lactation, but many of the herbal ingredients are also phytoestrogens.  Phytoestrogens basically increase the level of estrogen for some areas of your body, but in all honesty not much is known.  It may be purely mental, but the vitamins, running and tea seems to be helping.  

For the two weeks prior to today, Robey and I hadn’t been running at all.  I wasn’t as consistent in taking vitamin D and at one point we had run out of the tea I had been drinking.  Attempting to get back on to the regimen has been slow going as it’s been accompanied with recovering from this more intense bout of depression.  

Before I started doing these things Robey and I had been arguing a fair amount about the stupidest stuff.  Life was much more stressful from October through December.  That was also when I started doing translation work, so I’m certain that’s part of why things calmed down for a bit between January and early February.  This is not to say that this is the effective solution to my current stress and depression issues.  It seems to be working, but only more time will tell.

Up Next Time: Completing my ics file function

Finding a focal point

February 27, 2012

It’s been a rough couple of weeks now, but today that’s going to change.  First off I started my morning by turning the techno up and grabbing a full cup of coffee w/Poptart.  I signed up for The Dirty Dash in Eugene, of which I’m super excited about.  It’s part of what I need to get myself back on track.

When I was a senior in college I was going through a very rough patch.  My last fall term I didn’t show up to any of my classes during dead week.  I was severely depressed.  Much of it was related to, once again, family related stress (It’s an ongoing theme in my life).  To help get myself out of the slump I signed up for the 4-mile race of the Eugene Truffle Shuffle.  This would be the first time I had ever been a part of a running event, let alone trained to run 4 miles.  Signing up and the subsequent training for it, those two things helped significantly in extracting myself from my depression.

The Dirty Dash allows me a focal point.  The race itself is so varied I can train in a variety of ways.  After my very enjoyable trampoline fun on this past Saturday, I can make sure to include such experiences more in the future.  They’ll all help me with an obstacle course.  I can start rock climbing again, continue strength training exercises at home, and running/soccer/hiking/cycling on a regular basis.  Even working in my garden will help somewhat.

The best part?  I’m doing this for myself and because it sounds like waaaay to much fun.  Not to mention that proceeds go to charity and whatnot.      

Up Next Time: Self-prescribed stress prevention methods

5 movies and three beers later...

February 25, 2012

It’s been a long week, hell it’s been a long month.  Things started to turn around today.  I completed some translation work I’ve been working on for over a month and a half now.  Submitting that was happy times.  I also worked a heck of a lot today.  

I’m starting to feel like I can accomplish things again.  Lots of things to work out, but I’m going to go jump on trampolines tomorrow for a bit and get out of town.  That should straighten my head out again.  

Links