Skip to content

Instantly share code, notes, and snippets.

@mdigan
Last active March 16, 2016 04:05
Show Gist options
  • Save mdigan/7ed0492d76c30d6a664d to your computer and use it in GitHub Desktop.
Save mdigan/7ed0492d76c30d6a664d to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Install Jupyter\n",
"```\n",
"$ pip install jupyter\n",
"$ jupyter notebook\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Load this notebook file in Jupyter\n",
"\n",
"File > Open... > crash-course.ipynb"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Install and Start Riak"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[4;33mWarning\u001b[0m: riak-2.1.3 already installed\n",
"Node is already running!\n",
"================================= Membership ==================================\n",
"Status Ring Pending Node\n",
"-------------------------------------------------------------------------------\n",
"valid 100.0% -- '[email protected]'\n",
"-------------------------------------------------------------------------------\n",
"Valid:1 / Leaving:0 / Exiting:0 / Joining:0 / Down:0\n"
]
}
],
"source": [
"!brew install riak\n",
"!riak start\n",
"!riak-admin member-status"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Test Riak"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello Jupyter"
]
}
],
"source": [
"!curl -XPUT http://localhost:8098/buckets/welcome/keys/hello-spark \\\n",
" -H 'Content-Type: text/plain' \\\n",
" -d 'Hello Jupyter'\n",
" \n",
"!curl http://localhost:8098/buckets/welcome/keys/hello-spark"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Install Spark and a Helper"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[4;31mError\u001b[0m: apache-spark-1.5.1 already installed\r\n",
"To install this version, first `brew unlink apache-spark`\r\n"
]
}
],
"source": [
"!brew install apache-spark"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied (use --upgrade to upgrade): findspark in /usr/local/lib/python2.7/site-packages\r\n"
]
}
],
"source": [
"!pip install findspark"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Import Dependencies"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import findspark\n",
"findspark.init()\n",
"\n",
"import pyspark\n",
"sc = pyspark.SparkContext()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Run a Quick Spark Test"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pi is roughly 2.222222\n"
]
}
],
"source": [
"NUM_SAMPLES = 9\n",
"\n",
"from random import random\n",
"\n",
"def sample(p):\n",
" x, y = random(), random()\n",
" return 1 if x*x + y*y < 1 else 0\n",
"\n",
"count = sc.parallelize(xrange(0, NUM_SAMPLES)).map(sample) \\\n",
" .reduce(lambda a, b: a + b)\n",
" \n",
"print \"Pi is roughly %f\" % (4.0 * count / NUM_SAMPLES)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment