Skip to content

Instantly share code, notes, and snippets.


David Cochran davidcochran

View GitHub Profile
davidcochran /
Last active Mar 6, 2020
Remove json formatting from TMDB fields
# Import ast for ast.literal_eval
import ast
# Remove JSON from TMDB fields
# for genres, spoken_languages, production_companies, production_countries
# Works only with non-null values, so filter out null values before applying
# Requires import ast -- or use simply eval vs ast.literal_eval
def remove_json(content):
# Interpret the content as a Python list of dictionaries
content = ast.literal_eval(content)
davidcochran /
Created Feb 17, 2020
Apply a function to a pandas column
# Define a function to get the name field from the first item in a dictionary list
def get_genre1(x):
x = json.loads(x)
if len(x) > 0:
return x[0]['name']
# Now use pandas.apply to use the function on one column
# In thise case create a new column called genres1 to hold the new data
movies['genre1'] = movies['genres'].apply(get_genre1)
davidcochran /
Last active Jan 28, 2020
Lists of animals for practice with list methods
AussieAnimals = ['kangaroo', 'cassowary', 'wombat', 'possum', 'echidna', 'ibis', 'wallaby', 'koala',
'tasmanian devil', 'kookaburra', 'numbat', 'platypus', 'lyre bird', 'quokka', 'quoll',
'sugar glider', 'bandicoot', 'thorny devil', 'dingo', 'wallaroo', 'yabby', 'bilby']
GalapagosAnimals = ['rice rat', 'hoary bat', 'bottlenose dolphin', 'beaked whale', 'lava lizard',
'tortoise', 'flightless cormorant', 'green sea turtle', 'blue-footed booby',
'marine iguana', 'pink land iguana', 'darwins finches', 'brown noddy']
davidcochran /
Last active Sep 24, 2020
Change default browser for Jupyter Notebooks in Mac OS X

Change the Default Browser for Jupyter Notebooks in OS X

Step 1. Create an editable config file for Jupyter notebooks.

To do this, open Terminal and type:

jupyter notebook --generate-config

This generates the file:

davidcochran / reveal_library.txt
Created Aug 12, 2018
Reveal the Library Folder in OS X local user directory or a backup on another volume
View reveal_library.txt
# Using Mac OS X Terminal
# High Sierra
# August 2018
# Reveal Library folder in current user directory
chflags nohidden ~/Library/
# Reveal Library folder in backup user directory
chflags nohidden /Volumes/Volume_Name/Users/username/Library/
davidcochran / crypto-scraper.R
Last active Jan 10, 2018
Cryptocurrency data scraper in R -- script to utilize JesseVent/crypto
View crypto-scraper.R
# Install and use crypto scraper from
# This script is written to be used by running the desired line(s) separately, often one line at a time
# Install jessevent/crypto package in Rstudio
# If you do not have devtools installed, install devtools first
# Now install jessevent/crypto
davidcochran / risk_taxonomy.json
Created Jul 4, 2017
Cyber Security Risk Taxonomy
View risk_taxonomy.json
"name": "Threat Taxonomy",
"children": [
"name": "Actions of People",
"children": [
"name": "Inadvertent",
"children": [
{"name": "Mistakes", "size": 1},
davidcochran / vs-code-turnoff-autocomplete.json
Last active Jan 14, 2020
Turn off autocompletion (intellisense) in MS Visual Studio Code
View vs-code-turnoff-autocomplete.json
// Turn off autocomplete in Visual Studio Code
// Add the following lines to user settings
// Controls if lines should wrap. The lines will wrap at min(editor.wrappingColumn, viewportWidthInColumns).
"editor.wordWrap": true,
// Controls the indentation of wrapped lines. Can be one of 'none', 'same' or 'indent'.
"editor.wrappingIndent": "indent",
davidcochran / brackets-turnoff-autocomplete.json
Last active Sep 21, 2016
Brackets Preferences: Turn off autocompletion
View brackets-turnoff-autocomplete.json
// Turns off autocompletion and smart indents
// Add the following lines to your user preferences json file
"codehint.AttrHints": false,
"codehint.CssPropHints": false,
"codehint.SpecialCharHints": false,
"codehint.TagHints": false,
"codehint.UrlCodeHints": false,
"closeBrackets": false,
"closeTags": { "whenOpening": false, "whenClosing": false, "indentTags": [] },
davidcochran /
Created Sep 19, 2016
Python - Rounding and Formatting Numbers
Lesson("Interest Calculator (Challenge)")
## The formula is A = P(1+r/n)**(n*t)
## Create each variable separate
## P = Principal, r = Rate %, n = times compounded per year, t = years
## find How much money you will have if you invest your college tuition, $100,000 into a investment account for 40 years earning 7% interest compounded yearly.
You can’t perform that action at this time.