IPython cell_magic access to cell id - jupyter-notebook

We implemented an IPython extension using the #magics_class (and #line_magic and #cell_magic) annotations. It is working quite well for the most part, with one important limitation. #cell_magic only gets the cell contents as an argument, but we need a way of identifying the actual cell somehow.
I suspect IPython would internally have an identifier for each cell, but this is not passed into the cell magic as far as I can tell.
The reason for needing this is because we want different functionality depending on whether the call is the result of an edit or whether it's a new cell.
Thanks!

Related

How can I create a copy of a notebok with all (or most) code cells emptied?

I want to create Jupyter notebooks for teaching, which shall be delivered in two versions:
A full “textbook” with explanations in markdown cells and example code in code cells.
As above, but with most code cells being empty such that the students have to type all the code themselves.
Obviously, I do not want to do this manually in Jupyter, so I need a way to automatically clear those code cells (exceptions are rare and can be marked somehow).
Given that notebooks are stored as sources of Python objects, I could write a simple script to directly modify those.
However, this feels like I am re-inventing the wheel instead f using some existing, dedicated method – which what I am seeking in this question.
I briefly considered using NBGrader. However, while I am quite confident that this could solve my problem, it seems overkill for this purpose and require extra effort to make things work.
Have you checked out Chris Holdgraf's nbclean?

Vaadin numeric field?

Is there a DoubleField or LongField Vaadin 7? I see a TextField and PasswordField, so it sort of shocked me when I did not see fields for numeric types. This seems so standard, especially since GWT has such fields under the hood, that I feel like I am missing something.
Also, there are some numeric field add-ons, but most of them say they don't support Vaadin 7, which leads me to believe there is some standard way to do it in Vaadin 7 already. Am I missing something?
I couldn't find a way either but I created my own with a custom TextChangeListener. Basically you override the method textChange(TextChangeEvent event) to check if the value is valid. If it's not valid then you delete it. Just be careful to adjust the cursor appropriately. I created a listener for integers (with max/mins), one for doubles, percentages, etc. Basically any kind of number validation you need. The tricky part is managing the cursor position. I wish I had some sample code to show you but I don't have it available on my current computer, but at least this should give you a running start.

Adobe CQ: Make two <cq:include> with same path editable

I have two "cq:include" in same jsp with same path and I need to make both of them editable. But currently only one of them is editable.
If I change anything in one component that shows on second. But the second one itself is not editable. My requirement is to make both the components editable while keeping the include path same.
Code:
<cq:include path ="abc" resourceType="xyz"/>
<cq:include path ="abc" resourceType="xyz"/> # This one is not editable.
Having two components with the same resource type would create only a single node at the given path. Hence, any change you make in one of the component would be reflecting in both of them, as both the components would be reading from the same node.
This is also the reason for not being able to edit the second component. Try providing different paths for different components like shown below.
<cq:include path="abc" resourceType="xyz" />
<cq:include path="abc_0" resourceType="xyz" />
Similar questions have been asked here and here
The way the authoring system works it hooks per location so if you want to have it authored in two different places those two different places should NOT be on the same page. This is just good usability as it can be very confusing.
INSTEAD, I suggest the first one on the page add an attribute to the slingRequest noting that it has been placed on the page and future instances with the same path put a message on the screen saying that it is edited elsewhere. Without knowing more details it's hard to suggest the best usability for this scenario.
Update:
If you MUST do this, here is a work around.
Step 1: define a convention for naming 2 properties. e.g. realTitle (String) and realTitleLastUpdated (date/time). These will be page-level properties, making it easy to access and check them using pageProperties. Though you can do this through a subnode as well but that gets more complicated.
Step 2: For the components that must all be simulateously editable, allow them to create their own nodes. Then, on load in the EDIT environment, check the property realTitle and the lastUpdated time stored in realTitleLastUpdated
If the last edit of your component's title, e.g. jcr:lastModified is newer than realTitleLastUpdated, change the local value of title (e.g. jcr:title) to the value of the realTitle property and update the realTitleLastUpdated time to reflect the time in jcr:lastModified on your component.
If the opposite is true - realTitleLastUpdated is of a time newer than the last modification of the local component, then update the jcr:title of the component and the times to match.
Obviously if the last update times match, do nothing.
It's a bit of a run around, but this will keep everything in sync.
I realized that you may not realize that you probably need to save the state. I believe you can do this (among other ways) using resource.getResourceResolver().adaptTo(Session.class).save()
I've done this before but it's been a while. Let me know if you have issues, I'm working from memory.
Well, if you don't want author to bother about editing both the components, then you should use javascript/jquery and onChange() of one of the component, modify the value of another component as well.

Drupal 7: How can I create a key/value field(or field group, if that's even possible)?

Let's say I'm creating some app documentation. In creating a content type for functions, I have a text field for name, a box for a general description, and a couple other basic things. Now I need something for storing arguments to the function. Ideally, I'd like to input these as key-value pairs, or just two related fields, which can then be repeated as many times as needed for the given function. But I can't find any way to accomplish this.
The closest I've gotten is an abandonded field multigroup module that says to wait for CCK3, which hasn't even produced an alpha yet as far as I can tell and whose project page makes no obvious mention of this multi-group functionality. I also checked the CCK issue queue and don't think I saw it in there, either.
Is there a current viable way of doing this I'm not seeing? Viable includes "you're thinking of this the wrong way and do X instead." I've considered using a "Long text and summary" field, but that smells hackish and I don't know if I'd be setting myself up for side-effects. I'm new to Drupal.
There is the http://drupal.org/project/field_collection module but it's not yet ready. Right now you would need to implement your entity alas to do this :( not easy.
Not sure how well it would work, because it currently does a bit more (eg, forces to group pairs into categories and the keys need to be predefined) but you might want to have a look at http://drupal.org/project/properties.
You could create a these key-value fields on their own: create 2 regular fields that that can be added as often as needed.
So you have a x fields for the keys and x for the values. If this is only for you or other people it might work OK but usability wise, it's very ugly.
If you need to extract the fields from the function, to display it properly in a page template, you should propably use a different approach. Write the function with its arguemnts in a CCK field and in the template extract them as needed. The arguments are always (depending on language) in () and the different arguments are seperated by , so splitting them would by pretty easy.

Using one data source for multiple datagrids in Flex3

I want to use one data source (e.g. an Array) for multiple Datagrids that have different filterFunctions attached and show different columns.
First, I thought I use a very straight forward apporach:
create the Array
create an ArrayCollection for every DataGrid and set the "source" property to the Array
create the DataGrids and set their dataProvider property to its designated ArrayCollection
So now. every ArrayCollection can have its own filterFunction, sort state etc. but there needs to be only one Array with all the data in memory.
Now to the point that totally confused me:
As new items are added to the Array, of course no Events are dispatched and I have to call itemUpdated manually on each of the ArrayCollections. While debugging into the code in order to get a deeper understanding for Flex, I tried to figure out, what this misterious "itemUpdated" method does, especially as it notes in the adobe documentation, that, if no "property" is given (e.g. it is null), a simple "refresh()" will occur.
I did not find any calls to "refresh()" in the whole debugging (and I went down the framework whole as deep as possible (btw: lots of funny comments right in the code :-) )).
The only thing I could find was a CollectionChangeEvent getting dispatched with a PropertyChangeEvent in its "item" property. Which was of the kind "UPDATE" (and not, as I would expect "ADD"). When trying to dispatch that event manually, it never worked (e.g. the datagrid did not update).
I know I have to stick with itemUpdated for the moment, but as the dataprovider can get big (in both dimensions), performance does concern me and I wnat to understand what is going on under the hood.
And as expected, no help from adobe :-(
So a big thanks for everyone who read this whole text.
And an even bigger THANKS to anyone who answers and gives me the slightes hint in how I can get out of the confusion and understand (if thats possible at all) Fles a little better.
finest of all regards,
herbert
You have to call ArrayCollection.refresh() for each of your dataProviders to get the dataGrids to show the new changes to the source array.

Resources