There is such a command on windows. Cool.

# Author: Agnel

## “There are stopped jobs”

Seeing this message when trying to exit bash means some interactive processes launched from this terminal are still running in the background. Use the `jobs`

command to list them. Use `fg <n>`

to bring job number `n`

to the foreground and exit the process properly.

As an example, if a command being piped to less exits and less is left hanging without anything to show, it goes to the background. Example:

1 2 3 4 5 6 7 8 9 10 11 |
agnel@Carmen:~$ non-existent-command | less non-existent-command: command not found (END) [1]+ Stopped non-existent-command | less agnel@Carmen:~$ |

This means that less is still running in the background waiting for input. Here’s how to bring it to the foreground and exit it.

1 2 3 4 |
agnel@Carmen:~$ jobs [1]+ Stopped non-existent-command | less agnel@Carmen:~$ fg 1 non-existent-command | less |

In this case, after `fg 1`

, it is not immediately clear what to do. But since I know that it is `less`

that’s running now, I hit q (since q is the `less`

keystroke to quit).

## Object Relationships using smart pointers and “Modern C++”

- Don’t use raw pointers as class members; that requires managing object life time and manually avoiding dangling pointers
- Use smart pointers instead of raw pointers
- Don’t use object references as class members as that makes objects of the class non-assignable (which means you cannot store said objects in standard C++ containers)
- Using raw pointers and object references to objects stored in standard C++ containers is problematic or impossible. Objects in containers can be relocated (addresses can change) rendering raw pointers and object references invalid.
- Best (only feasible?) option is to store
`std::shared_ptr`

of the dynamically allocated object in the container. `std::shared_ptr`

is reference counted`std::weak_ptr`

is not- Use
`std::make_shared`

to create an`std::shared_ptr`

to a dynamically created object instance or use`std::shared_ptr(new T())`

- Only way to access members via
`std::weak_ptr`

is by calling`std::weak_ptr::lock`

which returns an`std::shared_ptr`

or 0 - To create an
`std::weak_ptr`

from the this pointer, the class must first derive from`std::enable_shared_from_this`

and then call the`shared_from_this`

function to get an`std::shared_ptr`

pointing to the object. The object in question must be “owned” by an`std::shared_ptr`

or else undefined behaviour results. Also,`shared_from_this`

must not be called from a constructor since the object is yet to be reference counted (i.e. object is not yet “owned” by an`std::shared_ptr`

) - As a result of the previous point, it helps to ensure that objects can only be created via
`std::shared_ptr`

by using a public static`create`

function (which returns objects “owned” by an`std::shared_ptr`

) and making constructors private. Note that when constructors are made private, you can no longer use std::make_shared to create a shared pointer. You must use`std::shared_ptr(new T())`

in this case.

## Sage Quick Reference

Run a file:

1 |
%runfile filename.sage |

Create matrices:

1 2 3 4 |
matrix(RR, nrows, ncols) # real ring matrix(SR, nrows, ncols) # symbolic ring matrix([[a,b,c],[d,e,f],[g,h,i]]) # real vector([a,b,c]) # single column matrix |

Solve M * X = Y (where M – co-efficients; Y – constants) :

1 |
M.solve_right(Y) |

Create variables (symbolic math):

1 2 |
x,y = var('x,y') tan_theta = y / x; |

## Algebra using Sage

Here are some examples of Sage used as a Computer algebra system.

Define the symbols x and y using `var`

. Then define r2 in terms of x and y as per the Pythagorean theorem.

1 2 3 |
sage: x, y = var('x, y') sage: r2 = x * x + y * y sage: r2 |

The output remains in terms of x and y:

1 |
x^2 + y^2 |

This works with trigonometry…

1 2 3 4 5 |
sage: r = sqrt(r2) sage: sin0 = y/r sage: cos0 = x/r sage: theta = atan(sin0/cos0) sage: tan(theta) |

Output:

1 |
y/x |

…and matrices too. Below is an example of a matrix to translate and rotate a point in two dimensions.

1 2 3 4 5 6 7 8 |
sage: dx, dy, r = var('dx, dy, r') sage: s = sin(r) sage: c = cos(r) sage: tx = matrix([[c, s, dx], ....: [-s, c, dy], ....: [0, 0, 1]]) sage: v = vector([x, y, 1]) sage: tx * v |

Output:

1 |
(x*cos(r) + y*sin(r) + dx, y*cos(r) - x*sin(r) + dy, 1) |

Sage also does differentiation and integration but I am still trying to wrap my head around those two concepts.

## Solve set of equations using Sage

Given the set of equations:

\( \begin{bmatrix} 5 & 0 & 0 \\ 0 & 10 & 0 \\ 0 & 0 & 15 \end{bmatrix} \times \left[ \begin{array}{c} x_1 \\ x_2 \\ x_3 \end{array} \right] = \left[ \begin{array}{c} 1 \\ 2 \\ 3 \end{array} \right] \)

Below is how to solve them using Sage:

1 2 3 4 |
sage: A = matrix([[5,0,0],[0,10,0],[0,0,15]]) sage: Y = vector([1,2,3]) sage: X = A.solve_right(Y) sage: X |

The output:

1 |
(1/5, 1/5, 1/5) |

In order to get the output as floating point numbers use the numerical_approx function:

1 |
sage: n(X, digits=4) |

The output:

1 |
(0.2000, 0.2000, 0.2000) |

## C++ Surprise 1 – const reference

“There are just two kinds of languages: the ones everybody complains about and the ones nobody uses.” — Bjarne

This doesn’t compile:

1 2 3 4 5 |
int main(){ int x = 10; double &y = x; // error: invalid initialization of reference of // type 'double&' from expression of type 'int' } |

This does:

1 2 3 4 |
int main(){ int x = 10; const double &y = x; } |

In the second case, `y`

is initialized by a temporary `double`

initialized from `x`

. Not sure what the rationale is but read up TCPPPL 5.5.

Here is where the inconsistency becomes very difficult to ignore:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include using std::cout; using std::endl; int main(){ int x = 10; const int &iy = x; const double &dy = x; x = 20; cout << x << endl; cout << iy << endl; cout << dy << endl; return 0; } |

If anyone knows the reasoning behind this, let me know.

## Setting RDLC Subreport Parameters via Code

To set parameters on an RDLC report on Windows Forms, you can say `viewer.LocalReport.SetParameters`

and send in an array of `ReportParameter`

objects. However, what if you need to set parameter values on a subreport object? There is no way to call `SetParameters`

on the subreport object as far as I can tell. Google turned up several seemingly promising results for “rdlc subreport parameter” but none of them provided an answer.

I discovered a solution by trial and error. Here it is:

- Open the subreport and define parameters (say SR_P1, SR_P2)
- Open main report, insert a subreport object on it
- Define the corresponding parameters on the main report (MR_P1 and MR_P2)
- Right click on the subreport, select “Subreport Properties…”
- Select “Parameters” and add one row for each parameter
- Set each subreport parameter to the value of the corresponding main report parameter like this:

Name Value SR_P1 [@MR_P1] - In code, set the values of the main report parameters
`MR_P1`

and`MR_P2`

as usual using`viewer.LocalReport.SetParameters`

You are welcome.

## “The procedure entry xxx could not be located in the dynamic link library msvcrt.dll.”

This is the error I was getting when trying to install an MSI I created for a C++/CLI project. Turns out that the MSI included glut.dll and opengll.dll. When building the MSI files, warnings are displayed to the effect that those two files should be excluded.

Click on the file name under “Application Folder” and set the “Exclude” property to false in the property grid. This fixes the problem.

## Qt4 Development on Ubuntu – 1

Searching Google for [qt development ubuntu] took me to this article which details downloading and installing binaries from qt-project.org. I found from other sources that simply installing the `qt4-dev-tools`

package (using `apt-get`

or `synaptic`

) is the easier option.

“Getting Started Programming with Qt” is a very good introduction to programming Qt. One quirk I came across in the code in that article is the qApp pointer. What looked like a typo turned out to be a global pointer to the `QApplication`

instance (similar to MFC’s `CWinApp`

instance).

I did not like the “private slots:” syntax. That is not standard C++. I think I liked almost everything else about Qt that I have seen so far.

Further reading: