*The first four slideshow pictures are mine and the last one with the pink background is his. The code is mine and is a screenshot of the javascript portion
Since we had a three day weekend and it was right after our hackathon, we didn't have much to do and I was pretty bored by today (Sunday). I decided to go to the awesome coffee shop a block away (Bennu!) and started to make an archery game. I wanted to do something visual (animation) and incorporate some physics into it so I thought projectile motion would be the easiest thing to start out with. We didn't really learn any animation stuff yet but it wasn't too difficult to figure out. Basically, this app allows you to enter the initial velocities in the x direction and the y direction (in meters per second) and when you click start, the arrow will make a parabola. In the x direction I didn't want to include drag (friction from the atmosphere) so I assumed that there was no negative acceleration slowing the arrow down. In the y direction, I incorporated gravity (-9.81 m/s^2). The kinetics equation I used was yposition = yvelocity * time + 0.5 * (-9.81 * time^2). The hardest part was converting the pixels into meters and choosing the most optimal dimensions. I settled on 1000px = 100 meters (so 10px per meter). Another difficulty was getting the time. I was using the Javascript function setTimeout which can be used in a function to call itself in a set interval. Here I chose every 10 milliseconds because I wanted the motion to look pretty smooth but I also didn't want it to make things more complicated. So for each second, the function to change the position of the arrow in both the x position and y position was called 100 times (1000 milliseconds in a second). I couldn't really find a simple function that just times things for you but I made one by defining a variable 'time' to start with the value 0, and incremented it by 0.01sec each time setTimeout would call the move arrow method. Anddd it works! The next step for me is to incorporate some type of scoring system but I need to do more reading on collisions so I'll save that for another day. One thing though, I started talking to a random kid this afternoon and he was interested in this mini project. I made him a collaborator on my github account and we finished around the same time and compared. He got the angles to correspond to the arch perfectly and didn't even use help from a single jQuery function. Well there goes my self-confidence... Gotta study more and get on his level! *The first four slideshow pictures are mine and the last one with the pink background is his. The code is mine and is a screenshot of the javascript portion
0 Comments
This is the app we made! Basically we finished it in two days which is a huge improvement from our previous rock paper scissors app. It's called ATX Hot Spots, and is a Yelp like app but you find restaurants on the map. We downloaded a database of all the restaurants in Austin and their addresses and converted that data into tables we could work with in PostgreSQL. We had three tables, placelist (<--), reviews, and users. You can sign up and sign in. If you sign up with an email address that is linked to Gravatar, your picture is automatically referenced and pops up (so you don't have to manually upload one!). Each user's data (username, password, and email) is saved into the database with the password encrypted for security. Once you sign in, a session ID is created and also saved into that database so that you don't have to log in every time you refresh the page. We used a map API (Open Street Map) and leaflet.js to drop the pins at the restaurants. We started out with data from all restaurants in Austin (19,000 rows in the DB) because we downloaded the info from health inspections. To get rid of duplicates (multiple inspections at the same restaurant), we simply combined psql and ruby code to iterate through and delete extra data with the same facility ID. We used the latitude and longitude coordinates of the places so that we could use it to drop the pins. You can click through the slideshow above to see how it works. Once you click on a pin, the restaurant name and a link to their reviews show up. That link will take you to all of the reviews of that restaurant in addition to showing how many stars each person gave. In the right hand form, you can write and rate a restaurant and it'll show up in the reviews!
Today we just finished our mock hackathon and presented our projects. We actually got everything to work on our project which was the most satisfying thing ever. Today we started brainstorming for our real hackathon that starts tomorrow. We have two days to get another app up and running! Our idea now is to make a map based app that functions like Yelp but our main focus is a visual of the city of Austin. We're debating if we should use the Open Street Map API or the Google Maps API. We also want to use the Facebook API for logins but implementing this might be the most difficult part of the project so we'll see. Some documentation that we're going to use to make this happen:
Open Street Map Doc Facebook SDK for Javascript Google Maps API Doc Facebook Login API It's so crazy to think that week 4 has come to an end. These past few weeks have flown by and the amount of stuff we've learned is insane. These past few days we've been working on our mock hackathon project. It's a simple rock paper scissors game but it's more difficult to construct than I had thought. By making use of the PostgreSQL database, and sessions (great article on them by the way : http://machinesaredigging.com/2013/10/29/how-does-a-web-session-work/ ) we need to allow for certain things to happen
Alex and I are partners because we really work well together and I'm glad we don't have arguments. We're about halfway through. It's really nice working on this because I finally understand how to work the erb files and CRUD methods. Tying in the front-end to the back-end is still my weakness but I'm learning! I'll update when we finish tomorrow night. UPDATE************************** Our finished project ! (slideshow) Tonight Alex and I got our project gutenberg to work! This is basically an app that could read a book and figure out what category (religion, philosophy, archeology, or astronomy) it belonged to. We wrote an algorithm that allowed the app to read a couple of sample books from each category and trained it to recognize what words were common in each category. We then wrote an algorithm for the books we passed through and came up with a scoring scheme to rank which category the book most likely belonged to. Although we had nested iteration which isn't best practice when focusing on time efficiency we also focused on minimizing the amount of tokens to loop through by using sorted arrays and hashes, we got ours to reach 100% accuracy with a pretty short run time!! I was proud of myself so I'll post proof :D. Tomorrow we start our mock hackathon and next week is our real one!
Update: picture below from our mock hackathon, we took a break to go watch the world cup and sachin went "too hard in the paint" :D git add .
git commit -m "comment" git remote -v (to check the origin) *optional: git remote rm origin git remote add origin https://github.com/ruinakata/backend-mks.git git checkout -b pizza (create a new branch) git push origin pizza Thanks Sachin! What a busy week. We had so many different projects all at the same time but surprisingly I wasn't too stressed out. We built a task-manager app with just Ruby and learned how to modularize our code to keep the user interface and business logic separated. We also made a web app which was a simple tic-tac-toe game but I had the most trouble with that. Using CSS, HTML, javascript and jquery all in one application confuses me a lot, but it's pretty fun because you can see how the code that creates the game interacts with the presentation. We also got introduced to Sinatra which we'll dive into this upcoming week. For algorithms, we had to make a war app (like the card game) and loop through the game to figure out on average how many turns it takes for someone to completely win (get all 52 cards). This basically took all weekend because I started out writing the code in a complicated way and was too stubborn to start over from the beginning. Also, using RSPEC to write tests is super helpful but also a nightmare because I tend to change around stuff and break every passing test from the past... But after about 30 hours of me getting confused by my own code I finally got the play_game method to work! I made my computer play the game 10,000 times and the lowest amount of turns it took for one player to get all 52 cards was 52 times and the highest was 2076 times. Now all I have to do for tomorrow is refractor it and shorten the runtime.... Ready for another week!!!
It's crazy to think that our first week has already come to an end. Seriously, it went by so fast! But the weird thing is at the same time I feel like I already know the instructors and the people in my cohort really well. Today we finished up our sass project and I finished my web design for Yogate. It's super simple because all I had were the images put up on their facebook page and it doesn't look good but it was a good way to learn all of the CSS functions and how premade frameworks like bootstrap and foundation are made. For the backend stuff, we learned how to use RSPEC and stubbing for test-driven development. It really does save you so much time when you use RSPEC because you don't have to go into irb and make random instances of classes just to check if the methods are working. Also, the git commands are slowly coming together for me hahaha. This is how far I got on one of the ruby projects we started today. (vagrant, ruby file, then rspec file) A typical day this week kind of went like this:
-7AM : wake up, get ready, eat -8AM : start walking to MakerSquare! -9AM: classes on backend stuff (Ruby) and problems to work through -NOON : lunch time, I usually bring food and eat on the couches there or while I do work -1PM : Patrick teaches us algorithms and data structures :D -2PM : Clay teaches us frontend stuff basically worked on sass and web design using a framework -5PM : Class is over but people usually stick around for an hour -7PM : Get home. Shower, eat. -8PM : Go next door to the annex and have our nightly coding party. -9PM : Basically we all sit in a circle in the living room burried under our laptops (Sachin brings out his monitor HAHA) I'm either freaking out because my tests are failing or super happy that my methods worked (pretty bad mood swings!) -midnight : go back to my part of the house and bedtime Today was the second day of MakerSquare, and I feel like I've known everyone in my cohort for weeks already. It's probably because I'm with them for 8 hours a day during class and we all go home and code together until bedtime. Also, I'm loving it so far :) . There are about 20 people in my cohort and everyone is super friendly, very healthy, and all have a passion for coding. It's about 15 men and 4 women mostly around the age of 27. The instructors and staff are also amazing, they are very helpful and fun to be around. We made our library app yesterday and started some CSS and SASS today. This new shoestring project is pretty difficult for me, we're trying to recreate something similar to bootstrap. Even though my brain is pounding trying to absorb every thing that we are exposed to, surprisingly it's not torturous. It's actually pretty enjoyable!
Anyways, I was having trouble with the clearfix function so I found this reading online that refreshed my memory on floats and clear http://css-tricks.com/all-about-floats/ Because moodle might stop working for me soon, I'll keep note of some useful resources I used while auditing a computer science class at Colgate before it's too late.
These resources focus on Java but it really helped me understand overall concepts that are probably shared with all programming languages not just Java (like stack and heap, run time differences, etc.)
Also, in learning new concepts throughout the course I realized that always keeping track of the run times of each bit of code and constantly thinking of how to rewrite it in an effort to shorten the time was one of the most important factors in writing good code. Unfortunately, I thought this was the hardest part and requires a lot of practice. I found a great wikipedia article that lists all of the different types of time complexities in algorithms and detailed explanations of each which everyone should check out!! I'll make a VERY condensed summary though. Time complexity
Examples 1. constant time (O(1)) An algorithm is in constant time if the value of T(n) (max time) is not determined by the size of input. An example would be accessing a single element in an array because one operation is performed. 2. linear time (O(n)) An algorithm is in linear time if the size of the input determines the run time. The running time increases linearly with the size of input (but usually for very large inputs). In contrast to constant time, finding the minimal value in an unordered array is considered to be in linear time because we need to scan over each element in the array to determine the minimal value. If the array was ordered, it can be considered constant. 3. logarithmic time T(n)=O(log n) An algorithm is said to take logarithmic time if T(n) = O(log n). Because computers use the binary numeral system the base of the log is generally base 2 (log2 n) but in big-O notation it is usually discarded because the change in base number only changes the runtime by a constant multiplier. Logarithmic time algorithms are usually found in operations on binary trees or binary searches. An O(log n) algorithm is highly time efficient because the operations per instance required decrease with each instance. A simple example would be an algorithm that cuts a string in half. 4. polynomial time T(n) = O(nk) for some constant k An algorithm is said to be polynomial if its running time is upper bounded by a polynomial expression in the size of the input. Examples of these algorithms are the quicksort and basic arithmetic operations. |