From bbc161a5737f87322b044b36e81d516c9cbe649b Mon Sep 17 00:00:00 2001 From: jahn Date: Mon, 31 Aug 2020 14:47:32 -0700 Subject: [PATCH 1/3] Code Snippet v1.0.2 --- binder/workspace.json | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/binder/workspace.json b/binder/workspace.json index dd1ceba..532a74d 100644 --- a/binder/workspace.json +++ b/binder/workspace.json @@ -1 +1,34 @@ -{"data": {"layout-restorer:data": {"main": {"dock": {"type": "tab-area", "currentIndex": 0, "widgets": ["notebook:Untitled.ipynb"]}, "mode": "multiple-document", "current": "notebook:Untitled.ipynb"}, "left": {"collapsed": false, "current": "code-snippet-extension", "widgets": ["filebrowser", "running-sessions", "git-sessions", "command-palette", "jp-property-inspector", "tab-manager", "@jupyterlab/toc:plugin", "code-snippet-extension", "extensionmanager.main-view"]}, "right": {"collapsed": true, "widgets": []}}, "file-browser-filebrowser:cwd": {"path": ""}, "codeSnippetEditor:jp-codeSnippet-editor-undefined": {"data": {}}, "notebook:Untitled.ipynb": {"data": {"path": "Untitled.ipynb", "factory": "Notebook"}}}, "metadata": {"id": "/lab"}} +{ + "data": { + "layout-restorer:data": { + "main": { + "dock": { + "type": "tab-area", + "currentIndex": 0, + "widgets": ["notebook:Untitled2.ipynb"] + }, + "mode": "multiple-document", + "current": "notebook:Untitled2.ipynb" + }, + "left": { + "collapsed": false, + "current": "code-snippet-extension", + "widgets": [ + "filebrowser", + "running-sessions", + "command-palette", + "jp-property-inspector", + "tab-manager", + "code-snippet-extension", + "extensionmanager.main-view" + ] + }, + "right": { "collapsed": true, "widgets": [] } + }, + "file-browser-filebrowser:cwd": { "path": "snippets" }, + "notebook:Untitled2.ipynb": { + "data": { "path": "Untitled2.ipynb", "factory": "Notebook" } + } + }, + "metadata": { "id": "/lab" } +} From afe14844fc11a889da7ff7031d7c62512d118efb Mon Sep 17 00:00:00 2001 From: jahn Date: Mon, 31 Aug 2020 14:58:33 -0700 Subject: [PATCH 2/3] remove snippets --- snippets/.ipynb_checkpoints/untitled-checkpoint.txt | 0 snippets/carbon_emissions.json | 1 - snippets/filter_income.json | 1 - snippets/gdp_calculator.json | 1 - snippets/generate_hundred.json | 1 - snippets/import_cleaning.json | 1 - snippets/life_exp_eur_asia.json | 1 - snippets/lorenz_deriv.json | 1 - snippets/matplotlib_import.json | 1 - snippets/matrix_lstsqr.json | 1 - snippets/most_frequent.json | 1 - snippets/parallel_strings.json | 1 - snippets/plotting_sine.json | 1 - snippets/progress_bar.json | 1 - snippets/sum_array.json | 1 - snippets/time_calculation.json | 1 - 16 files changed, 15 deletions(-) delete mode 100644 snippets/.ipynb_checkpoints/untitled-checkpoint.txt delete mode 100644 snippets/carbon_emissions.json delete mode 100644 snippets/filter_income.json delete mode 100644 snippets/gdp_calculator.json delete mode 100644 snippets/generate_hundred.json delete mode 100644 snippets/import_cleaning.json delete mode 100644 snippets/life_exp_eur_asia.json delete mode 100644 snippets/lorenz_deriv.json delete mode 100644 snippets/matplotlib_import.json delete mode 100644 snippets/matrix_lstsqr.json delete mode 100644 snippets/most_frequent.json delete mode 100644 snippets/parallel_strings.json delete mode 100644 snippets/plotting_sine.json delete mode 100644 snippets/progress_bar.json delete mode 100644 snippets/sum_array.json delete mode 100644 snippets/time_calculation.json diff --git a/snippets/.ipynb_checkpoints/untitled-checkpoint.txt b/snippets/.ipynb_checkpoints/untitled-checkpoint.txt deleted file mode 100644 index e69de29..0000000 diff --git a/snippets/carbon_emissions.json b/snippets/carbon_emissions.json deleted file mode 100644 index 7ea000b..0000000 --- a/snippets/carbon_emissions.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"carbon_emissions","description":"Total carbon dioxide, in gigatonnes, by region, over time","language":"R","code":["co2_regions <- nations %>%"," filter(year <= 2014) %>%"," mutate(co2 = co2_percap * population / 10^9) %>%"," group_by(region, year) %>%"," summarize(total_co2 = sum(co2, na.rm = TRUE))"],"id":14,"tags":["Countries Project"]} \ No newline at end of file diff --git a/snippets/filter_income.json b/snippets/filter_income.json deleted file mode 100644 index 3b7c26d..0000000 --- a/snippets/filter_income.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"filter_income","description":"Find the ten high income countries with the shortest life expectancy from country data.","language":"R","code":["high_income_short_life <- longevity %>%"," filter(income == \"High income\") %>%"," arrange(life_expect) %>%"," head(10)"],"id":7,"tags":["Countries Project"]} \ No newline at end of file diff --git a/snippets/gdp_calculator.json b/snippets/gdp_calculator.json deleted file mode 100644 index 7c2b9d4..0000000 --- a/snippets/gdp_calculator.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"gdp_calculator","description":"Calculate total GDP, in trillions of dollars, by region, over time","language":"R","code":["gdp_regions <- nations %>%"," mutate(gdp = gdp_percap * population,"," gdp_tn = gdp/1000000000000) %>%"," group_by(region, year) %>%"," summarize(total_gdp_tn = sum(gdp_tn, na.rm = TRUE))",""],"id":11,"tags":["Countries Project"]} \ No newline at end of file diff --git a/snippets/generate_hundred.json b/snippets/generate_hundred.json deleted file mode 100644 index 1e1a6f7..0000000 --- a/snippets/generate_hundred.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"generate_hundred","description":"Scala program to print numbers from 1 to 100 using for loop with until to determine loop range.","language":"Scala","code":["object ExampleForLoop2 {"," def main(args: Array[String]) {"," var counter: Int=0;"," "," for(counter <- 1 until 101)"," print(counter + \" \");"," "," // to print new line"," println();"," }","}"],"id":13,"tags":["math"]} \ No newline at end of file diff --git a/snippets/import_cleaning.json b/snippets/import_cleaning.json deleted file mode 100644 index a17f6c2..0000000 --- a/snippets/import_cleaning.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"import_cleaning","description":"Import statements for cleaning.","language":"Python","code":["# Importing the necessary libraries.","import pandas as pd","import numpy as np"],"id":4,"tags":["import statements"]} \ No newline at end of file diff --git a/snippets/life_exp_eur_asia.json b/snippets/life_exp_eur_asia.json deleted file mode 100644 index 432ec0c..0000000 --- a/snippets/life_exp_eur_asia.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"life_exp_eur_asia","description":"Find countries in North America or Europe and Central Asia with a life expectancy in 2016 of 75 to 80.","language":"R","code":["eur_na_75_80 <- longevity %>%"," filter(life_expect > 75 & life_expect < 80 & (region == \"Europe & Central Asia\" | region == \"North America\")) %>%"," arrange(desc(life_expect))"],"id":9,"tags":["Countries Project"]} \ No newline at end of file diff --git a/snippets/lorenz_deriv.json b/snippets/lorenz_deriv.json deleted file mode 100644 index 0bfe63e..0000000 --- a/snippets/lorenz_deriv.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"lorenz_deriv","description":"Math equation for lorenz.","language":"Python","code":[" def lorenz_deriv(x_y_z, t0, sigma=sigma, beta=beta, rho=rho):"," \"\"\"Compute the time-derivative of a Lorenz system.\"\"\""," x, y, z = x_y_z"," return [sigma * (y - x), x * (rho - z) - y, x * y - beta * z]"],"id":2,"tags":["custom","math","lorenz"]} \ No newline at end of file diff --git a/snippets/matplotlib_import.json b/snippets/matplotlib_import.json deleted file mode 100644 index ef37f36..0000000 --- a/snippets/matplotlib_import.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"matplotlib_import","description":"Import statements to start plotting with matplotlib.","language":"Python","code":["import matplotlib as mpl","import matplotlib.pyplot as plt"],"id":1,"tags":["import statements"]} \ No newline at end of file diff --git a/snippets/matrix_lstsqr.json b/snippets/matrix_lstsqr.json deleted file mode 100644 index 8b3825a..0000000 --- a/snippets/matrix_lstsqr.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"matrix_lstsqr","description":"Math equation for least squares","language":"Python","code":["import numpy as np","","def matrix_lstsqr(x, y):"," \"\"\" Computes the least-squares solution to a linear matrix equation. \"\"\""," X = np.vstack([x, np.ones(len(x))]).T"," return (np.linalg.inv(X.T.dot(X)).dot(X.T)).dot(y)"],"id":3,"tags":["math"]} \ No newline at end of file diff --git a/snippets/most_frequent.json b/snippets/most_frequent.json deleted file mode 100644 index 55cdc90..0000000 --- a/snippets/most_frequent.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"most_frequent","description":"This method returns the most frequent element that appears in a list.","language":"Python","code":["def most_frequent(list):"," return max(set(list), key = list.count)"," ","","numbers = [1,2,1,2,3,2,1,4,2]","most_frequent(numbers) "],"id":5} \ No newline at end of file diff --git a/snippets/parallel_strings.json b/snippets/parallel_strings.json deleted file mode 100644 index 1282421..0000000 --- a/snippets/parallel_strings.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"parallel_strings","description":"A simple queue function to generate four random strings in parallel.","language":"Python","code":["import multiprocessing as mp","import random","import string","","random.seed(123)","","# Define an output queue","output = mp.Queue()","","# define a example function","def rand_string(length, output):"," \"\"\" Generates a random string of numbers, lower- and uppercase chars. \"\"\""," rand_str = ''.join(random.choice("," string.ascii_lowercase "," + string.ascii_uppercase "," + string.digits)"," for i in range(length))"," output.put(rand_str)","","# Setup a list of processes that we want to run","processes = [mp.Process(target=rand_string, args=(5, output)) for x in range(4)]","","# Run processes","for p in processes:"," p.start()","","# Exit the completed processes","for p in processes:"," p.join()","","# Get process results from the output queue","results = [output.get() for p in processes]","","print(results)"],"id":8,"tags":["multiprocessing"]} \ No newline at end of file diff --git a/snippets/plotting_sine.json b/snippets/plotting_sine.json deleted file mode 100644 index 03f1fdf..0000000 --- a/snippets/plotting_sine.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"plotting_sine","description":"Plotting code for sine graph using matplotlib.","language":"Python","code":["import matplotlib.pyplot as plt","import numpy as np","","x = np.linspace(0, 10, 100)","","plt.plot(x, np.sin(x))","plt.plot(x, np.cos(x))","","plt.show()"],"id":0,"tags":["math"]} \ No newline at end of file diff --git a/snippets/progress_bar.json b/snippets/progress_bar.json deleted file mode 100644 index 73f002d..0000000 --- a/snippets/progress_bar.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"progress_bar","description":"Create a progress bar.","language":"Python","code":["class ProgressBar():"," def __init__(self, width=50):"," self.pointer = 0"," self.width = width",""," def __call__(self,x):"," # x in percent"," self.pointer = int(self.width*(x/100.0))"," return \"|\" + \"#\"*self.pointer + \"-\"*(self.width-self.pointer)+\\"," \"|\\n %d percent done\" % int(x) "],"id":10,"tags":["Time"]} \ No newline at end of file diff --git a/snippets/sum_array.json b/snippets/sum_array.json deleted file mode 100644 index 155b0a1..0000000 --- a/snippets/sum_array.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"sum_array","description":"Scala program of array. Declare, print, and calculate sum of all elements.","language":"Scala","code":["object ExampleArray1 {"," "," def main(args: Array[String]) {"," "," var numbers = Array(10,20,30,40,50);"," var N:Int=0;"," "," //print all array elements"," println(\"All array elements: \");"," for ( N <- numbers ) {"," println(N);"," }"," //calculating SUM of all elements"," var sum: Int=0;"," for ( N <- numbers ) {"," sum+=N;"," } "," println(\"Sum of all array elements: \"+sum);",""," }","}"],"id":12,"tags":["math"]} \ No newline at end of file diff --git a/snippets/time_calculation.json b/snippets/time_calculation.json deleted file mode 100644 index 25d40c3..0000000 --- a/snippets/time_calculation.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"time_calculation","description":"Snippet that measures the amount of time a section of code takes to run.","language":"Python","code":["import time","","start_time = time.time()","","a = 1","b = 2","c = a + b","print(c) #3","","end_time = time.time()","total_time = end_time - start_time","print(\"Time: \", total_time)","","# ('Time: ', 1.1205673217773438e-05)"],"id":6,"tags":["Time"]} \ No newline at end of file From 3051cb1567d0c5650060a8ae8449dd525d1c3e32 Mon Sep 17 00:00:00 2001 From: jahn Date: Mon, 31 Aug 2020 15:17:01 -0700 Subject: [PATCH 3/3] code snippet v1.0.3 --- binder/workspace.json | 39 +-------------------------------------- package.json | 2 +- 2 files changed, 2 insertions(+), 39 deletions(-) diff --git a/binder/workspace.json b/binder/workspace.json index e08bbd0..b8e697b 100644 --- a/binder/workspace.json +++ b/binder/workspace.json @@ -1,38 +1 @@ -<<<<<<< HEAD -{ - "data": { - "layout-restorer:data": { - "main": { - "dock": { - "type": "tab-area", - "currentIndex": 0, - "widgets": ["notebook:Untitled2.ipynb"] - }, - "mode": "multiple-document", - "current": "notebook:Untitled2.ipynb" - }, - "left": { - "collapsed": false, - "current": "code-snippet-extension", - "widgets": [ - "filebrowser", - "running-sessions", - "command-palette", - "jp-property-inspector", - "tab-manager", - "code-snippet-extension", - "extensionmanager.main-view" - ] - }, - "right": { "collapsed": true, "widgets": [] } - }, - "file-browser-filebrowser:cwd": { "path": "snippets" }, - "notebook:Untitled2.ipynb": { - "data": { "path": "Untitled2.ipynb", "factory": "Notebook" } - } - }, - "metadata": { "id": "/lab" } -} -======= -{"data":{"layout-restorer:data":{"main":{"dock":{"type":"tab-area","currentIndex":0,"widgets":["notebook:04_00_Introduction_To_Matplotlib.ipynb"]},"mode":"multiple-document"},"left":{"collapsed":false,"current":"code-snippet-extension","widgets":["filebrowser","running-sessions","command-palette","jp-property-inspector","tab-manager","code-snippet-extension","extensionmanager.main-view"]},"right":{"collapsed":true,"widgets":[]}},"file-browser-filebrowser:cwd":{"path":""},"codeSnippetEditor:test":{"data":{"namespace":"test","codeSnippet":"{\"name\":\"test\",\"displayName\":\"test\",\"description\":\"Testing to see how it would look like if the description is really long how it will show up in the preview feature ajklsjdklsf jdshfk fjskfjlskdjf kshdjksh kfldkfl;dskf hjk khds klskf;sld hjsdhjsk ;dkfl;dsk hdjsadhjs kldkfl; hjaskdhask ioiopwiroe jdkjfldksjfldksfjs jkdsjfkdslf jksdjflkfjhdsjf\",\"language\":\"python\",\"code\":[\"def add(num1, num2):\",\" return num1 + num2\"],\"id\":1,\"bookmarked\":false}"}},"codeSnippetEditor:test_dropdown":{"data":{"namespace":"test_dropdown","codeSnippet":"{\"name\":\"test_dropdown\",\"displayName\":\"test_dropdown\",\"description\":\"testing\",\"language\":\"R\",\"code\":[\"print(\\\"yeah\\\")\",\"print(\\\"yeah\\\")\",\"\"],\"id\":5,\"bookmarked\":false}"}},"codeSnippetEditor:testing_confirm":{"data":{"namespace":"testing_confirm","codeSnippet":"{\"name\":\"testing_confirm\",\"displayName\":\"testing_confirm\",\"description\":\"yeah\",\"language\":\"python\",\"code\":[\"def add(num1, num2):\",\" return num1 + num2\"],\"id\":6,\"bookmarked\":false}"}},"codeSnippetEditor:multi":{"data":{"namespace":"multi","codeSnippet":"{\"name\":\"multi\",\"displayName\":\"multi\",\"description\":\"multiple cells\",\"language\":\"python\",\"code\":[\"def add(num1, num2):\",\" return num1 + num2\",\"print(\\\"yeah\\\")\",\"def add(num1, num2):\",\" return num1 + num2\",\"print(\\\"yeah\\\")\",\"print(\\\"yeah\\\")\",\"\",\"print(\\\"yeah\\\")\",\"print(\\\"yeah\\\")\",\"\",\"print(\\\"Hello World\\\")\",\"\",\"print(\\\"potato\\\")\"],\"id\":9,\"bookmarked\":false}"}},"codeSnippetEditor:safari_test":{"data":{"namespace":"safari_test","codeSnippet":"{\"name\":\"safari_test\",\"displayName\":\"safari_test\",\"description\":\"testing safari\",\"language\":\"python\",\"code\":[\"\"],\"id\":0,\"bookmarked\":false}"}},"@jupyterlab/settingeditor-extension:plugin":{"sizes":[0.25,0.75],"container":{"plugin":"@jupyterlab/extensionmanager-extension:plugin","sizes":[0.5,0.5]}},"codeSnippetEditor:jp-codeSnippet-editor-undefined":{"data":{}},"notebook:04_00_Introduction_To_Matplotlib.ipynb":{"data":{"path":"04_00_Introduction_To_Matplotlib.ipynb","factory":"Notebook"}}},"metadata":{"id":"/lab"}} ->>>>>>> 0bcdca7a092d06e5cc86018cc97881660d4c8914 +{"data":{"layout-restorer:data":{"main":{"dock":{"type":"tab-area","currentIndex":0,"widgets":["notebook:Untitled2.ipynb"]},"mode":"multiple-document","current":"notebook:Untitled2.ipynb"},"left":{"collapsed":false,"current":"code-snippet-extension","widgets":["filebrowser","running-sessions","command-palette","jp-property-inspector","tab-manager","code-snippet-extension","extensionmanager.main-view"]},"right":{"collapsed":true,"widgets":[]}},"file-browser-filebrowser:cwd":{"path":""},"notebook:Untitled2.ipynb":{"data":{"path":"Untitled2.ipynb","factory":"Notebook"}}},"metadata":{"id":"/lab"}} diff --git a/package.json b/package.json index 3f0f51f..f03fb6a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jupyterlab-code-snippets", - "version": "1.0.2", + "version": "1.0.3", "description": "EXPERIMENTAL: Save, reuse, and share code snippets using JupyterLab Code Snippets", "keywords": [ "jupyter",