How to measure the execution time of a function, say f: ‘a -> ‘b in OCaml? This small OCaml function is handy: let time f = let t = Unix.gettimeofday () in let res = f () in Printf.printf “Execution time: %f secondsn” (Unix.gettimeofday () -. t); res ;; The gettimeofday returns a float representing
Read more
Tag: time
Which are sequence points in C?
Posted onWhat are sequence points in C? The comp.lang.c FAQ explains this quite well. A sequence point is a point in time at which the dust has settled and all side effects which have been seen so far are guaranteed to be complete. The sequence points listed in the C standard are: at the end of
Read more
How to resize a batch of images on Linux?
Posted onResizing images on Linux with gThumb is easy. However, I have a batch of images inside a folder. Manually resizing them will consume too much time. How to automatically resize them on Linux with a script? You can use convert from ImageMagick together with bash script to resize images inside a directory. mkdir resize; IFS=$(echo
Read more
How to increase the number of files allowed to be opened on Linux?
Posted onOn my system: $ ulimit -n 1024 Some tools like GATK are aggressive in creating temporary files by creating more than 1000 files under /tmp/. This will cause the program to fail. How to increase the number of files allowed to be opened on Linux? To increase the max number of open files to 10240,
Read more
How to get logs of a specific time range on Linux?
Posted onThe logs I am processing is Hadoop log (log4j). It is in format like: 2014-09-20 21:55:11,855 INFO org.apache.hadoop.nfs.nfs3.IdUserGroup: Updated user map size: 36 2014-09-20 21:55:11,863 INFO org.apache.hadoop.nfs.nfs3.IdUserGroup: Updated group map size: 55 2014-09-20 22:10:11,907 INFO org.apache.hadoop.nfs.nfs3.IdUserGroup: Update cache now 2014-09-20 22:10:11,907 INFO org.apache.hadoop.nfs.nfs3.IdUserGroup: Not doing static UID/GID mapping because ‘/etc/nfs.map’ does not exist. Now, I
Read more
How to change number of replications of certain files in HDFS?
Posted onThe HDFS has a configuration in hdfs-site.xml to set the global replication number of blocks with the “dfs.replication” property. However, there are some “hot” files that are access by many nodes. How to increase the number of blocks for these certain files in HDFS? You can the replication number of certain file to 10: hdfs
Read more
How to capture camera photo/video using MPlayer on Linux?
Posted onHow to capture camera photo/video using MPlayer on Linux? You can watch the video from the camera by MPlayer: # mplayer tv:// Note that you need the root privilege to play the tv://. You can use mplayer to capture photos by: # mplayer -vo png -frames 3 tv:// If will store files 0000000{1..3}.png in the
Read more
How to backup iPhone on Linux?
Posted onHow to backup iPhone on Linux? Not using iTunes or Windows. You can backup iPhone using libimobiledevice. By the time I replied here, it supports up to iOS 7. Please check this post for a tutorial. Actually, the methods introduced can be used on Linux systems with the libimobiledevice installed. Backup iPhone: idevicebackup2 backup ~/iPhoneBackups/
Read more
How to clone a snapshot of a remote repository at a specific branch?
Posted onI know that one can make a zip of the current branch by: git archive -o archive.zip HEAD However, at situations, one may want to clone a copy/snapshot of remote repository at a specific branch because: 1) The repository is large with long history and cloning the whole history takes too much time. 2) What
Read more
How to adjust the system partition (C:) size of Windows?
Posted onThe disk management tools of Windows can adjust it to some level. But there are more space available as far as I can tell. How to further adjust the system partition (C:) size of Windows? You may check these tools: EASEUS Partition Master (free) Includes Partition Manager, Disk & Partition Copy Wizard and Partition Recovery
Read more
Emacs Remembering Last Editing Positions
Posted onHow to make emacs remember last editing positions in files. It will be convenient next time I open the same file the cursor automatically moves to the position I was last time editing the same file. The behavior seems enabled by default in Vim. How to make Emacs do this? I use the saveplace mode.
Read more
How to calculate the average of value in lines of a text file on Linux by a script?
Posted onHow to calculate the average of value in lines of a text file on Linux by a script? The file.txt is like: Run 0: Time used: 22.235331711 seconds. Run 1: Time used: 20.784491219 seconds. Run 2: Time used: 21.851638876 seconds. What I want it to calculate the average time. awk is handy for this purpose:
Read more
How to install multiple versions of sbt on my Linux host?
Posted onHow to install multiple versions of sbt on my Linux host For example, some projects use 0.12.x while some use 0.13.x. Installing neither in the system only is not sufficient enough. You may use the excellent sbt-extras: https://github.com/paulp/sbt-extras Most of the time, it detects the version of sbt needed in the project direoctory automatically: [zma@office
Read more
How to get the time at millisecond level on Linux with command line?
Posted onI know that gettimeofday() is a nice API. But how to get the number of seconds with milliseconds since the epoch time? You can get the time at nano-seconds level (although it is not guaranteed that the last digits are accurate) by: date +%s.%N
Git branching tutorial
Posted onGood tutorials on git branching. The “Git Branching” chapter of Pro Git book is the best one that I ever seen: http://git-scm.com/book/en/Git-Branching It deserve the time to study the whole chapter. If you are working with a git server, this chapter is especially useful: http://git-scm.com/book/en/Git-Branching-Remote-Branches
How to exclude users from GDM login screen?
Posted onHow to exclude users from appearing in the GDM login screen of Gnome 3? There is a long-time bug related to this ( https://bugzilla.redhat.com/show_bug.cgi?id=723708 ) which causes that the /etc/gdm/custom.conf has no effect. The closes workaround I find working on Fedora 20 is to totally disable listing of users (run as root): cat > /etc/dconf/db/gdm.d/01-mysettings
Read more
How to set up the Java environment in Linux?
Posted onI am using Fedora 20. I installed the rpm from Oracle for the Oracle JDK. How to set up the environment so that the Java environment is Oracle JDK instead of the OpenJDK? The Oracle JDK is install to /usr/java/ directory. On my Fedora 20, it looks like this: $ ls /usr/java -l total 4
Read more
How to swap alt and ctrl on Linux for Emacs?
Posted onHow to swap alt and ctrl on Linux for Emacs? It will be more easier to press the ctrl keys which is a very important key for Emacs. You can make of xmodmap. Save this as a file modmap: clear control clear mod1 keycode 64 = Control_L NoSymbol Control_L keycode 37 = Alt_L Meta_L Alt_L
Read more
How to make Emacs run in command line by default?
Posted onHow to make Emacs run in command line by default? I do not want to open the X window. You have at least 2 choices. First choice: use emacs-nox and make it the default: # yum install emacs-nox # alternatives –config emacs and choose emacs-nox. Second choice: use emacs but with -nw to disable the
Read more
How to back up a complete IMAP account?
Posted onI have a large IMAP email account which contains many emails in a rich structure of directories. How to back up the whole IMAP account to my local computer? The requirements: Automatically downloading these files. There are many directories, and copying-pasting emails will take too much time. Keep the directory structures which are used to
Read more