In Golang, how to convert a string to unicode rune array and do the reverse way? Convert string s to a rune array: runes := []rune(s) Convert a rune array runes to string: str := string(runes)
Author: Eric Ma
Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.How to process a file line by line in Go?
Posted onIn the Go programming language, How to process a file line by line? An equivalent piece of Bash code could be while read line ; do echo $line done < ./input.txt You can make use of the bufio package’s Scan(). // open the file filepath f := os.Open(filepath) // create a scanner fs := bufio.NewScanner(f)
Read more
In Node.js, how to import functions from another JavaScript file?
Posted onIn Node.js, how to import functions from another JavaScript file like source common.sh in Bash? In the .js file to be imported such as ‘common.js’, organize functions to be exported like module.exports = { func1: function () { // func1 impl }, func2: function () { // func2 impl } }; In the other .js
Read more
How to convert the dmesg timestamps to easier to read format on Linux?
Posted onThe dmesg results from newer Linux kernels show the timestamps. It seems the time in seconds since the kernel start time. How to convert the dmesg timestamps to the real time on Linux? The dmesg timestamp is the time in seconds since the kernel starting time. Later dmesg has an -T option: -T, –ctime Print
Read more
How to get the full path and directory of a Makefile itself?
Posted onHow to get the full path and directory of a Makefile itself like finding Bash script’s own path? This 2 lines in Makefile get the full path and dir of the Makefile itself: mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) mkfile_dir := $(dir $(mkfile_path)) The piece of code gets you Makefile, finds its absolute path and the
Read more
How to grep a tab on Linux?
Posted onHow to grep a tab on Linux? Including ‘t’ seems not working. grep can grep tabs. The problem is likely the tab is not passed to grep. If you are using Bash, you can use ANSI-C quoting to pass the “tab” to grep: $ grep $’t’ file.txt Or, use Perl-style regex (only for GNU grep)
Read more
How to create a Reader from a string in Go?
Posted onIn Go, how to create a Reader from a string? Many APIs use a Reader as its input. In Go, the strings.NewReader(s) library function creates a Reader from a string. Check the doc at: https://golang.org/pkg/strings/#NewReader
Where are the data of metro apps stored in Windows 10?
Posted onWhere are the files for data of the moden metro apps stored in Windows 10? The files for data of the metro apps in Windows is stored under %userprofile%AppDataLocalPackages You can enter the string in the Explore and hit enter to open the directory directly.
Where are the Start menu files in Windows 10?
Posted onWhere are the Start menu files actually stored in Windows 10? There are two folders for the startup menu for Windows: Per-user Start menu: %userprofile%AppDataRoamingMicrosoftWindowsStart Menu All user’s Start menu: %programdata%MicrosoftWindowsStart Menu
Which ssh client on iOS works the best for socks?
Posted onThere are good ssh clients on Windows and, needless to mention, Linux. But which ssh client on iOS for iPhone/iPad works the best for socks? You may try vSSH. It is the best SSH client app I found on iOS. vSSH supports tunneling/port forwarding: you can setup port tunneling in the “Port forwarding” section of
Read more
How to choose the key used by SSH for a specific host?
Posted onHow to choose a key used rather than the default ~/.ssh/id_rsa when ssh to a remote server for a specific host? You have at least 2 choices for choosing the key used by ssh. Taking ~/.ssh/key1 and user@example.com as the example here. Method one, specify the key in command line with the -i option of
Read more
how to use pc internet of window8 on iphone 4s via usb
Posted onhow to use pc internet on iPhone 4s wia usb cable, pc is of window 8 and in network setting its not showing of connection of I phones network I ever wrote a tutorial at http://www.systutorials.com/136003/iphone-connecting-internet-using-windows-pc-network-through-usb-cable/ . But please be aware that it worked only on specific OS combinations. So, I am not sure whether
Read more
How to get the metadata of an AWS S3 object?
Posted onI upload files using the aws cli http://www.systutorials.com/239665/uploading-large-files-amazon-s3-aws-cli/ . But how to get the metadata of an object in AWS S3? You can use the s3api‘s head-object command to get the metadata of an object. Taking one example: $ aws s3api head-object –bucket test-hkust –key dir2/fileupload/fb0c6353-a90c-4522-9355-7cd16cf756ff.file.txt It will print results like { “AcceptRanges”: “bytes”, “ContentType”:
Read more
How to disable an option with a bash script?
Posted onIt is possible to set an option inside a Bash script such as set -o errexit. But how to do the reverse thing, that is, to unset an option? Change – to + to do the reverse thing of unseting an option in bash. For example, to unset the errexit option set by set -o
Read more
How to check whether a function has been defined in Bash?
Posted onI would like to know whether a function, say f1(), has already been defined in Bash. How should I do it? You can use the type -t to get a string of the type of the name: If the -t option is used, type prints a string which is one of alias, keyword, function, builtin,
Read more
How to change a user’s username on Linux?
Posted onI want to rename a user’s username on Linux. For example, rename user u1 to user1. How to change a user’s username on Linux? You can use the usermod command to modify the user’s info. For changing the user name, you can use the -l option: -l, –login NEW_LOGIN The name of the user will
Read more
how change my policy of scheduling in hadoop?
Posted onI want to change policy of scheduling in Hadoop, how to I can change job order in map reduce automatically. Assume you are using Hadoop 2 / YARN. The configuration parameter named yarn.resourcemanager.scheduler.class controls the class to be used as the resource scheduler for YARN/Hadoop. The default value for the scheduler class (check more at
Read more
How to get the CPU temperatur in command linux on Linux?
Posted onMost modern servers or computers have sensors to detect the temperature of various components. On Linux, how to get the CPU core temperatur in command linux? First, make sure the package “lm-sensors” is installed on your Linux and the command sensors works for you. Then, you can use this piece of script to get the
Read more
How to make lftp to use key for authentication for sftp on Linux?
Posted onI have successfully enabled password-less ssh login to a remote server, say example.com with username user. But when I use lftp to log on the sftp by lftp sftp://user@example.com it still asks my password. How it make lftp use my private key to logon the remote lftp server? There is a little trick to make
Read more
How to make the rpcbind.service auto start in systemd on Linux?
Posted onThe command systemctl enable rpcbind.service seems not work. The rpcbind.service does not start after rebooting. How to make/force the rpcbind.service auto start in systemd on Linux? You an force the rpcbind.service to start by making it be “wanted” by the target such as multi-user: # systemctl add-wants multi-user rpcbind.service This will force rpcbind.service to start.