Μηνιαία αρχεία: Απρίλιος 2017


VirtualBox on Windows: Stuck in capture mode as the keyboard does not have a right Ctrl button

Recently, we got a laptop that did not have a right Ctrl button and we found out after we started a VM with no Guest Additions installed.
Because of these two factors we could not escape the VM capture mode and return to the host OS.

To resolve the issue, we pressed Alt+Ctrl+Del to force the window to escape by entering that specialised Windows security screen and the hit Cancel.
Then, we went to the VirtualBox window and did the following procedure to change the button that allows you to escape the capture mode.

From the VirtualBox Window menu we went to: File –> Preferences –> Input and then clicked on the box next to HOST KEY COMBINATION and then typed the key we wanted to use.

Advertisements

C++ How to make cout not use scientific notation

To force cout to print numbers exactly as they are and prevent it from using the scientific notation, we can use the std::fixed I/O manipulator as follows

#include <iostream>

using namespace std;

int main()
{
    std::cout << "The number 0.0001 in fixed:      " << std::fixed << 0.0001 << endl
              << "The number 0.0001 in default:    " << std::defaultfloat << 0.0001 << endl;

    std::cout << "The number 1000000000.0 in fixed:      " << std::fixed << 1000000000.0 << endl
              << "The number 1000000000.0 in default:    " << std::defaultfloat << 1000000000.0 << endl;
return 0;
}

Output

The number 0.0001 in fixed:      0.000100
The number 0.0001 in default:    0.0001
The number 1000000000.0 in fixed:      1000000000.000000
The number 1000000000.0 in default:    1e+09

CCS Upcoming Events

Αγαπητά μας μέλη,

Χριστός Ανέστη και Χρόνια σας πολλά!

Υπενθυμίζουμε πως την επόμενη Τρίτη 25/4, είναι η Ετήσια Γενική Συνέλευση μας, της οποίας θα ακολουθήσει Δεξίωση. Παρακαλώ εγγραφείτε εδώ αν θα παρευρεθείτε αφού κάνετε login και διευθετήσετε τις οικονομικές σας οφειλές. Μέχρι αύριο είναι η προθεσμία για δήλωση υποψηφιότητας για το Δ.Σ.

Επιπλέον, την Τετάρτη 26/4 διοργανώνουμε το ανοικτό σεμινάριο Records Management, στο οποίο μπορείτε να συμμετάσχετε δωρεάν μαζί με συναδέλφους και συνεργάτες, αφού δηλώσετε συμμετοχή εδώ.

Στην ιστοσελίδα μας θα δείτε ακόμα πως στηρίζουμε την εκδήλωση Cybercrime Security Forum που θα γίνει στις 4 Μαΐου, και συνδιοργανώνουμε το Διαγωνισμό Προγραμματισμού ICPC που θα γίνει στις 13 Μαΐου.

Τέλος, σας καλούμε να δείτε την ιστοσελίδα του πρώτου Παγκύπριου Διαγωνισμού Ρομποτικής www.robotex.org.cy, για τον οποίο η προθεσμία για δηλώσεις συμμετοχής είναι η 25η Μαΐου.

Δείτε όλους τους σχετικούς συνδέσμους, δηλώστε συμμετοχή σε όσα σας αφορούν και προωθήστε σε πιθανούς ενδιαφερομένους!

Επικοινωνήστε μαζί μας για οποιαδήποτε διευκρίνιση.

Καλό Σαββατοκύριακο!

Με εκτίμηση
από την ομάδα του CCS

[email protected]


Replace a character in all filenames

The following command will search for files in the current directory (.) that have in their name the colon character :.
The files that match will then be renamed and all instances of the colon character : in the names will be replaced by the full stop character ..

find . -name "*:*" -execdir sh -c 'mv "$1" "${1//:/.}"' _ {} \;
  • -execdir command {} + is like -exec, but the specified command is run from the subdirectory containing the matched file, which is not normally the directory in which you started find.

Example: if you have a file named 2017-03-15 14:34:44.116002523.png then it will be renamed to 2017-03-15 14.34.44.116002523.png.


C++: Simplified version of ‘Friends with benefits’ demonstrating friend classes

A friend class in C++ can access the private and protected members of the class in which it is declared as a friend.

Friendship may allow a class to be better encapsulated by granting per-class access to parts of its API that would otherwise have to be public.[2] This increased encapsulation comes at the cost of tighter coupling due to interdependency between the classes.

Properties

  • Friendships are not symmetric – if class A is a friend of class B, class B is not automatically a friend of class A.
  • Friendships are not transitive – if class A is a friend of class B, and class B is a friend of class C, class A is not automatically a friend of class C.
  • Friendships are not inherited – if class Base is a friend of class X, subclass Derived is not automatically a friend of class X; and if class X is a friend of class Base, class X is not automatically a friend of subclass Derived.

From Wikipedia: https://en.wikipedia.org/wiki/Friend_class

In the following example we assign both the Man to be a friend of the Woman and the Woman to be a friend of the Man in order to allow both parties to access the private members of the other.

#include <iostream>
using namespace std;

class Man;

class Woman {
  friend class Man;

public:
  void touch(Man man);
private:
  void * body;
};

class Man {
  friend class Woman;

public:
  void touch(Woman woman);
private:
  void * body;
};

void Woman::touch(Man man) {
  void * other = man.body;
}

void Man::touch(Woman woman) {
  void * other = woman.body;
}

int main() {
  Man man;
  Woman woman;

  man.touch(woman);
  woman.touch(man);
  return 0;
}

How does ‘git pull’ and ‘git fetch’ differ?

In simple terms, the difference between the two Git commands is that git pull is composed by a git fetch followed by a git merge.

When you use git pull, Git will automatically merge any pulled commits into the branch you are currently working in, without letting you review them first. You will get a prompt only if there is conflict found during automatic merging.

When you use git fetch, Git retrieves any commits from the target branch that do not exist in your current branch and stores them in your local repository. However, it will not merge them with your current branch. To integrate the new commits into your current branch, you need to use git merge manually.
This command is particularly useful if you need to keep your repository up to date, but are working on something that might break if you merge your files.
For example, if you will go offline and you need to have those commits available to you but cannot merge at the time, using git fetch you will download the new commits to your machine without affecting your current code. Later you will be able to merge the new commits to your branch as/when you please.


Η Αμπαλατοσύνη εν φυλή συνότζιαιρη του κόσμου,
κανένας δεν εβρέθηκεν για να την ι-ξηλείψη,
κανένας, γιατί σιέπει την που τα ‘ψη ο Θεός μου.
Η Αμπαλατοσύνη εν να χαθή, όντας ο κόσμος λείψει!

Σφάξε μας ούλους κι ας γενεί το γαίμαν μας αυλάκιν,
κάμε τον κόσμον μακελλειόν και τους Αμπάλατους τραούλλια,
αμμά ξερε πως ίλαντρον όντας κοπεί καβάκιν
τριγύρου του πετάσσουνται τρακόσια παραπούλια.
Το ’νιν αντάν να τρώ’ την γην, τρώει την γην θαρκέται,
μα πάντα κείνον τρώεται και κείνον καταλυέται.


C++: «undefined reference to» templated class function

In case you have a project where you use a templated class that is split in its own header (.h) and source (.cpp) files, if you compile the class, into an object file (.o), separately from the code that uses it, you will get the undefined reference to error at linking.

Lets assume we have Stack.cpp and Stack.h which define a templated stack using vectors. And main.cpp that uses this class after including Stack.h.

If you try to compile these files as mentioned above, one by one, later you will get a linking error saying undefined reference to for the methods of the class.

The code in the template is not sufficient to instruct the compiler to produce the methods that are needed by main.cpp (e.g. Stack<int>::push(...) and Stack<string>::push(...)) as the compiler does not know, while compiling Stack.cpp by itself, the data types it should provide support for.

The reason it allows you to compile these incomplete objects is the following:

  • main.cpp: the compiler will implicitly instantiate the template classes Stack<int> and Stack<string> because those particular instantiations are requested in main.cpp. Since the implementations of those member functions are not in main.cpp, nor in any header file included in main.cpp (particularly Stack.h), the compiler will not include complete versions of those functions in main.o and it will expect to find them in another object during linking.
  • Stack.cpp: the compiler won’t compile the instantiations of Stack<int> and Stack<string> neither as there are no implicit or explicit instantiations of them in Stack.cpp nor Stack.h.

So in the end, neither of the .o files contain the actual implementations of Stack<int> and Stack<string> and the linking fails.

Solutions

Solution 1 : Explicitly instantiate the template

At the end of Stack.cpp, you can explicitly instantiate all needed templates.
In our example we would add:

template class Stack<int>;
template class Stack<std::string>;

This will ensure that, when the compiler is compiling Stack.cpp that it will explicitly compile all the code needed for the Stack<int> and Stack<std::string> classes.

Using this method, you should ensure that all the of the implementation is placed into one .cpp file and that the explicit instantation is placed after the definition of all the functions (for example, at the end of the file).

A problem with this method is that it forces you to update the Stack.cpp file each time you want to add support for a new data type (or remove one).

Solution 2 : Move the implementation code into the header file

Move all the source code of Stack.cpp to Stack.h, and then delete Stack.cpp. Using this method you do not need to manually instantiate all possible data types that are needed and thus you do not need to modify code of the class. As a side-effect, if you use the header file in many other source files, it will compile the functions of the header file in each source. This can make compilation slower but it will not create any compilation/linking problems, as the linker will ignore the duplicate implementations.

Solution 3 : Move the implementation code into a new header file and include it in the original header file

Rename Stack.cpp to Stack_impl.h, and then include Stack_impl.h from Stack.h to keep the implementation in a separate file from the declaration. This method will behave exactly like Solution 2.