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
Tag: Programming
Alternatives to goto in bash
Posted onAs 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
How to set options for scala in sbt
Posted onIn sbt, I found this message printed out by the scala compiler: [warn] there were 1 deprecation warning(s); re-run with -deprecation for details [warn] one warning found The question is, how to add options (-deprecation here) to the scala compiler in sbt? You can use this inside the sbt console: set scalacOptions += “-deprecation”
Programming language popularity indices?
Posted onAny 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 onI 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 onManaging 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
Syntactical difference among OCaml, Scala, F# and Haskell
Posted onWhat’s the syntactical difference among OCaml, Scala, F# and Haskell. This page gives a side-by-side reference among OCaml, F#, Scala and Haskell: ML Dialects and Friends: OCaml, F#, Scala, Haskell
How to find out which function causes Exception “Stack_overflow” in OCaml
Posted onMy 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 onHow 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 onutop 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
Remove trailing spaces at the end of each line in a file
Posted onHow to remove trailing spaces at the end of each line in a file on Linux? Use this script with sed: cat your_file | sed ‘s/[[:blank:]]+$//g’
Import Evolution mail directory to Thunderbird/imap account
Posted onI 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
Auto indenting for OCaml code in Vim
Posted onHow to set up auto indenting for OCaml code in Vim? The built-in indenting in Vim for OCaml seems not very good. Please check the post at https://www.systutorials.com/5212/auto-indenting-for-ocaml-code-in-vim-with-ocp-indent/
How to padding a integer with 0s in bash?
Posted onHow to convert an integer into a string of many characters padded with 0s in bash. To do this in C: sprintf(buffer, “%08d”, n); which convert integer n to a 8-character string padded with leading 0s. How to padding a integer with 0s in bash? In bash, you can also use printf For the previous
Read more
How to get the output of a system command in C
Posted onHow to get the output of a system command in C? The system function is handy. But how to get the output? popen is a useful function for this purpose: https://www.systutorials.com/docs/linux/man/3p-popen/ You can use normal file operation functions like fgets to read file content from the file opened by popen.
How to make a static library (.a) on Linux
Posted onHow to make a static library (.a) on Linux? How to generate a library from C programs in files lib1.c and lib2.c: $ gcc -c lib1.c lib2.c Create a library “libmy.a” using ar: $ ar -cvq libmy.a lib1.o lib2.o You can also list the files in a library with ar: $ ar -t libmy.a You
Read more
How to delete multiple items from Kindle Library
Posted onThe 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 onHow 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
C++ cout formatting output
Posted onHow to format outputs with cout in C++? You need IO Manipulators <iomanip>: Header providing parametric manipulators. There are also good tutorials on the Web: Output Formatting: http://arachnoid.com/cpptutor/student3.html Formatting Cout Output in C++ using iomanip: http://www.cprogramming.com/tutorial/iomanip.html
g++: sorry, unimplemented: non-trivial designated initializers not supported
Posted ong++ (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