Skip to content

Instantly share code, notes, and snippets.

View jarhoads's full-sized avatar

Josh jarhoads

  • Pittsburgh
View GitHub Profile
@jarhoads
jarhoads / app.component.html
Last active May 24, 2019 18:07
angular directives examples (component template)
<ng-template #titleTemplate let-text="title">
<h4 class="p-2 bg-success text-white">{{text}}</h4>
</ng-template>
<ng-template [ngTemplateOutlet]="titleTemplate"
[ngTemplateOutletContext]="{title: 'Header'}">
</ng-template>
<div class="text-white m-2">
// tail recursion: uses O(N) time and O(N) space (call stack)
function getNthFibTail(n, prev, curr){
if(n === 0){ return prev; }
if(n === 1){ return curr; }
return getNthFibTail((n-1), curr, (curr+prev));
}
// JavaScript objects can be created via the object literal {} or via the syntax new Object();
// Additional properties can be added or accessed in one of two ways:
// object.propertyName or object['propertyName'].
let javascriptObj = {};
let testArr = [1,2,3,4];
javascriptObj.array = testArr;
console.log(javascriptObj);
// array literal
let array1 = [1,2,3,4];
array1.push(5); //array1 = [1,2,3,4,5]
array1.push(7); //array1 = [1,2,3,4,5,7]
array1.push(2); //array1 = [1,2,3,4,5,7,2]
console.log(array1);
// deletion: pop returns last item
let array2 = [1,2,3,4];
array2.pop(); //returns 4, array2 = [1,2,3]
// sets
let exampleSet = new Set();
// has one property - size
exampleSet.add(1); // exampleSet: Set {1}
exampleSet.add(1); // exampleSet: Set {1}
exampleSet.add(2); // exampleSet: Set {1, 2}
// deletion
exampleSet.delete(1); // true, exampleSet: Set {2}
@jarhoads
jarhoads / numpy_notes.md
Created December 19, 2018 15:48
numpy notes

Intro to numpy

Spyder

  • Provides an ipython environment from the IDE
    Console -> Open ipython console

ipython

  • Can use standard help function help('numpy')
  • Can get help on numpy array function help('numpy.array')
  • Import numpy with import numpy as np
@jarhoads
jarhoads / jupyter_ipython.md
Created December 19, 2018 15:46
Jupyter and iPython Notes

Jupyter and IPython

Capture Cell Magic

  • cell magic for output capture:
    %%capture: captures output and stderr streams
    store streams in variable or discard streams (default)
    %%capture myCapture
    print('this is standard output')
    print('this is stderr', file=sys.stderr)
@jarhoads
jarhoads / pandas_notes.md
Created December 19, 2018 15:43
pandas notes for reference

Pandas

Summary

  • Python Package
  • Panel Data System
  • Data Analysis Library
  • Data Structures:
    Series
    DataFrame
    Panel
@jarhoads
jarhoads / pandassamp.py
Created November 14, 2018 18:38
Pandas Sample
import pandas as pd
# create dataframes
df1 = pd.DataFrame({'key': ['K0', 'K1', 'K2'],
'W': ['W0', 'W1', 'W2'],
'Y': ['Y0', 'Y1', 'Y2']})
df2 = pd.DataFrame({'key': ['K0', 'K1', 'K2'],
'X': ['X0', 'X1', 'X2'],
'Z': ['Z0', 'Z1', 'Z2']})
@jarhoads
jarhoads / pynotes.md
Last active November 14, 2018 18:36
Python Notes

Intro to NLTK

Using NLTK

  • import: import nltk
  • download examples: import nltk, then nltk.download()
  • opens nltk downloader GUI can download collections/packages
  • corpora: sets of structured text
  • Example: