Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

24 October 2014

Hackbright Day 19: Magical SQL Python Gnomes (but not GNOME as in RIP GNOME 2)

Today we talked about SQLAlchemy, which is a SQL handler for Python. It's called SQLAlchemy because it's basically magical if you don't know how SQL works and it's still pretty spectacular if you do. It basically takes ugly SQL calls and turns them into things that look way more like python syntax. SQLAlchemy is called an object-relational mapping (or ORM as people call it) program. In SQL, we have databases that contain tables. These tables have columns that contain different kinds of information for a given record (or row). What SQLAlchemy does, is translate the python we input so that SQL can handle it. It does this by essentially mapping a table to a class, a column to an attribute of a class, and a record (or row) to an instance of the class. It's really nice, the syntax is mostly familiar (although the OR and AND statements are a bit weird), but it seems pretty useful. The other cool thing about SQLAlchemy is that you can use whatever SQL "engine" that you want. We're using SQLite with it, but I'll probably look into things like PostgreSQL for my project.

Speaking of projects, we talked about project selection today. As of a week ago, I had a project that I was dead set on, but then I started working on other things on the side and found out that i was way more interested in that than the one I was originally going to work on. I'm still not sure what I'm going to do, but I'm looking into the new, exciting project right now because I think it will be a better way for me to display skills in areas that I'm interested in, rather than work on a project that I think should exist, but isn't the type of coding that I'm interested in (oh my god. back end. god help me if I have to do a ton of front end coding in my career).

We talked a bit about other projects that people have done during the 5 weeks leading up to career day, and one thing that came up was called Flattest Route, which works with the Google Maps API to determine which is the least hill-climby route you can take to get from point A to point B. As an example, here's my walk from the bus stop to the house we're staying in. The route is color coded to indicate the steepness. Green is easy, yellow is moderate, blue is difficult, red is very difficult, and black is basically mountain climbing.

Sometimes I wonder if i should get crampons to walk up this hill.

The other super awesome thing that happened was that I got to meet up with a friend from high school at lunch. We're going to be on a hackathon team this weekend to try to best display asteroid data for fun and not profit. Hopefully we'll be able to hack something together that looks awesome and is super informative.

Not these gnomes either

21 October 2014

Hackbright Day 16: Sessions + More Flask

When I transferred high schools way back in 2001, I joined all the extra curricular activities that I could in order to meet people and make friends. Some of them turned out to be life-changing (Hi, Ms. Maciolek!) and some of them turned out to be a huge waste of time (that would be you, softball). One of the things that sort of fell in between those extremes was the literary journal *thing* that I did one year. One of the first orders of business was to pick a name for it. My suggestion was "Sessions". They ended up going with "Harbinger". Speaking to the incredible content of my character, I basically lost interest once my name wasn't chosen.

Fast forward 13 years, and now I finally get to talk about sessions.

Sessions, in this context, are about storing information on the server side of a web app. In Flask, the session is a dictionary that you fill with information like, for instance, the user name. For websites where you might buy something, everything you'd add to a shopping cart would be in the session dictionary.

Our assignment today was to make a webapp. The skeleton for the app was already in place, but we needed to add things to it to make it functional. We ended up using Flask, the python framework for web apps, SQL, html + css, and jinja (which is a way to inject a little bit of python into the html). It was a lot of fun, actually, and we were able to make a functional app with a log in page and an account page.

I had a meeting with my advisor today and at his suggestion, I'm going to try to work on a project on my own to create an app, mostly to practice all these new skills that we've been talking about in class.

apt-get install ROBOJULIACHILD 
So my intent is to create a recipe-generating bot that is based on a few different recipe "structures" and will then randomly select things that would go with it. I've sort of sketched out an idea of how to implement it. The working name is cook roulette, but robojuliachild is my favorite. My biggest thought is to make the recipe structure a class and then have the different kinds of recipes (e.g., quiche, risotto, etc.). This works because I'm probably not going to make anything that's too fancy, but doing this with classes makes it modular so I could come back to this easily. What's also nice about this is that I can get more experience with classes without having to go back to that horrible game exercise. (I should definitely probably revisit that at some point.) I'm thinking that it would be interesting to add baking recipes to this because you could calculate the required ingredient amounts based on the ph of different ingredients.

We also talked about how the internet works and now I think I want to run my own server to deploy my own apps. And then I brought up cookie clicker because I'm totally a winner like that.


20 October 2014

Hackbright Day 15: Pro Set. That's way super fun.

Friday was uneventful and eventful. We reviewed all 17,000 new languages we learned this week. It was also install day, where everyone was told what to install to run everything we do in lab on their laptops. I figured out that I somehow totally fucked up my install of Chrubuntu and damaged the Chrome OS in the process. It's not a huge deal because my plan is to actually just reinstall Chrome OS and un-partition the teeny-tiny hard drive. Apparently there's something called Crouton that will let you run Ubuntu on top of the Chrome OS. I've come to the conclusion that getting that Chromebook was a mistake. Not a huge one, but typing on it makes my right hand hurt and it's hard to look at. 

We also got to see working examples of javascript webapps. One of the TAs has made some games, the best of which is called Pro Set. Similar to set in that i t's a concentration/matching game, it's also a lot more difficult, hence the "Pro" part.

Since I was basically set with install day (and also because I'm pretty sure that my install is the easiest what with apt-get install life), I was pretty much by myself in lab. I talked with one of the TAs for a really long time about Hackbright and life in general. It was good. I don't have a Hackbright alum mentor, so this was a nice way to absorb information and good vibes from someone who graduated the program and found success.

Friday night was also board game night. Colby came down to Hackbright, and we all played a game of friendly taboo, a concentration game called Ricochet Robots, and then some crazy taboo/charade game. It was really fun to interact with people in a non-work setting. It's something I feel like I don't do enough. 


On Saturday we FINALLY found a place to live after Nov 1. Thank jebus crust. We'll be in Alameda until the end of February. Hopefully by then, everyone will be employed and then we can focus on where we'll be living more permanently. 

On Sunday morning, I went to a Ladies Tech Brunch at some superfancy high rise apartment in the Financial District. It was nice, but there were a lot of people, and it was definitely good for networking that I just wasn't in the right frame of mind to pursue. I did meet a couple people that I'd like to keep in touch with, though, and I think it encouraged me to go to a PyLadies SF meetup when I can. After that, another HBer and I went to La Boheme Cafe in the Mission to meet up with a bunch of HBers + a HB instructor who were mostly just co-working. I love how accessible and friendly everyone, especially the instructors, are. Hackbright is shaping up into a good decision.

And my 10 second review of La Boheme Cafe:
I'm way too lazy to edit this. Pretend it's cropped.

  • great space to work
  • good, strong coffee
  • pretty good food, and they use zataar spice on their pitas so you know they must know something
  • will definitely return

01 October 2014

Hackbright: Day 2. An exploration in my pair programming partner's patience.


We spent the morning talking about the blockly maze exercise we did yesterday, along with algorithms in general. It turns out that the "left hand rule" of maze solving basically says, if you can turn left, turn left, otherwise, if you can go forward, go forward, and worst case scenario, go right. This has a real-world application of being a way to find items in file systems that are structured like "trees". It makes me think I should mess around and try to write my own locate script to see if I can make it work.

After that, we paired off to today's exercise, in which we created a guessing game. Pair programming is something that I am very much not good at. I speak quickly, I get excited by ideas (and have the subsequent unintelligible verbal diarrhea), and I'm not used to thinking out loud in such a way that it is decipherable to anyone but myself. To anyone reading this with whom I have pair programmed or will pair program with in the future: my deepest and sincerest apologies.

The guessing game was pretty straightforward, where it was a game where the user guessed a random number between 1 and 100 and then would be told if their guess was right, too high or too low. Then, we added features to alert the user when their guess was out of range or if they entered a string. Determining whether or not the input was out of range was easy. Trying to figure out if it was actually a string was much more difficult.

We prompted the user for input using the command:
guess = raw_input("Guess a number between 1-100")
Due to the way that python works, the raw_input function converts anything that is entered into a string, so if the user inputs a number, for instance, "67", we need to convert that number from a string to an integer. This is easy enough to do:
guess = int(guess)
BUT, if the user entered something that wasn't a number, e.g., "poop", then doing guess = int(guess) is going to puke on you. The way that we solved for this was to write a function that compared the input to a string of all the arabic numerals to see if the input contained only numbers (and thus was able to successfully run guess = int(guess)). The function was actually pretty nifty:

And I just realized that I emailed my pair programming partner and myself the wrong file. I am the awesome.

Finally, we added the functionality to play another round and to also keep track of the high score. I want to play around with it a bit more to see if I can make it look better and perhaps function faster. And now I should probably go to sleep or pack since we're moving again during the day.


EDITED TO ADD:

I totally forgot that we talked about git. git is way better than cvs and apparently I was doing horrible, terrible, no good things in cvs before, so it's good that I'm now committed (HA, GIT it??????) to git. Tabula rasa, amirite? (I understand that that's not at all what is meant by that.)