It's been a very long time since I've posted, but that's because a lot has been happening.
First the disappointments: that math midterm a few weeks ago went absolutely horribly, I have a nerve contusion that is keeping me from throwing a baseball, and I was not chosen to be an RA next year. I'm particularly upset about the RA situation because that was something I was really looking forward to doing, but I guess now I'll just have a lot more free time than I had planned on next year. Also, I will still help out with Orientation regardless, so I'll still feel helpful.
The successes outweigh the failures. Well the one success: I will be an intern with Major League Baseball's Commissioner's Office this summer. It happened right when I thought I wouldn't be able to find a job for the summer, so that was both exciting and relieving. I already have housing reserved in New York, and I cannot wait for summer to start. I also had my first non-phone interview (well, if you don't count video chatting as a phone) and they had me solve a Rubik's cube at the beginning. Apparently quite a few people watched, making this the first time I've ever solved a cube for someone over video. The solve was pretty bad (I thought they were joking when they mentioned it before so I wasn't really prepared). Actually, it was acceptable until I got a Ua PLL. That 1.5 second algorithm took closer to 10, and I've been practicing it at every opportunity since then. Next time someone asks, I'll be prepared!
As for the post title, I recently jailbroke (jailbreaked?) my iPod, and it was the best thing I've done with it since I bought it. Apple really does a great job with it's products, and it's always the little things that impress: uniform icon sizes, a responsive UI, the very nice notification center, etc. But there are things that I would like to have. For example, I don't want to be restricted to Apple's folder size limit, or be forced to deal with 12-15 default apps that I never use. So I fixed that, and I love it. It's still the same amazing core features, but it's the little things that make it so much better now. I love how the Calendar app displays the current date, and with a jailbroken device you can do the same with the weather (and clock, but I don't use that). I can remove app names and don't have to follow Apple's forced grid placement. And I can hide those pesky system apps.
It's been a long few weeks, but it's only 5 more till the end of the quarter.
Saturday, May 4, 2013
Sunday, March 31, 2013
Post Spring Break
So winter quarter ended and spring break is coming to a close, so I thought I could contribute a little to the blog. The quarter was very stressful (hence the lack of posts), but I made it through. Funnily enough it was my best academic quarter ever, though that may be more of a result of the amount of work I had to put in to stay alive in my classes. I also got my first A ever in a course! I definitely deserved 3, but I'll take whatever they give me.
Both quarters this year I've had to bite the bullet on one of either computer science or real analysis. Full effort in both classes takes between 15 and 20 hours per week, which is far too much. Last quarter I poured my effort into analysis, this quarter into computer science (though I would have preferred the analysis grade). I guess that's just how the world works. Biology was a cakewalk - I studied for the quizzes the class before. And SOSC is a paper-writing class, which means that I will get a good grade but not a great one. Easily the most stressful quarter I've had so far, but maybe my most productive.
But after all that hell, I got to go to Florida! It was a great trip for me, though the team didn't do as well as we could have. I still have a shiny 0.00 ERA, but I've only thrown 4 innings. Still, I got tan and was able to spend a full week away from school. I even have a decent tan (on my face). Still, it was a great time with the guys and I'm looking forward to spring quarter.
Both quarters this year I've had to bite the bullet on one of either computer science or real analysis. Full effort in both classes takes between 15 and 20 hours per week, which is far too much. Last quarter I poured my effort into analysis, this quarter into computer science (though I would have preferred the analysis grade). I guess that's just how the world works. Biology was a cakewalk - I studied for the quizzes the class before. And SOSC is a paper-writing class, which means that I will get a good grade but not a great one. Easily the most stressful quarter I've had so far, but maybe my most productive.
But after all that hell, I got to go to Florida! It was a great trip for me, though the team didn't do as well as we could have. I still have a shiny 0.00 ERA, but I've only thrown 4 innings. Still, I got tan and was able to spend a full week away from school. I even have a decent tan (on my face). Still, it was a great time with the guys and I'm looking forward to spring quarter.
Friday, February 22, 2013
Found out How to Put Code in Blog Posts!
It's an exciting day! Yesterday I figured out how to put code into my blog posts. It's sort of sad that I get excited by something like that, but, hey, I like it! I updated the only post I had with code in it, and I think it's beautiful.
In separate but related news, I finally got myself a github account. Nothing is on there yet, but I have big things in mind for it in the future. Not that big, mind you, but big. My current hope is to sync up my Dropbox and github repositories. What else am I going to do with 11GB of Dropbox storage? Not much else going on in my life, but woo code!
In separate but related news, I finally got myself a github account. Nothing is on there yet, but I have big things in mind for it in the future. Not that big, mind you, but big. My current hope is to sync up my Dropbox and github repositories. What else am I going to do with 11GB of Dropbox storage? Not much else going on in my life, but woo code!
Sunday, February 17, 2013
The C Programming Language
I suppose it was inevitable, but my path into the world of programming has led to to C. C might be the most famous of all programming languages. I can't actually tell you why that is the case, but in my experience it has been true. Just as well known as Java (by known I mean people recognize the name) and C++, and far ahead of languages like Python or Ruby or ML, C predates them all.
There's a reason C survived all these new languages, but I have yet to find it. As my computer science professor explained, C is like learning to drive a stick-shift car. It's very difficult to learn and people will laugh at you for not using an automatic, but it allows you to do much more with your knowledge and makes you appreciate the car more. The problem with that analogy, for me at least: I learned to drive on a stick shift, and it didn't take me nearly as much time to learn that as it has for me to learn C.
After learning to Program with a very "clean" (my own quotes) language in Haskell, and then a very English-friendly language in Python, learning C has been an adventure. I imagine myself as an explorer in the heart of Africa, paving new paths and meeting new people, always confused and amazed by their customs and constantly pondering how they are able to survive with such "primitive" methods. Just as those people were probably racist, I feel I am language-ist for thinking such thoughts. But I cannot see the need for the jungle of semicolons and curly brackets. My progressive programming languages had no need for such strange and unneeded grammar. But C does.
Harnessing C is difficult, and I am nowhere near where I should be. I spent a good 5 hours today trying to make my program read a file in 1 MB chunks instead of the whole thing at once. But it now works, and I think I'm a better programmer as a result. If learning Python was easy mode and Haskell hard mode, C would be god mode.
The thing I've found with C is that I improve much faster than I have with any other language. I wonder if that's because of the pace of the class (absurdly fast) or because the language just works like that. C is a stressful and complicated language, and I think working for 10-12 hours on "simple" programs trains your brain to deal with it better and faster next time. Somehow, being forced to solve a problem in C is training me to solve problems better and faster than any other language I have experience with. Also C programs run fast. If Haskell and Python were planes, C would be the Starship Enterprise. Not only are the file sizes smaller, but they just run faster. Significantly faster. And I can definitely appreciate that.
Lastly, I need to rant here for a bit. The big problem with teaching C in the modern day is Google. Google is the place to go for programming help. Need to know how to parse something in Haskell. Quick google search gets you the function you need. Need to know how to work with URLs in Python? Google that shit. Need to know how to do anything in C? Nope. Because of languages like C++ and C#, searching for any C code on the internet is a giant pain in the butt. Everybody tries to give you C++ code, and while the languages are similar they are different enough that the code will not work. Conversations I've had with some people all seem to lead to the same conclusion: C is used by programmers who do not need help from the internet, so they don't put anything on the internet. It may be true that C is at a level beyond that of the average programmer (if such a being exists), but I'd really appreciate it if Google could give me some answers every now and then (yes, I know about Stack Overflow).
There's a reason C survived all these new languages, but I have yet to find it. As my computer science professor explained, C is like learning to drive a stick-shift car. It's very difficult to learn and people will laugh at you for not using an automatic, but it allows you to do much more with your knowledge and makes you appreciate the car more. The problem with that analogy, for me at least: I learned to drive on a stick shift, and it didn't take me nearly as much time to learn that as it has for me to learn C.
After learning to Program with a very "clean" (my own quotes) language in Haskell, and then a very English-friendly language in Python, learning C has been an adventure. I imagine myself as an explorer in the heart of Africa, paving new paths and meeting new people, always confused and amazed by their customs and constantly pondering how they are able to survive with such "primitive" methods. Just as those people were probably racist, I feel I am language-ist for thinking such thoughts. But I cannot see the need for the jungle of semicolons and curly brackets. My progressive programming languages had no need for such strange and unneeded grammar. But C does.
Harnessing C is difficult, and I am nowhere near where I should be. I spent a good 5 hours today trying to make my program read a file in 1 MB chunks instead of the whole thing at once. But it now works, and I think I'm a better programmer as a result. If learning Python was easy mode and Haskell hard mode, C would be god mode.
The thing I've found with C is that I improve much faster than I have with any other language. I wonder if that's because of the pace of the class (absurdly fast) or because the language just works like that. C is a stressful and complicated language, and I think working for 10-12 hours on "simple" programs trains your brain to deal with it better and faster next time. Somehow, being forced to solve a problem in C is training me to solve problems better and faster than any other language I have experience with. Also C programs run fast. If Haskell and Python were planes, C would be the Starship Enterprise. Not only are the file sizes smaller, but they just run faster. Significantly faster. And I can definitely appreciate that.
Lastly, I need to rant here for a bit. The big problem with teaching C in the modern day is Google. Google is the place to go for programming help. Need to know how to parse something in Haskell. Quick google search gets you the function you need. Need to know how to work with URLs in Python? Google that shit. Need to know how to do anything in C? Nope. Because of languages like C++ and C#, searching for any C code on the internet is a giant pain in the butt. Everybody tries to give you C++ code, and while the languages are similar they are different enough that the code will not work. Conversations I've had with some people all seem to lead to the same conclusion: C is used by programmers who do not need help from the internet, so they don't put anything on the internet. It may be true that C is at a level beyond that of the average programmer (if such a being exists), but I'd really appreciate it if Google could give me some answers every now and then (yes, I know about Stack Overflow).
Wednesday, February 6, 2013
Obligatory Birthday Post
I should be writing a paper. And getting my computer science lab done. But why do that when I can blog?
Today is my 20th birthday, and that means very little to me. I prefer to celebrate every 1000 days rather than every 365.25. But society tells me that I should celebrate, so I did. I did some homework last night, I'll do some homework tonight, and I'll go to baseball practice and run some. Tomorrow I'll finish my paper and go to an info session on becoming an RA. If that's not celebrating, I don't know what is!
Actually, though, I'm celebrating by having some leftover soda from the Super Bowl party. I haven't had soda this whole quarter, so it is something of a big deal. Also related to food: I have eaten 3 full meals a day on almost 90% of days in school this year. Again, might not seem like a big thing, but that's something I've tried hard to improve on from last year.
I know I haven't addressed my workout schedule at all since, well, a long time ago. Now that baseball has started up I only give myself the option of working out on Thursdays (no practice) or Saturdays (might as well be no practice sometimes). My arm seems to be in pretty good shape but my ankle and legs still aren't 100% yet, which is very disappointing. Still, it's a big improvement from last year and I should be ready to go by the time games start up.
Till next time.
Today is my 20th birthday, and that means very little to me. I prefer to celebrate every 1000 days rather than every 365.25. But society tells me that I should celebrate, so I did. I did some homework last night, I'll do some homework tonight, and I'll go to baseball practice and run some. Tomorrow I'll finish my paper and go to an info session on becoming an RA. If that's not celebrating, I don't know what is!
Actually, though, I'm celebrating by having some leftover soda from the Super Bowl party. I haven't had soda this whole quarter, so it is something of a big deal. Also related to food: I have eaten 3 full meals a day on almost 90% of days in school this year. Again, might not seem like a big thing, but that's something I've tried hard to improve on from last year.
I know I haven't addressed my workout schedule at all since, well, a long time ago. Now that baseball has started up I only give myself the option of working out on Thursdays (no practice) or Saturdays (might as well be no practice sometimes). My arm seems to be in pretty good shape but my ankle and legs still aren't 100% yet, which is very disappointing. Still, it's a big improvement from last year and I should be ready to go by the time games start up.
Till next time.
Friday, January 25, 2013
Not Feeling So Great About Myself
Unfortunately, I have to make an unhappy post. It's almost the reason I made this blog: so I could be the one student that didn't cry to the internet every time something went wrong. But I guess I just didn't have it. I'm technically still a teenager, so I guess I'm just going through the final throes of my teenage angst. Something like that. Regardless, I a sad panda right now.
The worst part is I don't know why. Baseball started on Wednesday, and though I'm sore all over, I'm very happy to be back with the guys and doing things. Classes are going fine, though this internship thing is sort of stressing me out. I really don't want to go back home for the summer (though I can't even explain that) and all this down time is freaking me out. I was told in late December that I would be asked in January to schedule a phone interview (by two places I applied). Well, January is almost over but I haven't heard back from either one.
I don't know if I should contact them (my dad says they're busy and will get around to me), but I feel my Haskell comprehension slipping through my fingers as I spend less and less time programming for fun and more time programming for class. Honestly, who uses awk nowadays (don't answer - I know its still around)? I need the Haskell knowledge because one of the positions involves programming in OCaml, which is very similar to Haskell from what I've seen of it. Also I think its a shame I don't know how to use regex in Haskell, but that's mostly a product of my obsession with HTML scraping.
Next week is hell week for me: SOSC paper, analysis midterm, biology quiz, and a crazy lab of CS. I took the full brunt (as my House's vice president I have to take it) of some yelling during my neighbor house's House Meeting yesterday, which is unfortunate because most of them are my friends. I'm very unsure about my future because everywhere I turn someone is doing something better. Basically I'm unhappy right now with my life, and I doubt I'll be feeling better anytime soon.
The worst part is I don't know why. Baseball started on Wednesday, and though I'm sore all over, I'm very happy to be back with the guys and doing things. Classes are going fine, though this internship thing is sort of stressing me out. I really don't want to go back home for the summer (though I can't even explain that) and all this down time is freaking me out. I was told in late December that I would be asked in January to schedule a phone interview (by two places I applied). Well, January is almost over but I haven't heard back from either one.
I don't know if I should contact them (my dad says they're busy and will get around to me), but I feel my Haskell comprehension slipping through my fingers as I spend less and less time programming for fun and more time programming for class. Honestly, who uses awk nowadays (don't answer - I know its still around)? I need the Haskell knowledge because one of the positions involves programming in OCaml, which is very similar to Haskell from what I've seen of it. Also I think its a shame I don't know how to use regex in Haskell, but that's mostly a product of my obsession with HTML scraping.
Next week is hell week for me: SOSC paper, analysis midterm, biology quiz, and a crazy lab of CS. I took the full brunt (as my House's vice president I have to take it) of some yelling during my neighbor house's House Meeting yesterday, which is unfortunate because most of them are my friends. I'm very unsure about my future because everywhere I turn someone is doing something better. Basically I'm unhappy right now with my life, and I doubt I'll be feeling better anytime soon.
Friday, January 18, 2013
First Two Weeks
I just realized I haven't posted in a while. Not that anything really exciting has happened. Classes started up and are taking up time like only classes can. Most of my time recently has been spent on fantasy baseball, though. Below is the code I use to get information on every active major league player. Once baseball practice starts up I might have more to say here.
#!/usr/bin/python
# Simon Swanson
# baseball-reference.Extraction.py
import sys
import re
import urllib2
from string import lowercase
from bs4 import BeautifulSoup
# takes in a letter of the alphabet and passes that to a URL containing all baseball players whose last names starts with the given letter
def url_info(char):
'''Opens the correct URLs then delegates work to other functions to get player information.'''
req = urllib2.urlopen('http://www.baseball-reference.com/players/%s' % char)
f = req.read()
req.close()
info_name = {}
soup = BeautifulSoup(f, 'lxml')
# lines with boldface are famous and/or active players
boldface = soup.find_all('b')
for line in boldface:
if line.find(text=re.compile(r'\s+\d+-201[12]')):
link = line.a['href']
if link:
req = urllib2.urlopen('http://www.baseball-reference.com%s' % link)
f = req.read()
req.close()
soup = BeautifulSoup(f, 'lxml')
player = player_info(soup)
player_name = player[0]
# if the name already exists, add an underscore to the end of the name
if player_name in info_name.keys():
player_name = player_name + '_'
info_name[player_name] = (player[1], player[2], player[3])
print player_name
return info_name
def player_info(html):
'''Gets the players name, age, postition eligibility, and statistics. Returns a tuple.'''
# default values in case something goes wrong
player_name = 'Unknown'
age = None
positions = []
stats = []
info_name = {}
# gets fielding information only from 2012 to determine position eligibility (10+ games at the position previous year)
fielding = html.find_all(onclick='sumSpan(this);', id='2012:standard_fielding')
for lines in fielding:
games = lines.find_all('td', align='right')
line = lines.find_all('td', align='left')
# age can also be found in this fielding section. problematic if player didn't play in 2012, so I have a more complicated check below
age = int(games[0].string)
if int(games[1].string) >= 10:
positions.append(str(line[3].string))
# for cases where the player didn't play the field and/or doesn't have a position from 2012, I refer to baseball-reference.com's position (which is wrong in several cases, but at least gives me something to work with)
if not positions:
get_line = re.search(r'Positions?:([\w, ]+)\n', str(html))
positions = position_info(get_line.group(1))
# from the position I can find the appropriate stats (because there are no pitcher/fielders in the game today except in 20-0 blowouts)
if positions[0] == 'P':
stats = pitcher_info(html)
else:
stats = batter_info(html)
# player's name is in the first h1 tag
player_name = html.h1.string
# verifies that the player has an age
if not age:
tag = html.find('span', id='necro-birth')
dob = tag['data-birth']
age = 2013 - int(dob[:4])
return (player_name, age, positions, stats)
# simple extraction of batting stats (24 per year), puts into list
def batter_info(html):
'''Gets all batter stats.'''
batting_stats = []
hitting = html.find_all('tr', class_='full', id=re.compile(r'batting_standard\.\d+'))
if not hitting:
batting_stats = pitching_stats(html)
# excludes first element of the list because it's the player's age for each year (which I have more efficienty ways of getting)
for lines in hitting:
stats = lines.find_all('td', align='right')[1:]
for stat in stats:
stat = stat.string
# sometimes there isn't a stat for something, and baseball-reference just leaves it blank
if not stat:
stat = 0
batting_stats.append(float(stat))
return batting_stats
# simple extraction of pitching stats (29 per year). Pitchers are more likely to succumb to the None value in their stats (more ratios) and can even have inf ratio values
def pitcher_info(html):
'''Gets all statistics for pitchers.'''
pitching_stats = []
pitching = html.find_all('tr', class_='full', id=re.compile(r'pitching_standard\.\d+'))
if not pitching:
return ['0']
for lines in pitching:
stats = lines.find_all('td', align='right')[1:]
for stat in stats:
stat = stat.string
if not stat:
stat = 0
# it is possible to have a pitcher stat be divided by 0 in some extreme cases. 1000 seems like a punishable enough number to work with
if stat == 'inf':
stat = 1000
pitching_stats.append(float(stat))
return pitching_stats
# figures out what's in the baseball-reference.com position list
def position_info(pos):
'''If the position was not available before, matches with positions listed at the top of the page.'''
positions = []
position_dict = {'Pitcher': 'P', 'Catcher': 'C', 'First Baseman': '1B', 'Second Baseman': '2B', 'Third Baseman': '3B', 'Shortstop': 'SS', 'Outfielder': 'OF', 'Leftfielder': 'LF', 'Centerfielder': 'CF', 'Rightfielder': 'RF', 'Designated Hitter': 'DH'}
# loops through the dict to try and match the key with the string of positions
for key in position_dict:
if key in pos:
positions.append(position_dict[key])
# some people just don't have a real position (pinch runner, etc.) and get the unknown label
if not positions:
return ['Unknown']
return positions
# passes each letter of the alphabet to url_info
def main():
'''Gets the information from every active major league baseball player, returned as a dictionary to a file.'''
args = lowercase
output = open('/Users/Swanson/Programs/Python/All_Player_Information.txt', 'w')
info = []
s = ''
# adds all the separate dictionaries to a list as strings for further use
for arg in args:
info.append(str(url_info(arg)))
print 'Finished with letter %s!\n' % arg
# makes it all one big string to operate on
for players in info:
s += players
# replaces all the dictionary separators to make one large dictionary
s = s.replace('}{}{', ', ').replace('}{', ', ')
output.write(s)
output.close()
if __name__ == '__main__':
main()
Subscribe to:
Posts (Atom)