{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def a = 1 //local variable\n", "b = 2 //global variable" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "ename": "groovy.lang.MissingPropertyException", "evalue": " No such property", "output_type": "error", "traceback": [ "\u001b[0;31mgroovy.lang.MissingPropertyException: No such property: a for class: script1513885590590911287145", "\u001b[0;31m\tat script1513885590590911287145.run(script1513885590590911287145.groovy:1)", "\u001b[0;31m\tat com.twosigma.beakerx.groovy.evaluator.GroovyCodeRunner.run(GroovyCodeRunner.java:71)" ] } ], "source": [ "a //error" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b //this works" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "script1513885591155231881823$_run_closure1@68beeb7c" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "//closure example\n", "timesTwo = {x -> x*2}" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "8" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timesTwo(4)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Multiplying Strings!Multiplying Strings!" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timesTwo(\"Multiplying Strings!\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "9.265358966049026E-5" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sin(3.1415)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "d18dd18ed18f" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9d49268c-dd0e-41f1-9cc3-8867e252a353", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import java.nio.charset.Charset;\n", "\n", "byte[] cp1251Bytes = new byte[3];\n", "cp1251Bytes[0] = (byte) 0xFD;\n", "cp1251Bytes[1] = (byte) 0xFE;\n", "cp1251Bytes[2] = (byte) 0xFF;\n", "\n", "byte[] utfBytes = new byte[6];\n", "utfBytes[0] = (byte) 0xD1;\n", "utfBytes[1] = (byte) 0x8D;\n", "utfBytes[2] = (byte) 0xD1;\n", "utfBytes[3] = (byte) 0x8E;\n", "utfBytes[4] = (byte) 0xD1;\n", "utfBytes[5] = (byte) 0x8F;\n", "\n", "String cp1251Str = new String(cp1251Bytes, Charset.forName(\"CP1251\"));\n", "byte[] utfBb = cp1251Str.getBytes(Charset.forName(\"UTF-8\"));\n", "for(byte b: utfBb){\n", " System.out.print((String.format(\"%x\", b)));\n", "}\n", "\n", "new Plot(\n", " title: new String(cp1251Bytes, Charset.forName(\"CP1251\")), \n", " xLabel: new String(utfBb, Charset.forName(\"UTF-8\")), \n", " yLabel: new String(utfBytes, Charset.forName(\"UTF-8\")))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "tags": [ "tg1" ] }, "outputs": [ { "data": { "text/plain": [ "5" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "3 + 2" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e4975cbc-d144-42a2-a5c0-61feae204495", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "beakerx.getCodeCells('tg1')[0].outputs" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "celltoolbar": "Tags", "kernelspec": { "display_name": "Groovy", "language": "groovy", "name": "groovy" }, "language_info": { "codemirror_mode": "groovy", "file_extension": ".groovy", "mimetype": "", "name": "Groovy", "nbconverter_exporter": "", "version": "2.4.3" } }, "nbformat": 4, "nbformat_minor": 1 }