Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d47ad58
commit 848e819
Showing
1 changed file
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
{ | ||
"nbformat": 4, | ||
"nbformat_minor": 0, | ||
"metadata": { | ||
"colab": { | ||
"name": "001_test_cicada_sockio_notebook.ipynb", | ||
"provenance": [], | ||
"private_outputs": true, | ||
"collapsed_sections": [], | ||
"toc_visible": true, | ||
"include_colab_link": true | ||
}, | ||
"kernelspec": { | ||
"name": "python3", | ||
"display_name": "Python 3" | ||
}, | ||
"accelerator": "GPU" | ||
}, | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "view-in-github", | ||
"colab_type": "text" | ||
}, | ||
"source": [ | ||
"<a href=\"https://colab.research.google.com/github/omgimdrunk/cicada/blob/master/003_test_cicada_sockio_notebook.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "XlrPVwyqCkGr", | ||
"colab_type": "text" | ||
}, | ||
"source": [ | ||
"\n", | ||
"## .: Intro to the cicada python daemon library :. \n", | ||
" \n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "loE0T33BDhtT", | ||
"colab_type": "text" | ||
}, | ||
"source": [ | ||
"### :: Install cicada and loguru ::\n", | ||
"\n", | ||
"<hr color=\"#444567\">\n", | ||
"\n", | ||
" \n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"id": "SJvKkrMxosVS", | ||
"colab_type": "code", | ||
"colab": {} | ||
}, | ||
"source": [ | ||
"!pip install https://github.com/omgimdrunk/cicada/raw/master/dist/cicada-0.5.10-py3-none-any.whl\n", | ||
"!pip install --upgrade loguru" | ||
], | ||
"execution_count": 0, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "bXu6Kyd_ySKR", | ||
"colab_type": "text" | ||
}, | ||
"source": [ | ||
" ### :: Creating client socket and threading read out ::\n", | ||
"<hr color=\"#444567\">\n", | ||
"\n", | ||
" \n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"id": "ZAIyfxPf1k18", | ||
"colab_type": "code", | ||
"colab": {} | ||
}, | ||
"source": [ | ||
"from cicada.sockio import INET_TCP\n", | ||
"from getpass import getpass\n", | ||
"import sys\n", | ||
"import time\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
"def intohere(data):\n", | ||
"\n", | ||
" sys.stdout.write(\"{}\".format(data))\n", | ||
" sys.stdout.flush()\n", | ||
"\n", | ||
"def inetguest(typeinet):\n", | ||
" \"\"\"\n", | ||
" read_into :: def read_into(self, on_read)\n", | ||
"\n", | ||
" This will dup the socket but doesn't destroy the parent!\n", | ||
" From this point on it can only read,\n", | ||
" while the parent can only write.\n", | ||
" \n", | ||
" \"\"\"\n", | ||
"\n", | ||
"\n", | ||
" with typeinet('freechess.org', 5000) as muhsock:\n", | ||
" if muhsock.as_guest():\n", | ||
" muhsock.read_into(on_read=intohere)\n", | ||
" while muhsock.is_connected:\n", | ||
"\n", | ||
" x = getpass();\n", | ||
" try:\n", | ||
" d_out = muhsock.write(x)\n", | ||
" except Exception as E:\n", | ||
" sys.stderr.write(\"[{}] : {} {} !err \\n\".format(time.time(), E, d_out))\n", | ||
" sys.exit()\n", | ||
"\n", | ||
" \n", | ||
"inetguest(INET_TCP)\n", | ||
"\n" | ||
], | ||
"execution_count": 0, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"id": "pUfwaxOh1UKR", | ||
"colab_type": "code", | ||
"colab": {} | ||
}, | ||
"source": [ | ||
"" | ||
], | ||
"execution_count": 0, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "qX9xZFvk_Ini", | ||
"colab_type": "text" | ||
}, | ||
"source": [ | ||
"### :: Compile C and link to py quickly\n", | ||
"<hr color=\"#444567\">\n", | ||
"\n", | ||
" \n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"id": "aK39BZmd62ZS", | ||
"colab_type": "code", | ||
"colab": {} | ||
}, | ||
"source": [ | ||
"!echo -e ' #include <stdio.h> \\n int main(){ printf(\"%s\", \"aaaannnnndddd we have a SUPA C COMPILA!\"); return 0; }' > gcctest.c\n", | ||
"!gcc gcctest.c -o gcctest.o\n", | ||
"!./gcctest.o" | ||
], | ||
"execution_count": 0, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "IM5OLSuQ_uVN", | ||
"colab_type": "text" | ||
}, | ||
"source": [ | ||
"# New Section" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"id": "iz4HDHat_vYP", | ||
"colab_type": "code", | ||
"colab": {} | ||
}, | ||
"source": [ | ||
"!ls -lth\n", | ||
"!uname -m" | ||
], | ||
"execution_count": 0, | ||
"outputs": [] | ||
} | ||
] | ||
} |