Code Snippets

Code snippets are an easy way to save and share reusable notebook paragraphs. Use Zepl's code snippets to shorten the learning curve for new users by sharing repetitive tasks such as, connecting to data, data preparation, and setting visualization parameters or common color palettes.

Create Code Snippets

  1. In a notebook, create a paragraph with the desired code or text for to save

  2. Select the gear icon for paragraph settings

  3. Select "Add to code snippets"

  4. In the New Code Snippet modal:

    1. Name: Add any name to reference this code snippet

    2. Description (markdown supported): Add a description

    3. Code / Output / Meta Data: These values are for display only

  5. Create

Find Code Snippets

After any member of your Zepl organization creates a code snippet, all code snippets will be found in side any notebook.

  1. In any notebooks right hand menu, select the code snippet icon. If no code snippets are created, you will be prompted to create one

  2. In the table, select the code snippet of your choice to preview the Code and Meta Data of the code snippet

Sort

Code snippets can be sorted by three meta data categories. To do so, select the icon with the corresponding value below:

  1. Name: Alphanumeric order

  2. Recently Created

  3. Recently Used

The code snippet list can easily be sorted in ascending or descending order by selecting the ascending or descending arrow icon:

​

Code snippets can be searched by selecting the search icon

​

Filter

Code snippets can be filtered by selecting one of the pre-built filters. To select a filter, select the "All snippets" icon

Below are the pre-built filters to choose from:

  1. Created by Me: Only display the code snippets which your user account has created

  2. Created by Others: Only display the code snippets that other user accounts have created. Exclude the code snippets which your user created.

  3. Favorites: Only display the code snippets which your user account has selected the favorite star icon

Insert Code Snippets

There are several ways to insert a code snippet into your notebook:

  1. Select the menu icon in the code snippet list > Select "Add to Notebook"

  2. Select the code snippet icon as it appears in the snippet list and description

Code snippets are inserted below the last paragraph of your notebook

Edit Code Snippets

Editing a code snippet allows the user to change the Title and the Description of the code snippet. To edit a code snippet:

  1. Select the menu icon in the code snippet list

  2. Select Edit

If the user would like to edit the code of the code snippet, insert the code snippet into a notebook, make the desired changes, and create a new code snippet.

Duplicate Code Snippets

Duplicating a code snippet will make a copy of the code, but give the user the ability to edit the Title and Description. To duplicate a code snippet:

  1. Select the menu icon in the code snippet list

  2. Select Duplicate

Delete Code Snippets

Deleting a code snippet allows the user to remove a code snippet from the list for all users. Code snippets can only be deleted by the user that created them. To delete a code snippet:

  1. Select the menu icon in the code snippet list

  2. Select Remove

Examples

Repeatable tasks that make for great code snippets!

Connect to Snowflake
Set S3 Credentials for Spark
Display HTML
Embed a video
Connect to Snowflake
%python
import pandas as pd
​
# establish connection to Snowflake
cur = z.getDatasource("Shainsky_Snowflake")
​
# execute query
cur.execute("select * from LINEITEM LIMIT 10000")
​
# convert datasource into pandas dataframe
df = cur.fetch_pandas_all()
​
# print dataframe as table
z.show(df)
​
Set S3 Credentials for Spark
%spark
sc.hadoopConfiguration.set("fs.s3a.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem")
sc.hadoopConfiguration.set("fs.s3a.access.key", access_key)
sc.hadoopConfiguration.set("fs.s3a.secret.key", secret_key)
sc.hadoopConfiguration.set("fs.s3a.endpoint", "s3.us-west-2.amazonaws.com")
sc.hadoopConfiguration.set("com.amazonaws.services.s3.enableV4", "true")
Display HTML
%python
def card(title, value, secondValue = ""):
print("""%html
<div style="width: 200px;text-align:center;float:left;margin:10px 10px">
<div style="font-weight:bold;font-size:16px;color:#2BB5E9">
{title}
</div>
<div style='background-color:#62C1E2;color:white;padding:10px 10px; font-size: 30px'>
{value}
<div style="font-size:15px">{secondValue}</div>
</div>
</div>\n""".format(title=title, value=value, secondValue=secondValue))
print("""
%html
<style>
.dataframe td {
padding: 5px 5px;
}
.dataframe th {
padding: 5px 5px;
}
.analytics {
font-size:24px;
color:#62C1E2;
}
.analyticsHL {
font-size:28px;
color:#2BB5E9;
font-weight:bold;
}
</style>
""")
​
# Call Card function
card("United Kingdom", 2848, "GDP")

Output:

Embed a video
%md
<video width="100%" height="100%" autoplay loop>
<source src="https://zepl-dev.s3.amazonaws.com/home/ken/Tesla_video_4_Zepl.mp4" type="video/mp4" />
Your browser does not support the video tag.
</video>