Octave syntax highlighting in Jupyter notebook - octave

I'm running the octave kernel in Jupyter, but I'm not getting syntax highlighting in the code cells. I've installed Jupyter et. al. through Anaconda. I can't remember how I got the octave kernel installed, but probably from here:
https://github.com/calysto/octave_kernel
Do I need to do something in the kernel spec to flip on CodeMirror support?

Edit: turns out the syntax highlighting appeared after refreshing the notebook page, even without the config entry.
Leaving the answer in case it helps with other issues that people might be facing.
I managed to get syntax highlighting working for Octave by following the instructions here:
Configuring the notebook frontend
configuring the CodeMirror mode to Octave: "mode": "octave"
TL;DR
Put the following code snippet in ~/.jupyter/nbconfig/notebook.json. (If the file/directory structure is not present then create as required).
{
"CodeCell": {
"cm_config": {
"mode": "octave"
}
}
}
Caveats
I haven't tested this fully, but it seems the syntax highlighting will persist even for other languages, e.g. Python. This means that the config file might need to be disabled/deleted when using Jupyter for non-Octave notebooks.
Also, I noticed the syntax highlighting doesn't immediately show up on first load of the notebook. I had to refresh the page before it appeared.

Related

How do I solve 'Web Compiler found an error in compilerconfig.json'?

On trying to re-compile all files in a solution, using Visual Studio 2017, I get this uninformative error message:
Web Compiler found an error in compilerconfig.json
To begin with, there is more than one compilerconfig.json file in the solution.
Secondly, there is no indication whatsoever of what the error is, where it occurs (line number, for instance).
Any ideas how I can go about solving this?
In Visual Studio's Solution Explorer, right-click the compilerconfig.json file and click "Task Runner Explorer". In the left pane you will see "compilerconfig.json/all files", right-click on it and then click on "Run". You will see the details of the execution which, in my case, included the useful information about how to correct the error.
I was able to solve this issue for myself by using individual file compiling, instead of "All files".
I was getting a "Compiling successful!" message, but that didn't seem true because my compile file didn't contain my change. So here's what I did:
Open Window > Task Runner Explorer. In your left column, there is a task for "All Files". That's fine. Ignore it.
Compile your SCSS files individually. Do this by right clicking on each SCSS file in that list, and then Bindings > After Build. (Or add the task to whatever event you prefer. I chose After Build.)
Open any SCSS file in your project and add a test. I added something like #TEST2 {color: hotpink;} to my SCSS file.
Now when you save, your compiling takes a few seconds longer. Now open main.css and see if your change (#TEST2) exists in the file.
I just went through this and didn't find an easy way but I got past it.
My issue turns out to be a missing input file that was supposed to be compiled.
Method of attack:
Try to compile each compilerconfig.json file (right-click -> Web Compiler -> re-compile all files)
repeat until you find the file in question
Remove all data from this file and add entries in one at a time (or scan it to make sure your files are there, which ever fits your situation)
The root problem is that the Web Compiler didn't install successfully. I had the same problem as described in the other answers and went down a rabbit hole to figure out why I couldn't compile. Turns out I had to help the tool install itself. See this comment for details:
https://github.com/madskristensen/WebCompiler/issues/390#issuecomment-475427735
Once I did the steps listed in that comment, I able to both compile files again and was explicitly told by the tool which line of my SCSS had an error.
For an information:
I got the same error in VS2019 webcompiler. And I found a solution ie;
Project should be open as a "Web Site".
Do not open as a folder. This simple thing is solved my issue.

How do I run an R script from within RStudio's built-in R console?

I'm assuming it's like Python's import statement, but I'd like a quick answer, since I'm in the middle of an introduction class right now.
This was the closest I got, but it didn't seem to match the question, as it shows how to run an R Script from the system CLI, not the blue RStudio > prompt:
Run an R-script from command line and store results in subdirectory
Short Answer using source() function
Once you download, install, and open the RStudio, you'll see a part in the lower left with blue greater than symbols >.
In the part of RStudio's GUI with the blue >, enter the following
> setwd('/folder/where/the/file/is/')
> source('file_name')`
...output, if any, appears below...
Example:
Let's assume I have a file at /home/myusername/prj/r/learn_r/insurance_data.r that I want to run.
I would start up RStudio, and enter the following in the little window it has labeled Console:
Annoyingly long answer with screenshots using source() function
Well, it turned out to be much simpler than I expected to run this from RStudio's built-in console. I was surprised that this had not already been asked about RStudio, before. If it has, I guess I'll have a burned question.
Anyway, a little trial and error showed me how to do this:
Yay, output has appeared below.
Make sure to set your working directory, first.
I did this as follows from inside RStudio 1.0.143 on my Ubuntu 16.04 LTS environment:
setwd("~/proj/r/learn_r")
Next, you can enter help(source), you can search for the syntax of the source() function, and you can just type it in to the RStudio console for a prompt:
If you want to run a specific line from the R script, put the cursor somewhere in the line and press command+enter (on other pc I think is ctrl+enter). If you want to run the whole script or some parts, select the part and command+enter.

Unreadable Notebook NotJSONError('Notebook does not appear to be JSON: u\'{\\n "cells": [\\n {\\n "cell_type": "...',)

Getting this very strange error when I am trying to load my ipython notebook. Never had it before, and I cannot to my recollection, remember having done anything silly with ipython:
Unreadable Notebook: /path/to/notebooks/results.ipynb NotJSONError('Notebook does not appear to be JSON: u\'{\\n "cells": [\\n {\\n "cell_type": "...',)
which is followed by
400 GET /api/contents/results.ipynb?type=notebook&_=1440010858974 (127.0.0.1) 36.17ms referer=http://localhost:8888/notebooks/results.ipynb
Save yourself a headache. Open your .ipynb in any online JSON validator and it will tell you which lines have issues. I used this one.
In my case, I am using GitHub to save and share my ipython files with my teammate. When there is a conflict in the code, I had to delete those lines indicating the changes in the conflicting code such as:
>>>>>>>>head
=============
and It works for me.
This happened to me as well. I opened my data.ipynb file using notepad and found out it was blank.
I managed to recover my file by going into the hidden ipynb_checkpoints folder and copying data_checkpoint.ipynb out into my working directory.
In my Mac OS terminal
cd .ipynb_checkpoints
cp data-checkpoint.ipynb \..
Thankfully the codes were preserved. Hope this helps!
I just had the same issue after upgrading from IPython 0.13 (ish) to Jupyter 4.
The problem in my case were a few rogue trailing commas in the JSON, for example the comma following "outputs" in:
...
"language": "python",
"metadata": {},
"outputs": [],
},
After removing the commas, Jupyter/IPython could again read the notebook (and upgraded it to version 4). I hope this helps.
The easiest way to recover corrupted Jupyter notebook files, whether it contains text or not (size = 0KB), is to go to the project folder and display the hidden files. Once the hidden files are displayed, you will see a folder named '.ipynb_checkpoints'. Simply open this folder and take the file you want!
Visual studio code procedure
This is my procedure that usually avoids me groping in the dark.
I installed a json parser validator like this one.
Open the file and save a copy as .json file.
Open the json and look for the errors.
Save it back to the .ipynb extension.
Usually, I manage to fix the errors quickly.
Jupyter autosaves in a specific way. It means You have accidentally closed the notebook before properly saving it.
You need to look for three things -
Search for <<<<<<< and delete those lines.
Search for ====== and replace those lines with ,.
Search for >>>>>>> and delete those lines.
It will work fine after this.
this can be changed to reformat your ipynb file to readable in jupyter notebook. check your other ipynb files(open in notepad) which are working fine with your jupyter notebook, check and compare at the end of the files in notepad. there you can reformat the file which is not working.
I had this issue from accidentally saving as .txt from github and solved by deleting .txt (leaving .ipynb instead of .ipynb.txt when downloading)
Yes, the best solution for me was I saved my notebook in HTML format, then opened it in Notepad ++ , delete the long repeated lines of output which were causing my notebook to grow to 45MB, once that cleared, Saved the file back into (.ipynb) format , and was able to opened it with no JSON error.
Hope that worked for others as well!
Got this error after conflicts while pushing my code to Github. The code present on the repo was old, and my changes were stashed. Notebook wasn't opening in either Jupyter and github repo. Following above comments, I searched for the part in my code which was giving JSON error,i.e. '<<<<<<<<<<<', '=======' and '>>>>>>>>>>' characters using an online json parser. Then I opened my .ipynb notebook in notepad++ and manually replaced these characters with blank string ''. After this, the notebook opened on my local Jupyter, and I also pushed the changes to Github.
I have changed by ipynb file encoding from UTF-8-BOM to UTF-8, and then it worked.
My native language is not English, but because this problem helped me a part, I came to feedback my solution.
The following is translated with translation software:
Fundamentally, the file format is messed up due to wrong closing. When opening, the correctness of the json format will be checked first, and an error will be returned if it is found to be wrong.
The mess in my file format is not <<<<< or ====== but the lack of commas.
Either way, it's best to use a piece of software to detect errors in the json syntax, and then manually fix it yourself.
The json website detection provided by the highest praise is available, but the detection errors are not complete, and may need to be detected-modified-detected-modified.
Also use vscode to open the file, vscode will prompt the location of the json syntax error, which is also incomplete and needs to be checked and modified multiple times.
The error location provided is more difficult to find. I use nodepad++, and the lower right corner can display how many characters are selected (standard, including line breaks). Then select from the first character until the destination position.
Although it's a bit stupid, the main reason is that I didn't find the relevant positioning method.
Clear all outputs.
Then copy the notebook.
If you use Jupyter-Notebook in VS code, just save it in VS code, close the file and try to open it again by accessing the browser.
on ubuntu 20.04, I have file String.ipynb. I had same problem because I coded ơ [ echo 'hello' >> String.ipynb ]. deleting 'hello' in String.ipynb -> I could open my notebook like normal.
how did I delete? [ nano String.ipynb ] * move to last line (hello) * -> delete it.
I hope my answer help you :D
you will see this error may be because, you were getting merge conflict in .ipynb file. because of that git adds >>>>>>>> HEAD thing in .ipynb file which makes is unreadable.
To overcome this issue open .ipynb file in vim editor and then remove the incoming changes or your changes as per your use case.
vim <your-.ipynb-file-path>
To remove incoming changes remove content between these lines<<<<<<<<<< HEAD ==============. Note:- remove this line as well >>>>>>>>>>>> this line.
to remove your changes remove content between these lines ============== >>>>>>>>>>>. Note:- remove this line as well a <<<<<<<<<< HEAD
I had the same issue after git merge while using VS Code and Jupyter extension.
VS Code would not open the notebook after the merge conflicts were highlighted in the notebook JSON by git (e.g. <<<<<). One way around it was to highlight the changes and accept one by one using the file viewer in the VSCode git interface.
Alternative that worked for me was to rename the file to .json so that it would open and then search for each instance of <<<<< and accept the incoming change.

Sublime Text 2 - writing a script to process multimarkdown

There is an excellent package to preview markdown written using sublime text. I wanted to know how I might modify it, or perhaps use it as the basis for writing one that could process multi-markdown.
I'm using Linux (Ubuntu) and I'm currently calling multimarkdown in the terminal on each file.
One of the issues I think I might face is that multimarkdown refuses to parse an open file for some reason.
Any thoughts on how I might begin this or if an alternative solution exists would be very gratefully received.
There is a MultiMarkdown option in the syntax list - View > Syntax > Markdown > MultiMarkdown. Isn't that working? By the way the syntax (and almost any other) files are in packages folder of Sublime Text 2. This is the syntax file:
/Users/[username]/Library/Application Support/Sublime Text 2/Packages/Markdown/Markdown.tmLanguage
And MultiMarkdown file is in the same directory.
I'm intrigued by your statement that "multimarkdown refuses to parse an open file". Can you provide more information, or email me, or open an issue on github? MultiMarkdown doesn't check to see whether a file is open or not --- it simply reads the file and processes it. So if there's a problem, then the OS is not allowing MMD to proceed for some reason...
I don't have Sublime Text installed on Ubuntu (I generally use a command line only version of Ubuntu for testing MMD), so I can't test this situation exactly. I haven't had any other reports of difficulties parsing files (open or not). I don't have any trouble with Sublime Text 2 on Mac OS X and MMD.
As an alternative, you could try using one of the support scripts (e.g. mmd if you want MMD->HTML) and see if that has the same problem with open files.
PS> Are you using the latest build of MultiMarkdown, e.g. 4.2+?? (Though it shouldn't change anything related to open files)

igraph for python

I'm thoroughly confused about how to read/write into igraph's Python module. What I'm trying right now is:
g = igraph.read("football.gml")
g.write_svg("football.svg", g.layout_circle() )
I have a football.gml file, and this code runs and writes a file called football.svg. But when I try to open it using InkScape, I get an error message saying the file cannot be loaded. Is this the correct way to write the code? What could be going wrong?
The write_svg function is sort of deprecated; it was meant only as a quick hack to allow SVG exports from igraph even if you don't have the Cairo module for Python. It has not been maintained for a while so it could be the case that you hit a bug.
If you have the Cairo module for Python (on most Linux systems, you can simply install it from an appropriate package), you can simply do this:
igraph.plot(g, "football.svg", layout="circle")
This would use Cairo's SVG renderer, which is likely to generate the correct result. If you cannot install the Cairo module for Python for some reason, please file a bug report on https://bugs.launchpad.net/igraph so we can look into this.
(Even better, please file a bug report even if you managed to make it work using igraph.plot).
Couple years late, but maybe this will be helpful to somebody.
The write_svg function seems not to escape ampersands correctly. Texas A&M has an ampersand in its label -- InkScape is probably confused because it sees & rather than &. Just open football.svg in a text editor to fix that, and you should be golden!