How to get a 10-byte length random string in bash. Use this script to get a 10-byte string of letters: tr -dc “[:alpha:]” < /dev/urandom | head -c 10 You can also get a string of letters or numbers: tr -dc “[:alnum:]” < /dev/urandom | head -c 10 Or printable characters except space: tr -dc
Read more
Tag: Programming
Run cron jobs with environmental variables for an account
Posted onA common error for configuring cron is to use environmental variables for an account in the cron command. However, cron will run the commands without these variables defined. In the crontab -e, adding . $HOME/.profile before the commands play the trick. For example: 0 */8 * * * . $HOME/.profile; ~/bin/my-command Cron is started by
Read more
How to automatically fill a batch of data to the PDF form
Posted onHow to automatically fill a batch of data (well structured) to the PDF form? There are lots data items, so automatically do this by a program/script is required. If you know a little bit of Python, you can achieve this in Python with some libraries. Check How can I auto-populate a PDF form in Django/Python.
Read more
Excerpt in homepage, category, tag and author pages for WordPress theme Twenty Thriteen
Posted onExcerpt in homepage, category, tag and author pages for WordPress theme Twenty Thriteen. Also add the “read more” link after the excerpt. The patch: diff –git a/wp-content/themes/twentythirteen/content.php b/wp-content/themes/twentythirteen/content.php index 4f61b22..53b4686 100644 — a/wp-content/themes/twentythirteen/content.php +++ b/wp-content/themes/twentythirteen/content.php @@ -30,7 +30,7 @@ </div><!– .entry-meta –> </header><!– .entry-header –> – <?php if ( is_search() ) : // Only display
Read more
How to change the maximum execution time and memory size allowed for PHP
Posted onI see this message in the error log of httpd: PHP Fatal error: Maximum execution time of 30 seconds exceeded in and PHP Fatal error: Allowed memory size of 268435456 bytes exhausted How to change them to a longer and larger value? To change the allowed maximum memory usage of PHP: Set memory_limit = 256M
Read more
PDF annotation tools on Linux
Posted onWhat are good PDF annotation tools on Linux? Preferring saving the annotation in the PDF instead of separate files or images. I find the best solution may be wine + Foxit Reader. Foxit Reader can annotate PDF files and save them. It works very well on wine. Steps to install them: Install wine # yum
Read more
Trap Ctrl-C in a Bash script
Posted onHow to trap Ctrl-C in a Bash script? The piece of code: # trap ctrl-c and call ctrl_c() trap ctrl_c INT function ctrl_c() { echo echo “Ctrl-C by user” # do the jobs exit }
How to spawn a background process in a bash script
Posted onFor example, I want to spawn many ssh background processes in one bash script: for i in `cat ./all-hosts` do ssh $i “ifconfig | grep Link” done Simply adding a & to the ssh commands does not work. Here is the script that works: for i in `cat ./all-hosts` do ssh $i “ifconfig | grep
Read more
How to install Scala on Fedora Linux
Posted onThis tutorial introduces how to install Scala 2.9.2 on 64-bit Fedora Linux 17. There are some changes needed to make scala work on Fedora Linux 17. Please check it out in the answer. Install Java Scala depends on Java, so please install Java first. In this tutorial, we installed JDK to: /usr/java/jdk1.6.0_24/lib/. Install Scala from
Read more
How to install Scala from the official Scala distribution
Posted onHow to install Scala from the official Scala distribution? This is needed on a Linux release with older version of Scala in the repository, e.g. Fedora 12. Use the install-scala.sh script: # wget https://raw2.github.com/zma/usefulscripts/master/script/install-scala.sh # sh ./install-scala.sh VER where VER is the scala version that you want to install. First step, install and configure the
Read more
Where are the Linux routing table entries stored on disk?
Posted onI know the routing tables on Linux is in memory after being set. However, where are the routing table entries stored on disk? I mean where are the routing table is persistently stored so that the routing table can be reloaded like the iptables (under /etc/sysconfig/iptables on Fedora/RHEL/CentOS Linuxes). If the system uses the /etc/rc.d/init.d/network
Read more
How to use OCaml as a script language?
Posted onHow to use OCaml as a script language like bash and python? It will be good that I can write a script in OCaml and directly invoke it. For example, I write a script named “script.ml” and then I can invoke it directly by $ ./script.ml Thanks! Three helloworld scripts: script3.ml #! /usr/bin/env ocaml print_string
Read more
Is cin much slower than scanf in C++?
Posted onI frequently hear that cin is significantly slower than scanf in C++. Is this true? And how to improve the efficiency of cin? It is really nice to use most of time. One discussion about that cin is very slow is here: http://apps.topcoder.com/forums/?module=Thread&threadID=508058&start=0&mc=7 In short: cin is not always slower (can be faster actually, see
Read more
How to import a source file to OCaml’s toplevel?
Posted onHow to import a source file to OCaml’s toplevel? Say, I want to use a function implemented in a source file in the toplevel. #use “file-name”;; Read, compile and execute source phrases from the given file. This is textual inclusion: phrases are processed just as if they were typed on standard input. The reading of
Read more
How to call C functions from OCaml code
Posted onI am writing a OCaml program but want to call some C functions provided in some source code or library. How to achieve this? Is there any good tutorials on this? A very good tutorial that is easy to follow and understand: How to wrap C functions to OCaml. A comprehensive reference manual: Chapter 19
Read more
Consistency models for distributed systems
Posted onWhich are the consistency models used for distributed systems? Papers that survey the consistency models Robert C. Steinke and Gary J. Nutt. 2004. A unified theory of shared memory consistency. J. ACM 51, 5 (September 2004), 800-849. DOI=10.1145/1017460.1017464 http://doi.acm.org/10.1145/1017460.1017464 David Mosberger. 1993. Memory consistency models. SIGOPS Oper. Syst. Rev. 27, 1 (January 1993), 18-26. DOI=10.1145/160551.160553
Read more
How to restore a Gnome 3 session?
Posted onHow to restore a Gnome 3 session? Which means: opening all the programs running last time when I log out in Gnome 3. If your purpose is to automatically start programs after logging in Gnome, another possible method is using the autostart script: https://www.systutorials.com/qa/119/how-to-write-a-autostart-script-for-gnome Run gnome-session-properties. In the “Options” tab, select “Automatically remember running applications
Read more
Add readline features in OCaml toplevel
Posted onIt is painful for a Linux user to use the OCaml toplevel without the readline features. Is there a method to enable/add these kinds of features in readline to the OCaml toplevel? I find 2 options that work very well for me: utop provides a beautiful interface and supports completion, colors, parenthesis matching, etc. It
Read more
Statically linking C and C++ programs
Posted onHow to statically compile C and C++ projects? The compiled executable should lead no dynamical library during execution. I use gcc/g++ to compile the projects. Check this post: Statically Linking C and C++ Programs on Linux with gcc.
New Mingle Forum Class
Posted onHi , Thank you for your recommendation for removing the canonical link for the forum page only. However, I am am not able to find the following code in the wpf.class.php and was hoping you let us know where we can find this class so that we can modify it accordingly. (Does -1260 refer to
Read more