Skip to content

Instantly share code, notes, and snippets.

View stephaniemdavis's full-sized avatar
🎯
Focusing

Stephanie M. Davis stephaniemdavis

🎯
Focusing
View GitHub Profile
@stephaniemdavis
stephaniemdavis / US Zip Codes from 2013 Government Data
Created March 13, 2019 17:41 — forked from erichurst/US Zip Codes from 2013 Government Data
All US zip codes with their corresponding latitude and longitude coordinates. Comma delimited for your database goodness. Source: http://www.census.gov/geo/maps-data/data/gazetteer.html
This file has been truncated, but you can view the full file.
ZIP,LAT,LNG
00601,18.180555, -66.749961
00602,18.361945, -67.175597
00603,18.455183, -67.119887
00606,18.158345, -66.932911
00610,18.295366, -67.125135
00612,18.402253, -66.711397
00616,18.420412, -66.671979
00617,18.445147, -66.559696
00622,17.991245, -67.153993
@stephaniemdavis
stephaniemdavis / codewars_dna.py
Created September 8, 2018 16:37
Reusable code for Codewars DNA code challenges
# iterating a string and comparing it to dictionary values
# by adding the result variable, I eliminate redundant and costly printing, which is the PYTHONIC way to develop
d = {'A':'T','T':'A','C':'G','G':'C'}
for k in random_string:
if k not in d:
result = '{} is not valid. {} is the culprit!'.format(random_string,k)
break
@stephaniemdavis
stephaniemdavis / resilient_slicing.py
Created August 25, 2018 12:41
Python string slicing that's independent of string length (counter-intuitively)!!!
# Taken from Introduction to Computer Science - Dave Evans of Udacity
s = 'audacity' # Sample string
print(s[:3] + s[3:]
# Counterintuitive Example Below:
t = 'Hi'
print(t[:3] + t[3:] # NO error message despite t's length
# Code below references the character in third index position (which doesn't exist!!)
print(t[3])
@stephaniemdavis
stephaniemdavis / unique.py
Last active August 22, 2018 15:55
Lesson 1 of Coursera's Data Analysis with Python course. Datasets housed in ~/Code/intro_data_anal on local host
import os,unicodecsv
# write the csv reader function
def read_csv(filename): # write a function that reads a csv
with open(filename,'rb') as file_object: # open csv file
reader = unicodecsv.DictReader(file_object) # dictionary object created
return list(reader) # creating list of dictionary(reader) objects
enrolled = read_csv('enrollments.csv')
engaged = read_csv('daily_engagement.csv')
submitted = read_csv('project_submissions.csv')
@stephaniemdavis
stephaniemdavis / months.py
Created August 1, 2018 11:11
List comprehension, string operation; danger of NoneType assignment.
# Stephanie M. Davis. 8-1-2018 in Washington D.C. for NASA showcase event
# Just practicing list comprehensions. In the process, I FINALLY learned the futuility of assigning a NoneType method to a variable
# Build a list of the 12 months and build a new list of those months beginning with the letter 'A'
months = ['January','February','March','April','May','June','July','August','September','October','November','December']
a_months = [month for month in months if month.starswith('A')]
# just for laughs apply reverse method to a_months and assign to variable none_type and see what happens
none_type = a_months.reverse()
@stephaniemdavis
stephaniemdavis / scp-aws.md
Last active March 25, 2020 22:52
Syntax for using scp to to download a file from AWS to local disk

The following line uses the secure copy protocol to copy a file from an aws instance to the current (".") folder of a local machine.

scp -i aws.pem username@awsip(or ALIAS):/path/to/file .

aws.pem is the key AWS provides you to gain access to the AWS instance you want to copy from.

awsip is the IP address or DNS alias of the AWS instance.

path/to/file is the file's path on aws.

It is extremely important to add the period after the /path/to/file. Note the blank space between the /path/to/file and the period.

https://stackoverflow.com/questions/9441008/how-can-i-download-a-file-from-ec2

The obverse is true too; to upload FROM local folder to aws:

@stephaniemdavis
stephaniemdavis / easy_for.py
Last active June 23, 2018 12:48
A simple for loop. For loops only work on iterables
'''
Written 6-23-2018 s.m.d Implementation of EdX Introduction to Computation & Programming Using Python
Convert the following code into code that uses a for loop.
prints 2
prints 4
prints 6
prints 8
prints 10
prints "Goodbye!"
'''
@stephaniemdavis
stephaniemdavis / sum_from1_py
Last active June 23, 2018 12:17
A function which sums integers between 1 and some defined upper limit end
'''
Written 6-23-2018 s.m.d
Implementation of EdX Introduction to Computation & Programming Using Python
'''
# initialization state: grand_sum, incrementer, end
def sum_total(end):
grand_sum = 0
incrementer = 1
end = input("Enter a positive integer please, any positive integer") # instantiate and upper limit integer
end = int(end) # convert end to an integer type