How to print a plain text file to printers from a terminal in Linux

Posted on

How to quickly print a plain text file to printers from a terminal in Linux? You can also use enscript: enscript – convert text files to PostScript, HTML, RTF, ANSI, and overstrikes https://www.systutorials.com/docs/linux/man/1-enscript/ enscript text-file The lp command can print a plain text file to a printer. My favorite command: cat text-file | lp -o
Read more

Alternatives to goto in bash

Posted on

As we know: There is no goto statement support in bash. goto is useful for certain situations, especially for debugging. So, is there any alternative mechanisms to goto in bash? Robert Copeland gave an interesting hacking to this problem: http://bobcopeland.com/blog/2012/10/goto-in-bash/ The idea is like the self-modifying code. But the difference is to generate a piece
Read more

Programming language popularity indices?

Posted on

Any good programming language popularity indices? Those are interesting ones: TIOBE Indexhttp://www.tiobe.com/index.php/content/paperinfo/tpci/index.html The RedMonk Programming Language Rankings: January 2014 This ranking is published as blog posts. So no persistent homepage found yet. The January 2014 version is: http://redmonk.com/sogrady/2014/01/22/language-rankings-1-14/ Programming Language Popularityhttp://langpop.com/

How to get a Makefile’s directory for including other Makefiles

Posted on

I experience this problem: I have a file common.mk that includes release.mk which in the same directory. common.mk is included by the top-level Makefile. common.mk and release.mk are shared by multiple projects and the top-level Makefile may stay in different directories with {common,release}.mk. Now, include in make use the pwd as base directory. So, simply
Read more

Random string password generator in Scala

Posted on

Managing our research cluster, I frequently need to generate some string for new users’ password. How to generate them automatically and randomly in Scala? The passwords need characters ‘a’ – ‘z’, ‘A’ – ‘Z’ and ‘0’ – ‘9’ only. This piece of code works very well for me: def randomString(len: Int): String = { val
Read more

How to find out which function causes Exception “Stack_overflow” in OCaml

Posted on

My OCaml program prints: Fetal error: Exception “Stack_overflow” without any further information. How to find out which function causes this “Stack_overflow” exception? First, recompile your OCaml program with -g. Second, rerun your OCaml program with OCAMLRUNPARAM=b and the backtrace will be printed out after the “Stack_overflow” exception.

How to install sbt for scala on Fedora Linux

Posted on

How to install sbt for scala on Fedora Linux? It is not included in the default Fedora repository although scala is included. The download page of scala-sbt.org provides the RPM package. You can install the sbt rpm package by yum. We only need the URL to the RPM package. Here, let take version 0.13.1 as
Read more

utop key bindings / key shortcuts

Posted on

utop is an improved toplevel for OCaml supporting line edition, history, real-time and context sensitive completion, colors and etc. utop is convenient to use. However, the key bindings are a little bit different from the ones with GNU readline. What are all the key bindings? The #utop_bindings command will print all the key bindings. Here
Read more

Import Evolution mail directory to Thunderbird/imap account

Posted on

I have some old emails left in the Evolution local directory (unfortunately not in the mail server’s imap directory). So how to import the Evolution directory which contains some files for the emails to Thunderbird so that I can copy them to the imap directory if needed? You can do this in two steps: First,
Read more

How to delete multiple items from Kindle Library

Posted on

The Kindle Library Web interface only provide interface to delete items one by one. How to delete multiple items from my Kindle Library? This works on Chrome. First, browse deki.js to find the javascript for the “DeKi: Delete Kindle Items” plugin. Press “Ctrl + A” then “Ctrl + C” to copy all the javascript code.
Read more

How to set and get an environment variable in C on Linux?

Posted on

How to set and get an environment variable in C on Linux? You can use the setenv and getenv POSIX APIs to set and get environment variables. To add or change environment variable: #include <stdlib.h> int setenv(const char *envname, const char *envval, int overwrite); To get value of an environment variable: #include <stdlib.h> char *getenv(const
Read more

g++: sorry, unimplemented: non-trivial designated initializers not supported

Posted on

g++ (version g++ (GCC) 4.8.1 20130603 (Red Hat 4.8.1-1)) report: $ g++ -std=c++11 solution.cpp -o sol solution.cpp: In function ‘int main()’: solution.cpp:50:57: sorry, unimplemented: non-trivial designated initializers not supported Stat init_stat {.depth = 0, .moves = tv, .vec = init}; ^ solution.cpp:50:57: sorry, unimplemented: non-trivial designated initializers not supported solution.cpp:50:57: sorry, unimplemented: non-trivial designated initializers
Read more