Skip to content

Instantly share code, notes, and snippets.

@byanuaria
byanuaria / bisectionSearch.py
Created September 17, 2018 17:59
Guessing number using bisection search
low = 0
high = 100
guess = (low + high) // 2
ans = ""
userInput = input('Please think of a number between 0 and 100!')
while True:
print('Is Your secret number ' + str(guess) + '?')
ans = input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly. ")
if ans == 'c':
library(pitchRx)
library(tidyverse)
data <- scrape(start = "2011-04-04", end = "2011-06-01")
pitches <- data[["pitch"]]
ab <- data[["atbat"]]
newDat <- merge(pitches, ab, by = c("num", "gameday_link"))
newDat <- newDat[1:95]
@byanuaria
byanuaria / plot6.R
Last active August 15, 2018 17:53
Using EDA to compare emissions from motor vehicle sources in Baltimore City with emissions from motor vehicle sources in Los Angeles, CA. Graph shows which city has seen greater changes over time in motor vehicle emissions.
# read in data
NEI <- readRDS("summarySCC_PM25.rds")
SCC <- readRDS("Source_Classification_Code.rds")
# load packages
library(tidyverse)
# convert to proper class
SCC$SCC <- as.character(SCC$SCC)
SCC$EI.Sector <- as.character(SCC$EI.Sector)
@byanuaria
byanuaria / plot5.R
Created August 14, 2018 23:28
Plotting for question 5 in Exploratory Data Analysis
# reading in data
NEI <- readRDS("summarySCC_PM25.rds")
SCC <- readRDS("Source_Classification_Code.rds")
# load packages
library(tidyverse)
# convert to proper class
SCC$SCC <- as.character(SCC$SCC)
SCC$EI.Sector <- as.character(SCC$EI.Sector)
@byanuaria
byanuaria / commaCode.py
Created July 27, 2018 20:07
Automate the boring stuff pratice project: Comma Code. A function that takes a list value as an argument and returns a string with all the items seperated by a comma and a space, with 'and' inserted before the last item.
# lists to test
foo = ['apples', 'bananas', 'tofu', 'cats']
a = ['bat', 'rat', 'elephant', 'snake', 'hippo']
b = ['Ben', 'Ryan', 'Arthur', 'Dillon', 'Andre', 'Agnes', 'Aaron']
d = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
# comma code function
def commaCode(myList):
s = '' # creates an empty string vector
last = myList[len(myList) - 1] # gets the last value from the list
/* How many albums does the artist Led Zepplin have? */
SELECT COUNT(Albumid) AS totalAlbums
FROM albums
WHERE Artistid = (SELECT Artistid FROM artists WHERE name = 'Led Zeppelin')
/* Create a list of album titles and the unit prices for the artist Audioslave */
SELECT n.Name, u.UnitPrice
FROM ((albums t INNER JOIN artists n
ON t.Artistid = n.Artistid)
INNER JOIN tracks u ON t.Albumid = u.Albumid)
@byanuaria
byanuaria / sqlzooSelfJOIN.sql
Created July 18, 2018 20:19
self join section from sqlzoo
/* Self join * /
/* How many stops are in the database */
SELECT COUNT(*)
FROM stops
/* Find the id value for the stop Craiglockhart */
SELECT id
FROM stops
WHERE name = 'Craiglockhart'
@byanuaria
byanuaria / sqlzooNULL.sql
Created July 18, 2018 18:18
sqlzoo assignment working with joins and NULL values.
/* Using NULL */
/* List the teachers who have NULL for their department */
SELECT name
FROM teacher
WHERE dept IS NULL
/* Use a different JOIN so that all teachers are listed */
SELECT teacher.name, dept.name
FROM teacher LEFT JOIN dept ON teacher.dept = dept.id
/* More JOIN */
/* Give year of Citizen Kane */
SELECT yr
FROM movie
WHERE title = 'Citizen Kane'
/* List all of the Star Trek movies, include the id, title and yr (all of these movies include the words Stark Trek in the title). Order results by year */
SELECT id, title, yr
FROM movie
WHERE title LIKE 'Star Trek%'
@byanuaria
byanuaria / sqlzooJOIN.sql
Created July 17, 2018 20:03
SQLzoo JOIN assignments
/* Show matchid and player name for all goals scored by Germany */
SELECT matchid, player
FROM goal
WHERE teamid = 'GER'
/* Show id, stadium, team1, team2 for just game 1012 */
SELECT id, stadium, team1, team2
FROM game
WHERE id = 1012