- Disable “duplicated code” detection
- Settings → Editor → Inspections → General → Duplicated Code
- (Or better) in the source code, use @SuppressWarnings(“Duplicates”)
- Ref.: stackoverflow
- Show source file structure
- From menu: “View” -> “Tool Windows” -> “Structure”
- Quick key: CMD + 7
- Reformat all codes under a folder: in Project view, select the folder, then Code -> Reformat Code
Author Archives: writer
C++ Notes
This is reading notes on Professional C++ by Marc Gregoire, but also includes other notes.
- In switch statement, expression must be integer type.
- Why can’t be string? Because C++ does not recognize string as a type. Ref:
- Array initialization
- in C style:
- int myArray[3] = {0}; // all 0
- int myArray[3] = {1}; // first 1, other two 0
- int myArray[] = {0,1,2}; // an array of 3 elements, [0;1;2]
- in C++ style:
- array<int, 3> myArray = {0, 1, 2}
- For array of variable length, use vector
- in C style:
- Range-based for loop
- for (int i : myArray)
- __func__ is implicitly declared (i.e. can be used as function name directly inside of a function) as:
- static const char __func__[] = “func-name”;
- Alternative function syntax (with trailing return type):
- auto func(int i) -> int // {…}
- Function return type deduction (use compiler to figure out return type)
- auto func(int i) // {…}
- all returns should resolve to the same type
- in recursive calls, first return must be non-recursive
- Type inference
- by auto:
- auto result = func();
- by decltype:
- int x = 1; decltype(x) y = 2;
- by auto:
- const int i = 1 is not equal to #define i 1
- int *j; later *j is called “dereference”
- C++ coding style: https://google.github.io/styleguide/cppguide.html
- Better only use static_cast (according to Ira Pohl)
- binary literal to string:
std::string str = std::bitset<8>(123).to_string();</code>
- measure execution time of function:
https://stackoverflow.com/questions/22387586/measuring-execution-time-of-a-function-in-c
MacOS terminal shortcut keys
- Go to beginning of line: Ctrl + a
- Go to end of line: Ctrl + e
- Clear whole line: Ctrl + u
- Clear previous word: Ctrl + w
Notes on “Work Smarter Not Harder”
This is a free book by Timo Kiander. Below are the main points.
Foundation:
- Let mindset grow.
- Physically exercise regularly.
- Eat healthy foods.
- Sleep well:
- First find out how much sleep is needed by wake up without alarm
Tips:
- Powerful start of the day
- Get up early (and get to bed earlier), and spend the morning time to reach goals
- Optimize working rhythm
- e.g. work 25 min & rest 5 min; or work 90 min & rest 20 min; or work 52 min & rest 17 min.
- Avoid distractions
- Set up 2~3 time windows to handle emails and other communications; go to office early (because it is quiet);
- Write down ideas and thoughts on a paper for later review
- Plan the day in advance
- Write down 3 important tasks (and some lower-priority tasks); do not add new tasks
Find Java JDK installation path on MacOS
echo $(/usr/libexec/java_home)
Remove URL in IEEEtran bibliography on Mac OS
If you don’t want fields such as “[Online]”, “Available: …” appear in IEEEtran bibliography items:
1. Go to installation folder of IEEEtan bst.
(on my Mac OS with Texlive, the folder is /usr/local/texlive/2016/texmf-dist/bibtex/bst/IEEEtran)
2. Backup and then edit IEEEtran.bst, search “FUNCTION XXX” (XXX could be “inproceedings”, “inbook”, etc.), and comment out “format.url output”
3. run “texhash”
4. recompile .bib and .tex files.
Reference:https://tex.stackexchange.com/questions/45160/remove-url-in-ieeetran-bibliography
TensorFlow notes (2): Activation Functions
Reference: https://www.tensorflow.org/versions/r0.10/api_docs/python/nn/activation_functions_
1. Smooth nonlinearities:
(tf.nn.)sigmoid, tanh, elu, softplus, softsign
2. Continuous but not everywhere differentiable:
(tf.nn.)relu, relu6
3. Random regularization:
(tf.nn.)dropout
e.g. for tf.contrib.learn.DNNClassifier, the default activation function in __init__ is relu:
__init__( ..., activation_fn=tf.nn.relu, ...)
Ubuntu set hostname
hostnamectl set-hostname HOSTNAME-TO-USE
TensorFlow notes (1): Getting Started
Reference: https://www.tensorflow.org/get_started/get_started
1. Multiple level APIs:
(1) lowest level: TensorFlow Core, if you need fine controls on the model
(2) higher levels: built on Core, easier to use, e.g. tf.contrib.learn
2. Tensor: an array of primitive values. Rank: how many dimensions. Shape: a vector, containing the numbers of elements in each dimension.
e.g. [[[1., 2., 3.]], [[7., 8., 9.]]] has rank 3, shape [2,1,3]
3. Import library
import tensorflow as tf
Stop brute force attacks on WordPress
If there is “Error connecting to database” error, and the access.log file is huge (several GB), and there are many “POST /xmlrpc.php” or “POST /wp-login.php” in it, it’s brute force attack.
How to stop it?
I. Use password to protect wp-login.php
1. Generate file ./htpasswd, e.g. use http://www.htaccesstools.com/htpasswd-generator/, put it in folder (e.g. /var/www)
Note: could use the following command to generate random password first
openssl rand -base64 6
2. Add the following code in .htaccess under where the wp-login.php is (usually the root folder of WordPress installation)
# Stop Apache from serving .ht* files <Files ~ "^\.ht"> Order allow,deny Deny from all </Files> # Protect wp-login <Files wp-login.php> AuthUserFile [ABSOLUTE PATH]/.htpasswd AuthName "Private access" AuthType Basic require user USERNAME-SET-IN-HTPASSWD </Files>
Reference: Brute Force Attacks on WordPress.org
II. Stop access to xmlrpc.php
If xmlrpc is not used, just block access to it. In .htaccess file, add
<Files xmlrpc.php> order deny,allow deny from all </Files>