SysTutorials: tutorials on Linux, systems and more

Welcome to SysTutorials! Here you can find posts on Linux, Software, Programming and Web topics.

SysTutorials Keywords

Latest updates | Latest updated posts | Most viewed posts | All posts

Latest SysTutorials posts

To get updated when new posts are published? Subscribe here.

  • Posted on Saturday April 22, 2017
    You may call the System.getenv(name) library function in Java to get the environment variable value. public static String getenv(String name)Parameters: name - the name of the environment variable Returns: the string value of the variable, or null if the variable is not defined in the system environmentOne example, in the Java REPL: java> System.getenv("JAVA_HOME") java.lang.String res0 = "/usr/java/default/" Continue Reading »
  • Posted on Thursday April 20, 2017
    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 . Continue Reading »
  • Posted on Thursday April 20, 2017
    In Python, you can get the epoch time by calling time.time(): import timeprint time.time()Reference: https://www.systutorials.com/dtivl/16/how-to-get-the-epoch-timestamp#answer-18 Continue Reading »
  • Posted on Thursday April 20, 2017
    In Python, you can get the hostname by the socket.gethostname() library function in the socket module: import sockethostname = socket.gethostname()Reference: https://www.systutorials.com/dtivl/20/how-to-get-the-hostname-of-the-node?show=34#a34 Continue Reading »
  • Posted on Thursday April 20, 2017
    HTML supports many characters/symbols such as mathematical symbols, and currency symbols. They are not present on a normal keyboard. And some of these characters may have special meanings for formatting text. To add such characters / symbols to an HTML text, you can use an HTML entity name or an entity number in decimal or hexadecimal. This post list many special Characters in HTML as a friendly reference. » Read more Continue Reading »
  • Posted on Thursday April 20, 2017
    In C, we common way to store a list/collection of objects of the same type is to use one-dimensional arrays. In C, an array is a collection of data objects of the same type. An array is in a contiguous memory area. The lowest address of the memory area corresponds to the first element in the array and all other elements follow it one by one. Arrays can be statically allocated or dynamically allocated: // statically allocated // declare a static array a1 of 100 ints int a1[100];// dynamically allocated on the heap // allocate a dynamical Continue Reading »
  • Posted on Wednesday April 19, 2017
    In OCaml, you may print a string with the end line character by using the function in the Pervasives module: val print_endline : string -> unitPrint a string, followed by a newline character, on standard output and flush standard output. One usage example: $ ocaml OCaml version 4.01.1+dev2-2013-12-18+CLOSED# print_endline "hello world!";; hello world! - : unit = () # Continue Reading »
  • Posted on Wednesday April 19, 2017
    In C++, you may open a input stream on the file and use the std::getline() function from the <string> to read content line by line into a std::string and process them. std::ifstream file("input.txt"); std::string str; while (std::getline(file, str)) { // process string ... }A full example is as follows: $ g++ file-read-line.cpp -o s && ./s $ cp file-read-line.cpp input.txt $ ./s #include <iostream> #include <fstream> #include <string>int main () { std::ifstream file("input.txt"); std::string str; while (std::getline(file, str)) { std::cout << str << "\n"; } } Continue Reading »
  • Posted on Wednesday April 19, 2017
    In C and C++, you can call the getpid() library function which is a function from the POSIX library. #include <sys/types.h> #include <unistd.h>pid_t getpid(void);getppid() returns the process ID of the calling process. Example usage: getpid.c #include <stdio.h> #include <sys/types.h> #include <unistd.h>int main() { pid_t pid = getpid();printf("pid: %lu\n", pid); }Build and run it: $ gcc getpid.c -o s && ./s ppid: 7108 Continue Reading »
  • Posted on Wednesday April 19, 2017
    In C and C++, you can call the getppid() library function which is a function from the POSIX library. #include <sys/types.h> #include <unistd.h>pid_t getppid(void);getppid() returns the process ID of the parent of the calling process. Example usage: getppid.c #include <stdio.h> #include <sys/types.h> #include <unistd.h>int main() { pid_t ppid = getppid();printf("ppid: %lu\n", ppid); }Build and run it: $ gcc getppid.c -o s && ./s ppid: 22312Verify the pid of the parent process (the Bash shell): $ echo $$ 22312 Continue Reading »
  • Posted on Tuesday April 18, 2017
    From a small business owner, a blogger, a student or individual with a personal project, the need to create websites has never been more prominent. Having a basic understanding of HTML and canvas knowledge can be helpful, and it is simple to master. The thought of learning to code and programming may seem a long and daunting task, but some people may be surprised to know that it need not be as scary as it sounds. » Read more Continue Reading »
  • Posted on Saturday April 15, 2017
    This post introduces how to install a paravirtualized CentOS 7 DomU on Xen. The very common way of installing DomU does not work for CentOS 7. A little trick to set the repository and the network used by the VM should be used by adding a setting strings to the “extra=” field for this VM. To install the DomU VM, first download the pxeboot images from CentOS’s official website at http://mirror.centos.org/centos/7/os/x86_64/images/pxeboot/. » Read more Continue Reading »
  • Posted on Wednesday April 12, 2017
    In OCaml, you can use the Printf.eprintf function to print to STDERR (which is in Pervasives.stderr). Examples: Use Printf.eprintf: $ rlwrap ocaml 2>/tmp/a.txt OCaml version 4.01.1+dev2-2013-12-18+CLOSEDCannot find file topfind. Unknown directive `thread'. # Printf.eprintf "hello world!";; - : unit = () # $ cat /tmp/a.txt hello world!Use Printf.fprintf to print to Pervasives.stderr: $ rlwrap ocaml 2>/tmp/a.txt OCaml version 4.01.1+dev2-2013-12-18+CLOSEDCannot find file topfind. Unknown directive `thread'. # Printf.fprintf Pervasives.stderr "hello world!";; - : unit = () # $ Continue Reading »
  • Posted on Monday April 10, 2017
    In Go, you can use the os.Hostname() function to get the hostname of the node. func Hostname() (name string, err error)Hostname returns the host name reported by the kernel.One example is as follows. The main.go source code: package mainimport ( "fmt" "os" )func main() { name, err := os.Hostname() if err != nil { panic(err) }fmt.Println("hostname:", name) }Run it: $ go run main.go hostname: host001 Continue Reading »
  • Posted on Sunday April 09, 2017
    The USB standards have evolved to 3.1 and the supported throughput have been increased too. On Linux, the support to USB standards are following the standards development. In this post, we will survey the standards that common hardware support and the support in Linux. USB standards USB 2.0: https://en.wikipedia.org/wiki/USB#USB_2.0Speed: » Read more Continue Reading »
  • Posted on Sunday April 09, 2017
    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.jarOne usage example is as follows. $ 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 Welcome to JavaREPL version 428 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_25) Type expression to evaluate, :help for more options or press tab to auto-complete. Connected to local instance at http://localhost:33598 java> long ts = Continue Reading »
  • Posted on Saturday April 08, 2017
    In C, from man 7 time: UNIX systems represent time in seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). A program can determine the calendar time using gettimeofday(2), which returns time (in seconds and microseconds) that have elapsed since the Epoch; time(2) provides similar information, but only with accuracy to the nearest second.You can use the time() library function to get the epoch timestamp: On 32-bit POSIX systems: fprintf(stdout, "%u\n", (unsigned)time(NULL));On 64-bit POSIX systems: fprintf(stdout, "%lu\n", (unsigned long)time(NULL)); Continue Reading »
  • Posted on Monday April 03, 2017
    In Bash, you can use the date command's -d option: date -d @<your epoch>Here @ specifies the epoch timestamp. One example: $ date -d @1490157520.05 Wed Mar 22 12:38:40 HKT 2017 Continue Reading »
  • Posted on Friday March 31, 2017
    A tip to help you save a file with spaces in its name into HDFS: putting file from STDIN. One example is as follows: date | hdfs dfs -put - "/path/file with space.txt"For your example above, the command can be: cat "/home/u1/testa/test a" | hdfs dfs -put -f - "/u1/testa/test\ a"Then your file will be save into HDFS successfully with the space kept. Note that if you would like to keep the mode of the file, you will need to set it explicitly using hdfs dsf -chmod .... Continue Reading »
  • Posted on Friday March 31, 2017
    To get an environment variable (e.g. "VAR") in GO: import "os" import "fmt"fmt.Println("VAR:", os.Getenv("VAR")) Continue Reading »
hss-keywords.png

Most viewed posts

sai-kung-hong-kong.jpg

Latest updated posts

All posts

Pages

Posts

Subscribe, contact, and license

Subscribe to SysTutorials: Subscribe. Contact us: Contact. General license and policy: License.