Skip to content

Instantly share code, notes, and snippets.

@shuxiaokai
Forked from nmichlo/colab_vscode.py
Created October 4, 2022 09:59
Show Gist options
  • Save shuxiaokai/8a5f6baf9c3ee017cfc6b973ab59b22f to your computer and use it in GitHub Desktop.
Save shuxiaokai/8a5f6baf9c3ee017cfc6b973ab59b22f to your computer and use it in GitHub Desktop.

Revisions

  1. @nmichlo nmichlo revised this gist Sep 8, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion colab_vscode.py
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    # run vscode in background if needed
    !(ps -ef|awk '/code-server/&&!/awk/{exit 1}') && (nohup code-server --port 9000 --auth none &)

    # run ngrok tunnel
    # run ngrok tunnel if needed
    from pyngrok import ngrok
    if not ngrok.get_tunnels():
    ngrok.connect(port=9000)
  2. @nmichlo nmichlo revised this gist Sep 8, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions colab_vscode.py
    Original file line number Diff line number Diff line change
    @@ -3,10 +3,10 @@

    # install deps if needed
    !(command -v "code-server" 1>/dev/null) || (curl -fsSL https://code-server.dev/install.sh | sh && echo)
    !(python -c "import pyngrok" 2>/dev/null) || (pip install -qqq pyngrok && echo)
    !(python -c "import pyngrok" 2>/dev/null) || (pip install -qqq pyngrok)

    # run vscode in background if needed
    !(ps -ef|awk '/code-server/&&!/awk/{exit 1}') && ((nohup code-server --port 9000 --auth none &) && echo)
    !(ps -ef|awk '/code-server/&&!/awk/{exit 1}') && (nohup code-server --port 9000 --auth none &)

    # run ngrok tunnel
    from pyngrok import ngrok
  3. @nmichlo nmichlo revised this gist Sep 8, 2020. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions colab_vscode.py
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,11 @@
    # Copy this script into a colab cell

    # install deps if needed
    !(command -v "code-server" >out) || (curl -fsSL https://code-server.dev/install.sh | sh && echo)
    !(python -c "import pyngrok" >out) || (pip install -qqq pyngrok && echo)
    !(command -v "code-server" 1>/dev/null) || (curl -fsSL https://code-server.dev/install.sh | sh && echo)
    !(python -c "import pyngrok" 2>/dev/null) || (pip install -qqq pyngrok && echo)

    # run vscode in background if needed
    !(ps -ef|awk '/code-server/&&!/awk/{exit 1}') && (nohup code-server --port 9000 --auth none &)
    !(ps -ef|awk '/code-server/&&!/awk/{exit 1}') && ((nohup code-server --port 9000 --auth none &) && echo)

    # run ngrok tunnel
    from pyngrok import ngrok
  4. @nmichlo nmichlo created this gist Sep 8, 2020.
    18 changes: 18 additions & 0 deletions colab_vscode.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    # Adapted from https://amitness.com/vscode-on-colab
    # Copy this script into a colab cell

    # install deps if needed
    !(command -v "code-server" >out) || (curl -fsSL https://code-server.dev/install.sh | sh && echo)
    !(python -c "import pyngrok" >out) || (pip install -qqq pyngrok && echo)

    # run vscode in background if needed
    !(ps -ef|awk '/code-server/&&!/awk/{exit 1}') && (nohup code-server --port 9000 --auth none &)

    # run ngrok tunnel
    from pyngrok import ngrok
    if not ngrok.get_tunnels():
    ngrok.connect(port=9000)
    print('CONNECT:', ngrok.get_tunnels()[0].public_url)

    # kill ngrok & vscode
    !echo !kill $(ps -ef|awk '/ngrok|code-server/&&!/awk/{print $2}')