This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function from<T>(convertible: Promise<T> | ArrayLike<T>): Observable<T> { | |
if (typeof (convertible as any).length === "number") { | |
const arrayLike = convertible as ArrayLike<T>; | |
return new Observable(obs => { | |
for (let i = 0; i < arrayLike.length; i++) { | |
obs.next(arrayLike[i]); | |
} | |
obs.complete(); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function of<T>(...values: T[]): Observable<T> { | |
return new Observable(obs => { | |
for (const value of values) { | |
obs.next(value); | |
} | |
obs.complete(); | |
}); | |
} | |
// Logs: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const observable = new Observable(subscriber => { | |
subscriber.next(1); | |
subscriber.next(2); | |
subscriber.next(3); | |
setTimeout(() => { | |
subscriber.next(4); | |
subscriber.complete(); | |
}, 1000); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Observer<T> { | |
next(value: T): void; | |
error(err: any): void; | |
complete(): void; | |
} | |
interface Subscription { | |
unsubscribe(): void; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ipython-utils/researchenv/__init__.py | |
# imports... | |
from researchenv.magics import ResearchEnvMagics | |
from google.cloud import bigquery | |
def load_ipython_extension(ipython: InteractiveShell): | |
# previous logic... | |
bq = bigquery.Client(project='example-project-id') | |
ipython.register_magics(ResearchEnvMagics(shell=ipython, bq=bq)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ipython-utils/researchenv/magics.py | |
from IPython.core.magic import Magics, magics_class, cell_magic, needs_local_scope | |
from IPython.core.magic_arguments import magic_arguments, argument, parse_argstring | |
from IPython.core.interactiveshell import InteractiveShell | |
from IPython.core.display import display | |
from google.cloud import bigquery | |
@magics_class | |
class ResearchEnvMagics(Magics): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%bq --name hn_daily_comment_counts | |
SELECT | |
TIMESTAMP_TRUNC(time_ts, DAY) as day, | |
COUNT(0) as comment_count | |
FROM | |
`bigquery-public-data.hacker_news.comments` | |
GROUP BY | |
day | |
ORDER BY | |
day ASC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ipython-utils/setup.py | |
setup( | |
name='ipython-utils', | |
packages=find_packages(), | |
install_requires=[ | |
'ipython >= 4', | |
'notebook >= 4.3.1', | |
'jupyter', | |
'numpy', | |
'pandas', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ipython-utils/researchenv/__init__.py | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
from IPython.core.interactiveshell import InteractiveShell | |
def load_ipython_extension(ipython: InteractiveShell): | |
print('%matplotlib inline') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn as sns |