Is there a way to run powershell scripts with a typewriter effect output? - powershell-5.0

this is more so for fun and "cool" factor, something to imitate hollywood style tech scenes.
say i have a script that does a bunch of things and outputs as write-host/verbose.
i would like to get a typewriter effect for all these outputs, as if each line is getting typed.
of course i can probably wrap every write-host/verbose into something like the answer on this thread mentions, but is there a different way to do this much easier? my script is like a 1000 lines and i dont wanna go through all outputs i have wrapping them up this way. besides, i also tee to a file so i dont wanna break any of that output either.
i do hope there is an easy wrapper around the entire script perhaps? or maybe something i can activate in the powershell console configuration/settings?

Related

Sizeable screenshot UI code

I am in need of someway to access the UI for the screenshot command in OSX (Cmd+Shft+4) and I would like to be able to activate the UI with a UI button that will screenshot the region selected and save it to a temp location.
Thanks in advance ;)
If there's a direct way to do this from Cocoa, maybe someone will chime in... but I doubt it exists. You can, however, get any behavior you want from the "screencapture" command line utility; it does exactly the same as Cmd-Shift-3 or 4 with a gazillion options. Just type "man screencapture" in Terminal to see all the flags.
But this would require you to run a bash script from your app. If you haven't done that before, well, google it, or check out the many threads here on SO... Opinions vary on how complicated it should be, from a one-liner call to system() to fully thread-safe error reporting NSTask and all kinds of answers in between.
I'd recommend using one of the NSTask answers which keep themselves to half a dozen lines, but YMMV.

In Go when using the Example... testing method is there a way to have it show a diff instead of got... want...?

I've been using go for a bigger project and love it, and for my testing i've been using the
func ExampleXxx {
... code ...
//Output:
//...expected output ...
}
method for testing. When it fails it will say
got:
... bunch of lines showing the output of test ...
want:
... the comment you put in to show what you expected ...
is there any way to make it show just the difference? I can take the two and copy to separate files and run a diff etc, but I'd much rather just have it show the parts that were wrong as some of my tests have longer output.
Thanks in advance
EDIT:
I'm using http://golang.org/pkg/testing/#hdr-Examples and want the output to show a diff not the current output. I know I can do the diff manually.
No, you cannot do this. This is not the intended use of Examples.
Examples are a nice way to show how some function will behave: Examples exists to document. The main reason for validating the example output is to make sure the Examples are valid/correct, not that your code is okay. For the later you have Test functions
Most often the output of an Example displays input and output (or just output) of one invocation of a certain function/method per line; sometimes Examples use the different lines to show parts of a complex result, e.g. one line per element of the returned slice.
I think your use of Examples to "verify the flow of my program" contradicts the intention of Examples. I would use Test functions and use any of the available diff tools to generate a got, want, diff output myself if I'd like to test e.g. a text processor on large bunches of input.
If I understand your question correctly, it sounds like GoConvey would do the trick... It's a TDD tool that runs in the browser, and it will show you colored diffs for most failures:
You can use it with your existing tests; if you don't want to convert to the GoConvey DSL, that's okay. You don't have to be using a TDD workflow per-se in order for it to work, but if you can run go test, this tool should be able to pick it up. (I've never used the Example functions for testing... I'm not sure what you mean by that, honestly.)
(There's a new web UI in the works that will still show the diff. See below.)
These are contrived examples, but obviously the diff is more useful with longer output.
Is that kind of what you're looking for?
From the style guide: https://code.google.com/p/go-wiki/wiki/Style#Useful_Test_Failures
if got != tt.want {
t.Errorf("Foo(%q) = %d; want %d", tt.in, got, tt.want) // or Fatalf, if test can't test anything more past this point
}
This will put out only errors of course. There is nothing built into go that lets you show the diff. I think just piping this to whatever diff tool you are using against your last output would still be best.
Go is great, but no reason to re-invent tools that already do fantastic jobs that already exists at the terminal.

Ipython QtConsole %edit

When using the magic function %edit from QtConsole with IPython, the call does not block, and does not execute the saved code. It does however save a temporary file...
I think this is intended behavior due to GUI editors and uncertainty, and whatever that reason is for not being able to communicate with subprocess (pyZMQ?).
What do you suggest as the best way to mix %edit/%run magics?
I would not mind calling two different commands (one to edit, and one after I have saved and execution is safe). But those commands need a way to synchronize this target file location, or someone to persist storage, and probably need some crude form of predicatably generating filenames such that you can edit more than one file at a time, and execute in arbitrarily. Session persistence is not a must.
Would writing my own magic do any good? Hope we can %edit macros soon, that would do well enough to make it work.
you shoudl be able to do %edit filename.py and %run filename.py. The non blocking behavior is expected, and IIRC due to technical reason. Not unsurmountable but difficult.
You could define your own magic if you wish, improvement are welcomed.
Hope we can %edit macros soon, that would do well enough to make it work.
For that too, PR are welcomed. I guess as a workaround/option you can %load macro which would put macro on input n+1 , edit it and redefine it, that might be a good extension for a cell magic %%macro macroname
If you have some executable code on your input (from QtConsole), you can type
%edit 1-5
This fires the editor, creates a temporarily file (automatically managed), and loads your input lines. This is nearly enough, now how to retrieve the name of that temp file pragmatically?
I see the print statement on Stdout, but its not visible to QtConsole AFAIK. Could maybe redirect stdout to catch that line, but that may not be an option anyway if your doing something else with stdout.
If I could retrieve the full pathname that was just created, this would be cake. Store it where some magics will know how to find it. Then issue a followup command when ready,pops the name off the stack, loads it into a macro, and run. All this with 2 input commands and no names to remember (unless you want to find and use that macro again, but for 1 shot stuff...)
How do I catch or retrieve the path of that temporary file?

Is there any interactive console for some strong language for everyday work of processing strings?

starting to work as an IT man lately
with some programing background,
there are so many occasions where there's a need for processing large amount of data.
mainly strings i guess..
for example:
there's 2 large sets of lines, and we need all the lines in both of the sets
replacing one or more white characters in a row, to one line break...
taking the 4th to 7th character of each line and print them in one line with comma as a delimiter
these are not the best examples, but generally any kind of parsing, manipulating and query of texts.
it's very often that the task is extremely easy in any programing language, but it is just to frustrating to open the IDE of such language....
i'm looking to some way to write code (with intelisence/autocomplete), in an easy fast window...... with simple input and output textboxes....
do you understand my need? can you think of anything that can help?
i know some of the problems can be solved using excel.. but i really prefer some good old programing.... unless someone is strongly believe i'm wrong.
if i will build something myself, there will be an option to add any amount of unlimited multiline textboxes. they'll be automatically named, although the name is changeable (the names will be the the name of the variables).
you can as well add any number of output textboxes that have names...
and you have the editor window, in which you write the procedure..... and it will have some interactive intelisence like interface...
can you see what i'm saying? do you know anything similar?
Seems like Python would be fine for this.
Has an interactive keyboard interface, quite nice abstraction facilities,
and strings as objects with good libraries for processing such strings.
It sounds like a lot of what you want can be handled with regular expressions using sed, awk, or perl in a standard console. Autocomplete will be pretty limited, but your scripts will be short anyway - to deal with your third case above, for example:
sed 's/^...\(....\).*/\1/g' < input.txt | tr "\n" ',' > output.csv
What you can do is use an interactive regex tester. There's many online like this one.
You could also look into tools like Data Wrangler from Stanford, which are designed to be more accesible but as powerful as traditional shell tools.
(Note that your first issue - intersecting sets of lines - is a bit different, and would be solved in the shell with comm. This page has a good explanation of how to use comm to perform set operations like "all the files in this file not in this file" or "only the files in this file also in this other file".)

Putting a 'terminal' in my application?

Are there any frameworks for say, putting a display like in Terminal.app in MY app, and then displaying text on it like usual output to STDOUT? Complete with scrollback and etc.?
You may want to look at iTerm, an open-source terminal emulator written in Cocoa. If you really want terminal emulation, you might be able to lift from that framework.
This thread has a couple suggestions. The first is very UNIX'y - you use pipe() to map stdout to a new location. Then you'd need another process or a thread that reads that pipe and displays it into an NSTextView. The other approach that I liked as it seems cleaner and less resource intensive is to replace the File_writer_t _write proc in the stdout() FILE pointer with the hook that you want, which write the output into an NSTextView.