How can I clear the output portion of the Command Center.? - netlogo

Is there a command to clear the output portion of the Command Center? I can't find one in the user-guide -- only commands to clear a separate output area if one was defined.
I'm using NetLogo 6.1.1. in Windows 10.
I don't have a separate output section defined. The command "clear-output" doesn't clear the output portion of the Command Center.
I tried making a separate output section on the interface, and print-output and clear-output work fine on it. But without a separate area, print-output goes to the command center but clear-output doesn't clear it.
Manually pushing the "clear" button on the interface does clear it.
Am I missing something obvious?
Manually entering these commands in the command center does not clear it:
print "x"
clear-output
Doing it from inside code doesn't seem to work either
to setup
clear-all
reset-ticks
end
to go
if (ticks > 4) [stop]
print ( word "line one at tick " ticks)
if (ticks > 3 ) [clear-output]
tick
end

The answer is "you can not". You can put an "Output" on the interface tab and use output-print instead of print. This way clear-output works perfectly.

Related

NppExec in Notepad++ to "Run a Macro Multiple Times..."

I use simple NPP_Exec commands in N++ which work fine for macros. Eg.:
NPP_MENUCOMMAND Macro/Action1
NPP_MENUCOMMAND Encoding/Convert to ANSI
NPP_SAVE
But how can I run a specific macro several times?
I have tried NPP_MENUCOMMAND Macro/Run but then I still have to manually select the macro I need and set it to "Run until the end of line" in the pop-up window.
You can use the NppExec plugin for simple loops like this:
:REPEAT
SCI_SENDMSG SCI_GETCURRENTPOS
set pos1 = $(MSG_RESULT)
// put your Macro invocation here instead of the linedown:
SCI_SENDMSG SCI_LINEDOWN
SCI_SENDMSG SCI_GETCURRENTPOS
set pos2 = $(MSG_RESULT)
// if the linedown (or your macro) doesnot give another pos, we have reached the end
if $(pos1) == $(pos2) goto END
// else loop
goto REPEAT
:END
it stores the current position
then it does something that advances the position (in this example a linedown, you would put your Macro invocation there, make sure it changes the cursor position)
then the position is compared with the stored position; we have reached the end, if the position has not changed;
in this case we leave the loop
I just found a simple and easy solution for that. I did not use command lines but it might work as well:
Make sure the macro ends with a Ctrl-Tab key
From Settings -> Preferences -> MISC, disable the doc switcher.
Open all files to be edited.
Use the "Run macro multiple times" dialog, and enter the number of files you have just opened.
Execute
Save all
I did not create this, found it here:https://sourceforge.net/p/notepad-plus/discussion/331754/thread/469ffec9/ , but it worked like a charm for me. I could edit 400 documents in less than 2 min.
I found another way to achieve this. Inspired by Wagner Fontes's answer, we can do the following:
Step 1: Record your Macro
Step 2 (Important): Before you finish the Macro, type the "Ctrl + Tab" as the last record in the Macro. This hotkey means moving to the next opening text file.
Step 3: Save the Marco.
Because of the Step 2, Notepad will move to the next text file after running the macro once. In this method, "Run a Macro Multiple Times" makes "Multiple Files".

Seeing which part of code MatLab is currently running [duplicate]

Is there any way to stop the execution of a matlab program from the debugger like ctrl+c does, but then being able to continue execution (like you can in say c#)?
If not, is there any better way to workaround this other than trying to pre-emptively set break points or dbstop statements in your matlab code?
I would like to be able to interrupt a long running simulation to look at the current state and then continue the simulation.
The two options I'm currently using/considering are
dbstop commands (or (conditional) breakpoints) in the code.
Drawback is that sometimes I don't want to stop the simulation for a few hours, sometimes want to stop after only a few seconds (and I don't necessarily know that in advance) and this doesn't work well with this approach: If I set the break condition to break every 5 minutes, I can't leave matlab running for hours without interaction. If I set the condition to higher, I have to wait too long for the condition to hit.
include code to save the workspace every few seconds/minutes and import the workspace into a second matlab instance. Drawback is that this is a huge hassle and also doesn't necessarily allows me to resume the simulation with the state of the saved workspace then step through the code for a few iterations.
I'm hoping there is a better solution than either of the 2. Thanks for any advice!
Edit: I think what I'm going to do is write simple matlab function that checks an environment variable or a file on disk every iteration and calls dbstop if I set a flag in this file or env. This way I can control when (and if needed which of several) the breakpoint hits from outside matlab by editing the file. Messy, but should work.
This is not necessarily the best way, but you could simulate a file-based signal/interrupt framework. It could be done by checking every once in a while inside the long simulation loop for the existence of a specific file. If it does, you enter interactive mode using the keyboard command.
Something along the lines:
CHECK_EVERY = 10; %# like a polling rate
tic
i = 1; %# loop counter
while true %# long running loop
if rem(i,CHECK_EVERY) == 0 && exist('debug.txt','file')
fprintf('%f seconds since last time.\n', toc)
keyboard
tic
end
%# ... long calculations ...
i = i + 1;
end
You would run your simulation as usual. When you would like to step in the code, simply create a file debug.txt (manually that is), and the execution will halt and you get the prompt:
2.803095 seconds since last time.
K>>
You could then inspect your variables as usual... To continue, simply run return (dont forget to temporarily rename or remove the file). In order to exit, use dbquit
EDIT: Just occurred to me, instead of checking for files, an easier solution would be to use a dummy figure as the flag (as long as the figure is open, keep running).
hFig = figure; drawnow
while true
if ~ishandle(hFig)
keyboard
hFig = figure; drawnow
end
%# ...
pause(0.5)
end
With the release of R2016a, you can just hit the Pause button in the code editor and it will halt right away. The keyboard shortcut is Ctrl+F5.
To pause the execution of a program while it is running, in the Editor tab, click the Pause button. MATLAB pauses execution at the next executable line*.
When your code is running, the Start button will turn into a pause:
Another change with this release is the ability to add/remove breakpoints while running. Previously you couldn't do this, apparently.
You can set a conditional breakpoint in the MATLAB Editor. You can also use DBSTOP to do this. For example, this will set a conditional breakpoint in the file myFcn at line 20 which will stop execution when a loop variable i is a multiple of 500:
dbstop in myFcn.m at 20 if rem(i,500) == 0
Then you can continue execution after you inspect some of your variables.
If saving the workspace to a file is a good proxy for what you want, how about making a simple GUI with a toggle button. In your code, check the state of the button. If the button is depressed, save the state, update a static text to reflect time stamp of last save, unpress the button. Optionally, have a conditional breakpoint based on the state of that toggle button.
Here is an alternate solution using the waitinput File Exchange submission.
The advantage is that you can use it from whithin the current session or in cases where it is troublesome to set up a file. Also it won't leave a file behind on the computer.
The downside is there as well unfortunately, you need to wait for the checking moment before you can terminate and it costs a little bit of time.
for t = 1:10
pause(3) %Doing some calculations
str = waitinput('Enter 1 if you want to stop ',5);
if ~isnan(str)
keyboard; % Enter dbcont if you want to continue from here
end
['moving on, it is now: ' datestr(now)]
pause(3) %Doing some more calculations
end
If you want, you can prevent lines being printed to the screen. In this case you need to enter the input at the time the figure window is open (Look in your start bar on windows).
To summarize, the short code that you can put somewhere like a conditional breakpoint would be:
if ~isnan(waitinput('',5))
keyboard;
end
After certain version (I don't know which one exactly):
Windows: Ctrl + F5
Mac: Command + F5 (I guess)
Unix: I am looking for answer too
After 2016a, there is a button for that on the interface too.

How do I reset the Jupyter/IPython input prompt numbering?

I just wrote my first extensive Python tutorial using IPython notebooks. All went well, except I did a lot of testing and moving blocks around. How do I reset the In [ ]: numbering? I have tried quitting and reloading, but that doesn't seem to work.
I think, the only way to to what you want is:
- 'Kernel > Restart' (restart the kernel) and then 'Cell > Run All' (run the script).
Every .ipynb file can be opened in an editor. Everything written there is in plain text (JSON). For each cell which has the "cell_type": "code" there'd be another key-value pair as "execution_count": <number>. As you might have guessed, that is the prompt numbering. Hence, if the notebook contains code which will take time to execute (as was, in my case) this method would be time efficient.
Now, either you can manually change each execution_count or write a simple script to get the numbering right. To check the results just refresh the notebook in the browser without stopping the kernel. And, everything will be as per your needs, even all the variables/loaded data will remain in the environment.
You can reset the kernel (shortcut: C-m .) and re-run the whole notebook.
Quitting and reloading doesn't work because the code is not re-evaluated.
'Kernel' -> 'Restart & Run All'
Just make sure you saved your Notebook. You can also bind/assign keyboard key for running this command.
'Help' -> 'Edit Keyboard Shortcuts'
If what you want is to remove the numbers themselves, so that each cell shows In [ ] (instead of something like In [247] which is leftover from some previous incarnation of the kernel), use "Cell" > "All Output" > "Clear" (in Jupyter Notebook 5.4.0) or "Edit" > "Clear All Outputs" (In Jupyter Lab 0.32.1).
This will remove all the numbers, even if you're in the middle of running a notebook. It will not reset the numbering back to 1; e.g. if the last cell you executed was 18, the next will be 19.
If you're using this because you want clarity about which cells you've executed during this run of the kernel and which cells you haven't executed yet, use "Cell" > "All Output" > "Clear" (or "Edit" > "Clear All Outputs") immediately after you start (or restart) the kernel. This can be useful when restarting a kernel, or when opening a saved or duplicated notebook.
This will also remove all outputs from the notebook.
Thanks to user2651084 in a previous comment for this.
I'm a bit too late, but I had the same problem, and since my notebook had cells with execution time up to 5 minutes, I had to wait a long time until Restart & Run All finished.
So I've made a Python script to make this task for me:
import json
file = '/your/notebook/path/Notebook.ipynb'
# Since every notebook is actually a JSON (JavaScript
# Object Notation), then its contents can be represented
# in a dictionary (or a list of dictionaries)
with open(file, encoding='utf-8') as f:
nb = json.load(f)
count = 1
for cell in nb['cells']:
# Markdown cells doesn't have execution count,
# so apply this only to cells that have one
if 'execution_count' in cell:
cell['execution_count'] = count
count += 1
# Not all code cells have output, such as functions
# that return None or simple declarations, so apply
# this only to cells that have some output
try:
for output in cell['outputs']:
if 'execution_count' in output:
output['execution_count'] = cell['execution_count']
except KeyError:
continue
with open(file, 'w+') as f:
json.dump(nb, f, indent=2, ensure_ascii=False)
But be careful with the execution order and the variables in your cells, since applying the script above on your notebook can generate a different output if you run the notebook again. For example, let's suppose your notebook have the following cells with the execution order in square brackets:
In [2]: a = 1
In [1]: a = 2
In [3]: a
Out[3]: 1
If you apply the above script into your notebook, it'll show the following:
In [1]: a = 1
In [2]: a = 2
In [3]: a
Out[3]: 1
But if you run the notebook again, it'll show the following:
In [1]: a = 1
In [2]: a = 2
In [3]: a
Out[3]: 2
This can be a bit confusing for people who are downloading your notebook via GitHub for example, since they can see an output in the repository, but when they run on their machine, the output will be different.
Cell > All Output > Clear Clear all In []: numbers but do not reset them back to 1 for the next cell you run.
Kernel > Restart & Clear Output Restart the kernel, clear output, clear In []: numbers and reset them to 1, and clear output.
Restart & Run All isn't a good solution, because simply I don't want to run all (and that's the purpose of a notebook to run things cell by cell).
Anyways, I found this solution more plausible:
Main Menu > Cell > All Output > Clear
For those coming from Google:
%reset
This is useful when you want to reset all variables after a certain point in the notebook. It is going to ask if you are sure that you want to reset. If you want to force reset without asking, then use:
%reset -f
Here is how to clear the execution numbers to [ ] without re-running the whole notebook:
Just to be safe, make a copy of your notebook:
cp notebook.ipynb notebook_copy.ipynb
Open your notebook with vim:
vim notebook.ipynb
In vim, reset the execution numbers with the following search-replace command:
:%s/"execution_count":.*/"execution_count": null,/gc
You will then get the following prompt. Type a to replace all occurrences:
replace with "execution_count": null, (y/n/a/q/l/^E/^Y)? a
Save notebook and quit vim:
:wq

Dr Racket fails when trying to create ]

I'm playing around a bit with DrRacket in the BSL language.
When I'm trying to create a comment like so:
;; Hi(10, 50]
The program fails in the moment when typing the ]. I can only end it via TaskManager. It uses 13 CPU in the TM.
Has anyone of you a solution for that? or is it simply not to use ].
Thank you
This is some bug that was reported several times recently, and there's no fix, yet. It's probably a result of some non-english keyboard layout (which was the case in these reports). Hopefully it will get fixed soon...
UPDATE: The bug was fixed for the next release, but in the meanwhile Matthew posted some instructions on how to do a temporary fix -- repeated here for reference:
We have tracked down a problem that occurs when the AltGr key is needed
to type ].
DrRacket gets stuck due to a bad implementation of an operation that is
intended to be bound to Alt-]. For most of you, though, the problem is
that you didn't want the Alt-] keybinding at all; you're just trying to
type ], and it's misinterpreted as Alt-].
You can work around the problem by placing the five lines at the end of
this message in a file, and then selecting the file via the
Edit -> Keybindings -> Add User-defined Keybindings...
menu item in DrRacket. Typing ] should work immediately after, and
typing [ will also give you just [ (instead of [ and ]).
Beware that after you select the file, it will be difficult to unselect
it. It turns out the the menu item to un-select a keybindings file is
also buggy! Your best bet is to put the file in a place that it can
stay. (You can still edit the file and restart DrRacket if you just
want to drop the bindings.)

Adding A Quartz Composer Macro to the Patch Creator

Can I add a macro in Quartz Composer to the Patch Creator, so I can add it to all my compositions?
Yes. There are two ways you can do this:
Save the macro as a composition, and place the composition file in <your home folder>/Library/Graphics/Quartz Composer Patches. After you restart Quartz Composer, it'll appear in the Patch Creator.
Caveat: When you use a macro saved this way, a reference is created (rather than copying the actual contents of the macro), so you'll need to manually install the macro in order for it to work.
In Mac OS 10.6 and later, you can create a Virtual Macro. Select the patches you want to make into the Virtual Macro, go to the Editor menu, and "Add to Library".
Caveat: When you use a Virtual Macro, a copy will be embedded with the using composition, however these compositions will only work on 10.6 and later.
smokris has a good response although I find myself having to read it several times to get what it means! If you want to build a single patch out of pre-existing patches: Hit Add to Library, making sure you have selected all the patches you want to consolidate and the published the inputs outputs you want, etc (smokris option 2). I've made some of these "power patches" with only the relevant parameters/features I want. You lose the individual patches you've connected, which is maybe ok to make things concise.
IF you want to preserve the entire composition and configured patches so you can tweak and rewire them, then manually import it (smorkis option 1). What a hassle!
--BUT it doesn't have to be. If you use Automator, you can include an Apple Script step to do all the importing for you! For example, write one that:
*get specified finder items (your qtz composition you want to import)
*opens finder items
*run apple script:
on run {input, parameters}
tell application "Finder"
do shell script "jay is incredible"
end tell
tell application "System Events"
keystroke "a" using command down
keystroke "c" using command down
keystroke "`" using command down
keystroke "v" using command down
delay 1
end tell
return input
end run
*open finder items
*run apple script:
on run {input, parameters}
tell application "System Events"
keystroke "w" using command down
end tell
return input
end run
That way, you can open that Automator application via Spotlight (command spacebar) and it'll import the composition in 1-2 clicks. Awesome huh!!