LaTeX \newcommand default argument: is empty?

Try the following test: \documentclass{article} \usepackage{xifthen}% provides \isempty test \newcommand{\optarg}[1][]{% \ifthenelse{\isempty{#1}}% {}% if #1 is empty {(((#1)))}% if #1 is not empty } \begin{document} Testing \verb|\optarg|: \optarg% prints nothing Testing \verb|\optarg[]|: \optarg[]% prints nothing Testing \verb|\optarg[test]|: \optarg[test]% prints (((test))) \end{document} The xifthen package provides the \ifthenelse construct and the \isempty test. Another option is to … Read more

Advantages of using condition variables over mutex

A condition variable allows a thread to be signaled when something of interest to that thread occurs. By itself, a mutex doesn’t do this. If you just need mutual exclusion, then condition variables don’t do anything for you. However, if you need to know when something happens, then condition variables can help. For example, if … Read more

How to load a script only in IE

I’m curious why you specifically need to target IE browsers, but the following code should work if that really is what you need to do: <script type=”text/javascript”> if(/MSIE \d|Trident.*rv:/.test(navigator.userAgent)) document.write(‘<script src=”https://stackoverflow.com/questions/29987969/somescript.js”><\/script>’); </script> The first half of the Regex (MSIE \d) is for detecting Internet Explorer 10 and below. The second half is for detecting IE11 … Read more

Pandas – Case when & default in pandas

Option 1 For performance, use a nested np.where condition. For the condition, you can just use pd.Series.between, and the default value will be inserted accordingly. pd_df[‘difficulty’] = np.where( pd_df[‘Time’].between(0, 30, inclusive=False), ‘Easy’, np.where( pd_df[‘Time’].between(0, 30, inclusive=False), ‘Medium’, ‘Unknown’ ) ) Option 2 Similarly, using np.select, this gives more room for adding conditions: pd_df[‘difficulty’] = np.select( … Read more

Count number of elements in each column less than x

In [96]: df = pd.DataFrame({‘a’:randn(10), ‘b’:randn(10), ‘c’:randn(10)}) df Out[96]: a b c 0 -0.849903 0.944912 1.285790 1 -1.038706 1.445381 0.251002 2 0.683135 -0.539052 -0.622439 3 -1.224699 -0.358541 1.361618 4 -0.087021 0.041524 0.151286 5 -0.114031 -0.201018 -0.030050 6 0.001891 1.601687 -0.040442 7 0.024954 -1.839793 0.917328 8 -1.480281 0.079342 -0.405370 9 0.167295 -1.723555 -0.033937 [10 rows x … Read more