Zepl
Search…
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. 1.
    In a notebook, create a paragraph with the desired code or text for to save
  2. 2.
    Select the gear icon for paragraph settings
  3. 3.
    Select "Add to code snippets"
  4. 4.
    In the New Code Snippet modal:
    1. 1.
      Name: Add any name to reference this code snippet
    2. 2.
      Description (markdown supported): Add a description
    3. 3.
      Code / Output / Meta Data: These values are for display only
  5. 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. 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. 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. 1.
    Name: Alphanumeric order
  2. 2.
    Recently Created
  3. 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. 1.
    Created by Me: Only display the code snippets which your user account has created
  2. 2.
    Created by Others: Only display the code snippets that other user accounts have created. Exclude the code snippets which your user created.
  3. 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. 1.
    Select the menu icon
    in the code snippet list > Select "Add to Notebook"
  2. 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. 1.
    Select the menu icon
    in the code snippet list
  2. 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. 1.
    Select the menu icon
    in the code snippet list
  2. 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. 1.
    Select the menu icon
    in the code snippet list
  2. 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
1
%python
2
import pandas as pd
3
​
4
# establish connection to Snowflake
5
cur = z.getDatasource("Shainsky_Snowflake")
6
​
7
# execute query
8
cur.execute("select * from LINEITEM LIMIT 10000")
9
​
10
# convert datasource into pandas dataframe
11
df = cur.fetch_pandas_all()
12
​
13
# print dataframe as table
14
z.show(df)
15
​
Copied!
1
%spark
2
sc.hadoopConfiguration.set("fs.s3a.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem")
3
sc.hadoopConfiguration.set("fs.s3a.access.key", access_key)
4
sc.hadoopConfiguration.set("fs.s3a.secret.key", secret_key)
5
sc.hadoopConfiguration.set("fs.s3a.endpoint", "s3.us-west-2.amazonaws.com")
6
sc.hadoopConfiguration.set("com.amazonaws.services.s3.enableV4", "true")
Copied!
1
%python
2
def card(title, value, secondValue = ""):
3
print("""%html
4
<div style="width: 200px;text-align:center;float:left;margin:10px 10px">
5
<div style="font-weight:bold;font-size:16px;color:#2BB5E9">
6
{title}
7
</div>
8
<div style='background-color:#62C1E2;color:white;padding:10px 10px; font-size: 30px'>
9
{value}
10
<div style="font-size:15px">{secondValue}</div>
11
</div>
12
</div>\n""".format(title=title, value=value, secondValue=secondValue))
13
14
print("""
15
%html
16
<style>
17
.dataframe td {
18
padding: 5px 5px;
19
}
20
.dataframe th {
21
padding: 5px 5px;
22
}
23
.analytics {
24
font-size:24px;
25
color:#62C1E2;
26
}
27
.analyticsHL {
28
font-size:28px;
29
color:#2BB5E9;
30
font-weight:bold;
31
}
32
</style>
33
""")
34
​
35
# Call Card function
36
card("United Kingdom", 2848, "GDP")
Copied!

Output:

1
%md
2
<video width="100%" height="100%" autoplay loop>
3
<source src="https://zepl-dev.s3.amazonaws.com/home/ken/Tesla_video_4_Zepl.mp4" type="video/mp4" />
4
Your browser does not support the video tag.
5
</video>
Copied!
Last modified 1yr ago