Any good Java REPL tool/implementation?

Posted on

Any good suggestions on a Java REPL implementation like ‘scala’ and ‘python’ or ‘php -a’? The java-repl tool https://github.com/albertlatacz/java-repl/ works nicely for most situations for me. It is released as a .jar. Hence, it is easy to download and run: $ wget –quiet https://github.com/albertlatacz/java-repl/releases/download/428/javarepl-428.jar -O /tmp/javarepo-428.jar && java -jar /tmp/javarepo-428.jar One usage example is as
Read more

Any good Go REPL implementation / tool?

Posted on

Go lang is fast to compile and can be used as a script by go run prog.go. However, a REPL is more convenient for testing/trying some small pieces of code. Any good Go REPL implementation / tool? Try gore https://github.com/motemen/gore Get gore $ go get -u github.com/motemen/gore An example $ gore gore version 0.2.6 :help
Read more

How to get hostname in Python on Linux?

Posted on

In Python, how to get hostname as the command hostname does on Linux? In Python, you can get the hostname by the socket.gethostname() library function in the socket module: import socket hostname = socket.gethostname() Reference: https://www.systutorials.com/dtivl/20/how-to-get-the-hostname-of-the-node?show=34#a34

How to get an environment variable in Python?

Posted on

In Python, how to get an environment variable? In Python, you may use this piece of code to get an environment variable: os.environ.get(‘ENV_MIGHT_EXIST’) or this piece of code: os.getenv(‘ENV_MIGHT_EXIST’) It will return None if the environment variable is not present. Reference and for more ways, please check https://www.systutorials.com/dtivl/13/how-to-get-an-environment-variable?show=80#answer-80 .

How to read the whole file content into a string in Go?

Posted on

How to read the whole file content into a string in Go? You can use the ReadFile() func from the io/ioutil package in Go to read the whole file content: func ReadFile(filename string) ([]byte, error) For example, read file filepath content and check the error: if bytes, err := ioutil.ReadFile(filepath); err != nil { log.Fatal(“Failed
Read more

How to use ioprio_set in linux c

Posted on

Since there is no glibc wrapper for ioprio_set in linux c, we need to call this API with some definition. Using syscall in linux as follows. syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, pid, IOPRIO_PRIO_CLASS(IOPRIO_CLASS_IDLE)); Some other definitions to declare above macros. 69 enum { 70 IOPRIO_CLASS_NONE, 71 IOPRIO_CLASS_RT, 72 IOPRIO_CLASS_BE, 73 IOPRIO_CLASS_IDLE, 74 }; 75 76 enum { 77
Read more

In Bash script, how to join multiple lines from a file?

Posted on

In Bash script, how to join multiple lines from a file? For example, to join the lines a good boy to a good boy You can use tr command, something like: tr -s ‘n’ ‘ ‘ < file.txt It just goes through its input and makes changes according to what you specify in two sets
Read more

How to detect whether a file is readable and writable in Python?

Posted on

Before reading or writing a file, access should be checked first. How to detect whether a file is readable and writable in Python? You can use the os.access(path, mode) library function https://docs.python.org/release/2.6.6/library/os.html#os.access like the Linux access library function for C. It returns True if access is allowed, False if not. For readable and writable, you
Read more

How to make tee catch the stderr only in Linux?

Posted on

I would like to make tee catch the stderr and log it into a file. A brute force method by let tee listen on both stderr and stdout is okay like cmd 2>&1 | tee -a log But how to make tee catch the stderr only? You can make use of “process substitution” (>(…)) to
Read more

How to get the IP addresses of VMs in KVM with virsh

Posted on

When we create VMs in KVM, we may don’t know the IP addresses because they are automatically assigned by DHCP. So we want to get them in VMM so that can login by SSH. Do the commands as follows. $ virsh domiflist hvm1 Interface Type Source Model MAC ——————————————————- vnet0 network default virtio 52:54:00:1c:36:cd $
Read more

How to change CONFIG_HZ parameter for Linux Kernel

Posted on

If we want to change the tick time for Linux Kernel, we need to change CONFIG_HZ parameter in Linux Kernel. Do we have other better ways to change it rather than compiling Linux Kernel. Please ignore the way to add ‘divider=10’ in grub config file because it is limited only for RH/CentOS distros. Zhiqiang, please
Read more

How to install PARSEC correctly.

Posted on

PARSEC is the most important CPU-bound benchmark for systems. It is huge and hard to install because it needs lots of 3-part libs. PARSEC download link for 3.0 version: http://parsec.cs.princeton.edu/download.htm#parsec I remembered I added the answer yesterday night but I could not see the answer currently. Anyway, let me add the answer again after I
Read more