In Python, how to get the value (string) of an environment variable? In Python, all environment variables can be accessed directly through os.environ import os print os.environ[‘HOME’] If the environment variable is not present, it will raise a KeyError. You can use get to return None if the environment variable is not present: print os.environ.get(‘ENV_MIGHT_EXIST’)
Read more
Author: Q A
How to process a file line by line in Bash?
Posted onIn Bash, how to process a file line by line? The file is a plain text line like input.txt. As an example, the process can be to just print it out. In Bash to process a file ./input.txt line by line: while read line ; do echo $line done < ./input.txt Reference: https://www.systutorials.com/qa/2166/how-to-process-a-file-line-by-line-in-go
Reading and Processing a File Line by Line in C++
Posted onIn C++, how to process a file line by line? The file is a plain text line like input.txt. As an example, the process can be to just print it out. 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
Read more
How to process a file line by line in PHP?
Posted onIn PHP, how to process a file line by line? The file is a plain text line like input.txt. As an example, the process can be to just print it out. In PHP, you can use this code snippet to process a file line by line: if ( ($fhandle = fopen(“./input.txt”, “r”) !== FALSE )
Read more
Any good Java REPL tool/implementation?
Posted onAny 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
How to put files with spaces in names into HDFS?
Posted onI got this error when I tried to save a file with a space in its name into HDFS: $ hdfs dfs -put -f “/home/u1/testa/test a” “/u1/testa/test a” put: unexpected URISyntaxException while the HDFS seems allow spaces in its file names: https://hadoop.apache.org/docs/r2.7.3/hadoop-project-dist/hadoop-common/filesystem/model.html . How to achieve the effect of saving the files with spaces in
Read more
How to process a file line by line in Python?
Posted onIn Python, how to process read a file line by line to process it? Like those lines in Bash: while read line ; do echo $line done < ./input.txt In Python, you can process a file line by line by a for in the file like with open(“./input.txt”, “r”) as thefile: for line in thefile:
Read more
How to get hostname in Python on Linux?
Posted onIn 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 Go?
Posted onIn Go lang, how to get an environment variable? To get an environment variable (e.g. “VAR”) in GO: import “os” import “fmt” fmt.Println(“VAR:”, os.Getenv(“VAR”))
How to get an environment variable in Python?
Posted onIn 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 .
Where to download an old release package of Hadoop?
Posted onThe download page of Hadoop http://hadoop.apache.org/releases.html only contains several recent release packages. I would like to download some old release packages such as Hadoop 2.5.0 which is not available anymore on the release page. Where to download a copy of the old release? You can download the old release packages of Hadoop on the http://archive.apache.org
Read more
Extract Images from a PDF File in Linux
Posted onHow to extract the images from a PDF file in Linux? You may use the pdfimages tool. To output jpg images from a PDF ./a.pdf, run pdfimages -j ./a.pdf ./images ./images is the output images’ prefix. The images in ./a.pdf will be extracted and saved as ./images-nnn.jpg. -j options make pdfimages generate JPEG files.
In Bash script, how to join multiple lines from a file?
Posted onIn 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 export Google Chrome password on Linux?
Posted onHow to export my Google Chrome password on Linux to a human-readable text file? In newer versions of Chrome, the passwords are stored using the encrypted password storage provided by the system, either Gnome Keyring or KWallet. We need to force Chrome to use a temporary profile folder with unencrypted password storage. Step 1. Connect
Read more
How to put AdSense ads in BuySellAds without iframe?
Posted onHi, I noticed that your site serves AdSense ads through BuySellAds and it is not in an iframe. By default, BuySellAds puts the backfill ads in an iframe. Puting AdSense ads in iframe is violation of the terms. How do you make BuySellAds not put AdSense ads in an iframe? Thanks! To inline the ads
Read more
How to identify a certificated lightning cable for iPhone 6?
Posted onThere are various lightning cables on the market. I ever purchased one but it does not work for iPhone 6… How to identify a certificated lightning cable that is good for iPhone 6? (I know the cables from Apple will definitely work. But it takes time to receive one from Apple or not always easy
Read more
How to sort all files recursively by modification time in a directory on Linux?
Posted onHow to sort all the files in a directory and subdirectories recursively by modification time on Linux? You can make use of find (GNU find, or plus stat), sort and sed together to achieve recursively sort files by modification time: find . -type f -printf ‘%T@ %pn’ | sort -k 1 -n | sed ‘s/^[^
Read more
How to make WordPress regenerate the thumbnails after I changing the media aspects?
Posted onI recently changes the media aspects. The problem is that the existing thumbnails are not changed to the new aspects. How to make WordPress regenerate the thumbnails after I changing the media aspects? The “Regenerate Thumbnails” works like a charm for me: https://wordpress.org/plugins/regenerate-thumbnails/ . It allows you to regenerate your thumbnails after changing the thumbnail
Read more
How to add a crontab entry from a shell script on Linux?
Posted oncrontab -e will start an editor to edit the crontab entries. But how to add a crontab entry from a shell script on Linux without interaction from users? You can try this piece of script: (crontab -l; echo “@reboot echo “rebooted””;) | crontab – Note that the update by this line of script is not
Read more
How to convert between Simplified Chinese and Traditional Chinese characters in text files on Linux?
Posted onHow to convert between Simplified Chinese and Traditional Chinese characters in text files on Linux from command line? You can use opencc to convert between Traditional Chinese and Simplified Chinese: https://github.com/BYVoid/OpenCC For example, to transfer a file in simplified Chinese sc.txt to traditional Chinese: opencc -i sc.txt -o tc.txt -c zhs2zht.ini The authors also provide
Read more