How do I print colored text to the terminal in Rust?

You can use the colored crate to do this. Here is a simple example. with multiple colors and formats: use colored::Colorize; fn main() { println!( “{}, {}, {}, {}, {}, {}, and some normal text.”, “Bold”.bold(), “Red”.red(), “Yellow”.yellow(), “Green Strikethrough”.green().strikethrough(), “Blue Underline”.blue().underline(), “Purple Italics”.purple().italic() ); } Sample color output: Each of the format functions (red(), … Read more

How is returning the output of a function different from printing it? [duplicate]

print simply prints out the structure to your output device (normally the console). Nothing more. To return it from your function, you would do: def autoparts(): parts_dict = {} list_of_parts = open(‘list_of_parts.txt’, ‘r’) for line in list_of_parts: k, v = line.split() parts_dict[k] = v return parts_dict Why return? Well if you don’t, that dictionary dies … Read more

Write to multiple outputs by key Spark – one Spark job

If you use Spark 1.4+, this has become much, much easier thanks to the DataFrame API. (DataFrames were introduced in Spark 1.3, but partitionBy(), which we need, was introduced in 1.4.) If you’re starting out with an RDD, you’ll first need to convert it to a DataFrame: val people_rdd = sc.parallelize(Seq((1, “alice”), (1, “bob”), (2, … Read more

CMake: setting an environmental variable for ctest (or otherwise getting failed test output from ctest/make test automatically)

The built-in test target cannot be modified, but you can add a custom check target which invokes ctest with the –output-on-failure switch in the following way: if (CMAKE_CONFIGURATION_TYPES) add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} –force-new-ctest-process –output-on-failure –build-config “$<CONFIGURATION>”) else() add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} –force-new-ctest-process –output-on-failure) endif() The custom target has to be set up differently for single build type … Read more

Create Java console inside a GUI panel

Here’s a functioning class. You can install an instance of this into the system out and err using: PrintStream con=new PrintStream(new TextAreaOutputStream(…)); System.setOut(con); System.setErr(con); Updated 2014-02-19: To use EventQueue.invokeLater() to avoid GUI threading issues which can crop up very rarely with the original. Updated 2014-02-27: Better implementation Updated 2014-03-25: Correct recording & deletion of lines … Read more

Printing debug output to console in Codeception

See Debugging which says You may print any information inside a test using the codecept_debug function. And I’m using it in my *Cept class: codecept_debug($myVar); Your debug output is only visible when you run with –debug (-v doesn’t show it, but -vv and -vvv do): codecept run –debug And the output looked like: Validate MyEntity … Read more

Add each array element to the lines of a file in ruby

Either use Array#each to iterate over your array and call IO#puts to write each element to the file (puts adds a record separator, typically a newline character): File.open(“test.txt”, “w+”) do |f| a.each { |element| f.puts(element) } end Or pass the whole array to puts: File.open(“test.txt”, “w+”) do |f| f.puts(a) end From the documentation: If called … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)